[Mesa-dev] [PATCH 6/7] glsl: Allow non-constant expression initializers of const-qualified vars.

Matt Turner mattst88 at gmail.com
Sat Jun 29 19:42:15 PDT 2013


On Fri, May 24, 2013 at 6:28 PM, Matt Turner <mattst88 at gmail.com> wrote:
> Required by ARB_shading_language_420pack.
> ---
>  src/glsl/ast_to_hir.cpp | 30 +++++++++++++++++++-----------
>  1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 6e689b4..6b56e87 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -2337,17 +2337,25 @@ process_initializer(ir_variable *var, ast_declaration *decl,
>
>          ir_constant *constant_value = rhs->constant_expression_value();
>          if (!constant_value) {
> -           _mesa_glsl_error(& initializer_loc, state,
> -                            "initializer of %s variable `%s' must be a "
> -                            "constant expression",
> -                            (type->qualifier.flags.q.constant)
> -                            ? "const" : "uniform",
> -                            decl->identifier);
> -           if (var->type->is_numeric()) {
> -              /* Reduce cascading errors. */
> -              var->constant_value = ir_constant::zero(state, var->type);
> -           }
> -        } else {
> +            /* If ARB_shading_language_420pack is enabled, initializers of
> +             * const-qualified local variables do not have to be constant
> +             * expressions. Const-qualified global variables must still be
> +             * initialized with constant expressions.
> +             */
> +            if (!state->ARB_shading_language_420pack_enable
> +                || state->current_function == NULL) {
> +               _mesa_glsl_error(& initializer_loc, state,
> +                                "initializer of %s variable `%s' must be a "
> +                                "constant expression",
> +                                (type->qualifier.flags.q.constant)
> +                                ? "const" : "uniform",
> +                                decl->identifier);
> +               if (var->type->is_numeric()) {
> +                  /* Reduce cascading errors. */
> +                  var->constant_value = ir_constant::zero(state, var->type);
> +               }
> +            }
> +         } else {
>             rhs = constant_value;
>             var->constant_value = constant_value;
>          }
> --
> 1.8.1.5
>

Ping.

Check out the piglit tests:
   const-var-non-constant-expr.shader_test
   global-const-var-non-const-expr.frag

Those confirm that this change is correct.


More information about the mesa-dev mailing list