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;