Mesa (mesa_7_7_branch): glsl: added uniform initializer check

Brian Paul brianp at kemper.freedesktop.org
Tue Dec 29 09:16:37 PST 2009


Module: Mesa
Branch: mesa_7_7_branch
Commit: 4f481cb87ae948852effde2fa4d997c007afd99c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4f481cb87ae948852effde2fa4d997c007afd99c

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Dec 29 10:11:26 2009 -0700

glsl: added uniform initializer check

GLSL 1.10 disallows initializers for uniforms but GLSL 1.20 and later
allows them.  This patch uses the #version directive to allow/disallow
uniform initializers.

This addresses bug 25807, but piglit also needs to be fixed to specify
the GLSL version in the shader.

---

 src/mesa/shader/slang/slang_codegen.c |    8 ++++++++
 src/mesa/shader/slang/slang_codegen.h |    1 +
 src/mesa/shader/slang/slang_compile.c |    3 +++
 3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index ee5a50c..b62cfc3 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -3763,6 +3763,14 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var,
 #endif
       }
 
+      if (var->type.qualifier == SLANG_QUAL_UNIFORM &&
+          !A->allow_uniform_initializers) {
+         slang_info_log_error(A->log,
+                              "initializer for uniform %s not allowed",
+                              varName);
+         return NULL;
+      }
+
       /* IR for the variable we're initializing */
       varRef = new_var(A, var);
       if (!varRef) {
diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h
index ee3be55..461633f 100644
--- a/src/mesa/shader/slang/slang_codegen.h
+++ b/src/mesa/shader/slang/slang_codegen.h
@@ -42,6 +42,7 @@ typedef struct slang_assemble_ctx_
    struct gl_sl_pragmas *pragmas;
    slang_var_table *vartable;
    slang_info_log *log;
+   GLboolean allow_uniform_initializers;
 
    /* current loop stack */
    const slang_operation *LoopOperStack[MAX_LOOP_DEPTH];
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index 499e16e..57e3555 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -2058,6 +2058,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
    if (C->global_scope) {
       slang_assemble_ctx A;
       memset(&A, 0, sizeof(slang_assemble_ctx));
+      A.allow_uniform_initializers = C->version > 110;
       A.atoms = C->atoms;
       A.space.funcs = O->funs;
       A.space.structs = O->structs;
@@ -2077,6 +2078,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
       if (var->initializer != NULL) {
          slang_assemble_ctx A;
          memset(&A, 0, sizeof(slang_assemble_ctx));
+         A.allow_uniform_initializers = C->version > 110;
          A.atoms = C->atoms;
          A.space.funcs = O->funs;
          A.space.structs = O->structs;
@@ -2434,6 +2436,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
       A.vartable = o.vartable;
       A.EmitContReturn = ctx->Shader.EmitContReturn;
       A.log = C->L;
+      A.allow_uniform_initializers = C->version > 110;
 
       /* main() takes no parameters */
       if (mainFunc->param_count > 0) {



More information about the mesa-commit mailing list