Mesa (master): freedreno: make hw-query a helper

Rob Clark robclark at kemper.freedesktop.org
Sat Apr 22 14:11:27 UTC 2017


Module: Mesa
Branch: master
Commit: df63ff4d8248d81ecb8d0f3059bf2c67431e6f2f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=df63ff4d8248d81ecb8d0f3059bf2c67431e6f2f

Author: Rob Clark <robdclark at gmail.com>
Date:   Fri Apr 21 09:50:30 2017 -0400

freedreno: make hw-query a helper

For a5xx (and actually some queries on a4xx) we can accumulate results
in the cmdstream, so we don't need this elaborate mechanism of tracking
per-tile query results.  So make it into vfuncs so generation specific
backend can use it when it makes sense.

Signed-off-by: Rob Clark <robdclark at gmail.com>

---

 src/gallium/drivers/freedreno/a3xx/fd3_context.c   |  5 +++++
 src/gallium/drivers/freedreno/a3xx/fd3_query.c     |  7 +++++++
 src/gallium/drivers/freedreno/a4xx/fd4_context.c   |  5 +++++
 src/gallium/drivers/freedreno/a4xx/fd4_query.c     |  7 +++++++
 src/gallium/drivers/freedreno/a5xx/fd5_emit.c      |  2 --
 src/gallium/drivers/freedreno/freedreno_batch.c    |  2 +-
 src/gallium/drivers/freedreno/freedreno_context.c  |  2 --
 src/gallium/drivers/freedreno/freedreno_context.h  | 17 +++++++++++++++++
 src/gallium/drivers/freedreno/freedreno_draw.c     |  4 ++--
 src/gallium/drivers/freedreno/freedreno_gmem.c     | 12 ++++++++----
 src/gallium/drivers/freedreno/freedreno_query.c    |  4 ++--
 src/gallium/drivers/freedreno/freedreno_resource.c |  4 ++--
 src/gallium/drivers/freedreno/freedreno_state.c    |  2 +-
 13 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_context.c b/src/gallium/drivers/freedreno/a3xx/fd3_context.c
index dac59418df..b432f593e0 100644
--- a/src/gallium/drivers/freedreno/a3xx/fd3_context.c
+++ b/src/gallium/drivers/freedreno/a3xx/fd3_context.c
@@ -26,6 +26,7 @@
  *    Rob Clark <robclark at freedesktop.org>
  */
 
+#include "freedreno_query_hw.h"
 
 #include "fd3_context.h"
 #include "fd3_blend.h"
@@ -51,6 +52,8 @@ fd3_context_destroy(struct pipe_context *pctx)
 
 	u_upload_destroy(fd3_ctx->border_color_uploader);
 
+	fd_hw_query_fini(pctx);
+
 	fd_context_destroy(pctx);
 }
 
@@ -95,6 +98,8 @@ fd3_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
 	if (!pctx)
 		return NULL;
 
+	fd_hw_query_init(pctx);
+
 	fd3_ctx->vs_pvt_mem = fd_bo_new(screen->dev, 0x2000,
 			DRM_FREEDRENO_GEM_TYPE_KMEM);
 
diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_query.c b/src/gallium/drivers/freedreno/a3xx/fd3_query.c
index cce165c041..cde42c3731 100644
--- a/src/gallium/drivers/freedreno/a3xx/fd3_query.c
+++ b/src/gallium/drivers/freedreno/a3xx/fd3_query.c
@@ -133,6 +133,13 @@ static const struct fd_hw_sample_provider occlusion_predicate = {
 
 void fd3_query_context_init(struct pipe_context *pctx)
 {
+	struct fd_context *ctx = fd_context(pctx);
+
+	ctx->create_query = fd_hw_create_query;
+	ctx->query_prepare = fd_hw_query_prepare;
+	ctx->query_prepare_tile = fd_hw_query_prepare_tile;
+	ctx->query_set_stage = fd_hw_query_set_stage;
+
 	fd_hw_query_register_provider(pctx, &occlusion_counter);
 	fd_hw_query_register_provider(pctx, &occlusion_predicate);
 }
diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_context.c b/src/gallium/drivers/freedreno/a4xx/fd4_context.c
index 291df2d03f..db292af8be 100644
--- a/src/gallium/drivers/freedreno/a4xx/fd4_context.c
+++ b/src/gallium/drivers/freedreno/a4xx/fd4_context.c
@@ -26,6 +26,7 @@
  *    Rob Clark <robclark at freedesktop.org>
  */
 
+#include "freedreno_query_hw.h"
 
 #include "fd4_context.h"
 #include "fd4_blend.h"
@@ -51,6 +52,8 @@ fd4_context_destroy(struct pipe_context *pctx)
 
 	u_upload_destroy(fd4_ctx->border_color_uploader);
 
+	fd_hw_query_fini(pctx);
+
 	fd_context_destroy(pctx);
 }
 
@@ -95,6 +98,8 @@ fd4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
 	if (!pctx)
 		return NULL;
 
+	fd_hw_query_init(pctx);
+
 	fd4_ctx->vs_pvt_mem = fd_bo_new(screen->dev, 0x2000,
 			DRM_FREEDRENO_GEM_TYPE_KMEM);
 
diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_query.c b/src/gallium/drivers/freedreno/a4xx/fd4_query.c
index 3ae3971dc5..f7b385d552 100644
--- a/src/gallium/drivers/freedreno/a4xx/fd4_query.c
+++ b/src/gallium/drivers/freedreno/a4xx/fd4_query.c
@@ -275,6 +275,13 @@ static const struct fd_hw_sample_provider timestamp = {
 
 void fd4_query_context_init(struct pipe_context *pctx)
 {
+	struct fd_context *ctx = fd_context(pctx);
+
+	ctx->create_query = fd_hw_create_query;
+	ctx->query_prepare = fd_hw_query_prepare;
+	ctx->query_prepare_tile = fd_hw_query_prepare_tile;
+	ctx->query_set_stage = fd_hw_query_set_stage;
+
 	fd_hw_query_register_provider(pctx, &occlusion_counter);
 	fd_hw_query_register_provider(pctx, &occlusion_predicate);
 	fd_hw_query_register_provider(pctx, &time_elapsed);
diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_emit.c b/src/gallium/drivers/freedreno/a5xx/fd5_emit.c
index f2c9a6b85d..5b25257167 100644
--- a/src/gallium/drivers/freedreno/a5xx/fd5_emit.c
+++ b/src/gallium/drivers/freedreno/a5xx/fd5_emit.c
@@ -909,8 +909,6 @@ t7              opcode: CP_WAIT_FOR_IDLE (26) (1 dwords)
 	// TODO hacks.. these should not be hardcoded:
 	OUT_PKT4(ring, REG_A5XX_GRAS_SC_CNTL, 1);
 	OUT_RING(ring, 0x00000008);   /* GRAS_SC_CNTL */
-
-	fd_hw_query_enable(batch, ring);
 }
 
 static void
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.c b/src/gallium/drivers/freedreno/freedreno_batch.c
index f97282b340..17078d425e 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.c
+++ b/src/gallium/drivers/freedreno/freedreno_batch.c
@@ -262,7 +262,7 @@ batch_flush(struct fd_batch *batch)
 	/* close out the draw cmds by making sure any active queries are
 	 * paused:
 	 */
-	fd_hw_query_set_stage(batch, batch->draw, FD_STAGE_NULL);
+	fd_batch_set_stage(batch, batch->draw, FD_STAGE_NULL);
 
 	fd_context_all_dirty(batch->ctx);
 	batch_flush_reset_dependencies(batch, true);
diff --git a/src/gallium/drivers/freedreno/freedreno_context.c b/src/gallium/drivers/freedreno/freedreno_context.c
index 6478e0e7a9..c8d2138cfe 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.c
+++ b/src/gallium/drivers/freedreno/freedreno_context.c
@@ -121,7 +121,6 @@ fd_context_destroy(struct pipe_context *pctx)
 	fd_fence_ref(pctx->screen, &ctx->last_fence, NULL);
 
 	fd_prog_fini(pctx);
-	fd_hw_query_fini(pctx);
 
 	if (ctx->blitter)
 		util_blitter_destroy(ctx->blitter);
@@ -293,7 +292,6 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen,
 	fd_query_context_init(pctx);
 	fd_texture_init(pctx);
 	fd_state_init(pctx);
-	fd_hw_query_init(pctx);
 
 	ctx->blitter = util_blitter_create(pctx);
 	if (!ctx->blitter)
diff --git a/src/gallium/drivers/freedreno/freedreno_context.h b/src/gallium/drivers/freedreno/freedreno_context.h
index 733c64b180..fe685e1767 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.h
+++ b/src/gallium/drivers/freedreno/freedreno_context.h
@@ -291,6 +291,14 @@ struct fd_context {
 	/* indirect-branch emit: */
 	void (*emit_ib)(struct fd_ringbuffer *ring, struct fd_ringbuffer *target);
 
+	/* query: */
+	struct fd_query * (*create_query)(struct fd_context *ctx, unsigned query_type);
+	void (*query_prepare)(struct fd_batch *batch, uint32_t num_tiles);
+	void (*query_prepare_tile)(struct fd_batch *batch, uint32_t n,
+			struct fd_ringbuffer *ring);
+	void (*query_set_stage)(struct fd_batch *batch,
+			struct fd_ringbuffer *ring, enum fd_render_stage stage);
+
 	/*
 	 * Common pre-cooked VBO state (used for a3xx and later):
 	 */
@@ -368,6 +376,15 @@ fd_supported_prim(struct fd_context *ctx, unsigned prim)
 	return (1 << prim) & ctx->primtype_mask;
 }
 
+static inline void
+fd_batch_set_stage(struct fd_batch *batch,
+		struct fd_ringbuffer *ring, enum fd_render_stage stage)
+{
+	struct fd_context *ctx = batch->ctx;
+	if (ctx->query_set_stage)
+		ctx->query_set_stage(batch, ring, stage);
+}
+
 void fd_context_setup_common_vbos(struct fd_context *ctx);
 void fd_context_cleanup_common_vbos(struct fd_context *ctx);
 
diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c
index 6243984dc8..dc9effbb7b 100644
--- a/src/gallium/drivers/freedreno/freedreno_draw.c
+++ b/src/gallium/drivers/freedreno/freedreno_draw.c
@@ -109,7 +109,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 	/* NOTE: needs to be before resource_written(batch->query_buf), otherwise
 	 * query_buf may not be created yet.
 	 */
-	fd_hw_query_set_stage(batch, batch->draw, FD_STAGE_DRAW);
+	fd_batch_set_stage(batch, batch->draw, FD_STAGE_DRAW);
 
 	/*
 	 * Figure out the buffers/features we need:
@@ -368,7 +368,7 @@ fd_clear(struct pipe_context *pctx, unsigned buffers,
 		return;
 	}
 
-	fd_hw_query_set_stage(batch, batch->draw, FD_STAGE_CLEAR);
+	fd_batch_set_stage(batch, batch->draw, FD_STAGE_CLEAR);
 
 	ctx->clear(ctx, buffers, color, depth, stencil);
 
diff --git a/src/gallium/drivers/freedreno/freedreno_gmem.c b/src/gallium/drivers/freedreno/freedreno_gmem.c
index d9f707d9c9..ded23219dc 100644
--- a/src/gallium/drivers/freedreno/freedreno_gmem.c
+++ b/src/gallium/drivers/freedreno/freedreno_gmem.c
@@ -332,7 +332,8 @@ render_tiles(struct fd_batch *batch)
 
 		ctx->emit_tile_renderprep(batch, tile);
 
-		fd_hw_query_prepare_tile(batch, i, batch->gmem);
+		if (ctx->query_prepare_tile)
+			ctx->query_prepare_tile(batch, i, batch->gmem);
 
 		/* emit IB to drawcmds: */
 		ctx->emit_ib(batch->gmem, batch->draw);
@@ -353,7 +354,8 @@ render_sysmem(struct fd_batch *batch)
 
 	ctx->emit_sysmem_prep(batch);
 
-	fd_hw_query_prepare_tile(batch, 0, batch->gmem);
+	if (ctx->query_prepare_tile)
+		ctx->query_prepare_tile(batch, 0, batch->gmem);
 
 	/* emit IB to drawcmds: */
 	ctx->emit_ib(batch->gmem, batch->draw);
@@ -402,7 +404,8 @@ fd_gmem_render_tiles(struct fd_batch *batch)
 			batch, pfb->width, pfb->height,
 			util_format_short_name(pipe_surface_format(pfb->cbufs[0])),
 			util_format_short_name(pipe_surface_format(pfb->zsbuf)));
-		fd_hw_query_prepare(batch, 1);
+		if (ctx->query_prepare)
+			ctx->query_prepare(batch, 1);
 		render_sysmem(batch);
 		ctx->stats.batch_sysmem++;
 	} else {
@@ -412,7 +415,8 @@ fd_gmem_render_tiles(struct fd_batch *batch)
 			batch, pfb->width, pfb->height, gmem->nbins_x, gmem->nbins_y,
 			util_format_short_name(pipe_surface_format(pfb->cbufs[0])),
 			util_format_short_name(pipe_surface_format(pfb->zsbuf)));
-		fd_hw_query_prepare(batch, gmem->nbins_x * gmem->nbins_y);
+		if (ctx->query_prepare)
+			ctx->query_prepare(batch, gmem->nbins_x * gmem->nbins_y);
 		render_tiles(batch);
 		ctx->stats.batch_gmem++;
 	}
diff --git a/src/gallium/drivers/freedreno/freedreno_query.c b/src/gallium/drivers/freedreno/freedreno_query.c
index 1e72c6d65f..a27ddb5c63 100644
--- a/src/gallium/drivers/freedreno/freedreno_query.c
+++ b/src/gallium/drivers/freedreno/freedreno_query.c
@@ -46,8 +46,8 @@ fd_create_query(struct pipe_context *pctx, unsigned query_type, unsigned index)
 	struct fd_query *q;
 
 	q = fd_sw_create_query(ctx, query_type);
-	if (!q)
-		q = fd_hw_create_query(ctx, query_type);
+	if (!q && ctx->create_query)
+		q = ctx->create_query(ctx, query_type);
 
 	return (struct pipe_query *) q;
 }
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index 3b06709552..e4e7aa92a4 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -1091,7 +1091,7 @@ fd_blitter_pipe_begin(struct fd_context *ctx, bool render_cond, bool discard,
 			ctx->cond_query, ctx->cond_cond, ctx->cond_mode);
 
 	if (ctx->batch)
-		fd_hw_query_set_stage(ctx->batch, ctx->batch->draw, stage);
+		fd_batch_set_stage(ctx->batch, ctx->batch->draw, stage);
 
 	ctx->in_blit = discard;
 }
@@ -1100,7 +1100,7 @@ void
 fd_blitter_pipe_end(struct fd_context *ctx)
 {
 	if (ctx->batch)
-		fd_hw_query_set_stage(ctx->batch, ctx->batch->draw, FD_STAGE_NULL);
+		fd_batch_set_stage(ctx->batch, ctx->batch->draw, FD_STAGE_NULL);
 	ctx->in_blit = false;
 }
 
diff --git a/src/gallium/drivers/freedreno/freedreno_state.c b/src/gallium/drivers/freedreno/freedreno_state.c
index 3b02e63064..54bd54898a 100644
--- a/src/gallium/drivers/freedreno/freedreno_state.c
+++ b/src/gallium/drivers/freedreno/freedreno_state.c
@@ -126,7 +126,7 @@ fd_set_framebuffer_state(struct pipe_context *pctx,
 		fd_batch_reference(&old_batch, ctx->batch);
 
 		if (likely(old_batch))
-			fd_hw_query_set_stage(old_batch, old_batch->draw, FD_STAGE_NULL);
+			fd_batch_set_stage(old_batch, old_batch->draw, FD_STAGE_NULL);
 
 		batch = fd_batch_from_fb(&ctx->screen->batch_cache, ctx, framebuffer);
 		fd_batch_reference(&ctx->batch, NULL);




More information about the mesa-commit mailing list