From 8342b32585317036bf075bf884dd6b813eddd029 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Wed, 23 Apr 2025 21:06:22 +0000 Subject: [PATCH 1/7] Implement UAVsAtEveryStage shader flag --- llvm/lib/Target/DirectX/DXILShaderFlags.cpp | 20 ++++++++++ .../ShaderFlags/max-64-uavs-array-sm6_5.ll | 5 +++ .../ShaderFlags/max-64-uavs-array-sm6_6.ll | 5 +++ .../DirectX/ShaderFlags/max-64-uavs.ll | 5 +++ .../DirectX/ShaderFlags/res-may-alias-0.ll | 5 +++ .../DirectX/ShaderFlags/res-may-alias-1.ll | 6 ++- .../res-may-not-alias-shadermodel6.6.ll | 5 +++ .../res-may-not-alias-shadermodel6.7.ll | 5 +++ .../res-may-not-alias-shadermodel6.8.ll | 5 +++ .../typed-uav-load-additional-formats.ll | 5 +++ .../uavs-at-every-stage-lib-valver1.7.ll | 39 ++++++++++++++++++ .../uavs-at-every-stage-lib-valver1.8.ll | 29 ++++++++++++++ .../ShaderFlags/uavs-at-every-stage-vs.ll | 40 +++++++++++++++++++ 13 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp index 282b9dcf6de2b..aa140330c61bb 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp @@ -265,6 +265,26 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, NumUAVs += UAV.getBinding().Size; if (NumUAVs > 8) CombinedSFMask.Max64UAVs = true; + + // Set UAVsAtEveryStage flag based on the presence of UAVs, the shader + // model version, and the shader environment + if (!DRM.uavs().empty()) { + if (MMDI.ValidatorVersion < VersionTuple(1, 8)) + CombinedSFMask.UAVsAtEveryStage = + MMDI.ShaderProfile != Triple::EnvironmentType::Compute && + MMDI.ShaderProfile != Triple::EnvironmentType::Pixel; + else // MMDI.ValidatorVersion >= VersionTuple(1, 8) + switch (MMDI.ShaderProfile) { + default: + break; + case Triple::EnvironmentType::Vertex: + case Triple::EnvironmentType::Hull: + case Triple::EnvironmentType::Domain: + case Triple::EnvironmentType::Geometry: + CombinedSFMask.UAVsAtEveryStage = true; + break; + } + } } void ComputedShaderFlags::print(raw_ostream &OS) const { diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll index 5b978d67866be..b476cab236cb3 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll @@ -29,5 +29,10 @@ define void @test() "hlsl.export" { ret void } +; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and +; UAVsAtEveryStage from being set, as to not distract from the flag that is +; actually being tested !llvm.module.flags = !{!0} +!dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} +!1 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll index 4b901a78e6ea4..6c2b82a85188e 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll @@ -29,5 +29,10 @@ define void @test() "hlsl.export" { ret void } +; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and +; UAVsAtEveryStage from being set, as to not distract from the flag that is +; actually being tested !llvm.module.flags = !{!0} +!dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} +!1 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll index c002ff2851452..9045f75ef33c1 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll @@ -56,5 +56,10 @@ define void @test() "hlsl.export" { ret void } +; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and +; UAVsAtEveryStage from being set, as to not distract from the flag that is +; actually being tested !llvm.module.flags = !{!0} +!dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} +!1 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll index d15b5c7b61984..6996ccc59c204 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll @@ -40,4 +40,9 @@ define float @loadSRV() #0 { ; But if it does, ensure that it has no effect. !0 = !{i32 1, !"dx.resmayalias", i32 0} +; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not +; distract from the flag that is actually being tested +!dx.valver = !{!1} +!1 = !{i32 1, i32 8} + attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll index edd3250a2db0d..c4f9ab498bddf 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll @@ -35,7 +35,11 @@ define float @loadSRV() #0 { } !llvm.module.flags = !{!0} - !0 = !{i32 1, !"dx.resmayalias", i32 1} +; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not +; distract from the flag that is actually being tested +!dx.valver = !{!1} +!1 = !{i32 1, i32 8} + attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll index da7c4c619790c..e2f1155b26063 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll @@ -34,4 +34,9 @@ define float @loadSRV() #0 { ret float %val } +; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not +; distract from the flag that is actually being tested +!dx.valver = !{!0} +!0 = !{i32 1, i32 8} + attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll index 87a76162f734e..c6358473ff2e4 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll @@ -35,4 +35,9 @@ define float @loadSRV() #0 { ret float %val } +; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not +; distract from the flag that is actually being tested +!dx.valver = !{!0} +!0 = !{i32 1, i32 8} + attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll index a309d8ecea56c..10eb7a878e5c4 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll @@ -35,4 +35,9 @@ define float @loadSRV() #0 { ret float %val } +; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not +; distract from the flag that is actually being tested +!dx.valver = !{!0} +!0 = !{i32 1, i32 8} + attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll index 1bb8a4d78eb16..dd42bb73e9bdd 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll @@ -43,8 +43,13 @@ define void @noload(<4 x float> %val) #0 { ret void } +; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and +; UAVsAtEveryStage from being set, as to not distract from the flag that is +; actually being tested !llvm.module.flags = !{!0} +!dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} +!1 = !{i32 1, i32 8} attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll new file mode 100644 index 0000000000000..5db3b32deee62 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll @@ -0,0 +1,39 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s +; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC + +; This test ensures that a library shader with a UAV gets the module and +; shader feature flag UAVsAtEveryStage when the DXIL validator version is < 1.8 + +target triple = "dxil-pc-shadermodel6.5-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x00010000 + +; CHECK: Note: shader requires additional functionality: +; CHECK: UAVs at every shader stage + +; CHECK: Function test : 0x00000000 +define void @test() "hlsl.export" { + ; RWBuffer Buf : register(u0, space0) + %buf0 = call target("dx.TypedBuffer", float, 1, 0, 1) + @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0t( + i32 0, i32 0, i32 1, i32 0, i1 false) + ret void +} + +!dx.valver = !{!1} +!1 = !{i32 1, i32 7} + +; Set dx.resmayalias to prevent the shader flag ResMayNotAlias from being set, +; as to not distract from the shader flag that is actually being tested +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"dx.resmayalias", i32 1} + +; DXC: - Name: SFI0 +; DXC-NEXT: Size: 8 +; DXC-NEXT: Flags: +; DXC-NOT: {{[A-Za-z]+: +true}} +; DXC: UAVsAtEveryStage: true +; DXC-NOT: {{[A-Za-z]+: +true}} +; DXC: NextUnusedBit: false +; DXC: ... diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll new file mode 100644 index 0000000000000..98c2e833f4aee --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll @@ -0,0 +1,29 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +; This test ensures that a library shader with a UAV does not get the module and +; shader feature flag UAVsAtEveryStage when the DXIL validator version is >= 1.8 + +target triple = "dxil-pc-shadermodel6.5-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x00000000 + +; CHECK-NOT: Note: shader requires additional functionality: +; CHECK-NOT: UAVs at every shader stage + +; CHECK: Function test : 0x00000000 +define void @test() "hlsl.export" { + ; RWBuffer Buf : register(u0, space0) + %buf0 = call target("dx.TypedBuffer", float, 1, 0, 1) + @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0t( + i32 0, i32 0, i32 1, i32 0, i1 false) + ret void +} + +!dx.valver = !{!1} +!1 = !{i32 1, i32 8} + +; Set dx.resmayalias to prevent the shader flag ResMayNotAlias from being set, +; as to not distract from the shader flag that is actually being tested +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll new file mode 100644 index 0000000000000..4aeddf08f6a8b --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll @@ -0,0 +1,40 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s +; TODO: Remove this comment and add 'RUN' to the line below once vertex shaders are supported by llc +; llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC + +; This test ensures that a Vertex shader with a UAV gets the module and +; shader feature flag UAVsAtEveryStage + +target triple = "dxil-pc-shadermodel6.5-vertex" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x00010000 + +; CHECK: Note: shader requires additional functionality: +; CHECK: UAVs at every shader stage + +; CHECK: Function test : 0x00000000 +define void @test() "hlsl.export" { + ; RWBuffer Buf : register(u0, space0) + %buf0 = call target("dx.TypedBuffer", float, 1, 0, 1) + @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0t( + i32 0, i32 0, i32 1, i32 0, i1 false) + ret void +} + +!dx.valver = !{!1} +!1 = !{i32 1, i32 8} + +; Set dx.resmayalias to prevent the shader flag ResMayNotAlias from being set, +; as to not distract from the shader flag that is actually being tested +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"dx.resmayalias", i32 1} + +; DXC: - Name: SFI0 +; DXC-NEXT: Size: 8 +; DXC-NEXT: Flags: +; DXC-NOT: {{[A-Za-z]+: +true}} +; DXC-NEXT: UAVsAtEveryStage: true +; DXC-NOT: {{[A-Za-z]+: +true}} +; DXC: NextUnusedBit: false +; DXC: ... From 1f11675d444e81e4d7d3e194a2d6259dbc516341 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Thu, 24 Apr 2025 15:45:10 +0000 Subject: [PATCH 2/7] Change vertex shader test function name and remove hlsl.export from it --- .../CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll index 4aeddf08f6a8b..f0a9d0762d999 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll @@ -13,8 +13,8 @@ target triple = "dxil-pc-shadermodel6.5-vertex" ; CHECK: Note: shader requires additional functionality: ; CHECK: UAVs at every shader stage -; CHECK: Function test : 0x00000000 -define void @test() "hlsl.export" { +; CHECK: Function VSMain : 0x00000000 +define void @VSMain() { ; RWBuffer Buf : register(u0, space0) %buf0 = call target("dx.TypedBuffer", float, 1, 0, 1) @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0t( From 5955a67bfa42b3afb38717b4bdb2e85621fbe9e6 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Fri, 25 Apr 2025 19:08:05 +0000 Subject: [PATCH 3/7] Simplify the logic for setting UAVsAtEveryStage - Move the logic for setting UAVsAtEveryStage out into its own function to not increase the length of ModuleShaderFlags::initialize - Use one switch statement to handle both special cases with regards to DXIL validator version Co-authored-by: Justin Bogner --- llvm/lib/Target/DirectX/DXILShaderFlags.cpp | 48 +++++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp index aa140330c61bb..dc26d9f6efb2a 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp @@ -32,6 +32,34 @@ using namespace llvm; using namespace llvm::dxil; +static bool hasUAVsAtEveryStage(DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI) { + if (DRM.uavs().empty()) + return false; + + switch (MMDI.ShaderProfile) { + default: + return false; + case Triple::EnvironmentType::Compute: + case Triple::EnvironmentType::Pixel: + return false; + case Triple::EnvironmentType::Vertex: + case Triple::EnvironmentType::Geometry: + case Triple::EnvironmentType::Hull: + case Triple::EnvironmentType::Domain: + return true; + case Triple::EnvironmentType::Library: + case Triple::EnvironmentType::RayGeneration: + case Triple::EnvironmentType::Intersection: + case Triple::EnvironmentType::AnyHit: + case Triple::EnvironmentType::ClosestHit: + case Triple::EnvironmentType::Miss: + case Triple::EnvironmentType::Callable: + case Triple::EnvironmentType::Mesh: + case Triple::EnvironmentType::Amplification: + return MMDI.ValidatorVersion < VersionTuple(1, 8); + } +} + static bool checkWaveOps(Intrinsic::ID IID) { // Currently unsupported intrinsics // case Intrinsic::dx_wave_getlanecount: @@ -266,25 +294,7 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, if (NumUAVs > 8) CombinedSFMask.Max64UAVs = true; - // Set UAVsAtEveryStage flag based on the presence of UAVs, the shader - // model version, and the shader environment - if (!DRM.uavs().empty()) { - if (MMDI.ValidatorVersion < VersionTuple(1, 8)) - CombinedSFMask.UAVsAtEveryStage = - MMDI.ShaderProfile != Triple::EnvironmentType::Compute && - MMDI.ShaderProfile != Triple::EnvironmentType::Pixel; - else // MMDI.ValidatorVersion >= VersionTuple(1, 8) - switch (MMDI.ShaderProfile) { - default: - break; - case Triple::EnvironmentType::Vertex: - case Triple::EnvironmentType::Hull: - case Triple::EnvironmentType::Domain: - case Triple::EnvironmentType::Geometry: - CombinedSFMask.UAVsAtEveryStage = true; - break; - } - } + CombinedSFMask.UAVsAtEveryStage = hasUAVsAtEveryStage(DRM, MMDI); } void ComputedShaderFlags::print(raw_ostream &OS) const { From f6410d02655ffb05221c9e2cf34d20ecd140afe6 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Fri, 25 Apr 2025 20:11:39 +0000 Subject: [PATCH 4/7] Remove repeated comments among tests --- .../CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll | 3 --- .../CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll | 3 --- llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll | 3 --- llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll | 2 -- llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll | 2 -- .../DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll | 2 -- .../DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll | 2 -- .../DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll | 2 -- .../DirectX/ShaderFlags/typed-uav-load-additional-formats.ll | 3 --- .../DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll | 2 -- .../DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll | 2 -- .../test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll | 2 -- 12 files changed, 28 deletions(-) diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll index b476cab236cb3..4259491610a38 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_5.ll @@ -29,9 +29,6 @@ define void @test() "hlsl.export" { ret void } -; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and -; UAVsAtEveryStage from being set, as to not distract from the flag that is -; actually being tested !llvm.module.flags = !{!0} !dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll index 6c2b82a85188e..6fa0025010f51 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-sm6_6.ll @@ -29,9 +29,6 @@ define void @test() "hlsl.export" { ret void } -; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and -; UAVsAtEveryStage from being set, as to not distract from the flag that is -; actually being tested !llvm.module.flags = !{!0} !dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll index 9045f75ef33c1..30b974c61598a 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs.ll @@ -56,9 +56,6 @@ define void @test() "hlsl.export" { ret void } -; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and -; UAVsAtEveryStage from being set, as to not distract from the flag that is -; actually being tested !llvm.module.flags = !{!0} !dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll index 6996ccc59c204..36182a9bc0dde 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll @@ -40,8 +40,6 @@ define float @loadSRV() #0 { ; But if it does, ensure that it has no effect. !0 = !{i32 1, !"dx.resmayalias", i32 0} -; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not -; distract from the flag that is actually being tested !dx.valver = !{!1} !1 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll index c4f9ab498bddf..111873267d9a4 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll @@ -37,8 +37,6 @@ define float @loadSRV() #0 { !llvm.module.flags = !{!0} !0 = !{i32 1, !"dx.resmayalias", i32 1} -; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not -; distract from the flag that is actually being tested !dx.valver = !{!1} !1 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll index e2f1155b26063..067ee18b2d72f 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll @@ -34,8 +34,6 @@ define float @loadSRV() #0 { ret float %val } -; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not -; distract from the flag that is actually being tested !dx.valver = !{!0} !0 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll index c6358473ff2e4..2b2b41eda27fa 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll @@ -35,8 +35,6 @@ define float @loadSRV() #0 { ret float %val } -; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not -; distract from the flag that is actually being tested !dx.valver = !{!0} !0 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll index 10eb7a878e5c4..7fbc3f4f26ecf 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll @@ -35,8 +35,6 @@ define float @loadSRV() #0 { ret float %val } -; Set dx.valver to prevent the flag UAVsAtEveryStage from being set, as to not -; distract from the flag that is actually being tested !dx.valver = !{!0} !0 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll index dd42bb73e9bdd..e9fed4ccbb37c 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll @@ -43,9 +43,6 @@ define void @noload(<4 x float> %val) #0 { ret void } -; Set dx.valver and dx.resmayalias to prevent flags ResMayNotAlias and -; UAVsAtEveryStage from being set, as to not distract from the flag that is -; actually being tested !llvm.module.flags = !{!0} !dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll index 5db3b32deee62..b9882466887a4 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll @@ -24,8 +24,6 @@ define void @test() "hlsl.export" { !dx.valver = !{!1} !1 = !{i32 1, i32 7} -; Set dx.resmayalias to prevent the shader flag ResMayNotAlias from being set, -; as to not distract from the shader flag that is actually being tested !llvm.module.flags = !{!0} !0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll index 98c2e833f4aee..47da35b6c9d89 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.8.ll @@ -23,7 +23,5 @@ define void @test() "hlsl.export" { !dx.valver = !{!1} !1 = !{i32 1, i32 8} -; Set dx.resmayalias to prevent the shader flag ResMayNotAlias from being set, -; as to not distract from the shader flag that is actually being tested !llvm.module.flags = !{!0} !0 = !{i32 1, !"dx.resmayalias", i32 1} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll index f0a9d0762d999..5e4c1df3b55f2 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll @@ -25,8 +25,6 @@ define void @VSMain() { !dx.valver = !{!1} !1 = !{i32 1, i32 8} -; Set dx.resmayalias to prevent the shader flag ResMayNotAlias from being set, -; as to not distract from the shader flag that is actually being tested !llvm.module.flags = !{!0} !0 = !{i32 1, !"dx.resmayalias", i32 1} From bd1be2a6d9547444b948861bac67bdede6020c71 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Fri, 25 Apr 2025 20:14:02 +0000 Subject: [PATCH 5/7] Remove checks for no other shader flag is being set --- .../DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll | 4 +--- .../CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll index b9882466887a4..552f513095fa5 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-lib-valver1.7.ll @@ -30,8 +30,6 @@ define void @test() "hlsl.export" { ; DXC: - Name: SFI0 ; DXC-NEXT: Size: 8 ; DXC-NEXT: Flags: -; DXC-NOT: {{[A-Za-z]+: +true}} -; DXC: UAVsAtEveryStage: true -; DXC-NOT: {{[A-Za-z]+: +true}} +; DXC: UAVsAtEveryStage: true ; DXC: NextUnusedBit: false ; DXC: ... diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll index 5e4c1df3b55f2..d3f556b62ed0c 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/uavs-at-every-stage-vs.ll @@ -31,8 +31,6 @@ define void @VSMain() { ; DXC: - Name: SFI0 ; DXC-NEXT: Size: 8 ; DXC-NEXT: Flags: -; DXC-NOT: {{[A-Za-z]+: +true}} -; DXC-NEXT: UAVsAtEveryStage: true -; DXC-NOT: {{[A-Za-z]+: +true}} +; DXC: UAVsAtEveryStage: true ; DXC: NextUnusedBit: false ; DXC: ... From 88793b6c550f7538e82f00278a10e497da6880f5 Mon Sep 17 00:00:00 2001 From: Icohedron Date: Fri, 25 Apr 2025 21:32:53 +0000 Subject: [PATCH 6/7] Add additional fixes to unrelated shader-flag tests to account for UAVsAtEveryStage --- .../ShaderFlags/max-64-uavs-array-valver1.5.ll | 9 +++------ .../ShaderFlags/max-64-uavs-array-valver1.6.ll | 3 ++- .../CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll | 3 --- .../DirectX/ShaderFlags/res-may-not-alias-sm6.7.ll | 14 +++++++++----- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.5.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.5.ll index d3be3ae3417dc..af6001be1f610 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.5.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.5.ll @@ -7,9 +7,10 @@ target triple = "dxil-pc-shadermodel6.7-library" ; CHECK: Combined Shader Flags for Module -; CHECK-NEXT: Shader Flags Value: 0x00000000 +; CHECK-NEXT: Shader Flags Value: 0x00010000 -; CHECK-NOT: Note: shader requires additional functionality: +; CHECK: Note: shader requires additional functionality: +; CHECK: UAVs at every shader stage ; CHECK-NOT: 64 UAV slots ; CHECK: Function test : 0x00000000 @@ -26,12 +27,8 @@ define void @test() "hlsl.export" { ret void } -; Set validator version to 1.5 !dx.valver = !{!1} !1 = !{i32 1, i32 5} -; Set this flag to 1 to prevent the ResMayNotAlias flag from being set !llvm.module.flags = !{!0} -!dx.valver = !{!1} !0 = !{i32 1, !"dx.resmayalias", i32 1} -!1 = !{i32 1, i32 8} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.6.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.6.ll index cef5152187955..7e1d73b31b35b 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.6.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/max-64-uavs-array-valver1.6.ll @@ -8,9 +8,10 @@ target triple = "dxil-pc-shadermodel6.7-library" ; CHECK: Combined Shader Flags for Module -; CHECK-NEXT: Shader Flags Value: 0x00008000 +; CHECK-NEXT: Shader Flags Value: 0x00018000 ; CHECK: Note: shader requires additional functionality: +; CHECK: UAVs at every shader stage ; CHECK: 64 UAV slots ; CHECK: Function test : 0x00000000 diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll index 6bab125c54996..77d80470d6501 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll @@ -42,7 +42,4 @@ define float @loadSRV() #0 { !0 = !{i32 1, !"dx.resmayalias", i32 0} !1 = !{i32 1, i32 8} -!dx.valver = !{!1} -!1 = !{i32 1, i32 8} - attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-sm6.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-sm6.7.ll index 096ea8e2a00dc..e8bf16fccb798 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-sm6.7.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-sm6.7.ll @@ -1,14 +1,18 @@ ; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s ; This test checks to ensure the behavior of the DXIL shader flag analysis -; for the flag ResMayNotAlias is correct when the DXIL Version is >= 1.7. The -; ResMayNotAlias flag (0x20000000) should be set on all functions if there are -; one or more UAVs present globally in the module. +; for the flag ResMayNotAlias is correct when the DXIL Version is >= 1.7 and the +; DXIL Validator Version < 1.8. The ResMayNotAlias flag (0x20000000) should be +; set on all functions if there are one or more UAVs present globally in the +; module. target triple = "dxil-pc-shadermodel6.7-library" ; CHECK: Combined Shader Flags for Module -; CHECK-NEXT: Shader Flags Value: 0x200000010 +; CHECK-NEXT: Shader Flags Value: 0x200010010 + +; CHECK: Note: shader requires additional functionality: +; CHECK: UAVs at every shader stage ; CHECK: Note: extra DXIL module flags: ; CHECK: Raw and Structured buffers @@ -36,6 +40,6 @@ define float @loadSRV() #0 { } !dx.valver = !{!0} -!0 = !{i32 1, i32 8} +!0 = !{i32 1, i32 7} attributes #0 = { convergent norecurse nounwind "hlsl.export"} From 362c4420e668467b5bcb7de3097e858e10db49cb Mon Sep 17 00:00:00 2001 From: Icohedron Date: Fri, 25 Apr 2025 21:37:58 +0000 Subject: [PATCH 7/7] Apply clang-format --- llvm/lib/Target/DirectX/DXILShaderFlags.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp index 6262d8db28e8b..7027775f73440 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp @@ -32,7 +32,8 @@ using namespace llvm; using namespace llvm::dxil; -static bool hasUAVsAtEveryStage(DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI) { +static bool hasUAVsAtEveryStage(DXILResourceMap &DRM, + const ModuleMetadataInfo &MMDI) { if (DRM.uavs().empty()) return false;