summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-21 12:22:31 -0800
committerGitHub <noreply@github.com>2024-02-21 12:22:31 -0800
commitb3b6c44cb8b8ebc413d41f9ca3833d8242f3c805 (patch)
treee73edb286c8179f7fc3677b75bfa2468eb811e60 /tests
parent70ea0b048970b9d2e00451636c88313093de2337 (diff)
Fix SPIRV lowering issue. (#3608)
* Fix SPIRV pointer lowering issue. Fixes #3605. * Add another pointer test. Fixes #3601. * Fixes #3600. * Fix #3595.
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/gh-3601.slang56
-rw-r--r--tests/spirv/namespace-texture-array.slang20
-rw-r--r--tests/spirv/pointer-bug.slang18
3 files changed, 94 insertions, 0 deletions
diff --git a/tests/bugs/gh-3601.slang b/tests/bugs/gh-3601.slang
new file mode 100644
index 000000000..d12b480ac
--- /dev/null
+++ b/tests/bugs/gh-3601.slang
@@ -0,0 +1,56 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly
+struct TestStruct
+{
+ uint index;
+};
+
+[[vk::binding(2, 0)]] StructuredBuffer<uint64_t> test;
+
+struct PP
+{
+ int data;
+ int data2;
+}
+struct Data
+{
+ int data;
+ PP* pNext;
+};
+
+void funcThatTakesPointer(PP* p)
+{
+ p.data = 2;
+}
+int* funcThatReturnsPointer(PP* p)
+{
+ return &p.data;
+}
+
+// CHECK: OpEntryPoint
+
+[[vk::binding(0, 0)]] StructuredBuffer<Data> buffer;
+[[vk::binding(1, 0)]] RWStructuredBuffer<int> output;
+[shader("compute")]
+[numthreads(8, 8, 1)]
+void main(int id : SV_DispatchThreadID)
+{
+ TestStruct * ptr = (TestStruct *)(test[0]);
+ output[0] = buffer[ptr.index].pNext.data;
+ let pData = &(buffer[0].pNext.data);
+ // CHECK: OpPtrAccessChain
+ int* pData1 = pData + 1;
+ *pData1 = 3;
+ *(int2*)pData = int2(1, 2);
+ pData1[-1] = 2;
+ buffer[0].pNext[1] = {5};
+ // CHECK: OpConvertPtrToU
+ // CHECK: OpINotEqual
+ if (pData1)
+ {
+ *(funcThatReturnsPointer(buffer[0].pNext)) = 4;
+ }
+ if (pData1 > pData)
+ {
+ funcThatTakesPointer(buffer[0].pNext);
+ }
+} \ No newline at end of file
diff --git a/tests/spirv/namespace-texture-array.slang b/tests/spirv/namespace-texture-array.slang
new file mode 100644
index 000000000..b9dff510f
--- /dev/null
+++ b/tests/spirv/namespace-texture-array.slang
@@ -0,0 +1,20 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly
+struct ComputePush
+{
+ uint image_id;
+};
+[[vk::push_constant]] ComputePush p;
+
+namespace test_namespace
+{
+ [[vk::binding(0, 0)]] RWTexture2D<float4> textureTable[];
+}
+
+// CHECK: OpEntryPoint
+
+[shader("compute")]
+[numthreads(8, 8, 1)]
+void main(uint3 pixel_i : SV_DispatchThreadID)
+{
+ test_namespace.textureTable[p.image_id][pixel_i.xy] = float4(0,1,0,0);
+} \ No newline at end of file
diff --git a/tests/spirv/pointer-bug.slang b/tests/spirv/pointer-bug.slang
new file mode 100644
index 000000000..1668cec13
--- /dev/null
+++ b/tests/spirv/pointer-bug.slang
@@ -0,0 +1,18 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly
+struct Foo {
+ float4 *positions;
+};
+
+struct Params {
+ Foo *foo;
+};
+
+// CHECK: %_ptr_PhysicalStorageBuffer_Foo = OpTypePointer PhysicalStorageBuffer %Foo
+
+[[vk::push_constant]] Params params;
+
+[shader("compute")]
+[numthreads(1,1,1)]
+void main() {
+ params.foo.positions[10] += float4(1, 1, 1, 1);
+} \ No newline at end of file