3 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:vkdescriptorset
23 * @title: GstVulkanDescriptorSet
24 * @short_description: Vulkan descriptor set
25 * @see_also: #GstVulkanDescriptorPool, #GstVulkanDescriptorCache, #GstVulkanDevice
27 * vulkandescriptorset holds information about a descriptor set.
34 #include "gstvkdescriptorset.h"
35 #include "gstvkdescriptorpool.h"
36 #include "gstvkdescriptorcache.h"
38 #define GST_CAT_DEFAULT gst_debug_vulkan_descriptor_set
39 GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
41 #define gst_vulkan_descriptor_cache_release_set(c,s) \
42 gst_vulkan_handle_pool_release (GST_VULKAN_HANDLE_POOL_CAST (c), s);
47 static volatile gsize _init = 0;
49 if (g_once_init_enter (&_init)) {
50 GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "vulkandescriptorset", 0,
51 "Vulkan descriptor set");
52 g_once_init_leave (&_init, 1);
57 gst_vulkan_descriptor_set_dispose (GstVulkanDescriptorSet * set)
59 GstVulkanDescriptorCache *cache;
61 /* no pool, do free */
62 if ((cache = set->cache) == NULL)
65 /* keep the buffer alive */
66 gst_vulkan_descriptor_set_ref (set);
67 /* return the buffer to the pool */
68 gst_vulkan_descriptor_cache_release_set (cache, set);
74 gst_vulkan_descriptor_set_free (GstVulkanDescriptorSet * set)
78 g_assert (set->cache == NULL);
80 GST_TRACE ("Freeing %p", set);
82 for (i = 0; i < set->n_layouts; i++)
83 gst_vulkan_handle_unref (set->layouts[i]);
84 g_free (set->layouts);
86 vkFreeDescriptorSets (set->pool->device->device, set->pool->pool, 1,
89 gst_clear_object (&set->pool);
95 gst_vulkan_descriptor_set_init (GstVulkanDescriptorSet * set,
96 GstVulkanDescriptorPool * pool, VkDescriptorSet desc_set, guint n_layouts,
97 GstVulkanHandle ** layouts)
101 set->pool = gst_object_ref (pool);
103 set->n_layouts = n_layouts;
104 set->layouts = g_new0 (GstVulkanHandle *, n_layouts);
105 for (i = 0; i < n_layouts; i++)
106 set->layouts[i] = gst_vulkan_handle_ref (layouts[i]);
110 GST_TRACE ("new %p", set);
112 gst_mini_object_init (&set->parent, 0, GST_TYPE_VULKAN_DESCRIPTOR_SET,
113 NULL, (GstMiniObjectDisposeFunction) gst_vulkan_descriptor_set_dispose,
114 (GstMiniObjectFreeFunction) gst_vulkan_descriptor_set_free);
118 * gst_vulkan_descriptor_set_new_wrapped:
119 * @set: a VkDescriptorSet
121 * Returns: (transfer full): a new #GstVulkanDescriptorSet
125 GstVulkanDescriptorSet *
126 gst_vulkan_descriptor_set_new_wrapped (GstVulkanDescriptorPool * pool,
127 VkDescriptorSet set, guint n_layouts, GstVulkanHandle ** layouts)
129 GstVulkanDescriptorSet *ret;
131 g_return_val_if_fail (GST_IS_VULKAN_DESCRIPTOR_POOL (pool), NULL);
132 g_return_val_if_fail (set != VK_NULL_HANDLE, NULL);
133 g_return_val_if_fail (n_layouts > 0, NULL);
134 g_return_val_if_fail (layouts != NULL, NULL);
136 ret = g_new0 (GstVulkanDescriptorSet, 1);
137 gst_vulkan_descriptor_set_init (ret, pool, set, n_layouts, layouts);
142 GST_DEFINE_MINI_OBJECT_TYPE (GstVulkanDescriptorSet, gst_vulkan_descriptor_set);