From 0b26a9f773956fc00a77b0d4a7aafee5795ce935 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: --- src/gallium/drivers/panfrost/pan_resource.c | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index a2992253a2b..ac171ca13dc 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) {