Skip to content

Commit 84581c2

Browse files
Awata Yuichiarcady-lunarg
Awata Yuichi
authored andcommitted
DebugSourceContinued をサポートします
1 parent ca5ad6d commit 84581c2

File tree

4 files changed

+7691
-10
lines changed

4 files changed

+7691
-10
lines changed

SPIRV/SpvBuilder.cpp

+35-10
Original file line numberDiff line numberDiff line change
@@ -1194,24 +1194,49 @@ Id Builder::makeDebugSource(const Id fileName) {
11941194
sourceInst->addIdOperand(nonSemanticShaderDebugInfo);
11951195
sourceInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugSource);
11961196
sourceInst->addIdOperand(fileName);
1197+
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceInst));
1198+
module.mapInstruction(sourceInst);
11971199
if (emitNonSemanticShaderDebugSource) {
1198-
spv::Id sourceId = 0;
1200+
const int maxWordCount = 0xFFFF;
1201+
const int opSourceWordCount = 4;
1202+
const int nonNullBytesPerInstruction = 4 * (maxWordCount - opSourceWordCount) - 1;
1203+
auto processDebugSource = [&](std::string source) {
1204+
if (source.size() > 0) {
1205+
int nextByte = 0;
1206+
while ((int)source.size() - nextByte > 0) {
1207+
auto subString = source.substr(nextByte, nonNullBytesPerInstruction);
1208+
auto sourceId = getStringId(subString);
1209+
if (nextByte == 0) {
1210+
// DebugSource
1211+
sourceInst->addIdOperand(sourceId);
1212+
} else {
1213+
// DebugSourceContinued
1214+
Instruction* sourceContinuedInst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst);
1215+
sourceContinuedInst->reserveOperands(2);
1216+
sourceContinuedInst->addIdOperand(nonSemanticShaderDebugInfo);
1217+
sourceContinuedInst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugSourceContinued);
1218+
sourceContinuedInst->addIdOperand(sourceId);
1219+
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceContinuedInst));
1220+
module.mapInstruction(sourceContinuedInst);
1221+
}
1222+
nextByte += nonNullBytesPerInstruction;
1223+
}
1224+
} else {
1225+
auto sourceId = getStringId(source);
1226+
sourceInst->addIdOperand(sourceId);
1227+
}
1228+
};
11991229
if (fileName == mainFileId) {
1200-
sourceId = getStringId(sourceText);
1230+
processDebugSource(sourceText);
12011231
} else {
12021232
auto incItr = includeFiles.find(fileName);
12031233
if (incItr != includeFiles.end()) {
1204-
sourceId = getStringId(*incItr->second);
1234+
processDebugSource(*incItr->second);
1235+
} else {
1236+
// We omit the optional source text item if not available in glslang
12051237
}
12061238
}
1207-
1208-
// We omit the optional source text item if not available in glslang
1209-
if (sourceId != 0) {
1210-
sourceInst->addIdOperand(sourceId);
1211-
}
12121239
}
1213-
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(sourceInst));
1214-
module.mapInstruction(sourceInst);
12151240
debugSourceId[fileName] = resultId;
12161241
return resultId;
12171242
}

0 commit comments

Comments
 (0)