Mesa (master): st/mesa: exit the update fragment samplers/ textures loops early.

Dave Airlie airlied at kemper.freedesktop.org
Thu Feb 9 19:39:48 UTC 2012


Module: Mesa
Branch: master
Commit: 23c52caafba52c77092b9721bd4601f8ea592625
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=23c52caafba52c77092b9721bd4601f8ea592625

Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Feb  8 13:58:14 2012 +0000

st/mesa: exit the update fragment samplers/textures loops early.

If we have no more enabled samplers and we've reset all the previously
used ones, no need to keep going around this loop.

(just moved some stuff around to clean it up a bit).

Signed-off-by: Dave Airlie <airlied at redhat.com>
Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/state_tracker/st_atom_sampler.c |   16 ++++++++++------
 src/mesa/state_tracker/st_atom_texture.c |   19 +++++++++++++------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index 8845fed..ee69fc3 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -233,29 +233,33 @@ update_fragment_samplers(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
    struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
    GLuint su;
+   GLuint samplers_used = fprog->Base.SamplersUsed;
+   GLuint old_max = st->state.num_samplers;
 
    st->state.num_samplers = 0;
 
    /* loop over sampler units (aka tex image units) */
-   for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) {
+   for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++, samplers_used >>= 1) {
       struct pipe_sampler_state *sampler = st->state.samplers + su;
 
-
-      if (fprog->Base.SamplersUsed & (1 << su)) {
+      if (samplers_used & 1) {
          GLuint texUnit;
 
-	 texUnit = fprog->Base.SamplerUnits[su];
+         texUnit = fprog->Base.SamplerUnits[su];
 
-	 convert_sampler(st, sampler, texUnit);
+         convert_sampler(st, sampler, texUnit);
 
          st->state.num_samplers = su + 1;
 
          /*printf("%s su=%u non-null\n", __FUNCTION__, su);*/
          cso_single_sampler(st->cso_context, su, sampler);
       }
-      else {
+      else if (samplers_used != 0 || su < old_max) {
          /*printf("%s su=%u null\n", __FUNCTION__, su);*/
          cso_single_sampler(st->cso_context, su, NULL);
+      } else {
+         /* if we've reset all the old views and we have no more new ones */
+         break;
       }
    }
 
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index d241527..e8941da 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -300,24 +300,31 @@ update_fragment_textures(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
    struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
    GLuint su;
+   int old_max = st->state.num_textures;
+   GLbitfield samplers_used = fprog->Base.SamplersUsed;
 
    st->state.num_textures = 0;
 
    /* loop over sampler units (aka tex image units) */
-   for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) {
+   for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++, samplers_used >>= 1) {
       struct pipe_sampler_view *sampler_view = NULL;
-      if (fprog->Base.SamplersUsed & (1 << su)) {
+
+      if (samplers_used & 1) {
          GLboolean retval;
          GLuint texUnit;
 
-	 texUnit = fprog->Base.SamplerUnits[su];
+         texUnit = fprog->Base.SamplerUnits[su];
 
-	 retval = update_single_texture(st, &sampler_view, texUnit);
-	 if (retval == GL_FALSE)
-	    continue;
+         retval = update_single_texture(st, &sampler_view, texUnit);
+         if (retval == GL_FALSE)
+            continue;
 
          st->state.num_textures = su + 1;
+      } else if (samplers_used == 0 && su >= old_max) {
+         /* if we've reset all the old views and we have no more new ones */
+         break;
       }
+
       pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view);
    }
 




More information about the mesa-commit mailing list