mesa: track initialization status of uniform variables. Plus, asst clean-ups.
authorBrian Paul <brian.paul@tungstengraphics.com>
Mon, 10 Nov 2008 19:33:17 +0000 (12:33 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 6 Jan 2009 15:39:06 +0000 (08:39 -0700)
(cherry picked from commit 2d76a0d77af7be9539f89cba37ce84338c1cdda4)

src/mesa/shader/prog_parameter.c
src/mesa/shader/prog_parameter.h
src/mesa/shader/prog_uniform.c
src/mesa/shader/prog_uniform.h
src/mesa/shader/shader_api.c
src/mesa/shader/slang/slang_codegen.c
src/mesa/shader/slang/slang_link.c

index bfe27d2f6389133368e35dcc7bf143f2170605a5..e1729c7bff2fa530e7864ce65f489e8e159f19d2 100644 (file)
@@ -128,6 +128,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
          if (values) {
             COPY_4V(paramList->ParameterValues[oldNum + i], values);
             values += 4;
+            p->Initialized = GL_TRUE;
          }
          else {
             /* silence valgrind */
@@ -259,7 +260,8 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
  */
 GLint
 _mesa_add_uniform(struct gl_program_parameter_list *paramList,
-                  const char *name, GLuint size, GLenum datatype)
+                  const char *name, GLuint size, GLenum datatype,
+                  const GLfloat *values)
 {
    GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
    ASSERT(datatype != GL_NONE);
@@ -271,7 +273,7 @@ _mesa_add_uniform(struct gl_program_parameter_list *paramList,
    }
    else {
       i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name,
-                              size, datatype, NULL, NULL);
+                              size, datatype, values, NULL);
       return i;
    }
 }
index e8d3e9ec3362515e115d0358966f7d383a5fb728..0c35198de7e8bf83511ad92a6e52ab8f22c5a7e6 100644 (file)
@@ -49,6 +49,7 @@ struct gl_program_parameter
    GLenum DataType;         /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
    GLuint Size;             /**< Number of components (1..4) */
    GLboolean Used;          /**< Helper flag for GLSL uniform tracking */
+   GLboolean Initialized;   /**< Has the ParameterValue[] been set? */
    /**
     * A sequence of STATE_* tokens and integers to identify GL state.
     */
@@ -111,7 +112,8 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
 
 extern GLint
 _mesa_add_uniform(struct gl_program_parameter_list *paramList,
-                  const char *name, GLuint size, GLenum datatype);
+                  const char *name, GLuint size, GLenum datatype,
+                  const GLfloat *values);
 
 extern void
 _mesa_use_uniform(struct gl_program_parameter_list *paramList,
index a0aa615c5f62c4a93596dccecaea3b500200764d..dc76be8e46c3c15781893eebd23b11d0f274f70a 100644 (file)
@@ -52,11 +52,12 @@ _mesa_free_uniform_list(struct gl_uniform_list *list)
 }
 
 
-GLboolean
+struct gl_uniform *
 _mesa_append_uniform(struct gl_uniform_list *list,
                      const char *name, GLenum target, GLuint progPos)
 {
    const GLuint oldNum = list->NumUniforms;
+   struct gl_uniform *uniform;
    GLint index;
 
    assert(target == GL_VERTEX_PROGRAM_ARB ||
@@ -84,31 +85,37 @@ _mesa_append_uniform(struct gl_uniform_list *list,
          return GL_FALSE;
       }
 
-      list->Uniforms[oldNum].Name = _mesa_strdup(name);
-      list->Uniforms[oldNum].VertPos = -1;
-      list->Uniforms[oldNum].FragPos = -1;
-      list->Uniforms[oldNum].Initialized = GL_FALSE;
-      index = oldNum;
+      uniform = list->Uniforms + oldNum;
+
+      uniform->Name = _mesa_strdup(name);
+      uniform->VertPos = -1;
+      uniform->FragPos = -1;
+      uniform->Initialized = GL_FALSE;
+
       list->NumUniforms++;
    }
+   else {
+      /* found */
+      uniform = list->Uniforms + index;
+   }
 
    /* update position for the vertex or fragment program */
    if (target == GL_VERTEX_PROGRAM_ARB) {
-      if (list->Uniforms[index].VertPos != -1) {
+      if (uniform->VertPos != -1) {
          /* this uniform is already in the list - that shouldn't happen */
          return GL_FALSE;
       }
-      list->Uniforms[index].VertPos = progPos;
+      uniform->VertPos = progPos;
    }
    else {
-      if (list->Uniforms[index].FragPos != -1) {
+      if (uniform->FragPos != -1) {
          /* this uniform is already in the list - that shouldn't happen */
          return GL_FALSE;
       }
-      list->Uniforms[index].FragPos = progPos;
+      uniform->FragPos = progPos;
    }
 
-   return GL_TRUE;
+   return uniform;
 }
 
 
index deea7329912b2f905e2ca1f364498cbdf0e0f9d1..22a2bfd9701173cf99a5a10bed0c3fa146f052d3 100644 (file)
@@ -75,7 +75,7 @@ _mesa_new_uniform_list(void);
 extern void
 _mesa_free_uniform_list(struct gl_uniform_list *list);
 
-extern GLboolean
+extern struct gl_uniform *
 _mesa_append_uniform(struct gl_uniform_list *list,
                      const char *name, GLenum target, GLuint progPos);
 
index 7af502a84cb98f0775bf7b8237a59f25787bc4ac..2af97612f796784d6e1dd603bd5498979b7929bb 100644 (file)
@@ -1610,6 +1610,7 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
               const GLvoid *values, GLenum type)
 {
    struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
+   struct gl_uniform *uniform;
    GLint elems, offset;
 
    if (!shProg || !shProg->LinkStatus) {
@@ -1656,12 +1657,14 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
+   uniform = &shProg->Uniforms->Uniforms[location];
+
    /* A uniform var may be used by both a vertex shader and a fragment
     * shader.  We may need to update one or both shader's uniform here:
     */
    if (shProg->VertexProgram) {
       /* convert uniform location to program parameter index */
-      GLint index = shProg->Uniforms->Uniforms[location].VertPos;
+      GLint index = uniform->VertPos;
       if (index >= 0) {
          set_program_uniform(ctx, &shProg->VertexProgram->Base,
                              index, offset, type, count, elems, values);
@@ -1670,14 +1673,14 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
 
    if (shProg->FragmentProgram) {
       /* convert uniform location to program parameter index */
-      GLint index = shProg->Uniforms->Uniforms[location].FragPos;
+      GLint index = uniform->FragPos;
       if (index >= 0) {
          set_program_uniform(ctx, &shProg->FragmentProgram->Base,
                              index, offset, type, count, elems, values);
       }
    }
 
-   shProg->Uniforms->Uniforms[location].Initialized = GL_TRUE;
+   uniform->Initialized = GL_TRUE;
 }
 
 
@@ -1744,8 +1747,9 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows,
                      GLenum matrixType, GLint location, GLsizei count,
                      GLboolean transpose, const GLfloat *values)
 {
-   GLint offset;
    struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
+   struct gl_uniform *uniform;
+   GLint offset;
 
    if (!shProg || !shProg->LinkStatus) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -1769,9 +1773,11 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows,
 
    FLUSH_VERTICES(ctx, _NEW_PROGRAM);
 
+   uniform = &shProg->Uniforms->Uniforms[location];
+
    if (shProg->VertexProgram) {
       /* convert uniform location to program parameter index */
-      GLint index = shProg->Uniforms->Uniforms[location].VertPos;
+      GLint index = uniform->VertPos;
       if (index >= 0) {
          set_program_uniform_matrix(ctx, &shProg->VertexProgram->Base,
                                     index, offset,
@@ -1781,7 +1787,7 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows,
 
    if (shProg->FragmentProgram) {
       /* convert uniform location to program parameter index */
-      GLint index = shProg->Uniforms->Uniforms[location].FragPos;
+      GLint index = uniform->FragPos;
       if (index >= 0) {
          set_program_uniform_matrix(ctx, &shProg->FragmentProgram->Base,
                                     index, offset,
@@ -1789,7 +1795,7 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows,
       }
    }
 
-   shProg->Uniforms->Uniforms[location].Initialized = GL_TRUE;
+   uniform->Initialized = GL_TRUE;
 }
 
 
index a76b6da32b40d8e7161d176d83fcc9e984420c36..f9199a917f6706e7502bb1614b852322f94568ff 100644 (file)
@@ -3712,7 +3712,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
                /* temporary work-around */
                GLenum datatype = GL_FLOAT;
                GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
-                                                    totalSize, datatype);
+                                                    totalSize, datatype, NULL);
                store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
                                                  totalSize, swizzle);
 
@@ -3744,18 +3744,14 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
             }
          }
          else {
-            GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
-                                                 totalSize, datatype);
-            store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
-                                              totalSize, swizzle);
+            GLint uniformLoc;
+            const GLfloat *initialValues = NULL;
             if (var->initializer) {
                _slang_simplify(var->initializer, &A->space, A->atoms);
                if (var->initializer->type == SLANG_OPER_LITERAL_FLOAT ||
                    var->initializer->type == SLANG_OPER_LITERAL_INT) {
                   /* simple float/vector initializer */
-                  GLfloat *uniformValue =
-                     prog->Parameters->ParameterValues[uniformLoc];
-                  COPY_4V(uniformValue, var->initializer->literal);
+                  initialValues = var->initializer->literal;
                }
                else {
                   /* complex initializer */
@@ -3764,6 +3760,11 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
                   return GL_FALSE;
                }
             }
+
+            uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
+                                           totalSize, datatype, initialValues);
+            store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
+                                              totalSize, swizzle);
          }
       }
       else {
index 4361efc56e53f90ecf0cd3be4ee43860ac4a6b0b..79fd9a064f5f9bf373c2f2a8d47519cfa14c2b5f 100644 (file)
@@ -193,7 +193,10 @@ link_uniform_vars(struct gl_shader_program *shProg,
 
       if ((p->Type == PROGRAM_UNIFORM && p->Used) ||
           p->Type == PROGRAM_SAMPLER) {
-         _mesa_append_uniform(shProg->Uniforms, p->Name, prog->Target, i);
+         struct gl_uniform *uniform =
+            _mesa_append_uniform(shProg->Uniforms, p->Name, prog->Target, i);
+         if (uniform)
+            uniform->Initialized = p->Initialized;
       }
 
       if (p->Type == PROGRAM_SAMPLER) {