mesa/st: call _mesa_glthread_finish before _mesa_make_current

_mesa_make_current will use st_flush(ctx) to execute pending
commands before switching to the new context.

Since we can't have multiple threads using a pipe_context at
the same time, we must finish glthread to avoid having the
unmarshalling thread executing at the same time.

It's fixing random crashes where a thread would do:
  st_destroy_context ->
      _mesa_make_current ->
          st_glFlush(save_ctx) ->
            tc_execute_batch
While there's a glthread unmarshalling thread that's still
adding commands to TC.

Fixes: 08d97aadd1 ("st/mesa: fix texture deletion context mix-up issues (v2)")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33552>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2025-02-19 10:59:38 +01:00 committed by Marge Bot
parent a893a87625
commit f062c83f3a

View file

@ -898,6 +898,11 @@ st_destroy_context(struct st_context *st)
if (save_ctx) {
save_drawbuffer = save_ctx->WinSysDrawBuffer;
save_readbuffer = save_ctx->WinSysReadBuffer;
/* Calling _mesa_glthread_finish is required to avoid having an
* unmarshalling thread execute calls while the current thread
* flushes the context.
*/
_mesa_glthread_finish(save_ctx);
} else {
save_drawbuffer = save_readbuffer = NULL;
}