diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-01-15 18:06:10 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-01-18 13:21:15 +0100 |
commit | 9f7088fd7f0aac84b565f8a9494bf9de4bab85ea (patch) | |
tree | 79cb892bb96dfe97479206e731fc42f019c68b3a | |
parent | 036021b0d0ee03c095a26200cf8c8b478c37eae1 (diff) |
rhi: Stop hardcoding the Vulkan backend's desired instance extensions
Instead, have a static function in QRhiVulkanInitParams then Qt Quick
and anyone else who creates a QVulkanInstance that is then used in
combination with QRhi can query.
Change-Id: I046e0d84541fc00f5487a7527c97be262221527f
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/gui/rhi/qrhivulkan.cpp | 48 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan_p.h | 3 | ||||
-rw-r--r-- | tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 3 | ||||
-rw-r--r-- | tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp | 2 | ||||
-rw-r--r-- | tests/manual/rhi/shared/examplefw.h | 3 |
5 files changed, 44 insertions, 15 deletions
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 939c8fa8f2..a2e5579165 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -116,8 +116,7 @@ QT_BEGIN_NAMESPACE << "VK_LAYER_LUNARG_swapchain" << "VK_LAYER_GOOGLE_unique_objects"); #endif - inst.setExtensions(QByteArrayList() - << "VK_KHR_get_physical_device_properties2"); + inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); if (!inst.create()) qFatal("Vulkan not available"); @@ -125,16 +124,18 @@ QT_BEGIN_NAMESPACE } \endcode - The example here has two optional aspects: it enables the + This example enables the \l{https://github.com/KhronosGroup/Vulkan-ValidationLayers}{Vulkan validation layers}, when they are available, and also enables the - VK_KHR_get_physical_device_properties2 extension (part of Vulkan 1.1), when - available. The former is useful during the development phase (remember that - QVulkanInstance conveniently redirects messages and warnings to qDebug). - Avoid enabling it in production builds, however. The latter is important in - order to make QRhi::CustomInstanceStepRate available with Vulkan since - VK_EXT_vertex_attribute_divisor (part of Vulkan 1.1) depends on it. It can - be omitted when instanced drawing with a non-one step rate is not used. + instance-level extensions QRhi reports as desirable (such as, + VK_KHR_get_physical_device_properties2), as long as they are supported by + the Vulkan implementation at run time. + + The former is optional, and is useful during the development phase + QVulkanInstance conveniently redirects messages and warnings to qDebug. + Avoid enabling it in production builds, however. The latter is strongly + recommended, and is important in order to make certain features functional + (for example, QRhi::CustomInstanceStepRate). Once this is done, a Vulkan-based QRhi can be created by passing the instance and a QWindow with its surface type set to @@ -159,6 +160,12 @@ QT_BEGIN_NAMESPACE in deviceExtensions. This can be relevant when integrating with native Vulkan rendering code. + It is expected that the desired list of instance extensions will be queried + by calling the static function preferredInstanceExtensions() before + initializing a QVulkanInstance. The returned list can be passed to + QVulkanInstance::setExtensions() as-is, because unsupported extensions are + filtered out automatically. + \section2 Working with existing Vulkan devices When interoperating with another graphics engine, it may be necessary to @@ -182,6 +189,11 @@ QT_BEGIN_NAMESPACE memory allocator} between two QRhi instances. The QRhi does not take ownership of any of the external objects. + + Applications are encouraged to query the list of desired device extensions + by calling the static function preferredExtensionsForImportedDevice(), and + enable them on the VkDevice. Otherwise certain QRhi features may not be + available. */ /*! @@ -311,6 +323,22 @@ static inline VmaAllocator toVmaAllocator(QVkAllocator a) return reinterpret_cast<VmaAllocator>(a); } +QByteArrayList QRhiVulkanInitParams::preferredInstanceExtensions() +{ + return { + QByteArrayLiteral("VK_KHR_get_physical_device_properties2") + }; +} + +QByteArrayList QRhiVulkanInitParams::preferredExtensionsForImportedDevice() +{ + return { + QByteArrayLiteral("VK_KHR_swapchain"), + QByteArrayLiteral("VK_EXT_debug_marker"), + QByteArrayLiteral("VK_EXT_vertex_attribute_divisor") + }; +} + QRhiVulkan::QRhiVulkan(QRhiVulkanInitParams *params, QRhiVulkanNativeHandles *importParams) : ofr(this) { diff --git a/src/gui/rhi/qrhivulkan_p.h b/src/gui/rhi/qrhivulkan_p.h index 3e60b7dda4..4d20b93911 100644 --- a/src/gui/rhi/qrhivulkan_p.h +++ b/src/gui/rhi/qrhivulkan_p.h @@ -61,6 +61,9 @@ struct Q_GUI_EXPORT QRhiVulkanInitParams : public QRhiInitParams QVulkanInstance *inst = nullptr; QWindow *window = nullptr; QByteArrayList deviceExtensions; + + static QByteArrayList preferredInstanceExtensions(); + static QByteArrayList preferredExtensionsForImportedDevice(); }; struct Q_GUI_EXPORT QRhiVulkanNativeHandles : public QRhiNativeHandles diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index db83f7955f..1b473ed023 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -165,8 +165,7 @@ void tst_QRhi::initTestCase() QByteArrayLiteral("VK_LAYER_LUNARG_swapchain"), QByteArrayLiteral("VK_LAYER_GOOGLE_unique_objects") }); #endif - vulkanInstance.setExtensions(QByteArrayList() - << "VK_KHR_get_physical_device_properties2"); + vulkanInstance.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); vulkanInstance.create(); initParams.vk.inst = &vulkanInstance; #endif diff --git a/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp b/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp index 8e04e8303d..a8e1556057 100644 --- a/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp +++ b/tests/manual/rhi/hellominimalcrossgfxtriangle/main.cpp @@ -138,7 +138,7 @@ int main(int argc, char **argv) "VK_LAYER_LUNARG_swapchain", "VK_LAYER_GOOGLE_unique_objects"}); #endif - inst.setExtensions({ "VK_KHR_get_physical_device_properties2" }); + inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); if (!inst.create()) { qWarning("Failed to create Vulkan instance, switching to OpenGL"); graphicsApi = QRhi::OpenGLES2; diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h index 282e3ec8d6..228dc2a181 100644 --- a/tests/manual/rhi/shared/examplefw.h +++ b/tests/manual/rhi/shared/examplefw.h @@ -549,8 +549,7 @@ int main(int argc, char **argv) << "VK_LAYER_GOOGLE_unique_objects"); #endif } - inst.setExtensions(QByteArrayList() - << "VK_KHR_get_physical_device_properties2"); + inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); if (!inst.create()) { qWarning("Failed to create Vulkan instance, switching to OpenGL"); graphicsApi = OpenGL; |