vkdevice: select queue with expected flags

Allow to select a queue with the given flags
such as compute bit etc from a given device.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5656>
This commit is contained in:
Stéphane Cerveau 2023-06-28 18:15:59 +02:00 committed by GStreamer Marge Bot
parent 0004a52866
commit 74c6298eb7
4 changed files with 78 additions and 1 deletions

View file

@ -1866,6 +1866,25 @@ only have an effect before the call to gst_vulkan_device_open().</doc>
</instance-parameter>
</parameters>
</method>
<method name="select_queue" c:identifier="gst_vulkan_device_select_queue" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c">Select a compatible queue from the @device supporting the @expected_flags.</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.h"/>
<return-value transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c">a #GstVulkanQueue for @queue matching the
@expected_flags</doc>
<type name="VulkanQueue" c:type="GstVulkanQueue*"/>
</return-value>
<parameters>
<instance-parameter name="device" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c">a #GstVulkanDevice</doc>
<type name="VulkanDevice" c:type="GstVulkanDevice*"/>
</instance-parameter>
<parameter name="expected_flags" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkdevice.c">a VkQueueFlagBits</doc>
<type name="Vulkan.QueueFlagBits" c:type="VkQueueFlagBits"/>
</parameter>
</parameters>
</method>
<property name="instance" transfer-ownership="none">
<type name="VulkanInstance"/>
</property>

View file

@ -1070,3 +1070,58 @@ gst_vulkan_device_enable_layer (GstVulkanDevice * device, const gchar * name)
return ret;
}
struct choose_queue
{
guint expected_flags;
GstVulkanQueue *queue;
};
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
struct choose_queue *data)
{
guint flags =
device->physical_device->queue_family_props[queue->family].queueFlags;
if ((flags & data->expected_flags) != 0) {
if (data->queue)
gst_object_unref (data->queue);
data->queue = gst_object_ref (queue);
return FALSE;
}
return TRUE;
}
/**
* gst_vulkan_device_select_queue
* @device: a #GstVulkanDevice
* @expected_flags: a VkQueueFlagBits
*
* Select a compatible queue from the @device supporting the @expected_flags.
*
* Returns: (transfer full): a #GstVulkanQueue for @queue matching the
* @expected_flags
*
* Since: 1.24
*/
GstVulkanQueue *
gst_vulkan_device_select_queue (GstVulkanDevice * device,
VkQueueFlagBits expected_flags)
{
struct choose_queue data;
data.expected_flags = expected_flags;
data.queue = NULL;
if (!gst_vulkan_device_open (device, NULL)) {
gst_object_unref (device);
goto beach;
}
gst_vulkan_device_foreach_queue (device,
(GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
beach:
return data.queue;
}

View file

@ -147,6 +147,10 @@ GST_VULKAN_API
GstVulkanFence * gst_vulkan_device_create_fence (GstVulkanDevice * device,
GError ** error);
GST_VULKAN_API
GstVulkanQueue * gst_vulkan_device_select_queue (GstVulkanDevice * device,
VkQueueFlagBits expected_flags);
G_END_DECLS
#endif /* __GST_VULKAN_DEVICE_H__ */

View file

@ -59,7 +59,6 @@ GST_VULKAN_API
GstVulkanImageView * gst_vulkan_get_or_create_image_view_with_info (GstVulkanImageMemory * image,
VkImageViewCreateInfo * create_info);
GST_VULKAN_API
GstVulkanHandle * gst_vulkan_create_shader (GstVulkanDevice * device,
const gchar * code,