diff mbox series

[FFmpeg-devel,3/8] libavutil/hwcontext_qsv: enabling d3d11va usage by default, add usage child_device_type argument

Message ID 20210722105635.48075-3-artem.galin@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/8] libavcodec/qsv: enabling d3d11va support, added mfxhdlpair | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

galinart July 22, 2021, 10:56 a.m. UTC
From: Artem Galin <artem.galin@intel.com>

Rebase of last patch set over current master.
Makes selection of d3d11va/DX11 device type by default and over dxva/DX9, helps to cover more HW configurations without explicit parameters need.

Fixes TGL / AV1 decode as requires DX11 with default parameters
Add headless/multi adapter support and fixes:
    https://trac.ffmpeg.org/ticket/7511
    https://trac.ffmpeg.org/ticket/6827
    http://ffmpeg.org/pipermail/ffmpeg-trac/2017-November/041901.html
    https://trac.ffmpeg.org/ticket/7933
    https://github.com/InitialForce/FFmpeg/commit/338fbcd5bba1de0e1b3e3bad8985eee2fdfbeca1
    https://github.com/jellyfin/jellyfin/issues/2626#issuecomment-602153952

Any other fixes are welcome including OpenCL interop patch since I don't have proper setup to validate this use case

Decoding, encoding, transcoding have been validated.

Requires apply the following patch https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210623030346.2025933-1-haihao.xiang@intel.com/ to make command lines work as below.

child_device_type option is responsible for d3d11va/dxva2 device selection

Usage examples:

DirectX 11:
    -init_hw_device qsv:hw,child_device_type=d3d11va
    -init_hw_device qsv:hw,child_device_type=d3d11va,child_device=0
OR
    -init_hw_device d3d11va=dx -init_hw_device qsv@dx

DirectX 9 is still supported but requires explicit selection:
    -init_hw_device qsv:hw,child_device_type=dxva2
OR
    -init_hw_device dxva2=dx -init_hw_device qsv@dx

Signed-off-by: Artem Galin <artem.galin@intel.com>
---
 doc/ffmpeg.texi           | 20 ++++++++++++-
 libavutil/hwcontext_qsv.c | 59 +++++++++++++++++++++++++++++----------
 2 files changed, 64 insertions(+), 15 deletions(-)

Comments

Soft Works July 22, 2021, 4:44 p.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Artem Galin
> Sent: Thursday, 22 July 2021 12:57
> To: ffmpeg-devel@ffmpeg.org; ffmpeg-devep@ffmpeg.org
> Cc: Artem Galin <artem.galin@intel.com>
> Subject: [FFmpeg-devel] [PATCH 3/8] libavutil/hwcontext_qsv: enabling
> d3d11va usage by default, add usage child_device_type argument
> 
> From: Artem Galin <artem.galin@intel.com>
> 
> Rebase of last patch set over current master.
> Makes selection of d3d11va/DX11 device type by default and over dxva/DX9,
> helps to cover more HW configurations without explicit parameters need.
> 
> Fixes TGL / AV1 decode as requires DX11 with default parameters Add
> headless/multi adapter support and fixes:
>     https://trac.ffmpeg.org/ticket/7511
>     https://trac.ffmpeg.org/ticket/6827
>     http://ffmpeg.org/pipermail/ffmpeg-trac/2017-November/041901.html
>     https://trac.ffmpeg.org/ticket/7933
> 
> https://github.com/InitialForce/FFmpeg/commit/338fbcd5bba1de0e1b3e3b
> ad8985eee2fdfbeca1
>     https://github.com/jellyfin/jellyfin/issues/2626#issuecomment-602153952
> 
> Any other fixes are welcome including OpenCL interop patch since I don't
> have proper setup to validate this use case
> 
> Decoding, encoding, transcoding have been validated.
> 
> Requires apply the following patch
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210623030346.20259
> 33-1-haihao.xiang@intel.com/ to make command lines work as below.
> 
> child_device_type option is responsible for d3d11va/dxva2 device selection
> 
> Usage examples:
> 
> DirectX 11:
>     -init_hw_device qsv:hw,child_device_type=d3d11va
>     -init_hw_device qsv:hw,child_device_type=d3d11va,child_device=0
> OR
>     -init_hw_device d3d11va=dx -init_hw_device qsv@dx
> 
> DirectX 9 is still supported but requires explicit selection:
>     -init_hw_device qsv:hw,child_device_type=dxva2 OR
>     -init_hw_device dxva2=dx -init_hw_device qsv@dx


Still the same concern: this breaks existing command lines. 

D3D9 should remain the default for existing command lines.

softworkz
Soft Works July 22, 2021, 4:45 p.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Artem Galin
> Sent: Thursday, 22 July 2021 12:57
> To: ffmpeg-devel@ffmpeg.org; ffmpeg-devep@ffmpeg.org
> Cc: Artem Galin <artem.galin@intel.com>
> Subject: [FFmpeg-devel] [PATCH 3/8] libavutil/hwcontext_qsv: enabling
> d3d11va usage by default, add usage child_device_type argument
> 
> From: Artem Galin <artem.galin@intel.com>
> 
> Rebase of last patch set over current master.
> Makes selection of d3d11va/DX11 device type by default and over dxva/DX9,
> helps to cover more HW configurations without explicit parameters need.
> 
> Fixes TGL / AV1 decode as requires DX11 with default parameters Add
> headless/multi adapter support and fixes:
>     https://trac.ffmpeg.org/ticket/7511
>     https://trac.ffmpeg.org/ticket/6827
>     http://ffmpeg.org/pipermail/ffmpeg-trac/2017-November/041901.html
>     https://trac.ffmpeg.org/ticket/7933
> 
> https://github.com/InitialForce/FFmpeg/commit/338fbcd5bba1de0e1b3e3b
> ad8985eee2fdfbeca1
>     https://github.com/jellyfin/jellyfin/issues/2626#issuecomment-602153952
> 
> Any other fixes are welcome including OpenCL interop patch since I don't
> have proper setup to validate this use case
> 
> Decoding, encoding, transcoding have been validated.
> 
> Requires apply the following patch
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210623030346.20259
> 33-1-haihao.xiang@intel.com/ to make command lines work as below.
> 
> child_device_type option is responsible for d3d11va/dxva2 device selection
> 
> Usage examples:
> 
> DirectX 11:
>     -init_hw_device qsv:hw,child_device_type=d3d11va
>     -init_hw_device qsv:hw,child_device_type=d3d11va,child_device=0
> OR
>     -init_hw_device d3d11va=dx -init_hw_device qsv@dx
> 
> DirectX 9 is still supported but requires explicit selection:
>     -init_hw_device qsv:hw,child_device_type=dxva2 OR
>     -init_hw_device dxva2=dx -init_hw_device qsv@dx


Still the same concern: this breaks existing command lines. 

D3D9 should remain the default for existing command lines.

softworkz
diff mbox series

Patch

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index b27b9fe2c4..04e14bb56c 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1097,6 +1097,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})
@@ -1120,9 +1123,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}.
 
@@ -1225,6 +1240,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 95170323d9..f7cd13cf1b 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;