From cd50974490b82dd7e0f9ac0dd5ce9c17e390ff1f Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 9 Oct 2025 23:27:57 -0700 Subject: Update debug var when in-param proxy var is being updated. (#8671) Closes #8664. The problem is that when there is an `in` parameter, Slang will create a local variable to proxy the parameter, copy the value of the parameter into the proxy variable, and replace all uses of the parameter in the function body to use the proxy variable instead. This way all writes to the parameter become writes to the proxy variable. However, when there is debug info enabled, we are also going to create a "debugVariable" corresponding to the parameter, but this debugVariable isn't updated when the proxy variable is updated. The fix is to map the proxy var instead of the original param to the debug var during the `insertDebugValueStore` pass, so that any changes to the proxy var will result in additional stores being inserted to the debug var. Allowing function body to modify an `in` parameter is a bad legacy behavior we inherited from HLSL that we should really be moving away from. I would like us to completely treat an `in` parameter as immutable by default in the next language version (Slang 2026), and make it an error if the user tries to do so. This will allow us to generate much cleaner code and in many cases would help with performance. --- source/slang/slang-ir-insert-debug-value-store.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (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 91b7738f1..aeeb744ef 100644 --- a/source/slang/slang-ir-insert-debug-value-store.cpp +++ b/source/slang/slang-ir-insert-debug-value-store.cpp @@ -140,6 +140,17 @@ void DebugValueStoreContext::insertDebugValueStore(IRFunc* func) mapVarToDebugVar[param] = debugVar; + // Map any in-param proxy vars to the debug var. + bool hasProxyVar = false; + for (auto use = param->firstUse; use; use = use->nextUse) + { + if (auto inParamProxyVarDecor = as(use->getUser())) + { + mapVarToDebugVar[inParamProxyVarDecor->parent] = debugVar; + hasProxyVar = true; + } + } + // Store the initial value of the parameter into the debug var. IRInst* paramVal = nullptr; if (!isRefParam) @@ -153,7 +164,7 @@ void DebugValueStoreContext::insertDebugValueStore(IRFunc* func) paramVal = builder.emitLoad(param); } - if (paramVal) + if (paramVal && !hasProxyVar) { builder.emitDebugValue(debugVar, paramVal); } -- cgit v1.2.3