From dac2c210d6457d8497e25d71c5a9c76282094dd6 Mon Sep 17 00:00:00 2001 From: Yogesh Mohanmarimuthu Date: Mon, 3 May 2021 22:57:07 +0530 Subject: [PATCH] glx: Keep display fd open for prime MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Keep the display fd open for creating DRI screen on display gpu in case of prime. v2: initialize psc->fd_display_gpu early (Michel Dänzer) fix display gpu fd leakage (Michel Dänzer) v3: fix more display gpu fd leakage (Michel Dänzer) Signed-off-by: Yogesh Mohanmarimuthu Acked-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Michel Dänzer Reviewed-by: Marek Olšák Part-of: --- src/glx/dri3_glx.c | 10 ++++++++++ src/glx/dri3_priv.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index cd00ff6..980bd22 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -607,6 +607,8 @@ dri3_destroy_screen(struct glx_screen *base) struct dri3_screen *psc = (struct dri3_screen *) base; /* Free the direct rendering per screen data */ + if (psc->is_different_gpu) + close(psc->fd_display_gpu); loader_dri3_close_screen(psc->driScreen); (*psc->core->destroyScreen) (psc->driScreen); driDestroyConfigs(psc->driver_configs); @@ -842,6 +844,7 @@ dri3_create_screen(int screen, struct glx_display * priv) return NULL; psc->fd = -1; + psc->fd_display_gpu = -1; if (!glx_screen_init(&psc->base, screen, priv)) { free(psc); @@ -862,7 +865,12 @@ dri3_create_screen(int screen, struct glx_display * priv) return NULL; } + psc->fd_display_gpu = fcntl(psc->fd, F_DUPFD_CLOEXEC, 3); psc->fd = loader_get_user_preferred_fd(psc->fd, &psc->is_different_gpu); + if (!psc->is_different_gpu) { + close(psc->fd_display_gpu); + psc->fd_display_gpu = -1; + } driverName = loader_get_driver_for_fd(psc->fd); if (!driverName) { @@ -1013,6 +1021,8 @@ handle_error: psc->driScreen = NULL; if (psc->fd >= 0) close(psc->fd); + if (psc->fd_display_gpu >= 0) + close(psc->fd_display_gpu); if (psc->driver) dlclose(psc->driver); diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h index dbd04c0..4ccc832 100644 --- a/src/glx/dri3_priv.h +++ b/src/glx/dri3_priv.h @@ -103,6 +103,9 @@ struct dri3_screen { int fd; bool is_different_gpu; + /* fd for display GPU in case of prime */ + int fd_display_gpu; + int show_fps_interval; struct loader_dri3_extensions loader_dri3_ext; -- 2.7.4