radeonsi: don't re-create shader PM4 states after scratch buffer update
authorMarek Olšák <marek.olsak@amd.com>
Sat, 11 Jun 2016 19:07:14 +0000 (21:07 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 4 Oct 2016 14:12:05 +0000 (16:12 +0200)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
src/gallium/drivers/radeonsi/si_pm4.c
src/gallium/drivers/radeonsi/si_pm4.h
src/gallium/drivers/radeonsi/si_state_shaders.c

index c3032fc45b547594d8a9905bbe5df9529c8bf812..386d0935e83303824119a164c4f2b9a7f6d0b72d 100644 (file)
@@ -103,11 +103,18 @@ 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)
+void si_pm4_clear_state(struct si_pm4_state *state)
 {
        for (int i = 0; i < state->nbo; ++i)
                r600_resource_reference(&state->bo[i], NULL);
        r600_resource_reference(&state->indirect_buffer, NULL);
+       state->nbo = 0;
+       state->ndw = 0;
+}
+
+void si_pm4_free_state_simple(struct si_pm4_state *state)
+{
+       si_pm4_clear_state(state);
        FREE(state);
 }
 
index 35fa6c3a16f298efd8f05c249a4cab95edde1e52..9b02a8025a675b26d35014399433a08fb6e63afd 100644 (file)
@@ -71,6 +71,7 @@ void si_pm4_add_bo(struct si_pm4_state *state,
 void si_pm4_upload_indirect_buffer(struct si_context *sctx,
                                   struct si_pm4_state *state);
 
+void si_pm4_clear_state(struct si_pm4_state *state);
 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,
index 816aadcc4ff3375633c5f3842e22fa9d469c0dab..acbcebaecd9543b95520960e73ef0044546cfdf2 100644 (file)
@@ -329,13 +329,23 @@ static void si_set_tesseval_regs(struct si_screen *sscreen,
                       S_028B6C_DISTRIBUTION_MODE(distribution_mode));
 }
 
+static struct si_pm4_state *si_get_shader_pm4_state(struct si_shader *shader)
+{
+       if (shader->pm4)
+               si_pm4_clear_state(shader->pm4);
+       else
+               shader->pm4 = CALLOC_STRUCT(si_pm4_state);
+
+       return shader->pm4;
+}
+
 static void si_shader_ls(struct si_shader *shader)
 {
        struct si_pm4_state *pm4;
        unsigned vgpr_comp_cnt;
        uint64_t va;
 
-       pm4 = shader->pm4 = CALLOC_STRUCT(si_pm4_state);
+       pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
 
@@ -363,7 +373,7 @@ static void si_shader_hs(struct si_shader *shader)
        struct si_pm4_state *pm4;
        uint64_t va;
 
-       pm4 = shader->pm4 = CALLOC_STRUCT(si_pm4_state);
+       pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
 
@@ -391,8 +401,7 @@ static void si_shader_es(struct si_screen *sscreen, struct si_shader *shader)
        uint64_t va;
        unsigned oc_lds_en;
 
-       pm4 = shader->pm4 = CALLOC_STRUCT(si_pm4_state);
-
+       pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
 
@@ -467,8 +476,7 @@ static void si_shader_gs(struct si_shader *shader)
        /* The GSVS_RING_ITEMSIZE register takes 15 bits */
        assert(gsvs_itemsize < (1 << 15));
 
-       pm4 = shader->pm4 = CALLOC_STRUCT(si_pm4_state);
-
+       pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
 
@@ -525,8 +533,7 @@ static void si_shader_vs(struct si_screen *sscreen, struct si_shader *shader,
           shader->selector->info.properties[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION];
        bool enable_prim_id = si_vs_exports_prim_id(shader);
 
-       pm4 = shader->pm4 = CALLOC_STRUCT(si_pm4_state);
-
+       pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
 
@@ -689,8 +696,7 @@ static void si_shader_ps(struct si_shader *shader)
               G_0286CC_LINEAR_CENTROID_ENA(input_ena) ||
               G_0286CC_LINE_STIPPLE_TEX_ENA(input_ena));
 
-       pm4 = shader->pm4 = CALLOC_STRUCT(si_pm4_state);
-
+       pm4 = si_get_shader_pm4_state(shader);
        if (!pm4)
                return;
 
@@ -791,10 +797,6 @@ static void si_shader_ps(struct si_shader *shader)
 static void si_shader_init_pm4_state(struct si_screen *sscreen,
                                      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_ls)