From afe0bf0914362ff6f8e83ebd17f6cc346805a072 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 24 May 2023 10:39:21 +0200 Subject: [PATCH] rhi: vulkan: expose the instance in the nativeHandles query Mainly for completeness, but it has practical uses: someone retrieving a QRhi instance from somewhere should be able to tell the QVulkanInstance, and so the VkInstance, used by that QRhi without resorting to investigating other objects (e.g. retrieving the instance from the QWindow). This provides symmetry to other 3D APIs and QRhi backends where just a single QRhi instance is sufficient to get the MTLDevice, ID3D11Device/Context, etc. i.e. all that is needed to work with the 3D API directly. Change-Id: I5a8b9871a543ea648c76b868bf6ff7be5f2098f2 Reviewed-by: Jonas Karlsson Reviewed-by: Hatem ElKharashy --- src/gui/rhi/qrhi_platform.h | 5 ++++- src/gui/rhi/qrhivulkan.cpp | 14 +++++++++++--- tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gui/rhi/qrhi_platform.h b/src/gui/rhi/qrhi_platform.h index 8307e9217c..30676d0da6 100644 --- a/src/gui/rhi/qrhi_platform.h +++ b/src/gui/rhi/qrhi_platform.h @@ -86,9 +86,12 @@ struct Q_GUI_EXPORT QRhiVulkanNativeHandles : public QRhiNativeHandles VkDevice dev = VK_NULL_HANDLE; quint32 gfxQueueFamilyIdx = 0; quint32 gfxQueueIdx = 0; - VkQueue gfxQueue = VK_NULL_HANDLE; // and optionally, the mem allocator void *vmemAllocator = nullptr; + + // only for querying (rhi->nativeHandles()) + VkQueue gfxQueue = VK_NULL_HANDLE; + QVulkanInstance *inst = nullptr; }; struct Q_GUI_EXPORT QRhiVulkanCommandBufferNativeHandles : public QRhiNativeHandles diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 6fe79f223e..a0e6a467bb 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -225,6 +225,13 @@ QT_BEGIN_NAMESPACE Graphics queue index. */ +/*! + \variable QRhiVulkanNativeHandles::vmemAllocator + + Relevant only when importing an existing memory allocator object, + leave it set to \nullptr otherwise. +*/ + /*! \variable QRhiVulkanNativeHandles::gfxQueue @@ -233,10 +240,10 @@ QT_BEGIN_NAMESPACE */ /*! - \variable QRhiVulkanNativeHandles::vmemAllocator + \variable QRhiVulkanNativeHandles::inst - Relevant only when importing an existing memory allocator object, - leave it set to \nullptr otherwise. + Output only, not used by QRhi::create(), only set by the + QRhi::nativeHandles() accessor. The QVulkanInstance used by the QRhi. */ /*! @@ -819,6 +826,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) nativeHandlesStruct.gfxQueueIdx = gfxQueueIdx; nativeHandlesStruct.gfxQueue = gfxQueue; nativeHandlesStruct.vmemAllocator = allocator; + nativeHandlesStruct.inst = inst; return true; } diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 6aeae2eb03..942ee06fe4 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -487,6 +487,8 @@ void tst_QRhi::nativeHandles() case QRhi::Vulkan: { const QRhiVulkanNativeHandles *vkHandles = static_cast(rhiHandles); + QVERIFY(vkHandles->inst); + QCOMPARE(vkHandles->inst, &vulkanInstance); QVERIFY(vkHandles->physDev); QVERIFY(vkHandles->dev); QVERIFY(vkHandles->gfxQueue);