[vlc-commits] direct3d11: move D3D11_CompileShader() in a separate file

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


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Feb 20 16:48:39 2018 +0100| [6e51e865000ce86da5c52dcd29e4024e510fc22e] | committer: Steve Lhomme

direct3d11: move D3D11_CompileShader() in a separate file

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

 modules/video_output/Makefile.am           |  3 +-
 modules/video_output/win32/d3d11_shaders.c | 84 ++++++++++++++++++++++++++++++
 modules/video_output/win32/d3d11_shaders.h | 32 ++++++++++++
 modules/video_output/win32/direct3d11.c    | 51 ++----------------
 4 files changed, 122 insertions(+), 48 deletions(-)

diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 06502f7118..a6ad7fba02 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -299,7 +299,8 @@ libdirect3d11_plugin_la_SOURCES += video_output/win32/events.c \
  video_output/win32/events.h \
  video_output/win32/sensors.cpp \
  video_output/win32/win32touch.c video_output/win32/win32touch.h \
- video_output/win32/d3d11_quad.c video_output/win32/d3d11_quad.h
+ video_output/win32/d3d11_quad.c video_output/win32/d3d11_quad.h \
+ video_output/win32/d3d11_shaders.c video_output/win32/d3d11_shaders.h
 libdirect3d11_plugin_la_LIBADD += -lgdi32
 else
 libdirect3d11_plugin_la_LIBADD += -ld3d11
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
new file mode 100644
index 0000000000..219b94e706
--- /dev/null
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * d3d11_shaders.c: Direct3D11 Shaders
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ *
+ * Authors: Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#if !defined(_WIN32_WINNT) || _WIN32_WINNT < _WIN32_WINNT_WIN7
+# undef _WIN32_WINNT
+# define _WIN32_WINNT _WIN32_WINNT_WIN7
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+
+#include <assert.h>
+
+#define COBJMACROS
+#include <d3d11.h>
+
+#include "d3d11_shaders.h"
+
+#if !VLC_WINSTORE_APP
+# define D3DCompile(args...)                    hd3d->OurD3DCompile(args)
+#endif
+
+#undef D3D11_CompileShader
+ID3DBlob* D3D11_CompileShader(vlc_object_t *obj, const d3d11_handle_t *hd3d, const d3d11_device_t *d3d_dev,
+                              const char *psz_shader, bool pixel)
+{
+    ID3DBlob* pShaderBlob = NULL, *pErrBlob;
+    const char *target;
+    if (pixel)
+    {
+        if (likely(d3d_dev->feature_level >= D3D_FEATURE_LEVEL_10_0))
+            target = "ps_4_0";
+        else if (d3d_dev->feature_level >= D3D_FEATURE_LEVEL_9_3)
+            target = "ps_4_0_level_9_3";
+        else
+            target = "ps_4_0_level_9_1";
+    }
+    else
+    {
+        if (likely(d3d_dev->feature_level >= D3D_FEATURE_LEVEL_10_0))
+            target = "vs_4_0";
+        else if (d3d_dev->feature_level >= D3D_FEATURE_LEVEL_9_3)
+            target = "vs_4_0_level_9_3";
+        else
+            target = "vs_4_0_level_9_1";
+    }
+
+    HRESULT hr = D3DCompile(psz_shader, strlen(psz_shader),
+                            NULL, NULL, NULL, "main", target,
+                            0, 0, &pShaderBlob, &pErrBlob);
+
+    if (FAILED(hr)) {
+        char *err = pErrBlob ? ID3D10Blob_GetBufferPointer(pErrBlob) : NULL;
+        msg_Err(obj, "invalid %s Shader (hr=0x%lX): %s", pixel?"Pixel":"Vertex", hr, err );
+        if (pErrBlob)
+            ID3D10Blob_Release(pErrBlob);
+        return NULL;
+    }
+    return pShaderBlob;
+}
+
+
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
new file mode 100644
index 0000000000..6bb23f9dfc
--- /dev/null
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * d3d11_shaders.h: Direct3D11 Shaders
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ *
+ * Authors: Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_D3D11_SHADERS_H
+#define VLC_D3D11_SHADERS_H
+
+#include "../../video_chroma/d3d11_fmt.h"
+
+ID3DBlob* D3D11_CompileShader(vlc_object_t *, const d3d11_handle_t *, const d3d11_device_t *,
+                              const char *psz_shader, bool pixel);
+#define D3D11_CompileShader(a,b,c,d,e)  D3D11_CompileShader(VLC_OBJECT(a),b,c,d,e)
+
+#endif /* VLC_D3D11_SHADERS_H */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index ca9bd95bfa..eb8b427031 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -51,13 +51,10 @@
 
 #include "../../video_chroma/d3d11_fmt.h"
 #include "d3d11_quad.h"
+#include "d3d11_shaders.h"
 
 #include "common.h"
 
-#if !VLC_WINSTORE_APP
-# define D3DCompile(args...)                    hd3d->OurD3DCompile(args)
-#endif
-
 DEFINE_GUID(GUID_SWAPCHAIN_WIDTH,  0xf1b59347, 0x1643, 0x411a, 0xad, 0x6b, 0xc7, 0x80, 0x17, 0x7a, 0x06, 0xb6);
 DEFINE_GUID(GUID_SWAPCHAIN_HEIGHT, 0x6ea976a0, 0x9d60, 0x4bb7, 0xa5, 0xa9, 0x7d, 0xd1, 0x18, 0x7f, 0xc9, 0xbd);
 
@@ -1649,44 +1646,6 @@ static void UpdatePicQuadPosition(vout_display_t *vd)
 #endif
 }
 
-static ID3DBlob* D3D11_CompileShader(vlc_object_t *obj, const d3d11_handle_t *hd3d, const d3d11_device_t *d3d_dev,
-                                     const char *psz_shader, bool pixel, bool legacy_shader)
-{
-    ID3DBlob* pShaderBlob = NULL, *pErrBlob;
-    const char *target;
-    if (pixel)
-    {
-        if (likely(d3d_dev->feature_level >= D3D_FEATURE_LEVEL_10_0))
-            target = "ps_4_0";
-        else if (d3d_dev->feature_level >= D3D_FEATURE_LEVEL_9_3)
-            target = "ps_4_0_level_9_3";
-        else
-            target = "ps_4_0_level_9_1";
-    }
-    else
-    {
-        if (likely(d3d_dev->feature_level >= D3D_FEATURE_LEVEL_10_0))
-            target = "vs_4_0";
-        else if (d3d_dev->feature_level >= D3D_FEATURE_LEVEL_9_3)
-            target = "vs_4_0_level_9_3";
-        else
-            target = "vs_4_0_level_9_1";
-    }
-
-    HRESULT hr = D3DCompile(psz_shader, strlen(psz_shader),
-                            NULL, NULL, NULL, "main", target,
-                            0, 0, &pShaderBlob, &pErrBlob);
-
-    if (FAILED(hr)) {
-        char *err = pErrBlob ? ID3D10Blob_GetBufferPointer(pErrBlob) : NULL;
-        msg_Err(obj, "invalid %s Shader (hr=0x%lX): %s", pixel?"Pixel":"Vertex", hr, err );
-        if (pErrBlob)
-            ID3D10Blob_Release(pErrBlob);
-        return NULL;
-    }
-    return pShaderBlob;
-}
-
 static bool IsRGBShader(const d3d_format_t *cfg)
 {
     return cfg->resourceFormat[0] != DXGI_FORMAT_R8_UNORM &&
@@ -1932,7 +1891,7 @@ static HRESULT D3D11_CompilePixelShader(vlc_object_t *vd, d3d11_handle_t *hd3d,
 #endif
     free(psz_range);
 
-    ID3DBlob *pPSBlob = D3D11_CompileShader(VLC_OBJECT(vd), hd3d, d3d_dev, shader, true, legacy_shader);
+    ID3DBlob *pPSBlob = D3D11_CompileShader(vd, hd3d, d3d_dev, shader, true);
     free(shader);
     if (!pPSBlob)
         return E_INVALIDARG;
@@ -2111,8 +2070,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
         }
     }
 
-    ID3DBlob *pVSBlob = D3D11_CompileShader(VLC_OBJECT(vd), &sys->hd3d, &sys->d3d_dev, globVertexShaderFlat,
-                                            false, sys->legacy_shader);
+    ID3DBlob *pVSBlob = D3D11_CompileShader(vd, &sys->hd3d, &sys->d3d_dev, globVertexShaderFlat, false);
     if (!pVSBlob)
         return VLC_EGENERIC;
 
@@ -2143,8 +2101,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
     ID3D11DeviceContext_IASetInputLayout(sys->d3d_dev.d3dcontext, pVertexLayout);
     ID3D11InputLayout_Release(pVertexLayout);
 
-    pVSBlob = D3D11_CompileShader(VLC_OBJECT(vd), &sys->hd3d, &sys->d3d_dev, globVertexShaderProjection,
-                                  false, sys->legacy_shader);
+    pVSBlob = D3D11_CompileShader(vd, &sys->hd3d, &sys->d3d_dev, globVertexShaderProjection, false);
     if (!pVSBlob)
         return VLC_EGENERIC;
 



More information about the vlc-commits mailing list