From: Alyssa Rosenzweig Date: Fri, 3 Feb 2023 20:32:19 +0000 (-0500) Subject: asahi: Don't leak shader NIR X-Git-Tag: upstream/23.3.3~13635 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1a64656446e43cc26b6f7cde16b2d265120d3dd;p=platform%2Fupstream%2Fmesa.git asahi: Don't leak shader NIR create_shader_state passes ownership of the NIR to the driver, so we need to free it when we destroy the shader CSO later. Use ralloc to manage this in a uniform way between graphics and compute. Strategy from Panfrost. Signed-off-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index b5d6c6c..cca83e7 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1400,7 +1400,8 @@ static void * agx_create_shader_state(struct pipe_context *pctx, const struct pipe_shader_state *cso) { - struct agx_uncompiled_shader *so = CALLOC_STRUCT(agx_uncompiled_shader); + struct agx_uncompiled_shader *so = + rzalloc(NULL, struct agx_uncompiled_shader); struct agx_device *dev = agx_device(pctx->screen); if (!so) @@ -1412,6 +1413,11 @@ agx_create_shader_state(struct pipe_context *pctx, ? cso->ir.nir : tgsi_to_nir(cso->tokens, pctx->screen, false); + /* The driver gets ownership of the nir_shader for graphics. The NIR is + * ralloc'd. Free the NIR when we free the uncompiled shader. + */ + ralloc_steal(so, nir); + if (nir->info.stage == MESA_SHADER_VERTEX) { so->variants = _mesa_hash_table_create(NULL, asahi_vs_shader_key_hash, asahi_vs_shader_key_equal); @@ -1467,7 +1473,8 @@ static void * agx_create_compute_state(struct pipe_context *pctx, const struct pipe_compute_state *cso) { - struct agx_uncompiled_shader *so = CALLOC_STRUCT(agx_uncompiled_shader); + struct agx_uncompiled_shader *so = + rzalloc(NULL, struct agx_uncompiled_shader); if (!so) return NULL; @@ -1609,7 +1616,7 @@ agx_delete_shader_state(struct pipe_context *ctx, void *cso) { struct agx_uncompiled_shader *so = cso; _mesa_hash_table_destroy(so->variants, agx_delete_compiled_shader); - free(so); + ralloc_free(so); } static uint32_t