[Mesa-dev] [PATCH 20/53] mesa: simplify sampler setting code

Timothy Arceri timothy.arceri at collabora.com
Tue Jan 3 02:43:24 UTC 2017


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 <eric at anholt.net>
---
 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 73e7b0b..ffb20ca 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.9.3



More information about the mesa-dev mailing list