From fc44e708d71ea97f21aaa1e9274e4a89c032dd92 Mon Sep 17 00:00:00 2001 From: Mario Kleiner Date: Tue, 23 Sep 2025 21:11:34 +0100 Subject: [PATCH] asahi: Set PIPE_BIND_SCANOUT in agx_resource_from_handle(). Commit 534a04d557f3 optimized agx_resource_from_handle() to lazily defer assignment of a kms-ro renderonly_scanout object to an imported resource until its kms winsys handle is actually queried by a caller via agx_resource_get_handle(), to avoid unnecessary import into the DCP display controller. Only resources with bind flag PIPE_BIND_SCANOUT will get a renderonly_scanout object assigned during such queries. Problem: This prevents Mesa GBM's gbm_bo_import() function from properly importing dmabufs for direct scanout use by some Wayland compositors, e.g., GNOME mutter. gbm_bo_import() of dmabuf fd's (GBM_BO_IMPORT_FD / GBM_BO_IMPORT_FD_MODIFIER), even with GBM_BO_USE_SCANOUT flag, will not mark an imported bo with the PIPE_BIND_SCANOUT bind flag before internally assigning its KMS winsys handle via screen->resource_get_handle() -> agx_resource_get_handle(), causing silent failure of that query. Therefore gbm_bo_import() seems to return a successfully created gbm_bo with all proper properties, but gbm_bo_get_handle() and gbm_bo_get_handle_for_plane() will return invalid handles. These invalid handles cause drmAddFbXXX ioctl calls to fail, and therefore failure of direct scanout of wl_buffers. Setting PIPE_BIND_SCANOUT for a resource in agx_resource_from_handle() may retain the optimization and makes gbm_bo_get_handle[_for_plane]() work. This fixes direct scanout of fullscreen wl_surface / wl_buffers under at least GNOME mutter 48. Fixes: 534a04d557f3 ("asahi: Flip kmsro around to allocate on the GPU") Signed-off-by: Mario Kleiner Part-of: --- src/gallium/drivers/asahi/agx_pipe.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 6789b6ed090..5b08d028ceb 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -191,7 +191,11 @@ agx_resource_from_handle(struct pipe_screen *pscreen, pipe_reference_init(&prsc->reference, 1); prsc->screen = pscreen; - prsc->bind |= PIPE_BIND_SHARED; + /* Set PIPE_BIND_SCANOUT for lazy on-demand creation of renderonly + * scanout resource if agx_resource_get_handle is called for + * WINSYS_HANDLE_TYPE_KMS on a kms-ro screen. + */ + prsc->bind |= PIPE_BIND_SHARED | PIPE_BIND_SCANOUT; rsc->bo = agx_bo_import(dev, whandle->handle); /* Sometimes an import can fail e.g. on an invalid buffer fd, out of