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( ...@@ -163,6 +163,7 @@ bool VulkanInstance::Initialize(
result = vkCreateDebugReportCallbackEXT(vk_instance_, &cb_create_info, result = vkCreateDebugReportCallbackEXT(vk_instance_, &cb_create_info,
nullptr, &error_callback_); nullptr, &error_callback_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
error_callback_ = VK_NULL_HANDLE;
DLOG(ERROR) << "vkCreateDebugReportCallbackEXT(ERROR) failed: " << result; DLOG(ERROR) << "vkCreateDebugReportCallbackEXT(ERROR) failed: " << result;
return false; return false;
} }
...@@ -173,6 +174,7 @@ bool VulkanInstance::Initialize( ...@@ -173,6 +174,7 @@ bool VulkanInstance::Initialize(
result = vkCreateDebugReportCallbackEXT(vk_instance_, &cb_create_info, result = vkCreateDebugReportCallbackEXT(vk_instance_, &cb_create_info,
nullptr, &warning_callback_); nullptr, &warning_callback_);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
warning_callback_ = VK_NULL_HANDLE;
DLOG(ERROR) << "vkCreateDebugReportCallbackEXT(WARN) failed: " << result; DLOG(ERROR) << "vkCreateDebugReportCallbackEXT(WARN) failed: " << result;
return false; return false;
} }
...@@ -219,14 +221,17 @@ bool VulkanInstance::Initialize( ...@@ -219,14 +221,17 @@ bool VulkanInstance::Initialize(
void VulkanInstance::Destroy() { void VulkanInstance::Destroy() {
#if DCHECK_IS_ON() #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 = PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT =
reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>( reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(
vkGetInstanceProcAddr(vk_instance_, vkGetInstanceProcAddr(vk_instance_,
"vkDestroyDebugReportCallbackEXT")); "vkDestroyDebugReportCallbackEXT"));
DCHECK(vkDestroyDebugReportCallbackEXT); DCHECK(vkDestroyDebugReportCallbackEXT);
vkDestroyDebugReportCallbackEXT(vk_instance_, error_callback_, nullptr); if (error_callback_ != VK_NULL_HANDLE)
vkDestroyDebugReportCallbackEXT(vk_instance_, warning_callback_, nullptr); vkDestroyDebugReportCallbackEXT(vk_instance_, error_callback_, nullptr);
if (warning_callback_ != VK_NULL_HANDLE)
vkDestroyDebugReportCallbackEXT(vk_instance_, warning_callback_, nullptr);
} }
#endif #endif
if (vk_instance_ != VK_NULL_HANDLE) { if (vk_instance_ != VK_NULL_HANDLE) {
......
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