diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-09-03 07:17:28 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-09-03 07:17:28 +0000 |
commit | b0915d54037185ab191fbbbd1973f7de15b1be68 (patch) | |
tree | 90f2287f1fc5f927663b0bd10f75062b01ace42e /lib/mesa/src/gallium/drivers/etnaviv | |
parent | 53d4023d5d022dee9188af50de693343e5ab3842 (diff) |
Merge Mesa 20.1.7
Diffstat (limited to 'lib/mesa/src/gallium/drivers/etnaviv')
4 files changed, 53 insertions, 34 deletions
diff --git a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_context.c b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_context.c index 34698ce56..832cecbf6 100644 --- a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_context.c +++ b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_context.c @@ -93,6 +93,7 @@ etna_context_destroy(struct pipe_context *pctx) struct etna_context *ctx = etna_context(pctx); mtx_lock(&ctx->lock); + if (ctx->used_resources_read) { /* @@ -103,7 +104,9 @@ etna_context_destroy(struct pipe_context *pctx) 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); @@ -118,7 +121,9 @@ etna_context_destroy(struct pipe_context *pctx) 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); @@ -487,12 +492,16 @@ etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence, 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); @@ -501,11 +510,13 @@ etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence, 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); } diff --git a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.c b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.c index 4a992b5f6..e2ef97f28 100644 --- a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.c +++ b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.c @@ -321,6 +321,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, 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) @@ -463,8 +464,10 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc) { 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); @@ -483,6 +486,8 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc) for (unsigned i = 0; i < ETNA_NUM_LOD; i++) FREE(rsc->levels[i].patch_offsets); + mtx_destroy(&rsc->lock); + FREE(rsc); } @@ -559,6 +564,7 @@ etna_resource_from_handle(struct pipe_screen *pscreen, 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) @@ -603,34 +609,6 @@ etna_resource_get_handle(struct pipe_screen *pscreen, } } -enum etna_resource_status -etna_resource_get_status(struct etna_context *ctx, struct etna_resource *rsc) -{ - enum etna_resource_status newstatus = 0; - - set_foreach(rsc->pending_ctx, entry) { - struct etna_context *extctx = (struct etna_context *)entry->key; - - set_foreach(extctx->used_resources_read, entry2) { - struct etna_resource *rsc2 = (struct etna_resource *)entry2->key; - if (ctx == extctx || rsc2 != rsc) - continue; - - newstatus |= ETNA_PENDING_READ; - } - - set_foreach(extctx->used_resources_write, entry2) { - struct etna_resource *rsc2 = (struct etna_resource *)entry2->key; - if (ctx == extctx || rsc2 != rsc) - continue; - - newstatus |= ETNA_PENDING_WRITE; - } - } - - return newstatus; -} - void etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, enum etna_resource_status status) @@ -644,18 +622,41 @@ etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, 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) { @@ -663,8 +664,14 @@ etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, 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; @@ -676,6 +683,7 @@ etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, _mesa_set_add(rsc->pending_ctx, ctx); } + mtx_unlock(&rsc->lock); mtx_unlock(&ctx->lock); } diff --git a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.h b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.h index 1da0315ab..cb83e891d 100644 --- a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.h +++ b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_resource.h @@ -96,6 +96,7 @@ struct etna_resource { enum etna_resource_status status; + mtx_t lock; /* Lock to protect pending_ctx */ struct set *pending_ctx; }; @@ -150,9 +151,6 @@ etna_resource(struct pipe_resource *p) return (struct etna_resource *)p; } -enum etna_resource_status -etna_resource_get_status(struct etna_context *ctx, struct etna_resource *rsc); - void etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, enum etna_resource_status status); diff --git a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_transfer.c b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_transfer.c index 0d0324ec0..27f3ebe58 100644 --- a/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_transfer.c +++ b/lib/mesa/src/gallium/drivers/etnaviv/etnaviv_transfer.c @@ -391,12 +391,14 @@ etna_transfer_map(struct pipe_context *pctx, struct pipe_resource *prsc, (!trans->rsc && (((usage & PIPE_TRANSFER_READ) && (rsc->status & ETNA_PENDING_WRITE)) || ((usage & PIPE_TRANSFER_WRITE) && rsc->status)))) { + mtx_lock(&rsc->lock); set_foreach(rsc->pending_ctx, entry) { struct etna_context *pend_ctx = (struct etna_context *)entry->key; struct pipe_context *pend_pctx = &pend_ctx->base; pend_pctx->flush(pend_pctx, NULL, 0); } + mtx_unlock(&rsc->lock); } mtx_unlock(&ctx->lock); |