@@ -367,6 +367,11 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
367
367
if (!Params.has_value ())
368
368
return std::nullopt;
369
369
370
+ if (consumeExpectedToken (TokenKind::pu_r_paren,
371
+ diag::err_hlsl_unexpected_end_of_params,
372
+ /* param of=*/ TokenKind::kw_StaticSampler))
373
+ return std::nullopt;
374
+
370
375
// Check mandatory parameters were provided
371
376
if (!Params->Reg .has_value ()) {
372
377
reportDiag (diag::err_hlsl_rootsig_missing_param) << TokenKind::sReg ;
@@ -412,11 +417,6 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() {
412
417
if (Params->Visibility .has_value ())
413
418
Sampler.Visibility = Params->Visibility .value ();
414
419
415
- if (consumeExpectedToken (TokenKind::pu_r_paren,
416
- diag::err_hlsl_unexpected_end_of_params,
417
- /* param of=*/ TokenKind::kw_StaticSampler))
418
- return std::nullopt;
419
-
420
420
return Sampler;
421
421
}
422
422
@@ -664,9 +664,9 @@ RootSignatureParser::parseStaticSamplerParams() {
664
664
" Expects to only be invoked starting at given token" );
665
665
666
666
ParsedStaticSamplerParams Params;
667
- do {
668
- // `s` POS_INT
667
+ while (!peekExpectedToken (TokenKind::pu_r_paren)) {
669
668
if (tryConsumeExpectedToken (TokenKind::sReg )) {
669
+ // `s` POS_INT
670
670
if (Params.Reg .has_value ()) {
671
671
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
672
672
return std::nullopt;
@@ -675,10 +675,8 @@ RootSignatureParser::parseStaticSamplerParams() {
675
675
if (!Reg.has_value ())
676
676
return std::nullopt;
677
677
Params.Reg = Reg;
678
- }
679
-
680
- // `filter` `=` FILTER
681
- if (tryConsumeExpectedToken (TokenKind::kw_filter)) {
678
+ } else if (tryConsumeExpectedToken (TokenKind::kw_filter)) {
679
+ // `filter` `=` FILTER
682
680
if (Params.Filter .has_value ()) {
683
681
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
684
682
return std::nullopt;
@@ -691,10 +689,8 @@ RootSignatureParser::parseStaticSamplerParams() {
691
689
if (!Filter.has_value ())
692
690
return std::nullopt;
693
691
Params.Filter = Filter;
694
- }
695
-
696
- // `addressU` `=` TEXTURE_ADDRESS
697
- if (tryConsumeExpectedToken (TokenKind::kw_addressU)) {
692
+ } else if (tryConsumeExpectedToken (TokenKind::kw_addressU)) {
693
+ // `addressU` `=` TEXTURE_ADDRESS
698
694
if (Params.AddressU .has_value ()) {
699
695
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
700
696
return std::nullopt;
@@ -707,10 +703,8 @@ RootSignatureParser::parseStaticSamplerParams() {
707
703
if (!AddressU.has_value ())
708
704
return std::nullopt;
709
705
Params.AddressU = AddressU;
710
- }
711
-
712
- // `addressV` `=` TEXTURE_ADDRESS
713
- if (tryConsumeExpectedToken (TokenKind::kw_addressV)) {
706
+ } else if (tryConsumeExpectedToken (TokenKind::kw_addressV)) {
707
+ // `addressV` `=` TEXTURE_ADDRESS
714
708
if (Params.AddressV .has_value ()) {
715
709
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
716
710
return std::nullopt;
@@ -723,10 +717,8 @@ RootSignatureParser::parseStaticSamplerParams() {
723
717
if (!AddressV.has_value ())
724
718
return std::nullopt;
725
719
Params.AddressV = AddressV;
726
- }
727
-
728
- // `addressW` `=` TEXTURE_ADDRESS
729
- if (tryConsumeExpectedToken (TokenKind::kw_addressW)) {
720
+ } else if (tryConsumeExpectedToken (TokenKind::kw_addressW)) {
721
+ // `addressW` `=` TEXTURE_ADDRESS
730
722
if (Params.AddressW .has_value ()) {
731
723
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
732
724
return std::nullopt;
@@ -739,10 +731,8 @@ RootSignatureParser::parseStaticSamplerParams() {
739
731
if (!AddressW.has_value ())
740
732
return std::nullopt;
741
733
Params.AddressW = AddressW;
742
- }
743
-
744
- // `mipLODBias` `=` NUMBER
745
- if (tryConsumeExpectedToken (TokenKind::kw_mipLODBias)) {
734
+ } else if (tryConsumeExpectedToken (TokenKind::kw_mipLODBias)) {
735
+ // `mipLODBias` `=` NUMBER
746
736
if (Params.MipLODBias .has_value ()) {
747
737
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
748
738
return std::nullopt;
@@ -755,10 +745,8 @@ RootSignatureParser::parseStaticSamplerParams() {
755
745
if (!MipLODBias.has_value ())
756
746
return std::nullopt;
757
747
Params.MipLODBias = MipLODBias;
758
- }
759
-
760
- // `maxAnisotropy` `=` POS_INT
761
- if (tryConsumeExpectedToken (TokenKind::kw_maxAnisotropy)) {
748
+ } else if (tryConsumeExpectedToken (TokenKind::kw_maxAnisotropy)) {
749
+ // `maxAnisotropy` `=` POS_INT
762
750
if (Params.MaxAnisotropy .has_value ()) {
763
751
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
764
752
return std::nullopt;
@@ -771,10 +759,8 @@ RootSignatureParser::parseStaticSamplerParams() {
771
759
if (!MaxAnisotropy.has_value ())
772
760
return std::nullopt;
773
761
Params.MaxAnisotropy = MaxAnisotropy;
774
- }
775
-
776
- // `comparisonFunc` `=` COMPARISON_FUNC
777
- if (tryConsumeExpectedToken (TokenKind::kw_comparisonFunc)) {
762
+ } else if (tryConsumeExpectedToken (TokenKind::kw_comparisonFunc)) {
763
+ // `comparisonFunc` `=` COMPARISON_FUNC
778
764
if (Params.CompFunc .has_value ()) {
779
765
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
780
766
return std::nullopt;
@@ -787,10 +773,8 @@ RootSignatureParser::parseStaticSamplerParams() {
787
773
if (!CompFunc.has_value ())
788
774
return std::nullopt;
789
775
Params.CompFunc = CompFunc;
790
- }
791
-
792
- // `borderColor` `=` STATIC_BORDER_COLOR
793
- if (tryConsumeExpectedToken (TokenKind::kw_borderColor)) {
776
+ } else if (tryConsumeExpectedToken (TokenKind::kw_borderColor)) {
777
+ // `borderColor` `=` STATIC_BORDER_COLOR
794
778
if (Params.BorderColor .has_value ()) {
795
779
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
796
780
return std::nullopt;
@@ -803,10 +787,8 @@ RootSignatureParser::parseStaticSamplerParams() {
803
787
if (!BorderColor.has_value ())
804
788
return std::nullopt;
805
789
Params.BorderColor = BorderColor;
806
- }
807
-
808
- // `minLOD` `=` NUMBER
809
- if (tryConsumeExpectedToken (TokenKind::kw_minLOD)) {
790
+ } else if (tryConsumeExpectedToken (TokenKind::kw_minLOD)) {
791
+ // `minLOD` `=` NUMBER
810
792
if (Params.MinLOD .has_value ()) {
811
793
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
812
794
return std::nullopt;
@@ -819,10 +801,8 @@ RootSignatureParser::parseStaticSamplerParams() {
819
801
if (!MinLOD.has_value ())
820
802
return std::nullopt;
821
803
Params.MinLOD = MinLOD;
822
- }
823
-
824
- // `maxLOD` `=` NUMBER
825
- if (tryConsumeExpectedToken (TokenKind::kw_maxLOD)) {
804
+ } else if (tryConsumeExpectedToken (TokenKind::kw_maxLOD)) {
805
+ // `maxLOD` `=` NUMBER
826
806
if (Params.MaxLOD .has_value ()) {
827
807
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
828
808
return std::nullopt;
@@ -835,10 +815,8 @@ RootSignatureParser::parseStaticSamplerParams() {
835
815
if (!MaxLOD.has_value ())
836
816
return std::nullopt;
837
817
Params.MaxLOD = MaxLOD;
838
- }
839
-
840
- // `space` `=` POS_INT
841
- if (tryConsumeExpectedToken (TokenKind::kw_space)) {
818
+ } else if (tryConsumeExpectedToken (TokenKind::kw_space)) {
819
+ // `space` `=` POS_INT
842
820
if (Params.Space .has_value ()) {
843
821
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
844
822
return std::nullopt;
@@ -851,10 +829,8 @@ RootSignatureParser::parseStaticSamplerParams() {
851
829
if (!Space.has_value ())
852
830
return std::nullopt;
853
831
Params.Space = Space;
854
- }
855
-
856
- // `visibility` `=` SHADER_VISIBILITY
857
- if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
832
+ } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
833
+ // `visibility` `=` SHADER_VISIBILITY
858
834
if (Params.Visibility .has_value ()) {
859
835
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
860
836
return std::nullopt;
@@ -868,7 +844,11 @@ RootSignatureParser::parseStaticSamplerParams() {
868
844
return std::nullopt;
869
845
Params.Visibility = Visibility;
870
846
}
871
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
847
+
848
+ // ',' denotes another element, otherwise, expected to be at ')'
849
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
850
+ break ;
851
+ }
872
852
873
853
return Params;
874
854
}
0 commit comments