summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-07 23:44:19 -0800
committerGitHub <noreply@github.com>2024-03-07 23:44:19 -0800
commitfaaa532aeda5bb171222134a7128254a34b87a2a (patch)
tree7b421f94aaba96f0efaa665a1ad276a766bb6dd3
parenta810aa31f5f366d69e67be96c169fec7d6041df7 (diff)
[SPIRV] Fix pointer lowering bug. (#3713)
* [SPIRV] Fix pointer lowering bug. * Update falcor CI setting.
-rw-r--r--.github/workflows/falcor-test.yml2
-rw-r--r--source/slang/slang-emit-spirv.cpp23
-rw-r--r--tests/spirv/pointer-bug-2.slang41
3 files changed, 58 insertions, 8 deletions
diff --git a/.github/workflows/falcor-test.yml b/.github/workflows/falcor-test.yml
index df2b1c2d5..1e094f163 100644
--- a/.github/workflows/falcor-test.yml
+++ b/.github/workflows/falcor-test.yml
@@ -12,7 +12,7 @@ concurrency:
cancel-in-progress: true
jobs:
build:
- runs-on: [Windows, self-hosted]
+ runs-on: [Windows, self-hosted, falcor]
timeout-minutes: 100
continue-on-error: true
strategy:
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 098c2cc2b..1b5747621 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -5805,14 +5805,23 @@ SlangResult emitSPIRVFromIR(
}
// Move forward delcared pointers to the end.
- for (auto ptrType : context.m_forwardDeclaredPointers)
+ do
{
- auto spvPtrType = context.m_mapIRInstToSpvInst[ptrType];
- context.ensureInst(ptrType->getValueType());
- auto parent = spvPtrType->parent;
- spvPtrType->removeFromParent();
- parent->addInst(spvPtrType);
- }
+ auto fwdPointers = context.m_forwardDeclaredPointers;
+ context.m_forwardDeclaredPointers.clear();
+
+ for (auto ptrType : fwdPointers)
+ {
+ auto spvPtrType = context.m_mapIRInstToSpvInst[ptrType];
+ // When we emit a pointee type, we may introduce new
+ // forward-declared pointer types, so we need to
+ // keep iterating until we have emitted all of them.
+ context.ensureInst(ptrType->getValueType());
+ auto parent = spvPtrType->parent;
+ spvPtrType->removeFromParent();
+ parent->addInst(spvPtrType);
+ }
+ } while (context.m_forwardDeclaredPointers.getCount() != 0);
context.emitFrontMatter();
diff --git a/tests/spirv/pointer-bug-2.slang b/tests/spirv/pointer-bug-2.slang
new file mode 100644
index 000000000..e7729151b
--- /dev/null
+++ b/tests/spirv/pointer-bug-2.slang
@@ -0,0 +1,41 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -O0
+
+struct Tester0
+{
+ uint i;
+};
+
+struct Tester1
+{
+ Tester0 * tester0;
+};
+
+struct Tester2
+{
+ Tester1* tester1;
+};
+
+struct Tester3
+{
+ uint* i_ptr;
+};
+
+struct Push
+{
+ Tester2 * tester2;
+ Tester3 * tester3;
+};
+
+[[vk::push_constant]] Push push;
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void main(uint3 dtid : SV_DispatchThreadID)
+{
+ Tester3 tester3 = push.tester3[0];
+ if (uint64_t(tester3.i_ptr) != 0)
+ {
+ return;
+ }
+}
+
+// CHECK: OpEntryPoint \ No newline at end of file