vulkan/log: Allow but warn if called with a NULL object

Most of the time when the logging code is invoked, it means we're
already in an edge case.  It should be as robust as possible, otherwise
we risk making hard to debug things even harder.  To that end, instead
of blowing up if passed a NULL object on the list, handle it as
gracefully as we can.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16107>
This commit is contained in:
Jason Ekstrand 2022-04-22 12:46:02 -05:00 committed by Marge Bot
parent ef9d97ec1f
commit 62a44d1bda

View file

@ -90,8 +90,20 @@ __vk_log_impl(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
instance = (struct vk_instance *) objects_or_instance;
} else {
objects = (struct vk_object_base **) objects_or_instance;
instance = vk_object_to_instance(objects[0]);
assert(instance->base.client_visible);
for (unsigned i = 0; i < object_count; i++) {
if (unlikely(objects[i] == NULL)) {
mesa_logw("vk_log*() called with NULL object\n");
continue;
}
if (!instance) {
instance = vk_object_to_instance(objects[i]);
assert(instance->base.client_visible);
} else {
assert(vk_object_to_instance(objects[i]) == instance);
}
break;
}
}
#ifndef DEBUG
@ -160,9 +172,12 @@ __vk_log_impl(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
VkDebugUtilsObjectNameInfoEXT *object_name_infos =
ralloc_array(NULL, VkDebugUtilsObjectNameInfoEXT, object_count);
ASSERTED int cmdbuf_n = 0, queue_n = 0;
ASSERTED int cmdbuf_n = 0, queue_n = 0, obj_n = 0;
for (int i = 0; i < object_count; i++) {
struct vk_object_base *base = objects[i];
if (base == NULL)
continue;
assert(base->client_visible);
switch (base->type) {
@ -194,7 +209,7 @@ __vk_log_impl(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
break;
}
object_name_infos[i] = (VkDebugUtilsObjectNameInfoEXT){
object_name_infos[obj_n++] = (VkDebugUtilsObjectNameInfoEXT){
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.pNext = NULL,
.objectType = base->type,
@ -202,7 +217,7 @@ __vk_log_impl(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
.pObjectName = base->object_name,
};
}
cb_data.objectCount = object_count;
cb_data.objectCount = obj_n;
cb_data.pObjects = object_name_infos;
vk_debug_message(instance, severity, types, &cb_data);