Mesa (staging/21.2): panfrost: Cache number of users of a resource
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Aug 26 17:46:44 UTC 2021
Module: Mesa
Branch: staging/21.2
Commit: ca3c31add86e802ce8d2fbb95d88de8d97035ff2
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ca3c31add86e802ce8d2fbb95d88de8d97035ff2
Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date: Tue Aug 17 16:05:07 2021 +0000
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 at collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12528>
(cherry picked from commit b8da5b1b7f4b5c4663621fae3db319d244e5d0b0)
---
.pick_status.json | 2 +-
src/gallium/drivers/panfrost/pan_job.c | 5 +++++
src/gallium/drivers/panfrost/pan_resource.c | 4 ++--
src/gallium/drivers/panfrost/pan_resource.h | 4 ++++
4 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index b63aaf35281..70c711a3447 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -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
},
diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index ce6722c3bc8..9d20a799a7a 100644
--- a/src/gallium/drivers/panfrost/pan_job.c
+++ b/src/gallium/drivers/panfrost/pan_job.c
@@ -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);
}
diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index 174994aa63f..9917cfa3a03 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -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;
diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h
index a3cd7bf14e1..ec4f0005c4e 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;
More information about the mesa-commit
mailing list