@@ -374,6 +374,9 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
374
374
if (!Params.has_value ())
375
375
return std::nullopt;
376
376
377
+ if (consumeExpectedToken (TokenKind::pu_r_paren))
378
+ return std::nullopt;
379
+
377
380
// Check mandatory parameters were provided
378
381
if (!Params->Reg .has_value ()) {
379
382
reportDiag (diag::err_hlsl_rootsig_missing_param) << TokenKind::sReg ;
@@ -419,9 +422,6 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
419
422
if (Params->Visibility .has_value ())
420
423
Sampler.Visibility = Params->Visibility .value ();
421
424
422
- if (consumeExpectedToken (TokenKind::pu_r_paren))
423
- return std::nullopt;
424
-
425
425
return Sampler;
426
426
}
427
427
@@ -682,9 +682,9 @@ RootSignatureParser::parseStaticSamplerParams() {
682
682
" Expects to only be invoked starting at given token" );
683
683
684
684
ParsedStaticSamplerParams Params;
685
- do {
686
- // `s` POS_INT
685
+ while (!peekExpectedToken (TokenKind::pu_r_paren)) {
687
686
if (tryConsumeExpectedToken (TokenKind::sReg )) {
687
+ // `s` POS_INT
688
688
if (Params.Reg .has_value ()) {
689
689
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
690
690
return std::nullopt;
@@ -693,10 +693,8 @@ RootSignatureParser::parseStaticSamplerParams() {
693
693
if (!Reg.has_value ())
694
694
return std::nullopt;
695
695
Params.Reg = Reg;
696
- }
697
-
698
- // `filter` `=` FILTER
699
- if (tryConsumeExpectedToken (TokenKind::kw_filter)) {
696
+ } else if (tryConsumeExpectedToken (TokenKind::kw_filter)) {
697
+ // `filter` `=` FILTER
700
698
if (Params.Filter .has_value ()) {
701
699
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
702
700
return std::nullopt;
@@ -709,10 +707,8 @@ RootSignatureParser::parseStaticSamplerParams() {
709
707
if (!Filter.has_value ())
710
708
return std::nullopt;
711
709
Params.Filter = Filter;
712
- }
713
-
714
- // `addressU` `=` TEXTURE_ADDRESS
715
- if (tryConsumeExpectedToken (TokenKind::kw_addressU)) {
710
+ } else if (tryConsumeExpectedToken (TokenKind::kw_addressU)) {
711
+ // `addressU` `=` TEXTURE_ADDRESS
716
712
if (Params.AddressU .has_value ()) {
717
713
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
718
714
return std::nullopt;
@@ -725,10 +721,8 @@ RootSignatureParser::parseStaticSamplerParams() {
725
721
if (!AddressU.has_value ())
726
722
return std::nullopt;
727
723
Params.AddressU = AddressU;
728
- }
729
-
730
- // `addressV` `=` TEXTURE_ADDRESS
731
- if (tryConsumeExpectedToken (TokenKind::kw_addressV)) {
724
+ } else if (tryConsumeExpectedToken (TokenKind::kw_addressV)) {
725
+ // `addressV` `=` TEXTURE_ADDRESS
732
726
if (Params.AddressV .has_value ()) {
733
727
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
734
728
return std::nullopt;
@@ -741,10 +735,8 @@ RootSignatureParser::parseStaticSamplerParams() {
741
735
if (!AddressV.has_value ())
742
736
return std::nullopt;
743
737
Params.AddressV = AddressV;
744
- }
745
-
746
- // `addressW` `=` TEXTURE_ADDRESS
747
- if (tryConsumeExpectedToken (TokenKind::kw_addressW)) {
738
+ } else if (tryConsumeExpectedToken (TokenKind::kw_addressW)) {
739
+ // `addressW` `=` TEXTURE_ADDRESS
748
740
if (Params.AddressW .has_value ()) {
749
741
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
750
742
return std::nullopt;
@@ -757,10 +749,8 @@ RootSignatureParser::parseStaticSamplerParams() {
757
749
if (!AddressW.has_value ())
758
750
return std::nullopt;
759
751
Params.AddressW = AddressW;
760
- }
761
-
762
- // `mipLODBias` `=` NUMBER
763
- if (tryConsumeExpectedToken (TokenKind::kw_mipLODBias)) {
752
+ } else if (tryConsumeExpectedToken (TokenKind::kw_mipLODBias)) {
753
+ // `mipLODBias` `=` NUMBER
764
754
if (Params.MipLODBias .has_value ()) {
765
755
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
766
756
return std::nullopt;
@@ -773,10 +763,8 @@ RootSignatureParser::parseStaticSamplerParams() {
773
763
if (!MipLODBias.has_value ())
774
764
return std::nullopt;
775
765
Params.MipLODBias = MipLODBias;
776
- }
777
-
778
- // `maxAnisotropy` `=` POS_INT
779
- if (tryConsumeExpectedToken (TokenKind::kw_maxAnisotropy)) {
766
+ } else if (tryConsumeExpectedToken (TokenKind::kw_maxAnisotropy)) {
767
+ // `maxAnisotropy` `=` POS_INT
780
768
if (Params.MaxAnisotropy .has_value ()) {
781
769
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
782
770
return std::nullopt;
@@ -789,10 +777,8 @@ RootSignatureParser::parseStaticSamplerParams() {
789
777
if (!MaxAnisotropy.has_value ())
790
778
return std::nullopt;
791
779
Params.MaxAnisotropy = MaxAnisotropy;
792
- }
793
-
794
- // `comparisonFunc` `=` COMPARISON_FUNC
795
- if (tryConsumeExpectedToken (TokenKind::kw_comparisonFunc)) {
780
+ } else if (tryConsumeExpectedToken (TokenKind::kw_comparisonFunc)) {
781
+ // `comparisonFunc` `=` COMPARISON_FUNC
796
782
if (Params.CompFunc .has_value ()) {
797
783
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
798
784
return std::nullopt;
@@ -805,10 +791,8 @@ RootSignatureParser::parseStaticSamplerParams() {
805
791
if (!CompFunc.has_value ())
806
792
return std::nullopt;
807
793
Params.CompFunc = CompFunc;
808
- }
809
-
810
- // `borderColor` `=` STATIC_BORDER_COLOR
811
- if (tryConsumeExpectedToken (TokenKind::kw_borderColor)) {
794
+ } else if (tryConsumeExpectedToken (TokenKind::kw_borderColor)) {
795
+ // `borderColor` `=` STATIC_BORDER_COLOR
812
796
if (Params.BorderColor .has_value ()) {
813
797
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
814
798
return std::nullopt;
@@ -821,10 +805,8 @@ RootSignatureParser::parseStaticSamplerParams() {
821
805
if (!BorderColor.has_value ())
822
806
return std::nullopt;
823
807
Params.BorderColor = BorderColor;
824
- }
825
-
826
- // `minLOD` `=` NUMBER
827
- if (tryConsumeExpectedToken (TokenKind::kw_minLOD)) {
808
+ } else if (tryConsumeExpectedToken (TokenKind::kw_minLOD)) {
809
+ // `minLOD` `=` NUMBER
828
810
if (Params.MinLOD .has_value ()) {
829
811
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
830
812
return std::nullopt;
@@ -837,10 +819,8 @@ RootSignatureParser::parseStaticSamplerParams() {
837
819
if (!MinLOD.has_value ())
838
820
return std::nullopt;
839
821
Params.MinLOD = MinLOD;
840
- }
841
-
842
- // `maxLOD` `=` NUMBER
843
- if (tryConsumeExpectedToken (TokenKind::kw_maxLOD)) {
822
+ } else if (tryConsumeExpectedToken (TokenKind::kw_maxLOD)) {
823
+ // `maxLOD` `=` NUMBER
844
824
if (Params.MaxLOD .has_value ()) {
845
825
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
846
826
return std::nullopt;
@@ -853,10 +833,8 @@ RootSignatureParser::parseStaticSamplerParams() {
853
833
if (!MaxLOD.has_value ())
854
834
return std::nullopt;
855
835
Params.MaxLOD = MaxLOD;
856
- }
857
-
858
- // `space` `=` POS_INT
859
- if (tryConsumeExpectedToken (TokenKind::kw_space)) {
836
+ } else if (tryConsumeExpectedToken (TokenKind::kw_space)) {
837
+ // `space` `=` POS_INT
860
838
if (Params.Space .has_value ()) {
861
839
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
862
840
return std::nullopt;
@@ -869,10 +847,8 @@ RootSignatureParser::parseStaticSamplerParams() {
869
847
if (!Space.has_value ())
870
848
return std::nullopt;
871
849
Params.Space = Space;
872
- }
873
-
874
- // `visibility` `=` SHADER_VISIBILITY
875
- if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
850
+ } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
851
+ // `visibility` `=` SHADER_VISIBILITY
876
852
if (Params.Visibility .has_value ()) {
877
853
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
878
854
return std::nullopt;
@@ -885,8 +861,17 @@ RootSignatureParser::parseStaticSamplerParams() {
885
861
if (!Visibility.has_value ())
886
862
return std::nullopt;
887
863
Params.Visibility = Visibility;
864
+ } else {
865
+ consumeNextToken (); // position to start of invalid token
866
+ reportDiag (diag::err_hlsl_rootsig_invalid_param)
867
+ << /* param of=*/ TokenKind::kw_StaticSampler;
868
+ return std::nullopt;
888
869
}
889
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
870
+
871
+ // ',' denotes another element, otherwise, expected to be at ')'
872
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
873
+ break ;
874
+ }
890
875
891
876
return Params;
892
877
}
0 commit comments