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 <vk.h> 29 30 G_BEGIN_DECLS 31 32 #define GST_TYPE_VULKAN_MEMORY_ALLOCATOR (gst_vulkan_memory_allocator_get_type()) 33 GType gst_vulkan_memory_allocator_get_type(void); 34 35 #define GST_IS_VULKAN_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR)) 36 #define GST_IS_VULKAN_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VULKAN_MEMORY_ALLOCATOR)) 37 #define GST_VULKAN_MEMORY_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanMemoryAllocatorClass)) 38 #define GST_VULKAN_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanMemoryAllocator)) 39 #define GST_VULKAN_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VULKAN_MEMORY_ALLOCATOR, GstVulkanMemoryAllocatorClass)) 40 #define GST_VULKAN_MEMORY_ALLOCATOR_CAST(obj) ((GstVulkanMemoryAllocator *)(obj)) 41 42 #define GST_VULKAN_MEMORY_ALLOCATOR_NAME "Vulkan" 43 44 struct _GstVulkanMemory 45 { 46 GstMemory mem; 47 48 GstVulkanDevice *device; 49 50 VkDeviceMemory mem_ptr; 51 52 /* <protected> */ 53 GMutex lock; 54 guint map_count; 55 56 /* <private> */ 57 GDestroyNotify notify; 58 gpointer user_data; 59 60 VkMemoryAllocateInfo alloc_info; 61 VkMemoryPropertyFlags properties; 62 63 /* we need our own offset because GstMemory's is used to offset into the 64 * mapped pointer which when suballocating, we need to avoid. This in 65 * relation to the root memory */ 66 guint64 vk_offset; 67 gboolean wrapped; 68 }; 69 70 /** 71 * GstVulkanMemoryAllocator 72 * 73 * Opaque #GstVulkanMemoryAllocator struct 74 */ 75 struct _GstVulkanMemoryAllocator 76 { 77 GstAllocator parent; 78 }; 79 80 /** 81 * GstVulkanMemoryAllocatorClass: 82 * 83 * The #GstVulkanMemoryAllocatorClass only contains private data 84 */ 85 struct _GstVulkanMemoryAllocatorClass 86 { 87 GstAllocatorClass parent_class; 88 }; 89 90 void gst_vulkan_memory_init_once (void); 91 gboolean gst_is_vulkan_memory (GstMemory * mem); 92 93 GstMemory * gst_vulkan_memory_alloc (GstVulkanDevice * device, 94 guint32 memory_type_index, 95 GstAllocationParams * params, 96 gsize size, 97 VkMemoryPropertyFlags mem_prop_flags); 98 99 gboolean gst_vulkan_memory_find_memory_type_index_with_type_properties (GstVulkanDevice * device, 100 guint32 typeBits, 101 VkMemoryPropertyFlags properties, 102 guint32 * typeIndex); 103 104 G_END_DECLS 105 106 #endif /* _GST_VULKAN_BASE_BUFFER_H_ */ 107