From ba3015563849e61012f07ec6df790009c631d0c9 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 9 Aug 2022 11:47:54 +0200 Subject: rhi: vulkan: Enable all core features on the device ...except robustness. Have the appropriate compile and runtime checks. This way we still compile with any older (1.0, 1.1, 1.2) headers, and can function at runtime with a plain 1.0 implementation. With Vulkan 1.2+ we can start filling out the additional, version-specific (1.1, 1.2, 1.3) feature structs. Task-number: QTBUG-105158 Change-Id: I0ba87f0f467bc11782e9203ff11f1ce494aaaf63 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhivulkan.cpp | 43 +++++++++++++++++++++++++++++++++++++++---- src/gui/rhi/qrhivulkan_p_p.h | 2 ++ 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index c53dcc9a0b..e803e38056 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -389,6 +389,8 @@ bool QRhiVulkan::create(QRhi::Flags flags) f = inst->functions(); caps.vulkan11OrHigher = inst->apiVersion() >= QVersionNumber(1, 1); + caps.vulkan12OrHigher = inst->apiVersion() >= QVersionNumber(1, 2); + caps.vulkan13OrHigher = inst->apiVersion() >= QVersionNumber(1, 3); rhiFlags = flags; @@ -583,7 +585,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) devInfo.enabledExtensionCount = uint32_t(requestedDevExts.count()); devInfo.ppEnabledExtensionNames = requestedDevExts.constData(); - // Enable all 1.0 core features that are reported as supported, except + // Enable all features that are reported as supported, except // robustness because that potentially affects performance. // // Enabling all features mainly serves third-party renderers that may @@ -596,10 +598,43 @@ bool QRhiVulkan::create(QRhi::Flags flags) // tessellationShader, geometryShader // textureCompressionETC2, textureCompressionASTC_LDR, textureCompressionBC +#ifdef VK_VERSION_1_2 // Vulkan11Features is only in Vulkan 1.2 + VkPhysicalDeviceFeatures2 physDevFeatures2 = {}; + physDevFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + + VkPhysicalDeviceVulkan11Features features11 = {}; + features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES; + VkPhysicalDeviceVulkan12Features features12 = {}; + features12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; +#ifdef VK_VERSION_1_3 + VkPhysicalDeviceVulkan13Features features13 = {}; + features13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; +#endif + + if (caps.vulkan12OrHigher) { + physDevFeatures2.pNext = &features11; + features11.pNext = &features12; +#ifdef VK_VERSION_1_3 + if (caps.vulkan13OrHigher) + features12.pNext = &features13; +#endif + f->vkGetPhysicalDeviceFeatures2(physDev, &physDevFeatures2); + + physDevFeatures2.features.robustBufferAccess = VK_FALSE; +#ifdef VK_VERSION_1_3 + features13.robustImageAccess = VK_FALSE; +#endif + + devInfo.pNext = &physDevFeatures2; + } +#endif // VK_VERSION_1_2 + VkPhysicalDeviceFeatures features; - memcpy(&features, &physDevFeatures, sizeof(features)); - features.robustBufferAccess = VK_FALSE; - devInfo.pEnabledFeatures = &features; + if (!devInfo.pNext) { + memcpy(&features, &physDevFeatures, sizeof(features)); + features.robustBufferAccess = VK_FALSE; + devInfo.pEnabledFeatures = &features; + } VkResult err = f->vkCreateDevice(physDev, &devInfo, nullptr, &dev); if (err != VK_SUCCESS) { diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index 940cec7a58..fd981fffa6 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -857,6 +857,8 @@ public: bool vulkan11OrHigher = false; bool geometryShader = false; bool nonFillPolygonMode = false; + bool vulkan12OrHigher = false; + bool vulkan13OrHigher = false; } caps; VkPipelineCache pipelineCache = VK_NULL_HANDLE; -- cgit v1.2.3