Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GS-hw: Don't wrap on 16bit destination format for blend mix. #5540

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/resources/shaders/dx11/tfx.fx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define PS_BLEND_B 0
#define PS_BLEND_C 0
#define PS_BLEND_D 0
#define PS_ALPHA_CLAMP 0
#define PS_BLEND_MIX 0
#define PS_PABE 0
#define PS_DITHER 0
#define PS_ZCLAMP 0
Expand Down Expand Up @@ -717,7 +717,7 @@ void ps_color_clamp_wrap(inout float3 C)
C = clamp(C, (float3)0.0f, (float3)255.0f);

// In 16 bits format, only 5 bits of color are used. It impacts shadows computation of Castlevania
if (PS_DFMT == FMT_16)
if (PS_DFMT == FMT_16 && PS_BLEND_MIX == 0)
C = (float3)((int3)C & (int3)0xF8);
else if (PS_COLCLIP == 1 && PS_HDR == 0)
C = (float3)((int3)C & (int3)0xFF);
Expand Down Expand Up @@ -749,7 +749,7 @@ void ps_blend(inout float4 Color, float As, float2 pos_xy)
float3 D = (PS_BLEND_D == 0) ? Cs : ((PS_BLEND_D == 1) ? Cd : (float3)0.0f);

// As/Af clamp alpha for Blend mix
if (PS_ALPHA_CLAMP)
if (PS_BLEND_MIX)
C = min(C, (float)1.0f);

Color.rgb = (PS_BLEND_A == PS_BLEND_B) ? D : trunc(((A - B) * C) + D);
Expand Down
4 changes: 2 additions & 2 deletions bin/resources/shaders/opengl/tfx_fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void ps_color_clamp_wrap(inout vec3 C)
// Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy
// GS: Color = 1, Alpha = 255 => output 1
// GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875
#if PS_DFMT == FMT_16
#if PS_DFMT == FMT_16 && PS_BLEND_MIX == 0
// In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania
C = vec3(ivec3(C) & ivec3(0xF8));
#elif PS_COLCLIP == 1 && PS_HDR == 0
Expand Down Expand Up @@ -706,7 +706,7 @@ void ps_blend(inout vec4 Color, float As)
#endif

// As/Af clamp alpha for Blend mix
#if PS_ALPHA_CLAMP
#if PS_BLEND_MIX
C = min(C, float(1.0f));
#endif

Expand Down
4 changes: 2 additions & 2 deletions bin/resources/shaders/vulkan/tfx.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ void ps_color_clamp_wrap(inout vec3 C)
// Warning: normally blending equation is mult(A, B) = A * B >> 7. GPU have the full accuracy
// GS: Color = 1, Alpha = 255 => output 1
// GPU: Color = 1/255, Alpha = 255/255 * 255/128 => output 1.9921875
#if PS_DFMT == FMT_16
#if PS_DFMT == FMT_16 && PS_BLEND_MIX == 0
// In 16 bits format, only 5 bits of colors are used. It impacts shadows computation of Castlevania
C = vec3(ivec3(C) & ivec3(0xF8));
#elif PS_COLCLIP == 1 && PS_HDR == 0
Expand Down Expand Up @@ -1046,7 +1046,7 @@ void ps_blend(inout vec4 Color, float As)
#endif

// As/Af clamp alpha for Blend mix
#if PS_ALPHA_CLAMP
#if PS_BLEND_MIX
C = min(C, 1.0f);
#endif

Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/Common/GSDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ struct alignas(16) GSHWDrawConfig
u32 clr_hw : 3;
u32 hdr : 1;
u32 colclip : 1;
u32 alpha_clamp : 1;
u32 blend_mix : 1;
u32 pabe : 1;

// Others ways to fetch the texture
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/DX11/GSTextureFX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void GSDevice11::SetupPS(PSSelector sel, const GSHWDrawConfig::PSConstantBuffer*
sm.AddMacro("PS_BLEND_B", sel.blend_b);
sm.AddMacro("PS_BLEND_C", sel.blend_c);
sm.AddMacro("PS_BLEND_D", sel.blend_d);
sm.AddMacro("PS_ALPHA_CLAMP", sel.alpha_clamp);
sm.AddMacro("PS_BLEND_MIX", sel.blend_mix);
sm.AddMacro("PS_PABE", sel.pabe);
sm.AddMacro("PS_DITHER", sel.dither);
sm.AddMacro("PS_ZCLAMP", sel.zclamp);
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/GS/Renderers/HW/GSRendererNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void GSRendererNew::EmulateBlending(bool& DATE_PRIMID, bool& DATE_BARRIER)
accumulation_blend = false;
blend_mix = false;
}
else if (accumulation_blend || blend_mix)
else if (accumulation_blend)
{
// A fast algo that requires 2 passes
GL_INS("COLCLIP Fast HDR mode ENABLED");
Expand Down Expand Up @@ -796,7 +796,7 @@ void GSRendererNew::EmulateBlending(bool& DATE_PRIMID, bool& DATE_BARRIER)
else if (blend_mix)
{
m_conf.blend = {blend_index, ALPHA.FIX, ALPHA.C == 2, false, true};
m_conf.ps.alpha_clamp = 1;
m_conf.ps.blend_mix = 1;

if (blend_mix1)
{
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ std::string GSDeviceOGL::GetPSSource(PSSelector sel)
+ format("#define PS_HDR %d\n", sel.hdr)
+ format("#define PS_DITHER %d\n", sel.dither)
+ format("#define PS_ZCLAMP %d\n", sel.zclamp)
+ format("#define PS_ALPHA_CLAMP %d\n", sel.alpha_clamp)
+ format("#define PS_BLEND_MIX %d\n", sel.blend_mix)
+ format("#define PS_PABE %d\n", sel.pabe)
+ format("#define PS_SCANMSK %d\n", sel.scanmsk)
+ format("#define PS_SCALE_FACTOR %d\n", GSConfig.UpscaleMultiplier)
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ VkShaderModule GSDeviceVK::GetTFXFragmentShader(GSHWDrawConfig::PSSelector sel)
AddMacro(ss, "PS_BLEND_B", sel.blend_b);
AddMacro(ss, "PS_BLEND_C", sel.blend_c);
AddMacro(ss, "PS_BLEND_D", sel.blend_d);
AddMacro(ss, "PS_ALPHA_CLAMP", sel.alpha_clamp);
AddMacro(ss, "PS_BLEND_MIX", sel.blend_mix);
AddMacro(ss, "PS_IIP", sel.iip);
AddMacro(ss, "PS_SHUFFLE", sel.shuffle);
AddMacro(ss, "PS_READ_BA", sel.read_ba);
Expand Down