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>
bb10
Laszlo Agocs 2021-01-15 18:06:10 +01:00
parent 036021b0d0
commit 9f7088fd7f
5 changed files with 44 additions and 15 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;