From b484f7aef0a8e6d64bb442937886cfada89e777a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 25 Feb 2023 23:25:04 +1000 Subject: [PATCH] Context/Vulkan: Handle VK_INCOMPLETE return from vkEnumeratePhysicalDevices() --- common/Vulkan/Context.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/Vulkan/Context.cpp b/common/Vulkan/Context.cpp index a88290663a..625bc6949e 100644 --- a/common/Vulkan/Context.cpp +++ b/common/Vulkan/Context.cpp @@ -197,9 +197,9 @@ namespace Vulkan { u32 gpu_count = 0; VkResult res = vkEnumeratePhysicalDevices(instance, &gpu_count, nullptr); - if (res != VK_SUCCESS || gpu_count == 0) + if ((res != VK_SUCCESS && res != VK_INCOMPLETE) || gpu_count == 0) { - LOG_VULKAN_ERROR(res, "vkEnumeratePhysicalDevices failed: "); + LOG_VULKAN_ERROR(res, "vkEnumeratePhysicalDevices (1) failed: "); return {}; } @@ -207,12 +207,20 @@ namespace Vulkan gpus.resize(gpu_count); res = vkEnumeratePhysicalDevices(instance, &gpu_count, gpus.data()); - if (res != VK_SUCCESS) + if (res == VK_INCOMPLETE) { - LOG_VULKAN_ERROR(res, "vkEnumeratePhysicalDevices failed: "); + Console.Warning("First vkEnumeratePhysicalDevices() call returned %zu devices, but second returned %u", gpus.size(), gpu_count); + } + else if (res != VK_SUCCESS) + { + LOG_VULKAN_ERROR(res, "vkEnumeratePhysicalDevices (2) failed: "); return {}; } + // Maybe we lost a GPU? + if (gpu_count < gpus.size()) + gpus.resize(gpu_count); + return gpus; }