Skip to content

Commit 42f8f11

Browse files
committed
adding test and removing string switch
1 parent f9d16d2 commit 42f8f11

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

llvm/lib/Frontend/HLSL/RootSignatureMetadata.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,17 @@ Error MetadataParser::parseDescriptorRange(mcdxbc::DescriptorTable &Table,
330330
if (!ElementText.has_value())
331331
return make_error<InvalidRSMetadataFormat>("Descriptor Range");
332332

333-
Range.RangeType = StringSwitch<dxbc::DescriptorRangeType>(*ElementText)
334-
.Case("CBV", dxbc::DescriptorRangeType::CBV)
335-
.Case("SRV", dxbc::DescriptorRangeType::SRV)
336-
.Case("UAV", dxbc::DescriptorRangeType::UAV)
337-
.Case("Sampler", dxbc::DescriptorRangeType::Sampler);
333+
if (*ElementText == "CBV")
334+
Range.RangeType = dxbc::DescriptorRangeType::CBV;
335+
else if (*ElementText == "SRV")
336+
Range.RangeType = dxbc::DescriptorRangeType::SRV;
337+
else if (*ElementText == "UAV")
338+
Range.RangeType = dxbc::DescriptorRangeType::UAV;
339+
else if (*ElementText == "Sampler")
340+
Range.RangeType = dxbc::DescriptorRangeType::Sampler;
341+
else
342+
return make_error<GenericRSMetadataError>("Invalid Descriptor Range type.",
343+
RangeDescriptorNode);
338344

339345
if (std::optional<uint32_t> Val = extractMdIntValue(RangeDescriptorNode, 1))
340346
Range.NumDescriptors = *Val;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 Descriptor Range type
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, !7 }
19+
!6 = !{ !"Invalid", i32 1, i32 0, i32 -1, i32 -1, i32 4 }
20+
!7 = !{ !"UAV", i32 5, i32 1, i32 10, i32 5, i32 2 }

0 commit comments

Comments
 (0)