From ea9e7ecdc1240d4c42f2709086837459f9da818c Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 30 Aug 2022 11:06:39 -0500 Subject: [PATCH] vulkan: Add a concept of recycling an object This is not necessarily a full re-initialization of the object but is whatever is necessary/expedient for the client to see it as a new object and not the one it has seen before. For vk_base_object, this removes any private data and resets the object name to NULL. Reviewed-by: Dave Airlie Reviewed-by: Samuel Pitoiset Part-of: --- src/vulkan/runtime/vk_object.c | 9 +++++++++ src/vulkan/runtime/vk_object.h | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/vulkan/runtime/vk_object.c b/src/vulkan/runtime/vk_object.c index 4fe0db7..fb53ce6 100644 --- a/src/vulkan/runtime/vk_object.c +++ b/src/vulkan/runtime/vk_object.c @@ -52,6 +52,15 @@ vk_object_base_finish(struct vk_object_base *base) vk_free(&base->device->alloc, base->object_name); } +void +vk_object_base_recycle(struct vk_object_base *base) +{ + struct vk_device *device = base->device; + VkObjectType obj_type = base->type; + vk_object_base_finish(base); + vk_object_base_init(device, base, obj_type); +} + void * vk_object_alloc(struct vk_device *device, const VkAllocationCallbacks *alloc, diff --git a/src/vulkan/runtime/vk_object.h b/src/vulkan/runtime/vk_object.h index f60c200..79157f2 100644 --- a/src/vulkan/runtime/vk_object.h +++ b/src/vulkan/runtime/vk_object.h @@ -83,6 +83,17 @@ void vk_object_base_init(struct vk_device *device, */ void vk_object_base_finish(struct vk_object_base *base); +/** Recycles a vk_object_base + * + * This should be called when an object is recycled and handed back to the + * client as if it were a new object. When it's called is not important as + * long as it's called between when the client thinks the object was destroyed + * and when the client sees it again as a supposedly new object. + * + * @param[inout] base The vk_object_base being recycled + */ +void vk_object_base_recycle(struct vk_object_base *base); + static inline void vk_object_base_assert_valid(ASSERTED struct vk_object_base *base, ASSERTED VkObjectType obj_type) -- 2.7.4