[Mesa-dev] [PATCH 06/18] glsl: Turn UBO variable declarations into ir_variables and check qualifiers.

Kenneth Graunke kenneth at whitecape.org
Tue Jul 3 15:45:44 PDT 2012


On 07/02/2012 05:38 PM, Eric Anholt wrote:
> Fixes piglit layout-*-non-uniform and layout-*-within-block.
> ---
>  src/glsl/ast.h                  |    6 ++++++
>  src/glsl/ast_to_hir.cpp         |   36 +++++++++++++++++++++++++++++++++---
>  src/glsl/glsl_parser.yy         |    2 ++
>  src/glsl/glsl_parser_extras.cpp |    1 +
>  4 files changed, 42 insertions(+), 3 deletions(-)
> 
> diff --git a/src/glsl/ast.h b/src/glsl/ast.h
> index 4438b85..de3f2df 100644
> --- a/src/glsl/ast.h
> +++ b/src/glsl/ast.h
> @@ -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;
>  };
>  
>  
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index bbe8f05..fc3b547 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -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) {
> @@ -2191,6 +2192,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");
> +   }
>  }
>  
>  /**
> @@ -2611,7 +2629,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 ||
> @@ -3028,7 +3046,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:
>      *
> @@ -3997,6 +4016,17 @@ ast_uniform_block::hir(exec_list *instructions,
>      * need to turn those into ir_variables with an association
>      * with this uniform block.
>      */
> +   exec_list ubo_variables;
> +
> +   foreach_list_typed(ast_declarator_list, decl_list, link, &declarations) {
> +      exec_list declared_variables;
> +
> +      decl_list->hir(&declared_variables, state);
> +
> +      ubo_variables.append_list(&declared_variables);
> +   }
> +
> +   instructions->append_list(&ubo_variables);

Too many lists!!

foreach_list_typed(ast_declarator_list, decl_list, link, &declarations) {
   decl_list->hir(&instructions, state);
}

...should work just fine.  Otherwise, this looks OK to me.

>     return NULL;
>  }
>  
> diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
> index ccc1abb..09c37d1 100644
> --- a/src/glsl/glsl_parser.yy
> +++ b/src/glsl/glsl_parser.yy
> @@ -1962,6 +1962,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);
>  	}
> @@ -1975,6 +1976,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);
>  	}
> diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
> index d9ee406..df40459 100644
> --- a/src/glsl/glsl_parser_extras.cpp
> +++ b/src/glsl/glsl_parser_extras.cpp
> @@ -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
> 


More information about the mesa-dev mailing list