diff options
Diffstat (limited to 'src/mesa/program/ir_to_mesa.cpp')
-rw-r--r-- | src/mesa/program/ir_to_mesa.cpp | 47 |
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: |