radeonsi: Avoid leaking memory when rebuilding shader states
authorMarek Olšák <marek.olsak@amd.com>
Tue, 27 Jan 2015 14:52:37 +0000 (14:52 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Wed, 28 Jan 2015 21:03:46 +0000 (21:03 +0000)
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeonsi/si_pm4.c
src/gallium/drivers/radeonsi/si_pm4.h
src/gallium/drivers/radeonsi/si_state_shaders.c

index 5edf15218f6ba2fbc9f6b661fe38003bf3ad8fae..e9b9a5f556a8dba27c8577cbf447d98fced02316 100644 (file)
@@ -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)
index 8680a9ef11c93bb7c2efd741185ab9ce07fd144b..bfb55629581736f9c2b25a413b2a54dcfbaf03ff 100644 (file)
@@ -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);
index 887680f7b55d2a380cb0e8281b61ab15039d5c14..3249bcc5aa645a1349193dc1329e54d29c41eadc 100644 (file)
@@ -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)