Replace usage of old layer VK_LAYER_LUNARG_standard_validation and extension VK_EXT_debug_report with new layer VK_LAYER_KHRONOS_validation and extension VK_EXT_debug_utils

This commit is contained in:
Adam Sawicki 2020-07-15 16:56:30 +02:00
parent e9f387a31d
commit 8caf0bd1c0
2 changed files with 67 additions and 85 deletions

View File

@ -45,7 +45,7 @@ void SetConsoleColor(CONSOLE_COLOR color)
switch(color) switch(color)
{ {
case CONSOLE_COLOR::INFO: case CONSOLE_COLOR::INFO:
attr = FOREGROUND_INTENSITY;; attr = FOREGROUND_INTENSITY;
break; break;
case CONSOLE_COLOR::NORMAL: case CONSOLE_COLOR::NORMAL:
attr = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; attr = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;

View File

@ -31,7 +31,7 @@
static const char* const SHADER_PATH1 = "./"; static const char* const SHADER_PATH1 = "./";
static const char* const SHADER_PATH2 = "../bin/"; static const char* const SHADER_PATH2 = "../bin/";
static const wchar_t* const WINDOW_CLASS_NAME = L"VULKAN_MEMORY_ALLOCATOR_SAMPLE"; static const wchar_t* const WINDOW_CLASS_NAME = L"VULKAN_MEMORY_ALLOCATOR_SAMPLE";
static const char* const VALIDATION_LAYER_NAME = "VK_LAYER_LUNARG_standard_validation"; static const char* const VALIDATION_LAYER_NAME = "VK_LAYER_KHRONOS_validation";
static const char* const APP_TITLE_A = "Vulkan Memory Allocator Sample 2.4.0"; static const char* const APP_TITLE_A = "Vulkan Memory Allocator Sample 2.4.0";
static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 2.4.0"; static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 2.4.0";
@ -55,6 +55,7 @@ bool VK_EXT_memory_budget_enabled = false;
bool VK_AMD_device_coherent_memory_enabled = false; bool VK_AMD_device_coherent_memory_enabled = false;
bool VK_EXT_buffer_device_address_enabled = false; bool VK_EXT_buffer_device_address_enabled = false;
bool VK_KHR_buffer_device_address_enabled = false; bool VK_KHR_buffer_device_address_enabled = false;
bool VK_EXT_debug_utils_enabled = false;
bool g_SparseBindingEnabled = false; bool g_SparseBindingEnabled = false;
bool g_BufferDeviceAddressEnabled = false; bool g_BufferDeviceAddressEnabled = false;
@ -95,10 +96,18 @@ static VkSurfaceCapabilitiesKHR g_SurfaceCapabilities;
static std::vector<VkSurfaceFormatKHR> g_SurfaceFormats; static std::vector<VkSurfaceFormatKHR> g_SurfaceFormats;
static std::vector<VkPresentModeKHR> g_PresentModes; static std::vector<VkPresentModeKHR> g_PresentModes;
static PFN_vkCreateDebugReportCallbackEXT g_pvkCreateDebugReportCallbackEXT; static const VkDebugUtilsMessageSeverityFlagsEXT DEBUG_UTILS_MESSENGER_MESSAGE_SEVERITY =
static PFN_vkDebugReportMessageEXT g_pvkDebugReportMessageEXT; //VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
static PFN_vkDestroyDebugReportCallbackEXT g_pvkDestroyDebugReportCallbackEXT; //VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
static VkDebugReportCallbackEXT g_hCallback; VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
static const VkDebugUtilsMessageTypeFlagsEXT DEBUG_UTILS_MESSENGER_MESSAGE_TYPE =
VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
static PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT_Func;
static PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT_Func;
static VkDebugUtilsMessengerEXT g_DebugUtilsMessenger;
static VkQueue g_hGraphicsQueue; static VkQueue g_hGraphicsQueue;
VkQueue g_hSparseBindingQueue; VkQueue g_hSparseBindingQueue;
@ -208,67 +217,37 @@ void LoadShader(std::vector<char>& out, const char* fileName)
out.clear(); out.clear();
} }
VKAPI_ATTR VkBool32 VKAPI_CALL MyDebugReportCallback( static VkBool32 VKAPI_PTR MyDebugReportCallback(
VkDebugReportFlagsEXT flags, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugReportObjectTypeEXT objectType, VkDebugUtilsMessageTypeFlagsEXT messageTypes,
uint64_t object, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
size_t location, void* pUserData)
int32_t messageCode,
const char* pLayerPrefix,
const char* pMessage,
void* pUserData)
{ {
// "Non-linear image 0xebc91 is aliased with linear buffer 0xeb8e4 which may indicate a bug." assert(pCallbackData && pCallbackData->pMessageIdName && pCallbackData->pMessage);
if(!g_MemoryAliasingWarningEnabled && flags == VK_DEBUG_REPORT_WARNING_BIT_EXT &&
(strstr(pMessage, " is aliased with non-linear ") || strstr(pMessage, " is aliased with linear ")))
{
return VK_FALSE;
}
// Ignoring because when VK_KHR_dedicated_allocation extension is enabled, switch(messageSeverity)
// vkGetBufferMemoryRequirements2KHR function is used instead, while Validation
// Layer seems to be unaware of it.
if (strstr(pMessage, "but vkGetBufferMemoryRequirements() has not been called on that buffer") != nullptr)
{ {
return VK_FALSE; case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
}
if (strstr(pMessage, "but vkGetImageMemoryRequirements() has not been called on that image") != nullptr)
{
return VK_FALSE;
}
/*
"Mapping an image with layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used."
Ignoring because we map entire VkDeviceMemory blocks, where different types of
images and buffers may end up together, especially on GPUs with unified memory
like Intel.
*/
if(strstr(pMessage, "Mapping an image with layout") != nullptr &&
strstr(pMessage, "can result in undefined behavior if this memory is used by the device") != nullptr)
{
return VK_FALSE;
}
switch(flags)
{
case VK_DEBUG_REPORT_WARNING_BIT_EXT:
SetConsoleColor(CONSOLE_COLOR::WARNING); SetConsoleColor(CONSOLE_COLOR::WARNING);
break; break;
case VK_DEBUG_REPORT_ERROR_BIT_EXT: case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT:
SetConsoleColor(CONSOLE_COLOR::ERROR_); SetConsoleColor(CONSOLE_COLOR::ERROR_);
break; break;
default: case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
SetConsoleColor(CONSOLE_COLOR::NORMAL);
break;
default: // VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT
SetConsoleColor(CONSOLE_COLOR::INFO); SetConsoleColor(CONSOLE_COLOR::INFO);
} }
printf("%s \xBA %s\n", pLayerPrefix, pMessage); printf("%s \xBA %s\n", pCallbackData->pMessageIdName, pCallbackData->pMessage);
SetConsoleColor(CONSOLE_COLOR::NORMAL); SetConsoleColor(CONSOLE_COLOR::NORMAL);
if(flags == VK_DEBUG_REPORT_WARNING_BIT_EXT || if(messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT ||
flags == VK_DEBUG_REPORT_ERROR_BIT_EXT) messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
{ {
OutputDebugStringA(pMessage); OutputDebugStringA(pCallbackData->pMessage);
OutputDebugStringA("\n"); OutputDebugStringA("\n");
} }
@ -587,28 +566,26 @@ struct UniformBufferObject
static void RegisterDebugCallbacks() static void RegisterDebugCallbacks()
{ {
g_pvkCreateDebugReportCallbackEXT = vkCreateDebugUtilsMessengerEXT_Func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT> g_hVulkanInstance, "vkCreateDebugUtilsMessengerEXT");
(vkGetInstanceProcAddr(g_hVulkanInstance, "vkCreateDebugReportCallbackEXT")); vkDestroyDebugUtilsMessengerEXT_Func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
g_pvkDebugReportMessageEXT = g_hVulkanInstance, "vkDestroyDebugUtilsMessengerEXT");
reinterpret_cast<PFN_vkDebugReportMessageEXT> assert(vkCreateDebugUtilsMessengerEXT_Func);
(vkGetInstanceProcAddr(g_hVulkanInstance, "vkDebugReportMessageEXT")); assert(vkDestroyDebugUtilsMessengerEXT_Func);
g_pvkDestroyDebugReportCallbackEXT =
reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>
(vkGetInstanceProcAddr(g_hVulkanInstance, "vkDestroyDebugReportCallbackEXT"));
assert(g_pvkCreateDebugReportCallbackEXT);
assert(g_pvkDebugReportMessageEXT);
assert(g_pvkDestroyDebugReportCallbackEXT);
VkDebugReportCallbackCreateInfoEXT callbackCreateInfo = { VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT }; VkDebugUtilsMessengerCreateInfoEXT messengerCreateInfo = { VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT };
callbackCreateInfo.flags = //VK_DEBUG_REPORT_INFORMATION_BIT_EXT | messengerCreateInfo.messageSeverity = DEBUG_UTILS_MESSENGER_MESSAGE_SEVERITY;
VK_DEBUG_REPORT_ERROR_BIT_EXT | messengerCreateInfo.messageType = DEBUG_UTILS_MESSENGER_MESSAGE_TYPE;
VK_DEBUG_REPORT_WARNING_BIT_EXT | messengerCreateInfo.pfnUserCallback = MyDebugReportCallback;
VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT /*| ERR_GUARD_VULKAN( vkCreateDebugUtilsMessengerEXT_Func(g_hVulkanInstance, &messengerCreateInfo, g_Allocs, &g_DebugUtilsMessenger) );
VK_DEBUG_REPORT_DEBUG_BIT_EXT*/; }
callbackCreateInfo.pfnCallback = &MyDebugReportCallback;
ERR_GUARD_VULKAN( g_pvkCreateDebugReportCallbackEXT(g_hVulkanInstance, &callbackCreateInfo, g_Allocs, &g_hCallback) ); static void UnregisterDebugCallbacks()
{
if(g_DebugUtilsMessenger)
{
vkDestroyDebugUtilsMessengerEXT_Func(g_hVulkanInstance, g_DebugUtilsMessenger, g_Allocs);
}
} }
static bool IsLayerSupported(const VkLayerProperties* pProps, size_t propCount, const char* pLayerName) static bool IsLayerSupported(const VkLayerProperties* pProps, size_t propCount, const char* pLayerName)
@ -1230,7 +1207,7 @@ static void InitializeApplication()
ERR_GUARD_VULKAN( vkEnumerateInstanceLayerProperties(&instanceLayerPropCount, instanceLayerProps.data()) ); ERR_GUARD_VULKAN( vkEnumerateInstanceLayerProperties(&instanceLayerPropCount, instanceLayerProps.data()) );
} }
if(g_EnableValidationLayer == true) if(g_EnableValidationLayer)
{ {
if(IsLayerSupported(instanceLayerProps.data(), instanceLayerProps.size(), VALIDATION_LAYER_NAME) == false) if(IsLayerSupported(instanceLayerProps.data(), instanceLayerProps.size(), VALIDATION_LAYER_NAME) == false)
{ {
@ -1252,10 +1229,9 @@ static void InitializeApplication()
enabledInstanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); enabledInstanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
std::vector<const char*> instanceLayers; std::vector<const char*> instanceLayers;
if(g_EnableValidationLayer == true) if(g_EnableValidationLayer)
{ {
instanceLayers.push_back(VALIDATION_LAYER_NAME); instanceLayers.push_back(VALIDATION_LAYER_NAME);
enabledInstanceExtensions.push_back("VK_EXT_debug_report");
} }
for(const auto& extensionProperties : availableInstanceExtensions) for(const auto& extensionProperties : availableInstanceExtensions)
@ -1268,6 +1244,11 @@ static void InitializeApplication()
VK_KHR_get_physical_device_properties2_enabled = true; VK_KHR_get_physical_device_properties2_enabled = true;
} }
} }
else if(strcmp(extensionProperties.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0)
{
enabledInstanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
VK_EXT_debug_utils_enabled = true;
}
} }
VkApplicationInfo appInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO }; VkApplicationInfo appInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
@ -1295,6 +1276,11 @@ static void InitializeApplication()
ERR_GUARD_VULKAN( vkCreateInstance(&instInfo, g_Allocs, &g_hVulkanInstance) ); ERR_GUARD_VULKAN( vkCreateInstance(&instInfo, g_Allocs, &g_hVulkanInstance) );
if(VK_EXT_debug_utils_enabled)
{
RegisterDebugCallbacks();
}
// Create VkSurfaceKHR. // Create VkSurfaceKHR.
VkWin32SurfaceCreateInfoKHR surfaceInfo = { VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR }; VkWin32SurfaceCreateInfoKHR surfaceInfo = { VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR };
surfaceInfo.hinstance = g_hAppInstance; surfaceInfo.hinstance = g_hAppInstance;
@ -1302,9 +1288,6 @@ static void InitializeApplication()
VkResult result = vkCreateWin32SurfaceKHR(g_hVulkanInstance, &surfaceInfo, g_Allocs, &g_hSurface); VkResult result = vkCreateWin32SurfaceKHR(g_hVulkanInstance, &surfaceInfo, g_Allocs, &g_hSurface);
assert(result == VK_SUCCESS); assert(result == VK_SUCCESS);
if(g_EnableValidationLayer == true)
RegisterDebugCallbacks();
// Find physical device // Find physical device
uint32_t deviceCount = 0; uint32_t deviceCount = 0;
@ -1782,18 +1765,17 @@ static void FinalizeApplication()
g_hDevice = nullptr; g_hDevice = nullptr;
} }
if(g_pvkDestroyDebugReportCallbackEXT && g_hCallback != VK_NULL_HANDLE)
{
g_pvkDestroyDebugReportCallbackEXT(g_hVulkanInstance, g_hCallback, g_Allocs);
g_hCallback = VK_NULL_HANDLE;
}
if(g_hSurface != VK_NULL_HANDLE) if(g_hSurface != VK_NULL_HANDLE)
{ {
vkDestroySurfaceKHR(g_hVulkanInstance, g_hSurface, g_Allocs); vkDestroySurfaceKHR(g_hVulkanInstance, g_hSurface, g_Allocs);
g_hSurface = VK_NULL_HANDLE; g_hSurface = VK_NULL_HANDLE;
} }
if(VK_EXT_debug_utils_enabled)
{
UnregisterDebugCallbacks();
}
if(g_hVulkanInstance != VK_NULL_HANDLE) if(g_hVulkanInstance != VK_NULL_HANDLE)
{ {
vkDestroyInstance(g_hVulkanInstance, g_Allocs); vkDestroyInstance(g_hVulkanInstance, g_Allocs);