Mesa (master): radeonsi: only update vertex buffers when they need updating

Marek Olšák mareko at kemper.freedesktop.org
Thu Jul 17 23:59:18 UTC 2014


Module: Mesa
Branch: master
Commit: d808de31bd3bac26cdea4d1d9464ad7f010d77d1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d808de31bd3bac26cdea4d1d9464ad7f010d77d1

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Jul 11 23:17:07 2014 +0200

radeonsi: only update vertex buffers when they need updating

Reviewed-by: Michel Dänzer <michel.daenzer 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 bd7695c..4751b8b 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -933,6 +933,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,
@@ -945,7 +947,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 c691872..fde06fc 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -2813,6 +2813,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)
@@ -2848,6 +2849,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 a0078c0..f829d03 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.c
+++ b/src/gallium/drivers/radeonsi/si_state_draw.c
@@ -892,7 +892,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. */




More information about the mesa-commit mailing list