[vulkan] Add Report Callback to instance create

This commit is contained in:
Sandy Carter 2019-01-17 18:49:23 -08:00
parent 5ed4f88091
commit c4a2dff099
No known key found for this signature in database
GPG Key ID: CBEF579D87B6E212
1 changed files with 49 additions and 38 deletions

View File

@ -218,6 +218,43 @@ bool VulkanInstance::QueryGlobals() {
return true; return true;
} }
VkBool32 VKAPI_PTR DebugMessageCallback(VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType,
uint64_t object, size_t location,
int32_t messageCode,
const char* pLayerPrefix,
const char* pMessage, void* pUserData) {
if (strcmp(pLayerPrefix, "Validation") == 0) {
const char* blacklist[] = {
"bound but it was never updated. You may want to either update it or "
"not bind it.",
"is being used in draw but has not been updated.",
};
for (uint32_t i = 0; i < xe::countof(blacklist); ++i) {
if (strstr(pMessage, blacklist[i]) != nullptr) {
return false;
}
}
}
auto instance = reinterpret_cast<VulkanInstance*>(pUserData);
const char* message_type = "UNKNOWN";
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
message_type = "ERROR";
} else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
message_type = "WARN";
} else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
message_type = "PERF WARN";
} else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
message_type = "INFO";
} else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
message_type = "DEBUG";
}
XELOGVK("[{}/{}:{}] {}", pLayerPrefix, message_type, messageCode, pMessage);
return false;
}
bool VulkanInstance::CreateInstance() { bool VulkanInstance::CreateInstance() {
XELOGVK("Verifying layers and extensions..."); XELOGVK("Verifying layers and extensions...");
@ -239,10 +276,21 @@ bool VulkanInstance::CreateInstance() {
XELOGVK("Initializing application instance..."); XELOGVK("Initializing application instance...");
VkDebugReportCallbackCreateInfoEXT debug_info;
debug_info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
debug_info.pNext = nullptr;
// TODO(benvanik): flags to set these.
debug_info.flags =
VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT |
VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
debug_info.pfnCallback = &DebugMessageCallback;
debug_info.pUserData = this;
// TODO(benvanik): use GetEntryInfo? // TODO(benvanik): use GetEntryInfo?
VkApplicationInfo application_info; VkApplicationInfo application_info;
application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
application_info.pNext = nullptr; application_info.pNext = &debug_info;
application_info.pApplicationName = "xenia"; application_info.pApplicationName = "xenia";
application_info.applicationVersion = 1; application_info.applicationVersion = 1;
application_info.pEngineName = "xenia"; application_info.pEngineName = "xenia";
@ -306,43 +354,6 @@ void VulkanInstance::DestroyInstance() {
handle = nullptr; handle = nullptr;
} }
VkBool32 VKAPI_PTR DebugMessageCallback(VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType,
uint64_t object, size_t location,
int32_t messageCode,
const char* pLayerPrefix,
const char* pMessage, void* pUserData) {
if (strcmp(pLayerPrefix, "Validation") == 0) {
const char* blacklist[] = {
"bound but it was never updated. You may want to either update it or "
"not bind it.",
"is being used in draw but has not been updated.",
};
for (uint32_t i = 0; i < xe::countof(blacklist); ++i) {
if (strstr(pMessage, blacklist[i]) != nullptr) {
return false;
}
}
}
auto instance = reinterpret_cast<VulkanInstance*>(pUserData);
const char* message_type = "UNKNOWN";
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
message_type = "ERROR";
} else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
message_type = "WARN";
} else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
message_type = "PERF WARN";
} else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
message_type = "INFO";
} else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
message_type = "DEBUG";
}
XELOGVK("[{}/{}:{}] {}", pLayerPrefix, message_type, messageCode, pMessage);
return false;
}
void VulkanInstance::EnableDebugValidation() { void VulkanInstance::EnableDebugValidation() {
if (dbg_report_callback_) { if (dbg_report_callback_) {
DisableDebugValidation(); DisableDebugValidation();