summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGangzheng Tong <tonggangzheng@gmail.com>2025-09-10 00:14:05 -0700
committerGitHub <noreply@github.com>2025-09-10 07:14:05 +0000
commit2020a102e9e0ea2f39a0f2b2a75085c3607ce734 (patch)
tree2fb3782981a60c1151df06ad178c863d6f9c16a4 /tests
parent43dffcde78227113a0e62b02857eaf4ed6ea6e7e (diff)
Check if debugVar for is debuggable types in the legalization pass (#8326)
## Problem When generic functions with debug variables were specialized with concrete types containing non-debuggable fields (e.g., `StructuredBuffer`), the IR cloning process would create invalid `DebugVar` instructions without checking if the substituted types remained debuggable. ## Solution This fix adds a defensive check in the legalization pass that removes the debugVar created for the non-debuggable types. --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/spirv/debug-var-generic-param.slang62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/spirv/debug-var-generic-param.slang b/tests/spirv/debug-var-generic-param.slang
new file mode 100644
index 000000000..85049eefe
--- /dev/null
+++ b/tests/spirv/debug-var-generic-param.slang
@@ -0,0 +1,62 @@
+//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry main -stage compute -g2 -emit-spirv-directly
+
+// Test for debug variable handling with generic parameters and structs containing resources
+// This test ensures that structs containing StructuredBuffer fields don't get invalid DebugVar instructions
+
+StructuredBuffer<uint4> gData;
+
+interface IGeometryReader
+{
+ float4 read(uint attributeIndex);
+}
+
+struct PositionReader : IGeometryReader
+{
+ float4 read(uint vertexIndex)
+ {
+ return m_geometryBuffer[vertexIndex];
+ }
+
+ __init(StructuredBuffer<uint4> geometryBuffer)
+ {
+ m_geometryBuffer = geometryBuffer;
+ }
+
+ StructuredBuffer<uint4> m_geometryBuffer;
+}
+
+float4 test<Reader: IGeometryReader>(Reader reader)
+{
+ float4 pos = reader.read(0);
+ return pos;
+}
+
+RWStructuredBuffer<float4> result;
+
+[numthreads(1,1,1)]
+void main()
+{
+ let reader = PositionReader(gData);
+ float4 pos = test(reader);
+
+ result[0] = pos;
+}
+
+// Verify that debug info is generated but no invalid DebugVar for struct with StructuredBuffer
+// CHECK: OpExtInst %void {{.*}} DebugExpression
+
+// Ensure we have the expected legitimate debug variables
+// CHECK: pos{{.*}}DebugLocalVariable{{.*}}
+// CHECK: vertexIndex{{.*}}DebugLocalVariable{{.*}}
+
+// After legitimate debug vars, ensure we don't create debug vars for non-debuggable types
+// Specifically check that we don't create debug vars for variables containing StructuredBuffer:
+// - No debug var for 'reader' (PositionReader struct instance)
+// - No debug var for 'm_geometryBuffer' (StructuredBuffer field)
+// The absence of these variables in the output proves the fix is working
+// CHECK-NOT: reader{{.*}}DebugLocalVariable{{.*}}
+// CHECK-NOT: m_geometryBuffer{{.*}}DebugLocalVariable{{.*}}
+// CHECK-NOT: geometryBuffer{{.*}}DebugLocalVariable{{.*}}
+
+// Verify the function ends properly
+// CHECK: OpFunctionEnd \ No newline at end of file