summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-07-19 02:04:26 -0400
committerGitHub <noreply@github.com>2024-07-18 23:04:26 -0700
commit59dd133f1c52fb0a7a388f4a8f42234f4556a28a (patch)
tree02556f1660713ebc1272dec9e0e9766ee0999286 /tests
parent6e7c726658c775e97578e7a9dd99d23b819870bd (diff)
Allow CPP/CUDA/Metal to lower/legalize buffer-elements to support column_major/row_major. (#4653)
* Allow CPP/CUDA/Metal to legalize their buffer-elements. Fixes: #4537 Changes: 1. Matrix inputs require legalization (pack/unpack) to ensure consistent row_major/column_major throughout entire shader, the following enabled legalization pass fixes this. 2. Added missing CUDA intrinsic so CUDA can run more tests. 3. Added a memory packing test since this still fails for cpp/cuda/metal (due to having no memory packing enforcement). * change memory packing tests to run for targets without packing --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/column-major.slang60
-rw-r--r--tests/compute/column-major.slang.expected.txt5
-rw-r--r--tests/compute/constant-buffer-memory-packing.slang118
3 files changed, 161 insertions, 22 deletions
diff --git a/tests/compute/column-major.slang b/tests/compute/column-major.slang
index 19d863260..1cd08434b 100644
--- a/tests/compute/column-major.slang
+++ b/tests/compute/column-major.slang
@@ -1,33 +1,59 @@
// column-major.slang
-// Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here.
-
-//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -shaderobj
-//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj -Xslang -matrix-layout-column-major
-//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj -Xslang -matrix-layout-column-major
-//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj -Xslang -matrix-layout-column-major
-//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
-//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -mtl -shaderobj -Xslang -matrix-layout-column-major
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -compile-arg -O3 -shaderobj -Xslang -matrix-layout-column-major
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj -Xslang -matrix-layout-column-major
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -shaderobj -Xslang -matrix-layout-column-major
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj -Xslang -matrix-layout-column-major
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -emit-spirv-via-glsl -Xslang -matrix-layout-column-major
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -shaderobj -Xslang -matrix-layout-column-major
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-mtl -compute -shaderobj -Xslang -matrix-layout-column-major
// This data is in column major layout order....
//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 10.0 0.0 1.0 0.0 20.0 0.0 0.0 1.0 30.0 0.0 0.0 0.0 1.0]):name matrixBuffer
ConstantBuffer<float4x4> matrixBuffer;
-//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output
-RWStructuredBuffer<float> output;
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name output
+RWStructuredBuffer<uint> output;
+
+bool floatCheck(float data, float valueToCheckFor)
+{
+ return data < (valueToCheckFor + 0.001) && data > valueToCheckFor - 0.001;
+}
[numthreads(1, 1, 1)]
void computeMain(uint3 tid : SV_DispatchThreadID)
{
float4 v = float4(1, 2, 3, 1);
- float4x4 M = matrixBuffer;
+ float4x4 M1 = matrixBuffer;
- float4 r = mul(v, M);
-
- output[0] = r.x;
- output[1] = r.y;
- output[2] = r.z;
- output[3] = r.w;
+ float4 r = mul(v, M1);
+
+ float4x4 M2 = mul(M1, M1);
+
+ float4x4 M3 = float4x4(
+ 1.0, 0.0, 0.0, 10.0,
+ 0.0, 1.0, 0.0, 20.0,
+ 0.0, 0.0, 1.0, 30.0,
+ 0.0, 0.0, 0.0, 1.0
+ );
+
+ output[0] = uint(true
+ && floatCheck(r.x, 11)
+ && floatCheck(r.y, 22)
+ && floatCheck(r.z, 33)
+ && floatCheck(r.w, 1)
+
+ && floatCheck(M1[3][0], 10)
+
+ && floatCheck(M2[3][0], 20)
+ && floatCheck(M2._41, 20)
+ && floatCheck(M2._41_32[0], 20)
+ && floatCheck(M2._33_42[0], 1)
+ && floatCheck(M2._42_33[0], 40)
+
+ && floatCheck(M3[0][3], 10)
+ );
+ //BUF: 1
}
diff --git a/tests/compute/column-major.slang.expected.txt b/tests/compute/column-major.slang.expected.txt
deleted file mode 100644
index 1e24f3253..000000000
--- a/tests/compute/column-major.slang.expected.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-type: float
-11.000000
-22.000000
-33.000000
-1.000000
diff --git a/tests/compute/constant-buffer-memory-packing.slang b/tests/compute/constant-buffer-memory-packing.slang
new file mode 100644
index 000000000..5246c4d33
--- /dev/null
+++ b/tests/compute/constant-buffer-memory-packing.slang
@@ -0,0 +1,118 @@
+// column-major-with-row-major-operations.slang
+
+// Metal/CPP/CUDA do not deal with packing currently, different results will occur.
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -xslang -DTARGET_WITHOUT_PACKING
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -xslang -DTARGET_WITHOUT_PACKING
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-mtl -compute -xslang -DTARGET_WITHOUT_PACKING
+
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -emit-spirv-via-glsl
+
+// CPP/Metal/CUDA due to not having memory packing will recieve the following ROW matrix:
+// {1,2,3}
+// {0,4,5}
+// {6,0,7}
+
+// GLSL/SPIRV/HLSL due to having memory packing will recieve the following ROW/COL matrix:
+// {1,2,3}
+// {0,4,5}
+// {6,0,7}
+
+//TEST_INPUT:cbuffer(data=[1.0 2.0 3.0 0.0 4.0 5.0 6.0 0.0 7.0 8.0 9.0 0]):name matrixTestCBuf1
+ConstantBuffer<row_major float3x3> matrixTestCBuf1;
+
+// CPP/Metal/CUDA due to not having memory packing will recieve the following COL matrix post-transpose:
+// {1,0,8}
+// {4,2,0}
+// {7,5,3}
+
+//TEST_INPUT:cbuffer(data=[1.0 4.0 7.0 0.0 2.0 5.0 8.0 0.0 3.0 6.0 9.0 0.0]):name matrixTestCBuf2
+ConstantBuffer<column_major float3x3> matrixTestCBuf2;
+
+//TEST_INPUT:cbuffer(data=[1.0 2.0 3.0 0.0 4.0 5.0 6.0 0.0]):name NeedsPadding
+cbuffer NeedsPadding
+{
+ float3 data1;
+ float3 data2;
+};
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name output
+RWStructuredBuffer<uint> output;
+
+bool floatCheck(float data, float valueToCheckFor)
+{
+ return data < (valueToCheckFor + 0.001) && data > valueToCheckFor - 0.001;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 tid : SV_DispatchThreadID)
+{
+ float3x3 matrixTest1;
+ matrixTest1 = matrixTestCBuf1;
+
+ float3x3 matrixTest2;
+ matrixTest2 = matrixTestCBuf2;
+
+ output[0] = uint(true
+#ifndef TARGET_WITHOUT_PACKING
+ && floatCheck(matrixTest1[0][0], 1)
+ && floatCheck(matrixTest1[0][1], 2)
+ && floatCheck(matrixTest1[0][2], 3)
+ && floatCheck(matrixTest1[1][0], 4)
+ && floatCheck(matrixTest1[1][1], 5)
+ && floatCheck(matrixTest1[1][2], 6)
+ && floatCheck(matrixTest1[2][0], 7)
+ && floatCheck(matrixTest1[2][1], 8)
+ && floatCheck(matrixTest1[2][2], 9)
+
+ && floatCheck(matrixTest2[0][0], 1)
+ && floatCheck(matrixTest2[0][1], 2)
+ && floatCheck(matrixTest2[0][2], 3)
+ && floatCheck(matrixTest2[1][0], 4)
+ && floatCheck(matrixTest2[1][1], 5)
+ && floatCheck(matrixTest2[1][2], 6)
+ && floatCheck(matrixTest2[2][0], 7)
+ && floatCheck(matrixTest2[2][1], 8)
+ && floatCheck(matrixTest2[2][2], 9)
+
+ && floatCheck(data1[0], 1)
+ && floatCheck(data1[1], 2)
+ && floatCheck(data1[2], 3)
+ && floatCheck(data2[0], 4)
+ && floatCheck(data2[1], 5)
+ && floatCheck(data2[2], 6)
+#else
+ && floatCheck(matrixTest1[0][0], 1)
+ && floatCheck(matrixTest1[0][1], 2)
+ && floatCheck(matrixTest1[0][2], 3)
+ && floatCheck(matrixTest1[1][0], 0)
+ && floatCheck(matrixTest1[1][1], 4)
+ && floatCheck(matrixTest1[1][2], 5)
+ && floatCheck(matrixTest1[2][0], 6)
+ && floatCheck(matrixTest1[2][1], 0)
+ && floatCheck(matrixTest1[2][2], 7)
+
+ && floatCheck(matrixTest2[0][0], 1)
+ && floatCheck(matrixTest2[0][1], 0)
+ && floatCheck(matrixTest2[0][2], 8)
+ && floatCheck(matrixTest2[1][0], 4)
+ && floatCheck(matrixTest2[1][1], 2)
+ && floatCheck(matrixTest2[1][2], 0)
+ && floatCheck(matrixTest2[2][0], 7)
+ && floatCheck(matrixTest2[2][1], 5)
+ && floatCheck(matrixTest2[2][2], 3)
+
+ && floatCheck(data1[0], 1)
+ && floatCheck(data1[1], 2)
+ && floatCheck(data1[2], 3)
+ && floatCheck(data2[0], 0)
+ && floatCheck(data2[1], 4)
+ && floatCheck(data2[2], 5)
+#endif
+ );
+ output[1] = (uint)matrixTest2[0][0];
+ output[2] = (uint)matrixTest2[0][1];
+ output[3] = (uint)matrixTest2[0][2];
+ //BUF: 1
+}