[Mesa-dev] [PATCH 2/3] r600g: introduce query state in new design

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Sat Sep 25 07:11:41 PDT 2010


created a new state to set some bits which are needed for queries.
---
 src/gallium/drivers/r600/evergreen_state.c |   19 ++++++++++++-
 src/gallium/drivers/r600/evergreend.h      |    2 +-
 src/gallium/drivers/r600/r600_pipe.h       |    4 +++
 src/gallium/drivers/r600/r600_state2.c     |   39 +++++++++++++++++++++++++--
 4 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index c54b78a..5026f21 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -213,7 +213,7 @@ static void *evergreen_create_dsa_state(struct pipe_context *ctx,
 	db_render_override = S_02800C_FORCE_HIZ_ENABLE(V_02800C_FORCE_DISABLE) |
 		S_02800C_FORCE_HIS_ENABLE0(V_02800C_FORCE_DISABLE) |
 		S_02800C_FORCE_HIS_ENABLE1(V_02800C_FORCE_DISABLE);
-	/* TODO db_render_override depends on query */
+
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028028_DB_STENCIL_CLEAR, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_02802C_DB_DEPTH_CLEAR, 0x3F800000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028410_SX_ALPHA_TEST_CONTROL, alpha_test_control, 0xFFFFFFFF, NULL);
@@ -226,9 +226,15 @@ static void *evergreen_create_dsa_state(struct pipe_context *ctx,
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028438_SX_ALPHA_REF, alpha_ref, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_0286DC_SPI_FOG_CNTL, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028800_DB_DEPTH_CONTROL, db_depth_control, 0xFFFFFFFF, NULL);
+	
+	/* masked bits are set by the shader state */
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_02880C_DB_SHADER_CONTROL, db_shader_control, 0xFFFFFFBE, NULL);
+	
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028000_DB_RENDER_CONTROL, db_render_control, 0xFFFFFFFF, NULL);
-	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_02800C_DB_RENDER_OVERRIDE, db_render_override, 0xFFFFFFFF, NULL);
+	
+	/* masked bits are set by the query state */
+	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_02800C_DB_RENDER_OVERRIDE, db_render_override, 0xFFFFFDFF, NULL);
+	
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028AC0_DB_SRESULTS_COMPARE_STATE0, 0x0, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028AC4_DB_SRESULTS_COMPARE_STATE1, 0x0, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, EVERGREEN_GROUP_CONTEXT, R_028AC8_DB_PRELOAD_CONTROL, 0x0, 0xFFFFFFFF, NULL);
@@ -1624,3 +1630,12 @@ void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader
 			R_0288A4_SQ_PGM_START_FS,
 			0x00000000, 0xFFFFFFFF, shader->bo);
 }
+
+void evergreen_init_query_states(struct r600_pipe_context *rctx)
+{
+	r600_pipe_state_add_reg(&rctx->query_state_enabled, EVERGREEN_GROUP_CONTEXT, R_028004_DB_COUNT_CONTROL, S_028004_PERFECT_ZPASS_COUNTS(1), 0xFFFFFFFF, NULL);
+	r600_pipe_state_add_reg(&rctx->query_state_enabled, EVERGREEN_GROUP_CONTEXT, R_02800C_DB_RENDER_OVERRIDE, S_02800C_NOOP_CULL_DISABLE(1), 0x00000200, NULL);
+
+	r600_pipe_state_add_reg(&rctx->query_state_enabled, EVERGREEN_GROUP_CONTEXT, R_028004_DB_COUNT_CONTROL, 0, 0xFFFFFFFF, NULL);
+	r600_pipe_state_add_reg(&rctx->query_state_disabled, EVERGREEN_GROUP_CONTEXT, R_02800C_DB_RENDER_OVERRIDE, 0, 0x00000200, NULL);
+}
diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
index 0a0a91e..5b47ed4 100644
--- a/src/gallium/drivers/r600/evergreend.h
+++ b/src/gallium/drivers/r600/evergreend.h
@@ -1411,7 +1411,7 @@
 #define   S_028000_STENCIL_COMPRESS_DISABLE(x)         (((x) & 0x1) << 5)
 #define   S_028000_DEPTH_COMPRESS_DISABLE(x)           (((x) & 0x1) << 6)
 #define R_028004_DB_COUNT_CONTROL                    0x00028004
-#define   S_028004_ZPASS_INCREMENT_DISABLE        (((x) & 0x1) << 0)
+#define   S_028004_ZPASS_INCREMENT_DISABLE(x)        (((x) & 0x1) << 0)
 #define   S_028004_PERFECT_ZPASS_COUNTS(x)        (((x) & 0x1) << 1)
 #define R_028008_DB_DEPTH_VIEW                       0x00028008
 #define R_02800C_DB_RENDER_OVERRIDE                  0x0002800C
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index 19cfbcc..ee91469 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -43,6 +43,7 @@ enum r600_pipe_state_id {
 	R600_PIPE_STATE_CONSTANT,
 	R600_PIPE_STATE_SAMPLER,
 	R600_PIPE_STATE_RESOURCE,
+	R600_PIPE_STATE_QUERY,
 	R600_PIPE_NSTATES
 };
 
@@ -95,6 +96,9 @@ struct r600_pipe_context {
 	struct pipe_vertex_buffer	vertex_buffer[PIPE_MAX_ATTRIBS];
 	unsigned			nvertex_buffer;
 	unsigned			cb_target_mask;
+	signed				queries_running;
+	struct r600_pipe_state		query_state_enabled;
+	struct r600_pipe_state		query_state_disabled;
 	/* for saving when using blitter */
 	struct pipe_stencil_ref		stencil_ref;
 	struct pipe_viewport_state	viewport;
diff --git a/src/gallium/drivers/r600/r600_state2.c b/src/gallium/drivers/r600/r600_state2.c
index 8501b3f..7bab6f3 100644
--- a/src/gallium/drivers/r600/r600_state2.c
+++ b/src/gallium/drivers/r600/r600_state2.c
@@ -967,7 +967,7 @@ static void *r600_create_dsa_state(struct pipe_context *ctx,
 	db_render_override = S_028D10_FORCE_HIZ_ENABLE(V_028D10_FORCE_DISABLE) |
 		S_028D10_FORCE_HIS_ENABLE0(V_028D10_FORCE_DISABLE) |
 		S_028D10_FORCE_HIS_ENABLE1(V_028D10_FORCE_DISABLE);
-	/* TODO db_render_override depends on query */
+
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028028_DB_STENCIL_CLEAR, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_02802C_DB_DEPTH_CLEAR, 0x3F800000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028410_SX_ALPHA_TEST_CONTROL, alpha_test_control, 0xFFFFFFFF, NULL);
@@ -982,9 +982,14 @@ static void *r600_create_dsa_state(struct pipe_context *ctx,
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_0286E4_SPI_FOG_FUNC_BIAS, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_0286DC_SPI_FOG_CNTL, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028800_DB_DEPTH_CONTROL, db_depth_control, 0xFFFFFFFF, NULL);
+
+	/* masked bits are set by the shader state */
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_02880C_DB_SHADER_CONTROL, db_shader_control, 0xFFFFFFBE, NULL);
-	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D0C_DB_RENDER_CONTROL, db_render_control, 0xFFFFFFFF, NULL);
-	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D10_DB_RENDER_OVERRIDE, db_render_override, 0xFFFFFFFF, NULL);
+
+	/* masked bits are set by the query state */
+	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D0C_DB_RENDER_CONTROL, db_render_control, 0xFFFF7FFF, NULL);
+	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D10_DB_RENDER_OVERRIDE, db_render_override, 0xFFFFFDFF, NULL);
+
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D2C_DB_SRESULTS_COMPARE_STATE1, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D30_DB_PRELOAD_CONTROL, 0x00000000, 0xFFFFFFFF, NULL);
 	r600_pipe_state_add_reg(rstate, R600_GROUP_CONTEXT, R_028D44_DB_ALPHA_TO_MASK, 0x0000AA00, 0xFFFFFFFF, NULL);
@@ -2101,6 +2106,10 @@ static void r600_begin_query(struct pipe_context *ctx, struct pipe_query *query)
 	rquery->result = 0;
 	rquery->num_results = 0;
 	r600_query_begin(&rctx->ctx, (struct r600_query *)query);
+	
+	if(rctx->queries_running == 0)
+		r600_context_pipe_state_set(&rctx->ctx,&rctx->query_state_enabled);
+	rctx->queries_running++;
 }
 
 static void r600_end_query(struct pipe_context *ctx, struct pipe_query *query)
@@ -2108,6 +2117,11 @@ static void r600_end_query(struct pipe_context *ctx, struct pipe_query *query)
 	struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
 
 	r600_query_end(&rctx->ctx, (struct r600_query *)query);
+	
+	rctx->queries_running--;
+	assert(rctx->queries_running >=0);
+	if(rctx->queries_running == 0)
+		r600_context_pipe_state_set(&rctx->ctx,&rctx->query_state_disabled);
 }
 
 static boolean r600_get_query_result(struct pipe_context *ctx,
@@ -2123,6 +2137,23 @@ static boolean r600_get_query_result(struct pipe_context *ctx,
 	return r600_context_query_result(&rctx->ctx, (struct r600_query *)query, wait, vresult);
 }
 
+static void r600_init_query_states(struct r600_pipe_context *rctx)
+{
+	unsigned is_r700 = 0;
+
+	if(r600_get_family(rctx->radeon) >= CHIP_RV770)
+		is_r700 = 1;
+
+	
+	if(is_r700)
+		r600_pipe_state_add_reg(&rctx->query_state_enabled, R600_GROUP_CONTEXT, R_028D0C_DB_RENDER_CONTROL, S_028D0C_R700_PERFECT_ZPASS_COUNTS(1), 0x00008000, NULL);
+	r600_pipe_state_add_reg(&rctx->query_state_enabled, R600_GROUP_CONTEXT, R_028D10_DB_RENDER_OVERRIDE, S_028D10_NOOP_CULL_DISABLE(1), 0x00000200, NULL);
+
+	if(is_r700)
+		r600_pipe_state_add_reg(&rctx->query_state_disabled, R600_GROUP_CONTEXT, R_028D0C_DB_RENDER_CONTROL, 0, 0x00008000, NULL);
+	r600_pipe_state_add_reg(&rctx->query_state_disabled, R600_GROUP_CONTEXT, R_028D10_DB_RENDER_OVERRIDE, 0, 0x00000200, NULL);
+}
+
 static void r600_init_query_functions2(struct r600_pipe_context *rctx)
 {
 	rctx->context.create_query = r600_create_query;
@@ -2174,6 +2205,7 @@ static struct pipe_context *r600_create_context2(struct pipe_screen *screen, voi
 			return NULL;
 		}
 		r600_init_config2(rctx);
+		r600_init_query_states(rctx);
 		break;
 	case CHIP_CEDAR:
 	case CHIP_REDWOOD:
@@ -2187,6 +2219,7 @@ static struct pipe_context *r600_create_context2(struct pipe_screen *screen, voi
 			return NULL;
 		}
 		evergreen_init_config2(rctx);
+		evergreen_init_query_states(rctx);
 		break;
 	default:
 		R600_ERR("unsupported family %d\n", r600_get_family(rctx->radeon));
-- 
1.7.1



More information about the mesa-dev mailing list