From e1c6fecd90142761aaecbf4e281beb87893fc531 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:11:41 -0400 Subject: Implement `-fvk-use-dx-layout` (#4912) * Implement `-fvk-use-dx-layout` Fixes: #4126 Changes: * Added fvk-use-dx-layout * Modified `HLSLConstantBufferLayoutRulesImpl` for correctness (ex: Array is always 16 byte aligned) * Added kFXCShaderResourceLayoutRulesFamilyImpl and kFXCConstantBufferLayoutRulesFamilyImpl to handle fvk-use-dx-layout * Added `ConstantBufferLayoutRules` to manage constant buffer rules * Added `alignCompositeElementOfNonAggregate`/`alignCompositeElementOfAggregate` to handle forced alignment of composites for ConstantBuffers * `StructuredBuffer` rules are mostly equal to `scalar` layout, not much was needed to be changed to support this behavior. * seperate legacy constant buffer and how Slang does constant-buffer normally * undo an addition * remove accidental test * Address review and fix Address review and remove GLSL support since GLSL requires a seperate legalization (need to linearlize structs like with `legalizeMetalIR` to assign explicit offsets) * comments * remove aggregate and non-aggregate logic We don't need this distinction for the logic --------- Co-authored-by: Yong He --- tests/spirv/cbuffer-not-dx-layout.slang | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/spirv/cbuffer-not-dx-layout.slang (limited to 'tests/spirv/cbuffer-not-dx-layout.slang') diff --git a/tests/spirv/cbuffer-not-dx-layout.slang b/tests/spirv/cbuffer-not-dx-layout.slang new file mode 100644 index 000000000..27063188d --- /dev/null +++ b/tests/spirv/cbuffer-not-dx-layout.slang @@ -0,0 +1,56 @@ +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry computeMain -stage compute + +cbuffer Test +{ +//SPIRV: Offset 0 + uint v0; + +//SPIRV: Offset 16 + float3 v1; + +//SPIRV: Offset 32 + uint3 v2; + +//SPIRV: Offset 48 + uint2 v3; + +//SPIRV: Offset 56 + uint2 v4; + +//SPIRV: Offset 64 + uint v5[4]; + +//SPIRV: Offset 128 + uint3 v6[2]; +}; + +RWStructuredBuffer outputBuffer; + +__generic +bool comp(vector v1, vector v2) +{ + for (uint i = 0; i < N; i++) + if (v1[i] != v2[i]) + return false; + + return true; +} + +[shader("compute")] +[numthreads(16, 16, 1)] +void computeMain() +{ + outputBuffer[0] = (true + && v0 == 1 + && comp(v1, float3( 2, 3, 4)) + && comp(v2, uint3( 5, 6, 7)) + && comp(v3, uint2( 8, 9 )) + && comp(v4, uint2( 10, 11 )) + && v5[0] == 12 + && v5[1] == 13 + && v5[2] == 14 + && v5[3] == 15 + && comp(v6[0], uint3( 16, 17, 18 )) + && comp(v6[1], uint3( 19, 20, 21 )) + ) ? 100 : 0; +} \ No newline at end of file -- cgit v1.2.3