st/mesa: merge 3 unlikely blocks in _mesa_get_bufferobj_reference

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27587>
This commit is contained in:
Marek Olšák
2024-01-04 01:51:51 -05:00
committed by Marge Bot
parent bfe6d389a0
commit 9747cf2c8f

View File

@@ -44,26 +44,32 @@ _mesa_get_bufferobj_reference(struct gl_context *ctx, struct gl_buffer_object *o
struct pipe_resource *buffer = obj->buffer;
if (unlikely(!buffer))
return NULL;
/* Only one context is using the fast path. All other contexts must use
* the slow path.
*/
if (unlikely(obj->private_refcount_ctx != ctx)) {
p_atomic_inc(&buffer->reference.count);
if (unlikely(obj->private_refcount_ctx != ctx ||
obj->private_refcount <= 0)) {
if (buffer) {
if (obj->private_refcount_ctx != ctx) {
p_atomic_inc(&buffer->reference.count);
} else {
/* This is the number of atomic increments we will skip. */
const unsigned count = 100000000;
p_atomic_add(&buffer->reference.count, count);
/* Remove the reference that we return. */
assert(obj->private_refcount == 0);
obj->private_refcount = count - 1;
}
}
return buffer;
}
if (unlikely(obj->private_refcount <= 0)) {
assert(obj->private_refcount == 0);
/* This is the number of atomic increments we will skip. */
obj->private_refcount = 100000000;
p_atomic_add(&buffer->reference.count, obj->private_refcount);
}
/* Return a buffer reference while decrementing the private refcount. */
/* Return a buffer reference while decrementing the private refcount.
* The buffer must be non-NULL, which is implied by private_refcount_ctx
* being non-NULL.
*/
assert(buffer);
obj->private_refcount--;
return buffer;
}