From fb2684204617bc2556a86b3d370b384b72ce7f32 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 27 Aug 2023 13:39:20 +1000 Subject: [PATCH] GS/HW: Fix depth getting discarded with DATE on --- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 28 +++++++++++--------------- pcsx2/GS/Renderers/HW/GSRendererHW.h | 3 ++- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index 0ed0e6edf4..45b5fac59b 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -1873,7 +1873,7 @@ void GSRendererHW::Draw() const u32 frame_end_bp = GSLocalMemory::GetUnwrappedEndBlockAddress(m_cached_ctx.FRAME.Block(), m_cached_ctx.FRAME.FBW, m_cached_ctx.FRAME.PSM, m_r); const bool tex_is_rt = (process_texture && m_cached_ctx.TEX0.TBP0 >= m_cached_ctx.FRAME.Block() && m_cached_ctx.TEX0.TBP0 < frame_end_bp); - const bool not_writing_to_all = (!PrimitiveCoversWithoutGaps() || !all_depth_tests_pass); + const bool not_writing_to_all = (!PrimitiveCoversWithoutGaps() || AreAnyPixelsDiscarded() || !all_depth_tests_pass); const bool preserve_rt_rgb = (!no_rt && (!IsDiscardingDstRGB() || not_writing_to_all || tex_is_rt)); const bool preserve_rt_alpha = (!no_rt && (!IsDiscardingDstAlpha() || not_writing_to_all || @@ -6064,33 +6064,29 @@ bool GSRendererHW::OI_BlitFMV(GSTextureCache::Target* _rt, GSTextureCache::Sourc return true; } +bool GSRendererHW::AreAnyPixelsDiscarded() const +{ + return ((m_draw_env->SCANMSK.MSK & 2) || // skipping rows + m_cached_ctx.TEST.ATE || // testing alpha (might discard some pixels) + m_cached_ctx.TEST.DATE); // reading alpha +} + bool GSRendererHW::IsDiscardingDstColor() { return ((!PRIM->ABE || IsOpaque() || m_context->ALPHA.IsBlack()) && // no blending or writing black - !(m_draw_env->SCANMSK.MSK & 2) && // not skipping rows - !m_cached_ctx.TEST.ATE && // not testing alpha (might discard some pixels) - !m_cached_ctx.TEST.DATE && // not reading alpha - (m_cached_ctx.FRAME.FBMSK & GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmsk) == 0); // no channels masked + !AreAnyPixelsDiscarded() && (m_cached_ctx.FRAME.FBMSK & GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmsk) == 0); // no channels masked } bool GSRendererHW::IsDiscardingDstRGB() { return ((!PRIM->ABE || IsOpaque() || m_context->ALPHA.IsBlack()) && // no blending or writing black - !(m_draw_env->SCANMSK.MSK & 2) && // not skipping rows - !m_cached_ctx.TEST.ATE && // not testing alpha (might discard some pixels) - !m_cached_ctx.TEST.DATE && // not reading alpha - ((m_cached_ctx.FRAME.FBMSK & GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmsk) & 0xFFFFFFu) == - 0); // RGB isn't masked + ((m_cached_ctx.FRAME.FBMSK & GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmsk) & 0xFFFFFFu) == 0); // RGB isn't masked } -bool GSRendererHW::IsDiscardingDstAlpha() +bool GSRendererHW::IsDiscardingDstAlpha() const { return ((!PRIM->ABE || m_context->ALPHA.C != 1) && // not using Ad - !(m_draw_env->SCANMSK.MSK & 2) && // not skipping rows - !m_cached_ctx.TEST.ATE && // not testing alpha (might discard some pixels) - !m_cached_ctx.TEST.DATE && // not reading alpha - ((m_cached_ctx.FRAME.FBMSK & GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmsk) & 0xFF000000u) == - 0); // alpha isn't masked + ((m_cached_ctx.FRAME.FBMSK & GSLocalMemory::m_psm[m_cached_ctx.FRAME.PSM].fmsk) & 0xFF000000u) == 0); // alpha isn't masked } bool GSRendererHW::PrimitiveCoversWithoutGaps() diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.h b/pcsx2/GS/Renderers/HW/GSRendererHW.h index 45aedab158..6930e7d1a6 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.h +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.h @@ -63,9 +63,10 @@ private: u32 GetConstantDirectWriteMemClearColor() const; u32 GetConstantDirectWriteMemClearDepth() const; bool IsReallyDithered() const; + bool AreAnyPixelsDiscarded() const; bool IsDiscardingDstColor(); bool IsDiscardingDstRGB(); - bool IsDiscardingDstAlpha(); + bool IsDiscardingDstAlpha() const; bool PrimitiveCoversWithoutGaps(); enum class CLUTDrawTestResult