From 7b62c26139650529d32b80fe45cdb8c0d40700b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Tue, 28 Mar 2023 15:31:19 +0200 Subject: [PATCH] vkdevice: add gst_vulkan_device_queue_family_indices() This method will return a GArray with all the queue family indices created by the device when it's opened. This array will be used by VkImageCreateInfo to allocate a new Vulkan image. Part-of: --- .../gst-libs/gst/vulkan/gstvkdevice.c | 51 +++++++++++++++++++ .../gst-libs/gst/vulkan/gstvkdevice.h | 3 ++ 2 files changed, 54 insertions(+) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c index ae1dbc1cdd..4fb4f97442 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c @@ -60,6 +60,7 @@ struct _GstVulkanDevicePrivate gboolean opened; GArray *queues; + GArray *queue_family_indices; GstVulkanFenceCache *fence_cache; }; @@ -214,6 +215,11 @@ gst_vulkan_device_dispose (GObject * object) GstVulkanDevice *device = GST_VULKAN_DEVICE (object); GstVulkanDevicePrivate *priv = GET_PRIV (device); + if (priv->queue_family_indices) { + g_array_unref (priv->queue_family_indices); + priv->queue_family_indices = NULL; + } + if (priv->queues) { g_array_unref (priv->queues); priv->queues = NULL; @@ -556,6 +562,51 @@ gst_vulkan_device_foreach_queue (GstVulkanDevice * device, } } +/** + * gst_vulkan_device_queue_family_indices: + * @device: a #GstVulkanDevice + * + * Returns: (element-type uint32_t) (transfer full): An array with the family + * indexes of the created queues in @device + * + * Since: 1.24 + */ +GArray * +gst_vulkan_device_queue_family_indices (GstVulkanDevice * device) +{ + GstVulkanDevicePrivate *priv = GET_PRIV (device); + guint i, j; + + g_return_val_if_fail (GST_IS_VULKAN_DEVICE (device), NULL); + g_return_val_if_fail (priv->opened, NULL); + + GST_OBJECT_LOCK (device); + + if (priv->queue_family_indices) + goto beach; + + priv->queue_family_indices = + g_array_sized_new (FALSE, FALSE, sizeof (uint32_t), priv->queues->len); + + for (i = 0; i < priv->queues->len; i++) { + VkDeviceQueueCreateInfo *qi = + &g_array_index (priv->queues, VkDeviceQueueCreateInfo, i); + + for (j = 0; j < priv->queue_family_indices->len; j++) { + uint32_t qfi = g_array_index (priv->queue_family_indices, uint32_t, j); + if (qfi == qi->queueFamilyIndex) + break; + } + + if (j == priv->queue_family_indices->len) + g_array_append_val (priv->queue_family_indices, qi->queueFamilyIndex); + } + +beach: + GST_OBJECT_UNLOCK (device); + return g_array_ref (priv->queue_family_indices); +} + /** * gst_vulkan_device_get_proc_address: * @device: a #GstVulkanDevice diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.h b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.h index e486685690..6a84ec69ca 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.h @@ -123,6 +123,9 @@ GST_VULKAN_API GstVulkanQueue * gst_vulkan_device_get_queue (GstVulkanDevice * device, guint32 queue_family, guint32 queue_i); +GST_VULKAN_API +GArray * gst_vulkan_device_queue_family_indices (GstVulkanDevice * device); + GST_VULKAN_API VkPhysicalDevice gst_vulkan_device_get_physical_device (GstVulkanDevice * device);