summaryrefslogtreecommitdiffstats
path: root/tests/spirv/debug-var-generic-param.slang
blob: 85049eefe609742daa49e1f7b61c28d626c7a1fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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