summaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-01-15 20:43:01 -0800
committerGitHub <noreply@github.com>2025-01-15 20:43:01 -0800
commit387f2be1e48a805ef0da34510a5ae0ebc0ba9c3e (patch)
tree8769f2b809fae510cfab39ff430063978ec3abb3 /tests/bugs
parent6db69eae7ecfb5111a48723d3f3c4104c7da880a (diff)
Inline global constants that contains opaque handles for legalization. (#6098)
* Inline global constants that contains opaque handles for legalization. * Add diagnostics on opaque type global variables. * Fix. * Fix test.
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/gh-4874-2.slang41
-rw-r--r--tests/bugs/gh-4874.slang50
2 files changed, 91 insertions, 0 deletions
diff --git a/tests/bugs/gh-4874-2.slang b/tests/bugs/gh-4874-2.slang
new file mode 100644
index 000000000..7f6944f7a
--- /dev/null
+++ b/tests/bugs/gh-4874-2.slang
@@ -0,0 +1,41 @@
+// Same to gh-4874.slang, but defining the global resource typed variables
+// without the "const" modifier. This should lead to a compile time error.
+//
+//TEST:SIMPLE(filecheck=CHECK): -target spirv
+RWStructuredBuffer<uint> outputBuffer;
+
+RWStructuredBuffer<uint> inputBuffer;
+
+// CHECK: ([[# @LINE+1]]): error 30076:
+static RWStructuredBuffer<uint> gBuffer = inputBuffer;
+
+struct Stuff
+{
+ __init(RWStructuredBuffer<uint> a1, RWStructuredBuffer<uint> b2)
+ {
+ a = a1;
+ b = b2;
+ }
+
+ RWStructuredBuffer<uint> a;
+ RWStructuredBuffer<uint> b;
+}
+
+// CHECK: ([[# @LINE+1]]): error 30076:
+static Stuff gStuff = Stuff( inputBuffer, inputBuffer );
+
+uint test(uint x)
+{
+ return gBuffer[x]
+ + gStuff.a[x + 1] * 16
+ + gStuff.b[x + 2] * 256;
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ let tid = dispatchThreadID.x;
+ let inVal = tid;
+ let outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/bugs/gh-4874.slang b/tests/bugs/gh-4874.slang
new file mode 100644
index 000000000..403f6fc50
--- /dev/null
+++ b/tests/bugs/gh-4874.slang
@@ -0,0 +1,50 @@
+// type-legalize-global-with-init.slang
+//
+// Confirm that type legalization can handle a global constant
+// with a resource type or a type that recursively contains
+// resources.
+//
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -vk
+//
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<uint> outputBuffer;
+
+//TEST_INPUT:ubuffer(data=[1 2 3 4 5 6 7 8], stride=4):name=inputBuffer
+RWStructuredBuffer<uint> inputBuffer;
+
+static const RWStructuredBuffer<uint> gBuffer = inputBuffer;
+
+struct Stuff
+{
+ __init(RWStructuredBuffer<uint> a1, RWStructuredBuffer<uint> b2)
+ {
+ a = a1;
+ b = b2;
+ }
+
+ RWStructuredBuffer<uint> a;
+ RWStructuredBuffer<uint> b;
+}
+
+static const Stuff gStuff = Stuff( inputBuffer, inputBuffer );
+
+uint test(uint x)
+{
+ return gBuffer[x]
+ + gStuff.a[x + 1] * 16
+ + gStuff.b[x + 2] * 256;
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ let tid = dispatchThreadID.x;
+ let inVal = tid;
+ let outVal = test(inVal);
+ outputBuffer[tid] = outVal;
+ // CHECK: 321
+ // CHECK: 432
+ // CHECK: 543
+ // CHECK: 654
+} \ No newline at end of file