freedreno: Consolidate needs_flush and clearing last_fence
authorRob Clark <robdclark@chromium.org>
Mon, 3 May 2021 20:27:14 +0000 (13:27 -0700)
committerMarge Bot <eric+marge@anholt.net>
Mon, 3 May 2021 23:27:31 +0000 (23:27 +0000)
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@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10599>

src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
src/gallium/drivers/freedreno/freedreno_batch.h
src/gallium/drivers/freedreno/freedreno_blitter.c
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_fence.c
src/gallium/drivers/freedreno/freedreno_query_hw.c

index 85ab446..9c837a5 100644 (file)
@@ -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);
index 4b7d50d..ae9bd1e 100644 (file)
@@ -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);
index 2abe1d4..179f037 100644 (file)
@@ -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.
index 2a5bb4b..091f135 100644 (file)
@@ -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));
index 1fa4435..adc5309 100644 (file)
@@ -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);
index c82ec03..56e653a 100644 (file)
@@ -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);
index d858093..aa5645d 100644 (file)
@@ -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;
 
index feab589..2bfffdc 100644 (file)
@@ -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]);