From 373e698545127559cf5b8ec615cf2f27edf62a37 Mon Sep 17 00:00:00 2001 From: iMineLink Date: Mon, 29 Nov 2021 01:02:02 +0100 Subject: [PATCH] GS-hw, TC: fix tex scaling for native res draws. The GSTextureCache::ScaleTexture method did not work correctly when an old texture with a scale factor different from 1 was recycled for a draw which was forced at native resolution (the old scale factor was kept). --- pcsx2/GS/Renderers/Common/GSRenderer.h | 1 + pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 23 +++++++++++++++++++++++ pcsx2/GS/Renderers/HW/GSRendererHW.h | 1 + pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 20 ++------------------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pcsx2/GS/Renderers/Common/GSRenderer.h b/pcsx2/GS/Renderers/Common/GSRenderer.h index 19aed66a8e..8b8836aef9 100644 --- a/pcsx2/GS/Renderers/Common/GSRenderer.h +++ b/pcsx2/GS/Renderers/Common/GSRenderer.h @@ -60,6 +60,7 @@ public: virtual bool CanUpscale() { return false; } virtual int GetUpscaleMultiplier() { return 1; } virtual GSVector2i GetCustomResolution() { return GSVector2i(0, 0); } + virtual GSVector2 GetTextureScaleFactor() { return { 1.0f, 1.0f }; } GSVector2i GetInternalResolution(); void SetVSync(int vsync); diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index a519dd01a8..ec5ac9d381 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -775,6 +775,29 @@ void GSRendererHW::MergeSprite(GSTextureCache::Source* tex) } } +GSVector2 GSRendererHW::GetTextureScaleFactor() +{ + GSVector2 scale_factor{ 1.0f, 1.0f }; + if (CanUpscale()) + { + const int multiplier = GetUpscaleMultiplier(); + if (multiplier == 0) + { + // Custom resolution. + const GSVector4i display_rect = GetDisplayRect(); + const GSVector2i requested_resolution = GetCustomResolution(); + scale_factor.x = static_cast(requested_resolution.x) / display_rect.width(); + scale_factor.y = static_cast(requested_resolution.y) / display_rect.height(); + } + else + { + scale_factor.x = multiplier; + scale_factor.y = multiplier; + } + } + return scale_factor; +} + void GSRendererHW::InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r) { // printf("[%d] InvalidateVideoMem %d,%d - %d,%d %05x (%d)\n", (int)m_perfmon.GetFrame(), r.left, r.top, r.right, r.bottom, (int)BITBLTBUF.DBP, (int)BITBLTBUF.DPSM); diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.h b/pcsx2/GS/Renderers/HW/GSRendererHW.h index ee6aa29802..2ae25779bd 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.h +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.h @@ -179,6 +179,7 @@ public: GSVector4 RealignTargetTextureCoordinate(const GSTextureCache::Source* tex); GSVector4i ComputeBoundingBox(const GSVector2& rtscale, const GSVector2i& rtsize); void MergeSprite(GSTextureCache::Source* tex); + GSVector2 GetTextureScaleFactor(); void Reset(); void VSync(int field); diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index e19ccf6716..7c515bff27 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -498,24 +498,8 @@ GSTextureCache::Source* GSTextureCache::LookupSource(const GIFRegTEX0& TEX0, con void GSTextureCache::ScaleTexture(GSTexture* texture) { - if (!m_renderer->CanUpscale()) - return; - - float multiplier = static_cast(m_renderer->GetUpscaleMultiplier()); - bool custom_resolution = (multiplier == 0); - GSVector2 scale_factor(multiplier); - - if (custom_resolution) - { - int width = m_renderer->GetDisplayRect().width(); - int height = m_renderer->GetDisplayRect().height(); - - GSVector2i requested_resolution = m_renderer->GetCustomResolution(); - scale_factor.x = static_cast(requested_resolution.x) / width; - scale_factor.y = static_cast(requested_resolution.y) / height; - } - - texture->SetScale(scale_factor); + if (texture) + texture->SetScale(m_renderer->GetTextureScaleFactor()); } bool GSTextureCache::ShallSearchTextureInsideRt()