@@ -1194,24 +1194,49 @@ Id Builder::makeDebugSource(const Id fileName) {
1194
1194
sourceInst->addIdOperand (nonSemanticShaderDebugInfo);
1195
1195
sourceInst->addImmediateOperand (NonSemanticShaderDebugInfo100DebugSource);
1196
1196
sourceInst->addIdOperand (fileName);
1197
+ constantsTypesGlobals.push_back (std::unique_ptr<Instruction>(sourceInst));
1198
+ module.mapInstruction (sourceInst);
1197
1199
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
+ };
1199
1229
if (fileName == mainFileId) {
1200
- sourceId = getStringId (sourceText);
1230
+ processDebugSource (sourceText);
1201
1231
} else {
1202
1232
auto incItr = includeFiles.find (fileName);
1203
1233
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
1205
1237
}
1206
1238
}
1207
-
1208
- // We omit the optional source text item if not available in glslang
1209
- if (sourceId != 0 ) {
1210
- sourceInst->addIdOperand (sourceId);
1211
- }
1212
1239
}
1213
- constantsTypesGlobals.push_back (std::unique_ptr<Instruction>(sourceInst));
1214
- module.mapInstruction (sourceInst);
1215
1240
debugSourceId[fileName] = resultId;
1216
1241
return resultId;
1217
1242
}
0 commit comments