mesa: fix invalid index_bo refcounting

If take_index_buffer_ownership is true, then we should reserve
enough references of index_bo or we'll get an underflow later.

Fixes: 819627041e ("mesa: set pipe_draw_info::index::resource directly and remove gl_bo")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8747
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22237>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2023-03-31 16:57:08 +02:00 committed by Marge Bot
parent 09320705f0
commit 2b717f01f7

View file

@ -2534,6 +2534,11 @@ _mesa_MultiDrawElementsIndirect(GLenum mode, GLenum type,
/* Fast path for u_threaded_context to eliminate atomics. */
info.index.resource = _mesa_get_bufferobj_reference(ctx, index_bo);
info.take_index_buffer_ownership = true;
/* Increase refcount so be able to use take_index_buffer_ownership with
* multiple draws.
*/
if (primcount > 1 && info.index.resource)
p_atomic_add(&info.index.resource->reference.count, primcount - 1);
} else {
info.index.resource = index_bo->buffer;
}