summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Whitwell <keithw@vmware.com>2009-12-21 16:56:46 +0000
committerKeith Whitwell <keithw@vmware.com>2009-12-21 16:56:46 +0000
commit1ec7e058f50882b27c0a2abd961bd49848386ff7 (patch)
tree862e5413e63b0773ef5caeb906d8aad3f0136adf
parent6c719d4c22e84e315e5dc9cbc69885401a7ae231 (diff)
i965g: keep refcounts to bound vertex buffers
-rw-r--r--src/gallium/drivers/i965/brw_pipe_vertex.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/gallium/drivers/i965/brw_pipe_vertex.c b/src/gallium/drivers/i965/brw_pipe_vertex.c
index 73bba5b088..3d87a2853f 100644
--- a/src/gallium/drivers/i965/brw_pipe_vertex.c
+++ b/src/gallium/drivers/i965/brw_pipe_vertex.c
@@ -19,11 +19,26 @@ static void brw_set_vertex_buffers(struct pipe_context *pipe,
const struct pipe_vertex_buffer *buffers)
{
struct brw_context *brw = brw_context(pipe);
+ unsigned i;
- /* XXX: don't we need to take some references here? It's a bit
- * awkward to do so, though.
- */
- memcpy(brw->curr.vertex_buffer, buffers, count * sizeof(buffers[0]));
+ /* Check for no change */
+ if (count == brw->curr.num_vertex_buffers &&
+ memcmp(brw->curr.vertex_buffer,
+ buffers,
+ count * sizeof buffers[0]) == 0)
+ return;
+
+ /* Adjust refcounts */
+ for (i = 0; i < count; i++)
+ pipe_buffer_reference(&brw->curr.vertex_buffer[i].buffer,
+ buffers[i].buffer);
+
+ for ( ; i < brw->curr.num_vertex_buffers; i++)
+ pipe_buffer_reference(&brw->curr.vertex_buffer[i].buffer,
+ NULL);
+
+ /* Copy remaining data */
+ memcpy(brw->curr.vertex_buffer, buffers, count * sizeof buffers[0]);
brw->curr.num_vertex_buffers = count;
brw->state.dirty.mesa |= PIPE_NEW_VERTEX_BUFFER;