1 /* 2 * Copyright © 2010 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef GLSL_PARSER_EXTRAS_H 25 #define GLSL_PARSER_EXTRAS_H 26 27 /* 28 * Most of the definitions here only apply to C++ 29 */ 30 #ifdef __cplusplus 31 32 33 #include <stdlib.h> 34 #include "glsl_symbol_table.h" 35 #include "mesa/main/config.h" 36 #include "mesa/main/menums.h" /* for gl_api */ 37 38 /* THIS is a macro defined somewhere deep in the Windows MSVC header files. 39 * Undefine it here to avoid collision with the lexer's THIS token. 40 */ 41 #undef THIS 42 43 struct gl_context; 44 45 struct glsl_switch_state { 46 /** Temporary variables needed for switch statement. */ 47 ir_variable *test_var; 48 ir_variable *is_fallthru_var; 49 class ast_switch_statement *switch_nesting_ast; 50 51 /** Used to detect if 'continue' was called inside a switch. */ 52 ir_variable *continue_inside; 53 54 /** Used to set condition if 'default' label should be chosen. */ 55 ir_variable *run_default; 56 57 /** Table of constant values already used in case labels */ 58 struct hash_table *labels_ht; 59 class ast_case_label *previous_default; 60 61 bool is_switch_innermost; // if switch stmt is closest to break, ... 62 }; 63 64 const char * 65 glsl_compute_version_string(void *mem_ctx, bool is_es, unsigned version); 66 67 typedef struct YYLTYPE { 68 int first_line; 69 int first_column; 70 int last_line; 71 int last_column; 72 unsigned source; 73 /* Path for ARB_shading_language_include include source */ 74 char *path; 75 } YYLTYPE; 76 # define YYLTYPE_IS_DECLARED 1 77 # define YYLTYPE_IS_TRIVIAL 1 78 79 extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, 80 const char *fmt, ...) PRINTFLIKE(3, 4); 81 82 83 struct _mesa_glsl_parse_state { 84 _mesa_glsl_parse_state(struct gl_context *_ctx, gl_shader_stage stage, 85 void *mem_ctx); 86 87 DECLARE_RZALLOC_CXX_OPERATORS(_mesa_glsl_parse_state); 88 89 /** 90 * Generate a string representing the GLSL version currently being compiled 91 * (useful for error messages). 92 */ get_version_string_mesa_glsl_parse_state93 const char *get_version_string() 94 { 95 return glsl_compute_version_string(this, this->es_shader, 96 this->language_version); 97 } 98 99 /** 100 * Determine whether the current GLSL version is sufficiently high to 101 * support a certain feature. 102 * 103 * \param required_glsl_version is the desktop GLSL version that is 104 * required to support the feature, or 0 if no version of desktop GLSL 105 * supports the feature. 106 * 107 * \param required_glsl_es_version is the GLSL ES version that is required 108 * to support the feature, or 0 if no version of GLSL ES supports the 109 * feature. 110 */ is_version_mesa_glsl_parse_state111 bool is_version(unsigned required_glsl_version, 112 unsigned required_glsl_es_version) const 113 { 114 unsigned required_version = this->es_shader ? 115 required_glsl_es_version : required_glsl_version; 116 unsigned this_version = this->forced_language_version 117 ? this->forced_language_version : this->language_version; 118 return required_version != 0 119 && this_version >= required_version; 120 } 121 122 bool check_version(unsigned required_glsl_version, 123 unsigned required_glsl_es_version, 124 YYLTYPE *locp, const char *fmt, ...) PRINTFLIKE(5, 6); 125 check_arrays_of_arrays_allowed_mesa_glsl_parse_state126 bool check_arrays_of_arrays_allowed(YYLTYPE *locp) 127 { 128 if (!(ARB_arrays_of_arrays_enable || is_version(430, 310))) { 129 const char *const requirement = this->es_shader 130 ? "GLSL ES 3.10" 131 : "GL_ARB_arrays_of_arrays or GLSL 4.30"; 132 _mesa_glsl_error(locp, this, 133 "%s required for defining arrays of arrays.", 134 requirement); 135 return false; 136 } 137 return true; 138 } 139 check_precision_qualifiers_allowed_mesa_glsl_parse_state140 bool check_precision_qualifiers_allowed(YYLTYPE *locp) 141 { 142 return check_version(130, 100, locp, 143 "precision qualifiers are forbidden"); 144 } 145 check_bitwise_operations_allowed_mesa_glsl_parse_state146 bool check_bitwise_operations_allowed(YYLTYPE *locp) 147 { 148 return EXT_gpu_shader4_enable || 149 check_version(130, 300, locp, "bit-wise operations are forbidden"); 150 } 151 check_explicit_attrib_stream_allowed_mesa_glsl_parse_state152 bool check_explicit_attrib_stream_allowed(YYLTYPE *locp) 153 { 154 if (!this->has_explicit_attrib_stream()) { 155 const char *const requirement = "GL_ARB_gpu_shader5 extension or GLSL 4.00"; 156 157 _mesa_glsl_error(locp, this, "explicit stream requires %s", 158 requirement); 159 return false; 160 } 161 162 return true; 163 } 164 check_explicit_attrib_location_allowed_mesa_glsl_parse_state165 bool check_explicit_attrib_location_allowed(YYLTYPE *locp, 166 const ir_variable *var) 167 { 168 if (!this->has_explicit_attrib_location()) { 169 const char *const requirement = this->es_shader 170 ? "GLSL ES 3.00" 171 : "GL_ARB_explicit_attrib_location extension or GLSL 3.30"; 172 173 _mesa_glsl_error(locp, this, "%s explicit location requires %s", 174 mode_string(var), requirement); 175 return false; 176 } 177 178 return true; 179 } 180 check_separate_shader_objects_allowed_mesa_glsl_parse_state181 bool check_separate_shader_objects_allowed(YYLTYPE *locp, 182 const ir_variable *var) 183 { 184 if (!this->has_separate_shader_objects()) { 185 const char *const requirement = this->es_shader 186 ? "GL_EXT_separate_shader_objects extension or GLSL ES 3.10" 187 : "GL_ARB_separate_shader_objects extension or GLSL 4.20"; 188 189 _mesa_glsl_error(locp, this, "%s explicit location requires %s", 190 mode_string(var), requirement); 191 return false; 192 } 193 194 return true; 195 } 196 check_explicit_uniform_location_allowed_mesa_glsl_parse_state197 bool check_explicit_uniform_location_allowed(YYLTYPE *locp, 198 const ir_variable *) 199 { 200 if (!this->has_explicit_attrib_location() || 201 !this->has_explicit_uniform_location()) { 202 const char *const requirement = this->es_shader 203 ? "GLSL ES 3.10" 204 : "GL_ARB_explicit_uniform_location and either " 205 "GL_ARB_explicit_attrib_location or GLSL 3.30."; 206 207 _mesa_glsl_error(locp, this, 208 "uniform explicit location requires %s", 209 requirement); 210 return false; 211 } 212 213 return true; 214 } 215 has_atomic_counters_mesa_glsl_parse_state216 bool has_atomic_counters() const 217 { 218 return ARB_shader_atomic_counters_enable || is_version(420, 310); 219 } 220 has_enhanced_layouts_mesa_glsl_parse_state221 bool has_enhanced_layouts() const 222 { 223 return ARB_enhanced_layouts_enable || is_version(440, 0); 224 } 225 has_explicit_attrib_stream_mesa_glsl_parse_state226 bool has_explicit_attrib_stream() const 227 { 228 return ARB_gpu_shader5_enable || is_version(400, 0); 229 } 230 has_explicit_attrib_location_mesa_glsl_parse_state231 bool has_explicit_attrib_location() const 232 { 233 return ARB_explicit_attrib_location_enable || is_version(330, 300); 234 } 235 has_explicit_uniform_location_mesa_glsl_parse_state236 bool has_explicit_uniform_location() const 237 { 238 return ARB_explicit_uniform_location_enable || is_version(430, 310); 239 } 240 has_uniform_buffer_objects_mesa_glsl_parse_state241 bool has_uniform_buffer_objects() const 242 { 243 return ARB_uniform_buffer_object_enable || is_version(140, 300); 244 } 245 has_shader_storage_buffer_objects_mesa_glsl_parse_state246 bool has_shader_storage_buffer_objects() const 247 { 248 return ARB_shader_storage_buffer_object_enable || is_version(430, 310); 249 } 250 has_separate_shader_objects_mesa_glsl_parse_state251 bool has_separate_shader_objects() const 252 { 253 return ARB_separate_shader_objects_enable || is_version(410, 310) 254 || EXT_separate_shader_objects_enable; 255 } 256 has_double_mesa_glsl_parse_state257 bool has_double() const 258 { 259 return ARB_gpu_shader_fp64_enable || is_version(400, 0); 260 } 261 has_int64_mesa_glsl_parse_state262 bool has_int64() const 263 { 264 return ARB_gpu_shader_int64_enable || 265 AMD_gpu_shader_int64_enable; 266 } 267 has_420pack_mesa_glsl_parse_state268 bool has_420pack() const 269 { 270 return ARB_shading_language_420pack_enable || is_version(420, 0); 271 } 272 has_420pack_or_es31_mesa_glsl_parse_state273 bool has_420pack_or_es31() const 274 { 275 return ARB_shading_language_420pack_enable || is_version(420, 310); 276 } 277 has_compute_shader_mesa_glsl_parse_state278 bool has_compute_shader() const 279 { 280 return ARB_compute_shader_enable || is_version(430, 310); 281 } 282 has_shader_io_blocks_mesa_glsl_parse_state283 bool has_shader_io_blocks() const 284 { 285 /* The OES_geometry_shader_specification says: 286 * 287 * "If the OES_geometry_shader extension is enabled, the 288 * OES_shader_io_blocks extension is also implicitly enabled." 289 * 290 * The OES_tessellation_shader extension has similar wording. 291 */ 292 return OES_shader_io_blocks_enable || 293 EXT_shader_io_blocks_enable || 294 OES_geometry_shader_enable || 295 EXT_geometry_shader_enable || 296 OES_tessellation_shader_enable || 297 EXT_tessellation_shader_enable || 298 299 is_version(150, 320); 300 } 301 has_geometry_shader_mesa_glsl_parse_state302 bool has_geometry_shader() const 303 { 304 return OES_geometry_shader_enable || EXT_geometry_shader_enable || 305 is_version(150, 320); 306 } 307 has_tessellation_shader_mesa_glsl_parse_state308 bool has_tessellation_shader() const 309 { 310 return ARB_tessellation_shader_enable || 311 OES_tessellation_shader_enable || 312 EXT_tessellation_shader_enable || 313 is_version(400, 320); 314 } 315 has_clip_distance_mesa_glsl_parse_state316 bool has_clip_distance() const 317 { 318 return EXT_clip_cull_distance_enable || is_version(130, 0); 319 } 320 has_cull_distance_mesa_glsl_parse_state321 bool has_cull_distance() const 322 { 323 return EXT_clip_cull_distance_enable || 324 ARB_cull_distance_enable || 325 is_version(450, 0); 326 } 327 has_framebuffer_fetch_mesa_glsl_parse_state328 bool has_framebuffer_fetch() const 329 { 330 return EXT_shader_framebuffer_fetch_enable || 331 EXT_shader_framebuffer_fetch_non_coherent_enable; 332 } 333 has_framebuffer_fetch_zs_mesa_glsl_parse_state334 bool has_framebuffer_fetch_zs() const 335 { 336 return ARM_shader_framebuffer_fetch_depth_stencil_enable; 337 } 338 has_texture_cube_map_array_mesa_glsl_parse_state339 bool has_texture_cube_map_array() const 340 { 341 return ARB_texture_cube_map_array_enable || 342 EXT_texture_cube_map_array_enable || 343 OES_texture_cube_map_array_enable || 344 is_version(400, 320); 345 } 346 has_shader_image_load_store_mesa_glsl_parse_state347 bool has_shader_image_load_store() const 348 { 349 return ARB_shader_image_load_store_enable || 350 EXT_shader_image_load_store_enable || 351 is_version(420, 310); 352 } 353 has_bindless_mesa_glsl_parse_state354 bool has_bindless() const 355 { 356 return ARB_bindless_texture_enable; 357 } 358 has_image_load_formatted_mesa_glsl_parse_state359 bool has_image_load_formatted() const 360 { 361 return EXT_shader_image_load_formatted_enable; 362 } 363 has_implicit_conversions_mesa_glsl_parse_state364 bool has_implicit_conversions() const 365 { 366 return EXT_shader_implicit_conversions_enable || 367 is_version(allow_glsl_120_subset_in_110 ? 110 : 120, 0); 368 } 369 has_implicit_int_to_uint_conversion_mesa_glsl_parse_state370 bool has_implicit_int_to_uint_conversion() const 371 { 372 return ARB_gpu_shader5_enable || 373 MESA_shader_integer_functions_enable || 374 EXT_shader_implicit_conversions_enable || 375 is_version(400, 0); 376 } 377 378 void set_valid_gl_and_glsl_versions(YYLTYPE *locp); 379 380 void process_version_directive(YYLTYPE *locp, int version, 381 const char *ident); 382 383 struct gl_context *const ctx; /* only to be used for debug callback. */ 384 const struct gl_extensions *exts; 385 const struct gl_constants *consts; 386 gl_api api; 387 void *scanner; 388 exec_list translation_unit; 389 glsl_symbol_table *symbols; 390 391 linear_ctx *linalloc; 392 393 unsigned num_supported_versions; 394 struct { 395 unsigned ver; 396 uint8_t gl_ver; 397 bool es; 398 } supported_versions[17]; 399 400 bool es_shader; 401 bool compat_shader; 402 unsigned language_version; 403 unsigned forced_language_version; 404 /* Bitfield of ir_variable_mode to zero init */ 405 uint32_t zero_init; 406 unsigned gl_version; 407 gl_shader_stage stage; 408 409 /** 410 * Default uniform layout qualifiers tracked during parsing. 411 * Currently affects uniform blocks and uniform buffer variables in 412 * those blocks. 413 */ 414 struct ast_type_qualifier *default_uniform_qualifier; 415 416 /** 417 * Default shader storage layout qualifiers tracked during parsing. 418 * Currently affects shader storage blocks and shader storage buffer 419 * variables in those blocks. 420 */ 421 struct ast_type_qualifier *default_shader_storage_qualifier; 422 423 /** 424 * Variables to track different cases if a fragment shader redeclares 425 * built-in variable gl_FragCoord. 426 * 427 * Note: These values are computed at ast_to_hir time rather than at parse 428 * time. 429 */ 430 bool fs_redeclares_gl_fragcoord; 431 bool fs_origin_upper_left; 432 bool fs_pixel_center_integer; 433 bool fs_redeclares_gl_fragcoord_with_no_layout_qualifiers; 434 435 /** 436 * True if a geometry shader input primitive type or tessellation control 437 * output vertices were specified using a layout directive. 438 * 439 * Note: these values are computed at ast_to_hir time rather than at parse 440 * time. 441 */ 442 bool gs_input_prim_type_specified; 443 bool tcs_output_vertices_specified; 444 445 /** 446 * Input layout qualifiers from GLSL 1.50 (geometry shader controls), 447 * and GLSL 4.00 (tessellation evaluation shader) 448 */ 449 struct ast_type_qualifier *in_qualifier; 450 451 /** 452 * True if a compute shader input local size was specified using a layout 453 * directive. 454 * 455 * Note: this value is computed at ast_to_hir time rather than at parse 456 * time. 457 */ 458 bool cs_input_local_size_specified; 459 460 /** 461 * If cs_input_local_size_specified is true, the local size that was 462 * specified. Otherwise ignored. 463 */ 464 unsigned cs_input_local_size[3]; 465 466 /** 467 * True if a compute shader input local variable size was specified using 468 * a layout directive as specified by ARB_compute_variable_group_size. 469 */ 470 bool cs_input_local_size_variable_specified; 471 472 /** 473 * Arrangement of invocations used to calculate derivatives in a compute 474 * shader. From NV_compute_shader_derivatives. 475 */ 476 enum gl_derivative_group cs_derivative_group; 477 478 /** 479 * True if a shader declare bindless_sampler/bindless_image, and 480 * respectively bound_sampler/bound_image at global scope as specified by 481 * ARB_bindless_texture. 482 */ 483 bool bindless_sampler_specified; 484 bool bindless_image_specified; 485 bool bound_sampler_specified; 486 bool bound_image_specified; 487 488 /** 489 * Output layout qualifiers from GLSL 1.50 (geometry shader controls), 490 * and GLSL 4.00 (tessellation control shader). 491 */ 492 struct ast_type_qualifier *out_qualifier; 493 494 /** 495 * Printable list of GLSL versions supported by the current context 496 * 497 * \note 498 * This string should probably be generated per-context instead of per 499 * invokation of the compiler. This should be changed when the method of 500 * tracking supported GLSL versions changes. 501 */ 502 const char *supported_version_string; 503 504 /** 505 * Implementation defined limits that affect built-in variables, etc. 506 * 507 * \sa struct gl_constants (in mtypes.h) 508 */ 509 struct { 510 /* 1.10 */ 511 unsigned MaxLights; 512 unsigned MaxClipPlanes; 513 unsigned MaxTextureUnits; 514 unsigned MaxTextureCoords; 515 unsigned MaxVertexAttribs; 516 unsigned MaxVertexUniformComponents; 517 unsigned MaxVertexTextureImageUnits; 518 unsigned MaxCombinedTextureImageUnits; 519 unsigned MaxTextureImageUnits; 520 unsigned MaxFragmentUniformComponents; 521 522 /* ARB_draw_buffers */ 523 unsigned MaxDrawBuffers; 524 525 /* ARB_enhanced_layouts */ 526 unsigned MaxTransformFeedbackBuffers; 527 unsigned MaxTransformFeedbackInterleavedComponents; 528 529 /* ARB_blend_func_extended */ 530 unsigned MaxDualSourceDrawBuffers; 531 532 /* 3.00 ES */ 533 int MinProgramTexelOffset; 534 int MaxProgramTexelOffset; 535 536 /* 1.50 */ 537 unsigned MaxVertexOutputComponents; 538 unsigned MaxGeometryInputComponents; 539 unsigned MaxGeometryOutputComponents; 540 unsigned MaxGeometryShaderInvocations; 541 unsigned MaxFragmentInputComponents; 542 unsigned MaxGeometryTextureImageUnits; 543 unsigned MaxGeometryOutputVertices; 544 unsigned MaxGeometryTotalOutputComponents; 545 unsigned MaxGeometryUniformComponents; 546 547 /* ARB_shader_atomic_counters */ 548 unsigned MaxVertexAtomicCounters; 549 unsigned MaxTessControlAtomicCounters; 550 unsigned MaxTessEvaluationAtomicCounters; 551 unsigned MaxGeometryAtomicCounters; 552 unsigned MaxFragmentAtomicCounters; 553 unsigned MaxCombinedAtomicCounters; 554 unsigned MaxAtomicBufferBindings; 555 556 /* These are also atomic counter related, but they weren't added to 557 * until atomic counters were added to core in GLSL 4.20 and GLSL ES 558 * 3.10. 559 */ 560 unsigned MaxVertexAtomicCounterBuffers; 561 unsigned MaxTessControlAtomicCounterBuffers; 562 unsigned MaxTessEvaluationAtomicCounterBuffers; 563 unsigned MaxGeometryAtomicCounterBuffers; 564 unsigned MaxFragmentAtomicCounterBuffers; 565 unsigned MaxCombinedAtomicCounterBuffers; 566 unsigned MaxAtomicCounterBufferSize; 567 568 /* ARB_compute_shader */ 569 unsigned MaxComputeAtomicCounterBuffers; 570 unsigned MaxComputeAtomicCounters; 571 unsigned MaxComputeImageUniforms; 572 unsigned MaxComputeTextureImageUnits; 573 unsigned MaxComputeUniformComponents; 574 unsigned MaxComputeWorkGroupCount[3]; 575 unsigned MaxComputeWorkGroupSize[3]; 576 577 /* ARB_shader_image_load_store */ 578 unsigned MaxImageUnits; 579 unsigned MaxCombinedShaderOutputResources; 580 unsigned MaxImageSamples; 581 unsigned MaxVertexImageUniforms; 582 unsigned MaxTessControlImageUniforms; 583 unsigned MaxTessEvaluationImageUniforms; 584 unsigned MaxGeometryImageUniforms; 585 unsigned MaxFragmentImageUniforms; 586 unsigned MaxCombinedImageUniforms; 587 588 /* ARB_viewport_array */ 589 unsigned MaxViewports; 590 591 /* ARB_tessellation_shader */ 592 unsigned MaxPatchVertices; 593 unsigned MaxTessGenLevel; 594 unsigned MaxTessControlInputComponents; 595 unsigned MaxTessControlOutputComponents; 596 unsigned MaxTessControlTextureImageUnits; 597 unsigned MaxTessEvaluationInputComponents; 598 unsigned MaxTessEvaluationOutputComponents; 599 unsigned MaxTessEvaluationTextureImageUnits; 600 unsigned MaxTessPatchComponents; 601 unsigned MaxTessControlTotalOutputComponents; 602 unsigned MaxTessControlUniformComponents; 603 unsigned MaxTessEvaluationUniformComponents; 604 605 /* GL 4.5 / OES_sample_variables */ 606 unsigned MaxSamples; 607 } Const; 608 609 /** 610 * During AST to IR conversion, pointer to current IR function 611 * 612 * Will be \c NULL whenever the AST to IR conversion is not inside a 613 * function definition. 614 */ 615 class ir_function_signature *current_function; 616 617 /** 618 * During AST to IR conversion, pointer to the toplevel IR 619 * instruction list being generated. 620 */ 621 exec_list *toplevel_ir; 622 623 /** Have we found a return statement in this function? */ 624 bool found_return; 625 626 /** Have we found the interlock builtins in this function? */ 627 bool found_begin_interlock; 628 bool found_end_interlock; 629 630 /** Was there an error during compilation? */ 631 bool error; 632 633 /** 634 * Are all shader inputs / outputs invariant? 635 * 636 * This is set when the 'STDGL invariant(all)' pragma is used. 637 */ 638 bool all_invariant; 639 640 /** Loop or switch statement containing the current instructions. */ 641 class ast_iteration_statement *loop_nesting_ast; 642 643 struct glsl_switch_state switch_state; 644 645 /** List of structures defined in user code. */ 646 const glsl_type **user_structures; 647 unsigned num_user_structures; 648 649 char *info_log; 650 651 /** 652 * Are warnings enabled? 653 * 654 * Emission of warngins is controlled by '#pragma warning(...)'. 655 */ 656 bool warnings_enabled; 657 658 /** 659 * \name Enable bits for GLSL extensions 660 */ 661 /*@{*/ 662 /* ARB extensions go here, sorted alphabetically. 663 */ 664 bool ARB_ES3_1_compatibility_enable; 665 bool ARB_ES3_1_compatibility_warn; 666 bool ARB_ES3_2_compatibility_enable; 667 bool ARB_ES3_2_compatibility_warn; 668 bool ARB_arrays_of_arrays_enable; 669 bool ARB_arrays_of_arrays_warn; 670 bool ARB_bindless_texture_enable; 671 bool ARB_bindless_texture_warn; 672 bool ARB_compatibility_enable; 673 bool ARB_compatibility_warn; 674 bool ARB_compute_shader_enable; 675 bool ARB_compute_shader_warn; 676 bool ARB_compute_variable_group_size_enable; 677 bool ARB_compute_variable_group_size_warn; 678 bool ARB_conservative_depth_enable; 679 bool ARB_conservative_depth_warn; 680 bool ARB_cull_distance_enable; 681 bool ARB_cull_distance_warn; 682 bool ARB_derivative_control_enable; 683 bool ARB_derivative_control_warn; 684 bool ARB_draw_buffers_enable; 685 bool ARB_draw_buffers_warn; 686 bool ARB_draw_instanced_enable; 687 bool ARB_draw_instanced_warn; 688 bool ARB_enhanced_layouts_enable; 689 bool ARB_enhanced_layouts_warn; 690 bool ARB_explicit_attrib_location_enable; 691 bool ARB_explicit_attrib_location_warn; 692 bool ARB_explicit_uniform_location_enable; 693 bool ARB_explicit_uniform_location_warn; 694 bool ARB_fragment_coord_conventions_enable; 695 bool ARB_fragment_coord_conventions_warn; 696 bool ARB_fragment_layer_viewport_enable; 697 bool ARB_fragment_layer_viewport_warn; 698 bool ARB_fragment_shader_interlock_enable; 699 bool ARB_fragment_shader_interlock_warn; 700 bool ARB_gpu_shader5_enable; 701 bool ARB_gpu_shader5_warn; 702 bool ARB_gpu_shader_fp64_enable; 703 bool ARB_gpu_shader_fp64_warn; 704 bool ARB_gpu_shader_int64_enable; 705 bool ARB_gpu_shader_int64_warn; 706 bool ARB_post_depth_coverage_enable; 707 bool ARB_post_depth_coverage_warn; 708 bool ARB_sample_shading_enable; 709 bool ARB_sample_shading_warn; 710 bool ARB_separate_shader_objects_enable; 711 bool ARB_separate_shader_objects_warn; 712 bool ARB_shader_atomic_counter_ops_enable; 713 bool ARB_shader_atomic_counter_ops_warn; 714 bool ARB_shader_atomic_counters_enable; 715 bool ARB_shader_atomic_counters_warn; 716 bool ARB_shader_ballot_enable; 717 bool ARB_shader_ballot_warn; 718 bool ARB_shader_bit_encoding_enable; 719 bool ARB_shader_bit_encoding_warn; 720 bool ARB_shader_clock_enable; 721 bool ARB_shader_clock_warn; 722 bool ARB_shader_draw_parameters_enable; 723 bool ARB_shader_draw_parameters_warn; 724 bool ARB_shader_group_vote_enable; 725 bool ARB_shader_group_vote_warn; 726 bool ARB_shader_image_load_store_enable; 727 bool ARB_shader_image_load_store_warn; 728 bool ARB_shader_image_size_enable; 729 bool ARB_shader_image_size_warn; 730 bool ARB_shader_precision_enable; 731 bool ARB_shader_precision_warn; 732 bool ARB_shader_stencil_export_enable; 733 bool ARB_shader_stencil_export_warn; 734 bool ARB_shader_storage_buffer_object_enable; 735 bool ARB_shader_storage_buffer_object_warn; 736 bool ARB_shader_subroutine_enable; 737 bool ARB_shader_subroutine_warn; 738 bool ARB_shader_texture_image_samples_enable; 739 bool ARB_shader_texture_image_samples_warn; 740 bool ARB_shader_texture_lod_enable; 741 bool ARB_shader_texture_lod_warn; 742 bool ARB_shader_viewport_layer_array_enable; 743 bool ARB_shader_viewport_layer_array_warn; 744 bool ARB_shading_language_420pack_enable; 745 bool ARB_shading_language_420pack_warn; 746 bool ARB_shading_language_include_enable; 747 bool ARB_shading_language_include_warn; 748 bool ARB_shading_language_packing_enable; 749 bool ARB_shading_language_packing_warn; 750 bool ARB_sparse_texture2_enable; 751 bool ARB_sparse_texture2_warn; 752 bool ARB_sparse_texture_clamp_enable; 753 bool ARB_sparse_texture_clamp_warn; 754 bool ARB_tessellation_shader_enable; 755 bool ARB_tessellation_shader_warn; 756 bool ARB_texture_cube_map_array_enable; 757 bool ARB_texture_cube_map_array_warn; 758 bool ARB_texture_gather_enable; 759 bool ARB_texture_gather_warn; 760 bool ARB_texture_multisample_enable; 761 bool ARB_texture_multisample_warn; 762 bool ARB_texture_query_levels_enable; 763 bool ARB_texture_query_levels_warn; 764 bool ARB_texture_query_lod_enable; 765 bool ARB_texture_query_lod_warn; 766 bool ARB_texture_rectangle_enable; 767 bool ARB_texture_rectangle_warn; 768 bool ARB_uniform_buffer_object_enable; 769 bool ARB_uniform_buffer_object_warn; 770 bool ARB_vertex_attrib_64bit_enable; 771 bool ARB_vertex_attrib_64bit_warn; 772 bool ARB_viewport_array_enable; 773 bool ARB_viewport_array_warn; 774 775 /* KHR extensions go here, sorted alphabetically. 776 */ 777 bool KHR_blend_equation_advanced_enable; 778 bool KHR_blend_equation_advanced_warn; 779 bool KHR_shader_subgroup_arithmetic_enable; 780 bool KHR_shader_subgroup_arithmetic_warn; 781 bool KHR_shader_subgroup_ballot_enable; 782 bool KHR_shader_subgroup_ballot_warn; 783 bool KHR_shader_subgroup_basic_enable; 784 bool KHR_shader_subgroup_basic_warn; 785 bool KHR_shader_subgroup_clustered_enable; 786 bool KHR_shader_subgroup_clustered_warn; 787 bool KHR_shader_subgroup_quad_enable; 788 bool KHR_shader_subgroup_quad_warn; 789 bool KHR_shader_subgroup_shuffle_enable; 790 bool KHR_shader_subgroup_shuffle_warn; 791 bool KHR_shader_subgroup_shuffle_relative_enable; 792 bool KHR_shader_subgroup_shuffle_relative_warn; 793 bool KHR_shader_subgroup_vote_enable; 794 bool KHR_shader_subgroup_vote_warn; 795 796 /* OES extensions go here, sorted alphabetically. 797 */ 798 bool OES_EGL_image_external_enable; 799 bool OES_EGL_image_external_warn; 800 bool OES_EGL_image_external_essl3_enable; 801 bool OES_EGL_image_external_essl3_warn; 802 bool OES_geometry_point_size_enable; 803 bool OES_geometry_point_size_warn; 804 bool OES_geometry_shader_enable; 805 bool OES_geometry_shader_warn; 806 bool OES_gpu_shader5_enable; 807 bool OES_gpu_shader5_warn; 808 bool OES_primitive_bounding_box_enable; 809 bool OES_primitive_bounding_box_warn; 810 bool OES_sample_variables_enable; 811 bool OES_sample_variables_warn; 812 bool OES_shader_image_atomic_enable; 813 bool OES_shader_image_atomic_warn; 814 bool OES_shader_io_blocks_enable; 815 bool OES_shader_io_blocks_warn; 816 bool OES_shader_multisample_interpolation_enable; 817 bool OES_shader_multisample_interpolation_warn; 818 bool OES_standard_derivatives_enable; 819 bool OES_standard_derivatives_warn; 820 bool OES_tessellation_point_size_enable; 821 bool OES_tessellation_point_size_warn; 822 bool OES_tessellation_shader_enable; 823 bool OES_tessellation_shader_warn; 824 bool OES_texture_3D_enable; 825 bool OES_texture_3D_warn; 826 bool OES_texture_buffer_enable; 827 bool OES_texture_buffer_warn; 828 bool OES_texture_cube_map_array_enable; 829 bool OES_texture_cube_map_array_warn; 830 bool OES_texture_storage_multisample_2d_array_enable; 831 bool OES_texture_storage_multisample_2d_array_warn; 832 bool OES_viewport_array_enable; 833 bool OES_viewport_array_warn; 834 835 /* All other extensions go here, sorted alphabetically. 836 */ 837 bool AMD_conservative_depth_enable; 838 bool AMD_conservative_depth_warn; 839 bool AMD_gpu_shader_half_float_enable; 840 bool AMD_gpu_shader_half_float_warn; 841 bool AMD_gpu_shader_int64_enable; 842 bool AMD_gpu_shader_int64_warn; 843 bool AMD_shader_stencil_export_enable; 844 bool AMD_shader_stencil_export_warn; 845 bool AMD_shader_trinary_minmax_enable; 846 bool AMD_shader_trinary_minmax_warn; 847 bool AMD_texture_texture4_enable; 848 bool AMD_texture_texture4_warn; 849 bool AMD_vertex_shader_layer_enable; 850 bool AMD_vertex_shader_layer_warn; 851 bool AMD_vertex_shader_viewport_index_enable; 852 bool AMD_vertex_shader_viewport_index_warn; 853 bool ANDROID_extension_pack_es31a_enable; 854 bool ANDROID_extension_pack_es31a_warn; 855 bool ARM_shader_framebuffer_fetch_depth_stencil_enable; 856 bool ARM_shader_framebuffer_fetch_depth_stencil_warn; 857 bool EXT_blend_func_extended_enable; 858 bool EXT_blend_func_extended_warn; 859 bool EXT_clip_cull_distance_enable; 860 bool EXT_clip_cull_distance_warn; 861 bool EXT_demote_to_helper_invocation_enable; 862 bool EXT_demote_to_helper_invocation_warn; 863 bool EXT_draw_buffers_enable; 864 bool EXT_draw_buffers_warn; 865 bool EXT_draw_instanced_enable; 866 bool EXT_draw_instanced_warn; 867 bool EXT_frag_depth_enable; 868 bool EXT_frag_depth_warn; 869 bool EXT_geometry_point_size_enable; 870 bool EXT_geometry_point_size_warn; 871 bool EXT_geometry_shader_enable; 872 bool EXT_geometry_shader_warn; 873 bool EXT_gpu_shader4_enable; 874 bool EXT_gpu_shader4_warn; 875 bool EXT_gpu_shader5_enable; 876 bool EXT_gpu_shader5_warn; 877 bool EXT_primitive_bounding_box_enable; 878 bool EXT_primitive_bounding_box_warn; 879 bool EXT_separate_shader_objects_enable; 880 bool EXT_separate_shader_objects_warn; 881 bool EXT_shader_framebuffer_fetch_enable; 882 bool EXT_shader_framebuffer_fetch_warn; 883 bool EXT_shader_framebuffer_fetch_non_coherent_enable; 884 bool EXT_shader_framebuffer_fetch_non_coherent_warn; 885 bool EXT_shader_group_vote_enable; 886 bool EXT_shader_group_vote_warn; 887 bool EXT_shader_image_load_formatted_enable; 888 bool EXT_shader_image_load_formatted_warn; 889 bool EXT_shader_image_load_store_enable; 890 bool EXT_shader_image_load_store_warn; 891 bool EXT_shader_implicit_conversions_enable; 892 bool EXT_shader_implicit_conversions_warn; 893 bool EXT_shader_integer_mix_enable; 894 bool EXT_shader_integer_mix_warn; 895 bool EXT_shader_io_blocks_enable; 896 bool EXT_shader_io_blocks_warn; 897 bool EXT_shader_samples_identical_enable; 898 bool EXT_shader_samples_identical_warn; 899 bool EXT_shadow_samplers_enable; 900 bool EXT_shadow_samplers_warn; 901 bool EXT_tessellation_point_size_enable; 902 bool EXT_tessellation_point_size_warn; 903 bool EXT_tessellation_shader_enable; 904 bool EXT_tessellation_shader_warn; 905 bool EXT_texture_array_enable; 906 bool EXT_texture_array_warn; 907 bool EXT_texture_buffer_enable; 908 bool EXT_texture_buffer_warn; 909 bool EXT_texture_cube_map_array_enable; 910 bool EXT_texture_cube_map_array_warn; 911 bool EXT_texture_query_lod_enable; 912 bool EXT_texture_query_lod_warn; 913 bool EXT_texture_shadow_lod_enable; 914 bool EXT_texture_shadow_lod_warn; 915 bool INTEL_conservative_rasterization_enable; 916 bool INTEL_conservative_rasterization_warn; 917 bool INTEL_shader_atomic_float_minmax_enable; 918 bool INTEL_shader_atomic_float_minmax_warn; 919 bool INTEL_shader_integer_functions2_enable; 920 bool INTEL_shader_integer_functions2_warn; 921 bool MESA_shader_integer_functions_enable; 922 bool MESA_shader_integer_functions_warn; 923 bool NV_compute_shader_derivatives_enable; 924 bool NV_compute_shader_derivatives_warn; 925 bool NV_fragment_shader_interlock_enable; 926 bool NV_fragment_shader_interlock_warn; 927 bool NV_image_formats_enable; 928 bool NV_image_formats_warn; 929 bool NV_shader_atomic_float_enable; 930 bool NV_shader_atomic_float_warn; 931 bool NV_shader_atomic_int64_enable; 932 bool NV_shader_atomic_int64_warn; 933 bool NV_shader_noperspective_interpolation_enable; 934 bool NV_shader_noperspective_interpolation_warn; 935 bool NV_viewport_array2_enable; 936 bool NV_viewport_array2_warn; 937 bool OVR_multiview_enable; 938 bool OVR_multiview_warn; 939 bool OVR_multiview2_enable; 940 bool OVR_multiview2_warn; 941 /*@}*/ 942 943 /** Extensions supported by the OpenGL implementation. */ 944 const struct gl_extensions *extensions; 945 946 bool uses_builtin_functions; 947 bool fs_uses_gl_fragcoord; 948 949 /** 950 * For geometry shaders, size of the most recently seen input declaration 951 * that was a sized array, or 0 if no sized input array declarations have 952 * been seen. 953 * 954 * Unused for other shader types. 955 */ 956 unsigned gs_input_size; 957 958 bool fs_early_fragment_tests; 959 960 bool fs_inner_coverage; 961 962 bool fs_post_depth_coverage; 963 964 bool fs_pixel_interlock_ordered; 965 bool fs_pixel_interlock_unordered; 966 bool fs_sample_interlock_ordered; 967 bool fs_sample_interlock_unordered; 968 969 unsigned fs_blend_support; 970 971 /** 972 * For tessellation control shaders, size of the most recently seen output 973 * declaration that was a sized array, or 0 if no sized output array 974 * declarations have been seen. 975 * 976 * Unused for other shader types. 977 */ 978 unsigned tcs_output_size; 979 980 /** Atomic counter offsets by binding */ 981 unsigned atomic_counter_offsets[MAX_COMBINED_ATOMIC_BUFFERS]; 982 983 /** Whether gl_Layer output is viewport-relative. */ 984 bool redeclares_gl_layer; 985 bool layer_viewport_relative; 986 987 bool allow_extension_directive_midshader; 988 char *alias_shader_extension; 989 bool allow_vertex_texture_bias; 990 bool allow_glsl_120_subset_in_110; 991 bool allow_builtin_variable_redeclaration; 992 bool ignore_write_to_readonly_var; 993 994 /** 995 * Known subroutine type declarations. 996 */ 997 int num_subroutine_types; 998 ir_function **subroutine_types; 999 1000 /** 1001 * Functions that are associated with 1002 * subroutine types. 1003 */ 1004 int num_subroutines; 1005 ir_function **subroutines; 1006 1007 /** 1008 * field selection temporary parser storage - 1009 * did the parser just parse a dot. 1010 */ 1011 bool is_field; 1012 1013 /** 1014 * seen values for clip/cull distance sizes 1015 * so we can check totals aren't too large. 1016 */ 1017 unsigned clip_dist_size, cull_dist_size; 1018 }; 1019 1020 # define YYLLOC_DEFAULT(Current, Rhs, N) \ 1021 do { \ 1022 if (N) \ 1023 { \ 1024 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \ 1025 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \ 1026 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \ 1027 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \ 1028 (Current).path = YYRHSLOC(Rhs, N).path; \ 1029 (Current).source = YYRHSLOC(Rhs, N).source; \ 1030 } \ 1031 else \ 1032 { \ 1033 (Current).first_line = (Current).last_line = \ 1034 YYRHSLOC(Rhs, 0).last_line; \ 1035 (Current).first_column = (Current).last_column = \ 1036 YYRHSLOC(Rhs, 0).last_column; \ 1037 (Current).path = YYRHSLOC(Rhs, 0).path; \ 1038 (Current).source = YYRHSLOC(Rhs, 0).source; \ 1039 } \ 1040 } while (0) 1041 1042 /** 1043 * Emit a warning to the shader log 1044 * 1045 * \sa _mesa_glsl_error 1046 */ 1047 extern void _mesa_glsl_warning(const YYLTYPE *locp, 1048 _mesa_glsl_parse_state *state, 1049 const char *fmt, ...); 1050 1051 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, 1052 const char *string); 1053 1054 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state); 1055 1056 union YYSTYPE; 1057 extern int _mesa_glsl_lexer_lex(union YYSTYPE *yylval, YYLTYPE *yylloc, 1058 void *scanner); 1059 1060 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *); 1061 1062 /** 1063 * Process elements of the #extension directive 1064 * 1065 * \return 1066 * If \c name and \c behavior are valid, \c true is returned. Otherwise 1067 * \c false is returned. 1068 */ 1069 extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, 1070 const char *behavior, 1071 YYLTYPE *behavior_locp, 1072 _mesa_glsl_parse_state *state); 1073 1074 1075 /** 1076 * \brief Can \c from be implicitly converted to \c desired 1077 * 1078 * \return True if the types are identical or if \c from type can be converted 1079 * to \c desired according to Section 4.1.10 of the GLSL spec. 1080 * 1081 * \verbatim 1082 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10 1083 * Implicit Conversions: 1084 * 1085 * In some situations, an expression and its type will be implicitly 1086 * converted to a different type. The following table shows all allowed 1087 * implicit conversions: 1088 * 1089 * Type of expression | Can be implicitly converted to 1090 * -------------------------------------------------- 1091 * int float 1092 * uint 1093 * 1094 * ivec2 vec2 1095 * uvec2 1096 * 1097 * ivec3 vec3 1098 * uvec3 1099 * 1100 * ivec4 vec4 1101 * uvec4 1102 * 1103 * There are no implicit array or structure conversions. For example, 1104 * an array of int cannot be implicitly converted to an array of float. 1105 * There are no implicit conversions between signed and unsigned 1106 * integers. 1107 * \endverbatim 1108 */ 1109 extern bool _mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desired, 1110 bool has_implicit_conversions, 1111 bool has_implicit_int_to_uint_conversion); 1112 1113 #endif /* __cplusplus */ 1114 1115 1116 /* 1117 * These definitions apply to C and C++ 1118 */ 1119 #ifdef __cplusplus 1120 extern "C" { 1121 #endif 1122 1123 struct glcpp_parser; 1124 struct _mesa_glsl_parse_state; 1125 1126 typedef void (*glcpp_extension_iterator)( 1127 struct _mesa_glsl_parse_state *state, 1128 void (*add_builtin_define)(struct glcpp_parser *, const char *, int), 1129 struct glcpp_parser *data, 1130 unsigned version, 1131 bool es); 1132 1133 extern int glcpp_preprocess(void *ctx, const char **shader, char **info_log, 1134 glcpp_extension_iterator extensions, 1135 struct _mesa_glsl_parse_state *state, 1136 struct gl_context *gl_ctx); 1137 1138 extern void 1139 _mesa_glsl_copy_symbols_from_table(struct exec_list *shader_ir, 1140 struct glsl_symbol_table *src, 1141 struct glsl_symbol_table *dest); 1142 1143 #ifdef __cplusplus 1144 } 1145 #endif 1146 1147 1148 #endif /* GLSL_PARSER_EXTRAS_H */ 1149