Clean up the debug line info tracking and generation.

- Correctly populate the field `currentFileId` with the presence of include directive
- Support lazy OpLine/OpDebugLine generation only when a real instruction is added instead of a debug location is set
- Improve the debug location tracking to per-block instead of just per-builder
- A few bug fixes related to debug source info
This commit is contained in:
Qingyuan Zheng 2024-02-09 10:27:40 -08:00 committed by GitHub
parent b1f7affe94
commit 30661abd9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 8844 additions and 8834 deletions

View file

@ -1558,8 +1558,13 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
this->options.generateDebugInfo = true;
if (this->options.generateDebugInfo) {
builder.setEmitOpLines();
builder.setSourceFile(glslangIntermediate->getSourceFile());
if (this->options.emitNonSemanticShaderDebugInfo) {
builder.setEmitNonSemanticShaderDebugInfo(this->options.emitNonSemanticShaderDebugSource);
}
else {
builder.setEmitSpirvDebugInfo();
}
builder.setDebugSourceFile(glslangIntermediate->getSourceFile());
// Set the source shader's text. If for SPV version 1.0, include
// a preamble in comments stating the OpModuleProcessed instructions.
@ -1584,9 +1589,6 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
builder.addInclude(iItr->first, iItr->second);
}
builder.setEmitNonSemanticShaderDebugInfo(this->options.emitNonSemanticShaderDebugInfo);
builder.setEmitNonSemanticShaderDebugSource(this->options.emitNonSemanticShaderDebugSource);
stdBuiltins = builder.import("GLSL.std.450");
spv::AddressingModel addressingModel = spv::AddressingModelLogical;
@ -2037,7 +2039,9 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
{
// We update the line information even though no code might be generated here
// This is helpful to yield correct lines for control flow instructions
builder.setLine(symbol->getLoc().line, symbol->getLoc().getFilename());
if (!linkageOnly) {
builder.setDebugSourceLocation(symbol->getLoc().line, symbol->getLoc().getFilename());
}
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (symbol->getType().isStruct())
@ -2146,7 +2150,7 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::TIntermBinary* node)
{
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
if (node->getLeft()->getAsSymbolNode() != nullptr && node->getLeft()->getType().isStruct()) {
glslangTypeToIdMap[node->getLeft()->getType().getStruct()] = node->getLeft()->getAsSymbolNode()->getId();
}
@ -2191,7 +2195,7 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
spv::Id rValue = accessChainLoad(node->getRight()->getType());
// reset line number for assignment
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
if (node->getOp() != glslang::EOpAssign) {
// the left is also an r-value
@ -2524,7 +2528,7 @@ spv::Id TGlslangToSpvTraverser::translateForcedType(spv::Id object)
bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node)
{
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (node->getType().getQualifier().isSpecConstant())
@ -2912,11 +2916,11 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
return false;
} else {
if (node->getOp() == glslang::EOpScope)
builder.enterScope(0);
builder.enterLexicalBlock(0);
}
} else {
if (sequenceDepth > 1 && node->getOp() == glslang::EOpScope)
builder.leaveScope();
builder.leaveLexicalBlock();
--sequenceDepth;
}
@ -2943,6 +2947,9 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
}
case glslang::EOpFunction:
if (visit == glslang::EvPreVisit) {
if (options.generateDebugInfo) {
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
}
if (isShaderEntryPoint(node)) {
inEntryPoint = true;
builder.setBuildPoint(shaderEntry->getLastBlock());
@ -2951,10 +2958,10 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
} else {
handleFunctionEntry(node);
}
if (options.generateDebugInfo) {
if (options.generateDebugInfo && !options.emitNonSemanticShaderDebugInfo) {
const auto& loc = node->getLoc();
const char* sourceFileName = loc.getFilename();
spv::Id sourceFileId = sourceFileName ? builder.getStringId(sourceFileName) : builder.getSourceFile();
spv::Id sourceFileId = sourceFileName ? builder.getStringId(sourceFileName) : builder.getMainFileId();
currentFunction->setDebugLineInfo(sourceFileId, loc.line, loc.column);
}
} else {
@ -2972,7 +2979,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
return false;
case glslang::EOpFunctionCall:
{
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
if (node->isUserDefined())
result = handleUserFunctionCall(node);
if (result) {
@ -3093,7 +3100,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
case glslang::EOpConstructCooperativeMatrixNV:
case glslang::EOpConstructCooperativeMatrixKHR:
{
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
std::vector<spv::Id> arguments;
translateArguments(*node, arguments, lvalueCoherentFlags);
spv::Id constructed;
@ -3379,7 +3386,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
right->traverse(this);
spv::Id rightId = accessChainLoad(right->getType());
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
OpDecorations decorations = { precision,
TranslateNoContractionDecoration(node->getType().getQualifier()),
TranslateNonUniformDecoration(node->getType().getQualifier()) };
@ -3614,7 +3621,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
lvalueCoherentFlags = builder.getAccessChain().coherentFlags;
lvalueCoherentFlags |= TranslateCoherent(glslangOperands[arg]->getAsTyped()->getType());
} else {
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
glslang::TOperator glslangOp = node->getOp();
if (arg == 1 &&
(glslangOp == glslang::EOpRayQueryGetIntersectionType ||
@ -3666,7 +3673,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
}
}
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
if (node->getOp() == glslang::EOpCooperativeMatrixLoad ||
node->getOp() == glslang::EOpCooperativeMatrixLoadNV) {
std::vector<spv::IdImmediate> idImmOps;
@ -3906,7 +3913,7 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
node->getFalseBlock()->traverse(this);
spv::Id falseValue = accessChainLoad(node->getFalseBlock()->getAsTyped()->getType());
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
// done if void
if (node->getBasicType() == glslang::EbtVoid)
@ -4114,7 +4121,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn
// instructions in it, since the body/test may have arbitrary instructions,
// including merges of its own.
builder.setBuildPoint(&blocks.head);
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
builder.createLoopMerge(&blocks.merge, &blocks.continue_target, control, operands);
if (node->testFirst() && node->getTest()) {
spv::Block& test = builder.makeNewBlock();
@ -4137,7 +4144,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn
node->getTerminal()->traverse(this);
builder.createBranch(&blocks.head);
} else {
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
builder.createBranch(&blocks.body);
breakForLoop.push(true);
@ -4172,7 +4179,7 @@ bool TGlslangToSpvTraverser::visitBranch(glslang::TVisit /* visit */, glslang::T
if (node->getExpression())
node->getExpression()->traverse(this);
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
switch (node->getFlowOp()) {
case glslang::EOpKill:
@ -5756,7 +5763,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
if (! node->isImage() && ! node->isTexture())
return spv::NoResult;
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
builder.setDebugSourceLocation(node->getLoc().line, node->getLoc().getFilename());
// Process a GLSL texturing op (will be SPV image)