Skip to content

buffer offsets#51

Merged
charles-r-earp merged 3 commits intokrnl2from
buffer-offsets
Nov 11, 2025
Merged

buffer offsets#51
charles-r-earp merged 3 commits intokrnl2from
buffer-offsets

Conversation

@charles-r-earp
Copy link
Owner

Vulkan has a min alignment for buffer bindings, between 1 and 256 bytes. This makes it non trivial to pass an arbitrary slice as an argument, because it might not be aligned. For instance, the alignment might be 16 bytes, so slices that aren't multiples of 4 u32's would be invalid.

WebGPU has an identical restriction and works the same way.

This PR adds a pass at build time to add a buffer offset as a push constant for each buffer. This is computed as the remainder, the part of the offset that can't be passed via the offsets applied via Vulkan. The access chains and length ops are adjusted based on this offset.

v1 added push constants for both offsets and lengths via custom buffer / slice types. In v2, plain slices are supported, and offsets are added via manipulation of the resulting assembly at build time.

Because the offset can only be as large as 256, 4 could be packed into a single u32. Additionally, items could be computed directly from the lengths of arguments, and doesn't need to be passed as a push constant.

@charles-r-earp charles-r-earp merged commit eb08013 into krnl2 Nov 11, 2025
4 checks passed
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.

1 participant