test: look for proper queue among multiple physical device

There might be multiple GPUs in a system and only one might provided vulkan
video extensions. Now, in order to run the tests, the proper GPU is looked.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4850>
This commit is contained in:
Stéphane Cerveau 2023-06-15 12:09:01 +02:00 committed by GStreamer Marge Bot
parent 221811119a
commit 23a144dcec

View file

@ -30,17 +30,27 @@ static GstVulkanInstance *instance;
static GstVulkanDevice *device;
static GstVulkanQueue *queue = NULL;
static void
setup (void)
{
instance = gst_vulkan_instance_new ();
fail_unless (gst_vulkan_instance_open (instance, NULL));
}
static void
teardown (void)
{
gst_clear_object (&queue);
gst_clear_object (&device);
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 = VK_QUEUE_COMPUTE_BIT;
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
if (data)
expected_flags = VK_QUEUE_VIDEO_DECODE_BIT_KHR;
#endif
guint expected_flags = GPOINTER_TO_UINT (data);
if ((flags & expected_flags) != 0) {
gst_object_replace ((GstObject **) & queue, GST_OBJECT_CAST (_queue));
@ -51,23 +61,23 @@ _choose_queue (GstVulkanDevice * device, GstVulkanQueue * _queue, gpointer data)
}
static void
setup (void)
setup_queue (guint expected_flags)
{
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));
int i;
gst_vulkan_device_foreach_queue (device, _choose_queue, NULL);
fail_unless (GST_IS_VULKAN_QUEUE (queue));
}
static void
teardown (void)
{
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);
gst_object_unref (instance);
}
fail_unless (GST_IS_VULKAN_QUEUE (queue));
}
static GstBufferPool *
@ -108,6 +118,7 @@ GST_START_TEST (test_image)
GstFlowReturn ret;
GstBuffer *buffer = NULL;
setup_queue (VK_QUEUE_COMPUTE_BIT);
pool = create_buffer_pool ("NV12", 0, NULL);
ret = gst_buffer_pool_acquire_buffer (pool, &buffer, NULL);
@ -182,18 +193,7 @@ GST_START_TEST (test_decoding_image)
/* *INDENT-ON* */
/* force to use a queue with decoding support */
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) {
gst_vulkan_device_foreach_queue (device, _choose_queue,
GUINT_TO_POINTER (1));
}
if (!queue)
return;
setup_queue (VK_QUEUE_VIDEO_DECODE_BIT_KHR);
if ((device->physical_device->queue_family_ops[queue->family].video
& VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) == 0)
return;