microsoft / microsoft/DirectXShaderCompiler

Templated structs have invalid debug info.

Open
#6,251 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

The debug value mapping for templated structs map to the pointer of the struct, instead of the value of the struct.

Steps to Reproduce

Compile the following shader:

// /T ps_6_0 /Zi /Od
template<typename T>
struct S {
  T a, b;
  T Get() {
    return a + b;
  }
};


[RootSignature("")]
float main(float x : X, float y : Y, float z : Z, float w : W) : SV_Target {
  S<float> s;
  s.a = x;
  s.b = y;
  return s.Get();
}

Actual Behavior

You will see that the member b of variable s has the following mapping:

call void @llvm.dbg.value(metadata float %0, i64 0, metadata !53, metadata !58), !dbg !55 ; var:"this" !DIExpression(DW_OP_bit_piece, 32, 32) func:"Get"
!53 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: !8, type: !54)
!54 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 32, align: 32)
!9 = !DICompositeType(tag: DW_TAG_structure_type, name: "S<float>", file: !1, line: 4, size: 64, align: 32, elements: !10, templateParams: !17)

The expected behaviour should be that this variable should be a value type, like so:

call void @llvm.dbg.value(metadata float %0, i64 0, metadata !51, metadata !55), !dbg !52 ; var:"this" !DIExpression(DW_OP_bit_piece, 32, 32) func:"Get"
!51 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: !8, type: !9)
!9 = !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 11, size: 64, align: 32, elements: !10)

(This was done by compiling a non-templated version of struct S)

Environment

  • DXC version: Nightly
  • Host Operating System: Windows 11

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 compiling the provided HLSL shader with DXC using /T ps_6_0 /Zi /Od and inspect the emitted LLVM debug metadata for the templated struct. Compare it with the non-templated struct output; done means the this debug variable uses the structure value type rather than a pointer type.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.