Skip to content

Add NonSemantic.Shader.DebugInfo.100 options for Nvidia Nsight and/or RenderDoc source debugging - #1589

Open
DannyArends wants to merge 8 commits into
google:mainfrom
DannyArends:main
Open

DannyArends wants to merge 8 commits into
google:mainfrom
DannyArends:main

Conversation

@DannyArends

@DannyArends DannyArends commented Aug 1, 2026

Copy link
Copy Markdown

What

Adds two compile options that make shaderc emit NonSemantic.Shader.DebugInfo.100, equivalent to glslang's -gV / -gVS:

  • shaderc_compile_options_set_generate_nonsemantic_debug_info, equivalent to -gV
  • shaderc_compile_options_set_generate_nonsemantic_debug_source, equivalent to -gVS

Additionally, I have wired up matching CompileOptions::SetGenerateNonSemanticDebugInfo() / SetGenerateNonSemanticDebugSource() in the C++ wrapper.

Why

set_generate_debug_info only emits OpLine/OpSource (glslang -g). Tools like NVIDIA Nsight Graphics need NonSemantic.Shader.DebugInfo.100 for function- and call-site-level source correlation (Flame Graph, Top-Down/Bottom-Up Calls). shaderc had no way to request it (see #1391), so callers had to drop to glslang or dxc directly. The pull requests makes these new flag independent from generate_debug_info so plain -g stays available as a fallback for shaders that fail to compile withNonSemantic info enabled.

Usage: a Nsight-ready build

    shaderc_compile_options_t options = shaderc_compile_options_initialize();
    shaderc_compile_options_set_generate_debug_info(options);               // -g:   OpLine/OpSource
    shaderc_compile_options_set_generate_nonsemantic_debug_source(options); // -gVS: NonSemantic + source
    shaderc_compile_options_set_optimization_level(options, shaderc_optimization_level_zero);

-g provides the line table, -gVS provides the call graph; Nsight uses both. Optimization must stay at zero. The size/performance passes can mangle or strip NonSemantic info even with the strip-guards in place.

Notes

  • Build against glslang >= 15.0.0; earlier versions point every DebugFunction at the same file, corrupting name/line correlation.
  • Some shaders fail to compile with NonSemantic enabled; since the new flags are independent of -g, this is now a non-issue since builds need to opt in.

Add generate_nonsemantic_debug_info_ / _source_ to libshaderc_util's
Compiler, wired to glslang SpvOptions::emitNonSemanticShaderDebugInfo
and emitNonSemanticShaderDebugSource (equivalent to glslang -gV/-gVS).
Kept independent from generate_debug_info_ so plain -g stays available
as a fallback for shaders that fail to compile with NonSemantic info.

Enables function- and call-site-level source correlation in Nsight
Graphics (Flame Graph, Top-Down/Bottom-Up Calls), which the existing
-g-only path does not provide.

Extract the strip-pass unqueue loop into UnstripDebugInfoPasses() and
guard SetOptimizationLevel against stripping when either debug mode is on.
Wire SetGenerateNonSemanticDebugInfo / SetGenerateNonSemanticDebugSource
from libshaderc_util::Compiler up through the public API:
shaderc_compile_options_set_generate_nonsemantic_debug_{info,source} in
the C API, plus the matching CompileOptions methods in shaderc.hpp.

Mirrors the existing set_generate_debug_info plumbing. Lets callers
request glslang -gV/-gVS output (NonSemantic.Shader.DebugInfo.100) for
Nsight Graphics call-site correlation without dropping to internal headers.
@google-cla

google-cla Bot commented Aug 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@DannyArends

Copy link
Copy Markdown
Author

Update: I have signed the CLA, let me know if anything else is needed from my side.

Comment thread libshaderc_util/src/compiler.cc Outdated
for (size_t i = 0; i < enabled_opt_passes_.size(); ++i) {
if (enabled_opt_passes_[i] == PassId::kStripDebugInfo) {
enabled_opt_passes_[i] = PassId::kNullPass;
void Compiler::UnstripDebugInfoPasses() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name reads weirdly.

I'd prefer: RemoveStripDebugInfoPass.

Not a huge issue though.

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should also include a command-line option on glslc, and please at least one unit test for each option, and glslc-based tests.

@DannyArends

DannyArends commented Sep 5, 2026

Copy link
Copy Markdown
Author

Thanks for the review @dneto0.

I've pushed changes addressing all points raised:

  • Renamed UnstripDebugInfoPasses to RemoveStripDebugInfoPass.
  • Added -gV and -gVS to glslc, with matching --help entries (updated the HelpParameters test output to match).
  • Added unit tests for each option at both the C and C++ API layers, asserting that NonSemantic.Shader.DebugInfo.100 is imported in the disassembly.
  • Added glslc-based tests: OptionGV checks the import, and OptionGVS checks the import plus a source-bearing DebugSource.

A minor note on the OptionGVS test: both -gV and -gVS emit a DebugSource. The only structural difference is that -gVS adds a second operand (the embedded-source OpString). The test asserts two operands with an ID-independent regex (DebugSource %\w+ %\w+) rather than just matching on the source substring (which on its own isn't a reliable discriminator). Happy to adjust if you'd prefer a different approach.

I ran ctest --output-on-failure and everything passes locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants