Skip to content

[HLSL] Eliminate resource global variables from module #104271

@hekota

Description

@hekota

Global variables that represent shader resources need to be stripped from the final DXIL module, and accesses to resources need to happen locally rather than by round tripping through loads and stores of the global.

We'll need to either write a specific pass to eliminate global accesses to the resource (which needs to happen after inlining), or augment EarlyCSE and/or GVN to do so for us.

For example in this simple shader, we may end up with IR like so before lowering to DXIL ops:

  %In_h.i = tail call target("dx.TypedBuffer", <4 x float>, 1, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0t(i32 0, i32 0, i32 1, i32 0, i1 false)
  store target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %In_h.i, ptr @In, align 4
...
  %1 = tail call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %In_h.i, i32 %0)
...
  %2 = load target("dx.TypedBuffer", <4 x float>, 1, 0, 0), ptr @In, align 4, !tbaa !4, !noalias !8
  %3 = tail call noundef <4 x float> @llvm.dx.typedBufferLoad.v4f32.tdx.TypedBuffer_v4f32_1_0_0t(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %2, i32 %0)

Here, the store to @In and the load from the same for the argument to typedBufferLoad need to be eliminated. Note that in this case EarlyCSE was able to eliminate the load in the first call to typedBufferLoad but not the second.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions