[llvm] Set shader analysis flag EnableRawAndStructuredBuffers for RawBuffer and StructuredBuffer resource types (PR #114449)

Tex Riddell via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 15:53:26 PST 2024


================
@@ -0,0 +1,23 @@
+; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.3-compute"
+
+ at G = external constant <4 x float>, align 4
+
+define void @test_bufferflags() {
+
+  ; ByteAddressBuffer Buf : register(t8, space1)
+  %srv0 = call target("dx.RawBuffer", i8, 0, 0)
+      @llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
+          i32 1, i32 8, i32 1, i32 0, i1 false)
+
+  ret void
+}
+
+attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
+
+; CHECK: ; Shader Flags Value: 0x00000010
+; CHECK: ; Note: shader requires additional functionality:
+; CHECK-NEXT: ; Note: extra DXIL module flags:
+; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
----------------
tex3d wrote:

This isn't one of the optional feature flags used by the runtime.  So, it should not have a comment saying "shader requires additional functionality".  You can tell which flags should be reported under this statement by looking at the ones set in [the ShaderFlags::GetFeatureInfo method in DxilShaderFlags.cpp in DXC](https://github.com/microsoft/DirectXShaderCompiler/blob/ac36a797d3470e8ee906b98457a59270d01db30d/lib/DXIL/DxilShaderFlags.cpp#L55).

Instead, this flag mirrors a global flag that was set in the DXBC dcl_globalFlags instruction token: `D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS`.  This value this identifier is defined to in the DXBC token stream is not the same value as in the DXIL Shader Flags, so that could be a bit confusing to write that out here as the flag name.

Additionally: It turns out that this flag is only generated for SRV raw/structured buffers on `ps_4_0` or `ps_4_1`.  UAV's not allowed for those targets at all.

It only exists in DXIL as the way to preserve this DXBC flag when we were writing the initial version of the DXBC to DXIL converter (DxilConv.dll), which originally would try to preserve the shader model and any flags set in the original DXBC.

So due to these limitations, I believe we shouldn't ever need to set this flag for DXIL in this compiler after all.

https://github.com/llvm/llvm-project/pull/114449


More information about the llvm-commits mailing list