diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2024-02-14 12:10:30 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-06 20:34:30 +0000 |
commit | 513342052d25e4e4f8ff8b6c8464a97da3920aab (patch) | |
tree | b2d9ddfaee0ac45369d28714b4574881bb6145e4 | |
parent | 2c9587278f2d589e4f1cf3ee7706c0fbaf1c2173 (diff) |
QQuickWidget: Play nice with Vulkan and offscreen grabbing
The texture does not have the UsedAsTransferSource flag set. With
Vulkan this results in a validation layer warning (if that is enabled)
when issuing the VkImage -> buffer copy during the grab. Add the flag.
We also need to ensure there is a QVulkanInstance
(VkInstance). Normally we do not care about this and just forward what
the toplevel/backingstore use, but this is not there when trying to
grab with a not-yet-shown widget. Use the helper singleton
(QVulkanDefaultInstance) to get a QVulkanInstance. (this is also what
the backingstore and Qt Quick uses)
Change-Id: I9f5b4a67a1a7862e6b89e76f2a6d55c8a2be1972
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit b676c3fbc7117fbf0b3580c16a1173f9c383d54c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 205c9e31c7..a0efe916da 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -47,6 +47,10 @@ #include <QtWidgets/qgraphicsview.h> #endif +#if QT_CONFIG(vulkan) +#include <QtGui/private/qvulkandefaultinstance_p.h> +#endif + QT_BEGIN_NAMESPACE QQuickWidgetOffscreenWindow::QQuickWidgetOffscreenWindow(QQuickWindowPrivate &dd, QQuickRenderControl *control) @@ -1084,6 +1088,8 @@ void QQuickWidgetPrivate::initializeWithRhi() #if QT_CONFIG(vulkan) if (QWindow *w = q->window()->windowHandle()) offscreenWindow->setVulkanInstance(w->vulkanInstance()); + else if (rhi == offscreenRenderer.rhi()) + offscreenWindow->setVulkanInstance(QVulkanDefaultInstance::instance()); #endif renderControl->initialize(); } @@ -1130,7 +1136,7 @@ void QQuickWidget::createFramebufferObject() // Could be a simple hide - show, in which case the previous texture is just fine. if (!d->outputTexture) { - d->outputTexture = d->rhi->newTexture(QRhiTexture::RGBA8, fboSize, 1, QRhiTexture::RenderTarget); + d->outputTexture = d->rhi->newTexture(QRhiTexture::RGBA8, fboSize, 1, QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource); if (!d->outputTexture->create()) { qWarning("QQuickWidget: failed to create output texture of size %dx%d", fboSize.width(), fboSize.height()); |