From cb9d65b7c8da486e3aa20222a1546e75d3e4dc97 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 21 Sep 2015 08:52:06 +0200 Subject: [PATCH] Add LoaderAndTools patch to work with wrapped objects --- renderdoc/driver/vulkan/LoaderAndTools.patch | 98 ++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 renderdoc/driver/vulkan/LoaderAndTools.patch diff --git a/renderdoc/driver/vulkan/LoaderAndTools.patch b/renderdoc/driver/vulkan/LoaderAndTools.patch new file mode 100644 index 000000000..06bba0914 --- /dev/null +++ b/renderdoc/driver/vulkan/LoaderAndTools.patch @@ -0,0 +1,98 @@ +diff --git a/loader/loader.c b/loader/loader.c +index 936ca97..e4ba0a0 100644 +--- a/loader/loader.c ++++ b/loader/loader.c +@@ -741,7 +741,7 @@ static struct loader_icd *loader_get_icd_and_device(const VkDevice device, + for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { + for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { + for (struct loader_device *dev = icd->logical_device_list; dev; dev = dev->next) +- if (dev->device == device) { ++ if (loader_get_dispatch(dev->device) == loader_get_dispatch(device)) { + *found_dev = dev; + return icd; + } +@@ -1789,7 +1789,11 @@ struct loader_icd * loader_get_icd(const VkPhysicalDevice gpu, uint32_t *gpu_ind + for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { + for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { + for (uint32_t i = 0; i < icd->gpu_count; i++) +- if (icd->gpus[i] == gpu) { ++ /* Value comparison of VkPhysicalDevice prevents wrapping, use ++ * instance device table instead (TODO this aliases GPUs within ++ * an instance, since they have identical dispatch tables) ++ */ ++ if (loader_get_instance_dispatch(icd->gpus[i]) == loader_get_instance_dispatch(gpu)) { + *gpu_index = i; + return icd; + } +@@ -2574,7 +2578,7 @@ VkResult VKAPI loader_GetPhysicalDeviceProperties( + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetPhysicalDeviceProperties) +- res = icd->GetPhysicalDeviceProperties(gpu, pProperties); ++ res = icd->GetPhysicalDeviceProperties(icd->gpus[gpu_index], pProperties); + + return res; + } +@@ -2588,7 +2592,7 @@ VkResult VKAPI loader_GetPhysicalDeviceQueueCount( + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetPhysicalDeviceQueueCount) +- res = icd->GetPhysicalDeviceQueueCount(gpu, pCount); ++ res = icd->GetPhysicalDeviceQueueCount(icd->gpus[gpu_index], pCount); + + return res; + } +@@ -2603,7 +2607,7 @@ VkResult VKAPI loader_GetPhysicalDeviceQueueProperties ( + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetPhysicalDeviceQueueProperties) +- res = icd->GetPhysicalDeviceQueueProperties(gpu, count, pProperties); ++ res = icd->GetPhysicalDeviceQueueProperties(icd->gpus[gpu_index], count, pProperties); + + return res; + } +@@ -2617,7 +2621,7 @@ VkResult VKAPI loader_GetPhysicalDeviceMemoryProperties ( + VkResult res = VK_ERROR_INITIALIZATION_FAILED; + + if (icd->GetPhysicalDeviceMemoryProperties) +- res = icd->GetPhysicalDeviceMemoryProperties(gpu, pProperties); ++ res = icd->GetPhysicalDeviceMemoryProperties(icd->gpus[gpu_index], pProperties); + + return res; + } +@@ -2764,7 +2768,7 @@ VkResult VKAPI loader_CreateDevice( + } + } + +- res = icd->CreateDevice(gpu, pCreateInfo, pDevice); ++ res = icd->CreateDevice(icd->gpus[gpu_index], pCreateInfo, pDevice); + if (res != VK_SUCCESS) { + return res; + } +diff --git a/loader/trampoline.c b/loader/trampoline.c +index 2224ce2..8e5846e 100644 +--- a/loader/trampoline.c ++++ b/loader/trampoline.c +@@ -144,9 +144,21 @@ LOADER_EXPORT VkResult VKAPI vkDestroyInstance( + + loader_platform_thread_lock_mutex(&loader_lock); + ++ struct loader_instance *ptr_instance = NULL; ++ ++ /* look up the loader_instance in our list by comparing dispatch tables, as ++ * there is no guarantee the instance is still a loader_instance* after any ++ * layers. ++ */ ++ for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { ++ if (inst->disp == disp) { ++ ptr_instance = inst; ++ break; ++ } ++ } ++ + res = disp->DestroyInstance(instance); + +- struct loader_instance *ptr_instance = loader_instance(instance); + loader_deactivate_instance_layers(ptr_instance); + + free(ptr_instance);