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.
23 * @title: GstVulkanHandle
24 * @short_description: Vulkan handles
25 * @see_also: #GstVulkanHandlePool, #GstVulkanDevice
27 * #GstVulkanHandle holds information about a vulkan handle.
34 #include "gstvkhandle.h"
35 #include "gstvkdevice.h"
37 #define GST_CAT_DEFAULT gst_debug_vulkan_handle
38 GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
43 static volatile gsize _init = 0;
45 if (g_once_init_enter (&_init)) {
46 GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "vulkanhandle", 0,
48 g_once_init_leave (&_init, 1);
53 gst_vulkan_handle_free (GstVulkanHandle * handle)
55 GST_TRACE ("Freeing %p", handle);
58 handle->notify (handle, handle->user_data);
60 gst_clear_object (&handle->device);
66 gst_vulkan_handle_init (GstVulkanHandle * handle, GstVulkanDevice * device,
67 GstVulkanHandleType type, GstVulkanHandleTypedef handle_val,
68 GstVulkanHandleDestroyNotify notify, gpointer user_data)
70 handle->device = gst_object_ref (device);
72 handle->handle = handle_val;
73 handle->notify = notify;
74 handle->user_data = user_data;
78 GST_TRACE ("new %p", handle);
80 gst_mini_object_init (&handle->parent, 0, GST_TYPE_VULKAN_HANDLE, NULL, NULL,
81 (GstMiniObjectFreeFunction) gst_vulkan_handle_free);
85 * gst_vulkan_handle_new_wrapped:
86 * @handle: a Vulkan handle
87 * @notify: (scope call): a #GDestroyNotify
88 * @user_data: data to pass to @notify
90 * Returns: (transfer full): a new #GstVulkanHandle wrapping @handle
95 gst_vulkan_handle_new_wrapped (GstVulkanDevice * device,
96 GstVulkanHandleType type, GstVulkanHandleTypedef handle,
97 GstVulkanHandleDestroyNotify notify, gpointer user_data)
101 ret = g_new0 (GstVulkanHandle, 1);
102 gst_vulkan_handle_init (ret, device, type, handle, notify, user_data);
107 GST_DEFINE_MINI_OBJECT_TYPE (GstVulkanHandle, gst_vulkan_handle);
110 * gst_vulkan_handle_free_descriptor_set_layout:
111 * @handle: a #GstVulkanHandle containing a vulkan `VkDescriptorSetLayout`
112 * @user_data: callback user data
114 * Frees the descriptor set layout in @handle
119 gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle,
122 g_return_if_fail (handle != NULL);
123 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
124 g_return_if_fail (handle->type ==
125 GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT);
127 vkDestroyDescriptorSetLayout (handle->device->device,
128 (VkDescriptorSetLayout) handle->handle, NULL);
132 * gst_vulkan_handle_free_pipeline:
133 * @handle: a #GstVulkanHandle containing a vulkan `VkPipeline`
134 * @user_data: callback user data
136 * Frees the pipeline in @handle
141 gst_vulkan_handle_free_pipeline (GstVulkanHandle * handle, gpointer user_data)
143 g_return_if_fail (handle != NULL);
144 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
145 g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_PIPELINE);
147 vkDestroyPipeline (handle->device->device, (VkPipeline) handle->handle, NULL);
151 * gst_vulkan_handle_free_pipeline_layout:
152 * @handle: a #GstVulkanHandle containing a vulkan `VkPipelineLayout`
153 * @user_data: callback user data
155 * Frees the pipeline layout in @handle
160 gst_vulkan_handle_free_pipeline_layout (GstVulkanHandle * handle,
163 g_return_if_fail (handle != NULL);
164 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
165 g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT);
167 vkDestroyPipelineLayout (handle->device->device,
168 (VkPipelineLayout) handle->handle, NULL);
172 * gst_vulkan_handle_free_render_pass:
173 * @handle: a #GstVulkanHandle containing a vulkan `VkRenderPass`
174 * @user_data: callback user data
176 * Frees the render pass in @handle
181 gst_vulkan_handle_free_render_pass (GstVulkanHandle * handle,
184 g_return_if_fail (handle != NULL);
185 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
186 g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_RENDER_PASS);
188 vkDestroyRenderPass (handle->device->device,
189 (VkRenderPass) handle->handle, NULL);
193 * gst_vulkan_handle_free_sampler:
194 * @handle: a #GstVulkanHandle containing a vulkan `VkSampler`
195 * @user_data: callback user data
197 * Frees the sampler in @handle
202 gst_vulkan_handle_free_sampler (GstVulkanHandle * handle, gpointer user_data)
204 g_return_if_fail (handle != NULL);
205 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
206 g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_SAMPLER);
208 vkDestroySampler (handle->device->device, (VkSampler) handle->handle, NULL);
212 * gst_vulkan_handle_free_framebuffer:
213 * @handle: a #GstVulkanHandle containing a vulkan `VkFramebuffer`
214 * @user_data: callback user data
216 * Frees the framebuffer in @handle
221 gst_vulkan_handle_free_framebuffer (GstVulkanHandle * handle,
224 g_return_if_fail (handle != NULL);
225 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
226 g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER);
228 vkDestroyFramebuffer (handle->device->device, (VkFramebuffer) handle->handle,
233 * gst_vulkan_handle_free_shader:
234 * @handle: a #GstVulkanHandle containing a vulkan `VkFramebuffer`
235 * @user_data: callback user data
237 * Frees the shader in @handle
242 gst_vulkan_handle_free_shader (GstVulkanHandle * handle, gpointer user_data)
244 g_return_if_fail (handle != NULL);
245 g_return_if_fail (handle->handle != VK_NULL_HANDLE);
246 g_return_if_fail (handle->type == GST_VULKAN_HANDLE_TYPE_SHADER);
248 vkDestroyShaderModule (handle->device->device,
249 (VkShaderModule) handle->handle, NULL);