summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 28862f5b8..376a828cd 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -3215,6 +3215,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
if (layout)
emitVarLayout(param, varInst, layout);
emitDecorations(param, getID(varInst));
+ maybeEmitDebugGlobalVariable(param, varInst);
return varInst;
}
@@ -3237,6 +3238,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
if (layout)
emitVarLayout(globalVar, varInst, layout);
emitDecorations(globalVar, getID(varInst));
+ maybeEmitDebugGlobalVariable(globalVar, varInst);
return varInst;
}
@@ -3893,6 +3895,39 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
return nullptr;
}
+ void maybeEmitDebugGlobalVariable(IRInst* globalInst, SpvInst* spvVar)
+ {
+ auto scope = findDebugScope(globalInst->getModule()->getModuleInst());
+ if (!scope)
+ return;
+
+ auto name = getName(globalInst);
+ IRBuilder builder(globalInst);
+ auto varType = tryGetPointedToType(&builder, globalInst->getDataType());
+ auto debugType = emitDebugType(varType);
+
+ // Use default debug source and line info similar to struct debug type emission
+ auto loc = globalInst->findDecoration<IRDebugLocationDecoration>();
+ IRInst* source = loc ? loc->getSource() : m_defaultDebugSource;
+ IRInst* line = loc ? loc->getLine() : builder.getIntValue(builder.getUIntType(), 0);
+ IRInst* col = loc ? loc->getCol() : line;
+
+ emitOpDebugGlobalVariable(
+ getSection(SpvLogicalSectionID::GlobalVariables),
+ nullptr, // Don't associate with IR inst to avoid duplicate registration
+ m_voidType,
+ getNonSemanticDebugInfoExtInst(),
+ name,
+ debugType,
+ source,
+ line,
+ col,
+ scope,
+ name, // linkageName same as name
+ spvVar,
+ builder.getIntValue(builder.getUIntType(), 0)); // flags
+ }
+
SpvInst* emitMakeUInt64(SpvInstParent* parent, IRInst* inst)
{
IRBuilder builder(inst);
@@ -8524,7 +8559,29 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
debugBaseType,
builder.getIntValue(builder.getUIntType(), kDebugTypeAtomicQualifier));
}
- return ensureInst(m_voidType);
+
+ // Fallback for texture types, raytracing types, and other composite types
+ // Declare variables for debug location like struct handling does
+ IRInst* source = m_defaultDebugSource;
+ IRInst* line = builder.getIntValue(builder.getUIntType(), 0);
+ IRInst* col = line;
+
+ // Emit a composite debug type (struct-like for most types)
+ return emitOpDebugTypeComposite(
+ getSection(SpvLogicalSectionID::ConstantsAndTypes),
+ nullptr,
+ m_voidType,
+ getNonSemanticDebugInfoExtInst(),
+ name,
+ builder.getIntValue(builder.getUIntType(), 0),
+ source,
+ line,
+ col,
+ scope,
+ name,
+ builder.getIntValue(builder.getUIntType(), 0), // Size (unknown)
+ builder.getIntValue(builder.getUIntType(), kUnknownPhysicalLayout),
+ List<SpvInst*>()); // No members
}
SpvInst* emitDebugType(IRType* type)