summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-03-23 11:37:29 -0700
committerGitHub <noreply@github.com>2023-03-23 11:37:29 -0700
commit85f005888cadeb4b1d957b57a86cbad6cc9ea313 (patch)
treef227827398e1be0765df9478c6f78b4bb524e1b4 /tests
parent34acec2258ef1586564fe51126b25910b3202541 (diff)
Fix scope fixing for address insts. (#2724)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/addr-scope-fix.slang76
-rw-r--r--tests/bugs/addr-scope-fix.slang.expected.txt5
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/bugs/addr-scope-fix.slang b/tests/bugs/addr-scope-fix.slang
new file mode 100644
index 000000000..8a58b7daf
--- /dev/null
+++ b/tests/bugs/addr-scope-fix.slang
@@ -0,0 +1,76 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+struct HitInfo
+{
+ float val;
+ float getVal() { return val; }
+}
+struct PathInfo
+{
+ HitInfo hit;
+ [mutating]
+ void setVal(float x)
+ {
+ hit.val = x;
+ }
+}
+
+void someOp(HitInfo hitInfo)
+{
+ outputBuffer[0] = hitInfo.val;
+}
+
+void func(int x)
+{
+ PathInfo path = {};
+ int i = 0;
+ if (x < 10)
+ {
+ // The `elementAddr(path, hit)` is first defined in this block.
+ // Note that this block dominates all remaining blocks in this
+ // function, so all future references to path.hit will use
+ // `elementAddr` inst defined here.
+ //
+ // The bug here is that when we emit code, the emit logic will
+ // find that the elementAddr inst is not in a valid region for
+ // future use and will try to create a local var for it. This will
+ // result a pointer typed var being created, and leads to invalid
+ // hlsl/glsl code.
+ //
+ // The fix is to hoist all always-fold insts to earliest point
+ // in the program instead of creating a var for it.
+ //
+ someOp(path.hit);
+ }
+ else
+ {
+ // This return makes the true block dominate the rest of the blocks
+ // from a region that does not "dominate" the rest code regions.
+ return;
+ }
+
+ while (i < 3)
+ {
+ if (i < 2)
+ {
+ path.setVal(1);
+ }
+ else
+ {
+ path.setVal(2);
+ }
+
+ // This is the point where we are using path.hit again.
+ outputBuffer[i] = path.hit.getVal();
+ i++;
+ }
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ func(4);
+} \ No newline at end of file
diff --git a/tests/bugs/addr-scope-fix.slang.expected.txt b/tests/bugs/addr-scope-fix.slang.expected.txt
new file mode 100644
index 000000000..73616c399
--- /dev/null
+++ b/tests/bugs/addr-scope-fix.slang.expected.txt
@@ -0,0 +1,5 @@
+type: float
+1.0
+1.0
+2.0
+