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.
This commit is contained in:
Cameron Gutman 2025-12-14 16:21:32 -06:00
commit 3425fec33d
4 changed files with 15 additions and 22 deletions

View file

@ -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.

View file

@ -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.

View file

@ -11,6 +11,5 @@ namespace WMUtils {
bool isRunningWayland();
bool isRunningWindowManager();
bool isRunningDesktopEnvironment();
bool isX11EGLSafe();
QString getDrmCardOverride();
}

View file

@ -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();
}