Add compile-time validation for GPU buffer alignment
#1426 aperta il 23 ago 2025
Metriche repository
- Star
- (1037 star)
- Metriche merge PR
- (Metriche PR in attesa)
Descrizione
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: https://github.com/doodlum/skyrim-community-shaders/pull/542
- Comment: https://github.com/doodlum/skyrim-community-shaders/pull/542#issuecomment-
/cc @alandtse