[Mesa-dev] [PATCH 11/16] radeonsi: Simplify shader PM4 state handling

Michel Dänzer michel at daenzer.net
Fri Jan 24 01:33:23 PST 2014


From: Michel Dänzer <michel.daenzer at amd.com>

Just always bind the current states before drawing.

Besides the simplification, as a bonus this makes sure the VS hardware
shader stage always uses the GS copy shader when a geometry shader is
active, fixing a number of GS related piglit tests.

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/gallium/drivers/radeonsi/si_state.c      | 23 ++----------
 src/gallium/drivers/radeonsi/si_state.h      |  3 +-
 src/gallium/drivers/radeonsi/si_state_draw.c | 56 +++++++++-------------------
 3 files changed, 21 insertions(+), 61 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index 23667e7..03d524d 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -2190,11 +2190,9 @@ static INLINE void si_shader_selector_key(struct pipe_context *ctx,
 	}
 }
 
-/* Select the hw shader variant depending on the current state.
- * (*dirty) is set to 1 if current variant was changed */
+/* Select the hw shader variant depending on the current state. */
 int si_shader_select(struct pipe_context *ctx,
-		     struct si_pipe_shader_selector *sel,
-		     unsigned *dirty)
+		     struct si_pipe_shader_selector *sel)
 {
 	union si_shader_key key;
 	struct si_pipe_shader * shader = NULL;
@@ -2246,10 +2244,6 @@ int si_shader_select(struct pipe_context *ctx,
 		sel->num_shaders++;
 	}
 
-	if (dirty)
-		*dirty = 1;
-
-
 	return 0;
 }
 
@@ -2271,7 +2265,7 @@ static void *si_create_shader_state(struct pipe_context *ctx,
 		sel->fs_write_all = info.color0_writes_all_cbufs;
 	}
 
-	r = si_shader_select(ctx, sel, NULL);
+	r = si_shader_select(ctx, sel);
 	if (r) {
 	    free(sel);
 	    return NULL;
@@ -2314,9 +2308,6 @@ static void si_bind_vs_shader(struct pipe_context *ctx, void *state)
 		return;
 
 	sctx->vs_shader = sel;
-	si_pm4_bind_state(sctx, vs, sel->current->pm4);
-	sctx->b.streamout.stride_in_dw = sel->so.stride;
-	sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
 }
 
 #if HAVE_LLVM >= 0x0305
@@ -2330,12 +2321,6 @@ static void si_bind_gs_shader(struct pipe_context *ctx, void *state)
 		return;
 
 	sctx->gs_shader = sel;
-
-	if (sel && sel->current) {
-		si_pm4_bind_state(sctx, gs, sel->current->pm4);
-		sctx->b.streamout.stride_in_dw = sel->so.stride;
-		sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
-	}
 }
 
 #endif
@@ -2352,8 +2337,6 @@ static void si_bind_ps_shader(struct pipe_context *ctx, void *state)
 		sel = sctx->dummy_pixel_shader;
 
 	sctx->ps_shader = sel;
-	si_pm4_bind_state(sctx, ps, sel->current->pm4);
-	sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
 }
 
 static void si_delete_shader_selector(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h
index 7f40afb..06c0840 100644
--- a/src/gallium/drivers/radeonsi/si_state.h
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -222,8 +222,7 @@ boolean si_is_format_supported(struct pipe_screen *screen,
                                unsigned sample_count,
                                unsigned usage);
 int si_shader_select(struct pipe_context *ctx,
-		     struct si_pipe_shader_selector *sel,
-		     unsigned *dirty);
+		     struct si_pipe_shader_selector *sel);
 void si_init_state_functions(struct si_context *sctx);
 void si_init_config(struct si_context *sctx);
 
diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c
index 6f485e5..02526cb 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.c
+++ b/src/gallium/drivers/radeonsi/si_state_draw.c
@@ -100,7 +100,6 @@ static void si_pipe_shader_es(struct pipe_context *ctx, struct si_pipe_shader *s
 	si_pm4_set_reg(pm4, R_00B32C_SPI_SHADER_PGM_RSRC2_ES,
 		       S_00B32C_USER_SGPR(num_user_sgprs));
 
-	si_pm4_bind_state(sctx, es, shader->pm4);
 	sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
 }
 
@@ -175,7 +174,6 @@ static void si_pipe_shader_gs(struct pipe_context *ctx, struct si_pipe_shader *s
 	si_pm4_set_reg(pm4, R_00B22C_SPI_SHADER_PGM_RSRC2_GS,
 		       S_00B22C_USER_SGPR(num_user_sgprs));
 
-	si_pm4_bind_state(sctx, gs, shader->pm4);
 	sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
 }
 
@@ -254,7 +252,6 @@ static void si_pipe_shader_vs(struct pipe_context *ctx, struct si_pipe_shader *s
 		       S_00B12C_SO_BASE3_EN(!!shader->selector->so.stride[3]) |
 		       S_00B12C_SO_EN(!!shader->selector->so.num_outputs));
 
-	si_pm4_bind_state(sctx, vs, shader->pm4);
 	sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
 }
 
@@ -370,7 +367,6 @@ static void si_pipe_shader_ps(struct pipe_context *ctx, struct si_pipe_shader *s
 
 	shader->cb0_is_integer = sctx->fb_cb0_is_integer;
 	shader->sprite_coord_enable = sctx->sprite_coord_enable;
-	si_pm4_bind_state(sctx, ps, shader->pm4);
 	sctx->b.flags |= R600_CONTEXT_INV_SHADER_CACHE;
 }
 
@@ -589,7 +585,6 @@ static void si_init_gs_rings(struct si_context *sctx)
 static void si_update_derived_state(struct si_context *sctx)
 {
 	struct pipe_context * ctx = (struct pipe_context*)sctx;
-	unsigned vs_dirty = 0, ps_dirty = 0;
 
 	if (!sctx->blitter->running) {
 		/* Flush depth textures which need to be flushed. */
@@ -605,33 +600,25 @@ static void si_update_derived_state(struct si_context *sctx)
 
 #if HAVE_LLVM >= 0x0305
 	if (sctx->gs_shader) {
-		unsigned es_dirty = 0, gs_dirty = 0;
-
-		si_shader_select(ctx, sctx->gs_shader, &gs_dirty);
+		si_shader_select(ctx, sctx->gs_shader);
 
 		if (!sctx->gs_shader->current->pm4) {
 			si_pipe_shader_gs(ctx, sctx->gs_shader->current);
 			si_pipe_shader_vs(ctx,
 					  sctx->gs_shader->current->gs_copy_shader);
-			gs_dirty = 0;
 		}
 
-		if (gs_dirty) {
-			si_pm4_bind_state(sctx, gs, sctx->gs_shader->current->pm4);
-			si_pm4_bind_state(sctx, vs,
-					  sctx->gs_shader->current->gs_copy_shader->pm4);
-		}
+		si_pm4_bind_state(sctx, gs, sctx->gs_shader->current->pm4);
+		si_pm4_bind_state(sctx, vs, sctx->gs_shader->current->gs_copy_shader->pm4);
+
+		sctx->b.streamout.stride_in_dw = sctx->gs_shader->so.stride;
 
-		si_shader_select(ctx, sctx->vs_shader, &es_dirty);
+		si_shader_select(ctx, sctx->vs_shader);
 
-		if (!sctx->vs_shader->current->pm4) {
+		if (!sctx->vs_shader->current->pm4)
 			si_pipe_shader_es(ctx, sctx->vs_shader->current);
-			es_dirty = 0;
-		}
 
-		if (es_dirty) {
-			si_pm4_bind_state(sctx, es, sctx->vs_shader->current->pm4);
-		}
+		si_pm4_bind_state(sctx, es, sctx->vs_shader->current->pm4);
 
 		if (!sctx->gs_rings)
 			si_init_gs_rings(sctx);
@@ -656,16 +643,14 @@ static void si_update_derived_state(struct si_context *sctx)
 	} else
 #endif
 	{
-		si_shader_select(ctx, sctx->vs_shader, &vs_dirty);
+		si_shader_select(ctx, sctx->vs_shader);
 
-		if (!sctx->vs_shader->current->pm4) {
+		if (!sctx->vs_shader->current->pm4)
 			si_pipe_shader_vs(ctx, sctx->vs_shader->current);
-			vs_dirty = 0;
-		}
 
-		if (vs_dirty) {
-			si_pm4_bind_state(sctx, vs, sctx->vs_shader->current->pm4);
-		}
+		si_pm4_bind_state(sctx, vs, sctx->vs_shader->current->pm4);
+
+		sctx->b.streamout.stride_in_dw = sctx->vs_shader->so.stride;
 
 		if (!sctx->gs_off) {
 			sctx->gs_off = si_pm4_alloc_state(sctx);
@@ -682,20 +667,13 @@ static void si_update_derived_state(struct si_context *sctx)
 #endif
 	}
 
-	si_shader_select(ctx, sctx->ps_shader, &ps_dirty);
+	si_shader_select(ctx, sctx->ps_shader);
 
-	if (!sctx->ps_shader->current->pm4) {
-		si_pipe_shader_ps(ctx, sctx->ps_shader->current);
-		ps_dirty = 0;
-	}
-	if (sctx->ps_shader->current->cb0_is_integer != sctx->fb_cb0_is_integer) {
+	if (!sctx->ps_shader->current->pm4 ||
+	    sctx->ps_shader->current->cb0_is_integer != sctx->fb_cb0_is_integer)
 		si_pipe_shader_ps(ctx, sctx->ps_shader->current);
-		ps_dirty = 0;
-	}
 
-	if (ps_dirty) {
-		si_pm4_bind_state(sctx, ps, sctx->ps_shader->current->pm4);
-	}
+	si_pm4_bind_state(sctx, ps, sctx->ps_shader->current->pm4);
 
 	if (si_pm4_state_changed(sctx, ps) || si_pm4_state_changed(sctx, vs)) {
 		/* XXX: Emitting the PS state even when only the VS changed
-- 
1.8.5.3



More information about the mesa-dev mailing list