summaryrefslogtreecommitdiffstats
path: root/tests/spirv/structured-buffer-dx-layout.slang
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-08-26 15:11:41 -0400
committerGitHub <noreply@github.com>2024-08-26 12:11:41 -0700
commite1c6fecd90142761aaecbf4e281beb87893fc531 (patch)
tree30cf06cf6a7ea4a55b2d3e4ecd5d4f13f1f31e60 /tests/spirv/structured-buffer-dx-layout.slang
parent76999788902a8c50e8e5d0e867763e5ea2f10042 (diff)
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 <yonghe@outlook.com>
Diffstat (limited to 'tests/spirv/structured-buffer-dx-layout.slang')
-rw-r--r--tests/spirv/structured-buffer-dx-layout.slang57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/spirv/structured-buffer-dx-layout.slang b/tests/spirv/structured-buffer-dx-layout.slang
new file mode 100644
index 000000000..678ad758d
--- /dev/null
+++ b/tests/spirv/structured-buffer-dx-layout.slang
@@ -0,0 +1,57 @@
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -xslang -fvk-use-dx-layout -emit-spirv-directly
+//TEST:SIMPLE(filecheck=SPIRV): -target spirv -entry computeMain -stage compute -fvk-use-dx-layout
+
+struct Test_t
+{
+//SPIRV: Offset 0
+ uint v0;
+//SPIRV: Offset 4
+ float3 v1;
+//SPIRV: Offset 16
+ uint3 v2;
+//SPIRV: Offset 28
+ uint2 v3;
+//SPIRV: Offset 36
+ uint2 v4;
+//SPIRV: Offset 44
+ uint v5[4];
+//SPIRV: Offset 60
+ uint3 v6[2];
+};
+
+//TEST_INPUT:ubuffer(data=[1 2.0 3.0 4.0 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21], stride=4):out,name testBuffer
+RWStructuredBuffer<Test_t> testBuffer;
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+__generic<T : IArithmetic, let N : int>
+bool comp(vector<T,N> v1, vector<T,N> 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()
+{
+ // CHECK: 64
+ Test_t test = testBuffer[0];
+ outputBuffer[0] = (true
+ && test.v0 == 1
+ && comp(test.v1, float3( 2, 3, 4))
+ && comp(test.v2, uint3( 5, 6, 7))
+ && comp(test.v3, uint2( 8, 9 ))
+ && comp(test.v4, uint2( 10, 11 ))
+ && test.v5[0] == 12
+ && test.v5[1] == 13
+ && test.v5[2] == 14
+ && test.v5[3] == 15
+ && comp(test.v6[0], uint3( 16, 17, 18 ))
+ && comp(test.v6[1], uint3( 19, 20, 21 ))
+ ) ? 100 : 0;
+} \ No newline at end of file