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 <alyssa@collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12528>
(cherry picked from commit b8da5b1b7f)
This commit is contained in:
Alyssa Rosenzweig 2021-08-17 16:05:07 +00:00 committed by Dylan Baker
parent 2987bf8761
commit ca3c31add8
4 changed files with 12 additions and 3 deletions

View file

@ -1183,7 +1183,7 @@
"description": "panfrost: Cache number of users of a resource",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -133,6 +133,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);
}
@ -272,6 +274,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);
}

View file

@ -894,7 +894,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
@ -913,7 +913,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;

View file

@ -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;