Module: Mesa
Branch: staging/23.1
Commit: 03a8ab447d692ee417282dffd800e8b38f9c022d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=03a8ab447d692ee417282dffd800e8b38f9c022d

Author: antonino <[email protected]>
Date:   Thu Aug 17 15:09:15 2023 +0200

vulkan: Handle vkSetDebugUtilsObjectNameEXT on WSI objects

Some WSI objects don't extend `vk_object_base` therefore they need
special handling.

Fixes: 3c87618d357 ("vulkan: Handle vkGet/SetPrivateDataEXT on Android 
swapchains")
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24752>
(cherry picked from commit 76d150674bdcd1a79e66552c5e8bc148ce7dc14c)

---

 .pick_status.json                   |  2 +-
 src/vulkan/runtime/vk_debug_utils.c | 50 +++++++++++++++++++++++++++++++++++++
 src/vulkan/runtime/vk_device.h      |  2 ++
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index d158bcb4194..ad02e20e6da 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -571,7 +571,7 @@
         "description": "vulkan: Handle vkSetDebugUtilsObjectNameEXT on WSI 
objects",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "3c87618d357a4f75a4f47b2638c8f89939fd6c61"
     },
diff --git a/src/vulkan/runtime/vk_debug_utils.c 
b/src/vulkan/runtime/vk_debug_utils.c
index 91602ba4563..70bcf103dbf 100644
--- a/src/vulkan/runtime/vk_debug_utils.c
+++ b/src/vulkan/runtime/vk_debug_utils.c
@@ -153,12 +153,62 @@ vk_common_DestroyDebugUtilsMessengerEXT(
    vk_free2(&instance->alloc, pAllocator, messenger);
 }
 
+static VkResult
+vk_common_set_object_name_locked(
+   struct vk_device *device,
+   const VkDebugUtilsObjectNameInfoEXT *pNameInfo)
+{
+   if (unlikely(device->swapchain_name == NULL)) {
+      /* Even though VkSwapchain/Surface are non-dispatchable objects, we know
+       * a priori that these are actually pointers so we can use
+       * the pointer hash table for them.
+       */
+      device->swapchain_name = _mesa_pointer_hash_table_create(NULL);
+      if (device->swapchain_name == NULL)
+         return VK_ERROR_OUT_OF_HOST_MEMORY;
+   }
+
+   char *object_name = vk_strdup(&device->alloc, pNameInfo->pObjectName,
+                                 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   if (object_name == NULL)
+      return VK_ERROR_OUT_OF_HOST_MEMORY;
+   struct hash_entry *entry =
+      _mesa_hash_table_search(device->swapchain_name,
+                              (void *)(uintptr_t)pNameInfo->objectHandle);
+   if (unlikely(entry == NULL)) {
+      entry = _mesa_hash_table_insert(device->swapchain_name,
+                                      (void 
*)(uintptr_t)pNameInfo->objectHandle,
+                                      object_name);
+      if (entry == NULL) {
+         vk_free(&device->alloc, object_name);
+         return VK_ERROR_OUT_OF_HOST_MEMORY;
+      }
+   } else {
+      vk_free(&device->alloc, entry->data);
+      entry->data = object_name;
+   }
+   return VK_SUCCESS;
+}
+
 VKAPI_ATTR VkResult VKAPI_CALL
 vk_common_SetDebugUtilsObjectNameEXT(
    VkDevice _device,
    const VkDebugUtilsObjectNameInfoEXT *pNameInfo)
 {
    VK_FROM_HANDLE(vk_device, device, _device);
+
+#ifdef ANDROID
+   if (pNameInfo->objectType == VK_OBJECT_TYPE_SWAPCHAIN_KHR ||
+       pNameInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) {
+#else
+   if (pNameInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) {
+#endif
+      mtx_lock(&device->swapchain_name_mtx);
+      VkResult res = vk_common_set_object_name_locked(device, pNameInfo);
+      mtx_unlock(&device->swapchain_name_mtx);
+      return res;
+   }
+
    struct vk_object_base *object =
       vk_object_base_from_u64_handle(pNameInfo->objectHandle,
                                      pNameInfo->objectType);
diff --git a/src/vulkan/runtime/vk_device.h b/src/vulkan/runtime/vk_device.h
index f22a700fb19..fbc62c95fbd 100644
--- a/src/vulkan/runtime/vk_device.h
+++ b/src/vulkan/runtime/vk_device.h
@@ -244,6 +244,8 @@ struct vk_device {
 
    mtx_t swapchain_private_mtx;
    struct hash_table *swapchain_private;
+   mtx_t swapchain_name_mtx;
+   struct hash_table *swapchain_name;
 };
 
 VK_DEFINE_HANDLE_CASTS(vk_device, base, VkDevice,

Reply via email to