diff options
-rw-r--r-- | src/quick/scenegraph/qsgrenderloop.cpp | 5 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgrhisupport.cpp | 32 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgrhisupport_p.h | 1 |
3 files changed, 28 insertions, 10 deletions
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp index 9d1217edf9..0c1850f91f 100644 --- a/src/quick/scenegraph/qsgrenderloop.cpp +++ b/src/quick/scenegraph/qsgrenderloop.cpp @@ -517,6 +517,11 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window) // QQuickWindowPrivate, do it now cd->rhi = rhi; + // Unlike the threaded render loop, we use the same rhi for all windows + // and so createRhi() is called only once. Certain initialization may + // need to be done on a per window basis still, so make sure it is done. + rhiSupport->prepareWindowForRhi(window); + QRhiSwapChain::Flags flags = QRhiSwapChain::UsedAsTransferSource; // may be used in a grab // QQ is always premul alpha. Decide based on alphaBufferSize in diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp index 891beb0d90..6a66906ca1 100644 --- a/src/quick/scenegraph/qsgrhisupport.cpp +++ b/src/quick/scenegraph/qsgrhisupport.cpp @@ -543,6 +543,26 @@ QOffscreenSurface *QSGRhiSupport::maybeCreateOffscreenSurface(QWindow *window) return offscreenSurface; } +void QSGRhiSupport::prepareWindowForRhi(QQuickWindow *window) +{ +#if QT_CONFIG(vulkan) + if (rhiBackend() == QRhi::Vulkan) { + QQuickWindowPrivate *wd = QQuickWindowPrivate::get(window); + // QQuickWindows must get a QVulkanInstance automatically (it is + // created when the first window is constructed and is destroyed only + // on exit), unless the application decided to set its own. With + // QQuickRenderControl, no QVulkanInstance is created, because it must + // always be under the application's control then (since the default + // instance we could create here would not be configurable by the + // application in any way, and that is often not acceptable). + if (!window->vulkanInstance() && !wd->renderControl) + window->setVulkanInstance(QSGRhiSupport::defaultVulkanInstance()); + } +#else + Q_UNUSED(window); +#endif +} + // must be called on the render thread QRhi *QSGRhiSupport::createRhi(QQuickWindow *window, QOffscreenSurface *offscreenSurface) { @@ -558,7 +578,7 @@ QRhi *QSGRhiSupport::createRhi(QQuickWindow *window, QOffscreenSurface *offscree if (isSoftwareRendererRequested()) flags |= QRhi::PreferSoftwareRenderer; - QRhi::Implementation backend = rhiBackend(); + const QRhi::Implementation backend = rhiBackend(); if (backend == QRhi::Null) { QRhiNullInitParams rhiParams; rhi = QRhi::create(backend, &rhiParams, flags); @@ -585,15 +605,7 @@ QRhi *QSGRhiSupport::createRhi(QQuickWindow *window, QOffscreenSurface *offscree #if QT_CONFIG(vulkan) if (backend == QRhi::Vulkan) { QRhiVulkanInitParams rhiParams; - // QQuickWindows must get a QVulkanInstance automatically (it is - // created when the first window is constructed and is destroyed only - // on exit), unless the application decided to set its own. With - // QQuickRenderControl, no QVulkanInstance is created, because it must - // always be under the application's control then (since the default - // instance we could create here would not be configurable by the - // application in any way, and that is often not acceptable). - if (!window->vulkanInstance() && !wd->renderControl) - window->setVulkanInstance(QSGRhiSupport::defaultVulkanInstance()); + prepareWindowForRhi(window); // sets a vulkanInstance if not yet present rhiParams.inst = window->vulkanInstance(); if (!rhiParams.inst) qWarning("No QVulkanInstance set for QQuickWindow, this is wrong."); diff --git a/src/quick/scenegraph/qsgrhisupport_p.h b/src/quick/scenegraph/qsgrhisupport_p.h index 24cd787afc..f144a47a6a 100644 --- a/src/quick/scenegraph/qsgrhisupport_p.h +++ b/src/quick/scenegraph/qsgrhisupport_p.h @@ -127,6 +127,7 @@ public: QOffscreenSurface *maybeCreateOffscreenSurface(QWindow *window); QRhi *createRhi(QQuickWindow *window, QOffscreenSurface *offscreenSurface); + void prepareWindowForRhi(QQuickWindow *window); QImage grabAndBlockInCurrentFrame(QRhi *rhi, QRhiCommandBuffer *cb, QRhiTexture *src = nullptr); |