From 4ce41495b120b03a15e1cdf843bf42484c6a61d7 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Sun, 30 Jul 2023 17:07:27 -0300 Subject: [PATCH] Fix validation layer warnings 1. Validation layers on Windows were complaining w/ VUID-VkSwapchainCreateInfoKHR-surface-01270 that we were not calling vkGetPhysicalDeviceSurfaceSupportKHR before vkCreateSwapchainKHR. 2. Godot was only calling vkGetPhysicalDeviceSurfaceSupportKHR at startup, but it should be doing this for every window w/ a new surface it wants to create, not just the first one. - In practice this will likely not make a difference. If vkGetPhysicalDeviceSurfaceSupportKHR returns false after initialization, there's nothing we can do about it and it is likely because something else went terribly wrong, which is why the error message is worded like that. - This is mostly to shut up validation layers. Though technically, the layers are right. 3. Do not call vkGetPhysicalDeviceSurfaceSupportKHR on queues we don't even plan on ever using. We don't know how drivers will react to that (e.g. they may preemptetively allocate resources to support presentation on exotic queues, instead of just saying no). Just behave like every other Vulkan app out there. --- drivers/vulkan/vulkan_context.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index 3a1330b33104..c167caeb7cff 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -1195,12 +1195,15 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) { VkQueueFamilyProperties *device_queue_props = (VkQueueFamilyProperties *)malloc(device_queue_family_count * sizeof(VkQueueFamilyProperties)); vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[i], &device_queue_family_count, device_queue_props); for (uint32_t j = 0; j < device_queue_family_count; j++) { - VkBool32 supports; - vkGetPhysicalDeviceSurfaceSupportKHR(physical_devices[i], j, p_surface, &supports); - if (supports && ((device_queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)) { - present_supported = true; - } else { - continue; + if ((device_queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) { + VkBool32 supports; + err = vkGetPhysicalDeviceSurfaceSupportKHR( + physical_devices[i], j, p_surface, &supports); + if (err == VK_SUCCESS && supports) { + present_supported = true; + } else { + continue; + } } } String name = props.deviceName; @@ -1804,6 +1807,16 @@ Error VulkanContext::_update_swap_chain(Window *window) { err = fpGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu, window->surface, &surfCapabilities); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); + { + VkBool32 supports = VK_FALSE; + err = vkGetPhysicalDeviceSurfaceSupportKHR( + gpu, present_queue_family_index, window->surface, &supports); + ERR_FAIL_COND_V_MSG(err != VK_SUCCESS || supports == false, ERR_CANT_CREATE, + "Window's surface is not supported by device. Did the GPU go offline? Was the window " + "created on another monitor? Check previous errors & try launching with " + "--gpu-validation."); + } + uint32_t presentModeCount; err = fpGetPhysicalDeviceSurfacePresentModesKHR(gpu, window->surface, &presentModeCount, nullptr); ERR_FAIL_COND_V(err, ERR_CANT_CREATE);