From 64ba7fb2eb559f2be01e987600f3d7f6e1eff082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 4 Jan 2023 17:10:11 +0100 Subject: [PATCH] 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: --- .../gst-libs/gst/vulkan/gstvkimagememory.c | 86 +++++++++++++++---- .../gst-libs/gst/vulkan/gstvkimagememory.h | 7 ++ 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.c index e4d1af04ff..f264748de2 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.c @@ -188,29 +188,36 @@ gst_vulkan_image_memory_init (GstVulkanImageMemory * mem, } 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) +_vk_image_mem_new_alloc_with_image_info (GstAllocator * allocator, + GstMemory * parent, GstVulkanDevice * device, + VkImageCreateInfo * image_info, VkMemoryPropertyFlags mem_prop_flags, + gpointer user_data, GDestroyNotify notify) { GstVulkanImageMemory *mem = NULL; GstAllocationParams params = { 0, }; - VkImageCreateInfo image_info; VkPhysicalDevice gpu; GError *error = NULL; + GArray *qfi = NULL; guint32 type_idx; VkImage image; VkResult err; gpu = gst_vulkan_device_get_physical_device (device); - if (!_create_info_from_args (&image_info, format, width, height, tiling, - usage)) { - GST_CAT_ERROR (GST_CAT_VULKAN_IMAGE_MEMORY, "Incorrect image parameters"); - goto error; + + if (!image_info->pQueueFamilyIndices) { + /* XXX: overwrite the queue indices part of the structure */ + 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) goto vk_error; @@ -218,13 +225,16 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent, vkGetImageMemoryRequirements (device->device, image, &mem->requirements); - gst_vulkan_image_memory_init (mem, allocator, parent, device, usage, ¶ms, - mem->requirements.size, user_data, notify); - mem->create_info = image_info; + gst_vulkan_image_memory_init (mem, allocator, parent, device, + image_info->usage, ¶ms, mem->requirements.size, user_data, notify); + mem->create_info = *image_info; + /* XXX: to avoid handling pNext lifetime */ + mem->create_info.pNext = NULL; mem->image = image; - err = vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D, - tiling, usage, 0, &mem->format_properties); + err = vkGetPhysicalDeviceImageFormatProperties (gpu, image_info->format, + VK_IMAGE_TYPE_2D, image_info->tiling, image_info->usage, 0, + &mem->format_properties); if (gst_vulkan_error_to_g_error (err, &error, "vkGetPhysicalDeviceImageFormatProperties") < 0) 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 * _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent, GstVulkanDevice * device, VkImage image, VkFormat format, gsize width, @@ -417,6 +446,31 @@ _vk_image_mem_free (GstAllocator * allocator, GstMemory * memory) 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: * @device: a #GstVulkanDevice diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.h index ac4ba2f648..88ed48c5e5 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkimagememory.h @@ -175,6 +175,13 @@ gboolean gst_vulkan_image_memory_init (GstVulkanImageMemory * gsize size, gpointer user_data, 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 GstMemory * gst_vulkan_image_memory_alloc (GstVulkanDevice * device, VkFormat format,