From d812d83dda35a9ced0cde764e90457d1b8bcff61 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Tue, 1 Aug 2023 10:29:56 +0100 Subject: [PATCH] GS/HW: Limit alpha range on 16bit targets --- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 24 ++++++++++++++++++++++++ pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index 4025bbfe8f..bfaf4d0d50 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -4772,6 +4772,12 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta blend_alpha_min = std::min(blend_alpha_min, rt->m_alpha_min); blend_alpha_max = std::max(blend_alpha_max, rt->m_alpha_max); } + + if (!rt->m_32_bits_fmt) + { + rt->m_alpha_max &= 128; + rt->m_alpha_min &= 128; + } } // Not gonna spend too much time with this, it's not likely to be used much, can't be less accurate than it was. @@ -4780,6 +4786,12 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta ds->m_alpha_max = std::max(ds->m_alpha_max, static_cast(m_vt.m_max.p.z) >> 24); ds->m_alpha_min = std::min(ds->m_alpha_min, static_cast(m_vt.m_min.p.z) >> 24); GL_INS("New DS Alpha Range: %d-%d", ds->m_alpha_min, ds->m_alpha_max); + + if (GSLocalMemory::m_psm[ds->m_TEX0.PSM].bpp == 16) + { + ds->m_alpha_max &= 128; + ds->m_alpha_min &= 128; + } } bool blending_alpha_pass = false; @@ -5570,6 +5582,12 @@ bool GSRendererHW::TryTargetClear(GSTextureCache::Target* rt, GSTextureCache::Ta g_gs_device->ClearRenderTarget(rt->m_texture, c); rt->m_alpha_max = c >> 24; rt->m_alpha_min = c >> 24; + + if (!rt->m_32_bits_fmt) + { + rt->m_alpha_max &= 128; + rt->m_alpha_min &= 128; + } } else { @@ -5588,6 +5606,12 @@ bool GSRendererHW::TryTargetClear(GSTextureCache::Target* rt, GSTextureCache::Ta g_gs_device->ClearDepth(ds->m_texture, d); ds->m_alpha_max = z >> 24; ds->m_alpha_min = z >> 24; + + if (GSLocalMemory::m_psm[ds->m_TEX0.PSM].bpp == 16) + { + ds->m_alpha_max &= 128; + ds->m_alpha_min &= 128; + } } else { diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 00f0c9e45c..cce19b97f4 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -5211,7 +5211,7 @@ void GSTextureCache::Target::Update() } m_alpha_min = 0; - m_alpha_max = 255; + m_alpha_max = m_32_bits_fmt ? 255 : 128; g_gs_device->Recycle(t); m_dirty.clear(); }