diff options
| author | pdeayton-nv <205388607+pdeayton-nv@users.noreply.github.com> | 2025-07-15 17:44:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-16 00:44:33 +0000 |
| commit | 299eb0c889322a960d1907b6722ee1caf88475a4 (patch) | |
| tree | ded57d1c9fe1e8ec909722877b93cb0037bf190d /tests | |
| parent | a8519e68b6df636932ca5d89a332b2a689259b0f (diff) | |
Fix GLSL memory layout qualifiers not applied to uniform buffers or cbuffers (#7740)
* Fix GLSL memory layout qualifiers not applied to uniform buffers or cbuffers
The `layout(scalar)` qualifier was being ignored for GLSL `uniform` blocks and
HLSL `cbuffer` declarations, causing them to use std140 layout instead of the
requested scalar layout.
**Root Cause**:
The parsing logic in `slang-parser.cpp` handled layout qualifiers inconsistently:
- GLSL `buffer` blocks correctly used `getLayoutArg()` to map layout modifiers
- GLSL `uniform` blocks and HLSL `cbuffer` skipped layout arguments entirely
**Solution**:
- Enhanced `parseHLSLCBufferDecl()` to check for GLSL layout qualifiers
- Added same `getLayoutArg()` logic used by buffer blocks
- Modified uniform block parsing to pass layout arguments through
**Testing**:
- Added comprehensive test case: `tests/glsl/layout-scalar-qualifier.slang`
- Verified fix works for both `uniform` blocks and `cbuffer` declarations
- Confirmed no regressions in existing test suite
**Before**: `layout(scalar) uniform {...}` → std140 layout (32 bytes, offset 0,16)
**After**: `layout(scalar) uniform {...}` → scalar layout (16 bytes, offset 0,4)
Fixes #7735
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-authored-by: pdeayton-nv <pdeayton-nv@users.noreply.github.com>
* Apply code formatting to slang-parser.cpp
Fixed line wrapping, trailing whitespace, and parameter formatting
according to repository style guidelines.
Co-authored-by: Harsh Aggarwal (NVIDIA) <szihs@users.noreply.github.com>
* format code (#7742)
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: pdeayton-nv <pdeayton-nv@users.noreply.github.com>
Co-authored-by: Harsh Aggarwal (NVIDIA) <szihs@users.noreply.github.com>
Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/glsl/layout-scalar-qualifier.slang | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/glsl/layout-scalar-qualifier.slang b/tests/glsl/layout-scalar-qualifier.slang new file mode 100644 index 000000000..ac7b34d8b --- /dev/null +++ b/tests/glsl/layout-scalar-qualifier.slang @@ -0,0 +1,39 @@ +//TEST:SIMPLE(filecheck=CHECK): -allow-glsl -target spirv-asm + +RWStructuredBuffer<uint> result; + +// Test GLSL uniform block with scalar layout qualifier +// CHECK: SLANG_ParameterGroup_Data_uniform_natural +// CHECK: OpMemberDecorate %SLANG_ParameterGroup_Data_uniform_natural 0 Offset 0 +// CHECK: OpMemberDecorate %SLANG_ParameterGroup_Data_uniform_natural 1 Offset 4 +layout(scalar) uniform Data_uniform { + uint a; + uint3 b; +}; + +// Test HLSL cbuffer with scalar layout qualifier +// CHECK: SLANG_ParameterGroup_Data_cbuffer_natural +// CHECK: OpMemberDecorate %SLANG_ParameterGroup_Data_cbuffer_natural 0 Offset 0 +// CHECK: OpMemberDecorate %SLANG_ParameterGroup_Data_cbuffer_natural 1 Offset 4 +layout(scalar) cbuffer Data_cbuffer { + uint c; + uint3 d; +}; + +// Reference: ScalarDataLayout should work correctly +struct Data { + uint e; + uint3 f; +}; +ConstantBuffer<Data, ScalarDataLayout> Data_ConstantBufferScalarDataLayout; + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain(uint3 threadId : SV_DispatchThreadID) +{ + uint index = threadId.x; + result[index] = + a + b.x + + c + d.y + + Data_ConstantBufferScalarDataLayout.e + Data_ConstantBufferScalarDataLayout.f.z; +}
\ No newline at end of file |
