[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: do not use blocking queued connection in the current thread when probing rhi

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Sep 16 05:39:31 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
66ab8c1f by Fatih Uzunoglu at 2026-09-16T05:30:35+00:00
qt: do not use blocking queued connection in the current thread when probing rhi

We do asynchronous re-probing only if there was probing done before (from the
previous start), and the result logged in to the config file in `graphics-api`
entry.

If probing was not done before, or the config entry does not exist for any
reason, we do the probing synchronously. In this case, we can't blindly use
blocking queued connection since the thread would be the current thread.

The fix for this is trivial, check for the current thread and call the
function directly if it is the same as the GUI/QApplication thread. We
already employ this method in various other places.

- - - - -
863dce5c by Fatih Uzunoglu at 2026-09-16T05:30:35+00:00
qt: do not use `QRhiGles2InitParams::newFallbackSurface()` when probing rhi

- `QRhiGles2InitParams::newFallbackSurface()` checks if the format is valid, this is not
  necessary in this case since the format provided is guaranteed to be valid (we check
  ourselves in `createCompatibleOpenGLFormat()`.
- `QRhiGles2InitParams::newFallbackSurface()` calls `::create()`, beyond that point Qt
  RHI may not be able to use the format we supply in `QRhiGles2InitParams::format` for
  the fallback surface.

- - - - -
72446ca8 by Fatih Uzunoglu at 2026-09-16T05:30:35+00:00
qt: improve threaded rhi probing for opengl

The requirement is that `QOffscreenSurface`
must be initialized and destroyed in the
GUI thread, and `QOffscreenSurface::create()`
must be called in the GUI thread if the
platform backs the offscreen surface with
`QWindow`.

This means that we can limit our non-threaded
portion to specifically to that, rather than
calling `createCompatibleOpenGLFormat()` or
the expensive `QRhi::probe()` in the GUI thread.

- - - - -


1 changed file:

- modules/gui/qt/qt.cpp


Changes:

=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -72,6 +72,7 @@ extern "C" char **environ;
 #ifdef RHI_HEADER_AVAILABLE
 #include <QOffscreenSurface>
 #include <QThreadPool>
+#include <QThread>
 #include "util/asynctask.hpp"
 #endif
 
@@ -1043,28 +1044,44 @@ static void *Thread( void *obj )
         }
 #endif
 
-        std::optional<QPair<QSGRendererInterface::GraphicsApi, bool>> retGlProbe;
-        QMetaObject::invokeMethod(qApp, [&retGlProbe]() {
-            // Due to offscreen surface involvement, this has to be done in the
-            // gui thread only:
+        if (const std::optional<QSurfaceFormat> format = createCompatibleOpenGLFormat())
+        {
             QRhiGles2InitParams params;
+            QOffscreenSurface *surface = nullptr; // This is needed to not use explicit cast.
+
+            params.format = *format;
+
+            // Caller takes the ownership of the created fallback surface:
+            const auto initializeFallbackSurface = [&params, &surface, &format]() {
+                // Due to offscreen surface involvement, this has to be done in the
+                // gui thread only:
+                surface = new QOffscreenSurface;
+                params.fallbackSurface = surface;
+                surface->setFormat(*format);
+                surface->create();
+                assert(surface->isValid()); // The provided format is guaranteed to be valid (see `createCompatibleOpenGLFormat()`).
+            };
+
+            const auto isGuiThread = QThread::currentThread() == qApp->thread();
+
+            if (isGuiThread)
+                initializeFallbackSurface();
+            else
+                QMetaObject::invokeMethod(qApp, initializeFallbackSurface, Qt::BlockingQueuedConnection);
+
+            const bool probe = QRhi::probe(QRhi::OpenGLES2, &params);
 
-            const std::optional<QSurfaceFormat> format = createCompatibleOpenGLFormat();
-            if (format)
-                params.format = *format;
+            if (isGuiThread)
+                delete surface;
             else
-                return;
+                surface->deleteLater(); // No need to be blocking.
 
-            params.fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
-            if (QRhi::probe(QRhi::OpenGLES2, &params))
+            if (probe)
             {
-                retGlProbe = {QSGRendererInterface::OpenGL, false};
                 QSurfaceFormat::setDefaultFormat(*format);
+                return {QSGRendererInterface::OpenGL, false};
             }
-            delete params.fallbackSurface;
-        }, Qt::BlockingQueuedConnection);
-        if (retGlProbe)
-            return *retGlProbe;
+        }
 
         // TODO: Investigate if using Vulkan makes sense on Windows.
         // TODO: Investigate if it makes sense to try D3D12 when probing D3D11 failed.



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/045b920433197a9e8cbcf5a6566f6475ea3edbb8...72446ca8113c84f37bcadf6eaf25f60bafebbc74

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/045b920433197a9e8cbcf5a6566f6475ea3edbb8...72446ca8113c84f37bcadf6eaf25f60bafebbc74
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list