summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-11-10 12:33:17 -0700
committerBrian Paul <[email protected]>2009-01-06 08:39:06 -0700
commit6b05708ce2c4120921f43d82f1751e039306e0d6 (patch)
tree700d9da432f136714c1f53ab50fe933f466b7684
parentde445478915af41e1e078cbb8c2cbcce340f83b6 (diff)
mesa: track initialization status of uniform variables. Plus, asst clean-ups.
(cherry picked from commit 2d76a0d77af7be9539f89cba37ce84338c1cdda4)
-rw-r--r--src/mesa/shader/prog_parameter.c6
-rw-r--r--src/mesa/shader/prog_parameter.h4
-rw-r--r--src/mesa/shader/prog_uniform.c29
-rw-r--r--src/mesa/shader/prog_uniform.h2
-rw-r--r--src/mesa/shader/shader_api.c20
-rw-r--r--src/mesa/shader/slang/slang_codegen.c17
-rw-r--r--src/mesa/shader/slang/slang_link.c5
7 files changed, 52 insertions, 31 deletions
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index bfe27d2f638..e1729c7bff2 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 e8d3e9ec336..0c35198de7e 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 a0aa615c5f6..dc76be8e46c 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 deea7329912..22a2bfd9701 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 7af502a84cb..2af97612f79 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -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;
}
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index a76b6da32b4..f9199a917f6 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -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 {
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 4361efc56e5..79fd9a064f5 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) {