svga: add new memory-used HUD query

To track the amount of memory used by all pipe_resources (textures
and buffers).

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
This commit is contained in:
Brian Paul 2013-04-03 10:23:57 -06:00
parent a69efa9482
commit ac114c6824
8 changed files with 33 additions and 1 deletions

View File

@ -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;

View File

@ -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");
}

View File

@ -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:

View File

@ -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 */
};

View File

@ -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:

View File

@ -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 */
};

View File

@ -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)

View File

@ -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