GS: Put shadeboost params in uniforms

Compiling variants for these is silly.
This commit is contained in:
Connor McLaughlin 2022-03-27 04:15:56 +10:00 committed by lightningterror
parent dd28e33612
commit 4a5180bc0a
9 changed files with 37 additions and 55 deletions

View File

@ -1,5 +1,13 @@
#ifdef SHADER_MODEL // make safe to include in resource file to enforce dependency
Texture2D Texture;
SamplerState Sampler;
cbuffer cb0
{
float4 params;
};
/*
** Contrast, saturation, brightness
** Code of this function is from TGM's shader pack
@ -9,9 +17,9 @@
// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
float4 ContrastSaturationBrightness(float4 color) // Ported to HLSL
{
const float sat = SB_SATURATION / 50.0;
const float brt = SB_BRIGHTNESS / 50.0;
const float con = SB_CONTRAST / 50.0;
float brt = params.x;
float con = params.y;
float sat = params.z;
// Increase or decrease these values to adjust r, g and b color channels separately
const float AvgLumR = 0.5;
@ -30,14 +38,6 @@ float4 ContrastSaturationBrightness(float4 color) // Ported to HLSL
return color;
}
Texture2D Texture;
SamplerState Sampler;
cbuffer cb0
{
float4 BGColor;
};
struct PS_INPUT
{
float4 p : SV_Position;

View File

@ -11,6 +11,8 @@
#ifdef FRAGMENT_SHADER
uniform vec4 params;
in vec4 PSin_p;
in vec2 PSin_t;
in vec4 PSin_c;
@ -20,9 +22,9 @@ layout(location = 0) out vec4 SV_Target0;
// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
vec4 ContrastSaturationBrightness(vec4 color)
{
const float sat = SB_SATURATION / 50.0;
const float brt = SB_BRIGHTNESS / 50.0;
const float con = SB_CONTRAST / 50.0;
float brt = params.x;
float con = params.y;
float sat = params.z;
// Increase or decrease these values to adjust r, g and b color channels separately
const float AvgLumR = 0.5;

View File

@ -766,9 +766,6 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config)
GSConfig.SWExtraThreads != old_config.SWExtraThreads ||
GSConfig.SWExtraThreadsHeight != old_config.SWExtraThreadsHeight ||
GSConfig.ShadeBoost_Brightness != old_config.ShadeBoost_Brightness ||
GSConfig.ShadeBoost_Contrast != old_config.ShadeBoost_Contrast ||
GSConfig.ShadeBoost_Saturation != old_config.ShadeBoost_Saturation ||
GSConfig.SaveN != old_config.SaveN ||
GSConfig.SaveL != old_config.SaveL ||

View File

@ -425,8 +425,15 @@ void GSDevice::ShadeBoost()
const GSVector4 sRect(0, 0, 1, 1);
const GSVector4 dRect(0, 0, s.x, s.y);
// predivide to avoid the divide (multiply) in the shader
const float params[4] = {
static_cast<float>(GSConfig.ShadeBoost_Brightness) * (1.0f / 50.0f),
static_cast<float>(GSConfig.ShadeBoost_Contrast) * (1.0f / 50.0f),
static_cast<float>(GSConfig.ShadeBoost_Saturation) * (1.0f / 50.0f),
};
StretchRect(m_current, sRect, m_target_tmp, dRect, ShaderConvert::COPY, false);
DoShadeBoost(m_target_tmp, m_current);
DoShadeBoost(m_target_tmp, m_current, params);
}
}

View File

@ -103,15 +103,6 @@ public:
ExternalFXConstantBuffer() { memset(this, 0, sizeof(*this)); }
};
class ShadeBoostConstantBuffer
{
public:
GSVector4 rcpFrame;
GSVector4 rcpFrameOpt;
ShadeBoostConstantBuffer() { memset(this, 0, sizeof(*this)); }
};
#pragma pack(pop)
enum HWBlendFlags
@ -652,7 +643,7 @@ protected:
virtual void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) = 0;
virtual void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset) = 0;
virtual void DoFXAA(GSTexture* sTex, GSTexture* dTex) {}
virtual void DoShadeBoost(GSTexture* sTex, GSTexture* dTex) {}
virtual void DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float params[4]) {}
virtual void DoExternalFX(GSTexture* sTex, GSTexture* dTex) {}
public:

View File

@ -240,15 +240,8 @@ bool GSDevice11::Create(HostDisplay* display)
// Shade Boost
ShaderMacro sm_sboost(m_shader_cache.GetFeatureLevel());
sm_sboost.AddMacro("SB_CONTRAST", std::clamp(theApp.GetConfigI("ShadeBoost_Contrast"), 0, 100));
sm_sboost.AddMacro("SB_BRIGHTNESS", std::clamp(theApp.GetConfigI("ShadeBoost_Brightness"), 0, 100));
sm_sboost.AddMacro("SB_SATURATION", std::clamp(theApp.GetConfigI("ShadeBoost_Saturation"), 0, 100));
memset(&bd, 0, sizeof(bd));
bd.ByteWidth = sizeof(ShadeBoostConstantBuffer);
bd.ByteWidth = sizeof(float) * 4;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
@ -257,7 +250,7 @@ bool GSDevice11::Create(HostDisplay* display)
shader = Host::ReadResourceFileToString("shaders/dx11/shadeboost.fx");
if (!shader.has_value())
return false;
m_shadeboost.ps = m_shader_cache.GetPixelShader(m_dev.get(), *shader, sm_sboost.GetPtr(), "ps_main");
m_shadeboost.ps = m_shader_cache.GetPixelShader(m_dev.get(), *shader, sm_model.GetPtr(), "ps_main");
if (!m_shadeboost.ps)
return false;
@ -840,19 +833,14 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex)
//dTex->Save("c:\\temp1\\2.bmp");
}
void GSDevice11::DoShadeBoost(GSTexture* sTex, GSTexture* dTex)
void GSDevice11::DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float params[4])
{
const GSVector2i s = dTex->GetSize();
const GSVector4 sRect(0, 0, 1, 1);
const GSVector4 dRect(0, 0, s.x, s.y);
ShadeBoostConstantBuffer cb;
cb.rcpFrame = GSVector4(1.0f / s.x, 1.0f / s.y, 0.0f, 0.0f);
cb.rcpFrameOpt = GSVector4::zero();
m_ctx->UpdateSubresource(m_shadeboost.cb.get(), 0, nullptr, &cb, 0, 0);
m_ctx->UpdateSubresource(m_shadeboost.cb.get(), 0, nullptr, params, 0, 0);
StretchRect(sTex, sRect, dTex, dRect, m_shadeboost.ps.get(), m_shadeboost.cb.get(), true);
}

View File

@ -124,7 +124,7 @@ private:
void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) final;
void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) final;
void DoFXAA(GSTexture* sTex, GSTexture* dTex) final;
void DoShadeBoost(GSTexture* sTex, GSTexture* dTex) final;
void DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float params[4]) final;
void DoExternalFX(GSTexture* sTex, GSTexture* dTex) final;
wil::com_ptr_nothrow<ID3D11Device> m_dev;

View File

@ -446,13 +446,6 @@ bool GSDeviceOGL::Create(HostDisplay* display)
{
GL_PUSH("GSDeviceOGL::Shadeboost");
const int ShadeBoost_Contrast = std::clamp(theApp.GetConfigI("ShadeBoost_Contrast"), 0, 100);
const int ShadeBoost_Brightness = std::clamp(theApp.GetConfigI("ShadeBoost_Brightness"), 0, 100);
const int ShadeBoost_Saturation = std::clamp(theApp.GetConfigI("ShadeBoost_Saturation"), 0, 100);
std::string shade_macro = format("#define SB_SATURATION %d.0\n", ShadeBoost_Saturation)
+ format("#define SB_BRIGHTNESS %d.0\n", ShadeBoost_Brightness)
+ format("#define SB_CONTRAST %d.0\n", ShadeBoost_Contrast);
const auto shader = Host::ReadResourceFileToString("shaders/opengl/shadeboost.glsl");
if (!shader.has_value())
{
@ -460,9 +453,10 @@ bool GSDeviceOGL::Create(HostDisplay* display)
return false;
}
const std::string ps(GetShaderSource("ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, *shader, shade_macro));
const std::string ps(GetShaderSource("ps_main", GL_FRAGMENT_SHADER, m_shader_common_header, *shader, {}));
if (!m_shader_cache.GetProgram(&m_shadeboost.ps, m_convert.vs, {}, ps))
return false;
m_shadeboost.ps.RegisterUniform("params");
m_shadeboost.ps.SetName("Shadeboost pipe");
}
@ -1504,10 +1498,13 @@ void GSDeviceOGL::DoExternalFX(GSTexture* sTex, GSTexture* dTex)
#endif
}
void GSDeviceOGL::DoShadeBoost(GSTexture* sTex, GSTexture* dTex)
void GSDeviceOGL::DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float params[4])
{
GL_PUSH("DoShadeBoost");
m_shadeboost.ps.Bind();
m_shadeboost.ps.Uniform4fv(0, params);
OMSetColorMaskState();
const GSVector2i s = dTex->GetSize();

View File

@ -303,7 +303,7 @@ private:
void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) final;
void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) final;
void DoFXAA(GSTexture* sTex, GSTexture* dTex) final;
void DoShadeBoost(GSTexture* sTex, GSTexture* dTex) final;
void DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float params[4]) final;
void DoExternalFX(GSTexture* sTex, GSTexture* dTex) final;
void OMAttachRt(GSTextureOGL* rt = NULL);