-
Notifications
You must be signed in to change notification settings - Fork 596
spirv-opt: HLSL legalization moves function parameter DebugValue to wrong line/scope after inlining #6085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem is not inlining. Inlining correctly add the inlined at on the scope. The problem is that local single store elimination changes the DebugDeclare to a DebugValue because it is removing the variable. When doing that it uses the scope of the store. I believe this is wrong, but it is not obvious where it should get the scope from. The variable itself does not have a scope. We probably need to get it from the debug declare, but it is not immediately available. It is also unclear what to do if we have multiple debug declares. Off the top of my head I can't recall what the spec says about this. The problem is in this function: SPIRV-Tools/source/opt/local_single_store_elim_pass.cpp Lines 187 to 194 in feba06f
My first though is to modify this function to replace every debug declare with a separate debug value with the same scope. This happens at the point of the store. |
@sajjadmirzanv You probably have been insight than I do. Let me know what you think will work. Also, there are lots of DXC issues, with few maintainers. I don't know when I will get back to this. |
I agree, the pass should put the DebugValue where the DebugDeclare was, rather than where the OpStore was. Then it would automatically have the correct scope and line number.
Unfortunately, the spec doesn't say anything. But I think this change should be safe, since it would just convert them to DebugValue. |
@SteveUrquhart will be looking into this issue. |
spirv-opt converts the DebugDeclare instruction of a function parameter into a DebugValue with the actual value of the argument at the call site. However when it does this, it does not retain the DebugScope and DebugLine instructions for that DebugValue.
In the original HLSL I have a function "my_func" which is called from "main":
Pre-legalization SPIR-V:
After legalization inlines everything into one function:
Now the value is at line 15 instead of line 8, and the scope has changed to the "main" function.
The correct behavior would be for the DebugValue to keep the same position as the DebugDeclare even after inlining, and use a DebugScope with a DebugInlinedAt operand to represent that inlining happened.
Attaching the original HLSL shader for reference, but the main files to compare are
dxc_release_2025_02_20.notlegalized.spv
which has pre-legalization SPIR-V vs.dxc_release_2025_02_20.spv
andspvopt.legalized.spv
. The latter I generated withspirv-opt --legalize-hlsl
to confirm that the problem is specifically in spirv-opt.debug_legalization.zip
The text was updated successfully, but these errors were encountered: