From f062c83f3aa5a5b086914fec929cab681eb4b85d Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 19 Feb 2025 10:59:38 +0100 Subject: [PATCH] mesa/st: call _mesa_glthread_finish before _mesa_make_current MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _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: 08d97aadd14 ("st/mesa: fix texture deletion context mix-up issues (v2)") Reviewed-by: Marek Olšák Part-of: --- src/mesa/state_tracker/st_context.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 2e7a067620a..ebd4716493a 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -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; }