PR #23019 opened by DmitriiGershenkop URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23019 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23019.patch
>From 9c395b4ba490875d3bc68ddc02993f0db6ccaf0b Mon Sep 17 00:00:00 2001 From: Dmitrii Gershenkop <[email protected]> Date: Mon, 4 May 2026 15:42:08 +0200 Subject: [PATCH] avutil/hwcontext_{amf,vulkan}: Added the ability to derive an AMF hwdevice from a Vulkan hwdevice --- Changelog | 1 + libavutil/hwcontext_amf.c | 39 +++++++++++++++++++++++++++++++++++- libavutil/hwcontext_amf.h | 8 ++++++++ libavutil/hwcontext_vulkan.c | 12 +++++++++++ libavutil/version.h | 2 +- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 3f5e38e0c7..c95992d362 100644 --- a/Changelog +++ b/Changelog @@ -9,6 +9,7 @@ version <next>: - HE-AAC 960 decoding (DAB+) - transpose_cuda filter - Add AMF Frame Rate Converter (vf_frc_amf) filter +- Added the ability to derive an AMF hwdevice from a Vulkan hwdevice version 8.1: diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c index 754b1c60a2..086f2965a4 100644 --- a/libavutil/hwcontext_amf.c +++ b/libavutil/hwcontext_amf.c @@ -785,12 +785,45 @@ static int amf_init_from_d3d12_device(AVAMFDeviceContext* amf_ctx, AVHWDeviceCon } #endif +#if CONFIG_VULKAN +static int amf_init_from_vulkan_device(AVAMFDeviceContext* amf_ctx, AVHWDeviceContext *child_device_ctx) +{ + AVVulkanDeviceContext *hwctx = child_device_ctx->hwctx; + AMF_RESULT res; + AMFContext *context_base = amf_ctx->context; + AMFContext1 *context1 = NULL; + AMFVulkanDevice *amf_vlk = &amf_ctx->amf_vlk; + + AMFGuid guid = IID_AMFContext1(); + res = AMF_IFACE_CALL(context_base, QueryInterface, &guid, (void**)&context1); + AMF_RETURN_IF_FALSE(child_device_ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext1() failed with error %d\n", res); + + amf_vlk->cbSizeof = sizeof(AMFVulkanDevice); + amf_vlk->hInstance = hwctx->inst; + amf_vlk->hPhysicalDevice = hwctx->phys_dev; + amf_vlk->hDevice = hwctx->act_dev; + + res = AMF_IFACE_CALL(context1, InitVulkan, amf_vlk); + AMF_IFACE_CALL(context1, Release); + + if (res != AMF_OK && res != AMF_ALREADY_INITIALIZED) { + if (res == AMF_NOT_SUPPORTED) + av_log(child_device_ctx, AV_LOG_ERROR, "AMF via Vulkan is not supported on the given device.\n"); + else + av_log(child_device_ctx, AV_LOG_ERROR, "AMF failed to initialize on the given Vulkan device with error %d.\n", res); + return AVERROR(ENODEV); + } + + av_log(child_device_ctx, AV_LOG_INFO, "AMF via Vulkan.\n"); + return 0; +} +#endif static int amf_device_derive(AVHWDeviceContext *device_ctx, AVHWDeviceContext *child_device_ctx, AVDictionary *opts, int flags) { -#if CONFIG_DXVA2 || CONFIG_D3D11VA +#if CONFIG_DXVA2 || CONFIG_D3D11VA || CONFIG_VULKAN AVAMFDeviceContext *amf_ctx = device_ctx->hwctx; #endif int ret; @@ -811,6 +844,10 @@ static int amf_device_derive(AVHWDeviceContext *device_ctx, #if CONFIG_D3D12VA case AV_HWDEVICE_TYPE_D3D12VA: return amf_init_from_d3d12_device(amf_ctx, child_device_ctx); +#endif +#if CONFIG_VULKAN + case AV_HWDEVICE_TYPE_VULKAN: + return amf_init_from_vulkan_device(amf_ctx, child_device_ctx); #endif default: av_log(child_device_ctx, AV_LOG_ERROR, "AMF initialisation from a %s device is not supported.\n", diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h index 918eec97b8..e429e0370d 100644 --- a/libavutil/hwcontext_amf.h +++ b/libavutil/hwcontext_amf.h @@ -29,6 +29,10 @@ #include <AMF/components/ColorSpace.h> #include "libavutil/mastering_display_metadata.h" +#ifdef CONFIG_VULKAN +#include <AMF/core/VulkanAMF.h> +#endif + /** * This struct is allocated as AVHWDeviceContext.hwctx */ @@ -41,6 +45,10 @@ typedef struct AVAMFDeviceContext { AMFContext *context; AMF_MEMORY_TYPE memory_type; +#ifdef CONFIG_VULKAN + AMFVulkanDevice amf_vlk; +#endif + void (*lock)(void *lock_ctx); void (*unlock)(void *lock_ctx); void *lock_ctx; diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 291708c3b3..7e662bd0ff 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -692,6 +692,15 @@ typedef struct VulkanOptExtension { static const VulkanOptExtension optional_instance_exts[] = { #ifdef __APPLE__ { VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#endif +#ifdef CONFIG_AMF + { VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, + { VK_KHR_SURFACE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, + { VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, + { VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#if defined(_WIN32) + { VK_KHR_WIN32_SURFACE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#endif #endif { 0 }, }; @@ -756,6 +765,9 @@ static const VulkanOptExtension optional_device_exts[] = { { VK_KHR_VIDEO_ENCODE_AV1_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_AV1 }, #endif { VK_KHR_VIDEO_DECODE_AV1_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_AV1 }, +#ifdef CONFIG_AMF + { VK_KHR_SWAPCHAIN_EXTENSION_NAME, FF_VK_EXT_NO_FLAG }, +#endif }; const char **av_vk_get_optional_instance_extensions(int *count) diff --git a/libavutil/version.h b/libavutil/version.h index 40a7d8e300..d36dd28377 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -80,7 +80,7 @@ #define LIBAVUTIL_VERSION_MAJOR 60 #define LIBAVUTIL_VERSION_MINOR 30 -#define LIBAVUTIL_VERSION_MICRO 100 +#define LIBAVUTIL_VERSION_MICRO 101 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
