glsl: initialise killed_all field.
[mesa.git] / src / glsl / glsl_parser.yy
index f61d6b8dd3e8ee4298740608fc00ee4723caf5ce..407dbbeebccce72d5102b38cc7c32a1a9d9352df 100644 (file)
@@ -29,6 +29,7 @@
 #include "ast.h"
 #include "glsl_parser_extras.h"
 #include "glsl_types.h"
+#include "main/context.h"
 
 #define YYLEX_PARAM state->scanner
 
@@ -100,9 +101,11 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %token MAT4X2 MAT4X3 MAT4X4
 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
-%token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
-%token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
-%token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
+%token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
+%token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
+%token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
+%token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
+%token USAMPLER2DARRAY USAMPLERCUBEARRAY
 %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
 %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
 %token SAMPLEREXTERNALOES
@@ -235,6 +238,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %type <node> conditionopt
 %type <node> for_init_statement
 %type <for_rest_statement> for_rest_statement
+%type <n> integer_constant
 %%
 
 translation_unit: 
@@ -259,19 +263,25 @@ version_statement:
           switch ($2) {
           case 100:
              state->es_shader = true;
-             supported = state->Const.GLSL_100ES;
+             supported = state->ctx->API == API_OPENGLES2 ||
+                         state->ctx->Extensions.ARB_ES2_compatibility;
              break;
           case 110:
-             supported = state->Const.GLSL_110;
-             break;
           case 120:
-             supported = state->Const.GLSL_120;
-             break;
+             /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
+              * the OpenGL 3.2 Core context is supported, this logic will need
+              * change.  Older versions of GLSL are no longer supported
+              * outside the compatibility contexts of 3.x.
+              */
           case 130:
-             supported = state->Const.GLSL_130;
-             break;
           case 140:
-             supported = state->Const.GLSL_140;
+          case 150:
+          case 330:
+          case 400:
+          case 410:
+          case 420:
+             supported = _mesa_is_desktop_gl(state->ctx) &&
+                         ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
              break;
           default:
              supported = false;
@@ -291,6 +301,10 @@ version_statement:
                               state->version_string,
                               state->supported_version_string);
           }
+
+          if (state->language_version >= 140) {
+             state->ARB_uniform_buffer_object_enable = true;
+          }
        }
        ;
 
@@ -301,7 +315,7 @@ pragma_statement:
        | PRAGMA_OPTIMIZE_OFF EOL
        | PRAGMA_INVARIANT_ALL EOL
        {
-          if (state->language_version < 120 && !state->Const.GLSL_100ES) {
+          if (state->language_version == 110) {
              _mesa_glsl_warning(& @1, state,
                                 "pragma `invariant(all)' not supported in %s",
                                 state->version_string);
@@ -1102,23 +1116,17 @@ layout_qualifier_id_list:
        layout_qualifier_id
        | layout_qualifier_id_list ',' layout_qualifier_id
        {
-          if (($1.flags.i & $3.flags.i) != 0) {
-             _mesa_glsl_error(& @3, state,
-                              "duplicate layout qualifiers used\n");
+          $$ = $1;
+          if (!$$.merge_qualifier(& @3, state, $3)) {
              YYERROR;
           }
-
-          $$ = $1;
-          $$.flags.i |= $3.flags.i;
-
-          if ($3.flags.q.explicit_location)
-             $$.location = $3.location;
-
-          if ($3.flags.q.explicit_index)
-             $$.index = $3.index;
        }
        ;
 
+integer_constant:
+       INTCONSTANT { $$ = $1; }
+       | UINTCONSTANT { $$ = $1; }
+
 layout_qualifier_id:
        any_identifier
        {
@@ -1188,7 +1196,7 @@ layout_qualifier_id:
              YYERROR;
           }
        }
-       | any_identifier '=' INTCONSTANT
+       | any_identifier '=' integer_constant
        {
           memset(& $$, 0, sizeof($$));
 
@@ -1466,6 +1474,8 @@ basic_type_specifier_nonarray:
        | SAMPLER1DARRAYSHADOW  { $$ = "sampler1DArrayShadow"; }
        | SAMPLER2DARRAYSHADOW  { $$ = "sampler2DArrayShadow"; }
        | SAMPLERBUFFER         { $$ = "samplerBuffer"; }
+       | SAMPLERCUBEARRAY      { $$ = "samplerCubeArray"; }
+       | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
        | ISAMPLER1D            { $$ = "isampler1D"; }
        | ISAMPLER2D            { $$ = "isampler2D"; }
        | ISAMPLER2DRECT        { $$ = "isampler2DRect"; }
@@ -1474,6 +1484,7 @@ basic_type_specifier_nonarray:
        | ISAMPLER1DARRAY       { $$ = "isampler1DArray"; }
        | ISAMPLER2DARRAY       { $$ = "isampler2DArray"; }
        | ISAMPLERBUFFER        { $$ = "isamplerBuffer"; }
+       | ISAMPLERCUBEARRAY     { $$ = "isamplerCubeArray"; }
        | USAMPLER1D            { $$ = "usampler1D"; }
        | USAMPLER2D            { $$ = "usampler2D"; }
        | USAMPLER2DRECT        { $$ = "usampler2DRect"; }
@@ -1482,6 +1493,7 @@ basic_type_specifier_nonarray:
        | USAMPLER1DARRAY       { $$ = "usampler1DArray"; }
        | USAMPLER2DARRAY       { $$ = "usampler2DArray"; }
        | USAMPLERBUFFER        { $$ = "usamplerBuffer"; }
+       | USAMPLERCUBEARRAY     { $$ = "usamplerCubeArray"; }
        ;
 
 precision_qualifier:
@@ -1905,6 +1917,7 @@ external_declaration:
        function_definition     { $$ = $1; }
        | declaration           { $$ = $1; }
        | pragma_statement      { $$ = NULL; }
+       | layout_defaults       { $$ = NULL; }
        ;
 
 function_definition:
@@ -1925,14 +1938,38 @@ uniform_block:
        UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
        {
           void *ctx = state;
-          ast_type_qualifier no_qual;
-          memset(&no_qual, 0, sizeof(no_qual));
-          $$ = new(ctx) ast_uniform_block(no_qual, $2, $4);
+          $$ = new(ctx) ast_uniform_block(*state->default_uniform_qualifier,
+                                          $2, $4);
+
+          if (!state->ARB_uniform_buffer_object_enable) {
+             _mesa_glsl_error(& @1, state,
+                              "#version 140 / GL_ARB_uniform_buffer_object "
+                              "required for defining uniform blocks\n");
+          } 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");
+          }
        }
        | layout_qualifier UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
        {
           void *ctx = state;
-          $$ = new(ctx) ast_uniform_block($1, $3, $5);
+
+          ast_type_qualifier qual = *state->default_uniform_qualifier;
+          if (!qual.merge_qualifier(& @1, state, $1)) {
+             YYERROR;
+          }
+          $$ = new(ctx) ast_uniform_block(qual, $3, $5);
+
+          if (!state->ARB_uniform_buffer_object_enable) {
+             _mesa_glsl_error(& @1, state,
+                              "#version 140 / GL_ARB_uniform_buffer_object "
+                              "required for defining uniform blocks\n");
+          } 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");
+          }
        }
        ;
 
@@ -1986,3 +2023,12 @@ member_declaration:
           $$->declarations.push_degenerate_list_at_head(& $3->link);
        }
        ;
+
+layout_defaults:
+       layout_qualifier UNIFORM ';'
+       {
+          if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,
+                                                                 $1)) {
+             YYERROR;
+          }
+       }