yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Mukund KeshavaAdd debug information for slang inling (#6621)083eecee3

master
4.0 KiB141 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target spirv -O0 -g3
2RWStructuredBuffer<int> outputBuffer;
3
4// Function with a single basic block
5[ForceInline]
6int basicBlockFunc(int value1, int value2)
7{
8    // Simple operation that should be inlined
9    return value1 * 2 + value2;
10}
11
12// Function with multiple basic blocks
13[ForceInline]
14int multipleBlockFunc(int value1, int value2)
15{
16    int result = value1 * 2;
17    
18    // Add a condition to create multiple basic blocks
19    if (value1 > value2)
20    {
21        result += value2 * 3;
22    }
23    else
24    {
25        result -= value2;
26    }
27    
28    return result;
29}
30
31// Test case a: Multiple calls to basic block function
32int testMultipleBasicBlockCalls()
33{
34    int result = basicBlockFunc(10, 5);
35    result += basicBlockFunc(20, 15);
36    result += basicBlockFunc(30, 25);
37    return result;
38}
39
40// Test case b: Multiple calls to multiple block function
41int testMultipleBlockCalls()
42{
43    int result = multipleBlockFunc(10, 5);
44    result += multipleBlockFunc(20, 25);
45    result += multipleBlockFunc(30, 25);
46    return result;
47}
48
49// Test case c: One call to basic block, other instructions, another call to basic block
50int testBasicBlockWithInstructions()
51{
52    int result = basicBlockFunc(10, 5);
53    
54    // Some other instructions
55    result *= 2;
56    result += 10;
57    
58    result += basicBlockFunc(20, 15);
59    return result;
60}
61
62// Test case d: One call to multiple block func, other instructions, another call to multiple block func
63int testMultipleBlockWithInstructions()
64{
65    int result = multipleBlockFunc(10, 5);
66    
67    // Some other instructions
68    result *= 2;
69    result += 10;
70    
71    result += multipleBlockFunc(20, 25);
72    return result;
73}
74
75// Test case e: One call to basic block, other instructions, call to multiple block
76int testBasicToMultipleBlock()
77{
78    int result = basicBlockFunc(10, 5);
79    
80    // Some other instructions
81    result *= 2;
82    result += 10;
83    
84    result += multipleBlockFunc(20, 25);
85    return result;
86}
87
88// Additional test case: Mixed calls with condition
89int testMixedCallsWithCondition()
90{
91    int result = basicBlockFunc(15, 7);
92    if (result > 30)
93    {
94        result += multipleBlockFunc(8, 3);
95    }
96    else
97    {
98        result += multipleBlockFunc(12, 9);
99    }
100    return result;
101}
102
103[numthreads(8, 1, 1)]
104void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
105{
106    // Call all test functions directly and store results in different indices
107    
108    // Test case a: Multiple calls to basic block function
109    outputBuffer[0] = testMultipleBasicBlockCalls();
110    
111    // Test case b: Multiple calls to multiple block function
112    outputBuffer[1] = testMultipleBlockCalls();
113    
114    // Test case c: One call to basic block, other instructions, another call to basic block
115    outputBuffer[2] = testBasicBlockWithInstructions();
116    
117    // Test case d: One call to multiple block func, other instructions, another call to multiple block func
118    outputBuffer[3] = testMultipleBlockWithInstructions();
119    
120    // Test case e: One call to basic block, other instructions, call to multiple block
121    outputBuffer[4] = testBasicToMultipleBlock();
122    
123    // Additional test case: Mixed calls with condition
124    outputBuffer[5] = testMixedCallsWithCondition();
125    
126    // Set any remaining indices to 0
127    if (dispatchThreadID.x >= 6)
128    {
129        outputBuffer[dispatchThreadID.x] = 0;
130    }
131}
132
133// CHECK-COUNT-14: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugInlinedAt %uint_{{[0-9]+}} %{{[0-9]+}}
134// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugInlinedAt %uint_{{[0-9]+}} %{{[0-9]+}}
135// CHECK-COUNT-28: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugScope %{{[0-9]+}} %{{[0-9]+}}
136// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugScope %{{[0-9]+}} %{{[0-9]+}}
137
138// TODO: Verified manually that the count in the .actual file is 28. 
139// But the pattern matcher complains to match.
140// _CHECK-COUNT-28: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugNoScope
141// _CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugNoScope