From ed781c74032ec3ff893bd0d60d9b88a3055476f5 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 4 Sep 2024 11:36:04 +0200 Subject: [PATCH] frontends/va: honor DRI_PRIME for VA_DISPLAY_WAYLAND This matches the X11 behavior. Other display types are unaffected. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8069 Reviewed-by: Leo Liu Part-of: --- src/gallium/auxiliary/vl/vl_winsys.h | 2 +- src/gallium/auxiliary/vl/vl_winsys_drm.c | 17 ++++++++++++++++- src/gallium/frontends/va/context.c | 12 ++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_winsys.h b/src/gallium/auxiliary/vl/vl_winsys.h index 12c238191a9..9c6ee1a607d 100644 --- a/src/gallium/auxiliary/vl/vl_winsys.h +++ b/src/gallium/auxiliary/vl/vl_winsys.h @@ -106,7 +106,7 @@ struct vl_screen *vl_win32_screen_create_from_d3d12_device(IUnknown* d3d12_devic #else /* Always enable the DRM vl winsys */ struct vl_screen * -vl_drm_screen_create(int fd); +vl_drm_screen_create(int fd, bool honor_dri_prime); #ifdef USE_XSHM struct vl_screen * diff --git a/src/gallium/auxiliary/vl/vl_winsys_drm.c b/src/gallium/auxiliary/vl/vl_winsys_drm.c index 3e346d13abf..79bae2f199d 100644 --- a/src/gallium/auxiliary/vl/vl_winsys_drm.c +++ b/src/gallium/auxiliary/vl/vl_winsys_drm.c @@ -34,13 +34,25 @@ #include "util/u_memory.h" #include "vl/vl_winsys.h" +#include "loader.h" + static void vl_drm_screen_destroy(struct vl_screen *vscreen); struct vl_screen * -vl_drm_screen_create(int fd) +vl_drm_screen_create(int fd, bool honor_dri_prime) { struct vl_screen *vscreen; + int libva_owned_fd = -1; + + if (honor_dri_prime) { + /* Pass a non-NULL value as the 2nd param in order to not + * close the original fd - it's owned by libva. + * If fd is overriden, we'll close after the call to + * pipe_loader_drm_probe_fd because pipe_loader dups the fd. + */ + loader_get_user_preferred_fd(&fd, &libva_owned_fd); + } vscreen = CALLOC_STRUCT(vl_screen); if (!vscreen) @@ -49,6 +61,9 @@ vl_drm_screen_create(int fd) if (pipe_loader_drm_probe_fd(&vscreen->dev, fd, false)) vscreen->pscreen = pipe_loader_create_screen(vscreen->dev, false); + if (libva_owned_fd >= 0 && libva_owned_fd != fd) + close(fd); + if (!vscreen->pscreen) goto release_pipe; diff --git a/src/gallium/frontends/va/context.c b/src/gallium/frontends/va/context.c index 2f7ad716fa7..96f209d1ee3 100644 --- a/src/gallium/frontends/va/context.c +++ b/src/gallium/frontends/va/context.c @@ -169,8 +169,16 @@ VA_DRIVER_INIT_FUNC(VADriverContextP ctx) FREE(drm_driver_name); } #endif - if(!drv->vscreen) - drv->vscreen = vl_drm_screen_create(drm_info->fd); + if(!drv->vscreen) { + /* VA_DISPLAY_WAYLAND uses the compositor's fd, like VA_DISPLAY_X11 does. + * In this case, tell vl_drm_screen_create to consider the DRI_PRIME env + * variable to let the user select a different device. + * The other display types receive a fd explicitely picked by the application, + * so don't try to override them. + */ + bool honor_dri_prime = ctx->display_type == VA_DISPLAY_WAYLAND; + drv->vscreen = vl_drm_screen_create(drm_info->fd, honor_dri_prime); + } break; } #endif