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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21062>
This commit is contained in:
Alyssa Rosenzweig 2023-02-03 15:32:19 -05:00 committed by Marge Bot
parent 227d4f6d75
commit c1a6465644

View file

@ -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