vulkan: fine grained access to API

This patch is the payment to my technical debt.

The symbol GST_VULKAN_HAVE_VIDEO_EXTENSIONS is defined at compilation-time if
the user requests for the usage of the Vulkan Video extensions. And we used this
symbol for anything related with Vulkan Video. But this is not the smartest
approach.

The rule should be:

- If the code allocates Vulkan Video resources, use
  GST_VULKAN_HAVE_VIDEO_EXTENSIONS

- Otherwise, use the Vulkan's guard for the used API

In this way, API version bumps will be easier.

Also, this commit marks the end of GST_VULKAN_HAVE_VIDEO_EXTENSIONS guarded code
for readability.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9492>
This commit is contained in:
Víctor Manuel Jáquez Leal 2025-07-31 13:48:10 +02:00 committed by GStreamer Marge Bot
parent 92e2c5b29d
commit c84982b5c9
5 changed files with 26 additions and 19 deletions

View File

@ -109,7 +109,7 @@ plugin_init (GstPlugin * plugin)
VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME)) {
ret |= gst_vulkan_h264_encoder_register (plugin, device, GST_RANK_NONE);
}
#endif
#endif /* GST_VULKAN_HAVE_VIDEO_EXTENSIONS */
ret |= gst_vulkan_sink_register (plugin, device, GST_RANK_NONE);
gst_object_unref (device);
}

View File

@ -109,8 +109,10 @@ static const struct
#if VK_HEADER_VERSION >= 70
{VK_QUEUE_PROTECTED_BIT, "protected"},
#endif
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
#if defined(VK_KHR_video_decode_queue)
{VK_QUEUE_VIDEO_DECODE_BIT_KHR, "decode"},
#endif
#if defined(VK_KHR_video_encode_queue)
{VK_QUEUE_VIDEO_ENCODE_BIT_KHR, "encode"}
#endif
};

View File

@ -23,7 +23,6 @@
#endif
#include "gstvkdevice.h"
#include "gstvkdebug.h"
#include "gstvkphysicaldevice-private.h"
#include <string.h>
@ -463,10 +462,6 @@ gst_vulkan_device_choose_queues (GstVulkanDevice * device)
GArray *array;
guint32 *family_scores, n_queue_families;
int graph_index, comp_index, tx_index;
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
int dec_index = -1;
int enc_index = -1;
#endif
n_queue_families = device->physical_device->n_queue_families;
queue_family_props = device->physical_device->queue_family_props;
@ -486,13 +481,21 @@ gst_vulkan_device_choose_queues (GstVulkanDevice * device)
VK_QUEUE_TRANSFER_BIT, family_scores);
array = _append_queue_create_info (array, tx_index, queue_family_props);
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
dec_index = _pick_queue_family (queue_family_props, n_queue_families,
VK_QUEUE_VIDEO_DECODE_BIT_KHR, family_scores);
array = _append_queue_create_info (array, dec_index, queue_family_props);
enc_index = _pick_queue_family (queue_family_props, n_queue_families,
VK_QUEUE_VIDEO_ENCODE_BIT_KHR, family_scores);
array = _append_queue_create_info (array, enc_index, queue_family_props);
#endif
# if defined(VK_KHR_video_decode_queue)
{
int dec_index = _pick_queue_family (queue_family_props, n_queue_families,
VK_QUEUE_VIDEO_DECODE_BIT_KHR, family_scores);
array = _append_queue_create_info (array, dec_index, queue_family_props);
}
# endif
# if defined(VK_KHR_video_encode_queue)
{
int enc_index = _pick_queue_family (queue_family_props, n_queue_families,
VK_QUEUE_VIDEO_ENCODE_BIT_KHR, family_scores);
array = _append_queue_create_info (array, enc_index, queue_family_props);
}
# endif
#endif /* GST_VULKAN_HAVE_VIDEO_EXTENSIONS */
g_free (family_scores);

View File

@ -540,11 +540,13 @@ _get_usage (guint64 feature)
{VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT, VK_IMAGE_USAGE_STORAGE_BIT},
{VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT},
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
#if defined(VK_KHR_video_decode_queue)
{VK_FORMAT_FEATURE_2_VIDEO_DECODE_OUTPUT_BIT_KHR,
VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR},
{VK_FORMAT_FEATURE_2_VIDEO_DECODE_DPB_BIT_KHR,
VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR},
#endif
#if defined(VK_KHR_video_encode_queue)
{VK_FORMAT_FEATURE_2_VIDEO_ENCODE_DPB_BIT_KHR,
VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR},
{VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR,

View File

@ -1079,7 +1079,7 @@ gst_vulkan_physical_device_fill_info (GstVulkanPhysicalDevice * device,
VkQueueFamilyProperties2 *props;
int i;
void *next = NULL;
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
#if defined(VK_KHR_video_queue)
VkQueueFamilyVideoPropertiesKHR *queue_family_video_props;
VkQueueFamilyQueryResultStatusPropertiesKHR *queue_family_query_props;
@ -1091,7 +1091,7 @@ gst_vulkan_physical_device_fill_info (GstVulkanPhysicalDevice * device,
#endif
props = g_new0 (VkQueueFamilyProperties2, device->n_queue_families);
for (i = 0; i < device->n_queue_families; i++) {
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
#if defined(VK_KHR_video_queue)
queue_family_query_props[i].sType =
VK_STRUCTURE_TYPE_QUEUE_FAMILY_QUERY_RESULT_STATUS_PROPERTIES_KHR;
@ -1115,7 +1115,7 @@ gst_vulkan_physical_device_fill_info (GstVulkanPhysicalDevice * device,
memcpy (&device->queue_family_props[i], &props[i].queueFamilyProperties,
sizeof (device->queue_family_props[i]));
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
#if defined(VK_KHR_video_queue)
device->queue_family_ops[i].video =
queue_family_video_props[i].videoCodecOperations;
device->queue_family_ops[i].query_result_status =
@ -1123,7 +1123,7 @@ gst_vulkan_physical_device_fill_info (GstVulkanPhysicalDevice * device,
#endif
}
g_free (props);
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
#if defined(VK_KHR_video_queue)
g_free (queue_family_video_props);
g_free (queue_family_query_props);
#endif