From: Rob Clark Date: Tue, 28 Apr 2020 20:04:16 +0000 (-0700) Subject: freedreno: add screen lock wrappers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=336a8cd82a4070674ecc056be0af791bf6c7d042;p=mesa.git freedreno: add screen lock wrappers This will make it easier to swap out to simple_mtx_t Signed-off-by: Rob Clark Reviewed-by: Eric Anholt Part-of: --- diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c b/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c index 2da8438fbc3..21d5249451b 100644 --- a/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c +++ b/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c @@ -638,12 +638,12 @@ handle_rgba_blit(struct fd_context *ctx, const struct pipe_blit_info *info) fd6_emit_restore(batch, batch->draw); fd6_emit_lrz_flush(batch->draw); - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); fd_batch_resource_used(batch, fd_resource(info->src.resource), false); fd_batch_resource_used(batch, fd_resource(info->dst.resource), true); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); fd_batch_set_stage(batch, FD_STAGE_BLIT); diff --git a/src/gallium/drivers/freedreno/freedreno_batch.c b/src/gallium/drivers/freedreno/freedreno_batch.c index 082329eb59c..fcb11546b81 100644 --- a/src/gallium/drivers/freedreno/freedreno_batch.c +++ b/src/gallium/drivers/freedreno/freedreno_batch.c @@ -218,7 +218,7 @@ batch_flush_reset_dependencies(struct fd_batch *batch, bool flush) static void batch_reset_resources_locked(struct fd_batch *batch) { - pipe_mutex_assert_locked(batch->ctx->screen->lock); + fd_screen_assert_locked(batch->ctx->screen); set_foreach(batch->resources, entry) { struct fd_resource *rsc = (struct fd_resource *)entry->key; @@ -233,9 +233,9 @@ batch_reset_resources_locked(struct fd_batch *batch) static void batch_reset_resources(struct fd_batch *batch) { - mtx_lock(&batch->ctx->screen->lock); + fd_screen_lock(batch->ctx->screen); batch_reset_resources_locked(batch); - mtx_unlock(&batch->ctx->screen->lock); + fd_screen_unlock(batch->ctx->screen); } static void @@ -314,9 +314,9 @@ batch_flush(struct fd_batch *batch) debug_assert(batch->reference.count > 0); - mtx_lock(&batch->ctx->screen->lock); + fd_screen_lock(batch->ctx->screen); fd_bc_invalidate_batch(batch, false); - mtx_unlock(&batch->ctx->screen->lock); + fd_screen_unlock(batch->ctx->screen); } /* NOTE: could drop the last ref to batch @@ -364,7 +364,7 @@ recursive_dependents_mask(struct fd_batch *batch) void fd_batch_add_dep(struct fd_batch *batch, struct fd_batch *dep) { - pipe_mutex_assert_locked(batch->ctx->screen->lock); + fd_screen_assert_locked(batch->ctx->screen); if (batch->dependents_mask & (1 << dep->idx)) return; @@ -384,9 +384,9 @@ flush_write_batch(struct fd_resource *rsc) struct fd_batch *b = NULL; fd_batch_reference_locked(&b, rsc->write_batch); - mtx_unlock(&b->ctx->screen->lock); + fd_screen_unlock(b->ctx->screen); fd_batch_flush(b); - mtx_lock(&b->ctx->screen->lock); + fd_screen_lock(b->ctx->screen); fd_bc_invalidate_batch(b, false); fd_batch_reference_locked(&b, NULL); @@ -395,7 +395,7 @@ flush_write_batch(struct fd_resource *rsc) void fd_batch_resource_used(struct fd_batch *batch, struct fd_resource *rsc, bool write) { - pipe_mutex_assert_locked(batch->ctx->screen->lock); + fd_screen_assert_locked(batch->ctx->screen); if (rsc->stencil) fd_batch_resource_used(batch, rsc->stencil, write); diff --git a/src/gallium/drivers/freedreno/freedreno_batch_cache.c b/src/gallium/drivers/freedreno/freedreno_batch_cache.c index f86e75e8b89..9edca679449 100644 --- a/src/gallium/drivers/freedreno/freedreno_batch_cache.c +++ b/src/gallium/drivers/freedreno/freedreno_batch_cache.c @@ -191,14 +191,14 @@ fd_bc_invalidate_context(struct fd_context *ctx) struct fd_batch_cache *cache = &ctx->screen->batch_cache; struct fd_batch *batch; - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); foreach_batch(batch, cache, cache->batch_mask) { if (batch->ctx == ctx) fd_bc_invalidate_batch(batch, true); } - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); } /** @@ -250,7 +250,7 @@ fd_bc_invalidate_resource(struct fd_resource *rsc, bool destroy) struct fd_screen *screen = fd_screen(rsc->base.screen); struct fd_batch *batch; - mtx_lock(&screen->lock); + fd_screen_lock(screen); if (destroy) { foreach_batch(batch, &screen->batch_cache, rsc->batch_mask) { @@ -267,7 +267,7 @@ fd_bc_invalidate_resource(struct fd_resource *rsc, bool destroy) rsc->bc_batch_mask = 0; - mtx_unlock(&screen->lock); + fd_screen_unlock(screen); } struct fd_batch * @@ -276,7 +276,7 @@ fd_bc_alloc_batch(struct fd_batch_cache *cache, struct fd_context *ctx, bool non struct fd_batch *batch; uint32_t idx; - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); while ((idx = ffs(~cache->batch_mask)) == 0) { #if 0 @@ -302,10 +302,10 @@ fd_bc_alloc_batch(struct fd_batch_cache *cache, struct fd_context *ctx, bool non /* we can drop lock temporarily here, since we hold a ref, * flush_batch won't disappear under us. */ - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); DBG("%p: too many batches! flush forced!", flush_batch); fd_batch_flush(flush_batch); - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); /* While the resources get cleaned up automatically, the flush_batch * doesn't get removed from the dependencies of other batches, so @@ -342,7 +342,7 @@ fd_bc_alloc_batch(struct fd_batch_cache *cache, struct fd_context *ctx, bool non cache->batches[idx] = batch; out: - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); return batch; } @@ -377,7 +377,7 @@ batch_from_key(struct fd_batch_cache *cache, struct key *key, if (!batch) return NULL; - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); _mesa_hash_table_insert_pre_hashed(cache->ht, hash, key, batch); batch->key = key; @@ -388,7 +388,7 @@ batch_from_key(struct fd_batch_cache *cache, struct key *key, rsc->bc_batch_mask = (1 << batch->idx); } - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); return batch; } diff --git a/src/gallium/drivers/freedreno/freedreno_context.c b/src/gallium/drivers/freedreno/freedreno_context.c index 529b58e8b54..7c9eb4186b2 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.c +++ b/src/gallium/drivers/freedreno/freedreno_context.c @@ -178,9 +178,9 @@ fd_context_destroy(struct pipe_context *pctx) DBG(""); - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); list_del(&ctx->node); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); fd_log_process(ctx, true); assert(list_is_empty(&ctx->log_chunks)); @@ -423,9 +423,9 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen, list_inithead(&ctx->acc_active_queries); list_inithead(&ctx->log_chunks); - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); list_add(&ctx->node, &ctx->screen->context_list); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); ctx->log_out = stdout; diff --git a/src/gallium/drivers/freedreno/freedreno_context.h b/src/gallium/drivers/freedreno/freedreno_context.h index b920c01f7c6..3b422ffca64 100644 --- a/src/gallium/drivers/freedreno/freedreno_context.h +++ b/src/gallium/drivers/freedreno/freedreno_context.h @@ -415,19 +415,19 @@ fd_context(struct pipe_context *pctx) static inline void fd_context_assert_locked(struct fd_context *ctx) { - pipe_mutex_assert_locked(ctx->screen->lock); + fd_screen_assert_locked(ctx->screen); } static inline void fd_context_lock(struct fd_context *ctx) { - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); } static inline void fd_context_unlock(struct fd_context *ctx) { - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); } /* mark all state dirty: */ diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c index 0ba2106c0cc..b36e89dcb01 100644 --- a/src/gallium/drivers/freedreno/freedreno_draw.c +++ b/src/gallium/drivers/freedreno/freedreno_draw.c @@ -129,7 +129,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info) * Figure out the buffers/features we need: */ - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); if (ctx->dirty & (FD_DIRTY_FRAMEBUFFER | FD_DIRTY_ZSA)) { if (fd_depth_enabled(ctx)) { @@ -255,7 +255,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info) list_for_each_entry(struct fd_acc_query, aq, &ctx->acc_active_queries, node) resource_written(batch, aq->prsc); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); batch->num_draws++; @@ -350,7 +350,7 @@ fd_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_ batch->resolve |= buffers; batch->needs_flush = true; - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); if (buffers & PIPE_CLEAR_COLOR) for (i = 0; i < pfb->nr_cbufs; i++) @@ -367,7 +367,7 @@ fd_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_ list_for_each_entry(struct fd_acc_query, aq, &ctx->acc_active_queries, node) resource_written(batch, aq->prsc); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); DBG("%p: %x %ux%u depth=%f, stencil=%u (%s/%s)", batch, buffers, pfb->width, pfb->height, depth, stencil, @@ -429,7 +429,7 @@ fd_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info) fd_batch_reference(&ctx->batch, batch); fd_context_all_dirty(ctx); - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); /* Mark SSBOs */ foreach_bit (i, so->enabled_mask & so->writable_mask) @@ -464,7 +464,7 @@ fd_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info) if (info->indirect) resource_read(batch, info->indirect); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); batch->needs_flush = true; ctx->launch_grid(ctx, info); diff --git a/src/gallium/drivers/freedreno/freedreno_gmem.c b/src/gallium/drivers/freedreno/freedreno_gmem.c index fee9ea2d747..e3065f8671e 100644 --- a/src/gallium/drivers/freedreno/freedreno_gmem.c +++ b/src/gallium/drivers/freedreno/freedreno_gmem.c @@ -343,7 +343,7 @@ __fd_gmem_destroy(struct fd_gmem_stateobj *gmem) { struct fd_gmem_cache *cache = &gmem->screen->gmem_cache; - pipe_mutex_assert_locked(gmem->screen->lock); + fd_screen_assert_locked(gmem->screen); _mesa_hash_table_remove_key(cache->ht, gmem->key); list_del(&gmem->node); @@ -420,7 +420,7 @@ lookup_gmem_state(struct fd_batch *batch, bool assume_zs) struct gmem_key *key = gmem_key_init(batch, assume_zs); uint32_t hash = gmem_key_hash(key); - mtx_lock(&screen->lock); + fd_screen_lock(screen); struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(cache->ht, hash, key); @@ -447,7 +447,7 @@ found: list_delinit(&gmem->node); list_add(&gmem->node, &cache->lru); - mtx_unlock(&screen->lock); + fd_screen_unlock(screen); return gmem; } @@ -621,9 +621,9 @@ fd_gmem_render_tiles(struct fd_batch *batch) render_tiles(batch, gmem); batch->gmem_state = NULL; - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); fd_gmem_reference(&gmem, NULL); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); ctx->stats.batch_gmem++; } @@ -642,9 +642,9 @@ fd_gmem_estimate_bins_per_pipe(struct fd_batch *batch) struct fd_gmem_stateobj *gmem = lookup_gmem_state(batch, !!pfb->zsbuf); unsigned nbins = gmem->maxpw * gmem->maxph; - mtx_lock(&screen->lock); + fd_screen_lock(screen); fd_gmem_reference(&gmem, NULL); - mtx_unlock(&screen->lock); + fd_screen_unlock(screen); return nbins; } diff --git a/src/gallium/drivers/freedreno/freedreno_query_acc.c b/src/gallium/drivers/freedreno/freedreno_query_acc.c index 5bc10bce635..89312ed14c1 100644 --- a/src/gallium/drivers/freedreno/freedreno_query_acc.c +++ b/src/gallium/drivers/freedreno/freedreno_query_acc.c @@ -87,9 +87,9 @@ fd_acc_query_resume(struct fd_acc_query *aq, struct fd_batch *batch) aq->batch = batch; p->resume(aq, aq->batch); - mtx_lock(&batch->ctx->screen->lock); + fd_screen_lock(batch->ctx->screen); fd_batch_resource_used(batch, fd_resource(aq->prsc), true); - mtx_unlock(&batch->ctx->screen->lock); + fd_screen_unlock(batch->ctx->screen); } static void diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 25793a71859..68ecba24273 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -153,7 +153,7 @@ rebind_resource(struct fd_resource *rsc) { struct fd_screen *screen = fd_screen(rsc->base.screen); - mtx_lock(&screen->lock); + fd_screen_lock(screen); fd_resource_lock(rsc); if (rsc->dirty) @@ -161,7 +161,7 @@ rebind_resource(struct fd_resource *rsc) rebind_resource_in_ctx(ctx, rsc); fd_resource_unlock(rsc); - mtx_unlock(&screen->lock); + fd_screen_unlock(screen); } static void @@ -269,7 +269,7 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc, fd_bc_invalidate_resource(rsc, false); rebind_resource(rsc); - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); /* Swap the backing bo's, so shadow becomes the old buffer, * blit from shadow to new buffer. From here on out, we @@ -303,7 +303,7 @@ fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc, } swap(rsc->batch_mask, shadow->batch_mask); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); struct pipe_blit_info blit = {}; blit.dst.resource = prsc; @@ -481,9 +481,9 @@ flush_resource(struct fd_context *ctx, struct fd_resource *rsc, unsigned usage) { struct fd_batch *write_batch = NULL; - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); fd_batch_reference_locked(&write_batch, rsc->write_batch); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); if (usage & PIPE_TRANSFER_WRITE) { struct fd_batch *batch, *batches[32] = {}; @@ -494,11 +494,11 @@ flush_resource(struct fd_context *ctx, struct fd_resource *rsc, unsigned usage) * to iterate the batches which reference this resource. So * we must first grab references under a lock, then flush. */ - mtx_lock(&ctx->screen->lock); + fd_screen_lock(ctx->screen); batch_mask = rsc->batch_mask; foreach_batch(batch, &ctx->screen->batch_cache, batch_mask) fd_batch_reference_locked(&batches[batch->idx], batch); - mtx_unlock(&ctx->screen->lock); + fd_screen_unlock(ctx->screen); foreach_batch(batch, &ctx->screen->batch_cache, batch_mask) fd_batch_flush(batch); diff --git a/src/gallium/drivers/freedreno/freedreno_screen.h b/src/gallium/drivers/freedreno/freedreno_screen.h index c46d1c8793d..6370b310b2b 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.h +++ b/src/gallium/drivers/freedreno/freedreno_screen.h @@ -134,6 +134,24 @@ fd_screen(struct pipe_screen *pscreen) return (struct fd_screen *)pscreen; } +static inline void +fd_screen_lock(struct fd_screen *screen) +{ + mtx_lock(&screen->lock); +} + +static inline void +fd_screen_unlock(struct fd_screen *screen) +{ + mtx_unlock(&screen->lock); +} + +static inline void +fd_screen_assert_locked(struct fd_screen *screen) +{ + pipe_mutex_assert_locked(screen->lock); +} + bool fd_screen_bo_get_handle(struct pipe_screen *pscreen, struct fd_bo *bo, struct renderonly_scanout *scanout,