From ec5bc021fe77058ecb02a9ef2c429e0b889ce1d5 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 2 Nov 2022 13:43:11 -0400 Subject: [PATCH] panfrost: Don't copy resources if replaced If a synchronized transfer_map is going to overwrite an entire resource, there's no need to memcpy in the original contents ahead-of-time. This memcpy is particularly bad for large buffers where it's copying WC->WC, although that could be mitigated with threaded_context's cpu_storage in the future if needed. Prevents a performance regression in glmark2's buffer scenes from the next patch, hence the Cc. Cc: mesa-stable Signed-off-by: Alyssa Rosenzweig Part-of: (cherry picked from commit 0b26a9f773956fc00a77b0d4a7aafee5795ce935) --- .pick_status.json | 2 +- src/gallium/drivers/panfrost/pan_resource.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 2c42c5e..6dd464c 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2731,7 +2731,7 @@ "description": "panfrost: Don't copy resources if replaced", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index a299225..ac171ca 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -936,6 +936,17 @@ panfrost_store_tiled_images(struct panfrost_transfer *transfer, } } +static bool +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; +} + static void * panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource, @@ -1005,6 +1016,18 @@ panfrost_ptr_map(struct pipe_context *pctx, if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) pandecode_inject_mmap(bo->ptr.gpu, bo->ptr.cpu, bo->size, NULL); + /* Upgrade DISCARD_RANGE to WHOLE_RESOURCE if the whole resource is + * being mapped. + */ + if ((usage & PIPE_MAP_DISCARD_RANGE) && + !(usage & PIPE_MAP_UNSYNCHRONIZED) && + !(resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT) && + panfrost_box_covers_resource(resource, box) && + !(rsrc->image.data.bo->flags & PAN_BO_SHARED)) { + + usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE; + } + bool create_new_bo = usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE; bool copy_resource = false; @@ -1025,7 +1048,7 @@ panfrost_ptr_map(struct pipe_context *pctx, panfrost_bo_wait(bo, INT64_MAX, false); create_new_bo = true; - copy_resource = true; + copy_resource = !panfrost_box_covers_resource(resource, box); } if (create_new_bo) { -- 2.7.4