1 /*
2 * GStreamer
3 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
4 *
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.
9 *
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.
14 *
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.
19 */
20
21 #ifndef __GST_VULKAN_HANDLE_H__
22 #define __GST_VULKAN_HANDLE_H__
23
24 #include <gst/gst.h>
25
26 #include <gst/vulkan/vulkan_fwd.h>
27 #include <gst/vulkan/gstvkapi.h>
28
29 G_BEGIN_DECLS
30
31 /**
32 * gst_vulkan_handle_get_type:
33 *
34 * Since: 1.18
35 */
36 GST_VULKAN_API
37 GType gst_vulkan_handle_get_type (void);
38 /**
39 * GST_TYPE_VULKAN_HANDLE:
40 *
41 * Since: 1.18
42 */
43 #define GST_TYPE_VULKAN_HANDLE (gst_vulkan_handle_get_type ())
44
45 /**
46 * GstVulkanHandleTypedef:
47 *
48 * Since: 1.18
49 */
50 VK_DEFINE_NON_DISPATCHABLE_HANDLE(GstVulkanHandleTypedef)
51
52 /**
53 * GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT:
54 *
55 * The printf format specifier for raw Vulkan non dispatchable handles.
56 *
57 * When redefining VK_DEFINE_NON_DISPATCHABLE_HANDLE, also make sure
58 * to redefine a suitable printf format specifier.
59 *
60 * Since: 1.18
61 */
62 #if !defined(GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT)
63 # define GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT G_GUINT64_FORMAT
64 #endif
65
66 /**
67 * GstVulkanHandleDestroyNotify:
68 * @handle: the #GstVulkanHandle
69 * @user_data: callback user data
70 *
71 * Function definition called when the #GstVulkanHandle is no longer in use.
72 * All implementations of this callback must free the internal handle stored
73 * inside @handle.
74 *
75 * Since: 1.18
76 */
77 typedef void (*GstVulkanHandleDestroyNotify) (GstVulkanHandle * handle, gpointer user_data);
78
79 /**
80 * GstVulkanHandleType:
81 * @GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT: descripter set layout
82 * @GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT: pipeline layout
83 * @GST_VULKAN_HANDLE_TYPE_PIPELINE: pipeline
84 * @GST_VULKAN_HANDLE_TYPE_RENDER_PASS: render pass
85 * @GST_VULKAN_HANDLE_TYPE_SAMPLER: sampler
86 * @GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER: framebuffer
87 * @GST_VULKAN_HANDLE_TYPE_SHADER: shader
88 *
89 * Since: 1.18
90 */
91 typedef enum
92 {
93 GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT = 1,
94 GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT = 2,
95 GST_VULKAN_HANDLE_TYPE_PIPELINE = 3,
96 GST_VULKAN_HANDLE_TYPE_RENDER_PASS = 4,
97 GST_VULKAN_HANDLE_TYPE_SAMPLER = 5,
98 GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER = 6,
99 GST_VULKAN_HANDLE_TYPE_SHADER = 7,
100 } GstVulkanHandleType;
101
102 /**
103 * GstVulkanHandle:
104 * @parent: the parent #GstMiniObject
105 * @device: the #GstVulkanDevice for this handle
106 * @type: the type of handle
107 * @handle: the handle value
108 *
109 * Holds information about a vulkan non dispatchable handle that only has
110 * a vulkan device as a parent and no specific host synchronisation
111 * requirements. Command buffers have extra requirements that are serviced by
112 * more specific implementations (#GstVulkanCommandBuffer, #GstVulkanCommandPool).
113 *
114 * Since: 1.18
115 */
116 struct _GstVulkanHandle
117 {
118 GstMiniObject parent;
119
120 GstVulkanDevice *device;
121
122 GstVulkanHandleType type;
123 GstVulkanHandleTypedef handle;
124
125 /* <protected> */
126 GstVulkanHandleDestroyNotify notify;
127 gpointer user_data;
128
129 /* <private> */
130 gpointer _reserved [GST_PADDING];
131 };
132
133 /**
134 * gst_vulkan_handle_ref: (skip)
135 * @handle: a #GstVulkanHandle.
136 *
137 * Increases the refcount of the given handle by one.
138 *
139 * Returns: (transfer full): @buf
140 *
141 * Since: 1.18
142 */
143 static inline GstVulkanHandle* gst_vulkan_handle_ref(GstVulkanHandle* handle);
144 static inline GstVulkanHandle *
gst_vulkan_handle_ref(GstVulkanHandle * handle)145 gst_vulkan_handle_ref (GstVulkanHandle * handle)
146 {
147 return (GstVulkanHandle *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (handle));
148 }
149
150 /**
151 * gst_vulkan_handle_unref: (skip)
152 * @handle: (transfer full): a #GstVulkanHandle.
153 *
154 * Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
155 * will be freed.
156 *
157 * Since: 1.18
158 */
159 static inline void gst_vulkan_handle_unref(GstVulkanHandle* handle);
160 static inline void
gst_vulkan_handle_unref(GstVulkanHandle * handle)161 gst_vulkan_handle_unref (GstVulkanHandle * handle)
162 {
163 gst_mini_object_unref (GST_MINI_OBJECT_CAST (handle));
164 }
165
166 /**
167 * gst_clear_vulkan_handle: (skip)
168 * @handle_ptr: a pointer to a #GstVulkanHandle reference
169 *
170 * Clears a reference to a #GstVulkanHandle.
171 *
172 * @handle_ptr must not be %NULL.
173 *
174 * If the reference is %NULL then this function does nothing. Otherwise, the
175 * reference count of the handle is decreased and the pointer is set to %NULL.
176 *
177 * Since: 1.18
178 */
179 static inline void
gst_clear_vulkan_handle(GstVulkanHandle ** handle_ptr)180 gst_clear_vulkan_handle (GstVulkanHandle ** handle_ptr)
181 {
182 gst_clear_mini_object ((GstMiniObject **) handle_ptr);
183 }
184
185 GST_VULKAN_API
186 GstVulkanHandle * gst_vulkan_handle_new_wrapped (GstVulkanDevice *device,
187 GstVulkanHandleType type,
188 GstVulkanHandleTypedef handle,
189 GstVulkanHandleDestroyNotify notify,
190 gpointer user_data);
191
192 GST_VULKAN_API
193 void gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle,
194 gpointer user_data);
195 GST_VULKAN_API
196 void gst_vulkan_handle_free_pipeline_layout (GstVulkanHandle * handle,
197 gpointer user_data);
198 GST_VULKAN_API
199 void gst_vulkan_handle_free_pipeline (GstVulkanHandle * handle,
200 gpointer user_data);
201 GST_VULKAN_API
202 void gst_vulkan_handle_free_render_pass (GstVulkanHandle * handle,
203 gpointer user_data);
204 GST_VULKAN_API
205 void gst_vulkan_handle_free_sampler (GstVulkanHandle * handle,
206 gpointer user_data);
207 GST_VULKAN_API
208 void gst_vulkan_handle_free_framebuffer (GstVulkanHandle * handle,
209 gpointer user_data);
210 GST_VULKAN_API
211 void gst_vulkan_handle_free_shader (GstVulkanHandle * handle,
212 gpointer user_data);
213
214 G_END_DECLS
215
216 #endif /* _GST_VULKAN_HANDLE_H_ */
217