Updated debug callback, added more message prefixes and some comments (also fixes

This commit is contained in:
saschawillems 2016-06-08 22:41:29 +02:00
parent 7ae45a5157
commit a8d3e74734
2 changed files with 45 additions and 16 deletions

View file

@ -1,5 +1,7 @@
/* /*
* Vulkan examples debug wrapper * 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 * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
* *
@ -36,29 +38,52 @@ namespace vkDebug
const char* pMsg, const char* pMsg,
void* pUserData) 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) 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 // Diagnostic info from the Vulkan loader and layers
if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) // 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)
// Uncomment to see warnings {
//std::cout << "WARNING: " << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n"; prefix += "DEBUG:";
} }
else
{ // Display message to default output (console if activated)
return false; std::cout << prefix << " [" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n";
}
fflush(stdout); fflush(stdout);
free(message); // The return value of this callback controls wether the Vulkan call that caused
return false; // 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) void setupDebugging(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportCallbackEXT callBack)

View file

@ -242,7 +242,11 @@ void VulkanExampleBase::prepare()
{ {
if (enableValidation) 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) if (enableDebugMarkers)
{ {