From dbc33e8854e1c700a2c352322d8ee1d62c95fbec Mon Sep 17 00:00:00 2001 From: Boris Brezillon <boris.brezillon@collabora.com> Date: Thu, 8 Oct 2020 10:20:45 +0200 Subject: [PATCH] panfrost: Don't leak NIR blend shaders Right now we create shaders that are not attached to any memory context, leading to memory leaks. Ideally, we should free the NIR shader as soon as we've turned it into a binary, but there's no function explicitly destroy a shader. Let's attach those to the blend state so they get destroyed when this state is freed. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7066> --- src/gallium/drivers/panfrost/pan_blend_cso.c | 2 +- src/gallium/drivers/panfrost/pan_blend_shaders.c | 7 +++---- src/gallium/drivers/panfrost/pan_blend_shaders.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_blend_cso.c b/src/gallium/drivers/panfrost/pan_blend_cso.c index 4b724e2cc3211..a334199fbf124 100644 --- a/src/gallium/drivers/panfrost/pan_blend_cso.c +++ b/src/gallium/drivers/panfrost/pan_blend_cso.c @@ -89,7 +89,7 @@ panfrost_get_blend_shader( /* Cache miss. Build one instead, cache it, and go */ struct panfrost_blend_shader generated = - panfrost_compile_blend_shader(ctx, &blend->base, fmt, rt); + panfrost_compile_blend_shader(ctx, blend, fmt, rt); shader = mem_dup(&generated, sizeof(generated)); _mesa_hash_table_u64_insert(shaders, key, shader); diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c index 8564fa0eaf9ab..bfaf47491f2d3 100644 --- a/src/gallium/drivers/panfrost/pan_blend_shaders.c +++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c @@ -132,7 +132,7 @@ nir_iclamp(nir_builder *b, nir_ssa_def *v, int32_t lo, int32_t hi) struct panfrost_blend_shader panfrost_compile_blend_shader( struct panfrost_context *ctx, - struct pipe_blend_state *cso, + struct panfrost_blend_state *state, enum pipe_format format, unsigned rt) { @@ -143,7 +143,7 @@ panfrost_compile_blend_shader( /* Build the shader */ - nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_FRAGMENT, &midgard_nir_options, NULL); + nir_shader *shader = nir_shader_create(state, MESA_SHADER_FRAGMENT, &midgard_nir_options, NULL); nir_function *fn = nir_function_create(shader, "main"); nir_function_impl *impl = nir_function_impl_create(fn); @@ -201,8 +201,7 @@ panfrost_compile_blend_shader( /* Build a trivial blend shader */ nir_store_var(b, c_out, s_src[0], 0xFF); - nir_lower_blend_options options = - nir_make_options(cso, rt); + nir_lower_blend_options options = nir_make_options(&state->base, rt); options.format = format; options.src1 = s_src[1]; diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.h b/src/gallium/drivers/panfrost/pan_blend_shaders.h index cd3237684e2fd..40185cd943929 100644 --- a/src/gallium/drivers/panfrost/pan_blend_shaders.h +++ b/src/gallium/drivers/panfrost/pan_blend_shaders.h @@ -34,7 +34,7 @@ struct panfrost_blend_shader panfrost_compile_blend_shader( struct panfrost_context *ctx, - struct pipe_blend_state *cso, + struct panfrost_blend_state *state, enum pipe_format format, unsigned rt); -- GitLab