Add support for GL_NV_shader_invocation_reorder. (#3054)
[platform/upstream/glslang.git] / glslang / MachineIndependent / Versions.cpp
1 //
2 // Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
3 // Copyright (C) 2012-2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
5 // Copyright (C) 2015-2020 Google, Inc.
6 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
7 //
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
12 // are met:
13 //
14 //    Redistributions of source code must retain the above copyright
15 //    notice, this list of conditions and the following disclaimer.
16 //
17 //    Redistributions in binary form must reproduce the above
18 //    copyright notice, this list of conditions and the following
19 //    disclaimer in the documentation and/or other materials provided
20 //    with the distribution.
21 //
22 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
23 //    contributors may be used to endorse or promote products derived
24 //    from this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 // POSSIBILITY OF SUCH DAMAGE.
38 //
39
40 //
41 // Help manage multiple profiles, versions, extensions etc.
42 //
43 // These don't return error codes, as the presumption is parsing will
44 // always continue as if the tested feature were enabled, and thus there
45 // is no error recovery needed.
46 //
47
48 //
49 // HOW TO add a feature enabled by an extension.
50 //
51 // To add a new hypothetical "Feature F" to the front end, where an extension
52 // "XXX_extension_X" can be used to enable the feature, do the following.
53 //
54 // OVERVIEW: Specific features are what are error-checked for, not
55 //    extensions:  A specific Feature F might be enabled by an extension, or a
56 //    particular version in a particular profile, or a stage, or combinations, etc.
57 //
58 //    The basic mechanism is to use the following to "declare" all the things that
59 //    enable/disable Feature F, in a code path that implements Feature F:
60 //
61 //        requireProfile()
62 //        profileRequires()
63 //        requireStage()
64 //        checkDeprecated()
65 //        requireNotRemoved()
66 //        requireExtensions()
67 //        extensionRequires()
68 //
69 //    Typically, only the first two calls are needed.  They go into a code path that
70 //    implements Feature F, and will log the proper error/warning messages.  Parsing
71 //    will then always continue as if the tested feature was enabled.
72 //
73 //    There is typically no if-testing or conditional parsing, just insertion of the calls above.
74 //    However, if symbols specific to the extension are added (step 5), they will
75 //    only be added under tests that the minimum version and profile are present.
76 //
77 // 1) Add a symbol name for the extension string at the bottom of Versions.h:
78 //
79 //     const char* const XXX_extension_X = "XXX_extension_X";
80 //
81 // 2) Add extension initialization to TParseVersions::initializeExtensionBehavior(),
82 //    the first function below and optionally a entry to extensionData for additional
83 //    error checks:
84 //
85 //     extensionBehavior[XXX_extension_X] = EBhDisable;
86 //     (Optional) exts[] = {XXX_extension_X, EShTargetSpv_1_4}
87 //
88 // 3) Add any preprocessor directives etc. in the next function, TParseVersions::getPreamble():
89 //
90 //           "#define XXX_extension_X 1\n"
91 //
92 //    The new-line is important, as that ends preprocess tokens.
93 //
94 // 4) Insert a profile check in the feature's path (unless all profiles support the feature,
95 //    for some version level).  That is, call requireProfile() to constrain the profiles, e.g.:
96 //
97 //         // ... in a path specific to Feature F...
98 //         requireProfile(loc,
99 //                        ECoreProfile | ECompatibilityProfile,
100 //                        "Feature F");
101 //
102 // 5) For each profile that supports the feature, insert version/extension checks:
103 //
104 //    The mostly likely scenario is that Feature F can only be used with a
105 //    particular profile if XXX_extension_X is present or the version is
106 //    high enough that the core specification already incorporated it.
107 //
108 //        // following the requireProfile() call...
109 //        profileRequires(loc,
110 //                        ECoreProfile | ECompatibilityProfile,
111 //                        420,             // 0 if no version incorporated the feature into the core spec.
112 //                        XXX_extension_X, // can be a list of extensions that all add the feature
113 //                        "Feature F Description");
114 //
115 //    This allows the feature if either A) one of the extensions is enabled or
116 //    B) the version is high enough.  If no version yet incorporates the feature
117 //    into core, pass in 0.
118 //
119 //    This can be called multiple times, if different profiles support the
120 //    feature starting at different version numbers or with different
121 //    extensions.
122 //
123 //    This must be called for each profile allowed by the initial call to requireProfile().
124 //
125 //    Profiles are all masks, which can be "or"-ed together.
126 //
127 //        ENoProfile
128 //        ECoreProfile
129 //        ECompatibilityProfile
130 //        EEsProfile
131 //
132 //    The ENoProfile profile is only for desktop, before profiles showed up in version 150;
133 //    All other #version with no profile default to either es or core, and so have profiles.
134 //
135 //    You can select all but a particular profile using ~.  The following basically means "desktop":
136 //
137 //        ~EEsProfile
138 //
139 // 6) If built-in symbols are added by the extension, add them in Initialize.cpp:  Their use
140 //    will be automatically error checked against the extensions enabled at that moment.
141 //    see the comment at the top of Initialize.cpp for where to put them.  Establish them at
142 //    the earliest release that supports the extension.  Then, tag them with the
143 //    set of extensions that both enable them and are necessary, given the version of the symbol
144 //    table. (There is a different symbol table for each version.)
145 //
146 // 7) If the extension has additional requirements like minimum SPIR-V version required, add them
147 //    to extensionRequires()
148
149 #include "parseVersions.h"
150 #include "localintermediate.h"
151
152 namespace glslang {
153
154 #ifndef GLSLANG_WEB
155
156 //
157 // Initialize all extensions, almost always to 'disable', as once their features
158 // are incorporated into a core version, their features are supported through allowing that
159 // core version, not through a pseudo-enablement of the extension.
160 //
161 void TParseVersions::initializeExtensionBehavior()
162 {
163     typedef struct {
164         const char *const extensionName;
165         EShTargetLanguageVersion minSpvVersion;
166     } extensionData;
167
168     const extensionData exts[] = { {E_GL_EXT_ray_tracing, EShTargetSpv_1_4},
169                                    {E_GL_NV_ray_tracing_motion_blur, EShTargetSpv_1_4},
170                                    {E_GL_EXT_mesh_shader, EShTargetSpv_1_4}
171                                  };
172
173     for (size_t ii = 0; ii < sizeof(exts) / sizeof(exts[0]); ii++) {
174         // Add only extensions which require > spv1.0 to save space in map
175         if (exts[ii].minSpvVersion > EShTargetSpv_1_0) {
176             extensionMinSpv[exts[ii].extensionName] = exts[ii].minSpvVersion;
177         }
178     }
179
180     extensionBehavior[E_GL_OES_texture_3D]                   = EBhDisable;
181     extensionBehavior[E_GL_OES_standard_derivatives]         = EBhDisable;
182     extensionBehavior[E_GL_EXT_frag_depth]                   = EBhDisable;
183     extensionBehavior[E_GL_OES_EGL_image_external]           = EBhDisable;
184     extensionBehavior[E_GL_OES_EGL_image_external_essl3]     = EBhDisable;
185     extensionBehavior[E_GL_EXT_YUV_target]                   = EBhDisable;
186     extensionBehavior[E_GL_EXT_shader_texture_lod]           = EBhDisable;
187     extensionBehavior[E_GL_EXT_shadow_samplers]              = EBhDisable;
188     extensionBehavior[E_GL_ARB_texture_rectangle]            = EBhDisable;
189     extensionBehavior[E_GL_3DL_array_objects]                = EBhDisable;
190     extensionBehavior[E_GL_ARB_shading_language_420pack]     = EBhDisable;
191     extensionBehavior[E_GL_ARB_texture_gather]               = EBhDisable;
192     extensionBehavior[E_GL_ARB_gpu_shader5]                  = EBhDisablePartial;
193     extensionBehavior[E_GL_ARB_separate_shader_objects]      = EBhDisable;
194     extensionBehavior[E_GL_ARB_compute_shader]               = EBhDisable;
195     extensionBehavior[E_GL_ARB_tessellation_shader]          = EBhDisable;
196     extensionBehavior[E_GL_ARB_enhanced_layouts]             = EBhDisable;
197     extensionBehavior[E_GL_ARB_texture_cube_map_array]       = EBhDisable;
198     extensionBehavior[E_GL_ARB_texture_multisample]          = EBhDisable;
199     extensionBehavior[E_GL_ARB_shader_texture_lod]           = EBhDisable;
200     extensionBehavior[E_GL_ARB_explicit_attrib_location]     = EBhDisable;
201     extensionBehavior[E_GL_ARB_explicit_uniform_location]    = EBhDisable;
202     extensionBehavior[E_GL_ARB_shader_image_load_store]      = EBhDisable;
203     extensionBehavior[E_GL_ARB_shader_atomic_counters]       = EBhDisable;
204     extensionBehavior[E_GL_ARB_shader_atomic_counter_ops]    = EBhDisable;
205     extensionBehavior[E_GL_ARB_shader_draw_parameters]       = EBhDisable;
206     extensionBehavior[E_GL_ARB_shader_group_vote]            = EBhDisable;
207     extensionBehavior[E_GL_ARB_derivative_control]           = EBhDisable;
208     extensionBehavior[E_GL_ARB_shader_texture_image_samples] = EBhDisable;
209     extensionBehavior[E_GL_ARB_viewport_array]               = EBhDisable;
210     extensionBehavior[E_GL_ARB_gpu_shader_int64]             = EBhDisable;
211     extensionBehavior[E_GL_ARB_gpu_shader_fp64]              = EBhDisable;
212     extensionBehavior[E_GL_ARB_shader_ballot]                = EBhDisable;
213     extensionBehavior[E_GL_ARB_sparse_texture2]              = EBhDisable;
214     extensionBehavior[E_GL_ARB_sparse_texture_clamp]         = EBhDisable;
215     extensionBehavior[E_GL_ARB_shader_stencil_export]        = EBhDisable;
216 //    extensionBehavior[E_GL_ARB_cull_distance]                = EBhDisable;    // present for 4.5, but need extension control over block members
217     extensionBehavior[E_GL_ARB_post_depth_coverage]          = EBhDisable;
218     extensionBehavior[E_GL_ARB_shader_viewport_layer_array]  = EBhDisable;
219     extensionBehavior[E_GL_ARB_fragment_shader_interlock]    = EBhDisable;
220     extensionBehavior[E_GL_ARB_shader_clock]                 = EBhDisable;
221     extensionBehavior[E_GL_ARB_uniform_buffer_object]        = EBhDisable;
222     extensionBehavior[E_GL_ARB_sample_shading]               = EBhDisable;
223     extensionBehavior[E_GL_ARB_shader_bit_encoding]          = EBhDisable;
224     extensionBehavior[E_GL_ARB_shader_image_size]            = EBhDisable;
225     extensionBehavior[E_GL_ARB_shader_storage_buffer_object] = EBhDisable;
226     extensionBehavior[E_GL_ARB_shading_language_packing]     = EBhDisable;
227     extensionBehavior[E_GL_ARB_texture_query_lod]            = EBhDisable;
228     extensionBehavior[E_GL_ARB_vertex_attrib_64bit]          = EBhDisable;
229     extensionBehavior[E_GL_ARB_draw_instanced]               = EBhDisable;
230     extensionBehavior[E_GL_ARB_bindless_texture]             = EBhDisable;
231     extensionBehavior[E_GL_ARB_fragment_coord_conventions]   = EBhDisable;
232
233
234     extensionBehavior[E_GL_KHR_shader_subgroup_basic]            = EBhDisable;
235     extensionBehavior[E_GL_KHR_shader_subgroup_vote]             = EBhDisable;
236     extensionBehavior[E_GL_KHR_shader_subgroup_arithmetic]       = EBhDisable;
237     extensionBehavior[E_GL_KHR_shader_subgroup_ballot]           = EBhDisable;
238     extensionBehavior[E_GL_KHR_shader_subgroup_shuffle]          = EBhDisable;
239     extensionBehavior[E_GL_KHR_shader_subgroup_shuffle_relative] = EBhDisable;
240     extensionBehavior[E_GL_KHR_shader_subgroup_clustered]        = EBhDisable;
241     extensionBehavior[E_GL_KHR_shader_subgroup_quad]             = EBhDisable;
242     extensionBehavior[E_GL_KHR_memory_scope_semantics]           = EBhDisable;
243
244     extensionBehavior[E_GL_EXT_shader_atomic_int64]              = EBhDisable;
245
246     extensionBehavior[E_GL_EXT_shader_non_constant_global_initializers] = EBhDisable;
247     extensionBehavior[E_GL_EXT_shader_image_load_formatted]             = EBhDisable;
248     extensionBehavior[E_GL_EXT_post_depth_coverage]                     = EBhDisable;
249     extensionBehavior[E_GL_EXT_control_flow_attributes]                 = EBhDisable;
250     extensionBehavior[E_GL_EXT_nonuniform_qualifier]                    = EBhDisable;
251     extensionBehavior[E_GL_EXT_samplerless_texture_functions]           = EBhDisable;
252     extensionBehavior[E_GL_EXT_scalar_block_layout]                     = EBhDisable;
253     extensionBehavior[E_GL_EXT_fragment_invocation_density]             = EBhDisable;
254     extensionBehavior[E_GL_EXT_buffer_reference]                        = EBhDisable;
255     extensionBehavior[E_GL_EXT_buffer_reference2]                       = EBhDisable;
256     extensionBehavior[E_GL_EXT_buffer_reference_uvec2]                  = EBhDisable;
257     extensionBehavior[E_GL_EXT_demote_to_helper_invocation]             = EBhDisable;
258     extensionBehavior[E_GL_EXT_debug_printf]                            = EBhDisable;
259
260     extensionBehavior[E_GL_EXT_shader_16bit_storage]                    = EBhDisable;
261     extensionBehavior[E_GL_EXT_shader_8bit_storage]                     = EBhDisable;
262     extensionBehavior[E_GL_EXT_subgroup_uniform_control_flow]           = EBhDisable;
263
264     extensionBehavior[E_GL_EXT_fragment_shader_barycentric]             = EBhDisable;
265
266     // #line and #include
267     extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive]          = EBhDisable;
268     extensionBehavior[E_GL_GOOGLE_include_directive]                 = EBhDisable;
269
270     extensionBehavior[E_GL_AMD_shader_ballot]                        = EBhDisable;
271     extensionBehavior[E_GL_AMD_shader_trinary_minmax]                = EBhDisable;
272     extensionBehavior[E_GL_AMD_shader_explicit_vertex_parameter]     = EBhDisable;
273     extensionBehavior[E_GL_AMD_gcn_shader]                           = EBhDisable;
274     extensionBehavior[E_GL_AMD_gpu_shader_half_float]                = EBhDisable;
275     extensionBehavior[E_GL_AMD_texture_gather_bias_lod]              = EBhDisable;
276     extensionBehavior[E_GL_AMD_gpu_shader_int16]                     = EBhDisable;
277     extensionBehavior[E_GL_AMD_shader_image_load_store_lod]          = EBhDisable;
278     extensionBehavior[E_GL_AMD_shader_fragment_mask]                 = EBhDisable;
279     extensionBehavior[E_GL_AMD_gpu_shader_half_float_fetch]          = EBhDisable;
280     extensionBehavior[E_GL_AMD_shader_early_and_late_fragment_tests] = EBhDisable;
281
282     extensionBehavior[E_GL_INTEL_shader_integer_functions2]          = EBhDisable;
283
284     extensionBehavior[E_GL_NV_sample_mask_override_coverage]         = EBhDisable;
285     extensionBehavior[E_SPV_NV_geometry_shader_passthrough]          = EBhDisable;
286     extensionBehavior[E_GL_NV_viewport_array2]                       = EBhDisable;
287     extensionBehavior[E_GL_NV_stereo_view_rendering]                 = EBhDisable;
288     extensionBehavior[E_GL_NVX_multiview_per_view_attributes]        = EBhDisable;
289     extensionBehavior[E_GL_NV_shader_atomic_int64]                   = EBhDisable;
290     extensionBehavior[E_GL_NV_conservative_raster_underestimation]   = EBhDisable;
291     extensionBehavior[E_GL_NV_shader_noperspective_interpolation]    = EBhDisable;
292     extensionBehavior[E_GL_NV_shader_subgroup_partitioned]           = EBhDisable;
293     extensionBehavior[E_GL_NV_shading_rate_image]                    = EBhDisable;
294     extensionBehavior[E_GL_NV_ray_tracing]                           = EBhDisable;
295     extensionBehavior[E_GL_NV_ray_tracing_motion_blur]               = EBhDisable;
296     extensionBehavior[E_GL_NV_fragment_shader_barycentric]           = EBhDisable;
297     extensionBehavior[E_GL_NV_compute_shader_derivatives]            = EBhDisable;
298     extensionBehavior[E_GL_NV_shader_texture_footprint]              = EBhDisable;
299     extensionBehavior[E_GL_NV_mesh_shader]                           = EBhDisable;
300
301     extensionBehavior[E_GL_NV_cooperative_matrix]                    = EBhDisable;
302     extensionBehavior[E_GL_NV_shader_sm_builtins]                    = EBhDisable;
303     extensionBehavior[E_GL_NV_integer_cooperative_matrix]            = EBhDisable;
304
305     extensionBehavior[E_GL_NV_shader_invocation_reorder]             = EBhDisable;
306
307     // ARM
308     extensionBehavior[E_GL_ARM_shader_core_builtins]                 = EBhDisable;
309
310     // AEP
311     extensionBehavior[E_GL_ANDROID_extension_pack_es31a]             = EBhDisable;
312     extensionBehavior[E_GL_KHR_blend_equation_advanced]              = EBhDisable;
313     extensionBehavior[E_GL_OES_sample_variables]                     = EBhDisable;
314     extensionBehavior[E_GL_OES_shader_image_atomic]                  = EBhDisable;
315     extensionBehavior[E_GL_OES_shader_multisample_interpolation]     = EBhDisable;
316     extensionBehavior[E_GL_OES_texture_storage_multisample_2d_array] = EBhDisable;
317     extensionBehavior[E_GL_EXT_geometry_shader]                      = EBhDisable;
318     extensionBehavior[E_GL_EXT_geometry_point_size]                  = EBhDisable;
319     extensionBehavior[E_GL_EXT_gpu_shader5]                          = EBhDisable;
320     extensionBehavior[E_GL_EXT_primitive_bounding_box]               = EBhDisable;
321     extensionBehavior[E_GL_EXT_shader_io_blocks]                     = EBhDisable;
322     extensionBehavior[E_GL_EXT_tessellation_shader]                  = EBhDisable;
323     extensionBehavior[E_GL_EXT_tessellation_point_size]              = EBhDisable;
324     extensionBehavior[E_GL_EXT_texture_buffer]                       = EBhDisable;
325     extensionBehavior[E_GL_EXT_texture_cube_map_array]               = EBhDisable;
326     extensionBehavior[E_GL_EXT_null_initializer]                     = EBhDisable;
327
328     // OES matching AEP
329     extensionBehavior[E_GL_OES_geometry_shader]          = EBhDisable;
330     extensionBehavior[E_GL_OES_geometry_point_size]      = EBhDisable;
331     extensionBehavior[E_GL_OES_gpu_shader5]              = EBhDisable;
332     extensionBehavior[E_GL_OES_primitive_bounding_box]   = EBhDisable;
333     extensionBehavior[E_GL_OES_shader_io_blocks]         = EBhDisable;
334     extensionBehavior[E_GL_OES_tessellation_shader]      = EBhDisable;
335     extensionBehavior[E_GL_OES_tessellation_point_size]  = EBhDisable;
336     extensionBehavior[E_GL_OES_texture_buffer]           = EBhDisable;
337     extensionBehavior[E_GL_OES_texture_cube_map_array]   = EBhDisable;
338     extensionBehavior[E_GL_EXT_shader_integer_mix]       = EBhDisable;
339
340     // EXT extensions
341     extensionBehavior[E_GL_EXT_device_group]                = EBhDisable;
342     extensionBehavior[E_GL_EXT_multiview]                   = EBhDisable;
343     extensionBehavior[E_GL_EXT_shader_realtime_clock]       = EBhDisable;
344     extensionBehavior[E_GL_EXT_ray_tracing]                 = EBhDisable;
345     extensionBehavior[E_GL_EXT_ray_query]                   = EBhDisable;
346     extensionBehavior[E_GL_EXT_ray_flags_primitive_culling] = EBhDisable;
347     extensionBehavior[E_GL_EXT_ray_cull_mask]               = EBhDisable;
348     extensionBehavior[E_GL_EXT_blend_func_extended]         = EBhDisable;
349     extensionBehavior[E_GL_EXT_shader_implicit_conversions] = EBhDisable;
350     extensionBehavior[E_GL_EXT_fragment_shading_rate]       = EBhDisable;
351     extensionBehavior[E_GL_EXT_shader_image_int64]          = EBhDisable;
352     extensionBehavior[E_GL_EXT_terminate_invocation]        = EBhDisable;
353     extensionBehavior[E_GL_EXT_shared_memory_block]         = EBhDisable;
354     extensionBehavior[E_GL_EXT_spirv_intrinsics]            = EBhDisable;
355     extensionBehavior[E_GL_EXT_mesh_shader]                 = EBhDisable;
356     extensionBehavior[E_GL_EXT_opacity_micromap]            = EBhDisable;
357
358     // OVR extensions
359     extensionBehavior[E_GL_OVR_multiview]                = EBhDisable;
360     extensionBehavior[E_GL_OVR_multiview2]               = EBhDisable;
361
362     // explicit types
363     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types]         = EBhDisable;
364     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int8]    = EBhDisable;
365     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int16]   = EBhDisable;
366     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int32]   = EBhDisable;
367     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int64]   = EBhDisable;
368     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float16] = EBhDisable;
369     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float32] = EBhDisable;
370     extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float64] = EBhDisable;
371
372     // subgroup extended types
373     extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int8]    = EBhDisable;
374     extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int16]   = EBhDisable;
375     extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int64]   = EBhDisable;
376     extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_float16] = EBhDisable;
377     extensionBehavior[E_GL_EXT_shader_atomic_float]                    = EBhDisable;
378     extensionBehavior[E_GL_EXT_shader_atomic_float2]                   = EBhDisable;
379
380     // Record extensions not for spv.
381     spvUnsupportedExt.push_back(E_GL_ARB_bindless_texture);
382 }
383
384 #endif // GLSLANG_WEB
385
386 // Get code that is not part of a shared symbol table, is specific to this shader,
387 // or needed by the preprocessor (which does not use a shared symbol table).
388 void TParseVersions::getPreamble(std::string& preamble)
389 {
390     if (isEsProfile()) {
391         preamble =
392             "#define GL_ES 1\n"
393             "#define GL_FRAGMENT_PRECISION_HIGH 1\n"
394 #ifdef GLSLANG_WEB
395             ;
396 #else
397             "#define GL_OES_texture_3D 1\n"
398             "#define GL_OES_standard_derivatives 1\n"
399             "#define GL_EXT_frag_depth 1\n"
400             "#define GL_OES_EGL_image_external 1\n"
401             "#define GL_OES_EGL_image_external_essl3 1\n"
402             "#define GL_EXT_YUV_target 1\n"
403             "#define GL_EXT_shader_texture_lod 1\n"
404             "#define GL_EXT_shadow_samplers 1\n"
405             "#define GL_EXT_fragment_shading_rate 1\n"
406
407             // AEP
408             "#define GL_ANDROID_extension_pack_es31a 1\n"
409             "#define GL_OES_sample_variables 1\n"
410             "#define GL_OES_shader_image_atomic 1\n"
411             "#define GL_OES_shader_multisample_interpolation 1\n"
412             "#define GL_OES_texture_storage_multisample_2d_array 1\n"
413             "#define GL_EXT_geometry_shader 1\n"
414             "#define GL_EXT_geometry_point_size 1\n"
415             "#define GL_EXT_gpu_shader5 1\n"
416             "#define GL_EXT_primitive_bounding_box 1\n"
417             "#define GL_EXT_shader_io_blocks 1\n"
418             "#define GL_EXT_tessellation_shader 1\n"
419             "#define GL_EXT_tessellation_point_size 1\n"
420             "#define GL_EXT_texture_buffer 1\n"
421             "#define GL_EXT_texture_cube_map_array 1\n"
422             "#define GL_EXT_shader_implicit_conversions 1\n"
423             "#define GL_EXT_shader_integer_mix 1\n"
424             "#define GL_EXT_blend_func_extended 1\n"
425
426             // OES matching AEP
427             "#define GL_OES_geometry_shader 1\n"
428             "#define GL_OES_geometry_point_size 1\n"
429             "#define GL_OES_gpu_shader5 1\n"
430             "#define GL_OES_primitive_bounding_box 1\n"
431             "#define GL_OES_shader_io_blocks 1\n"
432             "#define GL_OES_tessellation_shader 1\n"
433             "#define GL_OES_tessellation_point_size 1\n"
434             "#define GL_OES_texture_buffer 1\n"
435             "#define GL_OES_texture_cube_map_array 1\n"
436             "#define GL_EXT_shader_non_constant_global_initializers 1\n"
437             ;
438
439             if (version >= 300) {
440                 preamble += "#define GL_NV_shader_noperspective_interpolation 1\n";
441             }
442             if (version >= 310) {
443                 preamble += "#define GL_EXT_null_initializer 1\n";
444                 preamble += "#define GL_EXT_subgroup_uniform_control_flow 1\n";
445             }
446
447     } else { // !isEsProfile()
448         preamble =
449             "#define GL_ARB_texture_rectangle 1\n"
450             "#define GL_ARB_shading_language_420pack 1\n"
451             "#define GL_ARB_texture_gather 1\n"
452             "#define GL_ARB_gpu_shader5 1\n"
453             "#define GL_ARB_separate_shader_objects 1\n"
454             "#define GL_ARB_compute_shader 1\n"
455             "#define GL_ARB_tessellation_shader 1\n"
456             "#define GL_ARB_enhanced_layouts 1\n"
457             "#define GL_ARB_texture_cube_map_array 1\n"
458             "#define GL_ARB_texture_multisample 1\n"
459             "#define GL_ARB_shader_texture_lod 1\n"
460             "#define GL_ARB_explicit_attrib_location 1\n"
461             "#define GL_ARB_explicit_uniform_location 1\n"
462             "#define GL_ARB_shader_image_load_store 1\n"
463             "#define GL_ARB_shader_atomic_counters 1\n"
464             "#define GL_ARB_shader_draw_parameters 1\n"
465             "#define GL_ARB_shader_group_vote 1\n"
466             "#define GL_ARB_derivative_control 1\n"
467             "#define GL_ARB_shader_texture_image_samples 1\n"
468             "#define GL_ARB_viewport_array 1\n"
469             "#define GL_ARB_gpu_shader_int64 1\n"
470             "#define GL_ARB_gpu_shader_fp64 1\n"
471             "#define GL_ARB_shader_ballot 1\n"
472             "#define GL_ARB_sparse_texture2 1\n"
473             "#define GL_ARB_sparse_texture_clamp 1\n"
474             "#define GL_ARB_shader_stencil_export 1\n"
475             "#define GL_ARB_sample_shading 1\n"
476             "#define GL_ARB_shader_image_size 1\n"
477             "#define GL_ARB_shading_language_packing 1\n"
478 //            "#define GL_ARB_cull_distance 1\n"    // present for 4.5, but need extension control over block members
479             "#define GL_ARB_post_depth_coverage 1\n"
480             "#define GL_ARB_fragment_shader_interlock 1\n"
481             "#define GL_ARB_uniform_buffer_object 1\n"
482             "#define GL_ARB_shader_bit_encoding 1\n"
483             "#define GL_ARB_shader_storage_buffer_object 1\n"
484             "#define GL_ARB_texture_query_lod 1\n"
485             "#define GL_ARB_vertex_attrib_64bit 1\n"
486             "#define GL_ARB_draw_instanced 1\n"
487             "#define GL_ARB_fragment_coord_conventions 1\n"
488             "#define GL_ARB_bindless_texture 1\n"
489             "#define GL_EXT_shader_non_constant_global_initializers 1\n"
490             "#define GL_EXT_shader_image_load_formatted 1\n"
491             "#define GL_EXT_post_depth_coverage 1\n"
492             "#define GL_EXT_control_flow_attributes 1\n"
493             "#define GL_EXT_nonuniform_qualifier 1\n"
494             "#define GL_EXT_shader_16bit_storage 1\n"
495             "#define GL_EXT_shader_8bit_storage 1\n"
496             "#define GL_EXT_samplerless_texture_functions 1\n"
497             "#define GL_EXT_scalar_block_layout 1\n"
498             "#define GL_EXT_fragment_invocation_density 1\n"
499             "#define GL_EXT_buffer_reference 1\n"
500             "#define GL_EXT_buffer_reference2 1\n"
501             "#define GL_EXT_buffer_reference_uvec2 1\n"
502             "#define GL_EXT_demote_to_helper_invocation 1\n"
503             "#define GL_EXT_debug_printf 1\n"
504             "#define GL_EXT_fragment_shading_rate 1\n"
505             "#define GL_EXT_shared_memory_block 1\n"
506             "#define GL_EXT_shader_integer_mix 1\n"
507
508             // GL_KHR_shader_subgroup
509             "#define GL_KHR_shader_subgroup_basic 1\n"
510             "#define GL_KHR_shader_subgroup_vote 1\n"
511             "#define GL_KHR_shader_subgroup_arithmetic 1\n"
512             "#define GL_KHR_shader_subgroup_ballot 1\n"
513             "#define GL_KHR_shader_subgroup_shuffle 1\n"
514             "#define GL_KHR_shader_subgroup_shuffle_relative 1\n"
515             "#define GL_KHR_shader_subgroup_clustered 1\n"
516             "#define GL_KHR_shader_subgroup_quad 1\n"
517
518             "#define GL_EXT_shader_image_int64 1\n"
519             "#define GL_EXT_shader_atomic_int64 1\n"
520             "#define GL_EXT_shader_realtime_clock 1\n"
521             "#define GL_EXT_ray_tracing 1\n"
522             "#define GL_EXT_ray_query 1\n"
523             "#define GL_EXT_ray_flags_primitive_culling 1\n"
524             "#define GL_EXT_ray_cull_mask 1\n"
525             "#define GL_EXT_spirv_intrinsics 1\n"
526             "#define GL_EXT_mesh_shader 1\n"
527
528             "#define GL_AMD_shader_ballot 1\n"
529             "#define GL_AMD_shader_trinary_minmax 1\n"
530             "#define GL_AMD_shader_explicit_vertex_parameter 1\n"
531             "#define GL_AMD_gcn_shader 1\n"
532             "#define GL_AMD_gpu_shader_half_float 1\n"
533             "#define GL_AMD_texture_gather_bias_lod 1\n"
534             "#define GL_AMD_gpu_shader_int16 1\n"
535             "#define GL_AMD_shader_image_load_store_lod 1\n"
536             "#define GL_AMD_shader_fragment_mask 1\n"
537             "#define GL_AMD_gpu_shader_half_float_fetch 1\n"
538
539             "#define GL_INTEL_shader_integer_functions2 1\n"
540
541             "#define GL_NV_sample_mask_override_coverage 1\n"
542             "#define GL_NV_geometry_shader_passthrough 1\n"
543             "#define GL_NV_viewport_array2 1\n"
544             "#define GL_NV_shader_atomic_int64 1\n"
545             "#define GL_NV_conservative_raster_underestimation 1\n"
546             "#define GL_NV_shader_subgroup_partitioned 1\n"
547             "#define GL_NV_shading_rate_image 1\n"
548             "#define GL_NV_ray_tracing 1\n"
549             "#define GL_NV_ray_tracing_motion_blur 1\n"
550             "#define GL_NV_fragment_shader_barycentric 1\n"
551             "#define GL_NV_compute_shader_derivatives 1\n"
552             "#define GL_NV_shader_texture_footprint 1\n"
553             "#define GL_NV_mesh_shader 1\n"
554             "#define GL_NV_cooperative_matrix 1\n"
555             "#define GL_NV_integer_cooperative_matrix 1\n"
556             "#define GL_NV_shader_execution_reorder 1\n"
557
558             "#define GL_EXT_shader_explicit_arithmetic_types 1\n"
559             "#define GL_EXT_shader_explicit_arithmetic_types_int8 1\n"
560             "#define GL_EXT_shader_explicit_arithmetic_types_int16 1\n"
561             "#define GL_EXT_shader_explicit_arithmetic_types_int32 1\n"
562             "#define GL_EXT_shader_explicit_arithmetic_types_int64 1\n"
563             "#define GL_EXT_shader_explicit_arithmetic_types_float16 1\n"
564             "#define GL_EXT_shader_explicit_arithmetic_types_float32 1\n"
565             "#define GL_EXT_shader_explicit_arithmetic_types_float64 1\n"
566
567             "#define GL_EXT_shader_subgroup_extended_types_int8 1\n"
568             "#define GL_EXT_shader_subgroup_extended_types_int16 1\n"
569             "#define GL_EXT_shader_subgroup_extended_types_int64 1\n"
570             "#define GL_EXT_shader_subgroup_extended_types_float16 1\n"
571
572             "#define GL_EXT_shader_atomic_float 1\n"
573             "#define GL_EXT_shader_atomic_float2 1\n"
574
575             "#define GL_EXT_fragment_shader_barycentric 1\n"
576             ;
577
578         if (version >= 150) {
579             // define GL_core_profile and GL_compatibility_profile
580             preamble += "#define GL_core_profile 1\n";
581
582             if (profile == ECompatibilityProfile)
583                 preamble += "#define GL_compatibility_profile 1\n";
584         }
585         if (version >= 140) {
586             preamble += "#define GL_EXT_null_initializer 1\n";
587             preamble += "#define GL_EXT_subgroup_uniform_control_flow 1\n";
588         }
589         if (version >= 130) {
590             preamble +="#define GL_FRAGMENT_PRECISION_HIGH 1\n";
591         }
592
593 #endif // GLSLANG_WEB
594     }
595
596 #ifndef GLSLANG_WEB
597     if ((!isEsProfile() && version >= 140) ||
598         (isEsProfile() && version >= 310)) {
599         preamble +=
600             "#define GL_EXT_device_group 1\n"
601             "#define GL_EXT_multiview 1\n"
602             "#define GL_NV_shader_sm_builtins 1\n"
603             ;
604     }
605
606     if (version >= 300 /* both ES and non-ES */) {
607         preamble +=
608             "#define GL_OVR_multiview 1\n"
609             "#define GL_OVR_multiview2 1\n"
610             ;
611     }
612
613     // #line and #include
614     preamble +=
615             "#define GL_GOOGLE_cpp_style_line_directive 1\n"
616             "#define GL_GOOGLE_include_directive 1\n"
617             "#define GL_KHR_blend_equation_advanced 1\n"
618             ;
619
620     // other general extensions
621     preamble +=
622             "#define GL_EXT_terminate_invocation 1\n"
623             ;
624 #endif
625
626     // #define VULKAN XXXX
627     const int numberBufSize = 12;
628     char numberBuf[numberBufSize];
629     if (spvVersion.vulkanGlsl > 0) {
630         preamble += "#define VULKAN ";
631         snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkanGlsl);
632         preamble += numberBuf;
633         preamble += "\n";
634     }
635
636 #ifndef GLSLANG_WEB
637     // #define GL_SPIRV XXXX
638     if (spvVersion.openGl > 0) {
639         preamble += "#define GL_SPIRV ";
640         snprintf(numberBuf, numberBufSize, "%d", spvVersion.openGl);
641         preamble += numberBuf;
642         preamble += "\n";
643     }
644 #endif
645
646 #ifndef GLSLANG_WEB
647     // GL_EXT_spirv_intrinsics
648     if (!isEsProfile()) {
649         switch (language) {
650         case EShLangVertex:         preamble += "#define GL_VERTEX_SHADER 1 \n";                    break;
651         case EShLangTessControl:    preamble += "#define GL_TESSELLATION_CONTROL_SHADER 1 \n";      break;
652         case EShLangTessEvaluation: preamble += "#define GL_TESSELLATION_EVALUATION_SHADER 1 \n";   break;
653         case EShLangGeometry:       preamble += "#define GL_GEOMETRY_SHADER 1 \n";                  break;
654         case EShLangFragment:       preamble += "#define GL_FRAGMENT_SHADER 1 \n";                  break;
655         case EShLangCompute:        preamble += "#define GL_COMPUTE_SHADER 1 \n";                   break;
656         case EShLangRayGen:         preamble += "#define GL_RAY_GENERATION_SHADER_EXT 1 \n";        break;
657         case EShLangIntersect:      preamble += "#define GL_INTERSECTION_SHADER_EXT 1 \n";          break;
658         case EShLangAnyHit:         preamble += "#define GL_ANY_HIT_SHADER_EXT 1 \n";               break;
659         case EShLangClosestHit:     preamble += "#define GL_CLOSEST_HIT_SHADER_EXT 1 \n";           break;
660         case EShLangMiss:           preamble += "#define GL_MISS_SHADER_EXT 1 \n";                  break;
661         case EShLangCallable:       preamble += "#define GL_CALLABLE_SHADER_EXT 1 \n";              break;
662         case EShLangTask:           preamble += "#define GL_TASK_SHADER_NV 1 \n";                   break;
663         case EShLangMesh:           preamble += "#define GL_MESH_SHADER_NV 1 \n";                   break;
664         default:                                                                                    break;
665         }
666     }
667 #endif
668 }
669
670 //
671 // Map from stage enum to externally readable text name.
672 //
673 const char* StageName(EShLanguage stage)
674 {
675     switch(stage) {
676     case EShLangVertex:         return "vertex";
677     case EShLangFragment:       return "fragment";
678     case EShLangCompute:        return "compute";
679 #ifndef GLSLANG_WEB
680     case EShLangTessControl:    return "tessellation control";
681     case EShLangTessEvaluation: return "tessellation evaluation";
682     case EShLangGeometry:       return "geometry";
683     case EShLangRayGen:         return "ray-generation";
684     case EShLangIntersect:      return "intersection";
685     case EShLangAnyHit:         return "any-hit";
686     case EShLangClosestHit:     return "closest-hit";
687     case EShLangMiss:           return "miss";
688     case EShLangCallable:       return "callable";
689     case EShLangMesh:           return "mesh";
690     case EShLangTask:           return "task";
691 #endif
692     default:                    return "unknown stage";
693     }
694 }
695
696 //
697 // When to use requireStage()
698 //
699 //     If only some stages support a feature.
700 //
701 // Operation: If the current stage is not present, give an error message.
702 //
703 void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguageMask languageMask, const char* featureDesc)
704 {
705     if (((1 << language) & languageMask) == 0)
706         error(loc, "not supported in this stage:", featureDesc, StageName(language));
707 }
708
709 // If only one stage supports a feature, this can be called.  But, all supporting stages
710 // must be specified with one call.
711 void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguage stage, const char* featureDesc)
712 {
713     requireStage(loc, static_cast<EShLanguageMask>(1 << stage), featureDesc);
714 }
715
716 #ifndef GLSLANG_WEB
717 //
718 // When to use requireProfile():
719 //
720 //     Use if only some profiles support a feature.  However, if within a profile the feature
721 //     is version or extension specific, follow this call with calls to profileRequires().
722 //
723 // Operation:  If the current profile is not one of the profileMask,
724 // give an error message.
725 //
726 void TParseVersions::requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc)
727 {
728     if (! (profile & profileMask))
729         error(loc, "not supported with this profile:", featureDesc, ProfileName(profile));
730 }
731
732 //
733 // When to use profileRequires():
734 //
735 //     If a set of profiles have the same requirements for what version or extensions
736 //     are needed to support a feature.
737 //
738 //     It must be called for each profile that needs protection.  Use requireProfile() first
739 //     to reduce that set of profiles.
740 //
741 // Operation: Will issue warnings/errors based on the current profile, version, and extension
742 // behaviors.  It only checks extensions when the current profile is one of the profileMask.
743 //
744 // A minVersion of 0 means no version of the profileMask support this in core,
745 // the extension must be present.
746 //
747
748 // entry point that takes multiple extensions
749 void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
750     const char* const extensions[], const char* featureDesc)
751 {
752     if (profile & profileMask) {
753         bool okay = minVersion > 0 && version >= minVersion;
754 #ifndef GLSLANG_WEB
755         for (int i = 0; i < numExtensions; ++i) {
756             switch (getExtensionBehavior(extensions[i])) {
757             case EBhWarn:
758                 infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
759                 // fall through
760             case EBhRequire:
761             case EBhEnable:
762                 okay = true;
763                 break;
764             default: break; // some compilers want this
765             }
766         }
767 #endif
768         if (! okay)
769             error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
770     }
771 }
772
773 // entry point for the above that takes a single extension
774 void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
775     const char* featureDesc)
776 {
777     profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc);
778 }
779
780 void TParseVersions::unimplemented(const TSourceLoc& loc, const char* featureDesc)
781 {
782     error(loc, "feature not yet implemented", featureDesc, "");
783 }
784
785 //
786 // Within a set of profiles, see if a feature is deprecated and give an error or warning based on whether
787 // a future compatibility context is being use.
788 //
789 void TParseVersions::checkDeprecated(const TSourceLoc& loc, int profileMask, int depVersion, const char* featureDesc)
790 {
791     if (profile & profileMask) {
792         if (version >= depVersion) {
793             if (forwardCompatible)
794                 error(loc, "deprecated, may be removed in future release", featureDesc, "");
795             else if (! suppressWarnings())
796                 infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
797                                                        String(depVersion) + "; may be removed in future release").c_str(), loc);
798         }
799     }
800 }
801
802 //
803 // Within a set of profiles, see if a feature has now been removed and if so, give an error.
804 // The version argument is the first version no longer having the feature.
805 //
806 void TParseVersions::requireNotRemoved(const TSourceLoc& loc, int profileMask, int removedVersion, const char* featureDesc)
807 {
808     if (profile & profileMask) {
809         if (version >= removedVersion) {
810             const int maxSize = 60;
811             char buf[maxSize];
812             snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName(profile), removedVersion);
813             error(loc, "no longer supported in", featureDesc, buf);
814         }
815     }
816 }
817
818 // Returns true if at least one of the extensions in the extensions parameter is requested. Otherwise, returns false.
819 // Warns appropriately if the requested behavior of an extension is "warn".
820 bool TParseVersions::checkExtensionsRequested(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
821 {
822     // First, see if any of the extensions are enabled
823     for (int i = 0; i < numExtensions; ++i) {
824         TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
825         if (behavior == EBhEnable || behavior == EBhRequire)
826             return true;
827     }
828
829     // See if any extensions want to give a warning on use; give warnings for all such extensions
830     bool warned = false;
831     for (int i = 0; i < numExtensions; ++i) {
832         TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
833         if (behavior == EBhDisable && relaxedErrors()) {
834             infoSink.info.message(EPrefixWarning, "The following extension must be enabled to use this feature:", loc);
835             behavior = EBhWarn;
836         }
837         if (behavior == EBhWarn) {
838             infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
839             warned = true;
840         }
841     }
842     if (warned)
843         return true;
844     return false;
845 }
846
847 //
848 // Use when there are no profile/version to check, it's just an error if one of the
849 // extensions is not present.
850 //
851 void TParseVersions::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
852     const char* featureDesc)
853 {
854     if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
855         return;
856
857     // If we get this far, give errors explaining what extensions are needed
858     if (numExtensions == 1)
859         error(loc, "required extension not requested:", featureDesc, extensions[0]);
860     else {
861         error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
862         for (int i = 0; i < numExtensions; ++i)
863             infoSink.info.message(EPrefixNone, extensions[i]);
864     }
865 }
866
867 //
868 // Use by preprocessor when there are no profile/version to check, it's just an error if one of the
869 // extensions is not present.
870 //
871 void TParseVersions::ppRequireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
872     const char* featureDesc)
873 {
874     if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
875         return;
876
877     // If we get this far, give errors explaining what extensions are needed
878     if (numExtensions == 1)
879         ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
880     else {
881         ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
882         for (int i = 0; i < numExtensions; ++i)
883             infoSink.info.message(EPrefixNone, extensions[i]);
884     }
885 }
886
887 TExtensionBehavior TParseVersions::getExtensionBehavior(const char* extension)
888 {
889     auto iter = extensionBehavior.find(TString(extension));
890     if (iter == extensionBehavior.end())
891         return EBhMissing;
892     else
893         return iter->second;
894 }
895
896 // Returns true if the given extension is set to enable, require, or warn.
897 bool TParseVersions::extensionTurnedOn(const char* const extension)
898 {
899       switch (getExtensionBehavior(extension)) {
900       case EBhEnable:
901       case EBhRequire:
902       case EBhWarn:
903           return true;
904       default:
905           break;
906       }
907       return false;
908 }
909 // See if any of the extensions are set to enable, require, or warn.
910 bool TParseVersions::extensionsTurnedOn(int numExtensions, const char* const extensions[])
911 {
912     for (int i = 0; i < numExtensions; ++i) {
913         if (extensionTurnedOn(extensions[i]))
914             return true;
915     }
916     return false;
917 }
918
919 //
920 // Change the current state of an extension's behavior.
921 //
922 void TParseVersions::updateExtensionBehavior(int line, const char* extension, const char* behaviorString)
923 {
924     // Translate from text string of extension's behavior to an enum.
925     TExtensionBehavior behavior = EBhDisable;
926     if (! strcmp("require", behaviorString))
927         behavior = EBhRequire;
928     else if (! strcmp("enable", behaviorString))
929         behavior = EBhEnable;
930     else if (! strcmp("disable", behaviorString))
931         behavior = EBhDisable;
932     else if (! strcmp("warn", behaviorString))
933         behavior = EBhWarn;
934     else {
935         error(getCurrentLoc(), "behavior not supported:", "#extension", behaviorString);
936         return;
937     }
938     bool on = behavior != EBhDisable;
939
940     // check if extension is used with correct shader stage
941     checkExtensionStage(getCurrentLoc(), extension);
942
943     // check if extension has additional requirements
944     extensionRequires(getCurrentLoc(), extension, behaviorString);
945
946     // update the requested extension
947     updateExtensionBehavior(extension, behavior);
948
949     // see if need to propagate to implicitly modified things
950     if (strcmp(extension, "GL_ANDROID_extension_pack_es31a") == 0) {
951         // to everything in AEP
952         updateExtensionBehavior(line, "GL_KHR_blend_equation_advanced", behaviorString);
953         updateExtensionBehavior(line, "GL_OES_sample_variables", behaviorString);
954         updateExtensionBehavior(line, "GL_OES_shader_image_atomic", behaviorString);
955         updateExtensionBehavior(line, "GL_OES_shader_multisample_interpolation", behaviorString);
956         updateExtensionBehavior(line, "GL_OES_texture_storage_multisample_2d_array", behaviorString);
957         updateExtensionBehavior(line, "GL_EXT_geometry_shader", behaviorString);
958         updateExtensionBehavior(line, "GL_EXT_gpu_shader5", behaviorString);
959         updateExtensionBehavior(line, "GL_EXT_primitive_bounding_box", behaviorString);
960         updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
961         updateExtensionBehavior(line, "GL_EXT_tessellation_shader", behaviorString);
962         updateExtensionBehavior(line, "GL_EXT_texture_buffer", behaviorString);
963         updateExtensionBehavior(line, "GL_EXT_texture_cube_map_array", behaviorString);
964     }
965     // geometry to io_blocks
966     else if (strcmp(extension, "GL_EXT_geometry_shader") == 0)
967         updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
968     else if (strcmp(extension, "GL_OES_geometry_shader") == 0)
969         updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
970     // tessellation to io_blocks
971     else if (strcmp(extension, "GL_EXT_tessellation_shader") == 0)
972         updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
973     else if (strcmp(extension, "GL_OES_tessellation_shader") == 0)
974         updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
975     else if (strcmp(extension, "GL_GOOGLE_include_directive") == 0)
976         updateExtensionBehavior(line, "GL_GOOGLE_cpp_style_line_directive", behaviorString);
977     // subgroup_* to subgroup_basic
978     else if (strcmp(extension, "GL_KHR_shader_subgroup_vote") == 0)
979         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
980     else if (strcmp(extension, "GL_KHR_shader_subgroup_arithmetic") == 0)
981         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
982     else if (strcmp(extension, "GL_KHR_shader_subgroup_ballot") == 0)
983         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
984     else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle") == 0)
985         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
986     else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle_relative") == 0)
987         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
988     else if (strcmp(extension, "GL_KHR_shader_subgroup_clustered") == 0)
989         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
990     else if (strcmp(extension, "GL_KHR_shader_subgroup_quad") == 0)
991         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
992     else if (strcmp(extension, "GL_NV_shader_subgroup_partitioned") == 0)
993         updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
994     else if (strcmp(extension, "GL_EXT_buffer_reference2") == 0 ||
995              strcmp(extension, "GL_EXT_buffer_reference_uvec2") == 0)
996         updateExtensionBehavior(line, "GL_EXT_buffer_reference", behaviorString);
997     else if (strcmp(extension, "GL_NV_integer_cooperative_matrix") == 0)
998         updateExtensionBehavior(line, "GL_NV_cooperative_matrix", behaviorString);
999     // subgroup extended types to explicit types
1000     else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int8") == 0)
1001         updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int8", behaviorString);
1002     else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int16") == 0)
1003         updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int16", behaviorString);
1004     else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int64") == 0)
1005         updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int64", behaviorString);
1006     else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_float16") == 0)
1007         updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_float16", behaviorString);
1008
1009     // see if we need to update the numeric features
1010     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types") == 0)
1011         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types, on);
1012     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int8") == 0)
1013         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int8, on);
1014     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int16") == 0)
1015         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int16, on);
1016     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int32") == 0)
1017         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int32, on);
1018     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int64") == 0)
1019         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int64, on);
1020     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float16") == 0)
1021         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float16, on);
1022     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float32") == 0)
1023         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float32, on);
1024     else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float64") == 0)
1025         intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float64, on);
1026     else if (strcmp(extension, "GL_EXT_shader_implicit_conversions") == 0)
1027         intermediate.updateNumericFeature(TNumericFeatures::shader_implicit_conversions, on);
1028     else if (strcmp(extension, "GL_ARB_gpu_shader_fp64") == 0)
1029         intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_fp64, on);
1030     else if (strcmp(extension, "GL_AMD_gpu_shader_int16") == 0)
1031         intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_int16, on);
1032     else if (strcmp(extension, "GL_AMD_gpu_shader_half_float") == 0)
1033         intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_half_float, on);
1034 }
1035
1036 void TParseVersions::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)
1037 {
1038     // Update the current behavior
1039     if (strcmp(extension, "all") == 0) {
1040         // special case for the 'all' extension; apply it to every extension present
1041         if (behavior == EBhRequire || behavior == EBhEnable) {
1042             error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
1043             return;
1044         } else {
1045             for (auto iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter)
1046                 iter->second = behavior;
1047         }
1048     } else {
1049         // Do the update for this single extension
1050         auto iter = extensionBehavior.find(TString(extension));
1051         if (iter == extensionBehavior.end()) {
1052             switch (behavior) {
1053             case EBhRequire:
1054                 error(getCurrentLoc(), "extension not supported:", "#extension", extension);
1055                 break;
1056             case EBhEnable:
1057             case EBhWarn:
1058             case EBhDisable:
1059                 warn(getCurrentLoc(), "extension not supported:", "#extension", extension);
1060                 break;
1061             default:
1062                 assert(0 && "unexpected behavior");
1063             }
1064
1065             return;
1066         } else {
1067             if (iter->second == EBhDisablePartial)
1068                 warn(getCurrentLoc(), "extension is only partially supported:", "#extension", extension);
1069             if (behavior != EBhDisable)
1070                 intermediate.addRequestedExtension(extension);
1071             iter->second = behavior;
1072         }
1073     }
1074 }
1075
1076 // Check if extension is used with correct shader stage.
1077 void TParseVersions::checkExtensionStage(const TSourceLoc& loc, const char * const extension)
1078 {
1079     // GL_NV_mesh_shader extension is only allowed in task/mesh shaders
1080     if (strcmp(extension, "GL_NV_mesh_shader") == 0) {
1081         requireStage(loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask | EShLangFragmentMask),
1082                      "#extension GL_NV_mesh_shader");
1083         profileRequires(loc, ECoreProfile, 450, nullptr, "#extension GL_NV_mesh_shader");
1084         profileRequires(loc, EEsProfile, 320, nullptr, "#extension GL_NV_mesh_shader");
1085         if (extensionTurnedOn(E_GL_EXT_mesh_shader)) {
1086             error(loc, "GL_EXT_mesh_shader is already turned on, and not allowed with", "#extension", extension);
1087         }
1088     }
1089     else if (strcmp(extension, "GL_EXT_mesh_shader") == 0) {
1090         requireStage(loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask | EShLangFragmentMask),
1091                      "#extension GL_EXT_mesh_shader");
1092         profileRequires(loc, ECoreProfile, 450, nullptr, "#extension GL_EXT_mesh_shader");
1093         profileRequires(loc, EEsProfile, 320, nullptr, "#extension GL_EXT_mesh_shader");
1094         if (extensionTurnedOn(E_GL_NV_mesh_shader)) {
1095             error(loc, "GL_NV_mesh_shader is already turned on, and not allowed with", "#extension", extension);
1096         }
1097     }
1098 }
1099
1100 // Check if extension has additional requirements
1101 void TParseVersions::extensionRequires(const TSourceLoc &loc, const char * const extension, const char *behaviorString)
1102 {
1103     bool isEnabled = false;
1104     if (!strcmp("require", behaviorString))
1105         isEnabled = true;
1106     else if (!strcmp("enable", behaviorString))
1107         isEnabled = true;
1108
1109     if (isEnabled) {
1110         unsigned int minSpvVersion = 0;
1111         auto iter = extensionMinSpv.find(TString(extension));
1112         if (iter != extensionMinSpv.end())
1113             minSpvVersion = iter->second;
1114         requireSpv(loc, extension, minSpvVersion);
1115     }
1116
1117     if (spvVersion.spv != 0){
1118         for (auto ext : spvUnsupportedExt){
1119             if (strcmp(extension, ext.c_str()) == 0)
1120                 error(loc, "not allowed when using generating SPIR-V codes", extension, "");
1121         }
1122     }
1123 }
1124
1125 // Call for any operation needing full GLSL integer data-type support.
1126 void TParseVersions::fullIntegerCheck(const TSourceLoc& loc, const char* op)
1127 {
1128     profileRequires(loc, ENoProfile, 130, nullptr, op);
1129     profileRequires(loc, EEsProfile, 300, nullptr, op);
1130 }
1131
1132 // Call for any operation needing GLSL double data-type support.
1133 void TParseVersions::doubleCheck(const TSourceLoc& loc, const char* op)
1134 {
1135
1136     //requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1137     if (language == EShLangVertex) {
1138         const char* const f64_Extensions[] = {E_GL_ARB_gpu_shader_fp64, E_GL_ARB_vertex_attrib_64bit};
1139         profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, 2, f64_Extensions, op);
1140     } else
1141         profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader_fp64, op);
1142 }
1143
1144 // Call for any operation needing GLSL float16 data-type support.
1145 void TParseVersions::float16Check(const TSourceLoc& loc, const char* op, bool builtIn)
1146 {
1147     if (!builtIn) {
1148         const char* const extensions[] = {
1149                                            E_GL_AMD_gpu_shader_half_float,
1150                                            E_GL_EXT_shader_explicit_arithmetic_types,
1151                                            E_GL_EXT_shader_explicit_arithmetic_types_float16};
1152         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1153     }
1154 }
1155
1156 bool TParseVersions::float16Arithmetic()
1157 {
1158     const char* const extensions[] = {
1159                                        E_GL_AMD_gpu_shader_half_float,
1160                                        E_GL_EXT_shader_explicit_arithmetic_types,
1161                                        E_GL_EXT_shader_explicit_arithmetic_types_float16};
1162     return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
1163 }
1164
1165 bool TParseVersions::int16Arithmetic()
1166 {
1167     const char* const extensions[] = {
1168                                        E_GL_AMD_gpu_shader_int16,
1169                                        E_GL_EXT_shader_explicit_arithmetic_types,
1170                                        E_GL_EXT_shader_explicit_arithmetic_types_int16};
1171     return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
1172 }
1173
1174 bool TParseVersions::int8Arithmetic()
1175 {
1176     const char* const extensions[] = {
1177                                        E_GL_EXT_shader_explicit_arithmetic_types,
1178                                        E_GL_EXT_shader_explicit_arithmetic_types_int8};
1179     return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
1180 }
1181
1182 void TParseVersions::requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
1183 {
1184     TString combined;
1185     combined = op;
1186     combined += ": ";
1187     combined += featureDesc;
1188
1189     const char* const extensions[] = {
1190                                        E_GL_AMD_gpu_shader_half_float,
1191                                        E_GL_EXT_shader_explicit_arithmetic_types,
1192                                        E_GL_EXT_shader_explicit_arithmetic_types_float16};
1193     requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
1194 }
1195
1196 void TParseVersions::requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
1197 {
1198     TString combined;
1199     combined = op;
1200     combined += ": ";
1201     combined += featureDesc;
1202
1203     const char* const extensions[] = {
1204                                        E_GL_AMD_gpu_shader_int16,
1205                                        E_GL_EXT_shader_explicit_arithmetic_types,
1206                                        E_GL_EXT_shader_explicit_arithmetic_types_int16};
1207     requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
1208 }
1209
1210 void TParseVersions::requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
1211 {
1212     TString combined;
1213     combined = op;
1214     combined += ": ";
1215     combined += featureDesc;
1216
1217     const char* const extensions[] = {
1218                                        E_GL_EXT_shader_explicit_arithmetic_types,
1219                                        E_GL_EXT_shader_explicit_arithmetic_types_int8};
1220     requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
1221 }
1222
1223 void TParseVersions::float16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1224 {
1225     if (!builtIn) {
1226         const char* const extensions[] = {
1227                                            E_GL_AMD_gpu_shader_half_float,
1228                                            E_GL_EXT_shader_16bit_storage,
1229                                            E_GL_EXT_shader_explicit_arithmetic_types,
1230                                            E_GL_EXT_shader_explicit_arithmetic_types_float16};
1231         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1232     }
1233 }
1234
1235 // Call for any operation needing GLSL float32 data-type support.
1236 void TParseVersions::explicitFloat32Check(const TSourceLoc& loc, const char* op, bool builtIn)
1237 {
1238     if (!builtIn) {
1239         const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1240                                            E_GL_EXT_shader_explicit_arithmetic_types_float32};
1241         requireExtensions(loc, 2, extensions, op);
1242     }
1243 }
1244
1245 // Call for any operation needing GLSL float64 data-type support.
1246 void TParseVersions::explicitFloat64Check(const TSourceLoc& loc, const char* op, bool builtIn)
1247 {
1248     if (!builtIn) {
1249         const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1250                                            E_GL_EXT_shader_explicit_arithmetic_types_float64};
1251         requireExtensions(loc, 2, extensions, op);
1252         requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1253         profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
1254     }
1255 }
1256
1257 // Call for any operation needing GLSL explicit int8 data-type support.
1258 void TParseVersions::explicitInt8Check(const TSourceLoc& loc, const char* op, bool builtIn)
1259 {
1260     if (! builtIn) {
1261         const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1262                                            E_GL_EXT_shader_explicit_arithmetic_types_int8};
1263         requireExtensions(loc, 2, extensions, op);
1264     }
1265 }
1266
1267 // Call for any operation needing GLSL float16 opaque-type support
1268 void TParseVersions::float16OpaqueCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1269 {
1270     if (! builtIn) {
1271         requireExtensions(loc, 1, &E_GL_AMD_gpu_shader_half_float_fetch, op);
1272         requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1273         profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
1274     }
1275 }
1276
1277 // Call for any operation needing GLSL explicit int16 data-type support.
1278 void TParseVersions::explicitInt16Check(const TSourceLoc& loc, const char* op, bool builtIn)
1279 {
1280     if (! builtIn) {
1281         const char* const extensions[] = {
1282                                            E_GL_AMD_gpu_shader_int16,
1283                                            E_GL_EXT_shader_explicit_arithmetic_types,
1284                                            E_GL_EXT_shader_explicit_arithmetic_types_int16};
1285         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1286     }
1287 }
1288
1289 void TParseVersions::int16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1290 {
1291     if (! builtIn) {
1292         const char* const extensions[] = {
1293                                            E_GL_AMD_gpu_shader_int16,
1294                                            E_GL_EXT_shader_16bit_storage,
1295                                            E_GL_EXT_shader_explicit_arithmetic_types,
1296                                            E_GL_EXT_shader_explicit_arithmetic_types_int16};
1297         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1298     }
1299 }
1300
1301 void TParseVersions::int8ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1302 {
1303     if (! builtIn) {
1304         const char* const extensions[] = {
1305                                            E_GL_EXT_shader_8bit_storage,
1306                                            E_GL_EXT_shader_explicit_arithmetic_types,
1307                                            E_GL_EXT_shader_explicit_arithmetic_types_int8};
1308         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1309     }
1310 }
1311
1312 // Call for any operation needing GLSL explicit int32 data-type support.
1313 void TParseVersions::explicitInt32Check(const TSourceLoc& loc, const char* op, bool builtIn)
1314 {
1315     if (! builtIn) {
1316         const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1317                                            E_GL_EXT_shader_explicit_arithmetic_types_int32};
1318         requireExtensions(loc, 2, extensions, op);
1319     }
1320 }
1321
1322 // Call for any operation needing GLSL 64-bit integer data-type support.
1323 void TParseVersions::int64Check(const TSourceLoc& loc, const char* op, bool builtIn)
1324 {
1325     if (! builtIn) {
1326         const char* const extensions[3] = {E_GL_ARB_gpu_shader_int64,
1327                                            E_GL_EXT_shader_explicit_arithmetic_types,
1328                                            E_GL_EXT_shader_explicit_arithmetic_types_int64};
1329         requireExtensions(loc, 3, extensions, op);
1330         requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1331         profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
1332     }
1333 }
1334
1335 void TParseVersions::fcoopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1336 {
1337     if (!builtIn) {
1338         const char* const extensions[] = {E_GL_NV_cooperative_matrix};
1339         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1340     }
1341 }
1342
1343 void TParseVersions::intcoopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1344 {
1345     if (!builtIn) {
1346         const char* const extensions[] = {E_GL_NV_integer_cooperative_matrix};
1347         requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1348     }
1349 }
1350 #endif // GLSLANG_WEB
1351 // Call for any operation removed because SPIR-V is in use.
1352 void TParseVersions::spvRemoved(const TSourceLoc& loc, const char* op)
1353 {
1354     if (spvVersion.spv != 0)
1355         error(loc, "not allowed when generating SPIR-V", op, "");
1356 }
1357
1358 // Call for any operation removed because Vulkan SPIR-V is being generated.
1359 void TParseVersions::vulkanRemoved(const TSourceLoc& loc, const char* op)
1360 {
1361     if (spvVersion.vulkan > 0 && !spvVersion.vulkanRelaxed)
1362         error(loc, "not allowed when using GLSL for Vulkan", op, "");
1363 }
1364
1365 // Call for any operation that requires Vulkan.
1366 void TParseVersions::requireVulkan(const TSourceLoc& loc, const char* op)
1367 {
1368 #ifndef GLSLANG_WEB
1369     if (spvVersion.vulkan == 0)
1370         error(loc, "only allowed when using GLSL for Vulkan", op, "");
1371 #endif
1372 }
1373
1374 // Call for any operation that requires SPIR-V.
1375 void TParseVersions::requireSpv(const TSourceLoc& loc, const char* op)
1376 {
1377 #ifndef GLSLANG_WEB
1378     if (spvVersion.spv == 0)
1379         error(loc, "only allowed when generating SPIR-V", op, "");
1380 #endif
1381 }
1382 void TParseVersions::requireSpv(const TSourceLoc& loc, const char *op, unsigned int version)
1383 {
1384 #ifndef GLSLANG_WEB
1385     if (spvVersion.spv < version)
1386         error(loc, "not supported for current targeted SPIR-V version", op, "");
1387 #endif
1388 }
1389
1390 } // end namespace glslang