glsl: Switch ast_type_qualifier to a 128-bit bitset.
[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 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1592 "`%s'", $1);
1593 YYERROR;
1594 }
1595 }
1596 | any_identifier '=' constant_expression
1597 {
1598 memset(& $$, 0, sizeof($$));
1599 void *ctx = state->linalloc;
1600
1601 if ($3->oper != ast_int_constant &&
1602 $3->oper != ast_uint_constant &&
1603 !state->has_enhanced_layouts()) {
1604 _mesa_glsl_error(& @1, state,
1605 "compile-time constant expressions require "
1606 "GLSL 4.40 or ARB_enhanced_layouts");
1607 }
1608
1609 if (match_layout_qualifier("align", $1, state) == 0) {
1610 if (!state->has_enhanced_layouts()) {
1611 _mesa_glsl_error(& @1, state,
1612 "align qualifier requires "
1613 "GLSL 4.40 or ARB_enhanced_layouts");
1614 } else {
1615 $$.flags.q.explicit_align = 1;
1616 $$.align = $3;
1617 }
1618 }
1619
1620 if (match_layout_qualifier("location", $1, state) == 0) {
1621 $$.flags.q.explicit_location = 1;
1622
1623 if ($$.flags.q.attribute == 1 &&
1624 state->ARB_explicit_attrib_location_warn) {
1625 _mesa_glsl_warning(& @1, state,
1626 "GL_ARB_explicit_attrib_location layout "
1627 "identifier `%s' used", $1);
1628 }
1629 $$.location = $3;
1630 }
1631
1632 if (match_layout_qualifier("component", $1, state) == 0) {
1633 if (!state->has_enhanced_layouts()) {
1634 _mesa_glsl_error(& @1, state,
1635 "component qualifier requires "
1636 "GLSL 4.40 or ARB_enhanced_layouts");
1637 } else {
1638 $$.flags.q.explicit_component = 1;
1639 $$.component = $3;
1640 }
1641 }
1642
1643 if (match_layout_qualifier("index", $1, state) == 0) {
1644 if (state->es_shader && !state->EXT_blend_func_extended_enable) {
1645 _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
1646 YYERROR;
1647 }
1648
1649 $$.flags.q.explicit_index = 1;
1650 $$.index = $3;
1651 }
1652
1653 if ((state->has_420pack_or_es31() ||
1654 state->has_atomic_counters() ||
1655 state->has_shader_storage_buffer_objects()) &&
1656 match_layout_qualifier("binding", $1, state) == 0) {
1657 $$.flags.q.explicit_binding = 1;
1658 $$.binding = $3;
1659 }
1660
1661 if ((state->has_atomic_counters() ||
1662 state->has_enhanced_layouts()) &&
1663 match_layout_qualifier("offset", $1, state) == 0) {
1664 $$.flags.q.explicit_offset = 1;
1665 $$.offset = $3;
1666 }
1667
1668 if (match_layout_qualifier("max_vertices", $1, state) == 0) {
1669 $$.flags.q.max_vertices = 1;
1670 $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
1671 if (!state->has_geometry_shader()) {
1672 _mesa_glsl_error(& @3, state,
1673 "#version 150 max_vertices qualifier "
1674 "specified", $3);
1675 }
1676 }
1677
1678 if (state->stage == MESA_SHADER_GEOMETRY) {
1679 if (match_layout_qualifier("stream", $1, state) == 0 &&
1680 state->check_explicit_attrib_stream_allowed(& @3)) {
1681 $$.flags.q.stream = 1;
1682 $$.flags.q.explicit_stream = 1;
1683 $$.stream = $3;
1684 }
1685 }
1686
1687 if (state->has_enhanced_layouts()) {
1688 if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
1689 $$.flags.q.xfb_buffer = 1;
1690 $$.flags.q.explicit_xfb_buffer = 1;
1691 $$.xfb_buffer = $3;
1692 }
1693
1694 if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
1695 $$.flags.q.explicit_xfb_offset = 1;
1696 $$.offset = $3;
1697 }
1698
1699 if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
1700 $$.flags.q.xfb_stride = 1;
1701 $$.flags.q.explicit_xfb_stride = 1;
1702 $$.xfb_stride = $3;
1703 }
1704 }
1705
1706 static const char * const local_size_qualifiers[3] = {
1707 "local_size_x",
1708 "local_size_y",
1709 "local_size_z",
1710 };
1711 for (int i = 0; i < 3; i++) {
1712 if (match_layout_qualifier(local_size_qualifiers[i], $1,
1713 state) == 0) {
1714 if (!state->has_compute_shader()) {
1715 _mesa_glsl_error(& @3, state,
1716 "%s qualifier requires GLSL 4.30 or "
1717 "GLSL ES 3.10 or ARB_compute_shader",
1718 local_size_qualifiers[i]);
1719 YYERROR;
1720 } else {
1721 $$.flags.q.local_size |= (1 << i);
1722 $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
1723 }
1724 break;
1725 }
1726 }
1727
1728 if (match_layout_qualifier("invocations", $1, state) == 0) {
1729 $$.flags.q.invocations = 1;
1730 $$.invocations = new(ctx) ast_layout_expression(@1, $3);
1731 if (!state->is_version(400, 320) &&
1732 !state->ARB_gpu_shader5_enable &&
1733 !state->OES_geometry_shader_enable &&
1734 !state->EXT_geometry_shader_enable) {
1735 _mesa_glsl_error(& @3, state,
1736 "GL_ARB_gpu_shader5 invocations "
1737 "qualifier specified", $3);
1738 }
1739 }
1740
1741 /* Layout qualifiers for tessellation control shaders. */
1742 if (match_layout_qualifier("vertices", $1, state) == 0) {
1743 $$.flags.q.vertices = 1;
1744 $$.vertices = new(ctx) ast_layout_expression(@1, $3);
1745 if (!state->has_tessellation_shader()) {
1746 _mesa_glsl_error(& @1, state,
1747 "vertices qualifier requires GLSL 4.00 or "
1748 "ARB_tessellation_shader");
1749 }
1750 }
1751
1752 /* If the identifier didn't match any known layout identifiers,
1753 * emit an error.
1754 */
1755 if (!$$.flags.i) {
1756 _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
1757 "`%s'", $1);
1758 YYERROR;
1759 }
1760 }
1761 | interface_block_layout_qualifier
1762 {
1763 $$ = $1;
1764 /* Layout qualifiers for ARB_uniform_buffer_object. */
1765 if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
1766 _mesa_glsl_error(& @1, state,
1767 "#version 140 / GL_ARB_uniform_buffer_object "
1768 "layout qualifier `%s' is used", $1);
1769 } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
1770 _mesa_glsl_warning(& @1, state,
1771 "#version 140 / GL_ARB_uniform_buffer_object "
1772 "layout qualifier `%s' is used", $1);
1773 }
1774 }
1775 ;
1776
1777 /* This is a separate language rule because we parse these as tokens
1778 * (due to them being reserved keywords) instead of identifiers like
1779 * most qualifiers. See the any_identifier path of
1780 * layout_qualifier_id for the others.
1781 *
1782 * Note that since layout qualifiers are case-insensitive in desktop
1783 * GLSL, all of these qualifiers need to be handled as identifiers as
1784 * well (by the any_identifier path of layout_qualifier_id).
1785 */
1786 interface_block_layout_qualifier:
1787 ROW_MAJOR
1788 {
1789 memset(& $$, 0, sizeof($$));
1790 $$.flags.q.row_major = 1;
1791 }
1792 | PACKED_TOK
1793 {
1794 memset(& $$, 0, sizeof($$));
1795 $$.flags.q.packed = 1;
1796 }
1797 | SHARED
1798 {
1799 memset(& $$, 0, sizeof($$));
1800 $$.flags.q.shared = 1;
1801 }
1802 ;
1803
1804 subroutine_qualifier:
1805 SUBROUTINE
1806 {
1807 memset(& $$, 0, sizeof($$));
1808 $$.flags.q.subroutine = 1;
1809 }
1810 | SUBROUTINE '(' subroutine_type_list ')'
1811 {
1812 memset(& $$, 0, sizeof($$));
1813 $$.flags.q.subroutine = 1;
1814 $$.subroutine_list = $3;
1815 }
1816 ;
1817
1818 subroutine_type_list:
1819 any_identifier
1820 {
1821 void *ctx = state->linalloc;
1822 ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
1823 decl->set_location(@1);
1824
1825 $$ = new(ctx) ast_subroutine_list();
1826 $$->declarations.push_tail(&decl->link);
1827 }
1828 | subroutine_type_list ',' any_identifier
1829 {
1830 void *ctx = state->linalloc;
1831 ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
1832 decl->set_location(@3);
1833
1834 $$ = $1;
1835 $$->declarations.push_tail(&decl->link);
1836 }
1837 ;
1838
1839 interpolation_qualifier:
1840 SMOOTH
1841 {
1842 memset(& $$, 0, sizeof($$));
1843 $$.flags.q.smooth = 1;
1844 }
1845 | FLAT
1846 {
1847 memset(& $$, 0, sizeof($$));
1848 $$.flags.q.flat = 1;
1849 }
1850 | NOPERSPECTIVE
1851 {
1852 memset(& $$, 0, sizeof($$));
1853 $$.flags.q.noperspective = 1;
1854 }
1855 ;
1856
1857 type_qualifier:
1858 /* Single qualifiers */
1859 INVARIANT
1860 {
1861 memset(& $$, 0, sizeof($$));
1862 $$.flags.q.invariant = 1;
1863 }
1864 | PRECISE
1865 {
1866 memset(& $$, 0, sizeof($$));
1867 $$.flags.q.precise = 1;
1868 }
1869 | auxiliary_storage_qualifier
1870 | storage_qualifier
1871 | interpolation_qualifier
1872 | layout_qualifier
1873 | memory_qualifier
1874 | subroutine_qualifier
1875 | precision_qualifier
1876 {
1877 memset(&$$, 0, sizeof($$));
1878 $$.precision = $1;
1879 }
1880
1881 /* Multiple qualifiers:
1882 * In GLSL 4.20, these can be specified in any order. In earlier versions,
1883 * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
1884 *
1885 * invariant interpolation auxiliary storage precision ...or...
1886 * layout storage precision
1887 *
1888 * Each qualifier's rule ensures that the accumulated qualifiers on the right
1889 * side don't contain any that must appear on the left hand side.
1890 * For example, when processing a storage qualifier, we check that there are
1891 * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
1892 */
1893 | PRECISE type_qualifier
1894 {
1895 if ($2.flags.q.precise)
1896 _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
1897
1898 $$ = $2;
1899 $$.flags.q.precise = 1;
1900 }
1901 | INVARIANT type_qualifier
1902 {
1903 if ($2.flags.q.invariant)
1904 _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
1905
1906 if (!state->has_420pack_or_es31() && $2.flags.q.precise)
1907 _mesa_glsl_error(&@1, state,
1908 "\"invariant\" must come after \"precise\"");
1909
1910 $$ = $2;
1911 $$.flags.q.invariant = 1;
1912
1913 /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
1914 *
1915 * "Only variables output from a shader can be candidates for invariance.
1916 * This includes user-defined output variables and the built-in output
1917 * variables. As only outputs can be declared as invariant, an invariant
1918 * output from one shader stage will still match an input of a subsequent
1919 * stage without the input being declared as invariant."
1920 *
1921 * On the desktop side, this text first appears in GLSL 4.30.
1922 */
1923 if (state->is_version(430, 300) && $$.flags.q.in)
1924 _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
1925 }
1926 | interpolation_qualifier type_qualifier
1927 {
1928 /* Section 4.3 of the GLSL 1.40 specification states:
1929 * "...qualified with one of these interpolation qualifiers"
1930 *
1931 * GLSL 1.30 claims to allow "one or more", but insists that:
1932 * "These interpolation qualifiers may only precede the qualifiers in,
1933 * centroid in, out, or centroid out in a declaration."
1934 *
1935 * ...which means that e.g. smooth can't precede smooth, so there can be
1936 * only one after all, and the 1.40 text is a clarification, not a change.
1937 */
1938 if ($2.has_interpolation())
1939 _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
1940
1941 if (!state->has_420pack_or_es31() &&
1942 ($2.flags.q.precise || $2.flags.q.invariant)) {
1943 _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
1944 "after \"precise\" or \"invariant\"");
1945 }
1946
1947 $$ = $1;
1948 $$.merge_qualifier(&@1, state, $2, false);
1949 }
1950 | layout_qualifier type_qualifier
1951 {
1952 /* In the absence of ARB_shading_language_420pack, layout qualifiers may
1953 * appear no later than auxiliary storage qualifiers. There is no
1954 * particularly clear spec language mandating this, but in all examples
1955 * the layout qualifier precedes the storage qualifier.
1956 *
1957 * We allow combinations of layout with interpolation, invariant or
1958 * precise qualifiers since these are useful in ARB_separate_shader_objects.
1959 * There is no clear spec guidance on this either.
1960 */
1961 $$ = $1;
1962 $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
1963 }
1964 | subroutine_qualifier type_qualifier
1965 {
1966 $$ = $1;
1967 $$.merge_qualifier(&@1, state, $2, false);
1968 }
1969 | auxiliary_storage_qualifier type_qualifier
1970 {
1971 if ($2.has_auxiliary_storage()) {
1972 _mesa_glsl_error(&@1, state,
1973 "duplicate auxiliary storage qualifier (centroid or sample)");
1974 }
1975
1976 if (!state->has_420pack_or_es31() &&
1977 ($2.flags.q.precise || $2.flags.q.invariant ||
1978 $2.has_interpolation() || $2.has_layout())) {
1979 _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
1980 "just before storage qualifiers");
1981 }
1982 $$ = $1;
1983 $$.merge_qualifier(&@1, state, $2, false);
1984 }
1985 | storage_qualifier type_qualifier
1986 {
1987 /* Section 4.3 of the GLSL 1.20 specification states:
1988 * "Variable declarations may have a storage qualifier specified..."
1989 * 1.30 clarifies this to "may have one storage qualifier".
1990 */
1991 if ($2.has_storage())
1992 _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
1993
1994 if (!state->has_420pack_or_es31() &&
1995 ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
1996 $2.has_layout() || $2.has_auxiliary_storage())) {
1997 _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
1998 "precise, invariant, interpolation, layout and auxiliary "
1999 "storage qualifiers");
2000 }
2001
2002 $$ = $1;
2003 $$.merge_qualifier(&@1, state, $2, false);
2004 }
2005 | precision_qualifier type_qualifier
2006 {
2007 if ($2.precision != ast_precision_none)
2008 _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
2009
2010 if (!(state->has_420pack_or_es31()) &&
2011 $2.flags.i != 0)
2012 _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
2013
2014 $$ = $2;
2015 $$.precision = $1;
2016 }
2017 | memory_qualifier type_qualifier
2018 {
2019 $$ = $1;
2020 $$.merge_qualifier(&@1, state, $2, false);
2021 }
2022 ;
2023
2024 auxiliary_storage_qualifier:
2025 CENTROID
2026 {
2027 memset(& $$, 0, sizeof($$));
2028 $$.flags.q.centroid = 1;
2029 }
2030 | SAMPLE
2031 {
2032 memset(& $$, 0, sizeof($$));
2033 $$.flags.q.sample = 1;
2034 }
2035 | PATCH
2036 {
2037 memset(& $$, 0, sizeof($$));
2038 $$.flags.q.patch = 1;
2039 }
2040
2041 storage_qualifier:
2042 CONST_TOK
2043 {
2044 memset(& $$, 0, sizeof($$));
2045 $$.flags.q.constant = 1;
2046 }
2047 | ATTRIBUTE
2048 {
2049 memset(& $$, 0, sizeof($$));
2050 $$.flags.q.attribute = 1;
2051 }
2052 | VARYING
2053 {
2054 memset(& $$, 0, sizeof($$));
2055 $$.flags.q.varying = 1;
2056 }
2057 | IN_TOK
2058 {
2059 memset(& $$, 0, sizeof($$));
2060 $$.flags.q.in = 1;
2061 }
2062 | OUT_TOK
2063 {
2064 memset(& $$, 0, sizeof($$));
2065 $$.flags.q.out = 1;
2066
2067 if (state->stage == MESA_SHADER_GEOMETRY &&
2068 state->has_explicit_attrib_stream()) {
2069 /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
2070 * spec says:
2071 *
2072 * "If the block or variable is declared with the stream
2073 * identifier, it is associated with the specified stream;
2074 * otherwise, it is associated with the current default stream."
2075 */
2076 $$.flags.q.stream = 1;
2077 $$.flags.q.explicit_stream = 0;
2078 $$.stream = state->out_qualifier->stream;
2079 }
2080
2081 if (state->has_enhanced_layouts()) {
2082 $$.flags.q.xfb_buffer = 1;
2083 $$.flags.q.explicit_xfb_buffer = 0;
2084 $$.xfb_buffer = state->out_qualifier->xfb_buffer;
2085 }
2086 }
2087 | INOUT_TOK
2088 {
2089 memset(& $$, 0, sizeof($$));
2090 $$.flags.q.in = 1;
2091 $$.flags.q.out = 1;
2092
2093 if (!state->has_framebuffer_fetch() ||
2094 !state->is_version(130, 300) ||
2095 state->stage != MESA_SHADER_FRAGMENT)
2096 _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
2097 "declared as both input and output");
2098 }
2099 | UNIFORM
2100 {
2101 memset(& $$, 0, sizeof($$));
2102 $$.flags.q.uniform = 1;
2103 }
2104 | BUFFER
2105 {
2106 memset(& $$, 0, sizeof($$));
2107 $$.flags.q.buffer = 1;
2108 }
2109 | SHARED
2110 {
2111 memset(& $$, 0, sizeof($$));
2112 $$.flags.q.shared_storage = 1;
2113 }
2114 ;
2115
2116 memory_qualifier:
2117 COHERENT
2118 {
2119 memset(& $$, 0, sizeof($$));
2120 $$.flags.q.coherent = 1;
2121 }
2122 | VOLATILE
2123 {
2124 memset(& $$, 0, sizeof($$));
2125 $$.flags.q._volatile = 1;
2126 }
2127 | RESTRICT
2128 {
2129 STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
2130 memset(& $$, 0, sizeof($$));
2131 $$.flags.q.restrict_flag = 1;
2132 }
2133 | READONLY
2134 {
2135 memset(& $$, 0, sizeof($$));
2136 $$.flags.q.read_only = 1;
2137 }
2138 | WRITEONLY
2139 {
2140 memset(& $$, 0, sizeof($$));
2141 $$.flags.q.write_only = 1;
2142 }
2143 ;
2144
2145 array_specifier:
2146 '[' ']'
2147 {
2148 void *ctx = state->linalloc;
2149 $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
2150 ast_unsized_array_dim, NULL,
2151 NULL, NULL));
2152 $$->set_location_range(@1, @2);
2153 }
2154 | '[' constant_expression ']'
2155 {
2156 void *ctx = state->linalloc;
2157 $$ = new(ctx) ast_array_specifier(@1, $2);
2158 $$->set_location_range(@1, @3);
2159 }
2160 | array_specifier '[' ']'
2161 {
2162 void *ctx = state->linalloc;
2163 $$ = $1;
2164
2165 if (state->check_arrays_of_arrays_allowed(& @1)) {
2166 $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
2167 NULL, NULL));
2168 }
2169 }
2170 | array_specifier '[' constant_expression ']'
2171 {
2172 $$ = $1;
2173
2174 if (state->check_arrays_of_arrays_allowed(& @1)) {
2175 $$->add_dimension($3);
2176 }
2177 }
2178 ;
2179
2180 type_specifier:
2181 type_specifier_nonarray
2182 | type_specifier_nonarray array_specifier
2183 {
2184 $$ = $1;
2185 $$->array_specifier = $2;
2186 }
2187 ;
2188
2189 type_specifier_nonarray:
2190 basic_type_specifier_nonarray
2191 {
2192 void *ctx = state->linalloc;
2193 $$ = new(ctx) ast_type_specifier($1);
2194 $$->set_location(@1);
2195 }
2196 | struct_specifier
2197 {
2198 void *ctx = state->linalloc;
2199 $$ = new(ctx) ast_type_specifier($1);
2200 $$->set_location(@1);
2201 }
2202 | TYPE_IDENTIFIER
2203 {
2204 void *ctx = state->linalloc;
2205 $$ = new(ctx) ast_type_specifier($1);
2206 $$->set_location(@1);
2207 }
2208 ;
2209
2210 basic_type_specifier_nonarray:
2211 VOID_TOK { $$ = glsl_type::void_type; }
2212 | BASIC_TYPE_TOK { $$ = $1; };
2213 ;
2214
2215 precision_qualifier:
2216 HIGHP
2217 {
2218 state->check_precision_qualifiers_allowed(&@1);
2219 $$ = ast_precision_high;
2220 }
2221 | MEDIUMP
2222 {
2223 state->check_precision_qualifiers_allowed(&@1);
2224 $$ = ast_precision_medium;
2225 }
2226 | LOWP
2227 {
2228 state->check_precision_qualifiers_allowed(&@1);
2229 $$ = ast_precision_low;
2230 }
2231 ;
2232
2233 struct_specifier:
2234 STRUCT any_identifier '{' struct_declaration_list '}'
2235 {
2236 void *ctx = state->linalloc;
2237 $$ = new(ctx) ast_struct_specifier($2, $4);
2238 $$->set_location_range(@2, @5);
2239 state->symbols->add_type($2, glsl_type::void_type);
2240 }
2241 | STRUCT '{' struct_declaration_list '}'
2242 {
2243 void *ctx = state->linalloc;
2244
2245 /* All anonymous structs have the same name. This simplifies matching of
2246 * globals whose type is an unnamed struct.
2247 *
2248 * It also avoids a memory leak when the same shader is compiled over and
2249 * over again.
2250 */
2251 $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
2252
2253 $$->set_location_range(@2, @4);
2254 }
2255 ;
2256
2257 struct_declaration_list:
2258 struct_declaration
2259 {
2260 $$ = $1;
2261 $1->link.self_link();
2262 }
2263 | struct_declaration_list struct_declaration
2264 {
2265 $$ = $1;
2266 $$->link.insert_before(& $2->link);
2267 }
2268 ;
2269
2270 struct_declaration:
2271 fully_specified_type struct_declarator_list ';'
2272 {
2273 void *ctx = state->linalloc;
2274 ast_fully_specified_type *const type = $1;
2275 type->set_location(@1);
2276
2277 if (state->has_bindless()) {
2278 ast_type_qualifier input_layout_mask;
2279
2280 /* Allow to declare qualifiers for images. */
2281 input_layout_mask.flags.i = 0;
2282 input_layout_mask.flags.q.coherent = 1;
2283 input_layout_mask.flags.q._volatile = 1;
2284 input_layout_mask.flags.q.restrict_flag = 1;
2285 input_layout_mask.flags.q.read_only = 1;
2286 input_layout_mask.flags.q.write_only = 1;
2287 input_layout_mask.flags.q.explicit_image_format = 1;
2288
2289 if ((type->qualifier.flags.i & ~input_layout_mask.flags.i) != 0) {
2290 _mesa_glsl_error(&@1, state,
2291 "only precision and image qualifiers may be "
2292 "applied to structure members");
2293 }
2294 } else {
2295 if (type->qualifier.flags.i != 0)
2296 _mesa_glsl_error(&@1, state,
2297 "only precision qualifiers may be applied to "
2298 "structure members");
2299 }
2300
2301 $$ = new(ctx) ast_declarator_list(type);
2302 $$->set_location(@2);
2303
2304 $$->declarations.push_degenerate_list_at_head(& $2->link);
2305 }
2306 ;
2307
2308 struct_declarator_list:
2309 struct_declarator
2310 {
2311 $$ = $1;
2312 $1->link.self_link();
2313 }
2314 | struct_declarator_list ',' struct_declarator
2315 {
2316 $$ = $1;
2317 $$->link.insert_before(& $3->link);
2318 }
2319 ;
2320
2321 struct_declarator:
2322 any_identifier
2323 {
2324 void *ctx = state->linalloc;
2325 $$ = new(ctx) ast_declaration($1, NULL, NULL);
2326 $$->set_location(@1);
2327 }
2328 | any_identifier array_specifier
2329 {
2330 void *ctx = state->linalloc;
2331 $$ = new(ctx) ast_declaration($1, $2, NULL);
2332 $$->set_location_range(@1, @2);
2333 }
2334 ;
2335
2336 initializer:
2337 assignment_expression
2338 | '{' initializer_list '}'
2339 {
2340 $$ = $2;
2341 }
2342 | '{' initializer_list ',' '}'
2343 {
2344 $$ = $2;
2345 }
2346 ;
2347
2348 initializer_list:
2349 initializer
2350 {
2351 void *ctx = state->linalloc;
2352 $$ = new(ctx) ast_aggregate_initializer();
2353 $$->set_location(@1);
2354 $$->expressions.push_tail(& $1->link);
2355 }
2356 | initializer_list ',' initializer
2357 {
2358 $1->expressions.push_tail(& $3->link);
2359 }
2360 ;
2361
2362 declaration_statement:
2363 declaration
2364 ;
2365
2366 // Grammar Note: labeled statements for SWITCH only; 'goto' is not
2367 // supported.
2368 statement:
2369 compound_statement { $$ = (ast_node *) $1; }
2370 | simple_statement
2371 ;
2372
2373 simple_statement:
2374 declaration_statement
2375 | expression_statement
2376 | selection_statement
2377 | switch_statement
2378 | iteration_statement
2379 | jump_statement
2380 ;
2381
2382 compound_statement:
2383 '{' '}'
2384 {
2385 void *ctx = state->linalloc;
2386 $$ = new(ctx) ast_compound_statement(true, NULL);
2387 $$->set_location_range(@1, @2);
2388 }
2389 | '{'
2390 {
2391 state->symbols->push_scope();
2392 }
2393 statement_list '}'
2394 {
2395 void *ctx = state->linalloc;
2396 $$ = new(ctx) ast_compound_statement(true, $3);
2397 $$->set_location_range(@1, @4);
2398 state->symbols->pop_scope();
2399 }
2400 ;
2401
2402 statement_no_new_scope:
2403 compound_statement_no_new_scope { $$ = (ast_node *) $1; }
2404 | simple_statement
2405 ;
2406
2407 compound_statement_no_new_scope:
2408 '{' '}'
2409 {
2410 void *ctx = state->linalloc;
2411 $$ = new(ctx) ast_compound_statement(false, NULL);
2412 $$->set_location_range(@1, @2);
2413 }
2414 | '{' statement_list '}'
2415 {
2416 void *ctx = state->linalloc;
2417 $$ = new(ctx) ast_compound_statement(false, $2);
2418 $$->set_location_range(@1, @3);
2419 }
2420 ;
2421
2422 statement_list:
2423 statement
2424 {
2425 if ($1 == NULL) {
2426 _mesa_glsl_error(& @1, state, "<nil> statement");
2427 assert($1 != NULL);
2428 }
2429
2430 $$ = $1;
2431 $$->link.self_link();
2432 }
2433 | statement_list statement
2434 {
2435 if ($2 == NULL) {
2436 _mesa_glsl_error(& @2, state, "<nil> statement");
2437 assert($2 != NULL);
2438 }
2439 $$ = $1;
2440 $$->link.insert_before(& $2->link);
2441 }
2442 ;
2443
2444 expression_statement:
2445 ';'
2446 {
2447 void *ctx = state->linalloc;
2448 $$ = new(ctx) ast_expression_statement(NULL);
2449 $$->set_location(@1);
2450 }
2451 | expression ';'
2452 {
2453 void *ctx = state->linalloc;
2454 $$ = new(ctx) ast_expression_statement($1);
2455 $$->set_location(@1);
2456 }
2457 ;
2458
2459 selection_statement:
2460 IF '(' expression ')' selection_rest_statement
2461 {
2462 $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
2463 $5.else_statement);
2464 $$->set_location_range(@1, @5);
2465 }
2466 ;
2467
2468 selection_rest_statement:
2469 statement ELSE statement
2470 {
2471 $$.then_statement = $1;
2472 $$.else_statement = $3;
2473 }
2474 | statement %prec THEN
2475 {
2476 $$.then_statement = $1;
2477 $$.else_statement = NULL;
2478 }
2479 ;
2480
2481 condition:
2482 expression
2483 {
2484 $$ = (ast_node *) $1;
2485 }
2486 | fully_specified_type any_identifier '=' initializer
2487 {
2488 void *ctx = state->linalloc;
2489 ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
2490 ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
2491 decl->set_location_range(@2, @4);
2492 declarator->set_location(@1);
2493
2494 declarator->declarations.push_tail(&decl->link);
2495 $$ = declarator;
2496 }
2497 ;
2498
2499 /*
2500 * switch_statement grammar is based on the syntax described in the body
2501 * of the GLSL spec, not in it's appendix!!!
2502 */
2503 switch_statement:
2504 SWITCH '(' expression ')' switch_body
2505 {
2506 $$ = new(state->linalloc) ast_switch_statement($3, $5);
2507 $$->set_location_range(@1, @5);
2508 }
2509 ;
2510
2511 switch_body:
2512 '{' '}'
2513 {
2514 $$ = new(state->linalloc) ast_switch_body(NULL);
2515 $$->set_location_range(@1, @2);
2516 }
2517 | '{' case_statement_list '}'
2518 {
2519 $$ = new(state->linalloc) ast_switch_body($2);
2520 $$->set_location_range(@1, @3);
2521 }
2522 ;
2523
2524 case_label:
2525 CASE expression ':'
2526 {
2527 $$ = new(state->linalloc) ast_case_label($2);
2528 $$->set_location(@2);
2529 }
2530 | DEFAULT ':'
2531 {
2532 $$ = new(state->linalloc) ast_case_label(NULL);
2533 $$->set_location(@2);
2534 }
2535 ;
2536
2537 case_label_list:
2538 case_label
2539 {
2540 ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
2541
2542 labels->labels.push_tail(& $1->link);
2543 $$ = labels;
2544 $$->set_location(@1);
2545 }
2546 | case_label_list case_label
2547 {
2548 $$ = $1;
2549 $$->labels.push_tail(& $2->link);
2550 }
2551 ;
2552
2553 case_statement:
2554 case_label_list statement
2555 {
2556 ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
2557 stmts->set_location(@2);
2558
2559 stmts->stmts.push_tail(& $2->link);
2560 $$ = stmts;
2561 }
2562 | case_statement statement
2563 {
2564 $$ = $1;
2565 $$->stmts.push_tail(& $2->link);
2566 }
2567 ;
2568
2569 case_statement_list:
2570 case_statement
2571 {
2572 ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
2573 cases->set_location(@1);
2574
2575 cases->cases.push_tail(& $1->link);
2576 $$ = cases;
2577 }
2578 | case_statement_list case_statement
2579 {
2580 $$ = $1;
2581 $$->cases.push_tail(& $2->link);
2582 }
2583 ;
2584
2585 iteration_statement:
2586 WHILE '(' condition ')' statement_no_new_scope
2587 {
2588 void *ctx = state->linalloc;
2589 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
2590 NULL, $3, NULL, $5);
2591 $$->set_location_range(@1, @4);
2592 }
2593 | DO statement WHILE '(' expression ')' ';'
2594 {
2595 void *ctx = state->linalloc;
2596 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
2597 NULL, $5, NULL, $2);
2598 $$->set_location_range(@1, @6);
2599 }
2600 | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
2601 {
2602 void *ctx = state->linalloc;
2603 $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
2604 $3, $4.cond, $4.rest, $6);
2605 $$->set_location_range(@1, @6);
2606 }
2607 ;
2608
2609 for_init_statement:
2610 expression_statement
2611 | declaration_statement
2612 ;
2613
2614 conditionopt:
2615 condition
2616 | /* empty */
2617 {
2618 $$ = NULL;
2619 }
2620 ;
2621
2622 for_rest_statement:
2623 conditionopt ';'
2624 {
2625 $$.cond = $1;
2626 $$.rest = NULL;
2627 }
2628 | conditionopt ';' expression
2629 {
2630 $$.cond = $1;
2631 $$.rest = $3;
2632 }
2633 ;
2634
2635 // Grammar Note: No 'goto'. Gotos are not supported.
2636 jump_statement:
2637 CONTINUE ';'
2638 {
2639 void *ctx = state->linalloc;
2640 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
2641 $$->set_location(@1);
2642 }
2643 | BREAK ';'
2644 {
2645 void *ctx = state->linalloc;
2646 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
2647 $$->set_location(@1);
2648 }
2649 | RETURN ';'
2650 {
2651 void *ctx = state->linalloc;
2652 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
2653 $$->set_location(@1);
2654 }
2655 | RETURN expression ';'
2656 {
2657 void *ctx = state->linalloc;
2658 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
2659 $$->set_location_range(@1, @2);
2660 }
2661 | DISCARD ';' // Fragment shader only.
2662 {
2663 void *ctx = state->linalloc;
2664 $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
2665 $$->set_location(@1);
2666 }
2667 ;
2668
2669 external_declaration:
2670 function_definition { $$ = $1; }
2671 | declaration { $$ = $1; }
2672 | pragma_statement { $$ = NULL; }
2673 | layout_defaults { $$ = $1; }
2674 ;
2675
2676 function_definition:
2677 function_prototype compound_statement_no_new_scope
2678 {
2679 void *ctx = state->linalloc;
2680 $$ = new(ctx) ast_function_definition();
2681 $$->set_location_range(@1, @2);
2682 $$->prototype = $1;
2683 $$->body = $2;
2684
2685 state->symbols->pop_scope();
2686 }
2687 ;
2688
2689 /* layout_qualifieropt is packed into this rule */
2690 interface_block:
2691 basic_interface_block
2692 {
2693 $$ = $1;
2694 }
2695 | layout_qualifier interface_block
2696 {
2697 ast_interface_block *block = (ast_interface_block *) $2;
2698
2699 if (!$1.merge_qualifier(& @1, state, block->layout, false,
2700 block->layout.has_layout())) {
2701 YYERROR;
2702 }
2703
2704 block->layout = $1;
2705
2706 $$ = block;
2707 }
2708 | memory_qualifier interface_block
2709 {
2710 ast_interface_block *block = (ast_interface_block *)$2;
2711
2712 if (!block->default_layout.flags.q.buffer) {
2713 _mesa_glsl_error(& @1, state,
2714 "memory qualifiers can only be used in the "
2715 "declaration of shader storage blocks");
2716 }
2717 if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
2718 YYERROR;
2719 }
2720 block->layout = $1;
2721 $$ = block;
2722 }
2723 ;
2724
2725 basic_interface_block:
2726 interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
2727 {
2728 ast_interface_block *const block = $6;
2729
2730 if ($1.flags.q.uniform) {
2731 block->default_layout = *state->default_uniform_qualifier;
2732 } else if ($1.flags.q.buffer) {
2733 block->default_layout = *state->default_shader_storage_qualifier;
2734 }
2735 block->block_name = $2;
2736 block->declarations.push_degenerate_list_at_head(& $4->link);
2737
2738 _mesa_ast_process_interface_block(& @1, state, block, $1);
2739
2740 $$ = block;
2741 }
2742 ;
2743
2744 interface_qualifier:
2745 IN_TOK
2746 {
2747 memset(& $$, 0, sizeof($$));
2748 $$.flags.q.in = 1;
2749 }
2750 | OUT_TOK
2751 {
2752 memset(& $$, 0, sizeof($$));
2753 $$.flags.q.out = 1;
2754 }
2755 | UNIFORM
2756 {
2757 memset(& $$, 0, sizeof($$));
2758 $$.flags.q.uniform = 1;
2759 }
2760 | BUFFER
2761 {
2762 memset(& $$, 0, sizeof($$));
2763 $$.flags.q.buffer = 1;
2764 }
2765 | auxiliary_storage_qualifier interface_qualifier
2766 {
2767 if (!$1.flags.q.patch) {
2768 _mesa_glsl_error(&@1, state, "invalid interface qualifier");
2769 }
2770 if ($2.has_auxiliary_storage()) {
2771 _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
2772 }
2773 $$ = $2;
2774 $$.flags.q.patch = 1;
2775 }
2776 ;
2777
2778 instance_name_opt:
2779 /* empty */
2780 {
2781 $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
2782 }
2783 | NEW_IDENTIFIER
2784 {
2785 $$ = new(state->linalloc) ast_interface_block($1, NULL);
2786 $$->set_location(@1);
2787 }
2788 | NEW_IDENTIFIER array_specifier
2789 {
2790 $$ = new(state->linalloc) ast_interface_block($1, $2);
2791 $$->set_location_range(@1, @2);
2792 }
2793 ;
2794
2795 member_list:
2796 member_declaration
2797 {
2798 $$ = $1;
2799 $1->link.self_link();
2800 }
2801 | member_declaration member_list
2802 {
2803 $$ = $1;
2804 $2->link.insert_before(& $$->link);
2805 }
2806 ;
2807
2808 member_declaration:
2809 fully_specified_type struct_declarator_list ';'
2810 {
2811 void *ctx = state->linalloc;
2812 ast_fully_specified_type *type = $1;
2813 type->set_location(@1);
2814
2815 if (type->qualifier.flags.q.attribute) {
2816 _mesa_glsl_error(& @1, state,
2817 "keyword 'attribute' cannot be used with "
2818 "interface block member");
2819 } else if (type->qualifier.flags.q.varying) {
2820 _mesa_glsl_error(& @1, state,
2821 "keyword 'varying' cannot be used with "
2822 "interface block member");
2823 }
2824
2825 $$ = new(ctx) ast_declarator_list(type);
2826 $$->set_location(@2);
2827
2828 $$->declarations.push_degenerate_list_at_head(& $2->link);
2829 }
2830 ;
2831
2832 layout_uniform_defaults:
2833 layout_qualifier layout_uniform_defaults
2834 {
2835 $$ = $1;
2836 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2837 YYERROR;
2838 }
2839 }
2840 | layout_qualifier UNIFORM ';'
2841 ;
2842
2843 layout_buffer_defaults:
2844 layout_qualifier layout_buffer_defaults
2845 {
2846 $$ = $1;
2847 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2848 YYERROR;
2849 }
2850 }
2851 | layout_qualifier BUFFER ';'
2852 ;
2853
2854 layout_in_defaults:
2855 layout_qualifier layout_in_defaults
2856 {
2857 $$ = $1;
2858 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2859 YYERROR;
2860 }
2861 if (!$$.validate_in_qualifier(& @1, state)) {
2862 YYERROR;
2863 }
2864 }
2865 | layout_qualifier IN_TOK ';'
2866 {
2867 if (!$1.validate_in_qualifier(& @1, state)) {
2868 YYERROR;
2869 }
2870 }
2871 ;
2872
2873 layout_out_defaults:
2874 layout_qualifier layout_out_defaults
2875 {
2876 $$ = $1;
2877 if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
2878 YYERROR;
2879 }
2880 if (!$$.validate_out_qualifier(& @1, state)) {
2881 YYERROR;
2882 }
2883 }
2884 | layout_qualifier OUT_TOK ';'
2885 {
2886 if (!$1.validate_out_qualifier(& @1, state)) {
2887 YYERROR;
2888 }
2889 }
2890 ;
2891
2892 layout_defaults:
2893 layout_uniform_defaults
2894 {
2895 $$ = NULL;
2896 if (!state->default_uniform_qualifier->
2897 merge_qualifier(& @1, state, $1, false)) {
2898 YYERROR;
2899 }
2900 if (!state->default_uniform_qualifier->
2901 push_to_global(& @1, state)) {
2902 YYERROR;
2903 }
2904 }
2905 | layout_buffer_defaults
2906 {
2907 $$ = NULL;
2908 if (!state->default_shader_storage_qualifier->
2909 merge_qualifier(& @1, state, $1, false)) {
2910 YYERROR;
2911 }
2912 if (!state->default_shader_storage_qualifier->
2913 push_to_global(& @1, state)) {
2914 YYERROR;
2915 }
2916
2917 /* From the GLSL 4.50 spec, section 4.4.5:
2918 *
2919 * "It is a compile-time error to specify the binding identifier for
2920 * the global scope or for block member declarations."
2921 */
2922 if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
2923 _mesa_glsl_error(& @1, state,
2924 "binding qualifier cannot be set for default layout");
2925 }
2926 }
2927 | layout_in_defaults
2928 {
2929 $$ = NULL;
2930 if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
2931 YYERROR;
2932 }
2933 if (!state->in_qualifier->push_to_global(& @1, state)) {
2934 YYERROR;
2935 }
2936 }
2937 | layout_out_defaults
2938 {
2939 $$ = NULL;
2940 if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
2941 YYERROR;
2942 }
2943 if (!state->out_qualifier->push_to_global(& @1, state)) {
2944 YYERROR;
2945 }
2946 }
2947 ;