20 DebugReportCallback* DebugReportCallback::current =
nullptr;
28 if (callback !=
nullptr) {
33 VkBool32 DebugReportCallback::dispatch(VkDebugReportFlagsEXT flags,
34 VkDebugReportObjectTypeEXT objectType,
38 const char* pLayerPrefix,
43 string messageType =
"DEBUG REPORT";
44 if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
45 messageType =
"ERROR";
46 }
else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
47 messageType =
"WARNING";
48 }
else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
49 messageType =
"PERFORMANCE WARNING";
50 }
else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
52 }
else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
53 messageType =
"DEBUG";
55 current->
invoke(messageType, messageCode,
string(pMessage));
61 DebugReportCallback::DebugReportCallback(
void) {
62 Instance* instance = VulkanContext::getCurrent()->getInstance();
65 VkDebugReportCallbackCreateInfoEXT createInfo = {};
66 createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
67 createInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
68 createInfo.pfnCallback = DebugReportCallback::dispatch;
71 auto vkCreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT) instance->
getProcAddr(
"vkCreateDebugReportCallbackEXT");
72 if (vkCreateDebugReportCallbackEXT(instance->
getHandle(), &createInfo,
nullptr, &handle) != VK_SUCCESS) {
73 throw runtime_error(
"Could not create debug report callback!");
77 DebugReportCallback::~DebugReportCallback(
void) {
78 Instance* instance = VulkanContext::getCurrent()->getInstance();
81 auto vkDestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT) instance->
getProcAddr(
"vkDestroyDebugReportCallbackEXT");
82 vkDestroyDebugReportCallbackEXT(instance->
getHandle(), handle,
nullptr);
85 if (DebugReportCallback::current ==
this) {
86 DebugReportCallback::current =
nullptr;
90 VkDebugReportCallbackEXT DebugReportCallback::getHandle() {
95 void DebugReportCallback::invoke(std::string messageType,
int messageCode, std::string message) {
96 Logger::logError(
"Vulkan " + messageType +
" Code " + to_string(messageCode) +
": " + message);
This class wraps a Vulkan instance.
VkInstance getHandle()
Returns the handle of the Vulkan instance.
Generic namespace for the SimpleGL framework.
This class wraps a Vulkan debug report callback.
virtual void invoke(std::string messageType, int messageCode, std::string message)
This function gets called whenever a Vulkan debug report occurs.
PFN_vkVoidFunction getProcAddr(std::string name)
Returns a function pointer for an instance function.