From dc7b4111fd9d9fc1b167c765face0d3a472d9988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= Date: Wed, 24 Jan 2024 00:51:42 -0500 Subject: [PATCH] panfrost: factor out method to check whether we can discard resource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The logic is gonna be re-used to determine whether we need to unpack a AFBC-packed texture before updating it (when unmapping). Signed-off-by: Louis-Francis Ratté-Boulianne Reviewed-by: Erik Faye-Lund Fixes: 33b48a55857 ("panfrost: Add debug flag to force packing of AFBC textures on upload") Part-of: (cherry picked from commit 22a7637b08255acc998e67bbdbc1ed34daf21465) --- .pick_status.json | 2 +- src/gallium/drivers/panfrost/pan_resource.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index f330617916c..5152001f8fd 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -954,7 +954,7 @@ "description": "panfrost: factor out method to check whether we can discard resource", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "33b48a55857b15f7e7b892a89cad2f0ad2399ba6", "notes": null diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 38f43cadf10..17fc51a04e9 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -1077,6 +1077,19 @@ panfrost_box_covers_resource(const struct pipe_resource *resource, box->width, box->height, box->depth); } +static bool +panfrost_can_discard(struct pipe_resource *resource, const struct pipe_box *box, + unsigned usage) +{ + struct panfrost_resource *rsrc = pan_resource(resource); + + return ((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)); +} + static void * panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource, unsigned level, @@ -1161,11 +1174,7 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource, /* 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)) { - + if (panfrost_can_discard(resource, box, usage)) { usage |= PIPE_MAP_DISCARD_WHOLE_RESOURCE; }