From b243e2532b9efd4e99a1297f335093cdc3ea8dd6 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 16 Dec 2015 23:21:09 +0000 Subject: [PATCH] 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