diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-07-10 11:24:39 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-07-10 11:24:39 -0400 |
| commit | 32f251204754fd51f04d11e29d17b62f9d1d7058 (patch) | |
| tree | b2d65b923d7806fa8e7146a35e314c05583a928d /src | |
| parent | 871649f7ffd327d317e96cb9f5b83d4bfc145ac9 (diff) | |
vulkan debug report callback
Diffstat (limited to 'src')
| -rw-r--r-- | src/window.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp index b18e723..d79b61d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,6 +1,7 @@ #include <cstdio> #include <vector> +#include <cassert> #include "window.hpp" @@ -10,8 +11,10 @@ GLFWwindow *window = nullptr; VkInstance vkInstance = nullptr; VkPhysicalDevice vkPhysicalDevice = nullptr; VkSurfaceKHR vkSurfaceKHR = nullptr; +VkDebugReportCallbackEXT vkDebugReport = nullptr; const bool ENABLE_VALIDATION_LAYERS = true; +const bool VULKAN_DEBUG_REPORT = true; VkBool32 UserDebugCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, @@ -21,6 +24,17 @@ VkBool32 UserDebugCallback( return VK_FALSE; } +static VKAPI_ATTR VkBool32 VKAPI_CALL DebugReport(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, unsigned long object, size_t location, int messageCode, const char *pLayerPrefix, const char *pMessage, void *pUserData) { + (void)flags; + (void)object; + (void)location; + (void)messageCode; + (void)pUserData; + (void)pLayerPrefix; // Unused arguments + fprintf(stderr, "[vulkan] Debug report from ObjectType: %i\nMessage: %s\n\n", objectType, pMessage); + return VK_FALSE; +} + void InitVulkan() { if (ENABLE_VALIDATION_LAYERS) { @@ -109,6 +123,26 @@ void InitVulkan() { throw result; } + if (VULKAN_DEBUG_REPORT) { + PFN_vkCreateDebugReportCallbackEXT func = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(vkInstance, "vkCreateDebugReportCallbackEXT"); + assert(func != nullptr && "vkCreateDebugReportCallbackEXT ProcAddr was nullptr"); + + VkDebugReportCallbackCreateInfoEXT debugReportCallbackCreateInfo{}; + debugReportCallbackCreateInfo.flags = + VK_DEBUG_REPORT_ERROR_BIT_EXT | + VK_DEBUG_REPORT_WARNING_BIT_EXT | + VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; + debugReportCallbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT; + debugReportCallbackCreateInfo.pfnCallback = DebugReport; + debugReportCallbackCreateInfo.pUserData = nullptr; + + VkResult result = func(vkInstance, &debugReportCallbackCreateInfo, nullptr, &vkDebugReport); + + if (result != VK_SUCCESS) { + fprintf(stderr, "%s\n", "Failed to create debug report!"); + } + } + } void CreateWindow(PKEWindowProperties *wp) { @@ -120,6 +154,10 @@ void CreateWindow(PKEWindowProperties *wp) { } void DestroyWindow() { + if (VULKAN_DEBUG_REPORT) { + auto vkDestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(vkInstance, "vkDestroyDebugReportCallbackEXT"); + vkDestroyDebugReportCallbackEXT(vkInstance, vkDebugReport, nullptr); + } if (vkInstance != nullptr) return; PFN_vkDestroyInstance(vkInstance); glfwDestroyWindow(window); |
