panfrost: Copy resources when necessary
authorAlyssa Rosenzweig <alyssa@collabora.com>
Mon, 7 Nov 2022 15:45:08 +0000 (10:45 -0500)
committerEric Engestrom <eric@engestrom.ch>
Wed, 9 Nov 2022 21:22:06 +0000 (21:22 +0000)
If the map doesn't set MAP_DISCARD_RANGE, we do have to copy the existing
contents over. MAP_WRITE on its only gives permission to replace the contents,
unfortunately it does not require that the application actually do so.

Closes: #7640
Fixes: 0b26a9f7739 ("panfrost: Don't copy resources if replaced")
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reported-by: Roman Elshin
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19576>
(cherry picked from commit cf7a3906b0629b2b6aadd3b18a39eae06b10fd6a)

.pick_status.json
src/gallium/drivers/panfrost/pan_resource.c

index 04e258f..4ca7f7e 100644 (file)
         "description": "panfrost: Copy resources when necessary",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "0b26a9f773956fc00a77b0d4a7aafee5795ce935"
     },
index 0bb5e97..402346d 100644 (file)
@@ -941,10 +941,9 @@ panfrost_box_covers_resource(const struct pipe_resource *resource,
                              const struct pipe_box *box)
 {
         return resource->last_level == 0 &&
-               resource->width0 == box->width &&
-               resource->height0 == box->height &&
-               resource->depth0 == box->depth &&
-               resource->array_size == 1;
+               util_texrange_covers_whole_level(resource, 0, box->x, box->y,
+                                                box->z, box->width, box->height,
+                                                box->depth);
 }
 
 static void *
@@ -1048,7 +1047,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
                 panfrost_bo_wait(bo, INT64_MAX, false);
 
                 create_new_bo = true;
-                copy_resource = !panfrost_box_covers_resource(resource, box);
+                copy_resource = !(usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE);
         }
 
         /* Shadowing with separate stencil may require additional accounting.