[vlc-commits] d3d11_shaders: initialize the shaders loader separately

Steve Lhomme git at videolan.org
Wed Feb 12 16:44:41 CET 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Feb 12 14:42:14 2020 +0100| [b6b7dcca5a262ae0668636c1870e19b141cbc596] | committer: Steve Lhomme

d3d11_shaders: initialize the shaders loader separately

Only the display module actually needs to get it for now.

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

 modules/codec/avcodec/d3d11va.c            |  2 +-
 modules/hw/d3d11/d3d11_deinterlace.c       |  2 +-
 modules/hw/d3d11/d3d11_device.c            |  2 +-
 modules/video_chroma/d3d11_fmt.c           | 41 +-------------------------
 modules/video_chroma/d3d11_fmt.h           | 12 ++------
 modules/video_output/win32/d3d11_shaders.c | 47 ++++++++++++++++++++++++++++++
 modules/video_output/win32/d3d11_shaders.h | 10 +++++++
 modules/video_output/win32/direct3d11.c    | 16 ++++++----
 8 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 24d6c370c3..320864d0a8 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -264,7 +264,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
-    err = D3D11_Create( va, &sys->hd3d, false );
+    err = D3D11_Create( va, &sys->hd3d );
     if (err != VLC_SUCCESS)
         goto error;
 
diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 7ea90c7698..48031bf464 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -256,7 +256,7 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
         return VLC_ENOMEM;
     memset(sys, 0, sizeof (*sys));
 
-    if ( unlikely(D3D11_Create(filter, &sys->hd3d, false) != VLC_SUCCESS ))
+    if ( unlikely(D3D11_Create(filter, &sys->hd3d) != VLC_SUCCESS ))
     {
        msg_Err(filter, "Could not access the d3d11.");
        goto error;
diff --git a/modules/hw/d3d11/d3d11_device.c b/modules/hw/d3d11/d3d11_device.c
index bec6670891..88605614df 100644
--- a/modules/hw/d3d11/d3d11_device.c
+++ b/modules/hw/d3d11/d3d11_device.c
@@ -77,7 +77,7 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
     if (unlikely(sys==NULL))
         return VLC_ENOMEM;
 
-    int ret = D3D11_Create(device, &sys->hd3d, true);
+    int ret = D3D11_Create(device, &sys->hd3d);
     if (ret != VLC_SUCCESS)
         return ret;
 
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 7a63fa52c7..523cf2c827 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -674,23 +674,8 @@ 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) {
-        WCHAR filename[19];
-        _snwprintf(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, bool with_shaders)
+int D3D11_Create(vlc_object_t *obj, d3d11_handle_t *hd3d)
 {
 #if !VLC_WINSTORE_APP
     hd3d->hdll = LoadLibrary(TEXT("D3D11.DLL"));
@@ -700,23 +685,6 @@ int D3D11_Create(vlc_object_t *obj, d3d11_handle_t *hd3d, bool with_shaders)
         return VLC_EGENERIC;
     }
 
-    if (with_shaders)
-    {
-        hd3d->shaders.compiler_dll = Direct3D11LoadShaderLibrary();
-        if (!hd3d->shaders.compiler_dll) {
-            msg_Err(obj, "cannot load d3dcompiler.dll, aborting");
-            FreeLibrary(hd3d->hdll);
-            return VLC_EGENERIC;
-        }
-
-        hd3d->shaders.OurD3DCompile = (void *)GetProcAddress(hd3d->shaders.compiler_dll, "D3DCompile");
-        if (!hd3d->shaders.OurD3DCompile) {
-            msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
-            FreeLibrary(hd3d->shaders.compiler_dll);
-            FreeLibrary(hd3d->hdll);
-            return VLC_EGENERIC;
-        }
-    }
 # if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     hd3d->dxgidebug_dll = NULL;
     hd3d->pf_DXGIGetDebugInterface = NULL;
@@ -760,13 +728,6 @@ void D3D11_Destroy(d3d11_handle_t *hd3d)
     if (hd3d->hdll)
         FreeLibrary(hd3d->hdll);
 
-    if (hd3d->shaders.compiler_dll)
-    {
-        FreeLibrary(hd3d->shaders.compiler_dll);
-        hd3d->shaders.compiler_dll = NULL;
-    }
-    hd3d->shaders.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 f8ff31724a..e969ba04dd 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -26,7 +26,6 @@
 #include <vlc_codec.h>
 
 #include <d3d11.h>
-#include <d3dcompiler.h>
 
 #include "dxgi_fmt.h"
 
@@ -54,17 +53,10 @@ typedef struct
     DXGI_ADAPTER_DESC        adapterDesc;
 } d3d11_device_t;
 
-typedef struct
-{
-    HINSTANCE                 compiler_dll; /* handle of the opened d3dcompiler dll */
-    pD3DCompile               OurD3DCompile;
-} d3d11_shaders_t;
-
 typedef struct
 {
 #if !VLC_WINSTORE_APP
     HINSTANCE                 hdll;         /* handle of the opened d3d11 dll */
-    d3d11_shaders_t           shaders;
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     HINSTANCE                 dxgidebug_dll;
     HRESULT (WINAPI * pf_DXGIGetDebugInterface)(const GUID *riid, void **ppDebug);
@@ -167,8 +159,8 @@ HRESULT D3D11_CreateDeviceExternal(vlc_object_t *obj, ID3D11DeviceContext *,
 
 void D3D11_ReleaseDevice(d3d11_device_t *);
 
-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 )
+int D3D11_Create(vlc_object_t *, d3d11_handle_t *);
+#define D3D11_Create(a,b) D3D11_Create( VLC_OBJECT(a), b )
 
 void D3D11_Destroy(d3d11_handle_t *);
 void D3D11_LogResources(d3d11_handle_t *);
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 49c80e607f..09826bf521 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -832,3 +832,50 @@ HRESULT (D3D11_CompileProjectionVertexShader)(vlc_object_t *obj, const d3d11_sha
 {
     return D3D11_CompileVertexShader(obj, shaders, d3d_dev, globVertexShaderProjection, output);
 }
+
+#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) {
+        WCHAR filename[19];
+        _snwprintf(filename, 19, TEXT("D3DCOMPILER_%d.dll"), i);
+        instance = LoadLibrary(filename);
+        if (instance) break;
+    }
+    return instance;
+}
+#endif // !VLC_WINSTORE_APP
+
+int (D3D11_InitShaders)(vlc_object_t *obj, d3d11_shaders_t *shaders)
+{
+#if !VLC_WINSTORE_APP
+    shaders->compiler_dll = Direct3D11LoadShaderLibrary();
+    if (!shaders->compiler_dll) {
+        msg_Err(obj, "cannot load d3dcompiler.dll, aborting");
+        return VLC_EGENERIC;
+    }
+
+    shaders->OurD3DCompile = (void *)GetProcAddress(shaders->compiler_dll, "D3DCompile");
+    if (!shaders->OurD3DCompile) {
+        msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL");
+        FreeLibrary(shaders->compiler_dll);
+        return VLC_EGENERIC;
+    }
+#endif // !VLC_WINSTORE_APP
+
+    return VLC_SUCCESS;
+}
+
+void D3D11_ReleaseShaders(d3d11_shaders_t *shaders)
+{
+#if !VLC_WINSTORE_APP
+    if (shaders->compiler_dll)
+    {
+        FreeLibrary(shaders->compiler_dll);
+        shaders->compiler_dll = NULL;
+    }
+    shaders->OurD3DCompile = NULL;
+#endif // !VLC_WINSTORE_APP
+}
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 16e24b6b13..7712c3eff3 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -23,8 +23,15 @@
 #ifndef VLC_D3D11_SHADERS_H
 #define VLC_D3D11_SHADERS_H
 
+#include <d3dcompiler.h>
 #include "../../video_chroma/d3d11_fmt.h"
 
+typedef struct
+{
+    HINSTANCE                 compiler_dll; /* handle of the opened d3dcompiler dll */
+    pD3DCompile               OurD3DCompile;
+} d3d11_shaders_t;
+
 #include <vlc_es.h>
 
 #define DEFAULT_BRIGHTNESS         100
@@ -98,6 +105,9 @@ typedef struct
 
 bool IsRGBShader(const d3d_format_t *);
 
+int D3D11_InitShaders(vlc_object_t *, d3d11_shaders_t *);
+void D3D11_ReleaseShaders(d3d11_shaders_t *);
+
 HRESULT D3D11_CompilePixelShader(vlc_object_t *, const d3d11_shaders_t *, bool legacy_shader,
                                  d3d11_device_t *, const display_info_t *,
                                  video_transfer_func_t, video_color_primaries_t,
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 3a870f787b..0e3e0c8696 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -98,6 +98,7 @@ struct vout_display_sys_t
     d3d11_handle_t           hd3d;
     d3d11_device_t           *d3d_dev;
     d3d11_device_t           local_d3d_dev; // when opened without a video context
+    d3d11_shaders_t          shaders;
     d3d_quad_t               picQuad;
 
     ID3D11Query              *prepareWait;
@@ -307,10 +308,14 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     if (!sys)
         return VLC_ENOMEM;
 
-    int ret = D3D11_Create(vd, &sys->hd3d, true);
+    int ret = D3D11_Create(vd, &sys->hd3d);
     if (ret != VLC_SUCCESS)
         return ret;
 
+    ret = D3D11_InitShaders(VLC_OBJECT(vd), &sys->shaders);
+    if (ret != VLC_SUCCESS)
+        goto error;
+
     CommonInit(vd, &sys->area, cfg);
 
     sys->outside_opaque = var_InheritAddress( vd, "vout-cb-opaque" );
@@ -394,6 +399,7 @@ error:
 
 static void Close(vout_display_t *vd)
 {
+    D3D11_ReleaseShaders(&vd->sys->shaders);
     Direct3D11Close(vd);
     UnhookWindowsSensors(vd->sys->p_sensors);
 #if !VLC_WINSTORE_APP
@@ -1071,7 +1077,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
     sys->legacy_shader = sys->d3d_dev->feature_level < D3D_FEATURE_LEVEL_10_0 || !CanUseTextureArray(vd) ||
             BogusZeroCopy(vd);
 
-    hr = D3D11_CompilePixelShader(vd, &sys->hd3d.shaders, sys->legacy_shader, sys->d3d_dev,
+    hr = D3D11_CompilePixelShader(vd, &sys->shaders, sys->legacy_shader, sys->d3d_dev,
                                   &sys->display, fmt->transfer, fmt->primaries,
                                   fmt->color_range == COLOR_RANGE_FULL,
                                   &sys->picQuad);
@@ -1188,7 +1194,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
 
     if (sys->regionQuad.textureFormat != NULL)
     {
-        hr = D3D11_CompilePixelShader(vd, &sys->hd3d.shaders, sys->legacy_shader, sys->d3d_dev,
+        hr = D3D11_CompilePixelShader(vd, &sys->shaders, sys->legacy_shader, sys->d3d_dev,
                                       &sys->display, TRANSFER_FUNC_SRGB, COLOR_PRIMARIES_SRGB, true,
                                       &sys->regionQuad);
         if (FAILED(hr))
@@ -1199,13 +1205,13 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
         }
     }
 
-    hr = D3D11_CompileFlatVertexShader(vd, &sys->hd3d.shaders, sys->d3d_dev, &sys->flatVShader);
+    hr = D3D11_CompileFlatVertexShader(vd, &sys->shaders, sys->d3d_dev, &sys->flatVShader);
     if(FAILED(hr)) {
       msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
       return VLC_EGENERIC;
     }
 
-    hr = D3D11_CompileProjectionVertexShader(vd, &sys->hd3d.shaders, sys->d3d_dev, &sys->projectionVShader);
+    hr = D3D11_CompileProjectionVertexShader(vd, &sys->shaders, sys->d3d_dev, &sys->projectionVShader);
     if(FAILED(hr)) {
       msg_Err(vd, "Failed to create the projection vertex shader. (hr=0x%lX)", hr);
       return VLC_EGENERIC;



More information about the vlc-commits mailing list