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 //
initializeExtensionBehavior()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_fragment_coord_conventions] = EBhDisable;
231
232
233 extensionBehavior[E_GL_KHR_shader_subgroup_basic] = EBhDisable;
234 extensionBehavior[E_GL_KHR_shader_subgroup_vote] = EBhDisable;
235 extensionBehavior[E_GL_KHR_shader_subgroup_arithmetic] = EBhDisable;
236 extensionBehavior[E_GL_KHR_shader_subgroup_ballot] = EBhDisable;
237 extensionBehavior[E_GL_KHR_shader_subgroup_shuffle] = EBhDisable;
238 extensionBehavior[E_GL_KHR_shader_subgroup_shuffle_relative] = EBhDisable;
239 extensionBehavior[E_GL_KHR_shader_subgroup_clustered] = EBhDisable;
240 extensionBehavior[E_GL_KHR_shader_subgroup_quad] = EBhDisable;
241 extensionBehavior[E_GL_KHR_memory_scope_semantics] = EBhDisable;
242
243 extensionBehavior[E_GL_EXT_shader_atomic_int64] = EBhDisable;
244
245 extensionBehavior[E_GL_EXT_shader_non_constant_global_initializers] = EBhDisable;
246 extensionBehavior[E_GL_EXT_shader_image_load_formatted] = EBhDisable;
247 extensionBehavior[E_GL_EXT_post_depth_coverage] = EBhDisable;
248 extensionBehavior[E_GL_EXT_control_flow_attributes] = EBhDisable;
249 extensionBehavior[E_GL_EXT_nonuniform_qualifier] = EBhDisable;
250 extensionBehavior[E_GL_EXT_samplerless_texture_functions] = EBhDisable;
251 extensionBehavior[E_GL_EXT_scalar_block_layout] = EBhDisable;
252 extensionBehavior[E_GL_EXT_fragment_invocation_density] = EBhDisable;
253 extensionBehavior[E_GL_EXT_buffer_reference] = EBhDisable;
254 extensionBehavior[E_GL_EXT_buffer_reference2] = EBhDisable;
255 extensionBehavior[E_GL_EXT_buffer_reference_uvec2] = EBhDisable;
256 extensionBehavior[E_GL_EXT_demote_to_helper_invocation] = EBhDisable;
257 extensionBehavior[E_GL_EXT_debug_printf] = EBhDisable;
258
259 extensionBehavior[E_GL_EXT_shader_16bit_storage] = EBhDisable;
260 extensionBehavior[E_GL_EXT_shader_8bit_storage] = EBhDisable;
261 extensionBehavior[E_GL_EXT_subgroup_uniform_control_flow] = EBhDisable;
262
263 extensionBehavior[E_GL_EXT_fragment_shader_barycentric] = EBhDisable;
264
265 // #line and #include
266 extensionBehavior[E_GL_GOOGLE_cpp_style_line_directive] = EBhDisable;
267 extensionBehavior[E_GL_GOOGLE_include_directive] = EBhDisable;
268
269 extensionBehavior[E_GL_AMD_shader_ballot] = EBhDisable;
270 extensionBehavior[E_GL_AMD_shader_trinary_minmax] = EBhDisable;
271 extensionBehavior[E_GL_AMD_shader_explicit_vertex_parameter] = EBhDisable;
272 extensionBehavior[E_GL_AMD_gcn_shader] = EBhDisable;
273 extensionBehavior[E_GL_AMD_gpu_shader_half_float] = EBhDisable;
274 extensionBehavior[E_GL_AMD_texture_gather_bias_lod] = EBhDisable;
275 extensionBehavior[E_GL_AMD_gpu_shader_int16] = EBhDisable;
276 extensionBehavior[E_GL_AMD_shader_image_load_store_lod] = EBhDisable;
277 extensionBehavior[E_GL_AMD_shader_fragment_mask] = EBhDisable;
278 extensionBehavior[E_GL_AMD_gpu_shader_half_float_fetch] = EBhDisable;
279 extensionBehavior[E_GL_AMD_shader_early_and_late_fragment_tests] = EBhDisable;
280
281 extensionBehavior[E_GL_INTEL_shader_integer_functions2] = EBhDisable;
282
283 extensionBehavior[E_GL_NV_sample_mask_override_coverage] = EBhDisable;
284 extensionBehavior[E_SPV_NV_geometry_shader_passthrough] = EBhDisable;
285 extensionBehavior[E_GL_NV_viewport_array2] = EBhDisable;
286 extensionBehavior[E_GL_NV_stereo_view_rendering] = EBhDisable;
287 extensionBehavior[E_GL_NVX_multiview_per_view_attributes] = EBhDisable;
288 extensionBehavior[E_GL_NV_shader_atomic_int64] = EBhDisable;
289 extensionBehavior[E_GL_NV_conservative_raster_underestimation] = EBhDisable;
290 extensionBehavior[E_GL_NV_shader_noperspective_interpolation] = EBhDisable;
291 extensionBehavior[E_GL_NV_shader_subgroup_partitioned] = EBhDisable;
292 extensionBehavior[E_GL_NV_shading_rate_image] = EBhDisable;
293 extensionBehavior[E_GL_NV_ray_tracing] = EBhDisable;
294 extensionBehavior[E_GL_NV_ray_tracing_motion_blur] = EBhDisable;
295 extensionBehavior[E_GL_NV_fragment_shader_barycentric] = EBhDisable;
296 extensionBehavior[E_GL_NV_compute_shader_derivatives] = EBhDisable;
297 extensionBehavior[E_GL_NV_shader_texture_footprint] = EBhDisable;
298 extensionBehavior[E_GL_NV_mesh_shader] = EBhDisable;
299
300 extensionBehavior[E_GL_NV_cooperative_matrix] = EBhDisable;
301 extensionBehavior[E_GL_NV_shader_sm_builtins] = EBhDisable;
302 extensionBehavior[E_GL_NV_integer_cooperative_matrix] = EBhDisable;
303
304 // ARM
305 extensionBehavior[E_GL_ARM_shader_core_builtins] = EBhDisable;
306
307
308 // AEP
309 extensionBehavior[E_GL_ANDROID_extension_pack_es31a] = EBhDisable;
310 extensionBehavior[E_GL_KHR_blend_equation_advanced] = EBhDisable;
311 extensionBehavior[E_GL_OES_sample_variables] = EBhDisable;
312 extensionBehavior[E_GL_OES_shader_image_atomic] = EBhDisable;
313 extensionBehavior[E_GL_OES_shader_multisample_interpolation] = EBhDisable;
314 extensionBehavior[E_GL_OES_texture_storage_multisample_2d_array] = EBhDisable;
315 extensionBehavior[E_GL_EXT_geometry_shader] = EBhDisable;
316 extensionBehavior[E_GL_EXT_geometry_point_size] = EBhDisable;
317 extensionBehavior[E_GL_EXT_gpu_shader5] = EBhDisable;
318 extensionBehavior[E_GL_EXT_primitive_bounding_box] = EBhDisable;
319 extensionBehavior[E_GL_EXT_shader_io_blocks] = EBhDisable;
320 extensionBehavior[E_GL_EXT_tessellation_shader] = EBhDisable;
321 extensionBehavior[E_GL_EXT_tessellation_point_size] = EBhDisable;
322 extensionBehavior[E_GL_EXT_texture_buffer] = EBhDisable;
323 extensionBehavior[E_GL_EXT_texture_cube_map_array] = EBhDisable;
324 extensionBehavior[E_GL_EXT_null_initializer] = EBhDisable;
325
326 // OES matching AEP
327 extensionBehavior[E_GL_OES_geometry_shader] = EBhDisable;
328 extensionBehavior[E_GL_OES_geometry_point_size] = EBhDisable;
329 extensionBehavior[E_GL_OES_gpu_shader5] = EBhDisable;
330 extensionBehavior[E_GL_OES_primitive_bounding_box] = EBhDisable;
331 extensionBehavior[E_GL_OES_shader_io_blocks] = EBhDisable;
332 extensionBehavior[E_GL_OES_tessellation_shader] = EBhDisable;
333 extensionBehavior[E_GL_OES_tessellation_point_size] = EBhDisable;
334 extensionBehavior[E_GL_OES_texture_buffer] = EBhDisable;
335 extensionBehavior[E_GL_OES_texture_cube_map_array] = EBhDisable;
336 extensionBehavior[E_GL_EXT_shader_integer_mix] = EBhDisable;
337
338 // EXT extensions
339 extensionBehavior[E_GL_EXT_device_group] = EBhDisable;
340 extensionBehavior[E_GL_EXT_multiview] = EBhDisable;
341 extensionBehavior[E_GL_EXT_shader_realtime_clock] = EBhDisable;
342 extensionBehavior[E_GL_EXT_ray_tracing] = EBhDisable;
343 extensionBehavior[E_GL_EXT_ray_query] = EBhDisable;
344 extensionBehavior[E_GL_EXT_ray_flags_primitive_culling] = EBhDisable;
345 extensionBehavior[E_GL_EXT_ray_cull_mask] = EBhDisable;
346 extensionBehavior[E_GL_EXT_blend_func_extended] = EBhDisable;
347 extensionBehavior[E_GL_EXT_shader_implicit_conversions] = EBhDisable;
348 extensionBehavior[E_GL_EXT_fragment_shading_rate] = EBhDisable;
349 extensionBehavior[E_GL_EXT_shader_image_int64] = EBhDisable;
350 extensionBehavior[E_GL_EXT_terminate_invocation] = EBhDisable;
351 extensionBehavior[E_GL_EXT_shared_memory_block] = EBhDisable;
352 extensionBehavior[E_GL_EXT_spirv_intrinsics] = EBhDisable;
353 extensionBehavior[E_GL_EXT_mesh_shader] = EBhDisable;
354 extensionBehavior[E_GL_EXT_opacity_micromap] = EBhDisable;
355
356 // OVR extensions
357 extensionBehavior[E_GL_OVR_multiview] = EBhDisable;
358 extensionBehavior[E_GL_OVR_multiview2] = EBhDisable;
359
360 // explicit types
361 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types] = EBhDisable;
362 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int8] = EBhDisable;
363 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int16] = EBhDisable;
364 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int32] = EBhDisable;
365 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_int64] = EBhDisable;
366 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float16] = EBhDisable;
367 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float32] = EBhDisable;
368 extensionBehavior[E_GL_EXT_shader_explicit_arithmetic_types_float64] = EBhDisable;
369
370 // subgroup extended types
371 extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int8] = EBhDisable;
372 extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int16] = EBhDisable;
373 extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int64] = EBhDisable;
374 extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_float16] = EBhDisable;
375 extensionBehavior[E_GL_EXT_shader_atomic_float] = EBhDisable;
376 extensionBehavior[E_GL_EXT_shader_atomic_float2] = EBhDisable;
377 }
378
379 #endif // GLSLANG_WEB
380
381 // Get code that is not part of a shared symbol table, is specific to this shader,
382 // or needed by the preprocessor (which does not use a shared symbol table).
getPreamble(std::string & preamble)383 void TParseVersions::getPreamble(std::string& preamble)
384 {
385 if (isEsProfile()) {
386 preamble =
387 "#define GL_ES 1\n"
388 "#define GL_FRAGMENT_PRECISION_HIGH 1\n"
389 #ifdef GLSLANG_WEB
390 ;
391 #else
392 "#define GL_OES_texture_3D 1\n"
393 "#define GL_OES_standard_derivatives 1\n"
394 "#define GL_EXT_frag_depth 1\n"
395 "#define GL_OES_EGL_image_external 1\n"
396 "#define GL_OES_EGL_image_external_essl3 1\n"
397 "#define GL_EXT_YUV_target 1\n"
398 "#define GL_EXT_shader_texture_lod 1\n"
399 "#define GL_EXT_shadow_samplers 1\n"
400 "#define GL_EXT_fragment_shading_rate 1\n"
401
402 // AEP
403 "#define GL_ANDROID_extension_pack_es31a 1\n"
404 "#define GL_OES_sample_variables 1\n"
405 "#define GL_OES_shader_image_atomic 1\n"
406 "#define GL_OES_shader_multisample_interpolation 1\n"
407 "#define GL_OES_texture_storage_multisample_2d_array 1\n"
408 "#define GL_EXT_geometry_shader 1\n"
409 "#define GL_EXT_geometry_point_size 1\n"
410 "#define GL_EXT_gpu_shader5 1\n"
411 "#define GL_EXT_primitive_bounding_box 1\n"
412 "#define GL_EXT_shader_io_blocks 1\n"
413 "#define GL_EXT_tessellation_shader 1\n"
414 "#define GL_EXT_tessellation_point_size 1\n"
415 "#define GL_EXT_texture_buffer 1\n"
416 "#define GL_EXT_texture_cube_map_array 1\n"
417 "#define GL_EXT_shader_implicit_conversions 1\n"
418 "#define GL_EXT_shader_integer_mix 1\n"
419 "#define GL_EXT_blend_func_extended 1\n"
420
421 // OES matching AEP
422 "#define GL_OES_geometry_shader 1\n"
423 "#define GL_OES_geometry_point_size 1\n"
424 "#define GL_OES_gpu_shader5 1\n"
425 "#define GL_OES_primitive_bounding_box 1\n"
426 "#define GL_OES_shader_io_blocks 1\n"
427 "#define GL_OES_tessellation_shader 1\n"
428 "#define GL_OES_tessellation_point_size 1\n"
429 "#define GL_OES_texture_buffer 1\n"
430 "#define GL_OES_texture_cube_map_array 1\n"
431 "#define GL_EXT_shader_non_constant_global_initializers 1\n"
432 ;
433
434 if (version >= 300) {
435 preamble += "#define GL_NV_shader_noperspective_interpolation 1\n";
436 }
437 if (version >= 310) {
438 preamble += "#define GL_EXT_null_initializer 1\n";
439 preamble += "#define GL_EXT_subgroup_uniform_control_flow 1\n";
440 }
441
442 } else { // !isEsProfile()
443 preamble =
444 "#define GL_FRAGMENT_PRECISION_HIGH 1\n"
445 "#define GL_ARB_texture_rectangle 1\n"
446 "#define GL_ARB_shading_language_420pack 1\n"
447 "#define GL_ARB_texture_gather 1\n"
448 "#define GL_ARB_gpu_shader5 1\n"
449 "#define GL_ARB_separate_shader_objects 1\n"
450 "#define GL_ARB_compute_shader 1\n"
451 "#define GL_ARB_tessellation_shader 1\n"
452 "#define GL_ARB_enhanced_layouts 1\n"
453 "#define GL_ARB_texture_cube_map_array 1\n"
454 "#define GL_ARB_texture_multisample 1\n"
455 "#define GL_ARB_shader_texture_lod 1\n"
456 "#define GL_ARB_explicit_attrib_location 1\n"
457 "#define GL_ARB_explicit_uniform_location 1\n"
458 "#define GL_ARB_shader_image_load_store 1\n"
459 "#define GL_ARB_shader_atomic_counters 1\n"
460 "#define GL_ARB_shader_draw_parameters 1\n"
461 "#define GL_ARB_shader_group_vote 1\n"
462 "#define GL_ARB_derivative_control 1\n"
463 "#define GL_ARB_shader_texture_image_samples 1\n"
464 "#define GL_ARB_viewport_array 1\n"
465 "#define GL_ARB_gpu_shader_int64 1\n"
466 "#define GL_ARB_gpu_shader_fp64 1\n"
467 "#define GL_ARB_shader_ballot 1\n"
468 "#define GL_ARB_sparse_texture2 1\n"
469 "#define GL_ARB_sparse_texture_clamp 1\n"
470 "#define GL_ARB_shader_stencil_export 1\n"
471 "#define GL_ARB_sample_shading 1\n"
472 "#define GL_ARB_shader_image_size 1\n"
473 "#define GL_ARB_shading_language_packing 1\n"
474 // "#define GL_ARB_cull_distance 1\n" // present for 4.5, but need extension control over block members
475 "#define GL_ARB_post_depth_coverage 1\n"
476 "#define GL_ARB_fragment_shader_interlock 1\n"
477 "#define GL_ARB_uniform_buffer_object 1\n"
478 "#define GL_ARB_shader_bit_encoding 1\n"
479 "#define GL_ARB_shader_storage_buffer_object 1\n"
480 "#define GL_ARB_texture_query_lod 1\n"
481 "#define GL_ARB_vertex_attrib_64bit 1\n"
482 "#define GL_ARB_draw_instanced 1\n"
483 "#define GL_ARB_fragment_coord_conventions 1\n"
484 "#define GL_EXT_shader_non_constant_global_initializers 1\n"
485 "#define GL_EXT_shader_image_load_formatted 1\n"
486 "#define GL_EXT_post_depth_coverage 1\n"
487 "#define GL_EXT_control_flow_attributes 1\n"
488 "#define GL_EXT_nonuniform_qualifier 1\n"
489 "#define GL_EXT_shader_16bit_storage 1\n"
490 "#define GL_EXT_shader_8bit_storage 1\n"
491 "#define GL_EXT_samplerless_texture_functions 1\n"
492 "#define GL_EXT_scalar_block_layout 1\n"
493 "#define GL_EXT_fragment_invocation_density 1\n"
494 "#define GL_EXT_buffer_reference 1\n"
495 "#define GL_EXT_buffer_reference2 1\n"
496 "#define GL_EXT_buffer_reference_uvec2 1\n"
497 "#define GL_EXT_demote_to_helper_invocation 1\n"
498 "#define GL_EXT_debug_printf 1\n"
499 "#define GL_EXT_fragment_shading_rate 1\n"
500 "#define GL_EXT_shared_memory_block 1\n"
501 "#define GL_EXT_shader_integer_mix 1\n"
502
503 // GL_KHR_shader_subgroup
504 "#define GL_KHR_shader_subgroup_basic 1\n"
505 "#define GL_KHR_shader_subgroup_vote 1\n"
506 "#define GL_KHR_shader_subgroup_arithmetic 1\n"
507 "#define GL_KHR_shader_subgroup_ballot 1\n"
508 "#define GL_KHR_shader_subgroup_shuffle 1\n"
509 "#define GL_KHR_shader_subgroup_shuffle_relative 1\n"
510 "#define GL_KHR_shader_subgroup_clustered 1\n"
511 "#define GL_KHR_shader_subgroup_quad 1\n"
512
513 "#define GL_EXT_shader_image_int64 1\n"
514 "#define GL_EXT_shader_atomic_int64 1\n"
515 "#define GL_EXT_shader_realtime_clock 1\n"
516 "#define GL_EXT_ray_tracing 1\n"
517 "#define GL_EXT_ray_query 1\n"
518 "#define GL_EXT_ray_flags_primitive_culling 1\n"
519 "#define GL_EXT_ray_cull_mask 1\n"
520 "#define GL_EXT_spirv_intrinsics 1\n"
521 "#define GL_EXT_mesh_shader 1\n"
522
523 "#define GL_AMD_shader_ballot 1\n"
524 "#define GL_AMD_shader_trinary_minmax 1\n"
525 "#define GL_AMD_shader_explicit_vertex_parameter 1\n"
526 "#define GL_AMD_gcn_shader 1\n"
527 "#define GL_AMD_gpu_shader_half_float 1\n"
528 "#define GL_AMD_texture_gather_bias_lod 1\n"
529 "#define GL_AMD_gpu_shader_int16 1\n"
530 "#define GL_AMD_shader_image_load_store_lod 1\n"
531 "#define GL_AMD_shader_fragment_mask 1\n"
532 "#define GL_AMD_gpu_shader_half_float_fetch 1\n"
533
534 "#define GL_INTEL_shader_integer_functions2 1\n"
535
536 "#define GL_NV_sample_mask_override_coverage 1\n"
537 "#define GL_NV_geometry_shader_passthrough 1\n"
538 "#define GL_NV_viewport_array2 1\n"
539 "#define GL_NV_shader_atomic_int64 1\n"
540 "#define GL_NV_conservative_raster_underestimation 1\n"
541 "#define GL_NV_shader_subgroup_partitioned 1\n"
542 "#define GL_NV_shading_rate_image 1\n"
543 "#define GL_NV_ray_tracing 1\n"
544 "#define GL_NV_ray_tracing_motion_blur 1\n"
545 "#define GL_NV_fragment_shader_barycentric 1\n"
546 "#define GL_NV_compute_shader_derivatives 1\n"
547 "#define GL_NV_shader_texture_footprint 1\n"
548 "#define GL_NV_mesh_shader 1\n"
549 "#define GL_NV_cooperative_matrix 1\n"
550 "#define GL_NV_integer_cooperative_matrix 1\n"
551
552 "#define GL_EXT_shader_explicit_arithmetic_types 1\n"
553 "#define GL_EXT_shader_explicit_arithmetic_types_int8 1\n"
554 "#define GL_EXT_shader_explicit_arithmetic_types_int16 1\n"
555 "#define GL_EXT_shader_explicit_arithmetic_types_int32 1\n"
556 "#define GL_EXT_shader_explicit_arithmetic_types_int64 1\n"
557 "#define GL_EXT_shader_explicit_arithmetic_types_float16 1\n"
558 "#define GL_EXT_shader_explicit_arithmetic_types_float32 1\n"
559 "#define GL_EXT_shader_explicit_arithmetic_types_float64 1\n"
560
561 "#define GL_EXT_shader_subgroup_extended_types_int8 1\n"
562 "#define GL_EXT_shader_subgroup_extended_types_int16 1\n"
563 "#define GL_EXT_shader_subgroup_extended_types_int64 1\n"
564 "#define GL_EXT_shader_subgroup_extended_types_float16 1\n"
565
566 "#define GL_EXT_shader_atomic_float 1\n"
567 "#define GL_EXT_shader_atomic_float2 1\n"
568
569 "#define GL_EXT_fragment_shader_barycentric 1\n"
570 ;
571
572 if (version >= 150) {
573 // define GL_core_profile and GL_compatibility_profile
574 preamble += "#define GL_core_profile 1\n";
575
576 if (profile == ECompatibilityProfile)
577 preamble += "#define GL_compatibility_profile 1\n";
578 }
579 if (version >= 140) {
580 preamble += "#define GL_EXT_null_initializer 1\n";
581 preamble += "#define GL_EXT_subgroup_uniform_control_flow 1\n";
582 }
583 #endif // GLSLANG_WEB
584 }
585
586 #ifndef GLSLANG_WEB
587 if ((!isEsProfile() && version >= 140) ||
588 (isEsProfile() && version >= 310)) {
589 preamble +=
590 "#define GL_EXT_device_group 1\n"
591 "#define GL_EXT_multiview 1\n"
592 "#define GL_NV_shader_sm_builtins 1\n"
593 ;
594 }
595
596 if (version >= 300 /* both ES and non-ES */) {
597 preamble +=
598 "#define GL_OVR_multiview 1\n"
599 "#define GL_OVR_multiview2 1\n"
600 ;
601 }
602
603 // #line and #include
604 preamble +=
605 "#define GL_GOOGLE_cpp_style_line_directive 1\n"
606 "#define GL_GOOGLE_include_directive 1\n"
607 "#define GL_KHR_blend_equation_advanced 1\n"
608 ;
609
610 // other general extensions
611 preamble +=
612 "#define GL_EXT_terminate_invocation 1\n"
613 ;
614 #endif
615
616 // #define VULKAN XXXX
617 const int numberBufSize = 12;
618 char numberBuf[numberBufSize];
619 if (spvVersion.vulkanGlsl > 0) {
620 preamble += "#define VULKAN ";
621 snprintf(numberBuf, numberBufSize, "%d", spvVersion.vulkanGlsl);
622 preamble += numberBuf;
623 preamble += "\n";
624 }
625
626 #ifndef GLSLANG_WEB
627 // #define GL_SPIRV XXXX
628 if (spvVersion.openGl > 0) {
629 preamble += "#define GL_SPIRV ";
630 snprintf(numberBuf, numberBufSize, "%d", spvVersion.openGl);
631 preamble += numberBuf;
632 preamble += "\n";
633 }
634 #endif
635
636 #ifndef GLSLANG_WEB
637 // GL_EXT_spirv_intrinsics
638 if (!isEsProfile()) {
639 switch (language) {
640 case EShLangVertex: preamble += "#define GL_VERTEX_SHADER 1 \n"; break;
641 case EShLangTessControl: preamble += "#define GL_TESSELLATION_CONTROL_SHADER 1 \n"; break;
642 case EShLangTessEvaluation: preamble += "#define GL_TESSELLATION_EVALUATION_SHADER 1 \n"; break;
643 case EShLangGeometry: preamble += "#define GL_GEOMETRY_SHADER 1 \n"; break;
644 case EShLangFragment: preamble += "#define GL_FRAGMENT_SHADER 1 \n"; break;
645 case EShLangCompute: preamble += "#define GL_COMPUTE_SHADER 1 \n"; break;
646 case EShLangRayGen: preamble += "#define GL_RAY_GENERATION_SHADER_EXT 1 \n"; break;
647 case EShLangIntersect: preamble += "#define GL_INTERSECTION_SHADER_EXT 1 \n"; break;
648 case EShLangAnyHit: preamble += "#define GL_ANY_HIT_SHADER_EXT 1 \n"; break;
649 case EShLangClosestHit: preamble += "#define GL_CLOSEST_HIT_SHADER_EXT 1 \n"; break;
650 case EShLangMiss: preamble += "#define GL_MISS_SHADER_EXT 1 \n"; break;
651 case EShLangCallable: preamble += "#define GL_CALLABLE_SHADER_EXT 1 \n"; break;
652 case EShLangTask: preamble += "#define GL_TASK_SHADER_NV 1 \n"; break;
653 case EShLangMesh: preamble += "#define GL_MESH_SHADER_NV 1 \n"; break;
654 default: break;
655 }
656 }
657 #endif
658 }
659
660 //
661 // Map from stage enum to externally readable text name.
662 //
StageName(EShLanguage stage)663 const char* StageName(EShLanguage stage)
664 {
665 switch(stage) {
666 case EShLangVertex: return "vertex";
667 case EShLangFragment: return "fragment";
668 case EShLangCompute: return "compute";
669 #ifndef GLSLANG_WEB
670 case EShLangTessControl: return "tessellation control";
671 case EShLangTessEvaluation: return "tessellation evaluation";
672 case EShLangGeometry: return "geometry";
673 case EShLangRayGen: return "ray-generation";
674 case EShLangIntersect: return "intersection";
675 case EShLangAnyHit: return "any-hit";
676 case EShLangClosestHit: return "closest-hit";
677 case EShLangMiss: return "miss";
678 case EShLangCallable: return "callable";
679 case EShLangMesh: return "mesh";
680 case EShLangTask: return "task";
681 #endif
682 default: return "unknown stage";
683 }
684 }
685
686 //
687 // When to use requireStage()
688 //
689 // If only some stages support a feature.
690 //
691 // Operation: If the current stage is not present, give an error message.
692 //
requireStage(const TSourceLoc & loc,EShLanguageMask languageMask,const char * featureDesc)693 void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguageMask languageMask, const char* featureDesc)
694 {
695 if (((1 << language) & languageMask) == 0)
696 error(loc, "not supported in this stage:", featureDesc, StageName(language));
697 }
698
699 // If only one stage supports a feature, this can be called. But, all supporting stages
700 // must be specified with one call.
requireStage(const TSourceLoc & loc,EShLanguage stage,const char * featureDesc)701 void TParseVersions::requireStage(const TSourceLoc& loc, EShLanguage stage, const char* featureDesc)
702 {
703 requireStage(loc, static_cast<EShLanguageMask>(1 << stage), featureDesc);
704 }
705
706 #ifndef GLSLANG_WEB
707 //
708 // When to use requireProfile():
709 //
710 // Use if only some profiles support a feature. However, if within a profile the feature
711 // is version or extension specific, follow this call with calls to profileRequires().
712 //
713 // Operation: If the current profile is not one of the profileMask,
714 // give an error message.
715 //
requireProfile(const TSourceLoc & loc,int profileMask,const char * featureDesc)716 void TParseVersions::requireProfile(const TSourceLoc& loc, int profileMask, const char* featureDesc)
717 {
718 if (! (profile & profileMask))
719 error(loc, "not supported with this profile:", featureDesc, ProfileName(profile));
720 }
721
722 //
723 // When to use profileRequires():
724 //
725 // If a set of profiles have the same requirements for what version or extensions
726 // are needed to support a feature.
727 //
728 // It must be called for each profile that needs protection. Use requireProfile() first
729 // to reduce that set of profiles.
730 //
731 // Operation: Will issue warnings/errors based on the current profile, version, and extension
732 // behaviors. It only checks extensions when the current profile is one of the profileMask.
733 //
734 // A minVersion of 0 means no version of the profileMask support this in core,
735 // the extension must be present.
736 //
737
738 // entry point that takes multiple extensions
profileRequires(const TSourceLoc & loc,int profileMask,int minVersion,int numExtensions,const char * const extensions[],const char * featureDesc)739 void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, int numExtensions,
740 const char* const extensions[], const char* featureDesc)
741 {
742 if (profile & profileMask) {
743 bool okay = minVersion > 0 && version >= minVersion;
744 #ifndef GLSLANG_WEB
745 for (int i = 0; i < numExtensions; ++i) {
746 switch (getExtensionBehavior(extensions[i])) {
747 case EBhWarn:
748 infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
749 // fall through
750 case EBhRequire:
751 case EBhEnable:
752 okay = true;
753 break;
754 default: break; // some compilers want this
755 }
756 }
757 #endif
758 if (! okay)
759 error(loc, "not supported for this version or the enabled extensions", featureDesc, "");
760 }
761 }
762
763 // entry point for the above that takes a single extension
profileRequires(const TSourceLoc & loc,int profileMask,int minVersion,const char * extension,const char * featureDesc)764 void TParseVersions::profileRequires(const TSourceLoc& loc, int profileMask, int minVersion, const char* extension,
765 const char* featureDesc)
766 {
767 profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc);
768 }
769
unimplemented(const TSourceLoc & loc,const char * featureDesc)770 void TParseVersions::unimplemented(const TSourceLoc& loc, const char* featureDesc)
771 {
772 error(loc, "feature not yet implemented", featureDesc, "");
773 }
774
775 //
776 // Within a set of profiles, see if a feature is deprecated and give an error or warning based on whether
777 // a future compatibility context is being use.
778 //
checkDeprecated(const TSourceLoc & loc,int profileMask,int depVersion,const char * featureDesc)779 void TParseVersions::checkDeprecated(const TSourceLoc& loc, int profileMask, int depVersion, const char* featureDesc)
780 {
781 if (profile & profileMask) {
782 if (version >= depVersion) {
783 if (forwardCompatible)
784 error(loc, "deprecated, may be removed in future release", featureDesc, "");
785 else if (! suppressWarnings())
786 infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
787 String(depVersion) + "; may be removed in future release").c_str(), loc);
788 }
789 }
790 }
791
792 //
793 // Within a set of profiles, see if a feature has now been removed and if so, give an error.
794 // The version argument is the first version no longer having the feature.
795 //
requireNotRemoved(const TSourceLoc & loc,int profileMask,int removedVersion,const char * featureDesc)796 void TParseVersions::requireNotRemoved(const TSourceLoc& loc, int profileMask, int removedVersion, const char* featureDesc)
797 {
798 if (profile & profileMask) {
799 if (version >= removedVersion) {
800 const int maxSize = 60;
801 char buf[maxSize];
802 snprintf(buf, maxSize, "%s profile; removed in version %d", ProfileName(profile), removedVersion);
803 error(loc, "no longer supported in", featureDesc, buf);
804 }
805 }
806 }
807
808 // Returns true if at least one of the extensions in the extensions parameter is requested. Otherwise, returns false.
809 // Warns appropriately if the requested behavior of an extension is "warn".
checkExtensionsRequested(const TSourceLoc & loc,int numExtensions,const char * const extensions[],const char * featureDesc)810 bool TParseVersions::checkExtensionsRequested(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
811 {
812 // First, see if any of the extensions are enabled
813 for (int i = 0; i < numExtensions; ++i) {
814 TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
815 if (behavior == EBhEnable || behavior == EBhRequire)
816 return true;
817 }
818
819 // See if any extensions want to give a warning on use; give warnings for all such extensions
820 bool warned = false;
821 for (int i = 0; i < numExtensions; ++i) {
822 TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
823 if (behavior == EBhDisable && relaxedErrors()) {
824 infoSink.info.message(EPrefixWarning, "The following extension must be enabled to use this feature:", loc);
825 behavior = EBhWarn;
826 }
827 if (behavior == EBhWarn) {
828 infoSink.info.message(EPrefixWarning, ("extension " + TString(extensions[i]) + " is being used for " + featureDesc).c_str(), loc);
829 warned = true;
830 }
831 }
832 if (warned)
833 return true;
834 return false;
835 }
836
837 //
838 // Use when there are no profile/version to check, it's just an error if one of the
839 // extensions is not present.
840 //
requireExtensions(const TSourceLoc & loc,int numExtensions,const char * const extensions[],const char * featureDesc)841 void TParseVersions::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
842 const char* featureDesc)
843 {
844 if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
845 return;
846
847 // If we get this far, give errors explaining what extensions are needed
848 if (numExtensions == 1)
849 error(loc, "required extension not requested:", featureDesc, extensions[0]);
850 else {
851 error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
852 for (int i = 0; i < numExtensions; ++i)
853 infoSink.info.message(EPrefixNone, extensions[i]);
854 }
855 }
856
857 //
858 // Use by preprocessor when there are no profile/version to check, it's just an error if one of the
859 // extensions is not present.
860 //
ppRequireExtensions(const TSourceLoc & loc,int numExtensions,const char * const extensions[],const char * featureDesc)861 void TParseVersions::ppRequireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[],
862 const char* featureDesc)
863 {
864 if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc))
865 return;
866
867 // If we get this far, give errors explaining what extensions are needed
868 if (numExtensions == 1)
869 ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
870 else {
871 ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
872 for (int i = 0; i < numExtensions; ++i)
873 infoSink.info.message(EPrefixNone, extensions[i]);
874 }
875 }
876
getExtensionBehavior(const char * extension)877 TExtensionBehavior TParseVersions::getExtensionBehavior(const char* extension)
878 {
879 auto iter = extensionBehavior.find(TString(extension));
880 if (iter == extensionBehavior.end())
881 return EBhMissing;
882 else
883 return iter->second;
884 }
885
886 // Returns true if the given extension is set to enable, require, or warn.
extensionTurnedOn(const char * const extension)887 bool TParseVersions::extensionTurnedOn(const char* const extension)
888 {
889 switch (getExtensionBehavior(extension)) {
890 case EBhEnable:
891 case EBhRequire:
892 case EBhWarn:
893 return true;
894 default:
895 break;
896 }
897 return false;
898 }
899 // See if any of the extensions are set to enable, require, or warn.
extensionsTurnedOn(int numExtensions,const char * const extensions[])900 bool TParseVersions::extensionsTurnedOn(int numExtensions, const char* const extensions[])
901 {
902 for (int i = 0; i < numExtensions; ++i) {
903 if (extensionTurnedOn(extensions[i]))
904 return true;
905 }
906 return false;
907 }
908
909 //
910 // Change the current state of an extension's behavior.
911 //
updateExtensionBehavior(int line,const char * extension,const char * behaviorString)912 void TParseVersions::updateExtensionBehavior(int line, const char* extension, const char* behaviorString)
913 {
914 // Translate from text string of extension's behavior to an enum.
915 TExtensionBehavior behavior = EBhDisable;
916 if (! strcmp("require", behaviorString))
917 behavior = EBhRequire;
918 else if (! strcmp("enable", behaviorString))
919 behavior = EBhEnable;
920 else if (! strcmp("disable", behaviorString))
921 behavior = EBhDisable;
922 else if (! strcmp("warn", behaviorString))
923 behavior = EBhWarn;
924 else {
925 error(getCurrentLoc(), "behavior not supported:", "#extension", behaviorString);
926 return;
927 }
928 bool on = behavior != EBhDisable;
929
930 // check if extension is used with correct shader stage
931 checkExtensionStage(getCurrentLoc(), extension);
932
933 // check if extension has additional requirements
934 extensionRequires(getCurrentLoc(), extension, behaviorString);
935
936 // update the requested extension
937 updateExtensionBehavior(extension, behavior);
938
939 // see if need to propagate to implicitly modified things
940 if (strcmp(extension, "GL_ANDROID_extension_pack_es31a") == 0) {
941 // to everything in AEP
942 updateExtensionBehavior(line, "GL_KHR_blend_equation_advanced", behaviorString);
943 updateExtensionBehavior(line, "GL_OES_sample_variables", behaviorString);
944 updateExtensionBehavior(line, "GL_OES_shader_image_atomic", behaviorString);
945 updateExtensionBehavior(line, "GL_OES_shader_multisample_interpolation", behaviorString);
946 updateExtensionBehavior(line, "GL_OES_texture_storage_multisample_2d_array", behaviorString);
947 updateExtensionBehavior(line, "GL_EXT_geometry_shader", behaviorString);
948 updateExtensionBehavior(line, "GL_EXT_gpu_shader5", behaviorString);
949 updateExtensionBehavior(line, "GL_EXT_primitive_bounding_box", behaviorString);
950 updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
951 updateExtensionBehavior(line, "GL_EXT_tessellation_shader", behaviorString);
952 updateExtensionBehavior(line, "GL_EXT_texture_buffer", behaviorString);
953 updateExtensionBehavior(line, "GL_EXT_texture_cube_map_array", behaviorString);
954 }
955 // geometry to io_blocks
956 else if (strcmp(extension, "GL_EXT_geometry_shader") == 0)
957 updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
958 else if (strcmp(extension, "GL_OES_geometry_shader") == 0)
959 updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
960 // tessellation to io_blocks
961 else if (strcmp(extension, "GL_EXT_tessellation_shader") == 0)
962 updateExtensionBehavior(line, "GL_EXT_shader_io_blocks", behaviorString);
963 else if (strcmp(extension, "GL_OES_tessellation_shader") == 0)
964 updateExtensionBehavior(line, "GL_OES_shader_io_blocks", behaviorString);
965 else if (strcmp(extension, "GL_GOOGLE_include_directive") == 0)
966 updateExtensionBehavior(line, "GL_GOOGLE_cpp_style_line_directive", behaviorString);
967 // subgroup_* to subgroup_basic
968 else if (strcmp(extension, "GL_KHR_shader_subgroup_vote") == 0)
969 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
970 else if (strcmp(extension, "GL_KHR_shader_subgroup_arithmetic") == 0)
971 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
972 else if (strcmp(extension, "GL_KHR_shader_subgroup_ballot") == 0)
973 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
974 else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle") == 0)
975 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
976 else if (strcmp(extension, "GL_KHR_shader_subgroup_shuffle_relative") == 0)
977 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
978 else if (strcmp(extension, "GL_KHR_shader_subgroup_clustered") == 0)
979 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
980 else if (strcmp(extension, "GL_KHR_shader_subgroup_quad") == 0)
981 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
982 else if (strcmp(extension, "GL_NV_shader_subgroup_partitioned") == 0)
983 updateExtensionBehavior(line, "GL_KHR_shader_subgroup_basic", behaviorString);
984 else if (strcmp(extension, "GL_EXT_buffer_reference2") == 0 ||
985 strcmp(extension, "GL_EXT_buffer_reference_uvec2") == 0)
986 updateExtensionBehavior(line, "GL_EXT_buffer_reference", behaviorString);
987 else if (strcmp(extension, "GL_NV_integer_cooperative_matrix") == 0)
988 updateExtensionBehavior(line, "GL_NV_cooperative_matrix", behaviorString);
989 // subgroup extended types to explicit types
990 else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int8") == 0)
991 updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int8", behaviorString);
992 else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int16") == 0)
993 updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int16", behaviorString);
994 else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_int64") == 0)
995 updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_int64", behaviorString);
996 else if (strcmp(extension, "GL_EXT_shader_subgroup_extended_types_float16") == 0)
997 updateExtensionBehavior(line, "GL_EXT_shader_explicit_arithmetic_types_float16", behaviorString);
998
999 // see if we need to update the numeric features
1000 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types") == 0)
1001 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types, on);
1002 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int8") == 0)
1003 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int8, on);
1004 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int16") == 0)
1005 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int16, on);
1006 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int32") == 0)
1007 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int32, on);
1008 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_int64") == 0)
1009 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_int64, on);
1010 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float16") == 0)
1011 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float16, on);
1012 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float32") == 0)
1013 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float32, on);
1014 else if (strcmp(extension, "GL_EXT_shader_explicit_arithmetic_types_float64") == 0)
1015 intermediate.updateNumericFeature(TNumericFeatures::shader_explicit_arithmetic_types_float64, on);
1016 else if (strcmp(extension, "GL_EXT_shader_implicit_conversions") == 0)
1017 intermediate.updateNumericFeature(TNumericFeatures::shader_implicit_conversions, on);
1018 else if (strcmp(extension, "GL_ARB_gpu_shader_fp64") == 0)
1019 intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_fp64, on);
1020 else if (strcmp(extension, "GL_AMD_gpu_shader_int16") == 0)
1021 intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_int16, on);
1022 else if (strcmp(extension, "GL_AMD_gpu_shader_half_float") == 0)
1023 intermediate.updateNumericFeature(TNumericFeatures::gpu_shader_half_float, on);
1024 }
1025
updateExtensionBehavior(const char * extension,TExtensionBehavior behavior)1026 void TParseVersions::updateExtensionBehavior(const char* extension, TExtensionBehavior behavior)
1027 {
1028 // Update the current behavior
1029 if (strcmp(extension, "all") == 0) {
1030 // special case for the 'all' extension; apply it to every extension present
1031 if (behavior == EBhRequire || behavior == EBhEnable) {
1032 error(getCurrentLoc(), "extension 'all' cannot have 'require' or 'enable' behavior", "#extension", "");
1033 return;
1034 } else {
1035 for (auto iter = extensionBehavior.begin(); iter != extensionBehavior.end(); ++iter)
1036 iter->second = behavior;
1037 }
1038 } else {
1039 // Do the update for this single extension
1040 auto iter = extensionBehavior.find(TString(extension));
1041 if (iter == extensionBehavior.end()) {
1042 switch (behavior) {
1043 case EBhRequire:
1044 error(getCurrentLoc(), "extension not supported:", "#extension", extension);
1045 break;
1046 case EBhEnable:
1047 case EBhWarn:
1048 case EBhDisable:
1049 warn(getCurrentLoc(), "extension not supported:", "#extension", extension);
1050 break;
1051 default:
1052 assert(0 && "unexpected behavior");
1053 }
1054
1055 return;
1056 } else {
1057 if (iter->second == EBhDisablePartial)
1058 warn(getCurrentLoc(), "extension is only partially supported:", "#extension", extension);
1059 if (behavior != EBhDisable)
1060 intermediate.addRequestedExtension(extension);
1061 iter->second = behavior;
1062 }
1063 }
1064 }
1065
1066 // Check if extension is used with correct shader stage.
checkExtensionStage(const TSourceLoc & loc,const char * const extension)1067 void TParseVersions::checkExtensionStage(const TSourceLoc& loc, const char * const extension)
1068 {
1069 // GL_NV_mesh_shader extension is only allowed in task/mesh shaders
1070 if (strcmp(extension, "GL_NV_mesh_shader") == 0) {
1071 requireStage(loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask | EShLangFragmentMask),
1072 "#extension GL_NV_mesh_shader");
1073 profileRequires(loc, ECoreProfile, 450, nullptr, "#extension GL_NV_mesh_shader");
1074 profileRequires(loc, EEsProfile, 320, nullptr, "#extension GL_NV_mesh_shader");
1075 if (extensionTurnedOn(E_GL_EXT_mesh_shader)) {
1076 error(loc, "GL_EXT_mesh_shader is already turned on, and not allowed with", "#extension", extension);
1077 }
1078 }
1079 else if (strcmp(extension, "GL_EXT_mesh_shader") == 0) {
1080 requireStage(loc, (EShLanguageMask)(EShLangTaskMask | EShLangMeshMask | EShLangFragmentMask),
1081 "#extension GL_EXT_mesh_shader");
1082 profileRequires(loc, ECoreProfile, 450, nullptr, "#extension GL_EXT_mesh_shader");
1083 profileRequires(loc, EEsProfile, 320, nullptr, "#extension GL_EXT_mesh_shader");
1084 if (extensionTurnedOn(E_GL_NV_mesh_shader)) {
1085 error(loc, "GL_NV_mesh_shader is already turned on, and not allowed with", "#extension", extension);
1086 }
1087 }
1088 }
1089
1090 // Check if extension has additional requirements
extensionRequires(const TSourceLoc & loc,const char * const extension,const char * behaviorString)1091 void TParseVersions::extensionRequires(const TSourceLoc &loc, const char * const extension, const char *behaviorString)
1092 {
1093 bool isEnabled = false;
1094 if (!strcmp("require", behaviorString))
1095 isEnabled = true;
1096 else if (!strcmp("enable", behaviorString))
1097 isEnabled = true;
1098
1099 if (isEnabled) {
1100 unsigned int minSpvVersion = 0;
1101 auto iter = extensionMinSpv.find(TString(extension));
1102 if (iter != extensionMinSpv.end())
1103 minSpvVersion = iter->second;
1104 requireSpv(loc, extension, minSpvVersion);
1105 }
1106 }
1107
1108 // Call for any operation needing full GLSL integer data-type support.
fullIntegerCheck(const TSourceLoc & loc,const char * op)1109 void TParseVersions::fullIntegerCheck(const TSourceLoc& loc, const char* op)
1110 {
1111 profileRequires(loc, ENoProfile, 130, nullptr, op);
1112 profileRequires(loc, EEsProfile, 300, nullptr, op);
1113 }
1114
1115 // Call for any operation needing GLSL double data-type support.
doubleCheck(const TSourceLoc & loc,const char * op)1116 void TParseVersions::doubleCheck(const TSourceLoc& loc, const char* op)
1117 {
1118
1119 //requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1120 if (language == EShLangVertex) {
1121 const char* const f64_Extensions[] = {E_GL_ARB_gpu_shader_fp64, E_GL_ARB_vertex_attrib_64bit};
1122 profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, 2, f64_Extensions, op);
1123 } else
1124 profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader_fp64, op);
1125 }
1126
1127 // Call for any operation needing GLSL float16 data-type support.
float16Check(const TSourceLoc & loc,const char * op,bool builtIn)1128 void TParseVersions::float16Check(const TSourceLoc& loc, const char* op, bool builtIn)
1129 {
1130 if (!builtIn) {
1131 const char* const extensions[] = {
1132 E_GL_AMD_gpu_shader_half_float,
1133 E_GL_EXT_shader_explicit_arithmetic_types,
1134 E_GL_EXT_shader_explicit_arithmetic_types_float16};
1135 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1136 }
1137 }
1138
float16Arithmetic()1139 bool TParseVersions::float16Arithmetic()
1140 {
1141 const char* const extensions[] = {
1142 E_GL_AMD_gpu_shader_half_float,
1143 E_GL_EXT_shader_explicit_arithmetic_types,
1144 E_GL_EXT_shader_explicit_arithmetic_types_float16};
1145 return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
1146 }
1147
int16Arithmetic()1148 bool TParseVersions::int16Arithmetic()
1149 {
1150 const char* const extensions[] = {
1151 E_GL_AMD_gpu_shader_int16,
1152 E_GL_EXT_shader_explicit_arithmetic_types,
1153 E_GL_EXT_shader_explicit_arithmetic_types_int16};
1154 return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
1155 }
1156
int8Arithmetic()1157 bool TParseVersions::int8Arithmetic()
1158 {
1159 const char* const extensions[] = {
1160 E_GL_EXT_shader_explicit_arithmetic_types,
1161 E_GL_EXT_shader_explicit_arithmetic_types_int8};
1162 return extensionsTurnedOn(sizeof(extensions)/sizeof(extensions[0]), extensions);
1163 }
1164
requireFloat16Arithmetic(const TSourceLoc & loc,const char * op,const char * featureDesc)1165 void TParseVersions::requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
1166 {
1167 TString combined;
1168 combined = op;
1169 combined += ": ";
1170 combined += featureDesc;
1171
1172 const char* const extensions[] = {
1173 E_GL_AMD_gpu_shader_half_float,
1174 E_GL_EXT_shader_explicit_arithmetic_types,
1175 E_GL_EXT_shader_explicit_arithmetic_types_float16};
1176 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
1177 }
1178
requireInt16Arithmetic(const TSourceLoc & loc,const char * op,const char * featureDesc)1179 void TParseVersions::requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
1180 {
1181 TString combined;
1182 combined = op;
1183 combined += ": ";
1184 combined += featureDesc;
1185
1186 const char* const extensions[] = {
1187 E_GL_AMD_gpu_shader_int16,
1188 E_GL_EXT_shader_explicit_arithmetic_types,
1189 E_GL_EXT_shader_explicit_arithmetic_types_int16};
1190 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
1191 }
1192
requireInt8Arithmetic(const TSourceLoc & loc,const char * op,const char * featureDesc)1193 void TParseVersions::requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc)
1194 {
1195 TString combined;
1196 combined = op;
1197 combined += ": ";
1198 combined += featureDesc;
1199
1200 const char* const extensions[] = {
1201 E_GL_EXT_shader_explicit_arithmetic_types,
1202 E_GL_EXT_shader_explicit_arithmetic_types_int8};
1203 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, combined.c_str());
1204 }
1205
float16ScalarVectorCheck(const TSourceLoc & loc,const char * op,bool builtIn)1206 void TParseVersions::float16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1207 {
1208 if (!builtIn) {
1209 const char* const extensions[] = {
1210 E_GL_AMD_gpu_shader_half_float,
1211 E_GL_EXT_shader_16bit_storage,
1212 E_GL_EXT_shader_explicit_arithmetic_types,
1213 E_GL_EXT_shader_explicit_arithmetic_types_float16};
1214 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1215 }
1216 }
1217
1218 // Call for any operation needing GLSL float32 data-type support.
explicitFloat32Check(const TSourceLoc & loc,const char * op,bool builtIn)1219 void TParseVersions::explicitFloat32Check(const TSourceLoc& loc, const char* op, bool builtIn)
1220 {
1221 if (!builtIn) {
1222 const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1223 E_GL_EXT_shader_explicit_arithmetic_types_float32};
1224 requireExtensions(loc, 2, extensions, op);
1225 }
1226 }
1227
1228 // Call for any operation needing GLSL float64 data-type support.
explicitFloat64Check(const TSourceLoc & loc,const char * op,bool builtIn)1229 void TParseVersions::explicitFloat64Check(const TSourceLoc& loc, const char* op, bool builtIn)
1230 {
1231 if (!builtIn) {
1232 const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1233 E_GL_EXT_shader_explicit_arithmetic_types_float64};
1234 requireExtensions(loc, 2, extensions, op);
1235 requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1236 profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
1237 }
1238 }
1239
1240 // Call for any operation needing GLSL explicit int8 data-type support.
explicitInt8Check(const TSourceLoc & loc,const char * op,bool builtIn)1241 void TParseVersions::explicitInt8Check(const TSourceLoc& loc, const char* op, bool builtIn)
1242 {
1243 if (! builtIn) {
1244 const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1245 E_GL_EXT_shader_explicit_arithmetic_types_int8};
1246 requireExtensions(loc, 2, extensions, op);
1247 }
1248 }
1249
1250 // Call for any operation needing GLSL float16 opaque-type support
float16OpaqueCheck(const TSourceLoc & loc,const char * op,bool builtIn)1251 void TParseVersions::float16OpaqueCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1252 {
1253 if (! builtIn) {
1254 requireExtensions(loc, 1, &E_GL_AMD_gpu_shader_half_float_fetch, op);
1255 requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1256 profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
1257 }
1258 }
1259
1260 // Call for any operation needing GLSL explicit int16 data-type support.
explicitInt16Check(const TSourceLoc & loc,const char * op,bool builtIn)1261 void TParseVersions::explicitInt16Check(const TSourceLoc& loc, const char* op, bool builtIn)
1262 {
1263 if (! builtIn) {
1264 const char* const extensions[] = {
1265 E_GL_AMD_gpu_shader_int16,
1266 E_GL_EXT_shader_explicit_arithmetic_types,
1267 E_GL_EXT_shader_explicit_arithmetic_types_int16};
1268 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1269 }
1270 }
1271
int16ScalarVectorCheck(const TSourceLoc & loc,const char * op,bool builtIn)1272 void TParseVersions::int16ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1273 {
1274 if (! builtIn) {
1275 const char* const extensions[] = {
1276 E_GL_AMD_gpu_shader_int16,
1277 E_GL_EXT_shader_16bit_storage,
1278 E_GL_EXT_shader_explicit_arithmetic_types,
1279 E_GL_EXT_shader_explicit_arithmetic_types_int16};
1280 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1281 }
1282 }
1283
int8ScalarVectorCheck(const TSourceLoc & loc,const char * op,bool builtIn)1284 void TParseVersions::int8ScalarVectorCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1285 {
1286 if (! builtIn) {
1287 const char* const extensions[] = {
1288 E_GL_EXT_shader_8bit_storage,
1289 E_GL_EXT_shader_explicit_arithmetic_types,
1290 E_GL_EXT_shader_explicit_arithmetic_types_int8};
1291 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1292 }
1293 }
1294
1295 // Call for any operation needing GLSL explicit int32 data-type support.
explicitInt32Check(const TSourceLoc & loc,const char * op,bool builtIn)1296 void TParseVersions::explicitInt32Check(const TSourceLoc& loc, const char* op, bool builtIn)
1297 {
1298 if (! builtIn) {
1299 const char* const extensions[2] = {E_GL_EXT_shader_explicit_arithmetic_types,
1300 E_GL_EXT_shader_explicit_arithmetic_types_int32};
1301 requireExtensions(loc, 2, extensions, op);
1302 }
1303 }
1304
1305 // Call for any operation needing GLSL 64-bit integer data-type support.
int64Check(const TSourceLoc & loc,const char * op,bool builtIn)1306 void TParseVersions::int64Check(const TSourceLoc& loc, const char* op, bool builtIn)
1307 {
1308 if (! builtIn) {
1309 const char* const extensions[3] = {E_GL_ARB_gpu_shader_int64,
1310 E_GL_EXT_shader_explicit_arithmetic_types,
1311 E_GL_EXT_shader_explicit_arithmetic_types_int64};
1312 requireExtensions(loc, 3, extensions, op);
1313 requireProfile(loc, ECoreProfile | ECompatibilityProfile, op);
1314 profileRequires(loc, ECoreProfile | ECompatibilityProfile, 400, nullptr, op);
1315 }
1316 }
1317
fcoopmatCheck(const TSourceLoc & loc,const char * op,bool builtIn)1318 void TParseVersions::fcoopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1319 {
1320 if (!builtIn) {
1321 const char* const extensions[] = {E_GL_NV_cooperative_matrix};
1322 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1323 }
1324 }
1325
intcoopmatCheck(const TSourceLoc & loc,const char * op,bool builtIn)1326 void TParseVersions::intcoopmatCheck(const TSourceLoc& loc, const char* op, bool builtIn)
1327 {
1328 if (!builtIn) {
1329 const char* const extensions[] = {E_GL_NV_integer_cooperative_matrix};
1330 requireExtensions(loc, sizeof(extensions)/sizeof(extensions[0]), extensions, op);
1331 }
1332 }
1333 #endif // GLSLANG_WEB
1334 // Call for any operation removed because SPIR-V is in use.
spvRemoved(const TSourceLoc & loc,const char * op)1335 void TParseVersions::spvRemoved(const TSourceLoc& loc, const char* op)
1336 {
1337 if (spvVersion.spv != 0)
1338 error(loc, "not allowed when generating SPIR-V", op, "");
1339 }
1340
1341 // Call for any operation removed because Vulkan SPIR-V is being generated.
vulkanRemoved(const TSourceLoc & loc,const char * op)1342 void TParseVersions::vulkanRemoved(const TSourceLoc& loc, const char* op)
1343 {
1344 if (spvVersion.vulkan > 0 && !spvVersion.vulkanRelaxed)
1345 error(loc, "not allowed when using GLSL for Vulkan", op, "");
1346 }
1347
1348 // Call for any operation that requires Vulkan.
requireVulkan(const TSourceLoc & loc,const char * op)1349 void TParseVersions::requireVulkan(const TSourceLoc& loc, const char* op)
1350 {
1351 #ifndef GLSLANG_WEB
1352 if (spvVersion.vulkan == 0)
1353 error(loc, "only allowed when using GLSL for Vulkan", op, "");
1354 #endif
1355 }
1356
1357 // Call for any operation that requires SPIR-V.
requireSpv(const TSourceLoc & loc,const char * op)1358 void TParseVersions::requireSpv(const TSourceLoc& loc, const char* op)
1359 {
1360 #ifndef GLSLANG_WEB
1361 if (spvVersion.spv == 0)
1362 error(loc, "only allowed when generating SPIR-V", op, "");
1363 #endif
1364 }
requireSpv(const TSourceLoc & loc,const char * op,unsigned int version)1365 void TParseVersions::requireSpv(const TSourceLoc& loc, const char *op, unsigned int version)
1366 {
1367 #ifndef GLSLANG_WEB
1368 if (spvVersion.spv < version)
1369 error(loc, "not supported for current targeted SPIR-V version", op, "");
1370 #endif
1371 }
1372
1373 } // end namespace glslang
1374