vlc | branch: master | Steve Lhomme <[email protected]> | Tue Feb 9 15:48:45 2021 +0100| [6c312eba4f0d8a7353f87749a47d3b07f9adf9ce] | committer: Steve Lhomme
direct3d11: move the shader compiler handling in a separate file The shader compiler doesn't depend on the D3D version. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6c312eba4f0d8a7353f87749a47d3b07f9adf9ce --- modules/video_output/Makefile.am | 1 + modules/video_output/win32/d3d11_shaders.c | 47 ------------------ modules/video_output/win32/d3d11_shaders.h | 12 +---- modules/video_output/win32/d3d_shaders.c | 76 ++++++++++++++++++++++++++++++ modules/video_output/win32/d3d_shaders.h | 37 +++++++++++++++ modules/video_output/win32/direct3d11.c | 4 +- 6 files changed, 118 insertions(+), 59 deletions(-) diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am index 36658aa4d7..5900db1c19 100644 --- a/modules/video_output/Makefile.am +++ b/modules/video_output/Makefile.am @@ -134,6 +134,7 @@ endif libdirect3d11_plugin_la_SOURCES = video_output/win32/direct3d11.c \ video_output/win32/d3d11_quad.c video_output/win32/d3d11_quad.h \ video_output/win32/d3d11_shaders.c video_output/win32/d3d11_shaders.h \ + video_output/win32/d3d_shaders.c video_output/win32/d3d_shaders.h \ video_output/win32/d3d11_swapchain.c video_output/win32/d3d11_swapchain.h \ video_output/win32/dxgi_swapchain.c video_output/win32/dxgi_swapchain.h \ video_output/win32/common.c video_output/win32/common.h diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c index 42e4dc1d77..11d6c979da 100644 --- a/modules/video_output/win32/d3d11_shaders.c +++ b/modules/video_output/win32/d3d11_shaders.c @@ -840,50 +840,3 @@ HRESULT (D3D11_CompileProjectionVertexShader)(vlc_object_t *obj, const d3d_shade { return D3D11_CompileVertexShader(obj, compiler, 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, d3d_shader_compiler_t *compiler) -{ -#if !VLC_WINSTORE_APP - compiler->compiler_dll = Direct3D11LoadShaderLibrary(); - if (!compiler->compiler_dll) { - msg_Err(obj, "cannot load d3dcompiler.dll, aborting"); - return VLC_EGENERIC; - } - - compiler->OurD3DCompile = (void *)GetProcAddress(compiler->compiler_dll, "D3DCompile"); - if (!compiler->OurD3DCompile) { - msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL"); - FreeLibrary(compiler->compiler_dll); - return VLC_EGENERIC; - } -#endif // !VLC_WINSTORE_APP - - return VLC_SUCCESS; -} - -void D3D11_ReleaseShaders(d3d_shader_compiler_t *compiler) -{ -#if !VLC_WINSTORE_APP - if (compiler->compiler_dll) - { - FreeLibrary(compiler->compiler_dll); - compiler->compiler_dll = NULL; - } - compiler->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 dc0f89b7f3..e019efc19e 100644 --- a/modules/video_output/win32/d3d11_shaders.h +++ b/modules/video_output/win32/d3d11_shaders.h @@ -23,17 +23,12 @@ #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; -} d3d_shader_compiler_t; - #include <vlc_es.h> +#include "d3d_shaders.h" + #define DEFAULT_BRIGHTNESS 100 #define DEFAULT_SRGB_BRIGHTNESS 100 #define MAX_HLG_BRIGHTNESS 1000 @@ -102,9 +97,6 @@ typedef struct VS_PROJECTION_CONST vertexConstants; } d3d11_quad_t; -int D3D11_InitShaders(vlc_object_t *, d3d_shader_compiler_t *); -void D3D11_ReleaseShaders(d3d_shader_compiler_t *); - HRESULT D3D11_CompilePixelShader(vlc_object_t *, const d3d_shader_compiler_t *, d3d11_device_t *, bool texture_array, size_t texture_count, const display_info_t *, bool sharp, diff --git a/modules/video_output/win32/d3d_shaders.c b/modules/video_output/win32/d3d_shaders.c new file mode 100644 index 0000000000..5d8ac4adc3 --- /dev/null +++ b/modules/video_output/win32/d3d_shaders.c @@ -0,0 +1,76 @@ +/***************************************************************************** + * d3d_shaders.c: Direct3D Shader APIs + ***************************************************************************** + * Copyright (C) 2017-2021 VLC authors and VideoLAN + * + * Authors: Steve Lhomme <[email protected]> + * + * 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. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <vlc_common.h> + +#include "d3d_shaders.h" + +#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 (D3D_InitShaders)(vlc_object_t *obj, d3d_shader_compiler_t *compiler) +{ +#if !VLC_WINSTORE_APP + compiler->compiler_dll = Direct3D11LoadShaderLibrary(); + if (!compiler->compiler_dll) { + msg_Err(obj, "cannot load d3dcompiler.dll, aborting"); + return VLC_EGENERIC; + } + + compiler->OurD3DCompile = (void *)GetProcAddress(compiler->compiler_dll, "D3DCompile"); + if (!compiler->OurD3DCompile) { + msg_Err(obj, "Cannot locate reference to D3DCompile in d3dcompiler DLL"); + FreeLibrary(compiler->compiler_dll); + return VLC_EGENERIC; + } +#endif // !VLC_WINSTORE_APP + + return VLC_SUCCESS; +} + +void D3D_ReleaseShaders(d3d_shader_compiler_t *compiler) +{ +#if !VLC_WINSTORE_APP + if (compiler->compiler_dll) + { + FreeLibrary(compiler->compiler_dll); + compiler->compiler_dll = NULL; + } + compiler->OurD3DCompile = NULL; +#endif // !VLC_WINSTORE_APP +} diff --git a/modules/video_output/win32/d3d_shaders.h b/modules/video_output/win32/d3d_shaders.h new file mode 100644 index 0000000000..227859d1db --- /dev/null +++ b/modules/video_output/win32/d3d_shaders.h @@ -0,0 +1,37 @@ +/***************************************************************************** + * d3d_shaders.h: Direct3D Shaders + ***************************************************************************** + * Copyright (C) 2017-2021 VLC authors and VideoLAN + * + * Authors: Steve Lhomme <[email protected]> + * + * 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_D3D_SHADERS_H +#define VLC_D3D_SHADERS_H + +#include <d3dcompiler.h> // for pD3DCompile + +typedef struct +{ + HINSTANCE compiler_dll; /* handle of the opened d3dcompiler dll */ + pD3DCompile OurD3DCompile; +} d3d_shader_compiler_t; + +int D3D_InitShaders(vlc_object_t *, d3d_shader_compiler_t *); +void D3D_ReleaseShaders(d3d_shader_compiler_t *); + +#endif /* VLC_D3D_SHADERS_H */ diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c index f34602cde4..24ab12d7c2 100644 --- a/modules/video_output/win32/direct3d11.c +++ b/modules/video_output/win32/direct3d11.c @@ -358,7 +358,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg, if (!sys) return VLC_ENOMEM; - int ret = D3D11_InitShaders(VLC_OBJECT(vd), &sys->shaders); + int ret = D3D_InitShaders(VLC_OBJECT(vd), &sys->shaders); if (ret != VLC_SUCCESS) goto error; @@ -450,7 +450,7 @@ error: static void Close(vout_display_t *vd) { - D3D11_ReleaseShaders(&vd->sys->shaders); + D3D_ReleaseShaders(&vd->sys->shaders); Direct3D11Close(vd); #if !VLC_WINSTORE_APP UnhookWindowsSensors(vd->sys->p_sensors); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
