-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Problem
GPU constant buffers (cbuffer structures) in HLSL must be aligned to 16-byte boundaries for optimal performance and correctness. Currently, the project relies on manual padding (e.g., uint b0pad0[2] in ClusterBuildingCS.hlsl) to ensure proper alignment, but this approach is error-prone and lacks compile-time validation.
Current State
The codebase contains various cbuffer structures across shader files that use manual padding:
cbuffer PerFrame : register(b0)
{
float LightsNear;
float LightsFar;
uint b0pad0[2]; // Manual padding for alignment
}Some settings may be combined from multiple features into a single cbuffer so misalignment may break later feature settings.
Goal
Implement a system that provides compile-time validation to ensure all GPU buffers maintain proper 16-byte alignment without relying solely on manual padding techniques.
Requirements
- Detect misaligned buffer structures at compile time
- Work with existing HLSL cbuffer declarations
- Minimize impact on current shader code
- Provide clear error messages when alignment issues are detected
- Consider compatibility with DirectX shader compilation pipeline
- Should be automatic or otherwise easy for developers to add
Context
This issue stems from PR #542 which attempted to add static asserts for buffer alignment. However, the solution should not be limited to static asserts and should explore various approaches to solve the compile-time alignment validation problem.
Related
- Original PR: chore: add static-assert for GPU buffersย #542
- Comment: chore: add static-assert for GPU buffersย #542 (comment)
/cc @alandtse