summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vulkan/gstvkhandle.h
blob: 2aa6f01f7fd5530bcb59a3312e162ef39b710f19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * GStreamer
 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __GST_VULKAN_HANDLE_H__
#define __GST_VULKAN_HANDLE_H__

#include <gst/gst.h>

#include <gst/vulkan/vulkan_fwd.h>
#include <gst/vulkan/gstvkapi.h>

G_BEGIN_DECLS

/**
 * gst_vulkan_handle_get_type:
 *
 * Since: 1.18
 */
GST_VULKAN_API
GType gst_vulkan_handle_get_type (void);
/**
 * GST_TYPE_VULKAN_HANDLE:
 *
 * Since: 1.18
 */
#define GST_TYPE_VULKAN_HANDLE (gst_vulkan_handle_get_type ())

/**
 * GstVulkanHandleTypedef:
 *
 * Since: 1.18
 */
VK_DEFINE_NON_DISPATCHABLE_HANDLE(GstVulkanHandleTypedef)

/**
 * GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT:
 *
 * The printf format specifier for raw Vulkan non dispatchable handles.
 *
 * When redefining VK_DEFINE_NON_DISPATCHABLE_HANDLE, also make sure
 * to redefine a suitable printf format specifier.
 *
 * Since: 1.18
 */
#if !defined(GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT)
# define GST_VULKAN_NON_DISPATCHABLE_HANDLE_FORMAT G_GUINT64_FORMAT
#endif

/**
 * GstVulkanHandleDestroyNotify:
 * @handle: the #GstVulkanHandle
 * @user_data: callback user data
 *
 * Function definition called when the #GstVulkanHandle is no longer in use.
 * All implementations of this callback must free the internal handle stored
 * inside @handle.
 *
 * Since: 1.18
 */
typedef void (*GstVulkanHandleDestroyNotify) (GstVulkanHandle * handle, gpointer user_data);

/**
 * GstVulkanHandleType:
 * @GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT: descripter set layout
 * @GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT: pipeline layout
 * @GST_VULKAN_HANDLE_TYPE_PIPELINE: pipeline
 * @GST_VULKAN_HANDLE_TYPE_RENDER_PASS: render pass
 * @GST_VULKAN_HANDLE_TYPE_SAMPLER: sampler
 * @GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER: framebuffer
 * @GST_VULKAN_HANDLE_TYPE_SHADER: shader
 *
 * Since: 1.18
 */
typedef enum
{
  GST_VULKAN_HANDLE_TYPE_DESCRIPTOR_SET_LAYOUT          = 1,
  GST_VULKAN_HANDLE_TYPE_PIPELINE_LAYOUT                = 2,
  GST_VULKAN_HANDLE_TYPE_PIPELINE                       = 3,
  GST_VULKAN_HANDLE_TYPE_RENDER_PASS                    = 4,
  GST_VULKAN_HANDLE_TYPE_SAMPLER                        = 5,
  GST_VULKAN_HANDLE_TYPE_FRAMEBUFFER                    = 6,
  GST_VULKAN_HANDLE_TYPE_SHADER                         = 7,
} GstVulkanHandleType;

/**
 * GstVulkanHandle:
 * @parent: the parent #GstMiniObject
 * @device: the #GstVulkanDevice for this handle
 * @type: the type of handle
 * @handle: the handle value
 *
 * Holds information about a vulkan non dispatchable handle that only has
 * a vulkan device as a parent and no specific host synchronisation
 * requirements.  Command buffers have extra requirements that are serviced by
 * more specific implementations (#GstVulkanCommandBuffer, #GstVulkanCommandPool).
 *
 * Since: 1.18
 */
struct _GstVulkanHandle
{
  GstMiniObject             parent;

  GstVulkanDevice          *device;

  GstVulkanHandleType       type;
  GstVulkanHandleTypedef    handle;

  /* <protected> */
  GstVulkanHandleDestroyNotify notify;
  gpointer                  user_data;

  /* <private> */
  gpointer _reserved        [GST_PADDING];
};

/**
 * gst_vulkan_handle_ref: (skip)
 * @handle: a #GstVulkanHandle.
 *
 * Increases the refcount of the given handle by one.
 *
 * Returns: (transfer full): @buf
 *
 * Since: 1.18
 */
static inline GstVulkanHandle* gst_vulkan_handle_ref(GstVulkanHandle* handle);
static inline GstVulkanHandle *
gst_vulkan_handle_ref (GstVulkanHandle * handle)
{
  return (GstVulkanHandle *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (handle));
}

/**
 * gst_vulkan_handle_unref: (skip)
 * @handle: (transfer full): a #GstVulkanHandle.
 *
 * Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
 * will be freed.
 *
 * Since: 1.18
 */
static inline void gst_vulkan_handle_unref(GstVulkanHandle* handle);
static inline void
gst_vulkan_handle_unref (GstVulkanHandle * handle)
{
  gst_mini_object_unref (GST_MINI_OBJECT_CAST (handle));
}

/**
 * gst_clear_vulkan_handle: (skip)
 * @handle_ptr: a pointer to a #GstVulkanHandle reference
 *
 * Clears a reference to a #GstVulkanHandle.
 *
 * @handle_ptr must not be %NULL.
 *
 * If the reference is %NULL then this function does nothing. Otherwise, the
 * reference count of the handle is decreased and the pointer is set to %NULL.
 *
 * Since: 1.18
 */
static inline void
gst_clear_vulkan_handle (GstVulkanHandle ** handle_ptr)
{
  gst_clear_mini_object ((GstMiniObject **) handle_ptr);
}

GST_VULKAN_API
GstVulkanHandle *       gst_vulkan_handle_new_wrapped       (GstVulkanDevice *device,
                                                             GstVulkanHandleType type,
                                                             GstVulkanHandleTypedef handle,
                                                             GstVulkanHandleDestroyNotify notify,
                                                             gpointer user_data);

GST_VULKAN_API
void                    gst_vulkan_handle_free_descriptor_set_layout (GstVulkanHandle * handle,
                                                                      gpointer user_data);
GST_VULKAN_API
void                    gst_vulkan_handle_free_pipeline_layout       (GstVulkanHandle * handle,
                                                                      gpointer user_data);
GST_VULKAN_API
void                    gst_vulkan_handle_free_pipeline              (GstVulkanHandle * handle,
                                                                      gpointer user_data);
GST_VULKAN_API
void                    gst_vulkan_handle_free_render_pass           (GstVulkanHandle * handle,
                                                                      gpointer user_data);
GST_VULKAN_API
void                    gst_vulkan_handle_free_sampler               (GstVulkanHandle * handle,
                                                                      gpointer user_data);
GST_VULKAN_API
void                    gst_vulkan_handle_free_framebuffer           (GstVulkanHandle * handle,
                                                                      gpointer user_data);
GST_VULKAN_API
void                    gst_vulkan_handle_free_shader                (GstVulkanHandle * handle,
                                                                      gpointer user_data);

G_END_DECLS

#endif /* _GST_VULKAN_HANDLE_H_ */