diff options
author | antonino <antonino.maniscalco@collabora.com> | 2023-11-06 22:52:35 +0100 |
---|---|---|
committer | Eric Engestrom <eric@engestrom.ch> | 2023-11-13 20:04:59 +0000 |
commit | a28ea69d0a54597f72be77f9c5ff6308fd15071f (patch) | |
tree | c60ec044b4167b261fdb9e3ec28871bd0d0d31c4 /src/vulkan | |
parent | c6a9afc57a96815391a3adba6b7b3ffcc8d2345d (diff) | |
download | mesa-a28ea69d0a54597f72be77f9c5ff6308fd15071f.tar.gz mesa-a28ea69d0a54597f72be77f9c5ff6308fd15071f.tar.bz2 mesa-a28ea69d0a54597f72be77f9c5ff6308fd15071f.zip |
vulkan: use instance allocator for `object_name` in some objects
The allocator passed to VkDevice won't be available once it is destroyed
and thefore it cannot be used to allocate `object_name` for instance
level objects such as `VkInstance` or `VkPhysicalDevice` or else there
would be no way of deallocating it when those objects are destroyed.
Cc: mesa-stable
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Mark Collins <mark@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26085>
(cherry picked from commit 2d49f834b20d705d901414f6fc2b1fec019689c4)
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/runtime/vk_debug_report.c | 4 | ||||
-rw-r--r-- | src/vulkan/runtime/vk_debug_utils.c | 7 | ||||
-rw-r--r-- | src/vulkan/runtime/vk_instance.c | 6 | ||||
-rw-r--r-- | src/vulkan/runtime/vk_object.c | 23 | ||||
-rw-r--r-- | src/vulkan/runtime/vk_object.h | 18 | ||||
-rw-r--r-- | src/vulkan/runtime/vk_physical_device.c | 2 |
6 files changed, 51 insertions, 9 deletions
diff --git a/src/vulkan/runtime/vk_debug_report.c b/src/vulkan/runtime/vk_debug_report.c index ea9aebf5930..6712ba6d1c8 100644 --- a/src/vulkan/runtime/vk_debug_report.c +++ b/src/vulkan/runtime/vk_debug_report.c @@ -58,8 +58,8 @@ vk_common_CreateDebugReportCallbackEXT(VkInstance _instance, if (!cb) return VK_ERROR_OUT_OF_HOST_MEMORY; - vk_object_base_init(NULL, &cb->base, - VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT); + vk_object_base_instance_init(instance, &cb->base, + VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT); cb->flags = pCreateInfo->flags; cb->callback = pCreateInfo->pfnCallback; diff --git a/src/vulkan/runtime/vk_debug_utils.c b/src/vulkan/runtime/vk_debug_utils.c index 70bcf103dbf..3865fd66802 100644 --- a/src/vulkan/runtime/vk_debug_utils.c +++ b/src/vulkan/runtime/vk_debug_utils.c @@ -213,11 +213,14 @@ vk_common_SetDebugUtilsObjectNameEXT( vk_object_base_from_u64_handle(pNameInfo->objectHandle, pNameInfo->objectType); + assert(object->device != NULL || object->instance != NULL); + VkAllocationCallbacks *alloc = object->device != NULL ? + &object->device->alloc : &object->instance->alloc; if (object->object_name) { - vk_free(&device->alloc, object->object_name); + vk_free(alloc, object->object_name); object->object_name = NULL; } - object->object_name = vk_strdup(&device->alloc, pNameInfo->pObjectName, + object->object_name = vk_strdup(alloc, pNameInfo->pObjectName, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (!object->object_name) return VK_ERROR_OUT_OF_HOST_MEMORY; diff --git a/src/vulkan/runtime/vk_instance.c b/src/vulkan/runtime/vk_instance.c index d14b196b27b..2224caf5841 100644 --- a/src/vulkan/runtime/vk_instance.c +++ b/src/vulkan/runtime/vk_instance.c @@ -52,7 +52,7 @@ vk_instance_init(struct vk_instance *instance, const VkAllocationCallbacks *alloc) { memset(instance, 0, sizeof(*instance)); - vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE); + vk_object_base_instance_init(instance, &instance->base, VK_OBJECT_TYPE_INSTANCE); instance->alloc = *alloc; util_cpu_trace_init(); @@ -75,8 +75,8 @@ vk_instance_init(struct vk_instance *instance, if (!messenger) return vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY); - vk_object_base_init(NULL, &messenger->base, - VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT); + vk_object_base_instance_init(instance, &messenger->base, + VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT); messenger->alloc = *alloc; messenger->severity = debugMessengerCreateInfo->messageSeverity; diff --git a/src/vulkan/runtime/vk_object.c b/src/vulkan/runtime/vk_object.c index b46a0f77554..753640b77b8 100644 --- a/src/vulkan/runtime/vk_object.c +++ b/src/vulkan/runtime/vk_object.c @@ -25,6 +25,7 @@ #include "vk_alloc.h" #include "vk_common_entrypoints.h" +#include "vk_instance.h" #include "vk_device.h" #include "util/hash_table.h" #include "util/ralloc.h" @@ -38,6 +39,20 @@ vk_object_base_init(struct vk_device *device, base->_loader_data.loaderMagic = ICD_LOADER_MAGIC; base->type = obj_type; base->device = device; + base->instance = NULL; + base->client_visible = false; + base->object_name = NULL; + util_sparse_array_init(&base->private_data, sizeof(uint64_t), 8); +} + +void vk_object_base_instance_init(struct vk_instance *instance, + struct vk_object_base *base, + VkObjectType obj_type) +{ + base->_loader_data.loaderMagic = ICD_LOADER_MAGIC; + base->type = obj_type; + base->device = NULL; + base->instance = instance; base->client_visible = false; base->object_name = NULL; util_sparse_array_init(&base->private_data, sizeof(uint64_t), 8); @@ -48,8 +63,14 @@ vk_object_base_finish(struct vk_object_base *base) { util_sparse_array_finish(&base->private_data); - if (base->object_name != NULL) + if (base->object_name == NULL) + return; + + assert(base->device != NULL || base->instance != NULL); + if (base->device) vk_free(&base->device->alloc, base->object_name); + else + vk_free(&base->instance->alloc, base->object_name); } void diff --git a/src/vulkan/runtime/vk_object.h b/src/vulkan/runtime/vk_object.h index ad87121e15c..0728e894b58 100644 --- a/src/vulkan/runtime/vk_object.h +++ b/src/vulkan/runtime/vk_object.h @@ -57,6 +57,14 @@ struct vk_object_base { */ struct vk_device *device; + /** Pointer to the instance in which this object exists + * + * This is NULL for device level objects as it's main purpose is to make + * the instance allocator reachable for freeing data owned by instance + * level objects. + */ + struct vk_instance *instance; + /* True if this object is fully constructed and visible to the client */ bool client_visible; @@ -77,6 +85,16 @@ void vk_object_base_init(struct vk_device *device, struct vk_object_base *base, VkObjectType obj_type); +/** Initialize a vk_base_object for an instance level object + * + * :param instance: |in| The vk_instance this object was created from + * :param base: |out| The vk_object_base to initialize + * :param obj_type: |in| The VkObjectType of the object being initialized + */ +void vk_object_base_instance_init(struct vk_instance *instance, + struct vk_object_base *base, + VkObjectType obj_type); + /** Tear down a vk_object_base * * @param[out] base The vk_object_base being torn down diff --git a/src/vulkan/runtime/vk_physical_device.c b/src/vulkan/runtime/vk_physical_device.c index ea277516be2..188449f8c50 100644 --- a/src/vulkan/runtime/vk_physical_device.c +++ b/src/vulkan/runtime/vk_physical_device.c @@ -35,7 +35,7 @@ vk_physical_device_init(struct vk_physical_device *pdevice, const struct vk_physical_device_dispatch_table *dispatch_table) { memset(pdevice, 0, sizeof(*pdevice)); - vk_object_base_init(NULL, &pdevice->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE); + vk_object_base_instance_init(instance, &pdevice->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE); pdevice->instance = instance; if (supported_extensions != NULL) |