mirror of https://github.com/PCSX2/pcsx2.git
gsdx-d3d11: Update d3d shader macro handling to a much better algorithm.
Bonus, remove unused options variable D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS.
This commit is contained in:
parent
cec185fd66
commit
6a122268cb
|
@ -248,10 +248,6 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
|
|||
m_hack_topleft_offset = (!nvidia_gpu || m_upscale_multiplier == 1 || spritehack_enabled) ? 0.0f : -0.01f;
|
||||
}
|
||||
|
||||
D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
|
||||
|
||||
hr = m_dev->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS));
|
||||
|
||||
// debug
|
||||
#ifdef _DEBUG
|
||||
CComPtr<ID3D11Debug> debug;
|
||||
|
@ -283,23 +279,20 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
|
|||
{"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
|
||||
ShaderMacro sm_model(m_shader.model);
|
||||
|
||||
std::vector<char> shader;
|
||||
theApp.LoadResource(IDR_CONVERT_FX, shader);
|
||||
CreateShader(shader, "convert.fx", nullptr, "vs_main", nullptr, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
|
||||
CreateShader(shader, "convert.fx", nullptr, "vs_main", sm_model.GetPtr(), &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
|
||||
|
||||
std::string convert_mstr[1];
|
||||
ShaderMacro sm_convert(m_shader.model);
|
||||
sm_convert.AddMacro("PS_SCALE_FACTOR", std::max(1, m_upscale_multiplier));
|
||||
|
||||
convert_mstr[0] = format("%d", std::max(1, m_upscale_multiplier));
|
||||
|
||||
D3D_SHADER_MACRO convert_macro[] =
|
||||
{
|
||||
{"PS_SCALE_FACTOR", convert_mstr[0].c_str()},
|
||||
{NULL, NULL},
|
||||
};
|
||||
D3D_SHADER_MACRO* sm_convert_ptr = sm_convert.GetPtr();
|
||||
|
||||
for(size_t i = 0; i < countof(m_convert.ps); i++)
|
||||
{
|
||||
CreateShader(shader, "convert.fx", nullptr, format("ps_main%d", i).c_str(), convert_macro, &m_convert.ps[i]);
|
||||
CreateShader(shader, "convert.fx", nullptr, format("ps_main%d", i).c_str(), sm_convert_ptr, & m_convert.ps[i]);
|
||||
}
|
||||
|
||||
memset(&dsd, 0, sizeof(dsd));
|
||||
|
@ -331,7 +324,7 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
|
|||
theApp.LoadResource(IDR_MERGE_FX, shader);
|
||||
for(size_t i = 0; i < countof(m_merge.ps); i++)
|
||||
{
|
||||
CreateShader(shader, "merge.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_merge.ps[i]);
|
||||
CreateShader(shader, "merge.fx", nullptr, format("ps_main%d", i).c_str(), sm_model.GetPtr(), &m_merge.ps[i]);
|
||||
}
|
||||
|
||||
memset(&bsd, 0, sizeof(bsd));
|
||||
|
@ -360,28 +353,16 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
|
|||
theApp.LoadResource(IDR_INTERLACE_FX, shader);
|
||||
for(size_t i = 0; i < countof(m_interlace.ps); i++)
|
||||
{
|
||||
CreateShader(shader, "interlace.fx", nullptr, format("ps_main%d", i).c_str(), nullptr, &m_interlace.ps[i]);
|
||||
CreateShader(shader, "interlace.fx", nullptr, format("ps_main%d", i).c_str(), sm_model.GetPtr(), &m_interlace.ps[i]);
|
||||
}
|
||||
|
||||
// Shade Boos
|
||||
// Shade Boost
|
||||
|
||||
int ShadeBoost_Contrast = theApp.GetConfigI("ShadeBoost_Contrast");
|
||||
int ShadeBoost_Brightness = theApp.GetConfigI("ShadeBoost_Brightness");
|
||||
int ShadeBoost_Saturation = theApp.GetConfigI("ShadeBoost_Saturation");
|
||||
ShaderMacro sm_sboost(m_shader.model);
|
||||
|
||||
std::string str[3];
|
||||
|
||||
str[0] = format("%d", ShadeBoost_Saturation);
|
||||
str[1] = format("%d", ShadeBoost_Brightness);
|
||||
str[2] = format("%d", ShadeBoost_Contrast);
|
||||
|
||||
D3D_SHADER_MACRO macro[] =
|
||||
{
|
||||
{"SB_SATURATION", str[0].c_str()},
|
||||
{"SB_BRIGHTNESS", str[1].c_str()},
|
||||
{"SB_CONTRAST", str[2].c_str()},
|
||||
{NULL, NULL},
|
||||
};
|
||||
sm_sboost.AddMacro("SB_SATURATION", theApp.GetConfigI("ShadeBoost_Saturation"));
|
||||
sm_sboost.AddMacro("SB_BRIGHTNESS", theApp.GetConfigI("ShadeBoost_Brightness"));
|
||||
sm_sboost.AddMacro("SB_CONTRAST", theApp.GetConfigI("ShadeBoost_Contrast"));
|
||||
|
||||
memset(&bd, 0, sizeof(bd));
|
||||
|
||||
|
@ -392,7 +373,7 @@ bool GSDevice11::Create(const std::shared_ptr<GSWnd> &wnd)
|
|||
hr = m_dev->CreateBuffer(&bd, NULL, &m_shadeboost.cb);
|
||||
|
||||
theApp.LoadResource(IDR_SHADEBOOST_FX, shader);
|
||||
CreateShader(shader, "shadeboost.fx", nullptr, "ps_main", macro, &m_shadeboost.ps);
|
||||
CreateShader(shader, "shadeboost.fx", nullptr, "ps_main", sm_sboost.GetPtr(), &m_shadeboost.ps);
|
||||
|
||||
// External fx shader
|
||||
|
||||
|
@ -1007,8 +988,8 @@ void GSDevice11::InitExternalFX()
|
|||
shader << fshader.rdbuf();
|
||||
const std::string& s = shader.str();
|
||||
std::vector<char> buff(s.begin(), s.end());
|
||||
|
||||
CreateShader(buff, shader_name.c_str(), D3D_COMPILE_STANDARD_FILE_INCLUDE, "ps_main", nullptr, &m_shaderfx.ps);
|
||||
ShaderMacro sm(m_shader.model);
|
||||
CreateShader(buff, shader_name.c_str(), D3D_COMPILE_STANDARD_FILE_INCLUDE, "ps_main", sm.GetPtr(), &m_shaderfx.ps);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1051,7 +1032,8 @@ void GSDevice11::InitFXAA()
|
|||
try {
|
||||
std::vector<char> shader;
|
||||
theApp.LoadResource(IDR_FXAA_FX, shader);
|
||||
CreateShader(shader, "fxaa.fx", nullptr, "ps_main", nullptr, &m_fxaa.ps);
|
||||
ShaderMacro sm(m_shader.model);
|
||||
CreateShader(shader, "fxaa.fx", nullptr, "ps_main", sm.GetPtr(), &m_fxaa.ps);
|
||||
}
|
||||
catch (GSDXRecoverableError) {
|
||||
printf("GSdx: failed to compile fxaa shader.\n");
|
||||
|
@ -1484,6 +1466,27 @@ void GSDevice11::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector
|
|||
}
|
||||
}
|
||||
|
||||
GSDevice11::ShaderMacro::ShaderMacro(std::string& smodel)
|
||||
{
|
||||
mlist.emplace_back("SHADER_MODEL", smodel);
|
||||
}
|
||||
|
||||
void GSDevice11::ShaderMacro::AddMacro(const char* n, int d)
|
||||
{
|
||||
mlist.emplace_back(n, std::to_string(d));
|
||||
}
|
||||
|
||||
D3D_SHADER_MACRO* GSDevice11::ShaderMacro::GetPtr(void)
|
||||
{
|
||||
mout.clear();
|
||||
|
||||
for (auto& i : mlist)
|
||||
mout.emplace_back(i.name.c_str(), i.def.c_str());
|
||||
|
||||
mout.emplace_back(nullptr, nullptr);
|
||||
return (D3D_SHADER_MACRO*)mout.data();
|
||||
}
|
||||
|
||||
void GSDevice11::CreateShader(std::vector<char> source, 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;
|
||||
|
@ -1543,10 +1546,6 @@ void GSDevice11::CompileShader(std::vector<char> source, const char* fn, ID3DInc
|
|||
{
|
||||
HRESULT hr;
|
||||
|
||||
std::vector<D3D_SHADER_MACRO> m;
|
||||
|
||||
PrepareShaderMacro(m, macro);
|
||||
|
||||
CComPtr<ID3DBlob> error;
|
||||
|
||||
UINT flags = 0;
|
||||
|
@ -1555,7 +1554,7 @@ void GSDevice11::CompileShader(std::vector<char> source, const char* fn, ID3DInc
|
|||
flags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_AVOID_FLOW_CONTROL;
|
||||
#endif
|
||||
|
||||
hr = s_pD3DCompile(source.data(), source.size(), fn, &m[0], include, entry, shader_model.c_str(), flags, 0, shader, &error);
|
||||
hr = s_pD3DCompile(source.data(), source.size(), fn, macro, include, entry, shader_model.c_str(), flags, 0, shader, &error);
|
||||
|
||||
if(error)
|
||||
{
|
||||
|
|
|
@ -315,6 +315,29 @@ public:
|
|||
|
||||
#pragma pack(pop)
|
||||
|
||||
class ShaderMacro
|
||||
{
|
||||
struct mcstr
|
||||
{
|
||||
const char* name, * def;
|
||||
mcstr(const char* n, const char* d) : name(n), def(d) {}
|
||||
};
|
||||
|
||||
struct mstring
|
||||
{
|
||||
std::string name, def;
|
||||
mstring(const char* n, std::string d) : name(n), def(d) {}
|
||||
};
|
||||
|
||||
std::vector<mstring> mlist;
|
||||
std::vector<mcstr> mout;
|
||||
|
||||
public:
|
||||
ShaderMacro(std::string& smodel);
|
||||
void AddMacro(const char* n, int d);
|
||||
D3D_SHADER_MACRO* GetPtr(void);
|
||||
};
|
||||
|
||||
private:
|
||||
float m_hack_topleft_offset;
|
||||
int m_upscale_multiplier;
|
||||
|
@ -533,27 +556,5 @@ public:
|
|||
void CreateShader(std::vector<char> source, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3D11PixelShader** ps);
|
||||
|
||||
void CompileShader(std::vector<char> source, const char* fn, ID3DInclude *include, const char* entry, D3D_SHADER_MACRO* macro, ID3DBlob** shader, std::string shader_model);
|
||||
|
||||
template<class T> void PrepareShaderMacro(std::vector<T>& dst, const T* src)
|
||||
{
|
||||
dst.clear();
|
||||
|
||||
while (src && src->Definition && src->Name)
|
||||
{
|
||||
dst.push_back(*src++);
|
||||
}
|
||||
|
||||
T m;
|
||||
|
||||
m.Name = "SHADER_MODEL";
|
||||
m.Definition = m_shader.model.c_str();
|
||||
|
||||
dst.push_back(m);
|
||||
|
||||
m.Name = NULL;
|
||||
m.Definition = NULL;
|
||||
|
||||
dst.push_back(m);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -103,19 +103,11 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
|
|||
|
||||
if(i == m_vs.end())
|
||||
{
|
||||
std::string str[3];
|
||||
ShaderMacro sm(m_shader.model);
|
||||
|
||||
str[0] = format("%d", sel.bppz);
|
||||
str[1] = format("%d", sel.tme);
|
||||
str[2] = format("%d", sel.fst);
|
||||
|
||||
D3D_SHADER_MACRO macro[] =
|
||||
{
|
||||
{"VS_BPPZ", str[0].c_str()},
|
||||
{"VS_TME", str[1].c_str()},
|
||||
{"VS_FST", str[2].c_str()},
|
||||
{NULL, NULL},
|
||||
};
|
||||
sm.AddMacro("VS_BPPZ", sel.bppz);
|
||||
sm.AddMacro("VS_TME", sel.tme);
|
||||
sm.AddMacro("VS_FST", sel.fst);
|
||||
|
||||
D3D11_INPUT_ELEMENT_DESC layout[] =
|
||||
{
|
||||
|
@ -132,7 +124,7 @@ void GSDevice11::SetupVS(VSSelector sel, const VSConstantBuffer* cb)
|
|||
|
||||
std::vector<char> shader;
|
||||
theApp.LoadResource(IDR_TFX_FX, shader);
|
||||
CreateShader(shader, "tfx.fx", nullptr, "vs_main", macro, &vs.vs, layout, countof(layout), &vs.il);
|
||||
CreateShader(shader, "tfx.fx", nullptr, "vs_main", sm.GetPtr(), &vs.vs, layout, countof(layout), &vs.il);
|
||||
|
||||
m_vs[sel] = vs;
|
||||
|
||||
|
@ -166,25 +158,16 @@ void GSDevice11::SetupGS(GSSelector sel, const GSConstantBuffer* cb)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::string str[4];
|
||||
ShaderMacro sm(m_shader.model);
|
||||
|
||||
str[0] = format("%d", sel.iip);
|
||||
str[1] = format("%d", sel.prim);
|
||||
str[2] = format("%d", sel.point);
|
||||
str[3] = format("%d", sel.line);
|
||||
|
||||
D3D_SHADER_MACRO macro[] =
|
||||
{
|
||||
{"GS_IIP", str[0].c_str()},
|
||||
{"GS_PRIM", str[1].c_str()},
|
||||
{"GS_POINT", str[2].c_str()},
|
||||
{"GS_LINE", str[3].c_str()},
|
||||
{NULL, NULL},
|
||||
};
|
||||
sm.AddMacro("GS_IIP", sel.iip);
|
||||
sm.AddMacro("GS_PRIM", sel.prim);
|
||||
sm.AddMacro("GS_POINT", sel.point);
|
||||
sm.AddMacro("GS_LINE", sel.line);
|
||||
|
||||
std::vector<char> shader;
|
||||
theApp.LoadResource(IDR_TFX_FX, shader);
|
||||
CreateShader(shader, "tfx.fx", nullptr, "gs_main", macro, &gs);
|
||||
CreateShader(shader, "tfx.fx", nullptr, "gs_main", sm.GetPtr(), &gs);
|
||||
|
||||
m_gs[sel] = gs;
|
||||
}
|
||||
|
@ -207,81 +190,45 @@ void GSDevice11::SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSe
|
|||
|
||||
if(i == m_ps.end())
|
||||
{
|
||||
std::string str[31];
|
||||
ShaderMacro sm(m_shader.model);
|
||||
|
||||
str[0] = format("%d", sel.fst);
|
||||
str[1] = format("%d", sel.wms);
|
||||
str[2] = format("%d", sel.wmt);
|
||||
str[3] = format("%d", sel.fmt);
|
||||
str[4] = format("%d", sel.aem);
|
||||
str[5] = format("%d", sel.tfx);
|
||||
str[6] = format("%d", sel.tcc);
|
||||
str[7] = format("%d", sel.atst);
|
||||
str[8] = format("%d", sel.fog);
|
||||
str[9] = format("%d", sel.clr1);
|
||||
str[10] = format("%d", sel.fba);
|
||||
str[11] = format("%d", sel.fbmask);
|
||||
str[12] = format("%d", sel.ltf);
|
||||
str[13] = format("%d", sel.spritehack);
|
||||
str[14] = format("%d", sel.tcoffsethack);
|
||||
str[15] = format("%d", sel.point_sampler);
|
||||
str[16] = format("%d", sel.shuffle);
|
||||
str[17] = format("%d", sel.read_ba);
|
||||
str[18] = format("%d", sel.channel);
|
||||
str[19] = format("%d", sel.tales_of_abyss_hle);
|
||||
str[20] = format("%d", sel.urban_chaos_hle);
|
||||
str[21] = format("%d", sel.dfmt);
|
||||
str[22] = format("%d", sel.depth_fmt);
|
||||
str[23] = format("%d", sel.fmt >> 2);
|
||||
str[24] = format("%d", sel.invalid_tex0);
|
||||
str[25] = format("%d", m_upscale_multiplier ? m_upscale_multiplier : 1);
|
||||
str[26] = format("%d", sel.hdr);
|
||||
str[27] = format("%d", sel.blend_a);
|
||||
str[28] = format("%d", sel.blend_b);
|
||||
str[29] = format("%d", sel.blend_c);
|
||||
str[30] = format("%d", sel.blend_d);
|
||||
|
||||
D3D_SHADER_MACRO macro[] =
|
||||
{
|
||||
{"PS_FST", str[0].c_str()},
|
||||
{"PS_WMS", str[1].c_str()},
|
||||
{"PS_WMT", str[2].c_str()},
|
||||
{"PS_FMT", str[3].c_str()},
|
||||
{"PS_AEM", str[4].c_str()},
|
||||
{"PS_TFX", str[5].c_str()},
|
||||
{"PS_TCC", str[6].c_str()},
|
||||
{"PS_ATST", str[7].c_str()},
|
||||
{"PS_FOG", str[8].c_str()},
|
||||
{"PS_CLR1", str[9].c_str()},
|
||||
{"PS_FBA", str[10].c_str()},
|
||||
{"PS_FBMASK", str[11].c_str()},
|
||||
{"PS_LTF", str[12].c_str()},
|
||||
{"PS_SPRITEHACK", str[13].c_str()},
|
||||
{"PS_TCOFFSETHACK", str[14].c_str()},
|
||||
{"PS_POINT_SAMPLER", str[15].c_str()},
|
||||
{"PS_SHUFFLE", str[16].c_str() },
|
||||
{"PS_READ_BA", str[17].c_str() },
|
||||
{"PS_CHANNEL_FETCH", str[18].c_str() },
|
||||
{"PS_TALES_OF_ABYSS_HLE", str[19].c_str() },
|
||||
{"PS_URBAN_CHAOS_HLE", str[20].c_str() },
|
||||
{"PS_DFMT", str[21].c_str() },
|
||||
{"PS_DEPTH_FMT", str[22].c_str() },
|
||||
{"PS_PAL_FMT", str[23].c_str() },
|
||||
{"PS_INVALID_TEX0", str[24].c_str() },
|
||||
{"PS_SCALE_FACTOR", str[25].c_str() },
|
||||
{"PS_HDR", str[26].c_str() },
|
||||
{"PS_BLEND_A", str[27].c_str() },
|
||||
{"PS_BLEND_B", str[28].c_str() },
|
||||
{"PS_BLEND_C", str[29].c_str() },
|
||||
{"PS_BLEND_D", str[30].c_str() },
|
||||
{NULL, NULL},
|
||||
};
|
||||
sm.AddMacro("PS_SCALE_FACTOR", std::max(1, m_upscale_multiplier));
|
||||
sm.AddMacro("PS_FST", sel.fst);
|
||||
sm.AddMacro("PS_WMS", sel.wms);
|
||||
sm.AddMacro("PS_WMT", sel.wmt);
|
||||
sm.AddMacro("PS_FMT", sel.fmt);
|
||||
sm.AddMacro("PS_AEM", sel.aem);
|
||||
sm.AddMacro("PS_TFX", sel.tfx);
|
||||
sm.AddMacro("PS_TCC", sel.tcc);
|
||||
sm.AddMacro("PS_ATST", sel.atst);
|
||||
sm.AddMacro("PS_FOG", sel.fog);
|
||||
sm.AddMacro("PS_CLR1", sel.clr1);
|
||||
sm.AddMacro("PS_FBA", sel.fba);
|
||||
sm.AddMacro("PS_FBMASK", sel.fbmask);
|
||||
sm.AddMacro("PS_LTF", sel.ltf);
|
||||
sm.AddMacro("PS_SPRITEHACK", sel.spritehack);
|
||||
sm.AddMacro("PS_TCOFFSETHACK", sel.tcoffsethack);
|
||||
sm.AddMacro("PS_POINT_SAMPLER", sel.point_sampler);
|
||||
sm.AddMacro("PS_SHUFFLE", sel.shuffle);
|
||||
sm.AddMacro("PS_READ_BA", sel.read_ba);
|
||||
sm.AddMacro("PS_CHANNEL_FETCH", sel.channel);
|
||||
sm.AddMacro("PS_TALES_OF_ABYSS_HLE", sel.tales_of_abyss_hle);
|
||||
sm.AddMacro("PS_URBAN_CHAOS_HLE", sel.urban_chaos_hle);
|
||||
sm.AddMacro("PS_DFMT", sel.dfmt);
|
||||
sm.AddMacro("PS_DEPTH_FMT", sel.depth_fmt);
|
||||
sm.AddMacro("PS_PAL_FMT", sel.fmt >> 2);
|
||||
sm.AddMacro("PS_INVALID_TEX0", sel.invalid_tex0);
|
||||
sm.AddMacro("PS_HDR", sel.hdr);
|
||||
sm.AddMacro("PS_BLEND_A", sel.blend_a);
|
||||
sm.AddMacro("PS_BLEND_B", sel.blend_b);
|
||||
sm.AddMacro("PS_BLEND_C", sel.blend_c);
|
||||
sm.AddMacro("PS_BLEND_D", sel.blend_d);
|
||||
|
||||
CComPtr<ID3D11PixelShader> ps;
|
||||
|
||||
std::vector<char> shader;
|
||||
theApp.LoadResource(IDR_TFX_FX, shader);
|
||||
CreateShader(shader, "tfx.fx", nullptr, "ps_main", macro, &ps);
|
||||
CreateShader(shader, "tfx.fx", nullptr, "ps_main", sm.GetPtr(), &ps);
|
||||
|
||||
m_ps[sel] = ps;
|
||||
|
||||
|
|
Loading…
Reference in New Issue