From 73595d93f315863cd8163a82b3ad6f18c46c7fe9 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Wed, 5 Feb 2025 01:16:16 +0000 Subject: [PATCH] GS/HW: Fix some format conversion scaling problems --- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 14 ++++++++------ pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index 57f14578e1..a59fd52ee0 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -2254,6 +2254,8 @@ void GSRendererHW::Draw() m_conf.scissor.w = m_conf.scissor.y + (((num_skipped_channel_shuffle_draws + 1 + (m_channel_shuffle_width - 1)) / std::max(1U, m_channel_shuffle_width)) * 32) * m_conf.cb_ps.ScaleFactor.z; if (width_pages) m_conf.scissor.z = m_conf.scissor.x + (((num_skipped_channel_shuffle_draws + 1) % std::max(1U, m_channel_shuffle_width) % std::max(1U, m_channel_shuffle_width)) * 64) * m_conf.cb_ps.ScaleFactor.z; + + m_last_rt->UpdateValidity(GSVector4i::loadh(m_last_rt->m_unscaled_size).rintersect(GSVector4i(GSVector4(m_conf.scissor) / m_conf.cb_ps.ScaleFactor.z)), true); } g_gs_device->RenderHW(m_conf); @@ -3715,13 +3717,13 @@ void GSRendererHW::Draw() update_rect.z = buffer_width; } - if (m_in_target_draw && src && m_channel_shuffle && src->m_from_target && src->m_from_target == rt && m_cached_ctx.TEX0.TBP0 == src->m_from_target->m_TEX0.TBP0) + /*if (m_in_target_draw && src && m_channel_shuffle && src->m_from_target && src->m_from_target == rt && m_cached_ctx.TEX0.TBP0 == src->m_from_target->m_TEX0.TBP0) { - new_size.y = std::max(new_size.y, static_cast((((m_cached_ctx.FRAME.Block() - rt->m_TEX0.TBP0) >> 5) / rt->m_TEX0.TBW) * frame_psm.pgs.y) * 2); + new_size.y = std::max(new_size.y, static_cast((((m_cached_ctx.FRAME.Block() - rt->m_TEX0.TBP0) >> 5) / rt->m_TEX0.TBW) * frame_psm.pgs.y)); GSVector4i new_valid = rt->m_valid; - new_valid.w = new_size.y; + new_valid.w = std::max(new_valid.w, static_cast((((m_cached_ctx.FRAME.Block() - rt->m_TEX0.TBP0) >> 5) / rt->m_TEX0.TBW) * frame_psm.pgs.y) + frame_psm.pgs.y); rt->UpdateValidity(new_valid, true); - } + }*/ // We still need to make sure the dimensions of the targets match. // Limit new size to 2048, the GS can't address more than this so may avoid some bugs/crashes. @@ -4056,8 +4058,8 @@ void GSRendererHW::Draw() const GSVector4i dRect = GSVector4i(0, z_vertical_offset * ds->m_scale, ds->m_unscaled_size.x * ds->m_scale, std::min(z_vertical_offset + m_r.w + 1 - vertical_offset, ds->m_unscaled_size.y) * ds->m_scale); GL_CACHE("RT in RT Z copy back draw %d z_vert_offset %d z_offset %d", s_n, z_vertical_offset, vertical_offset); - g_gs_device->StretchRect(g_texture_cache->GetTemporaryZ(), GSVector4(0.0f, vertical_offset / static_cast(g_texture_cache->GetTemporaryZ()->GetHeight()), 1.0f, - std::min(real_rect.w + 1, ds->m_unscaled_size.y + vertical_offset) / static_cast(g_texture_cache->GetTemporaryZ()->GetHeight())), ds->m_texture, GSVector4(dRect), ShaderConvert::DEPTH_COPY, false); + g_gs_device->StretchRect(g_texture_cache->GetTemporaryZ(), GSVector4(0.0f, (static_cast(vertical_offset) * ds->m_scale) / static_cast(g_texture_cache->GetTemporaryZ()->GetHeight()), 1.0f, + floor(static_cast(std::min(real_rect.w + 1, ds->m_unscaled_size.y + vertical_offset)) * ds->m_scale) / static_cast(g_texture_cache->GetTemporaryZ()->GetHeight())), ds->m_texture, GSVector4(dRect), ShaderConvert::DEPTH_COPY, false); } } } diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index b097766eaf..9f5195e2cd 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -2369,15 +2369,14 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(GIFRegTEX0 TEX0, const GSVe { if (scale_down) { - if ((new_size.y * 2) < 1024) - { - new_scaled_size.y *= 2; - new_size.y *= 2; - dst->m_valid.y *= 2; - dst->m_valid.w *= 2; - } + new_scaled_size.y *= 2; + dst->m_valid.y *= 2; + dst->m_valid.w *= 2; dRect.y *= 2; dRect.w *= 2; + + new_size.y *= 2; + new_size.y = std::max(dst->m_valid.w, new_size.y); } else { @@ -2387,6 +2386,7 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(GIFRegTEX0 TEX0, const GSVe dRect.w /= 2; dst->m_valid.y /= 2; dst->m_valid.w /= 2; + new_size.y = std::max(dst->m_valid.w, new_size.y); } } if (!is_shuffle) @@ -2627,7 +2627,7 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(GIFRegTEX0 TEX0, const GSVe dst->m_valid = dst_match->m_valid; dst->m_valid_alpha_low = dst_match->m_valid_alpha_low; //&& psm_s.trbpp != 24; dst->m_valid_alpha_high = dst_match->m_valid_alpha_high; //&& psm_s.trbpp != 24; - dst->m_valid_rgb = dst_match->m_valid_rgb; + dst->m_valid_rgb = dst_match->m_valid_rgb && (dst->m_TEX0.TBW == TEX0.TBW || min_rect.w <= GSLocalMemory::m_psm[dst_match->m_TEX0.PSM].pgs.y); dst->m_was_dst_matched = true; dst_match->m_was_dst_matched = true; dst_match->m_valid_rgb = preserve_rgb;