summaryrefslogtreecommitdiffstats
path: root/src/mesa/program/ir_to_mesa.cpp
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-10-18 16:01:49 -0700
committerIan Romanick <[email protected]>2011-11-07 13:33:16 -0800
commit719909698c67c287a393d2380278e7b7495ae018 (patch)
tree1a49879205ab93ea2d67db62cd8282b60302bdd7 /src/mesa/program/ir_to_mesa.cpp
parent143d20c16a33e2f08e834b28c23dbea772591ef9 (diff)
mesa: Rewrite the way uniforms are tracked and handled
Switch all of the code in ir_to_mesa, st_glsl_to_tgsi, glUniform*, glGetUniform, glGetUniformLocation, and glGetActiveUniforms to use the gl_uniform_storage structures in the gl_shader_program. A couple of notes: * Like most rewrite-the-world patches, this should be reviewed by applying the patch and examining the modified functions. * This leaves a lot of dead code around in linker.cpp and uniform_query.cpp. This will be deleted in the next patches. v2: Update the comment block (previously a FINISHME) in _mesa_uniform about generating GL_INVALID_VALUE when an out-of-range sampler index is specified. Signed-off-by: Ian Romanick <[email protected]> Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/mesa/program/ir_to_mesa.cpp')
-rw-r--r--src/mesa/program/ir_to_mesa.cpp47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 1bdfa2e10b7..cf868902c13 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -35,6 +35,7 @@
#include "ir_visitor.h"
#include "ir_print_visitor.h"
#include "ir_expression_flattening.h"
+#include "ir_uniform.h"
#include "glsl_types.h"
#include "glsl_parser_extras.h"
#include "../glsl/program.h"
@@ -2597,17 +2598,17 @@ class add_uniform_to_shader : public uniform_field_visitor {
public:
add_uniform_to_shader(struct gl_shader_program *shader_program,
struct gl_program_parameter_list *params)
- : shader_program(shader_program), params(params), next_sampler(0)
+ : shader_program(shader_program), params(params)
{
/* empty */
}
- int process(ir_variable *var)
+ void process(ir_variable *var)
{
this->idx = -1;
this->uniform_field_visitor::process(var);
- return this->idx;
+ var->location = this->idx;
}
private:
@@ -2615,7 +2616,6 @@ private:
struct gl_shader_program *shader_program;
struct gl_program_parameter_list *params;
- int next_sampler;
int idx;
};
@@ -2648,8 +2648,20 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name)
* store in ParameterValues[].
*/
if (file == PROGRAM_SAMPLER) {
+ unsigned location;
+ const bool found =
+ this->shader_program->UniformHash->get(location,
+ params->Parameters[index].Name);
+ assert(found);
+
+ if (!found)
+ return;
+
+ struct gl_uniform_storage *storage =
+ &this->shader_program->UniformStorage[location];
+
for (unsigned int j = 0; j < size / 4; j++)
- params->ParameterValues[index + j][0].f = this->next_sampler++;
+ params->ParameterValues[index + j][0].f = storage->sampler + j;
}
}
@@ -2684,17 +2696,7 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program
|| (strncmp(var->name, "gl_", 3) == 0))
continue;
- int loc = add.process(var);
-
- /* The location chosen in the Parameters list here (returned from
- * _mesa_add_parameter) has to match what the linker chose.
- */
- if (var->location != loc) {
- linker_error(shader_program,
- "Allocation of uniform `%s' to target failed "
- "(%d vs %d)\n",
- var->name, loc, var->location);
- }
+ add.process(var);
}
}
@@ -2830,12 +2832,12 @@ set_uniform_initializer(struct gl_context *ctx, void *mem_ctx,
element_type->matrix_columns,
element_type->vector_elements,
loc, 1, GL_FALSE, (GLfloat *)values);
- loc += element_type->matrix_columns;
} else {
_mesa_uniform(ctx, shader_program, loc, element_type->matrix_columns,
values, element_type->gl_type);
- loc += type_size(element_type);
}
+
+ loc++;
}
}
@@ -3282,6 +3284,15 @@ get_mesa_program(struct gl_context *ctx,
_mesa_optimize_program(ctx, prog);
}
+ /* This has to be done last. Any operation that can cause
+ * prog->ParameterValues to get reallocated (e.g., anything that adds a
+ * program constant) has to happen before creating this linkage.
+ */
+ _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters);
+ if (!shader_program->LinkStatus) {
+ goto fail_exit;
+ }
+
return prog;
fail_exit: