mesa/vbo: update NeedFlush before flushing

This prevents re-entering the flush if during the flush
of a context X we end up in vbo_exec_FlushVertices_internal.

I had this issue on one machine, with the following simplified
call sequence:

  glthread_unmarchash_batch
  ...
  vbo_exec_FlushVertices(ctxA)
  ...
  st_validate_state
  ...
  dri3_get_buffer
  loader_dri3_blit_context_get
  ...
  dri_destroy_context(ctxB)
  ...
  _mesa_make_current(ctxB)
  vbo_exec_FlushVertices(ctxA)

The last vbo_exec_FlushVertices would hit the assert checking
flush_call_depth == 1.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39857>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2026-02-12 14:07:42 +01:00 committed by Marge Bot
parent e166027e52
commit d616d9aed8

View file

@ -685,6 +685,9 @@ vbo_exec_FlushVertices_internal(struct vbo_exec_context *exec, unsigned flags)
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
if (flags & FLUSH_STORED_VERTICES) {
/* Update the flag before entering the flush to prevent re-entering. */
ctx->Driver.NeedFlush = 0;
if (exec->vtx.vert_count) {
vbo_exec_vtx_flush(exec);
}
@ -693,19 +696,15 @@ vbo_exec_FlushVertices_internal(struct vbo_exec_context *exec, unsigned flags)
vbo_exec_copy_to_current(exec);
vbo_reset_all_attr(ctx);
}
/* All done. */
ctx->Driver.NeedFlush = 0;
} else {
assert(flags == FLUSH_UPDATE_CURRENT);
/* Only FLUSH_UPDATE_CURRENT is done. */
ctx->Driver.NeedFlush = ~FLUSH_UPDATE_CURRENT;
/* Note that the vertex size is unchanged.
* (vbo_reset_all_attr isn't called)
*/
vbo_exec_copy_to_current(exec);
/* Only FLUSH_UPDATE_CURRENT is done. */
ctx->Driver.NeedFlush = ~FLUSH_UPDATE_CURRENT;
}
}