Mesa (master): mesa: add _mesa_total_texture_memory() debug function

Brian Paul brianp at kemper.freedesktop.org
Wed Apr 11 18:05:26 UTC 2012


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

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Apr  6 15:45:39 2012 -0600

mesa: add _mesa_total_texture_memory() debug function

This function can be called in gdb to find out how much memory is used
by all texture objects.

---

 src/mesa/main/texobj.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/texobj.h |    3 ++
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 4c3eed2..155b255 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -841,6 +841,65 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
 }
 
 
+/**
+ * Compute the size of the given texture object, in bytes.
+ */
+static GLuint
+texture_size(const struct gl_texture_object *texObj)
+{
+   const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   GLuint face, level, size = 0;
+
+   for (face = 0; face < numFaces; face++) {
+      for (level = 0; level < MAX_TEXTURE_LEVELS; level++) {
+         const struct gl_texture_image *img = texObj->Image[face][level];
+         if (img) {
+            GLuint sz = _mesa_format_image_size(img->TexFormat, img->Width,
+                                                img->Height, img->Depth);
+            size += sz;
+         }
+      }
+   }
+
+   return size;
+}
+
+
+/**
+ * Callback called from _mesa_HashWalk()
+ */
+static void
+count_tex_size(GLuint key, void *data, void *userData)
+{
+   const struct gl_texture_object *texObj =
+      (const struct gl_texture_object *) data;
+   GLuint *total = (GLuint *) userData;
+
+   *total = *total + texture_size(texObj);
+}
+
+
+/**
+ * Compute total size (in bytes) of all textures for the given context.
+ * For debugging purposes.
+ */
+GLuint
+_mesa_total_texture_memory(struct gl_context *ctx)
+{
+   GLuint tgt, total = 0;
+
+   _mesa_HashWalk(ctx->Shared->TexObjects, count_tex_size, &total);
+
+   /* plus, the default texture objects */
+   for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+      total += texture_size(ctx->Shared->DefaultTex[tgt]);
+   }
+
+   return total;
+}
+
+
+
 /*@}*/
 
 
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index c020b90..23e1ade 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -112,6 +112,9 @@ _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj,
 extern struct gl_texture_object *
 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex);
 
+extern GLuint
+_mesa_total_texture_memory(struct gl_context *ctx);
+
 extern void
 _mesa_unlock_context_textures( struct gl_context *ctx );
 




More information about the mesa-commit mailing list