If we map the bo upon creation, we can avoid the latency of mmapping it when querying, and later use the asynchronous, persistent map of the predicate to do a quick query.
v2: Inline the wait on results; it disappears shortly in the next few patches. Signed-off-by: Chris Wilson <ch...@chris-wilson.co.uk> Cc: Kenneth Graunke <kenn...@whitecape.org> Cc: Matt Turner <matts...@gmail.com> --- src/mesa/drivers/dri/i965/brw_context.h | 1 + src/mesa/drivers/dri/i965/gen6_queryobj.c | 42 +++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index d37e05bb47..4d0b76bebb 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -420,6 +420,7 @@ struct brw_query_object { /** Last query BO associated with this query. */ struct brw_bo *bo; + uint64_t *results; /** Last index in bo with query data for this object. */ int last_index; diff --git a/src/mesa/drivers/dri/i965/gen6_queryobj.c b/src/mesa/drivers/dri/i965/gen6_queryobj.c index a0b786f5d9..c96f00d8ba 100644 --- a/src/mesa/drivers/dri/i965/gen6_queryobj.c +++ b/src/mesa/drivers/dri/i965/gen6_queryobj.c @@ -33,6 +33,8 @@ */ #include "main/imports.h" +#include "common/gen_clflush.h" + #include "brw_context.h" #include "brw_defines.h" #include "brw_state.h" @@ -221,7 +223,11 @@ gen6_queryobj_get_results(struct gl_context *ctx, if (query->bo == NULL) return; - uint64_t *results = brw_bo_map(brw, query->bo, MAP_READ); + brw_bo_wait_rendering(query->bo); + uint64_t *results = query->results; + if (!query->bo->cache_coherent) + gen_invalidate_range(results, query->bo->size); + switch (query->Base.Target) { case GL_TIME_ELAPSED: /* The query BO contains the starting and ending timestamps. @@ -296,7 +302,6 @@ gen6_queryobj_get_results(struct gl_context *ctx, default: unreachable("Unrecognized query target in brw_queryobj_get_results()"); } - brw_bo_unmap(query->bo); /* Now that we've processed the data stored in the query's buffer object, * we can release it. @@ -307,6 +312,24 @@ gen6_queryobj_get_results(struct gl_context *ctx, query->Base.Ready = true; } +static int +gen6_alloc_query(struct brw_context *brw, struct brw_query_object *query) +{ + /* Since we're starting a new query, we need to throw away old results. */ + if (query->bo) + brw_bo_unreference(query->bo); + + query->bo = brw_bo_alloc(brw->bufmgr, "query results", 4096, 4096); + query->results = brw_bo_map(brw, query->bo, + MAP_COHERENT | MAP_PERSISTENT | + MAP_READ | MAP_ASYNC); + + /* For ARB_query_buffer_object: The result is not available */ + set_query_availability(brw, query, false); + + return 0; +} + /** * Driver hook for glBeginQuery(). * @@ -318,14 +341,7 @@ gen6_begin_query(struct gl_context *ctx, struct gl_query_object *q) { struct brw_context *brw = brw_context(ctx); struct brw_query_object *query = (struct brw_query_object *)q; - const int idx = GEN6_QUERY_RESULTS; - - /* Since we're starting a new query, we need to throw away old results. */ - brw_bo_unreference(query->bo); - query->bo = brw_bo_alloc(brw->bufmgr, "query results", 4096, 4096); - - /* For ARB_query_buffer_object: The result is not available */ - set_query_availability(brw, query, false); + const int idx = gen6_alloc_query(brw, query) + GEN6_QUERY_RESULTS; switch (query->Base.Target) { case GL_TIME_ELAPSED: @@ -539,8 +555,12 @@ gen6_query_counter(struct gl_context *ctx, struct gl_query_object *q) { struct brw_context *brw = brw_context(ctx); struct brw_query_object *query = (struct brw_query_object *)q; - brw_query_counter(ctx, q); + const int idx = gen6_alloc_query(brw, query) + GEN6_QUERY_RESULTS; + + brw_write_timestamp(brw, query->bo, idx); set_query_availability(brw, query, true); + + query->flushed = false; } /* Initialize Gen6+-specific query object functions. */ -- 2.13.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev