microsoft / microsoft/DirectXShaderCompiler

DXIL debug locations do not respect #line directives

Open
#4,615 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi, I'm working on a profiling tool that requires DXIL -> HLSL line mapping for low-level to high-level counters aggregating. However after dxc validator version >= 1.6, the debug locations from DXIL do not respect #line directives anymore. I think this issue is introduced from https://github.com/microsoft/DirectXShaderCompiler/pull/2991.

The HLSL source is also extracted from DXIL bytecode. When it has "#line" directives in it, we usually process the source and build virtual source files based on the line numbers followed "#line" directives, before we are able to display the HLSL source / DXIL text and the correlation between them on our UIs. However, when the debug locations do not respect "#line" directives, we have to display the unprocessed source on our UI, otherwise the correlation breaks.

At most cases (like UE4 game development), the processed sources (the virtual sources built from the extracted source of DXIL bytecode) are the original source files of developers and what's embedded in DXIL bytecode is a file merged by some tools before passing it to dxc. The change of dxc makes our displayed source less readable. So the virtual sources are more expected to be displayed to our users.

In my humble opinion, a regular compiler should always respect "#line" directives. And we always extract virtual sources for GLSL -> SPIRV (by glslc) and HLSL -> SPIRV (by dxc), so dxc (with version >= 1.6) compiling HLSL to DXIL is the only exception.

What I expect:

  • Restore the default behavior of "#line" locations processing.
  • If some clients of dxc need the locations of unprocessed source, add an option for dxc to do that.

Does this make sense?

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 reviewing the behavior change in pull request 2991 and reproduce the DXIL debug-location mapping with an HLSL source containing #line directives. Compare the resulting locations with the virtual source mapping described in the issue; done means default locations respect #line directives, with any unprocessed-source behavior explicitly handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.