diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-07-14 13:10:03 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-07-28 13:03:57 +0200 |
commit | 5707573926bd7329fb468f519020b04197b245a1 (patch) | |
tree | 56f63a911af7ef90134c33573957b5485383731b /src/quick/scenegraph/qsgrhisupport.cpp | |
parent | ca62d2c81fb8a8e689393d8ea97f03cfa652e8b5 (diff) |
Fix multiple windows with Vulkan on basic render loop
No problems with threaded, but when using QSG_RENDER_LOOP=basic with
Vulkan we missed setting the Vulkan instance for the second, third, etc.
window.
The problem can be seen with the quick/window example, running it with
QSG_RHI_BACKEND=vulkan QSG_RENDER_LOOP=basic makes it fail. With the
patch it will function as expected.
Change-Id: I98e7cb5ff960200dadb2fcbc30f771f9a7d9a9ae
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/scenegraph/qsgrhisupport.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgrhisupport.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
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."); |