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"
39 #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
44 static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
46 _mesa_glsl_error(loc, st, "%s", msg);
50 _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
52 return _mesa_glsl_lexer_lex(val, loc, state->scanner);
55 static bool match_layout_qualifier(const char *s1, const char *s2,
56 _mesa_glsl_parse_state *state)
58 /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
60 * "The tokens in any layout-qualifier-id-list ... are not case
61 * sensitive, unless explicitly noted otherwise."
63 * The text "unless explicitly noted otherwise" appears to be
64 * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
67 * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
70 * "As for other identifiers, they are case sensitive."
72 * So we need to do a case-sensitive or a case-insensitive match,
73 * depending on whether we are compiling for GLSL ES.
76 return strcmp(s1, s2);
78 return strcasecmp(s1, s2);
97 %lex-param {struct _mesa_glsl_parse_state *state}
98 %parse-param {struct _mesa_glsl_parse_state *state}
105 const char *identifier;
107 struct ast_type_qualifier type_qualifier;
110 ast_type_specifier *type_specifier;
111 ast_array_specifier *array_specifier;
112 ast_fully_specified_type *fully_specified_type;
113 ast_function *function;
114 ast_parameter_declarator *parameter_declarator;
115 ast_function_definition *function_definition;
116 ast_compound_statement *compound_statement;
117 ast_expression *expression;
118 ast_declarator_list *declarator_list;
119 ast_struct_specifier *struct_specifier;
120 ast_declaration *declaration;
121 ast_switch_body *switch_body;
122 ast_case_label *case_label;
123 ast_case_label_list *case_label_list;
124 ast_case_statement *case_statement;
125 ast_case_statement_list *case_statement_list;
126 ast_interface_block *interface_block;
127 ast_subroutine_list *subroutine_list;
130 ast_expression *rest;
131 } for_rest_statement;
134 ast_node *then_statement;
135 ast_node *else_statement;
136 } selection_rest_statement;
138 const glsl_type *type;
141 %token ATTRIBUTE CONST_TOK
142 %token <type> BASIC_TYPE_TOK
143 %token BREAK BUFFER CONTINUE DO ELSE FOR IF DEMOTE DISCARD RETURN SWITCH CASE DEFAULT
144 %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
145 %token NOPERSPECTIVE FLAT SMOOTH
146 %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
147 %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
149 %token STRUCT VOID_TOK WHILE
150 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
151 %type <identifier> any_identifier
152 %type <interface_block> instance_name_opt
153 %token <real> FLOATCONSTANT
154 %token <dreal> DOUBLECONSTANT
155 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
156 %token <n64> INT64CONSTANT UINT64CONSTANT
157 %token <identifier> FIELD_SELECTION
158 %token LEFT_OP RIGHT_OP
159 %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
160 %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
161 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
163 %token INVARIANT PRECISE
164 %token LOWP MEDIUMP HIGHP SUPERP PRECISION
166 %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
167 %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
168 %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
169 %token PRAGMA_WARNING_ON PRAGMA_WARNING_OFF
170 %token PRAGMA_INVARIANT_ALL
173 /* Reserved words that are not actually used in the grammar.
175 %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
176 %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
177 %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
178 %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
180 %token SIZEOF CAST NAMESPACE USING
181 %token RESOURCE PATCH
186 %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
188 %type <identifier> variable_identifier
189 %type <node> statement
190 %type <node> statement_list
191 %type <node> simple_statement
192 %type <n> precision_qualifier
193 %type <type_qualifier> type_qualifier
194 %type <type_qualifier> auxiliary_storage_qualifier
195 %type <type_qualifier> storage_qualifier
196 %type <type_qualifier> interpolation_qualifier
197 %type <type_qualifier> layout_qualifier
198 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
199 %type <type_qualifier> interface_block_layout_qualifier
200 %type <type_qualifier> memory_qualifier
201 %type <type_qualifier> subroutine_qualifier
202 %type <subroutine_list> subroutine_type_list
203 %type <type_qualifier> interface_qualifier
204 %type <type_specifier> type_specifier
205 %type <type_specifier> type_specifier_nonarray
206 %type <array_specifier> array_specifier
207 %type <type> basic_type_specifier_nonarray
208 %type <fully_specified_type> fully_specified_type
209 %type <function> function_prototype
210 %type <function> function_header
211 %type <function> function_header_with_parameters
212 %type <function> function_declarator
213 %type <parameter_declarator> parameter_declarator
214 %type <parameter_declarator> parameter_declaration
215 %type <type_qualifier> parameter_qualifier
216 %type <type_qualifier> parameter_direction_qualifier
217 %type <type_specifier> parameter_type_specifier
218 %type <function_definition> function_definition
219 %type <compound_statement> compound_statement_no_new_scope
220 %type <compound_statement> compound_statement
221 %type <node> statement_no_new_scope
222 %type <node> expression_statement
223 %type <expression> expression
224 %type <expression> primary_expression
225 %type <expression> assignment_expression
226 %type <expression> conditional_expression
227 %type <expression> logical_or_expression
228 %type <expression> logical_xor_expression
229 %type <expression> logical_and_expression
230 %type <expression> inclusive_or_expression
231 %type <expression> exclusive_or_expression
232 %type <expression> and_expression
233 %type <expression> equality_expression
234 %type <expression> relational_expression
235 %type <expression> shift_expression
236 %type <expression> additive_expression
237 %type <expression> multiplicative_expression
238 %type <expression> unary_expression
239 %type <expression> constant_expression
240 %type <expression> integer_expression
241 %type <expression> postfix_expression
242 %type <expression> function_call_header_with_parameters
243 %type <expression> function_call_header_no_parameters
244 %type <expression> function_call_header
245 %type <expression> function_call_generic
246 %type <expression> function_call_or_method
247 %type <expression> function_call
248 %type <n> assignment_operator
249 %type <n> unary_operator
250 %type <expression> function_identifier
251 %type <node> external_declaration
252 %type <node> pragma_statement
253 %type <declarator_list> init_declarator_list
254 %type <declarator_list> single_declaration
255 %type <expression> initializer
256 %type <expression> initializer_list
257 %type <node> declaration
258 %type <node> declaration_statement
259 %type <node> jump_statement
260 %type <node> demote_statement
261 %type <node> interface_block
262 %type <interface_block> basic_interface_block
263 %type <struct_specifier> struct_specifier
264 %type <declarator_list> struct_declaration_list
265 %type <declarator_list> struct_declaration
266 %type <declaration> struct_declarator
267 %type <declaration> struct_declarator_list
268 %type <declarator_list> member_list
269 %type <declarator_list> member_declaration
270 %type <node> selection_statement
271 %type <selection_rest_statement> selection_rest_statement
272 %type <node> switch_statement
273 %type <switch_body> switch_body
274 %type <case_label_list> case_label_list
275 %type <case_label> case_label
276 %type <case_statement> case_statement
277 %type <case_statement_list> case_statement_list
278 %type <node> iteration_statement
279 %type <node> condition
280 %type <node> conditionopt
281 %type <node> for_init_statement
282 %type <for_rest_statement> for_rest_statement
283 %type <node> layout_defaults
284 %type <type_qualifier> layout_uniform_defaults
285 %type <type_qualifier> layout_buffer_defaults
286 %type <type_qualifier> layout_in_defaults
287 %type <type_qualifier> layout_out_defaults
293 version_statement extension_statement_list
295 _mesa_glsl_initialize_types(state);
297 external_declaration_list
299 delete state->symbols;
300 state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
301 if (state->es_shader) {
302 if (state->stage == MESA_SHADER_FRAGMENT) {
303 state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
305 state->symbols->add_default_precision_qualifier("float", ast_precision_high);
306 state->symbols->add_default_precision_qualifier("int", ast_precision_high);
308 state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
309 state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
310 state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
311 state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
313 _mesa_glsl_initialize_types(state);
318 /* blank - no #version specified: defaults are already set */
319 | VERSION_TOK INTCONSTANT EOL
321 state->process_version_directive(&@2, $2, NULL);
326 | VERSION_TOK INTCONSTANT any_identifier EOL
328 state->process_version_directive(&@2, $2, $3);
336 PRAGMA_DEBUG_ON EOL { $$ = NULL; }
337 | PRAGMA_DEBUG_OFF EOL { $$ = NULL; }
338 | PRAGMA_OPTIMIZE_ON EOL { $$ = NULL; }
339 | PRAGMA_OPTIMIZE_OFF EOL { $$ = NULL; }
340 | PRAGMA_INVARIANT_ALL EOL
342 /* Pragma invariant(all) cannot be used in a fragment shader.
344 * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
346 * "It is an error to use this pragma in a fragment shader."
348 if (state->is_version(120, 300) &&
349 state->stage == MESA_SHADER_FRAGMENT) {
350 _mesa_glsl_error(& @1, state,
351 "pragma `invariant(all)' cannot be used "
352 "in a fragment shader.");
353 } else if (!state->is_version(120, 100)) {
354 _mesa_glsl_warning(& @1, state,
355 "pragma `invariant(all)' not supported in %s "
356 "(GLSL ES 1.00 or GLSL 1.20 required)",
357 state->get_version_string());
359 state->all_invariant = true;
364 | PRAGMA_WARNING_ON EOL
366 void *mem_ctx = state->linalloc;
367 $$ = new(mem_ctx) ast_warnings_toggle(true);
369 | PRAGMA_WARNING_OFF EOL
371 void *mem_ctx = state->linalloc;
372 $$ = new(mem_ctx) ast_warnings_toggle(false);
376 extension_statement_list:
378 | extension_statement_list extension_statement
388 EXTENSION any_identifier COLON any_identifier EOL
390 if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
396 external_declaration_list:
399 /* FINISHME: The NULL test is required because pragmas are set to
400 * FINISHME: NULL. (See production rule for external_declaration.)
403 state->translation_unit.push_tail(& $1->link);
405 | external_declaration_list external_declaration
407 /* FINISHME: The NULL test is required because pragmas are set to
408 * FINISHME: NULL. (See production rule for external_declaration.)
411 state->translation_unit.push_tail(& $2->link);
413 | external_declaration_list extension_statement {
414 if (!state->allow_extension_directive_midshader) {
415 _mesa_glsl_error(& @2, state,
416 "#extension directive is not allowed "
417 "in the middle of a shader");
431 void *ctx = state->linalloc;
432 $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
433 $$->set_location(@1);
434 $$->primary_expression.identifier = $1;
438 void *ctx = state->linalloc;
439 $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
440 $$->set_location(@1);
441 $$->primary_expression.int_constant = $1;
445 void *ctx = state->linalloc;
446 $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
447 $$->set_location(@1);
448 $$->primary_expression.uint_constant = $1;
452 void *ctx = state->linalloc;
453 $$ = new(ctx) ast_expression(ast_int64_constant, NULL, NULL, NULL);
454 $$->set_location(@1);
455 $$->primary_expression.int64_constant = $1;
459 void *ctx = state->linalloc;
460 $$ = new(ctx) ast_expression(ast_uint64_constant, NULL, NULL, NULL);
461 $$->set_location(@1);
462 $$->primary_expression.uint64_constant = $1;
466 void *ctx = state->linalloc;
467 $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
468 $$->set_location(@1);
469 $$->primary_expression.float_constant = $1;
473 void *ctx = state->linalloc;
474 $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
475 $$->set_location(@1);
476 $$->primary_expression.double_constant = $1;
480 void *ctx = state->linalloc;
481 $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
482 $$->set_location(@1);
483 $$->primary_expression.bool_constant = $1;
493 | postfix_expression '[' integer_expression ']'
495 void *ctx = state->linalloc;
496 $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
497 $$->set_location_range(@1, @4);
503 | postfix_expression DOT_TOK FIELD_SELECTION
505 void *ctx = state->linalloc;
506 $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
507 $$->set_location_range(@1, @3);
508 $$->primary_expression.identifier = $3;
510 | postfix_expression INC_OP
512 void *ctx = state->linalloc;
513 $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
514 $$->set_location_range(@1, @2);
516 | postfix_expression DEC_OP
518 void *ctx = state->linalloc;
519 $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
520 $$->set_location_range(@1, @2);
529 function_call_or_method
532 function_call_or_method:
533 function_call_generic
536 function_call_generic:
537 function_call_header_with_parameters ')'
538 | function_call_header_no_parameters ')'
541 function_call_header_no_parameters:
542 function_call_header VOID_TOK
543 | function_call_header
546 function_call_header_with_parameters:
547 function_call_header assignment_expression
550 $$->set_location(@1);
551 $$->expressions.push_tail(& $2->link);
553 | function_call_header_with_parameters ',' assignment_expression
556 $$->set_location(@1);
557 $$->expressions.push_tail(& $3->link);
561 // Grammar Note: Constructors look like functions, but lexical
562 // analysis recognized most of them as keywords. They are now
563 // recognized through "type_specifier".
564 function_call_header:
565 function_identifier '('
571 void *ctx = state->linalloc;
572 $$ = new(ctx) ast_function_expression($1);
573 $$->set_location(@1);
577 void *ctx = state->linalloc;
578 $$ = new(ctx) ast_function_expression($1);
579 $$->set_location(@1);
583 // Grammar Note: Constructors look like methods, but lexical
584 // analysis recognized most of them as keywords. They are now
585 // recognized through "type_specifier".
587 // Grammar Note: No traditional style type casts.
590 | INC_OP unary_expression
592 void *ctx = state->linalloc;
593 $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
594 $$->set_location(@1);
596 | DEC_OP unary_expression
598 void *ctx = state->linalloc;
599 $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
600 $$->set_location(@1);
602 | unary_operator unary_expression
604 void *ctx = state->linalloc;
605 $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
606 $$->set_location_range(@1, @2);
610 // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
612 '+' { $$ = ast_plus; }
613 | '-' { $$ = ast_neg; }
614 | '!' { $$ = ast_logic_not; }
615 | '~' { $$ = ast_bit_not; }
618 multiplicative_expression:
620 | multiplicative_expression '*' unary_expression
622 void *ctx = state->linalloc;
623 $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
624 $$->set_location_range(@1, @3);
626 | multiplicative_expression '/' unary_expression
628 void *ctx = state->linalloc;
629 $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
630 $$->set_location_range(@1, @3);
632 | multiplicative_expression '%' unary_expression
634 void *ctx = state->linalloc;
635 $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
636 $$->set_location_range(@1, @3);
641 multiplicative_expression
642 | additive_expression '+' multiplicative_expression
644 void *ctx = state->linalloc;
645 $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
646 $$->set_location_range(@1, @3);
648 | additive_expression '-' multiplicative_expression
650 void *ctx = state->linalloc;
651 $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
652 $$->set_location_range(@1, @3);
658 | shift_expression LEFT_OP additive_expression
660 void *ctx = state->linalloc;
661 $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
662 $$->set_location_range(@1, @3);
664 | shift_expression RIGHT_OP additive_expression
666 void *ctx = state->linalloc;
667 $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
668 $$->set_location_range(@1, @3);
672 relational_expression:
674 | relational_expression '<' shift_expression
676 void *ctx = state->linalloc;
677 $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
678 $$->set_location_range(@1, @3);
680 | relational_expression '>' shift_expression
682 void *ctx = state->linalloc;
683 $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
684 $$->set_location_range(@1, @3);
686 | relational_expression LE_OP shift_expression
688 void *ctx = state->linalloc;
689 $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
690 $$->set_location_range(@1, @3);
692 | relational_expression GE_OP shift_expression
694 void *ctx = state->linalloc;
695 $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
696 $$->set_location_range(@1, @3);
701 relational_expression
702 | equality_expression EQ_OP relational_expression
704 void *ctx = state->linalloc;
705 $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
706 $$->set_location_range(@1, @3);
708 | equality_expression NE_OP relational_expression
710 void *ctx = state->linalloc;
711 $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
712 $$->set_location_range(@1, @3);
718 | and_expression '&' equality_expression
720 void *ctx = state->linalloc;
721 $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
722 $$->set_location_range(@1, @3);
726 exclusive_or_expression:
728 | exclusive_or_expression '^' and_expression
730 void *ctx = state->linalloc;
731 $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
732 $$->set_location_range(@1, @3);
736 inclusive_or_expression:
737 exclusive_or_expression
738 | inclusive_or_expression '|' exclusive_or_expression
740 void *ctx = state->linalloc;
741 $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
742 $$->set_location_range(@1, @3);
746 logical_and_expression:
747 inclusive_or_expression
748 | logical_and_expression AND_OP inclusive_or_expression
750 void *ctx = state->linalloc;
751 $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
752 $$->set_location_range(@1, @3);
756 logical_xor_expression:
757 logical_and_expression
758 | logical_xor_expression XOR_OP logical_and_expression
760 void *ctx = state->linalloc;
761 $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
762 $$->set_location_range(@1, @3);
766 logical_or_expression:
767 logical_xor_expression
768 | logical_or_expression OR_OP logical_xor_expression
770 void *ctx = state->linalloc;
771 $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
772 $$->set_location_range(@1, @3);
776 conditional_expression:
777 logical_or_expression
778 | logical_or_expression '?' expression ':' assignment_expression
780 void *ctx = state->linalloc;
781 $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
782 $$->set_location_range(@1, @5);
786 assignment_expression:
787 conditional_expression
788 | unary_expression assignment_operator assignment_expression
790 void *ctx = state->linalloc;
791 $$ = new(ctx) ast_expression($2, $1, $3, NULL);
792 $$->set_location_range(@1, @3);
797 '=' { $$ = ast_assign; }
798 | MUL_ASSIGN { $$ = ast_mul_assign; }
799 | DIV_ASSIGN { $$ = ast_div_assign; }
800 | MOD_ASSIGN { $$ = ast_mod_assign; }
801 | ADD_ASSIGN { $$ = ast_add_assign; }
802 | SUB_ASSIGN { $$ = ast_sub_assign; }
803 | LEFT_ASSIGN { $$ = ast_ls_assign; }
804 | RIGHT_ASSIGN { $$ = ast_rs_assign; }
805 | AND_ASSIGN { $$ = ast_and_assign; }
806 | XOR_ASSIGN { $$ = ast_xor_assign; }
807 | OR_ASSIGN { $$ = ast_or_assign; }
811 assignment_expression
815 | expression ',' assignment_expression
817 void *ctx = state->linalloc;
818 if ($1->oper != ast_sequence) {
819 $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
820 $$->set_location_range(@1, @3);
821 $$->expressions.push_tail(& $1->link);
826 $$->expressions.push_tail(& $3->link);
831 conditional_expression
835 function_prototype ';'
837 state->symbols->pop_scope();
840 | init_declarator_list ';'
844 | PRECISION precision_qualifier type_specifier ';'
846 $3->default_precision = $2;
851 ast_interface_block *block = (ast_interface_block *) $1;
852 if (block->layout.has_layout() || block->layout.has_memory()) {
853 if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
857 block->layout = block->default_layout;
858 if (!block->layout.push_to_global(& @1, state)) {
866 function_declarator ')'
871 | function_header_with_parameters
874 function_header_with_parameters:
875 function_header parameter_declaration
878 $$->parameters.push_tail(& $2->link);
880 | function_header_with_parameters ',' parameter_declaration
883 $$->parameters.push_tail(& $3->link);
888 fully_specified_type variable_identifier '('
890 void *ctx = state->linalloc;
891 $$ = new(ctx) ast_function();
892 $$->set_location(@2);
893 $$->return_type = $1;
896 if ($1->qualifier.is_subroutine_decl()) {
897 /* add type for IDENTIFIER search */
898 state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
900 state->symbols->add_function(new(state) ir_function($2));
901 state->symbols->push_scope();
905 parameter_declarator:
906 type_specifier any_identifier
908 void *ctx = state->linalloc;
909 $$ = new(ctx) ast_parameter_declarator();
910 $$->set_location_range(@1, @2);
911 $$->type = new(ctx) ast_fully_specified_type();
912 $$->type->set_location(@1);
913 $$->type->specifier = $1;
915 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
917 | layout_qualifier type_specifier any_identifier
919 if (state->allow_layout_qualifier_on_function_parameter) {
920 void *ctx = state->linalloc;
921 $$ = new(ctx) ast_parameter_declarator();
922 $$->set_location_range(@2, @3);
923 $$->type = new(ctx) ast_fully_specified_type();
924 $$->type->set_location(@2);
925 $$->type->specifier = $2;
927 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
929 _mesa_glsl_error(&@1, state,
930 "is is not allowed on function parameter");
934 | type_specifier any_identifier array_specifier
936 void *ctx = state->linalloc;
937 $$ = new(ctx) ast_parameter_declarator();
938 $$->set_location_range(@1, @3);
939 $$->type = new(ctx) ast_fully_specified_type();
940 $$->type->set_location(@1);
941 $$->type->specifier = $1;
943 $$->array_specifier = $3;
944 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
948 parameter_declaration:
949 parameter_qualifier parameter_declarator
952 $$->type->qualifier = $1;
953 if (!$$->type->qualifier.push_to_global(& @1, state)) {
957 | parameter_qualifier parameter_type_specifier
959 void *ctx = state->linalloc;
960 $$ = new(ctx) ast_parameter_declarator();
961 $$->set_location(@2);
962 $$->type = new(ctx) ast_fully_specified_type();
963 $$->type->set_location_range(@1, @2);
964 $$->type->qualifier = $1;
965 if (!$$->type->qualifier.push_to_global(& @1, state)) {
968 $$->type->specifier = $2;
975 memset(& $$, 0, sizeof($$));
977 | CONST_TOK parameter_qualifier
979 if ($2.flags.q.constant)
980 _mesa_glsl_error(&@1, state, "duplicate const qualifier");
983 $$.flags.q.constant = 1;
985 | PRECISE parameter_qualifier
987 if ($2.flags.q.precise)
988 _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
991 $$.flags.q.precise = 1;
993 | parameter_direction_qualifier parameter_qualifier
995 if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
996 _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
998 if (!state->has_420pack_or_es31() && $2.flags.q.constant)
999 _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
1003 $$.merge_qualifier(&@1, state, $2, false);
1005 | precision_qualifier parameter_qualifier
1007 if ($2.precision != ast_precision_none)
1008 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
1010 if (!state->has_420pack_or_es31() &&
1012 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
1017 | memory_qualifier parameter_qualifier
1020 $$.merge_qualifier(&@1, state, $2, false);
1023 parameter_direction_qualifier:
1026 memset(& $$, 0, sizeof($$));
1031 memset(& $$, 0, sizeof($$));
1036 memset(& $$, 0, sizeof($$));
1042 parameter_type_specifier:
1046 init_declarator_list:
1048 | init_declarator_list ',' any_identifier
1050 void *ctx = state->linalloc;
1051 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1052 decl->set_location(@3);
1055 $$->declarations.push_tail(&decl->link);
1056 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1058 | init_declarator_list ',' any_identifier array_specifier
1060 void *ctx = state->linalloc;
1061 ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
1062 decl->set_location_range(@3, @4);
1065 $$->declarations.push_tail(&decl->link);
1066 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1068 | init_declarator_list ',' any_identifier array_specifier '=' initializer
1070 void *ctx = state->linalloc;
1071 ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
1072 decl->set_location_range(@3, @4);
1075 $$->declarations.push_tail(&decl->link);
1076 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1078 | init_declarator_list ',' any_identifier '=' initializer
1080 void *ctx = state->linalloc;
1081 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
1082 decl->set_location(@3);
1085 $$->declarations.push_tail(&decl->link);
1086 state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
1090 // Grammar Note: No 'enum', or 'typedef'.
1092 fully_specified_type
1094 void *ctx = state->linalloc;
1095 /* Empty declaration list is valid. */
1096 $$ = new(ctx) ast_declarator_list($1);
1097 $$->set_location(@1);
1099 | fully_specified_type any_identifier
1101 void *ctx = state->linalloc;
1102 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1103 decl->set_location(@2);
1105 $$ = new(ctx) ast_declarator_list($1);
1106 $$->set_location_range(@1, @2);
1107 $$->declarations.push_tail(&decl->link);
1108 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1110 | fully_specified_type any_identifier array_specifier
1112 void *ctx = state->linalloc;
1113 ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
1114 decl->set_location_range(@2, @3);
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));
1121 | fully_specified_type any_identifier array_specifier '=' initializer
1123 void *ctx = state->linalloc;
1124 ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
1125 decl->set_location_range(@2, @3);
1127 $$ = new(ctx) ast_declarator_list($1);
1128 $$->set_location_range(@1, @3);
1129 $$->declarations.push_tail(&decl->link);
1130 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1132 | fully_specified_type any_identifier '=' initializer
1134 void *ctx = state->linalloc;
1135 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
1136 decl->set_location(@2);
1138 $$ = new(ctx) ast_declarator_list($1);
1139 $$->set_location_range(@1, @2);
1140 $$->declarations.push_tail(&decl->link);
1141 state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
1143 | INVARIANT variable_identifier
1145 void *ctx = state->linalloc;
1146 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1147 decl->set_location(@2);
1149 $$ = new(ctx) ast_declarator_list(NULL);
1150 $$->set_location_range(@1, @2);
1151 $$->invariant = true;
1153 $$->declarations.push_tail(&decl->link);
1155 | PRECISE variable_identifier
1157 void *ctx = state->linalloc;
1158 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
1159 decl->set_location(@2);
1161 $$ = new(ctx) ast_declarator_list(NULL);
1162 $$->set_location_range(@1, @2);
1165 $$->declarations.push_tail(&decl->link);
1169 fully_specified_type:
1172 void *ctx = state->linalloc;
1173 $$ = new(ctx) ast_fully_specified_type();
1174 $$->set_location(@1);
1177 | type_qualifier type_specifier
1179 void *ctx = state->linalloc;
1180 $$ = new(ctx) ast_fully_specified_type();
1181 $$->set_location_range(@1, @2);
1183 if (!$$->qualifier.push_to_global(& @1, state)) {
1187 if ($$->specifier->structure != NULL &&
1188 $$->specifier->structure->is_declaration) {
1189 $$->specifier->structure->layout = &$$->qualifier;
1195 LAYOUT_TOK '(' layout_qualifier_id_list ')'
1201 layout_qualifier_id_list:
1203 | layout_qualifier_id_list ',' layout_qualifier_id
1206 if (!$$.merge_qualifier(& @3, state, $3, true)) {
1212 layout_qualifier_id:
1215 memset(& $$, 0, sizeof($$));
1217 /* Layout qualifiers for ARB_fragment_coord_conventions. */
1218 if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
1219 state->is_version(150, 0))) {
1220 if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
1221 $$.flags.q.origin_upper_left = 1;
1222 } else if (match_layout_qualifier($1, "pixel_center_integer",
1224 $$.flags.q.pixel_center_integer = 1;
1227 if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
1228 _mesa_glsl_warning(& @1, state,
1229 "GL_ARB_fragment_coord_conventions layout "
1230 "identifier `%s' used", $1);
1234 /* Layout qualifiers for AMD/ARB_conservative_depth. */
1236 (state->AMD_conservative_depth_enable ||
1237 state->ARB_conservative_depth_enable ||
1238 state->is_version(420, 0))) {
1239 if (match_layout_qualifier($1, "depth_any", state) == 0) {
1240 $$.flags.q.depth_type = 1;
1241 $$.depth_type = ast_depth_any;
1242 } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
1243 $$.flags.q.depth_type = 1;
1244 $$.depth_type = ast_depth_greater;
1245 } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
1246 $$.flags.q.depth_type = 1;
1247 $$.depth_type = ast_depth_less;
1248 } else if (match_layout_qualifier($1, "depth_unchanged",
1250 $$.flags.q.depth_type = 1;
1251 $$.depth_type = ast_depth_unchanged;
1254 if ($$.flags.i && state->AMD_conservative_depth_warn) {
1255 _mesa_glsl_warning(& @1, state,
1256 "GL_AMD_conservative_depth "
1257 "layout qualifier `%s' is used", $1);
1259 if ($$.flags.i && state->ARB_conservative_depth_warn) {
1260 _mesa_glsl_warning(& @1, state,
1261 "GL_ARB_conservative_depth "
1262 "layout qualifier `%s' is used", $1);
1266 /* See also interface_block_layout_qualifier. */
1267 if (!$$.flags.i && state->has_uniform_buffer_objects()) {
1268 if (match_layout_qualifier($1, "std140", state) == 0) {
1269 $$.flags.q.std140 = 1;
1270 } else if (match_layout_qualifier($1, "shared", state) == 0) {
1271 $$.flags.q.shared = 1;
1272 } else if (match_layout_qualifier($1, "std430", state) == 0) {
1273 $$.flags.q.std430 = 1;
1274 } else if (match_layout_qualifier($1, "column_major", state) == 0) {
1275 $$.flags.q.column_major = 1;
1276 /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
1277 * below in the interface_block_layout_qualifier rule.
1279 * It is not a reserved word in GLSL ES 3.00, so it's handled here as
1282 * Also, this takes care of alternate capitalizations of
1283 * "row_major" (which is necessary because layout qualifiers
1284 * are case-insensitive in desktop GLSL).
1286 } else if (match_layout_qualifier($1, "row_major", state) == 0) {
1287 $$.flags.q.row_major = 1;
1288 /* "packed" is a reserved word in GLSL, and its token is
1289 * parsed below in the interface_block_layout_qualifier rule.
1290 * However, we must take care of alternate capitalizations of
1291 * "packed", because layout qualifiers are case-insensitive
1294 } else if (match_layout_qualifier($1, "packed", state) == 0) {
1295 $$.flags.q.packed = 1;
1298 if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
1299 _mesa_glsl_warning(& @1, state,
1300 "#version 140 / GL_ARB_uniform_buffer_object "
1301 "layout qualifier `%s' is used", $1);
1305 /* Layout qualifiers for GLSL 1.50 geometry shaders. */
1307 static const struct {
1311 { "points", GL_POINTS },
1312 { "lines", GL_LINES },
1313 { "lines_adjacency", GL_LINES_ADJACENCY },
1314 { "line_strip", GL_LINE_STRIP },
1315 { "triangles", GL_TRIANGLES },
1316 { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
1317 { "triangle_strip", GL_TRIANGLE_STRIP },
1319 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1320 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1321 $$.flags.q.prim_type = 1;
1322 $$.prim_type = map[i].e;
1327 if ($$.flags.i && !state->has_geometry_shader() &&
1328 !state->has_tessellation_shader()) {
1329 _mesa_glsl_error(& @1, state, "#version 150 layout "
1330 "qualifier `%s' used", $1);
1334 /* Layout qualifiers for ARB_shader_image_load_store. */
1335 if (state->has_shader_image_load_store()) {
1337 static const struct {
1340 glsl_base_type base_type;
1341 /** Minimum desktop GLSL version required for the image
1342 * format. Use 130 if already present in the original
1345 unsigned required_glsl;
1346 /** Minimum GLSL ES version required for the image format. */
1347 unsigned required_essl;
1348 /* NV_image_formats */
1349 bool nv_image_formats;
1350 bool ext_qualifiers;
1352 { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false, false },
1353 { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false, false },
1354 { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1355 { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1356 { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1357 { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false, false },
1358 { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true, false },
1359 { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false, false },
1360 { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false, false },
1361 { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true, false },
1362 { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false, false },
1363 { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true, false },
1364 { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true, false },
1365 { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true, false },
1366 { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false, false },
1367 { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true, false },
1368 { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true, false },
1369 { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false, false },
1370 { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false, false },
1371 { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false, false },
1372 { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true, false },
1373 { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true, false },
1374 { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true, false },
1375 { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false, false },
1376 { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true, false },
1377 { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true, false },
1378 { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, true, false },
1379 { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true, false },
1380 { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false, false },
1381 { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, true, false },
1382 { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true, false },
1383 { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, true, false },
1384 { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true, false },
1385 { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1386 { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
1387 { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1388 { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1389 { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1390 { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
1392 /* From GL_EXT_shader_image_load_store: */
1393 /* base_type is incorrect but it'll be patched later when we know
1394 * the variable type. See ast_to_hir.cpp */
1395 { "size1x8", GL_R8I, GLSL_TYPE_VOID, 130, 0, false, true },
1396 { "size1x16", GL_R16I, GLSL_TYPE_VOID, 130, 0, false, true },
1397 { "size1x32", GL_R32I, GLSL_TYPE_VOID, 130, 0, false, true },
1398 { "size2x32", GL_RG32I, GLSL_TYPE_VOID, 130, 0, false, true },
1399 { "size4x32", GL_RGBA32I, GLSL_TYPE_VOID, 130, 0, false, true },
1402 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1403 if ((state->is_version(map[i].required_glsl,
1404 map[i].required_essl) ||
1405 (state->NV_image_formats_enable &&
1406 map[i].nv_image_formats)) &&
1407 match_layout_qualifier($1, map[i].name, state) == 0) {
1408 /* Skip ARB_shader_image_load_store qualifiers if not enabled */
1409 if (!map[i].ext_qualifiers && !(state->ARB_shader_image_load_store_enable ||
1410 state->is_version(420, 310))) {
1413 /* Skip EXT_shader_image_load_store qualifiers if not enabled */
1414 if (map[i].ext_qualifiers && !state->EXT_shader_image_load_store_enable) {
1417 $$.flags.q.explicit_image_format = 1;
1418 $$.image_format = map[i].format;
1419 $$.image_base_type = map[i].base_type;
1427 if (match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
1428 /* From section 4.4.1.3 of the GLSL 4.50 specification
1429 * (Fragment Shader Inputs):
1431 * "Fragment shaders also allow the following layout
1432 * qualifier on in only (not with variable declarations)
1433 * layout-qualifier-id
1434 * early_fragment_tests
1437 if (state->stage != MESA_SHADER_FRAGMENT) {
1438 _mesa_glsl_error(& @1, state,
1439 "early_fragment_tests layout qualifier only "
1440 "valid in fragment shaders");
1443 $$.flags.q.early_fragment_tests = 1;
1446 if (match_layout_qualifier($1, "inner_coverage", state) == 0) {
1447 if (state->stage != MESA_SHADER_FRAGMENT) {
1448 _mesa_glsl_error(& @1, state,
1449 "inner_coverage layout qualifier only "
1450 "valid in fragment shaders");
1453 if (state->INTEL_conservative_rasterization_enable) {
1454 $$.flags.q.inner_coverage = 1;
1456 _mesa_glsl_error(& @1, state,
1457 "inner_coverage layout qualifier present, "
1458 "but the INTEL_conservative_rasterization extension "
1463 if (match_layout_qualifier($1, "post_depth_coverage", state) == 0) {
1464 if (state->stage != MESA_SHADER_FRAGMENT) {
1465 _mesa_glsl_error(& @1, state,
1466 "post_depth_coverage layout qualifier only "
1467 "valid in fragment shaders");
1470 if (state->ARB_post_depth_coverage_enable ||
1471 state->INTEL_conservative_rasterization_enable) {
1472 $$.flags.q.post_depth_coverage = 1;
1474 _mesa_glsl_error(& @1, state,
1475 "post_depth_coverage layout qualifier present, "
1476 "but the GL_ARB_post_depth_coverage extension "
1481 if ($$.flags.q.post_depth_coverage && $$.flags.q.inner_coverage) {
1482 _mesa_glsl_error(& @1, state,
1483 "post_depth_coverage & inner_coverage layout qualifiers "
1484 "are mutually exclusive");
1488 const bool pixel_interlock_ordered = match_layout_qualifier($1,
1489 "pixel_interlock_ordered", state) == 0;
1490 const bool pixel_interlock_unordered = match_layout_qualifier($1,
1491 "pixel_interlock_unordered", state) == 0;
1492 const bool sample_interlock_ordered = match_layout_qualifier($1,
1493 "sample_interlock_ordered", state) == 0;
1494 const bool sample_interlock_unordered = match_layout_qualifier($1,
1495 "sample_interlock_unordered", state) == 0;
1497 if (pixel_interlock_ordered + pixel_interlock_unordered +
1498 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1499 state->stage != MESA_SHADER_FRAGMENT) {
1500 _mesa_glsl_error(& @1, state, "interlock layout qualifiers: "
1501 "pixel_interlock_ordered, pixel_interlock_unordered, "
1502 "sample_interlock_ordered and sample_interlock_unordered, "
1503 "only valid in fragment shader input layout declaration.");
1504 } else if (pixel_interlock_ordered + pixel_interlock_unordered +
1505 sample_interlock_ordered + sample_interlock_unordered > 0 &&
1506 !state->ARB_fragment_shader_interlock_enable &&
1507 !state->NV_fragment_shader_interlock_enable) {
1508 _mesa_glsl_error(& @1, state,
1509 "interlock layout qualifier present, but the "
1510 "GL_ARB_fragment_shader_interlock or "
1511 "GL_NV_fragment_shader_interlock extension is not "
1514 $$.flags.q.pixel_interlock_ordered = pixel_interlock_ordered;
1515 $$.flags.q.pixel_interlock_unordered = pixel_interlock_unordered;
1516 $$.flags.q.sample_interlock_ordered = sample_interlock_ordered;
1517 $$.flags.q.sample_interlock_unordered = sample_interlock_unordered;
1520 /* Layout qualifiers for tessellation evaluation shaders. */
1522 static const struct {
1526 /* triangles already parsed by gs-specific code */
1527 { "quads", GL_QUADS },
1528 { "isolines", GL_ISOLINES },
1530 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1531 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1532 $$.flags.q.prim_type = 1;
1533 $$.prim_type = map[i].e;
1538 if ($$.flags.i && !state->has_tessellation_shader()) {
1539 _mesa_glsl_error(& @1, state,
1540 "primitive mode qualifier `%s' requires "
1541 "GLSL 4.00 or ARB_tessellation_shader", $1);
1545 static const struct {
1547 enum gl_tess_spacing e;
1549 { "equal_spacing", TESS_SPACING_EQUAL },
1550 { "fractional_odd_spacing", TESS_SPACING_FRACTIONAL_ODD },
1551 { "fractional_even_spacing", TESS_SPACING_FRACTIONAL_EVEN },
1553 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1554 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1555 $$.flags.q.vertex_spacing = 1;
1556 $$.vertex_spacing = map[i].e;
1561 if ($$.flags.i && !state->has_tessellation_shader()) {
1562 _mesa_glsl_error(& @1, state,
1563 "vertex spacing qualifier `%s' requires "
1564 "GLSL 4.00 or ARB_tessellation_shader", $1);
1568 if (match_layout_qualifier($1, "cw", state) == 0) {
1569 $$.flags.q.ordering = 1;
1570 $$.ordering = GL_CW;
1571 } else if (match_layout_qualifier($1, "ccw", state) == 0) {
1572 $$.flags.q.ordering = 1;
1573 $$.ordering = GL_CCW;
1576 if ($$.flags.i && !state->has_tessellation_shader()) {
1577 _mesa_glsl_error(& @1, state,
1578 "ordering qualifier `%s' requires "
1579 "GLSL 4.00 or ARB_tessellation_shader", $1);
1583 if (match_layout_qualifier($1, "point_mode", state) == 0) {
1584 $$.flags.q.point_mode = 1;
1585 $$.point_mode = true;
1588 if ($$.flags.i && !state->has_tessellation_shader()) {
1589 _mesa_glsl_error(& @1, state,
1590 "qualifier `point_mode' requires "
1591 "GLSL 4.00 or ARB_tessellation_shader");
1596 static const struct {
1600 { "blend_support_multiply", BLEND_MULTIPLY },
1601 { "blend_support_screen", BLEND_SCREEN },
1602 { "blend_support_overlay", BLEND_OVERLAY },
1603 { "blend_support_darken", BLEND_DARKEN },
1604 { "blend_support_lighten", BLEND_LIGHTEN },
1605 { "blend_support_colordodge", BLEND_COLORDODGE },
1606 { "blend_support_colorburn", BLEND_COLORBURN },
1607 { "blend_support_hardlight", BLEND_HARDLIGHT },
1608 { "blend_support_softlight", BLEND_SOFTLIGHT },
1609 { "blend_support_difference", BLEND_DIFFERENCE },
1610 { "blend_support_exclusion", BLEND_EXCLUSION },
1611 { "blend_support_hsl_hue", BLEND_HSL_HUE },
1612 { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
1613 { "blend_support_hsl_color", BLEND_HSL_COLOR },
1614 { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
1615 { "blend_support_all_equations", BLEND_ALL },
1617 for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
1618 if (match_layout_qualifier($1, map[i].s, state) == 0) {
1619 $$.flags.q.blend_support = 1;
1620 state->fs_blend_support |= map[i].mask;
1626 !state->KHR_blend_equation_advanced_enable &&
1627 !state->is_version(0, 320)) {
1628 _mesa_glsl_error(& @1, state,
1629 "advanced blending layout qualifiers require "
1630 "ESSL 3.20 or KHR_blend_equation_advanced");
1633 if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
1634 _mesa_glsl_error(& @1, state,
1635 "advanced blending layout qualifiers only "
1636 "valid in fragment shaders");
1640 /* Layout qualifiers for ARB_compute_variable_group_size. */
1642 if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
1643 $$.flags.q.local_size_variable = 1;
1646 if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
1647 _mesa_glsl_error(& @1, state,
1648 "qualifier `local_size_variable` requires "
1649 "ARB_compute_variable_group_size");
1653 /* Layout qualifiers for ARB_bindless_texture. */
1655 if (match_layout_qualifier($1, "bindless_sampler", state) == 0)
1656 $$.flags.q.bindless_sampler = 1;
1657 if (match_layout_qualifier($1, "bound_sampler", state) == 0)
1658 $$.flags.q.bound_sampler = 1;
1660 if (state->has_shader_image_load_store()) {
1661 if (match_layout_qualifier($1, "bindless_image", state) == 0)
1662 $$.flags.q.bindless_image = 1;
1663 if (match_layout_qualifier($1, "bound_image", state) == 0)
1664 $$.flags.q.bound_image = 1;
1667 if ($$.flags.i && !state->has_bindless()) {
1668 _mesa_glsl_error(& @1, state,
1669 "qualifier `%s` requires "
1670 "ARB_bindless_texture", $1);
1675 state->EXT_shader_framebuffer_fetch_non_coherent_enable) {
1676 if (match_layout_qualifier($1, "noncoherent", state) == 0)
1677 $$.flags.q.non_coherent = 1;
1680 // Layout qualifiers for NV_compute_shader_derivatives.
1682 if (match_layout_qualifier($1, "derivative_group_quadsNV", state) == 0) {
1683 $$.flags.q.derivative_group = 1;
1684 $$.derivative_group = DERIVATIVE_GROUP_QUADS;
1685 } else if (match_layout_qualifier($1, "derivative_group_linearNV", state) == 0) {
1686 $$.flags.q.derivative_group = 1;
1687 $$.derivative_group = DERIVATIVE_GROUP_LINEAR;
1691 if (!state->has_compute_shader()) {
1692 _mesa_glsl_error(& @1, state,
1693 "qualifier `%s' requires "
1694 "a compute shader", $1);
1697 if (!state->NV_compute_shader_derivatives_enable) {
1698 _mesa_glsl_error(& @1, state,
1699 "qualifier `%s' requires "
1700 "NV_compute_shader_derivatives", $1);
1703 if (state->NV_compute_shader_derivatives_warn) {
1704 _mesa_glsl_warning(& @1, state,
1705 "NV_compute_shader_derivatives layout "
1706 "qualifier `%s' used", $1);
1712 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1717 | any_identifier '=' constant_expression
1719 memset(& $$, 0, sizeof($$));
1720 void *ctx = state->linalloc;
1722 if ($3->oper != ast_int_constant &&
1723 $3->oper != ast_uint_constant &&
1724 !state->has_enhanced_layouts()) {
1725 _mesa_glsl_error(& @1, state,
1726 "compile-time constant expressions require "
1727 "GLSL 4.40 or ARB_enhanced_layouts");
1730 if (match_layout_qualifier("align", $1, state) == 0) {
1731 if (!state->has_enhanced_layouts()) {
1732 _mesa_glsl_error(& @1, state,
1733 "align qualifier requires "
1734 "GLSL 4.40 or ARB_enhanced_layouts");
1736 $$.flags.q.explicit_align = 1;
1741 if (match_layout_qualifier("location", $1, state) == 0) {
1742 $$.flags.q.explicit_location = 1;
1744 if ($$.flags.q.attribute == 1 &&
1745 state->ARB_explicit_attrib_location_warn) {
1746 _mesa_glsl_warning(& @1, state,
1747 "GL_ARB_explicit_attrib_location layout "
1748 "identifier `%s' used", $1);
1753 if (match_layout_qualifier("component", $1, state) == 0) {
1754 if (!state->has_enhanced_layouts()) {
1755 _mesa_glsl_error(& @1, state,
1756 "component qualifier requires "
1757 "GLSL 4.40 or ARB_enhanced_layouts");
1759 $$.flags.q.explicit_component = 1;
1764 if (match_layout_qualifier("index", $1, state) == 0) {
1765 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1766 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1770 $$.flags.q.explicit_index = 1;
1774 if ((state->has_420pack_or_es31() ||
1775 state->has_atomic_counters() ||
1776 state->has_shader_storage_buffer_objects()) &&
1777 match_layout_qualifier("binding", $1, state) == 0) {
1778 $$.flags.q.explicit_binding = 1;
1782 if ((state->has_atomic_counters() ||
1783 state->has_enhanced_layouts()) &&
1784 match_layout_qualifier("offset", $1, state) == 0) {
1785 $$.flags.q.explicit_offset = 1;
1789 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1790 $$.flags.q.max_vertices = 1;
1791 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1792 if (!state->has_geometry_shader()) {
1793 _mesa_glsl_error(& @3, state,
1794 "#version 150 max_vertices qualifier "
1799 if (state->stage == MESA_SHADER_GEOMETRY) {
1800 if (match_layout_qualifier("stream", $1, state) == 0 &&
1801 state->check_explicit_attrib_stream_allowed(& @3)) {
1802 $$.flags.q.stream = 1;
1803 $$.flags.q.explicit_stream = 1;
1808 if (state->has_enhanced_layouts()) {
1809 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1810 $$.flags.q.xfb_buffer = 1;
1811 $$.flags.q.explicit_xfb_buffer = 1;
1815 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1816 $$.flags.q.explicit_xfb_offset = 1;
1820 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1821 $$.flags.q.xfb_stride = 1;
1822 $$.flags.q.explicit_xfb_stride = 1;
1827 static const char * const local_size_qualifiers[3] = {
1832 for (int i = 0; i < 3; i++) {
1833 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1835 if (!state->has_compute_shader()) {
1836 _mesa_glsl_error(& @3, state,
1837 "%s qualifier requires GLSL 4.30 or "
1838 "GLSL ES 3.10 or ARB_compute_shader",
1839 local_size_qualifiers[i]);
1842 $$.flags.q.local_size |= (1 << i);
1843 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1849 if (match_layout_qualifier("invocations", $1, state) == 0) {
1850 $$.flags.q.invocations = 1;
1851 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1852 if (!state->is_version(400, 320) &&
1853 !state->ARB_gpu_shader5_enable &&
1854 !state->OES_geometry_shader_enable &&
1855 !state->EXT_geometry_shader_enable) {
1856 _mesa_glsl_error(& @3, state,
1857 "GL_ARB_gpu_shader5 invocations "
1858 "qualifier specified", $3);
1862 /* Layout qualifiers for tessellation control shaders. */
1863 if (match_layout_qualifier("vertices", $1, state) == 0) {
1864 $$.flags.q.vertices = 1;
1865 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1866 if (!state->has_tessellation_shader()) {
1867 _mesa_glsl_error(& @1, state,
1868 "vertices qualifier requires GLSL 4.00 or "
1869 "ARB_tessellation_shader");
1873 /* If the identifier didn't match any known layout identifiers,
1877 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1882 | interface_block_layout_qualifier
1885 /* Layout qualifiers for ARB_uniform_buffer_object. */
1886 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1887 _mesa_glsl_error(& @1, state,
1888 "#version 140 / GL_ARB_uniform_buffer_object "
1889 "layout qualifier `%s' is used", $1);
1890 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1891 _mesa_glsl_warning(& @1, state,
1892 "#version 140 / GL_ARB_uniform_buffer_object "
1893 "layout qualifier `%s' is used", $1);
1898 /* This is a separate language rule because we parse these as tokens
1899 * (due to them being reserved keywords) instead of identifiers like
1900 * most qualifiers. See the any_identifier path of
1901 * layout_qualifier_id for the others.
1903 * Note that since layout qualifiers are case-insensitive in desktop
1904 * GLSL, all of these qualifiers need to be handled as identifiers as
1905 * well (by the any_identifier path of layout_qualifier_id).
1907 interface_block_layout_qualifier:
1910 memset(& $$, 0, sizeof($$));
1911 $$.flags.q.row_major = 1;
1915 memset(& $$, 0, sizeof($$));
1916 $$.flags.q.packed = 1;
1920 memset(& $$, 0, sizeof($$));
1921 $$.flags.q.shared = 1;
1925 subroutine_qualifier:
1928 memset(& $$, 0, sizeof($$));
1929 $$.flags.q.subroutine = 1;
1931 | SUBROUTINE '(' subroutine_type_list ')'
1933 memset(& $$, 0, sizeof($$));
1934 $$.flags.q.subroutine = 1;
1935 $$.subroutine_list = $3;
1939 subroutine_type_list:
1942 void *ctx = state->linalloc;
1943 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1944 decl->set_location(@1);
1946 $$ = new(ctx) ast_subroutine_list();
1947 $$->declarations.push_tail(&decl->link);
1949 | subroutine_type_list ',' any_identifier
1951 void *ctx = state->linalloc;
1952 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1953 decl->set_location(@3);
1956 $$->declarations.push_tail(&decl->link);
1960 interpolation_qualifier:
1963 memset(& $$, 0, sizeof($$));
1964 $$.flags.q.smooth = 1;
1968 memset(& $$, 0, sizeof($$));
1969 $$.flags.q.flat = 1;
1973 memset(& $$, 0, sizeof($$));
1974 $$.flags.q.noperspective = 1;
1979 /* Single qualifiers */
1982 memset(& $$, 0, sizeof($$));
1983 $$.flags.q.invariant = 1;
1987 memset(& $$, 0, sizeof($$));
1988 $$.flags.q.precise = 1;
1990 | auxiliary_storage_qualifier
1992 | interpolation_qualifier
1995 | subroutine_qualifier
1996 | precision_qualifier
1998 memset(&$$, 0, sizeof($$));
2002 /* Multiple qualifiers:
2003 * In GLSL 4.20, these can be specified in any order. In earlier versions,
2004 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
2006 * invariant interpolation auxiliary storage precision ...or...
2007 * layout storage precision
2009 * Each qualifier's rule ensures that the accumulated qualifiers on the right
2010 * side don't contain any that must appear on the left hand side.
2011 * For example, when processing a storage qualifier, we check that there are
2012 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
2014 | PRECISE type_qualifier
2016 if ($2.flags.q.precise)
2017 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
2020 $$.flags.q.precise = 1;
2022 | INVARIANT type_qualifier
2024 if ($2.flags.q.invariant)
2025 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
2027 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
2028 _mesa_glsl_error(&@1, state,
2029 "\"invariant\" must come after \"precise\"");
2032 $$.flags.q.invariant = 1;
2034 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
2036 * "Only variables output from a shader can be candidates for invariance.
2037 * This includes user-defined output variables and the built-in output
2038 * variables. As only outputs can be declared as invariant, an invariant
2039 * output from one shader stage will still match an input of a subsequent
2040 * stage without the input being declared as invariant."
2042 * On the desktop side, this text first appears in GLSL 4.30.
2044 if (state->is_version(430, 300) && $$.flags.q.in)
2045 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
2047 | interpolation_qualifier type_qualifier
2049 /* Section 4.3 of the GLSL 1.40 specification states:
2050 * "...qualified with one of these interpolation qualifiers"
2052 * GLSL 1.30 claims to allow "one or more", but insists that:
2053 * "These interpolation qualifiers may only precede the qualifiers in,
2054 * centroid in, out, or centroid out in a declaration."
2056 * ...which means that e.g. smooth can't precede smooth, so there can be
2057 * only one after all, and the 1.40 text is a clarification, not a change.
2059 if ($2.has_interpolation())
2060 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
2062 if (!state->has_420pack_or_es31() &&
2063 ($2.flags.q.precise || $2.flags.q.invariant)) {
2064 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
2065 "after \"precise\" or \"invariant\"");
2069 $$.merge_qualifier(&@1, state, $2, false);
2071 | layout_qualifier type_qualifier
2073 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
2074 * appear no later than auxiliary storage qualifiers. There is no
2075 * particularly clear spec language mandating this, but in all examples
2076 * the layout qualifier precedes the storage qualifier.
2078 * We allow combinations of layout with interpolation, invariant or
2079 * precise qualifiers since these are useful in ARB_separate_shader_objects.
2080 * There is no clear spec guidance on this either.
2083 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
2085 | subroutine_qualifier type_qualifier
2088 $$.merge_qualifier(&@1, state, $2, false);
2090 | auxiliary_storage_qualifier type_qualifier
2092 if ($2.has_auxiliary_storage()) {
2093 _mesa_glsl_error(&@1, state,
2094 "duplicate auxiliary storage qualifier (centroid or sample)");
2097 if ((!state->has_420pack_or_es31() && !state->EXT_gpu_shader4_enable) &&
2098 ($2.flags.q.precise || $2.flags.q.invariant ||
2099 $2.has_interpolation() || $2.has_layout())) {
2100 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
2101 "just before storage qualifiers");
2104 $$.merge_qualifier(&@1, state, $2, false);
2106 | storage_qualifier type_qualifier
2108 /* Section 4.3 of the GLSL 1.20 specification states:
2109 * "Variable declarations may have a storage qualifier specified..."
2110 * 1.30 clarifies this to "may have one storage qualifier".
2112 * GL_EXT_gpu_shader4 allows "varying out" in fragment shaders.
2114 if ($2.has_storage() &&
2115 (!state->EXT_gpu_shader4_enable ||
2116 state->stage != MESA_SHADER_FRAGMENT ||
2117 !$1.flags.q.varying || !$2.flags.q.out))
2118 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
2120 if (!state->has_420pack_or_es31() &&
2121 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
2122 $2.has_layout() || $2.has_auxiliary_storage())) {
2123 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
2124 "precise, invariant, interpolation, layout and auxiliary "
2125 "storage qualifiers");
2129 $$.merge_qualifier(&@1, state, $2, false);
2131 | precision_qualifier type_qualifier
2133 if ($2.precision != ast_precision_none)
2134 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2136 if (!(state->has_420pack_or_es31()) &&
2138 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2143 | memory_qualifier type_qualifier
2146 $$.merge_qualifier(&@1, state, $2, false);
2150 auxiliary_storage_qualifier:
2153 memset(& $$, 0, sizeof($$));
2154 $$.flags.q.centroid = 1;
2158 memset(& $$, 0, sizeof($$));
2159 $$.flags.q.sample = 1;
2163 memset(& $$, 0, sizeof($$));
2164 $$.flags.q.patch = 1;
2170 memset(& $$, 0, sizeof($$));
2171 $$.flags.q.constant = 1;
2175 memset(& $$, 0, sizeof($$));
2176 $$.flags.q.attribute = 1;
2180 memset(& $$, 0, sizeof($$));
2181 $$.flags.q.varying = 1;
2185 memset(& $$, 0, sizeof($$));
2190 memset(& $$, 0, sizeof($$));
2193 if (state->stage == MESA_SHADER_GEOMETRY &&
2194 state->has_explicit_attrib_stream()) {
2195 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2198 * "If the block or variable is declared with the stream
2199 * identifier, it is associated with the specified stream;
2200 * otherwise, it is associated with the current default stream."
2202 $$.flags.q.stream = 1;
2203 $$.flags.q.explicit_stream = 0;
2204 $$.stream = state->out_qualifier->stream;
2207 if (state->has_enhanced_layouts()) {
2208 $$.flags.q.xfb_buffer = 1;
2209 $$.flags.q.explicit_xfb_buffer = 0;
2210 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2215 memset(& $$, 0, sizeof($$));
2219 if (!state->has_framebuffer_fetch() ||
2220 !state->is_version(130, 300) ||
2221 state->stage != MESA_SHADER_FRAGMENT)
2222 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2223 "declared as both input and output");
2227 memset(& $$, 0, sizeof($$));
2228 $$.flags.q.uniform = 1;
2232 memset(& $$, 0, sizeof($$));
2233 $$.flags.q.buffer = 1;
2237 memset(& $$, 0, sizeof($$));
2238 $$.flags.q.shared_storage = 1;
2245 memset(& $$, 0, sizeof($$));
2246 $$.flags.q.coherent = 1;
2250 memset(& $$, 0, sizeof($$));
2251 $$.flags.q._volatile = 1;
2255 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2256 memset(& $$, 0, sizeof($$));
2257 $$.flags.q.restrict_flag = 1;
2261 memset(& $$, 0, sizeof($$));
2262 $$.flags.q.read_only = 1;
2266 memset(& $$, 0, sizeof($$));
2267 $$.flags.q.write_only = 1;
2274 void *ctx = state->linalloc;
2275 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2276 ast_unsized_array_dim, NULL,
2278 $$->set_location_range(@1, @2);
2280 | '[' constant_expression ']'
2282 void *ctx = state->linalloc;
2283 $$ = new(ctx) ast_array_specifier(@1, $2);
2284 $$->set_location_range(@1, @3);
2286 | array_specifier '[' ']'
2288 void *ctx = state->linalloc;
2291 if (state->check_arrays_of_arrays_allowed(& @1)) {
2292 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2296 | array_specifier '[' constant_expression ']'
2300 if (state->check_arrays_of_arrays_allowed(& @1)) {
2301 $$->add_dimension($3);
2307 type_specifier_nonarray
2308 | type_specifier_nonarray array_specifier
2311 $$->array_specifier = $2;
2315 type_specifier_nonarray:
2316 basic_type_specifier_nonarray
2318 void *ctx = state->linalloc;
2319 $$ = new(ctx) ast_type_specifier($1);
2320 $$->set_location(@1);
2324 void *ctx = state->linalloc;
2325 $$ = new(ctx) ast_type_specifier($1);
2326 $$->set_location(@1);
2330 void *ctx = state->linalloc;
2331 $$ = new(ctx) ast_type_specifier($1);
2332 $$->set_location(@1);
2336 basic_type_specifier_nonarray:
2337 VOID_TOK { $$ = glsl_type::void_type; }
2338 | BASIC_TYPE_TOK { $$ = $1; }
2339 | UNSIGNED BASIC_TYPE_TOK
2341 if ($2 == glsl_type::int_type) {
2342 $$ = glsl_type::uint_type;
2344 _mesa_glsl_error(&@1, state,
2345 "\"unsigned\" is only allowed before \"int\"");
2350 precision_qualifier:
2353 state->check_precision_qualifiers_allowed(&@1);
2354 $$ = ast_precision_high;
2358 state->check_precision_qualifiers_allowed(&@1);
2359 $$ = ast_precision_medium;
2363 state->check_precision_qualifiers_allowed(&@1);
2364 $$ = ast_precision_low;
2369 STRUCT any_identifier '{' struct_declaration_list '}'
2371 void *ctx = state->linalloc;
2372 $$ = new(ctx) ast_struct_specifier($2, $4);
2373 $$->set_location_range(@2, @5);
2374 state->symbols->add_type($2, glsl_type::void_type);
2376 | STRUCT '{' struct_declaration_list '}'
2378 void *ctx = state->linalloc;
2380 /* All anonymous structs have the same name. This simplifies matching of
2381 * globals whose type is an unnamed struct.
2383 * It also avoids a memory leak when the same shader is compiled over and
2386 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2388 $$->set_location_range(@2, @4);
2392 struct_declaration_list:
2396 $1->link.self_link();
2398 | struct_declaration_list struct_declaration
2401 $$->link.insert_before(& $2->link);
2406 fully_specified_type struct_declarator_list ';'
2408 void *ctx = state->linalloc;
2409 ast_fully_specified_type *const type = $1;
2410 type->set_location(@1);
2412 if (state->has_bindless()) {
2413 ast_type_qualifier input_layout_mask;
2415 /* Allow to declare qualifiers for images. */
2416 input_layout_mask.flags.i = 0;
2417 input_layout_mask.flags.q.coherent = 1;
2418 input_layout_mask.flags.q._volatile = 1;
2419 input_layout_mask.flags.q.restrict_flag = 1;
2420 input_layout_mask.flags.q.read_only = 1;
2421 input_layout_mask.flags.q.write_only = 1;
2422 input_layout_mask.flags.q.explicit_image_format = 1;
2424 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2425 _mesa_glsl_error(&@1, state,
2426 "only precision and image qualifiers may be "
2427 "applied to structure members");
2430 if (type->qualifier.flags.i != 0)
2431 _mesa_glsl_error(&@1, state,
2432 "only precision qualifiers may be applied to "
2433 "structure members");
2436 $$ = new(ctx) ast_declarator_list(type);
2437 $$->set_location(@2);
2439 $$->declarations.push_degenerate_list_at_head(& $2->link);
2443 struct_declarator_list:
2447 $1->link.self_link();
2449 | struct_declarator_list ',' struct_declarator
2452 $$->link.insert_before(& $3->link);
2459 void *ctx = state->linalloc;
2460 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2461 $$->set_location(@1);
2463 | any_identifier array_specifier
2465 void *ctx = state->linalloc;
2466 $$ = new(ctx) ast_declaration($1, $2, NULL);
2467 $$->set_location_range(@1, @2);
2472 assignment_expression
2473 | '{' initializer_list '}'
2477 | '{' initializer_list ',' '}'
2486 void *ctx = state->linalloc;
2487 $$ = new(ctx) ast_aggregate_initializer();
2488 $$->set_location(@1);
2489 $$->expressions.push_tail(& $1->link);
2491 | initializer_list ',' initializer
2493 $1->expressions.push_tail(& $3->link);
2497 declaration_statement:
2501 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2504 compound_statement { $$ = (ast_node *) $1; }
2509 declaration_statement
2510 | expression_statement
2511 | selection_statement
2513 | iteration_statement
2521 void *ctx = state->linalloc;
2522 $$ = new(ctx) ast_compound_statement(true, NULL);
2523 $$->set_location_range(@1, @2);
2527 state->symbols->push_scope();
2531 void *ctx = state->linalloc;
2532 $$ = new(ctx) ast_compound_statement(true, $3);
2533 $$->set_location_range(@1, @4);
2534 state->symbols->pop_scope();
2538 statement_no_new_scope:
2539 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2543 compound_statement_no_new_scope:
2546 void *ctx = state->linalloc;
2547 $$ = new(ctx) ast_compound_statement(false, NULL);
2548 $$->set_location_range(@1, @2);
2550 | '{' statement_list '}'
2552 void *ctx = state->linalloc;
2553 $$ = new(ctx) ast_compound_statement(false, $2);
2554 $$->set_location_range(@1, @3);
2562 _mesa_glsl_error(& @1, state, "<nil> statement");
2567 $$->link.self_link();
2569 | statement_list statement
2572 _mesa_glsl_error(& @2, state, "<nil> statement");
2576 $$->link.insert_before(& $2->link);
2578 | statement_list extension_statement
2580 if (!state->allow_extension_directive_midshader) {
2581 _mesa_glsl_error(& @1, state,
2582 "#extension directive is not allowed "
2583 "in the middle of a shader");
2589 expression_statement:
2592 void *ctx = state->linalloc;
2593 $$ = new(ctx) ast_expression_statement(NULL);
2594 $$->set_location(@1);
2598 void *ctx = state->linalloc;
2599 $$ = new(ctx) ast_expression_statement($1);
2600 $$->set_location(@1);
2604 selection_statement:
2605 IF '(' expression ')' selection_rest_statement
2607 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2609 $$->set_location_range(@1, @5);
2613 selection_rest_statement:
2614 statement ELSE statement
2616 $$.then_statement = $1;
2617 $$.else_statement = $3;
2619 | statement %prec THEN
2621 $$.then_statement = $1;
2622 $$.else_statement = NULL;
2629 $$ = (ast_node *) $1;
2631 | fully_specified_type any_identifier '=' initializer
2633 void *ctx = state->linalloc;
2634 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2635 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2636 decl->set_location_range(@2, @4);
2637 declarator->set_location(@1);
2639 declarator->declarations.push_tail(&decl->link);
2645 * switch_statement grammar is based on the syntax described in the body
2646 * of the GLSL spec, not in it's appendix!!!
2649 SWITCH '(' expression ')' switch_body
2651 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2652 $$->set_location_range(@1, @5);
2659 $$ = new(state->linalloc) ast_switch_body(NULL);
2660 $$->set_location_range(@1, @2);
2662 | '{' case_statement_list '}'
2664 $$ = new(state->linalloc) ast_switch_body($2);
2665 $$->set_location_range(@1, @3);
2672 $$ = new(state->linalloc) ast_case_label($2);
2673 $$->set_location(@2);
2677 $$ = new(state->linalloc) ast_case_label(NULL);
2678 $$->set_location(@2);
2685 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2687 labels->labels.push_tail(& $1->link);
2689 $$->set_location(@1);
2691 | case_label_list case_label
2694 $$->labels.push_tail(& $2->link);
2699 case_label_list statement
2701 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2702 stmts->set_location(@2);
2704 stmts->stmts.push_tail(& $2->link);
2707 | case_statement statement
2710 $$->stmts.push_tail(& $2->link);
2714 case_statement_list:
2717 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2718 cases->set_location(@1);
2720 cases->cases.push_tail(& $1->link);
2723 | case_statement_list case_statement
2726 $$->cases.push_tail(& $2->link);
2730 iteration_statement:
2731 WHILE '(' condition ')' statement_no_new_scope
2733 void *ctx = state->linalloc;
2734 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2735 NULL, $3, NULL, $5);
2736 $$->set_location_range(@1, @4);
2738 | DO statement WHILE '(' expression ')' ';'
2740 void *ctx = state->linalloc;
2741 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2742 NULL, $5, NULL, $2);
2743 $$->set_location_range(@1, @6);
2745 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2747 void *ctx = state->linalloc;
2748 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2749 $3, $4.cond, $4.rest, $6);
2750 $$->set_location_range(@1, @6);
2755 expression_statement
2756 | declaration_statement
2773 | conditionopt ';' expression
2780 // Grammar Note: No 'goto'. Gotos are not supported.
2784 void *ctx = state->linalloc;
2785 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2786 $$->set_location(@1);
2790 void *ctx = state->linalloc;
2791 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2792 $$->set_location(@1);
2796 void *ctx = state->linalloc;
2797 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2798 $$->set_location(@1);
2800 | RETURN expression ';'
2802 void *ctx = state->linalloc;
2803 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2804 $$->set_location_range(@1, @2);
2806 | DISCARD ';' // Fragment shader only.
2808 void *ctx = state->linalloc;
2809 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2810 $$->set_location(@1);
2817 void *ctx = state->linalloc;
2818 $$ = new(ctx) ast_demote_statement();
2819 $$->set_location(@1);
2823 external_declaration:
2824 function_definition { $$ = $1; }
2825 | declaration { $$ = $1; }
2826 | pragma_statement { $$ = $1; }
2827 | layout_defaults { $$ = $1; }
2828 | ';' { $$ = NULL; }
2831 function_definition:
2832 function_prototype compound_statement_no_new_scope
2834 void *ctx = state->linalloc;
2835 $$ = new(ctx) ast_function_definition();
2836 $$->set_location_range(@1, @2);
2840 state->symbols->pop_scope();
2844 /* layout_qualifieropt is packed into this rule */
2846 basic_interface_block
2850 | layout_qualifier interface_block
2852 ast_interface_block *block = (ast_interface_block *) $2;
2854 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2855 block->layout.has_layout())) {
2863 | memory_qualifier interface_block
2865 ast_interface_block *block = (ast_interface_block *)$2;
2867 if (!block->default_layout.flags.q.buffer) {
2868 _mesa_glsl_error(& @1, state,
2869 "memory qualifiers can only be used in the "
2870 "declaration of shader storage blocks");
2872 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2880 basic_interface_block:
2881 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2883 ast_interface_block *const block = $6;
2885 if ($1.flags.q.uniform) {
2886 block->default_layout = *state->default_uniform_qualifier;
2887 } else if ($1.flags.q.buffer) {
2888 block->default_layout = *state->default_shader_storage_qualifier;
2890 block->block_name = $2;
2891 block->declarations.push_degenerate_list_at_head(& $4->link);
2893 _mesa_ast_process_interface_block(& @1, state, block, $1);
2899 interface_qualifier:
2902 memset(& $$, 0, sizeof($$));
2907 memset(& $$, 0, sizeof($$));
2912 memset(& $$, 0, sizeof($$));
2913 $$.flags.q.uniform = 1;
2917 memset(& $$, 0, sizeof($$));
2918 $$.flags.q.buffer = 1;
2920 | auxiliary_storage_qualifier interface_qualifier
2922 if (!$1.flags.q.patch) {
2923 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2925 if ($2.has_auxiliary_storage()) {
2926 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2929 $$.flags.q.patch = 1;
2936 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2940 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2941 $$->set_location(@1);
2943 | NEW_IDENTIFIER array_specifier
2945 $$ = new(state->linalloc) ast_interface_block($1, $2);
2946 $$->set_location_range(@1, @2);
2954 $1->link.self_link();
2956 | member_declaration member_list
2959 $2->link.insert_before(& $$->link);
2964 fully_specified_type struct_declarator_list ';'
2966 void *ctx = state->linalloc;
2967 ast_fully_specified_type *type = $1;
2968 type->set_location(@1);
2970 if (type->qualifier.flags.q.attribute) {
2971 _mesa_glsl_error(& @1, state,
2972 "keyword 'attribute' cannot be used with "
2973 "interface block member");
2974 } else if (type->qualifier.flags.q.varying) {
2975 _mesa_glsl_error(& @1, state,
2976 "keyword 'varying' cannot be used with "
2977 "interface block member");
2980 $$ = new(ctx) ast_declarator_list(type);
2981 $$->set_location(@2);
2983 $$->declarations.push_degenerate_list_at_head(& $2->link);
2987 layout_uniform_defaults:
2988 layout_qualifier layout_uniform_defaults
2991 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2995 | layout_qualifier UNIFORM ';'
2998 layout_buffer_defaults:
2999 layout_qualifier layout_buffer_defaults
3002 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3006 | layout_qualifier BUFFER ';'
3010 layout_qualifier layout_in_defaults
3013 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3016 if (!$$.validate_in_qualifier(& @1, state)) {
3020 | layout_qualifier IN_TOK ';'
3022 if (!$1.validate_in_qualifier(& @1, state)) {
3028 layout_out_defaults:
3029 layout_qualifier layout_out_defaults
3032 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
3035 if (!$$.validate_out_qualifier(& @1, state)) {
3039 | layout_qualifier OUT_TOK ';'
3041 if (!$1.validate_out_qualifier(& @1, state)) {
3048 layout_uniform_defaults
3051 if (!state->default_uniform_qualifier->
3052 merge_qualifier(& @1, state, $1, false)) {
3055 if (!state->default_uniform_qualifier->
3056 push_to_global(& @1, state)) {
3060 | layout_buffer_defaults
3063 if (!state->default_shader_storage_qualifier->
3064 merge_qualifier(& @1, state, $1, false)) {
3067 if (!state->default_shader_storage_qualifier->
3068 push_to_global(& @1, state)) {
3072 /* From the GLSL 4.50 spec, section 4.4.5:
3074 * "It is a compile-time error to specify the binding identifier for
3075 * the global scope or for block member declarations."
3077 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
3078 _mesa_glsl_error(& @1, state,
3079 "binding qualifier cannot be set for default layout");
3082 | layout_in_defaults
3085 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
3088 if (!state->in_qualifier->push_to_global(& @1, state)) {
3092 | layout_out_defaults
3095 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
3098 if (!state->out_qualifier->push_to_global(& @1, state)) {