From c56bc94aa92158dbdd5301348dccbfe84218b11e Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Fri, 25 Mar 2016 08:43:01 -0600 Subject: loader: Setup temporary callback for vkDestroyInstance --- loader/loader.h | 1 + loader/trampoline.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/loader/loader.h b/loader/loader.h index cae78cc9..9efcb704 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -293,6 +293,7 @@ struct loader_instance { bool debug_report_enabled; VkLayerDbgFunctionNode *DbgFunctionHead; + VkDebugReportCallbackCreateInfoEXT *pDebugReportCreateInfo; VkAllocationCallbacks alloc_callbacks; diff --git a/loader/trampoline.c b/loader/trampoline.c index 41119e95..bfd2b8ca 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -279,6 +279,12 @@ vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, while (pNext) { if (((VkInstanceCreateInfo *)pNext)->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) { + // Use this pNext so that vkCreateInstance has a callback that can + // be used to log messages. Make a copy for use by + // vkDestroyInstance as well. + ptr_instance->pDebugReportCreateInfo = + ((VkDebugReportCallbackCreateInfoEXT *) + malloc(sizeof(VkDebugReportCallbackCreateInfoEXT))); instance_callback = (VkDebugReportCallbackEXT)ptr_instance; if (util_CreateDebugReportCallback(ptr_instance, pNext, NULL, instance_callback)) { @@ -442,18 +448,33 @@ vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { const VkLayerInstanceDispatchTable *disp; struct loader_instance *ptr_instance = NULL; + VkDebugReportCallbackEXT instance_callback = VK_NULL_HANDLE; + bool callback_setup = false; + disp = loader_get_instance_dispatch(instance); loader_platform_thread_lock_mutex(&loader_lock); - /* TODO: Do we need a temporary callback here to catch cleanup issues? */ - ptr_instance = loader_get_instance(instance); + + if (ptr_instance->pDebugReportCreateInfo) { + // Setup a temporary callback here to catch cleanup issues: + instance_callback = (VkDebugReportCallbackEXT)ptr_instance; + if (!util_CreateDebugReportCallback(ptr_instance, + ptr_instance->pDebugReportCreateInfo, + NULL, instance_callback)) { + callback_setup = true; + } + } + disp->DestroyInstance(instance, pAllocator); loader_deactivate_instance_layers(ptr_instance); if (ptr_instance->phys_devs) loader_heap_free(ptr_instance, ptr_instance->phys_devs); + if (callback_setup) { + util_DestroyDebugReportCallback(ptr_instance, instance_callback, NULL); + } loader_heap_free(ptr_instance, ptr_instance->disp); loader_heap_free(ptr_instance, ptr_instance); loader_platform_thread_unlock_mutex(&loader_lock); -- cgit v1.2.3