summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-12-11 14:19:00 -0800
committerGitHub <noreply@github.com>2024-12-11 14:19:00 -0800
commitc17369a507c9b2e3a2db409896dbdc7e250122c1 (patch)
treeff1f60a0b62d541b756b419549c8c4327607c81d
parent0af589bf2ddf383eb8e6014e8e9da3309284ce0f (diff)
Fix the logic to determine whether lower generic pass should run. (#5837)
-rw-r--r--source/slang/slang-emit.cpp9
-rw-r--r--tests/bugs/ptr-existential.slang20
2 files changed, 28 insertions, 1 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 04ad55c1f..f9118bb45 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -429,7 +429,14 @@ void calcRequiredLoweringPassSet(
{
// If any instruction has an interface type, we need to run
// the generics lowering pass.
- auto type = inst->getDataType();
+ auto type = as<IRType>(inst) ? inst : inst->getDataType();
+ for (;;)
+ {
+ if (auto ptrType = as<IRPtrTypeBase>(type))
+ type = ptrType->getValueType();
+ else
+ break;
+ }
if (type && type->getOp() == kIROp_InterfaceType)
{
result.generics = true;
diff --git a/tests/bugs/ptr-existential.slang b/tests/bugs/ptr-existential.slang
new file mode 100644
index 000000000..140e9a009
--- /dev/null
+++ b/tests/bugs/ptr-existential.slang
@@ -0,0 +1,20 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv
+
+//CHECK: OpEntryPoint
+
+interface IBsdf {};
+struct Foo : IBsdf {}
+//TEST_INPUT:type_conformance Foo:IBsdf = 0
+struct Mesh {
+ float4 *vertices;
+ IBsdf *bsdf;
+}
+[[vk::push_constant]] Mesh* mesh;
+RWStructuredBuffer<float4> outputBuffer;
+
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void main(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ outputBuffer[0] = mesh.vertices[0];
+} \ No newline at end of file