PR #23459 opened by llyyr URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23459 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23459.patch
Drivers may advertise the usage bit for a format, but reject image creation for some specific combination of format, tiling, modifier or image flag combination. Query with the final image parameters and only enable HIC when the final image succeeds. >From 0c259d3c498a9c7222d260bcba4b2d6a9f156e5b Mon Sep 17 00:00:00 2001 From: llyyr <[email protected]> Date: Fri, 12 Jun 2026 12:34:01 +0530 Subject: [PATCH] avutil/hwcontext_vulkan: validate HIC support with final image params Drivers may advertise the usage bit for a format, but reject image creation for some specific combination of format, tiling, modifier or image flag combination. Query with the final image parameters and only enable HIC when the final image succeeds. --- libavutil/hwcontext_vulkan.c | 53 ++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 17380a22c0..7921d519c0 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -3118,11 +3118,6 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); - if (p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY && - !(p->dprops.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY) && - !(p->dprops.driverID == VK_DRIVER_ID_MOLTENVK)) - 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) && @@ -3142,6 +3137,54 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) hwctx->img_flags |= VK_IMAGE_CREATE_EXTENDED_USAGE_BIT; } } + + if (p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY && + !(p->dprops.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY) && + !(p->dprops.driverID == VK_DRIVER_ID_MOLTENVK) && + (supported_usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT)) { + const VkImageDrmFormatModifierListCreateInfoEXT *drm_mod_info = + ff_vk_find_struct(hwctx->create_pnext, + VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT); + + for (int i = 0; i < AV_NUM_DATA_POINTERS && hwctx->format[i] != VK_FORMAT_UNDEFINED; i++) { + VkPhysicalDeviceImageDrmFormatModifierInfoEXT mod_info; + VkImageFormatProperties2 props_ret = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, + }; + VkPhysicalDeviceImageFormatInfo2 fmt_info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + .format = hwctx->format[i], + .type = VK_IMAGE_TYPE_2D, + .tiling = hwctx->tiling, + .usage = hwctx->usage | VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT, + .flags = hwctx->img_flags, + }; + + if (hwctx->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT && + drm_mod_info && drm_mod_info->drmFormatModifierCount > 0) { + mod_info = (VkPhysicalDeviceImageDrmFormatModifierInfoEXT) { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT, + .drmFormatModifier = drm_mod_info->pDrmFormatModifiers[0], + .sharingMode = p->nb_img_qfs > 1 ? VK_SHARING_MODE_CONCURRENT : + VK_SHARING_MODE_EXCLUSIVE, + }; + ff_vk_link_struct(&fmt_info, &mod_info); + } + + err = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev, + &fmt_info, &props_ret); + if (err != VK_SUCCESS) { + av_log(hwfc, AV_LOG_VERBOSE, + "Host image copy not usable for plane %d format %d " + "(%s), falling back to device copy\n", + i, fmt_info.format, ff_vk_ret2str(err)); + break; + } + } + + if (err == VK_SUCCESS) + hwctx->usage |= VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT; + } } /* If the image has an ENCODE_SRC usage, and the maintenance1 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
