llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.19k stars 12.04k forks source link

[DirectX] When lowering resources for library shaders, generate globals that are compatible with DXIL #75981

Open bogner opened 11 months ago

bogner commented 11 months ago

In DXIL, the resource metadata includes a ["Pointer to a global constant symbol with the original shape of resource and element type."(https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#metadata-resource-records). In a library shader, this is a global of %dx.types.Handle type that is bitcast in the metadata to a type based on the resource's template parameter:

%dx.types.Handle = type { i8* }
%"class.RWBuffer<float4>" = type { <4 x float> }
@"\01?In@@3V?$RWBuffer@V?$vector@M$03@@@@A" = external constant %dx.types.Handle, align 4

!... = !{i32 0, %"class.RWBuffer<vector<float, 4> >"* bitcast (%dx.types.Handle* @"\01?In@@3V?$RWBuffer@V?$vector@M$03@@@@A" to %"class.RWBuffer<vector<float, 4> >"*), !"", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, !...}

We should be able to recover the appropriate type from the [element type of our target extension type (https://llvm.org/docs/DirectX/DXILResources.html#buffers) during DXILResourceAnalysis. However, because of opaque pointers, the bitcast isn't really representable in modern LLVM. We'll need to find a way to pass the necessary information along until the DXIL bitcode writer can apply types to the pointers.

bogner commented 5 months ago

This will likely be done as part of #91366 but I'll leave this here as a check that we leave the right global symbol around when we emit metadata from that intrinsic.

Repurposed to track generating these types.