[vlc-commits] [Git][videolan/vlc][master] qt: do not wait for scene graph initialization when probing the graphics api

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Fri Sep 6 19:48:22 UTC 2024



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
3dff231e by Fatih Uzunoglu at 2024-09-06T19:25:13+00:00
qt: do not wait for scene graph initialization when probing the graphics api

It is documented that the static function `QQuickWindow::graphicsApi()` may
not yield the ultimate graphics API used by the scene graph and that the way
to get the "true, real result" is to wait until the scene graph is initialized.

However, at the same time, it is said that the result would be the "graphics
API that would be used by the scene graph if it was initialized at this point
in time". This is what is really necessary to know here, as we don't (and
should not) override the graphics API in compositors, rather the compositor
should tell if it is compatible with the graphics API. If the compositor is
not compatible (e.g. using QSGRendererInterface::OpenGL with compositor
dcomp), then it should fail at the earliest convenience so that the application
can try other compositors.

As of Qt 6.7, Qt Quick does not implement a fallback procedure in case the
initialization goes wrong due to the chosen graphics API that it tries a
different graphics API. In other words, Qt Quick does not have a cross-graphics
API fallback procedure unlike us. And the cross-graphics API fallback that
we use gets engaged earlier, so it can be assumed with certainty that the
graphics API would not change by the time scene graph is initialized.

Waiting for scene graph initialization has also become less relevant since
0dbfb4b9, where RHI probing and `QQuickWindow::setGraphicsApi()` became
being used in almost all cases. If we set the graphics API explicitly,
it means that the same API can be considered by the compositor directly
without getting concerned by scene graph initialization and it getting end
up with a different graphics API.

- - - - -


1 changed file:

- modules/gui/qt/maininterface/compositor_dcomp.cpp


Changes:

=====================================
modules/gui/qt/maininterface/compositor_dcomp.cpp
=====================================
@@ -138,6 +138,27 @@ bool CompositorDirectComposition::init()
         return false;
     }
 
+    const QString& sceneGraphBackend = qEnvironmentVariable("QT_QUICK_BACKEND");
+    if (!sceneGraphBackend.isEmpty() /* if empty, RHI is used */ &&
+        sceneGraphBackend != QLatin1String("rhi"))
+    {
+        // No RHI means no D3D11 or D3D12, the graphics API check
+        // below is only relevant when RHI is in use.
+        // If QT_QUICK_BACKEND is set to software or openvg, then
+        // `QQuickWindow::graphicsApi()` might still report D3D11 or
+        // D3D12 until the scene graph is initialized.
+        // Unlike `QQuickWindow::graphicsApi()`, `sceneGraphBackend()`
+        // is only valid after the window is constructed, so instead
+        // of using `QQuickWindow::sceneGraphBackend()`, simply probe
+        // the environment variable.
+        return false;
+    }
+
+    const auto graphicsApi = QQuickWindow::graphicsApi();
+    if (graphicsApi != QSGRendererInterface::Direct3D11 &&
+        graphicsApi != QSGRendererInterface::Direct3D12)
+        return false;
+
     return true;
 }
 
@@ -225,53 +246,22 @@ bool CompositorDirectComposition::makeMainInterface(MainCtx* mainCtx)
 
     bool appropriateGraphicsApi = true;
 
-    QEventLoop eventLoop;
     connect(quickViewPtr,
-            &QQuickWindow::sceneGraphInitialized,
-            &eventLoop,
-            [&eventLoop, &appropriateGraphicsApi, quickViewPtr, this]() {
-                if (QQuickWindow::graphicsApi() == QSGRendererInterface::Direct3D11 ||
-                    QQuickWindow::graphicsApi() == QSGRendererInterface::Direct3D12)
-                {
-                    connect(quickViewPtr,
-                            &QQuickWindow::frameSwapped, // At this stage, we can be sure that QRhi and QRhiSwapChain are valid.
-                            this,
-                            [this, &eventLoop]() {
-                                setup();
-                                eventLoop.quit();
-                            },
-                            Qt::SingleShotConnection);
-                }
-                else
-                {
-                    appropriateGraphicsApi = false;
-                    eventLoop.quit();
-                }
-        }, static_cast<Qt::ConnectionType>(Qt::SingleShotConnection | Qt::DirectConnection));
-
-    connect(quickViewPtr,
-            &QQuickWindow::sceneGraphError,
-            &eventLoop,
-            [&eventLoop, &appropriateGraphicsApi](QQuickWindow::SceneGraphError error, const QString &message) {
-                qWarning() << "CompositorDComp: Scene Graph Error: " << error << ", Message: " << message;
-                appropriateGraphicsApi = false;
-                eventLoop.quit();
-        }, static_cast<Qt::ConnectionType>(Qt::SingleShotConnection | Qt::DirectConnection));
-
-    CompositorVideo::Flags flags = CompositorVideo::CAN_SHOW_PIP | CompositorVideo::HAS_ACRYLIC;
+            &QQuickWindow::frameSwapped, // At this stage, we can be sure that QRhi and QRhiSwapChain are valid.
+            this,
+            &CompositorDirectComposition::setup,
+            Qt::SingleShotConnection);
 
     m_quickView->create();
 
-    const bool ret = commonGUICreate(quickViewPtr, quickViewPtr, flags);
+    const bool ret = commonGUICreate(quickViewPtr, quickViewPtr, CompositorVideo::CAN_SHOW_PIP | CompositorVideo::HAS_ACRYLIC);
 
-    if (ret)
-        m_quickView->show();
-    else
+    if (!ret)
         return false;
 
-    if (!m_quickView->isSceneGraphInitialized())
-        eventLoop.exec();
-    return (ret && appropriateGraphicsApi);
+    m_quickView->show();
+
+    return true;
 }
 
 void CompositorDirectComposition::onSurfacePositionChanged(const QPointF& position)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/3dff231ee7a719da9eff698475651003e356adac

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/3dff231ee7a719da9eff698475651003e356adac
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list