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

Steve Lhomme git at videolan.org
Mon May 28 13:25:11 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Mon Nov 20 11:51:40 2017 +0100| [6270679d7bb9fb775659a6d9358fde7badafd341] | committer: Steve Lhomme

direct3d11: move the shader DLL loading in libd3d11_common

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

 modules/codec/avcodec/d3d11va.c         |  2 +-
 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 ++-------------------------------
 5 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 76fecbfd51..04660f4737 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -369,7 +369,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_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 373b445829..93e7c3baae 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -683,7 +683,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);
@@ -794,7 +794,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 5ea6971111..8f47a32f80 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -570,8 +570,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"));
@@ -581,6 +596,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())
     {
@@ -606,6 +639,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 75df339105..c9b86b6d6d 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
@@ -104,8 +107,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 44064ec1ed..cb11baae0f 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, mtime_t);
 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 *);
@@ -401,23 +397,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)
@@ -1264,32 +1244,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