From: Alyssa Rosenzweig Date: Tue, 17 Aug 2021 16:05:07 +0000 (+0000) Subject: panfrost: Cache number of users of a resource X-Git-Tag: upstream/22.3.5~18848 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8da5b1b7f4b5c4663621fae3db319d244e5d0b0;p=platform%2Fupstream%2Fmesa.git panfrost: Cache number of users of a resource This can be tracked efficiently with atomics, and reduces the places we use the rsrc->track.users bitmap which has concurrency issues. Signed-off-by: Alyssa Rosenzweig Cc: mesa-stable Part-of: --- diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index f0c9f617e43..2bf544860a1 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -129,6 +129,8 @@ panfrost_batch_cleanup(struct panfrost_batch *batch) if (rsrc->track.writer == batch) rsrc->track.writer = NULL; + rsrc->track.nr_users--; + pipe_resource_reference((struct pipe_resource **) &rsrc, NULL); } @@ -238,6 +240,9 @@ panfrost_batch_update_access(struct panfrost_batch *batch, if (!found) { BITSET_SET(rsrc->track.users, batch_idx); + /* Cache number of batches accessing a resource */ + rsrc->track.nr_users++; + /* Reference the resource on the batch */ pipe_reference(NULL, &rsrc->base.reference); } diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index d7a53474c27..6f0c61b86ab 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -898,7 +898,7 @@ panfrost_ptr_map(struct pipe_context *pctx, (usage & PIPE_MAP_WRITE) && !(resource->target == PIPE_BUFFER && !util_ranges_intersect(&rsrc->valid_buffer_range, box->x, box->x + box->width)) && - BITSET_COUNT(rsrc->track.users) != 0) { + rsrc->track.nr_users > 0) { /* When a resource to be modified is already being used by a * pending batch, it is often faster to copy the whole BO than @@ -917,7 +917,7 @@ panfrost_ptr_map(struct pipe_context *pctx, * not ready yet (still accessed by one of the already flushed * batches), we try to allocate a new one to avoid waiting. */ - if (BITSET_COUNT(rsrc->track.users) || + if (rsrc->track.nr_users > 0 || !panfrost_bo_wait(bo, 0, true)) { /* We want the BO to be MMAPed. */ uint32_t flags = bo->flags & ~PAN_BO_DELAY_MMAP; diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h index 7ee2ef0e245..5da26d6d6b5 100644 --- a/src/gallium/drivers/panfrost/pan_resource.h +++ b/src/gallium/drivers/panfrost/pan_resource.h @@ -50,6 +50,10 @@ struct panfrost_resource { struct { struct panfrost_batch *writer; BITSET_DECLARE(users, PAN_MAX_BATCHES); + + /** Number of batches accessing this resource. Used to check if + * a resource is in use. */ + _Atomic unsigned nr_users; } track; struct renderonly_scanout *scanout;