Skip to content

gpuav: Move to typed device memory allocations - #13843

Open
arno-lunarg wants to merge 1 commit into
KhronosGroup:mainfrom
arno-lunarg:arno-gpuav-no-more-raw-pointers-v3
Open

arno-lunarg wants to merge 1 commit into
KhronosGroup:mainfrom
arno-lunarg:arno-gpuav-no-more-raw-pointers-v3

Conversation

@arno-lunarg

Copy link
Copy Markdown
Contributor

Part of #13769

Improves how GPU-AV reads and writes to buffers in both C++ and shaders, by moving to shared typed declarations between C++ and shader code.

When I originally made vko::BufferRange, I was scared of doing this shared types thing because of differences between how memory is read and written to on the host side and on the device side. Right now, we use a weird mix of "just in time" casting on the C++ side to C++ only types, or offsets in u32 arrays, and I have shot myself in the foot many times by forgetting to update the C++ definition or the shader definition of what is essentially the same struct. And chasing those subtle memory bugs can be hard, especially on the GPU side.

So now, all (thus the size of the change) vko::BufferRange are typed. Types are typically declared in a header filer shared between C++ and GLSL/Slang using my... custom syntax. Macro based, not too bad for now I feel.
It brings many benefits: more expressive code, easier to follow the host <-> device code path, easier to visualize data in the debugger because of types, possibly could bound check GPU arrays accesses on the C++ side because of the dedicated Array type, etc...

@arno-lunarg
arno-lunarg requested a review from a team as a code owner December 4, 2026 18:42
@arno-lunarg

Copy link
Copy Markdown
Contributor Author

So it turned out big since BufferRange is used everywhere.

Half of the diff is spirv

Main new things are the updates to vko::BufferRange in gpuav_vulkan_buffer and the weird struct definition syntax in gpuav_shader_struct_definitions.h

Then the rest is actual usage of those, and new header file declarations with the corresponding shader and C++ changes

// Track all decorations and add after when have full id_swap_map
InstructionList decorations;

// Types with an explicit layout are never merged, the existing type can have another layout (std140) or none (Private).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So @spencer-lunarg if you have one thing to look at it is this: LLM decided to do those changes because of new struct usage in the shaders (cannot say which one precisely at this point...), I had SPIR-V validation issues and was like "???"

@spencer-lunarg

Copy link
Copy Markdown
Contributor

this is going to be REALLY hard to review, sure no way to break this up into a something smaller... going to be a while until I get to this review, mainly because this is not solving an issue and just a 6000 quality of life line change

Improves how GPU-AV reads and writes to buffers in both C++ and
shaders, by moving to shared typed declarations between C++ and
shader code.

When I originally made vko::BufferRange, I was scared of doing this
shared types thing because of differences between how memory is
read and written to on the host side and on the device side.
Right now, we use a weird mix of "just in time" casting on the C++
side to C++ only types, or offsets in u32 arrays, and I have shot
myself in the foot many times by forgetting to update the C++
definition or the shader definition of what is essentially the same
struct. And chasing those subtle memory bugs can be hard, especially
on the GPU side.

So now, *all* (thus the size of the change) vko::BufferRange are
typed. Types are typically declared in a header filer shared between
C++ and GLSL/Slang using my... custom syntax. Macro based, not too
bad for now I feel.
It brings many benefits: more expressive code, easier to follow the
host <-> device code path, easier to visualize data in the debugger
because of types, possibly could bound check GPU arrays accesses on
the C++ side because of the dedicated Array type, etc...
@arno-lunarg
arno-lunarg force-pushed the arno-gpuav-no-more-raw-pointers-v3 branch from d504830 to d4cfa36 Compare December 4, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants