glsl: parser changes for GL_ARB_explicit_uniform_location
authorTapani Pälli <tapani.palli@intel.com>
Wed, 5 Mar 2014 10:35:03 +0000 (12:35 +0200)
committerTapani Pälli <tapani.palli@intel.com>
Mon, 16 Jun 2014 03:49:59 +0000 (06:49 +0300)
Patch adds a preprocessor define for the extension and stores explicit
location data for uniforms during AST->HIR conversion. It also sets
layout token to be available when having the extension in place.

v2: change parser check to require GLSL 330 or enabling
    GL_ARB_explicit_attrib_location (Ian)
v3: fix the check and comment in AST->HIR (Petri)

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
src/glsl/ast_to_hir.cpp
src/glsl/glcpp/glcpp-parse.y
src/glsl/glsl_lexer.ll
src/glsl/glsl_parser_extras.h

index 73825760ed8821a83c93b72aea3ba9e12c67ec00..12c691a2d727ce44ce56488959b31d9b881bb39e 100644 (file)
@@ -2181,6 +2181,41 @@ validate_explicit_location(const struct ast_type_qualifier *qual,
 {
    bool fail = false;
 
+   /* Checks for GL_ARB_explicit_uniform_location. */
+   if (qual->flags.q.uniform) {
+      if (!state->check_explicit_uniform_location_allowed(loc, var))
+         return;
+
+      const struct gl_context *const ctx = state->ctx;
+      unsigned max_loc = qual->location + var->type->uniform_locations() - 1;
+
+      /* ARB_explicit_uniform_location specification states:
+       *
+       *     "The explicitly defined locations and the generated locations
+       *     must be in the range of 0 to MAX_UNIFORM_LOCATIONS minus one."
+       *
+       *     "Valid locations for default-block uniform variable locations
+       *     are in the range of 0 to the implementation-defined maximum
+       *     number of uniform locations."
+       */
+      if (qual->location < 0) {
+         _mesa_glsl_error(loc, state,
+                          "explicit location < 0 for uniform %s", var->name);
+         return;
+      }
+
+      if (max_loc >= ctx->Const.MaxUserAssignableUniformLocations) {
+         _mesa_glsl_error(loc, state, "location(s) consumed by uniform %s "
+                          ">= MAX_UNIFORM_LOCATIONS (%u)", var->name,
+                          ctx->Const.MaxUserAssignableUniformLocations);
+         return;
+      }
+
+      var->data.explicit_location = true;
+      var->data.location = qual->location;
+      return;
+   }
+
    /* Between GL_ARB_explicit_attrib_location an
     * GL_ARB_separate_shader_objects, the inputs and outputs of any shader
     * stage can be assigned explicit locations.  The checking here associates
index 98875837cdd4c9bd0d64bfe8d93ffaf20f31312b..dacb954b52cce684b71ab6dc915a93bcb5adcb03 100644 (file)
@@ -2089,6 +2089,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
              if (extensions->ARB_explicit_attrib_location)
                 add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
 
+             if (extensions->ARB_explicit_uniform_location)
+                add_builtin_define(parser, "GL_ARB_explicit_uniform_location", 1);
+
              if (extensions->ARB_shader_texture_lod)
                 add_builtin_define(parser, "GL_ARB_shader_texture_lod", 1);
 
index 6c3f9b692b453a93a0d1738f9e2e2e6dfe3d55f3..db7b1d1791b28f05b2ee65b930ff276b10354f6a 100644 (file)
@@ -396,6 +396,7 @@ layout              {
                      || yyextra->AMD_conservative_depth_enable
                      || yyextra->ARB_conservative_depth_enable
                      || yyextra->ARB_explicit_attrib_location_enable
+                     || yyextra->ARB_explicit_uniform_location_enable
                       || yyextra->has_separate_shader_objects()
                      || yyextra->ARB_uniform_buffer_object_enable
                      || yyextra->ARB_fragment_coord_conventions_enable
index 6459cac64c999ee3c8a23bca6a41f9c19de96b65..a59090f8220e93532b5d938029cb5bffa79840dc 100644 (file)
@@ -151,6 +151,21 @@ struct _mesa_glsl_parse_state {
       return true;
    }
 
+   bool check_explicit_uniform_location_allowed(YYLTYPE *locp,
+                                                const ir_variable *var)
+   {
+      if (!this->has_explicit_attrib_location() ||
+          !this->ARB_explicit_uniform_location_enable) {
+         _mesa_glsl_error(locp, this,
+                          "uniform explicit location requires "
+                          "GL_ARB_explicit_uniform_location and either "
+                          "GL_ARB_explicit_attrib_location or GLSL 330.");
+         return false;
+      }
+
+      return true;
+   }
+
    bool has_explicit_attrib_location() const
    {
       return ARB_explicit_attrib_location_enable || is_version(330, 300);