Updated debug callback, added more message prefixes and some comments (also fixes
This commit is contained in:
parent
7ae45a5157
commit
a8d3e74734
2 changed files with 45 additions and 16 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
|
|
@ -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:";
|
||||||
}
|
};
|
||||||
else
|
// Warnings may hint at unexpected / non-spec API usage
|
||||||
if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
|
if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
|
||||||
{
|
{
|
||||||
// Uncomment to see warnings
|
prefix += "WARNING:";
|
||||||
//std::cout << "WARNING: " << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n";
|
};
|
||||||
}
|
// May indicate sub-optimal usage of the API
|
||||||
else
|
if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
|
||||||
{
|
{
|
||||||
return false;
|
prefix += "PERFORMANCE:";
|
||||||
|
};
|
||||||
|
// Informal messages that may become handy during debugging
|
||||||
|
if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT)
|
||||||
|
{
|
||||||
|
prefix += "INFO:";
|
||||||
}
|
}
|
||||||
|
// 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);
|
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)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue