Skip to content

Commit

Permalink
Add correct line number to OpDebugFunction and OpDebugScope for funct…
Browse files Browse the repository at this point in the history
…ion:

1. Pull OpDebugFunction, OpDebugScope and OpDebugVariable for params out
   of makeFunctionEntry.
2. Put above in a separate function called setupDebugFunctionEntry,
   which also accept line number and set it correctly in builder.
3. Call setupDebugFunctionEntry in makeFunction. Also special case
   handle entry function since it's created ealier elsewhere.
  • Loading branch information
chaocNV committed Oct 12, 2023
1 parent 277d09e commit 95cdcf5
Show file tree
Hide file tree
Showing 18 changed files with 8,921 additions and 8,862 deletions.
14 changes: 12 additions & 2 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5394,9 +5394,17 @@ void TGlslangToSpvTraverser::makeFunctions(const glslang::TIntermSequence& glslF

for (int f = 0; f < (int)glslFunctions.size(); ++f) {
glslang::TIntermAggregate* glslFunction = glslFunctions[f]->getAsAggregate();
if (! glslFunction || glslFunction->getOp() != glslang::EOpFunction || isShaderEntryPoint(glslFunction))
if (! glslFunction || glslFunction->getOp() != glslang::EOpFunction)
continue;

if (isShaderEntryPoint(glslFunction)) {
if (glslangIntermediate->getSource() != glslang::EShSourceHlsl) {
builder.setupDebugFunctionEntry(shaderEntry, glslangIntermediate->getEntryPointMangledName().c_str(),
glslFunction->getLoc().line,
std::vector<spv::Id>(), // main function has no param
std::vector<char const*>());
}
continue;
}
// We're on a user function. Set up the basic interface for the function now,
// so that it's available to call. Translating the body will happen later.
//
Expand Down Expand Up @@ -5446,6 +5454,8 @@ void TGlslangToSpvTraverser::makeFunctions(const glslang::TIntermSequence& glslF
TranslatePrecisionDecoration(glslFunction->getType()), convertGlslangToSpvType(glslFunction->getType()),
glslFunction->getName().c_str(), convertGlslangLinkageToSpv(glslFunction->getLinkType()), paramTypes,
paramNames, paramDecorations, &functionBlock);
builder.setupDebugFunctionEntry(function, glslFunction->getName().c_str(), glslFunction->getLoc().line,
paramTypes, paramNames);
if (implicitThis)
function->setImplicitThis();

Expand Down
65 changes: 41 additions & 24 deletions SPIRV/SpvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,12 +2098,8 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const
}
}

// Make the debug function instruction
// reset last debug scope
if (emitNonSemanticShaderDebugInfo) {
Id nameId = getStringId(unmangleFunctionName(name));
Id debugFuncId = makeDebugFunction(function, nameId, typeId);
debugId[funcId] = debugFuncId;
currentDebugScopeId.push(debugFuncId);
lastDebugScopeId = NoResult;
}

Expand All @@ -2113,41 +2109,62 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const
function->addBlock(*entry);
setBuildPoint(*entry);

if (name)
addName(function->getId(), name);

functions.push_back(std::unique_ptr<Function>(function));

return function;
}

void Builder::setupDebugFunctionEntry(Function* function, const char* name, int line, const std::vector<Id>& paramTypes,
const std::vector<char const*>& paramNames)
{

if (!emitNonSemanticShaderDebugInfo)
return;

currentLine = line;
Id nameId = getStringId(unmangleFunctionName(name));
Id funcTypeId = function->getFuncTypeId();
assert(debugId[funcTypeId] != 0);
Id funcId = function->getId();

assert(funcId != 0);

// Make the debug function instruction
Id debugFuncId = makeDebugFunction(function, nameId, funcTypeId);
debugId[funcId] = debugFuncId;
currentDebugScopeId.push(debugFuncId);

// DebugScope and DebugLine for parameter DebugDeclares
if (emitNonSemanticShaderDebugInfo && (int)paramTypes.size() > 0) {
assert(paramTypes.size() == paramNames.size());
if ((int)paramTypes.size() > 0) {
addDebugScopeAndLine(currentFileId, currentLine, 0);
}

if (emitNonSemanticShaderDebugInfo) {
assert(paramTypes.size() == paramNames.size());
for(size_t p = 0; p < paramTypes.size(); ++p)
{
Id firstParamId = function->getParamId(0);

for (size_t p = 0; p < paramTypes.size(); ++p) {
auto getParamTypeId = [this](Id const& typeId) {
if (isPointerType(typeId) || isArrayType(typeId)) {
return getContainedTypeId(typeId);
}
else {
} else {
return typeId;
}
};
auto const& paramName = paramNames[p];
auto const debugLocalVariableId = createDebugLocalVariable(debugId[getParamTypeId(paramTypes[p])], paramName, p+1);
auto const debugLocalVariableId =
createDebugLocalVariable(debugId[getParamTypeId(paramTypes[p])], paramName, p + 1);

debugId[firstParamId + p] = debugLocalVariableId;

makeDebugDeclare(debugLocalVariableId, firstParamId + p);
}
}

if (name)
addName(function->getId(), name);

functions.push_back(std::unique_ptr<Function>(function));

// Clear debug scope stack
if (emitNonSemanticShaderDebugInfo)
currentDebugScopeId.pop();

return function;
}

Id Builder::makeDebugFunction([[maybe_unused]] Function* function, Id nameId, Id funcTypeId)
Expand All @@ -2163,13 +2180,13 @@ Id Builder::makeDebugFunction([[maybe_unused]] Function* function, Id nameId, Id
type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugFunction);
type->addIdOperand(nameId);
type->addIdOperand(debugId[funcTypeId]);
type->addIdOperand(makeDebugSource(currentFileId)); // Will be fixed later when true filename available
type->addIdOperand(makeUintConstant(currentLine)); // Will be fixed later when true line available
type->addIdOperand(makeDebugSource(currentFileId)); // TODO: This points to file of definiation instead of declaration
type->addIdOperand(makeUintConstant(currentLine)); // TODO: This points to line of definiation instead of declaration
type->addIdOperand(makeUintConstant(0)); // column
type->addIdOperand(makeDebugCompilationUnit()); // scope
type->addIdOperand(nameId); // linkage name
type->addIdOperand(makeUintConstant(NonSemanticShaderDebugInfo100FlagIsPublic));
type->addIdOperand(makeUintConstant(currentLine)); // TODO(greg-lunarg): correct scope line
type->addIdOperand(makeUintConstant(currentLine));
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return funcId;
Expand Down
3 changes: 3 additions & 0 deletions SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ class Builder {
Id makeDebugFunction(Function* function, Id nameId, Id funcTypeId);
Id makeDebugLexicalBlock(uint32_t line);
std::string unmangleFunctionName(std::string const& name) const;
void setupDebugFunctionEntry(Function* function, const char* name, int line,
const std::vector<Id>& paramTypes,
const std::vector<char const*>& paramNames);

// accelerationStructureNV type
Id makeAccelerationStructureType();
Expand Down
1 change: 1 addition & 0 deletions SPIRV/spvIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class Function {
void addLocalVariable(std::unique_ptr<Instruction> inst);
Id getReturnType() const { return functionInstruction.getTypeId(); }
Id getFuncId() const { return functionInstruction.getResultId(); }
Id getFuncTypeId() const { return functionInstruction.getIdOperand(1); }
void setReturnPrecision(Decoration precision)
{
if (precision == DecorationRelaxedPrecision)
Expand Down
120 changes: 61 additions & 59 deletions Test/baseResults/spv.debuginfo.const_params.glsl.comp.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spv.debuginfo.const_params.glsl.comp
// Module Version 10000
// Generated by (magic number): 8000b
// Id's are bound by 68
// Id's are bound by 70

Capability Shader
Extension "SPV_KHR_non_semantic_info"
Expand All @@ -12,27 +12,27 @@ spv.debuginfo.const_params.glsl.comp
ExecutionMode 14 LocalSize 1 1 1
1: String ""
8: String "uint"
15: String "main"
18: String "// OpModuleProcessed auto-map-locations
17: String "float"
35: String "function"
38: String "// OpModuleProcessed auto-map-locations
// OpModuleProcessed auto-map-bindings
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed keep-uncalled
// OpModuleProcessed entry-point main
#line 1
"
25: String "float"
40: String "function"
46: String "f"
50: String "f2"
53: String "f3"
56: String "f4"
45: String "f"
49: String "f2"
52: String "f3"
55: String "f4"
57: String "main"
Name 14 "main"
Name 39 "function(f1;vf2;vf3;vf4;"
Name 35 "f"
Name 36 "f2"
Name 37 "f3"
Name 38 "f4"
Name 33 "function(f1;vf2;vf3;vf4;"
Name 29 "f"
Name 30 "f2"
Name 31 "f3"
Name 32 "f4"
4: TypeVoid
5: TypeFunction 4
7: TypeInt 32 0
Expand All @@ -42,55 +42,57 @@ spv.debuginfo.const_params.glsl.comp
9: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 2(DebugTypeBasic) 8 10 11 12
13: 7(int) Constant 3
6: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 8(DebugTypeFunction) 13 4
17: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 35(DebugSource) 1 18
20: 7(int) Constant 1
21: 7(int) Constant 4
22: 7(int) Constant 2
19: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 1(DebugCompilationUnit) 20 21 17 22
16: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 20(DebugFunction) 15 6 17 12 12 19 15 13 12
24: TypeFloat 32
26: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 2(DebugTypeBasic) 25 10 13 12
27: TypeVector 24(float) 2
28: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 6(DebugTypeVector) 26 22
29: TypeVector 24(float) 3
30: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 6(DebugTypeVector) 26 13
31: TypeVector 24(float) 4
32: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 6(DebugTypeVector) 26 21
33: TypeFunction 4 24(float) 27(fvec2) 29(fvec3) 31(fvec4)
34: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 8(DebugTypeFunction) 13 4 26 28 30 32
41: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 20(DebugFunction) 40 34 17 12 12 19 40 13 12
45: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 46 26 17 12 12 41 21 20
48: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 31(DebugExpression)
49: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 50 28 17 12 12 41 21 22
52: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 53 30 17 12 12 41 21 13
55: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 56 32 17 12 12 41 21 21
62: 7(int) Constant 13
63: 24(float) Constant 0
64: 27(fvec2) ConstantComposite 63 63
65: 29(fvec3) ConstantComposite 63 63 63
66: 31(fvec4) ConstantComposite 63 63 63 63
16: TypeFloat 32
18: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 2(DebugTypeBasic) 17 10 13 12
19: TypeVector 16(float) 2
20: 7(int) Constant 2
21: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 6(DebugTypeVector) 18 20
22: TypeVector 16(float) 3
23: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 6(DebugTypeVector) 18 13
24: TypeVector 16(float) 4
25: 7(int) Constant 4
26: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 6(DebugTypeVector) 18 25
27: TypeFunction 4 16(float) 19(fvec2) 22(fvec3) 24(fvec4)
28: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 8(DebugTypeFunction) 13 4 18 21 23 26
37: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 35(DebugSource) 1 38
39: 7(int) Constant 7
41: 7(int) Constant 1
40: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 1(DebugCompilationUnit) 41 25 37 20
36: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 20(DebugFunction) 35 28 37 39 12 40 35 13 39
44: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 45 18 37 39 12 36 25 41
47: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 31(DebugExpression)
48: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 49 21 37 39 12 36 25 20
51: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 52 23 37 39 12 36 25 13
54: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 26(DebugLocalVariable) 55 26 37 39 12 36 25 25
59: 7(int) Constant 11
58: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 20(DebugFunction) 57 6 37 59 12 40 57 13 59
64: 7(int) Constant 13
65: 16(float) Constant 0
66: 19(fvec2) ConstantComposite 65 65
67: 22(fvec3) ConstantComposite 65 65 65
68: 24(fvec4) ConstantComposite 65 65 65 65
Line 1 11 11
14(main): 4 Function None 5
23: Label
59: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 101(DebugFunctionDefinition) 16 14(main)
60: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 16
61: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 103(DebugLine) 17 62 62 12 12
67: 4 FunctionCall 39(function(f1;vf2;vf3;vf4;) 63 64 65 66
15: Label
61: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 101(DebugFunctionDefinition) 58 14(main)
62: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 58
63: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 103(DebugLine) 37 64 64 12 12
69: 4 FunctionCall 33(function(f1;vf2;vf3;vf4;) 65 66 67 68
Return
FunctionEnd
Line 1 7 18
39(function(f1;vf2;vf3;vf4;): 4 Function None 33
35(f): 24(float) FunctionParameter
36(f2): 27(fvec2) FunctionParameter
37(f3): 29(fvec3) FunctionParameter
38(f4): 31(fvec4) FunctionParameter
42: Label
43: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 41
44: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 103(DebugLine) 17 12 12 12 12
47: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 45 35(f) 48
51: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 49 36(f2) 48
54: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 52 37(f3) 48
57: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 55 38(f4) 48
58: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 101(DebugFunctionDefinition) 41 39(function(f1;vf2;vf3;vf4;)
33(function(f1;vf2;vf3;vf4;): 4 Function None 27
29(f): 16(float) FunctionParameter
30(f2): 19(fvec2) FunctionParameter
31(f3): 22(fvec3) FunctionParameter
32(f4): 24(fvec4) FunctionParameter
34: Label
42: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 36
43: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 103(DebugLine) 37 39 39 12 12
46: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 44 29(f) 47
50: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 48 30(f2) 47
53: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 51 31(f3) 47
56: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 54 32(f4) 47
60: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 101(DebugFunctionDefinition) 36 33(function(f1;vf2;vf3;vf4;)
Return
FunctionEnd
Loading

0 comments on commit 95cdcf5

Please sign in to comment.