Module: Mesa Branch: main Commit: a98e4195f567b39af9fd8a6cfccec6f772efe9fc URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a98e4195f567b39af9fd8a6cfccec6f772efe9fc
Author: Pierre-Eric Pelloux-Prayer <[email protected]> Date: Tue Jan 24 21:42:49 2023 +0100 yegl/wayland: fix glthread deadlocks We need to make sure that glthread is idle before using wl_* functions or they might be used from 2 threads at the same time. Thanks to @deltib for the investigation of this issue. Fixes: 58f90fd03f4 ("egl/wayland: fix glthread crashes") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7624 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8136 Reviewed-by: Michel Dänzer <[email protected]> Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20887> --- src/egl/drivers/dri2/platform_wayland.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index 209a77143ec..fe152294a85 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -1588,15 +1588,6 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, if (!dri2_surf->wl_win) return _eglError(EGL_BAD_NATIVE_WINDOW, "dri2_swap_buffers"); - while (dri2_surf->throttle_callback != NULL) - if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, - dri2_surf->wl_queue) == -1) - return -1; - - for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) - if (dri2_surf->color_buffers[i].age > 0) - dri2_surf->color_buffers[i].age++; - /* Flush (and finish glthread) before: * - update_buffers_if_needed because the unmarshalling thread * may be running currently, and we would concurrently alloc/free @@ -1604,10 +1595,21 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, * - swapping current/back because flushing may free the buffer and * dri_image and reallocate them using get_back_bo (which causes a * a crash because 'current' becomes NULL). + * - using any wl_* function because accessing them from this thread + * and glthread causes troubles (see #7624 and #8136) */ dri2_flush_drawable_for_swapbuffers(disp, draw); dri2_dpy->flush->invalidate(dri2_surf->dri_drawable); + while (dri2_surf->throttle_callback != NULL) + if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, + dri2_surf->wl_queue) == -1) + return -1; + + for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) + if (dri2_surf->color_buffers[i].age > 0) + dri2_surf->color_buffers[i].age++; + /* Make sure we have a back buffer in case we're swapping without ever * rendering. */ if (update_buffers_if_needed(dri2_surf) < 0)
