• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2015 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_BASE_BUFFER_H__
22 #define __GST_VULKAN_BASE_BUFFER_H__
23 
24 #include <gst/gst.h>
25 #include <gst/gstallocator.h>
26 #include <gst/gstmemory.h>
27 
28 #include <gst/vulkan/vulkan.h>
29 
30 G_BEGIN_DECLS
31 
32 #define GST_TYPE_VULKAN_MEMORY_ALLOCATOR (gst_vulkan_memory_allocator_get_type())
33 GST_VULKAN_API
34 GType gst_vulkan_memory_allocator_get_type(void);
35 
36 #define GST_IS_VULKAN_MEMORY_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR))
37 #define GST_IS_VULKAN_MEMORY_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VULKAN_MEMORY_ALLOCATOR))
38 #define GST_VULKAN_MEMORY_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanMemoryAllocatorClass))
39 #define GST_VULKAN_MEMORY_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanMemoryAllocator))
40 #define GST_VULKAN_MEMORY_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanMemoryAllocatorClass))
41 /**
42  * GST_VULKAN_MEMORY_ALLOCATOR_CAST:
43  *
44  * Since: 1.18
45  */
46 #define GST_VULKAN_MEMORY_ALLOCATOR_CAST(obj)            ((GstVulkanMemoryAllocator *)(obj))
47 
48 /**
49  * GST_VULKAN_MEMORY_ALLOCATOR_NAME:
50  *
51  * Since: 1.18
52  */
53 #define GST_VULKAN_MEMORY_ALLOCATOR_NAME "Vulkan"
54 
55 /**
56  * GstVulkanMemory
57  * @mem: the parent #GstMemory
58  * @device: the #GstVulkanDevice this memory is allocated from
59  * @mem_ptr: the vulkan memory handle
60  * @lock: lock for accessing/changing memory informat
61  * @map_count: number of times this memory is mapped
62  *
63  * Since: 1.18
64  */
65 struct _GstVulkanMemory
66 {
67   GstMemory                 mem;
68 
69   GstVulkanDevice          *device;
70 
71   VkDeviceMemory            mem_ptr;
72 
73   /* <protected> */
74   GMutex                    lock;
75   guint                     map_count;
76 
77   /* <private> */
78   GDestroyNotify            notify;
79   gpointer                  user_data;
80 
81   VkMemoryAllocateInfo      alloc_info;
82   VkMemoryPropertyFlags     properties;
83 
84   /* we need our own offset because GstMemory's is used to offset into the
85    * mapped pointer which when suballocating, we need to avoid.  This in
86    * relation to the root memory */
87   guint64                   vk_offset;
88   gboolean                  wrapped;
89 
90   /* <private> */
91   gpointer _reserved        [GST_PADDING];
92 };
93 
94 /**
95  * GstVulkanMemoryAllocator
96  * @parent: the parent #GstAllocator
97  *
98  * Opaque #GstVulkanMemoryAllocator struct
99  *
100  * Since: 1.18
101  */
102 struct _GstVulkanMemoryAllocator
103 {
104   GstAllocator parent;
105 
106   /* <private> */
107   gpointer _reserved        [GST_PADDING];
108 };
109 
110 /**
111  * GstVulkanMemoryAllocatorClass:
112  * @parent_class: the parent #GstAllocatorClass
113  *
114  * The #GstVulkanMemoryAllocatorClass only contains private data
115  *
116  * Since: 1.18
117  */
118 struct _GstVulkanMemoryAllocatorClass
119 {
120   GstAllocatorClass parent_class;
121 
122   /* <private> */
123   gpointer _reserved        [GST_PADDING];
124 };
125 
126 GST_VULKAN_API
127 void            gst_vulkan_memory_init_once     (void);
128 GST_VULKAN_API
129 gboolean        gst_is_vulkan_memory            (GstMemory * mem);
130 
131 GST_VULKAN_API
132 GstMemory *     gst_vulkan_memory_alloc         (GstVulkanDevice * device,
133                                                  guint32 memory_type_index,
134                                                  GstAllocationParams * params,
135                                                  gsize size,
136                                                  VkMemoryPropertyFlags mem_prop_flags);
137 
138 GST_VULKAN_API
139 gboolean        gst_vulkan_memory_find_memory_type_index_with_type_properties   (GstVulkanDevice * device,
140                                                                                  guint32 type_bits,
141                                                                                  VkMemoryPropertyFlags properties,
142                                                                                  guint32 * type_index);
143 
144 G_END_DECLS
145 
146 #endif /* _GST_VULKAN_BASE_BUFFER_H_ */
147