From b1b8b712c1d4bf93ce74c383f54aa2b5e54288db Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 20 Jan 2022 12:06:05 -0500 Subject: [PATCH] aux/vbuf: add fastpath for skipping identical vbuf updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the overhead of comparing these is MUCH less than the overhead of queuing a driver method and performing the update Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/util/u_vbuf.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index 587a45e61ec..5e4f4f4b9c3 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -989,7 +989,7 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, uint32_t nonzero_stride_vb_mask = 0; /* which buffers are unaligned to 2/4 bytes */ uint32_t unaligned_vb_mask[2] = {0}; - const uint32_t mask = + uint32_t mask = ~(((1ull << (count + unbind_num_trailing_slots)) - 1) << start_slot); if (!bufs) { @@ -1030,6 +1030,21 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, continue; } + bool not_user = !vb->is_user_buffer && vb->is_user_buffer == orig_vb->is_user_buffer; + /* struct isn't tightly packed: do not use memcmp */ + if (not_user && orig_vb->stride == vb->stride && + orig_vb->buffer_offset == vb->buffer_offset && orig_vb->buffer.resource == vb->buffer.resource) { + mask |= BITFIELD_BIT(dst_index); + if (take_ownership) { + pipe_vertex_buffer_unreference(orig_vb); + /* the pointer was unset in the line above, so copy it back */ + orig_vb->buffer.resource = vb->buffer.resource; + } + if (mask == UINT32_MAX) + return; + continue; + } + if (take_ownership) { pipe_vertex_buffer_unreference(orig_vb); memcpy(orig_vb, vb, sizeof(*vb));