From 104a41bd0743596f7eccadcef3a70a3d40c370d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 2 Jan 2021 16:35:15 -0500 Subject: [PATCH] gallium/util: optimize pipe_vertex_buffer_reference binding the same buffer This eliminates atomic ops when the buffer doesn't change. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/auxiliary/util/u_inlines.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index d751f1cce28..f3a74d7fb0a 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -223,6 +223,14 @@ static inline void pipe_vertex_buffer_reference(struct pipe_vertex_buffer *dst, const struct pipe_vertex_buffer *src) { + if (dst->buffer.resource == src->buffer.resource) { + /* Just copy the fields, don't touch reference counts. */ + dst->stride = src->stride; + dst->is_user_buffer = src->is_user_buffer; + dst->buffer_offset = src->buffer_offset; + return; + } + pipe_vertex_buffer_unreference(dst); if (!src->is_user_buffer) pipe_resource_reference(&dst->buffer.resource, src->buffer.resource);