Commit fb39a215 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Improve initialization failure handling in VulkanInstance

In debug builds VulkanInstance::Destroy() was trying to call
vkDestroyDebugReportCallbackEXT and it would DCHECK after a failure to
find that function. That would happen even if Destroy() is called in
after a failed attempt to load Vulkan libs. It doesn't make sense to
DCHECK in that case. Also now vkDestroyDebugReportCallbackEXT() is
called only if debug callbacks were created successfully.

Bug: 861853
Change-Id: I03bbdbb1793ddb74f07352f354d0f70ee739a93a
Reviewed-on: https://chromium-review.googlesource.com/c/1332263
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607476}
parent bbf03776
......@@ -163,6 +163,7 @@ bool VulkanInstance::Initialize(
result = vkCreateDebugReportCallbackEXT(vk_instance_, &cb_create_info,
nullptr, &error_callback_);
if (VK_SUCCESS != result) {
error_callback_ = VK_NULL_HANDLE;
DLOG(ERROR) << "vkCreateDebugReportCallbackEXT(ERROR) failed: " << result;
return false;
}
......@@ -173,6 +174,7 @@ bool VulkanInstance::Initialize(
result = vkCreateDebugReportCallbackEXT(vk_instance_, &cb_create_info,
nullptr, &warning_callback_);
if (VK_SUCCESS != result) {
warning_callback_ = VK_NULL_HANDLE;
DLOG(ERROR) << "vkCreateDebugReportCallbackEXT(WARN) failed: " << result;
return false;
}
......@@ -219,13 +221,16 @@ bool VulkanInstance::Initialize(
void VulkanInstance::Destroy() {
#if DCHECK_IS_ON()
if (debug_report_enabled_) {
if (debug_report_enabled_ && (error_callback_ != VK_NULL_HANDLE ||
warning_callback_ != VK_NULL_HANDLE)) {
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT =
reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
vkGetInstanceProcAddr(vk_instance_,
"vkDestroyDebugReportCallbackEXT"));
DCHECK(vkDestroyDebugReportCallbackEXT);
if (error_callback_ != VK_NULL_HANDLE)
vkDestroyDebugReportCallbackEXT(vk_instance_, error_callback_, nullptr);
if (warning_callback_ != VK_NULL_HANDLE)
vkDestroyDebugReportCallbackEXT(vk_instance_, warning_callback_, nullptr);
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment