vulkan: Add a concept of recycling an object
authorJason Ekstrand <jason.ekstrand@collabora.com>
Tue, 30 Aug 2022 16:06:39 +0000 (11:06 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 1 Sep 2022 20:17:25 +0000 (20:17 +0000)
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 <airlied@redhat.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18324>

src/vulkan/runtime/vk_object.c
src/vulkan/runtime/vk_object.h

index 4fe0db7..fb53ce6 100644 (file)
@@ -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,
index f60c200..79157f2 100644 (file)
@@ -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)