Mesa (main): vulkan/log: Allow but warn if called with a NULL object

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 26 16:58:11 UTC 2022


Module: Mesa
Branch: main
Commit: 62a44d1bda958e6f8f56fd958023de9be7347a08
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=62a44d1bda958e6f8f56fd958023de9be7347a08

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Fri Apr 22 12:46:02 2022 -0500

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 at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16107>

---

 src/vulkan/runtime/vk_log.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/vulkan/runtime/vk_log.c b/src/vulkan/runtime/vk_log.c
index b085b369f62..9fb15f59420 100644
--- a/src/vulkan/runtime/vk_log.c
+++ b/src/vulkan/runtime/vk_log.c
@@ -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);



More information about the mesa-commit mailing list