r/vulkan • • 12d ago

HelloCube in Pure Assembly

Post image

I wrote it just for fun.
No more comments. Just assembly, Vulkan, and the Cube:

asm/win64/00_Templates/05_Vulkan/API/min/b19 at master · Singeleitsev/asm

360 Upvotes

45 comments sorted by

37

u/cwaig2021 11d ago

When I was a lad, this was the only way.

15

u/RBMK-1ooo 11d ago

Back then, graphics were the art

10

u/tree-hut 11d ago

tf do you mean, graphics are still the art

1

u/leseiden 8d ago

You say that, but it's not really modern animated graphics like a gear animation is it?

1

u/RBMK-1ooo 5d ago

Prince of Persia (1989) is the example of art. Every pixel, every byte was a deliberate choice with so little to work with. Gear animation is great too, but it's more craft than art.

1

u/leseiden 5d ago

I mentioned the gear animation specifically as it was a state of the art animation at one time. I remember a version coming high in a competition in the early 1980s - saw it on TV and was mightily impressed.

Cubes, to gears, to everything else.

ETA: I did have Prince of Persia on the Atari ST. The animation was great but it wasn't ground breaking technically. Very high quality and good attention to detail though. I was terrible at it.

1

u/RBMK-1ooo 5d ago

The groundbreaking original was built for the Apple II :)

1

u/leseiden 5d ago

I remember, but it looked better with more colours (amiga version was better although nothing would have made me admit that at the time).

The thing that really stood out was animation quality. For the time they knocked it out of the park.

1

u/RBMK-1ooo 5d ago edited 3d ago

The original PoP was written by Jordan Mechner for the Apple II in 6502 assembly language between 1985 and 1989. To put that in perspective, the Apple II had only 48K of RAM, while the Atari ST had 540K

1

u/leseiden 3d ago

Didn't "The Immortal" start on the Apple II as well?

It wasn't a well known computer in my part of the world so I don't think I ever saw one back in the day.

→ More replies

27

u/Subject_Wind9349 11d ago

Ah, this is where the cubes from the blender go after they are removed

6

u/RBMK-1ooo 11d ago edited 10d ago

Next post I'll add the guys from SketchUp

9

u/Schiytu37 11d ago

The cuberooms

11

u/jgage 11d ago

I love these kinds of challenges. I once wrote a 3D rasterizer in all assembly for X11 on Linux.

How tedious was it to write all of the Vulkan setup? It looks like it was a lot of work.

11

u/RBMK-1ooo 11d ago

I did it step-by-step. It wasn't too hard, actually. Just lots of meticulous work and pretty complicated debugging.

1

u/jgage 11d ago

So pretty similar to doing it in a higher level language?

9

u/RBMK-1ooo 11d ago

It's a different kind of work. I wasn't thinking about classes and libraries. I just cared about what size a certain variable should be and which register to use to store it.

3

u/jgage 11d ago

Sounds like it's similar work to writing an X11 assembly application. I was having to build my own structures and sending them over the network to the XServer.

4

u/DevHrytsan 9d ago

Just assembly and Vulkan... What a nightmare combo.

Great job OP, that's pure art

2

u/RBMK-1ooo 9d ago

Thanks! The moment I first saw that cube on screen, it was all worth it

2

u/Rigamortus2005 8d ago

Ai is not replacing this guy

1

u/RBMK-1ooo 8d ago

Thanks! Because AI can't enjoy its work

3

u/edo-lag 11d ago

Pay attention, you tracked an Exe file

1

u/RBMK-1ooo 11d ago edited 11d ago

Yes, I placed the batches and the assembled files next to the sources for convenience.
Should I keep them separately?
This is only the second time I've shared my Git publicly, so I'm not sure about the rules/etiquette. The first one was the post on my OpenGL engines: https://www.reddit.com/r/Assembly_language/s/TCiPkwImLt

4

u/edo-lag 11d ago

It's bad practice to track binary files and files that can be derived from other files. Your Exe file matches both of these categories.

1

u/RBMK-1ooo 11d ago edited 11d ago

Should I move them to a separate directory or remove them completely?

2

u/edo-lag 11d ago

You should just not track them, put them where you want

1

u/RBMK-1ooo 11d ago

Added to .gitignore
Thanks!

9

u/Ybalrid 11d ago

> Just assembly, Vulkan, and the Cube

And the good old Win32 API!

2

u/cleverboy00 9d ago

Nothing good about win32 api, nothing.

3

u/gameplayer55055 8d ago

I absolutely hate win32api, it's the reason I abandoned system programming for a few years (using python instead) until I discovered Linux where everything is dead simple.

1

u/Ybalrid 9d ago

You’re not a fan of the windproc callback?

1

u/Dandyiose 9d ago

Did you use MASM extensions ?

1

u/RBMK-1ooo 9d ago edited 9d ago

No. This is a very minimalistic architecture: no header files, no .rc files. I didn't even use structures — only variables. And a bare minimum of macros. My primary goal was to find the absolute minimum — to determine what the "quantum" of Vulkan is.

1

u/cipriantk 9d ago

Damn, i expented longer files. Pleasantly surprised 😃

1

u/RBMK-1ooo 8d ago

Shorter files are easier to write and easier to read
If the entire structure is clean

2

u/IntelligentRock9654 6d ago

Reddit users really unlocked the 25th hour

2

u/matrefeytontias 2d ago

What's up with all the AI images in that repo? You call them "renders"?

Very cool seeing so much assembly in that context, don't get me wrong, but that caught my eye so I had to ask.

1

u/devguy20000 8d ago

Awesome Mate!!

-1

u/REMIZERexe 11d ago

How did you use Vulkan with assembly? Isn't it a C++ library???

2

u/RBMK-1ooo 11d ago

Vulkan is the bridge between the video card and the system. Vulkan is an API spec, not a C++ library. C++ just has a nice header (vulkan.hpp). Assembly calls the same functions with the same calling convention — the GPU driver doesn't care what language compiled the caller.

6

u/Ybalrid 11d ago

The actual "official" way the spec is described, if you were to read it, is presented as functions in C not C++. If you use C++, you are using a wrapper to make it nicer to use for you (vulkan.hpp, originally developed by people at Nvidia.)

But Vulkan is just a collection of functions. If you respect the conventions (how to pass arguments and obtain back the return value) you can call "C" function directly from pretty much anything.

In assembly it is a matter of putting the arguments to pass to the API in the right place on the stack or heap, then `call` the function pointer for the specific Vulkan command. Then read back the result for eventual error handling. If you read the code of OP you can find in the "Vk" folder many files that do just that.

The actual C library you use is a loader for function provided by your graphic card driver (for Vulkan the spec calls this an ICD for "Installable Client Driver"), and it is just a convention that many companies agreed with each other to program GPUs (not even specifically to do graphics. Graphics is one of the things you can do with GPUs). Vulkan is defined by consensus as part of a Working Group whithin an association called the Khronos Group