From 7cc61cf706e857e27ea3ce9578b9c480bfbc94a1 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 4 Nov 2016 16:41:30 +1100 Subject: [PATCH] mesa: simplify sampler setting code There is no need to loop over active samplers the code above this would have already exited if the sampler was inactive, or errored if the count was larger than the uniforms array size. Reviewed-by: Eric Anholt --- src/mesa/main/uniform_query.cpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp index 73e7b0bfdfd..ffb20ca2ac1 100644 --- a/src/mesa/main/uniform_query.cpp +++ b/src/mesa/main/uniform_query.cpp @@ -859,39 +859,28 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg, for (int i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_linked_shader *const sh = shProg->_LinkedShaders[i]; - /* If the shader stage doesn't use the sampler uniform, skip this. - */ - if (sh == NULL || !uni->opaque[i].active) + /* If the shader stage doesn't use the sampler uniform, skip this. */ + if (!uni->opaque[i].active) continue; + bool changed = false; for (int j = 0; j < count; j++) { - sh->SamplerUnits[uni->opaque[i].index + offset + j] = - ((unsigned *) values)[j]; + unsigned unit = uni->opaque[i].index + offset + j; + if (sh->SamplerUnits[unit] != ((unsigned *) values)[j]) { + sh->SamplerUnits[unit] = ((unsigned *) values)[j]; + changed = true; + } } - struct gl_program *const prog = sh->Program; - - assert(sizeof(prog->SamplerUnits) == sizeof(sh->SamplerUnits)); - - /* Determine if any of the samplers used by this shader stage have - * been modified. - */ - bool changed = false; - GLbitfield mask = sh->active_samplers; - while (mask) { - const int j = u_bit_scan(&mask); - if (prog->SamplerUnits[j] != sh->SamplerUnits[j]) { - changed = true; - break; - } - } - if (changed) { if (!flushed) { FLUSH_VERTICES(ctx, _NEW_TEXTURE | _NEW_PROGRAM); flushed = true; } + struct gl_program *const prog = sh->Program; + assert(sizeof(prog->SamplerUnits) == sizeof(sh->SamplerUnits)); + _mesa_update_shader_textures_used(shProg, prog); if (ctx->Driver.SamplerUniformChange) ctx->Driver.SamplerUniformChange(ctx, prog->Target, prog); -- 2.30.2