diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp index e24b8b5e8e594f..5df9ed518436f8 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp @@ -48,19 +48,37 @@ static void updateResourceFlags(ComputedShaderFlags &Flags, Module &M, if (DRM.empty()) return; - const dxil::ModuleMetadataInfo &MMDI = AM->getResult(M); - VersionTuple SM = MMDI.ShaderModelVersion; - Triple::EnvironmentType SP = MMDI.ShaderProfile; - - // RWBuffer for (const ResourceInfo &RI : DRM.uavs()) { - if (RI.getResourceKind() == ResourceKind::TypedBuffer) { + switch (RI.getResourceKind()) { + case ResourceKind::RawBuffer: + case ResourceKind::StructuredBuffer: Flags.EnableRawAndStructuredBuffers = true; - Flags.ComputeShadersPlusRawAndStructuredBuffers = - (SP == Triple::EnvironmentType::Compute && SM.getMajor() == 4); + break; + default: break; } } + + for (const ResourceInfo &RI : DRM.srvs()) { + switch (RI.getResourceKind()) { + case ResourceKind::RawBuffer: + case ResourceKind::StructuredBuffer: + Flags.EnableRawAndStructuredBuffers = true; + break; + default: + break; + } + } + + if (Flags.EnableRawAndStructuredBuffers) { + const dxil::ModuleMetadataInfo &MMDI = + AM->getResult(M); + VersionTuple SM = MMDI.ShaderModelVersion; + Triple::EnvironmentType SP = MMDI.ShaderProfile; + + Flags.ComputeShadersPlusRawAndStructuredBuffers = + (SP == Triple::EnvironmentType::Compute && SM.getMajor() == 4); + } } ComputedShaderFlags diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/buffers.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/buffer.ll similarity index 69% rename from llvm/test/CodeGen/DirectX/ShaderFlags/buffers.ll rename to llvm/test/CodeGen/DirectX/ShaderFlags/buffer.ll index 93346c2d5587db..c31ecbf4385d95 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/buffers.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/buffer.ll @@ -6,18 +6,18 @@ target triple = "dxil-pc-shadermodel6.3-compute" define void @test_bufferflags() { - ; RWBuffer Buf : register(u7, space2) - %uav0 = call target("dx.TypedBuffer", i32, 1, 0, 1) - @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t( - i32 2, i32 7, i32 1, i32 0, i1 false) + ; 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 ; CHECK-NEXT: {{^;$}} - - ret void -} - -attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) } diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/buffers_cs4.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/buffer_cs4.ll similarity index 71% rename from llvm/test/CodeGen/DirectX/ShaderFlags/buffers_cs4.ll rename to llvm/test/CodeGen/DirectX/ShaderFlags/buffer_cs4.ll index 21b05e4ef59a22..574dd652f4e890 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/buffers_cs4.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/buffer_cs4.ll @@ -6,10 +6,15 @@ target triple = "dxil-pc-shadermodel4.0-compute" define void @test_bufferflags() { - ; RWBuffer Buf : register(u7, space2) - %uav0 = call target("dx.TypedBuffer", i32, 1, 0, 1) - @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t( - i32 2, i32 7, i32 1, i32 0, i1 false) + ; 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: 0x00020010 ; CHECK: ; Note: shader requires additional functionality: @@ -17,8 +22,3 @@ define void @test_bufferflags() { ; CHECK-NEXT: ; Note: extra DXIL module flags: ; CHECK-NEXT: ; D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS ; CHECK-NEXT: {{^;$}} - - ret void -} - -attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) } diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/rwbuffer.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/rwbuffer.ll new file mode 100644 index 00000000000000..5cbe79305329f0 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/rwbuffer.ll @@ -0,0 +1,23 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +target triple = "dxil-pc-shadermodel6.3-compute" + +@G = external constant <4 x float>, align 4 + +define void @test_bufferflags() { + + ; RWByteAddressBuffer Buf : register(u8, space1) + %uav0 = call target("dx.RawBuffer", i8, 1, 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 +; CHECK-NEXT: {{^;$}} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/rwstructuredbuffer.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/rwstructuredbuffer.ll new file mode 100644 index 00000000000000..e442c01c628860 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/rwstructuredbuffer.ll @@ -0,0 +1,24 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +target triple = "dxil-pc-shadermodel6.7-library" + +@G = external constant <4 x float>, align 4 + +define void @test_bufferflags() { + + ; struct S { float4 a; uint4 b; }; + ; RWStructuredBuffer Buf : register(u2, space4) + %struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 1, 0) + @llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t( + i32 4, i32 2, i32 1, i32 10, i1 true) + + 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 +; CHECK-NEXT: {{^;$}} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/structuredbuffer.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/structuredbuffer.ll new file mode 100644 index 00000000000000..e45eaaec652a65 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/structuredbuffer.ll @@ -0,0 +1,24 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +target triple = "dxil-pc-shadermodel6.7-library" + +@G = external constant <4 x float>, align 4 + +define void @test_bufferflags() { + + ; struct S { float4 a; uint4 b; }; + ; StructuredBuffer Buf : register(t2, space4) + %struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0) + @llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t( + i32 4, i32 2, i32 1, i32 10, i1 true) + + 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 +; CHECK-NEXT: {{^;$}}