freedreno: Fix missing rsc->seqno updates
[mesa.git] / src / gallium / drivers / freedreno / freedreno_resource.c
index ed7daaaf63a84f1583c5d52050f7ad7f0061bfe9..803054c4f2fa0d569cf0d1bfc84c2974b073062c 100644 (file)
@@ -166,6 +166,15 @@ rebind_resource(struct fd_resource *rsc)
        fd_screen_unlock(screen);
 }
 
+static inline void
+fd_resource_set_bo(struct fd_resource *rsc, struct fd_bo *bo)
+{
+       struct fd_screen *screen = fd_screen(rsc->base.screen);
+
+       rsc->bo = bo;
+       rsc->seqno = p_atomic_inc_return(&screen->rsc_seqno);
+}
+
 static void
 realloc_bo(struct fd_resource *rsc, uint32_t size)
 {
@@ -183,8 +192,9 @@ realloc_bo(struct fd_resource *rsc, uint32_t size)
        if (rsc->bo)
                fd_bo_del(rsc->bo);
 
-       rsc->bo = fd_bo_new(screen->dev, size, flags, "%ux%ux%u@%u:%x",
+       struct fd_bo *bo = fd_bo_new(screen->dev, size, flags, "%ux%ux%u@%u:%x",
                        prsc->width0, prsc->height0, prsc->depth0, rsc->layout.cpp, prsc->bind);
+       fd_resource_set_bo(rsc, bo);
 
        /* Zero out the UBWC area on allocation.  This fixes intermittent failures
         * with UBWC, which I suspect are due to the HW having a hard time
@@ -194,11 +204,9 @@ realloc_bo(struct fd_resource *rsc, uint32_t size)
         * around the issue, but any memset value seems to.
         */
        if (rsc->layout.ubwc) {
-               void *buf = fd_bo_map(rsc->bo);
-               memset(buf, 0, rsc->layout.slices[0].offset);
+               rsc->needs_ubwc_clear = true;
        }
 
-       rsc->seqno = p_atomic_inc_return(&screen->rsc_seqno);
        util_range_set_empty(&rsc->valid_buffer_range);
        fd_bc_invalidate_resource(rsc, true);
 }
@@ -218,6 +226,9 @@ do_blit(struct fd_context *ctx, const struct pipe_blit_info *blit, bool fallback
        }
 }
 
+static void
+flush_resource(struct fd_context *ctx, struct fd_resource *rsc, unsigned usage);
+
 /**
  * @rsc: the resource to shadow
  * @level: the level to discard (if box != NULL, otherwise ignored)
@@ -235,6 +246,21 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc,
        if (prsc->next)
                return false;
 
+       /* 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
+        * swap the new shadow and rsc before the back-blit, you could end
+        * up confusing things into thinking that u_blitter's framebuffer
+        * state is the same as the current framebuffer state, which has
+        * the result of blitting to rsc rather than shadow.
+        *
+        * Normally we wouldn't want to unconditionally trigger a flush,
+        * since that defeats the purpose of shadowing, but this is a
+        * case where we'd have to flush anyways.
+        */
+       if (rsc->write_batch == ctx->batch)
+               flush_resource(ctx, rsc, 0);
+
        /* TODO: somehow munge dimensions and format to copy unsupported
         * render target format to something that is supported?
         */
@@ -1060,10 +1086,12 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
 
        simple_mtx_init(&rsc->lock, mtx_plain);
 
-       rsc->bo = fd_screen_bo_from_handle(pscreen, handle);
-       if (!rsc->bo)
+       struct fd_bo *bo = fd_screen_bo_from_handle(pscreen, handle);
+       if (!bo)
                goto fail;
 
+       fd_resource_set_bo(rsc, bo);
+
        rsc->internal_format = tmpl->format;
        rsc->layout.pitch0 = handle->stride;
        slice->offset = handle->offset;
@@ -1253,7 +1281,7 @@ fd_resource_from_memobj(struct pipe_screen *pscreen,
        }
 
        /* Share the bo with the memory object. */
-       rsc->bo = fd_bo_ref(memobj->bo);
+       fd_resource_set_bo(rsc, fd_bo_ref(memobj->bo));
 
        return prsc;
 }