vlc/vlc-3.0 | branch: master | Steve Lhomme <[email protected]> | Tue Feb 20 16:48:39 2018 +0100| [02fadfcd4c92312489e67c4e7e94525981d521a6] | committer: Steve Lhomme
direct3d11: move D3D11_CompileShader() in a separate file (cherry picked from commit 6e51e865000ce86da5c52dcd29e4024e510fc22e) > http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=02fadfcd4c92312489e67c4e7e94525981d521a6 --- 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 0e00e8fbea..7790b1d8e9 100644 --- a/modules/video_output/Makefile.am +++ b/modules/video_output/Makefile.am @@ -276,7 +276,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 <[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. + *****************************************************************************/ + +#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 <[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_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 eb0b2c1cd5..339e1e9470 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); @@ -1674,44 +1671,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 && @@ -1957,7 +1916,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; @@ -2130,8 +2089,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; @@ -2162,8 +2120,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; _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
