Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 7 additions & 4 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ bool SemaHLSL::handleRootSignatureElements(
bool HasAnySampler = false;
bool HasAnyNonSampler = false;
uint32_t Offset = 0;
bool Unbound = false;
for (const auto &[Clause, ClauseElem] : UnboundClauses) {
SourceLocation Loc = ClauseElem->getLocation();
if (Clause->Type == llvm::dxil::ResourceClass::Sampler)
Expand All @@ -1381,22 +1382,24 @@ bool SemaHLSL::handleRootSignatureElements(
llvm::hlsl::rootsig::DescriptorTableOffsetAppend) {
// Manually specified the offset
Offset = Clause->Offset;
} else if (Unbound) {
// Trying to append onto unbound offset
Diag(Loc, diag::err_hlsl_appending_onto_unbound);
}

uint64_t RangeBound = llvm::hlsl::rootsig::computeRangeBound(
Offset, Clause->NumDescriptors);

if (!llvm::hlsl::rootsig::verifyBoundOffset(Offset)) {
// Trying to append onto unbound offset
Diag(Loc, diag::err_hlsl_appending_onto_unbound);
} else if (!llvm::hlsl::rootsig::verifyNoOverflowedOffset(RangeBound)) {
if (!llvm::hlsl::rootsig::verifyNoOverflowedOffset(RangeBound)) {
// Upper bound overflows maximum offset
Diag(Loc, diag::err_hlsl_offset_overflow) << Offset << RangeBound;
}

Offset = RangeBound == llvm::hlsl::rootsig::NumDescriptorsUnbounded
? uint32_t(RangeBound)
: uint32_t(RangeBound + 1);
Unbound = Clause->NumDescriptors ==
llvm::hlsl::rootsig::NumDescriptorsUnbounded;

// Compute the register bounds and track resource binding
uint32_t LowerBound(Clause->Reg.Number);
Expand Down
6 changes: 5 additions & 1 deletion clang/test/SemaHLSL/RootSignature-resource-ranges-err.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ void append_offset_overflow_signature() {}

// expected-error@+1 {{descriptor range offset overflows [4294967292, 4294967296]}}
[RootSignature("DescriptorTable(CBV(b0, offset = 4294967292, numDescriptors = 5))")]
void offset_() {}
void offset_overflow() {}

// expected-error@+1 {{descriptor range offset overflows [4294967295, 4294967296]}}
[RootSignature("DescriptorTable(CBV(b0, offset = 4294967294), CBV(b1, numDescriptors = 2))")]
void appended_offset_overflow() {}
3 changes: 3 additions & 0 deletions clang/test/SemaHLSL/RootSignature-resource-ranges.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ void valid_root_signature_6() {}

[RootSignature("DescriptorTable(CBV(b0, offset = 4294967292), CBV(b1, numDescriptors = 3))")]
void valid_root_signature_7() {}

[RootSignature("DescriptorTable(CBV(b0, offset = 4294967294), CBV(b1))")]
void valid_root_signature_8() {}
1 change: 0 additions & 1 deletion llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ LLVM_ABI bool verifyMipLODBias(float MipLODBias);
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy);
LLVM_ABI bool verifyLOD(float LOD);

LLVM_ABI bool verifyBoundOffset(uint32_t Offset);
LLVM_ABI bool verifyNoOverflowedOffset(uint64_t Offset);
LLVM_ABI uint64_t computeRangeBound(uint32_t Offset, uint32_t Size);

Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ bool verifyMaxAnisotropy(uint32_t MaxAnisotropy) {

bool verifyLOD(float LOD) { return !std::isnan(LOD); }

bool verifyBoundOffset(uint32_t Offset) {
return Offset != NumDescriptorsUnbounded;
}

bool verifyNoOverflowedOffset(uint64_t Offset) {
return Offset <= std::numeric_limits<uint32_t>::max();
}
Expand Down