Skip to content

Commit 6f51315

Browse files
[SPIRV] Emit OpLine for internally generated SPIR-V wrapper function (microsoft#6074)
This PR improves the experience for profilers and debuggers that consume SPIR-V produced by dxc. When debugging information is output, additionally note the beginning of the internally generated wrapper function. This will assign all parameter setup to the entry point declaration, providing context to the user of a shader profiler or debugger.
1 parent fc0ecb8 commit 6f51315

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

tools/clang/lib/SPIRV/EmitVisitor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ void EmitVisitor::emitDebugLine(spv::Op op, const SourceLocation &loc,
262262
// Technically entry function wrappers do not exist in HLSL. They are just
263263
// created by DXC. We do not want to emit line information for their
264264
// instructions. To prevent spirv-opt from removing all debug info, we emit
265-
// at least a single OpLine to specify the end of the shader.
266-
if (inEntryFunctionWrapper && op != spv::Op::OpReturn)
265+
// OpLines to specify the beginning and end of the function.
266+
if (inEntryFunctionWrapper &&
267+
(op != spv::Op::OpReturn && op != spv::Op::OpFunction))
267268
return;
268269

269270
// Based on SPIR-V spec, OpSelectionMerge must immediately precede either an

tools/clang/test/CodeGenSPIRV/spirv.debug.opline.entry.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ float4 main(float2 a : TEXCOORD0,
77
float3 b : NORMAL,
88
float4 c : COLOR) : SV_Target {
99
// CHECK: OpLine [[file]] 6 1
10+
// CHECK-NEXT: %main = OpFunction %void None
11+
// CHECK: OpLine [[file]] 6 1
1012
// CHECK-NEXT: %src_main = OpFunction %v4float None
1113
// CHECK-NEXT: OpLine [[file]] 6 20
1214
// CHECK-NEXT: %a = OpFunctionParameter %_ptr_Function_v2float

tools/clang/test/CodeGenSPIRV/spirv.debug.opline.function.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
void foo(in float4 a, out float3 b);
77

88
// CHECK: OpLine [[file]] 28 1
9-
// CHECK-NEXT: %src_main = OpFunction %void None
9+
// CHECK-NEXT: %main = OpFunction %void None
1010

1111
void bar(int a, in float b, inout bool2 c, const float3 d, out uint4 e) {
1212
}

tools/clang/test/CodeGenSPIRV/spirv.debug.opline.include.hlsl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// CHECK-SAME: spirv.debug.opline.include-file-3.hlsli
1414
// CHECK-NEXT: OpSource HLSL 600 [[file3]] "int b;
1515

16-
// CHECK: OpLine [[main]] 65 1
16+
// CHECK: OpLine [[main]] 67 1
17+
// CHECK-NEXT: %main = OpFunction %void None
18+
// CHECK: OpLine [[main]] 67 1
1719
// CHECK-NEXT: %src_main = OpFunction %void None
1820

1921
#include "spirv.debug.opline.include-file-1.hlsli"
@@ -63,7 +65,7 @@ int callFunction3() {
6365
}
6466

6567
void main() {
66-
// CHECK: OpLine [[main]] 68 3
68+
// CHECK: OpLine [[main]] 70 3
6769
// CHECK-NEXT: OpFunctionCall %int %callFunction1
6870
callFunction1();
6971

@@ -81,11 +83,11 @@ void main() {
8183
// line
8284
// in
8385
// OpSource.
84-
// CHECK: OpLine [[main]] 86 3
86+
// CHECK: OpLine [[main]] 88 3
8587
// CHECK-NEXT: OpFunctionCall %int %callFunction2
8688
callFunction2();
8789

88-
// CHECK: OpLine [[main]] 90 3
90+
// CHECK: OpLine [[main]] 92 3
8991
// CHECK-NEXT: OpFunctionCall %int %callFunction3
9092
callFunction3();
9193
}

0 commit comments

Comments
 (0)