[Mesa-dev] [PATCH 7/9] gallium/radeon: zero all query buffers

Nicolai Hähnle nhaehnle at gmail.com
Fri Sep 16 13:57:09 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

To ensure that fences are properly initialized.
---
 src/gallium/drivers/radeon/r600_query.c | 26 ++++++++++----------------
 src/gallium/drivers/radeon/r600_query.h |  2 +-
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_query.c b/src/gallium/drivers/radeon/r600_query.c
index c1c3599..d96f9fc 100644
--- a/src/gallium/drivers/radeon/r600_query.c
+++ b/src/gallium/drivers/radeon/r600_query.c
@@ -331,25 +331,23 @@ static struct r600_resource *r600_new_query_buffer(struct r600_common_context *c
 	/* Queries are normally read by the CPU after
 	 * being written by the gpu, hence staging is probably a good
 	 * usage pattern.
 	 */
 	struct r600_resource *buf = (struct r600_resource*)
 		pipe_buffer_create(ctx->b.screen, PIPE_BIND_CUSTOM,
 				   PIPE_USAGE_STAGING, buf_size);
 	if (!buf)
 		return NULL;
 
-	if (query->flags & R600_QUERY_HW_FLAG_PREDICATE) {
-		if (!query->ops->prepare_buffer(ctx, query, buf)) {
-			r600_resource_reference(&buf, NULL);
-			return NULL;
-		}
+	if (!query->ops->prepare_buffer(ctx, query, buf)) {
+		r600_resource_reference(&buf, NULL);
+		return NULL;
 	}
 
 	return buf;
 }
 
 static bool r600_query_hw_prepare_buffer(struct r600_common_context *ctx,
 					 struct r600_query_hw *query,
 					 struct r600_resource *buffer)
 {
 	/* Callers ensure that the buffer is currently unused by the GPU. */
@@ -433,42 +431,40 @@ static struct pipe_query *r600_query_hw_create(struct r600_common_context *rctx,
 	query->b.ops = &query_hw_ops;
 	query->ops = &query_hw_default_hw_ops;
 
 	switch (query_type) {
 	case PIPE_QUERY_OCCLUSION_COUNTER:
 	case PIPE_QUERY_OCCLUSION_PREDICATE:
 		query->result_size = 16 * rctx->max_db;
 		query->result_size += 16; /* for the fence + alignment */
 		query->num_cs_dw_begin = 6;
 		query->num_cs_dw_end = 6 + r600_gfx_write_fence_dwords(rctx->screen);
-		query->flags |= R600_QUERY_HW_FLAG_PREDICATE;
 		break;
 	case PIPE_QUERY_TIME_ELAPSED:
 		query->result_size = 24;
 		query->num_cs_dw_begin = 8;
 		query->num_cs_dw_end = 8 + r600_gfx_write_fence_dwords(rctx->screen);
 		break;
 	case PIPE_QUERY_TIMESTAMP:
 		query->result_size = 16;
 		query->num_cs_dw_end = 8 + r600_gfx_write_fence_dwords(rctx->screen);
 		query->flags = R600_QUERY_HW_FLAG_NO_START;
 		break;
 	case PIPE_QUERY_PRIMITIVES_EMITTED:
 	case PIPE_QUERY_PRIMITIVES_GENERATED:
 	case PIPE_QUERY_SO_STATISTICS:
 	case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
 		/* NumPrimitivesWritten, PrimitiveStorageNeeded. */
 		query->result_size = 32;
 		query->num_cs_dw_begin = 6;
 		query->num_cs_dw_end = 6;
 		query->stream = index;
-		query->flags |= R600_QUERY_HW_FLAG_PREDICATE;
 		break;
 	case PIPE_QUERY_PIPELINE_STATISTICS:
 		/* 11 values on EG, 8 on R600. */
 		query->result_size = (rctx->chip_class >= EVERGREEN ? 11 : 8) * 16;
 		query->result_size += 8; /* for the fence + alignment */
 		query->num_cs_dw_begin = 6;
 		query->num_cs_dw_end = 6 + r600_gfx_write_fence_dwords(rctx->screen);
 		break;
 	default:
 		assert(0);
@@ -786,30 +782,28 @@ void r600_query_hw_reset_buffers(struct r600_common_context *rctx,
 	while (prev) {
 		struct r600_query_buffer *qbuf = prev;
 		prev = prev->previous;
 		r600_resource_reference(&qbuf->buf, NULL);
 		FREE(qbuf);
 	}
 
 	query->buffer.results_end = 0;
 	query->buffer.previous = NULL;
 
-	if (query->flags & R600_QUERY_HW_FLAG_PREDICATE) {
-		/* Obtain a new buffer if the current one can't be mapped without a stall. */
-		if (r600_rings_is_buffer_referenced(rctx, query->buffer.buf->buf, RADEON_USAGE_READWRITE) ||
-		    !rctx->ws->buffer_wait(query->buffer.buf->buf, 0, RADEON_USAGE_READWRITE)) {
+	/* Obtain a new buffer if the current one can't be mapped without a stall. */
+	if (r600_rings_is_buffer_referenced(rctx, query->buffer.buf->buf, RADEON_USAGE_READWRITE) ||
+	    !rctx->ws->buffer_wait(query->buffer.buf->buf, 0, RADEON_USAGE_READWRITE)) {
+		r600_resource_reference(&query->buffer.buf, NULL);
+		query->buffer.buf = r600_new_query_buffer(rctx, query);
+	} else {
+		if (!query->ops->prepare_buffer(rctx, query, query->buffer.buf))
 			r600_resource_reference(&query->buffer.buf, NULL);
-			query->buffer.buf = r600_new_query_buffer(rctx, query);
-		} else {
-			if (!query->ops->prepare_buffer(rctx, query, query->buffer.buf))
-				r600_resource_reference(&query->buffer.buf, NULL);
-		}
 	}
 }
 
 bool r600_query_hw_begin(struct r600_common_context *rctx,
 			 struct r600_query *rquery)
 {
 	struct r600_query_hw *query = (struct r600_query_hw *)rquery;
 
 	if (query->flags & R600_QUERY_HW_FLAG_NO_START) {
 		assert(0);
diff --git a/src/gallium/drivers/radeon/r600_query.h b/src/gallium/drivers/radeon/r600_query.h
index 4f5aa3a..8c637a5 100644
--- a/src/gallium/drivers/radeon/r600_query.h
+++ b/src/gallium/drivers/radeon/r600_query.h
@@ -92,21 +92,21 @@ struct r600_query_ops {
 
 struct r600_query {
 	struct r600_query_ops *ops;
 
 	/* The type of query */
 	unsigned type;
 };
 
 enum {
 	R600_QUERY_HW_FLAG_NO_START = (1 << 0),
-	R600_QUERY_HW_FLAG_PREDICATE = (1 << 1),
+	/* gap */
 	/* whether begin_query doesn't clear the result */
 	R600_QUERY_HW_FLAG_BEGIN_RESUMES = (1 << 2),
 };
 
 struct r600_query_hw_ops {
 	bool (*prepare_buffer)(struct r600_common_context *,
 			       struct r600_query_hw *,
 			       struct r600_resource *);
 	void (*emit_start)(struct r600_common_context *,
 			   struct r600_query_hw *,
-- 
2.7.4



More information about the mesa-dev mailing list