vkbuffermemory: add gst_vulkan_buffer_memory_alloc_with_buffer_info()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4351>
This commit is contained in:
Víctor Manuel Jáquez Leal 2023-01-17 15:07:14 +01:00 committed by GStreamer Marge Bot
parent 64ba7fb2eb
commit 1e2ff519c6
2 changed files with 66 additions and 20 deletions

View file

@ -96,25 +96,19 @@ _vk_buffer_mem_init (GstVulkanBufferMemory * mem, GstAllocator * allocator,
} }
static GstVulkanBufferMemory * static GstVulkanBufferMemory *
_vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent, _vk_buffer_mem_new_alloc_with_buffer_info (GstAllocator * allocator,
GstVulkanDevice * device, gsize size, VkBufferUsageFlags usage, GstMemory * parent, GstVulkanDevice * device,
VkMemoryPropertyFlags mem_prop_flags, gpointer user_data, VkBufferCreateInfo * buffer_info, VkMemoryPropertyFlags mem_prop_flags,
GDestroyNotify notify) gpointer user_data, GDestroyNotify notify)
{ {
GstVulkanBufferMemory *mem = NULL; GstVulkanBufferMemory *mem = NULL;
GstAllocationParams params = { 0, }; GstAllocationParams params = { 0, };
VkBufferCreateInfo buffer_info;
GError *error = NULL; GError *error = NULL;
guint32 type_idx; guint32 type_idx;
VkBuffer buffer; VkBuffer buffer;
VkResult err; VkResult err;
if (!_create_info_from_args (&buffer_info, size, usage)) { err = vkCreateBuffer (device->device, buffer_info, NULL, &buffer);
GST_CAT_ERROR (GST_CAT_VULKAN_BUFFER_MEMORY, "Incorrect buffer parameters");
goto error;
}
err = vkCreateBuffer (device->device, &buffer_info, NULL, &buffer);
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateBuffer") < 0) if (gst_vulkan_error_to_g_error (err, &error, "vkCreateBuffer") < 0)
goto vk_error; goto vk_error;
@ -128,8 +122,8 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
} }
params.align = mem->requirements.alignment - 1; params.align = mem->requirements.alignment - 1;
_vk_buffer_mem_init (mem, allocator, parent, device, usage, &params, size, _vk_buffer_mem_init (mem, allocator, parent, device, buffer_info->usage,
user_data, notify); &params, buffer_info->size, user_data, notify);
mem->buffer = buffer; mem->buffer = buffer;
if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device, if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device,
@ -163,6 +157,23 @@ error:
} }
} }
static GstVulkanBufferMemory *
_vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
GstVulkanDevice * device, gsize size, VkBufferUsageFlags usage,
VkMemoryPropertyFlags mem_prop_flags, gpointer user_data,
GDestroyNotify notify)
{
VkBufferCreateInfo buffer_info;
if (!_create_info_from_args (&buffer_info, size, usage)) {
GST_CAT_ERROR (GST_CAT_VULKAN_BUFFER_MEMORY, "Incorrect buffer parameters");
return NULL;
}
return _vk_buffer_mem_new_alloc_with_buffer_info (allocator, parent, device,
&buffer_info, mem_prop_flags, user_data, notify);
}
static GstVulkanBufferMemory * static GstVulkanBufferMemory *
_vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent, _vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
GstVulkanDevice * device, VkBuffer buffer, VkBufferUsageFlags usage, GstVulkanDevice * device, VkBuffer buffer, VkBufferUsageFlags usage,
@ -271,6 +282,35 @@ _vk_buffer_mem_free (GstAllocator * allocator, GstMemory * memory)
g_free (mem); g_free (mem);
} }
/**
* gst_vulkan_buffer_memory_alloc_with_buffer_info:
* @device: a #GstVulkanDevice
* @buffer_info: the VkBufferCreateInfo structure
* @mem_prop_flags: memory properties flags for the backing memory
*
* Allocate a new #GstVulkanBufferMemory.
*
* Returns: (transfer full): a #GstMemory object backed by a vulkan buffer
* backed by vulkan device memory
*
* Since: 1.24
*/
GstMemory *
gst_vulkan_buffer_memory_alloc_with_buffer_info (GstVulkanDevice * device,
VkBufferCreateInfo * buffer_info, VkMemoryPropertyFlags mem_prop_flags)
{
GstVulkanBufferMemory *mem;
g_return_val_if_fail (buffer_info
&& buffer_info->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, NULL);
mem = _vk_buffer_mem_new_alloc_with_buffer_info
(_vulkan_buffer_memory_allocator, NULL, device, buffer_info,
mem_prop_flags, NULL, NULL);
return (GstMemory *) mem;
}
/** /**
* gst_vulkan_buffer_memory_alloc: * gst_vulkan_buffer_memory_alloc:
* @device: a #GstVulkanDevice * @device: a #GstVulkanDevice

View file

@ -152,6 +152,12 @@ GstMemory * gst_vulkan_buffer_memory_alloc (GstVulkanDevice * devi
VkBufferUsageFlags usage, VkBufferUsageFlags usage,
VkMemoryPropertyFlags mem_prop_flags); VkMemoryPropertyFlags mem_prop_flags);
GST_VULKAN_API
GstMemory * gst_vulkan_buffer_memory_alloc_with_buffer_info
(GstVulkanDevice * device,
VkBufferCreateInfo * buffer_info,
VkMemoryPropertyFlags mem_prop_flags);
GST_VULKAN_API GST_VULKAN_API
GstMemory * gst_vulkan_buffer_memory_wrapped (GstVulkanDevice * device, GstMemory * gst_vulkan_buffer_memory_wrapped (GstVulkanDevice * device,
VkBuffer buffer, VkBuffer buffer,