From 0803bef00675ddd90ca9365b733b222dbb58c373 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 12 Mar 2019 15:18:43 -0700 Subject: mesa/st: Fix leaks of TGSI tokens in VP variants. Starting a glxgears and closing it, I was seeing a lot of leaked TGSI for the fixed function VPs. v2: drop unused delete_ir() arg. Fixes: 3b4929ec6e64 ("st/mesa: Copy VP TGSI tokens if they exist, even for NIR shaders.") Reviewed-by: Kenneth Graunke --- src/mesa/state_tracker/st_program.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index ebedf4daa21..0df800a60e0 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -206,6 +206,22 @@ st_set_prog_affected_state_flags(struct gl_program *prog) } } +static void +delete_ir(struct pipe_shader_state *ir) +{ + if (ir->tokens) + ureg_free_tokens(ir->tokens); + + /* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on + * it has resulted in the driver taking ownership of the NIR. Those + * callers should be NULLing out the nir field in any pipe_shader_state + * that might have this called in order to indicate that. + * + * GLSL IR and ARB programs will have set gl_program->nir to the same + * shader as ir->ir.nir, so it will be freed by _mesa_delete_program(). + */ +} + /** * Delete a vertex program variant. Note the caller must unlink * the variant from the linked list. @@ -219,8 +235,7 @@ delete_vp_variant(struct st_context *st, struct st_vp_variant *vpv) if (vpv->draw_shader) draw_delete_vertex_shader( st->draw, vpv->draw_shader ); - if (((vpv->tgsi.type == PIPE_SHADER_IR_TGSI)) && vpv->tgsi.tokens) - ureg_free_tokens(vpv->tgsi.tokens); + delete_ir(&vpv->tgsi); free( vpv ); } @@ -244,10 +259,7 @@ st_release_vp_variants( struct st_context *st, stvp->variants = NULL; - if ((stvp->tgsi.type == PIPE_SHADER_IR_TGSI) && stvp->tgsi.tokens) { - tgsi_free_tokens(stvp->tgsi.tokens); - stvp->tgsi.tokens = NULL; - } + delete_ir(&stvp->tgsi); } @@ -281,10 +293,7 @@ st_release_fp_variants(struct st_context *st, struct st_fragment_program *stfp) stfp->variants = NULL; - if ((stfp->tgsi.type == PIPE_SHADER_IR_TGSI) && stfp->tgsi.tokens) { - ureg_free_tokens(stfp->tgsi.tokens); - stfp->tgsi.tokens = NULL; - } + delete_ir(&stfp->tgsi); } @@ -337,10 +346,7 @@ st_release_basic_variants(struct st_context *st, GLenum target, *variants = NULL; - if (tgsi->tokens) { - ureg_free_tokens(tgsi->tokens); - tgsi->tokens = NULL; - } + delete_ir(tgsi); } -- cgit v1.2.3