[Mesa-dev] [PATCH] glsl: Restrict initializers for global variables to constant expression in ES

Ian Romanick idr at freedesktop.org
Tue Oct 6 19:09:39 PDT 2015


From: Ian Romanick <ian.d.romanick at intel.com>

It may be possible to consolodate this check with the existing check for
uniform and const initializers, but a way that didn't require a huge
amount of restructing was not obvious to me.

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
Cc: "10.6 11.0" <mesa-stable at lists.freedesktop.org>
---
 src/glsl/ast_to_hir.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 9511440..92f288f 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3300,6 +3300,27 @@ process_initializer(ir_variable *var, ast_declaration *decl,
       var->data.read_only = temp;
    }
 
+   /* 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.
+    *
+    * Initializers for const-decorated declarations are handled above.
+    */
+   const bool is_global_declaration = state->current_function == NULL;
+   if (state->es_shader &&
+       is_global_declaration &&
+       var->data.has_initializer &&
+       var->constant_initializer == NULL)
+      _mesa_glsl_error(&initializer_loc, state,
+                       "initializer of global variable `%s' must be a "
+                       "constant expression",
+                       decl->identifier);
+
    return result;
 }
 
-- 
2.1.0



More information about the mesa-dev mailing list