X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fetnaviv%2Fetnaviv_resource.c;h=e2ef97f286fa89979139ba39e080e1826d83d19a;hp=be5d87168f1cebc0f7ead992b1d06db2f8090d6b;hb=60975ebe58ddb05beebbdd3850dc9d866aee5420;hpb=a949fa9d5df228244a44b1f5c8be635baa595d5e diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c b/src/gallium/drivers/etnaviv/etnaviv_resource.c index be5d87168f1..e2ef97f286f 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c +++ b/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) @@ -351,17 +352,13 @@ etna_resource_create(struct pipe_screen *pscreen, * and a texture-compatible base buffer in other cases * */ - if (templat->bind & (PIPE_BIND_SCANOUT | PIPE_BIND_DEPTH_STENCIL)) { if (screen->specs.pixel_pipes > 1 && !screen->specs.single_buffer) layout |= ETNA_LAYOUT_BIT_MULTI; if (screen->specs.can_supertile) layout |= ETNA_LAYOUT_BIT_SUPER; } else if (VIV_FEATURE(screen, chipMinorFeatures2, SUPERTILED_TEXTURE) && - /* RS can't tile 1 byte per pixel formats, will have to CPU tile, - * which doesn't support super-tiling - */ - util_format_get_blocksize(templat->format) > 1) { + etna_resource_hw_tileable(screen->specs.use_blt, templat)) { layout |= ETNA_LAYOUT_BIT_SUPER; } @@ -467,7 +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); @@ -486,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); } @@ -498,7 +500,6 @@ etna_resource_from_handle(struct pipe_screen *pscreen, struct etna_resource *rsc; struct etna_resource_level *level; struct pipe_resource *prsc; - struct pipe_resource *ptiled = NULL; DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, " "nr_samples=%u, usage=%u, bind=%x, flags=%x", @@ -563,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) @@ -572,8 +574,6 @@ etna_resource_from_handle(struct pipe_screen *pscreen, fail: etna_resource_destroy(pscreen, prsc); - if (ptiled) - etna_resource_destroy(pscreen, ptiled); return NULL; } @@ -609,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) @@ -650,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) { @@ -669,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; @@ -682,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); }