microsoft / microsoft/DirectXShaderCompiler

Standardize #line handling in dxcompiler

Open
#8,679 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Hi HLSL Team!

Hope everyone's doing well, it's been a while! On behalf of Nvidia, I'd like to revisit how the compiler handles #line directives in debug info, originally raised in https://github.com/microsoft/DirectXShaderCompiler/issues/4615. It's still causing problems for our shader tooling.

#line N "file" is meant to remap source locations back to the original authored file and line after preprocessing has flattened #include's, which is exactly what shader build systems like Unreal do. Clang, GCC and MSVC all honour it in their line tables, as does DXC's own SPIR-V backend. The normal DXIL path is the exception: it keeps the un-preprocessed source and line numbers, so downstream tools have to re-parse the embedded source to reconstruct the intended mapping.

The shader profiler and Aftermath could work around this because they only need a line table. A full source-level debugger can't, since it relies on the debug info being the source of truth, and source references are spread across more of the DWARF than just the line table. Reconstructing all of that downstream isn't really viable in the debugger core, which is shared with the CUDA debugger and works on standard ELF/DWARF. As we bring that same source-level debugging experience to DirectX, standard #line handling stops being something we can work around.

I understand dxcompiler is in maintenance mode and change in default behaviour is unlikely, so here are two proposals:

  1. Near term: an opt-in flag for standard #line handling in the DXIL debug metadata, so it doesn't affect anyone relying on today's behaviour. That alone would unblock us and let developers make use of our tools. I'd be happy to draft a PR for this.

  2. Longer term: since the HLSL/Clang modernization effort is aiming for standards alignment, it would be good to make standard #line semantics the default there from the start.

Thanks,
Adam

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the normal DXIL path emits debug metadata and compare its handling of #line directives with DXC's SPIR-V backend. Define the opt-in behavior so standard source mappings are available without changing the current default. Done means DXIL debug metadata preserves the authored file and line mappings needed by source-level debuggers.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.