From dbc33e8854e1c700a2c352322d8ee1d62c95fbec Mon Sep 17 00:00:00 2001 From: Boris Brezillon 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 Reviewed-by: Alyssa Rosenzweig Part-of: --- 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 4b724e2cc32..a334199fbf1 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 8564fa0eaf9..bfaf47491f2 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 cd3237684e2..40185cd9439 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);