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 {