[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#983390: mesa-vulkan-drivers: bad interactions between VkLayer_MESA_device_select and other layers

Package: mesa-vulkan-drivers
Version: 20.3.4-1
Severity: important
Tags: patch fixed-upstream
Forwarded: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3801
Control: found -1 21.0.0~rc2-1

The device selection layer in Mesa 20.3.x >= 20.3.4 and 21.0.x >= 21.0.0~rc2
has problematic interactions with other Vulkan layers, in particular
MangoHUD. The bad interactions seem to be relatively complicated (dependent
on other components), and particularly likely to be triggered when using
Wine with DXVK.

In Steam's Proton compatibility tool (Wine + DXVK) this seems to manifest
as a game not starting, rather than as a crash - although maybe this is
really a behind-the-scenes component like winedevice.exe crashing.

The attached patch from upstream appears to resolve this. I'm talking to
an upstream Mesa maintainer about getting this into point releases, but
it would also be great if you could make sure this gets into Debian 11.0.

I can reproduce this with 20.3.4-1, and it can be resolved by rebuilding
20.3.4 with this patch and overwriting both word-sizes' versions of
/usr/lib/*-linux-gnu/libVkLayer_MESA_device_select.so. Unfortunately, my
only reliable reproducer is far from minimal:

* Debian testing
* Install mesa-vulkan-drivers:amd64, mesa-vulkan-drivers:i386,
  mangohud:amd64, mangohud:i386 and Steam
* In Steam, install some games, and force them to use the Proton 5.13
  compatibility tool so that you get the Windows version instead of any
  native Linux version that might exist.
  I used Life Is Strange (32-bit) and Life Is Strange 2 (64-bit) which
  are available at no cost.
* Opt in to the beta branch of the "Steam Linux Runtime - soldier"
  container tool. This fixes a bug that hid this one by not always
  enabling MangoHUD successfully.
* Run Steam with MANGOHUD=1 in the environment
* Launch each game in turn
* Good result: The games launch, and have the MangoHUD fps display showing
* Bad result: The games don't start; `top` shows intermittent activity
  from winedevice.exe

I haven't yet verified that the Mesa in experimental also has this bug,
but from the git history, versions >= 21.0.0~rc2-1 are likely to have it,
and I've had reports of the same issue in 21.0.0~rc4 and ~rc5 in
non-Debian distros.

From: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Date: Mon, 11 Jan 2021 15:20:40 +0100
Subject: vulkan/device_select: Stop using device properties 2.

We have to choose between:
1) Stop handling two identical GPUs
2) Stop having crashes with other layers active.
3) Fix the Vulkan Loader.

Since nobody seems to want to spend enough effort to do 3 the
effective choice is between 1 and 2. This is choosing 2, as
two identical GPUs is pretty uncommon since crossfire doesn't
work on Linux anyway.

(And it would only work sporadically as the game needs to enable the

CC: mesa-stable
Bug: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3801
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8414>
Origin: upstream, 21.1, commit:38ce8d4d00c2b0e567b6dd36876cf171acb1dbc7
 .../device-select-layer/device_select_layer.c      | 30 +++++++++++++---------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/vulkan/device-select-layer/device_select_layer.c b/src/vulkan/device-select-layer/device_select_layer.c
index c381ac3..134a3bd 100644
--- a/src/vulkan/device-select-layer/device_select_layer.c
+++ b/src/vulkan/device-select-layer/device_select_layer.c
@@ -51,8 +51,8 @@ struct instance_info {
    PFN_GetPhysicalDeviceProcAddr  GetPhysicalDeviceProcAddr;
    PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
    PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
-   PFN_vkGetPhysicalDeviceProperties2KHR GetPhysicalDeviceProperties2KHR;
-   bool has_props2, has_pci_bus;
+   PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2;
+   bool has_pci_bus, has_vulkan11;
    bool has_wayland, has_xcb;
@@ -150,8 +150,6 @@ static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreate
    for (unsigned i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-      if (!strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
-         info->has_props2 = true;
       if (!strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME))
          info->has_wayland = true;
@@ -162,6 +160,14 @@ static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreate
+   /*
+    * The loader is currently not able to handle GetPhysicalDeviceProperties2KHR calls in
+    * EnumeratePhysicalDevices when there are other layers present. To avoid mysterious crashes
+    * for users just use only the vulkan version for now.
+    */
+   info->has_vulkan11 = pCreateInfo->pApplicationInfo &&
+                        pCreateInfo->pApplicationInfo->apiVersion >= VK_MAKE_VERSION(1, 1, 0);
    info->GetPhysicalDeviceProcAddr = (PFN_GetPhysicalDeviceProcAddr)info->GetInstanceProcAddr(*pInstance, "vk_layerGetPhysicalDeviceProcAddr");
 #define DEVSEL_GET_CB(func) info->func = (PFN_vk##func)info->GetInstanceProcAddr(*pInstance, "vk" #func)
@@ -169,8 +175,8 @@ static VkResult device_select_CreateInstance(const VkInstanceCreateInfo *pCreate
-   if (info->has_props2)
-      DEVSEL_GET_CB(GetPhysicalDeviceProperties2KHR);
+   if (info->has_vulkan11)
+      DEVSEL_GET_CB(GetPhysicalDeviceProperties2);
    device_select_layer_add_instance(*pInstance, info);
@@ -197,10 +203,10 @@ static void print_gpu(const struct instance_info *info, unsigned index, VkPhysic
    VkPhysicalDeviceProperties2KHR properties = (VkPhysicalDeviceProperties2KHR){
-   if (info->has_props2 && info->has_pci_bus)
+   if (info->has_vulkan11 && info->has_pci_bus)
       properties.pNext = &ext_pci_properties;
-   if (info->GetPhysicalDeviceProperties2KHR)
-      info->GetPhysicalDeviceProperties2KHR(device, &properties);
+   if (info->GetPhysicalDeviceProperties2)
+      info->GetPhysicalDeviceProperties2(device, &properties);
       info->GetPhysicalDeviceProperties(device, &properties.properties);
@@ -243,10 +249,10 @@ static bool fill_drm_device_info(const struct instance_info *info,
-   if (info->has_props2 && info->has_pci_bus)
+   if (info->has_vulkan11 && info->has_pci_bus)
       properties.pNext = &ext_pci_properties;
-   if (info->GetPhysicalDeviceProperties2KHR)
-     info->GetPhysicalDeviceProperties2KHR(device, &properties);
+   if (info->GetPhysicalDeviceProperties2)
+     info->GetPhysicalDeviceProperties2(device, &properties);
      info->GetPhysicalDeviceProperties(device, &properties.properties);

Reply to: