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@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13956>
This commit is contained in:
Samuel Pitoiset 2021-11-24 18:22:23 +01:00 committed by Marge Bot
parent a58f68fc68
commit 990a8ee5eb
3 changed files with 49 additions and 2 deletions

View file

@ -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);
}

View file

@ -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',

View file

@ -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 {