Skip to content

Commit ab274d2

Browse files
committed
[HLSL][DirectX] Add verifyNumDescriptors
1 parent 6513f02 commit ab274d2

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bool verifyDescriptorFlag(uint32_t Flags);
3131
bool verifyRangeType(uint32_t Type);
3232
bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
3333
uint32_t FlagsVal);
34+
bool verifyNumDescriptors(uint32_t NumDescriptors);
3435
bool verifySamplerFilter(uint32_t Value);
3536
bool verifyAddress(uint32_t Address);
3637
bool verifyMipLODBias(float MipLODBias);

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
108108
return (Flags & ~Mask) == FlagT::None;
109109
}
110110

111+
bool verifyNumDescriptors(uint32_t NumDescriptors) {
112+
return NumDescriptors > 0;
113+
}
114+
111115
bool verifySamplerFilter(uint32_t Value) {
112116
switch (Value) {
113117
#define FILTER(Num, Val) case llvm::to_underlying(dxbc::SamplerFilter::Val):

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
447447
if (!llvm::hlsl::rootsig::verifyRegisterSpace(Range.RegisterSpace))
448448
return reportValueError(Ctx, "RegisterSpace", Range.RegisterSpace);
449449

450+
if (!llvm::hlsl::rootsig::verifyNumDescriptors(Range.NumDescriptors))
451+
return reportValueError(Ctx, "NumDescriptors", Range.NumDescriptors);
452+
450453
if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(
451454
RSD.Version, Range.RangeType, Range.Flags))
452455
return reportValueError(Ctx, "DescriptorFlag", Range.Flags);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
2+
3+
target triple = "dxil-unknown-shadermodel6.0-compute"
4+
5+
; CHECK: error: Invalid value for NumDescriptors: 0
6+
; CHECK-NOT: Root Signature Definitions
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
13+
14+
15+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"DescriptorTable", i32 0, !6}
19+
!6 = !{ !"SRV", i32 0, i32 0, i32 10, i32 -1, i32 4 }

0 commit comments

Comments
 (0)