vulkan: use gst_vulkan_device_select_queue

Use gst_vulkan_device_select_queue api to retrieve a valid queue
in vkupload, vkdownload, vkimagebufferpool, and vkvideofilter

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5656>
This commit is contained in:
Stéphane Cerveau 2023-06-30 18:00:38 +02:00 committed by GStreamer Marge Bot
parent 74c6298eb7
commit 159f24c07f
5 changed files with 29 additions and 150 deletions

View file

@ -544,37 +544,6 @@ struct choose_data
GstVulkanQueue *queue;
};
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
struct choose_data *data)
{
guint flags =
device->physical_device->queue_family_props[queue->family].queueFlags;
if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
if (data->queue)
gst_object_unref (data->queue);
data->queue = gst_object_ref (queue);
return FALSE;
}
return TRUE;
}
static GstVulkanQueue *
_find_graphics_queue (GstVulkanDownload * download)
{
struct choose_data data;
data.download = download;
data.queue = NULL;
gst_vulkan_device_foreach_queue (download->device,
(GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
return data.queue;
}
static GstStateChangeReturn
gst_vulkan_download_change_state (GstElement * element,
GstStateChange transition)
@ -615,7 +584,9 @@ gst_vulkan_download_change_state (GstElement * element,
if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (vk_download),
&vk_download->queue)) {
GST_DEBUG_OBJECT (vk_download, "No queue retrieved from peer elements");
vk_download->queue = _find_graphics_queue (vk_download);
vk_download->queue =
gst_vulkan_device_select_queue (vk_download->device,
VK_QUEUE_GRAPHICS_BIT);
}
if (!vk_download->queue) {
GST_ELEMENT_ERROR (vk_download, RESOURCE, NOT_FOUND,

View file

@ -1221,43 +1221,6 @@ gst_vulkan_upload_set_context (GstElement * element, GstContext * context)
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
}
struct choose_data
{
GstVulkanUpload *upload;
GstVulkanQueue *queue;
};
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
struct choose_data *data)
{
guint flags =
device->physical_device->queue_family_props[queue->family].queueFlags;
if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
if (data->queue)
gst_object_unref (data->queue);
data->queue = gst_object_ref (queue);
return FALSE;
}
return TRUE;
}
static GstVulkanQueue *
_find_graphics_queue (GstVulkanUpload * upload)
{
struct choose_data data;
data.upload = upload;
data.queue = NULL;
gst_vulkan_device_foreach_queue (upload->device,
(GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
return data.queue;
}
static GstStateChangeReturn
gst_vulkan_upload_change_state (GstElement * element, GstStateChange transition)
{
@ -1295,7 +1258,9 @@ gst_vulkan_upload_change_state (GstElement * element, GstStateChange transition)
if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (vk_upload),
&vk_upload->queue)) {
GST_DEBUG_OBJECT (vk_upload, "No queue retrieved from peer elements");
vk_upload->queue = _find_graphics_queue (vk_upload);
vk_upload->queue =
gst_vulkan_device_select_queue (vk_upload->device,
VK_QUEUE_GRAPHICS_BIT);
}
if (!vk_upload->queue) {
GST_ELEMENT_ERROR (vk_upload, RESOURCE, NOT_FOUND,

View file

@ -318,24 +318,6 @@ image_failed:
}
}
#if defined(VK_KHR_synchronization2)
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * _queue,
gpointer user_data)
{
GstVulkanQueue **queue = user_data;
guint flags =
device->physical_device->queue_family_props[_queue->family].queueFlags;
if ((flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT)) != 0) {
*queue = gst_object_ref (_queue);
return FALSE;
}
return TRUE;
}
#endif
static gboolean
prepare_buffer (GstVulkanImageBufferPool * vk_pool, GstBuffer * buffer)
{
@ -350,7 +332,9 @@ prepare_buffer (GstVulkanImageBufferPool * vk_pool, GstBuffer * buffer)
GstVulkanCommandPool *cmd_pool;
GstVulkanQueue *queue = NULL;
gst_vulkan_device_foreach_queue (vk_pool->device, _choose_queue, &queue);
queue =
gst_vulkan_device_select_queue (vk_pool->device,
VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT);
if (!queue)
return FALSE;
cmd_pool = gst_vulkan_queue_create_command_pool (queue, &error);

View file

@ -165,37 +165,6 @@ struct choose_data
GstVulkanQueue *queue;
};
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
struct choose_data *data)
{
guint flags =
device->physical_device->queue_family_props[queue->family].queueFlags;
if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
if (data->queue)
gst_object_unref (data->queue);
data->queue = gst_object_ref (queue);
return FALSE;
}
return TRUE;
}
static GstVulkanQueue *
_find_graphics_queue (GstVulkanVideoFilter * filter)
{
struct choose_data data;
data.filter = filter;
data.queue = NULL;
gst_vulkan_device_foreach_queue (filter->device,
(GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
return data.queue;
}
static GstCaps *
gst_vulkan_video_filter_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
@ -318,7 +287,8 @@ gst_vulkan_video_filter_start (GstBaseTransform * bt)
if (!gst_vulkan_queue_run_context_query (GST_ELEMENT (render),
&render->queue)) {
GST_DEBUG_OBJECT (render, "No queue retrieved from peer elements");
render->queue = _find_graphics_queue (render);
render->queue =
gst_vulkan_device_select_queue (render->device, VK_QUEUE_GRAPHICS_BIT);
}
if (!render->queue)
return FALSE;

View file

@ -35,6 +35,11 @@ setup (void)
{
instance = gst_vulkan_instance_new ();
fail_unless (gst_vulkan_instance_open (instance, NULL));
device = gst_vulkan_device_new_with_index (instance, 0);
fail_unless (gst_vulkan_device_open (device, NULL));
queue = gst_vulkan_device_select_queue (device, VK_QUEUE_COMPUTE_BIT);
}
static void
@ -45,37 +50,10 @@ teardown (void)
gst_object_unref (instance);
}
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * _queue, gpointer data)
{
guint flags =
device->physical_device->queue_family_props[_queue->family].queueFlags;
guint expected_flags = GPOINTER_TO_UINT (data);
if ((flags & expected_flags) != 0) {
gst_object_replace ((GstObject **) & queue, GST_OBJECT_CAST (_queue));
return FALSE;
}
return TRUE;
}
static void
setup_queue (guint expected_flags)
{
int i;
gst_clear_object (&queue);
for (i = 0; i < instance->n_physical_devices; i++) {
device = gst_vulkan_device_new_with_index (instance, i);
fail_unless (gst_vulkan_device_open (device, NULL));
gst_vulkan_device_foreach_queue (device, _choose_queue,
GUINT_TO_POINTER (expected_flags));
if (queue && GST_IS_VULKAN_QUEUE (queue))
break;
gst_object_unref (device);
}
queue = gst_vulkan_device_select_queue (device, VK_QUEUE_COMPUTE_BIT);
fail_unless (GST_IS_VULKAN_QUEUE (queue));
}
@ -193,7 +171,18 @@ GST_START_TEST (test_decoding_image)
/* *INDENT-ON* */
/* force to use a queue with decoding support */
setup_queue (VK_QUEUE_VIDEO_DECODE_BIT_KHR);
if (queue && (device->physical_device->queue_family_ops[queue->family].video
& VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) == 0)
gst_clear_object (&queue);
if (!queue) {
queue =
gst_vulkan_device_select_queue (device, VK_QUEUE_VIDEO_DECODE_BIT_KHR);
}
if (!queue)
return;
if ((device->physical_device->queue_family_ops[queue->family].video
& VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) == 0)
return;