From 0978ea6d168fa8bfb1b4f50cac26b013744660f6 Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:06:37 +0200 Subject: [PATCH] GS/HW: Cleanup date and rt alpha min max function. Always make sure rt is checked for date, no need for individual checks. Code cleanup. Some other cleanups. --- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 53 +++++++++++--------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index 0647966f1aa54..27536fa17bd8d 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -5206,7 +5206,7 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta #endif const GSDrawingEnvironment& env = *m_draw_env; - bool DATE = m_cached_ctx.TEST.DATE && m_cached_ctx.FRAME.PSM != PSMCT24; + bool DATE = rt && m_cached_ctx.TEST.DATE && m_cached_ctx.FRAME.PSM != PSMCT24; bool DATE_PRIMID = false; bool DATE_BARRIER = false; bool DATE_one = false; @@ -5243,29 +5243,24 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta if (DATE) { - // Should always be true, but sanity check... - if (rt) + const bool is_overlap_alpha = m_prim_overlap != PRIM_OVERLAP_NO && !(m_cached_ctx.FRAME.FBMSK & 0x80000000); + if (m_cached_ctx.TEST.DATM == 0) { - const bool is_overlap_alpha = m_prim_overlap != PRIM_OVERLAP_NO && !(m_cached_ctx.FRAME.FBMSK & 0x80000000); - - if (m_cached_ctx.TEST.DATM == 0) - { - // Some pixles are >= 1 so some fail, or some pixels get written but the written alpha matches or exceeds 1 (so overlap doesn't always pass). - DATE = rt->m_alpha_max >= 128 || (is_overlap_alpha && rt->m_alpha_min < 128 && (GetAlphaMinMax().max >= 128 || (m_context->FBA.FBA || IsCoverageAlpha()))); + // Some pixles are >= 1 so some fail, or some pixels get written but the written alpha matches or exceeds 1 (so overlap doesn't always pass). + DATE = rt->m_alpha_max >= 128 || (is_overlap_alpha && rt->m_alpha_min < 128 && (GetAlphaMinMax().max >= 128 || (m_context->FBA.FBA || IsCoverageAlpha()))); - // All pixels fail. - if (DATE && rt->m_alpha_min >= 128) - return; - } - else - { - // Some pixles are < 1 so some fail, or some pixels get written but the written alpha goes below 1 (so overlap doesn't always pass). - DATE = rt->m_alpha_min < 128 || (is_overlap_alpha && rt->m_alpha_max >= 128 && (GetAlphaMinMax().min < 128 && !(m_context->FBA.FBA || IsCoverageAlpha()))); + // All pixels fail. + if (DATE && rt->m_alpha_min >= 128) + return; + } + else + { + // Some pixles are < 1 so some fail, or some pixels get written but the written alpha goes below 1 (so overlap doesn't always pass). + DATE = rt->m_alpha_min < 128 || (is_overlap_alpha && rt->m_alpha_max >= 128 && (GetAlphaMinMax().min < 128 && !(m_context->FBA.FBA || IsCoverageAlpha()))); - // All pixels fail. - if (DATE && rt->m_alpha_max < 128) - return; - } + // All pixels fail. + if (DATE && rt->m_alpha_max < 128) + return; } } @@ -5280,18 +5275,11 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta int rt_new_alpha_min = 0, rt_new_alpha_max = 255; if (rt) { - rt_new_alpha_min = rt->m_alpha_min; - rt_new_alpha_max = rt->m_alpha_max; + blend_alpha_min = rt_new_alpha_min = rt->m_alpha_min; + blend_alpha_max = rt_new_alpha_max = rt->m_alpha_max; - blend_alpha_min = rt_new_alpha_min; - blend_alpha_max = rt_new_alpha_max; - - const bool is_24_bit = (GSLocalMemory::m_psm[rt->m_TEX0.PSM].trbpp == 24); - // On DX FBMask emulation can be missing on lower blend levels, so we'll do whatever the API does. - const u32 fb_mask = m_conf.colormask.wa ? (m_conf.ps.fbmask ? m_conf.cb_ps.FbMask.a : 0) : 0xFF; - const u32 alpha_mask = (GSLocalMemory::m_psm[rt->m_TEX0.PSM].fmsk & 0xFF000000) >> 24; const int fba_value = m_draw_env->CTXT[m_draw_env->PRIM.CTXT].FBA.FBA * 128; - + const bool is_24_bit = (GSLocalMemory::m_psm[rt->m_TEX0.PSM].trbpp == 24); if (is_24_bit) { // C24/Z24 - alpha is 1. @@ -5308,6 +5296,9 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta const bool always_passing_alpha = !m_cached_ctx.TEST.ATE || afail_always_fb_alpha || (m_cached_ctx.TEST.ATE && m_cached_ctx.TEST.ATST == ATST_ALWAYS); const bool full_cover = rt->m_valid.rintersect(m_r).eq(rt->m_valid) && PrimitiveCoversWithoutGaps() && !(DATE || !always_passing_alpha || !IsDepthAlwaysPassing()); + // On DX FBMask emulation can be missing on lower blend levels, so we'll do whatever the API does. + const u32 fb_mask = m_conf.colormask.wa ? (m_conf.ps.fbmask ? m_conf.cb_ps.FbMask.a : 0) : 0xFF; + const u32 alpha_mask = (GSLocalMemory::m_psm[rt->m_TEX0.PSM].fmsk & 0xFF000000) >> 24; if ((fb_mask & alpha_mask) == 0) { if (full_cover)