PR #23752 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23752
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23752.patch

GetPhysicalDeviceImageFormatProperties2() must be queried with the format
that will actually be used to create the image, otherwise the external
memory export capability check answers for a different format than the one
being allocated.

When AV_VK_FRAME_FLAG_DISABLE_MULTIPLANE is set (e.g. by ffplay for CUDA
interop), vulkan_frames_init selects the per-plane fallback format via
vkfmt_from_pixfmt2(disable_multiplane=1) and stores it in hwctx->format[].
The image is then created with that fallback format. Querying the
multiplane vkf instead returns capability for a format that is never
instantiated, and on NVIDIA GPUs with OPTIMAL tiling the answer differs
between the two formats, producing broken CUDA hwaccel output.

Read hwctx->format[0], which is populated by vulkan_frames_init before
vulkan_pool_alloc runs, so the query matches the image regardless of
whether the multiplane or fallback path was taken.

Fix artifacts with `ffplay -hwaccel cuda foo.mp4`.

-------------------------------

`ffplay -hwaccel cuda` was broken since d5f4a55123393756c3a3e75cc8, but 
d5f4a55123393756c3a3e75cc8 isn't the root cause.


>From 9258bf9540635b524f548bb0eeac21aad36c0400 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <[email protected]>
Date: Thu, 9 Jul 2026 22:19:44 +0800
Subject: [PATCH] avutil/hwcontext_vulkan: query the actual image format in
 try_export_flags

GetPhysicalDeviceImageFormatProperties2() must be queried with the format
that will actually be used to create the image, otherwise the external
memory export capability check answers for a different format than the one
being allocated.

When AV_VK_FRAME_FLAG_DISABLE_MULTIPLANE is set (e.g. by ffplay for CUDA
interop), vulkan_frames_init selects the per-plane fallback format via
vkfmt_from_pixfmt2(disable_multiplane=1) and stores it in hwctx->format[].
The image is then created with that fallback format. Querying the
multiplane vkf instead returns capability for a format that is never
instantiated, and on NVIDIA GPUs with OPTIMAL tiling the answer differs
between the two formats, producing broken CUDA hwaccel output.

Read hwctx->format[0], which is populated by vulkan_frames_init before
vulkan_pool_alloc runs, so the query matches the image regardless of
whether the multiplane or fallback path was taken.

Fix artifacts with `ffplay -hwaccel cuda foo.mp4`.
---
 libavutil/hwcontext_vulkan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index fad35f9ad6..e6c6dcff7b 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2799,7 +2799,7 @@ static void try_export_flags(AVHWFramesContext *hwfc,
     VkPhysicalDeviceImageFormatInfo2 pinfo = {
         .sType  = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
         .pNext  = !exp ? NULL : &enext,
-        .format = vk_find_format_entry(hwfc->sw_format)->vkf,
+        .format = hwctx->format[0],
         .type   = VK_IMAGE_TYPE_2D,
         .tiling = hwctx->tiling,
         .usage  = hwctx->usage,
-- 
2.52.0

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

Reply via email to