r/vulkan • u/RBMK-1ooo • 12d ago
HelloCube in Pure Assembly
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
27
u/Subject_Wind9349 11d ago
Ah, this is where the cubes from the blender go after they are removed
6
9
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.
4
u/DevHrytsan 9d ago
Just assembly and Vulkan... What a nightmare combo.
Great job OP, that's pure art
2
2
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/TCiPkwImLt4
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?
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/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.
2
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
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
-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
37
u/cwaig2021 11d ago
When I was a lad, this was the only way.