Skip to content

Commit 18f9e9c

Browse files
committed
Merge branch 'validation/descriptor-tables' into validation/root-flags
2 parents b3bc8b8 + f3253ed commit 18f9e9c

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,9 @@ bool SemaHLSL::handleRootSignatureElements(
13941394
Diag(Loc, diag::err_hlsl_offset_overflow) << Offset << RangeBound;
13951395
}
13961396

1397-
Offset = llvm::hlsl::rootsig::updateOngoingOffset(
1398-
Offset, Clause->NumDescriptors, Clause->Offset);
1397+
Offset = RangeBound == llvm::hlsl::rootsig::NumDescriptorsUnbounded
1398+
? uint32_t(RangeBound)
1399+
: uint32_t(RangeBound + 1);
13991400

14001401
// Compute the register bounds and track resource binding
14011402
uint32_t LowerBound(Clause->Reg.Number);

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -545,25 +545,13 @@ Error MetadataParser::parseRootSignatureElement(mcdxbc::RootSignatureDesc &RSD,
545545

546546
Error validateDescriptorTableSamplerMixin(mcdxbc::DescriptorTable Table,
547547
uint32_t Location) {
548-
bool HasSampler = false;
549-
bool HasOtherRangeType = false;
550-
dxil::ResourceClass OtherRangeType;
551-
548+
dxil::ResourceClass CurrRC = dxil::ResourceClass::Sampler;
552549
for (const mcdxbc::DescriptorRange &Range : Table.Ranges) {
553-
dxil::ResourceClass RangeType =
554-
static_cast<dxil::ResourceClass>(Range.RangeType);
555-
556-
if (RangeType == dxil::ResourceClass::Sampler) {
557-
HasSampler = true;
558-
} else {
559-
HasOtherRangeType = true;
560-
OtherRangeType = RangeType;
561-
}
550+
if (Range.RangeType == dxil::ResourceClass::Sampler &&
551+
CurrRC != dxil::ResourceClass::Sampler)
552+
return make_error<TableSamplerMixinError>(CurrRC, Location);
553+
CurrRC = Range.RangeType;
562554
}
563-
564-
// Samplers cannot be mixed with other resources in a descriptor table.
565-
if (HasSampler && HasOtherRangeType)
566-
return make_error<TableSamplerMixinError>(OtherRangeType, Location);
567555
return Error::success();
568556
}
569557

@@ -573,31 +561,29 @@ Error validateDescriptorTableRegisterOverflow(mcdxbc::DescriptorTable Table,
573561

574562
for (const mcdxbc::DescriptorRange &Range : Table.Ranges) {
575563
// Validation of NumDescriptors should have happened by this point.
576-
if (Range.NumDescriptors <= 0)
564+
if (Range.NumDescriptors == 0)
577565
continue;
578-
const dxil::ResourceClass &RangeType =
579-
static_cast<dxil::ResourceClass>(Range.RangeType);
580566

581567
if (Range.OffsetInDescriptorsFromTableStart != DescriptorTableOffsetAppend)
582568
Offset = Range.OffsetInDescriptorsFromTableStart;
583569

584570
if (!verifyNoOverflowedOffset(Offset))
585571
return make_error<OffsetOverflowError>(
586-
RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
572+
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
587573

588574
const uint64_t RangeBound = llvm::hlsl::rootsig::computeRangeBound(
589575
Range.BaseShaderRegister, Range.NumDescriptors);
590576

591577
if (!verifyNoOverflowedOffset(RangeBound))
592578
return make_error<ShaderRegisterOverflowError>(
593-
RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
579+
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
594580

595581
const uint64_t OffsetBound =
596582
llvm::hlsl::rootsig::computeRangeBound(Offset, Range.NumDescriptors);
597583

598584
if (!verifyNoOverflowedOffset(OffsetBound))
599585
return make_error<DescriptorRangeOverflowError>(
600-
RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
586+
Range.RangeType, Range.BaseShaderRegister, Range.RegisterSpace);
601587
Offset = updateOngoingOffset(Offset, Range.NumDescriptors,
602588
Range.OffsetInDescriptorsFromTableStart);
603589
}

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-AllValidFlagCombinations.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1414
!3 = !{ !5, !21 } ; list of root signature elements
1515
!5 = !{ !"DescriptorTable", i32 0, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20 }
16-
!21 = !{ !"DescriptorTable", i32 0,!6, !8, !9 }
16+
!21 = !{ !"DescriptorTable", i32 0, !6, !8, !9 }
1717

1818
; typedef enum D3D12_DESCRIPTOR_RANGE_FLAGS {
1919
; NONE = 0,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1 | FileCheck %s
2+
; This is correct according to DXC: https://hlsl.godbolt.org/z/KPG5o74KE
3+
; CHECK-NOT: error:
4+
5+
define void @CSMain() "hlsl.shader"="compute" {
6+
entry:
7+
ret void
8+
}
9+
10+
!dx.rootsignatures = !{!0}
11+
12+
!0 = !{ptr @CSMain, !1, i32 2}
13+
!1 = !{!3}
14+
!3 = !{!"DescriptorTable", i32 0, !4, !5}
15+
!4 = !{!"UAV", i32 1, i32 1, i32 0, i32 4294967294, i32 0}
16+
!5 = !{!"UAV", i32 1, i32 0, i32 0, i32 -1, i32 0}

0 commit comments

Comments
 (0)