From 3425fec33d8b12d392e2d13d3973a01d31687812 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 14 Dec 2025 16:21:32 -0600 Subject: [PATCH] Use EGL+GLES workaround for Nvidia X11 We can avoid disabling EGL entirely by forcing Qt to use GLES, which is not impacted by the black window issue. This lets us simplify back to EGL everywhere. --- app/main.cpp | 22 +++++++++++++------ .../video/ffmpeg-renderers/eglvid.cpp | 7 ------ app/utils.h | 1 - app/wm.cpp | 7 ------ 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index c8824f18..84d7c620 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -476,15 +476,23 @@ int main(int argc, char *argv[]) #endif } - if (WMUtils::isX11EGLSafe()) { - // Some ARM and RISC-V embedded devices don't have working GLX which can cause - // SDL to fail to find a working OpenGL implementation at all. Let's force EGL - // on all platforms for both SDL and Qt. This also avoids GLX-EGL interop issues - // when trying to use EGL on the main thread after Qt uses GLX. - SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1"); - qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl"); + if (WMUtils::isRunningNvidiaProprietaryDriverX11() || qEnvironmentVariableIntValue("FORCE_QT_GLES")) { + // The Nvidia proprietary driver causes Qt to render a black window when using + // the default Desktop GL profile with EGL. AS a workaround, we default to + // OpenGL ES when running on Nvidia on X11. + // https://qt-project.atlassian.net/browse/QTBUG-106065 + QSurfaceFormat fmt; + fmt.setRenderableType(QSurfaceFormat::OpenGLES); + QSurfaceFormat::setDefaultFormat(fmt); } + // Some ARM and RISC-V embedded devices don't have working GLX which can cause + // SDL to fail to find a working OpenGL implementation at all. Let's force EGL + // on all platforms for both SDL and Qt. This also avoids GLX-EGL interop issues + // when trying to use EGL on the main thread after Qt uses GLX. + SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1"); + qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl"); + #ifdef Q_OS_MACOS // This avoids using the default keychain for SSL, which may cause // password prompts on macOS. diff --git a/app/streaming/video/ffmpeg-renderers/eglvid.cpp b/app/streaming/video/ffmpeg-renderers/eglvid.cpp index a74923e7..69ede9e9 100644 --- a/app/streaming/video/ffmpeg-renderers/eglvid.cpp +++ b/app/streaming/video/ffmpeg-renderers/eglvid.cpp @@ -426,13 +426,6 @@ bool EGLRenderer::initialize(PDECODER_PARAMETERS params) return false; } - // If we're using X11 GLX (both in SDL and Qt), don't use this renderer. - // Switching between EGL and GLX can cause interoperability issues. - if (strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0 && !WMUtils::isX11EGLSafe()) { - EGL_LOG(Warn, "Disabled due to use of GLX"); - return false; - } - // This hint will ensure we use EGL to retrieve our GL context, // even on X11 where that is not the default. EGL is required // to avoid a crash in Mesa. diff --git a/app/utils.h b/app/utils.h index d437968f..d589f137 100644 --- a/app/utils.h +++ b/app/utils.h @@ -11,6 +11,5 @@ namespace WMUtils { bool isRunningWayland(); bool isRunningWindowManager(); bool isRunningDesktopEnvironment(); - bool isX11EGLSafe(); QString getDrmCardOverride(); } diff --git a/app/wm.cpp b/app/wm.cpp index 5f605392..7ade1d8c 100644 --- a/app/wm.cpp +++ b/app/wm.cpp @@ -183,10 +183,3 @@ QString WMUtils::getDrmCardOverride() return QString(); } - -bool WMUtils::isX11EGLSafe() -{ - // Nvidia's driver has broken EGL support on X11 and XWayland - // https://github.com/moonlight-stream/moonlight-qt/issues/1751 - return !WMUtils::isRunningNvidiaProprietaryDriverX11(); -}