X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=inline;f=src%2Fglsl%2Fglsl_parser.yy;h=7fb8c38abe3d2bc859e4f278b4fca653c81345d0;hb=4f8230e247a222314ab124e348482628adb5af32;hp=72bf560f07e1b0029d0d0d5ca07827cbaab45836;hpb=48e3bd33dc28aedcd9fccf4ba3bdc5e8a894b27b;p=mesa.git diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy index 72bf560f07e..7fb8c38abe3 100644 --- a/src/glsl/glsl_parser.yy +++ b/src/glsl/glsl_parser.yy @@ -24,6 +24,9 @@ #include #include #include +#ifndef _MSC_VER +#include +#endif #include #include "ast.h" @@ -31,14 +34,44 @@ #include "glsl_types.h" #include "main/context.h" -#define YYLEX_PARAM state->scanner - #undef yyerror static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) { _mesa_glsl_error(loc, st, "%s", msg); } + +static int +_mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state) +{ + return _mesa_glsl_lexer_lex(val, loc, state->scanner); +} + +static bool match_layout_qualifier(const char *s1, const char *s2, + _mesa_glsl_parse_state *state) +{ + /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers): + * + * "The tokens in any layout-qualifier-id-list ... are not case + * sensitive, unless explicitly noted otherwise." + * + * The text "unless explicitly noted otherwise" appears to be + * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes + * otherwise. + * + * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout + * Qualifiers): + * + * "As for other identifiers, they are case sensitive." + * + * So we need to do a case-sensitive or a case-insensitive match, + * depending on whether we are compiling for GLSL ES. + */ + if (state->es_shader) + return strcmp(s1, s2); + else + return strcasecmp(s1, s2); +} %} %expect 0 @@ -55,7 +88,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) @$.source = 0; } -%lex-param {void *scanner} +%lex-param {struct _mesa_glsl_parse_state *state} %parse-param {struct _mesa_glsl_parse_state *state} %union { @@ -67,6 +100,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) ast_node *node; ast_type_specifier *type_specifier; + ast_array_specifier *array_specifier; ast_fully_specified_type *fully_specified_type; ast_function *function; ast_parameter_declarator *parameter_declarator; @@ -97,7 +131,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 -%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING +%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE %token NOPERSPECTIVE FLAT SMOOTH %token MAT2X2 MAT2X3 MAT2X4 %token MAT3X2 MAT3X3 MAT3X4 @@ -114,6 +148,15 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY %token SAMPLEREXTERNALOES +%token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER +%token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY +%token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER +%token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY +%token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER +%token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY +%token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW +%token COHERENT VOLATILE RESTRICT READONLY WRITEONLY +%token ATOMIC_UINT %token STRUCT VOID_TOK WHILE %token IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER %type any_identifier @@ -126,7 +169,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN %token SUB_ASSIGN -%token INVARIANT +%token INVARIANT PRECISE %token LOWP MEDIUMP HIGHP SUPERP PRECISION %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT @@ -138,23 +181,17 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) /* Reserved words that are not actually used in the grammar. */ %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO -%token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL -%token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT +%token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL +%token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4 %token SAMPLER3DRECT %token SIZEOF CAST NAMESPACE USING -%token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE +%token RESOURCE PATCH %token SUBROUTINE %token ERROR_TOK -%token COMMON PARTITION ACTIVE FILTER -%token IMAGE1D IMAGE2D IMAGE3D IMAGECUBE IMAGE1DARRAY IMAGE2DARRAY -%token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY -%token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY -%token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER -%token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW -%token ROW_MAJOR +%token COMMON PARTITION ACTIVE FILTER ROW_MAJOR %type variable_identifier %type statement @@ -162,6 +199,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %type simple_statement %type precision_qualifier %type type_qualifier +%type auxiliary_storage_qualifier %type storage_qualifier %type interpolation_qualifier %type layout_qualifier @@ -169,8 +207,8 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %type interface_block_layout_qualifier %type interface_qualifier %type type_specifier -%type type_specifier_no_prec %type type_specifier_nonarray +%type array_specifier %type basic_type_specifier_nonarray %type fully_specified_type %type function_prototype @@ -180,7 +218,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %type parameter_declarator %type parameter_declaration %type parameter_qualifier -%type parameter_type_qualifier +%type parameter_direction_qualifier %type parameter_type_specifier %type function_definition %type compound_statement_no_new_scope @@ -250,6 +288,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg) %type for_init_statement %type for_rest_statement %type integer_constant +%type layout_defaults %right THEN ELSE %% @@ -292,10 +331,21 @@ pragma_statement: | PRAGMA_OPTIMIZE_OFF EOL | PRAGMA_INVARIANT_ALL EOL { - if (!state->is_version(120, 100)) { + /* Pragma invariant(all) cannot be used in a fragment shader. + * + * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec: + * + * "It is an error to use this pragma in a fragment shader." + */ + if (state->is_version(120, 300) && + state->stage == MESA_SHADER_FRAGMENT) { + _mesa_glsl_error(& @1, state, + "pragma `invariant(all)' cannot be used " + "in a fragment shader."); + } else if (!state->is_version(120, 100)) { _mesa_glsl_warning(& @1, state, "pragma `invariant(all)' not supported in %s " - "(GLSL ES 1.00 or GLSL 1.20 required).", + "(GLSL ES 1.00 or GLSL 1.20 required)", state->get_version_string()); } else { state->all_invariant = true; @@ -340,6 +390,14 @@ external_declaration_list: if ($2 != NULL) state->translation_unit.push_tail(& $2->link); } + | external_declaration_list extension_statement { + if (!state->allow_extension_directive_midshader) { + _mesa_glsl_error(& @2, state, + "#extension directive is not allowed " + "in the middle of a shader"); + YYERROR; + } + } ; variable_identifier: @@ -352,35 +410,35 @@ primary_expression: { void *ctx = state; $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); $$->primary_expression.identifier = $1; } | INTCONSTANT { void *ctx = state; $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); $$->primary_expression.int_constant = $1; } | UINTCONSTANT { void *ctx = state; $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); $$->primary_expression.uint_constant = $1; } | FLOATCONSTANT { void *ctx = state; $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); $$->primary_expression.float_constant = $1; } | BOOLCONSTANT { void *ctx = state; $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); $$->primary_expression.bool_constant = $1; } | '(' expression ')' @@ -395,7 +453,7 @@ postfix_expression: { void *ctx = state; $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @4); } | function_call { @@ -405,20 +463,20 @@ postfix_expression: { void *ctx = state; $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); $$->primary_expression.identifier = $3; } | postfix_expression INC_OP { void *ctx = state; $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } | postfix_expression DEC_OP { void *ctx = state; $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } ; @@ -436,7 +494,7 @@ function_call_or_method: { void *ctx = state; $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -454,13 +512,13 @@ function_call_header_with_parameters: function_call_header assignment_expression { $$ = $1; - $$->set_location(yylloc); + $$->set_location(@1); $$->expressions.push_tail(& $2->link); } | function_call_header_with_parameters ',' assignment_expression { $$ = $1; - $$->set_location(yylloc); + $$->set_location(@1); $$->expressions.push_tail(& $3->link); } ; @@ -477,21 +535,23 @@ function_identifier: { void *ctx = state; $$ = new(ctx) ast_function_expression($1); - $$->set_location(yylloc); + $$->set_location(@1); } | variable_identifier { void *ctx = state; ast_expression *callee = new(ctx) ast_expression($1); + callee->set_location(@1); $$ = new(ctx) ast_function_expression(callee); - $$->set_location(yylloc); + $$->set_location(@1); } | FIELD_SELECTION { void *ctx = state; ast_expression *callee = new(ctx) ast_expression($1); + callee->set_location(@1); $$ = new(ctx) ast_function_expression(callee); - $$->set_location(yylloc); + $$->set_location(@1); } ; @@ -509,13 +569,13 @@ method_call_header_with_parameters: method_call_header assignment_expression { $$ = $1; - $$->set_location(yylloc); + $$->set_location(@1); $$->expressions.push_tail(& $2->link); } | method_call_header_with_parameters ',' assignment_expression { $$ = $1; - $$->set_location(yylloc); + $$->set_location(@1); $$->expressions.push_tail(& $3->link); } ; @@ -528,8 +588,9 @@ method_call_header: { void *ctx = state; ast_expression *callee = new(ctx) ast_expression($1); + callee->set_location(@1); $$ = new(ctx) ast_function_expression(callee); - $$->set_location(yylloc); + $$->set_location(@1); } ; @@ -540,19 +601,19 @@ unary_expression: { void *ctx = state; $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); } | DEC_OP unary_expression { void *ctx = state; $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL); - $$->set_location(yylloc); + $$->set_location(@1); } | unary_operator unary_expression { void *ctx = state; $$ = new(ctx) ast_expression($1, $2, NULL, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } ; @@ -570,19 +631,19 @@ multiplicative_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | multiplicative_expression '/' unary_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_div, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | multiplicative_expression '%' unary_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -592,13 +653,13 @@ additive_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_add, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | additive_expression '-' multiplicative_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -608,13 +669,13 @@ shift_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | shift_expression RIGHT_OP additive_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -624,25 +685,25 @@ relational_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_less, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | relational_expression '>' shift_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | relational_expression LE_OP shift_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | relational_expression GE_OP shift_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -652,13 +713,13 @@ equality_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } | equality_expression NE_OP relational_expression { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -668,7 +729,7 @@ and_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -678,7 +739,7 @@ exclusive_or_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -688,7 +749,7 @@ inclusive_or_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -698,7 +759,7 @@ logical_and_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -708,7 +769,7 @@ logical_xor_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -718,7 +779,7 @@ logical_or_expression: { void *ctx = state; $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -728,7 +789,7 @@ conditional_expression: { void *ctx = state; $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5); - $$->set_location(yylloc); + $$->set_location_range(@1, @5); } ; @@ -738,7 +799,7 @@ assignment_expression: { void *ctx = state; $$ = new(ctx) ast_expression($2, $1, $3, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -766,7 +827,7 @@ expression: void *ctx = state; if ($1->oper != ast_sequence) { $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); $$->expressions.push_tail(& $1->link); } else { $$ = $1; @@ -790,10 +851,9 @@ declaration: { $$ = $1; } - | PRECISION precision_qualifier type_specifier_no_prec ';' + | PRECISION precision_qualifier type_specifier ';' { - $3->precision = $2; - $3->is_precision_statement = true; + $3->default_precision = $2; $$ = $3; } | interface_block @@ -829,7 +889,7 @@ function_header: { void *ctx = state; $$ = new(ctx) ast_function(); - $$->set_location(yylloc); + $$->set_location(@2); $$->return_type = $1; $$->identifier = $2; @@ -843,56 +903,38 @@ parameter_declarator: { void *ctx = state; $$ = new(ctx) ast_parameter_declarator(); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); $$->type = new(ctx) ast_fully_specified_type(); - $$->type->set_location(yylloc); + $$->type->set_location(@1); $$->type->specifier = $1; $$->identifier = $2; } - | type_specifier any_identifier '[' constant_expression ']' + | type_specifier any_identifier array_specifier { void *ctx = state; $$ = new(ctx) ast_parameter_declarator(); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); $$->type = new(ctx) ast_fully_specified_type(); - $$->type->set_location(yylloc); + $$->type->set_location(@1); $$->type->specifier = $1; $$->identifier = $2; - $$->is_array = true; - $$->array_size = $4; + $$->array_specifier = $3; } ; parameter_declaration: - parameter_type_qualifier parameter_qualifier parameter_declarator - { - $1.flags.i |= $2.flags.i; - - $$ = $3; - $$->type->qualifier = $1; - } - | parameter_qualifier parameter_declarator + parameter_qualifier parameter_declarator { $$ = $2; $$->type->qualifier = $1; } - | parameter_type_qualifier parameter_qualifier parameter_type_specifier - { - void *ctx = state; - $1.flags.i |= $2.flags.i; - - $$ = new(ctx) ast_parameter_declarator(); - $$->set_location(yylloc); - $$->type = new(ctx) ast_fully_specified_type(); - $$->type->qualifier = $1; - $$->type->specifier = $3; - } | parameter_qualifier parameter_type_specifier { void *ctx = state; $$ = new(ctx) ast_parameter_declarator(); - $$->set_location(yylloc); + $$->set_location(@2); $$->type = new(ctx) ast_fully_specified_type(); + $$->type->set_location_range(@1, @2); $$->type->qualifier = $1; $$->type->specifier = $2; } @@ -903,7 +945,48 @@ parameter_qualifier: { memset(& $$, 0, sizeof($$)); } - | IN_TOK + | CONST_TOK parameter_qualifier + { + if ($2.flags.q.constant) + _mesa_glsl_error(&@1, state, "duplicate const qualifier"); + + $$ = $2; + $$.flags.q.constant = 1; + } + | PRECISE parameter_qualifier + { + if ($2.flags.q.precise) + _mesa_glsl_error(&@1, state, "duplicate precise qualifier"); + + $$ = $2; + $$.flags.q.precise = 1; + } + | parameter_direction_qualifier parameter_qualifier + { + if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out)) + _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier"); + + if (!state->ARB_shading_language_420pack_enable && $2.flags.q.constant) + _mesa_glsl_error(&@1, state, "in/out/inout must come after const " + "or precise"); + + $$ = $1; + $$.merge_qualifier(&@1, state, $2); + } + | precision_qualifier parameter_qualifier + { + if ($2.precision != ast_precision_none) + _mesa_glsl_error(&@1, state, "duplicate precision qualifier"); + + if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0) + _mesa_glsl_error(&@1, state, "precision qualifiers must come last"); + + $$ = $2; + $$.precision = $1; + } + +parameter_direction_qualifier: + IN_TOK { memset(& $$, 0, sizeof($$)); $$.flags.q.in = 1; @@ -930,76 +1013,42 @@ init_declarator_list: | init_declarator_list ',' any_identifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL); - decl->set_location(yylloc); - - $$ = $1; - $$->declarations.push_tail(&decl->link); - state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - } - | init_declarator_list ',' any_identifier '[' ']' - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL); - decl->set_location(yylloc); - - $$ = $1; - $$->declarations.push_tail(&decl->link); - state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - } - | init_declarator_list ',' any_identifier '[' constant_expression ']' - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL); - decl->set_location(yylloc); + ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL); + decl->set_location(@3); $$ = $1; $$->declarations.push_tail(&decl->link); state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); } - | init_declarator_list ',' any_identifier '[' ']' '=' initializer + | init_declarator_list ',' any_identifier array_specifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7); - decl->set_location(yylloc); + ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL); + decl->set_location_range(@3, @4); $$ = $1; $$->declarations.push_tail(&decl->link); state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - if ($7->oper == ast_aggregate) { - ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7; - ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL); - _mesa_ast_set_aggregate_type(type, ai, state); - } } - | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer + | init_declarator_list ',' any_identifier array_specifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8); - decl->set_location(yylloc); + ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6); + decl->set_location_range(@3, @4); $$ = $1; $$->declarations.push_tail(&decl->link); state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - if ($8->oper == ast_aggregate) { - ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8; - ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5); - _mesa_ast_set_aggregate_type(type, ai, state); - } } | init_declarator_list ',' any_identifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5); - decl->set_location(yylloc); + ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5); + decl->set_location(@3); $$ = $1; $$->declarations.push_tail(&decl->link); state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - if ($5->oper == ast_aggregate) { - ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5; - _mesa_ast_set_aggregate_type($1->type->specifier, ai, state); - } } ; @@ -1010,83 +1059,69 @@ single_declaration: void *ctx = state; /* Empty declaration list is valid. */ $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); + $$->set_location(@1); } | fully_specified_type any_identifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL); + ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL); + decl->set_location(@2); $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); $$->declarations.push_tail(&decl->link); } - | fully_specified_type any_identifier '[' ']' + | fully_specified_type any_identifier array_specifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL); + ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL); + decl->set_location_range(@2, @3); $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); $$->declarations.push_tail(&decl->link); } - | fully_specified_type any_identifier '[' constant_expression ']' + | fully_specified_type any_identifier array_specifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL); + ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5); + decl->set_location_range(@2, @3); $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); $$->declarations.push_tail(&decl->link); } - | fully_specified_type any_identifier '[' ']' '=' initializer + | fully_specified_type any_identifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6); + ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4); + decl->set_location(@2); $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); $$->declarations.push_tail(&decl->link); - if ($6->oper == ast_aggregate) { - ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6; - ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL); - _mesa_ast_set_aggregate_type(type, ai, state); - } } - | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer + | INVARIANT variable_identifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7); + ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL); + decl->set_location(@2); - $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); - $$->declarations.push_tail(&decl->link); - if ($7->oper == ast_aggregate) { - ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7; - ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4); - _mesa_ast_set_aggregate_type(type, ai, state); - } - } - | fully_specified_type any_identifier '=' initializer - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4); + $$ = new(ctx) ast_declarator_list(NULL); + $$->set_location_range(@1, @2); + $$->invariant = true; - $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); $$->declarations.push_tail(&decl->link); - if ($4->oper == ast_aggregate) { - _mesa_ast_set_aggregate_type($1->specifier, $4, state); - } } - | INVARIANT variable_identifier // Vertex only. + | PRECISE variable_identifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL); + ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL); + decl->set_location(@2); $$ = new(ctx) ast_declarator_list(NULL); - $$->set_location(yylloc); - $$->invariant = true; + $$->set_location_range(@1, @2); + $$->precise = true; $$->declarations.push_tail(&decl->link); } @@ -1097,14 +1132,14 @@ fully_specified_type: { void *ctx = state; $$ = new(ctx) ast_fully_specified_type(); - $$->set_location(yylloc); + $$->set_location(@1); $$->specifier = $1; } | type_qualifier type_specifier { void *ctx = state; $$ = new(ctx) ast_fully_specified_type(); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); $$->qualifier = $1; $$->specifier = $2; } @@ -1139,17 +1174,19 @@ layout_qualifier_id: memset(& $$, 0, sizeof($$)); /* Layout qualifiers for ARB_fragment_coord_conventions. */ - if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) { - if (strcmp($1, "origin_upper_left") == 0) { + if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable || + state->is_version(150, 0))) { + if (match_layout_qualifier($1, "origin_upper_left", state) == 0) { $$.flags.q.origin_upper_left = 1; - } else if (strcmp($1, "pixel_center_integer") == 0) { + } else if (match_layout_qualifier($1, "pixel_center_integer", + state) == 0) { $$.flags.q.pixel_center_integer = 1; } if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) { _mesa_glsl_warning(& @1, state, "GL_ARB_fragment_coord_conventions layout " - "identifier `%s' used\n", $1); + "identifier `%s' used", $1); } } @@ -1157,56 +1194,163 @@ layout_qualifier_id: if (!$$.flags.i && (state->AMD_conservative_depth_enable || state->ARB_conservative_depth_enable)) { - if (strcmp($1, "depth_any") == 0) { + if (match_layout_qualifier($1, "depth_any", state) == 0) { $$.flags.q.depth_any = 1; - } else if (strcmp($1, "depth_greater") == 0) { + } else if (match_layout_qualifier($1, "depth_greater", state) == 0) { $$.flags.q.depth_greater = 1; - } else if (strcmp($1, "depth_less") == 0) { + } else if (match_layout_qualifier($1, "depth_less", state) == 0) { $$.flags.q.depth_less = 1; - } else if (strcmp($1, "depth_unchanged") == 0) { + } else if (match_layout_qualifier($1, "depth_unchanged", + state) == 0) { $$.flags.q.depth_unchanged = 1; } if ($$.flags.i && state->AMD_conservative_depth_warn) { _mesa_glsl_warning(& @1, state, "GL_AMD_conservative_depth " - "layout qualifier `%s' is used\n", $1); + "layout qualifier `%s' is used", $1); } if ($$.flags.i && state->ARB_conservative_depth_warn) { _mesa_glsl_warning(& @1, state, "GL_ARB_conservative_depth " - "layout qualifier `%s' is used\n", $1); + "layout qualifier `%s' is used", $1); } } /* See also interface_block_layout_qualifier. */ - if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) { - if (strcmp($1, "std140") == 0) { + if (!$$.flags.i && state->has_uniform_buffer_objects()) { + if (match_layout_qualifier($1, "std140", state) == 0) { $$.flags.q.std140 = 1; - } else if (strcmp($1, "shared") == 0) { + } else if (match_layout_qualifier($1, "shared", state) == 0) { $$.flags.q.shared = 1; - } else if (strcmp($1, "column_major") == 0) { + } else if (match_layout_qualifier($1, "column_major", state) == 0) { $$.flags.q.column_major = 1; /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed * below in the interface_block_layout_qualifier rule. * * It is not a reserved word in GLSL ES 3.00, so it's handled here as * an identifier. + * + * Also, this takes care of alternate capitalizations of + * "row_major" (which is necessary because layout qualifiers + * are case-insensitive in desktop GLSL). */ - } else if (strcmp($1, "row_major") == 0) { + } else if (match_layout_qualifier($1, "row_major", state) == 0) { $$.flags.q.row_major = 1; + /* "packed" is a reserved word in GLSL, and its token is + * parsed below in the interface_block_layout_qualifier rule. + * However, we must take care of alternate capitalizations of + * "packed", because layout qualifiers are case-insensitive + * in desktop GLSL. + */ + } else if (match_layout_qualifier($1, "packed", state) == 0) { + $$.flags.q.packed = 1; } if ($$.flags.i && state->ARB_uniform_buffer_object_warn) { _mesa_glsl_warning(& @1, state, "#version 140 / GL_ARB_uniform_buffer_object " - "layout qualifier `%s' is used\n", $1); + "layout qualifier `%s' is used", $1); + } + } + + /* Layout qualifiers for GLSL 1.50 geometry shaders. */ + if (!$$.flags.i) { + static const struct { + const char *s; + GLenum e; + } map[] = { + { "points", GL_POINTS }, + { "lines", GL_LINES }, + { "lines_adjacency", GL_LINES_ADJACENCY }, + { "line_strip", GL_LINE_STRIP }, + { "triangles", GL_TRIANGLES }, + { "triangles_adjacency", GL_TRIANGLES_ADJACENCY }, + { "triangle_strip", GL_TRIANGLE_STRIP }, + }; + for (unsigned i = 0; i < Elements(map); i++) { + if (match_layout_qualifier($1, map[i].s, state) == 0) { + $$.flags.q.prim_type = 1; + $$.prim_type = map[i].e; + break; + } + } + + if ($$.flags.i && !state->is_version(150, 0)) { + _mesa_glsl_error(& @1, state, "#version 150 layout " + "qualifier `%s' used", $1); + } + } + + /* Layout qualifiers for ARB_shader_image_load_store. */ + if (state->ARB_shader_image_load_store_enable || + state->is_version(420, 0)) { + if (!$$.flags.i) { + static const struct { + const char *name; + GLenum format; + glsl_base_type base_type; + } map[] = { + { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT }, + { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT }, + { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT }, + { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT }, + { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT }, + { "r32f", GL_R32F, GLSL_TYPE_FLOAT }, + { "r16f", GL_R16F, GLSL_TYPE_FLOAT }, + { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT }, + { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT }, + { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT }, + { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT }, + { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT }, + { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT }, + { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT }, + { "r32ui", GL_R32UI, GLSL_TYPE_UINT }, + { "r16ui", GL_R16UI, GLSL_TYPE_UINT }, + { "r8ui", GL_R8UI, GLSL_TYPE_UINT }, + { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT }, + { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT }, + { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT }, + { "rg32i", GL_RG32I, GLSL_TYPE_INT }, + { "rg16i", GL_RG16I, GLSL_TYPE_INT }, + { "rg8i", GL_RG8I, GLSL_TYPE_INT }, + { "r32i", GL_R32I, GLSL_TYPE_INT }, + { "r16i", GL_R16I, GLSL_TYPE_INT }, + { "r8i", GL_R8I, GLSL_TYPE_INT }, + { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT }, + { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT }, + { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT }, + { "rg16", GL_RG16, GLSL_TYPE_FLOAT }, + { "rg8", GL_RG8, GLSL_TYPE_FLOAT }, + { "r16", GL_R16, GLSL_TYPE_FLOAT }, + { "r8", GL_R8, GLSL_TYPE_FLOAT }, + { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT }, + { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT }, + { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT }, + { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT }, + { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT }, + { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT } + }; + + for (unsigned i = 0; i < Elements(map); i++) { + if (match_layout_qualifier($1, map[i].name, state) == 0) { + $$.flags.q.explicit_image_format = 1; + $$.image_format = map[i].format; + $$.image_base_type = map[i].base_type; + break; + } + } + } + + if (!$$.flags.i && + match_layout_qualifier($1, "early_fragment_tests", state) == 0) { + $$.flags.q.early_fragment_tests = 1; } } if (!$$.flags.i) { _mesa_glsl_error(& @1, state, "unrecognized layout identifier " - "`%s'\n", $1); + "`%s'", $1); YYERROR; } } @@ -1214,28 +1358,128 @@ layout_qualifier_id: { memset(& $$, 0, sizeof($$)); - if (state->ARB_explicit_attrib_location_enable) { - if (strcmp("location", $1) == 0) { - $$.flags.q.explicit_location = 1; + if (match_layout_qualifier("location", $1, state) == 0) { + $$.flags.q.explicit_location = 1; - if ($3 >= 0) { - $$.location = $3; - } else { + if ($$.flags.q.attribute == 1 && + state->ARB_explicit_attrib_location_warn) { + _mesa_glsl_warning(& @1, state, + "GL_ARB_explicit_attrib_location layout " + "identifier `%s' used", $1); + } + + if ($3 >= 0) { + $$.location = $3; + } else { + _mesa_glsl_error(& @3, state, "invalid location %d specified", $3); + YYERROR; + } + } + + if (match_layout_qualifier("index", $1, state) == 0) { + $$.flags.q.explicit_index = 1; + + if ($3 >= 0) { + $$.index = $3; + } else { + _mesa_glsl_error(& @3, state, "invalid index %d specified", $3); + YYERROR; + } + } + + if ((state->ARB_shading_language_420pack_enable || + state->ARB_shader_atomic_counters_enable) && + match_layout_qualifier("binding", $1, state) == 0) { + $$.flags.q.explicit_binding = 1; + $$.binding = $3; + } + + if (state->ARB_shader_atomic_counters_enable && + match_layout_qualifier("offset", $1, state) == 0) { + $$.flags.q.explicit_offset = 1; + $$.offset = $3; + } + + if (match_layout_qualifier("max_vertices", $1, state) == 0) { + $$.flags.q.max_vertices = 1; + + if ($3 < 0) { + _mesa_glsl_error(& @3, state, + "invalid max_vertices %d specified", $3); + YYERROR; + } else { + $$.max_vertices = $3; + if (!state->is_version(150, 0)) { _mesa_glsl_error(& @3, state, - "invalid location %d specified\n", $3); - YYERROR; + "#version 150 max_vertices qualifier " + "specified", $3); } } + } - if (strcmp("index", $1) == 0) { - $$.flags.q.explicit_index = 1; + if (state->stage == MESA_SHADER_GEOMETRY) { + if (match_layout_qualifier("stream", $1, state) == 0 && + state->check_explicit_attrib_stream_allowed(& @3)) { + $$.flags.q.stream = 1; - if ($3 >= 0) { - $$.index = $3; + if ($3 < 0) { + _mesa_glsl_error(& @3, state, + "invalid stream %d specified", $3); + YYERROR; } else { + $$.flags.q.explicit_stream = 1; + $$.stream = $3; + } + } + } + + static const char * const local_size_qualifiers[3] = { + "local_size_x", + "local_size_y", + "local_size_z", + }; + for (int i = 0; i < 3; i++) { + if (match_layout_qualifier(local_size_qualifiers[i], $1, + state) == 0) { + if ($3 <= 0) { _mesa_glsl_error(& @3, state, - "invalid index %d specified\n", $3); + "invalid %s of %d specified", + local_size_qualifiers[i], $3); YYERROR; + } else if (!state->is_version(430, 0) && + !state->ARB_compute_shader_enable) { + _mesa_glsl_error(& @3, state, + "%s qualifier requires GLSL 4.30 or " + "ARB_compute_shader", + local_size_qualifiers[i]); + YYERROR; + } else { + $$.flags.q.local_size |= (1 << i); + $$.local_size[i] = $3; + } + break; + } + } + + if (match_layout_qualifier("invocations", $1, state) == 0) { + $$.flags.q.invocations = 1; + + if ($3 <= 0) { + _mesa_glsl_error(& @3, state, + "invalid invocations %d specified", $3); + YYERROR; + } else if ($3 > MAX_GEOMETRY_SHADER_INVOCATIONS) { + _mesa_glsl_error(& @3, state, + "invocations (%d) exceeds " + "GL_MAX_GEOMETRY_SHADER_INVOCATIONS", $3); + YYERROR; + } else { + $$.invocations = $3; + if (!state->is_version(400, 0) && + !state->ARB_gpu_shader5_enable) { + _mesa_glsl_error(& @3, state, + "GL_ARB_gpu_shader5 invocations " + "qualifier specified", $3); } } } @@ -1245,26 +1489,22 @@ layout_qualifier_id: */ if (!$$.flags.i) { _mesa_glsl_error(& @1, state, "unrecognized layout identifier " - "`%s'\n", $1); + "`%s'", $1); YYERROR; - } else if (state->ARB_explicit_attrib_location_warn) { - _mesa_glsl_warning(& @1, state, - "GL_ARB_explicit_attrib_location layout " - "identifier `%s' used\n", $1); } } | interface_block_layout_qualifier { $$ = $1; /* Layout qualifiers for ARB_uniform_buffer_object. */ - if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) { + if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) { _mesa_glsl_error(& @1, state, "#version 140 / GL_ARB_uniform_buffer_object " - "layout qualifier `%s' is used\n", $1); + "layout qualifier `%s' is used", $1); } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) { _mesa_glsl_warning(& @1, state, "#version 140 / GL_ARB_uniform_buffer_object " - "layout qualifier `%s' is used\n", $1); + "layout qualifier `%s' is used", $1); } } ; @@ -1273,6 +1513,10 @@ layout_qualifier_id: * (due to them being reserved keywords) instead of identifiers like * most qualifiers. See the any_identifier path of * layout_qualifier_id for the others. + * + * Note that since layout qualifiers are case-insensitive in desktop + * GLSL, all of these qualifiers need to be handled as identifiers as + * well (by the any_identifier path of layout_qualifier_id). */ interface_block_layout_qualifier: ROW_MAJOR @@ -1305,14 +1549,6 @@ interpolation_qualifier: } ; -parameter_type_qualifier: - CONST_TOK - { - memset(& $$, 0, sizeof($$)); - $$.flags.q.constant = 1; - } - ; - type_qualifier: /* Single qualifiers */ INVARIANT @@ -1320,34 +1556,63 @@ type_qualifier: memset(& $$, 0, sizeof($$)); $$.flags.q.invariant = 1; } + | PRECISE + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.precise = 1; + } + | auxiliary_storage_qualifier | storage_qualifier | interpolation_qualifier | layout_qualifier + | precision_qualifier + { + memset(&$$, 0, sizeof($$)); + $$.precision = $1; + } /* Multiple qualifiers: * In GLSL 4.20, these can be specified in any order. In earlier versions, * they appear in this order (see GLSL 1.50 section 4.7 & comments below): * - * invariant interpolation storage precision ...or... + * invariant interpolation auxiliary storage precision ...or... * layout storage precision * * Each qualifier's rule ensures that the accumulated qualifiers on the right * side don't contain any that must appear on the left hand side. * For example, when processing a storage qualifier, we check that there are - * no interpolation, layout, or invariant qualifiers to the right. + * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right. */ + | PRECISE type_qualifier + { + if ($2.flags.q.precise) + _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier"); + + $$ = $2; + $$.flags.q.precise = 1; + } | INVARIANT type_qualifier { if ($2.flags.q.invariant) - _mesa_glsl_error(&@1, state, "Duplicate \"invariant\" qualifier.\n"); + _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier"); - if ($2.has_layout()) { + if (!state->ARB_shading_language_420pack_enable && $2.flags.q.precise) _mesa_glsl_error(&@1, state, - "\"invariant\" cannot be used with layout(...).\n"); - } + "\"invariant\" must come after \"precise\""); $$ = $2; $$.flags.q.invariant = 1; + + /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier": + * + * "Only variables output from a shader can be candidates for invariance. + * This includes user-defined output variables and the built-in output + * variables. As only outputs can be declared as invariant, an invariant + * output from one shader stage will still match an input of a subsequent + * stage without the input being declared as invariant." + */ + if (state->es_shader && state->language_version >= 300 && $$.flags.q.in) + _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs"); } | interpolation_qualifier type_qualifier { @@ -1362,43 +1627,49 @@ type_qualifier: * only one after all, and the 1.40 text is a clarification, not a change. */ if ($2.has_interpolation()) - _mesa_glsl_error(&@1, state, "Duplicate interpolation qualifier.\n"); - - if ($2.has_layout()) { - _mesa_glsl_error(&@1, state, "Interpolation qualifiers cannot be used " - "with layout(...).\n"); - } + _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier"); - if ($2.flags.q.invariant) { - _mesa_glsl_error(&@1, state, "Interpolation qualifiers must come " - "after \"invariant\".\n"); + if (!state->ARB_shading_language_420pack_enable && + ($2.flags.q.precise || $2.flags.q.invariant)) { + _mesa_glsl_error(&@1, state, "interpolation qualifiers must come " + "after \"precise\" or \"invariant\""); } $$ = $1; - $$.flags.i |= $2.flags.i; + $$.merge_qualifier(&@1, state, $2); } | layout_qualifier type_qualifier { - /* The GLSL 1.50 grammar indicates that a layout(...) declaration can be - * used standalone or immediately before a storage qualifier. It cannot - * be used with interpolation qualifiers or invariant. There does not - * appear to be any text indicating that it must come before the storage - * qualifier, but always seems to in examples. + /* In the absence of ARB_shading_language_420pack, layout qualifiers may + * appear no later than auxiliary storage qualifiers. There is no + * particularly clear spec language mandating this, but in all examples + * the layout qualifier precedes the storage qualifier. + * + * We allow combinations of layout with interpolation, invariant or + * precise qualifiers since these are useful in ARB_separate_shader_objects. + * There is no clear spec guidance on this either. */ - if ($2.has_layout()) - _mesa_glsl_error(&@1, state, "Duplicate layout(...) qualifiers.\n"); - - if ($2.flags.q.invariant) - _mesa_glsl_error(&@1, state, "layout(...) cannot be used with " - "the \"invariant\" qualifier\n"); + if (!state->ARB_shading_language_420pack_enable && $2.has_layout()) + _mesa_glsl_error(&@1, state, "duplicate layout(...) qualifiers"); - if ($2.has_interpolation()) { - _mesa_glsl_error(&@1, state, "layout(...) cannot be used with " - "interpolation qualifiers.\n"); + $$ = $1; + $$.merge_qualifier(&@1, state, $2); + } + | auxiliary_storage_qualifier type_qualifier + { + if ($2.has_auxiliary_storage()) { + _mesa_glsl_error(&@1, state, + "duplicate auxiliary storage qualifier (centroid or sample)"); } + if (!state->ARB_shading_language_420pack_enable && + ($2.flags.q.precise || $2.flags.q.invariant || + $2.has_interpolation() || $2.has_layout())) { + _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come " + "just before storage qualifiers"); + } $$ = $1; - $$.flags.i |= $2.flags.i; + $$.merge_qualifier(&@1, state, $2); } | storage_qualifier type_qualifier { @@ -1407,18 +1678,45 @@ type_qualifier: * 1.30 clarifies this to "may have one storage qualifier". */ if ($2.has_storage()) - _mesa_glsl_error(&@1, state, "Duplicate storage qualifier.\n"); - - if ($2.flags.q.invariant || $2.has_interpolation() || $2.has_layout()) { - _mesa_glsl_error(&@1, state, "Storage qualifiers must come after " - "invariant, interpolation, and layout qualifiers.\n"); + _mesa_glsl_error(&@1, state, "duplicate storage qualifier"); + + if (!state->ARB_shading_language_420pack_enable && + ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() || + $2.has_layout() || $2.has_auxiliary_storage())) { + _mesa_glsl_error(&@1, state, "storage qualifiers must come after " + "precise, invariant, interpolation, layout and auxiliary " + "storage qualifiers"); } $$ = $1; - $$.flags.i |= $2.flags.i; + $$.merge_qualifier(&@1, state, $2); + } + | precision_qualifier type_qualifier + { + if ($2.precision != ast_precision_none) + _mesa_glsl_error(&@1, state, "duplicate precision qualifier"); + + if (!state->ARB_shading_language_420pack_enable && $2.flags.i != 0) + _mesa_glsl_error(&@1, state, "precision qualifiers must come last"); + + $$ = $2; + $$.precision = $1; } ; +auxiliary_storage_qualifier: + CENTROID + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.centroid = 1; + } + | SAMPLE + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.sample = 1; + } + /* TODO: "patch" also goes here someday. */ + storage_qualifier: CONST_TOK { @@ -1435,12 +1733,6 @@ storage_qualifier: memset(& $$, 0, sizeof($$)); $$.flags.q.varying = 1; } - | CENTROID VARYING - { - memset(& $$, 0, sizeof($$)); - $$.flags.q.centroid = 1; - $$.flags.q.varying = 1; - } | IN_TOK { memset(& $$, 0, sizeof($$)); @@ -1450,49 +1742,101 @@ storage_qualifier: { memset(& $$, 0, sizeof($$)); $$.flags.q.out = 1; + + if (state->stage == MESA_SHADER_GEOMETRY && + state->has_explicit_attrib_stream()) { + /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00 + * spec says: + * + * "If the block or variable is declared with the stream + * identifier, it is associated with the specified stream; + * otherwise, it is associated with the current default stream." + */ + $$.flags.q.stream = 1; + $$.flags.q.explicit_stream = 0; + $$.stream = state->out_qualifier->stream; + } } - | CENTROID IN_TOK + | UNIFORM { memset(& $$, 0, sizeof($$)); - $$.flags.q.centroid = 1; $$.flags.q.in = 1; + $$.flags.q.uniform = 1; } - | CENTROID OUT_TOK + | COHERENT { memset(& $$, 0, sizeof($$)); - $$.flags.q.centroid = 1; $$.flags.q.out = 1; + $$.flags.q.coherent = 1; } - | UNIFORM + | VOLATILE { memset(& $$, 0, sizeof($$)); - $$.flags.q.uniform = 1; + $$.flags.q._volatile = 1; + } + | RESTRICT + { + STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i)); + memset(& $$, 0, sizeof($$)); + $$.flags.q.restrict_flag = 1; + } + | READONLY + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.read_only = 1; + } + | WRITEONLY + { + memset(& $$, 0, sizeof($$)); + $$.flags.q.write_only = 1; } ; -type_specifier: - type_specifier_no_prec +array_specifier: + '[' ']' { - $$ = $1; + void *ctx = state; + $$ = new(ctx) ast_array_specifier(@1); + $$->set_location_range(@1, @2); } - | precision_qualifier type_specifier_no_prec + | '[' constant_expression ']' { - $$ = $2; - $$->precision = $1; + void *ctx = state; + $$ = new(ctx) ast_array_specifier(@1, $2); + $$->set_location_range(@1, @3); } - ; + | array_specifier '[' ']' + { + $$ = $1; -type_specifier_no_prec: - type_specifier_nonarray - | type_specifier_nonarray '[' ']' + if (!state->ARB_arrays_of_arrays_enable) { + _mesa_glsl_error(& @1, state, + "GL_ARB_arrays_of_arrays " + "required for defining arrays of arrays"); + } else { + _mesa_glsl_error(& @1, state, + "only the outermost array dimension can " + "be unsized"); + } + } + | array_specifier '[' constant_expression ']' { $$ = $1; - $$->is_array = true; - $$->array_size = NULL; + + if (!state->ARB_arrays_of_arrays_enable) { + _mesa_glsl_error(& @1, state, + "GL_ARB_arrays_of_arrays " + "required for defining arrays of arrays"); + } + + $$->add_dimension($3); } - | type_specifier_nonarray '[' constant_expression ']' + ; + +type_specifier: + type_specifier_nonarray + | type_specifier_nonarray array_specifier { $$ = $1; - $$->is_array = true; - $$->array_size = $3; + $$->array_specifier = $2; } ; @@ -1501,19 +1845,19 @@ type_specifier_nonarray: { void *ctx = state; $$ = new(ctx) ast_type_specifier($1); - $$->set_location(yylloc); + $$->set_location(@1); } | struct_specifier { void *ctx = state; $$ = new(ctx) ast_type_specifier($1); - $$->set_location(yylloc); + $$->set_location(@1); } | TYPE_IDENTIFIER { void *ctx = state; $$ = new(ctx) ast_type_specifier($1); - $$->set_location(yylloc); + $$->set_location(@1); } ; @@ -1585,6 +1929,40 @@ basic_type_specifier_nonarray: | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; } | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; } | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; } + | IMAGE1D { $$ = "image1D"; } + | IMAGE2D { $$ = "image2D"; } + | IMAGE3D { $$ = "image3D"; } + | IMAGE2DRECT { $$ = "image2DRect"; } + | IMAGECUBE { $$ = "imageCube"; } + | IMAGEBUFFER { $$ = "imageBuffer"; } + | IMAGE1DARRAY { $$ = "image1DArray"; } + | IMAGE2DARRAY { $$ = "image2DArray"; } + | IMAGECUBEARRAY { $$ = "imageCubeArray"; } + | IMAGE2DMS { $$ = "image2DMS"; } + | IMAGE2DMSARRAY { $$ = "image2DMSArray"; } + | IIMAGE1D { $$ = "iimage1D"; } + | IIMAGE2D { $$ = "iimage2D"; } + | IIMAGE3D { $$ = "iimage3D"; } + | IIMAGE2DRECT { $$ = "iimage2DRect"; } + | IIMAGECUBE { $$ = "iimageCube"; } + | IIMAGEBUFFER { $$ = "iimageBuffer"; } + | IIMAGE1DARRAY { $$ = "iimage1DArray"; } + | IIMAGE2DARRAY { $$ = "iimage2DArray"; } + | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; } + | IIMAGE2DMS { $$ = "iimage2DMS"; } + | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; } + | UIMAGE1D { $$ = "uimage1D"; } + | UIMAGE2D { $$ = "uimage2D"; } + | UIMAGE3D { $$ = "uimage3D"; } + | UIMAGE2DRECT { $$ = "uimage2DRect"; } + | UIMAGECUBE { $$ = "uimageCube"; } + | UIMAGEBUFFER { $$ = "uimageBuffer"; } + | UIMAGE1DARRAY { $$ = "uimage1DArray"; } + | UIMAGE2DARRAY { $$ = "uimage2DArray"; } + | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; } + | UIMAGE2DMS { $$ = "uimage2DMS"; } + | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; } + | ATOMIC_UINT { $$ = "atomic_uint"; } ; precision_qualifier: @@ -1610,15 +1988,14 @@ struct_specifier: { void *ctx = state; $$ = new(ctx) ast_struct_specifier($2, $4); - $$->set_location(yylloc); + $$->set_location_range(@2, @5); state->symbols->add_type($2, glsl_type::void_type); - state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$)); } | STRUCT '{' struct_declaration_list '}' { void *ctx = state; $$ = new(ctx) ast_struct_specifier(NULL, $3); - $$->set_location(yylloc); + $$->set_location_range(@2, @4); } ; @@ -1636,15 +2013,19 @@ struct_declaration_list: ; struct_declaration: - type_specifier struct_declarator_list ';' + fully_specified_type struct_declarator_list ';' { void *ctx = state; - ast_fully_specified_type *type = new(ctx) ast_fully_specified_type(); - type->set_location(yylloc); + ast_fully_specified_type *const type = $1; + type->set_location(@1); + + if (type->qualifier.flags.i != 0) + _mesa_glsl_error(&@1, state, + "only precision qualifiers may be applied to " + "structure members"); - type->specifier = $1; $$ = new(ctx) ast_declarator_list(type); - $$->set_location(yylloc); + $$->set_location(@2); $$->declarations.push_degenerate_list_at_head(& $2->link); } @@ -1667,14 +2048,14 @@ struct_declarator: any_identifier { void *ctx = state; - $$ = new(ctx) ast_declaration($1, false, NULL, NULL); - $$->set_location(yylloc); + $$ = new(ctx) ast_declaration($1, NULL, NULL); + $$->set_location(@1); } - | any_identifier '[' constant_expression ']' + | any_identifier array_specifier { void *ctx = state; - $$ = new(ctx) ast_declaration($1, true, $3, NULL); - $$->set_location(yylloc); + $$ = new(ctx) ast_declaration($1, $2, NULL); + $$->set_location_range(@1, @2); } ; @@ -1695,7 +2076,7 @@ initializer_list: { void *ctx = state; $$ = new(ctx) ast_aggregate_initializer(); - $$->set_location(yylloc); + $$->set_location(@1); $$->expressions.push_tail(& $1->link); } | initializer_list ',' initializer @@ -1729,7 +2110,7 @@ compound_statement: { void *ctx = state; $$ = new(ctx) ast_compound_statement(true, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } | '{' { @@ -1739,7 +2120,7 @@ compound_statement: { void *ctx = state; $$ = new(ctx) ast_compound_statement(true, $3); - $$->set_location(yylloc); + $$->set_location_range(@1, @4); state->symbols->pop_scope(); } ; @@ -1754,13 +2135,13 @@ compound_statement_no_new_scope: { void *ctx = state; $$ = new(ctx) ast_compound_statement(false, NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } | '{' statement_list '}' { void *ctx = state; $$ = new(ctx) ast_compound_statement(false, $2); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -1768,7 +2149,7 @@ statement_list: statement { if ($1 == NULL) { - _mesa_glsl_error(& @1, state, " statement\n"); + _mesa_glsl_error(& @1, state, " statement"); assert($1 != NULL); } @@ -1778,7 +2159,7 @@ statement_list: | statement_list statement { if ($2 == NULL) { - _mesa_glsl_error(& @2, state, " statement\n"); + _mesa_glsl_error(& @2, state, " statement"); assert($2 != NULL); } $$ = $1; @@ -1791,13 +2172,13 @@ expression_statement: { void *ctx = state; $$ = new(ctx) ast_expression_statement(NULL); - $$->set_location(yylloc); + $$->set_location(@1); } | expression ';' { void *ctx = state; $$ = new(ctx) ast_expression_statement($1); - $$->set_location(yylloc); + $$->set_location(@1); } ; @@ -1806,7 +2187,7 @@ selection_statement: { $$ = new(state) ast_selection_statement($3, $5.then_statement, $5.else_statement); - $$->set_location(yylloc); + $$->set_location_range(@1, @5); } ; @@ -1831,10 +2212,10 @@ condition: | fully_specified_type any_identifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4); + ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4); ast_declarator_list *declarator = new(ctx) ast_declarator_list($1); - decl->set_location(yylloc); - declarator->set_location(yylloc); + decl->set_location_range(@2, @4); + declarator->set_location(@1); declarator->declarations.push_tail(&decl->link); $$ = declarator; @@ -1842,14 +2223,14 @@ condition: ; /* - * siwtch_statement grammar is based on the syntax described in the body + * switch_statement grammar is based on the syntax described in the body * of the GLSL spec, not in it's appendix!!! */ switch_statement: SWITCH '(' expression ')' switch_body { $$ = new(state) ast_switch_statement($3, $5); - $$->set_location(yylloc); + $$->set_location_range(@1, @5); } ; @@ -1857,12 +2238,12 @@ switch_body: '{' '}' { $$ = new(state) ast_switch_body(NULL); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } | '{' case_statement_list '}' { $$ = new(state) ast_switch_body($2); - $$->set_location(yylloc); + $$->set_location_range(@1, @3); } ; @@ -1870,12 +2251,12 @@ case_label: CASE expression ':' { $$ = new(state) ast_case_label($2); - $$->set_location(yylloc); + $$->set_location(@2); } | DEFAULT ':' { $$ = new(state) ast_case_label(NULL); - $$->set_location(yylloc); + $$->set_location(@2); } ; @@ -1886,7 +2267,7 @@ case_label_list: labels->labels.push_tail(& $1->link); $$ = labels; - $$->set_location(yylloc); + $$->set_location(@1); } | case_label_list case_label { @@ -1899,7 +2280,7 @@ case_statement: case_label_list statement { ast_case_statement *stmts = new(state) ast_case_statement($1); - stmts->set_location(yylloc); + stmts->set_location(@2); stmts->stmts.push_tail(& $2->link); $$ = stmts; @@ -1915,7 +2296,7 @@ case_statement_list: case_statement { ast_case_statement_list *cases= new(state) ast_case_statement_list(); - cases->set_location(yylloc); + cases->set_location(@1); cases->cases.push_tail(& $1->link); $$ = cases; @@ -1933,21 +2314,21 @@ iteration_statement: void *ctx = state; $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while, NULL, $3, NULL, $5); - $$->set_location(yylloc); + $$->set_location_range(@1, @4); } | DO statement WHILE '(' expression ')' ';' { void *ctx = state; $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while, NULL, $5, NULL, $2); - $$->set_location(yylloc); + $$->set_location_range(@1, @6); } | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope { void *ctx = state; $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for, $3, $4.cond, $4.rest, $6); - $$->set_location(yylloc); + $$->set_location_range(@1, @6); } ; @@ -1983,31 +2364,31 @@ jump_statement: { void *ctx = state; $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL); - $$->set_location(yylloc); + $$->set_location(@1); } | BREAK ';' { void *ctx = state; $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL); - $$->set_location(yylloc); + $$->set_location(@1); } | RETURN ';' { void *ctx = state; $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL); - $$->set_location(yylloc); + $$->set_location(@1); } | RETURN expression ';' { void *ctx = state; $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); } | DISCARD ';' // Fragment shader only. { void *ctx = state; $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL); - $$->set_location(yylloc); + $$->set_location(@1); } ; @@ -2015,7 +2396,7 @@ external_declaration: function_definition { $$ = $1; } | declaration { $$ = $1; } | pragma_statement { $$ = NULL; } - | layout_defaults { $$ = NULL; } + | layout_defaults { $$ = $1; } ; function_definition: @@ -2023,7 +2404,7 @@ function_definition: { void *ctx = state; $$ = new(ctx) ast_function_definition(); - $$->set_location(yylloc); + $$->set_location_range(@1, @2); $$->prototype = $1; $$->body = $2; @@ -2043,6 +2424,18 @@ interface_block: if (!block->layout.merge_qualifier(& @1, state, $1)) { YYERROR; } + + foreach_list_typed (ast_declarator_list, member, link, &block->declarations) { + ast_type_qualifier& qualifier = member->type->qualifier; + if (qualifier.flags.q.stream && qualifier.stream != block->layout.stream) { + _mesa_glsl_error(& @1, state, + "stream layout qualifier on " + "interface block member does not match " + "the interface block (%d vs %d)", + qualifier.stream, block->layout.stream); + YYERROR; + } + } $$ = block; } ; @@ -2056,20 +2449,20 @@ basic_interface_block: block->declarations.push_degenerate_list_at_head(& $4->link); if ($1.flags.q.uniform) { - if (!state->ARB_uniform_buffer_object_enable) { + if (!state->has_uniform_buffer_objects()) { _mesa_glsl_error(& @1, state, "#version 140 / GL_ARB_uniform_buffer_object " - "required for defining uniform blocks\n"); + "required for defining uniform blocks"); } else if (state->ARB_uniform_buffer_object_warn) { _mesa_glsl_warning(& @1, state, "#version 140 / GL_ARB_uniform_buffer_object " - "required for defining uniform blocks\n"); + "required for defining uniform blocks"); } } else { if (state->es_shader || state->language_version < 150) { _mesa_glsl_error(& @1, state, "#version 150 required for using " - "interface blocks.\n"); + "interface blocks"); } } @@ -2077,14 +2470,14 @@ basic_interface_block: * "It is illegal to have an input block in a vertex shader * or an output block in a fragment shader" */ - if ((state->target == vertex_shader) && $1.flags.q.in) { + if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) { _mesa_glsl_error(& @1, state, "`in' interface block is not allowed for " - "a vertex shader\n"); - } else if ((state->target == fragment_shader) && $1.flags.q.out) { + "a vertex shader"); + } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) { _mesa_glsl_error(& @1, state, "`out' interface block is not allowed for " - "a fragment shader\n"); + "a fragment shader"); } /* Since block arrays require names, and both features are added in @@ -2096,7 +2489,7 @@ basic_interface_block: "an instance name are not allowed"); } - unsigned interface_type_mask; + uint64_t interface_type_mask; struct ast_type_qualifier temp_type_qualifier; /* Get a bitmask containing only the in/out/uniform flags, allowing us @@ -2112,10 +2505,18 @@ basic_interface_block: * production rule guarantees that only one bit will be set (and * it will be in/out/uniform). */ - unsigned block_interface_qualifier = $1.flags.i; + uint64_t block_interface_qualifier = $1.flags.i; block->layout.flags.i |= block_interface_qualifier; + if (state->stage == MESA_SHADER_GEOMETRY && + state->has_explicit_attrib_stream()) { + /* Assign global layout's stream value. */ + block->layout.flags.q.stream = 1; + block->layout.flags.q.explicit_stream = 0; + block->layout.stream = state->out_qualifier->stream; + } + foreach_list_typed (ast_declarator_list, member, link, &block->declarations) { ast_type_qualifier& qualifier = member->type->qualifier; if ((qualifier.flags.i & interface_type_mask) == 0) { @@ -2136,7 +2537,7 @@ basic_interface_block: _mesa_glsl_error(& @1, state, "uniform/in/out qualifier on " "interface block member does not match " - "the interface block\n"); + "the interface block"); } } @@ -2172,19 +2573,13 @@ instance_name_opt: { $$ = new(state) ast_interface_block(*state->default_uniform_qualifier, $1, NULL); + $$->set_location(@1); } - | NEW_IDENTIFIER '[' constant_expression ']' - { - $$ = new(state) ast_interface_block(*state->default_uniform_qualifier, - $1, $3); - } - | NEW_IDENTIFIER '[' ']' + | NEW_IDENTIFIER array_specifier { - _mesa_glsl_error(& @1, state, - "instance block arrays must be explicitly sized\n"); - $$ = new(state) ast_interface_block(*state->default_uniform_qualifier, - $1, NULL); + $1, $2); + $$->set_location_range(@1, @2); } ; @@ -2206,21 +2601,20 @@ member_declaration: { void *ctx = state; ast_fully_specified_type *type = $1; - type->set_location(yylloc); + type->set_location(@1); if (type->qualifier.flags.q.attribute) { _mesa_glsl_error(& @1, state, "keyword 'attribute' cannot be used with " - "interface block member\n"); + "interface block member"); } else if (type->qualifier.flags.q.varying) { _mesa_glsl_error(& @1, state, "keyword 'varying' cannot be used with " - "interface block member\n"); + "interface block member"); } $$ = new(ctx) ast_declarator_list(type); - $$->set_location(yylloc); - $$->ubo_qualifiers_valid = true; + $$->set_location(@2); $$->declarations.push_degenerate_list_at_head(& $2->link); } @@ -2232,4 +2626,42 @@ layout_defaults: if (!state->default_uniform_qualifier->merge_qualifier(& @1, state, $1)) { YYERROR; } + $$ = NULL; + } + + | layout_qualifier IN_TOK ';' + { + $$ = NULL; + if (!state->in_qualifier->merge_in_qualifier(& @1, state, $1, $$)) { + YYERROR; + } + } + + | layout_qualifier OUT_TOK ';' + { + if (state->stage != MESA_SHADER_GEOMETRY) { + _mesa_glsl_error(& @1, state, + "out layout qualifiers only valid in " + "geometry shaders"); + } else { + if ($1.flags.q.prim_type) { + /* Make sure this is a valid output primitive type. */ + switch ($1.prim_type) { + case GL_POINTS: + case GL_LINE_STRIP: + case GL_TRIANGLE_STRIP: + break; + default: + _mesa_glsl_error(&@1, state, "invalid geometry shader output " + "primitive type"); + break; + } + } + if (!state->out_qualifier->merge_qualifier(& @1, state, $1)) + YYERROR; + + /* Allow future assigments of global out's stream id value */ + state->out_qualifier->flags.q.explicit_stream = 0; + } + $$ = NULL; }