diff options
| author | Anton <anton@picapica.im> | 2026-11-27 05:23:02 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-11-27 05:23:02 +0400 |
| commit | 0fc689fc8bcef54a91915f46ab29dc86d293e957 (patch) | |
| tree | 0db8b51330661bb2a4e89f54b3cf229f75673bc1 | |
| parent | cf57b9c33311a646611599f9f9dca1f4523451be (diff) | |
| download | pica-pica-0fc689fc8bcef54a91915f46ab29dc86d293e957.tar.gz pica-pica-0fc689fc8bcef54a91915f46ab29dc86d293e957.zip | |
| -rw-r--r-- | pica-client/main.cpp | 1 | ||||
| -rw-r--r-- | pica-client/vaapi.cpp | 39 | ||||
| -rw-r--r-- | pica-client/vaapi.h | 6 |
3 files changed, 46 insertions, 0 deletions
diff --git a/pica-client/main.cpp b/pica-client/main.cpp index 477fa10..56d0092 100644 --- a/pica-client/main.cpp +++ b/pica-client/main.cpp @@ -520,6 +520,7 @@ int main(int argc, char *argv[]) // Before Qt opens its X connection, which is the only time Xlib will // listen - see the comment on the function itself. VaapiContext::initX11Threading(); + VaapiContext::preferEglOnX11(); #endif QApplication a(argc, argv); diff --git a/pica-client/vaapi.cpp b/pica-client/vaapi.cpp index d5dd2f5..39cd0ed 100644 --- a/pica-client/vaapi.cpp +++ b/pica-client/vaapi.cpp @@ -150,6 +150,29 @@ namespace return nullptr; } + // Mesa's VA drivers (radeonsi, r600, nouveau and the other Gallium ones) + // cannot be drawn with across more than one window. They keep what + // vaPutSurface() presents with per display, for one window at a time, + // and drawing on another window throws away the X server's + // confirmation that the old window's last frame was shown - so the + // first frame on the new window waits for it forever, holding the + // driver lock and freezing the GUI thread and the decoder along with + // it. Every call opens a new window while this display lives for the + // whole process, which makes it the second window that hangs. Seen with + // Mesa 26.1, in dri3_set_drawable() in vl_winsys_dri3.c. + // + // Leave such drivers to a DRM render node, as if this session had no + // X11 path: drawn as EGL images when Qt is on EGL, which + // preferEglOnX11() asks for, and in software when it is not. + const QByteArray vendor(vaQueryVendorString(va_display)); + + if (vendor.startsWith("Mesa Gallium")) + { + qDebug() << "VAAPI: not drawing with vaPutSurface(), it deadlocks with" << vendor; + vaTerminate(va_display); + return nullptr; + } + AVBufferRef *ref = wrapVaDisplay(va_display); if (!ref) @@ -270,6 +293,22 @@ void VaapiContext::initX11Threading() #endif } +void VaapiContext::preferEglOnX11() +{ + // Qt makes GLX contexts in an X11 session unless told otherwise, and with + // GLX the only way to get a decoded surface on screen is vaPutSurface() - + // which Mesa's VA drivers deadlock in, see createX11Device(). With EGL the + // surface is imported as an EGL image instead, and that works with every + // driver. + // + // The variable only moves xcb_egl to the front of the list Qt tries, so if + // EGL cannot be initialised Qt still falls back to GLX, and the video to + // the X11 path or to software. Read only by the xcb platform plugin, so + // harmless in a Wayland session or on another platform. + if (!qEnvironmentVariableIsSet("QT_XCB_GL_INTEGRATION")) + qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl"); +} + void VaapiContext::detectX11Display() { #ifdef HAVE_VAAPI_X11 diff --git a/pica-client/vaapi.h b/pica-client/vaapi.h index 888a9d6..0a5afff 100644 --- a/pica-client/vaapi.h +++ b/pica-client/vaapi.h @@ -81,6 +81,12 @@ public: // X11 rendering support. static void initX11Threading(); + // Asks Qt for EGL rather than GLX OpenGL contexts in an X11 session, so + // that decoded surfaces can be drawn as EGL images instead of through + // vaPutSurface(). Has to run before QApplication is constructed. A choice + // the user made through QT_XCB_GL_INTEGRATION is left alone. + static void preferEglOnX11(); + // Works out whether this session needs the X11 drawing path - that is, // whether Qt's OpenGL contexts come from GLX, leaving no way to import a // surface as an EGL image - and if so remembers Qt's X connection to open |
