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