PR #22606 opened by Stephane Cerveau (dabrain34)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22606
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22606.patch

Check that the driver supports both BUFFER_OFFSET and BYTES_WRITTEN
encode feedback flags before creating the query pool, failing with
EINVAL if either is missing.

Set these flags explicitly instead of masking off HAS_OVERRIDES with a
bitwise NOT, which could pass unrecognized bits from newer drivers to
vkCreateQueryPool causing validation errors and
crashes.


>From 59ed421c58f88f53e317b0a14d22ee6eca199525 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= <[email protected]>
Date: Tue, 24 Mar 2026 15:41:30 +0100
Subject: [PATCH] vulkan: fix encode feedback query handling

Check that the driver supports both BUFFER_OFFSET and BYTES_WRITTEN
encode feedback flags before creating the query pool, failing with
EINVAL if either is missing.

Set these flags explicitly instead of masking off HAS_OVERRIDES with a
bitwise NOT, which could pass unrecognized bits from newer drivers to
vkCreateQueryPool causing validation errors and
crashes.
---
 libavcodec/vulkan_encode.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vulkan_encode.c b/libavcodec/vulkan_encode.c
index a440646e4f..112ea2272d 100644
--- a/libavcodec/vulkan_encode.c
+++ b/libavcodec/vulkan_encode.c
@@ -751,6 +751,9 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, 
FFVulkanEncodeContext *
 
     VkVideoFormatPropertiesKHR *ret_info;
     uint32_t nb_out_fmts = 0;
+    uint32_t feedback_flags =
+      VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BUFFER_OFFSET_BIT_KHR |
+      VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_BYTES_WRITTEN_BIT_KHR;
 
     VkPhysicalDeviceVideoEncodeQualityLevelInfoKHR quality_info;
 
@@ -770,6 +773,14 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, 
FFVulkanEncodeContext *
         return AVERROR(EINVAL);
     }
 
+    if ((ctx->enc_caps.supportedEncodeFeedbackFlags & feedback_flags) !=
+        feedback_flags) {
+        av_log (avctx, AV_LOG_ERROR,
+            "Driver does not support required encode feedback flags "
+            "(BUFFER_OFFSET and BYTES_WRITTEN)");
+        return AVERROR(EINVAL);
+    }
+
     ctx->base.op = &vulkan_base_encode_ops;
     ctx->codec = codec;
 
@@ -879,8 +890,7 @@ av_cold int ff_vulkan_encode_init(AVCodecContext *avctx, 
FFVulkanEncodeContext *
     query_create = (VkQueryPoolVideoEncodeFeedbackCreateInfoKHR) {
         .sType = 
VK_STRUCTURE_TYPE_QUERY_POOL_VIDEO_ENCODE_FEEDBACK_CREATE_INFO_KHR,
         .pNext = &ctx->profile,
-        .encodeFeedbackFlags = ctx->enc_caps.supportedEncodeFeedbackFlags &
-                               
(~VK_VIDEO_ENCODE_FEEDBACK_BITSTREAM_HAS_OVERRIDES_BIT_KHR),
+        .encodeFeedbackFlags = feedback_flags,
     };
     err = ff_vk_exec_pool_init(s, ctx->qf_enc, &ctx->enc_pool, 
base_ctx->async_depth,
                                1, VK_QUERY_TYPE_VIDEO_ENCODE_FEEDBACK_KHR, 0,
-- 
2.52.0

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

Reply via email to