diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2008-11-10 12:33:17 -0700 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2008-11-10 12:39:36 -0700 |
commit | 2d76a0d77af7be9539f89cba37ce84338c1cdda4 (patch) | |
tree | 6e722f4d0f8356707ed9402dc9eeeb5dc56704b4 /src | |
parent | 379ff8c9567940ebff44870cf7b0202882445fa6 (diff) |
mesa: track initialization status of uniform variables. Plus, asst clean-ups.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/shader/prog_parameter.c | 6 | ||||
-rw-r--r-- | src/mesa/shader/prog_parameter.h | 4 | ||||
-rw-r--r-- | src/mesa/shader/prog_uniform.c | 29 | ||||
-rw-r--r-- | src/mesa/shader/prog_uniform.h | 2 | ||||
-rw-r--r-- | src/mesa/shader/shader_api.c | 20 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 17 | ||||
-rw-r--r-- | src/mesa/shader/slang/slang_link.c | 5 |
7 files changed, 52 insertions, 31 deletions
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index 2dfd923a0f..29c5b33f6c 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -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; } } diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h index e8d3e9ec33..0c35198de7 100644 --- a/src/mesa/shader/prog_parameter.h +++ b/src/mesa/shader/prog_parameter.h @@ -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, diff --git a/src/mesa/shader/prog_uniform.c b/src/mesa/shader/prog_uniform.c index a0aa615c5f..dc76be8e46 100644 --- a/src/mesa/shader/prog_uniform.c +++ b/src/mesa/shader/prog_uniform.c @@ -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; } diff --git a/src/mesa/shader/prog_uniform.h b/src/mesa/shader/prog_uniform.h index deea732991..22a2bfd970 100644 --- a/src/mesa/shader/prog_uniform.h +++ b/src/mesa/shader/prog_uniform.h @@ -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); diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index e883f8b8be..b3d66c5bab 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -1608,6 +1608,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) { @@ -1654,12 +1655,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); @@ -1668,14 +1671,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; } @@ -1742,8 +1745,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, @@ -1767,9 +1771,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, @@ -1779,7 +1785,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, @@ -1787,7 +1793,7 @@ _mesa_uniform_matrix(GLcontext *ctx, GLint cols, GLint rows, } } - shProg->Uniforms->Uniforms[location].Initialized = GL_TRUE; + uniform->Initialized = GL_TRUE; } diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 8ab1fa8f2a..dea1fcf087 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -3715,7 +3715,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); @@ -3747,18 +3747,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 */ @@ -3767,6 +3763,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 { diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 4361efc56e..79fd9a064f 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -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) { |