From 6ad64387dd065560035917a898e036af35b90da5 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Wed, 15 Feb 2023 19:46:37 +0900 Subject: [PATCH] asahi: Do not use memctx for pools / meta cache ralloc is not thread-safe, so we can't use dev->memctx for allocating context-specific things without locking. On top of that, we always need to explicitly clean up pools anyway since we need to unref the BOs, so there is no point to using a memctx. And since pools need to be explicitly cleaned up, the meta cache code needs explicit cleanup, so add that and drop memctx from there too. Signed-off-by: Asahi Lina Part-of: --- src/asahi/lib/agx_meta.c | 13 ++++++++++--- src/asahi/lib/agx_meta.h | 4 ++-- src/asahi/lib/pool.c | 2 +- src/gallium/drivers/asahi/agx_pipe.c | 4 +++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/asahi/lib/agx_meta.c b/src/asahi/lib/agx_meta.c index b73d2ac..7d842e7 100644 --- a/src/asahi/lib/agx_meta.c +++ b/src/asahi/lib/agx_meta.c @@ -166,9 +166,16 @@ key_compare(const void *a, const void *b) } void -agx_meta_init(struct agx_meta_cache *cache, struct agx_device *dev, - void *memctx) +agx_meta_init(struct agx_meta_cache *cache, struct agx_device *dev) { agx_pool_init(&cache->pool, dev, AGX_BO_EXEC | AGX_BO_LOW_VA, true); - cache->ht = _mesa_hash_table_create(memctx, key_hash, key_compare); + cache->ht = _mesa_hash_table_create(NULL, key_hash, key_compare); +} + +void +agx_meta_cleanup(struct agx_meta_cache *cache) +{ + agx_pool_cleanup(&cache->pool); + _mesa_hash_table_destroy(cache->ht, NULL); + cache->ht = NULL; } diff --git a/src/asahi/lib/agx_meta.h b/src/asahi/lib/agx_meta.h index a58f611..8bc84a9 100644 --- a/src/asahi/lib/agx_meta.h +++ b/src/asahi/lib/agx_meta.h @@ -39,7 +39,7 @@ struct agx_meta_shader { struct agx_meta_shader *agx_get_meta_shader(struct agx_meta_cache *cache, struct agx_meta_key *key); -void agx_meta_init(struct agx_meta_cache *cache, struct agx_device *dev, - void *memctx); +void agx_meta_init(struct agx_meta_cache *cache, struct agx_device *dev); +void agx_meta_cleanup(struct agx_meta_cache *cache); #endif diff --git a/src/asahi/lib/pool.c b/src/asahi/lib/pool.c index 6291ea7..ba12e18 100644 --- a/src/asahi/lib/pool.c +++ b/src/asahi/lib/pool.c @@ -53,7 +53,7 @@ agx_pool_init(struct agx_pool *pool, struct agx_device *dev, memset(pool, 0, sizeof(*pool)); pool->dev = dev; pool->create_flags = create_flags; - util_dynarray_init(&pool->bos, dev->memctx); + util_dynarray_init(&pool->bos, NULL); if (prealloc) agx_pool_alloc_backing(pool, POOL_SLAB_SIZE); diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index aea0f18..8108706 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -1103,6 +1103,8 @@ agx_destroy_context(struct pipe_context *pctx) util_unreference_framebuffer_state(&ctx->framebuffer); + agx_meta_cleanup(&ctx->meta); + ralloc_free(ctx); } @@ -1167,7 +1169,7 @@ agx_create_context(struct pipe_screen *screen, void *priv, unsigned flags) agx_init_state_functions(pctx); agx_init_query_functions(pctx); - agx_meta_init(&ctx->meta, agx_device(screen), ctx); + agx_meta_init(&ctx->meta, agx_device(screen)); ctx->blitter = util_blitter_create(pctx); -- 2.7.4