[Mesa-dev] [PATCH 6/6] radeonsi: only update vertex buffers when they need updating

Marek Olšák maraeo at gmail.com
Sat Jul 12 09:35:37 PDT 2014


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

---
 src/gallium/drivers/radeonsi/si_descriptors.c | 16 +++++++++++++++-
 src/gallium/drivers/radeonsi/si_state.c       |  2 ++
 src/gallium/drivers/radeonsi/si_state_draw.c  |  6 +++++-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c
index fedb4e2..d21c56f 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -935,6 +935,8 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
 	struct r600_resource *rbuffer = r600_resource(buf);
 	unsigned i, shader, alignment = rbuffer->buf->alignment;
 	uint64_t old_va = r600_resource_va(ctx->screen, buf);
+	unsigned num_elems = sctx->vertex_elements ?
+				       sctx->vertex_elements->count : 0;
 
 	/* Reallocate the buffer in the same pipe_resource. */
 	r600_init_resource(&sctx->screen->b, rbuffer, rbuffer->b.b.width0,
@@ -947,7 +949,19 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
 	 */
 
 	/* Vertex buffers. */
-	/* Nothing to do. Vertex buffer bindings are updated before every draw call. */
+	for (i = 0; i < num_elems; i++) {
+		int vb = sctx->vertex_elements->elements[i].vertex_buffer_index;
+
+		if (vb >= Elements(sctx->vertex_buffer))
+			continue;
+		if (!sctx->vertex_buffer[vb].buffer)
+			continue;
+
+		if (sctx->vertex_buffer[vb].buffer == buf) {
+			sctx->vertex_buffers_dirty = true;
+			break;
+		}
+	}
 
 	/* Read/Write buffers. */
 	for (shader = 0; shader < SI_NUM_SHADERS; shader++) {
diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index 71ece91..b147e02 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -2831,6 +2831,7 @@ static void si_bind_vertex_elements(struct pipe_context *ctx, void *state)
 	struct si_vertex_element *v = (struct si_vertex_element*)state;
 
 	sctx->vertex_elements = v;
+	sctx->vertex_buffers_dirty = true;
 }
 
 static void si_delete_vertex_element(struct pipe_context *ctx, void *state)
@@ -2866,6 +2867,7 @@ static void si_set_vertex_buffers(struct pipe_context *ctx,
 			pipe_resource_reference(&dst[i].buffer, NULL);
 		}
 	}
+	sctx->vertex_buffers_dirty = true;
 }
 
 static void si_set_index_buffer(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c
index c02494d..28bc4ae 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.c
+++ b/src/gallium/drivers/radeonsi/si_state_draw.c
@@ -845,7 +845,11 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 		return;
 
 	si_update_derived_state(sctx);
-	si_update_vertex_buffers(sctx);
+
+	if (sctx->vertex_buffers_dirty) {
+		si_update_vertex_buffers(sctx);
+		sctx->vertex_buffers_dirty = false;
+	}
 
 	if (info->indexed) {
 		/* Initialize the index buffer struct. */
-- 
1.9.1



More information about the mesa-dev mailing list