[Mesa-stable] [Mesa-dev] [PATCH 2/4 v2] glsl: Restrict initializers for global variables to constant expression in ES

Lofstedt, Marta marta.lofstedt at intel.com
Thu Oct 8 03:19:48 PDT 2015


Reviewed-by: Marta Lofstedt <marta.lofstedt at intel.com>


> -----Original Message-----
> From: mesa-dev [mailto:mesa-dev-bounces at lists.freedesktop.org] On
> Behalf Of Ian Romanick
> Sent: Wednesday, October 7, 2015 11:34 PM
> To: mesa-dev at lists.freedesktop.org
> Cc: Romanick, Ian D; 10.6 11.0
> Subject: [Mesa-dev] [PATCH 2/4 v2] glsl: Restrict initializers for global
> variables to constant expression in ES
> 
> From: Ian Romanick <ian.d.romanick at intel.com>
> 
> v2: Combine this check with the existing const and uniform checks.  This
> change depends on the previous patch (glsl: Only set
> ir_variable::constant_value for const-decorated variables).
> 
> Fixes:
> 
>     ES2-CTS.shaders.negative.initialize
>     ES3-CTS.shaders.negative.initialize
> 
>     spec/glsl-es-1.00/compiler/global-initializer/from-attribute.vert
>     spec/glsl-es-1.00/compiler/global-initializer/from-uniform.vert
>     spec/glsl-es-1.00/compiler/global-initializer/from-uniform.frag
>     spec/glsl-es-1.00/compiler/global-initializer/from-global.vert
>     spec/glsl-es-1.00/compiler/global-initializer/from-global.frag
>     spec/glsl-es-1.00/compiler/global-initializer/from-varying.frag
>     spec/glsl-es-3.00/compiler/global-initializer/from-uniform.vert
>     spec/glsl-es-3.00/compiler/global-initializer/from-uniform.frag
>     spec/glsl-es-3.00/compiler/global-initializer/from-in.vert
>     spec/glsl-es-3.00/compiler/global-initializer/from-in.frag
>     spec/glsl-es-3.00/compiler/global-initializer/from-global.vert
>     spec/glsl-es-3.00/compiler/global-initializer/from-global.frag
> 
> Note: spec/glsl-es-3.00/compiler/global-initializer/from-sequence.*
> still fail because the result of a sequence operator is still considered to be a
> constant expression.
> 
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92304
> Reviewed-by: Tapani Pälli <tapani.palli at intel.com> [v1]
> Reviewed-by: Iago Toral Quiroga <itoral at igalia.com> [v1]
> Cc: "10.6 11.0" <mesa-stable at lists.freedesktop.org>
> ---
>  src/glsl/ast_to_hir.cpp | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index
> e3d4c44..eefc7b7 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -3213,9 +3213,19 @@ process_initializer(ir_variable *var,
> ast_declaration *decl,
> 
>     /* Calculate the constant value if this is a const or uniform
>      * declaration.
> +    *
> +    * Section 4.3 (Storage Qualifiers) of the GLSL ES 1.00.17 spec says:
> +    *
> +    *     "Declarations of globals without a storage qualifier, or with
> +    *     just the const qualifier, may include initializers, in which case
> +    *     they will be initialized before the first line of main() is
> +    *     executed.  Such initializers must be a constant expression."
> +    *
> +    * The same section of the GLSL ES 3.00.4 spec has similar language.
>      */
>     if (type->qualifier.flags.q.constant
> -       || type->qualifier.flags.q.uniform) {
> +       || type->qualifier.flags.q.uniform
> +       || (state->es_shader && state->current_function == NULL)) {
>        ir_rvalue *new_rhs = validate_assignment(state, initializer_loc,
>                                                 lhs, rhs, true);
>        if (new_rhs != NULL) {
> @@ -3223,6 +3233,11 @@ process_initializer(ir_variable *var,
> ast_declaration *decl,
> 
>           ir_constant *constant_value = rhs->constant_expression_value();
>           if (!constant_value) {
> +            const char *const variable_mode =
> +               (type->qualifier.flags.q.constant)
> +               ? "const"
> +               : ((type->qualifier.flags.q.uniform) ? "uniform" :
> + "global");
> +
>              /* 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 @@ -
> 3233,8 +3248,7 @@ process_initializer(ir_variable *var, ast_declaration *decl,
>                 _mesa_glsl_error(& initializer_loc, state,
>                                  "initializer of %s variable `%s' must be a "
>                                  "constant expression",
> -                                (type->qualifier.flags.q.constant)
> -                                ? "const" : "uniform",
> +                                variable_mode,
>                                  decl->identifier);
>                 if (var->type->is_numeric()) {
>                    /* Reduce cascading errors. */
> --
> 2.1.0
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-stable mailing list