if (rsrc->track.writer == batch)
rsrc->track.writer = NULL;
+ rsrc->track.nr_users--;
+
pipe_resource_reference((struct pipe_resource **) &rsrc, NULL);
}
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);
}
(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
* 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;
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;