From 18febd62379f1392ea30bdb799f26933897e96ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Thu, 19 Dec 2019 14:00:51 +0100 Subject: [PATCH] Add usage of DebugUtilsMessenger in vk::su::createInstance (#461) --- samples/utils/utils.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/samples/utils/utils.cpp b/samples/utils/utils.cpp index ddcddb3..d749183 100644 --- a/samples/utils/utils.cpp +++ b/samples/utils/utils.cpp @@ -20,19 +20,6 @@ #if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE -#elif !defined(NDEBUG) -PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT; -PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT; - -VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger) -{ - return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger); -} - -VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator) -{ - return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator); -} #endif namespace vk @@ -231,23 +218,25 @@ namespace vk // create a UniqueInstance vk::ApplicationInfo applicationInfo(appName.c_str(), 1, engineName.c_str(), 1, apiVersion); - vk::InstanceCreateInfo instanceCreateInfo({}, &applicationInfo, checked_cast(enabledLayers.size()), enabledLayers.data(), checked_cast(enabledExtensions.size()), enabledExtensions.data()); - vk::UniqueInstance instance = vk::createInstanceUnique(instanceCreateInfo); +#if defined(NDEBUG) + // in non-debug mode just use the InstanceCreateInfo for instance creation + vk::StructureChain instanceCreateInfo({ {}, &applicationInfo, checked_cast(enabledLayers.size()), enabledLayers.data(), + checked_cast(enabledExtensions.size()), enabledExtensions.data() }); +#else + // in debug mode, addionally use the debugUtilsMessengerCallback in instance creation! + vk::DebugUtilsMessageSeverityFlagsEXT severityFlags(vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagBitsEXT::eError); + vk::DebugUtilsMessageTypeFlagsEXT messageTypeFlags(vk::DebugUtilsMessageTypeFlagBitsEXT::eGeneral | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation); + vk::StructureChain instanceCreateInfo + ( + { {}, &applicationInfo, checked_cast(enabledLayers.size()), enabledLayers.data(), checked_cast(enabledExtensions.size()), enabledExtensions.data() }, + { {}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback } + ); +#endif + vk::UniqueInstance instance = vk::createInstanceUnique(instanceCreateInfo.get()); #if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) // initialize function pointers for instance VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance); -#else -# if !defined(NDEBUG) - static bool initialized = false; - if (!initialized) - { - pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast(instance->getProcAddr("vkCreateDebugUtilsMessengerEXT")); - pfnVkDestroyDebugUtilsMessengerEXT = reinterpret_cast(instance->getProcAddr("vkDestroyDebugUtilsMessengerEXT")); - assert(pfnVkCreateDebugUtilsMessengerEXT && pfnVkDestroyDebugUtilsMessengerEXT); - initialized = true; - } -# endif #endif return instance;