Commit 90db7c053a for ffmpeg
commit 90db7c053af87dc75ea606583603dd5206eab745
Author: Lynne <dev@lynne.ee>
Date: Sat Dec 5 16:13:04 2026 +0800
avutil/hwcontext_vulkan: only host copy images created with host transfer usage
The host copy path was chosen from the frames context's usage, but
images imported from DRM are created without it, and so can images
supplied by the user. Downloading VAAPI frames mapped to Vulkan crashed
in ANV as a result.
Keep the usage our own images were created with, and only use host
copies when it includes host transfers.
Fixes: #26019
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 2c9a9cfcfb..d8464e2436 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -225,6 +225,9 @@ typedef struct AVVkFrameInternal {
* re-signaled each time via a submit in vulkan_map_to_drm. */
VkSemaphore drm_sync_sem;
+ /* Usage the images were created with, imports can differ from the context */
+ VkImageUsageFlags usage;
+
#if CONFIG_CUDA
/* Importing external memory into cuda is really expensive so we keep the
* memory imported all the time */
@@ -2818,6 +2821,7 @@ static int create_frame(AVHWFramesContext *hwfc, AVVkFrame **frame,
av_log(ctx, AV_LOG_ERROR, "Unable to allocate memory for AVVkFrame!\n");
return AVERROR(ENOMEM);
}
+ f->internal->usage = usage;
// TODO: check width and height for alignment in case of multiplanar (must be mod-2 if subsampled)
@@ -3743,6 +3747,7 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
goto fail;
}
+ f->internal->usage = create_info.usage;
f->queue_family[i] = VK_QUEUE_FAMILY_EXTERNAL;
f->layout[i] = create_info.initialLayout;
f->access[i] = 0x0;
@@ -5030,7 +5035,6 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc,
{
int err;
VulkanFramesPriv *fp = hwfc->hwctx;
- AVVulkanFramesContext *hwctx = &fp->p;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
@@ -5061,7 +5065,10 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc,
if (swf->width > hwfc->width || swf->height > hwfc->height)
return AVERROR(EINVAL);
- int host_copy = hwctx->usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT;
+ /* Only images we created with host transfer usage, not imports or
+ * images supplied by the user */
+ int host_copy = hwf_vk->internal &&
+ (hwf_vk->internal->usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT);
int host_map = p->vkctx.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY &&
!p->avoid_host_import;