From be7d8ddf0c0a293ee94db360a44561beb10e62f9 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 7 Jun 2010 12:14:56 -0400 Subject: [PATCH] gallium: add basic support for stream output queries --- src/gallium/drivers/softpipe/sp_context.h | 1 + src/gallium/drivers/softpipe/sp_prim_vbuf.c | 5 +++++ src/gallium/drivers/softpipe/sp_query.c | 24 +++++++++++++++++++-- src/gallium/include/pipe/p_defines.h | 11 +++++++++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index 79165fba32c..e641a81d1fb 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -86,6 +86,7 @@ struct softpipe_context { int so_count[PIPE_MAX_SO_BUFFERS]; int num_buffers; } so_target; + struct pipe_query_data_so_statistics so_stats; unsigned num_samplers; unsigned num_sampler_views; diff --git a/src/gallium/drivers/softpipe/sp_prim_vbuf.c b/src/gallium/drivers/softpipe/sp_prim_vbuf.c index 06691e83953..ddfe56f73a4 100644 --- a/src/gallium/drivers/softpipe/sp_prim_vbuf.c +++ b/src/gallium/drivers/softpipe/sp_prim_vbuf.c @@ -549,6 +549,11 @@ sp_vbuf_so_info(struct vbuf_render *vbr, uint buffer, uint vertices) struct softpipe_context *softpipe = cvbr->softpipe; softpipe->so_target.so_count[buffer] += vertices; + + softpipe->so_stats.num_primitives_written = + vertices / u_vertices_per_prim(cvbr->prim); + softpipe->so_stats.primitives_storage_needed = + vertices * 4 /*sizeof(float|int32)*/ * 4 /*x,y,z,w*/; } diff --git a/src/gallium/drivers/softpipe/sp_query.c b/src/gallium/drivers/softpipe/sp_query.c index ae52c22b3ee..43ff5c56afe 100644 --- a/src/gallium/drivers/softpipe/sp_query.c +++ b/src/gallium/drivers/softpipe/sp_query.c @@ -41,6 +41,7 @@ struct softpipe_query { unsigned type; uint64_t start; uint64_t end; + struct pipe_query_data_so_statistics so; }; @@ -55,7 +56,9 @@ softpipe_create_query(struct pipe_context *pipe, { struct softpipe_query* sq; - assert(type == PIPE_QUERY_OCCLUSION_COUNTER || type == PIPE_QUERY_TIME_ELAPSED); + assert(type == PIPE_QUERY_OCCLUSION_COUNTER || + type == PIPE_QUERY_TIME_ELAPSED || + type == PIPE_QUERY_SO_STATISTICS); sq = CALLOC_STRUCT( softpipe_query ); sq->type = type; @@ -83,6 +86,9 @@ softpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q) case PIPE_QUERY_TIME_ELAPSED: sq->start = 1000*os_time_get(); break; + case PIPE_QUERY_SO_STATISTICS: + sq->so.num_primitives_written = 0; + sq->so.primitives_storage_needed = 0; default: assert(0); break; @@ -106,6 +112,11 @@ softpipe_end_query(struct pipe_context *pipe, struct pipe_query *q) case PIPE_QUERY_TIME_ELAPSED: sq->end = 1000*os_time_get(); break; + case PIPE_QUERY_SO_STATISTICS: + sq->so.num_primitives_written = + softpipe->so_stats.num_primitives_written; + sq->so.primitives_storage_needed = + softpipe->so_stats.primitives_storage_needed; default: assert(0); break; @@ -122,7 +133,16 @@ softpipe_get_query_result(struct pipe_context *pipe, { struct softpipe_query *sq = softpipe_query(q); uint64_t *result = (uint64_t*)vresult; - *result = sq->end - sq->start; + + switch (sq->type) { + case PIPE_QUERY_SO_STATISTICS: + memcpy(vresult, &sq->so, + sizeof(struct pipe_query_data_so_statistics)); + break; + default: + *result = sq->end - sq->start; + break; + } return TRUE; } diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index f47db407dc1..85551cac25a 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -381,7 +381,8 @@ enum pipe_transfer_usage { #define PIPE_QUERY_PRIMITIVES_GENERATED 1 #define PIPE_QUERY_PRIMITIVES_EMITTED 2 #define PIPE_QUERY_TIME_ELAPSED 3 -#define PIPE_QUERY_TYPES 4 +#define PIPE_QUERY_SO_STATISTICS 5 +#define PIPE_QUERY_TYPES 6 /** @@ -498,6 +499,14 @@ enum pipe_cap { #define PIPE_REFERENCED_FOR_READ (1 << 0) #define PIPE_REFERENCED_FOR_WRITE (1 << 1) +/** + * Composite query types + */ +struct pipe_query_data_so_statistics +{ + uint64_t num_primitives_written; + uint64_t primitives_storage_needed; +}; #ifdef __cplusplus } -- 2.30.2