[vlc-commits] direct3d11: only use the D3D11 decoder device automatically on Win8+

Steve Lhomme git at videolan.org
Thu Sep 19 15:03:37 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Sep 18 15:00:18 2019 +0200| [604d30d615e8ee820056369145ee5f6b5141e00c] | committer: Steve Lhomme

direct3d11: only use the D3D11 decoder device automatically on Win8+

If W8+ is not found on the most prioritary call, D3D9 is tried next. If D3D9
also fails, then the "Any" variant of D3D11 is tried for real.

If the decoder device is forced with --dec-dev the "Any" variant is used.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=604d30d615e8ee820056369145ee5f6b5141e00c
---

 modules/hw/d3d11/d3d11_device.c  | 25 ++++++++++++++++++++++++-
 modules/hw/d3d11/d3d11_filters.c |  6 +++++-
 modules/hw/d3d11/d3d11_filters.h |  3 ++-
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/modules/hw/d3d11/d3d11_device.c b/modules/hw/d3d11/d3d11_device.c
index 1d543e2087..e7bc13264b 100644
--- a/modules/hw/d3d11/d3d11_device.c
+++ b/modules/hw/d3d11/d3d11_device.c
@@ -71,7 +71,7 @@ static const struct vlc_decoder_device_operations d3d11_dev_ops = {
     .close = D3D11CloseDecoderDevice,
 };
 
-int D3D11OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)
+static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_window_t *wnd)
 {
     VLC_UNUSED(wnd);
     d3d11_decoder_device *sys = vlc_obj_malloc(VLC_OBJECT(device), sizeof(*sys));
@@ -114,6 +114,19 @@ int D3D11OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)
         else
         {
             /* internal decoder device */
+#if !VLC_WINSTORE_APP
+            if (!forced)
+            {
+                /* Allow using D3D11 automatically starting from Windows 8.1 */
+                bool isWin81OrGreater = false;
+                HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+                if (likely(hKernel32 != NULL))
+                    isWin81OrGreater = GetProcAddress(hKernel32, "IsProcessCritical") != NULL;
+                if (!isWin81OrGreater)
+                    return VLC_EGENERIC;
+            }
+#endif /* !VLC_WINSTORE_APP */
+
             HRESULT hr = D3D11_CreateDevice( device, &sys->hd3d, NULL,
                                             true /* is_d3d11_opaque(chroma) */,
                                             &sys->d3d_dev );
@@ -144,3 +157,13 @@ error:
     vlc_obj_free( VLC_OBJECT(device), sys );
     return VLC_EGENERIC;
 }
+
+int D3D11OpenDecoderDeviceW8(vlc_decoder_device *device, vout_window_t *wnd)
+{
+    return D3D11OpenDecoderDevice(device, false, wnd);
+}
+
+int D3D11OpenDecoderDeviceAny(vlc_decoder_device *device, vout_window_t *wnd)
+{
+    return D3D11OpenDecoderDevice(device, true, wnd);
+}
diff --git a/modules/hw/d3d11/d3d11_filters.c b/modules/hw/d3d11/d3d11_filters.c
index 1feb03fc5f..233b78c649 100644
--- a/modules/hw/d3d11/d3d11_filters.c
+++ b/modules/hw/d3d11/d3d11_filters.c
@@ -588,7 +588,11 @@ vlc_module_begin()
 
     add_submodule()
     set_description(N_("Direct3D11"))
-    set_callback_dec_device( D3D11OpenDecoderDevice, 20 )
+    set_callback_dec_device( D3D11OpenDecoderDeviceW8, 20 )
+
+    add_submodule()
+    set_description(N_("Direct3D11"))
+    set_callback_dec_device( D3D11OpenDecoderDeviceAny, 8 )
 #if VLC_WINSTORE_APP
     /* LEGACY, the d3dcontext and swapchain were given by the host app */
     add_integer("winrt-d3dcontext",    0x0, NULL, NULL, true) /* ID3D11DeviceContext* */
diff --git a/modules/hw/d3d11/d3d11_filters.h b/modules/hw/d3d11/d3d11_filters.h
index 0c03523dde..8654994bca 100644
--- a/modules/hw/d3d11/d3d11_filters.h
+++ b/modules/hw/d3d11/d3d11_filters.h
@@ -35,7 +35,8 @@ void D3D11CloseConverter(vlc_object_t *);
 int  D3D11OpenCPUConverter(vlc_object_t *);
 void D3D11CloseCPUConverter(vlc_object_t *);
 
-int  D3D11OpenDecoderDevice(vlc_decoder_device *, vout_window_t *);
+int  D3D11OpenDecoderDeviceW8(vlc_decoder_device *, vout_window_t *);
+int  D3D11OpenDecoderDeviceAny(vlc_decoder_device *, vout_window_t *);
 
 void D3D11_FilterHoldInstance(filter_t *, d3d11_device_t *, D3D11_TEXTURE2D_DESC *);
 void D3D11_FilterReleaseInstance(d3d11_device_t *);



More information about the vlc-commits mailing list