Skip to content

Commit

Permalink
Add support for OpSourceDebugContinued
Browse files Browse the repository at this point in the history
  • Loading branch information
chaocNV committed Oct 25, 2023
1 parent 25ab13a commit c8b3ad5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
43 changes: 34 additions & 9 deletions SPIRV/SpvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,20 +1077,48 @@ Id Builder::makeDebugSource(const Id fileName) {
sourceInst->addIdOperand(nonSemanticShaderDebugInfo);
sourceInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugSource);
sourceInst->addIdOperand(fileName);


if (emitNonSemanticShaderDebugSource) {
std::string text;
spv::Id sourceId = 0;
if (fileName == sourceFileStringId) {
sourceId = getStringId(sourceText);
text =sourceText;
} else {
auto incItr = includeFiles.find(fileName);
assert(incItr != includeFiles.end());
sourceId = getStringId(*incItr->second);
text =*incItr->second;
}
// Source operand
if (text.size() > 0) {
int nextByte = 0;
std::string subString;
while ((int)text.size() - nextByte > 0) {
subString = text.substr(nextByte, nonNullBytesPerInstruction);
if (nextByte == 0) {
sourceId = getStringId(subString);
sourceInst->addIdOperand(sourceId);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceInst));
module.mapInstruction(sourceInst);
debugSourceId[fileName] = resultId;
} else {
// DebugSourcContinued
Instruction* sourceContinuedInst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst);
sourceContinuedInst->addIdOperand(nonSemanticShaderDebugInfo);
sourceContinuedInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugSourceContinued);
sourceContinuedInst->addIdOperand(getStringId(subString));
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceContinuedInst));
module.mapInstruction(sourceContinuedInst);
}
nextByte += nonNullBytesPerInstruction;
}
} else {
module.mapInstruction(sourceInst);
debugSourceId[fileName] = resultId;
}
sourceInst->addIdOperand(sourceId);

}
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceInst));
module.mapInstruction(sourceInst);
debugSourceId[fileName] = resultId;

return resultId;
}

Expand Down Expand Up @@ -4081,9 +4109,6 @@ void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* els
void Builder::dumpSourceInstructions(const spv::Id fileId, const std::string& text,
std::vector<unsigned int>& out) const
{
const int maxWordCount = 0xFFFF;
const int opSourceWordCount = 4;
const int nonNullBytesPerInstruction = 4 * (maxWordCount - opSourceWordCount) - 1;

if (sourceLang != SourceLanguageUnknown) {
// OpSource Language Version File Source
Expand Down
5 changes: 5 additions & 0 deletions SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ class Builder {

// The stream for outputting warnings and errors.
SpvBuildLogger* logger;

// constants for OpSourceContinued and OpDebugSourceContinued
const int maxWordCount = 0xFFFF;
const int opSourceWordCount = 4;
const int nonNullBytesPerInstruction = 4 * (maxWordCount - opSourceWordCount) - 1;
}; // end Builder class

}; // end spv namespace
Expand Down

0 comments on commit c8b3ad5

Please sign in to comment.