[Mesa-dev] [PATCH 2/2] r600g: enable DUAL_EXPORT mode when possible

Vadim Girlin vadimgirlin at gmail.com
Fri Jun 22 07:02:02 PDT 2012


It seems DUAL_EXPORT on evergreen may be enabled when all CBs use 16-bit export
mode (EXPORT_4C_16BPC), also there should be at least one CB, and the PS
shouldn't export depth/stencil. 

Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
---
 src/gallium/drivers/r600/evergreen_state.c   |   46 ++++++++++++++++++++++----
 src/gallium/drivers/r600/evergreend.h        |    7 ++++
 src/gallium/drivers/r600/r600_pipe.h         |    5 +++
 src/gallium/drivers/r600/r600_state_common.c |    3 ++
 4 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 3fe95e1..bddb67e 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -1458,7 +1458,6 @@ static void evergreen_cb(struct r600_context *rctx, struct r600_pipe_state *rsta
 	     (desc->channel[i].size < 17 &&
 	      desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT))) {
 		color_info |= S_028C70_SOURCE_FORMAT(V_028C70_EXPORT_4C_16BPC);
-		rctx->export_16bpc = true;
 	} else {
 		rctx->export_16bpc = false;
 	}
@@ -1661,6 +1660,7 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx,
 	struct r600_context *rctx = (struct r600_context *)ctx;
 	struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
 	uint32_t tl, br;
+	int i;
 
 	if (rstate == NULL)
 		return;
@@ -1674,10 +1674,16 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx,
 
 	/* build states */
 	rctx->have_depth_fb = 0;
+	rctx->export_16bpc = true;
 	rctx->nr_cbufs = state->nr_cbufs;
-	for (int i = 0; i < state->nr_cbufs; i++) {
+	for (i = 0; i < state->nr_cbufs; i++) {
 		evergreen_cb(rctx, rstate, state, i);
 	}
+
+	for (; i < 8 ; i++) {
+		r600_pipe_state_add_reg(rstate, R_028C70_CB_COLOR0_INFO + i * 0x3C, 0);
+	}
+
 	if (state->zsbuf) {
 		evergreen_db(rctx, rstate, state);
 	}
@@ -2585,6 +2591,7 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
 	int ninterp = 0;
 	boolean have_linear = FALSE, have_centroid = FALSE, have_perspective = FALSE;
 	unsigned spi_baryc_cntl, sid, tmp, idx = 0;
+	unsigned z_export = 0, stencil_export = 0;
 
 	rstate->nregs = 0;
 
@@ -2633,13 +2640,16 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
 
 	for (i = 0; i < rshader->noutput; i++) {
 		if (rshader->output[i].name == TGSI_SEMANTIC_POSITION)
-			db_shader_control |= S_02880C_Z_EXPORT_ENABLE(1);
+			z_export = 1;
 		if (rshader->output[i].name == TGSI_SEMANTIC_STENCIL)
-			db_shader_control |= S_02880C_STENCIL_EXPORT_ENABLE(1);
+			stencil_export = 1;
 	}
 	if (rshader->uses_kill)
 		db_shader_control |= S_02880C_KILL_ENABLE(1);
 
+	db_shader_control |= S_02880C_Z_EXPORT_ENABLE(z_export);
+	db_shader_control |= S_02880C_STENCIL_EXPORT_ENABLE(stencil_export);
+
 	exports_ps = 0;
 	for (i = 0; i < rshader->noutput; i++) {
 		if (rshader->output[i].name == TGSI_SEMANTIC_POSITION ||
@@ -2711,8 +2721,9 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
 	r600_pipe_state_add_reg(rstate,
 				R_02884C_SQ_PGM_EXPORTS_PS,
 				exports_ps);
-	r600_pipe_state_add_reg(rstate, R_02880C_DB_SHADER_CONTROL,
-				db_shader_control);
+
+	shader->db_shader_control = db_shader_control;
+	shader->ps_depth_export = z_export | stencil_export;
 
 	shader->sprite_coord_enable = rctx->sprite_coord_enable;
 	if (rctx->rasterizer)
@@ -2798,3 +2809,26 @@ void *evergreen_create_db_flush_dsa(struct r600_context *rctx)
 	/* Don't set the 'is_flush' flag in r600_pipe_dsa, evergreen doesn't need it. */
 	return rstate;
 }
+
+void evergreen_update_dual_export_state(struct r600_context * rctx)
+{
+	unsigned dual_export = rctx->export_16bpc && rctx->nr_cbufs &&
+			!rctx->ps_shader->ps_depth_export;
+
+	unsigned db_source_format = dual_export ? V_02880C_EXPORT_DB_TWO :
+			V_02880C_EXPORT_DB_FULL;
+
+	unsigned db_shader_control = rctx->ps_shader->db_shader_control |
+			S_02880C_DUAL_EXPORT_ENABLE(dual_export) |
+			S_02880C_DB_SOURCE_FORMAT(db_source_format);
+
+	if (db_shader_control != rctx->db_shader_control) {
+		struct r600_pipe_state rstate;
+
+		rctx->db_shader_control = db_shader_control;
+
+		rstate.nregs = 0;
+		r600_pipe_state_add_reg(&rstate, R_02880C_DB_SHADER_CONTROL, db_shader_control);
+		r600_context_pipe_state_set(rctx, &rstate);
+	}
+}
diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
index 5d57ce3..a067ad2 100644
--- a/src/gallium/drivers/r600/evergreend.h
+++ b/src/gallium/drivers/r600/evergreend.h
@@ -746,6 +746,13 @@
 #define   S_02880C_DUAL_EXPORT_ENABLE(x)               (((x) & 0x1) << 9)
 #define   G_02880C_DUAL_EXPORT_ENABLE(x)               (((x) >> 9) & 0x1)
 #define   C_02880C_DUAL_EXPORT_ENABLE                  0xFFFFFDFF
+#define   S_02880C_DB_SOURCE_FORMAT(x)                 (((x) & 0x3) << 13)
+#define   G_02880C_DB_SOURCE_FORMAT(x)                 (((x) >> 13) & 0x3)
+#define   C_02880C_DB_SOURCE_FORMAT                    0xFFFF9FFF
+#define     V_02880C_EXPORT_DB_FULL                    0x00
+#define     V_02880C_EXPORT_DB_FOUR16                  0x01
+#define     V_02880C_EXPORT_DB_TWO                     0x02
+
 #define R_028A00_PA_SU_POINT_SIZE                    0x028A00
 #define   S_028A00_HEIGHT(x)                           (((x) & 0xFFFF) << 0)
 #define   G_028A00_HEIGHT(x)                           (((x) >> 0) & 0xFFFF)
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index b5eff34..2c107c8 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -196,6 +196,8 @@ struct r600_pipe_shader {
 	unsigned	flatshade;
 	unsigned	pa_cl_vs_out_cntl;
 	unsigned        ps_cb_shader_mask;
+	unsigned		db_shader_control;
+	unsigned		ps_depth_export;
 	struct pipe_stream_output_info	so;
 };
 
@@ -265,6 +267,7 @@ struct r600_context {
 	unsigned			fb_cb_shader_mask;
 	unsigned			sx_alpha_test_control;
 	unsigned			cb_shader_mask;
+	unsigned			db_shader_control;
 	unsigned			cb_color_control;
 	unsigned			pa_sc_line_stipple;
 	unsigned			pa_cl_clip_cntl;
@@ -402,6 +405,8 @@ boolean evergreen_is_format_supported(struct pipe_screen *screen,
 				      unsigned sample_count,
 				      unsigned usage);
 
+void evergreen_update_dual_export_state(struct r600_context * rctx);
+
 /* r600_blit.c */
 void r600_init_blit_functions(struct r600_context *rctx);
 void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 36a891e..91387f9 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -711,6 +711,9 @@ static void r600_update_derived_state(struct r600_context *rctx)
 		r600_context_pipe_state_set(rctx, &rctx->ps_shader->rstate);
 	}
 
+	if (rctx->chip_class >= EVERGREEN)
+		evergreen_update_dual_export_state(rctx);
+
 	if (rctx->dual_src_blend)
 		rctx->cb_shader_mask = rctx->ps_shader->ps_cb_shader_mask | rctx->fb_cb_shader_mask;
 	else
-- 
1.7.10.4



More information about the mesa-dev mailing list