From a8d3e74734f2b892824d361a7a0e7abe076ce1eb Mon Sep 17 00:00:00 2001 From: saschawillems Date: Wed, 8 Jun 2016 22:41:29 +0200 Subject: [PATCH] Updated debug callback, added more message prefixes and some comments (also fixes --- base/vulkandebug.cpp | 55 +++++++++++++++++++++++++++----------- base/vulkanexamplebase.cpp | 6 ++++- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/base/vulkandebug.cpp b/base/vulkandebug.cpp index 0b0b6ddd..333f5603 100644 --- a/base/vulkandebug.cpp +++ b/base/vulkandebug.cpp @@ -1,5 +1,7 @@ /* * Vulkan examples debug wrapper +* +* Appendix for VK_EXT_Debug_Report can be found at https://github.com/KhronosGroup/Vulkan-Docs/blob/1.0-VK_EXT_debug_report/doc/specs/vulkan/appendices/debug_report.txt * * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de * @@ -36,29 +38,52 @@ namespace vkDebug const char* pMsg, void* pUserData) { - char *message = (char *)malloc(strlen(pMsg) + 100); + // Message text passed in by validation layer + std::string text(pMsg); - assert(message); + // Select prefix depending on flags passed to the callback + // Note that multiple flags may be set for a single validation message + std::string prefix(""); + // Error that may result in undefined behaviour if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { - std::cout << "ERROR: " << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n"; + prefix += "ERROR:"; + }; + // Warnings may hint at unexpected / non-spec API usage + if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) + { + prefix += "WARNING:"; + }; + // May indicate sub-optimal usage of the API + if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) + { + prefix += "PERFORMANCE:"; + }; + // Informal messages that may become handy during debugging + if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) + { + prefix += "INFO:"; } - else - if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) - { - // Uncomment to see warnings - //std::cout << "WARNING: " << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n"; - } - else - { - return false; - } + // Diagnostic info from the Vulkan loader and layers + // Usually not helpful in terms of API usage, but may help to debug layer and loader problems + if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) + { + prefix += "DEBUG:"; + } + + // Display message to default output (console if activated) + std::cout << prefix << " [" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n"; fflush(stdout); - free(message); - return false; + // The return value of this callback controls wether 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 + // (and return a VkResult) to abort + // 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, VkDebugReportFlagsEXT flags, VkDebugReportCallbackEXT callBack) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index ca942ef3..86b4a877 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -242,7 +242,11 @@ void VulkanExampleBase::prepare() { if (enableValidation) { - vkDebug::setupDebugging(instance, VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_NULL_HANDLE); + // The report flags determine what type of messages for the layers will be displayed + // For validating (debugging) an appplication the error and warning bits should suffice + VkDebugReportFlagsEXT debugReportFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT; // VK_DEBUG_REPORT_WARNING_BIT_EXT (enable to also display warnings) + // Additional flags include performance info, loader and layer debug messages, etc. + vkDebug::setupDebugging(instance, debugReportFlags, VK_NULL_HANDLE); } if (enableDebugMarkers) {