From 80dee1a9f9c9ce46eca912d28ebcc9cb2971abb5 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 30 Jan 2025 11:05:07 +0100 Subject: [PATCH] rhi: vulkan: Don't assert in VMA when vk header is older than runtime Building Qt with e.g. a version 1.2.x Vulkan SDK and then running on an implementation providing 1.3 or 1.4, one will likely get an assert in debug builds upon initializing the memory allocator. Work it around by restricting the apiVersion passed in based on the preprocessor macros. Pick-to: 6.8 Change-Id: Ia689ffc29d5675b84b6683e289d0725d7e47220b Reviewed-by: Andy Nichols (cherry picked from commit b6d4c1368d38242a8c677efc3144c10cfe363179) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhivulkan.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 9d217a3bfdd..d0528fd7c75 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -1017,9 +1017,37 @@ bool QRhiVulkan::create(QRhi::Flags flags) allocatorInfo.device = dev; allocatorInfo.pVulkanFunctions = &funcs; allocatorInfo.instance = inst->vkInstance(); - allocatorInfo.vulkanApiVersion = VK_MAKE_VERSION(caps.apiVersion.majorVersion(), - caps.apiVersion.minorVersion(), - caps.apiVersion.microVersion()); + + // Logic would dictate setting allocatorInfo.vulkanApiVersion to caps.apiVersion. + // However, VMA has asserts to test if the header version Qt was built with is + // older than the runtime version. This is nice, but a bit unnecessary (in Qt we'd + // rather prefer losing the affected features automatically, and perhaps printing + // a warning, instead of aborting the application). Restrict the runtime version + // passed in based on the preprocessor macro to keep VMA happy. +#ifdef VK_VERSION_1_4 + if (caps.apiVersion >= QVersionNumber(1, 4)) + allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_4; + else +#endif +#ifdef VK_VERSION_1_3 + if (caps.apiVersion >= QVersionNumber(1, 3)) + allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_3; + else +#endif +#ifdef VK_VERSION_1_2 + if (caps.apiVersion >= QVersionNumber(1, 2)) + allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_2; + else +#endif +#ifdef VK_VERSION_1_1 + if (caps.apiVersion >= QVersionNumber(1, 1)) + allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_1; + else +#endif +#ifdef VK_VERSION_1_0 + allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_0; +#endif + VmaAllocator vmaallocator; VkResult err = vmaCreateAllocator(&allocatorInfo, &vmaallocator); if (err != VK_SUCCESS) {