From bf1c7ac5cf0da0af15b527ae835f572608a31520 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Fri, 25 Aug 2023 09:44:35 -0500 Subject: [PATCH] vulkan/wsi: warn about unset present_mode in PresentModeCompatibilityExt A bug in vulkan tools, https://github.com/KhronosGroup/Vulkan-Tools/issues/846 causes vulkaninfo to crash in Mesa under wayland since the changes in 5ceba97c Handle the crashing case on wayland similarly to how other WSIs do (nonsensically claiming a single compatible mode), and log the condition once for all WSIs. Fixes 5ceba97c2 Signed-off-by: Derek Foreman Reviewed-By: Mike Blumenkrantz Part-of: --- src/vulkan/wsi/wsi_common.h | 10 ++++++++++ src/vulkan/wsi/wsi_common_wayland.c | 21 ++++++++++++++------- src/vulkan/wsi/wsi_common_win32.cpp | 4 ++++ src/vulkan/wsi/wsi_common_x11.c | 4 ++++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index 3460256..fc30bee 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -26,6 +26,7 @@ #include #include +#include "util/log.h" #include "vk_alloc.h" #include "vk_dispatch_table.h" #include @@ -343,6 +344,15 @@ wsi_common_bind_swapchain_image(const struct wsi_device *wsi, bool wsi_common_vk_instance_supports_present_wait(const struct vk_instance *instance); +#define wsi_common_vk_warn_once(warning) \ + do { \ + static int warned = false; \ + if (!warned) { \ + mesa_loge(warning); \ + warned = true; \ + } \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 51b9e18..21fe7a5 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -1157,14 +1157,21 @@ wsi_wl_surface_get_capabilities2(VkIcdSurfaceBase *surface, break; } } else { - switch (present_mode->presentMode) { - case VK_PRESENT_MODE_MAILBOX_KHR: - case VK_PRESENT_MODE_FIFO_KHR: - compat->presentModeCount = 2; - break; - default: + if (!present_mode) { + wsi_common_vk_warn_once("Use of VkSurfacePresentModeCompatibilityEXT " + "without a VkSurfacePresentModeEXT set. This is an " + "application bug.\n"); compat->presentModeCount = 1; - break; + } else { + switch (present_mode->presentMode) { + case VK_PRESENT_MODE_MAILBOX_KHR: + case VK_PRESENT_MODE_FIFO_KHR: + compat->presentModeCount = 2; + break; + default: + compat->presentModeCount = 1; + break; + } } } break; diff --git a/src/vulkan/wsi/wsi_common_win32.cpp b/src/vulkan/wsi/wsi_common_win32.cpp index 89276a1..34b0c64 100644 --- a/src/vulkan/wsi/wsi_common_win32.cpp +++ b/src/vulkan/wsi/wsi_common_win32.cpp @@ -270,6 +270,10 @@ wsi_win32_surface_get_capabilities2(VkIcdSurfaceBase *surface, compat->presentModeCount = 1; } } else { + if (!present_mode) + wsi_common_vk_warn_once("Use of VkSurfacePresentModeCompatibilityEXT " + "without a VkSurfacePresentModeEXT set. This is an " + "application bug.\n"); compat->presentModeCount = 1; } break; diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 6dd22b5..ce5e914 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -788,6 +788,10 @@ x11_surface_get_capabilities2(VkIcdSurfaceBase *icd_surface, compat->presentModeCount = 1; } } else { + if (!present_mode) + wsi_common_vk_warn_once("Use of VkSurfacePresentModeCompatibilityEXT " + "without a VkSurfacePresentModeEXT set. This is an " + "application bug.\n"); compat->presentModeCount = 1; } break; -- 2.7.4