diff options
Diffstat (limited to 'mesalib/src/glsl/link_uniforms.cpp')
-rw-r--r-- | mesalib/src/glsl/link_uniforms.cpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp index 087651bd0..0b8a02d4e 100644 --- a/mesalib/src/glsl/link_uniforms.cpp +++ b/mesalib/src/glsl/link_uniforms.cpp @@ -209,7 +209,13 @@ public: union gl_constant_value *values) : map(map), uniforms(uniforms), next_sampler(0), values(values) { - /* empty */ + memset(this->targets, 0, sizeof(this->targets)); + } + + void start_shader() + { + this->shader_samplers_used = 0; + this->shader_shadow_samplers = 0; } private: @@ -230,8 +236,25 @@ private: * example, we may be processing the uniform in the fragment shader, but * the uniform was already processed in the vertex shader. */ - if (this->uniforms[id].storage != NULL) + if (this->uniforms[id].storage != NULL) { + /* If the uniform already has storage set from another shader stage, + * mark the samplers used for this shader stage. + */ + if (type->contains_sampler()) { + const unsigned count = MAX2(1, this->uniforms[id].array_elements); + const unsigned shadow = (type->is_array()) + ? type->fields.array->sampler_shadow : type->sampler_shadow; + + for (unsigned i = 0; i < count; i++) { + const unsigned s = this->uniforms[id].sampler + i; + + this->shader_samplers_used |= 1U << s; + this->shader_shadow_samplers |= shadow << s; + } + } + return; + } const glsl_type *base_type; if (type->is_array()) { @@ -249,6 +272,17 @@ private: * array elements for arrays. */ this->next_sampler += MAX2(1, this->uniforms[id].array_elements); + + const gl_texture_index target = base_type->sampler_index(); + const unsigned shadow = base_type->sampler_shadow; + for (unsigned i = this->uniforms[id].sampler + ; i < this->next_sampler + ; i++) { + this->targets[i] = target; + this->shader_samplers_used |= 1U << i; + this->shader_shadow_samplers |= shadow << i; + } + } else { this->uniforms[id].sampler = ~0; } @@ -270,6 +304,18 @@ private: public: union gl_constant_value *values; + + gl_texture_index targets[MAX_SAMPLERS]; + + /** + * Mask of samplers used by the current shader stage. + */ + unsigned shader_samplers_used; + + /** + * Mask of samplers used by the current shader stage for shadows. + */ + unsigned shader_shadow_samplers; }; void @@ -346,6 +392,10 @@ link_assign_uniform_locations(struct gl_shader_program *prog) if (prog->_LinkedShaders[i] == NULL) continue; + /* Reset various per-shader target counts. + */ + parcel.start_shader(); + foreach_list(node, prog->_LinkedShaders[i]->ir) { ir_variable *const var = ((ir_instruction *) node)->as_variable(); @@ -359,8 +409,14 @@ link_assign_uniform_locations(struct gl_shader_program *prog) parcel.process(var); } + + prog->_LinkedShaders[i]->active_samplers = parcel.shader_samplers_used; + prog->_LinkedShaders[i]->shadow_samplers = parcel.shader_shadow_samplers; } + assert(sizeof(prog->SamplerTargets) == sizeof(parcel.targets)); + memcpy(prog->SamplerTargets, parcel.targets, sizeof(prog->SamplerTargets)); + #ifndef NDEBUG for (unsigned i = 0; i < num_user_uniforms; i++) { assert(uniforms[i].storage != NULL); |