Skip to content

Commit 53f54bf

Browse files
committed
update parser tests
1 parent 9befc49 commit 53f54bf

File tree

1 file changed

+174
-26
lines changed

1 file changed

+174
-26
lines changed

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 174 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ using namespace llvm::hlsl::rootsig;
2929

3030
namespace {
3131

32+
static const llvm::dxbc::RootSignatureVersion DefVersion =
33+
llvm::dxbc::RootSignatureVersion::V1_1;
34+
3235
// Diagnostic helper for helper tests
3336
class ExpectedDiagConsumer : public DiagnosticConsumer {
3437
virtual void anchor() {}
@@ -115,7 +118,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
115118

116119
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
117120
SmallVector<RootElement> Elements;
118-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
121+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
119122

120123
// Test no diagnostics produced
121124
Consumer->setNoDiag();
@@ -148,7 +151,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
148151

149152
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
150153
SmallVector<RootElement> Elements;
151-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
154+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
152155

153156
// Test no diagnostics produced
154157
Consumer->setNoDiag();
@@ -246,7 +249,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
246249

247250
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
248251
SmallVector<RootElement> Elements;
249-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
252+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
250253

251254
// Test no diagnostics produced
252255
Consumer->setNoDiag();
@@ -331,7 +334,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
331334

332335
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
333336
SmallVector<RootElement> Elements;
334-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
337+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
335338

336339
// Test no diagnostics produced
337340
Consumer->setNoDiag();
@@ -406,7 +409,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
406409

407410
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
408411
SmallVector<RootElement> Elements;
409-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
412+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
410413

411414
// Test no diagnostics produced
412415
Consumer->setNoDiag();
@@ -436,7 +439,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
436439

437440
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
438441
SmallVector<RootElement> Elements;
439-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
442+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
440443

441444
// Test no diagnostics produced
442445
Consumer->setNoDiag();
@@ -492,7 +495,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
492495

493496
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
494497
SmallVector<RootElement> Elements;
495-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
498+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
496499

497500
// Test no diagnostics produced
498501
Consumer->setNoDiag();
@@ -533,7 +536,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
533536

534537
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
535538
SmallVector<RootElement> Elements;
536-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
539+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
537540

538541
// Test no diagnostics produced
539542
Consumer->setNoDiag();
@@ -605,7 +608,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
605608

606609
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
607610
SmallVector<RootElement> Elements;
608-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
611+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
609612

610613
// Test no diagnostics produced
611614
Consumer->setNoDiag();
@@ -615,6 +618,151 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
615618
ASSERT_TRUE(Consumer->isSatisfied());
616619
}
617620

621+
TEST_F(ParseHLSLRootSignatureTest, ValidVersion10Test) {
622+
// This test checks that the default values are set correctly
623+
// when parsing with root signature version 1.0
624+
const llvm::StringLiteral Source = R"cc(
625+
CBV(b0),
626+
SRV(t0),
627+
UAV(u0),
628+
DescriptorTable(
629+
CBV(b1),
630+
SRV(t1),
631+
UAV(u1),
632+
Sampler(s1),
633+
)
634+
)cc";
635+
636+
TrivialModuleLoader ModLoader;
637+
auto PP = createPP(Source, ModLoader);
638+
auto TokLoc = SourceLocation();
639+
640+
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
641+
SmallVector<RootElement> Elements;
642+
auto Version = llvm::dxbc::RootSignatureVersion::V1_0;
643+
hlsl::RootSignatureParser Parser(Version, Elements, Lexer, *PP);
644+
645+
// Test no diagnostics produced
646+
Consumer->setNoDiag();
647+
648+
ASSERT_FALSE(Parser.parse());
649+
650+
auto DefRootDescriptorFlag = RootDescriptorFlags::DataVolatile;
651+
RootElement Elem = Elements[0];
652+
ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));
653+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::CBuffer);
654+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag);
655+
656+
Elem = Elements[1];
657+
ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));
658+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::SRV);
659+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag);
660+
661+
Elem = Elements[2];
662+
ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));
663+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::UAV);
664+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag);
665+
666+
auto ValidNonSamplerFlags = DescriptorRangeFlags::DescriptorsVolatile |
667+
DescriptorRangeFlags::DataVolatile;
668+
Elem = Elements[3];
669+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
670+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::CBuffer);
671+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags);
672+
673+
Elem = Elements[4];
674+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
675+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::SRV);
676+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags);
677+
678+
Elem = Elements[5];
679+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
680+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::UAV);
681+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags);
682+
683+
Elem = Elements[6];
684+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
685+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::Sampler);
686+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,
687+
DescriptorRangeFlags::DescriptorsVolatile);
688+
689+
ASSERT_TRUE(Consumer->isSatisfied());
690+
}
691+
692+
TEST_F(ParseHLSLRootSignatureTest, ValidVersion11Test) {
693+
// This test checks that the default values are set correctly
694+
// when parsing with root signature version 1.0
695+
const llvm::StringLiteral Source = R"cc(
696+
CBV(b0),
697+
SRV(t0),
698+
UAV(u0),
699+
DescriptorTable(
700+
CBV(b1),
701+
SRV(t1),
702+
UAV(u1),
703+
Sampler(s1),
704+
)
705+
)cc";
706+
707+
TrivialModuleLoader ModLoader;
708+
auto PP = createPP(Source, ModLoader);
709+
auto TokLoc = SourceLocation();
710+
711+
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
712+
SmallVector<RootElement> Elements;
713+
auto Version = llvm::dxbc::RootSignatureVersion::V1_1;
714+
hlsl::RootSignatureParser Parser(Version, Elements, Lexer, *PP);
715+
716+
// Test no diagnostics produced
717+
Consumer->setNoDiag();
718+
719+
ASSERT_FALSE(Parser.parse());
720+
721+
RootElement Elem = Elements[0];
722+
ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));
723+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::CBuffer);
724+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,
725+
RootDescriptorFlags::DataStaticWhileSetAtExecute);
726+
727+
Elem = Elements[1];
728+
ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));
729+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::SRV);
730+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,
731+
RootDescriptorFlags::DataStaticWhileSetAtExecute);
732+
733+
Elem = Elements[2];
734+
ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));
735+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::UAV);
736+
ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,
737+
RootDescriptorFlags::DataVolatile);
738+
739+
Elem = Elements[3];
740+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
741+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::CBuffer);
742+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,
743+
DescriptorRangeFlags::DataStaticWhileSetAtExecute);
744+
745+
Elem = Elements[4];
746+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
747+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::SRV);
748+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,
749+
DescriptorRangeFlags::DataStaticWhileSetAtExecute);
750+
751+
Elem = Elements[5];
752+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
753+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::UAV);
754+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,
755+
DescriptorRangeFlags::DataVolatile);
756+
757+
Elem = Elements[6];
758+
ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));
759+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::Sampler);
760+
ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,
761+
DescriptorRangeFlags::None);
762+
763+
ASSERT_TRUE(Consumer->isSatisfied());
764+
}
765+
618766
// Invalid Parser Tests
619767

620768
TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
@@ -629,7 +777,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
629777

630778
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
631779
SmallVector<RootElement> Elements;
632-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
780+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
633781

634782
// Test correct diagnostic produced
635783
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -649,7 +797,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
649797

650798
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
651799
SmallVector<RootElement> Elements;
652-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
800+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
653801

654802
// Test correct diagnostic produced - invalid token
655803
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -669,7 +817,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
669817

670818
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
671819
SmallVector<RootElement> Elements;
672-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
820+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
673821

674822
// Test correct diagnostic produced - end of stream
675823
Consumer->setExpected(diag::err_expected_after);
@@ -694,7 +842,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
694842

695843
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
696844
SmallVector<RootElement> Elements;
697-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
845+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
698846

699847
// Test correct diagnostic produced
700848
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -716,7 +864,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
716864

717865
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
718866
SmallVector<RootElement> Elements;
719-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
867+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
720868

721869
// Test correct diagnostic produced
722870
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -738,7 +886,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
738886

739887
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
740888
SmallVector<RootElement> Elements;
741-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
889+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
742890

743891
// Test correct diagnostic produced
744892
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -762,7 +910,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
762910

763911
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
764912
SmallVector<RootElement> Elements;
765-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
913+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
766914

767915
// Test correct diagnostic produced
768916
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -784,7 +932,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
784932

785933
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
786934
SmallVector<RootElement> Elements;
787-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
935+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
788936

789937
// Test correct diagnostic produced
790938
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -808,7 +956,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
808956

809957
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
810958
SmallVector<RootElement> Elements;
811-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
959+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
812960

813961
// Test correct diagnostic produced
814962
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -834,7 +982,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
834982

835983
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
836984
SmallVector<RootElement> Elements;
837-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
985+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
838986

839987
// Test correct diagnostic produced
840988
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -857,7 +1005,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
8571005

8581006
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
8591007
SmallVector<RootElement> Elements;
860-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1008+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
8611009

8621010
// Test correct diagnostic produced
8631011
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -879,7 +1027,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
8791027

8801028
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
8811029
SmallVector<RootElement> Elements;
882-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1030+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
8831031

8841032
// Test correct diagnostic produced
8851033
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -900,7 +1048,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
9001048

9011049
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
9021050
SmallVector<RootElement> Elements;
903-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1051+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
9041052

9051053
// Test correct diagnostic produced
9061054
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -921,7 +1069,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
9211069

9221070
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
9231071
SmallVector<RootElement> Elements;
924-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1072+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
9251073

9261074
// Test correct diagnostic produced
9271075
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -942,7 +1090,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
9421090

9431091
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
9441092
SmallVector<RootElement> Elements;
945-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1093+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
9461094

9471095
// Test correct diagnostic produced
9481096
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -963,7 +1111,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
9631111

9641112
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
9651113
SmallVector<RootElement> Elements;
966-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1114+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
9671115

9681116
// Test correct diagnostic produced
9691117
Consumer->setExpected(diag::err_hlsl_number_literal_underflow);
@@ -987,7 +1135,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
9871135

9881136
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
9891137
SmallVector<RootElement> Elements;
990-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1138+
hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP);
9911139

9921140
// Test correct diagnostic produced
9931141
Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);

0 commit comments

Comments
 (0)