From ce20544a4f2b78997dadece493ea82fde1d7079f Mon Sep 17 00:00:00 2001 From: Akash Date: Sat, 25 Jun 2016 21:55:50 +0530 Subject: [PATCH 1/3] GSDX-TextureCache: Remove hacks which caused scaling issues * Ignore Frame memory offsets for calculating dimensions value of display rectangle. * Remove hack which limited scaling size based on the scissor value. Note: With the following commit, SilentHill 2 now properly outputs the desired resolution by the users on custom resolution. Previously if we set 1024 x 1024 , it'll output a lower height value which was caused by the hack removed on this commit. --- plugins/GSdx/GSTextureCache.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 3c499dc106..a8af5eee70 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -472,21 +472,8 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int } else // Custom resolution hack { - GSVector4i fr = m_renderer->GetFrameRect(); - - int ww = (int)(fr.left + m_renderer->GetDisplayRect().width()); - int hh = (int)(fr.top + m_renderer->GetDisplayRect().height()); - - // Gregory: I'm sure this sillyness is related to the usage of a 32bits - // buffer as a 16 bits format. In this case the height of the buffer is - // multiplyed by 2 (Hence a scissor bigger than the RT) - - // This vp2 fix doesn't work most of the time - - if(hh < 512 && m_renderer->m_context->SCISSOR.SCAY1 == 511) // vp2 - { - hh = 512; - } + int ww = m_renderer->GetDisplayRect().width(); + int hh = m_renderer->GetDisplayRect().height(); if(ww && hh) { From a5671f016a83e517093806bc45130844b6706203 Mon Sep 17 00:00:00 2001 From: Akash Date: Sun, 26 Jun 2016 11:33:16 +0530 Subject: [PATCH 2/3] GSDX-TextureCache: Add proper scaling for custom resolution * Improve frame buffer height management on custom resolution. Width seems to be fine with the same size as scaled image output. * Prevent offset issues on Persona 3 based on the data from merge circuit. Note: Fixes custom resolution upscaling on ICO 50Hz/60Hz mode when large frame buffer is enabled. previously 60Hz mode only displayed half of the screen and 50Hz mode only worked due to the scissor hack. --- plugins/GSdx/GSRenderer.h | 1 + plugins/GSdx/GSRendererHW.cpp | 26 ++++++++++++++++++++++---- plugins/GSdx/GSRendererHW.h | 3 +++ plugins/GSdx/GSSettingsDlg.cpp | 2 +- plugins/GSdx/GSTextureCache.cpp | 28 ++++++++++++++++------------ 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/plugins/GSdx/GSRenderer.h b/plugins/GSdx/GSRenderer.h index c4059f813c..06abd0a3dc 100644 --- a/plugins/GSdx/GSRenderer.h +++ b/plugins/GSdx/GSRenderer.h @@ -69,6 +69,7 @@ public: virtual void KeyEvent(GSKeyEventData* e); virtual bool CanUpscale() {return false;} virtual int GetUpscaleMultiplier() {return 1;} + virtual GSVector2i GetCustomResolution() {return GSVector2i(0,0);} GSVector2i GetInternalResolution(); void SetAspectRatio(int aspect) {m_aspectratio = aspect;} void SetVSync(bool enabled); diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index 4b2af8f387..abe6708bb1 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -44,8 +44,8 @@ GSRendererHW::GSRendererHW(GSTextureCache* tc) } if (!m_upscale_multiplier) { //Custom Resolution - m_width = theApp.GetConfigI("resx"); - m_height = theApp.GetConfigI("resy"); + m_custom_width = m_width = theApp.GetConfigI("resx"); + m_custom_height = m_height = theApp.GetConfigI("resy"); } if (m_upscale_multiplier == 1) { // hacks are only needed for upscaling issues. @@ -103,6 +103,20 @@ void GSRendererHW::SetScaling() int upscaled_fb_w = fb_width * m_upscale_multiplier; int upscaled_fb_h = fb_height * m_upscale_multiplier; bool good_rt_size = m_width >= upscaled_fb_w && m_height >= upscaled_fb_h; + bool initialized_register_state = (m_context->FRAME.FBW > 1) && (crtc_size.y > 1); + + if (!m_upscale_multiplier && initialized_register_state) + { + if (m_height == m_custom_height) + { + float ratio = ceil(static_cast(m_height) / crtc_size.y); + float buffer_scale_offset = (m_large_framebuffer) ? ratio : 0.5f; + ratio = round(ratio + buffer_scale_offset); + + m_tc->RemovePartial(); + m_height = crtc_size.y * ratio; + } + } // No need to resize for native/custom resolutions as default size will be enough for native and we manually get RT Buffer size for custom. // don't resize until the display rectangle and register states are stabilized. @@ -139,8 +153,12 @@ bool GSRendererHW::CanUpscale() int GSRendererHW::GetUpscaleMultiplier() { - // Custom resolution (currently 0) needs an upscale multiplier of 1. - return m_upscale_multiplier ? m_upscale_multiplier : 1; + return m_upscale_multiplier; +} + +GSVector2i GSRendererHW::GetCustomResolution() +{ + return GSVector2i(m_custom_width, m_custom_height); } void GSRendererHW::Reset() diff --git a/plugins/GSdx/GSRendererHW.h b/plugins/GSdx/GSRendererHW.h index 2378377dd8..c6b3041537 100644 --- a/plugins/GSdx/GSRendererHW.h +++ b/plugins/GSdx/GSRendererHW.h @@ -32,6 +32,8 @@ class GSRendererHW : public GSRenderer private: int m_width; int m_height; + int m_custom_width; + int m_custom_height; bool m_reset; int m_upscale_multiplier; @@ -162,6 +164,7 @@ public: void SetGameCRC(uint32 crc, int options); bool CanUpscale(); int GetUpscaleMultiplier(); + GSVector2i GetCustomResolution(); void SetScaling(); void Reset(); diff --git a/plugins/GSdx/GSSettingsDlg.cpp b/plugins/GSdx/GSSettingsDlg.cpp index 37751151d9..d719e47180 100644 --- a/plugins/GSdx/GSSettingsDlg.cpp +++ b/plugins/GSdx/GSSettingsDlg.cpp @@ -389,7 +389,7 @@ void GSSettingsDlg::UpdateControls() ShowWindow(GetDlgItem(m_hWnd, IDC_TC_DEPTH), ogl ? SW_SHOW : SW_HIDE); EnableWindow(GetDlgItem(m_hWnd, IDC_CRC_LEVEL), hw); - EnableWindow(GetDlgItem(m_hWnd, IDC_LARGE_FB), integer_scaling > 1 && hw); + EnableWindow(GetDlgItem(m_hWnd, IDC_LARGE_FB), integer_scaling != 1 && hw); EnableWindow(GetDlgItem(m_hWnd, IDC_CRC_LEVEL_TEXT), hw); EnableWindow(GetDlgItem(m_hWnd, IDC_OPENCL_DEVICE), ocl); EnableWindow(GetDlgItem(m_hWnd, IDC_RESX), hw && !integer_scaling); diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index a8af5eee70..8c01b4017b 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -464,22 +464,26 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int if(m_renderer->CanUpscale()) { - int multiplier = m_renderer->GetUpscaleMultiplier(); + float multiplier = static_cast(m_renderer->GetUpscaleMultiplier()); + GSVector2 scale_factor(multiplier, multiplier); - if(multiplier > 1) + if(!multiplier) //Custom Resolution { - dst->m_texture->SetScale(GSVector2((float)multiplier, (float)multiplier)); - } - else // Custom resolution hack - { - int ww = m_renderer->GetDisplayRect().width(); - int hh = m_renderer->GetDisplayRect().height(); + int width = m_renderer->GetDisplayRect().width(); + int height = m_renderer->GetDisplayRect().height(); + int real_height = static_cast(round(m_renderer->GetInternalResolution().y / dst->m_texture->GetScale().y)); - if(ww && hh) - { - dst->m_texture->SetScale(GSVector2((float)w / ww, (float)h / hh)); - } + // Fixes offset issues on Persona 3 (512x511) where real value of height is 512 + if(real_height % height == 1) + height = real_height; + + GSVector2i custom_resolution = m_renderer->GetCustomResolution(); + scale_factor.x = static_cast(custom_resolution.x) / width; + scale_factor.y = static_cast(custom_resolution.y) / height; } + + if(scale_factor.x && scale_factor.y) + dst->m_texture->SetScale(scale_factor); } if(used) From 309a8283b2c99d29865055b33c376ac87a55fe42 Mon Sep 17 00:00:00 2001 From: Akash Date: Fri, 1 Jul 2016 17:51:07 +0530 Subject: [PATCH 3/3] GSDX-TextureCache: Don't allow RT size below default value Fixes upscaling issues on Burnout dominator where setting custom resolution of 640x448 looks way worse than the native resolution. --- plugins/GSdx/GSRendererHW.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index abe6708bb1..77cffcbb6a 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -114,7 +114,8 @@ void GSRendererHW::SetScaling() ratio = round(ratio + buffer_scale_offset); m_tc->RemovePartial(); - m_height = crtc_size.y * ratio; + m_width = max(m_width, 1280); + m_height = max(static_cast(crtc_size.y * ratio) , 1024); } }