vk/descriptor_set_layout: Add optional destructor
authorConnor Abbott <cwabbott0@gmail.com>
Thu, 6 Oct 2022 14:46:19 +0000 (16:46 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 12 Dec 2022 17:38:19 +0000 (17:38 +0000)
Drivers implementing descriptor buffers will want to allocate and free
descriptors with the layout for embedded samplers, so we need a hook to
allow them to free any GPU buffers.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19849>

src/vulkan/runtime/vk_descriptor_set_layout.c
src/vulkan/runtime/vk_descriptor_set_layout.h

index f70302a101c3d4bfa5998be2eef5d00dc08e8465..9e657bec4c57be688b2c91a2037de0e9080a9b48 100644 (file)
@@ -35,6 +35,7 @@ vk_descriptor_set_layout_init(struct vk_device *device,
                        VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
 
    layout->ref_cnt = 1;
+   layout->destroy = vk_descriptor_set_layout_destroy;
 }
 
 void *
@@ -73,6 +74,13 @@ vk_descriptor_set_layout_multizalloc(struct vk_device *device,
    return layout;
 }
 
+void
+vk_descriptor_set_layout_destroy(struct vk_device *device,
+                                 struct vk_descriptor_set_layout *layout)
+{
+   vk_object_free(device, NULL, layout);
+}
+
 VKAPI_ATTR void VKAPI_CALL
 vk_common_DestroyDescriptorSetLayout(VkDevice _device,
                                      VkDescriptorSetLayout descriptorSetLayout,
index 4c43c5e47222101b693bd673902d50d2d87574e7..857ec1a7beaea292a9e65664ae5a5dea18ea1e84 100644 (file)
@@ -34,6 +34,9 @@ extern "C" {
 struct vk_descriptor_set_layout {
    struct vk_object_base base;
 
+   void (*destroy)(struct vk_device *device,
+                   struct vk_descriptor_set_layout *layout);
+
    /** Reference count
     *
     * It's often necessary to store a pointer to the descriptor set layout in
@@ -60,6 +63,9 @@ void *vk_descriptor_set_layout_zalloc(struct vk_device *device, size_t size);
 void *vk_descriptor_set_layout_multizalloc(struct vk_device *device,
                                            struct vk_multialloc *ma);
 
+void vk_descriptor_set_layout_destroy(struct vk_device *device,
+                                      struct vk_descriptor_set_layout *layout);
+
 static inline struct vk_descriptor_set_layout *
 vk_descriptor_set_layout_ref(struct vk_descriptor_set_layout *layout)
 {
@@ -74,7 +80,7 @@ vk_descriptor_set_layout_unref(struct vk_device *device,
 {
    assert(layout && layout->ref_cnt >= 1);
    if (p_atomic_dec_zero(&layout->ref_cnt))
-      vk_object_free(device, NULL, layout);
+      layout->destroy(device, layout);
 }
 
 #ifdef __cplusplus