From 13a6c98143bd604075347aa34319efec2cf39653 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 13 Jul 2016 17:07:16 +0200 Subject: [PATCH] Handle duplicate semaphores (mesa returns all handles as 0x1 atm) --- .../driver/vulkan/wrappers/vk_sync_funcs.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp index a6a887fde..7ddffdda2 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_sync_funcs.cpp @@ -481,8 +481,28 @@ bool WrappedVulkan::Serialise_vkCreateSemaphore(Serialiser *localSerialiser, VkD } else { - ResourceId live = GetResourceManager()->WrapResource(Unwrap(device), sem); - GetResourceManager()->AddLiveResource(id, sem); + ResourceId live; + + if(GetResourceManager()->HasWrapper(ToTypedHandle(sem))) + { + live = GetResourceManager()->GetNonDispWrapper(sem)->id; + + RDCWARN( + "On replay, semaphore got a duplicate handle - maybe a bug, or it could be an " + "indication of an implementation that doesn't use semaphores"); + + // destroy this instance of the duplicate, as we must have matching create/destroy + // calls and there won't be a wrapped resource hanging around to destroy this one. + ObjDisp(device)->DestroySemaphore(Unwrap(device), sem, NULL); + + // whenever the new ID is requested, return the old ID, via replacements. + GetResourceManager()->ReplaceResource(id, GetResourceManager()->GetOriginalID(live)); + } + else + { + live = GetResourceManager()->WrapResource(Unwrap(device), sem); + GetResourceManager()->AddLiveResource(id, sem); + } } }