From b4dc746a66886319e1a2a607fd53ee2ba6e12cc8 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 13 Jul 2019 01:11:34 +0900 Subject: [PATCH] Clean up the debug callback --- include/QF/Vulkan/funclist.h | 2 ++ include/QF/Vulkan/instance.h | 1 + libs/video/renderer/vulkan/instance.c | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/QF/Vulkan/funclist.h b/include/QF/Vulkan/funclist.h index 43bad39c7..5fe467937 100644 --- a/include/QF/Vulkan/funclist.h +++ b/include/QF/Vulkan/funclist.h @@ -40,6 +40,8 @@ INSTANCE_LEVEL_VULKAN_FUNCTION (vkGetPhysicalDeviceMemoryProperties) INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION (vkCreateDebugUtilsMessengerEXT, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) +INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION + (vkDestroyDebugUtilsMessengerEXT, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION (vkGetPhysicalDeviceSurfaceSupportKHR, VK_KHR_SURFACE_EXTENSION_NAME) INSTANCE_LEVEL_VULKAN_FUNCTION_FROM_EXTENSION diff --git a/include/QF/Vulkan/instance.h b/include/QF/Vulkan/instance.h index 1cc05d6cf..0a677c945 100644 --- a/include/QF/Vulkan/instance.h +++ b/include/QF/Vulkan/instance.h @@ -42,6 +42,7 @@ typedef struct qfv_instance_s { struct strset_s *enabled_extensions; int (*extension_enabled) (struct qfv_instance_s *inst, const char *ext); + VkDebugUtilsMessengerEXT debug_handle; } qfv_instance_t; struct vulkan_ctx_s; diff --git a/libs/video/renderer/vulkan/instance.c b/libs/video/renderer/vulkan/instance.c index 74b0ea756..25ccdb306 100644 --- a/libs/video/renderer/vulkan/instance.c +++ b/libs/video/renderer/vulkan/instance.c @@ -150,7 +150,7 @@ debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, static void setup_debug_callback (qfv_instance_t *instance) { - VkDebugUtilsMessengerEXT debug_callback_handle; + VkDebugUtilsMessengerEXT debug_handle; VkDebugUtilsMessengerCreateInfoEXT createInfo = { .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT, .messageSeverity = message_severities, @@ -160,7 +160,8 @@ setup_debug_callback (qfv_instance_t *instance) }; instance->funcs->vkCreateDebugUtilsMessengerEXT(instance->instance, &createInfo, 0, - &debug_callback_handle); + &debug_handle); + instance->debug_handle = debug_handle; } static void @@ -242,7 +243,7 @@ QFV_CreateInstance (vulkan_ctx_t *ctx, if (res != VK_SUCCESS) { Sys_Error ("unable to create vulkan instance\n"); } - qfv_instance_t *inst = malloc (sizeof(qfv_instance_t) + qfv_instance_t *inst = calloc (1, sizeof(qfv_instance_t) + sizeof (qfv_instfuncs_t)); inst->instance = instance; inst->funcs = (qfv_instfuncs_t *)(inst + 1); @@ -261,6 +262,11 @@ QFV_CreateInstance (vulkan_ctx_t *ctx, void QFV_DestroyInstance (qfv_instance_t *instance) { + qfv_instfuncs_t *ifunc = instance->funcs; + if (instance->debug_handle) { + ifunc->vkDestroyDebugUtilsMessengerEXT (instance->instance, + instance->debug_handle, 0); + } instance->funcs->vkDestroyInstance (instance->instance, 0); free (instance); }