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

Author: Rob Clark <[email protected]>
Date:   Tue Sep 13 15:20:58 2022 -0700

freedreno/virtio: Don't upload if we have valid range

A transfer that only partially writes the staging buffer could overwrite
valid buffer contents, unless we are told that it is ok to discard the
entire range.

Signed-off-by: Rob Clark <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18604>

---

 src/gallium/drivers/freedreno/freedreno_resource.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c 
b/src/gallium/drivers/freedreno/freedreno_resource.c
index eb189b091e9..8836fb57998 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -744,6 +744,12 @@ invalidate_resource(struct fd_resource *rsc, unsigned 
usage) assert_dt
    }
 }
 
+static bool
+valid_range(struct fd_resource *rsc, const struct pipe_box *box)
+{
+   return util_ranges_intersect(&rsc->valid_buffer_range, box->x, box->x + 
box->width);
+}
+
 static void *
 resource_transfer_map_staging(struct pipe_context *pctx,
                               struct pipe_resource *prsc,
@@ -794,6 +800,7 @@ resource_transfer_map_unsync(struct pipe_context *pctx,
 
    if ((prsc->target == PIPE_BUFFER) &&
        !(usage & (PIPE_MAP_READ | PIPE_MAP_DIRECTLY | PIPE_MAP_PERSISTENT)) &&
+       ((usage & PIPE_MAP_DISCARD_RANGE) || !valid_range(rsc, box)) &&
        fd_bo_prefer_upload(rsc->bo, box->width)) {
       trans->upload_ptr = malloc(box->width);
       return trans->upload_ptr;
@@ -958,8 +965,7 @@ improve_transfer_map_usage(struct fd_context *ctx, struct 
fd_resource *rsc,
       if (ctx->in_shadow && !(usage & PIPE_MAP_READ)) {
          usage |= PIPE_MAP_UNSYNCHRONIZED;
       } else if ((usage & PIPE_MAP_WRITE) && (rsc->b.b.target == PIPE_BUFFER) 
&&
-                 !util_ranges_intersect(&rsc->valid_buffer_range, box->x,
-                                        box->x + box->width)) {
+                 !valid_range(rsc, box)) {
          /* We are trying to write to a previously uninitialized range. No need
           * to synchronize.
           */

Reply via email to