-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Revert "[DirectX] Validating Root flags are denying shader stage" #160917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joaosaffran
merged 1 commit into
users/joaosaffran/153276
from
revert-153287-validation/root-flags
Sep 26, 2025
Merged
Revert "[DirectX] Validating Root flags are denying shader stage" #160917
joaosaffran
merged 1 commit into
users/joaosaffran/153276
from
revert-153287-validation/root-flags
Sep 26, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-directx Author: None (joaosaffran) ChangesReverts llvm/llvm-project#153287 Full diff: https://github.com/llvm/llvm-project/pull/160917.diff 6 Files Affected:
diff --git a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
index 6e95a4232fabe..7e93474e73118 100644
--- a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
+++ b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
@@ -160,41 +160,6 @@ tripleToVisibility(llvm::Triple::EnvironmentType ET) {
}
}
-static void reportIfDeniedShaderStageAccess(Module &M,
- const dxbc::RootFlags &Flags,
- const dxbc::RootFlags &Mask) {
- if ((Flags & Mask) != Mask)
- return;
-
- SmallString<128> Message;
- raw_svector_ostream OS(Message);
- OS << "Shader has root bindings but root signature uses a DENY flag to "
- "disallow root binding access to the shader stage.";
- M.getContext().diagnose(DiagnosticInfoGeneric(Message));
-}
-
-static std::optional<dxbc::RootFlags>
-getEnvironmentDenyFlagMask(Triple::EnvironmentType ShaderProfile) {
- switch (ShaderProfile) {
- case Triple::Pixel:
- return dxbc::RootFlags::DenyPixelShaderRootAccess;
- case Triple::Vertex:
- return dxbc::RootFlags::DenyVertexShaderRootAccess;
- case Triple::Geometry:
- return dxbc::RootFlags::DenyGeometryShaderRootAccess;
- case Triple::Hull:
- return dxbc::RootFlags::DenyHullShaderRootAccess;
- case Triple::Domain:
- return dxbc::RootFlags::DenyDomainShaderRootAccess;
- case Triple::Mesh:
- return dxbc::RootFlags::DenyMeshShaderRootAccess;
- case Triple::Amplification:
- return dxbc::RootFlags::DenyAmplificationShaderRootAccess;
- default:
- return std::nullopt;
- }
-}
-
static void validateRootSignature(Module &M,
const mcdxbc::RootSignatureDesc &RSD,
dxil::ModuleMetadataInfo &MMI,
@@ -260,9 +225,7 @@ static void validateRootSignature(Module &M,
Builder.findOverlapping(ReportedBinding);
reportOverlappingRegisters(M, ReportedBinding, Overlaping);
});
-
const hlsl::BoundRegs &BoundRegs = Builder.takeBoundRegs();
- bool HasBindings = false;
for (const ResourceInfo &RI : DRM) {
const ResourceInfo::ResourceBinding &Binding = RI.getBinding();
const dxil::ResourceTypeInfo &RTI = DRTM[RI.getHandleTy()];
@@ -273,33 +236,22 @@ static void validateRootSignature(Module &M,
BoundRegs.findBoundReg(RC, Binding.Space, Binding.LowerBound,
Binding.LowerBound + Binding.Size - 1);
- if (!Reg) {
- reportRegNotBound(M, RC, Binding);
- continue;
- }
+ if (Reg != nullptr) {
+ const auto *ParamInfo =
+ static_cast<const mcdxbc::RootParameterInfo *>(Reg->Cookie);
+
+ if (RC != ResourceClass::SRV && RC != ResourceClass::UAV)
+ continue;
- const auto *ParamInfo =
- static_cast<const mcdxbc::RootParameterInfo *>(Reg->Cookie);
+ if (ParamInfo->Type == dxbc::RootParameterType::DescriptorTable)
+ continue;
- bool IsSRVOrUAV = RC == ResourceClass::SRV || RC == ResourceClass::UAV;
- bool IsDescriptorTable =
- ParamInfo->Type == dxbc::RootParameterType::DescriptorTable;
- bool IsRawOrStructuredBuffer =
- RK != ResourceKind::RawBuffer && RK != ResourceKind::StructuredBuffer;
- if (IsSRVOrUAV && !IsDescriptorTable && IsRawOrStructuredBuffer) {
- reportInvalidHandleTyError(M, RC, Binding);
- continue;
+ if (RK != ResourceKind::RawBuffer && RK != ResourceKind::StructuredBuffer)
+ reportInvalidHandleTyError(M, RC, Binding);
+ } else {
+ reportRegNotBound(M, RC, Binding);
}
-
- HasBindings = true;
}
-
- if (!HasBindings)
- return;
-
- if (std::optional<dxbc::RootFlags> Mask =
- getEnvironmentDenyFlagMask(MMI.ShaderProfile))
- reportIfDeniedShaderStageAccess(M, dxbc::RootFlags(RSD.Flags), *Mask);
}
static mcdxbc::RootSignatureDesc *
diff --git a/llvm/test/CodeGen/DirectX/rootsignature-validation-deny-no-binding.ll b/llvm/test/CodeGen/DirectX/rootsignature-validation-deny-no-binding.ll
deleted file mode 100644
index 15326d438f021..0000000000000
--- a/llvm/test/CodeGen/DirectX/rootsignature-validation-deny-no-binding.ll
+++ /dev/null
@@ -1,17 +0,0 @@
-; RUN: opt -S -passes='dxil-post-optimization-validation' %s
-; This is a valid case where no resource is being used
-target triple = "dxil-pc-shadermodel6.6-pixel"
-
-define void @CSMain() #0 {
-entry:
- ret void
-}
-attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="geometry" }
-
-!dx.rootsignatures = !{!0}
-
-!0 = !{ptr @CSMain, !1, i32 2}
-!1 = !{!2, !3, !4}
-!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}
-!3 = !{ !"RootFlags", i32 294 } ; 294 = deny_pixel/hull/vertex/amplification_shader_root_access
-!4 = !{ !"RootSRV", i32 0, i32 1, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-multiple-shader.ll b/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-multiple-shader.ll
deleted file mode 100644
index b11cce694bd25..0000000000000
--- a/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-multiple-shader.ll
+++ /dev/null
@@ -1,20 +0,0 @@
-; RUN: not opt -S -passes='dxil-post-optimization-validation' %s 2>&1 | FileCheck %s
-; CHECK: error: Shader has root bindings but root signature uses a DENY flag to disallow root binding access to the shader stage.
-target triple = "dxil-pc-shadermodel6.6-pixel"
-
-%__cblayout_CB = type <{ float }>
-
-@CB.str = private unnamed_addr constant [3 x i8] c"CB\00", align 1
-
-define void @CSMain() "hlsl.shader"="compute" {
-entry:
- %CB = tail call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB, 4, 0)) @llvm.dx.resource.handlefrombinding(i32 0, i32 2, i32 1, i32 0, ptr nonnull @CB.str)
- ret void
-}
-
-!dx.rootsignatures = !{!0}
-
-!0 = !{ptr @CSMain, !1, i32 2}
-!1 = !{!2, !3}
-!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}
-!3 = !{!"RootFlags", i32 294} ; 294 = deny_pixel/hull/vertex/amplification_shader_root_access
diff --git a/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-root-descriptor.ll b/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-root-descriptor.ll
deleted file mode 100644
index 6d323757d5897..0000000000000
--- a/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-root-descriptor.ll
+++ /dev/null
@@ -1,20 +0,0 @@
-; RUN: not opt -S -passes='dxil-post-optimization-validation' %s 2>&1 | FileCheck %s
-
-; CHECK: error: Shader has root bindings but root signature uses a DENY flag to disallow root binding access to the shader stage.
-target triple = "dxil-pc-shadermodel6.6-pixel"
-
-@SB.str = private unnamed_addr constant [3 x i8] c"SB\00", align 1
-
-define void @CSMain() "hlsl.shader"="pixel" {
-entry:
- %SB = tail call target("dx.RawBuffer", i32, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, ptr nonnull @SB.str)
- ret void
-}
-
-!dx.rootsignatures = !{!0}
-
-!0 = !{ptr @CSMain, !1, i32 2}
-!1 = !{!2, !3}
-!2 = !{!"DescriptorTable", i32 0, !4}
-!4 = !{!"SRV", i32 1, i32 0, i32 0, i32 -1, i32 4}
-!3 = !{!"RootFlags", i32 32} ; 32 = deny_pixel_shader_root_access
diff --git a/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-single-shader.ll b/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-single-shader.ll
deleted file mode 100644
index 4e50f50049b0e..0000000000000
--- a/llvm/test/CodeGen/DirectX/rootsignature-validation-fail-deny-single-shader.ll
+++ /dev/null
@@ -1,19 +0,0 @@
-; RUN: not opt -S -passes='dxil-post-optimization-validation' %s 2>&1 | FileCheck %s
-
-; CHECK: error: Shader has root bindings but root signature uses a DENY flag to disallow root binding access to the shader stage.
-target triple = "dxil-pc-shadermodel6.6-pixel"
-
-@SB.str = private unnamed_addr constant [3 x i8] c"SB\00", align 1
-
-define void @CSMain() "hlsl.shader"="pixel" {
-entry:
- %SB = tail call target("dx.RawBuffer", i32, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, ptr nonnull @SB.str)
- ret void
-}
-
-!dx.rootsignatures = !{!0}
-
-!0 = !{ptr @CSMain, !1, i32 2}
-!1 = !{!2, !3}
-!2 = !{!"RootSRV", i32 0, i32 0, i32 0, i32 4}
-!3 = !{!"RootFlags", i32 32} ; 32 = deny_pixel_shader_root_access
diff --git a/llvm/test/CodeGen/DirectX/rootsignature-validation-not-dening-shader.ll b/llvm/test/CodeGen/DirectX/rootsignature-validation-not-dening-shader.ll
deleted file mode 100644
index 775fc3512ca84..0000000000000
--- a/llvm/test/CodeGen/DirectX/rootsignature-validation-not-dening-shader.ll
+++ /dev/null
@@ -1,21 +0,0 @@
-; RUN: opt -S -passes='dxil-post-optimization-validation' %s
-; Valid scenario where shader stage is not blocked from accessing root bindings
-target triple = "dxil-pc-shadermodel6.6-geometry"
-
-%__cblayout_CB = type <{ float }>
-
-@CB.str = private unnamed_addr constant [3 x i8] c"CB\00", align 1
-
-define void @CSMain() "hlsl.shader"="geometry" {
-entry:
- %CB = tail call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB, 4, 0)) @llvm.dx.resource.handlefrombinding(i32 0, i32 2, i32 1, i32 0, ptr nonnull @CB.str)
- ret void
-}
-attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1" "hlsl.shader"="geometry" }
-
-!dx.rootsignatures = !{!0}
-
-!0 = !{ptr @CSMain, !1, i32 2}
-!1 = !{!2, !3}
-!2 = !{ !"RootFlags", i32 294 } ; 294 = deny_pixel/hull/vertex/amplification_shader_root_access
-!3 = !{ !"RootCBV", i32 0, i32 2, i32 0, i32 0 }
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #153287