freedreno: add screen lock wrappers
authorRob Clark <robdclark@chromium.org>
Tue, 28 Apr 2020 20:04:16 +0000 (13:04 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 20:37:00 +0000 (20:37 +0000)
This will make it easier to swap out to simple_mtx_t

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4810>

src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
src/gallium/drivers/freedreno/freedreno_batch.c
src/gallium/drivers/freedreno/freedreno_batch_cache.c
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_gmem.c
src/gallium/drivers/freedreno/freedreno_query_acc.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_screen.h

index 2da8438fbc387d4fc2875c5dd30b284f15c65041..21d5249451bae40982c0d515c2110707a72c0a29 100644 (file)
@@ -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);
 
index 082329eb59c50171a3f45c310a5628b64bf29186..fcb11546b814150349b87f8b12d475443f3aedb9 100644 (file)
@@ -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);
index f86e75e8b8998136bb02cbb9f6e1eeaa5f15b9c0..9edca679449a36c04883d502029d854641a122da 100644 (file)
@@ -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;
 }
index 529b58e8b54a6a0cc669babbdd1b60cc2b5fbcc5..7c9eb4186b2c3cbfb69c9500f7f6726f1e10906d 100644 (file)
@@ -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;
 
index b920c01f7c65a1466e95c0ecbdfec8f03e9d8cc7..3b422ffca649bff7b518778e60ea1c10778839aa 100644 (file)
@@ -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: */
index 0ba2106c0cc5536dd4a4dc2f211edcdc80c132f0..b36e89dcb0172336b9bea8f4689de2696070c3b5 100644 (file)
@@ -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);
index fee9ea2d747d9fbc156fe77d32ec832380a47c64..e3065f8671ebf503bd9510e9e26aeff69e0ea6c5 100644 (file)
@@ -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;
 }
index 5bc10bce6353694dc67af9aa514bc9b7434e940f..89312ed14c1c05c61c238a0b10a60536009dbd06 100644 (file)
@@ -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
index 25793a71859ef1c92da6399d61006f22819da246..68ecba242735cd188eb6a29a9fcf63754275dda0 100644 (file)
@@ -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);
index c46d1c8793dbbde12f02f3c3c4e4f3bee00bae6b..6370b310b2bb5157139e131af3078008bf144251 100644 (file)
@@ -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,