struct etna_context *ctx = etna_context(pctx);
mtx_lock(&ctx->lock);
+
if (ctx->used_resources_read) {
/*
set_foreach(ctx->used_resources_read, entry) {
struct etna_resource *rsc = (struct etna_resource *)entry->key;
+ mtx_lock(&rsc->lock);
_mesa_set_remove_key(rsc->pending_ctx, ctx);
+ mtx_unlock(&rsc->lock);
}
_mesa_set_destroy(ctx->used_resources_read, NULL);
set_foreach(ctx->used_resources_write, entry) {
struct etna_resource *rsc = (struct etna_resource *)entry->key;
+ mtx_lock(&rsc->lock);
_mesa_set_remove_key(rsc->pending_ctx, ctx);
+ mtx_unlock(&rsc->lock);
}
_mesa_set_destroy(ctx->used_resources_write, NULL);
struct etna_resource *rsc = (struct etna_resource *)entry->key;
struct pipe_resource *referenced = &rsc->base;
+ mtx_lock(&rsc->lock);
+
_mesa_set_remove_key(rsc->pending_ctx, ctx);
/* if resource has no pending ctx's reset its status */
if (_mesa_set_next_entry(rsc->pending_ctx, NULL) == NULL)
rsc->status &= ~ETNA_PENDING_READ;
+ mtx_unlock(&rsc->lock);
+
pipe_resource_reference(&referenced, NULL);
}
_mesa_set_clear(ctx->used_resources_read, NULL);
struct etna_resource *rsc = (struct etna_resource *)entry->key;
struct pipe_resource *referenced = &rsc->base;
+ mtx_lock(&rsc->lock);
_mesa_set_remove_key(rsc->pending_ctx, ctx);
/* if resource has no pending ctx's reset its status */
if (_mesa_set_next_entry(rsc->pending_ctx, NULL) == NULL)
rsc->status &= ~ETNA_PENDING_WRITE;
+ mtx_unlock(&rsc->lock);
pipe_resource_reference(&referenced, NULL);
}
memset(map, 0, size);
}
+ mtx_init(&rsc->lock, mtx_recursive);
rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
if (!rsc->pending_ctx)
{
struct etna_resource *rsc = etna_resource(prsc);
+ mtx_lock(&rsc->lock);
assert(!_mesa_set_next_entry(rsc->pending_ctx, NULL));
_mesa_set_destroy(rsc->pending_ctx, NULL);
+ mtx_unlock(&rsc->lock);
if (rsc->bo)
etna_bo_del(rsc->bo);
for (unsigned i = 0; i < ETNA_NUM_LOD; i++)
FREE(rsc->levels[i].patch_offsets);
+ mtx_destroy(&rsc->lock);
+
FREE(rsc);
}
goto fail;
}
+ mtx_init(&rsc->lock, mtx_recursive);
rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
if (!rsc->pending_ctx)
mtx_lock(&ctx->lock);
rsc = etna_resource(prsc);
+again:
+ mtx_lock(&rsc->lock);
set_foreach(rsc->pending_ctx, entry) {
struct etna_context *extctx = (struct etna_context *)entry->key;
struct pipe_context *pctx = &extctx->base;
+ bool need_flush = false;
+
+ if (mtx_trylock(&extctx->lock) != thrd_success) {
+ /*
+ * The other context could be locked in etna_flush() and
+ * stuck waiting for the resource lock, so release the
+ * resource lock here, let etna_flush() finish, and try
+ * again.
+ */
+ mtx_unlock(&rsc->lock);
+ thrd_yield();
+ goto again;
+ }
set_foreach(extctx->used_resources_read, entry2) {
struct etna_resource *rsc2 = (struct etna_resource *)entry2->key;
if (ctx == extctx || rsc2 != rsc)
continue;
- if (status & ETNA_PENDING_WRITE)
- pctx->flush(pctx, NULL, 0);
+ if (status & ETNA_PENDING_WRITE) {
+ need_flush = true;
+ break;
+ }
+ }
+
+ if (need_flush) {
+ pctx->flush(pctx, NULL, 0);
+ mtx_unlock(&extctx->lock);
+ continue;
}
set_foreach(extctx->used_resources_write, entry2) {
if (ctx == extctx || rsc2 != rsc)
continue;
- pctx->flush(pctx, NULL, 0);
+ need_flush = true;
+ break;
}
+
+ if (need_flush)
+ pctx->flush(pctx, NULL, 0);
+
+ mtx_unlock(&extctx->lock);
}
rsc->status = status;
_mesa_set_add(rsc->pending_ctx, ctx);
}
+ mtx_unlock(&rsc->lock);
mtx_unlock(&ctx->lock);
}