diff options
| author | Yong He <yonghe@outlook.com> | 2024-10-24 21:31:34 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-24 21:31:34 -0700 |
| commit | a2a201e327559e6a24b081fee73096b2a3b3e33f (patch) | |
| tree | b0b5ca96db7e95d364779cc4ca84936a02962534 /source/slang/slang-ir-insert-debug-value-store.cpp | |
| parent | 46b8ab8353966f2590ed2667028b220b57f963ae (diff) | |
Use DebugDeclare instead of DebugValue. (#5404)
* Use DebugDeclare instead of DebugValue.
* Avoid generating illegal SPIRV.
* Improve DebugLine output.
* Fix.
* Fix.
* Misc improvements.
Diffstat (limited to 'source/slang/slang-ir-insert-debug-value-store.cpp')
| -rw-r--r-- | source/slang/slang-ir-insert-debug-value-store.cpp | 51 |
1 files changed, 11 insertions, 40 deletions
diff --git a/source/slang/slang-ir-insert-debug-value-store.cpp b/source/slang/slang-ir-insert-debug-value-store.cpp index ee343b263..af86cb6dd 100644 --- a/source/slang/slang-ir-insert-debug-value-store.cpp +++ b/source/slang/slang-ir-insert-debug-value-store.cpp @@ -136,8 +136,7 @@ namespace Slang paramVal = builder.emitLoad(param); if (paramVal) { - ArrayView<IRInst*> accessChain; - builder.emitDebugValue(debugVar, paramVal, accessChain); + builder.emitDebugValue(debugVar, paramVal); } paramIndex++; } @@ -172,36 +171,11 @@ namespace Slang // Helper func to insert debugValue updates. auto setDebugValue = [&]( - IRInst* debugVar, IRInst* rootVar, IRInst* newValue, - ArrayView<IRInst*> accessChain, ArrayView<IRInst*> types) + IRInst* debugVar, 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 (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), types.head(i)); - auto compositeVal = builder.emitLoad(compositePtr); - builder.emitDebugValue(debugVar, compositeVal, accessChain.head(i)); + auto ptr = builder.emitElementAddress(debugVar, accessChain); + builder.emitDebugValue(ptr, newValue); }; for (auto block : func->getBlocks()) { @@ -213,26 +187,24 @@ namespace Slang if (auto storeInst = as<IRStore>(inst)) { List<IRInst*> accessChain; - List<IRInst*> types; - auto varInst = getRootAddr(storeInst->getPtr(), accessChain, &types); + auto varInst = getRootAddr(storeInst->getPtr(), accessChain); IRInst* debugVar = nullptr; if (mapVarToDebugVar.tryGetValue(varInst, debugVar)) { builder.setInsertAfter(storeInst); - setDebugValue(debugVar, varInst, storeInst->getVal(), accessChain.getArrayView(), types.getArrayView()); + setDebugValue(debugVar, storeInst->getVal(), accessChain.getArrayView()); } } else if (auto swizzledStore = as<IRSwizzledStore>(inst)) { List<IRInst*> accessChain; - List<IRInst*> types; - auto varInst = getRootAddr(swizzledStore->getDest(), accessChain, &types); + auto varInst = getRootAddr(swizzledStore->getDest(), accessChain); IRInst* debugVar = nullptr; if (mapVarToDebugVar.tryGetValue(varInst, debugVar)) { builder.setInsertAfter(swizzledStore); auto loadVal = builder.emitLoad(swizzledStore->getDest()); - setDebugValue(debugVar, varInst, loadVal, accessChain.getArrayView(), types.getArrayView()); + setDebugValue(debugVar, loadVal, accessChain.getArrayView()); } } else if (auto callInst = as<IRCall>(inst)) @@ -246,14 +218,13 @@ namespace Slang if (!as<IRPtrTypeBase>(arg->getDataType())) continue; List<IRInst*> accessChain; - List<IRInst*> types; - auto varInst = getRootAddr(arg, accessChain, &types); + auto varInst = getRootAddr(arg, accessChain); IRInst* debugVar = nullptr; if (mapVarToDebugVar.tryGetValue(varInst, debugVar)) { builder.setInsertAfter(callInst); auto loadVal = builder.emitLoad(arg); - setDebugValue(debugVar, varInst, loadVal, accessChain.getArrayView(), types.getArrayView()); + setDebugValue(debugVar, loadVal, accessChain.getArrayView()); } } } |
