[FFmpeg-cvslog] vulkan_decode: port to the new queue family API

Lynne git at videolan.org
Sun Aug 11 06:21:29 EEST 2024


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Sun Aug 11 03:27:46 2024 +0200| [680d969a305c0927480573a1b455024088b51aeb] | committer: Lynne

vulkan_decode: port to the new queue family API

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=680d969a305c0927480573a1b455024088b51aeb
---

 libavcodec/vulkan_decode.c | 18 +++++++++---------
 libavcodec/vulkan_video.c  | 14 ++++++++++++++
 libavcodec/vulkan_video.h  |  5 +++++
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index e6e14778cb..b89bfa17f2 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -1118,7 +1118,7 @@ int ff_vk_decode_uninit(AVCodecContext *avctx)
 
 int ff_vk_decode_init(AVCodecContext *avctx)
 {
-    int err, qf, cxpos = 0, cypos = 0, nb_q = 0;
+    int err, cxpos = 0, cypos = 0, nb_q = 0;
     VkResult ret;
     FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
     FFVulkanDecodeShared *ctx;
@@ -1183,18 +1183,18 @@ int ff_vk_decode_init(AVCodecContext *avctx)
         goto fail;
 
     /* Create queue context */
-    qf = ff_vk_qf_init(s, &ctx->qf, VK_QUEUE_VIDEO_DECODE_BIT_KHR);
-
     vk_desc = get_codecdesc(avctx->codec_id);
-    /* Check for support */
-    if (!(s->video_props[qf].videoCodecOperations & vk_desc->decode_op)) {
-        av_log(avctx, AV_LOG_ERROR, "Decoding %s not supported on the given "
-               "queue family %i!\n", avcodec_get_name(avctx->codec_id), qf);
-        return AVERROR(EINVAL);
+    err = ff_vk_video_qf_init(s, &ctx->qf,
+                              VK_QUEUE_VIDEO_DECODE_BIT_KHR,
+                              vk_desc->decode_op);
+    if (err < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Decoding of %s is not supported by this device\n",
+               avcodec_get_name(avctx->codec_id));
+        return err;
     }
 
     /* Enable queries if supported */
-    if (s->query_props[qf].queryResultStatusSupport)
+    if (s->query_props[ctx->qf.queue_family].queryResultStatusSupport)
         nb_q = 1;
 
     session_create.flags = 0x0;
diff --git a/libavcodec/vulkan_video.c b/libavcodec/vulkan_video.c
index f2a15d392e..b9a0ed5022 100644
--- a/libavcodec/vulkan_video.c
+++ b/libavcodec/vulkan_video.c
@@ -177,6 +177,20 @@ int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level)
     }
 }
 
+int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
+                        VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps)
+{
+    for (int i = 0; i < s->hwctx->nb_qf; i++) {
+        if ((s->hwctx->qf[i].flags & family) &&
+            (s->hwctx->qf[i].video_caps & caps)) {
+            qf->queue_family = s->hwctx->qf[i].idx;
+            qf->nb_queues = s->hwctx->qf[i].num;
+            return 0;
+        }
+    }
+    return AVERROR(ENOTSUP);
+}
+
 av_cold void ff_vk_video_common_uninit(FFVulkanContext *s,
                                        FFVkVideoCommon *common)
 {
diff --git a/libavcodec/vulkan_video.h b/libavcodec/vulkan_video.h
index 1894f1f1b7..2cb9419fd8 100644
--- a/libavcodec/vulkan_video.h
+++ b/libavcodec/vulkan_video.h
@@ -54,6 +54,11 @@ VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFm
  */
 VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
 
+/**
+ * Chooses a QF and loads it into a context.
+ */
+int ff_vk_video_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
+                        VkQueueFlagBits family, VkVideoCodecOperationFlagBitsKHR caps);
 
 /**
  * Convert level from Vulkan to AV.



More information about the ffmpeg-cvslog mailing list