Mesa (staging/21.3): radv: add a workaround to fix a segfault with Metro Exodus (Linux native)

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 1 00:23:45 UTC 2021


Module: Mesa
Branch: staging/21.3
Commit: a32da163fc4b038fa8bda6deced96a5ca214f6f3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a32da163fc4b038fa8bda6deced96a5ca214f6f3

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Wed Nov 24 18:22:23 2021 +0100

radv: add a workaround to fix a segfault with Metro Exodus (Linux native)

The game calls vkGetSemaphoreCounterValue() with an invalid semaphore
handle and it crashes. This is an invalid Vulkan usage and it should
be fixed in the game. I reported the issue to the developers.

Workaround this temporarily (hopefully) by ignoring
vkGetSemaphoreCounterValue() if the semaphore is NULL from an internal
RADV layer.

Cc: 21.3 mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5119
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13956>
(cherry picked from commit 990a8ee5eb9c78ae0f675bd6baf0850e4031b9f3)

---

 .pick_status.json                         |  2 +-
 src/amd/vulkan/layers/radv_metro_exodus.c | 38 +++++++++++++++++++++++++++++++
 src/amd/vulkan/meson.build                |  3 ++-
 src/amd/vulkan/radv_device.c              | 10 +++++++-
 4 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 25051ac217d..392baa6d330 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -337,7 +337,7 @@
         "description": "radv: add a workaround to fix a segfault with Metro Exodus (Linux native)",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/amd/vulkan/layers/radv_metro_exodus.c b/src/amd/vulkan/layers/radv_metro_exodus.c
new file mode 100644
index 00000000000..d5cc5225027
--- /dev/null
+++ b/src/amd/vulkan/layers/radv_metro_exodus.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2021 Valve Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "radv_private.h"
+
+VKAPI_ATTR VkResult VKAPI_CALL
+metro_exodus_GetSemaphoreCounterValue(VkDevice _device, VkSemaphore _semaphore, uint64_t *pValue)
+{
+   RADV_FROM_HANDLE(radv_semaphore, semaphore, _semaphore);
+
+   /* See https://gitlab.freedesktop.org/mesa/mesa/-/issues/5119. */
+   if (semaphore == NULL) {
+      fprintf(stderr, "RADV: Ignoring vkGetSemaphoreCounterValue() with NULL semaphore (game bug)!\n");
+      return VK_SUCCESS;
+   }
+
+   return radv_GetSemaphoreCounterValue(_device, _semaphore, pValue);
+}
diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build
index 1d09248036c..186f1960613 100644
--- a/src/amd/vulkan/meson.build
+++ b/src/amd/vulkan/meson.build
@@ -25,12 +25,13 @@ radv_entrypoints = custom_target(
   command : [
     prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--proto', '--weak',
     '--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@', '--prefix', 'radv',
-    '--device-prefix', 'sqtt',
+    '--device-prefix', 'sqtt', '--device-prefix', 'metro_exodus',
   ],
   depend_files : vk_entrypoints_gen_depend_files,
 )
 
 libradv_files = files(
+  'layers/radv_metro_exodus.c',
   'layers/radv_sqtt_layer.c',
   'winsys/null/radv_null_bo.c',
   'winsys/null/radv_null_bo.h',
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index a220b7a2391..c2539fe5785 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -2965,7 +2965,15 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr
 
    struct vk_device_dispatch_table dispatch_table;
 
-   if (radv_thread_trace_enabled()) {
+   if (physical_device->instance->vk.app_info.app_name &&
+       !strcmp(physical_device->instance->vk.app_info.app_name, "metroexodus")) {
+      /* Metro Exodus (Linux native) calls vkGetSemaphoreCounterValue() with a NULL semaphore and it
+       * crashes sometimes.  Workaround this game bug by enabling an internal layer. Remove this
+       * when the game is fixed.
+       */
+      vk_device_dispatch_table_from_entrypoints(&dispatch_table, &metro_exodus_device_entrypoints, true);
+      vk_device_dispatch_table_from_entrypoints(&dispatch_table, &radv_device_entrypoints, false);
+   } else if (radv_thread_trace_enabled()) {
       vk_device_dispatch_table_from_entrypoints(&dispatch_table, &sqtt_device_entrypoints, true);
       vk_device_dispatch_table_from_entrypoints(&dispatch_table, &radv_device_entrypoints, false);
    } else {



More information about the mesa-commit mailing list