Versions.cpp 61 KB

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