From 16f0d70ffe6d42d22b9e6b927b297e75a199aa78 Mon Sep 17 00:00:00 2001 From: James Benton Date: Mon, 3 Dec 2012 07:00:37 +0000 Subject: llvmpipe: Implement PIPE_QUERY_TIMESTAMP and PIPE_QUERY_TIME_ELAPSED. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This required an update for the query storage in llvmpipe, there can now be an active query per query type, so an occlusion query can run at the same time as a time elapsed query. Based on PIPE_QUERY_TIME_ELAPSED patch from Dave Airlie. v2: fix up piglits for timers (also from Dave Airlie) a) if we don't render anything the result is 0, so just return the current time b) add missing screen get_timestamp callback. Signed-off-by: Dave Airlie Signed-off-by: José Fonseca --- src/gallium/drivers/llvmpipe/lp_query.c | 51 +++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'src/gallium/drivers/llvmpipe/lp_query.c') diff --git a/src/gallium/drivers/llvmpipe/lp_query.c b/src/gallium/drivers/llvmpipe/lp_query.c index 20c0a1e..e302197 100644 --- a/src/gallium/drivers/llvmpipe/lp_query.c +++ b/src/gallium/drivers/llvmpipe/lp_query.c @@ -33,6 +33,7 @@ #include "draw/draw_context.h" #include "pipe/p_defines.h" #include "util/u_memory.h" +#include "os/os_time.h" #include "lp_context.h" #include "lp_flush.h" #include "lp_fence.h" @@ -51,10 +52,14 @@ llvmpipe_create_query(struct pipe_context *pipe, { struct llvmpipe_query *pq; - assert(type == PIPE_QUERY_OCCLUSION_COUNTER); + assert(type < PIPE_QUERY_TYPES); pq = CALLOC_STRUCT( llvmpipe_query ); + if (pq) { + pq->type = type; + } + return (struct pipe_query *) pq; } @@ -100,7 +105,7 @@ llvmpipe_get_query_result(struct pipe_context *pipe, if (!lp_fence_signalled(pq->fence)) { if (!lp_fence_issued(pq->fence)) llvmpipe_flush(pipe, NULL, __FUNCTION__); - + if (!wait) return FALSE; @@ -110,8 +115,32 @@ llvmpipe_get_query_result(struct pipe_context *pipe, /* Sum the results from each of the threads: */ *result = 0; - for (i = 0; i < LP_MAX_THREADS; i++) { - *result += pq->count[i]; + + switch (pq->type) { + case PIPE_QUERY_OCCLUSION_COUNTER: + for (i = 0; i < LP_MAX_THREADS; i++) { + *result += pq->count[i]; + } + break; + case PIPE_QUERY_TIME_ELAPSED: + for (i = 0; i < LP_MAX_THREADS; i++) { + if (pq->count[i] > *result) { + *result = pq->count[i]; + } + } + break; + case PIPE_QUERY_TIMESTAMP: + for (i = 0; i < LP_MAX_THREADS; i++) { + if (pq->count[i] > *result) { + *result = pq->count[i]; + } + if (*result == 0) + *result = os_time_get_nano(); + } + break; + default: + assert(0); + break; } return TRUE; @@ -136,8 +165,10 @@ llvmpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q) memset(pq->count, 0, sizeof(pq->count)); lp_setup_begin_query(llvmpipe->setup, pq); - llvmpipe->active_query_count++; - llvmpipe->dirty |= LP_NEW_QUERY; + if (pq->type == PIPE_QUERY_OCCLUSION_COUNTER) { + llvmpipe->active_occlusion_query = TRUE; + llvmpipe->dirty |= LP_NEW_OCCLUSION_QUERY; + } } @@ -149,9 +180,11 @@ llvmpipe_end_query(struct pipe_context *pipe, struct pipe_query *q) lp_setup_end_query(llvmpipe->setup, pq); - assert(llvmpipe->active_query_count); - llvmpipe->active_query_count--; - llvmpipe->dirty |= LP_NEW_QUERY; + if (pq->type == PIPE_QUERY_OCCLUSION_COUNTER) { + assert(llvmpipe->active_occlusion_query); + llvmpipe->active_occlusion_query = FALSE; + llvmpipe->dirty |= LP_NEW_OCCLUSION_QUERY; + } } boolean -- cgit v1.1