@@ -29,6 +29,9 @@ using namespace llvm::hlsl::rootsig;
29
29
30
30
namespace {
31
31
32
+ static const llvm::dxbc::RootSignatureVersion DefVersion =
33
+ llvm::dxbc::RootSignatureVersion::V1_1;
34
+
32
35
// Diagnostic helper for helper tests
33
36
class ExpectedDiagConsumer : public DiagnosticConsumer {
34
37
virtual void anchor () {}
@@ -115,7 +118,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
115
118
116
119
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
117
120
SmallVector<RootElement> Elements;
118
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
121
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
119
122
120
123
// Test no diagnostics produced
121
124
Consumer->setNoDiag ();
@@ -148,7 +151,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
148
151
149
152
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
150
153
SmallVector<RootElement> Elements;
151
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
154
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
152
155
153
156
// Test no diagnostics produced
154
157
Consumer->setNoDiag ();
@@ -246,7 +249,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
246
249
247
250
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
248
251
SmallVector<RootElement> Elements;
249
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
252
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
250
253
251
254
// Test no diagnostics produced
252
255
Consumer->setNoDiag ();
@@ -331,7 +334,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
331
334
332
335
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
333
336
SmallVector<RootElement> Elements;
334
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
337
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
335
338
336
339
// Test no diagnostics produced
337
340
Consumer->setNoDiag ();
@@ -406,7 +409,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
406
409
407
410
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
408
411
SmallVector<RootElement> Elements;
409
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
412
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
410
413
411
414
// Test no diagnostics produced
412
415
Consumer->setNoDiag ();
@@ -436,7 +439,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
436
439
437
440
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
438
441
SmallVector<RootElement> Elements;
439
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
442
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
440
443
441
444
// Test no diagnostics produced
442
445
Consumer->setNoDiag ();
@@ -492,7 +495,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
492
495
493
496
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
494
497
SmallVector<RootElement> Elements;
495
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
498
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
496
499
497
500
// Test no diagnostics produced
498
501
Consumer->setNoDiag ();
@@ -533,7 +536,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
533
536
534
537
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
535
538
SmallVector<RootElement> Elements;
536
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
539
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
537
540
538
541
// Test no diagnostics produced
539
542
Consumer->setNoDiag ();
@@ -605,7 +608,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
605
608
606
609
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
607
610
SmallVector<RootElement> Elements;
608
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
611
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
609
612
610
613
// Test no diagnostics produced
611
614
Consumer->setNoDiag ();
@@ -615,6 +618,151 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
615
618
ASSERT_TRUE (Consumer->isSatisfied ());
616
619
}
617
620
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
+
618
766
// Invalid Parser Tests
619
767
620
768
TEST_F (ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
@@ -629,7 +777,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
629
777
630
778
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
631
779
SmallVector<RootElement> Elements;
632
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
780
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
633
781
634
782
// Test correct diagnostic produced
635
783
Consumer->setExpected (diag::err_hlsl_unexpected_end_of_params);
@@ -649,7 +797,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
649
797
650
798
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
651
799
SmallVector<RootElement> Elements;
652
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
800
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
653
801
654
802
// Test correct diagnostic produced - invalid token
655
803
Consumer->setExpected (diag::err_hlsl_unexpected_end_of_params);
@@ -669,7 +817,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
669
817
670
818
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
671
819
SmallVector<RootElement> Elements;
672
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
820
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
673
821
674
822
// Test correct diagnostic produced - end of stream
675
823
Consumer->setExpected (diag::err_expected_after);
@@ -694,7 +842,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
694
842
695
843
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
696
844
SmallVector<RootElement> Elements;
697
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
845
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
698
846
699
847
// Test correct diagnostic produced
700
848
Consumer->setExpected (diag::err_hlsl_rootsig_missing_param);
@@ -716,7 +864,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
716
864
717
865
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
718
866
SmallVector<RootElement> Elements;
719
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
867
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
720
868
721
869
// Test correct diagnostic produced
722
870
Consumer->setExpected (diag::err_hlsl_rootsig_missing_param);
@@ -738,7 +886,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
738
886
739
887
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
740
888
SmallVector<RootElement> Elements;
741
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
889
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
742
890
743
891
// Test correct diagnostic produced
744
892
Consumer->setExpected (diag::err_hlsl_rootsig_missing_param);
@@ -762,7 +910,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
762
910
763
911
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
764
912
SmallVector<RootElement> Elements;
765
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
913
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
766
914
767
915
// Test correct diagnostic produced
768
916
Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
@@ -784,7 +932,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
784
932
785
933
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
786
934
SmallVector<RootElement> Elements;
787
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
935
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
788
936
789
937
// Test correct diagnostic produced
790
938
Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
@@ -808,7 +956,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
808
956
809
957
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
810
958
SmallVector<RootElement> Elements;
811
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
959
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
812
960
813
961
// Test correct diagnostic produced
814
962
Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
@@ -834,7 +982,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
834
982
835
983
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
836
984
SmallVector<RootElement> Elements;
837
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
985
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
838
986
839
987
// Test correct diagnostic produced
840
988
Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
@@ -857,7 +1005,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
857
1005
858
1006
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
859
1007
SmallVector<RootElement> Elements;
860
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1008
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
861
1009
862
1010
// Test correct diagnostic produced
863
1011
Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
@@ -879,7 +1027,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
879
1027
880
1028
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
881
1029
SmallVector<RootElement> Elements;
882
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1030
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
883
1031
884
1032
// Test correct diagnostic produced
885
1033
Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
@@ -900,7 +1048,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
900
1048
901
1049
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
902
1050
SmallVector<RootElement> Elements;
903
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1051
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
904
1052
905
1053
// Test correct diagnostic produced
906
1054
Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
@@ -921,7 +1069,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
921
1069
922
1070
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
923
1071
SmallVector<RootElement> Elements;
924
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1072
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
925
1073
926
1074
// Test correct diagnostic produced
927
1075
Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
@@ -942,7 +1090,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
942
1090
943
1091
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
944
1092
SmallVector<RootElement> Elements;
945
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1093
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
946
1094
947
1095
// Test correct diagnostic produced
948
1096
Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
@@ -963,7 +1111,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
963
1111
964
1112
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
965
1113
SmallVector<RootElement> Elements;
966
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1114
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
967
1115
968
1116
// Test correct diagnostic produced
969
1117
Consumer->setExpected (diag::err_hlsl_number_literal_underflow);
@@ -987,7 +1135,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
987
1135
988
1136
hlsl::RootSignatureLexer Lexer (Source, TokLoc);
989
1137
SmallVector<RootElement> Elements;
990
- hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
1138
+ hlsl::RootSignatureParser Parser (DefVersion, Elements, Lexer, *PP);
991
1139
992
1140
// Test correct diagnostic produced
993
1141
Consumer->setExpected (diag::err_hlsl_rootsig_non_zero_flag);
0 commit comments