vulkan/wsi: warn about unset present_mode in PresentModeCompatibilityExt
authorDerek Foreman <derek.foreman@collabora.com>
Fri, 25 Aug 2023 14:44:35 +0000 (09:44 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 30 Aug 2023 21:44:46 +0000 (21:44 +0000)
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 <derek.foreman@collabora.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24888>

src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_win32.cpp
src/vulkan/wsi/wsi_common_x11.c

index 3460256..fc30bee 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include "util/log.h"
 #include "vk_alloc.h"
 #include "vk_dispatch_table.h"
 #include <vulkan/vulkan.h>
@@ -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
index 51b9e18..21fe7a5 100644 (file)
@@ -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;
index 89276a1..34b0c64 100644 (file)
@@ -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;
index 6dd22b5..ce5e914 100644 (file)
@@ -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;