From 76d150674bdcd1a79e66552c5e8bc148ce7dc14c Mon Sep 17 00:00:00 2001 From: antonino Date: Thu, 17 Aug 2023 15:09:15 +0200 Subject: [PATCH] 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 Part-of: --- src/vulkan/runtime/vk_debug_utils.c | 50 +++++++++++++++++++++++++++++ src/vulkan/runtime/vk_device.h | 2 ++ 2 files changed, 52 insertions(+) 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 6331f7656db..69bf7fd5858 100644 --- a/src/vulkan/runtime/vk_device.h +++ b/src/vulkan/runtime/vk_device.h @@ -258,6 +258,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,