From c12fa6b6fab8d78aa4ec0748068b5eaca97be07e Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 20 Jun 2023 12:52:28 +0200 Subject: [PATCH] rhi: vulkan: Shuffle post-1.0 phys.dev.feature queries Make it so that what we query with regards to 1.1, 1.2, and 1.3 features are stored for later use. This will be relevant for e.g. multiview where the multiview field will need to be checked when deciding if the feature is supported at run time. All this is only really compatible with Vulkan 1.2 and newer. Vulkan 1.1 does not have the 1.2 approach, i.e. there is no VkPhysicalDeviceVulkan11Features in Vulkan 1.1 (!). That is a struct added in Vulkan 1.2. In 1.1 one had the feature (extension) specific structs, such as VkPhysicalDeviceMultiviewFeatures in case of multiview. That we do not bother with at the moment. Then again that's nothing new. The existing code to enable all features with a few exceptions, that's already tied to the 1.2+ way of working with physical device features, and not quite compatible with a pure 1.1 (not 1.0, not 1.2+) implementation (which should be hopefully rare out there). Change-Id: I661f2634651d28edd9b5feec66a423220920f894 Reviewed-by: Andy Nichols Reviewed-by: Qt CI Bot (cherry picked from commit fc3ee08737ab53b8ad033e50b3b14fc8bba4bca1) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhivulkan.cpp | 66 +++++++++++++++++++------------------- src/gui/rhi/qrhivulkan_p.h | 7 ++++ 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index db9c6ed6ad6..a3c94042478 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -529,7 +529,31 @@ bool QRhiVulkan::create(QRhi::Flags flags) driverInfoStruct.vendorId = physDevProperties.vendorID; driverInfoStruct.deviceType = toRhiDeviceType(physDevProperties.deviceType); - f->vkGetPhysicalDeviceFeatures(physDev, &physDevFeatures); +#ifdef VK_VERSION_1_2 // Vulkan11Features is only in Vulkan 1.2 + VkPhysicalDeviceFeatures2 physDevFeaturesChainable = {}; + physDevFeaturesChainable.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + physDevFeatures11 = {}; + physDevFeatures11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES; + physDevFeatures12 = {}; + physDevFeatures12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; +#ifdef VK_VERSION_1_3 + physDevFeatures13 = {}; + physDevFeatures13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; +#endif + if (caps.apiVersion >= QVersionNumber(1, 2)) { + physDevFeaturesChainable.pNext = &physDevFeatures11; + physDevFeatures11.pNext = &physDevFeatures12; +#ifdef VK_VERSION_1_3 + if (caps.apiVersion >= QVersionNumber(1, 3)) + physDevFeatures12.pNext = &physDevFeatures13; +#endif + f->vkGetPhysicalDeviceFeatures2(physDev, &physDevFeaturesChainable); + memcpy(&physDevFeatures, &physDevFeaturesChainable.features, sizeof(VkPhysicalDeviceFeatures)); + } else +#endif // VK_VERSION_1_2 + { + f->vkGetPhysicalDeviceFeatures(physDev, &physDevFeatures); + } // Choose queue and create device, unless the device was specified in importParams. if (!importedDevice) { @@ -662,42 +686,18 @@ 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 - +#ifdef VK_VERSION_1_2 if (caps.apiVersion >= QVersionNumber(1, 2)) { - physDevFeatures2.pNext = &features11; - features11.pNext = &features12; + physDevFeaturesChainable.features.robustBufferAccess = VK_FALSE; #ifdef VK_VERSION_1_3 - if (caps.apiVersion >= QVersionNumber(1, 3)) - features12.pNext = &features13; + physDevFeatures13.robustImageAccess = VK_FALSE; #endif - f->vkGetPhysicalDeviceFeatures2(physDev, &physDevFeatures2); - - physDevFeatures2.features.robustBufferAccess = VK_FALSE; -#ifdef VK_VERSION_1_3 - features13.robustImageAccess = VK_FALSE; -#endif - - devInfo.pNext = &physDevFeatures2; - } + devInfo.pNext = &physDevFeaturesChainable; + } else #endif // VK_VERSION_1_2 - - VkPhysicalDeviceFeatures features; - if (!devInfo.pNext) { - memcpy(&features, &physDevFeatures, sizeof(features)); - features.robustBufferAccess = VK_FALSE; - devInfo.pEnabledFeatures = &features; + { + physDevFeatures.robustBufferAccess = VK_FALSE; + devInfo.pEnabledFeatures = &physDevFeatures; } VkResult err = f->vkCreateDevice(physDev, &devInfo, nullptr, &dev); diff --git a/src/gui/rhi/qrhivulkan_p.h b/src/gui/rhi/qrhivulkan_p.h index 7ba1b8c89b3..fa35dcc4667 100644 --- a/src/gui/rhi/qrhivulkan_p.h +++ b/src/gui/rhi/qrhivulkan_p.h @@ -834,6 +834,13 @@ public: QVulkanDeviceFunctions *df = nullptr; QRhi::Flags rhiFlags; VkPhysicalDeviceFeatures physDevFeatures; +#ifdef VK_VERSION_1_2 + VkPhysicalDeviceVulkan11Features physDevFeatures11; + VkPhysicalDeviceVulkan12Features physDevFeatures12; +#endif +#ifdef VK_VERSION_1_3 + VkPhysicalDeviceVulkan13Features physDevFeatures13; +#endif VkPhysicalDeviceProperties physDevProperties; VkDeviceSize ubufAlign; VkDeviceSize texbufAlign;