News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Vulkan Triangle in MASM64 Assembler

Started by IbrahimElHindawi, June 07, 2025, 05:41:47 PM

Previous topic - Next topic

IbrahimElHindawi


https://github.com/IbrahimHindawi/vulkasm
Hello, here is my Vulkan/Assembler triangle. I had a lot of fun doing things in MASM64 Assembler.
I used the MASM64 SDK's include files (included in the git repo under extern/masm64) + translated the Vulkan C headers to Assembly.
Can someone check out the repo and give me feedback on how the code can be better? I am seriously considering building a 3D game engine in Assembly.
Right now Im working on abstracting this macro:
arenaPushArrayZero macro __arena:req, __type:req, __count:req, __align:req
    ; lea rcx, __arena
    ; rdx = __type * __count
    ; r8 = alignof __type
    mov rdx, sizeof __type
    mov rax, __count
    mul rdx
    ; automate alignof
    invoke arenaPushZero, __arena, rax, __align
endm
I just want to give varying register/variable sizes to pass to `mov rax, __count` so I think I'll check the size at assembly time and set the correct instruction maybe movzx it into rax.
Otherwise I don't know what can be made simpler, Assembly doesn't really feel that bad at all compared to C.
Thanks!

IbrahimElHindawi

I tried this but when I use it in an external asm file with global variables It fails:
error A2006:undefined symbol : g_swapchain_image_views_countarenaPushArrayZero macro __arena:req, __type:req, __count:req, __align:req
    ; lea rcx, __arena
    ; rdx = sizeof(type)
    mov rdx, sizeof __type
    ; rax = count
    ; ifidni <__count>, <rax> ; if idn i if identifier case insenitive
        ; do nothing coz rax already set
    if sizeof __count eq sizeof qword
        echo "got rax"
        mov rax, __count
    elseif sizeof __count eq sizeof dword
        echo "got eax"
        mov eax, __count
    elseif sizeof __count eq sizeof word
        echo "got ax"
        mov ax, __count
    elseif sizeof __count eq sizeof byte
        echo "got al"
        mov al, __count
    else
        echo "unknown type error"
    endif
    ; rax = __type * __count
    ; rax = rax * rdx
    ; mov rax, __count
    mul rdx
    ; automate alignof
    ; r8 = alignof __type
    invoke arenaPushZero, __arena, rax, __align
endm

NoCforMe

I don't see that identifier anywhere in your macro code; was it one of the macro arguments? If so, looks like it was just what the error says it was, an undefined symbol.
32-bit code and Windows 7 foreva!

IbrahimElHindawi

yeah it was one of the macro args.
if the macro arg isnt in the same asm file it fails. ended up passing to rax before the macro invocation:
; __arena is ADDR arena, reference to the arena
; __type is the type of data to allocate
; __count is always passed into rax, eax, ax, al
; __align is the data structure memory alignment
arenaPushArrayZero macro __arena:req, __type:req, __count:req, __align:req
    ; rcx = &__arena
    ; rdx = sizeof(__type)
    ; rax = __count
    ; r8 = __align
    mov rdx, sizeof __type
    ;---
    ; handle rax zero extension:
    ;---
    ; if type __count eq type qword; this is not needed since rax is ready
        ; mov rax, rax
    ; if type __count eq type dword; this is not needed since eax is already zero extended
        ; mov eax, eax
    if type __count eq type word
        movzx rax, ax
    elseif type __count eq type byte
        movzx rax, al
    endif
    ; rax = __type * __count
    mul rdx
    invoke arenaPushZero, __arena, rax, __align
endm

NoCforMe

Can you show us the invocation of that macro, not just its definition?
32-bit code and Windows 7 foreva!

IbrahimElHindawi

my API now looks like this:
.data
image_count dword ?; this can be byte word dword qword
pos qword ?; arena position
.code
main proc
    invoke arenaGetPos
    mov pos, rax
    mov eax, image_count
    arenaPushArrayZero ADDR arena, VkImage, eax, 8; allocate
    ; do work
    invoke arenaSetPos, ADDR arena, pos; deallocate
main endp
I wanted to pass image_count directly but this works fine now, whatever

NoCforMe

I'm just curious about that rendered triangle:
It's obviously an RGB triangle, with those colors at each of its vertices.

My guess®™ as to how it's coded is that for each point in the triangle's interior you calculate its distance (straight line) to each vertex and use those distances to set the proportion of each color for that point. Amiright?

The first problem I'd have to solve is just how to get the set of all points within the triangle.
32-bit code and Windows 7 foreva!

daydreamer

Good luck with 64 bit 3d engine  :thumbsup:
But I prefer use 128 bit SSE /SSE2

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Quote from: daydreamer on June 08, 2025, 05:45:38 PMGood luck with 64 bit 3d engine  :thumbsup:
But I prefer use 128 bit SSE /SSE2

Well, goody gumdrops for you.

I think we're all tired of hearing you squawk about "SSE" this and "SIMD" that.
32-bit code and Windows 7 foreva!

TimoVJL

#9
SSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?
May the source be with you

NoCforMe

Quote from: TimoVJL on June 09, 2025, 09:51:58 PMSSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?

Oh, you bad, bad boy ...
32-bit code and Windows 7 foreva!

zedd

Quote from: NoCforMe on June 10, 2025, 05:38:17 AM
Quote from: TimoVJL on June 09, 2025, 09:51:58 PMSSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?

Oh, you bad, bad boy ...
Very naughty. Too naughty for words.  :tongue:
... and the horse that you rode in on...  :badgrin:  :biggrin:

daydreamer

Quote from: NoCforMe on June 10, 2025, 05:38:17 AM
Quote from: TimoVJL on June 09, 2025, 09:51:58 PMSSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?

Oh, you bad, bad boy ...
The bad boys get the chicks,computer nerds not  :badgrin:  :greenclp:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Quote from: daydreamer on June 10, 2025, 04:39:12 PM
Quote from: NoCforMe on June 10, 2025, 05:38:17 AM
Quote from: TimoVJL on June 09, 2025, 09:51:58 PMSSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?

Oh, you bad, bad boy ...
The bad boys get the chicks,computer nerds not  :badgrin:  :greenclp:


Too bad for you, since you're the latter.
32-bit code and Windows 7 foreva!

jj2007

Quote from: TimoVJL on June 09, 2025, 09:51:58 PMSSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?

Real 10 inches should be ok :thumbsup: