From 2ec8d88d804c664e6dc70ea0d875ff7553b91350 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 16 Dec 2015 23:05:58 +0000 Subject: [PATCH] gsdx-d3d11: Remove d3dx11 stuff and use d3dcompile Using D3DX11 requires the end user to install the DirectX redist files. Switch to using D3DCompile, and distribute D3DCompiler_47.dll for Windows Vista, 7 and 8 users (Windows 8.1 onwards supplies D3DCompiler_47.dll with the OS). --- plugins/GSdx/GSDevice11.cpp | 57 +++++++++++++++---------------- plugins/GSdx/GSDevice11.h | 10 +++--- plugins/GSdx/GSRendererCS.cpp | 16 ++++----- plugins/GSdx/GSTextureFX11.cpp | 12 +++---- plugins/GSdx/stdafx.h | 3 -- plugins/GSdx/vsprops/common.props | 8 ++--- 6 files changed, 51 insertions(+), 55 deletions(-) diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp index e15a44e314..12fe4c4202 100644 --- a/plugins/GSdx/GSDevice11.cpp +++ b/plugins/GSdx/GSDevice11.cpp @@ -175,11 +175,11 @@ bool GSDevice11::Create(GSWnd* wnd) vector shader; theApp.LoadResource(IDR_CONVERT_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "convert.fx", "vs_main", NULL, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il); + CompileShader((const char *)shader.data(), shader.size(), "convert.fx", nullptr, "vs_main", nullptr, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il); for(size_t i = 0; i < countof(m_convert.ps); i++) { - CompileShader((const char *)shader.data(), shader.size(), "convert.fx", format("ps_main%d", i).c_str(), NULL, &m_convert.ps[i]); + CompileShader((const char *)shader.data(), shader.size(), "convert.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_convert.ps[i]); } memset(&dsd, 0, sizeof(dsd)); @@ -208,7 +208,7 @@ bool GSDevice11::Create(GSWnd* wnd) theApp.LoadResource(IDR_MERGE_FX, shader); for(size_t i = 0; i < countof(m_merge.ps); i++) { - CompileShader((const char *)shader.data(), shader.size(), "merge.fx", format("ps_main%d", i).c_str(), NULL, &m_merge.ps[i]); + CompileShader((const char *)shader.data(), shader.size(), "merge.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_merge.ps[i]); } memset(&bsd, 0, sizeof(bsd)); @@ -237,7 +237,7 @@ bool GSDevice11::Create(GSWnd* wnd) theApp.LoadResource(IDR_INTERLACE_FX, shader); for(size_t i = 0; i < countof(m_interlace.ps); i++) { - CompileShader((const char *)shader.data(), shader.size(), "interlace.fx", format("ps_main%d", i).c_str(), NULL, &m_interlace.ps[i]); + CompileShader((const char *)shader.data(), shader.size(), "interlace.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_interlace.ps[i]); } // Shade Boost @@ -252,7 +252,7 @@ bool GSDevice11::Create(GSWnd* wnd) str[1] = format("%d", ShadeBoost_Brightness); str[2] = format("%d", ShadeBoost_Contrast); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"SB_SATURATION", str[0].c_str()}, {"SB_BRIGHTNESS", str[1].c_str()}, @@ -269,7 +269,7 @@ bool GSDevice11::Create(GSWnd* wnd) hr = m_dev->CreateBuffer(&bd, NULL, &m_shadeboost.cb); theApp.LoadResource(IDR_SHADEBOOST_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "shadeboost.fx", "ps_main", macro, &m_shadeboost.ps); + CompileShader((const char *)shader.data(), shader.size(), "shadeboost.fx", nullptr, "ps_main", macro, &m_shadeboost.ps); // External fx shader @@ -768,7 +768,7 @@ void GSDevice11::InitExternalFX() if (fshader.good()) { shader << fshader.rdbuf(); - CompileShader(shader.str().c_str(), shader.str().length(), shader_name.c_str(), "ps_main", NULL, &m_shaderfx.ps); + CompileShader(shader.str().c_str(), shader.str().length(), shader_name.c_str(), D3D_COMPILE_STANDARD_FILE_INCLUDE, "ps_main", nullptr, &m_shaderfx.ps); } else { @@ -811,7 +811,7 @@ void GSDevice11::InitFXAA() try { vector shader; theApp.LoadResource(IDR_FXAA_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "fxaa.fx", "ps_main", NULL, &m_fxaa.ps); + CompileShader((const char *)shader.data(), shader.size(), "fxaa.fx", nullptr, "ps_main", nullptr, &m_fxaa.ps); } catch (GSDXRecoverableError) { printf("GSdx: failed to compile fxaa shader.\n"); @@ -1324,17 +1324,17 @@ void GSDevice11::OMSetRenderTargets(const GSVector2i& rtsize, int count, ID3D11U } } -void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il) +void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il) { HRESULT hr; - vector m; + vector m; PrepareShaderMacro(m, macro); - CComPtr shader, error; + CComPtr shader, error; - hr = D3DX11CompileFromMemory(source, size, fn, &m[0], NULL, entry, m_shader.vs.c_str(), 0, 0, NULL, &shader, &error, NULL); + hr = s_pD3DCompile(source, size, fn, &m[0], s_old_d3d_compiler_dll? nullptr : include, entry, m_shader.vs.c_str(), 0, 0, &shader, &error); if(error) { @@ -1361,17 +1361,17 @@ void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, } } -void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs) +void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs) { HRESULT hr; - vector m; + vector m; PrepareShaderMacro(m, macro); - CComPtr shader, error; + CComPtr shader, error; - hr = D3DX11CompileFromMemory(source, size, fn, &m[0], NULL, entry, m_shader.gs.c_str(), 0, 0, NULL, &shader, &error, NULL); + hr = s_pD3DCompile(source, size, fn, &m[0], s_old_d3d_compiler_dll ? nullptr : include, entry, m_shader.gs.c_str(), 0, 0, &shader, &error); if(error) { @@ -1391,17 +1391,17 @@ void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, } } -void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count) +void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count) { HRESULT hr; - vector m; + vector m; PrepareShaderMacro(m, macro); - CComPtr shader, error; + CComPtr shader, error; - hr = D3DX11CompileFromMemory(source, size, fn, &m[0], NULL, entry, m_shader.gs.c_str(), 0, 0, NULL, &shader, &error, NULL); + hr = s_pD3DCompile(source, size, fn, &m[0], s_old_d3d_compiler_dll ? nullptr : include, entry, m_shader.gs.c_str(), 0, 0, &shader, &error); if(error) { @@ -1421,17 +1421,17 @@ void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, } } -void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps) +void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps) { HRESULT hr; - vector m; + vector m; PrepareShaderMacro(m, macro); - CComPtr shader, error; + CComPtr shader, error; - hr = D3DX11CompileFromMemory(source, size, fn, &m[0], NULL, entry, m_shader.ps.c_str(), 0, 0, NULL, &shader, &error, NULL); + hr = s_pD3DCompile(source, size, fn, &m[0], s_old_d3d_compiler_dll ? nullptr : include, entry, m_shader.ps.c_str(), 0, 0, &shader, &error); if(error) { @@ -1451,17 +1451,17 @@ void GSDevice11::CompileShader(const char* source, size_t size, const char* fn, } } -void GSDevice11::CompileShader(const char* source, size_t size, const char *fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs) +void GSDevice11::CompileShader(const char* source, size_t size, const char *fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11ComputeShader** cs) { HRESULT hr; - vector m; + vector m; PrepareShaderMacro(m, macro); - CComPtr shader, error; + CComPtr shader, error; - hr = D3DX11CompileFromMemory(source, size, fn, &m[0], NULL, entry, m_shader.cs.c_str(), 0, 0, NULL, &shader, &error, NULL); + hr = s_pD3DCompile(source, size, fn, &m[0], s_old_d3d_compiler_dll ? nullptr : include, entry, m_shader.cs.c_str(), 0, 0, &shader, &error); if(error) { @@ -1480,4 +1480,3 @@ void GSDevice11::CompileShader(const char* source, size_t size, const char *fn, throw GSDXRecoverableError(); } } - diff --git a/plugins/GSdx/GSDevice11.h b/plugins/GSdx/GSDevice11.h index 30413f0d55..06ef75f230 100644 --- a/plugins/GSdx/GSDevice11.h +++ b/plugins/GSdx/GSDevice11.h @@ -227,10 +227,10 @@ public: operator ID3D11Device*() {return m_dev;} operator ID3D11DeviceContext*() {return m_ctx;} - void CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il); - void CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs); - void CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count); - void CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps); - void CompileShader(const char* source, size_t size, const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs); + void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il); + void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs); + void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count); + void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps); + void CompileShader(const char* source, size_t size, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11ComputeShader** cs); }; diff --git a/plugins/GSdx/GSRendererCS.cpp b/plugins/GSdx/GSRendererCS.cpp index de09cd5f9c..86b1e23b07 100644 --- a/plugins/GSdx/GSRendererCS.cpp +++ b/plugins/GSdx/GSRendererCS.cpp @@ -288,7 +288,7 @@ bool GSRendererCS::CreateDevice(GSDevice* dev_unk) // PS - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {NULL, NULL}, }; @@ -297,7 +297,7 @@ bool GSRendererCS::CreateDevice(GSDevice* dev_unk) { vector shader; theApp.LoadResource(IDR_CS_FX, shader); - dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", "ps_main0", macro, &m_ps0); + dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", nullptr, "ps_main0", macro, &m_ps0); } catch (GSDXRecoverableError) { @@ -514,7 +514,7 @@ void GSRendererCS::Draw() str[0] = format("%d", vs_sel.tme); str[1] = format("%d", vs_sel.fst); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"VS_TME", str[0].c_str()}, {"VS_FST", str[1].c_str()}, @@ -534,7 +534,7 @@ void GSRendererCS::Draw() vector shader; theApp.LoadResource(IDR_CS_FX, shader); - dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); + dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", nullptr, "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); m_vs[vs_sel] = vs; } @@ -571,7 +571,7 @@ void GSRendererCS::Draw() str[0] = format("%d", gs_sel.iip); str[1] = format("%d", j == 0 ? gs_sel.prim : GS_SPRITE_CLASS); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"GS_IIP", str[0].c_str()}, {"GS_PRIM", str[1].c_str()}, @@ -580,7 +580,7 @@ void GSRendererCS::Draw() vector shader; theApp.LoadResource(IDR_CS_FX, shader); - dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", "gs_main", macro, &gs[j]); + dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", nullptr, "gs_main", macro, &gs[j]); m_gs[gs_sel] = gs[j]; } @@ -611,7 +611,7 @@ void GSRendererCS::Draw() str[1] = format("%d", context->FRAME.PSM); str[2] = format("%d", context->ZBUF.PSM); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"PS_BATCH_SIZE", str[0].c_str()}, {"PS_FPSM", str[1].c_str()}, @@ -621,7 +621,7 @@ void GSRendererCS::Draw() vector shader; theApp.LoadResource(IDR_CS_FX, shader); - dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", "ps_main1", macro, &ps[1]); + dev->CompileShader((const char *)shader.data(), shader.size(), "cs.fx", nullptr, "ps_main1", macro, &ps[1]); m_ps1[ps_sel] = ps[1]; } diff --git a/plugins/GSdx/GSTextureFX11.cpp b/plugins/GSdx/GSTextureFX11.cpp index cb3f022eaa..77cf05d2fb 100644 --- a/plugins/GSdx/GSTextureFX11.cpp +++ b/plugins/GSdx/GSTextureFX11.cpp @@ -96,7 +96,7 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb) str[2] = format("%d", sel.fst); str[3] = format("%d", sel.rtcopy); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"VS_BPPZ", str[0].c_str()}, {"VS_TME", str[1].c_str()}, @@ -120,7 +120,7 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb) vector shader; theApp.LoadResource(IDR_TFX_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); + CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", nullptr, "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); m_vs[sel] = vs; @@ -158,7 +158,7 @@ void GSDevice11::SetupGS(GSSelector sel) str[0] = format("%d", sel.iip); str[1] = format("%d", sel.prim); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"GS_IIP", str[0].c_str()}, {"GS_PRIM", str[1].c_str()}, @@ -167,7 +167,7 @@ void GSDevice11::SetupGS(GSSelector sel) vector shader; theApp.LoadResource(IDR_TFX_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", "gs_main", macro, &gs); + CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", nullptr, "gs_main", macro, &gs); m_gs[sel] = gs; } @@ -205,7 +205,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe str[18] = format("%d", sel.shuffle); str[19] = format("%d", sel.read_ba); - D3D11_SHADER_MACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"PS_FST", str[0].c_str()}, {"PS_WMS", str[1].c_str()}, @@ -234,7 +234,7 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe vector shader; theApp.LoadResource(IDR_TFX_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", "ps_main", macro, &ps); + CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", nullptr, "ps_main", macro, &ps); m_ps[sel] = ps; diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 6f2e63e3d4..66748cc69d 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -39,15 +39,12 @@ #include #include #include -#include #include #include #include #include #define D3DCOLORWRITEENABLE_RGBA (D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA) -#define D3D11_SHADER_MACRO D3D10_SHADER_MACRO -#define ID3D11Blob ID3D10Blob #endif diff --git a/plugins/GSdx/vsprops/common.props b/plugins/GSdx/vsprops/common.props index e0768144c3..de5f133806 100644 --- a/plugins/GSdx/vsprops/common.props +++ b/plugins/GSdx/vsprops/common.props @@ -14,12 +14,12 @@ Level4 ProgramDatabase 4456;4458;4996;4995;4324;4100;4101;4201;4556;4127;4512;%(DisableSpecificWarnings) - $(DXSDK_DIR)include;$(VTUNE_AMPLIFIER_XE_2015_DIR)include;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\libpng;$(SolutionDir)3rdparty\opencl;$(SolutionDir)3rdparty\zlib;%(AdditionalIncludeDirectories) + $(VTUNE_AMPLIFIER_XE_2015_DIR)include;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\libpng;$(SolutionDir)3rdparty\opencl;$(SolutionDir)3rdparty\zlib;%(AdditionalIncludeDirectories) true - d3d11.lib;d3dx11.lib;d3d10_1.lib;d3dx10.lib;d3d9.lib;d3dx9.lib;dxgi.lib;dxguid.lib;winmm.lib;strmiids.lib;xinput.lib;opengl32.lib;opencl.lib;comsuppw.lib;comctl32.lib;%(AdditionalDependencies) - d3d9.dll;d3dx9_43.dll;d3d11.dll;d3dx11_43.dll;dxgi.dll;opengl32.dll;%(DelayLoadDLLs) + d3d11.lib;d3d10_1.lib;d3d9.lib;d3dx9.lib;dxgi.lib;dxguid.lib;winmm.lib;strmiids.lib;xinput.lib;opengl32.lib;opencl.lib;comsuppw.lib;comctl32.lib;%(AdditionalDependencies) + d3d9.dll;d3dx9_43.dll;d3d11.dll;dxgi.dll;opengl32.dll;%(DelayLoadDLLs) true Windows false @@ -29,4 +29,4 @@ "$(SvnCommonDir)\vsprops\preBuild.cmd" "$(ProjectRootDir)" - \ No newline at end of file +