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).
This commit is contained in:
Jonathan Li 2015-12-16 23:05:58 +00:00
parent 8f4823d604
commit 2ec8d88d80
6 changed files with 51 additions and 55 deletions

View File

@ -175,11 +175,11 @@ bool GSDevice11::Create(GSWnd* wnd)
vector<unsigned char> 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<unsigned char> 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<D3D11_SHADER_MACRO> m;
vector<D3D_SHADER_MACRO> m;
PrepareShaderMacro(m, macro);
CComPtr<ID3D11Blob> shader, error;
CComPtr<ID3DBlob> 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<D3D11_SHADER_MACRO> m;
vector<D3D_SHADER_MACRO> m;
PrepareShaderMacro(m, macro);
CComPtr<ID3D11Blob> shader, error;
CComPtr<ID3DBlob> 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<D3D11_SHADER_MACRO> m;
vector<D3D_SHADER_MACRO> m;
PrepareShaderMacro(m, macro);
CComPtr<ID3D11Blob> shader, error;
CComPtr<ID3DBlob> 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<D3D11_SHADER_MACRO> m;
vector<D3D_SHADER_MACRO> m;
PrepareShaderMacro(m, macro);
CComPtr<ID3D11Blob> shader, error;
CComPtr<ID3DBlob> 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<D3D11_SHADER_MACRO> m;
vector<D3D_SHADER_MACRO> m;
PrepareShaderMacro(m, macro);
CComPtr<ID3D11Blob> shader, error;
CComPtr<ID3DBlob> 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();
}
}

View File

@ -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);
};

View File

@ -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<unsigned char> 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<unsigned char> 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<unsigned char> 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<unsigned char> 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];
}

View File

@ -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<unsigned char> 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<unsigned char> 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<unsigned char> 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;

View File

@ -39,15 +39,12 @@
#include <shellapi.h>
#include <d3dcompiler.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <comutil.h>
#include <atlcomcli.h>
#define D3DCOLORWRITEENABLE_RGBA (D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA)
#define D3D11_SHADER_MACRO D3D10_SHADER_MACRO
#define ID3D11Blob ID3D10Blob
#endif

View File

@ -14,12 +14,12 @@
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DisableSpecificWarnings>4456;4458;4996;4995;4324;4100;4101;4201;4556;4127;4512;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<AdditionalIncludeDirectories>$(DXSDK_DIR)include;$(VTUNE_AMPLIFIER_XE_2015_DIR)include;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\libpng;$(SolutionDir)3rdparty\opencl;$(SolutionDir)3rdparty\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(VTUNE_AMPLIFIER_XE_2015_DIR)include;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\libpng;$(SolutionDir)3rdparty\opencl;$(SolutionDir)3rdparty\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<AdditionalDependencies>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)</AdditionalDependencies>
<DelayLoadDLLs>d3d9.dll;d3dx9_43.dll;d3d11.dll;d3dx11_43.dll;dxgi.dll;opengl32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<AdditionalDependencies>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)</AdditionalDependencies>
<DelayLoadDLLs>d3d9.dll;d3dx9_43.dll;d3d11.dll;dxgi.dll;opengl32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>