Skip to content

Commit eefd22c

Browse files
author
joaosaffran
committed
refactor to copy frontend
1 parent f785d25 commit eefd22c

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ LLVM_ABI bool verifyLOD(float LOD);
4141
LLVM_ABI bool verifyBoundOffset(uint32_t Offset);
4242
LLVM_ABI bool verifyNoOverflowedOffset(uint64_t Offset);
4343
LLVM_ABI uint64_t computeRangeBound(uint32_t Offset, uint32_t Size);
44-
LLVM_ABI uint64_t updateOngoingOffset(uint64_t CurOffset,
45-
uint64_t NumDescriptors, uint64_t Offset);
4644

4745
} // namespace rootsig
4846
} // namespace hlsl

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,34 +561,39 @@ static Error
561561
validateDescriptorTableRegisterOverflow(const mcdxbc::DescriptorTable &Table,
562562
uint32_t Location) {
563563
uint64_t Offset = 0;
564-
564+
bool IsPrevUnbound = false;
565+
565566
for (const mcdxbc::DescriptorRange &Range : Table.Ranges) {
566567
// Validation of NumDescriptors should have happened by this point.
567568
if (Range.NumDescriptors == 0)
568569
continue;
569570

570-
if (Range.OffsetInDescriptorsFromTableStart != DescriptorTableOffsetAppend)
571-
Offset = Range.OffsetInDescriptorsFromTableStart;
572-
573-
if (!verifyNoOverflowedOffset(Offset))
574-
return make_error<OffsetOverflowError>(
575-
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
576-
577571
const uint64_t RangeBound = llvm::hlsl::rootsig::computeRangeBound(
578572
Range.BaseShaderRegister, Range.NumDescriptors);
579573

580574
if (!verifyNoOverflowedOffset(RangeBound))
581575
return make_error<ShaderRegisterOverflowError>(
582576
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
583577

578+
bool IsAppending =
579+
Range.OffsetInDescriptorsFromTableStart == DescriptorTableOffsetAppend;
580+
if (!IsAppending)
581+
Offset = Range.OffsetInDescriptorsFromTableStart;
582+
583+
if (IsPrevUnbound && IsAppending)
584+
return make_error<ShaderRegisterOverflowError>(
585+
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
586+
584587
const uint64_t OffsetBound =
585588
llvm::hlsl::rootsig::computeRangeBound(Offset, Range.NumDescriptors);
586589

587590
if (!verifyNoOverflowedOffset(OffsetBound))
588591
return make_error<DescriptorRangeOverflowError>(
589592
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
590-
Offset = updateOngoingOffset(Offset, Range.NumDescriptors,
591-
Range.OffsetInDescriptorsFromTableStart);
593+
594+
Offset = OffsetBound + 1;
595+
IsPrevUnbound =
596+
Range.NumDescriptors == llvm::hlsl::rootsig::NumDescriptorsUnbounded;
592597
}
593598

594599
return Error::success();

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,6 @@ uint64_t computeRangeBound(uint32_t Offset, uint32_t Size) {
140140

141141
return uint64_t(Offset) + uint64_t(Size) - 1;
142142
}
143-
144-
uint64_t updateOngoingOffset(uint64_t CurOffset, uint64_t NumDescriptors,
145-
uint64_t Offset) {
146-
// Append to the current offset if DescriptorTableOffsetAppend is set,
147-
// otherwise calculate the new Offset.
148-
return Offset == DescriptorTableOffsetAppend ? CurOffset + NumDescriptors
149-
: Offset + NumDescriptors;
150-
}
151-
152143
} // namespace rootsig
153144
} // namespace hlsl
154145
} // namespace llvm

0 commit comments

Comments
 (0)