[Mesa-dev] [PATCH 11/18] radeonsi: emit primitive restart only if it changes

Marek Olšák maraeo at gmail.com
Tue Dec 9 03:39:59 PST 2014


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/drivers/radeonsi/si_hw_context.c |  2 ++
 src/gallium/drivers/radeonsi/si_pipe.h       |  9 ++++++---
 src/gallium/drivers/radeonsi/si_state_draw.c | 16 ++++++++++++++--
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_hw_context.c b/src/gallium/drivers/radeonsi/si_hw_context.c
index 5d46365..a7e29b1 100644
--- a/src/gallium/drivers/radeonsi/si_hw_context.c
+++ b/src/gallium/drivers/radeonsi/si_hw_context.c
@@ -158,4 +158,6 @@ void si_begin_new_cs(struct si_context *ctx)
 	ctx->last_base_vertex = SI_BASE_VERTEX_UNKNOWN;
 	ctx->last_start_instance = -1; /* reset to an unknown value */
 	ctx->last_sh_base_reg = -1; /* reset to an unknown value */
+	ctx->last_primitive_restart_en = -1;
+	ctx->last_restart_index = SI_RESTART_INDEX_UNKNOWN;
 }
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index cc497af..b4a1ea0 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -34,10 +34,11 @@
 #define SI_BIG_ENDIAN 0
 #endif
 
-/* The base vertex can be any number, but we must pick one which
- * will mean "unknown" for the purpose of state tracking and the number
- * shouldn't be a commonly-used one. */
+/* The base vertex and primitive restartcan be any number, but we must pick
+ * one which will mean "unknown" for the purpose of state tracking and
+ * the number shouldn't be a commonly-used one. */
 #define SI_BASE_VERTEX_UNKNOWN INT_MIN
+#define SI_RESTART_INDEX_UNKNOWN INT_MIN
 
 #define SI_TRACE_CS 0
 #define SI_TRACE_CS_DWORDS		6
@@ -179,6 +180,8 @@ struct si_context {
 	int			last_base_vertex;
 	int			last_start_instance;
 	int			last_sh_base_reg;
+	int			last_primitive_restart_en;
+	int			last_restart_index;
 };
 
 /* si_blit.c */
diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c
index 3e581ab..fedf19b 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.c
+++ b/src/gallium/drivers/radeonsi/si_state_draw.c
@@ -193,8 +193,20 @@ static void si_emit_draw_registers(struct si_context *sctx,
 	}
 
 	r600_write_context_reg(cs, R_028A6C_VGT_GS_OUT_PRIM_TYPE, gs_out_prim);
-	r600_write_context_reg(cs, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX, info->restart_index);
-	r600_write_context_reg(cs, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN, info->primitive_restart);
+
+	/* Primitive restart. */
+	if (info->primitive_restart != sctx->last_primitive_restart_en) {
+		r600_write_context_reg(cs, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN, info->primitive_restart);
+		sctx->last_primitive_restart_en = info->primitive_restart;
+
+		if (info->primitive_restart &&
+		    (info->restart_index != sctx->last_restart_index ||
+		     sctx->last_restart_index == SI_RESTART_INDEX_UNKNOWN)) {
+			r600_write_context_reg(cs, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX,
+					       info->restart_index);
+			sctx->last_restart_index = info->restart_index;
+		}
+	}
 }
 
 static void si_emit_draw_packets(struct si_context *sctx,
-- 
2.1.0



More information about the mesa-dev mailing list