mesa: add unlikely() and adjust error handling in BindBuffer

Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Acked-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19844>
This commit is contained in:
Marek Olšák
2022-11-18 05:13:42 -05:00
committed by Marge Bot
parent c924cfae42
commit c1a0f4b8fa
+8 -9
View File
@@ -1296,20 +1296,19 @@ handle_bind_buffer_gen(struct gl_context *ctx,
{
struct gl_buffer_object *buf = *buf_handle;
if (!no_error && !buf && (ctx->API == API_OPENGL_CORE)) {
if (unlikely(!no_error && !buf && (ctx->API == API_OPENGL_CORE))) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", caller);
return false;
}
if (!buf || buf == &DummyBufferObject) {
if (unlikely(!buf || buf == &DummyBufferObject)) {
/* If this is a new buffer object id, or one which was generated but
* never used before, allocate a buffer object now.
*/
*buf_handle = new_gl_buffer_object(ctx, buffer);
if (!*buf_handle) {
if (!no_error)
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return false;
if (!no_error && !*buf_handle) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
return false;
}
_mesa_HashLockMaybeLocked(ctx->Shared->BufferObjects,
ctx->BufferObjectsLocked);
@@ -1363,13 +1362,13 @@ bind_buffer_object(struct gl_context *ctx,
/* Get pointer to old buffer object (to be unbound) */
oldBufObj = *bindTarget;
GLuint old_name = oldBufObj && !oldBufObj->DeletePending ? oldBufObj->Name : 0;
if (old_name == buffer)
if (unlikely(old_name == buffer))
return; /* rebinding the same buffer object- no change */
newBufObj = _mesa_lookup_bufferobj(ctx, buffer);
/* Get a new buffer object if it hasn't been created. */
if (!handle_bind_buffer_gen(ctx, buffer, &newBufObj, "glBindBuffer",
no_error))
if (unlikely(!handle_bind_buffer_gen(ctx, buffer, &newBufObj, "glBindBuffer",
no_error)))
return;
/* At this point, the compiler should deduce that newBufObj is non-NULL if