diff options
Diffstat (limited to 'src/quick/scenegraph/qsgrhisupport.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgrhisupport.cpp | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/src/quick/scenegraph/qsgrhisupport.cpp b/src/quick/scenegraph/qsgrhisupport.cpp index 2bf70ddec6..2a49a0958d 100644 --- a/src/quick/scenegraph/qsgrhisupport.cpp +++ b/src/quick/scenegraph/qsgrhisupport.cpp @@ -42,8 +42,11 @@ #if QT_CONFIG(opengl) # include "qsgdefaultrendercontext_p.h" #endif -#include <QtGui/qwindow.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquickwindow_p.h> + +#include <QtGui/qwindow.h> #if QT_CONFIG(vulkan) #include <QtGui/qvulkaninstance.h> #endif @@ -91,7 +94,7 @@ QVulkanInstance *QSGRhiSupport::vulkanInstance() #endif } -void QSGRhiSupport::cleanup() +void QSGRhiSupport::cleanupVulkanInstance() { #if QT_CONFIG(vulkan) delete s_vulkanInstance; @@ -100,7 +103,7 @@ void QSGRhiSupport::cleanup() } QSGRhiSupport::QSGRhiSupport() - : m_set(false), + : m_settingsApplied(false), m_enableRhi(false), m_debugLayer(false), m_profile(false), @@ -111,7 +114,7 @@ QSGRhiSupport::QSGRhiSupport() void QSGRhiSupport::applySettings() { - m_set = true; + m_settingsApplied = true; // This is also done when creating the renderloop but we may be before that // in case we get here due to a setScenegraphBackend() -> configure() early @@ -160,8 +163,10 @@ void QSGRhiSupport::applySettings() } else if (rhiBackend == QByteArrayLiteral("null")) { m_rhiBackend = QRhi::Null; } else { - if (!rhiBackend.isEmpty()) - qWarning("Unknown key \"%s\" for QSG_RHI_BACKEND, falling back to default backend.", qPrintable(rhiBackend)); + if (!rhiBackend.isEmpty()) { + qWarning("Unknown key \"%s\" for QSG_RHI_BACKEND, falling back to default backend.", + rhiBackend.constData()); + } #if defined(Q_OS_WIN) m_rhiBackend = QRhi::D3D11; #elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) @@ -215,10 +220,6 @@ void QSGRhiSupport::configure(QSGRendererInterface::GraphicsApi api) { Q_ASSERT(QSGRendererInterface::isApiRhiBased(api)); QSGRhiSupport *inst = staticInst(); - if (inst->m_set) { - qWarning("QRhi is already configured, request ignored"); - return; - } inst->m_requested.valid = true; inst->m_requested.api = api; inst->m_requested.rhi = true; @@ -228,7 +229,7 @@ void QSGRhiSupport::configure(QSGRendererInterface::GraphicsApi api) QSGRhiSupport *QSGRhiSupport::instance() { QSGRhiSupport *inst = staticInst(); - if (!inst->m_set) + if (!inst->m_settingsApplied) inst->applySettings(); return inst; } @@ -474,11 +475,10 @@ QOffscreenSurface *QSGRhiSupport::maybeCreateOffscreenSurface(QWindow *window) } // must be called on the render thread -QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurface) +QRhi *QSGRhiSupport::createRhi(QQuickWindow *window, QOffscreenSurface *offscreenSurface) { -#if !QT_CONFIG(opengl) && !QT_CONFIG(vulkan) - Q_UNUSED(window); -#endif + const QQuickGraphicsDevice &customDev(QQuickWindowPrivate::get(window)->customDeviceObjects); + const QQuickGraphicsDevicePrivate *customDevD = QQuickGraphicsDevicePrivate::get(&customDev); QRhi *rhi = nullptr; @@ -500,7 +500,14 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf rhiParams.format = format; rhiParams.fallbackSurface = offscreenSurface; rhiParams.window = window; - rhi = QRhi::create(backend, &rhiParams, flags); + if (customDevD->type == QQuickGraphicsDevicePrivate::Type::OpenGLContext) { + QRhiGles2NativeHandles importDev; + importDev.context = customDevD->u.context; + qCDebug(QSG_LOG_INFO, "Using existing QOpenGLContext %p", importDev.context); + rhi = QRhi::create(backend, &rhiParams, flags, &importDev); + } else { + rhi = QRhi::create(backend, &rhiParams, flags); + } } #else Q_UNUSED(offscreenSurface); @@ -511,8 +518,19 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf rhiParams.inst = window->vulkanInstance(); if (!rhiParams.inst) qWarning("No QVulkanInstance set for QQuickWindow, this is wrong."); - rhiParams.window = window; - rhi = QRhi::create(backend, &rhiParams, flags); + if (window->handle()) // only used for vkGetPhysicalDeviceSurfaceSupportKHR and that implies having a valid native window + rhiParams.window = window; + if (customDevD->type == QQuickGraphicsDevicePrivate::Type::DeviceObjects) { + QRhiVulkanNativeHandles importDev; + importDev.physDev = reinterpret_cast<VkPhysicalDevice>(customDevD->u.deviceObjects.physicalDevice); + importDev.dev = reinterpret_cast<VkDevice>(customDevD->u.deviceObjects.device); + importDev.gfxQueueFamilyIdx = customDevD->u.deviceObjects.queueFamilyIndex; + qCDebug(QSG_LOG_INFO, "Using existing native Vulkan physical device %p device %p graphics queue family index %d", + importDev.physDev, importDev.dev, importDev.gfxQueueFamilyIdx); + rhi = QRhi::create(backend, &rhiParams, flags, &importDev); + } else { + rhi = QRhi::create(backend, &rhiParams, flags); + } } #endif #ifdef Q_OS_WIN @@ -523,13 +541,31 @@ QRhi *QSGRhiSupport::createRhi(QWindow *window, QOffscreenSurface *offscreenSurf rhiParams.framesUntilKillingDeviceViaTdr = m_killDeviceFrameCount; rhiParams.repeatDeviceKill = true; } - rhi = QRhi::create(backend, &rhiParams, flags); + if (customDevD->type == QQuickGraphicsDevicePrivate::Type::DeviceAndContext) { + QRhiD3D11NativeHandles importDev; + importDev.dev = customDevD->u.deviceAndContext.device; + importDev.context = customDevD->u.deviceAndContext.context; + qCDebug(QSG_LOG_INFO, "Using existing native D3D11 device %p and context %p", + importDev.dev, importDev.context); + rhi = QRhi::create(backend, &rhiParams, flags, &importDev); + } else { + rhi = QRhi::create(backend, &rhiParams, flags); + } } #endif #if defined(Q_OS_MACOS) || defined(Q_OS_IOS) if (backend == QRhi::Metal) { QRhiMetalInitParams rhiParams; - rhi = QRhi::create(backend, &rhiParams, flags); + if (customDevD->type == QQuickGraphicsDevicePrivate::Type::DeviceAndCommandQueue) { + QRhiMetalNativeHandles importDev; + importDev.dev = customDevD->u.deviceAndCommandQueue.device; + importDev.cmdQueue = customDevD->u.deviceAndCommandQueue.cmdQueue; + qCDebug(QSG_LOG_INFO, "Using existing native Metal device %p and command queue %p", + importDev.dev, importDev.cmdQueue); + rhi = QRhi::create(backend, &rhiParams, flags, &importDev); + } else { + rhi = QRhi::create(backend, &rhiParams, flags); + } } #endif |