From a45d30a67579f00926525ffd23c7a6b5470d77a0 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 20 Aug 2025 16:56:22 +0200 Subject: [PATCH] avutil/hwcontext_vulkan: always enable baseline usage flags The documentation states that this field is for enabling "extra" usage flags. This conflicts with the implementation, and the rest of the comment, though. In resolving this ambiguity, I think it's better to lean towards the first sentence and treat this field purely as specifying *extra* usage flags to enable. Otherwise, this may break vulkan encoding or subsequent hwdownload if the upstream filter did not specifically advertise this. Change the default behavior and update the documentation slightly to more clearly document the semantics. --- libavutil/hwcontext_vulkan.c | 24 +++++++++++------------- libavutil/hwcontext_vulkan.h | 3 ++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 286e13c509..ae4b07c698 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -2901,21 +2901,19 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) supported_usage &= ~VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT; /* Image usage flags */ - if (!hwctx->usage) { - hwctx->usage = supported_usage & (VK_IMAGE_USAGE_TRANSFER_DST_BIT | - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | - VK_IMAGE_USAGE_STORAGE_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT); + hwctx->usage |= supported_usage & (VK_IMAGE_USAGE_TRANSFER_DST_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_STORAGE_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT); - if ((p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY) && !p->disable_host_transfer) - hwctx->usage |= supported_usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT; + if ((p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY) && !p->disable_host_transfer) + hwctx->usage |= supported_usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT; - /* Enables encoding of images, if supported by format and extensions */ - if ((supported_usage & VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR) && - (p->vkctx.extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE | - FF_VK_EXT_VIDEO_MAINTENANCE_1))) - hwctx->usage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR; - } + /* Enables encoding of images, if supported by format and extensions */ + if ((supported_usage & VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR) && + (p->vkctx.extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE | + FF_VK_EXT_VIDEO_MAINTENANCE_1))) + hwctx->usage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR; /* Image creation flags. * Only fill them in automatically if the image is not going to be used as diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h index 15cf515668..0bb536ab3f 100644 --- a/libavutil/hwcontext_vulkan.h +++ b/libavutil/hwcontext_vulkan.h @@ -218,7 +218,8 @@ typedef struct AVVulkanFramesContext { /** * Defines extra usage of output frames. If non-zero, all flags MUST be - * supported by the VkFormat. Otherwise, will use supported flags amongst: + * supported by the VkFormat. Regardless, frames will always have the + * following usage flags enabled, if supported by the format: * - VK_IMAGE_USAGE_SAMPLED_BIT * - VK_IMAGE_USAGE_STORAGE_BIT * - VK_IMAGE_USAGE_TRANSFER_SRC_BIT