SPIR-V OpLines now contain filenames from HLSL-style #lines.
This commit is contained in:
committed by
John Kessenich
parent
127cea5c9a
commit
5d43c4aac7
@@ -1594,7 +1594,7 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
|
||||
|
||||
bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::TIntermBinary* node)
|
||||
{
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
|
||||
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
|
||||
if (node->getType().getQualifier().isSpecConstant())
|
||||
@@ -1789,7 +1789,7 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
|
||||
|
||||
bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node)
|
||||
{
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
|
||||
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
|
||||
if (node->getType().getQualifier().isSpecConstant())
|
||||
@@ -2053,7 +2053,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
|
||||
return false;
|
||||
case glslang::EOpFunctionCall:
|
||||
{
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
if (node->isUserDefined())
|
||||
result = handleUserFunctionCall(node);
|
||||
// assert(result); // this can happen for bad shaders because the call graph completeness checking is not yet done
|
||||
@@ -2172,7 +2172,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
|
||||
case glslang::EOpConstructStruct:
|
||||
case glslang::EOpConstructTextureSampler:
|
||||
{
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
std::vector<spv::Id> arguments;
|
||||
translateArguments(*node, arguments);
|
||||
spv::Id constructed;
|
||||
@@ -2317,7 +2317,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
|
||||
right->traverse(this);
|
||||
spv::Id rightId = accessChainLoad(right->getType());
|
||||
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
OpDecorations decorations = { precision,
|
||||
TranslateNoContractionDecoration(node->getType().getQualifier()),
|
||||
TranslateNonUniformDecoration(node->getType().getQualifier()) };
|
||||
@@ -2405,12 +2405,12 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
|
||||
if (lvalue)
|
||||
operands.push_back(builder.accessChainGetLValue());
|
||||
else {
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
operands.push_back(accessChainLoad(glslangOperands[arg]->getAsTyped()->getType()));
|
||||
}
|
||||
}
|
||||
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
if (atomic) {
|
||||
// Handle all atomics
|
||||
result = createAtomicOperation(node->getOp(), precision, resultType(), operands, node->getBasicType());
|
||||
@@ -2511,7 +2511,7 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
|
||||
node->getFalseBlock()->traverse(this);
|
||||
spv::Id falseValue = accessChainLoad(node->getTrueBlock()->getAsTyped()->getType());
|
||||
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
|
||||
// done if void
|
||||
if (node->getBasicType() == glslang::EbtVoid)
|
||||
@@ -2685,7 +2685,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn
|
||||
// by a block-ending branch. But we don't want to put any other body/test
|
||||
// instructions in it, since the body/test may have arbitrary instructions,
|
||||
// including merges of its own.
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
builder.setBuildPoint(&blocks.head);
|
||||
builder.createLoopMerge(&blocks.merge, &blocks.continue_target, control, dependencyLength);
|
||||
if (node->testFirst() && node->getTest()) {
|
||||
@@ -2709,7 +2709,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn
|
||||
node->getTerminal()->traverse(this);
|
||||
builder.createBranch(&blocks.head);
|
||||
} else {
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
builder.createBranch(&blocks.body);
|
||||
|
||||
breakForLoop.push(true);
|
||||
@@ -2744,7 +2744,7 @@ bool TGlslangToSpvTraverser::visitBranch(glslang::TVisit /* visit */, glslang::T
|
||||
if (node->getExpression())
|
||||
node->getExpression()->traverse(this);
|
||||
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
|
||||
switch (node->getFlowOp()) {
|
||||
case glslang::EOpKill:
|
||||
@@ -3913,7 +3913,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
|
||||
if (! node->isImage() && ! node->isTexture())
|
||||
return spv::NoResult;
|
||||
|
||||
builder.setLine(node->getLoc().line);
|
||||
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
|
||||
|
||||
// Process a GLSL texturing op (will be SPV image)
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ Builder::Builder(unsigned int spvVersion, unsigned int magicNumber, SpvBuildLogg
|
||||
sourceVersion(0),
|
||||
sourceFileStringId(NoResult),
|
||||
currentLine(0),
|
||||
currentFile(nullptr),
|
||||
emitOpLines(false),
|
||||
addressModel(AddressingModelLogical),
|
||||
memoryModel(MemoryModelGLSL450),
|
||||
@@ -87,8 +88,9 @@ Id Builder::import(const char* name)
|
||||
return import->getResultId();
|
||||
}
|
||||
|
||||
// Emit an OpLine if we've been asked to emit OpLines and the line number
|
||||
// has changed since the last time, and is a valid line number.
|
||||
// Emit instruction for non-filename-based #line directives (ie. no filename
|
||||
// seen yet): emit an OpLine if we've been asked to emit OpLines and the line
|
||||
// number has changed since the last time, and is a valid line number.
|
||||
void Builder::setLine(int lineNum)
|
||||
{
|
||||
if (lineNum != 0 && lineNum != currentLine) {
|
||||
@@ -98,6 +100,38 @@ void Builder::setLine(int lineNum)
|
||||
}
|
||||
}
|
||||
|
||||
// If no filename, do non-filename-based #line emit. Else do filename-based emit.
|
||||
// Emit OpLine if we've been asked to emit OpLines and the line number or filename
|
||||
// has changed since the last time, and line number is valid.
|
||||
void Builder::setLine(int lineNum, const char* filename)
|
||||
{
|
||||
if (filename == nullptr) {
|
||||
setLine(lineNum);
|
||||
return;
|
||||
}
|
||||
if ((lineNum != 0 && lineNum != currentLine) || currentFile == nullptr ||
|
||||
strncmp(filename, currentFile, strlen(currentFile) + 1) != 0) {
|
||||
currentLine = lineNum;
|
||||
currentFile = filename;
|
||||
if (emitOpLines) {
|
||||
// If filename previously seen, use its id, else create a string
|
||||
// and put it in the map.
|
||||
auto sItr = stringIds.find(filename);
|
||||
if (sItr != stringIds.end()) {
|
||||
addLine(sItr->second, currentLine, 0);
|
||||
} else {
|
||||
Instruction* fileString =
|
||||
new Instruction(getUniqueId(), NoType, OpString);
|
||||
fileString->addStringOperand(filename);
|
||||
spv::Id stringId = fileString->getResultId();
|
||||
strings.push_back(std::unique_ptr<Instruction>(fileString));
|
||||
addLine(stringId, currentLine, 0);
|
||||
stringIds[filename] = stringId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Builder::addLine(Id fileName, int lineNum, int column)
|
||||
{
|
||||
Instruction* line = new Instruction(OpLine);
|
||||
|
||||
@@ -77,9 +77,11 @@ public:
|
||||
void setSourceFile(const std::string& file)
|
||||
{
|
||||
Instruction* fileString = new Instruction(getUniqueId(), NoType, OpString);
|
||||
fileString->addStringOperand(file.c_str());
|
||||
const char* file_c_str = file.c_str();
|
||||
fileString->addStringOperand(file_c_str);
|
||||
sourceFileStringId = fileString->getResultId();
|
||||
strings.push_back(std::unique_ptr<Instruction>(fileString));
|
||||
stringIds[file_c_str] = sourceFileStringId;
|
||||
}
|
||||
void setSourceText(const std::string& text) { sourceText = text; }
|
||||
void addSourceExtension(const char* ext) { sourceExtensions.push_back(ext); }
|
||||
@@ -106,9 +108,16 @@ public:
|
||||
return id;
|
||||
}
|
||||
|
||||
// Log the current line, and if different than the last one,
|
||||
// issue a new OpLine, using the current file name.
|
||||
// Generate OpLine for non-filename-based #line directives (ie no filename
|
||||
// seen yet): Log the current line, and if different than the last one,
|
||||
// issue a new OpLine using the new line and current source file name.
|
||||
void setLine(int line);
|
||||
|
||||
// If filename null, generate OpLine for non-filename-based line directives,
|
||||
// else do filename-based: Log the current line and file, and if different
|
||||
// than the last one, issue a new OpLine using the new line and file
|
||||
// name.
|
||||
void setLine(int line, const char* filename);
|
||||
// Low-level OpLine. See setLine() for a layered helper.
|
||||
void addLine(Id fileName, int line, int column);
|
||||
|
||||
@@ -658,6 +667,7 @@ public:
|
||||
spv::Id sourceFileStringId;
|
||||
std::string sourceText;
|
||||
int currentLine;
|
||||
const char* currentFile;
|
||||
bool emitOpLines;
|
||||
std::set<std::string> extensions;
|
||||
std::vector<const char*> sourceExtensions;
|
||||
@@ -695,6 +705,9 @@ public:
|
||||
// Our loop stack.
|
||||
std::stack<LoopBlocks> loops;
|
||||
|
||||
// map from strings to their string ids
|
||||
std::unordered_map<std::string, spv::Id> stringIds;
|
||||
|
||||
// The stream for outputting warnings and errors.
|
||||
SpvBuildLogger* logger;
|
||||
}; // end Builder class
|
||||
|
||||
Reference in New Issue
Block a user