From 661d6198bbb9857d3fdc6df477e0742ed0b0765c Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 14 Aug 2023 16:23:19 -0700 Subject: Support per field matrix layout (#3101) * Support per field matrix layout * Fix warnings. * Fix. * Fix tests. * Fix spiv gen. * Fix. * More test fixes. * Fix. * Run only GPU tests on self-hosted servers. * Remove -use-glsl-matrix-layout-modifier. * Fix. --------- Co-authored-by: Yong He --- tests/hlsl/glsl-matrix-layout.slang | 67 ++++++++++++++++++++++++ tests/hlsl/glsl-matrix-layout.slang.expected.txt | 14 +++++ 2 files changed, 81 insertions(+) create mode 100644 tests/hlsl/glsl-matrix-layout.slang create mode 100644 tests/hlsl/glsl-matrix-layout.slang.expected.txt (limited to 'tests/hlsl') diff --git a/tests/hlsl/glsl-matrix-layout.slang b/tests/hlsl/glsl-matrix-layout.slang new file mode 100644 index 000000000..6178cc813 --- /dev/null +++ b/tests/hlsl/glsl-matrix-layout.slang @@ -0,0 +1,67 @@ +// Test that storage type lowering correctly handles matrix layout modifiers. + +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type -xslang -use-glsl-matrix-layout-modifier -xslang -fvk-use-gl-layout + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 ], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +struct MyStruct +{ + // row_major here is flipped by the `-use-glsl-matrix-layout-modifier` compiler option so + // it actually means column_major here. + row_major float3x2 mat; + int otherVal[4]; + +} + +//TEST_INPUT: set gConst = cbuffer(data=[1.0 3.0 5.0 0.0 2.0 4.0 6.0 0.0 100 101 102 103]) +// gConst will be: +// -- -- +// | 1.0 2.0 | +// | 3.0 4.0 | +// | 5.0 6.0 | +// -- -- +ConstantBuffer gConst; + +//TEST_INPUT: set gStructBuffer = ubuffer(data=[1.0 3.0 5.0 0.0 2.0 4.0 6.0 0.0 100 101 102 103 1.0 3.0 5.0 0.0 2.0 4.0 6.0 0.0 100 101 102 103]) +RWStructuredBuffer gStructBuffer; + +//TEST_INPUT: set gRawBuffer = ubuffer(data=[1.0 3.0 5.0 0.0 2.0 4.0 6.0 0.0 100 101 102 103]) +RWByteAddressBuffer gRawBuffer; + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + { + float2 v = float2(2.0, 3.0); + float3 vm = mul(gConst.mat, v); + outputBuffer[0] = vm.x; // 8 + outputBuffer[1] = vm.y; // 18 + outputBuffer[2] = vm.z; // 28 + } + { + float2 v = float2(2.0, 3.0); + float3 vm = mul(gStructBuffer[0][0].mat, v); + outputBuffer[3] = vm.x; // 8 + outputBuffer[4] = vm.y; // 18 + outputBuffer[5] = vm.z; // 28 + } + { + float2 v = float2(2.0, 3.0); + float3 vm = mul(gRawBuffer.Load(0).mat, v); + outputBuffer[6] = vm.x; // 8 + outputBuffer[7] = vm.y; // 18 + outputBuffer[8] = vm.z; // 28 + gRawBuffer.Store(0, gRawBuffer.Load(0)); + vm = mul(gRawBuffer.Load(0).mat, v); + outputBuffer[9] = vm.x; // 8 + outputBuffer[10] = vm.y; // 18 + outputBuffer[11] = vm.z; // 28 + } + + { + int original; + InterlockedAdd(gStructBuffer[0][0].otherVal[0], 1, original); + outputBuffer[12] = gStructBuffer[0][0].otherVal[0]; + } +} diff --git a/tests/hlsl/glsl-matrix-layout.slang.expected.txt b/tests/hlsl/glsl-matrix-layout.slang.expected.txt new file mode 100644 index 000000000..0c2522f4f --- /dev/null +++ b/tests/hlsl/glsl-matrix-layout.slang.expected.txt @@ -0,0 +1,14 @@ +type: float +8 +18 +28 +8 +18 +28 +8 +18 +28 +8 +18 +28 +101.0 \ No newline at end of file -- cgit v1.2.3