Mesa (master): freedreno: Consolidate needs_flush and clearing last_fence

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon May 3 23:50:04 UTC 2021


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

Author: Rob Clark <robdclark at chromium.org>
Date:   Mon May  3 13:27:14 2021 -0700

freedreno: Consolidate needs_flush and clearing last_fence

Add a helper to both set batch->needs_flush and clear ctx->last_fence so
that the two related bits of state do not get out of sync.

Signed-off-by: Rob Clark <robdclark at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10599>

---

 src/gallium/drivers/freedreno/a5xx/fd5_blitter.c   |  2 +-
 src/gallium/drivers/freedreno/a6xx/fd6_blitter.c   |  9 ++++-----
 src/gallium/drivers/freedreno/freedreno_batch.h    | 12 ++++++++++++
 src/gallium/drivers/freedreno/freedreno_blitter.c  |  7 +++----
 src/gallium/drivers/freedreno/freedreno_context.c  |  2 +-
 src/gallium/drivers/freedreno/freedreno_draw.c     | 22 ++++++++++------------
 src/gallium/drivers/freedreno/freedreno_fence.c    |  2 +-
 src/gallium/drivers/freedreno/freedreno_query_hw.c |  2 +-
 8 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c b/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
index 85ab44688b2..9c837a5a01b 100644
--- a/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
+++ b/src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
@@ -460,7 +460,7 @@ fd5_blitter_blit(struct fd_context *ctx,
    }
 
    fd_resource(info->dst.resource)->valid = true;
-   batch->needs_flush = true;
+   fd_batch_needs_flush(batch);
 
    fd_batch_flush(batch);
    fd_batch_reference(&batch, NULL);
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c b/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
index 4b7d50d585e..ae9bd1e43a2 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
@@ -926,11 +926,11 @@ handle_rgba_blit(struct fd_context *ctx,
    ASSERTED bool ret = fd_batch_lock_submit(batch);
    assert(ret);
 
-   /* Clearing last_fence must come after the batch dependency tracking
-    * (resource_read()/resource_write()), as that can trigger a flush,
-    * re-populating last_fence
+   /* Marking the batch as needing flush must come after the batch
+    * dependency tracking (resource_read()/resource_write()), as that
+    * can trigger a flush
     */
-   fd_fence_ref(&ctx->last_fence, NULL);
+   fd_batch_needs_flush(batch);
 
    fd_batch_update_queries(batch);
 
@@ -965,7 +965,6 @@ handle_rgba_blit(struct fd_context *ctx,
    fd_batch_unlock_submit(batch);
 
    fd_resource(info->dst.resource)->valid = true;
-   batch->needs_flush = true;
 
    fd_batch_flush(batch);
    fd_batch_reference(&batch, NULL);
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.h b/src/gallium/drivers/freedreno/freedreno_batch.h
index 2abe1d48247..179f0378bc9 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.h
+++ b/src/gallium/drivers/freedreno/freedreno_batch.h
@@ -34,6 +34,7 @@
 #include "util/u_trace.h"
 
 #include "freedreno_context.h"
+#include "freedreno_fence.h"
 #include "freedreno_util.h"
 
 #ifdef DEBUG
@@ -359,6 +360,17 @@ fd_batch_lock_submit(struct fd_batch *batch)
    return ret;
 }
 
+/**
+ * Mark the batch as having something worth flushing (rendering, blit, query,
+ * etc)
+ */
+static inline void
+fd_batch_needs_flush(struct fd_batch *batch)
+{
+   batch->needs_flush = true;
+   fd_fence_ref(&batch->ctx->last_fence, NULL);
+}
+
 /* Since we reorder batches and can pause/resume queries (notably for disabling
  * queries dueing some meta operations), we update the current query state for
  * the batch before each draw.
diff --git a/src/gallium/drivers/freedreno/freedreno_blitter.c b/src/gallium/drivers/freedreno/freedreno_blitter.c
index 2a5bb4b84a2..091f135aae2 100644
--- a/src/gallium/drivers/freedreno/freedreno_blitter.c
+++ b/src/gallium/drivers/freedreno/freedreno_blitter.c
@@ -80,8 +80,6 @@ static void
 fd_blitter_pipe_begin(struct fd_context *ctx, bool render_cond,
                       bool discard) assert_dt
 {
-   fd_fence_ref(&ctx->last_fence, NULL);
-
    util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vtx.vertexbuf.vb);
    util_blitter_save_vertex_elements(ctx->blitter, ctx->vtx.vtx);
    util_blitter_save_vertex_shader(ctx->blitter, ctx->prog.vs);
@@ -241,10 +239,11 @@ fd_blitter_clear(struct pipe_context *pctx, unsigned buffers,
       .max_index = 1,
       .instance_count = MAX2(1, pfb->layers),
    };
-	struct pipe_draw_start_count_bias draw = {
+   struct pipe_draw_start_count_bias draw = {
       .count = 2,
    };
-	pctx->draw_vbo(pctx, &info, 0, NULL, &draw, 1);
+
+   pctx->draw_vbo(pctx, &info, 0, NULL, &draw, 1);
 
    /* We expect that this should not have triggered a change in pfb: */
    assert(util_framebuffer_state_equal(pfb, &ctx->framebuffer));
diff --git a/src/gallium/drivers/freedreno/freedreno_context.c b/src/gallium/drivers/freedreno/freedreno_context.c
index 1fa4435ed4a..adc5309dffb 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.c
+++ b/src/gallium/drivers/freedreno/freedreno_context.c
@@ -240,7 +240,7 @@ fd_emit_string_marker(struct pipe_context *pctx, const char *string,
 
    struct fd_batch *batch = fd_context_batch_locked(ctx);
 
-   ctx->batch->needs_flush = true;
+   fd_batch_needs_flush(batch);
 
    if (ctx->screen->gpu_id >= 500) {
       fd_emit_string5(batch->draw, string, len);
diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c
index c82ec03aa68..56e653aa3bc 100644
--- a/src/gallium/drivers/freedreno/freedreno_draw.c
+++ b/src/gallium/drivers/freedreno/freedreno_draw.c
@@ -347,11 +347,11 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info,
    batch->back_blit = ctx->in_shadow;
    batch->num_draws++;
 
-   /* Clearing last_fence must come after the batch dependency tracking
-    * (resource_read()/resource_written()), as that can trigger a flush,
-    * re-populating last_fence
+   /* Marking the batch as needing flush must come after the batch
+    * dependency tracking (resource_read()/resource_write()), as that
+    * can trigger a flush
     */
-   fd_fence_ref(&ctx->last_fence, NULL);
+   fd_batch_needs_flush(batch);
 
    struct pipe_framebuffer_state *pfb = &batch->framebuffer;
    DBG("%p: %ux%u num_draws=%u (%s/%s)", batch, pfb->width, pfb->height,
@@ -362,8 +362,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info,
    batch->cost += ctx->draw_cost;
 
    for (unsigned i = 0; i < num_draws; i++) {
-		if (ctx->draw_vbo(ctx, info, drawid_offset, indirect, &draws[i], index_offset))
-         batch->needs_flush = true;
+      ctx->draw_vbo(ctx, info, drawid_offset, indirect, &draws[i], index_offset);
 
       batch->num_vertices += draws[i].count * info->instance_count;
    }
@@ -414,7 +413,6 @@ batch_clear_tracking(struct fd_batch *batch, unsigned buffers) assert_dt
    batch->invalidated |= cleared_buffers;
 
    batch->resolve |= buffers;
-   batch->needs_flush = true;
 
    fd_screen_lock(ctx->screen);
 
@@ -468,11 +466,11 @@ fd_clear(struct pipe_context *pctx, unsigned buffers,
       assert(ctx->batch == batch);
    }
 
-   /* Clearing last_fence must come after the batch dependency tracking
-    * (resource_read()/resource_written()), as that can trigger a flush,
-    * re-populating last_fence
+   /* Marking the batch as needing flush must come after the batch
+    * dependency tracking (resource_read()/resource_write()), as that
+    * can trigger a flush
     */
-   fd_fence_ref(&ctx->last_fence, NULL);
+   fd_batch_needs_flush(batch);
 
    struct pipe_framebuffer_state *pfb = &batch->framebuffer;
    DBG("%p: %x %ux%u depth=%f, stencil=%u (%s/%s)", batch, buffers, pfb->width,
@@ -580,7 +578,7 @@ fd_launch_grid(struct pipe_context *pctx,
        info->block[0], info->block[1], info->block[2],
        info->grid[0], info->grid[1], info->grid[2]);
 
-   batch->needs_flush = true;
+   fd_batch_needs_flush(batch);
    ctx->launch_grid(ctx, info);
 
    fd_batch_flush(batch);
diff --git a/src/gallium/drivers/freedreno/freedreno_fence.c b/src/gallium/drivers/freedreno/freedreno_fence.c
index d85809317dd..aa5645d835d 100644
--- a/src/gallium/drivers/freedreno/freedreno_fence.c
+++ b/src/gallium/drivers/freedreno/freedreno_fence.c
@@ -279,7 +279,7 @@ fd_fence_set_batch(struct pipe_fence_handle *fence, struct fd_batch *batch)
    if (batch) {
       assert(!fence->batch);
       fence->batch = batch;
-      batch->needs_flush = true;
+      fd_batch_needs_flush(batch);
    } else {
       fence->batch = NULL;
 
diff --git a/src/gallium/drivers/freedreno/freedreno_query_hw.c b/src/gallium/drivers/freedreno/freedreno_query_hw.c
index feab589e677..2bfffdc8350 100644
--- a/src/gallium/drivers/freedreno/freedreno_query_hw.c
+++ b/src/gallium/drivers/freedreno/freedreno_query_hw.c
@@ -53,7 +53,7 @@ get_sample(struct fd_batch *batch, struct fd_ringbuffer *ring,
          ctx->hw_sample_providers[idx]->get_sample(batch, ring);
       fd_hw_sample_reference(ctx, &batch->sample_cache[idx], new_samp);
       util_dynarray_append(&batch->samples, struct fd_hw_sample *, new_samp);
-      batch->needs_flush = true;
+      fd_batch_needs_flush(batch);
    }
 
    fd_hw_sample_reference(ctx, &samp, batch->sample_cache[idx]);



More information about the mesa-commit mailing list