From 97b237712ca91564ce80e19db8c3ae0a1007e8f8 Mon Sep 17 00:00:00 2001 From: refraction Date: Wed, 13 May 2015 20:00:25 +0200 Subject: [PATCH] gsdx: detect RT size based on fb size and gs output configuration * It is required for snowbling games * Targets of Texture cache are dropped. --- plugins/GSdx/GSRendererHW.cpp | 39 ++++++++++++++++++++++++--------- plugins/GSdx/GSRendererHW.h | 3 +++ plugins/GSdx/GSTextureCache.cpp | 12 ++++++++++ plugins/GSdx/GSTextureCache.h | 2 ++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index 3437ea2c7..96784c6d2 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -34,22 +34,37 @@ GSRendererHW::GSRendererHW(GSTextureCache* tc) m_userhacks_skipdraw = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_SkipDraw", 0) : 0; m_userhacks_align_sprite_X = !!theApp.GetConfig("UserHacks_align_sprite_X", 0) && !!theApp.GetConfig("UserHacks", 0); m_userhacks_round_sprite_offset = !!theApp.GetConfig("UserHacks", 0) ? theApp.GetConfig("UserHacks_round_sprite_offset", 0) : 0; +} - if(!m_nativeres) +void GSRendererHW::SetScaling(){ + int env = IsEnabled(1) ? 1 : 0; + + m_buffer_size = max(m_context->FRAME.FBW, m_regs->DISP[env].DISPFB.FBW); + + if (m_upscale_multiplier < 6 && (m_width / m_upscale_multiplier) != (m_buffer_size * 64)){ + printf("Frame buffer width on vsync %d m_width %d\n", m_buffer_size, (m_width / m_upscale_multiplier)); + m_tc->RemovePartial(); + } + else { + return; + } + + if (!m_nativeres) { m_width = theApp.GetConfig("resx", m_width); m_height = theApp.GetConfig("resy", m_height); m_upscale_multiplier = theApp.GetConfig("upscale_multiplier", m_upscale_multiplier); - if(m_upscale_multiplier > 6) + if (m_upscale_multiplier > 6) { m_upscale_multiplier = 1; // use the normal upscale math } - else if(m_upscale_multiplier > 1) + else if (m_upscale_multiplier > 1) { - m_width = 640 * m_upscale_multiplier; // 512 is also common, but this is not always detected right. - m_height = 512 * m_upscale_multiplier; // 448 is also common, but this is not always detected right. + m_width = (m_buffer_size * 64) * m_upscale_multiplier; + m_height = m_width; //Keep it square + } } else @@ -59,9 +74,15 @@ GSRendererHW::GSRendererHW(GSTextureCache* tc) if (m_upscale_multiplier == 1) { // No upscaling hack at native resolution + if (m_nativeres) { + m_width = (m_buffer_size * 64) * m_upscale_multiplier; + m_height = m_width; //Keep it square + } + m_userhacks_round_sprite_offset = 0; m_userhacks_align_sprite_X = 0; } + printf("Frame buffer width %d m_width set to %d multiplier %d", m_buffer_size, m_width, m_upscale_multiplier); } GSRendererHW::~GSRendererHW() @@ -74,11 +95,6 @@ void GSRendererHW::SetGameCRC(uint32 crc, int options) GSRenderer::SetGameCRC(crc, options); m_hacks.SetGameCRC(m_game); - - if(m_game.title == CRC::JackieChanAdv) - { - m_width = 1280; // TODO: uses a 1280px wide 16 bit render target, but this only fixes half of the problem - } } bool GSRendererHW::CanUpscale() @@ -108,6 +124,9 @@ void GSRendererHW::Reset() void GSRendererHW::VSync(int field) { + //Check if the frame buffer width or display width has changed + SetScaling(); + if(m_reset) { m_tc->RemoveAll(); diff --git a/plugins/GSdx/GSRendererHW.h b/plugins/GSdx/GSRendererHW.h index f1e09e2da..b5a73e68e 100644 --- a/plugins/GSdx/GSRendererHW.h +++ b/plugins/GSdx/GSRendererHW.h @@ -25,6 +25,7 @@ #include "GSTextureCache.h" #include "GSCrc.h" #include "GSFunctionMap.h" +#include "GSState.h" class GSRendererHW : public GSRenderer { @@ -34,6 +35,7 @@ private: int m_skip; bool m_reset; int m_upscale_multiplier; + int m_buffer_size; int m_userhacks_skipdraw; bool m_userhacks_align_sprite_X; @@ -151,6 +153,7 @@ public: void SetGameCRC(uint32 crc, int options); bool CanUpscale(); int GetUpscaleMultiplier(); + void SetScaling(); void Reset(); void VSync(int field); diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index ff5a13556..7eb86d74a 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -40,6 +40,18 @@ GSTextureCache::~GSTextureCache() _aligned_free(m_temp); } +void GSTextureCache::RemovePartial() +{ + //m_src.RemoveAll(); + + for (int type = 0; type < 2; type++) + { + for_each(m_dst[type].begin(), m_dst[type].end(), delete_object()); + + m_dst[type].clear(); + } +} + void GSTextureCache::RemoveAll() { m_src.RemoveAll(); diff --git a/plugins/GSdx/GSTextureCache.h b/plugins/GSdx/GSTextureCache.h index 63ec2b260..04f71b4aa 100644 --- a/plugins/GSdx/GSTextureCache.h +++ b/plugins/GSdx/GSTextureCache.h @@ -99,6 +99,7 @@ public: void Add(Source* s, const GIFRegTEX0& TEX0, const GSOffset* off); void RemoveAll(); + void RemovePartial(); void RemoveAt(Source* s); }; @@ -128,6 +129,7 @@ public: virtual void Read(Target* t, const GSVector4i& r) = 0; #endif void RemoveAll(); + void RemovePartial(); Source* LookupSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GSVector4i& r); Target* LookupTarget(const GIFRegTEX0& TEX0, int w, int h, int type, bool used);