diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 8 | ||||
| -rw-r--r-- | source/slang/slang-ir-insert-debug-value-store.cpp | 34 | ||||
| -rw-r--r-- | source/slang/slang-ir-insts.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir-legalize-types.cpp | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir.cpp | 14 |
5 files changed, 46 insertions, 16 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 64ef469ef..320263b25 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -4855,16 +4855,10 @@ struct SPIRVEmitContext return nullptr; IRBuilder builder(debugVar); auto name = getName(debugVar); - if (!name) - { - static uint32_t uid = 0; - uid++; - name = builder.getStringValue((String("unamed_local_var_") + String(uid)).getUnownedSlice()); - } auto debugType = emitDebugType(debugVar->getDataType()); auto spvLocalVar = emitOpDebugLocalVariable(getSection(SpvLogicalSectionID::ConstantsAndTypes), debugVar, m_voidType, getNonSemanticDebugInfoExtInst(), name, debugType, debugVar->getSource(), debugVar->getLine(), debugVar->getCol(), scope, - builder.getIntValue(builder.getUIntType(), 0), nullptr); + builder.getIntValue(builder.getUIntType(), 0), debugVar->getArgIndex()); return spvLocalVar; } diff --git a/source/slang/slang-ir-insert-debug-value-store.cpp b/source/slang/slang-ir-insert-debug-value-store.cpp index b689124a2..8aad3e417 100644 --- a/source/slang/slang-ir-insert-debug-value-store.cpp +++ b/source/slang/slang-ir-insert-debug-value-store.cpp @@ -21,7 +21,7 @@ namespace Slang { params.add(param); } - + Index paramIndex = 0; for (auto param : params) { builder.setInsertBefore(firstBlock->getFirstOrdinaryInst()); @@ -36,7 +36,8 @@ namespace Slang paramType, funcDebugLoc->getSource(), funcDebugLoc->getLine(), - funcDebugLoc->getCol()); + funcDebugLoc->getCol(), + builder.getIntValue(builder.getUIntType(), paramIndex)); copyNameHintAndDebugDecorations(debugVar, param); mapVarToDebugVar[param] = debugVar; @@ -52,6 +53,7 @@ namespace Slang ArrayView<IRInst*> accessChain; builder.emitDebugValue(debugVar, paramVal, accessChain); } + paramIndex++; } for (auto block : func->getBlocks()) @@ -80,8 +82,11 @@ namespace Slang // Collect all stores and insert debug value insts to update debug vars. for (auto block : func->getBlocks()) { - for (auto inst = block->getFirstInst(); inst; inst = inst->getNextInst()) + IRInst* nextInst = nullptr; + for (auto inst = block->getFirstInst(); inst; inst = nextInst) { + nextInst = inst->getNextInst(); + if (auto storeInst = as<IRStore>(inst)) { List<IRInst*> accessChain; @@ -89,10 +94,31 @@ namespace Slang IRInst* debugVar = nullptr; if (mapVarToDebugVar.tryGetValue(varInst, debugVar)) { - builder.setInsertBefore(storeInst); + builder.setInsertAfter(storeInst); builder.emitDebugValue(debugVar, storeInst->getVal(), accessChain.getArrayView()); } } + else if (auto callInst = as<IRCall>(inst)) + { + auto funcValue = getResolvedInstForDecorations(callInst->getCallee()); + if (!funcValue) + continue; + for (UInt i = 0; i < callInst->getArgCount(); i++) + { + auto arg = callInst->getArg(i); + if (!as<IRPtrTypeBase>(arg->getDataType())) + continue; + List<IRInst*> accessChain; + auto varInst = getRootAddr(arg, accessChain); + IRInst* debugVar = nullptr; + if (mapVarToDebugVar.tryGetValue(varInst, debugVar)) + { + builder.setInsertAfter(callInst); + auto loadVal = builder.emitLoad(arg); + builder.emitDebugValue(debugVar, loadVal, accessChain.getArrayView()); + } + } + } } } } diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 620695d46..a80f7fb29 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -3020,6 +3020,7 @@ struct IRDebugVar : IRInst IRInst* getSource() { return getOperand(0); } IRInst* getLine() { return getOperand(1); } IRInst* getCol() { return getOperand(2); } + IRInst* getArgIndex() { return getOperandCount() >= 4 ? getOperand(3) : nullptr; } }; struct IRDebugValue : IRInst @@ -3475,7 +3476,7 @@ public: IRInst* emitDebugSource(UnownedStringSlice fileName, UnownedStringSlice source); IRInst* emitDebugLine(IRInst* source, IRIntegerValue lineStart, IRIntegerValue lineEnd, IRIntegerValue colStart, IRIntegerValue colEnd); - IRInst* emitDebugVar(IRType* type, IRInst* source, IRInst* line, IRInst* col); + IRInst* emitDebugVar(IRType* type, IRInst* source, IRInst* line, IRInst* col, IRInst* argIndex = nullptr); IRInst* emitDebugValue(IRInst* debugVar, IRInst* debugValue, ArrayView<IRInst*> accessChain); /// Emit an LiveRangeStart instruction indicating the referenced item is live following this instruction diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp index 93715bc36..e164bd2c6 100644 --- a/source/slang/slang-ir-legalize-types.cpp +++ b/source/slang/slang-ir-legalize-types.cpp @@ -826,7 +826,8 @@ static LegalVal legalizeDebugVar(IRTypeLegalizationContext* context, LegalType t type.getSimple(), originalInst->getSource(), originalInst->getLine(), - originalInst->getCol()); + originalInst->getCol(), + originalInst->getArgIndex()); copyNameHintAndDebugDecorations(legalVal, originalInst); return LegalVal::simple(legalVal); } diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 68b002153..ff9c6f6f8 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3221,10 +3221,18 @@ namespace Slang }; return emitIntrinsicInst(getVoidType(), kIROp_DebugLine, 5, args); } - IRInst* IRBuilder::emitDebugVar(IRType* type, IRInst* source, IRInst* line, IRInst* col) + IRInst* IRBuilder::emitDebugVar(IRType* type, IRInst* source, IRInst* line, IRInst* col, IRInst* argIndex) { - IRInst* args[] = { source, line, col }; - return emitIntrinsicInst(type, kIROp_DebugVar, 3, args); + if (argIndex) + { + IRInst* args[] = { source, line, col, argIndex }; + return emitIntrinsicInst(type, kIROp_DebugVar, 4, args); + } + else + { + IRInst* args[] = { source, line, col }; + return emitIntrinsicInst(type, kIROp_DebugVar, 3, args); + } } IRInst* IRBuilder::emitDebugValue(IRInst* debugVar, IRInst* debugValue, ArrayView<IRInst*> accessChain) |
