1%{ 2/* 3 * Copyright © 2008, 2009 Intel Corporation 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24#include <stdio.h> 25#include <stdlib.h> 26#include <string.h> 27#ifndef _MSC_VER 28#include <strings.h> 29#endif 30#include <assert.h> 31 32#include "ast.h" 33#include "glsl_parser_extras.h" 34#include "compiler/glsl_types.h" 35#include "main/context.h" 36#include "util/u_string.h" 37#include "util/format/u_format.h" 38 39#ifdef _MSC_VER 40#pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels 41#endif 42 43#undef yyerror 44 45static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) 46{ 47 _mesa_glsl_error(loc, st, "%s", msg); 48} 49 50static int 51_mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state) 52{ 53 return _mesa_glsl_lexer_lex(val, loc, state->scanner); 54} 55 56static bool match_layout_qualifier(const char *s1, const char *s2, 57 _mesa_glsl_parse_state *state) 58{ 59 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers): 60 * 61 * "The tokens in any layout-qualifier-id-list ... are not case 62 * sensitive, unless explicitly noted otherwise." 63 * 64 * The text "unless explicitly noted otherwise" appears to be 65 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes 66 * otherwise. 67 * 68 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout 69 * Qualifiers): 70 * 71 * "As for other identifiers, they are case sensitive." 72 * 73 * So we need to do a case-sensitive or a case-insensitive match, 74 * depending on whether we are compiling for GLSL ES. 75 */ 76 if (state->es_shader) 77 return strcmp(s1, s2); 78 else 79 return strcasecmp(s1, s2); 80} 81%} 82 83%expect 0 84 85%pure-parser 86%error-verbose 87 88%locations 89%initial-action { 90 @$.first_line = 1; 91 @$.first_column = 1; 92 @$.last_line = 1; 93 @$.last_column = 1; 94 @$.source = 0; 95 @$.path = NULL; 96} 97 98%lex-param {struct _mesa_glsl_parse_state *state} 99%parse-param {struct _mesa_glsl_parse_state *state} 100 101%union { 102 int n; 103 int64_t n64; 104 float real; 105 double dreal; 106 const char *identifier; 107 108 struct ast_type_qualifier type_qualifier; 109 110 ast_node *node; 111 ast_type_specifier *type_specifier; 112 ast_array_specifier *array_specifier; 113 ast_fully_specified_type *fully_specified_type; 114 ast_function *function; 115 ast_parameter_declarator *parameter_declarator; 116 ast_function_definition *function_definition; 117 ast_compound_statement *compound_statement; 118 ast_expression *expression; 119 ast_declarator_list *declarator_list; 120 ast_struct_specifier *struct_specifier; 121 ast_declaration *declaration; 122 ast_switch_body *switch_body; 123 ast_case_label *case_label; 124 ast_case_label_list *case_label_list; 125 ast_case_statement *case_statement; 126 ast_case_statement_list *case_statement_list; 127 ast_interface_block *interface_block; 128 ast_subroutine_list *subroutine_list; 129 struct { 130 ast_node *cond; 131 ast_expression *rest; 132 } for_rest_statement; 133 134 struct { 135 ast_node *then_statement; 136 ast_node *else_statement; 137 } selection_rest_statement; 138 139 const glsl_type *type; 140} 141 142%token ATTRIBUTE CONST_TOK 143%token <type> BASIC_TYPE_TOK 144%token BREAK BUFFER CONTINUE DO ELSE FOR IF DEMOTE DISCARD RETURN SWITCH CASE DEFAULT 145%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE 146%token NOPERSPECTIVE FLAT SMOOTH 147%token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW 148%token COHERENT VOLATILE RESTRICT READONLY WRITEONLY 149%token SHARED 150%token STRUCT VOID_TOK WHILE 151%token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER 152%type <identifier> any_identifier 153%type <interface_block> instance_name_opt 154%token <real> FLOATCONSTANT 155%token <dreal> DOUBLECONSTANT 156%token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT 157%token <n64> INT64CONSTANT UINT64CONSTANT 158%token <identifier> FIELD_SELECTION 159%token LEFT_OP RIGHT_OP 160%token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP 161%token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN 162%token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN 163%token SUB_ASSIGN 164%token INVARIANT PRECISE 165%token LOWP MEDIUMP HIGHP SUPERP PRECISION 166 167%token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT 168%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF 169%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF 170%token PRAGMA_WARNING_ON PRAGMA_WARNING_OFF 171%token PRAGMA_INVARIANT_ALL 172%token LAYOUT_TOK 173%token DOT_TOK 174 /* Reserved words that are not actually used in the grammar. 175 */ 176%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO 177%token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL 178%token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK 179%token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4 180%token SAMPLER3DRECT 181%token SIZEOF CAST NAMESPACE USING 182%token RESOURCE PATCH 183%token SUBROUTINE 184 185%token ERROR_TOK 186 187%token COMMON PARTITION ACTIVE FILTER ROW_MAJOR 188 189%type <identifier> variable_identifier 190%type <node> statement 191%type <node> statement_list 192%type <node> simple_statement 193%type <n> precision_qualifier 194%type <type_qualifier> type_qualifier 195%type <type_qualifier> auxiliary_storage_qualifier 196%type <type_qualifier> storage_qualifier 197%type <type_qualifier> interpolation_qualifier 198%type <type_qualifier> layout_qualifier 199%type <type_qualifier> layout_qualifier_id_list layout_qualifier_id 200%type <type_qualifier> interface_block_layout_qualifier 201%type <type_qualifier> memory_qualifier 202%type <type_qualifier> subroutine_qualifier 203%type <subroutine_list> subroutine_type_list 204%type <type_qualifier> interface_qualifier 205%type <type_specifier> type_specifier 206%type <type_specifier> type_specifier_nonarray 207%type <array_specifier> array_specifier 208%type <type> basic_type_specifier_nonarray 209%type <fully_specified_type> fully_specified_type 210%type <function> function_prototype 211%type <function> function_header 212%type <function> function_header_with_parameters 213%type <function> function_declarator 214%type <parameter_declarator> parameter_declarator 215%type <parameter_declarator> parameter_declaration 216%type <type_qualifier> parameter_qualifier 217%type <type_qualifier> parameter_direction_qualifier 218%type <type_specifier> parameter_type_specifier 219%type <function_definition> function_definition 220%type <compound_statement> compound_statement_no_new_scope 221%type <compound_statement> compound_statement 222%type <node> statement_no_new_scope 223%type <node> expression_statement 224%type <expression> expression 225%type <expression> primary_expression 226%type <expression> assignment_expression 227%type <expression> conditional_expression 228%type <expression> logical_or_expression 229%type <expression> logical_xor_expression 230%type <expression> logical_and_expression 231%type <expression> inclusive_or_expression 232%type <expression> exclusive_or_expression 233%type <expression> and_expression 234%type <expression> equality_expression 235%type <expression> relational_expression 236%type <expression> shift_expression 237%type <expression> additive_expression 238%type <expression> multiplicative_expression 239%type <expression> unary_expression 240%type <expression> constant_expression 241%type <expression> integer_expression 242%type <expression> postfix_expression 243%type <expression> function_call_header_with_parameters 244%type <expression> function_call_header_no_parameters 245%type <expression> function_call_header 246%type <expression> function_call_generic 247%type <expression> function_call_or_method 248%type <expression> function_call 249%type <n> assignment_operator 250%type <n> unary_operator 251%type <expression> function_identifier 252%type <node> external_declaration 253%type <node> pragma_statement 254%type <declarator_list> init_declarator_list 255%type <declarator_list> single_declaration 256%type <expression> initializer 257%type <expression> initializer_list 258%type <node> declaration 259%type <node> declaration_statement 260%type <node> jump_statement 261%type <node> demote_statement 262%type <node> interface_block 263%type <interface_block> basic_interface_block 264%type <struct_specifier> struct_specifier 265%type <declarator_list> struct_declaration_list 266%type <declarator_list> struct_declaration 267%type <declaration> struct_declarator 268%type <declaration> struct_declarator_list 269%type <declarator_list> member_list 270%type <declarator_list> member_declaration 271%type <node> selection_statement 272%type <selection_rest_statement> selection_rest_statement 273%type <node> switch_statement 274%type <switch_body> switch_body 275%type <case_label_list> case_label_list 276%type <case_label> case_label 277%type <case_statement> case_statement 278%type <case_statement_list> case_statement_list 279%type <node> iteration_statement 280%type <node> condition 281%type <node> conditionopt 282%type <node> for_init_statement 283%type <for_rest_statement> for_rest_statement 284%type <node> layout_defaults 285%type <type_qualifier> layout_uniform_defaults 286%type <type_qualifier> layout_buffer_defaults 287%type <type_qualifier> layout_in_defaults 288%type <type_qualifier> layout_out_defaults 289 290%right THEN ELSE 291%% 292 293translation_unit: 294 version_statement extension_statement_list 295 { 296 _mesa_glsl_initialize_types(state); 297 } 298 external_declaration_list 299 { 300 delete state->symbols; 301 state->symbols = new(ralloc_parent(state)) glsl_symbol_table; 302 if (state->es_shader) { 303 if (state->stage == MESA_SHADER_FRAGMENT) { 304 state->symbols->add_default_precision_qualifier("int", ast_precision_medium); 305 } else { 306 state->symbols->add_default_precision_qualifier("float", ast_precision_high); 307 state->symbols->add_default_precision_qualifier("int", ast_precision_high); 308 } 309 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low); 310 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low); 311 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low); 312 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high); 313 } 314 _mesa_glsl_initialize_types(state); 315 } 316 ; 317 318version_statement: 319 /* blank - no #version specified: defaults are already set */ 320 | VERSION_TOK INTCONSTANT EOL 321 { 322 state->process_version_directive(&@2, $2, NULL); 323 if (state->error) { 324 YYERROR; 325 } 326 } 327 | VERSION_TOK INTCONSTANT any_identifier EOL 328 { 329 state->process_version_directive(&@2, $2, $3); 330 if (state->error) { 331 YYERROR; 332 } 333 } 334 ; 335 336pragma_statement: 337 PRAGMA_DEBUG_ON EOL { $$ = NULL; } 338 | PRAGMA_DEBUG_OFF EOL { $$ = NULL; } 339 | PRAGMA_OPTIMIZE_ON EOL { $$ = NULL; } 340 | PRAGMA_OPTIMIZE_OFF EOL { $$ = NULL; } 341 | PRAGMA_INVARIANT_ALL EOL 342 { 343 /* Pragma invariant(all) cannot be used in a fragment shader. 344 * 345 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec: 346 * 347 * "It is an error to use this pragma in a fragment shader." 348 */ 349 if (state->is_version(120, 300) && 350 state->stage == MESA_SHADER_FRAGMENT) { 351 _mesa_glsl_error(& @1, state, 352 "pragma `invariant(all)' cannot be used " 353 "in a fragment shader."); 354 } else if (!state->is_version(120, 100)) { 355 _mesa_glsl_warning(& @1, state, 356 "pragma `invariant(all)' not supported in %s " 357 "(GLSL ES 1.00 or GLSL 1.20 required)", 358 state->get_version_string()); 359 } else { 360 state->all_invariant = true; 361 } 362 363 $$ = NULL; 364 } 365 | PRAGMA_WARNING_ON EOL 366 { 367 void *mem_ctx = state->linalloc; 368 $$ = new(mem_ctx) ast_warnings_toggle(true); 369 } 370 | PRAGMA_WARNING_OFF EOL 371 { 372 void *mem_ctx = state->linalloc; 373 $$ = new(mem_ctx) ast_warnings_toggle(false); 374 } 375 ; 376 377extension_statement_list: 378 379 | extension_statement_list extension_statement 380 ; 381 382any_identifier: 383 IDENTIFIER 384 | TYPE_IDENTIFIER 385 | NEW_IDENTIFIER 386 ; 387 388extension_statement: 389 EXTENSION any_identifier COLON any_identifier EOL 390 { 391 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) { 392 YYERROR; 393 } 394 } 395 ; 396 397external_declaration_list: 398 external_declaration 399 { 400 /* FINISHME: The NULL test is required because pragmas are set to 401 * FINISHME: NULL. (See production rule for external_declaration.) 402 */ 403 if ($1 != NULL) 404 state->translation_unit.push_tail(& $1->link); 405 } 406 | external_declaration_list external_declaration 407 { 408 /* FINISHME: The NULL test is required because pragmas are set to 409 * FINISHME: NULL. (See production rule for external_declaration.) 410 */ 411 if ($2 != NULL) 412 state->translation_unit.push_tail(& $2->link); 413 } 414 | external_declaration_list extension_statement { 415 if (!state->allow_extension_directive_midshader) { 416 _mesa_glsl_error(& @2, state, 417 "#extension directive is not allowed " 418 "in the middle of a shader"); 419 YYERROR; 420 } 421 } 422 ; 423 424variable_identifier: 425 IDENTIFIER 426 | NEW_IDENTIFIER 427 ; 428 429primary_expression: 430 variable_identifier 431 { 432 void *ctx = state->linalloc; 433 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL); 434 $$->set_location(@1); 435 $$->primary_expression.identifier = $1; 436 } 437 | INTCONSTANT 438 { 439 void *ctx = state->linalloc; 440 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL); 441 $$->set_location(@1); 442 $$->primary_expression.int_constant = $1; 443 } 444 | UINTCONSTANT 445 { 446 void *ctx = state->linalloc; 447 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL); 448 $$->set_location(@1); 449 $$->primary_expression.uint_constant = $1; 450 } 451 | INT64CONSTANT 452 { 453 void *ctx = state->linalloc; 454 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL); 455 $$->set_location(@1); 456 $$->primary_expression.int64_constant = $1; 457 } 458 | UINT64CONSTANT 459 { 460 void *ctx = state->linalloc; 461 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL); 462 $$->set_location(@1); 463 $$->primary_expression.uint64_constant = $1; 464 } 465 | FLOATCONSTANT 466 { 467 void *ctx = state->linalloc; 468 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL); 469 $$->set_location(@1); 470 $$->primary_expression.float_constant = $1; 471 } 472 | DOUBLECONSTANT 473 { 474 void *ctx = state->linalloc; 475 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL); 476 $$->set_location(@1); 477 $$->primary_expression.double_constant = $1; 478 } 479 | BOOLCONSTANT 480 { 481 void *ctx = state->linalloc; 482 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL); 483 $$->set_location(@1); 484 $$->primary_expression.bool_constant = $1; 485 } 486 | '(' expression ')' 487 { 488 $$ = $2; 489 } 490 ; 491 492postfix_expression: 493 primary_expression 494 | postfix_expression '[' integer_expression ']' 495 { 496 void *ctx = state->linalloc; 497 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL); 498 $$->set_location_range(@1, @4); 499 } 500 | function_call 501 { 502 $$ = $1; 503 } 504 | postfix_expression DOT_TOK FIELD_SELECTION 505 { 506 void *ctx = state->linalloc; 507 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL); 508 $$->set_location_range(@1, @3); 509 $$->primary_expression.identifier = $3; 510 } 511 | postfix_expression INC_OP 512 { 513 void *ctx = state->linalloc; 514 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL); 515 $$->set_location_range(@1, @2); 516 } 517 | postfix_expression DEC_OP 518 { 519 void *ctx = state->linalloc; 520 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL); 521 $$->set_location_range(@1, @2); 522 } 523 ; 524 525integer_expression: 526 expression 527 ; 528 529function_call: 530 function_call_or_method 531 ; 532 533function_call_or_method: 534 function_call_generic 535 ; 536 537function_call_generic: 538 function_call_header_with_parameters ')' 539 | function_call_header_no_parameters ')' 540 ; 541 542function_call_header_no_parameters: 543 function_call_header VOID_TOK 544 | function_call_header 545 ; 546 547function_call_header_with_parameters: 548 function_call_header assignment_expression 549 { 550 $$ = $1; 551 $$->set_location(@1); 552 $$->expressions.push_tail(& $2->link); 553 } 554 | function_call_header_with_parameters ',' assignment_expression 555 { 556 $$ = $1; 557 $$->set_location(@1); 558 $$->expressions.push_tail(& $3->link); 559 } 560 ; 561 562 // Grammar Note: Constructors look like functions, but lexical 563 // analysis recognized most of them as keywords. They are now 564 // recognized through "type_specifier". 565function_call_header: 566 function_identifier '(' 567 ; 568 569function_identifier: 570 type_specifier 571 { 572 void *ctx = state->linalloc; 573 $$ = new(ctx) ast_function_expression($1); 574 $$->set_location(@1); 575 } 576 | postfix_expression 577 { 578 void *ctx = state->linalloc; 579 $$ = new(ctx) ast_function_expression($1); 580 $$->set_location(@1); 581 } 582 ; 583 584 // Grammar Note: Constructors look like methods, but lexical 585 // analysis recognized most of them as keywords. They are now 586 // recognized through "type_specifier". 587 588 // Grammar Note: No traditional style type casts. 589unary_expression: 590 postfix_expression 591 | INC_OP unary_expression 592 { 593 void *ctx = state->linalloc; 594 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL); 595 $$->set_location(@1); 596 } 597 | DEC_OP unary_expression 598 { 599 void *ctx = state->linalloc; 600 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL); 601 $$->set_location(@1); 602 } 603 | unary_operator unary_expression 604 { 605 void *ctx = state->linalloc; 606 $$ = new(ctx) ast_expression($1, $2, NULL, NULL); 607 $$->set_location_range(@1, @2); 608 } 609 ; 610 611 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported. 612unary_operator: 613 '+' { $$ = ast_plus; } 614 | '-' { $$ = ast_neg; } 615 | '!' { $$ = ast_logic_not; } 616 | '~' { $$ = ast_bit_not; } 617 ; 618 619multiplicative_expression: 620 unary_expression 621 | multiplicative_expression '*' unary_expression 622 { 623 void *ctx = state->linalloc; 624 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3); 625 $$->set_location_range(@1, @3); 626 } 627 | multiplicative_expression '/' unary_expression 628 { 629 void *ctx = state->linalloc; 630 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3); 631 $$->set_location_range(@1, @3); 632 } 633 | multiplicative_expression '%' unary_expression 634 { 635 void *ctx = state->linalloc; 636 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3); 637 $$->set_location_range(@1, @3); 638 } 639 ; 640 641additive_expression: 642 multiplicative_expression 643 | additive_expression '+' multiplicative_expression 644 { 645 void *ctx = state->linalloc; 646 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3); 647 $$->set_location_range(@1, @3); 648 } 649 | additive_expression '-' multiplicative_expression 650 { 651 void *ctx = state->linalloc; 652 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3); 653 $$->set_location_range(@1, @3); 654 } 655 ; 656 657shift_expression: 658 additive_expression 659 | shift_expression LEFT_OP additive_expression 660 { 661 void *ctx = state->linalloc; 662 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3); 663 $$->set_location_range(@1, @3); 664 } 665 | shift_expression RIGHT_OP additive_expression 666 { 667 void *ctx = state->linalloc; 668 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3); 669 $$->set_location_range(@1, @3); 670 } 671 ; 672 673relational_expression: 674 shift_expression 675 | relational_expression '<' shift_expression 676 { 677 void *ctx = state->linalloc; 678 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3); 679 $$->set_location_range(@1, @3); 680 } 681 | relational_expression '>' shift_expression 682 { 683 void *ctx = state->linalloc; 684 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3); 685 $$->set_location_range(@1, @3); 686 } 687 | relational_expression LE_OP shift_expression 688 { 689 void *ctx = state->linalloc; 690 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3); 691 $$->set_location_range(@1, @3); 692 } 693 | relational_expression GE_OP shift_expression 694 { 695 void *ctx = state->linalloc; 696 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3); 697 $$->set_location_range(@1, @3); 698 } 699 ; 700 701equality_expression: 702 relational_expression 703 | equality_expression EQ_OP relational_expression 704 { 705 void *ctx = state->linalloc; 706 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3); 707 $$->set_location_range(@1, @3); 708 } 709 | equality_expression NE_OP relational_expression 710 { 711 void *ctx = state->linalloc; 712 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3); 713 $$->set_location_range(@1, @3); 714 } 715 ; 716 717and_expression: 718 equality_expression 719 | and_expression '&' equality_expression 720 { 721 void *ctx = state->linalloc; 722 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3); 723 $$->set_location_range(@1, @3); 724 } 725 ; 726 727exclusive_or_expression: 728 and_expression 729 | exclusive_or_expression '^' and_expression 730 { 731 void *ctx = state->linalloc; 732 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3); 733 $$->set_location_range(@1, @3); 734 } 735 ; 736 737inclusive_or_expression: 738 exclusive_or_expression 739 | inclusive_or_expression '|' exclusive_or_expression 740 { 741 void *ctx = state->linalloc; 742 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3); 743 $$->set_location_range(@1, @3); 744 } 745 ; 746 747logical_and_expression: 748 inclusive_or_expression 749 | logical_and_expression AND_OP inclusive_or_expression 750 { 751 void *ctx = state->linalloc; 752 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3); 753 $$->set_location_range(@1, @3); 754 } 755 ; 756 757logical_xor_expression: 758 logical_and_expression 759 | logical_xor_expression XOR_OP logical_and_expression 760 { 761 void *ctx = state->linalloc; 762 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3); 763 $$->set_location_range(@1, @3); 764 } 765 ; 766 767logical_or_expression: 768 logical_xor_expression 769 | logical_or_expression OR_OP logical_xor_expression 770 { 771 void *ctx = state->linalloc; 772 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3); 773 $$->set_location_range(@1, @3); 774 } 775 ; 776 777conditional_expression: 778 logical_or_expression 779 | logical_or_expression '?' expression ':' assignment_expression 780 { 781 void *ctx = state->linalloc; 782 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5); 783 $$->set_location_range(@1, @5); 784 } 785 ; 786 787assignment_expression: 788 conditional_expression 789 | unary_expression assignment_operator assignment_expression 790 { 791 void *ctx = state->linalloc; 792 $$ = new(ctx) ast_expression($2, $1, $3, NULL); 793 $$->set_location_range(@1, @3); 794 } 795 ; 796 797assignment_operator: 798 '=' { $$ = ast_assign; } 799 | MUL_ASSIGN { $$ = ast_mul_assign; } 800 | DIV_ASSIGN { $$ = ast_div_assign; } 801 | MOD_ASSIGN { $$ = ast_mod_assign; } 802 | ADD_ASSIGN { $$ = ast_add_assign; } 803 | SUB_ASSIGN { $$ = ast_sub_assign; } 804 | LEFT_ASSIGN { $$ = ast_ls_assign; } 805 | RIGHT_ASSIGN { $$ = ast_rs_assign; } 806 | AND_ASSIGN { $$ = ast_and_assign; } 807 | XOR_ASSIGN { $$ = ast_xor_assign; } 808 | OR_ASSIGN { $$ = ast_or_assign; } 809 ; 810 811expression: 812 assignment_expression 813 { 814 $$ = $1; 815 } 816 | expression ',' assignment_expression 817 { 818 void *ctx = state->linalloc; 819 if ($1->oper != ast_sequence) { 820 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL); 821 $$->set_location_range(@1, @3); 822 $$->expressions.push_tail(& $1->link); 823 } else { 824 $$ = $1; 825 } 826 827 $$->expressions.push_tail(& $3->link); 828 } 829 ; 830 831constant_expression: 832 conditional_expression 833 ; 834 835declaration: 836 function_prototype ';' 837 { 838 state->symbols->pop_scope(); 839 $$ = $1; 840 } 841 | init_declarator_list ';' 842 { 843 $$ = $1; 844 } 845 | PRECISION precision_qualifier type_specifier ';' 846 { 847 $3->default_precision = $2; 848 $$ = $3; 849 } 850 | interface_block 851 { 852 ast_interface_block *block = (ast_interface_block *) $1; 853 if (block->layout.has_layout() || block->layout.has_memory()) { 854 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) { 855 YYERROR; 856 } 857 } 858 block->layout = block->default_layout; 859 if (!block->layout.push_to_global(& @1, state)) { 860 YYERROR; 861 } 862 $$ = $1; 863 } 864 ; 865 866function_prototype: 867 function_declarator ')' 868 ; 869 870function_declarator: 871 function_header 872 | function_header_with_parameters 873 ; 874 875function_header_with_parameters: 876 function_header parameter_declaration 877 { 878 $$ = $1; 879 $$->parameters.push_tail(& $2->link); 880 } 881 | function_header_with_parameters ',' parameter_declaration 882 { 883 $$ = $1; 884 $$->parameters.push_tail(& $3->link); 885 } 886 ; 887 888function_header: 889 fully_specified_type variable_identifier '(' 890 { 891 void *ctx = state->linalloc; 892 $$ = new(ctx) ast_function(); 893 $$->set_location(@2); 894 $$->return_type = $1; 895 $$->identifier = $2; 896 897 if ($1->qualifier.is_subroutine_decl()) { 898 /* add type for IDENTIFIER search */ 899 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2)); 900 } else 901 state->symbols->add_function(new(state) ir_function($2)); 902 state->symbols->push_scope(); 903 } 904 ; 905 906parameter_declarator: 907 type_specifier any_identifier 908 { 909 void *ctx = state->linalloc; 910 $$ = new(ctx) ast_parameter_declarator(); 911 $$->set_location_range(@1, @2); 912 $$->type = new(ctx) ast_fully_specified_type(); 913 $$->type->set_location(@1); 914 $$->type->specifier = $1; 915 $$->identifier = $2; 916 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto)); 917 } 918 | layout_qualifier type_specifier any_identifier 919 { 920 _mesa_glsl_error(&@1, state, "is is not allowed on function parameter"); 921 YYERROR; 922 } 923 | type_specifier any_identifier array_specifier 924 { 925 void *ctx = state->linalloc; 926 $$ = new(ctx) ast_parameter_declarator(); 927 $$->set_location_range(@1, @3); 928 $$->type = new(ctx) ast_fully_specified_type(); 929 $$->type->set_location(@1); 930 $$->type->specifier = $1; 931 $$->identifier = $2; 932 $$->array_specifier = $3; 933 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto)); 934 } 935 ; 936 937parameter_declaration: 938 parameter_qualifier parameter_declarator 939 { 940 $$ = $2; 941 $$->type->qualifier = $1; 942 if (!$$->type->qualifier.push_to_global(& @1, state)) { 943 YYERROR; 944 } 945 } 946 | parameter_qualifier parameter_type_specifier 947 { 948 void *ctx = state->linalloc; 949 $$ = new(ctx) ast_parameter_declarator(); 950 $$->set_location(@2); 951 $$->type = new(ctx) ast_fully_specified_type(); 952 $$->type->set_location_range(@1, @2); 953 $$->type->qualifier = $1; 954 if (!$$->type->qualifier.push_to_global(& @1, state)) { 955 YYERROR; 956 } 957 $$->type->specifier = $2; 958 } 959 ; 960 961parameter_qualifier: 962 /* empty */ 963 { 964 memset(& $$, 0, sizeof($$)); 965 } 966 | CONST_TOK parameter_qualifier 967 { 968 if ($2.flags.q.constant) 969 _mesa_glsl_error(&@1, state, "duplicate const qualifier"); 970 971 $$ = $2; 972 $$.flags.q.constant = 1; 973 } 974 | PRECISE parameter_qualifier 975 { 976 if ($2.flags.q.precise) 977 _mesa_glsl_error(&@1, state, "duplicate precise qualifier"); 978 979 $$ = $2; 980 $$.flags.q.precise = 1; 981 } 982 | parameter_direction_qualifier parameter_qualifier 983 { 984 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out)) 985 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier"); 986 987 if (!state->has_420pack_or_es31() && $2.flags.q.constant) 988 _mesa_glsl_error(&@1, state, "in/out/inout must come after const " 989 "or precise"); 990 991 $$ = $1; 992 $$.merge_qualifier(&@1, state, $2, false); 993 } 994 | precision_qualifier parameter_qualifier 995 { 996 if ($2.precision != ast_precision_none) 997 _mesa_glsl_error(&@1, state, "duplicate precision qualifier"); 998 999 if (!state->has_420pack_or_es31() && 1000 $2.flags.i != 0) 1001 _mesa_glsl_error(&@1, state, "precision qualifiers must come last"); 1002 1003 $$ = $2; 1004 $$.precision = $1; 1005 } 1006 | memory_qualifier parameter_qualifier 1007 { 1008 $$ = $1; 1009 $$.merge_qualifier(&@1, state, $2, false); 1010 } 1011 1012parameter_direction_qualifier: 1013 IN_TOK 1014 { 1015 memset(& $$, 0, sizeof($$)); 1016 $$.flags.q.in = 1; 1017 } 1018 | OUT_TOK 1019 { 1020 memset(& $$, 0, sizeof($$)); 1021 $$.flags.q.out = 1; 1022 } 1023 | INOUT_TOK 1024 { 1025 memset(& $$, 0, sizeof($$)); 1026 $$.flags.q.in = 1; 1027 $$.flags.q.out = 1; 1028 } 1029 ; 1030 1031parameter_type_specifier: 1032 type_specifier 1033 ; 1034 1035init_declarator_list: 1036 single_declaration 1037 | init_declarator_list ',' any_identifier 1038 { 1039 void *ctx = state->linalloc; 1040 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL); 1041 decl->set_location(@3); 1042 1043 $$ = $1; 1044 $$->declarations.push_tail(&decl->link); 1045 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); 1046 } 1047 | init_declarator_list ',' any_identifier array_specifier 1048 { 1049 void *ctx = state->linalloc; 1050 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL); 1051 decl->set_location_range(@3, @4); 1052 1053 $$ = $1; 1054 $$->declarations.push_tail(&decl->link); 1055 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); 1056 } 1057 | init_declarator_list ',' any_identifier array_specifier '=' initializer 1058 { 1059 void *ctx = state->linalloc; 1060 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6); 1061 decl->set_location_range(@3, @4); 1062 1063 $$ = $1; 1064 $$->declarations.push_tail(&decl->link); 1065 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); 1066 } 1067 | init_declarator_list ',' any_identifier '=' initializer 1068 { 1069 void *ctx = state->linalloc; 1070 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5); 1071 decl->set_location(@3); 1072 1073 $$ = $1; 1074 $$->declarations.push_tail(&decl->link); 1075 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); 1076 } 1077 ; 1078 1079 // Grammar Note: No 'enum', or 'typedef'. 1080single_declaration: 1081 fully_specified_type 1082 { 1083 void *ctx = state->linalloc; 1084 /* Empty declaration list is valid. */ 1085 $$ = new(ctx) ast_declarator_list($1); 1086 $$->set_location(@1); 1087 } 1088 | fully_specified_type any_identifier 1089 { 1090 void *ctx = state->linalloc; 1091 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL); 1092 decl->set_location(@2); 1093 1094 $$ = new(ctx) ast_declarator_list($1); 1095 $$->set_location_range(@1, @2); 1096 $$->declarations.push_tail(&decl->link); 1097 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto)); 1098 } 1099 | fully_specified_type any_identifier array_specifier 1100 { 1101 void *ctx = state->linalloc; 1102 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL); 1103 decl->set_location_range(@2, @3); 1104 1105 $$ = new(ctx) ast_declarator_list($1); 1106 $$->set_location_range(@1, @3); 1107 $$->declarations.push_tail(&decl->link); 1108 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto)); 1109 } 1110 | fully_specified_type any_identifier array_specifier '=' initializer 1111 { 1112 void *ctx = state->linalloc; 1113 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5); 1114 decl->set_location_range(@2, @3); 1115 1116 $$ = new(ctx) ast_declarator_list($1); 1117 $$->set_location_range(@1, @3); 1118 $$->declarations.push_tail(&decl->link); 1119 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto)); 1120 } 1121 | fully_specified_type any_identifier '=' initializer 1122 { 1123 void *ctx = state->linalloc; 1124 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4); 1125 decl->set_location(@2); 1126 1127 $$ = new(ctx) ast_declarator_list($1); 1128 $$->set_location_range(@1, @2); 1129 $$->declarations.push_tail(&decl->link); 1130 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto)); 1131 } 1132 | INVARIANT variable_identifier 1133 { 1134 void *ctx = state->linalloc; 1135 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL); 1136 decl->set_location(@2); 1137 1138 $$ = new(ctx) ast_declarator_list(NULL); 1139 $$->set_location_range(@1, @2); 1140 $$->invariant = true; 1141 1142 $$->declarations.push_tail(&decl->link); 1143 } 1144 | PRECISE variable_identifier 1145 { 1146 void *ctx = state->linalloc; 1147 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL); 1148 decl->set_location(@2); 1149 1150 $$ = new(ctx) ast_declarator_list(NULL); 1151 $$->set_location_range(@1, @2); 1152 $$->precise = true; 1153 1154 $$->declarations.push_tail(&decl->link); 1155 } 1156 ; 1157 1158fully_specified_type: 1159 type_specifier 1160 { 1161 void *ctx = state->linalloc; 1162 $$ = new(ctx) ast_fully_specified_type(); 1163 $$->set_location(@1); 1164 $$->specifier = $1; 1165 } 1166 | type_qualifier type_specifier 1167 { 1168 void *ctx = state->linalloc; 1169 $$ = new(ctx) ast_fully_specified_type(); 1170 $$->set_location_range(@1, @2); 1171 $$->qualifier = $1; 1172 if (!$$->qualifier.push_to_global(& @1, state)) { 1173 YYERROR; 1174 } 1175 $$->specifier = $2; 1176 if ($$->specifier->structure != NULL && 1177 $$->specifier->structure->is_declaration) { 1178 $$->specifier->structure->layout = &$$->qualifier; 1179 } 1180 } 1181 ; 1182 1183layout_qualifier: 1184 LAYOUT_TOK '(' layout_qualifier_id_list ')' 1185 { 1186 $$ = $3; 1187 } 1188 ; 1189 1190layout_qualifier_id_list: 1191 layout_qualifier_id 1192 | layout_qualifier_id_list ',' layout_qualifier_id 1193 { 1194 $$ = $1; 1195 if (!$$.merge_qualifier(& @3, state, $3, true)) { 1196 YYERROR; 1197 } 1198 } 1199 ; 1200 1201layout_qualifier_id: 1202 any_identifier 1203 { 1204 memset(& $$, 0, sizeof($$)); 1205 1206 /* Layout qualifiers for ARB_fragment_coord_conventions. */ 1207 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable || 1208 state->is_version(150, 0))) { 1209 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) { 1210 $$.flags.q.origin_upper_left = 1; 1211 } else if (match_layout_qualifier($1, "pixel_center_integer", 1212 state) == 0) { 1213 $$.flags.q.pixel_center_integer = 1; 1214 } 1215 1216 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) { 1217 _mesa_glsl_warning(& @1, state, 1218 "GL_ARB_fragment_coord_conventions layout " 1219 "identifier `%s' used", $1); 1220 } 1221 } 1222 1223 /* Layout qualifiers for AMD/ARB_conservative_depth. */ 1224 if (!$$.flags.i && 1225 (state->AMD_conservative_depth_enable || 1226 state->ARB_conservative_depth_enable || 1227 state->is_version(420, 0))) { 1228 if (match_layout_qualifier($1, "depth_any", state) == 0) { 1229 $$.flags.q.depth_type = 1; 1230 $$.depth_type = ast_depth_any; 1231 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) { 1232 $$.flags.q.depth_type = 1; 1233 $$.depth_type = ast_depth_greater; 1234 } else if (match_layout_qualifier($1, "depth_less", state) == 0) { 1235 $$.flags.q.depth_type = 1; 1236 $$.depth_type = ast_depth_less; 1237 } else if (match_layout_qualifier($1, "depth_unchanged", 1238 state) == 0) { 1239 $$.flags.q.depth_type = 1; 1240 $$.depth_type = ast_depth_unchanged; 1241 } 1242 1243 if ($$.flags.i && state->AMD_conservative_depth_warn) { 1244 _mesa_glsl_warning(& @1, state, 1245 "GL_AMD_conservative_depth " 1246 "layout qualifier `%s' is used", $1); 1247 } 1248 if ($$.flags.i && state->ARB_conservative_depth_warn) { 1249 _mesa_glsl_warning(& @1, state, 1250 "GL_ARB_conservative_depth " 1251 "layout qualifier `%s' is used", $1); 1252 } 1253 } 1254 1255 /* See also interface_block_layout_qualifier. */ 1256 if (!$$.flags.i && state->has_uniform_buffer_objects()) { 1257 if (match_layout_qualifier($1, "std140", state) == 0) { 1258 $$.flags.q.std140 = 1; 1259 } else if (match_layout_qualifier($1, "shared", state) == 0) { 1260 $$.flags.q.shared = 1; 1261 } else if (match_layout_qualifier($1, "std430", state) == 0) { 1262 $$.flags.q.std430 = 1; 1263 } else if (match_layout_qualifier($1, "column_major", state) == 0) { 1264 $$.flags.q.column_major = 1; 1265 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed 1266 * below in the interface_block_layout_qualifier rule. 1267 * 1268 * It is not a reserved word in GLSL ES 3.00, so it's handled here as 1269 * an identifier. 1270 * 1271 * Also, this takes care of alternate capitalizations of 1272 * "row_major" (which is necessary because layout qualifiers 1273 * are case-insensitive in desktop GLSL). 1274 */ 1275 } else if (match_layout_qualifier($1, "row_major", state) == 0) { 1276 $$.flags.q.row_major = 1; 1277 /* "packed" is a reserved word in GLSL, and its token is 1278 * parsed below in the interface_block_layout_qualifier rule. 1279 * However, we must take care of alternate capitalizations of 1280 * "packed", because layout qualifiers are case-insensitive 1281 * in desktop GLSL. 1282 */ 1283 } else if (match_layout_qualifier($1, "packed", state) == 0) { 1284 $$.flags.q.packed = 1; 1285 } 1286 1287 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) { 1288 _mesa_glsl_warning(& @1, state, 1289 "#version 140 / GL_ARB_uniform_buffer_object " 1290 "layout qualifier `%s' is used", $1); 1291 } 1292 } 1293 1294 /* Layout qualifiers for GLSL 1.50 geometry shaders. */ 1295 if (!$$.flags.i) { 1296 static const struct { 1297 const char *s; 1298 GLenum e; 1299 } map[] = { 1300 { "points", GL_POINTS }, 1301 { "lines", GL_LINES }, 1302 { "lines_adjacency", GL_LINES_ADJACENCY }, 1303 { "line_strip", GL_LINE_STRIP }, 1304 { "triangles", GL_TRIANGLES }, 1305 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY }, 1306 { "triangle_strip", GL_TRIANGLE_STRIP }, 1307 }; 1308 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) { 1309 if (match_layout_qualifier($1, map[i].s, state) == 0) { 1310 $$.flags.q.prim_type = 1; 1311 $$.prim_type = map[i].e; 1312 break; 1313 } 1314 } 1315 1316 if ($$.flags.i && !state->has_geometry_shader() && 1317 !state->has_tessellation_shader()) { 1318 _mesa_glsl_error(& @1, state, "#version 150 layout " 1319 "qualifier `%s' used", $1); 1320 } 1321 } 1322 1323 /* Layout qualifiers for ARB_shader_image_load_store. */ 1324 if (state->has_shader_image_load_store()) { 1325 if (!$$.flags.i) { 1326 static const struct { 1327 const char *name; 1328 enum pipe_format format; 1329 glsl_base_type base_type; 1330 /** Minimum desktop GLSL version required for the image 1331 * format. Use 130 if already present in the original 1332 * ARB extension. 1333 */ 1334 unsigned required_glsl; 1335 /** Minimum GLSL ES version required for the image format. */ 1336 unsigned required_essl; 1337 /* NV_image_formats */ 1338 bool nv_image_formats; 1339 bool ext_qualifiers; 1340 } map[] = { 1341 { "rgba32f", PIPE_FORMAT_R32G32B32A32_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false }, 1342 { "rgba16f", PIPE_FORMAT_R16G16B16A16_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false }, 1343 { "rg32f", PIPE_FORMAT_R32G32_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1344 { "rg16f", PIPE_FORMAT_R16G16_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1345 { "r11f_g11f_b10f", PIPE_FORMAT_R11G11B10_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1346 { "r32f", PIPE_FORMAT_R32_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false }, 1347 { "r16f", PIPE_FORMAT_R16_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1348 { "rgba32ui", PIPE_FORMAT_R32G32B32A32_UINT, GLSL_TYPE_UINT, 130, 310, false, false }, 1349 { "rgba16ui", PIPE_FORMAT_R16G16B16A16_UINT, GLSL_TYPE_UINT, 130, 310, false, false }, 1350 { "rgb10_a2ui", PIPE_FORMAT_R10G10B10A2_UINT, GLSL_TYPE_UINT, 130, 0, true, false }, 1351 { "rgba8ui", PIPE_FORMAT_R8G8B8A8_UINT, GLSL_TYPE_UINT, 130, 310, false, false }, 1352 { "rg32ui", PIPE_FORMAT_R32G32_UINT, GLSL_TYPE_UINT, 130, 0, true, false }, 1353 { "rg16ui", PIPE_FORMAT_R16G16_UINT, GLSL_TYPE_UINT, 130, 0, true, false }, 1354 { "rg8ui", PIPE_FORMAT_R8G8_UINT, GLSL_TYPE_UINT, 130, 0, true, false }, 1355 { "r32ui", PIPE_FORMAT_R32_UINT, GLSL_TYPE_UINT, 130, 310, false, false }, 1356 { "r16ui", PIPE_FORMAT_R16_UINT, GLSL_TYPE_UINT, 130, 0, true, false }, 1357 { "r8ui", PIPE_FORMAT_R8_UINT, GLSL_TYPE_UINT, 130, 0, true, false }, 1358 { "rgba32i", PIPE_FORMAT_R32G32B32A32_SINT, GLSL_TYPE_INT, 130, 310, false, false }, 1359 { "rgba16i", PIPE_FORMAT_R16G16B16A16_SINT, GLSL_TYPE_INT, 130, 310, false, false }, 1360 { "rgba8i", PIPE_FORMAT_R8G8B8A8_SINT, GLSL_TYPE_INT, 130, 310, false, false }, 1361 { "rg32i", PIPE_FORMAT_R32G32_SINT, GLSL_TYPE_INT, 130, 0, true, false }, 1362 { "rg16i", PIPE_FORMAT_R16G16_SINT, GLSL_TYPE_INT, 130, 0, true, false }, 1363 { "rg8i", PIPE_FORMAT_R8G8_SINT, GLSL_TYPE_INT, 130, 0, true, false }, 1364 { "r32i", PIPE_FORMAT_R32_SINT, GLSL_TYPE_INT, 130, 310, false, false }, 1365 { "r16i", PIPE_FORMAT_R16_SINT, GLSL_TYPE_INT, 130, 0, true, false }, 1366 { "r8i", PIPE_FORMAT_R8_SINT, GLSL_TYPE_INT, 130, 0, true, false }, 1367 { "rgba16", PIPE_FORMAT_R16G16B16A16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1368 { "rgb10_a2", PIPE_FORMAT_R10G10B10A2_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1369 { "rgba8", PIPE_FORMAT_R8G8B8A8_UNORM, GLSL_TYPE_FLOAT, 130, 310, false, false }, 1370 { "rg16", PIPE_FORMAT_R16G16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1371 { "rg8", PIPE_FORMAT_R8G8_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1372 { "r16", PIPE_FORMAT_R16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1373 { "r8", PIPE_FORMAT_R8_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1374 { "rgba16_snorm", PIPE_FORMAT_R16G16B16A16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1375 { "rgba8_snorm", PIPE_FORMAT_R8G8B8A8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false, false }, 1376 { "rg16_snorm", PIPE_FORMAT_R16G16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1377 { "rg8_snorm", PIPE_FORMAT_R8G8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1378 { "r16_snorm", PIPE_FORMAT_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1379 { "r8_snorm", PIPE_FORMAT_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false }, 1380 1381 /* From GL_EXT_shader_image_load_store: */ 1382 /* base_type is incorrect but it'll be patched later when we know 1383 * the variable type. See ast_to_hir.cpp */ 1384 { "size1x8", PIPE_FORMAT_R8_SINT, GLSL_TYPE_VOID, 130, 0, false, true }, 1385 { "size1x16", PIPE_FORMAT_R16_SINT, GLSL_TYPE_VOID, 130, 0, false, true }, 1386 { "size1x32", PIPE_FORMAT_R32_SINT, GLSL_TYPE_VOID, 130, 0, false, true }, 1387 { "size2x32", PIPE_FORMAT_R32G32_SINT, GLSL_TYPE_VOID, 130, 0, false, true }, 1388 { "size4x32", PIPE_FORMAT_R32G32B32A32_SINT, GLSL_TYPE_VOID, 130, 0, false, true }, 1389 }; 1390 1391 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) { 1392 if ((state->is_version(map[i].required_glsl, 1393 map[i].required_essl) || 1394 (state->NV_image_formats_enable && 1395 map[i].nv_image_formats)) && 1396 match_layout_qualifier($1, map[i].name, state) == 0) { 1397 /* Skip ARB_shader_image_load_store qualifiers if not enabled */ 1398 if (!map[i].ext_qualifiers && !(state->ARB_shader_image_load_store_enable || 1399 state->is_version(420, 310))) { 1400 continue; 1401 } 1402 /* Skip EXT_shader_image_load_store qualifiers if not enabled */ 1403 if (map[i].ext_qualifiers && !state->EXT_shader_image_load_store_enable) { 1404 continue; 1405 } 1406 $$.flags.q.explicit_image_format = 1; 1407 $$.image_format = map[i].format; 1408 $$.image_base_type = map[i].base_type; 1409 break; 1410 } 1411 } 1412 } 1413 } 1414 1415 if (!$$.flags.i) { 1416 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) { 1417 /* From section 4.4.1.3 of the GLSL 4.50 specification 1418 * (Fragment Shader Inputs): 1419 * 1420 * "Fragment shaders also allow the following layout 1421 * qualifier on in only (not with variable declarations) 1422 * layout-qualifier-id 1423 * early_fragment_tests 1424 * [...]" 1425 */ 1426 if (state->stage != MESA_SHADER_FRAGMENT) { 1427 _mesa_glsl_error(& @1, state, 1428 "early_fragment_tests layout qualifier only " 1429 "valid in fragment shaders"); 1430 } 1431 1432 $$.flags.q.early_fragment_tests = 1; 1433 } 1434 1435 if (match_layout_qualifier($1, "inner_coverage", state) == 0) { 1436 if (state->stage != MESA_SHADER_FRAGMENT) { 1437 _mesa_glsl_error(& @1, state, 1438 "inner_coverage layout qualifier only " 1439 "valid in fragment shaders"); 1440 } 1441 1442 if (state->INTEL_conservative_rasterization_enable) { 1443 $$.flags.q.inner_coverage = 1; 1444 } else { 1445 _mesa_glsl_error(& @1, state, 1446 "inner_coverage layout qualifier present, " 1447 "but the INTEL_conservative_rasterization extension " 1448 "is not enabled."); 1449 } 1450 } 1451 1452 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) { 1453 if (state->stage != MESA_SHADER_FRAGMENT) { 1454 _mesa_glsl_error(& @1, state, 1455 "post_depth_coverage layout qualifier only " 1456 "valid in fragment shaders"); 1457 } 1458 1459 if (state->ARB_post_depth_coverage_enable || 1460 state->INTEL_conservative_rasterization_enable) { 1461 $$.flags.q.post_depth_coverage = 1; 1462 } else { 1463 _mesa_glsl_error(& @1, state, 1464 "post_depth_coverage layout qualifier present, " 1465 "but the GL_ARB_post_depth_coverage extension " 1466 "is not enabled."); 1467 } 1468 } 1469 1470 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) { 1471 _mesa_glsl_error(& @1, state, 1472 "post_depth_coverage & inner_coverage layout qualifiers " 1473 "are mutually exclusive"); 1474 } 1475 } 1476 1477 const bool pixel_interlock_ordered = match_layout_qualifier($1, 1478 "pixel_interlock_ordered", state) == 0; 1479 const bool pixel_interlock_unordered = match_layout_qualifier($1, 1480 "pixel_interlock_unordered", state) == 0; 1481 const bool sample_interlock_ordered = match_layout_qualifier($1, 1482 "sample_interlock_ordered", state) == 0; 1483 const bool sample_interlock_unordered = match_layout_qualifier($1, 1484 "sample_interlock_unordered", state) == 0; 1485 1486 if (pixel_interlock_ordered + pixel_interlock_unordered + 1487 sample_interlock_ordered + sample_interlock_unordered > 0 && 1488 state->stage != MESA_SHADER_FRAGMENT) { 1489 _mesa_glsl_error(& @1, state, "interlock layout qualifiers: " 1490 "pixel_interlock_ordered, pixel_interlock_unordered, " 1491 "sample_interlock_ordered and sample_interlock_unordered, " 1492 "only valid in fragment shader input layout declaration."); 1493 } else if (pixel_interlock_ordered + pixel_interlock_unordered + 1494 sample_interlock_ordered + sample_interlock_unordered > 0 && 1495 !state->ARB_fragment_shader_interlock_enable && 1496 !state->NV_fragment_shader_interlock_enable) { 1497 _mesa_glsl_error(& @1, state, 1498 "interlock layout qualifier present, but the " 1499 "GL_ARB_fragment_shader_interlock or " 1500 "GL_NV_fragment_shader_interlock extension is not " 1501 "enabled."); 1502 } else { 1503 $$.flags.q.pixel_interlock_ordered = pixel_interlock_ordered; 1504 $$.flags.q.pixel_interlock_unordered = pixel_interlock_unordered; 1505 $$.flags.q.sample_interlock_ordered = sample_interlock_ordered; 1506 $$.flags.q.sample_interlock_unordered = sample_interlock_unordered; 1507 } 1508 1509 /* Layout qualifiers for tessellation evaluation shaders. */ 1510 if (!$$.flags.i) { 1511 static const struct { 1512 const char *s; 1513 GLenum e; 1514 } map[] = { 1515 /* triangles already parsed by gs-specific code */ 1516 { "quads", GL_QUADS }, 1517 { "isolines", GL_ISOLINES }, 1518 }; 1519 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) { 1520 if (match_layout_qualifier($1, map[i].s, state) == 0) { 1521 $$.flags.q.prim_type = 1; 1522 $$.prim_type = map[i].e; 1523 break; 1524 } 1525 } 1526 1527 if ($$.flags.i && !state->has_tessellation_shader()) { 1528 _mesa_glsl_error(& @1, state, 1529 "primitive mode qualifier `%s' requires " 1530 "GLSL 4.00 or ARB_tessellation_shader", $1); 1531 } 1532 } 1533 if (!$$.flags.i) { 1534 static const struct { 1535 const char *s; 1536 enum gl_tess_spacing e; 1537 } map[] = { 1538 { "equal_spacing", TESS_SPACING_EQUAL }, 1539 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD }, 1540 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN }, 1541 }; 1542 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) { 1543 if (match_layout_qualifier($1, map[i].s, state) == 0) { 1544 $$.flags.q.vertex_spacing = 1; 1545 $$.vertex_spacing = map[i].e; 1546 break; 1547 } 1548 } 1549 1550 if ($$.flags.i && !state->has_tessellation_shader()) { 1551 _mesa_glsl_error(& @1, state, 1552 "vertex spacing qualifier `%s' requires " 1553 "GLSL 4.00 or ARB_tessellation_shader", $1); 1554 } 1555 } 1556 if (!$$.flags.i) { 1557 if (match_layout_qualifier($1, "cw", state) == 0) { 1558 $$.flags.q.ordering = 1; 1559 $$.ordering = GL_CW; 1560 } else if (match_layout_qualifier($1, "ccw", state) == 0) { 1561 $$.flags.q.ordering = 1; 1562 $$.ordering = GL_CCW; 1563 } 1564 1565 if ($$.flags.i && !state->has_tessellation_shader()) { 1566 _mesa_glsl_error(& @1, state, 1567 "ordering qualifier `%s' requires " 1568 "GLSL 4.00 or ARB_tessellation_shader", $1); 1569 } 1570 } 1571 if (!$$.flags.i) { 1572 if (match_layout_qualifier($1, "point_mode", state) == 0) { 1573 $$.flags.q.point_mode = 1; 1574 $$.point_mode = true; 1575 } 1576 1577 if ($$.flags.i && !state->has_tessellation_shader()) { 1578 _mesa_glsl_error(& @1, state, 1579 "qualifier `point_mode' requires " 1580 "GLSL 4.00 or ARB_tessellation_shader"); 1581 } 1582 } 1583 1584 if (!$$.flags.i) { 1585 static const struct { 1586 const char *s; 1587 uint32_t mask; 1588 } map[] = { 1589 { "blend_support_multiply", BITFIELD_BIT(BLEND_MULTIPLY) }, 1590 { "blend_support_screen", BITFIELD_BIT(BLEND_SCREEN) }, 1591 { "blend_support_overlay", BITFIELD_BIT(BLEND_OVERLAY) }, 1592 { "blend_support_darken", BITFIELD_BIT(BLEND_DARKEN) }, 1593 { "blend_support_lighten", BITFIELD_BIT(BLEND_LIGHTEN) }, 1594 { "blend_support_colordodge", BITFIELD_BIT(BLEND_COLORDODGE) }, 1595 { "blend_support_colorburn", BITFIELD_BIT(BLEND_COLORBURN) }, 1596 { "blend_support_hardlight", BITFIELD_BIT(BLEND_HARDLIGHT) }, 1597 { "blend_support_softlight", BITFIELD_BIT(BLEND_SOFTLIGHT) }, 1598 { "blend_support_difference", BITFIELD_BIT(BLEND_DIFFERENCE) }, 1599 { "blend_support_exclusion", BITFIELD_BIT(BLEND_EXCLUSION) }, 1600 { "blend_support_hsl_hue", BITFIELD_BIT(BLEND_HSL_HUE) }, 1601 { "blend_support_hsl_saturation", BITFIELD_BIT(BLEND_HSL_SATURATION) }, 1602 { "blend_support_hsl_color", BITFIELD_BIT(BLEND_HSL_COLOR) }, 1603 { "blend_support_hsl_luminosity", BITFIELD_BIT(BLEND_HSL_LUMINOSITY) }, 1604 { "blend_support_all_equations", (1u << (BLEND_HSL_LUMINOSITY + 1)) - 2 }, 1605 }; 1606 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) { 1607 if (match_layout_qualifier($1, map[i].s, state) == 0) { 1608 $$.flags.q.blend_support = 1; 1609 state->fs_blend_support |= map[i].mask; 1610 break; 1611 } 1612 } 1613 1614 if ($$.flags.i && 1615 !state->KHR_blend_equation_advanced_enable && 1616 !state->is_version(0, 320)) { 1617 _mesa_glsl_error(& @1, state, 1618 "advanced blending layout qualifiers require " 1619 "ESSL 3.20 or KHR_blend_equation_advanced"); 1620 } 1621 1622 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) { 1623 _mesa_glsl_error(& @1, state, 1624 "advanced blending layout qualifiers only " 1625 "valid in fragment shaders"); 1626 } 1627 } 1628 1629 /* Layout qualifiers for ARB_compute_variable_group_size. */ 1630 if (!$$.flags.i) { 1631 if (match_layout_qualifier($1, "local_size_variable", state) == 0) { 1632 $$.flags.q.local_size_variable = 1; 1633 } 1634 1635 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) { 1636 _mesa_glsl_error(& @1, state, 1637 "qualifier `local_size_variable` requires " 1638 "ARB_compute_variable_group_size"); 1639 } 1640 } 1641 1642 /* Layout qualifiers for ARB_bindless_texture. */ 1643 if (!$$.flags.i) { 1644 if (match_layout_qualifier($1, "bindless_sampler", state) == 0) 1645 $$.flags.q.bindless_sampler = 1; 1646 if (match_layout_qualifier($1, "bound_sampler", state) == 0) 1647 $$.flags.q.bound_sampler = 1; 1648 1649 if (state->has_shader_image_load_store()) { 1650 if (match_layout_qualifier($1, "bindless_image", state) == 0) 1651 $$.flags.q.bindless_image = 1; 1652 if (match_layout_qualifier($1, "bound_image", state) == 0) 1653 $$.flags.q.bound_image = 1; 1654 } 1655 1656 if ($$.flags.i && !state->has_bindless()) { 1657 _mesa_glsl_error(& @1, state, 1658 "qualifier `%s` requires " 1659 "ARB_bindless_texture", $1); 1660 } 1661 } 1662 1663 if (!$$.flags.i && 1664 state->EXT_shader_framebuffer_fetch_non_coherent_enable) { 1665 if (match_layout_qualifier($1, "noncoherent", state) == 0) 1666 $$.flags.q.non_coherent = 1; 1667 } 1668 1669 // Layout qualifiers for NV_compute_shader_derivatives. 1670 if (!$$.flags.i) { 1671 if (match_layout_qualifier($1, "derivative_group_quadsNV", state) == 0) { 1672 $$.flags.q.derivative_group = 1; 1673 $$.derivative_group = DERIVATIVE_GROUP_QUADS; 1674 } else if (match_layout_qualifier($1, "derivative_group_linearNV", state) == 0) { 1675 $$.flags.q.derivative_group = 1; 1676 $$.derivative_group = DERIVATIVE_GROUP_LINEAR; 1677 } 1678 1679 if ($$.flags.i) { 1680 if (!state->has_compute_shader()) { 1681 _mesa_glsl_error(& @1, state, 1682 "qualifier `%s' requires " 1683 "a compute shader", $1); 1684 } 1685 1686 if (!state->NV_compute_shader_derivatives_enable) { 1687 _mesa_glsl_error(& @1, state, 1688 "qualifier `%s' requires " 1689 "NV_compute_shader_derivatives", $1); 1690 } 1691 1692 if (state->NV_compute_shader_derivatives_warn) { 1693 _mesa_glsl_warning(& @1, state, 1694 "NV_compute_shader_derivatives layout " 1695 "qualifier `%s' used", $1); 1696 } 1697 } 1698 } 1699 1700 /* Layout qualifier for NV_viewport_array2. */ 1701 if (!$$.flags.i && state->stage != MESA_SHADER_FRAGMENT) { 1702 if (match_layout_qualifier($1, "viewport_relative", state) == 0) { 1703 $$.flags.q.viewport_relative = 1; 1704 } 1705 1706 if ($$.flags.i && !state->NV_viewport_array2_enable) { 1707 _mesa_glsl_error(& @1, state, 1708 "qualifier `%s' requires " 1709 "GL_NV_viewport_array2", $1); 1710 } 1711 1712 if ($$.flags.i && state->NV_viewport_array2_warn) { 1713 _mesa_glsl_warning(& @1, state, 1714 "GL_NV_viewport_array2 layout " 1715 "identifier `%s' used", $1); 1716 } 1717 } 1718 1719 if (!$$.flags.i) { 1720 _mesa_glsl_error(& @1, state, "unrecognized layout identifier " 1721 "`%s'", $1); 1722 YYERROR; 1723 } 1724 } 1725 | any_identifier '=' constant_expression 1726 { 1727 memset(& $$, 0, sizeof($$)); 1728 void *ctx = state->linalloc; 1729 1730 if ($3->oper != ast_int_constant && 1731 $3->oper != ast_uint_constant && 1732 !state->has_enhanced_layouts()) { 1733 _mesa_glsl_error(& @1, state, 1734 "compile-time constant expressions require " 1735 "GLSL 4.40 or ARB_enhanced_layouts"); 1736 } 1737 1738 if (match_layout_qualifier("align", $1, state) == 0) { 1739 if (!state->has_enhanced_layouts()) { 1740 _mesa_glsl_error(& @1, state, 1741 "align qualifier requires " 1742 "GLSL 4.40 or ARB_enhanced_layouts"); 1743 } else { 1744 $$.flags.q.explicit_align = 1; 1745 $$.align = $3; 1746 } 1747 } 1748 1749 if (match_layout_qualifier("location", $1, state) == 0) { 1750 $$.flags.q.explicit_location = 1; 1751 1752 if ($$.flags.q.attribute == 1 && 1753 state->ARB_explicit_attrib_location_warn) { 1754 _mesa_glsl_warning(& @1, state, 1755 "GL_ARB_explicit_attrib_location layout " 1756 "identifier `%s' used", $1); 1757 } 1758 $$.location = $3; 1759 } 1760 1761 if (match_layout_qualifier("component", $1, state) == 0) { 1762 if (!state->has_enhanced_layouts()) { 1763 _mesa_glsl_error(& @1, state, 1764 "component qualifier requires " 1765 "GLSL 4.40 or ARB_enhanced_layouts"); 1766 } else { 1767 $$.flags.q.explicit_component = 1; 1768 $$.component = $3; 1769 } 1770 } 1771 1772 if (match_layout_qualifier("index", $1, state) == 0) { 1773 if (state->es_shader && !state->EXT_blend_func_extended_enable) { 1774 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended"); 1775 YYERROR; 1776 } 1777 1778 $$.flags.q.explicit_index = 1; 1779 $$.index = $3; 1780 } 1781 1782 if ((state->has_420pack_or_es31() || 1783 state->has_atomic_counters() || 1784 state->has_shader_storage_buffer_objects()) && 1785 match_layout_qualifier("binding", $1, state) == 0) { 1786 $$.flags.q.explicit_binding = 1; 1787 $$.binding = $3; 1788 } 1789 1790 if ((state->has_atomic_counters() || 1791 state->has_enhanced_layouts()) && 1792 match_layout_qualifier("offset", $1, state) == 0) { 1793 $$.flags.q.explicit_offset = 1; 1794 $$.offset = $3; 1795 } 1796 1797 if (match_layout_qualifier("max_vertices", $1, state) == 0) { 1798 $$.flags.q.max_vertices = 1; 1799 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3); 1800 if (!state->has_geometry_shader()) { 1801 _mesa_glsl_error(& @3, state, 1802 "#version 150 max_vertices qualifier " 1803 "specified", $3); 1804 } 1805 } 1806 1807 if (state->stage == MESA_SHADER_GEOMETRY) { 1808 if (match_layout_qualifier("stream", $1, state) == 0 && 1809 state->check_explicit_attrib_stream_allowed(& @3)) { 1810 $$.flags.q.stream = 1; 1811 $$.flags.q.explicit_stream = 1; 1812 $$.stream = $3; 1813 } 1814 } 1815 1816 if (state->has_enhanced_layouts()) { 1817 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) { 1818 $$.flags.q.xfb_buffer = 1; 1819 $$.flags.q.explicit_xfb_buffer = 1; 1820 $$.xfb_buffer = $3; 1821 } 1822 1823 if (match_layout_qualifier("xfb_offset", $1, state) == 0) { 1824 $$.flags.q.explicit_xfb_offset = 1; 1825 $$.offset = $3; 1826 } 1827 1828 if (match_layout_qualifier("xfb_stride", $1, state) == 0) { 1829 $$.flags.q.xfb_stride = 1; 1830 $$.flags.q.explicit_xfb_stride = 1; 1831 $$.xfb_stride = $3; 1832 } 1833 } 1834 1835 static const char * const local_size_qualifiers[3] = { 1836 "local_size_x", 1837 "local_size_y", 1838 "local_size_z", 1839 }; 1840 for (int i = 0; i < 3; i++) { 1841 if (match_layout_qualifier(local_size_qualifiers[i], $1, 1842 state) == 0) { 1843 if (!state->has_compute_shader()) { 1844 _mesa_glsl_error(& @3, state, 1845 "%s qualifier requires GLSL 4.30 or " 1846 "GLSL ES 3.10 or ARB_compute_shader", 1847 local_size_qualifiers[i]); 1848 YYERROR; 1849 } else { 1850 $$.flags.q.local_size |= (1 << i); 1851 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3); 1852 } 1853 break; 1854 } 1855 } 1856 1857 if (match_layout_qualifier("invocations", $1, state) == 0) { 1858 $$.flags.q.invocations = 1; 1859 $$.invocations = new(ctx) ast_layout_expression(@1, $3); 1860 if (!state->is_version(400, 320) && 1861 !state->ARB_gpu_shader5_enable && 1862 !state->OES_geometry_shader_enable && 1863 !state->EXT_geometry_shader_enable) { 1864 _mesa_glsl_error(& @3, state, 1865 "GL_ARB_gpu_shader5 invocations " 1866 "qualifier specified", $3); 1867 } 1868 } 1869 1870 /* Layout qualifiers for tessellation control shaders. */ 1871 if (match_layout_qualifier("vertices", $1, state) == 0) { 1872 $$.flags.q.vertices = 1; 1873 $$.vertices = new(ctx) ast_layout_expression(@1, $3); 1874 if (!state->has_tessellation_shader()) { 1875 _mesa_glsl_error(& @1, state, 1876 "vertices qualifier requires GLSL 4.00 or " 1877 "ARB_tessellation_shader"); 1878 } 1879 } 1880 1881 /* If the identifier didn't match any known layout identifiers, 1882 * emit an error. 1883 */ 1884 if (!$$.flags.i) { 1885 _mesa_glsl_error(& @1, state, "unrecognized layout identifier " 1886 "`%s'", $1); 1887 YYERROR; 1888 } 1889 } 1890 | interface_block_layout_qualifier 1891 { 1892 $$ = $1; 1893 /* Layout qualifiers for ARB_uniform_buffer_object. */ 1894 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) { 1895 _mesa_glsl_error(& @1, state, 1896 "#version 140 / GL_ARB_uniform_buffer_object " 1897 "layout qualifier `%s' is used", $1); 1898 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) { 1899 _mesa_glsl_warning(& @1, state, 1900 "#version 140 / GL_ARB_uniform_buffer_object " 1901 "layout qualifier `%s' is used", $1); 1902 } 1903 } 1904 ; 1905 1906/* This is a separate language rule because we parse these as tokens 1907 * (due to them being reserved keywords) instead of identifiers like 1908 * most qualifiers. See the any_identifier path of 1909 * layout_qualifier_id for the others. 1910 * 1911 * Note that since layout qualifiers are case-insensitive in desktop 1912 * GLSL, all of these qualifiers need to be handled as identifiers as 1913 * well (by the any_identifier path of layout_qualifier_id). 1914 */ 1915interface_block_layout_qualifier: 1916 ROW_MAJOR 1917 { 1918 memset(& $$, 0, sizeof($$)); 1919 $$.flags.q.row_major = 1; 1920 } 1921 | PACKED_TOK 1922 { 1923 memset(& $$, 0, sizeof($$)); 1924 $$.flags.q.packed = 1; 1925 } 1926 | SHARED 1927 { 1928 memset(& $$, 0, sizeof($$)); 1929 $$.flags.q.shared = 1; 1930 } 1931 ; 1932 1933subroutine_qualifier: 1934 SUBROUTINE 1935 { 1936 memset(& $$, 0, sizeof($$)); 1937 $$.flags.q.subroutine = 1; 1938 } 1939 | SUBROUTINE '(' subroutine_type_list ')' 1940 { 1941 memset(& $$, 0, sizeof($$)); 1942 $$.flags.q.subroutine = 1; 1943 $$.subroutine_list = $3; 1944 } 1945 ; 1946 1947subroutine_type_list: 1948 any_identifier 1949 { 1950 void *ctx = state->linalloc; 1951 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL); 1952 decl->set_location(@1); 1953 1954 $$ = new(ctx) ast_subroutine_list(); 1955 $$->declarations.push_tail(&decl->link); 1956 } 1957 | subroutine_type_list ',' any_identifier 1958 { 1959 void *ctx = state->linalloc; 1960 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL); 1961 decl->set_location(@3); 1962 1963 $$ = $1; 1964 $$->declarations.push_tail(&decl->link); 1965 } 1966 ; 1967 1968interpolation_qualifier: 1969 SMOOTH 1970 { 1971 memset(& $$, 0, sizeof($$)); 1972 $$.flags.q.smooth = 1; 1973 } 1974 | FLAT 1975 { 1976 memset(& $$, 0, sizeof($$)); 1977 $$.flags.q.flat = 1; 1978 } 1979 | NOPERSPECTIVE 1980 { 1981 memset(& $$, 0, sizeof($$)); 1982 $$.flags.q.noperspective = 1; 1983 } 1984 ; 1985 1986type_qualifier: 1987 /* Single qualifiers */ 1988 INVARIANT 1989 { 1990 memset(& $$, 0, sizeof($$)); 1991 $$.flags.q.invariant = 1; 1992 } 1993 | PRECISE 1994 { 1995 memset(& $$, 0, sizeof($$)); 1996 $$.flags.q.precise = 1; 1997 } 1998 | auxiliary_storage_qualifier 1999 | storage_qualifier 2000 | interpolation_qualifier 2001 | layout_qualifier 2002 | memory_qualifier 2003 | subroutine_qualifier 2004 | precision_qualifier 2005 { 2006 memset(&$$, 0, sizeof($$)); 2007 $$.precision = $1; 2008 } 2009 2010 /* Multiple qualifiers: 2011 * In GLSL 4.20, these can be specified in any order. In earlier versions, 2012 * they appear in this order (see GLSL 1.50 section 4.7 & comments below): 2013 * 2014 * invariant interpolation auxiliary storage precision ...or... 2015 * layout storage precision 2016 * 2017 * Each qualifier's rule ensures that the accumulated qualifiers on the right 2018 * side don't contain any that must appear on the left hand side. 2019 * For example, when processing a storage qualifier, we check that there are 2020 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right. 2021 */ 2022 | PRECISE type_qualifier 2023 { 2024 if ($2.flags.q.precise) 2025 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier"); 2026 2027 $$ = $2; 2028 $$.flags.q.precise = 1; 2029 } 2030 | INVARIANT type_qualifier 2031 { 2032 if ($2.flags.q.invariant) 2033 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier"); 2034 2035 if (!state->has_420pack_or_es31() && $2.flags.q.precise) 2036 _mesa_glsl_error(&@1, state, 2037 "\"invariant\" must come after \"precise\""); 2038 2039 $$ = $2; 2040 $$.flags.q.invariant = 1; 2041 2042 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier": 2043 * 2044 * "Only variables output from a shader can be candidates for invariance. 2045 * This includes user-defined output variables and the built-in output 2046 * variables. As only outputs can be declared as invariant, an invariant 2047 * output from one shader stage will still match an input of a subsequent 2048 * stage without the input being declared as invariant." 2049 * 2050 * On the desktop side, this text first appears in GLSL 4.30. 2051 */ 2052 if (state->is_version(430, 300) && $$.flags.q.in) 2053 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs"); 2054 } 2055 | interpolation_qualifier type_qualifier 2056 { 2057 /* Section 4.3 of the GLSL 1.40 specification states: 2058 * "...qualified with one of these interpolation qualifiers" 2059 * 2060 * GLSL 1.30 claims to allow "one or more", but insists that: 2061 * "These interpolation qualifiers may only precede the qualifiers in, 2062 * centroid in, out, or centroid out in a declaration." 2063 * 2064 * ...which means that e.g. smooth can't precede smooth, so there can be 2065 * only one after all, and the 1.40 text is a clarification, not a change. 2066 */ 2067 if ($2.has_interpolation()) 2068 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier"); 2069 2070 if (!state->has_420pack_or_es31() && 2071 ($2.flags.q.precise || $2.flags.q.invariant)) { 2072 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come " 2073 "after \"precise\" or \"invariant\""); 2074 } 2075 2076 $$ = $1; 2077 $$.merge_qualifier(&@1, state, $2, false); 2078 } 2079 | layout_qualifier type_qualifier 2080 { 2081 /* In the absence of ARB_shading_language_420pack, layout qualifiers may 2082 * appear no later than auxiliary storage qualifiers. There is no 2083 * particularly clear spec language mandating this, but in all examples 2084 * the layout qualifier precedes the storage qualifier. 2085 * 2086 * We allow combinations of layout with interpolation, invariant or 2087 * precise qualifiers since these are useful in ARB_separate_shader_objects. 2088 * There is no clear spec guidance on this either. 2089 */ 2090 $$ = $1; 2091 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout()); 2092 } 2093 | subroutine_qualifier type_qualifier 2094 { 2095 $$ = $1; 2096 $$.merge_qualifier(&@1, state, $2, false); 2097 } 2098 | auxiliary_storage_qualifier type_qualifier 2099 { 2100 if ($2.has_auxiliary_storage()) { 2101 _mesa_glsl_error(&@1, state, 2102 "duplicate auxiliary storage qualifier (centroid or sample)"); 2103 } 2104 2105 if ((!state->has_420pack_or_es31() && !state->EXT_gpu_shader4_enable) && 2106 ($2.flags.q.precise || $2.flags.q.invariant || 2107 $2.has_interpolation() || $2.has_layout())) { 2108 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come " 2109 "just before storage qualifiers"); 2110 } 2111 $$ = $1; 2112 $$.merge_qualifier(&@1, state, $2, false); 2113 } 2114 | storage_qualifier type_qualifier 2115 { 2116 /* Section 4.3 of the GLSL 1.20 specification states: 2117 * "Variable declarations may have a storage qualifier specified..." 2118 * 1.30 clarifies this to "may have one storage qualifier". 2119 * 2120 * GL_EXT_gpu_shader4 allows "varying out" in fragment shaders. 2121 */ 2122 if ($2.has_storage() && 2123 (!state->EXT_gpu_shader4_enable || 2124 state->stage != MESA_SHADER_FRAGMENT || 2125 !$1.flags.q.varying || !$2.flags.q.out)) 2126 _mesa_glsl_error(&@1, state, "duplicate storage qualifier"); 2127 2128 if (!state->has_420pack_or_es31() && 2129 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() || 2130 $2.has_layout() || $2.has_auxiliary_storage())) { 2131 _mesa_glsl_error(&@1, state, "storage qualifiers must come after " 2132 "precise, invariant, interpolation, layout and auxiliary " 2133 "storage qualifiers"); 2134 } 2135 2136 $$ = $1; 2137 $$.merge_qualifier(&@1, state, $2, false); 2138 } 2139 | precision_qualifier type_qualifier 2140 { 2141 if ($2.precision != ast_precision_none) 2142 _mesa_glsl_error(&@1, state, "duplicate precision qualifier"); 2143 2144 if (!(state->has_420pack_or_es31()) && 2145 $2.flags.i != 0) 2146 _mesa_glsl_error(&@1, state, "precision qualifiers must come last"); 2147 2148 $$ = $2; 2149 $$.precision = $1; 2150 } 2151 | memory_qualifier type_qualifier 2152 { 2153 $$ = $1; 2154 $$.merge_qualifier(&@1, state, $2, false); 2155 } 2156 ; 2157 2158auxiliary_storage_qualifier: 2159 CENTROID 2160 { 2161 memset(& $$, 0, sizeof($$)); 2162 $$.flags.q.centroid = 1; 2163 } 2164 | SAMPLE 2165 { 2166 memset(& $$, 0, sizeof($$)); 2167 $$.flags.q.sample = 1; 2168 } 2169 | PATCH 2170 { 2171 memset(& $$, 0, sizeof($$)); 2172 $$.flags.q.patch = 1; 2173 } 2174 2175storage_qualifier: 2176 CONST_TOK 2177 { 2178 memset(& $$, 0, sizeof($$)); 2179 $$.flags.q.constant = 1; 2180 } 2181 | ATTRIBUTE 2182 { 2183 memset(& $$, 0, sizeof($$)); 2184 $$.flags.q.attribute = 1; 2185 } 2186 | VARYING 2187 { 2188 memset(& $$, 0, sizeof($$)); 2189 $$.flags.q.varying = 1; 2190 } 2191 | IN_TOK 2192 { 2193 memset(& $$, 0, sizeof($$)); 2194 $$.flags.q.in = 1; 2195 } 2196 | OUT_TOK 2197 { 2198 memset(& $$, 0, sizeof($$)); 2199 $$.flags.q.out = 1; 2200 2201 if (state->stage == MESA_SHADER_GEOMETRY && 2202 state->has_explicit_attrib_stream()) { 2203 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00 2204 * spec says: 2205 * 2206 * "If the block or variable is declared with the stream 2207 * identifier, it is associated with the specified stream; 2208 * otherwise, it is associated with the current default stream." 2209 */ 2210 $$.flags.q.stream = 1; 2211 $$.flags.q.explicit_stream = 0; 2212 $$.stream = state->out_qualifier->stream; 2213 } 2214 2215 if (state->has_enhanced_layouts()) { 2216 $$.flags.q.xfb_buffer = 1; 2217 $$.flags.q.explicit_xfb_buffer = 0; 2218 $$.xfb_buffer = state->out_qualifier->xfb_buffer; 2219 } 2220 } 2221 | INOUT_TOK 2222 { 2223 memset(& $$, 0, sizeof($$)); 2224 $$.flags.q.in = 1; 2225 $$.flags.q.out = 1; 2226 2227 if (!state->has_framebuffer_fetch() || 2228 !state->is_version(130, 300) || 2229 state->stage != MESA_SHADER_FRAGMENT) 2230 _mesa_glsl_error(&@1, state, "A single interface variable cannot be " 2231 "declared as both input and output"); 2232 } 2233 | UNIFORM 2234 { 2235 memset(& $$, 0, sizeof($$)); 2236 $$.flags.q.uniform = 1; 2237 } 2238 | BUFFER 2239 { 2240 memset(& $$, 0, sizeof($$)); 2241 $$.flags.q.buffer = 1; 2242 } 2243 | SHARED 2244 { 2245 memset(& $$, 0, sizeof($$)); 2246 $$.flags.q.shared_storage = 1; 2247 } 2248 ; 2249 2250memory_qualifier: 2251 COHERENT 2252 { 2253 memset(& $$, 0, sizeof($$)); 2254 $$.flags.q.coherent = 1; 2255 } 2256 | VOLATILE 2257 { 2258 memset(& $$, 0, sizeof($$)); 2259 $$.flags.q._volatile = 1; 2260 } 2261 | RESTRICT 2262 { 2263 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i)); 2264 memset(& $$, 0, sizeof($$)); 2265 $$.flags.q.restrict_flag = 1; 2266 } 2267 | READONLY 2268 { 2269 memset(& $$, 0, sizeof($$)); 2270 $$.flags.q.read_only = 1; 2271 } 2272 | WRITEONLY 2273 { 2274 memset(& $$, 0, sizeof($$)); 2275 $$.flags.q.write_only = 1; 2276 } 2277 ; 2278 2279array_specifier: 2280 '[' ']' 2281 { 2282 void *ctx = state->linalloc; 2283 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression( 2284 ast_unsized_array_dim, NULL, 2285 NULL, NULL)); 2286 $$->set_location_range(@1, @2); 2287 } 2288 | '[' constant_expression ']' 2289 { 2290 void *ctx = state->linalloc; 2291 $$ = new(ctx) ast_array_specifier(@1, $2); 2292 $$->set_location_range(@1, @3); 2293 } 2294 | array_specifier '[' ']' 2295 { 2296 void *ctx = state->linalloc; 2297 $$ = $1; 2298 2299 if (state->check_arrays_of_arrays_allowed(& @1)) { 2300 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL, 2301 NULL, NULL)); 2302 } 2303 } 2304 | array_specifier '[' constant_expression ']' 2305 { 2306 $$ = $1; 2307 2308 if (state->check_arrays_of_arrays_allowed(& @1)) { 2309 $$->add_dimension($3); 2310 } 2311 } 2312 ; 2313 2314type_specifier: 2315 type_specifier_nonarray 2316 | type_specifier_nonarray array_specifier 2317 { 2318 $$ = $1; 2319 $$->array_specifier = $2; 2320 } 2321 ; 2322 2323type_specifier_nonarray: 2324 basic_type_specifier_nonarray 2325 { 2326 void *ctx = state->linalloc; 2327 $$ = new(ctx) ast_type_specifier($1); 2328 $$->set_location(@1); 2329 } 2330 | struct_specifier 2331 { 2332 void *ctx = state->linalloc; 2333 $$ = new(ctx) ast_type_specifier($1); 2334 $$->set_location(@1); 2335 } 2336 | TYPE_IDENTIFIER 2337 { 2338 void *ctx = state->linalloc; 2339 $$ = new(ctx) ast_type_specifier($1); 2340 $$->set_location(@1); 2341 } 2342 ; 2343 2344basic_type_specifier_nonarray: 2345 VOID_TOK { $$ = glsl_type::void_type; } 2346 | BASIC_TYPE_TOK { $$ = $1; } 2347 | UNSIGNED BASIC_TYPE_TOK 2348 { 2349 if ($2 == glsl_type::int_type) { 2350 $$ = glsl_type::uint_type; 2351 } else { 2352 _mesa_glsl_error(&@1, state, 2353 "\"unsigned\" is only allowed before \"int\""); 2354 } 2355 } 2356 ; 2357 2358precision_qualifier: 2359 HIGHP 2360 { 2361 state->check_precision_qualifiers_allowed(&@1); 2362 $$ = ast_precision_high; 2363 } 2364 | MEDIUMP 2365 { 2366 state->check_precision_qualifiers_allowed(&@1); 2367 $$ = ast_precision_medium; 2368 } 2369 | LOWP 2370 { 2371 state->check_precision_qualifiers_allowed(&@1); 2372 $$ = ast_precision_low; 2373 } 2374 ; 2375 2376struct_specifier: 2377 STRUCT any_identifier '{' struct_declaration_list '}' 2378 { 2379 void *ctx = state->linalloc; 2380 $$ = new(ctx) ast_struct_specifier($2, $4); 2381 $$->set_location_range(@2, @5); 2382 state->symbols->add_type($2, glsl_type::void_type); 2383 } 2384 | STRUCT '{' struct_declaration_list '}' 2385 { 2386 void *ctx = state->linalloc; 2387 2388 /* All anonymous structs have the same name. This simplifies matching of 2389 * globals whose type is an unnamed struct. 2390 * 2391 * It also avoids a memory leak when the same shader is compiled over and 2392 * over again. 2393 */ 2394 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3); 2395 2396 $$->set_location_range(@2, @4); 2397 } 2398 ; 2399 2400struct_declaration_list: 2401 struct_declaration 2402 { 2403 $$ = $1; 2404 $1->link.self_link(); 2405 } 2406 | struct_declaration_list struct_declaration 2407 { 2408 $$ = $1; 2409 $$->link.insert_before(& $2->link); 2410 } 2411 ; 2412 2413struct_declaration: 2414 fully_specified_type struct_declarator_list ';' 2415 { 2416 void *ctx = state->linalloc; 2417 ast_fully_specified_type *const type = $1; 2418 type->set_location(@1); 2419 2420 if (state->has_bindless()) { 2421 ast_type_qualifier input_layout_mask; 2422 2423 /* Allow to declare qualifiers for images. */ 2424 input_layout_mask.flags.i = 0; 2425 input_layout_mask.flags.q.coherent = 1; 2426 input_layout_mask.flags.q._volatile = 1; 2427 input_layout_mask.flags.q.restrict_flag = 1; 2428 input_layout_mask.flags.q.read_only = 1; 2429 input_layout_mask.flags.q.write_only = 1; 2430 input_layout_mask.flags.q.explicit_image_format = 1; 2431 2432 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) { 2433 _mesa_glsl_error(&@1, state, 2434 "only precision and image qualifiers may be " 2435 "applied to structure members"); 2436 } 2437 } else { 2438 if (type->qualifier.flags.i != 0) 2439 _mesa_glsl_error(&@1, state, 2440 "only precision qualifiers may be applied to " 2441 "structure members"); 2442 } 2443 2444 $$ = new(ctx) ast_declarator_list(type); 2445 $$->set_location(@2); 2446 2447 $$->declarations.push_degenerate_list_at_head(& $2->link); 2448 } 2449 ; 2450 2451struct_declarator_list: 2452 struct_declarator 2453 { 2454 $$ = $1; 2455 $1->link.self_link(); 2456 } 2457 | struct_declarator_list ',' struct_declarator 2458 { 2459 $$ = $1; 2460 $$->link.insert_before(& $3->link); 2461 } 2462 ; 2463 2464struct_declarator: 2465 any_identifier 2466 { 2467 void *ctx = state->linalloc; 2468 $$ = new(ctx) ast_declaration($1, NULL, NULL); 2469 $$->set_location(@1); 2470 } 2471 | any_identifier array_specifier 2472 { 2473 void *ctx = state->linalloc; 2474 $$ = new(ctx) ast_declaration($1, $2, NULL); 2475 $$->set_location_range(@1, @2); 2476 } 2477 ; 2478 2479initializer: 2480 assignment_expression 2481 | '{' initializer_list '}' 2482 { 2483 $$ = $2; 2484 } 2485 | '{' initializer_list ',' '}' 2486 { 2487 $$ = $2; 2488 } 2489 ; 2490 2491initializer_list: 2492 initializer 2493 { 2494 void *ctx = state->linalloc; 2495 $$ = new(ctx) ast_aggregate_initializer(); 2496 $$->set_location(@1); 2497 $$->expressions.push_tail(& $1->link); 2498 } 2499 | initializer_list ',' initializer 2500 { 2501 $1->expressions.push_tail(& $3->link); 2502 } 2503 ; 2504 2505declaration_statement: 2506 declaration 2507 ; 2508 2509 // Grammar Note: labeled statements for SWITCH only; 'goto' is not 2510 // supported. 2511statement: 2512 compound_statement { $$ = (ast_node *) $1; } 2513 | simple_statement 2514 ; 2515 2516simple_statement: 2517 declaration_statement 2518 | expression_statement 2519 | selection_statement 2520 | switch_statement 2521 | iteration_statement 2522 | jump_statement 2523 | demote_statement 2524 ; 2525 2526compound_statement: 2527 '{' '}' 2528 { 2529 void *ctx = state->linalloc; 2530 $$ = new(ctx) ast_compound_statement(true, NULL); 2531 $$->set_location_range(@1, @2); 2532 } 2533 | '{' 2534 { 2535 state->symbols->push_scope(); 2536 } 2537 statement_list '}' 2538 { 2539 void *ctx = state->linalloc; 2540 $$ = new(ctx) ast_compound_statement(true, $3); 2541 $$->set_location_range(@1, @4); 2542 state->symbols->pop_scope(); 2543 } 2544 ; 2545 2546statement_no_new_scope: 2547 compound_statement_no_new_scope { $$ = (ast_node *) $1; } 2548 | simple_statement 2549 ; 2550 2551compound_statement_no_new_scope: 2552 '{' '}' 2553 { 2554 void *ctx = state->linalloc; 2555 $$ = new(ctx) ast_compound_statement(false, NULL); 2556 $$->set_location_range(@1, @2); 2557 } 2558 | '{' statement_list '}' 2559 { 2560 void *ctx = state->linalloc; 2561 $$ = new(ctx) ast_compound_statement(false, $2); 2562 $$->set_location_range(@1, @3); 2563 } 2564 ; 2565 2566statement_list: 2567 statement 2568 { 2569 if ($1 == NULL) { 2570 _mesa_glsl_error(& @1, state, "<nil> statement"); 2571 assert($1 != NULL); 2572 } 2573 2574 $$ = $1; 2575 $$->link.self_link(); 2576 } 2577 | statement_list statement 2578 { 2579 if ($2 == NULL) { 2580 _mesa_glsl_error(& @2, state, "<nil> statement"); 2581 assert($2 != NULL); 2582 } 2583 $$ = $1; 2584 $$->link.insert_before(& $2->link); 2585 } 2586 | statement_list extension_statement 2587 { 2588 if (!state->allow_extension_directive_midshader) { 2589 _mesa_glsl_error(& @1, state, 2590 "#extension directive is not allowed " 2591 "in the middle of a shader"); 2592 YYERROR; 2593 } 2594 } 2595 ; 2596 2597expression_statement: 2598 ';' 2599 { 2600 void *ctx = state->linalloc; 2601 $$ = new(ctx) ast_expression_statement(NULL); 2602 $$->set_location(@1); 2603 } 2604 | expression ';' 2605 { 2606 void *ctx = state->linalloc; 2607 $$ = new(ctx) ast_expression_statement($1); 2608 $$->set_location(@1); 2609 } 2610 ; 2611 2612selection_statement: 2613 IF '(' expression ')' selection_rest_statement 2614 { 2615 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement, 2616 $5.else_statement); 2617 $$->set_location_range(@1, @5); 2618 } 2619 ; 2620 2621selection_rest_statement: 2622 statement ELSE statement 2623 { 2624 $$.then_statement = $1; 2625 $$.else_statement = $3; 2626 } 2627 | statement %prec THEN 2628 { 2629 $$.then_statement = $1; 2630 $$.else_statement = NULL; 2631 } 2632 ; 2633 2634condition: 2635 expression 2636 { 2637 $$ = (ast_node *) $1; 2638 } 2639 | fully_specified_type any_identifier '=' initializer 2640 { 2641 void *ctx = state->linalloc; 2642 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4); 2643 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1); 2644 decl->set_location_range(@2, @4); 2645 declarator->set_location(@1); 2646 2647 declarator->declarations.push_tail(&decl->link); 2648 $$ = declarator; 2649 } 2650 ; 2651 2652/* 2653 * switch_statement grammar is based on the syntax described in the body 2654 * of the GLSL spec, not in it's appendix!!! 2655 */ 2656switch_statement: 2657 SWITCH '(' expression ')' switch_body 2658 { 2659 $$ = new(state->linalloc) ast_switch_statement($3, $5); 2660 $$->set_location_range(@1, @5); 2661 } 2662 ; 2663 2664switch_body: 2665 '{' '}' 2666 { 2667 $$ = new(state->linalloc) ast_switch_body(NULL); 2668 $$->set_location_range(@1, @2); 2669 } 2670 | '{' case_statement_list '}' 2671 { 2672 $$ = new(state->linalloc) ast_switch_body($2); 2673 $$->set_location_range(@1, @3); 2674 } 2675 ; 2676 2677case_label: 2678 CASE expression ':' 2679 { 2680 $$ = new(state->linalloc) ast_case_label($2); 2681 $$->set_location(@2); 2682 } 2683 | DEFAULT ':' 2684 { 2685 $$ = new(state->linalloc) ast_case_label(NULL); 2686 $$->set_location(@2); 2687 } 2688 ; 2689 2690case_label_list: 2691 case_label 2692 { 2693 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list(); 2694 2695 labels->labels.push_tail(& $1->link); 2696 $$ = labels; 2697 $$->set_location(@1); 2698 } 2699 | case_label_list case_label 2700 { 2701 $$ = $1; 2702 $$->labels.push_tail(& $2->link); 2703 } 2704 ; 2705 2706case_statement: 2707 case_label_list statement 2708 { 2709 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1); 2710 stmts->set_location(@2); 2711 2712 stmts->stmts.push_tail(& $2->link); 2713 $$ = stmts; 2714 } 2715 | case_statement statement 2716 { 2717 $$ = $1; 2718 $$->stmts.push_tail(& $2->link); 2719 } 2720 ; 2721 2722case_statement_list: 2723 case_statement 2724 { 2725 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list(); 2726 cases->set_location(@1); 2727 2728 cases->cases.push_tail(& $1->link); 2729 $$ = cases; 2730 } 2731 | case_statement_list case_statement 2732 { 2733 $$ = $1; 2734 $$->cases.push_tail(& $2->link); 2735 } 2736 ; 2737 2738iteration_statement: 2739 WHILE '(' condition ')' statement_no_new_scope 2740 { 2741 void *ctx = state->linalloc; 2742 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while, 2743 NULL, $3, NULL, $5); 2744 $$->set_location_range(@1, @4); 2745 } 2746 | DO statement WHILE '(' expression ')' ';' 2747 { 2748 void *ctx = state->linalloc; 2749 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while, 2750 NULL, $5, NULL, $2); 2751 $$->set_location_range(@1, @6); 2752 } 2753 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope 2754 { 2755 void *ctx = state->linalloc; 2756 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for, 2757 $3, $4.cond, $4.rest, $6); 2758 $$->set_location_range(@1, @6); 2759 } 2760 ; 2761 2762for_init_statement: 2763 expression_statement 2764 | declaration_statement 2765 ; 2766 2767conditionopt: 2768 condition 2769 | /* empty */ 2770 { 2771 $$ = NULL; 2772 } 2773 ; 2774 2775for_rest_statement: 2776 conditionopt ';' 2777 { 2778 $$.cond = $1; 2779 $$.rest = NULL; 2780 } 2781 | conditionopt ';' expression 2782 { 2783 $$.cond = $1; 2784 $$.rest = $3; 2785 } 2786 ; 2787 2788 // Grammar Note: No 'goto'. Gotos are not supported. 2789jump_statement: 2790 CONTINUE ';' 2791 { 2792 void *ctx = state->linalloc; 2793 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL); 2794 $$->set_location(@1); 2795 } 2796 | BREAK ';' 2797 { 2798 void *ctx = state->linalloc; 2799 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL); 2800 $$->set_location(@1); 2801 } 2802 | RETURN ';' 2803 { 2804 void *ctx = state->linalloc; 2805 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL); 2806 $$->set_location(@1); 2807 } 2808 | RETURN expression ';' 2809 { 2810 void *ctx = state->linalloc; 2811 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2); 2812 $$->set_location_range(@1, @2); 2813 } 2814 | DISCARD ';' // Fragment shader only. 2815 { 2816 void *ctx = state->linalloc; 2817 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL); 2818 $$->set_location(@1); 2819 } 2820 ; 2821 2822demote_statement: 2823 DEMOTE ';' 2824 { 2825 void *ctx = state->linalloc; 2826 $$ = new(ctx) ast_demote_statement(); 2827 $$->set_location(@1); 2828 } 2829 ; 2830 2831external_declaration: 2832 function_definition { $$ = $1; } 2833 | declaration { $$ = $1; } 2834 | pragma_statement { $$ = $1; } 2835 | layout_defaults { $$ = $1; } 2836 | ';' { $$ = NULL; } 2837 ; 2838 2839function_definition: 2840 function_prototype compound_statement_no_new_scope 2841 { 2842 void *ctx = state->linalloc; 2843 $$ = new(ctx) ast_function_definition(); 2844 $$->set_location_range(@1, @2); 2845 $$->prototype = $1; 2846 $$->body = $2; 2847 2848 state->symbols->pop_scope(); 2849 } 2850 ; 2851 2852/* layout_qualifieropt is packed into this rule */ 2853interface_block: 2854 basic_interface_block 2855 { 2856 $$ = $1; 2857 } 2858 | layout_qualifier interface_block 2859 { 2860 ast_interface_block *block = (ast_interface_block *) $2; 2861 2862 if (!$1.merge_qualifier(& @1, state, block->layout, false, 2863 block->layout.has_layout())) { 2864 YYERROR; 2865 } 2866 2867 block->layout = $1; 2868 2869 $$ = block; 2870 } 2871 | memory_qualifier interface_block 2872 { 2873 ast_interface_block *block = (ast_interface_block *)$2; 2874 2875 if (!block->default_layout.flags.q.buffer) { 2876 _mesa_glsl_error(& @1, state, 2877 "memory qualifiers can only be used in the " 2878 "declaration of shader storage blocks"); 2879 } 2880 if (!$1.merge_qualifier(& @1, state, block->layout, false)) { 2881 YYERROR; 2882 } 2883 block->layout = $1; 2884 $$ = block; 2885 } 2886 ; 2887 2888basic_interface_block: 2889 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';' 2890 { 2891 ast_interface_block *const block = $6; 2892 2893 if ($1.flags.q.uniform) { 2894 block->default_layout = *state->default_uniform_qualifier; 2895 } else if ($1.flags.q.buffer) { 2896 block->default_layout = *state->default_shader_storage_qualifier; 2897 } 2898 block->block_name = $2; 2899 block->declarations.push_degenerate_list_at_head(& $4->link); 2900 2901 _mesa_ast_process_interface_block(& @1, state, block, $1); 2902 2903 $$ = block; 2904 } 2905 ; 2906 2907interface_qualifier: 2908 IN_TOK 2909 { 2910 memset(& $$, 0, sizeof($$)); 2911 $$.flags.q.in = 1; 2912 } 2913 | OUT_TOK 2914 { 2915 memset(& $$, 0, sizeof($$)); 2916 $$.flags.q.out = 1; 2917 } 2918 | UNIFORM 2919 { 2920 memset(& $$, 0, sizeof($$)); 2921 $$.flags.q.uniform = 1; 2922 } 2923 | BUFFER 2924 { 2925 memset(& $$, 0, sizeof($$)); 2926 $$.flags.q.buffer = 1; 2927 } 2928 | auxiliary_storage_qualifier interface_qualifier 2929 { 2930 if (!$1.flags.q.patch) { 2931 _mesa_glsl_error(&@1, state, "invalid interface qualifier"); 2932 } 2933 if ($2.has_auxiliary_storage()) { 2934 _mesa_glsl_error(&@1, state, "duplicate patch qualifier"); 2935 } 2936 $$ = $2; 2937 $$.flags.q.patch = 1; 2938 } 2939 ; 2940 2941instance_name_opt: 2942 /* empty */ 2943 { 2944 $$ = new(state->linalloc) ast_interface_block(NULL, NULL); 2945 } 2946 | NEW_IDENTIFIER 2947 { 2948 $$ = new(state->linalloc) ast_interface_block($1, NULL); 2949 $$->set_location(@1); 2950 } 2951 | NEW_IDENTIFIER array_specifier 2952 { 2953 $$ = new(state->linalloc) ast_interface_block($1, $2); 2954 $$->set_location_range(@1, @2); 2955 } 2956 ; 2957 2958member_list: 2959 member_declaration 2960 { 2961 $$ = $1; 2962 $1->link.self_link(); 2963 } 2964 | member_declaration member_list 2965 { 2966 $$ = $1; 2967 $2->link.insert_before(& $$->link); 2968 } 2969 ; 2970 2971member_declaration: 2972 fully_specified_type struct_declarator_list ';' 2973 { 2974 void *ctx = state->linalloc; 2975 ast_fully_specified_type *type = $1; 2976 type->set_location(@1); 2977 2978 if (type->qualifier.flags.q.attribute) { 2979 _mesa_glsl_error(& @1, state, 2980 "keyword 'attribute' cannot be used with " 2981 "interface block member"); 2982 } else if (type->qualifier.flags.q.varying) { 2983 _mesa_glsl_error(& @1, state, 2984 "keyword 'varying' cannot be used with " 2985 "interface block member"); 2986 } 2987 2988 $$ = new(ctx) ast_declarator_list(type); 2989 $$->set_location(@2); 2990 2991 $$->declarations.push_degenerate_list_at_head(& $2->link); 2992 } 2993 ; 2994 2995layout_uniform_defaults: 2996 layout_qualifier layout_uniform_defaults 2997 { 2998 $$ = $1; 2999 if (!$$.merge_qualifier(& @1, state, $2, false, true)) { 3000 YYERROR; 3001 } 3002 } 3003 | layout_qualifier UNIFORM ';' 3004 ; 3005 3006layout_buffer_defaults: 3007 layout_qualifier layout_buffer_defaults 3008 { 3009 $$ = $1; 3010 if (!$$.merge_qualifier(& @1, state, $2, false, true)) { 3011 YYERROR; 3012 } 3013 } 3014 | layout_qualifier BUFFER ';' 3015 ; 3016 3017layout_in_defaults: 3018 layout_qualifier layout_in_defaults 3019 { 3020 $$ = $1; 3021 if (!$$.merge_qualifier(& @1, state, $2, false, true)) { 3022 YYERROR; 3023 } 3024 if (!$$.validate_in_qualifier(& @1, state)) { 3025 YYERROR; 3026 } 3027 } 3028 | layout_qualifier IN_TOK ';' 3029 { 3030 if (!$1.validate_in_qualifier(& @1, state)) { 3031 YYERROR; 3032 } 3033 } 3034 ; 3035 3036layout_out_defaults: 3037 layout_qualifier layout_out_defaults 3038 { 3039 $$ = $1; 3040 if (!$$.merge_qualifier(& @1, state, $2, false, true)) { 3041 YYERROR; 3042 } 3043 if (!$$.validate_out_qualifier(& @1, state)) { 3044 YYERROR; 3045 } 3046 } 3047 | layout_qualifier OUT_TOK ';' 3048 { 3049 if (!$1.validate_out_qualifier(& @1, state)) { 3050 YYERROR; 3051 } 3052 } 3053 ; 3054 3055layout_defaults: 3056 layout_uniform_defaults 3057 { 3058 $$ = NULL; 3059 if (!state->default_uniform_qualifier-> 3060 merge_qualifier(& @1, state, $1, false)) { 3061 YYERROR; 3062 } 3063 if (!state->default_uniform_qualifier-> 3064 push_to_global(& @1, state)) { 3065 YYERROR; 3066 } 3067 } 3068 | layout_buffer_defaults 3069 { 3070 $$ = NULL; 3071 if (!state->default_shader_storage_qualifier-> 3072 merge_qualifier(& @1, state, $1, false)) { 3073 YYERROR; 3074 } 3075 if (!state->default_shader_storage_qualifier-> 3076 push_to_global(& @1, state)) { 3077 YYERROR; 3078 } 3079 3080 /* From the GLSL 4.50 spec, section 4.4.5: 3081 * 3082 * "It is a compile-time error to specify the binding identifier for 3083 * the global scope or for block member declarations." 3084 */ 3085 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) { 3086 _mesa_glsl_error(& @1, state, 3087 "binding qualifier cannot be set for default layout"); 3088 } 3089 } 3090 | layout_in_defaults 3091 { 3092 $$ = NULL; 3093 if (!$1.merge_into_in_qualifier(& @1, state, $$)) { 3094 YYERROR; 3095 } 3096 if (!state->in_qualifier->push_to_global(& @1, state)) { 3097 YYERROR; 3098 } 3099 } 3100 | layout_out_defaults 3101 { 3102 $$ = NULL; 3103 if (!$1.merge_into_out_qualifier(& @1, state, $$)) { 3104 YYERROR; 3105 } 3106 if (!state->out_qualifier->push_to_global(& @1, state)) { 3107 YYERROR; 3108 } 3109 } 3110 ; 3111