From a2a201e327559e6a24b081fee73096b2a3b3e33f Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 24 Oct 2024 21:31:34 -0700 Subject: Use DebugDeclare instead of DebugValue. (#5404) * Use DebugDeclare instead of DebugValue. * Avoid generating illegal SPIRV. * Improve DebugLine output. * Fix. * Fix. * Misc improvements. --- source/slang/slang-ir-insert-debug-value-store.cpp | 51 +++++----------------- 1 file changed, 11 insertions(+), 40 deletions(-) (limited to 'source/slang/slang-ir-insert-debug-value-store.cpp') 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 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 accessChain, ArrayView types) + IRInst* debugVar, IRInst* newValue, + ArrayView 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(accessChain[i])) - { - continue; - } - if (as(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(inst)) { List accessChain; - List 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(inst)) { List accessChain; - List 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(inst)) @@ -246,14 +218,13 @@ namespace Slang if (!as(arg->getDataType())) continue; List accessChain; - List 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()); } } } -- cgit v1.2.3