Merge pull request #2336 from Wunkolo/vk-debug-utils

GPU/Vulkan: Update VK_EXT_debug_report to VK_EXT_debug_utils
This commit is contained in:
Connor McLaughlin 2021-06-30 14:20:37 +10:00 committed by GitHub
commit 48422a9932
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 53 deletions

View file

@ -44,9 +44,9 @@
#define vkCreateAndroidSurfaceKHR ds_vkCreateAndroidSurfaceKHR #define vkCreateAndroidSurfaceKHR ds_vkCreateAndroidSurfaceKHR
#define vkCreateMacOSSurfaceMVK ds_vkCreateMacOSSurfaceMVK #define vkCreateMacOSSurfaceMVK ds_vkCreateMacOSSurfaceMVK
#define vkCreateMetalSurfaceEXT ds_vkCreateMetalSurfaceEXT #define vkCreateMetalSurfaceEXT ds_vkCreateMetalSurfaceEXT
#define vkCreateDebugReportCallbackEXT ds_vkCreateDebugReportCallbackEXT #define vkCreateDebugUtilsMessengerEXT ds_vkCreateDebugUtilsMessengerEXT
#define vkDestroyDebugReportCallbackEXT ds_vkDestroyDebugReportCallbackEXT #define vkDestroyDebugUtilsMessengerEXT ds_vkDestroyDebugUtilsMessengerEXT
#define vkDebugReportMessageEXT ds_vkDebugReportMessageEXT #define vkSubmitDebugUtilsMessageEXT ds_vkSubmitDebugUtilsMessageEXT
#define vkGetPhysicalDeviceProperties2 ds_vkGetPhysicalDeviceProperties2 #define vkGetPhysicalDeviceProperties2 ds_vkGetPhysicalDeviceProperties2
#define vkGetPhysicalDeviceSurfaceCapabilities2KHR ds_vkGetPhysicalDeviceSurfaceCapabilities2KHR #define vkGetPhysicalDeviceSurfaceCapabilities2KHR ds_vkGetPhysicalDeviceSurfaceCapabilities2KHR
#define vkGetPhysicalDeviceDisplayPropertiesKHR ds_vkGetPhysicalDeviceDisplayPropertiesKHR #define vkGetPhysicalDeviceDisplayPropertiesKHR ds_vkGetPhysicalDeviceDisplayPropertiesKHR

View file

@ -66,9 +66,10 @@ VULKAN_INSTANCE_ENTRY_POINT(vkCreateMacOSSurfaceMVK, false)
VULKAN_INSTANCE_ENTRY_POINT(vkCreateMetalSurfaceEXT, false) VULKAN_INSTANCE_ENTRY_POINT(vkCreateMetalSurfaceEXT, false)
#endif #endif
VULKAN_INSTANCE_ENTRY_POINT(vkCreateDebugReportCallbackEXT, false) VULKAN_INSTANCE_ENTRY_POINT(vkCreateDebugUtilsMessengerEXT, false)
VULKAN_INSTANCE_ENTRY_POINT(vkDestroyDebugReportCallbackEXT, false) VULKAN_INSTANCE_ENTRY_POINT(vkDestroyDebugUtilsMessengerEXT, false)
VULKAN_INSTANCE_ENTRY_POINT(vkDebugReportMessageEXT, false) VULKAN_INSTANCE_ENTRY_POINT(vkSubmitDebugUtilsMessageEXT, false)
VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceProperties2, false) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceProperties2, false)
VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceSurfaceCapabilities2KHR, false) VULKAN_INSTANCE_ENTRY_POINT(vkGetPhysicalDeviceSurfaceCapabilities2KHR, false)

View file

@ -51,8 +51,8 @@ Context::~Context()
if (m_owns_device && m_device != VK_NULL_HANDLE) if (m_owns_device && m_device != VK_NULL_HANDLE)
vkDestroyDevice(m_device, nullptr); vkDestroyDevice(m_device, nullptr);
if (m_debug_report_callback != VK_NULL_HANDLE) if (m_debug_messenger_callback != VK_NULL_HANDLE)
DisableDebugReports(); DisableDebugUtils();
if (m_owns_device) if (m_owns_device)
{ {
@ -87,20 +87,20 @@ bool Context::CheckValidationLayerAvailablility()
res = vkEnumerateInstanceLayerProperties(&layer_count, layer_list.data()); res = vkEnumerateInstanceLayerProperties(&layer_count, layer_list.data());
Assert(res == VK_SUCCESS); Assert(res == VK_SUCCESS);
// Check for both VK_EXT_debug_report and VK_LAYER_LUNARG_standard_validation // Check for both VK_EXT_debug_utils and VK_LAYER_LUNARG_standard_validation
return (std::find_if(extension_list.begin(), extension_list.end(), return (std::find_if(extension_list.begin(), extension_list.end(),
[](const auto& it) { [](const auto& it) {
return strcmp(it.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0; return strcmp(it.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0;
}) != extension_list.end() && }) != extension_list.end() &&
std::find_if(layer_list.begin(), layer_list.end(), [](const auto& it) { std::find_if(layer_list.begin(), layer_list.end(), [](const auto& it) {
return strcmp(it.layerName, "VK_LAYER_KHRONOS_validation") == 0; return strcmp(it.layerName, "VK_LAYER_KHRONOS_validation") == 0;
}) != layer_list.end()); }) != layer_list.end());
} }
VkInstance Context::CreateVulkanInstance(const WindowInfo* wi, bool enable_debug_report, bool enable_validation_layer) VkInstance Context::CreateVulkanInstance(const WindowInfo* wi, bool enable_debug_utils, bool enable_validation_layer)
{ {
ExtensionList enabled_extensions; ExtensionList enabled_extensions;
if (!SelectInstanceExtensions(&enabled_extensions, wi, enable_debug_report)) if (!SelectInstanceExtensions(&enabled_extensions, wi, enable_debug_utils))
return VK_NULL_HANDLE; return VK_NULL_HANDLE;
VkApplicationInfo app_info = {}; VkApplicationInfo app_info = {};
@ -141,7 +141,7 @@ VkInstance Context::CreateVulkanInstance(const WindowInfo* wi, bool enable_debug
return instance; return instance;
} }
bool Context::SelectInstanceExtensions(ExtensionList* extension_list, const WindowInfo* wi, bool enable_debug_report) bool Context::SelectInstanceExtensions(ExtensionList* extension_list, const WindowInfo* wi, bool enable_debug_utils)
{ {
u32 extension_count = 0; u32 extension_count = 0;
VkResult res = vkEnumerateInstanceExtensionProperties(nullptr, &extension_count, nullptr); VkResult res = vkEnumerateInstanceExtensionProperties(nullptr, &extension_count, nullptr);
@ -209,8 +209,8 @@ bool Context::SelectInstanceExtensions(ExtensionList* extension_list, const Wind
if (wi && wi->type == WindowInfo::Type::Display && !SupportsExtension(VK_KHR_DISPLAY_EXTENSION_NAME, true)) if (wi && wi->type == WindowInfo::Type::Display && !SupportsExtension(VK_KHR_DISPLAY_EXTENSION_NAME, true))
return false; return false;
// VK_EXT_debug_report // VK_EXT_debug_utils
if (enable_debug_report && !SupportsExtension(VK_EXT_DEBUG_REPORT_EXTENSION_NAME, false)) if (enable_debug_utils && !SupportsExtension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, false))
Log_WarningPrintf("Vulkan: Debug report requested, but extension is not available."); Log_WarningPrintf("Vulkan: Debug report requested, but extension is not available.");
return true; return true;
@ -290,7 +290,7 @@ Context::GPUNameList Context::EnumerateGPUNames(VkInstance instance)
} }
bool Context::Create(std::string_view gpu_name, const WindowInfo* wi, std::unique_ptr<SwapChain>* out_swap_chain, bool Context::Create(std::string_view gpu_name, const WindowInfo* wi, std::unique_ptr<SwapChain>* out_swap_chain,
bool threaded_presentation, bool enable_debug_reports, bool enable_validation_layer) bool threaded_presentation, bool enable_debug_utils, bool enable_validation_layer)
{ {
AssertMsg(!g_vulkan_context, "Has no current context"); AssertMsg(!g_vulkan_context, "Has no current context");
@ -301,7 +301,7 @@ bool Context::Create(std::string_view gpu_name, const WindowInfo* wi, std::uniqu
} }
const bool enable_surface = (wi && wi->type != WindowInfo::Type::Surfaceless); const bool enable_surface = (wi && wi->type != WindowInfo::Type::Surfaceless);
VkInstance instance = CreateVulkanInstance(wi, enable_debug_reports, enable_validation_layer); VkInstance instance = CreateVulkanInstance(wi, enable_debug_utils, enable_validation_layer);
if (instance == VK_NULL_HANDLE) if (instance == VK_NULL_HANDLE)
{ {
Vulkan::UnloadVulkanLibrary(); Vulkan::UnloadVulkanLibrary();
@ -363,8 +363,8 @@ bool Context::Create(std::string_view gpu_name, const WindowInfo* wi, std::uniqu
g_vulkan_context.reset(new Context(instance, gpus[gpu_index], true)); g_vulkan_context.reset(new Context(instance, gpus[gpu_index], true));
// Enable debug reports if the "Host GPU" log category is enabled. // Enable debug reports if the "Host GPU" log category is enabled.
if (enable_debug_reports) if (enable_debug_utils)
g_vulkan_context->EnableDebugReports(); g_vulkan_context->EnableDebugUtils();
// Attempt to create the device. // Attempt to create the device.
if (!g_vulkan_context->CreateDevice(surface, enable_validation_layer, nullptr, 0, nullptr, 0, nullptr) || if (!g_vulkan_context->CreateDevice(surface, enable_validation_layer, nullptr, 0, nullptr, 0, nullptr) ||
@ -386,7 +386,7 @@ bool Context::Create(std::string_view gpu_name, const WindowInfo* wi, std::uniqu
} }
bool Context::CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface, bool Context::CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface,
bool take_ownership, bool enable_validation_layer, bool enable_debug_reports, bool take_ownership, bool enable_validation_layer, bool enable_debug_utils,
const char** required_device_extensions /* = nullptr */, const char** required_device_extensions /* = nullptr */,
u32 num_required_device_extensions /* = 0 */, u32 num_required_device_extensions /* = 0 */,
const char** required_device_layers /* = nullptr */, const char** required_device_layers /* = nullptr */,
@ -395,9 +395,9 @@ bool Context::CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice g
{ {
g_vulkan_context.reset(new Context(instance, gpu, take_ownership)); g_vulkan_context.reset(new Context(instance, gpu, take_ownership));
// Enable debug reports if the "Host GPU" log category is enabled. // Enable debug utils if the "Host GPU" log category is enabled.
if (enable_debug_reports) if (enable_debug_utils)
g_vulkan_context->EnableDebugReports(); g_vulkan_context->EnableDebugUtils();
// Attempt to create the device. // Attempt to create the device.
if (!g_vulkan_context->CreateDevice(surface, enable_validation_layer, required_device_extensions, if (!g_vulkan_context->CreateDevice(surface, enable_validation_layer, required_device_extensions,
@ -1103,60 +1103,61 @@ void Context::DeferPipelineDestruction(VkPipeline pipeline)
resources.cleanup_resources.push_back([this, pipeline]() { vkDestroyPipeline(m_device, pipeline, nullptr); }); resources.cleanup_resources.push_back([this, pipeline]() { vkDestroyPipeline(m_device, pipeline, nullptr); });
} }
static VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType, uint64_t object, VKAPI_ATTR VkBool32 VKAPI_CALL DebugMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
size_t location, int32_t messageCode, VkDebugUtilsMessageTypeFlagsEXT messageType,
const char* pLayerPrefix, const char* pMessage, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
void* pUserData) void* pUserData)
{ {
LOGLEVEL level; LOGLEVEL level;
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) if (severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
level = LOGLEVEL_ERROR; level = LOGLEVEL_ERROR;
else if (flags & (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)) else if (severity & (VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT))
level = LOGLEVEL_WARNING; level = LOGLEVEL_WARNING;
else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) else if (severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT)
level = LOGLEVEL_INFO; level = LOGLEVEL_INFO;
else else
level = LOGLEVEL_DEBUG; level = LOGLEVEL_DEBUG;
Log::Writef("Vulkan", __func__, level, "Vulkan debug report: (%s) %s", pLayerPrefix ? pLayerPrefix : "", pMessage); Log::Writef("Vulkan", __func__, level, "Vulkan debug report: (%s) %s",
pCallbackData->pMessageIdName ? pCallbackData->pMessageIdName : "", pCallbackData->pMessage);
return VK_FALSE; return VK_FALSE;
} }
bool Context::EnableDebugReports() bool Context::EnableDebugUtils()
{ {
// Already enabled? // Already enabled?
if (m_debug_report_callback != VK_NULL_HANDLE) if (m_debug_messenger_callback != VK_NULL_HANDLE)
return true; return true;
// Check for presence of the functions before calling // Check for presence of the functions before calling
if (!vkCreateDebugReportCallbackEXT || !vkDestroyDebugReportCallbackEXT || !vkDebugReportMessageEXT) if (!vkCreateDebugUtilsMessengerEXT || !vkDestroyDebugUtilsMessengerEXT || !vkSubmitDebugUtilsMessageEXT)
{ {
return false; return false;
} }
VkDebugReportCallbackCreateInfoEXT callback_info = { VkDebugUtilsMessengerCreateInfoEXT messenger_info = {
VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT, nullptr, VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT, nullptr, 0,
VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,
VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT, VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT,
DebugReportCallback, nullptr}; DebugMessengerCallback, nullptr};
VkResult res = vkCreateDebugReportCallbackEXT(m_instance, &callback_info, nullptr, &m_debug_report_callback); VkResult res = vkCreateDebugUtilsMessengerEXT(m_instance, &messenger_info, nullptr, &m_debug_messenger_callback);
if (res != VK_SUCCESS) if (res != VK_SUCCESS)
{ {
LOG_VULKAN_ERROR(res, "vkCreateDebugReportCallbackEXT failed: "); LOG_VULKAN_ERROR(res, "vkCreateDebugUtilsMessengerEXT failed: ");
return false; return false;
} }
return true; return true;
} }
void Context::DisableDebugReports() void Context::DisableDebugUtils()
{ {
if (m_debug_report_callback != VK_NULL_HANDLE) if (m_debug_messenger_callback != VK_NULL_HANDLE)
{ {
vkDestroyDebugReportCallbackEXT(m_instance, m_debug_report_callback, nullptr); vkDestroyDebugUtilsMessengerEXT(m_instance, m_debug_messenger_callback, nullptr);
m_debug_report_callback = VK_NULL_HANDLE; m_debug_messenger_callback = VK_NULL_HANDLE;
} }
} }

View file

@ -38,7 +38,7 @@ public:
static bool CheckValidationLayerAvailablility(); static bool CheckValidationLayerAvailablility();
// Helper method to create a Vulkan instance. // Helper method to create a Vulkan instance.
static VkInstance CreateVulkanInstance(const WindowInfo* wi, bool enable_debug_report, bool enable_validation_layer); static VkInstance CreateVulkanInstance(const WindowInfo* wi, bool enable_debug_utils, bool enable_validation_layer);
// Returns a list of Vulkan-compatible GPUs. // Returns a list of Vulkan-compatible GPUs.
using GPUList = std::vector<VkPhysicalDevice>; using GPUList = std::vector<VkPhysicalDevice>;
@ -48,11 +48,11 @@ public:
// Creates a new context and sets it up as global. // Creates a new context and sets it up as global.
static bool Create(std::string_view gpu_name, const WindowInfo* wi, std::unique_ptr<SwapChain>* out_swap_chain, static bool Create(std::string_view gpu_name, const WindowInfo* wi, std::unique_ptr<SwapChain>* out_swap_chain,
bool threaded_presentation, bool enable_debug_reports, bool enable_validation_layer); bool threaded_presentation, bool enable_debug_utils, bool enable_validation_layer);
// Creates a new context from a pre-existing instance. // Creates a new context from a pre-existing instance.
static bool CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface, static bool CreateFromExistingInstance(VkInstance instance, VkPhysicalDevice gpu, VkSurfaceKHR surface,
bool take_ownership, bool enable_validation_layer, bool enable_debug_reports, bool take_ownership, bool enable_validation_layer, bool enable_debug_utils,
const char** required_device_extensions = nullptr, const char** required_device_extensions = nullptr,
u32 num_required_device_extensions = 0, u32 num_required_device_extensions = 0,
const char** required_device_layers = nullptr, const char** required_device_layers = nullptr,
@ -63,8 +63,8 @@ public:
static void Destroy(); static void Destroy();
// Enable/disable debug message runtime. // Enable/disable debug message runtime.
bool EnableDebugReports(); bool EnableDebugUtils();
void DisableDebugReports(); void DisableDebugUtils();
// Global state accessors // Global state accessors
ALWAYS_INLINE VkInstance GetVulkanInstance() const { return m_instance; } ALWAYS_INLINE VkInstance GetVulkanInstance() const { return m_instance; }
@ -184,7 +184,7 @@ private:
Context(VkInstance instance, VkPhysicalDevice physical_device, bool owns_device); Context(VkInstance instance, VkPhysicalDevice physical_device, bool owns_device);
using ExtensionList = std::vector<const char*>; using ExtensionList = std::vector<const char*>;
static bool SelectInstanceExtensions(ExtensionList* extension_list, const WindowInfo* wi, bool enable_debug_report); static bool SelectInstanceExtensions(ExtensionList* extension_list, const WindowInfo* wi, bool enable_debug_utils);
bool SelectDeviceExtensions(ExtensionList* extension_list, bool enable_surface); bool SelectDeviceExtensions(ExtensionList* extension_list, bool enable_surface);
bool SelectDeviceFeatures(const VkPhysicalDeviceFeatures* required_features); bool SelectDeviceFeatures(const VkPhysicalDeviceFeatures* required_features);
bool CreateDevice(VkSurfaceKHR surface, bool enable_validation_layer, const char** required_device_extensions, bool CreateDevice(VkSurfaceKHR surface, bool enable_validation_layer, const char** required_device_extensions,
@ -263,7 +263,7 @@ private:
using RenderPassCacheKey = std::tuple<VkFormat, VkFormat, VkSampleCountFlagBits, VkAttachmentLoadOp>; using RenderPassCacheKey = std::tuple<VkFormat, VkFormat, VkSampleCountFlagBits, VkAttachmentLoadOp>;
std::map<RenderPassCacheKey, VkRenderPass> m_render_pass_cache; std::map<RenderPassCacheKey, VkRenderPass> m_render_pass_cache;
VkDebugReportCallbackEXT m_debug_report_callback = VK_NULL_HANDLE; VkDebugUtilsMessengerEXT m_debug_messenger_callback = VK_NULL_HANDLE;
VkQueueFamilyProperties m_graphics_queue_properties = {}; VkQueueFamilyProperties m_graphics_queue_properties = {};
VkPhysicalDeviceFeatures m_device_features = {}; VkPhysicalDeviceFeatures m_device_features = {};