aboutsummaryrefslogtreecommitdiff
path: root/glslang/MachineIndependent/Versions.cpp
blob: 488c98c5ccb101831e418cc765e1f2e97b028eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
//
// Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
// Copyright (C) 2012-2013 LunarG, Inc.
// Copyright (C) 2017 ARM Limited.
// Copyright (C) 2015-2020 Google, Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
//    Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//
//    Redistributions in binary form must reproduce the above
//    copyright notice, this list of conditions and the following
//    disclaimer in the documentation and/or other materials provided
//    with the distribution.
//
//    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//

//
// Help manage multiple profiles, versions, extensions etc.
//
// These don't return error codes, as the presumption is parsing will
// always continue as if the tested feature were enabled, and thus there
// is no error recovery needed.
//

//
// HOW TO add a feature enabled by an extension.
//
// To add a new hypothetical "Feature F" to the front end, where an extension
// "XXX_extension_X" can be used to enable the feature, do the following.
//
// OVERVIEW: Specific features are what are error-checked for, not
//    extensions:  A specific Feature F might be enabled by an extension, or a
//    particular version in a particular profile, or a stage, or combinations, etc.
//
//    The basic mechanism is to use the following to "declare" all the things that
//    enable/disable Feature F, in a code path that implements Feature F:
//
//        requireProfile()
//        profileRequires()
//        requireStage()
//        checkDeprecated()
//        requireNotRemoved()
//        requireExtensions()
//        extensionRequires()
//
//    Typically, only the first two calls are needed.  They go into a code path that
//    implements Feature F, and will log the proper error/warning messages.  Parsing
//    will then always continue as if the tested feature was enabled.
//
//    There is typically no if-testing or conditional parsing, just insertion of the calls above.
//    However, if symbols specific to the extension are added (step 5), they will
//    only be added under tests that the minimum version and profile are present.
//
// 1) Add a symbol name for the extension string at the bottom of Versions.h:
//
//     const char* const XXX_extension_X = "XXX_extension_X";
//
// 2) Add extension initialization to TParseVersions::initializeExtensionBehavior(),
//    the first function below and optionally a entry to extensionData for additional
//    error checks:
//
//     extensionBehavior[XXX_extension_X] = EBhDisable;
//     (Optional) exts[] = {XXX_extension_X, EShTargetSpv_1_4}
//
// 3) Add any preprocessor directives etc. in the next function, TParseVersions::getPreamble():
//
//           "#define XXX_extension_X 1\n"
//
//    The new-line is important, as that ends preprocess tokens.
//
// 4) Insert a profile check in the feature's path (unless all profiles support the feature,
//    for some version level).  That is, call requireProfile() to constrain the profiles, e.g.:
//
//         // ... in a path specific to Feature F...
//         requireProfile(loc,
//                        ECoreProfile | ECompatibilityProfile,
//                        "Feature F");
//
// 5) For each profile that supports the feature, insert version/extension checks:
//
//    The mostly likely scenario is that Feature F can only be used with a
//    particular profile if XXX_extension_X is present or the version is
//    high enough that the core specification already incorporated it.
//
//        // following the requireProfile() call...
//        profileRequires(loc,
//                        ECoreProfile | ECompatibilityProfile,
//                        420,             // 0 if no version incorporated the feature into the core spec.
//                        XXX_extension_X, // can be a list of extensions that all add the feature
//                        "Feature F Description");
//
//    This allows the feature if either A) one of the extensions is enabled or
//    B) the version is high enough.  If no version yet incorporates the feature
//    into core, pass in 0.
//
//    This can be called multiple times, if different profiles support the
//    feature starting at different version numbers or with different
//    extensions.
//
//    This must be called for each profile allowed by the initial call to requireProfile().
//
//    Profiles are all masks, which can be "or"-ed together.
//
//        ENoProfile
//        ECoreProfile
//        ECompatibilityProfile
//        EEsProfile
//
//    The ENoProfile profile is only for desktop, before profiles showed up in version 150;
//    All other #version with no profile default to either es or core, and so have profiles.
//
//    You can select all but a particular profile using ~.  The following basically means "desktop":
//
//        ~EEsProfile
//
// 6) If built-in symbols are added by the extension, add them in Initialize.cpp:  Their use
//    will be automatically error checked against the extensions enabled at that moment.
//    see the comment at the top of Initialize.cpp for where to put them.  Establish them at
//    the earliest release that supports the extension.  Then, tag them with the
//    set of extensions that both enable them and are necessary, given the version of the symbol
//    table. (There is a different symbol table for each version.)
//
// 7) If the extension has additional requirements like minimum SPIR-V version required, add them
//    to extensionRequires()

#include "parseVersions.h"
#include "localintermediate.h"

namespace glslang {

#ifndef GLSLANG_WEB

//
// Initialize all extensions, almost always to 'disable', as once their features
// are incorporated into a core version, their features are supported through allowing that
// core version, not through a pseudo-enablement of the extension.
//
void TParseVersions::initializeExtensionBehavior()
{
    typedef struct {
        const char *const extensionName;
        EShTargetLanguageVersion minSpvVersion;
    } extensionData;

    const extensionData exts[] = { {E_GL_EXT_ray_tracing, EShTargetSpv_1_4} };

    for (size_t ii = 0; ii < sizeof(exts) / sizeof(exts[0]); ii++) {
        // Add only extensions which require > spv1.0 to save space in map
        if (exts[ii].minSpvVersion > EShTargetSpv_1_0) {
            extensionMinSpv[E_GL_EXT_ray_tracing] = exts[ii].minSpvVersion;
        }
    }

    extensionBehavior[E_GL_OES_texture_3D]                   = EBhDisable;
    extensionBehavior[E_GL_OES_standard_derivatives]         = EBhDisable;
    extensionBehavior[E_GL_EXT_frag_depth]                   = EBhDisable;
    extensionBehavior[E_GL_OES_EGL_image_external]           = EBhDisable;
    extensionBehavior[E_GL_OES_EGL_image_external_essl3]     = EBhDisable;
    extensionBehavior[E_GL_EXT_YUV_target]                   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_texture_lod]           = EBhDisable;
    extensionBehavior[E_GL_EXT_shadow_samplers]              = EBhDisable;
    extensionBehavior[E_GL_ARB_texture_rectangle]            = EBhDisable;
    extensionBehavior[E_GL_3DL_array_objects]                = EBhDisable;
    extensionBehavior[E_GL_ARB_shading_language_420pack]     = EBhDisable;
    extensionBehavior[E_GL_ARB_texture_gather]               = EBhDisable;
    extensionBehavior[E_GL_ARB_gpu_shader5]                  = EBhDisablePartial;
    extensionBehavior[E_GL_ARB_separate_shader_objects]      = EBhDisable;
    extensionBehavior[E_GL_ARB_compute_shader]               = EBhDisable;
    extensionBehavior[E_GL_ARB_tessellation_shader]          = EBhDisable;
    extensionBehavior[E_GL_ARB_enhanced_layouts]             = EBhDisable;
    extensionBehavior[E_GL_ARB_texture_cube_map_array]       = EBhDisable;
    extensionBehavior[E_GL_ARB_texture_multisample]          = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_texture_lod]           = EBhDisable;
    extensionBehavior[E_GL_ARB_explicit_attrib_location]     = EBhDisable;
    extensionBehavior[E_GL_ARB_explicit_uniform_location]    = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_image_load_store]      = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_atomic_counters]       = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_draw_parameters]       = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_group_vote]            = EBhDisable;
    extensionBehavior[E_GL_ARB_derivative_control]           = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_texture_image_samples] = EBhDisable;
    extensionBehavior[E_GL_ARB_viewport_array]               = EBhDisable;
    extensionBehavior[E_GL_ARB_gpu_shader_int64]             = EBhDisable;
    extensionBehavior[E_GL_ARB_gpu_shader_fp64]              = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_ballot]                = EBhDisable;
    extensionBehavior[E_GL_ARB_sparse_texture2]              = EBhDisable;
    extensionBehavior[E_GL_ARB_sparse_texture_clamp]         = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_stencil_export]        = EBhDisable;
//    extensionBehavior[E_GL_ARB_cull_distance]                = EBhDisable;    // present for 4.5, but need extension control over block members
    extensionBehavior[E_GL_ARB_post_depth_coverage]          = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_viewport_layer_array]  = EBhDisable;
    extensionBehavior[E_GL_ARB_fragment_shader_interlock]    = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_clock]                 = EBhDisable;
    extensionBehavior[E_GL_ARB_uniform_buffer_object]        = EBhDisable;
    extensionBehavior[E_GL_ARB_sample_shading]               = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_bit_encoding]          = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_image_size]            = EBhDisable;
    extensionBehavior[E_GL_ARB_shader_storage_buffer_object] = EBhDisable;
    extensionBehavior[E_GL_ARB_shading_language_packing]     = EBhDisable;
    extensionBehavior[E_GL_ARB_texture_query_lod]            = EBhDisable;
    extensionBehavior[E_GL_ARB_vertex_attrib_64bit]          = EBhDisable;

    extensionBehavior[E_GL_KHR_shader_subgroup_basic]            = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_vote]             = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_arithmetic]       = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_ballot]           = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_shuffle]          = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_shuffle_relative] = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_clustered]        = EBhDisable;
    extensionBehavior[E_GL_KHR_shader_subgroup_quad]             = EBhDisable;
    extensionBehavior[E_GL_KHR_memory_scope_semantics]           = EBhDisable;

    extensionBehavior[E_GL_EXT_shader_atomic_int64]              = EBhDisable;

    extensionBehavior[E_GL_EXT_shader_non_constant_global_initializers] = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_image_load_formatted]             = EBhDisable;
    extensionBehavior[E_GL_EXT_post_depth_coverage]                     = EBhDisable;
    extensionBehavior[E_GL_EXT_control_flow_attributes]                 = EBhDisable;
    extensionBehavior[E_GL_EXT_nonuniform_qualifier]                    = EBhDisable;
    extensionBehavior[E_GL_EXT_samplerless_texture_functions]           = EBhDisable;
    extensionBehavior[E_GL_EXT_scalar_block_layout]                     = EBhDisable;
    extensionBehavior[E_GL_EXT_fragment_invocation_density]             = EBhDisable;
    extensionBehavior[E_GL_EXT_buffer_reference]                        = EBhDisable;
    extensionBehavior[E_GL_EXT_buffer_reference2]                       = EBhDisable;
    extensionBehavior[E_GL_EXT_buffer_reference_uvec2]                  = EBhDisable;
    extensionBehavior[E_GL_EXT_demote_to_helper_invocation]             = EBhDisable;
    extensionBehavior[E_GL_EXT_debug_printf]                            = EBhDisable;

    extensionBehavior[E_GL_EXT_shader_16bit_storage]                    = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_8bit_storage]                     = EBhDisable;

    // #line and #include
    extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive]          = EBhDisable;
    extensionBehavior[E_GL_GOOGLE_include_directive]                 = EBhDisable;

    extensionBehavior[E_GL_AMD_shader_ballot]                        = EBhDisable;
    extensionBehavior[E_GL_AMD_shader_trinary_minmax]                = EBhDisable;
    extensionBehavior[E_GL_AMD_shader_explicit_vertex_parameter]     = EBhDisable;
    extensionBehavior[E_GL_AMD_gcn_shader]                           = EBhDisable;
    extensionBehavior[E_GL_AMD_gpu_shader_half_float]                = EBhDisable;
    extensionBehavior[E_GL_AMD_texture_gather_bias_lod]              = EBhDisable;
    extensionBehavior[E_GL_AMD_gpu_shader_int16]                     = EBhDisable;
    extensionBehavior[E_GL_AMD_shader_image_load_store_lod]          = EBhDisable;
    extensionBehavior[E_GL_AMD_shader_fragment_mask]                 = EBhDisable;
    extensionBehavior[E_GL_AMD_gpu_shader_half_float_fetch]          = EBhDisable;

    extensionBehavior[E_GL_INTEL_shader_integer_functions2]          = EBhDisable;

    extensionBehavior[E_GL_NV_sample_mask_override_coverage]         = EBhDisable;
    extensionBehavior[E_SPV_NV_geometry_shader_passthrough]          = EBhDisable;
    extensionBehavior[E_GL_NV_viewport_array2]                       = EBhDisable;
    extensionBehavior[E_GL_NV_stereo_view_rendering]                 = EBhDisable;
    extensionBehavior[E_GL_NVX_multiview_per_view_attributes]        = EBhDisable;
    extensionBehavior[E_GL_NV_shader_atomic_int64]                   = EBhDisable;
    extensionBehavior[E_GL_NV_conservative_raster_underestimation]   = EBhDisable;
    extensionBehavior[E_GL_NV_shader_noperspective_interpolation]    = EBhDisable;
    extensionBehavior[E_GL_NV_shader_subgroup_partitioned]           = EBhDisable;
    extensionBehavior[E_GL_NV_shading_rate_image]                    = EBhDisable;
    extensionBehavior[E_GL_NV_ray_tracing]                           = EBhDisable;
    extensionBehavior[E_GL_NV_fragment_shader_barycentric]           = EBhDisable;
    extensionBehavior[E_GL_NV_compute_shader_derivatives]            = EBhDisable;
    extensionBehavior[E_GL_NV_shader_texture_footprint]              = EBhDisable;
    extensionBehavior[E_GL_NV_mesh_shader]                           = EBhDisable;

    extensionBehavior[E_GL_NV_cooperative_matrix]                    = EBhDisable;
    extensionBehavior[E_GL_NV_shader_sm_builtins]                    = EBhDisable;
    extensionBehavior[E_GL_NV_integer_cooperative_matrix]            = EBhDisable;

    // AEP
    extensionBehavior[E_GL_ANDROID_extension_pack_es31a]             = EBhDisable;
    extensionBehavior[E_GL_KHR_blend_equation_advanced]              = EBhDisable;
    extensionBehavior[E_GL_OES_sample_variables]                     = EBhDisable;
    extensionBehavior[E_GL_OES_shader_image_atomic]                  = EBhDisable;
    extensionBehavior[E_GL_OES_shader_multisample_interpolation]     = EBhDisable;
    extensionBehavior[E_GL_OES_texture_storage_multisample_2d_array] = EBhDisable;
    extensionBehavior[E_GL_EXT_geometry_shader]                      = EBhDisable;
    extensionBehavior[E_GL_EXT_geometry_point_size]                  = EBhDisable;
    extensionBehavior[E_GL_EXT_gpu_shader5]                          = EBhDisable;
    extensionBehavior[E_GL_EXT_primitive_bounding_box]               = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_io_blocks]                     = EBhDisable;
    extensionBehavior[E_GL_EXT_tessellation_shader]                  = EBhDisable;
    extensionBehavior[E_GL_EXT_tessellation_point_size]              = EBhDisable;
    extensionBehavior[E_GL_EXT_texture_buffer]                       = EBhDisable;
    extensionBehavior[E_GL_EXT_texture_cube_map_array]               = EBhDisable;
    extensionBehavior[E_GL_EXT_null_initializer]                     = EBhDisable;

    // OES matching AEP
    extensionBehavior[E_GL_OES_geometry_shader]          = EBhDisable;
    extensionBehavior[E_GL_OES_geometry_point_size]      = EBhDisable;
    extensionBehavior[E_GL_OES_gpu_shader5]              = EBhDisable;
    extensionBehavior[E_GL_OES_primitive_bounding_box]   = EBhDisable;
    extensionBehavior[E_GL_OES_shader_io_blocks]         = EBhDisable;
    extensionBehavior[E_GL_OES_tessellation_shader]      = EBhDisable;
    extensionBehavior[E_GL_OES_tessellation_point_size]  = EBhDisable;
    extensionBehavior[E_GL_OES_texture_buffer]           = EBhDisable;
    extensionBehavior[E_GL_OES_texture_cube_map_array]   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_integer_mix]       = EBhDisable;

    // EXT extensions
    extensionBehavior[E_GL_EXT_device_group]                = EBhDisable;
    extensionBehavior[E_GL_EXT_multiview]                   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_realtime_clock]       = EBhDisable;
    extensionBehavior[E_GL_EXT_ray_tracing]                 = EBhDisable;
    extensionBehavior[E_GL_EXT_ray_query]                   = EBhDisable;
    extensionBehavior[E_GL_EXT_ray_flags_primitive_culling] = EBhDisable;
    extensionBehavior[E_GL_EXT_blend_func_extended]         = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_implicit_conversions] = EBhDisable;
    extensionBehavior[E_GL_EXT_fragment_shading_rate]       = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_image_int64]   = EBhDisable;
    extensionBehavior[E_GL_EXT_terminate_invocation]        = EBhDisable;
    extensionBehavior[E_GL_EXT_shared_memory_block]         = EBhDisable;

    // OVR extensions
    extensionBehavior[E_GL_OVR_multiview]                = EBhDisable;
    extensionBehavior[E_GL_OVR_multiview2]               = EBhDisable;

    // explicit types
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types]         = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int8]    = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int16]   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int32]   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int64]   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float16] = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float32] = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float64] = EBhDisable;

    // subgroup extended types
    extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int8]    = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int16]   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int64]   = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_float16] = EBhDisable;
    extensionBehavior[E_GL_EXT_shader_atomic_float]                    = EBhDisable;
}

#endif // GLSLANG_WEB

// Get code that is not part of a shared symbol table, is specific to this shader,
// or needed by the preprocessor (which does not use a shared symbol table).
void TParseVersions::getPreamble(std::string& preamble)
{
    if (isEsProfile()) {
        preamble =
            "#define GL_ES 1\n"
            "#define GL_FRAGMENT_PRECISION_HIGH 1\n"
#ifdef GLSLANG_WEB
            ;
#else
            "#define GL_OES_texture_3D 1\n"
            "#define GL_OES_standard_derivatives 1\n"
            "#define GL_EXT_frag_depth 1\n"
            "#define GL_OES_EGL_image_external 1\n"
            "#define GL_OES_EGL_image_external_essl3 1\n"
            "#define GL_EXT_YUV_target 1\n"
            "#define GL_EXT_shader_texture_lod 1\n"
            "#define GL_EXT_shadow_samplers 1\n"
            "#define GL_EXT_fragment_shading_rate 1\n"

            // AEP
            "#define GL_ANDROID_extension_pack_es31a 1\n"
            "#define GL_OES_sample_variables 1\n"
            "#define GL_OES_shader_image_atomic 1\n"
            "#define GL_OES_shader_multisample_interpolation 1\n"
            "#define GL_OES_texture_storage_multisample_2d_array 1\n"
            "#define GL_EXT_geometry_shader 1\n"
            "#define GL_EXT_geometry_point_size 1\n"
            "#define GL_EXT_gpu_shader5 1\n"
            "#define GL_EXT_primitive_bounding_box 1\n"
            "#define GL_EXT_shader_io_blocks 1\n"
            "#define GL_EXT_tessellation_shader 1\n"
            "#define GL_EXT_tessellation_point_size 1\n"
            "#define GL_EXT_texture_buffer 1\n"
            "#define GL_EXT_texture_cube_map_array 1\n"
            "#define GL_EXT_shader_implicit_conversions 1\n"
            "#define GL_EXT_shader_integer_mix 1\n"
            "#define GL_EXT_blend_func_extended 1\n"

            // OES matching AEP
            "#define GL_OES_geometry_shader 1\n"
            "#define GL_OES_geometry_point_size 1\n"
            "#define GL_OES_gpu_shader5 1\n"
            "#define GL_OES_primitive_bounding_box 1\n"
            "#define GL_OES_shader_io_blocks 1\n"
            "#define GL_OES_tessellation_shader 1\n"
            "#define GL_OES_tessellation_point_size 1\n"
            "#define GL_OES_texture_buffer 1\n"
            "#define GL_OES_texture_cube_map_array 1\n"
            "#define GL_EXT_shader_non_constant_global_initializers 1\n"
            ;

            if (version >= 300) {
                preamble += "#define GL_NV_shader_noperspective_interpolation 1\n";
            }
            if (version >= 310) {
                preamble += "#define GL_EXT_null_initializer 1\n";
            }

    } else { // !isEsProfile()
        preamble =
            "#define GL_FRAGMENT_PRECISION_HIGH 1\n"
            "#define GL_ARB_texture_rectangle 1\n"
            "#define GL_ARB_shading_language_420pack 1\n"
            "#define GL_ARB_texture_gather 1\n"
            "#define GL_ARB_gpu_shader5 1\n"
            "#define GL_ARB_separate_shader_objects 1\n"
            "#define GL_ARB_compute_shader 1\n"
            "#define GL_ARB_tessellation_shader 1\n"
            "#define GL_ARB_enhanced_layouts 1\n"
            "#define GL_ARB_texture_cube_map_array 1\n"
            "#define GL_ARB_texture_multisample 1\n"
            "#define GL_ARB_shader_texture_lod 1\n"
            "#define GL_ARB_explicit_attrib_location 1\n"
            "#define GL_ARB_explicit_uniform_location 1\n"
            "#define GL_ARB_shader_image_load_store 1\n"
            "#define GL_ARB_shader_atomic_counters 1\n"
            "#define GL_ARB_shader_draw_parameters 1\n"
            "#define GL_ARB_shader_group_vote 1\n"
            "#define GL_ARB_derivative_control 1\n"
            "#define GL_ARB_shader_texture_image_samples 1\n"
            "#define GL_ARB_viewport_array 1\n"
            "#define GL_ARB_gpu_shader_int64 1\n"
            "#define GL_ARB_gpu_shader_fp64 1\n"
            "#define GL_ARB_shader_ballot 1\n"
            "#define GL_ARB_sparse_texture2 1\n"
            "#define GL_ARB_sparse_texture_clamp 1\n"
            "#define GL_ARB_shader_stencil_export 1\n"
            "#define GL_ARB_sample_shading 1\n"
            "#define GL_ARB_shader_image_size 1\n"
            "#define GL_ARB_shading_language_packing 1\n"
//            "#define GL_ARB_cull_distance 1\n"    // present for 4.5, but need extension control over block members
            "#define GL_ARB_post_depth_coverage 1\n"
            "#define GL_ARB_fragment_shader_interlock 1\n"
            "#define GL_ARB_uniform_buffer_object 1\n"
            "#define GL_ARB_shader_bit_encoding 1\n"
            "#define GL_ARB_shader_storage_buffer_object 1\n"
            "#define GL_ARB_texture_query_lod 1\n"
            "#define GL_ARB_vertex_attrib_64bit 1\n"
            "#define GL_EXT_shader_non_constant_global_initializers 1\n"
            "#define GL_EXT_shader_image_load_formatted 1\n"
            "#define GL_EXT_post_depth_coverage 1\n"
            "#define GL_EXT_control_flow_attributes 1\n"
            "#define GL_EXT_nonuniform_qualifier 1\n"
            "#define GL_EXT_shader_16bit_storage 1\n"
            "#define GL_EXT_shader_8bit_storage 1\n"
            "#define GL_EXT_samplerless_texture_functions 1\n"
            "#define GL_EXT_scalar_block_layout 1\n"
            "#define GL_EXT_fragment_invocation_density 1\n"
            "#define GL_EXT_buffer_reference 1\n"
            "#define GL_EXT_buffer_reference2 1\n"
            "#define GL_EXT_buffer_reference_uvec2 1\n"
            "#define GL_EXT_demote_to_helper_invocation 1\n"
            "#define GL_EXT_debug_printf 1\n"
            "#define GL_EXT_fragment_shading_rate 1\n"
            "#define GL_EXT_shared_memory_block 1\n"

            // GL_KHR_shader_subgroup
            "#define GL_KHR_shader_subgroup_basic 1\n"
            "#define GL_KHR_shader_subgroup_vote 1\n"
            "#define GL_KHR_shader_subgroup_arithmetic 1\n"
            "#define GL_KHR_shader_subgroup_ballot 1\n"
            "#define GL_KHR_shader_subgroup_shuffle 1\n"
            "#define GL_KHR_shader_subgroup_shuffle_relative 1\n"
            "#define GL_KHR_shader_subgroup_clustered 1\n"
            "#define GL_KHR_shader_subgroup_quad 1\n"

            "#define GL_EXT_shader_image_int64 1\n"
            "#define GL_EXT_shader_atomic_int64 1\n"
            "#define GL_EXT_shader_realtime_clock 1\n"
            "#define GL_EXT_ray_tracing 1\n"
            "#define GL_EXT_ray_query 1\n"
            "#define GL_EXT_ray_flags_primitive_culling 1\n"

            "#define GL_AMD_shader_ballot 1\n"
            "#define GL_AMD_shader_trinary_minmax 1\n"
            "#define GL_AMD_shader_explicit_vertex_parameter 1\n"
            "#define GL_AMD_gcn_shader 1\n"
            "#define GL_AMD_gpu_shader_half_float 1\n"
            "#define GL_AMD_texture_gather_bias_lod 1\n"
            "#define GL_AMD_gpu_shader_int16 1\n"
            "#define GL_AMD_shader_image_load_store_lod 1\n"
            "#define GL_AMD_shader_fragment_mask 1\n"
            "#define GL_AMD_gpu_shader_half_float_fetch 1\n"

            "#define GL_INTEL_shader_integer_functions2 1\n"

            "#define GL_NV_sample_mask_override_coverage 1\n"
            "#define GL_NV_geometry_shader_passthrough 1\n"
            "#define GL_NV_viewport_array2 1\n"
            "#define GL_NV_shader_atomic_int64 1\n"
            "#define GL_NV_conservative_raster_underestimation 1\n"
            "#define GL_NV_shader_subgroup_partitioned 1\n"
            "#define GL_NV_shading_rate_image 1\n"
            "#define GL_NV_ray_tracing 1\n"
            "#define GL_NV_fragment_shader_barycentric 1\n"
            "#define GL_NV_compute_shader_derivatives 1\n"
            "#define GL_NV_shader_texture_footprint 1\n"
            "#define GL_NV_mesh_shader 1\n"
            "#define GL_NV_cooperative_matrix 1\n"
            "#define GL_NV_integer_cooperative_matrix 1\n"

            "#define GL_EXT_shader_explicit_arithmetic_types 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_int8 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_int16 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_int32 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_int64 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_float16 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_float32 1\n"
            "#define GL_EXT_shader_explicit_arithmetic_types_float64 1\n"

            "#define GL_EXT_shader_subgroup_extended_types_int8 1\n"
            "#define GL_EXT_shader_subgroup_extended_types_int16 1\n"
            "#define GL_EXT_shader_subgroup_extended_types_int64 1\n"
            "#define GL_EXT_shader_subgroup_extended_types_float16 1\n"

            "#define GL_EXT_shader_atomic_float 1\n"
            ;

        if (version >= 150) {
            // define GL_core_profile and GL_compatibility_profile
            preamble += "#define GL_core_profile 1\n";

            if (profile == ECompatibilityProfile)
                preamble += "#define GL_compatibility_profile 1\n";
        }
        if (version >= 140) {
            preamble += "#define GL_EXT_null_initializer 1\n";
        }
#endif // GLSLANG_WEB
    }

#ifndef GLSLANG_WEB
    if ((!isEsProfile() && version >= 140) ||
        (isEsProfile() && version >= 310)) {
        preamble +=
            "#define GL_EXT_device_group 1\n"
            "#define GL_EXT_multiview 1\n"
            "#define GL_NV_shader_sm_builtins 1\n"
            ;
    }

    if (version >= 300 /* both ES and non-ES */) {
        preamble +=
            "#define GL_OVR_multiview 1\n"
            "#define GL_OVR_multiview2 1\n"
            ;
    }

    // #line and #include
    preamble +=
            "#define GL_GOOGLE_cpp_style_line_directive 1\n"
            "#define GL_GOOGLE_include_directive 1\n"
            "#define GL_KHR_blend_equation_advanced 1\n"
            ;

    // other general extensions
    preamble +=
            "#define GL_EXT_terminate_invocation 1\n"
            ;
#endif

    // #define VULKAN XXXX
    const int numberBufSize = 12;
    char numberBuf[numberBufSize];
    if (spvVersion.vulkanGlsl > 0) {
        preamble += "#define VULKAN ";
        snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkanGlsl);
        preamble += numberBuf;
        preamble += "\n";
    }

#ifndef GLSLANG_WEB
    // #define GL_SPIRV XXXX
    if (spvVersion.openGl > 0) {
        preamble += "#define GL_SPIRV ";
        snprintf(numberBuf, numberBufSize, "%d", spvVersion.openGl);
        preamble += numberBuf;
        preamble += "\n";
    }
#endif
}

//
// Map from stage enum to externally readable text name.
//
const char* StageName(EShLanguage stage)
{
    switch(stage) {
    case EShLangVertex:         return "vertex";
    case EShLangFragment:       return "fragment";
    case EShLangCompute:        return "compute";
#ifndef GLSLANG_WEB
    case EShLangTessControl:    return "tessellation control";
    case EShLangTessEvaluation: return "tessellation evaluation";
    case EShLangGeometry:       return "geometry";
    case EShLangRayGen:         return "ray-generation";
    case EShLangIntersect:      return "intersection";
    case EShLangAnyHit:         return "any-hit";
    case EShLangClosestHit:     return "closest-hit";
    case EShLangMiss:           return "miss";
    case EShLangCallable:       return "callable";
    case EShLangMeshNV:         return "mesh";
    case EShLangTaskNV:         return "task";
#endif
    default:                    return "unknown stage";
    }
}

//
// When to use requireStage()
//
//     If only some stages support a feature.
//
// Operation: If the current stage is not present, give an error message.
//
void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguageMask languageMask, const char* featureDesc)
{
    if (((1 << language) & languageMask) == 0)
        error(loc, "not supported in this stage:", featureDesc, StageName(language));
}

// If only one stage supports a feature, this can be called.  But, all supporting stages
// must be specified with one call.
void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguage stage, const char* featureDesc)
{
    requireStage(loc, static_cast<EShLanguageMask>(1 << stage), featureDesc);
}

#ifndef GLSLANG_WEB
//
// When to use requireProfile():
//
//     Use if only some profiles support a feature.  However, if within a profile the feature
//     is version or extension specific, follow this call with calls to profileRequires().
//
// Operation:  If the current profile is not one of the profileMask,
// give an error message.
//
void TParseVersions::requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc)
{
    if (! (profile & profileMask))
        error(loc, "not supported with this profile:", featureDesc, ProfileName(profile));
}

//
// When to use profileRequires():
//
//     If a set of profiles have the same requirements for what version or extensions
//     are needed to support a feature.
//
//     It must be called for each profile that needs protection.  Use requireProfile() first
//     to reduce that set of profiles.
//
// Operation: Will issue warnings/errors based on the current profile, version, and extension
// behaviors.  It only checks extensions when the current profile is one of the profileMask.
//
// A minVersion of 0 means no version of the profileMask support this in core,
// the extension must be present.
//

// entry point that takes multiple extensions
void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
    const char* const extensions[], const char* featureDesc)
{
    if (profile & profileMask) {
        bool okay = minVersion > 0 && version >= minVersion;
#ifndef GLSLANG_WEB
        for (int i = 0; i < numExtensions; ++i) {
            switch (getExtensionBehavior(extensions[i])) {
            case EBhWarn:
                infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
                // fall through
            case EBhRequire:
            case EBhEnable:
                okay = true;
                break;
            default: break; // some compilers want this
            }
        }
#endif
        if (! okay)
            error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
    }
}

// entry point for the above that takes a single extension
void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
    const char* featureDesc)
{
    profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc);
}

void TParseVersions::unimplemented(const TSourceLoc& loc, const char* featureDesc)
{
    error(loc, "feature not yet implemented", featureDesc, "");
}

//
// Within a set of profiles, see if a feature is deprecated and give an error or warning based on whether
// a future compatibility context is being use.
//
void TParseVersions::checkDeprecated(const TSourceLoc& loc, int profileMask, int depVersion, const char* featureDesc)
{
    if (profile & profileMask) {
        if (version >= depVersion) {
            if (forwardCompatible)
                error(loc, "deprecated, may be removed in future release", featureDesc, "");
            else if (! suppressWarnings())
                infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
                                                       String(depVersion) + "; may be removed in future release").c_str(), loc);
        }
    }
}

//
// Within a set of profiles, see if a feature has now been removed and if so, give an error.
// The version argument is the first version no longer having the feature.
//
void TParseVersions::requireNotRemoved(const TSourceLoc& loc, int profileMask, int removedVersion, const char* featureDesc)
{
    if (profile & profileMask) {
        if (version >= removedVersion) {
            const int maxSize = 60;
            char buf[maxSize];
            snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName(profile), removedVersion);
            error(loc, "no longer supported in", featureDesc, buf);
        }
    }
}

// Returns true if at least one of the extensions in the extensions parameter is requested. Otherwise, returns false.
// Warns appropriately if the requested behavior of an extension is "warn".
bool TParseVersions::checkExtensionsRequested(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
{
    // First, see if any of the extensions are enabled
    for (int i = 0; i < numExtensions; ++i) {
        TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
        if (behavior == EBhEnable || behavior == EBhRequire)
            return true;
    }

    // See if any extensions want to give a warning on use; give warnings for all such extensions
    bool warned = false;
    for (int i = 0; i < numExtensions; ++i) {
        TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
        if (behavior == EBhDisable && relaxedErrors()) {
            infoSink.info.message(EPrefixWarning, "The following extension must be enabled to use this feature:", loc);
            behavior = EBhWarn;
        }
        if (behavior == EBhWarn) {
            infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
            warned = true;
        }
    }
    if (warned)
        return true;
    return false;
}

//
// Use when there are no profile/version to check, it's just an error if one of the
// extensions is not present.
//
void TParseVersions::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
    const char* featureDesc)
{
    if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
        return;

    // If we get this far, give errors explaining what extensions are needed
    if (numExtensions == 1)
        error(loc, "required extension not requested:", featureDesc, extensions[0]);
    else {
        error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
        for (int i = 0; i < numExtensions; ++i)
            infoSink.info.message(EPrefixNone, extensions[i]);
    }
}

//
// Use by preprocessor when there are no profile/version to check, it's just an error if one of the
// extensions is not present.
//
void TParseVersions::ppRequireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
    const char* featureDesc)
{
    if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
        return;

    // If we get this far, give errors explaining what extensions are needed
    if (numExtensions == 1)
        ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
    else {
        ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
        for (int i = 0; i < numExtensions; ++i)
            infoSink.info.message(EPrefixNone, extensions[i]);
    }
}

TExtensionBehavior TParseVersions::getExtensionBehavior(const char* extension)
{
    auto iter = extensionBehavior.find(TString(extension));
    if (iter == extensionBehavior.end())
        return EBhMissing;
    else
        return iter->second;
}

// Returns true if the given extension is set to enable, require, or warn.
bool TParseVersions::extensionTurnedOn(const char* const extension)
{
      switch (getExtensionBehavior(extension)) {
      case EBhEnable:
      case EBhRequire:
      case EBhWarn:
          return true;
      default:
          break;
      }
      return false;
}
// See if any of the extensions are set to enable, require, or warn.
bool TParseVersions::extensionsTurnedOn(int numExtensions, const char* const extensions[])
{
    for (int i = 0; i < numExtensions; ++i) {
        if (extensionTurnedOn(extensions[i]))
            return true;
    }
    return false;
}

//
// Change the current state of an extension's behavior.
//
void TParseVersions::updateExtensionBehavior(int line, const char* extension, const char* behaviorString)
{
    // Translate from text string of extension's behavior to an enum.
    TExtensionBehavior behavior = EBhDisable;
    if (! strcmp("require", behaviorString))
        behavior = EBhRequire;
    else if (! strcmp("enable", behaviorString))
        behavior = EBhEnable;
    else if (! strcmp("disable", behaviorString))
        behavior = EBhDisable;
    else if (! strcmp("warn", behaviorString))
        behavior = EBhWarn;
    else {
        error(getCurrentLoc(), "behavior not supported:", "#extension", behaviorString);
        return;
    }
    bool on = behavior != EBhDisable;

    // check if extension is used with correct shader stage
    checkExtensionStage(getCurrentLoc(), extension);

    // check if extension has additional requirements
    extensionRequires(getCurrentLoc(), extension ,behaviorString);

    // update the requested extension
    updateExtensionBehavior(extension, behavior);

    // see if need to propagate to implicitly modified things
    if (strcmp(extension, "GL_ANDROID_extension_pack_es31a") == 0) {
        // to everything in AEP
        updateExtensionBehavior(line, "GL_KHR_blend_equation_advanced", behaviorString);
        updateExtensionBehavior(line, "GL_OES_sample_variables", behaviorString);
        updateExtensionBehavior(line, "GL_OES_shader_image_atomic", behaviorString);
        updateExtensionBehavior(line, "GL_OES_shader_multisample_interpolation", behaviorString);
        updateExtensionBehavior(line, "GL_OES_texture_storage_multisample_2d_array", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_geometry_shader", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_gpu_shader5", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_primitive_bounding_box", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_tessellation_shader", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_texture_buffer", behaviorString);
        updateExtensionBehavior(line, "GL_EXT_texture_cube_map_array", behaviorString);
    }
    // geometry to io_blocks
    else if (strcmp(extension, "GL_EXT_geometry_shader") == 0)
        updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
    else if (strcmp(extension, "GL_OES_geometry_shader") == 0)
        updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
    // tessellation to io_blocks
    else if (strcmp(extension, "GL_EXT_tessellation_shader") == 0)
        updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
    else if (strcmp(extension, "GL_OES_tessellation_shader") == 0)
        updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
    else if (strcmp(extension, "GL_GOOGLE_include_directive") == 0)
        updateExtensionBehavior(line, "GL_GOOGLE_cpp_style_line_directive", behaviorString);
    // subgroup_* to subgroup_basic
    else if (strcmp(extension, "GL_KHR_shader_subgroup_vote") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_KHR_shader_subgroup_arithmetic") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_KHR_shader_subgroup_ballot") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle_relative") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_KHR_shader_subgroup_clustered") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_KHR_shader_subgroup_quad") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_NV_shader_subgroup_partitioned") == 0)
        updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
    else if (strcmp(extension, "GL_EXT_buffer_reference2") == 0 ||
             strcmp(extension, "GL_EXT_buffer_reference_uvec2") == 0)
        updateExtensionBehavior(line, "GL_EXT_buffer_reference", behaviorString);
    else if (strcmp(extension, "GL_NV_integer_cooperative_matrix") == 0)
        updateExtensionBehavior(line, "GL_NV_cooperative_matrix", behaviorString);
    // subgroup extended types to explicit types
    else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int8") == 0)
        updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int8", behaviorString);
    else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int16") == 0)
        updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int16", behaviorString);
    else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int64") == 0)
        updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int64", behaviorString);
    else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_float16") == 0)
        updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_float16", behaviorString);

    // see if we need to update the numeric features
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int8") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int8, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int16") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int16, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int32") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int32, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int64") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int64, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float16") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float16, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float32") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float32, on);
    else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float64") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float64, on);
    else if (strcmp(extension, "GL_EXT_shader_implicit_conversions") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::shader_implicit_conversions, on);
    else if (strcmp(extension, "GL_ARB_gpu_shader_fp64") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_fp64, on);
    else if (strcmp(extension, "GL_AMD_gpu_shader_int16") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_int16, on);
    else if (strcmp(extension, "GL_AMD_gpu_shader_half_float") == 0)
        intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_half_float, on);
}

void TParseVersions::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)
{
    // Update the current behavior
    if (strcmp(extension, "all") == 0) {
        // special case for the 'all' extension; apply it to every extension present
        if (behavior == EBhRequire || behavior == EBhEnable) {
            error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
            return;
        } else {
            for (auto iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter)
                iter->second = behavior;
        }
    } else {
        // Do the update for this single extension
        auto iter = extensionBehavior.find(TString(extension));
        if (iter == extensionBehavior.end()) {
            switch (behavior) {
            case EBhRequire:
                error(getCurrentLoc(), "extension not supported:", "#extension", extension);
                break;
            case EBhEnable:
            case EBhWarn:
            case EBhDisable:
                warn(getCurrentLoc(), "extension not supported:", "#extension", extension);
                break;
            default:
                assert(0 && "unexpected behavior");
            }

            return;
        } else {
            if (iter->second == EBhDisablePartial)
                warn(getCurrentLoc(), "extension is only partially supported:", "#extension", extension);
            if (behavior != EBhDisable)
                intermediate.addRequestedExtension(extension);
            iter->second = behavior;
        }
    }
}

// Check if extension is used with correct shader stage.
void TParseVersions::checkExtensionStage(const TSourceLoc& loc, const char * const extension)
{
    // GL_NV_mesh_shader extension is only allowed in task/mesh shaders
    if (strcmp(extension, "GL_NV_mesh_shader") == 0) {
        requireStage(loc, (EShLanguageMask)(EShLangTaskNVMask | EShLangMeshNVMask | EShLangFragmentMask),
                     "#extension GL_NV_mesh_shader");
        profileRequires(loc, ECoreProfile, 450, 0, "#extension GL_NV_mesh_shader");
        profileRequires(loc, EEsProfile, 320, 0, "#extension GL_NV_mesh_shader");
    }
}

// Check if extension has additional requirements
void TParseVersions::extensionRequires(const TSourceLoc &loc, const char * const extension, const char *behaviorString)
{
    bool isEnabled = false;
    if (!strcmp("require", behaviorString))
        isEnabled = true;
    else if (!strcmp("enable", behaviorString))
        isEnabled = true;

    if (isEnabled) {
        unsigned int minSpvVersion = 0;
        auto iter = extensionMinSpv.find(TString(extension));
        if (iter != extensionMinSpv.end())
            minSpvVersion = iter->second;
        requireSpv(loc, extension, minSpvVersion);
    }
}

// Call for any operation needing full GLSL integer data-type support.
void TParseVersions::fullIntegerCheck(const TSourceLoc& loc, const char* op)
{
    profileRequires(loc, ENoProfile, 130, nullptr, op);
    profileRequires(loc, EEsProfile, 300, nullptr, op);
}

// Call for any operation needing GLSL double data-type support.
void TParseVersions::doubleCheck(const TSourceLoc& loc, const char* op)
{

    //requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
    if (language == EShLangVertex) {
        const char* const f64_Extensions[] = {E_GL_ARB_gpu_shader_fp64, E_GL_ARB_vertex_attrib_64bit};
        profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, 2, f64_Extensions, op);
    } else
        profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader_fp64, op);
}

// Call for any operation needing GLSL float16 data-type support.
void TParseVersions::float16Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (!builtIn) {
        const char* const extensions[] = {
                                           E_GL_AMD_gpu_shader_half_float,
                                           E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_float16};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}

bool TParseVersions::float16Arithmetic()
{
    const char* const extensions[] = {
                                       E_GL_AMD_gpu_shader_half_float,
                                       E_GL_EXT_shader_explicit_arithmetic_types,
                                       E_GL_EXT_shader_explicit_arithmetic_types_float16};
    return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
}

bool TParseVersions::int16Arithmetic()
{
    const char* const extensions[] = {
                                       E_GL_AMD_gpu_shader_int16,
                                       E_GL_EXT_shader_explicit_arithmetic_types,
                                       E_GL_EXT_shader_explicit_arithmetic_types_int16};
    return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
}

bool TParseVersions::int8Arithmetic()
{
    const char* const extensions[] = {
                                       E_GL_EXT_shader_explicit_arithmetic_types,
                                       E_GL_EXT_shader_explicit_arithmetic_types_int8};
    return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
}

void TParseVersions::requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
{
    TString combined;
    combined = op;
    combined += ": ";
    combined += featureDesc;

    const char* const extensions[] = {
                                       E_GL_AMD_gpu_shader_half_float,
                                       E_GL_EXT_shader_explicit_arithmetic_types,
                                       E_GL_EXT_shader_explicit_arithmetic_types_float16};
    requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
}

void TParseVersions::requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
{
    TString combined;
    combined = op;
    combined += ": ";
    combined += featureDesc;

    const char* const extensions[] = {
                                       E_GL_AMD_gpu_shader_int16,
                                       E_GL_EXT_shader_explicit_arithmetic_types,
                                       E_GL_EXT_shader_explicit_arithmetic_types_int16};
    requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
}

void TParseVersions::requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
{
    TString combined;
    combined = op;
    combined += ": ";
    combined += featureDesc;

    const char* const extensions[] = {
                                       E_GL_EXT_shader_explicit_arithmetic_types,
                                       E_GL_EXT_shader_explicit_arithmetic_types_int8};
    requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
}

void TParseVersions::float16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (!builtIn) {
        const char* const extensions[] = {
                                           E_GL_AMD_gpu_shader_half_float,
                                           E_GL_EXT_shader_16bit_storage,
                                           E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_float16};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}

// Call for any operation needing GLSL float32 data-type support.
void TParseVersions::explicitFloat32Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (!builtIn) {
        const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_float32};
        requireExtensions(loc, 2, extensions, op);
    }
}

// Call for any operation needing GLSL float64 data-type support.
void TParseVersions::explicitFloat64Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (!builtIn) {
        const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_float64};
        requireExtensions(loc, 2, extensions, op);
        requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
        profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
    }
}

// Call for any operation needing GLSL explicit int8 data-type support.
void TParseVersions::explicitInt8Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
        const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_int8};
        requireExtensions(loc, 2, extensions, op);
    }
}

// Call for any operation needing GLSL float16 opaque-type support
void TParseVersions::float16OpaqueCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
        requireExtensions(loc, 1, &E_GL_AMD_gpu_shader_half_float_fetch, op);
        requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
        profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
    }
}

// Call for any operation needing GLSL explicit int16 data-type support.
void TParseVersions::explicitInt16Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
        const char* const extensions[] = {
                                           E_GL_AMD_gpu_shader_int16,
                                           E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_int16};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}

void TParseVersions::int16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
    	const char* const extensions[] = {
                                           E_GL_AMD_gpu_shader_int16,
                                           E_GL_EXT_shader_16bit_storage,
                                           E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_int16};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}

void TParseVersions::int8ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
    	const char* const extensions[] = {
                                           E_GL_EXT_shader_8bit_storage,
                                           E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_int8};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}

// Call for any operation needing GLSL explicit int32 data-type support.
void TParseVersions::explicitInt32Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
        const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_int32};
        requireExtensions(loc, 2, extensions, op);
    }
}

// Call for any operation needing GLSL 64-bit integer data-type support.
void TParseVersions::int64Check(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (! builtIn) {
        const char* const extensions[3] = {E_GL_ARB_gpu_shader_int64,
                                           E_GL_EXT_shader_explicit_arithmetic_types,
                                           E_GL_EXT_shader_explicit_arithmetic_types_int64};
        requireExtensions(loc, 3, extensions, op);
        requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
        profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
    }
}

void TParseVersions::fcoopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (!builtIn) {
        const char* const extensions[] = {E_GL_NV_cooperative_matrix};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}

void TParseVersions::intcoopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
{
    if (!builtIn) {
        const char* const extensions[] = {E_GL_NV_integer_cooperative_matrix};
        requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
    }
}
#endif // GLSLANG_WEB
// Call for any operation removed because SPIR-V is in use.
void TParseVersions::spvRemoved(const TSourceLoc& loc, const char* op)
{
    if (spvVersion.spv != 0)
        error(loc, "not allowed when generating SPIR-V", op, "");
}

// Call for any operation removed because Vulkan SPIR-V is being generated.
void TParseVersions::vulkanRemoved(const TSourceLoc& loc, const char* op)
{
    if (spvVersion.vulkan > 0)
        error(loc, "not allowed when using GLSL for Vulkan", op, "");
}

// Call for any operation that requires Vulkan.
void TParseVersions::requireVulkan(const TSourceLoc& loc, const char* op)
{
#ifndef GLSLANG_WEB
    if (spvVersion.vulkan == 0)
        error(loc, "only allowed when using GLSL for Vulkan", op, "");
#endif
}

// Call for any operation that requires SPIR-V.
void TParseVersions::requireSpv(const TSourceLoc& loc, const char* op)
{
#ifndef GLSLANG_WEB
    if (spvVersion.spv == 0)
        error(loc, "only allowed when generating SPIR-V", op, "");
#endif
}
void TParseVersions::requireSpv(const TSourceLoc& loc, const char *op, unsigned int version)
{
#ifndef GLSLANG_WEB
    if (spvVersion.spv < version)
        error(loc, "not supported for current targeted SPIR-V version", op, "");
#endif
}

} // end namespace glslang