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>
This commit is contained in:
Boris Brezillon 2020-10-08 10:20:45 +02:00 committed by Marge Bot
parent 8a5b885c94
commit dbc33e8854
3 changed files with 5 additions and 6 deletions

View File

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

View File

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

View File

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