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_COMMAND_BUFFER_H__
22 #define __GST_VULKAN_COMMAND_BUFFER_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_command_buffer_get_type:
33 *
34 * Since: 1.18
35 */
36 GST_VULKAN_API
37 GType gst_vulkan_command_buffer_get_type (void);
38 /**
39 * GST_TYPE_VULKAN_COMMAND_BUFFER:
40 *
41 * Since: 1.18
42 */
43 #define GST_TYPE_VULKAN_COMMAND_BUFFER (gst_vulkan_command_buffer_get_type ())
44
45 typedef struct _GstVulkanCommandBuffer GstVulkanCommandBuffer;
46
47 /**
48 * GstVulkanCommandBuffer:
49 * @parent: the parent #GstMiniObject
50 * @cmd: the vulkan command buffer handle
51 * @pool: the parent #GstVulkanCommandPool for command buffer reuse and locking
52 * @level: the level of the vulkan command buffer
53 *
54 * Since: 1.18
55 */
56 struct _GstVulkanCommandBuffer
57 {
58 GstMiniObject parent;
59
60 VkCommandBuffer cmd;
61
62 /* <protected> */
63 GstVulkanCommandPool *pool;
64 VkCommandBufferLevel level;
65
66 /* <private> */
67 gpointer _reserved [GST_PADDING];
68 };
69
70 /**
71 * gst_vulkan_command_buffer_ref: (skip)
72 * @cmd: a #GstVulkanCommandBuffer.
73 *
74 * Increases the refcount of the given buffer by one.
75 *
76 * Returns: (transfer full): @cmd
77 *
78 * Since: 1.18
79 */
80 static inline GstVulkanCommandBuffer* gst_vulkan_command_buffer_ref(GstVulkanCommandBuffer* cmd);
81 static inline GstVulkanCommandBuffer *
gst_vulkan_command_buffer_ref(GstVulkanCommandBuffer * cmd)82 gst_vulkan_command_buffer_ref (GstVulkanCommandBuffer * cmd)
83 {
84 return (GstVulkanCommandBuffer *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (cmd));
85 }
86
87 /**
88 * gst_vulkan_command_buffer_unref: (skip)
89 * @cmd: (transfer full): a #GstVulkanCommandBuffer.
90 *
91 * Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
92 * will be freed.
93 *
94 * Since: 1.18
95 */
96 static inline void gst_vulkan_command_buffer_unref(GstVulkanCommandBuffer* cmd);
97 static inline void
gst_vulkan_command_buffer_unref(GstVulkanCommandBuffer * cmd)98 gst_vulkan_command_buffer_unref (GstVulkanCommandBuffer * cmd)
99 {
100 gst_mini_object_unref (GST_MINI_OBJECT_CAST (cmd));
101 }
102
103 /**
104 * gst_clear_vulkan_command_buffer: (skip)
105 * @cmd_ptr: a pointer to a #GstVulkanCommandBuffer reference
106 *
107 * Clears a reference to a #GstVulkanCommandBuffer.
108 *
109 * @cmd_ptr must not be %NULL.
110 *
111 * If the reference is %NULL then this function does nothing. Otherwise, the
112 * reference count of the command buffer is decreased and the pointer is set
113 * to %NULL.
114 *
115 * Since: 1.18
116 */
117 static inline void
gst_clear_vulkan_command_buffer(GstVulkanCommandBuffer ** cmd_ptr)118 gst_clear_vulkan_command_buffer (GstVulkanCommandBuffer ** cmd_ptr)
119 {
120 gst_clear_mini_object ((GstMiniObject **) cmd_ptr);
121 }
122
123 /**
124 * gst_vulkan_command_buffer_lock:
125 * @cmd: the #GstVulkanCommandBuffer
126 *
127 * Lock @cmd for writing cmmands to @cmd. Must be matched by a corresponding
128 * gst_vulkan_command_buffer_unlock().
129 *
130 * Since: 1.18
131 */
132 #define gst_vulkan_command_buffer_lock(cmd) (gst_vulkan_command_pool_lock((cmd)->pool))
133 /**
134 * gst_vulkan_command_buffer_unlock:
135 * @cmd: the #GstVulkanCommandBuffer
136 *
137 * Unlock @cmd for writing cmmands to @cmd. Must be matched by a corresponding
138 * gst_vulkan_command_buffer_lock().
139 *
140 * Since: 1.18
141 */
142 #define gst_vulkan_command_buffer_unlock(cmd) (gst_vulkan_command_pool_unlock((cmd)->pool))
143
144 GST_VULKAN_API
145 GstVulkanCommandBuffer * gst_vulkan_command_buffer_new_wrapped (VkCommandBuffer cmd,
146 VkCommandBufferLevel level);
147
148 G_END_DECLS
149
150 #endif /* _GST_VULKAN_COMMAND_BUFFER_H_ */
151