From 80b6140a3e14a52f345dede32ee91d8185855c18 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 16 Dec 2015 21:27:12 +0000 Subject: [PATCH 1/5] gsdx:windows: Prefer Windows SDK over old DX SDK Some files are present in both the Windows SDK and the old DirectX SDK. Use the newer versions of the files in the Windows SDK where possible. --- plugins/GSdx/vsprops/common.props | 1 + plugins/GSdx/vsprops/x64.props | 6 ++++-- plugins/GSdx/vsprops/x86.props | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/GSdx/vsprops/common.props b/plugins/GSdx/vsprops/common.props index fa802053ae..e0768144c3 100644 --- a/plugins/GSdx/vsprops/common.props +++ b/plugins/GSdx/vsprops/common.props @@ -4,6 +4,7 @@ <_ProjectFileVersion>10.0.30128.1 $(SolutionDir)bin\$(PcsxSubsection)\ $(PlatformName)\$(Configuration)\ + $(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include; diff --git a/plugins/GSdx/vsprops/x64.props b/plugins/GSdx/vsprops/x64.props index 4703984444..563b3b1ed1 100644 --- a/plugins/GSdx/vsprops/x64.props +++ b/plugins/GSdx/vsprops/x64.props @@ -2,10 +2,12 @@ - + + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(DXSDK_DIR)Lib\x64; + - $(DXSDK_DIR)Lib\x64;$(ProjectDir)vtune\x64;%(AdditionalLibraryDirectories) + $(ProjectDir)vtune\x64;%(AdditionalLibraryDirectories) _WIN64;%(PreprocessorDefinitions) diff --git a/plugins/GSdx/vsprops/x86.props b/plugins/GSdx/vsprops/x86.props index c37342f62e..81cba30ae7 100644 --- a/plugins/GSdx/vsprops/x86.props +++ b/plugins/GSdx/vsprops/x86.props @@ -2,10 +2,12 @@ - + + $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(DXSDK_DIR)Lib\x86; + - $(DXSDK_DIR)Lib\x86;$(ProjectDir)vtune\x86;%(AdditionalLibraryDirectories) + $(ProjectDir)vtune\x86;%(AdditionalLibraryDirectories) From 8f4823d60413a0581ecc0b0580e6c388a80b23f0 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sat, 19 Mar 2016 19:07:02 +0000 Subject: [PATCH 2/5] gsdx-dx: Load D3DCompiler dll at runtime D3DCompiler_47.dll will be loaded for Windows 8.1 and above (and maybe Windows 7 devs), D3DCompiler_43.dll will be loaded for Windows 7 and below. --- plugins/GSdx/GS.cpp | 6 +++++ plugins/GSdx/GSDeviceDX.cpp | 47 +++++++++++++++++++++++++++++++++++++ plugins/GSdx/GSDeviceDX.h | 9 +++++++ plugins/GSdx/stdafx.h | 1 + 4 files changed, 63 insertions(+) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index fd867e51fe..bfa7c8010b 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -132,6 +132,10 @@ EXPORT_C_(int) GSinit() return -1; } + if (!GSDeviceDX::LoadD3DCompiler()) + { + return -1; + } #endif return 0; @@ -156,6 +160,8 @@ EXPORT_C GSshutdown() s_hr = E_FAIL; } + GSDeviceDX::FreeD3DCompiler(); + #endif } diff --git a/plugins/GSdx/GSDeviceDX.cpp b/plugins/GSdx/GSDeviceDX.cpp index 2b23b5b5bc..346de8c1a6 100644 --- a/plugins/GSdx/GSDeviceDX.cpp +++ b/plugins/GSdx/GSDeviceDX.cpp @@ -22,6 +22,11 @@ #include "stdafx.h" #include "GSdx.h" #include "GSDeviceDX.h" +#include + +HMODULE GSDeviceDX::s_d3d_compiler_dll = nullptr; +decltype(&D3DCompile) GSDeviceDX::s_pD3DCompile = nullptr; +bool GSDeviceDX::s_old_d3d_compiler_dll; GSDeviceDX::GSDeviceDX() { @@ -35,6 +40,48 @@ GSDeviceDX::~GSDeviceDX() { } +bool GSDeviceDX::LoadD3DCompiler() +{ + // Windows 8.1 and later come with the latest d3dcompiler_47.dll, but + // Windows 7 devs might also have the dll available for use (which will + // have to be placed in the application directory) + s_d3d_compiler_dll = LoadLibraryEx(D3DCOMPILER_DLL, nullptr, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); + + // Windows Vista and 7 can use the older version. If the previous LoadLibrary + // call fails on Windows 8.1 and later, then the user's system is likely + // broken. + if (s_d3d_compiler_dll) + { + s_old_d3d_compiler_dll = false; + } + else + { + if (!IsWindows8Point1OrGreater()) + s_d3d_compiler_dll = LoadLibraryEx("D3DCompiler_43.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + + if (s_d3d_compiler_dll == nullptr) + return false; + + s_old_d3d_compiler_dll = true; + } + + s_pD3DCompile = reinterpret_cast(GetProcAddress(s_d3d_compiler_dll, "D3DCompile")); + if (s_pD3DCompile) + return true; + + FreeLibrary(s_d3d_compiler_dll); + s_d3d_compiler_dll = nullptr; + return false; +} + +void GSDeviceDX::FreeD3DCompiler() +{ + s_pD3DCompile = nullptr; + if (s_d3d_compiler_dll) + FreeLibrary(s_d3d_compiler_dll); + s_d3d_compiler_dll = nullptr; +} + GSTexture* GSDeviceDX::FetchSurface(int type, int w, int h, bool msaa, int format) { if(m_msaa < 2) diff --git a/plugins/GSdx/GSDeviceDX.h b/plugins/GSdx/GSDeviceDX.h index 680b22744a..cdf03312ad 100644 --- a/plugins/GSdx/GSDeviceDX.h +++ b/plugins/GSdx/GSDeviceDX.h @@ -278,6 +278,12 @@ protected: uint32 m_msaa; DXGI_SAMPLE_DESC m_msaa_desc; + static HMODULE s_d3d_compiler_dll; + static decltype(&D3DCompile) s_pD3DCompile; + // Older version doesn't support D3D_COMPILE_STANDARD_FILE_INCLUDE, which + // could be useful for external shaders. + static bool s_old_d3d_compiler_dll; + GSTexture* FetchSurface(int type, int w, int h, bool msaa, int format); public: @@ -297,6 +303,9 @@ public: virtual bool HasStencil() = 0; virtual bool HasDepth32() = 0; + static bool LoadD3DCompiler(); + static void FreeD3DCompiler(); + template void PrepareShaderMacro(vector& dst, const T* src) { dst.clear(); diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 7aac17529d..6f2e63e3d4 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include From 2ec8d88d804c664e6dc70ea0d875ff7553b91350 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 16 Dec 2015 23:05:58 +0000 Subject: [PATCH 3/5] 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 + From b243e2532b9efd4e99a1297f335093cdc3ea8dd6 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 16 Dec 2015 23:21:09 +0000 Subject: [PATCH 4/5] gsdx-d3d9: Remove d3dx9 stuff and use d3dcompile Using D3DX9 requires the end user to install the Direct X redist files. Switch to using D3DCompile. --- plugins/GSdx/GS.cpp | 5 ---- plugins/GSdx/GSDevice9.cpp | 36 ++++++++++++------------- plugins/GSdx/GSDevice9.h | 4 +-- plugins/GSdx/GSTextureFX9.cpp | 8 +++--- plugins/GSdx/GSUtil.cpp | 45 +++++++++---------------------- plugins/GSdx/stdafx.h | 1 - plugins/GSdx/vsprops/common.props | 4 +-- 7 files changed, 39 insertions(+), 64 deletions(-) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index bfa7c8010b..d3579fbff5 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -127,11 +127,6 @@ EXPORT_C_(int) GSinit() s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); - if(!GSUtil::CheckDirectX()) - { - return -1; - } - if (!GSDeviceDX::LoadD3DCompiler()) { return -1; diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index 25d41dcc4f..1414d07fd7 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -292,11 +292,11 @@ bool GSDevice9::Create(GSWnd* wnd) vector shader; theApp.LoadResource(IDR_CONVERT_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "vs_main", NULL, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il); + CompileShader((const char *)shader.data(), shader.size(), "convert.fx", "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(), format("ps_main%d", i), NULL, &m_convert.ps[i]); + CompileShader((const char *)shader.data(), shader.size(), "convert.fx", format("ps_main%d", i), nullptr, &m_convert.ps[i]); } m_convert.dss.DepthEnable = false; @@ -328,7 +328,7 @@ bool GSDevice9::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(), format("ps_main%d", i), NULL, &m_merge.ps[i]); + CompileShader((const char *)shader.data(), shader.size(), "merge.fx", format("ps_main%d", i), nullptr, &m_merge.ps[i]); } m_merge.bs.BlendEnable = true; @@ -345,7 +345,7 @@ bool GSDevice9::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(), format("ps_main%d", i), NULL, &m_interlace.ps[i]); + CompileShader((const char *)shader.data(), shader.size(), "interlace.fx", format("ps_main%d", i), nullptr, &m_interlace.ps[i]); } // Shade Boost @@ -360,7 +360,7 @@ bool GSDevice9::Create(GSWnd* wnd) str[1] = format("%d", ShadeBoost_Brightness); str[2] = format("%d", ShadeBoost_Contrast); - D3DXMACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"SB_SATURATION", str[0].c_str()}, {"SB_BRIGHTNESS", str[1].c_str()}, @@ -369,7 +369,7 @@ bool GSDevice9::Create(GSWnd* wnd) }; theApp.LoadResource(IDR_SHADEBOOST_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "ps_main", macro, &m_shadeboost.ps); + CompileShader((const char *)shader.data(), shader.size(), "shadeboost.fx", "ps_main", macro, &m_shadeboost.ps); // create shader layout @@ -952,7 +952,7 @@ void GSDevice9::InitExternalFX() if (fshader.good()) { shader << fshader.rdbuf(); - CompileShader(shader.str().c_str(), shader.str().length(), "ps_main", NULL, &m_shaderfx.ps); + CompileShader(shader.str().c_str(), shader.str().length(), shader_name.c_str(), "ps_main", nullptr, &m_shaderfx.ps); } else { @@ -991,7 +991,7 @@ void GSDevice9::InitFXAA() try { vector shader; theApp.LoadResource(IDR_FXAA_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "ps_main", NULL, &m_fxaa.ps); + CompileShader((const char *)shader.data(), shader.size(), "fxaa.fx", "ps_main", nullptr, &m_fxaa.ps); } catch (GSDXRecoverableError) { printf("GSdx: Failed to compile fxaa shader.\n"); @@ -1447,17 +1447,17 @@ void GSDevice9::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4 } } -void GSDevice9::CompileShader(const char *source, size_t size, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il) +void GSDevice9::CompileShader(const char *source, size_t size, const char *filename, const string& entry, const D3D_SHADER_MACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il) { - vector m; + vector m; PrepareShaderMacro(m, macro); HRESULT hr; - CComPtr shader, error; + CComPtr shader, error; - hr = D3DXCompileShader(source, size, &m[0], NULL, entry.c_str(), m_shader.vs.c_str(), 0, &shader, &error, NULL); + hr = s_pD3DCompile(source, size, nullptr, &m[0], nullptr, entry.c_str(), m_shader.vs.c_str(), 0, 0, &shader, &error); if(SUCCEEDED(hr)) { @@ -1483,27 +1483,27 @@ void GSDevice9::CompileShader(const char *source, size_t size, const string& ent } } -void GSDevice9::CompileShader(const char *source, size_t size, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps) +void GSDevice9::CompileShader(const char *source, size_t size, const char *filename, const string& entry, const D3D_SHADER_MACRO* macro, IDirect3DPixelShader9** ps) { uint32 flags = 0; if(m_shader.level >= D3D_FEATURE_LEVEL_9_3) { - flags |= D3DXSHADER_AVOID_FLOW_CONTROL; + flags |= D3DCOMPILE_AVOID_FLOW_CONTROL; } else { - flags |= D3DXSHADER_SKIPVALIDATION; + flags |= D3DCOMPILE_SKIP_VALIDATION; } - vector m; + vector m; PrepareShaderMacro(m, macro); HRESULT hr; - CComPtr shader, error; - hr = D3DXCompileShader(source, size, &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), flags, &shader, &error, NULL); + CComPtr shader, error; + hr = s_pD3DCompile(source, size, filename, &m[0], nullptr, entry.c_str(), m_shader.ps.c_str(), flags, 0, &shader, &error); if(SUCCEEDED(hr)) { diff --git a/plugins/GSdx/GSDevice9.h b/plugins/GSdx/GSDevice9.h index 6fbf359376..6bb1477e34 100644 --- a/plugins/GSdx/GSDevice9.h +++ b/plugins/GSdx/GSDevice9.h @@ -237,8 +237,8 @@ public: IDirect3DDevice9* operator->() {return m_dev;} operator IDirect3DDevice9*() {return m_dev;} - void CompileShader(const char *source, size_t size, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il); - void CompileShader(const char *source, size_t size, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps); + void CompileShader(const char *source, size_t size, const char *filename, const string& entry, const D3D_SHADER_MACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il); + void CompileShader(const char *source, size_t size, const char *filename, const string& entry, const D3D_SHADER_MACRO* macro, IDirect3DPixelShader9** ps); void SetupVS(VSSelector sel, const VSConstantBuffer* cb); void SetupGS(GSSelector sel) {} diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index 4a19122921..66f735c17c 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -75,7 +75,7 @@ void GSDevice9::SetupVS(VSSelector sel, const VSConstantBuffer* cb) str[3] = format("%d", sel.logz); str[4] = format("%d", sel.rtcopy); - D3DXMACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"VS_BPPZ", str[0].c_str()}, {"VS_TME", str[1].c_str()}, @@ -98,7 +98,7 @@ void GSDevice9::SetupVS(VSSelector sel, const VSConstantBuffer* cb) vector shader; theApp.LoadResource(IDR_TFX_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); + CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il); m_vs[sel] = vs; @@ -157,7 +157,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel str[15] = format("%d", sel.tcoffsethack); str[16] = format("%d", sel.point_sampler); - D3DXMACRO macro[] = + D3D_SHADER_MACRO macro[] = { {"PS_FST", str[0].c_str()}, {"PS_WMS", str[1].c_str()}, @@ -183,7 +183,7 @@ void GSDevice9::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSel vector shader; theApp.LoadResource(IDR_TFX_FX, shader); - CompileShader((const char *)shader.data(), shader.size(), "ps_main", macro, &ps); + CompileShader((const char *)shader.data(), shader.size(), "tfx.fx", "ps_main", macro, &ps); m_ps[sel] = ps; diff --git a/plugins/GSdx/GSUtil.cpp b/plugins/GSdx/GSUtil.cpp index 27e0b9869c..2afded494d 100644 --- a/plugins/GSdx/GSUtil.cpp +++ b/plugins/GSdx/GSUtil.cpp @@ -25,6 +25,8 @@ #include "xbyak/xbyak_util.h" #ifdef _WIN32 +#include "GSDeviceDX.h" +#include #include "svnrev.h" #else #define SVN_REV 0 @@ -324,43 +326,22 @@ string GSUtil::GetDeviceUniqueName(cl::Device& device) bool GSUtil::CheckDirectX() { - OSVERSIONINFOEX version; - memset(&version, 0, sizeof(version)); - version.dwOSVersionInfoSize = sizeof(version); - - if(GetVersionEx((OSVERSIONINFO*)&version)) + if (GSDeviceDX::LoadD3DCompiler()) { - printf("Windows %d.%d.%d", version.dwMajorVersion, version.dwMinorVersion, version.dwBuildNumber); + GSDeviceDX::FreeD3DCompiler(); + return true; + } - if(version.wServicePackMajor > 0) + // User's system is likely broken if it fails and is Windows 8.1 or greater. + if (!IsWindows8Point1OrGreater()) + { + printf("Cannot find d3dcompiler_43.dll\n"); + if (MessageBox(nullptr, TEXT("You need to update some DirectX libraries, would you like to do it now?"), TEXT("GSdx"), MB_YESNO) == IDYES) { - printf(" (%s %d.%d)", version.szCSDVersion, version.wServicePackMajor, version.wServicePackMinor); + ShellExecute(nullptr, TEXT("open"), TEXT("https://www.microsoft.com/en-us/download/details.aspx?id=8109"), nullptr, nullptr, SW_SHOWNORMAL); } - - printf("\n"); } - - string d3dx9_dll = format("d3dx9_%d.dll", D3DX_SDK_VERSION); - - if(HINSTANCE hDll = LoadLibrary(d3dx9_dll.c_str())) - { - FreeLibrary(hDll); - } - else - { - printf("Cannot find %s\n", d3dx9_dll.c_str()); - - if(MessageBox(NULL, "You need to update some directx libraries, would you like to do it now?", "GSdx", MB_YESNO) == IDYES) - { - const char* url = "https://www.microsoft.com/en-us/download/details.aspx?id=8109"; - - ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); - } - - return false; - } - - return true; + return false; } // --------------------------------------------------------------------------------- diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index 66748cc69d..e1ffe1ed74 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -40,7 +40,6 @@ #include #include #include -#include #include #include diff --git a/plugins/GSdx/vsprops/common.props b/plugins/GSdx/vsprops/common.props index de5f133806..ca95a90511 100644 --- a/plugins/GSdx/vsprops/common.props +++ b/plugins/GSdx/vsprops/common.props @@ -18,8 +18,8 @@ true - 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) + d3d11.lib;d3d10_1.lib;d3d9.lib;dxgi.lib;dxguid.lib;winmm.lib;strmiids.lib;opengl32.lib;opencl.lib;comsuppw.lib;comctl32.lib;%(AdditionalDependencies) + d3d9.dll;d3d11.dll;dxgi.dll;opengl32.dll;%(DelayLoadDLLs) true Windows false From e347c8b0b11bef636323811f1c751400bc0ca906 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Fri, 4 Mar 2016 12:38:22 +0000 Subject: [PATCH 5/5] gsdx:windows: Remove DXSDK references from property sheets GSdx doesn't use the DirectX SDK anymore. Also clean up the property sheets while I'm at it. --- plugins/GSdx/vsprops/common.props | 1 - plugins/GSdx/vsprops/x64.props | 11 +---------- plugins/GSdx/vsprops/x86.props | 12 +----------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/plugins/GSdx/vsprops/common.props b/plugins/GSdx/vsprops/common.props index ca95a90511..d5b4b2c6f7 100644 --- a/plugins/GSdx/vsprops/common.props +++ b/plugins/GSdx/vsprops/common.props @@ -4,7 +4,6 @@ <_ProjectFileVersion>10.0.30128.1 $(SolutionDir)bin\$(PcsxSubsection)\ $(PlatformName)\$(Configuration)\ - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)Include; diff --git a/plugins/GSdx/vsprops/x64.props b/plugins/GSdx/vsprops/x64.props index 563b3b1ed1..55af6278c1 100644 --- a/plugins/GSdx/vsprops/x64.props +++ b/plugins/GSdx/vsprops/x64.props @@ -1,17 +1,8 @@  - - - - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(DXSDK_DIR)Lib\x64; - $(ProjectDir)vtune\x64;%(AdditionalLibraryDirectories) - - _WIN64;%(PreprocessorDefinitions) - - - \ No newline at end of file + diff --git a/plugins/GSdx/vsprops/x86.props b/plugins/GSdx/vsprops/x86.props index 81cba30ae7..c6dd1d02de 100644 --- a/plugins/GSdx/vsprops/x86.props +++ b/plugins/GSdx/vsprops/x86.props @@ -1,18 +1,8 @@  - - - - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(DXSDK_DIR)Lib\x86; - $(ProjectDir)vtune\x86;%(AdditionalLibraryDirectories) - - - _WIN32;%(PreprocessorDefinitions) - - - \ No newline at end of file +