diff options
Diffstat (limited to 'lib/mesa/src/gallium/drivers')
7 files changed, 76 insertions, 35 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); diff --git a/lib/mesa/src/gallium/drivers/freedreno/freedreno_resource.c b/lib/mesa/src/gallium/drivers/freedreno/freedreno_resource.c index c9e408fe9..e6016189e 100644 --- a/lib/mesa/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/lib/mesa/src/gallium/drivers/freedreno/freedreno_resource.c @@ -216,6 +216,9 @@ do_blit(struct fd_context *ctx, const struct pipe_blit_info *blit, bool fallback } } +static void +flush_resource(struct fd_context *ctx, struct fd_resource *rsc, unsigned usage); + /** * @rsc: the resource to shadow * @level: the level to discard (if box != NULL, otherwise ignored) @@ -233,6 +236,21 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc, if (prsc->next) return false; + /* If you have a sequence where there is a single rsc associated + * with the current render target, and then you end up shadowing + * that same rsc on the 3d pipe (u_blitter), because of how we + * swap the new shadow and rsc before the back-blit, you could end + * up confusing things into thinking that u_blitter's framebuffer + * state is the same as the current framebuffer state, which has + * the result of blitting to rsc rather than shadow. + * + * Normally we wouldn't want to unconditionally trigger a flush, + * since that defeats the purpose of shadowing, but this is a + * case where we'd have to flush anyways. + */ + if (rsc->write_batch == ctx->batch) + flush_resource(ctx, rsc, 0); + /* TODO: somehow munge dimensions and format to copy unsupported * render target format to something that is supported? */ diff --git a/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.c b/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.c index e0420934c..81614cbfb 100644 --- a/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.c +++ b/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.c @@ -885,7 +885,7 @@ static void si_disk_cache_create(struct si_screen *sscreen) disk_cache_format_hex_id(cache_id, sha1, 20 * 2); /* These flags affect shader compilation. */ -#define ALL_FLAGS (DBG(GISEL)) +#define ALL_FLAGS (DBG(GISEL) | DBG(CLAMP_DIV_BY_ZERO)) uint64_t shader_debug_flags = sscreen->debug_flags & ALL_FLAGS; /* Add the high bits of 32-bit addresses, which affects @@ -1002,6 +1002,9 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, #include "si_debug_options.h" } + if (sscreen->options.clamp_div_by_zero) + sscreen->debug_flags |= DBG(CLAMP_DIV_BY_ZERO); + si_disk_cache_create(sscreen); /* Determine the number of shader compiler threads. */ diff --git a/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.h b/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.h index de4f0e342..2b576a8fe 100644 --- a/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.h +++ b/lib/mesa/src/gallium/drivers/radeonsi/si_pipe.h @@ -159,6 +159,7 @@ enum DBG_W64_GE, DBG_W64_PS, DBG_W64_CS, + DBG_CLAMP_DIV_BY_ZERO, /* Shader compiler options (with no effect on the shader cache): */ DBG_CHECK_IR, |