3 * Copyright © 2008, 2009 Intel Corporation
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:
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
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.
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"
40 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
45 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
47 _mesa_glsl_error(loc, st, "%s", msg);
51 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
53 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
56 static bool match_layout_qualifier(const char *s1, const char *s2,
57 _mesa_glsl_parse_state *state)
59 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
61 * "The tokens in any layout-qualifier-id-list ... are not case
62 * sensitive, unless explicitly noted otherwise."
64 * The text "unless explicitly noted otherwise" appears to be
65 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
68 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
71 * "As for other identifiers, they are case sensitive."
73 * So we need to do a case-sensitive or a case-insensitive match,
74 * depending on whether we are compiling for GLSL ES.
77 return strcmp(s1, s2);
79 return strcasecmp(s1, s2);
98 %lex-param {struct _mesa_glsl_parse_state *state}
99 %parse-param {struct _mesa_glsl_parse_state *state}
106 const char *identifier;
108 struct ast_type_qualifier type_qualifier;
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;
131 ast_expression *rest;
132 } for_rest_statement;
135 ast_node *then_statement;
136 ast_node *else_statement;
137 } selection_rest_statement;
139 const glsl_type *type;
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
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
164 %token INVARIANT PRECISE
165 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
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
174 /* Reserved words that are not actually used in the grammar.
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
181 %token SIZEOF CAST NAMESPACE USING
182 %token RESOURCE PATCH
187 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
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
294 version_statement extension_statement_list
296 _mesa_glsl_initialize_types(state);
298 external_declaration_list
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);
306 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
307 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
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);
314 _mesa_glsl_initialize_types(state);
319 /* blank - no #version specified: defaults are already set */
320 | VERSION_TOK INTCONSTANT EOL
322 state->process_version_directive(&@2, $2, NULL);
327 | VERSION_TOK INTCONSTANT any_identifier EOL
329 state->process_version_directive(&@2, $2, $3);
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
343 /* Pragma invariant(all) cannot be used in a fragment shader.
345 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
347 * "It is an error to use this pragma in a fragment shader."
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());
360 state->all_invariant = true;
365 | PRAGMA_WARNING_ON EOL
367 void *mem_ctx = state->linalloc;
368 $$ = new(mem_ctx) ast_warnings_toggle(true);
370 | PRAGMA_WARNING_OFF EOL
372 void *mem_ctx = state->linalloc;
373 $$ = new(mem_ctx) ast_warnings_toggle(false);
377 extension_statement_list:
379 | extension_statement_list extension_statement
389 EXTENSION any_identifier COLON any_identifier EOL
391 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
397 external_declaration_list:
400 /* FINISHME: The NULL test is required because pragmas are set to
401 * FINISHME: NULL. (See production rule for external_declaration.)
404 state->translation_unit.push_tail(& $1->link);
406 | external_declaration_list external_declaration
408 /* FINISHME: The NULL test is required because pragmas are set to
409 * FINISHME: NULL. (See production rule for external_declaration.)
412 state->translation_unit.push_tail(& $2->link);
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");
432 void *ctx = state->linalloc;
433 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
434 $$->set_location(@1);
435 $$->primary_expression.identifier = $1;
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;
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;
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;
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;
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;
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;
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;
494 | postfix_expression '[' integer_expression ']'
496 void *ctx = state->linalloc;
497 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
498 $$->set_location_range(@1, @4);
504 | postfix_expression DOT_TOK FIELD_SELECTION
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;
511 | postfix_expression INC_OP
513 void *ctx = state->linalloc;
514 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
515 $$->set_location_range(@1, @2);
517 | postfix_expression DEC_OP
519 void *ctx = state->linalloc;
520 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
521 $$->set_location_range(@1, @2);
530 function_call_or_method
533 function_call_or_method:
534 function_call_generic
537 function_call_generic:
538 function_call_header_with_parameters ')'
539 | function_call_header_no_parameters ')'
542 function_call_header_no_parameters:
543 function_call_header VOID_TOK
544 | function_call_header
547 function_call_header_with_parameters:
548 function_call_header assignment_expression
551 $$->set_location(@1);
552 $$->expressions.push_tail(& $2->link);
554 | function_call_header_with_parameters ',' assignment_expression
557 $$->set_location(@1);
558 $$->expressions.push_tail(& $3->link);
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".
565 function_call_header:
566 function_identifier '('
572 void *ctx = state->linalloc;
573 $$ = new(ctx) ast_function_expression($1);
574 $$->set_location(@1);
578 void *ctx = state->linalloc;
579 $$ = new(ctx) ast_function_expression($1);
580 $$->set_location(@1);
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".
588 // Grammar Note: No traditional style type casts.
591 | INC_OP unary_expression
593 void *ctx = state->linalloc;
594 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
595 $$->set_location(@1);
597 | DEC_OP unary_expression
599 void *ctx = state->linalloc;
600 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
601 $$->set_location(@1);
603 | unary_operator unary_expression
605 void *ctx = state->linalloc;
606 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
607 $$->set_location_range(@1, @2);
611 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
613 '+' { $$ = ast_plus; }
614 | '-' { $$ = ast_neg; }
615 | '!' { $$ = ast_logic_not; }
616 | '~' { $$ = ast_bit_not; }
619 multiplicative_expression:
621 | multiplicative_expression '*' unary_expression
623 void *ctx = state->linalloc;
624 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
625 $$->set_location_range(@1, @3);
627 | multiplicative_expression '/' unary_expression
629 void *ctx = state->linalloc;
630 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
631 $$->set_location_range(@1, @3);
633 | multiplicative_expression '%' unary_expression
635 void *ctx = state->linalloc;
636 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
637 $$->set_location_range(@1, @3);
642 multiplicative_expression
643 | additive_expression '+' multiplicative_expression
645 void *ctx = state->linalloc;
646 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
647 $$->set_location_range(@1, @3);
649 | additive_expression '-' multiplicative_expression
651 void *ctx = state->linalloc;
652 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
653 $$->set_location_range(@1, @3);
659 | shift_expression LEFT_OP additive_expression
661 void *ctx = state->linalloc;
662 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
663 $$->set_location_range(@1, @3);
665 | shift_expression RIGHT_OP additive_expression
667 void *ctx = state->linalloc;
668 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
669 $$->set_location_range(@1, @3);
673 relational_expression:
675 | relational_expression '<' shift_expression
677 void *ctx = state->linalloc;
678 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
679 $$->set_location_range(@1, @3);
681 | relational_expression '>' shift_expression
683 void *ctx = state->linalloc;
684 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
685 $$->set_location_range(@1, @3);
687 | relational_expression LE_OP shift_expression
689 void *ctx = state->linalloc;
690 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
691 $$->set_location_range(@1, @3);
693 | relational_expression GE_OP shift_expression
695 void *ctx = state->linalloc;
696 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
697 $$->set_location_range(@1, @3);
702 relational_expression
703 | equality_expression EQ_OP relational_expression
705 void *ctx = state->linalloc;
706 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
707 $$->set_location_range(@1, @3);
709 | equality_expression NE_OP relational_expression
711 void *ctx = state->linalloc;
712 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
713 $$->set_location_range(@1, @3);
719 | and_expression '&' equality_expression
721 void *ctx = state->linalloc;
722 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
723 $$->set_location_range(@1, @3);
727 exclusive_or_expression:
729 | exclusive_or_expression '^' and_expression
731 void *ctx = state->linalloc;
732 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
733 $$->set_location_range(@1, @3);
737 inclusive_or_expression:
738 exclusive_or_expression
739 | inclusive_or_expression '|' exclusive_or_expression
741 void *ctx = state->linalloc;
742 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
743 $$->set_location_range(@1, @3);
747 logical_and_expression:
748 inclusive_or_expression
749 | logical_and_expression AND_OP inclusive_or_expression
751 void *ctx = state->linalloc;
752 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
753 $$->set_location_range(@1, @3);
757 logical_xor_expression:
758 logical_and_expression
759 | logical_xor_expression XOR_OP logical_and_expression
761 void *ctx = state->linalloc;
762 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
763 $$->set_location_range(@1, @3);
767 logical_or_expression:
768 logical_xor_expression
769 | logical_or_expression OR_OP logical_xor_expression
771 void *ctx = state->linalloc;
772 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
773 $$->set_location_range(@1, @3);
777 conditional_expression:
778 logical_or_expression
779 | logical_or_expression '?' expression ':' assignment_expression
781 void *ctx = state->linalloc;
782 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
783 $$->set_location_range(@1, @5);
787 assignment_expression:
788 conditional_expression
789 | unary_expression assignment_operator assignment_expression
791 void *ctx = state->linalloc;
792 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
793 $$->set_location_range(@1, @3);
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; }
812 assignment_expression
816 | expression ',' assignment_expression
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);
827 $$->expressions.push_tail(& $3->link);
832 conditional_expression
836 function_prototype ';'
838 state->symbols->pop_scope();
841 | init_declarator_list ';'
845 | PRECISION precision_qualifier type_specifier ';'
847 $3->default_precision = $2;
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)) {
858 block->layout = block->default_layout;
859 if (!block->layout.push_to_global(& @1, state)) {
867 function_declarator ')'
872 | function_header_with_parameters
875 function_header_with_parameters:
876 function_header parameter_declaration
879 $$->parameters.push_tail(& $2->link);
881 | function_header_with_parameters ',' parameter_declaration
884 $$->parameters.push_tail(& $3->link);
889 fully_specified_type variable_identifier '('
891 void *ctx = state->linalloc;
892 $$ = new(ctx) ast_function();
893 $$->set_location(@2);
894 $$->return_type = $1;
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));
901 state->symbols->add_function(new(state) ir_function($2));
902 state->symbols->push_scope();
906 parameter_declarator:
907 type_specifier any_identifier
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;
916 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
918 | layout_qualifier type_specifier any_identifier
920 if (state->allow_layout_qualifier_on_function_parameter) {
921 void *ctx = state->linalloc;
922 $$ = new(ctx) ast_parameter_declarator();
923 $$->set_location_range(@2, @3);
924 $$->type = new(ctx) ast_fully_specified_type();
925 $$->type->set_location(@2);
926 $$->type->specifier = $2;
928 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
930 _mesa_glsl_error(&@1, state,
931 "is is not allowed on function parameter");
935 | type_specifier any_identifier array_specifier
937 void *ctx = state->linalloc;
938 $$ = new(ctx) ast_parameter_declarator();
939 $$->set_location_range(@1, @3);
940 $$->type = new(ctx) ast_fully_specified_type();
941 $$->type->set_location(@1);
942 $$->type->specifier = $1;
944 $$->array_specifier = $3;
945 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
949 parameter_declaration:
950 parameter_qualifier parameter_declarator
953 $$->type->qualifier = $1;
954 if (!$$->type->qualifier.push_to_global(& @1, state)) {
958 | parameter_qualifier parameter_type_specifier
960 void *ctx = state->linalloc;
961 $$ = new(ctx) ast_parameter_declarator();
962 $$->set_location(@2);
963 $$->type = new(ctx) ast_fully_specified_type();
964 $$->type->set_location_range(@1, @2);
965 $$->type->qualifier = $1;
966 if (!$$->type->qualifier.push_to_global(& @1, state)) {
969 $$->type->specifier = $2;
976 memset(& $$, 0, sizeof($$));
978 | CONST_TOK parameter_qualifier
980 if ($2.flags.q.constant)
981 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
984 $$.flags.q.constant = 1;
986 | PRECISE parameter_qualifier
988 if ($2.flags.q.precise)
989 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
992 $$.flags.q.precise = 1;
994 | parameter_direction_qualifier parameter_qualifier
996 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
997 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
999 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
1000 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
1004 $$.merge_qualifier(&@1, state, $2, false);
1006 | precision_qualifier parameter_qualifier
1008 if ($2.precision != ast_precision_none)
1009 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1011 if (!state->has_420pack_or_es31() &&
1013 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1018 | memory_qualifier parameter_qualifier
1021 $$.merge_qualifier(&@1, state, $2, false);
1024 parameter_direction_qualifier:
1027 memset(& $$, 0, sizeof($$));
1032 memset(& $$, 0, sizeof($$));
1037 memset(& $$, 0, sizeof($$));
1043 parameter_type_specifier:
1047 init_declarator_list:
1049 | init_declarator_list ',' any_identifier
1051 void *ctx = state->linalloc;
1052 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1053 decl->set_location(@3);
1056 $$->declarations.push_tail(&decl->link);
1057 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1059 | init_declarator_list ',' any_identifier array_specifier
1061 void *ctx = state->linalloc;
1062 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1063 decl->set_location_range(@3, @4);
1066 $$->declarations.push_tail(&decl->link);
1067 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1069 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1071 void *ctx = state->linalloc;
1072 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1073 decl->set_location_range(@3, @4);
1076 $$->declarations.push_tail(&decl->link);
1077 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1079 | init_declarator_list ',' any_identifier '=' initializer
1081 void *ctx = state->linalloc;
1082 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1083 decl->set_location(@3);
1086 $$->declarations.push_tail(&decl->link);
1087 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1091 // Grammar Note: No 'enum', or 'typedef'.
1093 fully_specified_type
1095 void *ctx = state->linalloc;
1096 /* Empty declaration list is valid. */
1097 $$ = new(ctx) ast_declarator_list($1);
1098 $$->set_location(@1);
1100 | fully_specified_type any_identifier
1102 void *ctx = state->linalloc;
1103 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1104 decl->set_location(@2);
1106 $$ = new(ctx) ast_declarator_list($1);
1107 $$->set_location_range(@1, @2);
1108 $$->declarations.push_tail(&decl->link);
1109 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1111 | fully_specified_type any_identifier array_specifier
1113 void *ctx = state->linalloc;
1114 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1115 decl->set_location_range(@2, @3);
1117 $$ = new(ctx) ast_declarator_list($1);
1118 $$->set_location_range(@1, @3);
1119 $$->declarations.push_tail(&decl->link);
1120 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1122 | fully_specified_type any_identifier array_specifier '=' initializer
1124 void *ctx = state->linalloc;
1125 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1126 decl->set_location_range(@2, @3);
1128 $$ = new(ctx) ast_declarator_list($1);
1129 $$->set_location_range(@1, @3);
1130 $$->declarations.push_tail(&decl->link);
1131 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1133 | fully_specified_type any_identifier '=' initializer
1135 void *ctx = state->linalloc;
1136 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1137 decl->set_location(@2);
1139 $$ = new(ctx) ast_declarator_list($1);
1140 $$->set_location_range(@1, @2);
1141 $$->declarations.push_tail(&decl->link);
1142 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1144 | INVARIANT variable_identifier
1146 void *ctx = state->linalloc;
1147 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1148 decl->set_location(@2);
1150 $$ = new(ctx) ast_declarator_list(NULL);
1151 $$->set_location_range(@1, @2);
1152 $$->invariant = true;
1154 $$->declarations.push_tail(&decl->link);
1156 | PRECISE variable_identifier
1158 void *ctx = state->linalloc;
1159 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1160 decl->set_location(@2);
1162 $$ = new(ctx) ast_declarator_list(NULL);
1163 $$->set_location_range(@1, @2);
1166 $$->declarations.push_tail(&decl->link);
1170 fully_specified_type:
1173 void *ctx = state->linalloc;
1174 $$ = new(ctx) ast_fully_specified_type();
1175 $$->set_location(@1);
1178 | type_qualifier type_specifier
1180 void *ctx = state->linalloc;
1181 $$ = new(ctx) ast_fully_specified_type();
1182 $$->set_location_range(@1, @2);
1184 if (!$$->qualifier.push_to_global(& @1, state)) {
1188 if ($$->specifier->structure != NULL &&
1189 $$->specifier->structure->is_declaration) {
1190 $$->specifier->structure->layout = &$$->qualifier;
1196 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1202 layout_qualifier_id_list:
1204 | layout_qualifier_id_list ',' layout_qualifier_id
1207 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1213 layout_qualifier_id:
1216 memset(& $$, 0, sizeof($$));
1218 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1219 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1220 state->is_version(150, 0))) {
1221 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1222 $$.flags.q.origin_upper_left = 1;
1223 } else if (match_layout_qualifier($1, "pixel_center_integer",
1225 $$.flags.q.pixel_center_integer = 1;
1228 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1229 _mesa_glsl_warning(& @1, state,
1230 "GL_ARB_fragment_coord_conventions layout "
1231 "identifier `%s' used", $1);
1235 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1237 (state->AMD_conservative_depth_enable ||
1238 state->ARB_conservative_depth_enable ||
1239 state->is_version(420, 0))) {
1240 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1241 $$.flags.q.depth_type = 1;
1242 $$.depth_type = ast_depth_any;
1243 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1244 $$.flags.q.depth_type = 1;
1245 $$.depth_type = ast_depth_greater;
1246 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1247 $$.flags.q.depth_type = 1;
1248 $$.depth_type = ast_depth_less;
1249 } else if (match_layout_qualifier($1, "depth_unchanged",
1251 $$.flags.q.depth_type = 1;
1252 $$.depth_type = ast_depth_unchanged;
1255 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1256 _mesa_glsl_warning(& @1, state,
1257 "GL_AMD_conservative_depth "
1258 "layout qualifier `%s' is used", $1);
1260 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1261 _mesa_glsl_warning(& @1, state,
1262 "GL_ARB_conservative_depth "
1263 "layout qualifier `%s' is used", $1);
1267 /* See also interface_block_layout_qualifier. */
1268 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1269 if (match_layout_qualifier($1, "std140", state) == 0) {
1270 $$.flags.q.std140 = 1;
1271 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1272 $$.flags.q.shared = 1;
1273 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1274 $$.flags.q.std430 = 1;
1275 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1276 $$.flags.q.column_major = 1;
1277 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1278 * below in the interface_block_layout_qualifier rule.
1280 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1283 * Also, this takes care of alternate capitalizations of
1284 * "row_major" (which is necessary because layout qualifiers
1285 * are case-insensitive in desktop GLSL).
1287 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1288 $$.flags.q.row_major = 1;
1289 /* "packed" is a reserved word in GLSL, and its token is
1290 * parsed below in the interface_block_layout_qualifier rule.
1291 * However, we must take care of alternate capitalizations of
1292 * "packed", because layout qualifiers are case-insensitive
1295 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1296 $$.flags.q.packed = 1;
1299 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1300 _mesa_glsl_warning(& @1, state,
1301 "#version 140 / GL_ARB_uniform_buffer_object "
1302 "layout qualifier `%s' is used", $1);
1306 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1308 static const struct {
1312 { "points", GL_POINTS },
1313 { "lines", GL_LINES },
1314 { "lines_adjacency", GL_LINES_ADJACENCY },
1315 { "line_strip", GL_LINE_STRIP },
1316 { "triangles", GL_TRIANGLES },
1317 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1318 { "triangle_strip", GL_TRIANGLE_STRIP },
1320 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1321 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1322 $$.flags.q.prim_type = 1;
1323 $$.prim_type = map[i].e;
1328 if ($$.flags.i && !state->has_geometry_shader() &&
1329 !state->has_tessellation_shader()) {
1330 _mesa_glsl_error(& @1, state, "#version 150 layout "
1331 "qualifier `%s' used", $1);
1335 /* Layout qualifiers for ARB_shader_image_load_store. */
1336 if (state->has_shader_image_load_store()) {
1338 static const struct {
1340 enum pipe_format format;
1341 glsl_base_type base_type;
1342 /** Minimum desktop GLSL version required for the image
1343 * format. Use 130 if already present in the original
1346 unsigned required_glsl;
1347 /** Minimum GLSL ES version required for the image format. */
1348 unsigned required_essl;
1349 /* NV_image_formats */
1350 bool nv_image_formats;
1351 bool ext_qualifiers;
1353 { "rgba32f", PIPE_FORMAT_R32G32B32A32_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false },
1354 { "rgba16f", PIPE_FORMAT_R16G16B16A16_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false },
1355 { "rg32f", PIPE_FORMAT_R32G32_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
1356 { "rg16f", PIPE_FORMAT_R16G16_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
1357 { "r11f_g11f_b10f", PIPE_FORMAT_R11G11B10_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
1358 { "r32f", PIPE_FORMAT_R32_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false },
1359 { "r16f", PIPE_FORMAT_R16_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
1360 { "rgba32ui", PIPE_FORMAT_R32G32B32A32_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
1361 { "rgba16ui", PIPE_FORMAT_R16G16B16A16_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
1362 { "rgb10_a2ui", PIPE_FORMAT_R10G10B10A2_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
1363 { "rgba8ui", PIPE_FORMAT_R8G8B8A8_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
1364 { "rg32ui", PIPE_FORMAT_R32G32_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
1365 { "rg16ui", PIPE_FORMAT_R16G16_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
1366 { "rg8ui", PIPE_FORMAT_R8G8_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
1367 { "r32ui", PIPE_FORMAT_R32_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
1368 { "r16ui", PIPE_FORMAT_R16_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
1369 { "r8ui", PIPE_FORMAT_R8_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
1370 { "rgba32i", PIPE_FORMAT_R32G32B32A32_SINT, GLSL_TYPE_INT, 130, 310, false, false },
1371 { "rgba16i", PIPE_FORMAT_R16G16B16A16_SINT, GLSL_TYPE_INT, 130, 310, false, false },
1372 { "rgba8i", PIPE_FORMAT_R8G8B8A8_SINT, GLSL_TYPE_INT, 130, 310, false, false },
1373 { "rg32i", PIPE_FORMAT_R32G32_SINT, GLSL_TYPE_INT, 130, 0, true, false },
1374 { "rg16i", PIPE_FORMAT_R16G16_SINT, GLSL_TYPE_INT, 130, 0, true, false },
1375 { "rg8i", PIPE_FORMAT_R8G8_SINT, GLSL_TYPE_INT, 130, 0, true, false },
1376 { "r32i", PIPE_FORMAT_R32_SINT, GLSL_TYPE_INT, 130, 310, false, false },
1377 { "r16i", PIPE_FORMAT_R16_SINT, GLSL_TYPE_INT, 130, 0, true, false },
1378 { "r8i", PIPE_FORMAT_R8_SINT, GLSL_TYPE_INT, 130, 0, true, false },
1379 { "rgba16", PIPE_FORMAT_R16G16B16A16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1380 { "rgb10_a2", PIPE_FORMAT_R10G10B10A2_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1381 { "rgba8", PIPE_FORMAT_R8G8B8A8_UNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
1382 { "rg16", PIPE_FORMAT_R16G16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1383 { "rg8", PIPE_FORMAT_R8G8_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1384 { "r16", PIPE_FORMAT_R16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1385 { "r8", PIPE_FORMAT_R8_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1386 { "rgba16_snorm", PIPE_FORMAT_R16G16B16A16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1387 { "rgba8_snorm", PIPE_FORMAT_R8G8B8A8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
1388 { "rg16_snorm", PIPE_FORMAT_R16G16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1389 { "rg8_snorm", PIPE_FORMAT_R8G8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1390 { "r16_snorm", PIPE_FORMAT_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1391 { "r8_snorm", PIPE_FORMAT_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1393 /* From GL_EXT_shader_image_load_store: */
1394 /* base_type is incorrect but it'll be patched later when we know
1395 * the variable type. See ast_to_hir.cpp */
1396 { "size1x8", PIPE_FORMAT_R8_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
1397 { "size1x16", PIPE_FORMAT_R16_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
1398 { "size1x32", PIPE_FORMAT_R32_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
1399 { "size2x32", PIPE_FORMAT_R32G32_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
1400 { "size4x32", PIPE_FORMAT_R32G32B32A32_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
1403 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1404 if ((state->is_version(map[i].required_glsl,
1405 map[i].required_essl) ||
1406 (state->NV_image_formats_enable &&
1407 map[i].nv_image_formats)) &&
1408 match_layout_qualifier($1, map[i].name, state) == 0) {
1409 /* Skip ARB_shader_image_load_store qualifiers if not enabled */
1410 if (!map[i].ext_qualifiers && !(state->ARB_shader_image_load_store_enable ||
1411 state->is_version(420, 310))) {
1414 /* Skip EXT_shader_image_load_store qualifiers if not enabled */
1415 if (map[i].ext_qualifiers && !state->EXT_shader_image_load_store_enable) {
1418 $$.flags.q.explicit_image_format = 1;
1419 $$.image_format = map[i].format;
1420 $$.image_base_type = map[i].base_type;
1428 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1429 /* From section 4.4.1.3 of the GLSL 4.50 specification
1430 * (Fragment Shader Inputs):
1432 * "Fragment shaders also allow the following layout
1433 * qualifier on in only (not with variable declarations)
1434 * layout-qualifier-id
1435 * early_fragment_tests
1438 if (state->stage != MESA_SHADER_FRAGMENT) {
1439 _mesa_glsl_error(& @1, state,
1440 "early_fragment_tests layout qualifier only "
1441 "valid in fragment shaders");
1444 $$.flags.q.early_fragment_tests = 1;
1447 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1448 if (state->stage != MESA_SHADER_FRAGMENT) {
1449 _mesa_glsl_error(& @1, state,
1450 "inner_coverage layout qualifier only "
1451 "valid in fragment shaders");
1454 if (state->INTEL_conservative_rasterization_enable) {
1455 $$.flags.q.inner_coverage = 1;
1457 _mesa_glsl_error(& @1, state,
1458 "inner_coverage layout qualifier present, "
1459 "but the INTEL_conservative_rasterization extension "
1464 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1465 if (state->stage != MESA_SHADER_FRAGMENT) {
1466 _mesa_glsl_error(& @1, state,
1467 "post_depth_coverage layout qualifier only "
1468 "valid in fragment shaders");
1471 if (state->ARB_post_depth_coverage_enable ||
1472 state->INTEL_conservative_rasterization_enable) {
1473 $$.flags.q.post_depth_coverage = 1;
1475 _mesa_glsl_error(& @1, state,
1476 "post_depth_coverage layout qualifier present, "
1477 "but the GL_ARB_post_depth_coverage extension "
1482 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1483 _mesa_glsl_error(& @1, state,
1484 "post_depth_coverage & inner_coverage layout qualifiers "
1485 "are mutually exclusive");
1489 const bool pixel_interlock_ordered = match_layout_qualifier($1,
1490 "pixel_interlock_ordered", state) == 0;
1491 const bool pixel_interlock_unordered = match_layout_qualifier($1,
1492 "pixel_interlock_unordered", state) == 0;
1493 const bool sample_interlock_ordered = match_layout_qualifier($1,
1494 "sample_interlock_ordered", state) == 0;
1495 const bool sample_interlock_unordered = match_layout_qualifier($1,
1496 "sample_interlock_unordered", state) == 0;
1498 if (pixel_interlock_ordered + pixel_interlock_unordered +
1499 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1500 state->stage != MESA_SHADER_FRAGMENT) {
1501 _mesa_glsl_error(& @1, state, "interlock layout qualifiers: "
1502 "pixel_interlock_ordered, pixel_interlock_unordered, "
1503 "sample_interlock_ordered and sample_interlock_unordered, "
1504 "only valid in fragment shader input layout declaration.");
1505 } else if (pixel_interlock_ordered + pixel_interlock_unordered +
1506 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1507 !state->ARB_fragment_shader_interlock_enable &&
1508 !state->NV_fragment_shader_interlock_enable) {
1509 _mesa_glsl_error(& @1, state,
1510 "interlock layout qualifier present, but the "
1511 "GL_ARB_fragment_shader_interlock or "
1512 "GL_NV_fragment_shader_interlock extension is not "
1515 $$.flags.q.pixel_interlock_ordered = pixel_interlock_ordered;
1516 $$.flags.q.pixel_interlock_unordered = pixel_interlock_unordered;
1517 $$.flags.q.sample_interlock_ordered = sample_interlock_ordered;
1518 $$.flags.q.sample_interlock_unordered = sample_interlock_unordered;
1521 /* Layout qualifiers for tessellation evaluation shaders. */
1523 static const struct {
1527 /* triangles already parsed by gs-specific code */
1528 { "quads", GL_QUADS },
1529 { "isolines", GL_ISOLINES },
1531 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1532 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1533 $$.flags.q.prim_type = 1;
1534 $$.prim_type = map[i].e;
1539 if ($$.flags.i && !state->has_tessellation_shader()) {
1540 _mesa_glsl_error(& @1, state,
1541 "primitive mode qualifier `%s' requires "
1542 "GLSL 4.00 or ARB_tessellation_shader", $1);
1546 static const struct {
1548 enum gl_tess_spacing e;
1550 { "equal_spacing", TESS_SPACING_EQUAL },
1551 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1552 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1554 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1555 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1556 $$.flags.q.vertex_spacing = 1;
1557 $$.vertex_spacing = map[i].e;
1562 if ($$.flags.i && !state->has_tessellation_shader()) {
1563 _mesa_glsl_error(& @1, state,
1564 "vertex spacing qualifier `%s' requires "
1565 "GLSL 4.00 or ARB_tessellation_shader", $1);
1569 if (match_layout_qualifier($1, "cw", state) == 0) {
1570 $$.flags.q.ordering = 1;
1571 $$.ordering = GL_CW;
1572 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1573 $$.flags.q.ordering = 1;
1574 $$.ordering = GL_CCW;
1577 if ($$.flags.i && !state->has_tessellation_shader()) {
1578 _mesa_glsl_error(& @1, state,
1579 "ordering qualifier `%s' requires "
1580 "GLSL 4.00 or ARB_tessellation_shader", $1);
1584 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1585 $$.flags.q.point_mode = 1;
1586 $$.point_mode = true;
1589 if ($$.flags.i && !state->has_tessellation_shader()) {
1590 _mesa_glsl_error(& @1, state,
1591 "qualifier `point_mode' requires "
1592 "GLSL 4.00 or ARB_tessellation_shader");
1597 static const struct {
1601 { "blend_support_multiply", BLEND_MULTIPLY },
1602 { "blend_support_screen", BLEND_SCREEN },
1603 { "blend_support_overlay", BLEND_OVERLAY },
1604 { "blend_support_darken", BLEND_DARKEN },
1605 { "blend_support_lighten", BLEND_LIGHTEN },
1606 { "blend_support_colordodge", BLEND_COLORDODGE },
1607 { "blend_support_colorburn", BLEND_COLORBURN },
1608 { "blend_support_hardlight", BLEND_HARDLIGHT },
1609 { "blend_support_softlight", BLEND_SOFTLIGHT },
1610 { "blend_support_difference", BLEND_DIFFERENCE },
1611 { "blend_support_exclusion", BLEND_EXCLUSION },
1612 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1613 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1614 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1615 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1616 { "blend_support_all_equations", BLEND_ALL },
1618 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1619 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1620 $$.flags.q.blend_support = 1;
1621 state->fs_blend_support |= map[i].mask;
1627 !state->KHR_blend_equation_advanced_enable &&
1628 !state->is_version(0, 320)) {
1629 _mesa_glsl_error(& @1, state,
1630 "advanced blending layout qualifiers require "
1631 "ESSL 3.20 or KHR_blend_equation_advanced");
1634 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1635 _mesa_glsl_error(& @1, state,
1636 "advanced blending layout qualifiers only "
1637 "valid in fragment shaders");
1641 /* Layout qualifiers for ARB_compute_variable_group_size. */
1643 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1644 $$.flags.q.local_size_variable = 1;
1647 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1648 _mesa_glsl_error(& @1, state,
1649 "qualifier `local_size_variable` requires "
1650 "ARB_compute_variable_group_size");
1654 /* Layout qualifiers for ARB_bindless_texture. */
1656 if (match_layout_qualifier($1, "bindless_sampler", state) == 0)
1657 $$.flags.q.bindless_sampler = 1;
1658 if (match_layout_qualifier($1, "bound_sampler", state) == 0)
1659 $$.flags.q.bound_sampler = 1;
1661 if (state->has_shader_image_load_store()) {
1662 if (match_layout_qualifier($1, "bindless_image", state) == 0)
1663 $$.flags.q.bindless_image = 1;
1664 if (match_layout_qualifier($1, "bound_image", state) == 0)
1665 $$.flags.q.bound_image = 1;
1668 if ($$.flags.i && !state->has_bindless()) {
1669 _mesa_glsl_error(& @1, state,
1670 "qualifier `%s` requires "
1671 "ARB_bindless_texture", $1);
1676 state->EXT_shader_framebuffer_fetch_non_coherent_enable) {
1677 if (match_layout_qualifier($1, "noncoherent", state) == 0)
1678 $$.flags.q.non_coherent = 1;
1681 // Layout qualifiers for NV_compute_shader_derivatives.
1683 if (match_layout_qualifier($1, "derivative_group_quadsNV", state) == 0) {
1684 $$.flags.q.derivative_group = 1;
1685 $$.derivative_group = DERIVATIVE_GROUP_QUADS;
1686 } else if (match_layout_qualifier($1, "derivative_group_linearNV", state) == 0) {
1687 $$.flags.q.derivative_group = 1;
1688 $$.derivative_group = DERIVATIVE_GROUP_LINEAR;
1692 if (!state->has_compute_shader()) {
1693 _mesa_glsl_error(& @1, state,
1694 "qualifier `%s' requires "
1695 "a compute shader", $1);
1698 if (!state->NV_compute_shader_derivatives_enable) {
1699 _mesa_glsl_error(& @1, state,
1700 "qualifier `%s' requires "
1701 "NV_compute_shader_derivatives", $1);
1704 if (state->NV_compute_shader_derivatives_warn) {
1705 _mesa_glsl_warning(& @1, state,
1706 "NV_compute_shader_derivatives layout "
1707 "qualifier `%s' used", $1);
1713 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1718 | any_identifier '=' constant_expression
1720 memset(& $$, 0, sizeof($$));
1721 void *ctx = state->linalloc;
1723 if ($3->oper != ast_int_constant &&
1724 $3->oper != ast_uint_constant &&
1725 !state->has_enhanced_layouts()) {
1726 _mesa_glsl_error(& @1, state,
1727 "compile-time constant expressions require "
1728 "GLSL 4.40 or ARB_enhanced_layouts");
1731 if (match_layout_qualifier("align", $1, state) == 0) {
1732 if (!state->has_enhanced_layouts()) {
1733 _mesa_glsl_error(& @1, state,
1734 "align qualifier requires "
1735 "GLSL 4.40 or ARB_enhanced_layouts");
1737 $$.flags.q.explicit_align = 1;
1742 if (match_layout_qualifier("location", $1, state) == 0) {
1743 $$.flags.q.explicit_location = 1;
1745 if ($$.flags.q.attribute == 1 &&
1746 state->ARB_explicit_attrib_location_warn) {
1747 _mesa_glsl_warning(& @1, state,
1748 "GL_ARB_explicit_attrib_location layout "
1749 "identifier `%s' used", $1);
1754 if (match_layout_qualifier("component", $1, state) == 0) {
1755 if (!state->has_enhanced_layouts()) {
1756 _mesa_glsl_error(& @1, state,
1757 "component qualifier requires "
1758 "GLSL 4.40 or ARB_enhanced_layouts");
1760 $$.flags.q.explicit_component = 1;
1765 if (match_layout_qualifier("index", $1, state) == 0) {
1766 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1767 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1771 $$.flags.q.explicit_index = 1;
1775 if ((state->has_420pack_or_es31() ||
1776 state->has_atomic_counters() ||
1777 state->has_shader_storage_buffer_objects()) &&
1778 match_layout_qualifier("binding", $1, state) == 0) {
1779 $$.flags.q.explicit_binding = 1;
1783 if ((state->has_atomic_counters() ||
1784 state->has_enhanced_layouts()) &&
1785 match_layout_qualifier("offset", $1, state) == 0) {
1786 $$.flags.q.explicit_offset = 1;
1790 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1791 $$.flags.q.max_vertices = 1;
1792 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1793 if (!state->has_geometry_shader()) {
1794 _mesa_glsl_error(& @3, state,
1795 "#version 150 max_vertices qualifier "
1800 if (state->stage == MESA_SHADER_GEOMETRY) {
1801 if (match_layout_qualifier("stream", $1, state) == 0 &&
1802 state->check_explicit_attrib_stream_allowed(& @3)) {
1803 $$.flags.q.stream = 1;
1804 $$.flags.q.explicit_stream = 1;
1809 if (state->has_enhanced_layouts()) {
1810 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1811 $$.flags.q.xfb_buffer = 1;
1812 $$.flags.q.explicit_xfb_buffer = 1;
1816 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1817 $$.flags.q.explicit_xfb_offset = 1;
1821 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1822 $$.flags.q.xfb_stride = 1;
1823 $$.flags.q.explicit_xfb_stride = 1;
1828 static const char * const local_size_qualifiers[3] = {
1833 for (int i = 0; i < 3; i++) {
1834 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1836 if (!state->has_compute_shader()) {
1837 _mesa_glsl_error(& @3, state,
1838 "%s qualifier requires GLSL 4.30 or "
1839 "GLSL ES 3.10 or ARB_compute_shader",
1840 local_size_qualifiers[i]);
1843 $$.flags.q.local_size |= (1 << i);
1844 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1850 if (match_layout_qualifier("invocations", $1, state) == 0) {
1851 $$.flags.q.invocations = 1;
1852 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1853 if (!state->is_version(400, 320) &&
1854 !state->ARB_gpu_shader5_enable &&
1855 !state->OES_geometry_shader_enable &&
1856 !state->EXT_geometry_shader_enable) {
1857 _mesa_glsl_error(& @3, state,
1858 "GL_ARB_gpu_shader5 invocations "
1859 "qualifier specified", $3);
1863 /* Layout qualifiers for tessellation control shaders. */
1864 if (match_layout_qualifier("vertices", $1, state) == 0) {
1865 $$.flags.q.vertices = 1;
1866 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1867 if (!state->has_tessellation_shader()) {
1868 _mesa_glsl_error(& @1, state,
1869 "vertices qualifier requires GLSL 4.00 or "
1870 "ARB_tessellation_shader");
1874 /* If the identifier didn't match any known layout identifiers,
1878 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1883 | interface_block_layout_qualifier
1886 /* Layout qualifiers for ARB_uniform_buffer_object. */
1887 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1888 _mesa_glsl_error(& @1, state,
1889 "#version 140 / GL_ARB_uniform_buffer_object "
1890 "layout qualifier `%s' is used", $1);
1891 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1892 _mesa_glsl_warning(& @1, state,
1893 "#version 140 / GL_ARB_uniform_buffer_object "
1894 "layout qualifier `%s' is used", $1);
1899 /* This is a separate language rule because we parse these as tokens
1900 * (due to them being reserved keywords) instead of identifiers like
1901 * most qualifiers. See the any_identifier path of
1902 * layout_qualifier_id for the others.
1904 * Note that since layout qualifiers are case-insensitive in desktop
1905 * GLSL, all of these qualifiers need to be handled as identifiers as
1906 * well (by the any_identifier path of layout_qualifier_id).
1908 interface_block_layout_qualifier:
1911 memset(& $$, 0, sizeof($$));
1912 $$.flags.q.row_major = 1;
1916 memset(& $$, 0, sizeof($$));
1917 $$.flags.q.packed = 1;
1921 memset(& $$, 0, sizeof($$));
1922 $$.flags.q.shared = 1;
1926 subroutine_qualifier:
1929 memset(& $$, 0, sizeof($$));
1930 $$.flags.q.subroutine = 1;
1932 | SUBROUTINE '(' subroutine_type_list ')'
1934 memset(& $$, 0, sizeof($$));
1935 $$.flags.q.subroutine = 1;
1936 $$.subroutine_list = $3;
1940 subroutine_type_list:
1943 void *ctx = state->linalloc;
1944 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1945 decl->set_location(@1);
1947 $$ = new(ctx) ast_subroutine_list();
1948 $$->declarations.push_tail(&decl->link);
1950 | subroutine_type_list ',' any_identifier
1952 void *ctx = state->linalloc;
1953 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1954 decl->set_location(@3);
1957 $$->declarations.push_tail(&decl->link);
1961 interpolation_qualifier:
1964 memset(& $$, 0, sizeof($$));
1965 $$.flags.q.smooth = 1;
1969 memset(& $$, 0, sizeof($$));
1970 $$.flags.q.flat = 1;
1974 memset(& $$, 0, sizeof($$));
1975 $$.flags.q.noperspective = 1;
1980 /* Single qualifiers */
1983 memset(& $$, 0, sizeof($$));
1984 $$.flags.q.invariant = 1;
1988 memset(& $$, 0, sizeof($$));
1989 $$.flags.q.precise = 1;
1991 | auxiliary_storage_qualifier
1993 | interpolation_qualifier
1996 | subroutine_qualifier
1997 | precision_qualifier
1999 memset(&$$, 0, sizeof($$));
2003 /* Multiple qualifiers:
2004 * In GLSL 4.20, these can be specified in any order. In earlier versions,
2005 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
2007 * invariant interpolation auxiliary storage precision ...or...
2008 * layout storage precision
2010 * Each qualifier's rule ensures that the accumulated qualifiers on the right
2011 * side don't contain any that must appear on the left hand side.
2012 * For example, when processing a storage qualifier, we check that there are
2013 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
2015 | PRECISE type_qualifier
2017 if ($2.flags.q.precise)
2018 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
2021 $$.flags.q.precise = 1;
2023 | INVARIANT type_qualifier
2025 if ($2.flags.q.invariant)
2026 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
2028 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
2029 _mesa_glsl_error(&@1, state,
2030 "\"invariant\" must come after \"precise\"");
2033 $$.flags.q.invariant = 1;
2035 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
2037 * "Only variables output from a shader can be candidates for invariance.
2038 * This includes user-defined output variables and the built-in output
2039 * variables. As only outputs can be declared as invariant, an invariant
2040 * output from one shader stage will still match an input of a subsequent
2041 * stage without the input being declared as invariant."
2043 * On the desktop side, this text first appears in GLSL 4.30.
2045 if (state->is_version(430, 300) && $$.flags.q.in)
2046 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
2048 | interpolation_qualifier type_qualifier
2050 /* Section 4.3 of the GLSL 1.40 specification states:
2051 * "...qualified with one of these interpolation qualifiers"
2053 * GLSL 1.30 claims to allow "one or more", but insists that:
2054 * "These interpolation qualifiers may only precede the qualifiers in,
2055 * centroid in, out, or centroid out in a declaration."
2057 * ...which means that e.g. smooth can't precede smooth, so there can be
2058 * only one after all, and the 1.40 text is a clarification, not a change.
2060 if ($2.has_interpolation())
2061 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
2063 if (!state->has_420pack_or_es31() &&
2064 ($2.flags.q.precise || $2.flags.q.invariant)) {
2065 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
2066 "after \"precise\" or \"invariant\"");
2070 $$.merge_qualifier(&@1, state, $2, false);
2072 | layout_qualifier type_qualifier
2074 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
2075 * appear no later than auxiliary storage qualifiers. There is no
2076 * particularly clear spec language mandating this, but in all examples
2077 * the layout qualifier precedes the storage qualifier.
2079 * We allow combinations of layout with interpolation, invariant or
2080 * precise qualifiers since these are useful in ARB_separate_shader_objects.
2081 * There is no clear spec guidance on this either.
2084 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
2086 | subroutine_qualifier type_qualifier
2089 $$.merge_qualifier(&@1, state, $2, false);
2091 | auxiliary_storage_qualifier type_qualifier
2093 if ($2.has_auxiliary_storage()) {
2094 _mesa_glsl_error(&@1, state,
2095 "duplicate auxiliary storage qualifier (centroid or sample)");
2098 if ((!state->has_420pack_or_es31() && !state->EXT_gpu_shader4_enable) &&
2099 ($2.flags.q.precise || $2.flags.q.invariant ||
2100 $2.has_interpolation() || $2.has_layout())) {
2101 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
2102 "just before storage qualifiers");
2105 $$.merge_qualifier(&@1, state, $2, false);
2107 | storage_qualifier type_qualifier
2109 /* Section 4.3 of the GLSL 1.20 specification states:
2110 * "Variable declarations may have a storage qualifier specified..."
2111 * 1.30 clarifies this to "may have one storage qualifier".
2113 * GL_EXT_gpu_shader4 allows "varying out" in fragment shaders.
2115 if ($2.has_storage() &&
2116 (!state->EXT_gpu_shader4_enable ||
2117 state->stage != MESA_SHADER_FRAGMENT ||
2118 !$1.flags.q.varying || !$2.flags.q.out))
2119 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
2121 if (!state->has_420pack_or_es31() &&
2122 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
2123 $2.has_layout() || $2.has_auxiliary_storage())) {
2124 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2125 "precise, invariant, interpolation, layout and auxiliary "
2126 "storage qualifiers");
2130 $$.merge_qualifier(&@1, state, $2, false);
2132 | precision_qualifier type_qualifier
2134 if ($2.precision != ast_precision_none)
2135 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2137 if (!(state->has_420pack_or_es31()) &&
2139 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2144 | memory_qualifier type_qualifier
2147 $$.merge_qualifier(&@1, state, $2, false);
2151 auxiliary_storage_qualifier:
2154 memset(& $$, 0, sizeof($$));
2155 $$.flags.q.centroid = 1;
2159 memset(& $$, 0, sizeof($$));
2160 $$.flags.q.sample = 1;
2164 memset(& $$, 0, sizeof($$));
2165 $$.flags.q.patch = 1;
2171 memset(& $$, 0, sizeof($$));
2172 $$.flags.q.constant = 1;
2176 memset(& $$, 0, sizeof($$));
2177 $$.flags.q.attribute = 1;
2181 memset(& $$, 0, sizeof($$));
2182 $$.flags.q.varying = 1;
2186 memset(& $$, 0, sizeof($$));
2191 memset(& $$, 0, sizeof($$));
2194 if (state->stage == MESA_SHADER_GEOMETRY &&
2195 state->has_explicit_attrib_stream()) {
2196 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2199 * "If the block or variable is declared with the stream
2200 * identifier, it is associated with the specified stream;
2201 * otherwise, it is associated with the current default stream."
2203 $$.flags.q.stream = 1;
2204 $$.flags.q.explicit_stream = 0;
2205 $$.stream = state->out_qualifier->stream;
2208 if (state->has_enhanced_layouts()) {
2209 $$.flags.q.xfb_buffer = 1;
2210 $$.flags.q.explicit_xfb_buffer = 0;
2211 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2216 memset(& $$, 0, sizeof($$));
2220 if (!state->has_framebuffer_fetch() ||
2221 !state->is_version(130, 300) ||
2222 state->stage != MESA_SHADER_FRAGMENT)
2223 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2224 "declared as both input and output");
2228 memset(& $$, 0, sizeof($$));
2229 $$.flags.q.uniform = 1;
2233 memset(& $$, 0, sizeof($$));
2234 $$.flags.q.buffer = 1;
2238 memset(& $$, 0, sizeof($$));
2239 $$.flags.q.shared_storage = 1;
2246 memset(& $$, 0, sizeof($$));
2247 $$.flags.q.coherent = 1;
2251 memset(& $$, 0, sizeof($$));
2252 $$.flags.q._volatile = 1;
2256 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2257 memset(& $$, 0, sizeof($$));
2258 $$.flags.q.restrict_flag = 1;
2262 memset(& $$, 0, sizeof($$));
2263 $$.flags.q.read_only = 1;
2267 memset(& $$, 0, sizeof($$));
2268 $$.flags.q.write_only = 1;
2275 void *ctx = state->linalloc;
2276 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2277 ast_unsized_array_dim, NULL,
2279 $$->set_location_range(@1, @2);
2281 | '[' constant_expression ']'
2283 void *ctx = state->linalloc;
2284 $$ = new(ctx) ast_array_specifier(@1, $2);
2285 $$->set_location_range(@1, @3);
2287 | array_specifier '[' ']'
2289 void *ctx = state->linalloc;
2292 if (state->check_arrays_of_arrays_allowed(& @1)) {
2293 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2297 | array_specifier '[' constant_expression ']'
2301 if (state->check_arrays_of_arrays_allowed(& @1)) {
2302 $$->add_dimension($3);
2308 type_specifier_nonarray
2309 | type_specifier_nonarray array_specifier
2312 $$->array_specifier = $2;
2316 type_specifier_nonarray:
2317 basic_type_specifier_nonarray
2319 void *ctx = state->linalloc;
2320 $$ = new(ctx) ast_type_specifier($1);
2321 $$->set_location(@1);
2325 void *ctx = state->linalloc;
2326 $$ = new(ctx) ast_type_specifier($1);
2327 $$->set_location(@1);
2331 void *ctx = state->linalloc;
2332 $$ = new(ctx) ast_type_specifier($1);
2333 $$->set_location(@1);
2337 basic_type_specifier_nonarray:
2338 VOID_TOK { $$ = glsl_type::void_type; }
2339 | BASIC_TYPE_TOK { $$ = $1; }
2340 | UNSIGNED BASIC_TYPE_TOK
2342 if ($2 == glsl_type::int_type) {
2343 $$ = glsl_type::uint_type;
2345 _mesa_glsl_error(&@1, state,
2346 "\"unsigned\" is only allowed before \"int\"");
2351 precision_qualifier:
2354 state->check_precision_qualifiers_allowed(&@1);
2355 $$ = ast_precision_high;
2359 state->check_precision_qualifiers_allowed(&@1);
2360 $$ = ast_precision_medium;
2364 state->check_precision_qualifiers_allowed(&@1);
2365 $$ = ast_precision_low;
2370 STRUCT any_identifier '{' struct_declaration_list '}'
2372 void *ctx = state->linalloc;
2373 $$ = new(ctx) ast_struct_specifier($2, $4);
2374 $$->set_location_range(@2, @5);
2375 state->symbols->add_type($2, glsl_type::void_type);
2377 | STRUCT '{' struct_declaration_list '}'
2379 void *ctx = state->linalloc;
2381 /* All anonymous structs have the same name. This simplifies matching of
2382 * globals whose type is an unnamed struct.
2384 * It also avoids a memory leak when the same shader is compiled over and
2387 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2389 $$->set_location_range(@2, @4);
2393 struct_declaration_list:
2397 $1->link.self_link();
2399 | struct_declaration_list struct_declaration
2402 $$->link.insert_before(& $2->link);
2407 fully_specified_type struct_declarator_list ';'
2409 void *ctx = state->linalloc;
2410 ast_fully_specified_type *const type = $1;
2411 type->set_location(@1);
2413 if (state->has_bindless()) {
2414 ast_type_qualifier input_layout_mask;
2416 /* Allow to declare qualifiers for images. */
2417 input_layout_mask.flags.i = 0;
2418 input_layout_mask.flags.q.coherent = 1;
2419 input_layout_mask.flags.q._volatile = 1;
2420 input_layout_mask.flags.q.restrict_flag = 1;
2421 input_layout_mask.flags.q.read_only = 1;
2422 input_layout_mask.flags.q.write_only = 1;
2423 input_layout_mask.flags.q.explicit_image_format = 1;
2425 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2426 _mesa_glsl_error(&@1, state,
2427 "only precision and image qualifiers may be "
2428 "applied to structure members");
2431 if (type->qualifier.flags.i != 0)
2432 _mesa_glsl_error(&@1, state,
2433 "only precision qualifiers may be applied to "
2434 "structure members");
2437 $$ = new(ctx) ast_declarator_list(type);
2438 $$->set_location(@2);
2440 $$->declarations.push_degenerate_list_at_head(& $2->link);
2444 struct_declarator_list:
2448 $1->link.self_link();
2450 | struct_declarator_list ',' struct_declarator
2453 $$->link.insert_before(& $3->link);
2460 void *ctx = state->linalloc;
2461 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2462 $$->set_location(@1);
2464 | any_identifier array_specifier
2466 void *ctx = state->linalloc;
2467 $$ = new(ctx) ast_declaration($1, $2, NULL);
2468 $$->set_location_range(@1, @2);
2473 assignment_expression
2474 | '{' initializer_list '}'
2478 | '{' initializer_list ',' '}'
2487 void *ctx = state->linalloc;
2488 $$ = new(ctx) ast_aggregate_initializer();
2489 $$->set_location(@1);
2490 $$->expressions.push_tail(& $1->link);
2492 | initializer_list ',' initializer
2494 $1->expressions.push_tail(& $3->link);
2498 declaration_statement:
2502 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2505 compound_statement { $$ = (ast_node *) $1; }
2510 declaration_statement
2511 | expression_statement
2512 | selection_statement
2514 | iteration_statement
2522 void *ctx = state->linalloc;
2523 $$ = new(ctx) ast_compound_statement(true, NULL);
2524 $$->set_location_range(@1, @2);
2528 state->symbols->push_scope();
2532 void *ctx = state->linalloc;
2533 $$ = new(ctx) ast_compound_statement(true, $3);
2534 $$->set_location_range(@1, @4);
2535 state->symbols->pop_scope();
2539 statement_no_new_scope:
2540 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2544 compound_statement_no_new_scope:
2547 void *ctx = state->linalloc;
2548 $$ = new(ctx) ast_compound_statement(false, NULL);
2549 $$->set_location_range(@1, @2);
2551 | '{' statement_list '}'
2553 void *ctx = state->linalloc;
2554 $$ = new(ctx) ast_compound_statement(false, $2);
2555 $$->set_location_range(@1, @3);
2563 _mesa_glsl_error(& @1, state, "<nil> statement");
2568 $$->link.self_link();
2570 | statement_list statement
2573 _mesa_glsl_error(& @2, state, "<nil> statement");
2577 $$->link.insert_before(& $2->link);
2579 | statement_list extension_statement
2581 if (!state->allow_extension_directive_midshader) {
2582 _mesa_glsl_error(& @1, state,
2583 "#extension directive is not allowed "
2584 "in the middle of a shader");
2590 expression_statement:
2593 void *ctx = state->linalloc;
2594 $$ = new(ctx) ast_expression_statement(NULL);
2595 $$->set_location(@1);
2599 void *ctx = state->linalloc;
2600 $$ = new(ctx) ast_expression_statement($1);
2601 $$->set_location(@1);
2605 selection_statement:
2606 IF '(' expression ')' selection_rest_statement
2608 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2610 $$->set_location_range(@1, @5);
2614 selection_rest_statement:
2615 statement ELSE statement
2617 $$.then_statement = $1;
2618 $$.else_statement = $3;
2620 | statement %prec THEN
2622 $$.then_statement = $1;
2623 $$.else_statement = NULL;
2630 $$ = (ast_node *) $1;
2632 | fully_specified_type any_identifier '=' initializer
2634 void *ctx = state->linalloc;
2635 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2636 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2637 decl->set_location_range(@2, @4);
2638 declarator->set_location(@1);
2640 declarator->declarations.push_tail(&decl->link);
2646 * switch_statement grammar is based on the syntax described in the body
2647 * of the GLSL spec, not in it's appendix!!!
2650 SWITCH '(' expression ')' switch_body
2652 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2653 $$->set_location_range(@1, @5);
2660 $$ = new(state->linalloc) ast_switch_body(NULL);
2661 $$->set_location_range(@1, @2);
2663 | '{' case_statement_list '}'
2665 $$ = new(state->linalloc) ast_switch_body($2);
2666 $$->set_location_range(@1, @3);
2673 $$ = new(state->linalloc) ast_case_label($2);
2674 $$->set_location(@2);
2678 $$ = new(state->linalloc) ast_case_label(NULL);
2679 $$->set_location(@2);
2686 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2688 labels->labels.push_tail(& $1->link);
2690 $$->set_location(@1);
2692 | case_label_list case_label
2695 $$->labels.push_tail(& $2->link);
2700 case_label_list statement
2702 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2703 stmts->set_location(@2);
2705 stmts->stmts.push_tail(& $2->link);
2708 | case_statement statement
2711 $$->stmts.push_tail(& $2->link);
2715 case_statement_list:
2718 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2719 cases->set_location(@1);
2721 cases->cases.push_tail(& $1->link);
2724 | case_statement_list case_statement
2727 $$->cases.push_tail(& $2->link);
2731 iteration_statement:
2732 WHILE '(' condition ')' statement_no_new_scope
2734 void *ctx = state->linalloc;
2735 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2736 NULL, $3, NULL, $5);
2737 $$->set_location_range(@1, @4);
2739 | DO statement WHILE '(' expression ')' ';'
2741 void *ctx = state->linalloc;
2742 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2743 NULL, $5, NULL, $2);
2744 $$->set_location_range(@1, @6);
2746 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2748 void *ctx = state->linalloc;
2749 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2750 $3, $4.cond, $4.rest, $6);
2751 $$->set_location_range(@1, @6);
2756 expression_statement
2757 | declaration_statement
2774 | conditionopt ';' expression
2781 // Grammar Note: No 'goto'. Gotos are not supported.
2785 void *ctx = state->linalloc;
2786 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2787 $$->set_location(@1);
2791 void *ctx = state->linalloc;
2792 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2793 $$->set_location(@1);
2797 void *ctx = state->linalloc;
2798 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2799 $$->set_location(@1);
2801 | RETURN expression ';'
2803 void *ctx = state->linalloc;
2804 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2805 $$->set_location_range(@1, @2);
2807 | DISCARD ';' // Fragment shader only.
2809 void *ctx = state->linalloc;
2810 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2811 $$->set_location(@1);
2818 void *ctx = state->linalloc;
2819 $$ = new(ctx) ast_demote_statement();
2820 $$->set_location(@1);
2824 external_declaration:
2825 function_definition { $$ = $1; }
2826 | declaration { $$ = $1; }
2827 | pragma_statement { $$ = $1; }
2828 | layout_defaults { $$ = $1; }
2829 | ';' { $$ = NULL; }
2832 function_definition:
2833 function_prototype compound_statement_no_new_scope
2835 void *ctx = state->linalloc;
2836 $$ = new(ctx) ast_function_definition();
2837 $$->set_location_range(@1, @2);
2841 state->symbols->pop_scope();
2845 /* layout_qualifieropt is packed into this rule */
2847 basic_interface_block
2851 | layout_qualifier interface_block
2853 ast_interface_block *block = (ast_interface_block *) $2;
2855 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2856 block->layout.has_layout())) {
2864 | memory_qualifier interface_block
2866 ast_interface_block *block = (ast_interface_block *)$2;
2868 if (!block->default_layout.flags.q.buffer) {
2869 _mesa_glsl_error(& @1, state,
2870 "memory qualifiers can only be used in the "
2871 "declaration of shader storage blocks");
2873 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2881 basic_interface_block:
2882 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2884 ast_interface_block *const block = $6;
2886 if ($1.flags.q.uniform) {
2887 block->default_layout = *state->default_uniform_qualifier;
2888 } else if ($1.flags.q.buffer) {
2889 block->default_layout = *state->default_shader_storage_qualifier;
2891 block->block_name = $2;
2892 block->declarations.push_degenerate_list_at_head(& $4->link);
2894 _mesa_ast_process_interface_block(& @1, state, block, $1);
2900 interface_qualifier:
2903 memset(& $$, 0, sizeof($$));
2908 memset(& $$, 0, sizeof($$));
2913 memset(& $$, 0, sizeof($$));
2914 $$.flags.q.uniform = 1;
2918 memset(& $$, 0, sizeof($$));
2919 $$.flags.q.buffer = 1;
2921 | auxiliary_storage_qualifier interface_qualifier
2923 if (!$1.flags.q.patch) {
2924 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2926 if ($2.has_auxiliary_storage()) {
2927 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2930 $$.flags.q.patch = 1;
2937 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2941 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2942 $$->set_location(@1);
2944 | NEW_IDENTIFIER array_specifier
2946 $$ = new(state->linalloc) ast_interface_block($1, $2);
2947 $$->set_location_range(@1, @2);
2955 $1->link.self_link();
2957 | member_declaration member_list
2960 $2->link.insert_before(& $$->link);
2965 fully_specified_type struct_declarator_list ';'
2967 void *ctx = state->linalloc;
2968 ast_fully_specified_type *type = $1;
2969 type->set_location(@1);
2971 if (type->qualifier.flags.q.attribute) {
2972 _mesa_glsl_error(& @1, state,
2973 "keyword 'attribute' cannot be used with "
2974 "interface block member");
2975 } else if (type->qualifier.flags.q.varying) {
2976 _mesa_glsl_error(& @1, state,
2977 "keyword 'varying' cannot be used with "
2978 "interface block member");
2981 $$ = new(ctx) ast_declarator_list(type);
2982 $$->set_location(@2);
2984 $$->declarations.push_degenerate_list_at_head(& $2->link);
2988 layout_uniform_defaults:
2989 layout_qualifier layout_uniform_defaults
2992 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2996 | layout_qualifier UNIFORM ';'
2999 layout_buffer_defaults:
3000 layout_qualifier layout_buffer_defaults
3003 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3007 | layout_qualifier BUFFER ';'
3011 layout_qualifier layout_in_defaults
3014 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3017 if (!$$.validate_in_qualifier(& @1, state)) {
3021 | layout_qualifier IN_TOK ';'
3023 if (!$1.validate_in_qualifier(& @1, state)) {
3029 layout_out_defaults:
3030 layout_qualifier layout_out_defaults
3033 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3036 if (!$$.validate_out_qualifier(& @1, state)) {
3040 | layout_qualifier OUT_TOK ';'
3042 if (!$1.validate_out_qualifier(& @1, state)) {
3049 layout_uniform_defaults
3052 if (!state->default_uniform_qualifier->
3053 merge_qualifier(& @1, state, $1, false)) {
3056 if (!state->default_uniform_qualifier->
3057 push_to_global(& @1, state)) {
3061 | layout_buffer_defaults
3064 if (!state->default_shader_storage_qualifier->
3065 merge_qualifier(& @1, state, $1, false)) {
3068 if (!state->default_shader_storage_qualifier->
3069 push_to_global(& @1, state)) {
3073 /* From the GLSL 4.50 spec, section 4.4.5:
3075 * "It is a compile-time error to specify the binding identifier for
3076 * the global scope or for block member declarations."
3078 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
3079 _mesa_glsl_error(& @1, state,
3080 "binding qualifier cannot be set for default layout");
3083 | layout_in_defaults
3086 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
3089 if (!state->in_qualifier->push_to_global(& @1, state)) {
3093 | layout_out_defaults
3096 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
3099 if (!state->out_qualifier->push_to_global(& @1, state)) {