Skip to content

[DirectX] Capture the "name of the resource variable" in DXIL resource analysis #105059

Open
@bogner

Description

@bogner

Currently the DXILResourceAnalysis gives a blank name to in the "name of the resource variable" field of the resource, which means it's always blank in the metadata. This is allowed in DXIL, but DXC only drops the name when we strip reflection data. We should capture the source name of the variable and emit it here.

This needs a little bit of thought, as exactly what mechanism to use to capture this has some trade offs. One option is to leverage debug info, which should work reasonably well (at least for globals) but we don't necessarily always have it available. Another is to capture this in specialized metadata for our purposes, but that feels like a bit of a hack.

The name of the resource variables show up in the resource binding table so that users can identify the resource bindings (if implicit). It is also useful for diagnostic like overlapping resource bindings, which looks like will need to be done in the LLVM backend after unused resources are eliminated.

RWBuffer<float4> A : register(u0);
RWBuffer<float4> B : register(u1);

[numthreads(4,1,1)]
void main() {
    A[0] = B[0];
}

DXC:

; Resource Bindings:
;
; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ------
; A                                     UAV     f32         buf      U0             u0     1
; B                                     UAV     f32         buf      U1             u1     1
...
!dx.resources = !{!33}
!33 = !{null, !34, null, null}
!34 = !{!35, !37}
!35 = !{i32 0, %"class.RWBuffer<vector<float, 4> >"* undef, !"A", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, !36}
!36 = !{i32 0, i32 9}
!37 = !{i32 1, %"class.RWBuffer<vector<float, 4> >"* undef, !"B", i32 0, i32 1, i32 1, i32 10, i1 false, i1 false, i1 false, !36}

Clang:

; Resource Bindings:
;
; Name                                 Type  Format         Dim      ID      HLSL Bind     Count
; ------------------------------ ---------- ------- ----------- ------- -------------- ---------
;                                       UAV     f32         buf      U0             u0         1
;                                       UAV     f32         buf      U1             u1         1
...
!dx.resources = !{!44}
!44 = !{null, !45, null, null}
!45 = !{!46, !48}
!46 = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, !47}
!47 = !{i32 0, i32 9}
!48 = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 10, i1 false, i1 false, i1 false, !47}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Active

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions