[Mesa-dev] [PATCH 1/4] mesa: Track maximum CurrentTexUnit to reduce glDeleteTextures() overhead.

Eric Anholt eric at anholt.net
Fri Apr 25 18:19:03 PDT 2014


No more walking 96*6 pointers looking to see if they're the current
texture, when we only use the first 2 out of 96 units.  -6.26002% +/-
1.87817% effect on cairo runtime on no-fbo-cache glamor (n=36).
---
 src/mesa/main/mtypes.h   | 3 +++
 src/mesa/main/texobj.c   | 4 +++-
 src/mesa/main/texstate.c | 6 ++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 4c619ba..4541c75 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1400,6 +1400,9 @@ struct gl_texture_attrib
 
    /** Largest index of a texture unit with _Current != NULL. */
    GLint _MaxEnabledTexImageUnit;
+
+   /** Largest index + 1 of texture units that have had any CurrentTex set. */
+   GLint NumCurrentTexUsed;
 };
 
 
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 918dd59..85246c8 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1094,7 +1094,7 @@ unbind_texobj_from_texunits(struct gl_context *ctx,
 {
    GLuint u, tex;
 
-   for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
+   for (u = 0; u < ctx->Texture.NumCurrentTexUsed; u++) {
       struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
       for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
          if (texObj == unit->CurrentTex[tex]) {
@@ -1353,6 +1353,8 @@ _mesa_BindTexture( GLenum target, GLuint texName )
     * count hits zero.
     */
    _mesa_reference_texobj(&texUnit->CurrentTex[targetIndex], newTexObj);
+   ctx->Texture.NumCurrentTexUsed = MAX2(ctx->Texture.NumCurrentTexUsed,
+                                         ctx->Texture.CurrentUnit + 1);
    ASSERT(texUnit->CurrentTex[targetIndex]);
 
    /* Pass BindTexture call to device driver */
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 3a7e227..000af94 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -108,6 +108,10 @@ _mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
          for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
             _mesa_reference_texobj(&dst->Texture.Unit[u].CurrentTex[tex],
                                    src->Texture.Unit[u].CurrentTex[tex]);
+            if (src->Texture.Unit[u].CurrentTex[tex]) {
+               dst->Texture.NumCurrentTexUsed =
+                  MAX2(dst->Texture.NumCurrentTexUsed, u + 1);
+            }
          }
          _mesa_unlock_context_textures(dst);
       }
@@ -912,6 +916,8 @@ _mesa_init_texture(struct gl_context *ctx)
    _mesa_reference_buffer_object(ctx, &ctx->Texture.BufferObject,
                                  ctx->Shared->NullBufferObj);
 
+   ctx->Texture.NumCurrentTexUsed = 0;
+
    return GL_TRUE;
 }
 
-- 
1.9.2



More information about the mesa-dev mailing list