Skip to content

Commit 1e78247

Browse files
[SPIRV] Generate DebugFunctionDefinition in real function instead of wrapper (microsoft#6758)
This PR moves the DebugFunctionDefinition instruction from the SPIR-V wrapper to the real function. This supplies debugger users with greater accuracy.
1 parent b52f9ba commit 1e78247

File tree

3 files changed

+12
-33
lines changed

3 files changed

+12
-33
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ void SpirvEmitter::doFunctionDecl(const FunctionDecl *decl) {
14621462
isEntry = true;
14631463
funcName = "src." + funcName;
14641464
// Create wrapper for the entry function
1465-
if (!emitEntryFunctionWrapper(decl, func, debugFunction))
1465+
if (!emitEntryFunctionWrapper(decl, func))
14661466
return;
14671467
// Generate DebugEntryPoint if function definition
14681468
if (spirvOptions.debugInfoVulkan && debugFunction) {
@@ -1531,8 +1531,7 @@ void SpirvEmitter::doFunctionDecl(const FunctionDecl *decl) {
15311531

15321532
// Add DebugFunctionDefinition if we are emitting
15331533
// NonSemantic.Shader.DebugInfo.100 debug info
1534-
// and we haven't already added it to the wrapper.
1535-
if (!isEntry && spirvOptions.debugInfoVulkan && debugFunction)
1534+
if (spirvOptions.debugInfoVulkan && debugFunction)
15361535
spvBuilder.createDebugFunctionDef(debugFunction, func);
15371536

15381537
// Process all statments in the body.
@@ -13017,19 +13016,11 @@ bool SpirvEmitter::processTessellationShaderAttributes(
1301713016
}
1301813017

1301913018
bool SpirvEmitter::emitEntryFunctionWrapperForRayTracing(
13020-
const FunctionDecl *decl, SpirvFunction *entryFuncInstr,
13021-
SpirvDebugFunction *debugFunction) {
13019+
const FunctionDecl *decl, SpirvFunction *entryFuncInstr) {
1302213020
// The entry basic block.
1302313021
auto *entryLabel = spvBuilder.createBasicBlock();
1302413022
spvBuilder.setInsertPoint(entryLabel);
1302513023

13026-
// Add DebugFunctionDefinition if we are emitting
13027-
// NonSemantic.Shader.DebugInfo.100 debug info.
13028-
// We will emit it in the wrapper rather than the
13029-
// user function.
13030-
if (spirvOptions.debugInfoVulkan && debugFunction)
13031-
spvBuilder.createDebugFunctionDef(debugFunction, entryFunction);
13032-
1303313024
// Initialize all global variables at the beginning of the wrapper
1303413025
for (const VarDecl *varDecl : toInitGloalVars) {
1303513026
const auto varInfo =
@@ -13293,8 +13284,7 @@ bool SpirvEmitter::processMeshOrAmplificationShaderAttributes(
1329313284
}
1329413285

1329513286
bool SpirvEmitter::emitEntryFunctionWrapper(const FunctionDecl *decl,
13296-
SpirvFunction *entryFuncInstr,
13297-
SpirvDebugFunction *debugFunction) {
13287+
SpirvFunction *entryFuncInstr) {
1329813288
// HS specific attributes
1329913289
uint32_t numOutputControlPoints = 0;
1330013290
SpirvInstruction *outputControlPointIdVal =
@@ -13329,8 +13319,7 @@ bool SpirvEmitter::emitEntryFunctionWrapper(const FunctionDecl *decl,
1332913319
entryInfo->entryFunction = entryFunction;
1333013320

1333113321
if (spvContext.isRay()) {
13332-
return emitEntryFunctionWrapperForRayTracing(decl, entryFuncInstr,
13333-
debugFunction);
13322+
return emitEntryFunctionWrapperForRayTracing(decl, entryFuncInstr);
1333413323
}
1333513324
// Handle attributes specific to each shader stage
1333613325
if (spvContext.isPS()) {
@@ -13411,13 +13400,6 @@ bool SpirvEmitter::emitEntryFunctionWrapper(const FunctionDecl *decl,
1341113400
// after the basic block is created and insert point is set.
1341213401
processInlineSpirvAttributes(decl);
1341313402

13414-
// Add DebugFunctionDefinition if we are emitting
13415-
// NonSemantic.Shader.DebugInfo.100 debug info.
13416-
// We will emit it in the wrapper rather than the
13417-
// user function.
13418-
if (spirvOptions.debugInfoVulkan && debugFunction)
13419-
spvBuilder.createDebugFunctionDef(debugFunction, entryFunction);
13420-
1342113403
// Initialize all global variables at the beginning of the wrapper
1342213404
for (const VarDecl *varDecl : toInitGloalVars) {
1342313405
// SPIR-V does not have string variables

tools/clang/lib/SPIRV/SpirvEmitter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,7 @@ class SpirvEmitter : public ASTConsumer {
848848
/// The wrapper function is also responsible for initializing global static
849849
/// variables for some cases.
850850
bool emitEntryFunctionWrapper(const FunctionDecl *entryFunction,
851-
SpirvFunction *entryFuncId,
852-
SpirvDebugFunction *debugFunction);
851+
SpirvFunction *entryFuncId);
853852

854853
/// \brief Emits a wrapper function for the entry functions for raytracing
855854
/// stages and returns true on success.
@@ -859,8 +858,7 @@ class SpirvEmitter : public ASTConsumer {
859858
/// The wrapper function is also responsible for initializing global static
860859
/// variables for some cases.
861860
bool emitEntryFunctionWrapperForRayTracing(const FunctionDecl *entryFunction,
862-
SpirvFunction *entryFuncId,
863-
SpirvDebugFunction *debugFunction);
861+
SpirvFunction *entryFuncId);
864862

865863
/// \brief Performs the following operations for the Hull shader:
866864
/// * Creates an output variable which is an Array containing results for all

tools/clang/test/CodeGenSPIRV/shader.debug.function.hlsl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717

1818
// Check DebugFunction instructions
1919
//
20-
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugFunction [[fooName]] [[fooFnType]] [[source]] %uint_35 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_36
20+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugFunction [[fooName]] [[fooFnType]] [[source]] %uint_34 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_35
2121

2222
// CHECK: [[float4:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeVector [[float]] %uint_4
2323
// CHECK: [[mainFnType:%[0-9]+]] = OpExtInst %void [[set]] DebugTypeFunction %uint_3 [[float4]] [[float4]]
24-
// CHECK: [[mainDbgFn:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] [[mainFnType]] [[source]] %uint_40 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_41
24+
// CHECK: [[mainDbgFn:%[0-9]+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] [[mainFnType]] [[source]] %uint_39 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_40
2525
// CHECK: [[mainDbgEp:%[0-9]+]] = OpExtInst %void [[set]] DebugEntryPoint [[mainDbgFn]] [[compilationUnit]] {{%[0-9]+}} [[clOpts]]
2626

27-
// Check DebugFunctionDefintion is in main
27+
// Check DebugFunctionDefintion is in src_main
2828
//
29-
// CHECK: %main = OpFunction %void None {{%[0-9]+}}
30-
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugFunctionDefinition [[mainDbgFn]] %main
31-
// CHECK: OpFunctionEnd
29+
// CHECK: %src_main = OpFunction %v4float None {{%[0-9]+}}
30+
// CHECK: {{%[0-9]+}} = OpExtInst %void [[set]] DebugFunctionDefinition [[mainDbgFn]] %src_main
3231
// CHECK: OpFunctionEnd
3332
// CHECK: OpFunctionEnd
3433

0 commit comments

Comments
 (0)