From patchwork Tue Nov 3 18:45:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: galinart X-Patchwork-Id: 23374 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 868CA44A9C4 for ; Tue, 3 Nov 2020 21:19:57 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64D9068B6CB; Tue, 3 Nov 2020 21:19:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67B23687EB0 for ; Tue, 3 Nov 2020 21:19:51 +0200 (EET) Received: by mail-ed1-f67.google.com with SMTP id a10so2376364edt.12 for ; Tue, 03 Nov 2020 11:19:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N/CECbmD9fEpR+nRNwXZy1LskyAIQDNMwNPjTdr+IY8=; b=Tg6lY3ZW4LRLbPCzf8nSgAcTwllK/8RZ+cfNWYOOPZbJs5+fgSPv9NrcsVtPsiFVrE KzcUQqgodM1HQE6G4e5dH2RSKtgLkYkzGbE+JBZPKbWF+vvTAVV14MY9WaqUCDGy5gHD mWDIP1Ep4P4Wxr3zgdrSY28epndbexNR4ax3Tc5Pd7KoXZMESgsSg8sxuxPG2EOWQ1RD dJDT/VI3JsFyBwUxClfkyzxjQPzZV1XFHgcVboAw2lcCYTmmyjQ22Atq9RJ7XwZZ8gtP wo+BHoeX5Bp+zlseQiSAOoq8pHtrxqHiZ541sLt1nRIWMXNgs/X6IfEGGbavjr00QIIj 3NFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N/CECbmD9fEpR+nRNwXZy1LskyAIQDNMwNPjTdr+IY8=; b=pRbpV+5Gjy9TAT5Bb0mDI5PusvmH8gYWAlld4VcNYLoEZa1GPYe4N60yABt7olTtYR 58fcm/+x/R1eto8yiNoEgP4VX9vRztP+pCu36+LFmVlDWFyQTJyQmf5F94ivMQ9r+OD4 gw0P2pXYLuLxn9etuPFNNg7ubVAcgmX2uppjdyYs4iRUiI7L0kxwLJpi7D3eb2OLrouJ ANDDG9An83ev5a6YAIsO+iD5cuDXP+3c/tTti7kb15ficYpgIsAoN3C3Ob8+AETNvKn+ UlBloAb0U781pOnv7WWEBRbxb5tqf8zdM3eAcrhUhHmmmcoJZ8XolKOMs6y9ijqq9SyQ UiKA== X-Gm-Message-State: AOAM533u2jmluTwL4trw4iPYCVdLgyu7NXbHX/ENmdqGhLGKumDA2Hfd YRX/hTeyFfMXgIJofTNNVxaxX00X2Nq+1w== X-Google-Smtp-Source: ABdhPJzd+a92SSpETa4rvH6AcGTke9Ob/ANf4ml679wozdzEeiwGn+vezIc5bT4NtqBwstUkOCxBxw== X-Received: by 2002:adf:9b8e:: with SMTP id d14mr29394039wrc.360.1604429272986; Tue, 03 Nov 2020 10:47:52 -0800 (PST) Received: from localhost.localdomain ([2a02:c7f:3015:4e00:e4c4:5a5e:dd23:ce22]) by smtp.googlemail.com with ESMTPSA id z2sm3905249wmf.45.2020.11.03.10.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 10:47:52 -0800 (PST) From: Artem Galin X-Google-Original-From: Artem Galin To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:45:52 +0000 Message-Id: <20201103184557.18444-3-artem.galin@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103184557.18444-1-artem.galin@intel.com> References: <20201103184557.18444-1-artem.galin@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 3/8] libavutil/hwcontext_qsv: enabling d3d11va usage by default, add usage child_device_type argument 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 Cc: Artem Galin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Makes selection of d3d11va device type by default and over DirectX 9, which might break users with older drivers/systems. DCH driver with Gen6th support should be still fine. Decode, encode, transcode have been validated. child_device_type option is responsible for d3d11va/dxva2 device selection Usage examples: DirectX 11 -init_hw_device qsv:hw,child_device_type=d3d11va DirectX 9 is still supported but requires explicit selection -init_hw_device qsv:hw,child_device_type=dxva2 Signed-off-by: Artem Galin --- doc/ffmpeg.texi | 20 ++++++++++++- libavutil/hwcontext_qsv.c | 59 +++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 95d6463685..2fa99813c6 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -974,6 +974,9 @@ device type: @item dxva2 @var{device} is the number of the Direct3D 9 display adapter. +@item d3d11va +@var{device} is the number of the Direct3D 11 display adapter. + @item vaapi @var{device} is either an X11 display name or a DRM render node. If not specified, it will attempt to open the default X11 display (@emph{$DISPLAY}) @@ -997,9 +1000,21 @@ If not specified, it will attempt to open the default X11 display (@emph{$DISPLA @end table If not specified, @samp{auto_any} is used. (Note that it may be easier to achieve the desired result for QSV by creating the -platform-appropriate subdevice (@samp{dxva2} or @samp{vaapi}) and then deriving a +platform-appropriate subdevice (@samp{dxva2} or @samp{d3d11va} or @samp{vaapi}) and then deriving a QSV device from that.) +Alternatively, @samp{child_device_type} helps to choose platform-appropriate subdevice type. +On Windows @samp{d3d11va} is used as default subdevice type. + +Examples: +@table @emph +@item -init_hw_device qsv:hw,child_device_type=d3d11va +Choose the GPU subdevice with type @samp{d3d11va} and create QSV device with @samp{MFX_IMPL_HARDWARE}. + +@item -init_hw_device qsv:hw,child_device_type=dxva2 +Choose the GPU subdevice with type @samp{dxva2} and create QSV device with @samp{MFX_IMPL_HARDWARE}. +@end table + @item opencl @var{device} selects the platform and device as @emph{platform_index.device_index}. @@ -1102,6 +1117,9 @@ Use VDPAU (Video Decode and Presentation API for Unix) hardware acceleration. @item dxva2 Use DXVA2 (DirectX Video Acceleration) hardware acceleration. +@item d3d11va +Use D3D11VA (DirectX Video Acceleration) hardware acceleration. + @item vaapi Use VAAPI (Video Acceleration API) hardware acceleration. diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 1f5a3d1c57..c0a71c9822 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1440,28 +1440,59 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, ctx->user_opaque = priv; ctx->free = qsv_device_free; - e = av_dict_get(opts, "child_device", NULL, 0); - - child_device_opts = NULL; - if (CONFIG_VAAPI) { + e = av_dict_get(opts, "child_device_type", NULL, 0); + if (e) { + child_device_type = av_hwdevice_find_type_by_name(e ? e->value : NULL); + if (child_device_type == AV_HWDEVICE_TYPE_NONE) { + av_log(ctx, AV_LOG_ERROR, "Unknown child device type " + "\"%s\".\n", e ? e->value : NULL); + return AVERROR(EINVAL); + } + } else if (CONFIG_VAAPI) { child_device_type = AV_HWDEVICE_TYPE_VAAPI; - // libmfx does not actually implement VAAPI properly, rather it - // depends on the specific behaviour of a matching iHD driver when - // used on recent Intel hardware. Set options to the VAAPI device - // creation so that we should pick a usable setup by default if - // possible, even when multiple devices and drivers are available. - av_dict_set(&child_device_opts, "kernel_driver", "i915", 0); - av_dict_set(&child_device_opts, "driver", "iHD", 0); - } else if (CONFIG_DXVA2) + } else if (CONFIG_D3D11VA) { + child_device_type = AV_HWDEVICE_TYPE_D3D11VA; + } else if (CONFIG_DXVA2) { child_device_type = AV_HWDEVICE_TYPE_DXVA2; - else { + } else { av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); return AVERROR(ENOSYS); } + child_device_opts = NULL; + switch (child_device_type) { +#if CONFIG_VAAPI + case AV_HWDEVICE_TYPE_VAAPI: + { + // libmfx does not actually implement VAAPI properly, rather it + // depends on the specific behaviour of a matching iHD driver when + // used on recent Intel hardware. Set options to the VAAPI device + // creation so that we should pick a usable setup by default if + // possible, even when multiple devices and drivers are available. + av_dict_set(&child_device_opts, "kernel_driver", "i915", 0); + av_dict_set(&child_device_opts, "driver", "iHD", 0); + } + break; +#endif +#if CONFIG_D3D11VA + case AV_HWDEVICE_TYPE_D3D11VA: + break; +#endif +#if CONFIG_DXVA2 + case AV_HWDEVICE_TYPE_DXVA2: + break; +#endif + default: + { + av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); + return AVERROR(ENOSYS); + } + break; + } + + e = av_dict_get(opts, "child_device", NULL, 0); ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type, e ? e->value : NULL, child_device_opts, 0); - av_dict_free(&child_device_opts); if (ret < 0) return ret;