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