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 <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8298>
This commit is contained in:
Marek Olšák 2021-01-02 16:35:15 -05:00 committed by Marge Bot
parent cf82b3dc74
commit 104a41bd07
1 changed files with 8 additions and 0 deletions

View File

@ -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);