Skip to content

[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

Open
wants to merge 9 commits into
base: users/joaosaffran/146785
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions clang/test/SemaHLSL/RootSignature-Validation-Textures.hlsl
Copy link
Contributor

@bogner bogner Jul 8, 2025

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.

Original file line number Diff line number Diff line change
@@ -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];
}
25 changes: 25 additions & 0 deletions llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Loading