freedreno: don't realloc idle bo's
authorRob Clark <robdclark@chromium.org>
Fri, 24 Apr 2020 20:56:09 +0000 (13:56 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 00:08:57 +0000 (00:08 +0000)
The `DISCARD_WHOLE_RESOURCE` is just a hint.  And `rebind_resource()` is
a bunch of faffing about (and going to get worse in a later patch), so
let's not bother when the bo is already idle.

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

src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_resource.h

index 04e0553f670bc2728d7555c4ee1971ff0dbc257f..247fbe53072940324314202c8aa8265e7081b089 100644 (file)
@@ -594,9 +594,13 @@ fd_resource_transfer_map(struct pipe_context *pctx,
        if (usage & PIPE_TRANSFER_WRITE)
                op |= DRM_FREEDRENO_PREP_WRITE;
 
+       bool needs_flush = pending(rsc, !!(usage & PIPE_TRANSFER_WRITE));
+
        if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
-               realloc_bo(rsc, fd_bo_size(rsc->bo));
-               rebind_resource(ctx, prsc);
+               if (needs_flush || fd_resource_busy(rsc, op)) {
+                       realloc_bo(rsc, fd_bo_size(rsc->bo));
+                       rebind_resource(ctx, prsc);
+               }
        } else if ((usage & PIPE_TRANSFER_WRITE) &&
                           prsc->target == PIPE_BUFFER &&
                           !util_ranges_intersect(&rsc->valid_buffer_range,
@@ -621,9 +625,7 @@ fd_resource_transfer_map(struct pipe_context *pctx,
                /* If the GPU is writing to the resource, or if it is reading from the
                 * resource and we're trying to write to it, flush the renders.
                 */
-               bool needs_flush = pending(rsc, !!(usage & PIPE_TRANSFER_WRITE));
-               bool busy = needs_flush || (0 != fd_bo_cpu_prep(rsc->bo,
-                               ctx->pipe, op | DRM_FREEDRENO_PREP_NOSYNC));
+               bool busy = needs_flush || fd_resource_busy(rsc, op);
 
                /* if we need to flush/stall, see if we can make a shadow buffer
                 * to avoid this:
index 478417e6ba35692e46ef12969212f87571741c6b..9cb1270c74ad4f816519fbf3816a2a29495cd704 100644 (file)
@@ -113,6 +113,12 @@ pending(struct fd_resource *rsc, bool write)
        return false;
 }
 
+static inline bool
+fd_resource_busy(struct fd_resource *rsc, unsigned op)
+{
+       return fd_bo_cpu_prep(rsc->bo, NULL, op | DRM_FREEDRENO_PREP_NOSYNC) != 0;
+}
+
 static inline bool
 has_depth(enum pipe_format format)
 {