[vlc-commits] direct3d11: move the shader DLL loading in libd3d11_common

Steve Lhomme git at videolan.org
Wed Oct 17 16:07:17 CEST 2018


vlc/vlc-3.0 | branch: master | Steve Lhomme <robux4 at videolabs.io> | Mon Nov 20 11:51:40 2017 +0100| [6cc15f832d46fbd962ba66f60cff727ae4983df5] | committer: Steve Lhomme

direct3d11: move the shader DLL loading in libd3d11_common

(cherry picked from commit 6270679d7bb9fb775659a6d9358fde7badafd341)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=6cc15f832d46fbd962ba66f60cff727ae4983df5
---

 modules/codec/avcodec/d3d11va.c         |  2 +-
 modules/hw/d3d11/d3d11_deinterlace.c    |  4 +--
 modules/hw/d3d11/d3d11_surface.c        |  4 +--
 modules/video_chroma/d3d11_fmt.c        | 42 +++++++++++++++++++++++++++++-
 modules/video_chroma/d3d11_fmt.h        |  9 ++++---
 modules/video_output/win32/direct3d11.c | 45 ++-------------------------------
 6 files changed, 54 insertions(+), 52 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 250ca4ac6d..2caf5c65e7 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -381,7 +381,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
         }
     }
 
-    err = D3D11_Create( va, &sys->hd3d );
+    err = D3D11_Create( va, &sys->hd3d, false );
     if (err != VLC_SUCCESS)
         goto error;
 
diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 63341fe6f9..3c4a992c7c 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -354,7 +354,7 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
         return VLC_ENOMEM;
     memset(sys, 0, sizeof (*sys));
 
-    if ( unlikely(D3D11_Create(filter, &sys->hd3d) != VLC_SUCCESS ))
+    if ( unlikely(D3D11_Create(filter, &sys->hd3d, false) != VLC_SUCCESS ))
     {
        msg_Err(filter, "Could not access the d3d11.");
        goto error;
@@ -369,7 +369,7 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
         return VLC_ENOOBJ;
     }
 
-    if (D3D11_Create(filter, &sys->hd3d) != VLC_SUCCESS)
+    if (D3D11_Create(filter, &sys->hd3d, false) != VLC_SUCCESS)
         goto error;
 
     hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 78bcc9e468..e9a421122c 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -705,7 +705,7 @@ int D3D11OpenConverter( vlc_object_t *obj )
     if (CopyInitCache(&p_sys->cache, p_filter->fmt_in.video.i_width * pixel_bytes))
         return VLC_ENOMEM;
 
-    if (D3D11_Create(p_filter, &p_sys->hd3d) != VLC_SUCCESS)
+    if (D3D11_Create(p_filter, &p_sys->hd3d, false) != VLC_SUCCESS)
     {
         msg_Warn(p_filter, "cannot load d3d11.dll, aborting");
         CopyCleanCache(&p_sys->cache);
@@ -813,7 +813,7 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
          goto done;
     }
 
-    if (D3D11_Create(p_filter, &p_sys->hd3d) != VLC_SUCCESS)
+    if (D3D11_Create(p_filter, &p_sys->hd3d, false) != VLC_SUCCESS)
     {
         msg_Warn(p_filter, "cannot load d3d11.dll, aborting");
         goto done;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 795f370b42..343ea17fb2 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -631,8 +631,23 @@ error:
     return VLC_EGENERIC;
 }
 
+#if !VLC_WINSTORE_APP
+static HINSTANCE Direct3D11LoadShaderLibrary(void)
+{
+    HINSTANCE instance = NULL;
+    /* d3dcompiler_47 is the latest on windows 8.1 */
+    for (int i = 47; i > 41; --i) {
+        TCHAR filename[19];
+        _sntprintf(filename, 19, TEXT("D3DCOMPILER_%d.dll"), i);
+        instance = LoadLibrary(filename);
+        if (instance) break;
+    }
+    return instance;
+}
+#endif
+
 #undef D3D11_Create
-int D3D11_Create(vlc_object_t *obj, d3d11_handle_t *hd3d)
+int D3D11_Create(vlc_object_t *obj, d3d11_handle_t *hd3d, bool with_shaders)
 {
 #if !VLC_WINSTORE_APP
     hd3d->hdll = LoadLibrary(TEXT("D3D11.DLL"));
@@ -642,6 +657,24 @@ int D3D11_Create(vlc_object_t *obj, d3d11_handle_t *hd3d)
         return VLC_EGENERIC;
     }
 
+    if (with_shaders)
+    {
+        hd3d->compiler_dll = Direct3D11LoadShaderLibrary();
+        if (!hd3d->compiler_dll) {
+            msg_Err(obj, "cannot load d3dcompiler.dll, aborting");
+            FreeLibrary(hd3d->hdll);
+            return VLC_EGENERIC;
+        }
+
+        hd3d->OurD3DCompile = (void *)GetProcAddress(hd3d->compiler_dll, "D3DCompile");
+        if (!hd3d->OurD3DCompile) {
+            msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
+            FreeLibrary(hd3d->compiler_dll);
+            FreeLibrary(hd3d->hdll);
+            return VLC_EGENERIC;
+        }
+    }
+
 # if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     if (IsDebuggerPresent())
     {
@@ -667,6 +700,13 @@ void D3D11_Destroy(d3d11_handle_t *hd3d)
     if (hd3d->hdll)
         FreeLibrary(hd3d->hdll);
 
+    if (hd3d->compiler_dll)
+    {
+        FreeLibrary(hd3d->compiler_dll);
+        hd3d->compiler_dll = NULL;
+    }
+    hd3d->OurD3DCompile = NULL;
+
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     if (hd3d->dxgidebug_dll)
         FreeLibrary(hd3d->dxgidebug_dll);
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 8f396c4be6..ce1fd8231c 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -24,6 +24,7 @@
 #define VLC_VIDEOCHROMA_D3D11_FMT_H_
 
 #include <d3d11.h>
+#include <d3dcompiler.h>
 
 #include "dxgi_fmt.h"
 
@@ -48,7 +49,9 @@ typedef struct
 typedef struct
 {
 #if !VLC_WINSTORE_APP
-    HINSTANCE                 hdll;       /* handle of the opened d3d11 dll */
+    HINSTANCE                 hdll;         /* handle of the opened d3d11 dll */
+    HINSTANCE                 compiler_dll; /* handle of the opened d3dcompiler dll */
+    pD3DCompile               OurD3DCompile;
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     HINSTANCE                 dxgidebug_dll;
 #endif
@@ -102,8 +105,8 @@ HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *,
 
 void D3D11_ReleaseDevice(d3d11_device_t *);
 
-int D3D11_Create(vlc_object_t *, d3d11_handle_t *);
-#define D3D11_Create(a,b) D3D11_Create( VLC_OBJECT(a), b )
+int D3D11_Create(vlc_object_t *, d3d11_handle_t *, bool with_shaders);
+#define D3D11_Create(a,b,c) D3D11_Create( VLC_OBJECT(a), b, c )
 
 void D3D11_Destroy(d3d11_handle_t *);
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 326d9ad1a5..ed8c8348de 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -45,7 +45,6 @@
 #else
 # include <dxgi1_5.h>
 #endif
-#include <d3dcompiler.h>
 
 /* avoided until we can pass ISwapchainPanel without c++/cx mode
 # include <windows.ui.xaml.media.dxinterop.h> */
@@ -56,7 +55,7 @@
 #include "common.h"
 
 #if !VLC_WINSTORE_APP
-# define D3DCompile(args...)                    sys->OurD3DCompile(args)
+# define D3DCompile(args...)                    sys->hd3d.OurD3DCompile(args)
 #endif
 
 DEFINE_GUID(GUID_SWAPCHAIN_WIDTH,  0xf1b59347, 0x1643, 0x411a, 0xad, 0x6b, 0xc7, 0x80, 0x17, 0x7a, 0x06, 0xb6);
@@ -122,8 +121,6 @@ struct vout_display_sys_t
 #if !VLC_WINSTORE_APP
     HINSTANCE                hdxgi_dll;        /* handle of the opened dxgi dll */
     d3d11_handle_t           hd3d;
-    HINSTANCE                hd3dcompiler_dll; /* handle of the opened d3dcompiler dll */
-    pD3DCompile                            OurD3DCompile;
 #endif
     IDXGISwapChain1          *dxgiswapChain;   /* DXGI 1.2 swap chain */
     IDXGISwapChain4          *dxgiswapChain4;  /* DXGI 1.5 for HDR */
@@ -188,7 +185,6 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned count);
 static void Prepare(vout_display_t *, picture_t *, subpicture_t *subpicture);
 static void Display(vout_display_t *, picture_t *, subpicture_t *subpicture);
 
-static HINSTANCE Direct3D11LoadShaderLibrary(void);
 static void Direct3D11Destroy(vout_display_t *);
 
 static int  Direct3D11Open (vout_display_t *);
@@ -402,23 +398,7 @@ static int OpenHwnd(vout_display_t *vd)
     if (!sys)
         return VLC_ENOMEM;
 
-    if (D3D11_Create(vd, &sys->hd3d) != VLC_SUCCESS)
-        return VLC_EGENERIC;
-
-    sys->hd3dcompiler_dll = Direct3D11LoadShaderLibrary();
-    if (!sys->hd3dcompiler_dll) {
-        msg_Err(vd, "cannot load d3dcompiler.dll, aborting");
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-
-    sys->OurD3DCompile = (void *)GetProcAddress(sys->hd3dcompiler_dll, "D3DCompile");
-    if (!sys->OurD3DCompile) {
-        msg_Err(vd, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
-        Direct3D11Destroy(vd);
-        return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
+    return D3D11_Create(vd, &sys->hd3d, true);
 }
 #else
 static int OpenCoreW(vout_display_t *vd)
@@ -1296,32 +1276,11 @@ static void Direct3D11Destroy(vout_display_t *vd)
 {
 #if !VLC_WINSTORE_APP
     vout_display_sys_t *sys = vd->sys;
-
-    if (sys->hd3dcompiler_dll)
-        FreeLibrary(sys->hd3dcompiler_dll);
-
-    sys->OurD3DCompile = NULL;
     sys->hdxgi_dll = NULL;
-    sys->hd3dcompiler_dll = NULL;
     D3D11_Destroy( &vd->sys->hd3d );
 #endif
 }
 
-#if !VLC_WINSTORE_APP
-static HINSTANCE Direct3D11LoadShaderLibrary(void)
-{
-    HINSTANCE instance = NULL;
-    /* d3dcompiler_47 is the latest on windows 8.1 */
-    for (int i = 47; i > 41; --i) {
-        TCHAR filename[19];
-        _sntprintf(filename, 19, TEXT("D3DCOMPILER_%d.dll"), i);
-        instance = LoadLibrary(filename);
-        if (instance) break;
-    }
-    return instance;
-}
-#endif
-
 #define COLOR_RANGE_FULL   1 /* 0-255 */
 #define COLOR_RANGE_STUDIO 0 /* 16-235 */
 



More information about the vlc-commits mailing list