From 330f4c9bc918977aae65bbb92504fa4922ced793 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 24 Sep 2021 15:52:04 -0500 Subject: [PATCH] vulkan/instance: Use vk_error in vk_instance_init We have to be a bit careful here. Calling log functions during instance initialization can be a bit sketchy. However, we know that __vk_log_impl only ever touches the callbacks lists if instance->base.client_visible so it's safe to call vk_error as soon as we've set up instance_callbacks. Tested-by: Boris Brezillon Reviewed-By: Mike Blumenkrantz Part-of: --- src/vulkan/util/vk_instance.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/vulkan/util/vk_instance.c b/src/vulkan/util/vk_instance.c index fdb1b480f30..93107150913 100644 --- a/src/vulkan/util/vk_instance.c +++ b/src/vulkan/util/vk_instance.c @@ -25,6 +25,7 @@ #include "vk_alloc.h" #include "vk_common_entrypoints.h" +#include "vk_log.h" #include "vk_util.h" #include "vk_debug_utils.h" @@ -43,7 +44,8 @@ vk_instance_init(struct vk_instance *instance, /* VK_EXT_debug_utils */ /* These messengers will only be used during vkCreateInstance or - * vkDestroyInstance calls. + * vkDestroyInstance calls. We do this first so that it's safe to use + * vk_errorf and friends. */ list_inithead(&instance->debug_utils.instance_callbacks); vk_foreach_struct_const(ext, pCreateInfo->pNext) { @@ -56,7 +58,7 @@ vk_instance_init(struct vk_instance *instance, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!messenger) - return VK_ERROR_OUT_OF_HOST_MEMORY; + return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY); vk_object_base_init(NULL, &messenger->base, VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT); @@ -101,14 +103,20 @@ vk_instance_init(struct vk_instance *instance, } if (idx >= VK_INSTANCE_EXTENSION_COUNT) - return VK_ERROR_EXTENSION_NOT_PRESENT; + return vk_errorf(instance, VK_ERROR_EXTENSION_NOT_PRESENT, + "%s not supported", + pCreateInfo->ppEnabledExtensionNames[i]); if (!supported_extensions->extensions[idx]) - return VK_ERROR_EXTENSION_NOT_PRESENT; + return vk_errorf(instance, VK_ERROR_EXTENSION_NOT_PRESENT, + "%s not supported", + pCreateInfo->ppEnabledExtensionNames[i]); #ifdef ANDROID if (!vk_android_allowed_instance_extensions.extensions[idx]) - return VK_ERROR_EXTENSION_NOT_PRESENT; + return vk_errorf(instance, VK_ERROR_EXTENSION_NOT_PRESENT, + "%s not supported", + pCreateInfo->ppEnabledExtensionNames[i]); #endif instance->enabled_extensions.extensions[idx] = true; @@ -121,13 +129,13 @@ vk_instance_init(struct vk_instance *instance, &instance->dispatch_table, &vk_common_instance_entrypoints, false); if (mtx_init(&instance->debug_report.callbacks_mutex, mtx_plain) != 0) - return VK_ERROR_INITIALIZATION_FAILED; + return vk_error(instance, VK_ERROR_INITIALIZATION_FAILED); list_inithead(&instance->debug_report.callbacks); if (mtx_init(&instance->debug_utils.callbacks_mutex, mtx_plain) != 0) { mtx_destroy(&instance->debug_report.callbacks_mutex); - return VK_ERROR_INITIALIZATION_FAILED; + return vk_error(instance, VK_ERROR_INITIALIZATION_FAILED); } list_inithead(&instance->debug_utils.callbacks);