PR #25947 opened by t-boiko
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25947
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25947.patch

Vulkan decode initialization currently requires VIDEO_ENCODE_SRC when the 
device exposes video encoding. This rejects valid decode-only formats, 
including 12-bit VP9 and HEVC on NVIDIA hardware, causing FFmpeg to fall back 
to software decoding.

Query formats without requiring encode usage, retain the selected format’s 
advertised usage flags, and add VIDEO_ENCODE_SRC to frame parameters only when 
supported and the required extensions are enabled. This preserves supported 
transcoding paths, including DRM modifier frame pools.

Validation on NVIDIA Blackwell:
- VP9 and HEVC 12-bit: three runs of 64 frames each, with Vulkan output hashes 
matching software decoding.
- VP9 8/10/12-bit: optimal and DRM modifier decode paths verified.
- H.264/HEVC transcoding: expected output counts.


From b3b1490628f31294648948ba0198d88a1bb176e5 Mon Sep 17 00:00:00 2001
From: Tymur Boiko <[email protected]>
Date: Thu, 5 Nov 2026 17:24:51 +0100
Subject: [PATCH] avcodec/vulkan_decode: make encode usage optional for
 decoding

Requiring VIDEO_ENCODE_SRC in decode format queries rejects valid
decode-only formats, such as 12-bit VP9 on NVIDIA Blackwell GPU,
and causes hardware initialization to fail.

Query formats without requiring encode usage, then retain the selected
format's advertised usage flags. Add VIDEO_ENCODE_SRC to the frame
parameters only when advertised and the required extensions are enabled.
This preserves supported transcoding paths, including DRM modifier frame
pools that skip automatic usage additions, while allowing decode-only
formats to initialize.

Tested 8/10-bit DRM transcoding and 12-bit decoding on NVIDIA Blackwell
GPU, with normal, filter, H.264, HEVC and VP9 pipeline checks.

Signed-off-by: Tymur Boiko <[email protected]>
---
 libavcodec/vulkan_decode.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 5cf338b0d35..c594571f1ea 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -827,7 +827,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx,
 static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef 
*frames_ref,
                                      enum AVPixelFormat *pix_fmt, VkFormat 
*vk_fmt,
                                      FFVulkanDecodeProfileData *prof,
-                                     int *dpb_dedicate)
+                                     int *dpb_dedicate, VkImageUsageFlags 
*supported_usage)
 {
     VkResult ret;
     int max_level, base_profile, cur_profile;
@@ -1030,10 +1030,6 @@ static int vulkan_decode_get_profile(AVCodecContext 
*avctx, AVBufferRef *frames_
                               VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR |
                               VK_IMAGE_USAGE_TRANSFER_SRC_BIT         |
                               VK_IMAGE_USAGE_SAMPLED_BIT;
-
-        if ((ctx->s.extensions & FF_VK_EXT_VIDEO_ENCODE_QUEUE) &&
-            (ctx->s.extensions & FF_VK_EXT_VIDEO_MAINTENANCE_1))
-            fmt_info.imageUsage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
     }
 
     /* Get the format of the images necessary */
@@ -1084,8 +1080,10 @@ static int vulkan_decode_get_profile(AVCodecContext 
*avctx, AVBufferRef *frames_
         }
 
         best_format = av_find_best_pix_fmt_of_2(tmp, best_format, 
source_format, 0, NULL);
-        if (tmp == best_format)
+        if (tmp == best_format) {
             best_vkfmt = ret_info[i].format;
+            *supported_usage = ret_info[i].imageUsageFlags;
+        }
 
         av_log(avctx, AV_LOG_DEBUG, "    %s%s (Vulkan ID: %i)\n",
                av_get_pix_fmt_name(tmp), tmp == best_format ? "*" : "",
@@ -1118,6 +1116,7 @@ static void free_profile_data(AVHWFramesContext *hwfc)
 int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
 {
     int err, dedicated_dpb;
+    VkImageUsageFlags supported_usage = 0;
     AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
     AVVulkanFramesContext *hwfc = frames_ctx->hwctx;
     FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
@@ -1140,7 +1139,7 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef 
*hw_frames_ctx)
         err = vulkan_decode_get_profile(avctx, hw_frames_ctx,
                                         &frames_ctx->sw_format,
                                         &hwfc->format[0],
-                                        prof, &dedicated_dpb);
+                                        prof, &dedicated_dpb, 
&supported_usage);
         if (err < 0) {
             av_free(prof);
             return err;
@@ -1209,9 +1208,10 @@ int ff_vk_frame_params(AVCodecContext *avctx, 
AVBufferRef *hw_frames_ctx)
             hwfc->usage |= VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
 
         ctx = dec->shared_ctx;
+        /* Preserve supported encode usage before callers select DRM 
modifiers. */
         if ((ctx->s.extensions & FF_VK_EXT_VIDEO_ENCODE_QUEUE) &&
             (ctx->s.extensions & FF_VK_EXT_VIDEO_MAINTENANCE_1))
-            hwfc->usage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
+            hwfc->usage |= supported_usage & 
VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
     }
 
     return err;
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to