Skip to content

[SPIRV] Generate DebugFunctionDefinition in real function instead of wrapper - #6758

Merged
Steven Perron (s-perron) merged 1 commit into
microsoft:mainfrom
SteveUrquhart:fix-debugfunctiondefinition
Aug 7, 2024
Merged

Steven Perron (s-perron) merged 1 commit into
microsoft:mainfrom
SteveUrquhart:fix-debugfunctiondefinition

Conversation

@SteveUrquhart

Copy link
Copy Markdown
Contributor

This PR moves the DebugFunctionDefinition instruction from the SPIR-V wrapper to the real function. This supplies debugger users with greater accuracy.

@SteveUrquhart
Steve Urquhart (SteveUrquhart) requested a review from a team as a code owner July 9, 2024 22:46
@SteveUrquhart

Copy link
Copy Markdown
Contributor Author

The purpose of debug info is to connect the original source code to the corresponding machine code. In this case, the SPIR-V function that corresponds to HLSL's main function is %src_main, not %main. %main is just wrapper code inserted by dxc. By analogy: when debugging a C program the user wants to start at main, even though technically the program begins at an implementation-specific entry point like _start.

Furthermore, putting the DebugFunctionDefinition into %main breaks other debug info. For example, in the following shader:

%25 = OpExtInst %void %1 DebugFunction %23 %16 %18 %uint_1 %uint_1 %19 %24 %uint_3 %uint_2
%27 = OpExtInst %void %1 DebugLexicalBlock %18 %uint_2 %uint_1 %25
%29 = OpExtInst %void %1 DebugLocalVariable %28 %13 %18 %uint_3 %uint_11 %27 %uint_4
%33 = OpExtInst %void %1 DebugEntryPoint %25 %19 %31 %32
%main = OpFunction %void None %34
%35 = OpLabel
%36 = OpExtInst %void %1 DebugFunctionDefinition %25 %main

The real function will refer to DebugLocalVariable %29, which points to the DebugFunction %25, but the DebugFunctionDefinition that points to %25 is in %main.

@s-perron
Steven Perron (s-perron) enabled auto-merge (squash) July 19, 2024 16:25
@s-perron
Steven Perron (s-perron) merged commit 1e78247 into microsoft:main Aug 7, 2024
Steven Perron (s-perron) pushed a commit that referenced this pull request Nov 19, 2024
…ions (#6966)

#6758
unfortunately caused a regression for shaders compiled without -fcgl.
This PR extends the original fix and corrects the regression. We now
emit DebugFunction and DebugFunctionDefinition pairs for both the
wrapper and the main functions, and a DebugEntrypoint that points at the
wrapper function. This survives inlining.
Mxr (SjMxr233) pushed a commit to ShaderHelper/DirectXShaderCompiler that referenced this pull request Jul 24, 2025
…wrapper (microsoft#6758)

This PR moves the DebugFunctionDefinition instruction from the SPIR-V
wrapper to the real function. This supplies debugger users with greater
accuracy.
Mxr (SjMxr233) pushed a commit to ShaderHelper/DirectXShaderCompiler that referenced this pull request Jul 24, 2025
…ions (microsoft#6966)

microsoft#6758
unfortunately caused a regression for shaders compiled without -fcgl.
This PR extends the original fix and corrects the regression. We now
emit DebugFunction and DebugFunctionDefinition pairs for both the
wrapper and the main functions, and a DebugEntrypoint that points at the
wrapper function. This survives inlining.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants