Support NonSemantic DebugValue and generate it for const arg

For passing-by-value semantic, DebugDeclare cannot be used for parameters because there's no pointer.
This commit is contained in:
Qingyuan Zheng 2023-10-24 15:41:12 -07:00 committed by Jeremy Hayes
parent 1dcb072cda
commit 109b5979d3
3 changed files with 46 additions and 28 deletions

View file

@ -1182,13 +1182,26 @@ Id Builder::makeDebugExpression()
return debugExpression; return debugExpression;
} }
Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const localVariable) Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const pointer)
{ {
Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst); Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst);
inst->addIdOperand(nonSemanticShaderDebugInfo); inst->addIdOperand(nonSemanticShaderDebugInfo);
inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugDeclare); inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugDeclare);
inst->addIdOperand(debugLocalVariable); // debug local variable id inst->addIdOperand(debugLocalVariable); // debug local variable id
inst->addIdOperand(localVariable); // local variable id inst->addIdOperand(pointer); // pointer to local variable id
inst->addIdOperand(makeDebugExpression()); // expression id
buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
return inst->getResultId();
}
Id Builder::makeDebugValue(Id const debugLocalVariable, Id const value)
{
Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst);
inst->addIdOperand(nonSemanticShaderDebugInfo);
inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugValue);
inst->addIdOperand(debugLocalVariable); // debug local variable id
inst->addIdOperand(value); // value of local variable id
inst->addIdOperand(makeDebugExpression()); // expression id inst->addIdOperand(makeDebugExpression()); // expression id
buildPoint->addInstruction(std::unique_ptr<Instruction>(inst)); buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
@ -2148,20 +2161,25 @@ void Builder::setupDebugFunctionEntry(Function* function, const char* name, int
Id firstParamId = function->getParamId(0); Id firstParamId = function->getParamId(0);
for (size_t p = 0; p < paramTypes.size(); ++p) { for (size_t p = 0; p < paramTypes.size(); ++p) {
auto getParamTypeId = [this](Id const& typeId) { bool passByRef = false;
if (isPointerType(typeId) || isArrayType(typeId)) { Id paramTypeId = paramTypes[p];
return getContainedTypeId(typeId);
} else { // For pointer-typed parameters, they are actually passed by reference and we need unwrap the pointer to get the actual parameter type.
return typeId; if (isPointerType(paramTypeId) || isArrayType(paramTypeId)) {
passByRef = true;
paramTypeId = getContainedTypeId(paramTypeId);
} }
};
auto const& paramName = paramNames[p]; auto const& paramName = paramNames[p];
auto const debugLocalVariableId = auto const debugLocalVariableId = createDebugLocalVariable(debugId[paramTypeId], paramName, p + 1);
createDebugLocalVariable(debugId[getParamTypeId(paramTypes[p])], paramName, p + 1); auto const paramId = static_cast<Id>(firstParamId + p);
debugId[paramId] = debugLocalVariableId;
debugId[firstParamId + p] = debugLocalVariableId; if (passByRef) {
makeDebugDeclare(debugLocalVariableId, paramId);
makeDebugDeclare(debugLocalVariableId, firstParamId + p); } else {
makeDebugValue(debugLocalVariableId, paramId);
}
} }
} }

View file

@ -231,7 +231,7 @@ public:
Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable); Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable);
Id createDebugLocalVariable(Id type, char const*const name, size_t const argNumber = 0); Id createDebugLocalVariable(Id type, char const*const name, size_t const argNumber = 0);
Id makeDebugExpression(); Id makeDebugExpression();
Id makeDebugDeclare(Id const debugLocalVariable, Id const localVariable); Id makeDebugDeclare(Id const debugLocalVariable, Id const pointer);
Id makeDebugValue(Id const debugLocalVariable, Id const value); Id makeDebugValue(Id const debugLocalVariable, Id const value);
Id makeDebugFunctionType(Id returnType, const std::vector<Id>& paramTypes); Id makeDebugFunctionType(Id returnType, const std::vector<Id>& paramTypes);
Id makeDebugFunction(Function* function, Id nameId, Id funcTypeId); Id makeDebugFunction(Function* function, Id nameId, Id funcTypeId);

View file

@ -81,18 +81,18 @@ spv.debuginfo.const_params.glsl.comp
Return Return
FunctionEnd FunctionEnd
Line 1 7 18 Line 1 7 18
33(function(f1;vf2;vf3;vf4;): 4 Function None 27 39(function(f1;vf2;vf3;vf4;): 4 Function None 33
29(f): 16(float) FunctionParameter 35(f): 24(float) FunctionParameter
30(f2): 19(fvec2) FunctionParameter 36(f2): 27(fvec2) FunctionParameter
31(f3): 22(fvec3) FunctionParameter 37(f3): 29(fvec3) FunctionParameter
32(f4): 24(fvec4) FunctionParameter 38(f4): 31(fvec4) FunctionParameter
34: Label 42: Label
42: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 36 43: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 23(DebugScope) 41
43: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 103(DebugLine) 37 39 39 12 12 44: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 103(DebugLine) 17 12 12 12 12
46: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 44 29(f) 47 47: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 29(DebugValue) 45 35(f) 48
50: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 48 30(f2) 47 51: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 29(DebugValue) 49 36(f2) 48
53: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 51 31(f3) 47 54: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 29(DebugValue) 52 37(f3) 48
56: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 28(DebugDeclare) 54 32(f4) 47 57: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 29(DebugValue) 55 38(f4) 48
60: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 101(DebugFunctionDefinition) 36 33(function(f1;vf2;vf3;vf4;) 58: 4 ExtInst 2(NonSemantic.Shader.DebugInfo.100) 101(DebugFunctionDefinition) 41 39(function(f1;vf2;vf3;vf4;)
Return Return
FunctionEnd FunctionEnd