-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[DirectX] Validate if Textures/TypedBuffers are being bound in Root Signatures #147573
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
base: users/joaosaffran/146785
Are you sure you want to change the base?
[DirectX] Validate if Textures/TypedBuffers are being bound in Root Signatures #147573
Conversation
…/textures-not-bind-root-signatures
@llvm/pr-subscribers-hlsl Author: None (joaosaffran) ChangesDXC doesn't allow Textures/TypedBuffers to bind with root signature descriptors, this implements the same check in clang. Closes: #126647 Full diff: https://github.com/llvm/llvm-project/pull/147573.diff 2 Files Affected:
diff --git a/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl b/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
new file mode 100644
index 0000000000000..9daf38e30dd67
--- /dev/null
+++ b/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
@@ -0,0 +1,13 @@
+// RUN: not %clang_dxc -T cs_6_6 -E CSMain %s 2>&1 | FileCheck %s
+
+// CHECK: error: register srv (space=0, register=0) is bound to a texture or typed buffer.
+
+RWStructuredBuffer<int> Out : register(u0);
+Buffer<float> B : register(t0);
+// Compute Shader for UAV testing
+[numthreads(8, 8, 1)]
+[RootSignature("SRV(t0), UAV(u0)")]
+void CSMain(uint id : SV_GroupID)
+{
+ Out[0] = B[0];
+}
diff --git a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
index a52a04323514c..c34f31fbe35e5 100644
--- a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
+++ b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
@@ -85,6 +85,17 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
}
}
+static void
+reportInvalidHandleTyBoundInRs(Module &M, Twine Type,
+ ResourceInfo::ResourceBinding Binding) {
+ SmallString<128> Message;
+ raw_svector_ostream OS(Message);
+ OS << "register " << Type << " (space=" << Binding.Space
+ << ", register=" << Binding.LowerBound << ")"
+ << " is bound to a texture or typed buffer.";
+ M.getContext().diagnose(DiagnosticInfoGeneric(Message));
+}
+
static void reportRegNotBound(Module &M, Twine Type,
ResourceInfo::ResourceBinding Binding) {
SmallString<128> Message;
@@ -163,12 +174,26 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
ResourceInfo::ResourceBinding Binding = SRV.getBinding();
if (!Validation.checkTRegBinding(Binding))
reportRegNotBound(M, "srv", Binding);
+ else {
+ const auto *Handle =
+ dyn_cast_or_null<RawBufferExtType>(SRV.getHandleTy());
+
+ if (!Handle)
+ reportInvalidHandleTyBoundInRs(M, "srv", Binding);
+ }
}
for (const ResourceInfo &UAV : DRM.uavs()) {
ResourceInfo::ResourceBinding Binding = UAV.getBinding();
if (!Validation.checkURegBinding(Binding))
reportRegNotBound(M, "uav", Binding);
+ else {
+ const auto *Handle =
+ dyn_cast_or_null<RawBufferExtType>(UAV.getHandleTy());
+
+ if (!Handle)
+ reportInvalidHandleTyBoundInRs(M, "srv", Binding);
+ }
}
for (const ResourceInfo &Sampler : DRM.samplers()) {
|
@llvm/pr-subscribers-backend-directx Author: None (joaosaffran) ChangesDXC doesn't allow Textures/TypedBuffers to bind with root signature descriptors, this implements the same check in clang. Closes: #126647 Full diff: https://github.com/llvm/llvm-project/pull/147573.diff 2 Files Affected:
diff --git a/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl b/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
new file mode 100644
index 0000000000000..9daf38e30dd67
--- /dev/null
+++ b/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
@@ -0,0 +1,13 @@
+// RUN: not %clang_dxc -T cs_6_6 -E CSMain %s 2>&1 | FileCheck %s
+
+// CHECK: error: register srv (space=0, register=0) is bound to a texture or typed buffer.
+
+RWStructuredBuffer<int> Out : register(u0);
+Buffer<float> B : register(t0);
+// Compute Shader for UAV testing
+[numthreads(8, 8, 1)]
+[RootSignature("SRV(t0), UAV(u0)")]
+void CSMain(uint id : SV_GroupID)
+{
+ Out[0] = B[0];
+}
diff --git a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
index a52a04323514c..c34f31fbe35e5 100644
--- a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
+++ b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
@@ -85,6 +85,17 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
}
}
+static void
+reportInvalidHandleTyBoundInRs(Module &M, Twine Type,
+ ResourceInfo::ResourceBinding Binding) {
+ SmallString<128> Message;
+ raw_svector_ostream OS(Message);
+ OS << "register " << Type << " (space=" << Binding.Space
+ << ", register=" << Binding.LowerBound << ")"
+ << " is bound to a texture or typed buffer.";
+ M.getContext().diagnose(DiagnosticInfoGeneric(Message));
+}
+
static void reportRegNotBound(Module &M, Twine Type,
ResourceInfo::ResourceBinding Binding) {
SmallString<128> Message;
@@ -163,12 +174,26 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
ResourceInfo::ResourceBinding Binding = SRV.getBinding();
if (!Validation.checkTRegBinding(Binding))
reportRegNotBound(M, "srv", Binding);
+ else {
+ const auto *Handle =
+ dyn_cast_or_null<RawBufferExtType>(SRV.getHandleTy());
+
+ if (!Handle)
+ reportInvalidHandleTyBoundInRs(M, "srv", Binding);
+ }
}
for (const ResourceInfo &UAV : DRM.uavs()) {
ResourceInfo::ResourceBinding Binding = UAV.getBinding();
if (!Validation.checkURegBinding(Binding))
reportRegNotBound(M, "uav", Binding);
+ else {
+ const auto *Handle =
+ dyn_cast_or_null<RawBufferExtType>(UAV.getHandleTy());
+
+ if (!Handle)
+ reportInvalidHandleTyBoundInRs(M, "srv", Binding);
+ }
}
for (const ResourceInfo &Sampler : DRM.samplers()) {
|
@llvm/pr-subscribers-clang Author: None (joaosaffran) ChangesDXC doesn't allow Textures/TypedBuffers to bind with root signature descriptors, this implements the same check in clang. Closes: #126647 Full diff: https://github.com/llvm/llvm-project/pull/147573.diff 2 Files Affected:
diff --git a/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl b/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
new file mode 100644
index 0000000000000..9daf38e30dd67
--- /dev/null
+++ b/clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
@@ -0,0 +1,13 @@
+// RUN: not %clang_dxc -T cs_6_6 -E CSMain %s 2>&1 | FileCheck %s
+
+// CHECK: error: register srv (space=0, register=0) is bound to a texture or typed buffer.
+
+RWStructuredBuffer<int> Out : register(u0);
+Buffer<float> B : register(t0);
+// Compute Shader for UAV testing
+[numthreads(8, 8, 1)]
+[RootSignature("SRV(t0), UAV(u0)")]
+void CSMain(uint id : SV_GroupID)
+{
+ Out[0] = B[0];
+}
diff --git a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
index a52a04323514c..c34f31fbe35e5 100644
--- a/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
+++ b/llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
@@ -85,6 +85,17 @@ static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM) {
}
}
+static void
+reportInvalidHandleTyBoundInRs(Module &M, Twine Type,
+ ResourceInfo::ResourceBinding Binding) {
+ SmallString<128> Message;
+ raw_svector_ostream OS(Message);
+ OS << "register " << Type << " (space=" << Binding.Space
+ << ", register=" << Binding.LowerBound << ")"
+ << " is bound to a texture or typed buffer.";
+ M.getContext().diagnose(DiagnosticInfoGeneric(Message));
+}
+
static void reportRegNotBound(Module &M, Twine Type,
ResourceInfo::ResourceBinding Binding) {
SmallString<128> Message;
@@ -163,12 +174,26 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
ResourceInfo::ResourceBinding Binding = SRV.getBinding();
if (!Validation.checkTRegBinding(Binding))
reportRegNotBound(M, "srv", Binding);
+ else {
+ const auto *Handle =
+ dyn_cast_or_null<RawBufferExtType>(SRV.getHandleTy());
+
+ if (!Handle)
+ reportInvalidHandleTyBoundInRs(M, "srv", Binding);
+ }
}
for (const ResourceInfo &UAV : DRM.uavs()) {
ResourceInfo::ResourceBinding Binding = UAV.getBinding();
if (!Validation.checkURegBinding(Binding))
reportRegNotBound(M, "uav", Binding);
+ else {
+ const auto *Handle =
+ dyn_cast_or_null<RawBufferExtType>(UAV.getHandleTy());
+
+ if (!Handle)
+ reportInvalidHandleTyBoundInRs(M, "srv", Binding);
+ }
}
for (const ResourceInfo &Sampler : DRM.samplers()) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this implements the same check in clang.
This isn't a check "in clang" - that implies that this is a frontend check, but the logic here is fully in the backend. That said - does this need to be done post optimizations? Couldn't a frontend check catch this reliably?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right place for this test - we can't have clang tests for llvm backend behaviour. We'll need something in llvm/test/CodeGen/DirectX
instead.
…idation/check-descriptors-are-bound
…/textures-not-bind-root-signatures
DXC doesn't allow Textures/TypedBuffers to bind with root signature descriptors, this implements the same check.
Closes: #126647