Skip to content

Commit

Permalink
GS/HW: Implement dithering on blend second pass on some formulas.
Browse files Browse the repository at this point in the history
Alpha = As or Af
Cs + Cd*Alpha, Cs - Cd*Alpha.
  • Loading branch information
lightningterror committed May 1, 2024
1 parent 8f57d8a commit df6a33e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/Common/GSDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ struct alignas(16) GSHWDrawConfig
{
BlendState blend;
u8 blend_hw;
u8 dither;
bool enable;
};
static_assert(sizeof(BlendPass) == 8, "blend pass is 8 bytes");
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/DX11/GSDevice11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,7 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config)
if (config.blend_second_pass.enable)
{
config.ps.blend_hw = config.blend_second_pass.blend_hw;
config.ps.dither = config.blend_second_pass.dither;
SetupPS(config.ps, &config.cb_ps, config.sampler);
SetupOM(config.depth, OMBlendSelector(config.colormask, config.blend_second_pass.blend), config.blend_second_pass.blend.constant);
DrawIndexedPrimitive();
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/DX12/GSDevice12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3950,6 +3950,7 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config)

pipe.bs = config.blend_second_pass.blend;
pipe.ps.blend_hw = config.blend_second_pass.blend_hw;
pipe.ps.dither = config.blend_second_pass.dither;
if (BindDrawPipeline(pipe))
DrawIndexedPrimitive();
}
Expand Down
3 changes: 3 additions & 0 deletions pcsx2/GS/Renderers/HW/GSRendererHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4443,14 +4443,17 @@ void GSRendererHW::EmulateBlending(int rt_alpha_min, int rt_alpha_max, bool& DAT
{
// Alpha = As or Af.
// Cs + Cd*Alpha, Cs - Cd*Alpha.
const u8 dither = m_conf.ps.dither;
// Render pass 1: Calculate Cd*Alpha with an alpha range of 0-2.
m_conf.ps.blend_hw = 2;
m_conf.ps.dither = 0;
blend.src = GSDevice::DST_COLOR;
blend.dst = (m_conf.ps.blend_c == 2) ? GSDevice::CONST_COLOR : GSDevice::SRC1_COLOR;
blend.op = GSDevice::OP_ADD;
// Render pass 2: Add or subtract result of render pass 1(Cd) from Cs.
m_conf.blend_second_pass.enable = true;
m_conf.blend_second_pass.blend_hw = 0;
m_conf.blend_second_pass.dither = dither;
m_conf.blend_second_pass.blend = {true, blend_second_pass.src, GSDevice::CONST_ONE, blend_second_pass.op, GSDevice::CONST_ONE, GSDevice::CONST_ZERO, false, 0};
}
else if (alpha_c1_high_no_rta_correct && (blend_flag & BLEND_HW5))
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,7 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
OMSetBlendState();
}
psel.ps.blend_hw = config.blend_second_pass.blend_hw;
psel.ps.dither = config.blend_second_pass.dither;
SetupPipeline(psel);
SendHWDraw(config, psel.ps.IsFeedbackLoop());
}
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5844,6 +5844,7 @@ void GSDeviceVK::RenderHW(GSHWDrawConfig& config)

pipe.bs = config.blend_second_pass.blend;
pipe.ps.blend_hw = config.blend_second_pass.blend_hw;
pipe.ps.dither = config.blend_second_pass.dither;
if (BindDrawPipeline(pipe))
DrawIndexedPrimitive();
}
Expand Down

0 comments on commit df6a33e

Please sign in to comment.