From 6cd32859d0871098f92c99e6f1666445ea4304af Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 18 Jan 2024 14:18:27 +0100 Subject: [PATCH] egl/drm: flush before calling get_back_bo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to what was done for Wayland in 58f90fd03f4: the glthread unmarhsal thread needs to be idle to avoid concurrent calls to get_back_bo. Also the existing code flushed after setting dri2_surf->back to NULL so a new back buffer was always allocated by the glthread flush: |---------------> dri2_drm_swap_buffers | get_back_bo (back=0x55eb93c6c488) > # First get_back_bo call | get_back_bo (back=0x55eb93c6c488 age: 0)< | # dri2_surf->back = NULL |-----> FLUSH | get_back_bo (back=nil) > # Another get_back_bo call | get_back_bo (back=0x55eb93c6c4c8 age: 3)< |-----< FLUSH |---------------< dri2_drm_swap_buffers Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10437 Cc: mesa-stable Reviewed-by: Marek Olšák Part-of: (cherry picked from commit 6f47e87a605897a851ab7ee6cc2ae49dc4f1f5a2) --- .pick_status.json | 2 +- src/egl/drivers/dri2/platform_drm.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 2cf4b648226..96075929488 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -764,7 +764,7 @@ "description": "egl/drm: flush before calling get_back_bo", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index 9ae16f384e2..1a35ae3b0fe 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -329,6 +329,13 @@ dri2_drm_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) if (dri2_surf->color_buffers[i].age > 0) dri2_surf->color_buffers[i].age++; + /* Flushing must be done before get_back_bo to make sure glthread's + * unmarshalling thread is idle otherwise it might concurrently + * call get_back_bo (eg: through dri2_drm_image_get_buffers). + */ + dri2_flush_drawable_for_swapbuffers(disp, draw); + dri2_dpy->flush->invalidate(dri2_surf->dri_drawable); + /* Make sure we have a back buffer in case we're swapping without * ever rendering. */ if (get_back_bo(dri2_surf) < 0) @@ -338,9 +345,6 @@ dri2_drm_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) dri2_surf->current->age = 1; dri2_surf->back = NULL; - dri2_flush_drawable_for_swapbuffers(disp, draw); - dri2_dpy->flush->invalidate(dri2_surf->dri_drawable); - return EGL_TRUE; }