summaryrefslogtreecommitdiffstats
path: root/tests/optimization
diff options
context:
space:
mode:
Diffstat (limited to 'tests/optimization')
-rw-r--r--tests/optimization/arrray-storage-lowering.slang42
-rw-r--r--tests/optimization/get-array-element.slang17
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/optimization/arrray-storage-lowering.slang b/tests/optimization/arrray-storage-lowering.slang
new file mode 100644
index 000000000..42bb8f127
--- /dev/null
+++ b/tests/optimization/arrray-storage-lowering.slang
@@ -0,0 +1,42 @@
+// TEST:SIMPLE(filecheck=SPV): -target spirv
+
+// TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type -emit-spirv-directly
+
+struct DoubleNested
+{
+ int4x3 matrix;
+ int getMatVal(int i, int j) { return matrix[i][j]; }
+}
+
+struct Nested
+{
+ bool values[4];
+ DoubleNested doubleNested;
+ int getVal(int id) { return (int)values[0] + doubleNested.getMatVal(0, 1); }
+}
+
+struct Params
+{
+ Nested nested;
+
+ int getVal(int id) { return nested.getVal(id) + nested.getVal(id + 1); }
+}
+
+// TEST_INPUT: set outputBuffer = out ubuffer(data=[0], stride=4)
+RWStructuredBuffer<int4> outputBuffer;
+
+// TEST_INPUT:set gParams = cbuffer(data=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1])
+ConstantBuffer<Params> gParams;
+
+// TEST_INPUT: set gDoubleNested = ubuffer(data=[1 2 3 4 5 6 7 8 9 10 11 12])
+uniform DoubleNested *gDoubleNested;
+
+// CHECK: 9
+
+[numthreads(1,1,1)]
+void computeMain(int id: SV_DispatchThreadID)
+{
+ outputBuffer[0].xyz = gParams.getVal(id) + gDoubleNested.getMatVal(1, 1);
+}
+
+// SPV-NOT: OpCompositeConstruct
diff --git a/tests/optimization/get-array-element.slang b/tests/optimization/get-array-element.slang
new file mode 100644
index 000000000..16a71aee2
--- /dev/null
+++ b/tests/optimization/get-array-element.slang
@@ -0,0 +1,17 @@
+//TEST:SIMPLE(filecheck=CHECK):-target spirv
+
+int test(int arr[32]) {
+ int sum = 0;
+ for (int i =0; i < 32; i++) sum += arr[i];
+ return sum;
+}
+
+uniform int gArr[32];
+uniform int* result;
+
+[numthreads(1,1,1)]
+void computeMain()
+{
+ // CHECK-NOT: OpCompositeConstruct
+ *result = test(gArr);
+} \ No newline at end of file