glsl: Turn UBO variable declarations into ir_variables and check qualifiers.
authorEric Anholt <eric@anholt.net>
Fri, 27 Apr 2012 01:19:39 +0000 (18:19 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 20 Jul 2012 17:43:12 +0000 (10:43 -0700)
Fixes piglit layout-*-non-uniform and layout-*-within-block.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/ast.h
src/glsl/ast_to_hir.cpp
src/glsl/glsl_parser.yy
src/glsl/glsl_parser_extras.cpp

index 4438b85bbdafb6db037eaca4c4dd5396cc5895f0..de3f2dfeb0b8f1699b510942878535f1f3e9d563 100644 (file)
@@ -513,6 +513,12 @@ public:
     * is used to note these cases when no type is specified.
     */
    int invariant;
+
+   /**
+    * Flag indicating that these declarators are in a uniform block,
+    * allowing UBO type qualifiers.
+    */
+   bool ubo_qualifiers_valid;
 };
 
 
index 5ad754c398d796edca75a69b748eb49416dc284c..8c739653fbe02fef996d99c52f2c58b84dadd276 100644 (file)
@@ -1917,7 +1917,8 @@ static void
 apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
                                 ir_variable *var,
                                 struct _mesa_glsl_parse_state *state,
-                                YYLTYPE *loc)
+                                YYLTYPE *loc,
+                                bool ubo_qualifiers_valid)
 {
    if (qual->flags.q.invariant) {
       if (var->used) {
@@ -2177,6 +2178,23 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
        var->depth_layout = ir_depth_layout_unchanged;
    else
        var->depth_layout = ir_depth_layout_none;
+
+   if (qual->flags.q.std140 ||
+       qual->flags.q.packed ||
+       qual->flags.q.shared) {
+      _mesa_glsl_error(loc, state,
+                       "uniform block layout qualifiers std140, packed, and "
+                      "shared can only be applied to uniform blocks, not "
+                      "members");
+   }
+
+   if (!ubo_qualifiers_valid &&
+       (qual->flags.q.row_major || qual->flags.q.column_major)) {
+      _mesa_glsl_error(loc, state,
+                       "uniform block layout qualifiers row_major and "
+                      "column_major can only be applied to uniform block "
+                      "members");
+   }
 }
 
 /**
@@ -2597,7 +2615,7 @@ ast_declarator_list::hir(exec_list *instructions,
       }
 
       apply_type_qualifier_to_variable(& this->type->qualifier, var, state,
-                                      & loc);
+                                      & loc, this->ubo_qualifiers_valid);
 
       if (this->type->qualifier.flags.q.invariant) {
         if ((state->target == vertex_shader) && !(var->mode == ir_var_out ||
@@ -3014,7 +3032,8 @@ ast_parameter_declarator::hir(exec_list *instructions,
    /* Apply any specified qualifiers to the parameter declaration.  Note that
     * for function parameters the default mode is 'in'.
     */
-   apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc);
+   apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc,
+                                   false);
 
    /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
     *
@@ -3983,6 +4002,14 @@ ast_uniform_block::hir(exec_list *instructions,
     * need to turn those into ir_variables with an association
     * with this uniform block.
     */
+   foreach_list_typed(ast_declarator_list, decl_list, link, &declarations) {
+      exec_list declared_variables;
+
+      decl_list->hir(&declared_variables, state);
+
+      instructions->append_list(&declared_variables);
+   }
+
    return NULL;
 }
 
index 3373375911b76c3eb84a8ab147bfd449a7a37e74..b2533c8476f2b0257f758be9a2cec45fbde9f512 100644 (file)
@@ -1967,6 +1967,7 @@ member_declaration:
           type->specifier = $3;
           $$ = new(ctx) ast_declarator_list(type);
           $$->set_location(yylloc);
+          $$->ubo_qualifiers_valid = true;
 
           $$->declarations.push_degenerate_list_at_head(& $4->link);
        }
@@ -1980,6 +1981,7 @@ member_declaration:
           type->specifier = $2;
           $$ = new(ctx) ast_declarator_list(type);
           $$->set_location(yylloc);
+          $$->ubo_qualifiers_valid = true;
 
           $$->declarations.push_degenerate_list_at_head(& $3->link);
        }
index d9ee406cfd472c4bece904ea3dd22906c02bcccd..df4045938ce09737a8b9b6f83808b1a509b6f2cf 100644 (file)
@@ -773,6 +773,7 @@ ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type)
 {
    this->type = type;
    this->invariant = false;
+   this->ubo_qualifiers_valid = false;
 }
 
 void