From patchwork Mon May 11 10:25:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 19621 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0CBF544AB79 for ; Mon, 11 May 2020 13:25:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D7691680D0B; Mon, 11 May 2020 13:25:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 349B6680B67 for ; Mon, 11 May 2020 13:25:16 +0300 (EEST) Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id CE0C81060D1F for ; Mon, 11 May 2020 10:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1589192715; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=6akmiBlBfn/XnwiyNwbGweoabKim6PopIWNbyZ5Sv1c=; b=WnM99XVu5Zk4TuPc4M0r/2k4qMjAT2GcGd0K0PEoAmLCDy5CfZwIRBaR0vBnmuzX //NHfScL4sigD6CUc/iThyi+WPVC6f+pGV5Zv6U+Wg7xVemRl2s2YTQNwOQKXCfiNQm 52wnwPfdCGph4n2PIH2bb6wE0vtYYiqTodDHzRtrXLAMB4YrcKcguW6js9VJ+LsLY/+ akXNO/zAmWwwmes0X79myfGxX8IWiQIade3p4szStwkGPMkIGkAVcMc5qWG9k4ZBeAX wTln6T+5bq32k0E26uVLV/C5vZX+T3XeGg7qSchlmbZR5PyLGnsxZS4gO63RbWDykUk ifXbNsaPjw== Date: Mon, 11 May 2020 12:25:15 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] hwcontext: add av_hwdevice_ctx_create_derived2 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This allows for users who derive devices to set options for the new device context they derive. The main use case of this is to allow users to enable extensions (such as surface drawing extensions) in Vulkan while deriving from the device their frames are on. That way, users don't need to write any initialization code themselves, since currently Vulkan prevents mixing instances and devices. Also, with this, users can also set custom OpenCL extensions such as cl_khr_gl_sharing and cl_khr_gl_depth_images. Apart from OpenCL and Vulkan, other hwcontexts ignore the opts argument since they don't support options at all (or in VAAPI's case, options are only used for device selection, which device_derive overrides). Patch attached. Subject: [PATCH] hwcontext: add av_hwdevice_ctx_create_derived2 This allows for users who derive devices to set options for the new device context they derive. The main use case of this is to allow users to enable extensions (such as surface drawing extensions) in Vulkan while deriving from the device their frames are on. That way, users don't need to write any initialization code themselves, since currently Vulkan prevents mixing instances and devices. Also, with this, users can also set custom OpenCL extensions such as cl_khr_gl_sharing and cl_khr_gl_depth_images. Apart from OpenCL and Vulkan, other hwcontexts ignore the opts argument since they don't support options at all (or in VAAPI's case, options are only used for device selection, which device_derive overrides). --- doc/APIchanges | 3 +++ libavutil/hwcontext.c | 16 +++++++++++++--- libavutil/hwcontext.h | 20 ++++++++++++++++++++ libavutil/hwcontext_cuda.c | 1 + libavutil/hwcontext_internal.h | 2 +- libavutil/hwcontext_opencl.c | 13 +++++++------ libavutil/hwcontext_qsv.c | 2 +- libavutil/hwcontext_vaapi.c | 2 +- libavutil/hwcontext_vulkan.c | 8 ++++---- libavutil/version.h | 2 +- 10 files changed, 52 insertions(+), 17 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 75cfdb08b0..1bb0677142 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2020-05-11 - xxxxxxxxxx - lavu 56.45.100 - hwcontext.h + Add av_hwdevice_ctx_create_derived2. + 2020-05-10 - xxxxxxxxxx - lavu 56.44.100 - hwcontext_vulkan.h Add enabled_inst_extensions, num_enabled_inst_extensions, enabled_dev_extensions and num_enabled_dev_extensions fields to AVVulkanDeviceContext diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index b01612de05..77b7014c39 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -643,9 +643,10 @@ fail: return ret; } -int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, - enum AVHWDeviceType type, - AVBufferRef *src_ref, int flags) +int av_hwdevice_ctx_create_derived2(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVDictionary *options, + AVBufferRef *src_ref, int flags) { AVBufferRef *dst_ref = NULL, *tmp_ref; AVHWDeviceContext *dst_ctx, *tmp_ctx; @@ -677,6 +678,7 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, tmp_ctx = (AVHWDeviceContext*)tmp_ref->data; if (dst_ctx->internal->hw_type->device_derive) { ret = dst_ctx->internal->hw_type->device_derive(dst_ctx, + options, tmp_ctx, flags); if (ret == 0) { @@ -709,6 +711,14 @@ fail: return ret; } +int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVBufferRef *src_ref, int flags) +{ + return av_hwdevice_ctx_create_derived2(dst_ref_ptr, type, NULL, + src_ref, flags); +} + static void ff_hwframe_unmap(void *opaque, uint8_t *data) { HWMapDescriptor *hwmap = (HWMapDescriptor*)data; diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index f874af9f8f..4a94a2a8e4 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -328,6 +328,26 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx, enum AVHWDeviceType type, AVBufferRef *src_ctx, int flags); +/** + * Create a new device of the specified type from an existing device. + * + * This function performs the same action as av_hwdevice_ctx_create_derived, + * however, it is able to set options for the new device to be derived. + * + * @param dst_ctx On success, a reference to the newly-created + * AVHWDeviceContext. + * @param type The type of the new device to create. + * @param options Options for the new device to create, same format as in + * av_hwdevice_ctx_create. + * @param src_ctx A reference to an existing AVHWDeviceContext which will be + * used to create the new device. + * @param flags Currently unused; should be set to zero. + * @return Zero on success, a negative AVERROR code on failure. + */ +int av_hwdevice_ctx_create_derived2(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVDictionary *options, + AVBufferRef *src_ref, int flags); /** * Allocate an AVHWFramesContext tied to a given device context. diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c index 58d128a280..a4fbc3675a 100644 --- a/libavutil/hwcontext_cuda.c +++ b/libavutil/hwcontext_cuda.c @@ -395,6 +395,7 @@ error: } static int cuda_device_derive(AVHWDeviceContext *device_ctx, + AVDictionart *options, AVHWDeviceContext *src_ctx, int flags) { AVCUDADeviceContext *hwctx = device_ctx->hwctx; diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h index dba0f39944..9d66245a23 100644 --- a/libavutil/hwcontext_internal.h +++ b/libavutil/hwcontext_internal.h @@ -66,7 +66,7 @@ typedef struct HWContextType { int (*device_create)(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags); - int (*device_derive)(AVHWDeviceContext *dst_ctx, + int (*device_derive)(AVHWDeviceContext *dst_ctx, AVDictionary *opts, AVHWDeviceContext *src_ctx, int flags); int (*device_init)(AVHWDeviceContext *ctx); diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c index 41fdfe96f1..b5a282b55b 100644 --- a/libavutil/hwcontext_opencl.c +++ b/libavutil/hwcontext_opencl.c @@ -1193,7 +1193,7 @@ static int opencl_filter_drm_arm_device(AVHWDeviceContext *hwdev, } #endif -static int opencl_device_derive(AVHWDeviceContext *hwdev, +static int opencl_device_derive(AVHWDeviceContext *hwdev, AVDictionary *opts, AVHWDeviceContext *src_ctx, int flags) { @@ -1207,16 +1207,17 @@ static int opencl_device_derive(AVHWDeviceContext *hwdev, // Surface mapping works via DRM PRIME fds with no special // initialisation required in advance. This just finds the // Beignet ICD by name. - AVDictionary *opts = NULL; + AVDictionary *selector_opts = NULL; + av_dict_copy(&selector_opts, opts, 0); - err = av_dict_set(&opts, "platform_vendor", "Intel", 0); + err = av_dict_set(&selector_opts, "platform_vendor", "Intel", 0); if (err >= 0) - err = av_dict_set(&opts, "platform_version", "beignet", 0); + err = av_dict_set(&selector_opts, "platform_version", "beignet", 0); if (err >= 0) { OpenCLDeviceSelector selector = { .platform_index = -1, .device_index = 0, - .context = opts, + .context = selector_opts, .enumerate_platforms = &opencl_enumerate_platforms, .filter_platform = &opencl_filter_platform, .enumerate_devices = &opencl_enumerate_devices, @@ -1224,7 +1225,7 @@ static int opencl_device_derive(AVHWDeviceContext *hwdev, }; err = opencl_device_create_internal(hwdev, &selector, NULL); } - av_dict_free(&opts); + av_dict_free(&selector_opts); } break; #endif diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index b1b67400de..e3b969c20f 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1188,7 +1188,7 @@ fail: return ret; } -static int qsv_device_derive(AVHWDeviceContext *ctx, +static int qsv_device_derive(AVHWDeviceContext *ctx, AVDictionary *opts, AVHWDeviceContext *child_device_ctx, int flags) { return qsv_device_derive_from_child(ctx, MFX_IMPL_HARDWARE_ANY, diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index b306965b4a..e2ab149622 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -1623,7 +1623,7 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, return vaapi_device_connect(ctx, display); } -static int vaapi_device_derive(AVHWDeviceContext *ctx, +static int vaapi_device_derive(AVHWDeviceContext *ctx, AVDictionary *opts, AVHWDeviceContext *src_ctx, int flags) { #if HAVE_VAAPI_DRM diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index a5983f2735..cb581c1468 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -936,7 +936,7 @@ static int vulkan_device_create(AVHWDeviceContext *ctx, const char *device, return vulkan_device_create_internal(ctx, &dev_select, opts, flags); } -static int vulkan_device_derive(AVHWDeviceContext *ctx, +static int vulkan_device_derive(AVHWDeviceContext *ctx, AVDictionary *opts, AVHWDeviceContext *src_ctx, int flags) { av_unused VulkanDeviceSelection dev_select = { 0 }; @@ -961,7 +961,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx, if (strstr(vendor, "AMD")) dev_select.vendor_id = 0x1002; - return vulkan_device_create_internal(ctx, &dev_select, NULL, flags); + return vulkan_device_create_internal(ctx, &dev_select, opts, flags); } #endif case AV_HWDEVICE_TYPE_DRM: { @@ -979,7 +979,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx, drmFreeDevice(&drm_dev_info); - return vulkan_device_create_internal(ctx, &dev_select, NULL, flags); + return vulkan_device_create_internal(ctx, &dev_select, opts, flags); } #endif #if CONFIG_CUDA @@ -998,7 +998,7 @@ static int vulkan_device_derive(AVHWDeviceContext *ctx, dev_select.has_uuid = 1; - return vulkan_device_create_internal(ctx, &dev_select, NULL, flags); + return vulkan_device_create_internal(ctx, &dev_select, opts, flags); } #endif default: diff --git a/libavutil/version.h b/libavutil/version.h index 48d8a38c42..77592fcd8e 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 44 +#define LIBAVUTIL_VERSION_MINOR 45 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \