[Mesa-dev] [PATCH 3/3] svga: add new memory-used HUD query

Brian Paul brian.e.paul at gmail.com
Wed Apr 3 09:26:32 PDT 2013


From: Brian Paul <brianp at vmware.com>

To track the amount of memory used by all pipe_resources (textures
and buffers).
---
 src/gallium/drivers/svga/svga_context.h          |    1 +
 src/gallium/drivers/svga/svga_pipe_query.c       |   11 +++++++++++
 src/gallium/drivers/svga/svga_resource_buffer.c  |    6 ++++++
 src/gallium/drivers/svga/svga_resource_buffer.h  |    2 ++
 src/gallium/drivers/svga/svga_resource_texture.c |    6 ++++++
 src/gallium/drivers/svga/svga_resource_texture.h |    2 ++
 src/gallium/drivers/svga/svga_screen.c           |    3 ++-
 src/gallium/drivers/svga/svga_screen.h           |    3 +++
 8 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index e27778e..517102d 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -45,6 +45,7 @@
 /** Non-GPU queries for gallium HUD */
 #define SVGA_QUERY_DRAW_CALLS   (PIPE_QUERY_DRIVER_SPECIFIC + 0)
 #define SVGA_QUERY_FALLBACKS    (PIPE_QUERY_DRIVER_SPECIFIC + 1)
+#define SVGA_QUERY_MEMORY_USED  (PIPE_QUERY_DRIVER_SPECIFIC + 2)
 
 
 struct draw_vertex_shader;
diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c
index 11f6a05..de84189 100644
--- a/src/gallium/drivers/svga/svga_pipe_query.c
+++ b/src/gallium/drivers/svga/svga_pipe_query.c
@@ -111,6 +111,7 @@ static struct pipe_query *svga_create_query( struct pipe_context *pipe,
       break;
    case SVGA_QUERY_DRAW_CALLS:
    case SVGA_QUERY_FALLBACKS:
+   case SVGA_QUERY_MEMORY_USED:
       break;
    default:
       assert(!"unexpected query type in svga_create_query()");
@@ -144,6 +145,7 @@ static void svga_destroy_query(struct pipe_context *pipe,
       break;
    case SVGA_QUERY_DRAW_CALLS:
    case SVGA_QUERY_FALLBACKS:
+   case SVGA_QUERY_MEMORY_USED:
       /* nothing */
       break;
    default:
@@ -203,6 +205,9 @@ static void svga_begin_query(struct pipe_context *pipe,
    case SVGA_QUERY_FALLBACKS:
       sq->begin_count = svga->num_fallbacks;
       break;
+   case SVGA_QUERY_MEMORY_USED:
+      /* nothing */
+      break;
    default:
       assert(!"unexpected query type in svga_begin_query()");
    }
@@ -246,6 +251,9 @@ static void svga_end_query(struct pipe_context *pipe,
    case SVGA_QUERY_FALLBACKS:
       sq->end_count = svga->num_fallbacks;
       break;
+   case SVGA_QUERY_MEMORY_USED:
+      /* nothing */
+      break;
    default:
       assert(!"unexpected query type in svga_end_query()");
    }
@@ -304,6 +312,9 @@ static boolean svga_get_query_result(struct pipe_context *pipe,
    case SVGA_QUERY_FALLBACKS:
       vresult->u64 = sq->end_count - sq->begin_count;
       break;
+   case SVGA_QUERY_MEMORY_USED:
+      vresult->u64 = svgascreen->total_resource_bytes;
+      break;
    default:
       assert(!"unexpected query type in svga_get_query_result");
    }
diff --git a/src/gallium/drivers/svga/svga_resource_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer.c
index 3aa6644..8ba2252 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.c
+++ b/src/gallium/drivers/svga/svga_resource_buffer.c
@@ -31,6 +31,7 @@
 #include "os/os_thread.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "util/u_resource.h"
 
 #include "svga_context.h"
 #include "svga_screen.h"
@@ -297,6 +298,8 @@ svga_buffer_destroy( struct pipe_screen *screen,
    if(sbuf->swbuf && !sbuf->user)
       align_free(sbuf->swbuf);
    
+   ss->total_resource_bytes -= sbuf->size;
+
    FREE(sbuf);
 }
 
@@ -342,6 +345,9 @@ svga_buffer_create(struct pipe_screen *screen,
    debug_reference(&sbuf->b.b.reference,
                    (debug_reference_descriptor)debug_describe_resource, 0);
 
+   sbuf->size = util_resource_size(template);
+   ss->total_resource_bytes += sbuf->size;
+
    return &sbuf->b.b; 
 
 error2:
diff --git a/src/gallium/drivers/svga/svga_resource_buffer.h b/src/gallium/drivers/svga/svga_resource_buffer.h
index ee12acf..b431d7b 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.h
+++ b/src/gallium/drivers/svga/svga_resource_buffer.h
@@ -177,6 +177,8 @@ struct svga_buffer
     * a context. It is only valid if the dma.pending is set above.
     */
    struct list_head head;
+
+   unsigned size;  /**< Approximate size in bytes */
 };
 
 
diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
index 7f36da8..3cb7d34 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.c
+++ b/src/gallium/drivers/svga/svga_resource_texture.c
@@ -32,6 +32,7 @@
 #include "util/u_format.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "util/u_resource.h"
 
 #include "svga_format.h"
 #include "svga_screen.h"
@@ -229,6 +230,8 @@ svga_texture_destroy(struct pipe_screen *screen,
    SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle);
    svga_screen_surface_destroy(ss, &tex->key, &tex->handle);
 
+   ss->total_resource_bytes -= tex->size;
+
    FREE(tex);
 }
 
@@ -470,6 +473,9 @@ svga_texture_create(struct pipe_screen *screen,
    debug_reference(&tex->b.b.reference,
                    (debug_reference_descriptor)debug_describe_resource, 0);
 
+   tex->size = util_resource_size(template);
+   svgascreen->total_resource_bytes += tex->size;
+
    return &tex->b.b;
 
 error2:
diff --git a/src/gallium/drivers/svga/svga_resource_texture.h b/src/gallium/drivers/svga/svga_resource_texture.h
index 57ed0f5..b3a1a6d 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.h
+++ b/src/gallium/drivers/svga/svga_resource_texture.h
@@ -75,6 +75,8 @@ struct svga_texture
     * to this texture and never destroy this handle directly.
     */
    struct svga_winsys_surface *handle;
+
+   unsigned size;  /**< Approximate size in bytes */
 };
 
 
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index bd1b03f..6213535 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -499,7 +499,8 @@ svga_get_driver_query_info(struct pipe_screen *screen,
 {
    static const struct pipe_driver_query_info queries[] = {
       {"draw-calls", SVGA_QUERY_DRAW_CALLS, 0, FALSE},
-      {"fallbacks", SVGA_QUERY_FALLBACKS, 0, FALSE}
+      {"fallbacks", SVGA_QUERY_FALLBACKS, 0, FALSE},
+      {"memory-used", SVGA_QUERY_MEMORY_USED, 0, TRUE}
    };
 
    if (!info)
diff --git a/src/gallium/drivers/svga/svga_screen.h b/src/gallium/drivers/svga/svga_screen.h
index d7d2c75..77b552a 100644
--- a/src/gallium/drivers/svga/svga_screen.h
+++ b/src/gallium/drivers/svga/svga_screen.h
@@ -73,6 +73,9 @@ struct svga_screen
    } depth;
 
    struct svga_host_surface_cache cache;
+
+   /** Memory used by all resources (buffers and surfaces) */
+   uint64_t total_resource_bytes;
 };
 
 #ifndef DEBUG
-- 
1.7.9.5



More information about the mesa-dev mailing list