mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-16 19:25:18 +00:00
vkimagememory: gst_vulkan_image_memory_alloc_with_image_info()
This new method instead of passing a bunch of variables which will fill `VkImageCreateInfo`, the method accepts this whole structure, so the caller can customize it as much as they want. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4351>
This commit is contained in:
parent
5f5249cf73
commit
64ba7fb2eb
2 changed files with 77 additions and 16 deletions
|
@ -188,29 +188,36 @@ gst_vulkan_image_memory_init (GstVulkanImageMemory * mem,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstVulkanImageMemory *
|
static GstVulkanImageMemory *
|
||||||
_vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
_vk_image_mem_new_alloc_with_image_info (GstAllocator * allocator,
|
||||||
GstVulkanDevice * device, VkFormat format, gsize width, gsize height,
|
GstMemory * parent, GstVulkanDevice * device,
|
||||||
VkImageTiling tiling, VkImageUsageFlags usage,
|
VkImageCreateInfo * image_info, VkMemoryPropertyFlags mem_prop_flags,
|
||||||
VkMemoryPropertyFlags mem_prop_flags, gpointer user_data,
|
gpointer user_data, GDestroyNotify notify)
|
||||||
GDestroyNotify notify)
|
|
||||||
{
|
{
|
||||||
GstVulkanImageMemory *mem = NULL;
|
GstVulkanImageMemory *mem = NULL;
|
||||||
GstAllocationParams params = { 0, };
|
GstAllocationParams params = { 0, };
|
||||||
VkImageCreateInfo image_info;
|
|
||||||
VkPhysicalDevice gpu;
|
VkPhysicalDevice gpu;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
GArray *qfi = NULL;
|
||||||
guint32 type_idx;
|
guint32 type_idx;
|
||||||
VkImage image;
|
VkImage image;
|
||||||
VkResult err;
|
VkResult err;
|
||||||
|
|
||||||
gpu = gst_vulkan_device_get_physical_device (device);
|
gpu = gst_vulkan_device_get_physical_device (device);
|
||||||
if (!_create_info_from_args (&image_info, format, width, height, tiling,
|
|
||||||
usage)) {
|
if (!image_info->pQueueFamilyIndices) {
|
||||||
GST_CAT_ERROR (GST_CAT_VULKAN_IMAGE_MEMORY, "Incorrect image parameters");
|
/* XXX: overwrite the queue indices part of the structure */
|
||||||
goto error;
|
qfi = gst_vulkan_device_queue_family_indices (device);
|
||||||
|
image_info->pQueueFamilyIndices = (uint32_t *) qfi->data;
|
||||||
|
image_info->queueFamilyIndexCount = qfi->len;
|
||||||
|
image_info->sharingMode = qfi->len > 1 ? VK_SHARING_MODE_CONCURRENT :
|
||||||
|
VK_SHARING_MODE_EXCLUSIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = vkCreateImage (device->device, &image_info, NULL, &image);
|
err = vkCreateImage (device->device, image_info, NULL, &image);
|
||||||
|
|
||||||
|
if (qfi)
|
||||||
|
g_array_unref (qfi);
|
||||||
|
|
||||||
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImage") < 0)
|
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImage") < 0)
|
||||||
goto vk_error;
|
goto vk_error;
|
||||||
|
|
||||||
|
@ -218,13 +225,16 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
||||||
|
|
||||||
vkGetImageMemoryRequirements (device->device, image, &mem->requirements);
|
vkGetImageMemoryRequirements (device->device, image, &mem->requirements);
|
||||||
|
|
||||||
gst_vulkan_image_memory_init (mem, allocator, parent, device, usage, ¶ms,
|
gst_vulkan_image_memory_init (mem, allocator, parent, device,
|
||||||
mem->requirements.size, user_data, notify);
|
image_info->usage, ¶ms, mem->requirements.size, user_data, notify);
|
||||||
mem->create_info = image_info;
|
mem->create_info = *image_info;
|
||||||
|
/* XXX: to avoid handling pNext lifetime */
|
||||||
|
mem->create_info.pNext = NULL;
|
||||||
mem->image = image;
|
mem->image = image;
|
||||||
|
|
||||||
err = vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
|
err = vkGetPhysicalDeviceImageFormatProperties (gpu, image_info->format,
|
||||||
tiling, usage, 0, &mem->format_properties);
|
VK_IMAGE_TYPE_2D, image_info->tiling, image_info->usage, 0,
|
||||||
|
&mem->format_properties);
|
||||||
if (gst_vulkan_error_to_g_error (err, &error,
|
if (gst_vulkan_error_to_g_error (err, &error,
|
||||||
"vkGetPhysicalDeviceImageFormatProperties") < 0)
|
"vkGetPhysicalDeviceImageFormatProperties") < 0)
|
||||||
goto vk_error;
|
goto vk_error;
|
||||||
|
@ -266,6 +276,25 @@ error:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstVulkanImageMemory *
|
||||||
|
_vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
||||||
|
GstVulkanDevice * device, VkFormat format, gsize width, gsize height,
|
||||||
|
VkImageTiling tiling, VkImageUsageFlags usage,
|
||||||
|
VkMemoryPropertyFlags mem_prop_flags, gpointer user_data,
|
||||||
|
GDestroyNotify notify)
|
||||||
|
{
|
||||||
|
VkImageCreateInfo image_info;
|
||||||
|
|
||||||
|
if (!_create_info_from_args (&image_info, format, width, height, tiling,
|
||||||
|
usage)) {
|
||||||
|
GST_CAT_ERROR (GST_CAT_VULKAN_IMAGE_MEMORY, "Incorrect image parameters");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _vk_image_mem_new_alloc_with_image_info (allocator, parent, device,
|
||||||
|
&image_info, mem_prop_flags, user_data, notify);
|
||||||
|
}
|
||||||
|
|
||||||
static GstVulkanImageMemory *
|
static GstVulkanImageMemory *
|
||||||
_vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
_vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
||||||
GstVulkanDevice * device, VkImage image, VkFormat format, gsize width,
|
GstVulkanDevice * device, VkImage image, VkFormat format, gsize width,
|
||||||
|
@ -417,6 +446,31 @@ _vk_image_mem_free (GstAllocator * allocator, GstMemory * memory)
|
||||||
g_free (mem);
|
g_free (mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_vulkan_image_memory_alloc_with_image_info:
|
||||||
|
* @device: a #GstVulkanDevice
|
||||||
|
* @image_info: VkImageCreateInfo structure
|
||||||
|
* @mem_prop_flags: VkMemoryPropertyFlags flags
|
||||||
|
*
|
||||||
|
* Returns: a #GstMemory object backed by a vulkan device memory
|
||||||
|
*
|
||||||
|
* Since: 1.24
|
||||||
|
*/
|
||||||
|
GstMemory *
|
||||||
|
gst_vulkan_image_memory_alloc_with_image_info (GstVulkanDevice * device,
|
||||||
|
VkImageCreateInfo * image_info, VkMemoryPropertyFlags mem_prop_flags)
|
||||||
|
{
|
||||||
|
GstVulkanImageMemory *mem;
|
||||||
|
|
||||||
|
g_return_val_if_fail (image_info
|
||||||
|
&& image_info->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, NULL);
|
||||||
|
|
||||||
|
mem = _vk_image_mem_new_alloc_with_image_info (_vulkan_image_memory_allocator,
|
||||||
|
NULL, device, image_info, mem_prop_flags, NULL, NULL);
|
||||||
|
|
||||||
|
return (GstMemory *) mem;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_vulkan_image_memory_alloc:
|
* gst_vulkan_image_memory_alloc:
|
||||||
* @device: a #GstVulkanDevice
|
* @device: a #GstVulkanDevice
|
||||||
|
|
|
@ -175,6 +175,13 @@ gboolean gst_vulkan_image_memory_init (GstVulkanImageMemory *
|
||||||
gsize size,
|
gsize size,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GDestroyNotify notify);
|
GDestroyNotify notify);
|
||||||
|
|
||||||
|
GST_VULKAN_API
|
||||||
|
GstMemory * gst_vulkan_image_memory_alloc_with_image_info
|
||||||
|
(GstVulkanDevice * device,
|
||||||
|
VkImageCreateInfo * image_info,
|
||||||
|
VkMemoryPropertyFlags mem_prop_flags);
|
||||||
|
|
||||||
GST_VULKAN_API
|
GST_VULKAN_API
|
||||||
GstMemory * gst_vulkan_image_memory_alloc (GstVulkanDevice * device,
|
GstMemory * gst_vulkan_image_memory_alloc (GstVulkanDevice * device,
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
|
|
Loading…
Reference in a new issue