The MASM Forum

General => The Workshop => Topic started by: IbrahimElHindawi on June 07, 2025, 05:41:47 PM

Title: Vulkan Triangle in MASM64 Assembler
Post by: IbrahimElHindawi on June 07, 2025, 05:41:47 PM
(https://i.postimg.cc/gwZCJwSN/image-22.png) (https://postimg.cc/gwZCJwSN)
https://github.com/IbrahimHindawi/vulkasm (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!
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: IbrahimElHindawi on June 08, 2025, 02:06:02 AM
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
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: NoCforMe on June 08, 2025, 04:41:19 AM
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.
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: IbrahimElHindawi on June 08, 2025, 05:17:44 AM
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
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: NoCforMe on June 08, 2025, 05:19:35 AM
Can you show us the invocation of that macro, not just its definition?
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: IbrahimElHindawi on June 08, 2025, 05:20:20 AM
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
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: NoCforMe on June 08, 2025, 09:28:06 AM
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.
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: daydreamer on June 08, 2025, 05:45:38 PM
Good luck with 64 bit 3d engine  :thumbsup:
But I prefer use 128 bit SSE /SSE2

Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: NoCforMe on June 09, 2025, 06:39:50 AM
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.
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: TimoVJL on June 09, 2025, 09:51:58 PM
SSE (Sperm Spreading Equipments) works well with Blondes even with real 10 in Vulvan Triangle ?
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: 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 ...
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: zedd on June 10, 2025, 09:11:14 AM
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:
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: 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:
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: NoCforMe on June 10, 2025, 06:43:53 PM
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.
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: jj2007 on June 10, 2025, 08:19:04 PM
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:
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: IbrahimElHindawi on June 14, 2025, 04:33:08 PM
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


i will use all the simd stuff at some point
Title: Re: Vulkan Triangle in MASM64 Assembler
Post by: daydreamer on June 15, 2025, 02:22:22 PM
Quote from: IbrahimElHindawi on June 14, 2025, 04:33:08 PM
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


i will use all the simd stuff at some point
I have somewhere SSE packed 2d rotation code,rotating 2 points simultaneously
For me it's alternative to pixelshaders because I am most skilled in asm(25 years SSE experience) , but hopeless newbie in pixelshaders, to work with 4 ARGB float channels in pixels and you have fast sqrtps = packed 4x sqrt,Divps rcpps,which you don't have in integer mmx/SSE2 opcodes