From 990a8ee5eb9c78ae0f675bd6baf0850e4031b9f3 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 24 Nov 2021 18:22:23 +0100 Subject: [PATCH] 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 Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/layers/radv_metro_exodus.c | 38 +++++++++++++++++++++++ src/amd/vulkan/meson.build | 3 +- src/amd/vulkan/radv_device.c | 10 +++++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/amd/vulkan/layers/radv_metro_exodus.c 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 d81660366a3..c5e4bc2e1cd 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 9846c78c724..7f4604c2baf 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -2978,7 +2978,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 {