From 5935edd47c3b2a7a3047da5ad03c4d82e082628b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 27 Jan 2015 14:52:37 +0000 Subject: [PATCH] radeonsi: Avoid leaking memory when rebuilding shader states MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Michel Dänzer --- src/gallium/drivers/radeonsi/si_pm4.c | 12 ++++++++---- src/gallium/drivers/radeonsi/si_pm4.h | 1 + src/gallium/drivers/radeonsi/si_state_shaders.c | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_pm4.c b/src/gallium/drivers/radeonsi/si_pm4.c index 5edf15218f6..e9b9a5f556a 100644 --- a/src/gallium/drivers/radeonsi/si_pm4.c +++ b/src/gallium/drivers/radeonsi/si_pm4.c @@ -103,6 +103,13 @@ void si_pm4_add_bo(struct si_pm4_state *state, state->bo_priority[idx] = priority; } +void si_pm4_free_state_simple(struct si_pm4_state *state) +{ + for (int i = 0; i < state->nbo; ++i) + r600_resource_reference(&state->bo[i], NULL); + FREE(state); +} + void si_pm4_free_state(struct si_context *sctx, struct si_pm4_state *state, unsigned idx) @@ -114,10 +121,7 @@ void si_pm4_free_state(struct si_context *sctx, sctx->emitted.array[idx] = NULL; } - for (int i = 0; i < state->nbo; ++i) { - r600_resource_reference(&state->bo[i], NULL); - } - FREE(state); + si_pm4_free_state_simple(state); } unsigned si_pm4_dirty_dw(struct si_context *sctx) diff --git a/src/gallium/drivers/radeonsi/si_pm4.h b/src/gallium/drivers/radeonsi/si_pm4.h index 8680a9ef11c..bfb55629581 100644 --- a/src/gallium/drivers/radeonsi/si_pm4.h +++ b/src/gallium/drivers/radeonsi/si_pm4.h @@ -71,6 +71,7 @@ void si_pm4_add_bo(struct si_pm4_state *state, enum radeon_bo_usage usage, enum radeon_bo_priority priority); +void si_pm4_free_state_simple(struct si_pm4_state *state); void si_pm4_free_state(struct si_context *sctx, struct si_pm4_state *state, unsigned idx); diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index 887680f7b55..3249bcc5aa6 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -316,6 +316,10 @@ static void si_shader_ps(struct si_shader *shader) static void si_shader_init_pm4_state(struct si_shader *shader) { + + if (shader->pm4) + si_pm4_free_state_simple(shader->pm4); + switch (shader->selector->type) { case PIPE_SHADER_VERTEX: if (shader->key.vs.as_es) -- 2.30.2