summaryrefslogtreecommitdiffstats
path: root/tests/spirv
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-10-09 23:27:57 -0700
committerGitHub <noreply@github.com>2025-10-10 06:27:57 +0000
commitcd50974490b82dd7e0f9ac0dd5ce9c17e390ff1f (patch)
tree3206340b7c970e2d50f36c91af858c5277a17427 /tests/spirv
parenta3372605363cfe511b5248cb1393f59b25cb2483 (diff)
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.
Diffstat (limited to 'tests/spirv')
-rw-r--r--tests/spirv/debug-store.slang33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/spirv/debug-store.slang b/tests/spirv/debug-store.slang
new file mode 100644
index 000000000..dd1847f56
--- /dev/null
+++ b/tests/spirv/debug-store.slang
@@ -0,0 +1,33 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -g2 -O0
+
+// Test that writes to stand-in proxy variables for an `in` parameter are
+// properly updating the corresponding debug variable for the parameter when
+// debug info is enabled.
+
+//CHECK-COUNT-4: OpStore %_dbgvar_func_value
+
+cbuffer CBuffer
+{
+ float x;
+} cb;
+
+float Func(float func_value)
+{
+ func_value = func_value > 10.0f ? func_value + 1.0f : func_value - 1.0f;
+ func_value = sqrt(func_value);
+ func_value = sin(func_value);
+
+ return func_value;
+}
+
+RWBuffer<float> outbuf;
+
+[numthreads(1, 1, 1)]
+void main()
+{
+ float value = cb.x;
+
+ value = Func(cb.x);
+
+ outbuf[0] = value;
+}