diff options
Diffstat (limited to 'source/slang/slang-ir-insert-debug-value-store.cpp')
| -rw-r--r-- | source/slang/slang-ir-insert-debug-value-store.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/source/slang/slang-ir-insert-debug-value-store.cpp b/source/slang/slang-ir-insert-debug-value-store.cpp index 8aad3e417..6243e6c09 100644 --- a/source/slang/slang-ir-insert-debug-value-store.cpp +++ b/source/slang/slang-ir-insert-debug-value-store.cpp @@ -80,6 +80,38 @@ namespace Slang } // Collect all stores and insert debug value insts to update debug vars. + + // Helper func to insert debugValue updates. + auto setDebugValue = [&](IRInst* debugVar, IRInst* rootVar, IRInst* newValue, ArrayView<IRInst*> accessChain) + { + // SPIRV does not allow dynamic indices in DebugValue, + // so we need to stop the access chain at the first dynamic index. + Index i = 0; + for (; i < accessChain.getCount(); i++) + { + if (auto key = as<IRStructKey>(accessChain[i])) + { + continue; + } + if (as<IRIntLit>(accessChain[i])) + { + continue; + } + break; + } + // If everything is static on the access chain, we can simply emit a DebugValue. + if (i == accessChain.getCount()) + { + builder.emitDebugValue(debugVar, newValue, accessChain); + return; + } + + // Otherwise we need to load the entire composite value starting at the dynamic index access chain + // and set it. + auto compositePtr = builder.emitElementAddress(rootVar, accessChain.head(i)); + auto compositeVal = builder.emitLoad(compositePtr); + builder.emitDebugValue(debugVar, compositeVal, accessChain.head(i)); + }; for (auto block : func->getBlocks()) { IRInst* nextInst = nullptr; @@ -95,7 +127,7 @@ namespace Slang if (mapVarToDebugVar.tryGetValue(varInst, debugVar)) { builder.setInsertAfter(storeInst); - builder.emitDebugValue(debugVar, storeInst->getVal(), accessChain.getArrayView()); + setDebugValue(debugVar, varInst, storeInst->getVal(), accessChain.getArrayView()); } } else if (auto callInst = as<IRCall>(inst)) @@ -115,7 +147,7 @@ namespace Slang { builder.setInsertAfter(callInst); auto loadVal = builder.emitLoad(arg); - builder.emitDebugValue(debugVar, loadVal, accessChain.getArrayView()); + setDebugValue(debugVar, varInst, loadVal, accessChain.getArrayView()); } } } |
