procedural-3d-engine/base/vulkandebug.cpp

91 lines
2.6 KiB
C++
Raw Normal View History

2016-02-23 13:45:51 +01:00
/*
* Vulkan examples debug wrapper
*
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
2016-02-16 15:07:25 +01:00
#include "vulkandebug.h"
#include <iostream>
namespace vkDebug
{
2016-04-09 14:20:57 +02:00
int validationLayerCount = 1;
2016-02-16 15:07:25 +01:00
const char *validationLayerNames[] =
{
2016-04-09 14:20:57 +02:00
// This is a meta layer that enables all of the standard
// validation layers in the correct order :
// threading, parameter_validation, device_limits, object_tracker, image, core_validation, swapchain, and unique_objects
"VK_LAYER_LUNARG_standard_validation"
2016-02-16 15:07:25 +01:00
};
PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallback;
PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallback;
PFN_vkDebugReportMessageEXT dbgBreakCallback;
VkDebugReportCallbackEXT msgCallback;
VkBool32 messageCallback(
VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objType,
uint64_t srcObject,
size_t location,
int32_t msgCode,
const char* pLayerPrefix,
const char* pMsg,
void* pUserData)
{
char *message = (char *)malloc(strlen(pMsg) + 100);
assert(message);
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)
{
std::cout << "ERROR: " << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n";
}
else
if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
{
// Uncomment to see warnings
//std::cout << "WARNING: " << "[" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg << "\n";
}
else
{
return false;
}
fflush(stdout);
free(message);
return false;
}
void setupDebugging(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportCallbackEXT callBack)
{
CreateDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
DestroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
dbgBreakCallback = (PFN_vkDebugReportMessageEXT)vkGetInstanceProcAddr(instance, "vkDebugReportMessageEXT");
2016-04-09 14:20:57 +02:00
VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = {};
2016-02-16 15:07:25 +01:00
dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
dbgCreateInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)messageCallback;
2016-02-23 13:45:51 +01:00
dbgCreateInfo.flags = flags;
2016-04-09 14:20:57 +02:00
2016-02-16 15:07:25 +01:00
VkResult err = CreateDebugReportCallback(
instance,
&dbgCreateInfo,
2016-04-09 14:20:57 +02:00
nullptr,
&msgCallback);
2016-02-16 15:07:25 +01:00
assert(!err);
}
void freeDebugCallback(VkInstance instance)
{
2016-04-09 14:20:57 +02:00
if (msgCallback != nullptr)
2016-02-16 15:07:25 +01:00
{
2016-04-09 14:20:57 +02:00
// Commented out as this crashes on some implementations for some reason (at least in VS2015)
// DestroyDebugReportCallback(instance, msgCallback, nullptr);
2016-02-16 15:07:25 +01:00
}
}
}