From 7fd41ab3f6a7c4d9a62263d9da6f78e4633571b5 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 10 Jan 2024 22:01:15 -0800 Subject: [PATCH 1/2] Use debug utils during instance creation --- base/VulkanDebug.cpp | 4 ++-- base/VulkanDebug.h | 12 ++++-------- base/vulkanexamplebase.cpp | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/base/VulkanDebug.cpp b/base/VulkanDebug.cpp index e7b9c5bad..8cc7c9ea6 100644 --- a/base/VulkanDebug.cpp +++ b/base/VulkanDebug.cpp @@ -17,7 +17,7 @@ namespace vks PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT; VkDebugUtilsMessengerEXT debugUtilsMessenger; - VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback( + VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, @@ -88,7 +88,7 @@ namespace vks debugUtilsMessengerCI.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; debugUtilsMessengerCI.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; debugUtilsMessengerCI.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT; - debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessengerCallback; + debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessageCallback; VkResult result = vkCreateDebugUtilsMessengerEXT(instance, &debugUtilsMessengerCI, nullptr, &debugUtilsMessenger); assert(result == VK_SUCCESS); } diff --git a/base/VulkanDebug.h b/base/VulkanDebug.h index e45a5128f..f6623fc27 100644 --- a/base/VulkanDebug.h +++ b/base/VulkanDebug.h @@ -35,14 +35,10 @@ namespace vks namespace debug { // Default debug callback - VKAPI_ATTR VkBool32 VKAPI_CALL messageCallback( - VkDebugReportFlagsEXT flags, - VkDebugReportObjectTypeEXT objType, - uint64_t srcObject, - size_t location, - int32_t msgCode, - const char* pLayerPrefix, - const char* pMsg, + VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback( + VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, + VkDebugUtilsMessageTypeFlagsEXT messageType, + const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData); // Load debug function pointers and set debug callback diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 5d7434ba0..ea30915bc 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -98,6 +98,22 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) instanceCreateInfo.pNext = NULL; instanceCreateInfo.pApplicationInfo = &appInfo; + + + VkDebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCI{}; + if (settings.validation) { + PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT; + PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT; + vkCreateDebugUtilsMessengerEXT = reinterpret_cast(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT")); + vkDestroyDebugUtilsMessengerEXT = reinterpret_cast(vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT")); + debugUtilsMessengerCI.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; + debugUtilsMessengerCI.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT| VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; + debugUtilsMessengerCI.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; + debugUtilsMessengerCI.pfnUserCallback = vks::debug::debugUtilsMessageCallback; + instanceCreateInfo.pNext = &debugUtilsMessengerCI; + } + + #if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK)) && defined(VK_KHR_portability_enumeration) // SRS - When running on iOS/macOS with MoltenVK and VK_KHR_portability_enumeration is defined and supported by the instance, enable the extension and the flag if (std::find(supportedInstanceExtensions.begin(), supportedInstanceExtensions.end(), VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) != supportedInstanceExtensions.end()) From 36ef86aea04148f63f119dc64bbc7b8a1d85f1f4 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Sun, 14 Jan 2024 10:49:22 -0800 Subject: [PATCH 2/2] fixup! Use debug utils during instance creation --- base/VulkanDebug.cpp | 16 ++++++++++------ base/VulkanDebug.h | 2 ++ base/vulkanexamplebase.cpp | 32 ++++++++++++-------------------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/base/VulkanDebug.cpp b/base/VulkanDebug.cpp index 8cc7c9ea6..eacd6ac33 100644 --- a/base/VulkanDebug.cpp +++ b/base/VulkanDebug.cpp @@ -74,21 +74,25 @@ namespace vks // The return value of this callback controls whether the Vulkan call that caused the validation message will be aborted or not // We return VK_FALSE as we DON'T want Vulkan calls that cause a validation message to abort - // If you instead want to have calls abort, pass in VK_TRUE and the function will return VK_ERROR_VALIDATION_FAILED_EXT + // If you instead want to have calls abort, pass in VK_TRUE and the function will return VK_ERROR_VALIDATION_FAILED_EXT return VK_FALSE; } - void setupDebugging(VkInstance instance) + void setupDebugingMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugUtilsMessengerCI) { + debugUtilsMessengerCI.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; + debugUtilsMessengerCI.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; + debugUtilsMessengerCI.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT; + debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessageCallback; + } + void setupDebugging(VkInstance instance) + { vkCreateDebugUtilsMessengerEXT = reinterpret_cast(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT")); vkDestroyDebugUtilsMessengerEXT = reinterpret_cast(vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT")); VkDebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCI{}; - debugUtilsMessengerCI.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; - debugUtilsMessengerCI.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; - debugUtilsMessengerCI.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT; - debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessageCallback; + setupDebugingMessengerCreateInfo(debugUtilsMessengerCI); VkResult result = vkCreateDebugUtilsMessengerEXT(instance, &debugUtilsMessengerCI, nullptr, &debugUtilsMessenger); assert(result == VK_SUCCESS); } diff --git a/base/VulkanDebug.h b/base/VulkanDebug.h index f6623fc27..87c5eb411 100644 --- a/base/VulkanDebug.h +++ b/base/VulkanDebug.h @@ -45,6 +45,8 @@ namespace vks void setupDebugging(VkInstance instance); // Clear debug callback void freeDebugCallback(VkInstance instance); + // Used to populate a VkDebugUtilsMessengerCreateInfoEXT with our example messenger function and desired flags + void setupDebugingMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugUtilsMessengerCI); } // Wrapper for the VK_EXT_debug_utils extension diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index ea30915bc..f5b869acd 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -55,7 +55,7 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) #elif defined(VK_USE_PLATFORM_SCREEN_QNX) instanceExtensions.push_back(VK_QNX_SCREEN_SURFACE_EXTENSION_NAME); #endif - + // Get extensions supported by the instance and store for later use uint32_t extCount = 0; vkEnumerateInstanceExtensionProperties(nullptr, &extCount, nullptr); @@ -80,9 +80,9 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) #endif // Enabled requested instance extensions - if (enabledInstanceExtensions.size() > 0) + if (enabledInstanceExtensions.size() > 0) { - for (const char * enabledExtension : enabledInstanceExtensions) + for (const char * enabledExtension : enabledInstanceExtensions) { // Output message if requested extension is not available if (std::find(supportedInstanceExtensions.begin(), supportedInstanceExtensions.end(), enabledExtension) == supportedInstanceExtensions.end()) @@ -98,18 +98,10 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) instanceCreateInfo.pNext = NULL; instanceCreateInfo.pApplicationInfo = &appInfo; - - VkDebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCI{}; if (settings.validation) { - PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT; - PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT; - vkCreateDebugUtilsMessengerEXT = reinterpret_cast(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT")); - vkDestroyDebugUtilsMessengerEXT = reinterpret_cast(vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT")); - debugUtilsMessengerCI.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; - debugUtilsMessengerCI.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT| VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; - debugUtilsMessengerCI.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; - debugUtilsMessengerCI.pfnUserCallback = vks::debug::debugUtilsMessageCallback; + vks::debug::setupDebugingMessengerCreateInfo(debugUtilsMessengerCI); + debugUtilsMessengerCI.pNext = instanceCreateInfo.pNext; instanceCreateInfo.pNext = &debugUtilsMessengerCI; } @@ -306,7 +298,7 @@ void VulkanExampleBase::nextFrame() lastTimestamp = tEnd; } tPrevEnd = tEnd; - + // TODO: Cap UI overlay update rates updateOverlay(); } @@ -813,10 +805,10 @@ VulkanExampleBase::VulkanExampleBase() #endif // Validation for all samples can be forced at compile time using the FORCE_VALIDATION define -#if defined(FORCE_VALIDATION) +#if defined(FORCE_VALIDATION) settings.validation = true; #endif - + // Command line arguments commandLineParser.add("help", { "--help" }, 0, "Show help"); commandLineParser.add("validation", { "-v", "--validation" }, 0, "Enable validation layers"); @@ -879,7 +871,7 @@ VulkanExampleBase::VulkanExampleBase() } if (commandLineParser.isSet("benchmarkresultfile")) { benchmark.filename = commandLineParser.getValueAsString("benchmarkresultfile", benchmark.filename); - } + } if (commandLineParser.isSet("benchmarkresultframes")) { benchmark.outputFrameTimes = true; } @@ -1622,7 +1614,7 @@ dispatch_group_t concurrentGroup; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [NSApp activateIgnoringOtherApps:YES]; // SRS - Make sure app window launches in front of Xcode window - + concurrentGroup = dispatch_group_create(); dispatch_queue_t concurrentQueue = dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0); dispatch_group_async(concurrentGroup, concurrentQueue, ^{ @@ -1631,7 +1623,7 @@ dispatch_group_t concurrentGroup; vulkanExample->displayLinkOutputCb(); } }); - + // SRS - When benchmarking, set up termination notification on main thread when concurrent queue completes if (vulkanExample->benchmark.active) { dispatch_queue_t notifyQueue = dispatch_get_main_queue(); @@ -3194,7 +3186,7 @@ void VulkanExampleBase::windowResize() destroyCommandBuffers(); createCommandBuffers(); buildCommandBuffers(); - + // SRS - Recreate fences in case number of swapchain images has changed on resize for (auto& fence : waitFences) { vkDestroyFence(device, fence, nullptr);