freedreno: Flush batches on shadow/uncompress
authorRob Clark <robdclark@chromium.org>
Mon, 14 Jun 2021 22:18:25 +0000 (15:18 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 15 Jun 2021 19:09:24 +0000 (19:09 +0000)
Normally when we shadow a resource (whether it is changing the modifier
or not) we do not need to flush existing batches, since they reference
the original version of the resource.  There is a special case for
resources that are referenced by a batches framebuffer state, because
this state is emitted when the batch is flushed.  Because of this, we
need those batches to be flushed before we shadow the resource.

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

src/gallium/drivers/freedreno/freedreno_resource.c

index 54c520f..74b0b10 100644 (file)
@@ -357,11 +357,23 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc,
 {
    struct pipe_context *pctx = &ctx->base;
    struct pipe_resource *prsc = &rsc->b.b;
+   struct fd_screen *screen = fd_screen(pctx->screen);
+   struct fd_batch *batch;
    bool fallback = false;
 
    if (prsc->next)
       return false;
 
+   /* Because IB1 ("gmem") cmdstream is built only when we flush the
+    * batch, we need to flush any batches that reference this rsc as
+    * a render target.  Otherwise the framebuffer state emitted in
+    * IB1 will reference the resources new state, and not the state
+    * at the point in time that the earlier draws referenced it.
+    */
+   foreach_batch (batch, &screen->batch_cache, rsc->track->bc_batch_mask) {
+      fd_batch_flush(batch);
+   }
+
    /* If you have a sequence where there is a single rsc associated
     * with the current render target, and then you end up shadowing
     * that same rsc on the 3d pipe (u_blitter), because of how we
@@ -435,7 +447,6 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc,
     * transfer those references over:
     */
    debug_assert(shadow->track->batch_mask == 0);
-   struct fd_batch *batch;
    foreach_batch (batch, &ctx->screen->batch_cache, rsc->track->batch_mask) {
       struct set_entry *entry = _mesa_set_search(batch->resources, rsc);
       _mesa_set_remove(batch->resources, entry);