freedreno: make hw-query a helper
authorRob Clark <robdclark@gmail.com>
Fri, 21 Apr 2017 13:50:30 +0000 (09:50 -0400)
committerRob Clark <robdclark@gmail.com>
Sat, 22 Apr 2017 14:03:01 +0000 (10:03 -0400)
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@gmail.com>
13 files changed:
src/gallium/drivers/freedreno/a3xx/fd3_context.c
src/gallium/drivers/freedreno/a3xx/fd3_query.c
src/gallium/drivers/freedreno/a4xx/fd4_context.c
src/gallium/drivers/freedreno/a4xx/fd4_query.c
src/gallium/drivers/freedreno/a5xx/fd5_emit.c
src/gallium/drivers/freedreno/freedreno_batch.c
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_gmem.c
src/gallium/drivers/freedreno/freedreno_query.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_state.c

index dac59418df0707578e8e9ca1b7f26acc298dcbbf..b432f593e0f4f1de2ceedd08ccfe1ae2602f5a6e 100644 (file)
@@ -26,6 +26,7 @@
  *    Rob Clark <robclark@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);
 
index cce165c0410bcb0a32116dff72d50f152f98803a..cde42c37313d63a2b5853eb318a2197389a05e06 100644 (file)
@@ -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);
 }
index 291df2d03fcb4cd3166755c7645ddd0fd1097b08..db292af8be1a6e4d658e24ef4d56c8b65b97344a 100644 (file)
@@ -26,6 +26,7 @@
  *    Rob Clark <robclark@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);
 
index 3ae3971dc5fb74ac08c2563236911fde07d9bc22..f7b385d552d4b0d2ea864f689bfc04d10c18cddf 100644 (file)
@@ -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);
index f2c9a6b85d5c2c78fdff3c9e05511cce48011abb..5b25257167b0f2fea67a670aa3a4cce854950f3a 100644 (file)
@@ -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
index f97282b3405dea95a41e83e4de3d9f0873c4210f..17078d425e090f4c0d5bfe878a9fa4958656fc66 100644 (file)
@@ -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);
index 6478e0e7a9c5be4d7b3e5a4b557c4e995a709278..c8d2138cfea7967574d2c03b65b811b62a82b8dd 100644 (file)
@@ -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)
index 733c64b18070be22ada8b0d46e35f0ea8954a854..fe685e1767d01e4343191ad808b2f4cdedd7c3cd 100644 (file)
@@ -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);
 
index 6243984dc80e0802fffcbb527ae1a36847e22c18..dc9effbb7b79358aadaf3a4eb14551cd2123f8a8 100644 (file)
@@ -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);
 
index d9f707d9c9a1f9bdafec9d8ef813ec07795b6610..ded23219dc200c083a1aecfe30174237f6dcbd53 100644 (file)
@@ -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++;
        }
index 1e72c6d65f1bd5c3987d712e9f2be0c7900e817f..a27ddb5c638d7cd5813740209e02c8220eeb20f8 100644 (file)
@@ -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;
 }
index 3b067095523538bfd81dfd7c98f84055c66ee486..e4e7aa92a462329e588825909abef654fba51cf5 100644 (file)
@@ -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;
 }
 
index 3b02e630646ea6f9a8c3434818838d06164a8fa6..54bd54898a3421b418bde645bcb812c408091051 100644 (file)
@@ -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);