From ab77eb46462a632646e8601a521cb9d3668548f4 Mon Sep 17 00:00:00 2001 From: sudonim1 Date: Sun, 23 May 2010 15:33:50 +0000 Subject: [PATCH] GSDx: Free textures that have been in the unused texture pool for a few frames. GSDx: Reset device on save state load. GSDx: Made GSRenderer::ResetDevice() actually do the main function in its name and implemented InvalidateTextureCache(). If anything breaks, it's because of this change. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3067 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GS.cpp | 1 + plugins/GSdx/GSDevice.cpp | 12 ++++++++++++ plugins/GSdx/GSDevice.h | 3 +++ plugins/GSdx/GSRenderer.h | 1 + plugins/GSdx/GSRendererHW.h | 7 ++++++- plugins/GSdx/GSRendererSW.h | 5 +++++ plugins/GSdx/GSTexture.h | 6 +++++- 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index 2092a8eefa..5ec7636bf4 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -368,6 +368,7 @@ EXPORT_C_(int) GSfreeze(int mode, GSFreezeData* data) } else if(mode == FREEZE_LOAD) { + s_gs->ResetDevice(); return s_gs->Defrost(data); } diff --git a/plugins/GSdx/GSDevice.cpp b/plugins/GSdx/GSDevice.cpp index 7793eb0ddf..ab3818d11c 100644 --- a/plugins/GSdx/GSDevice.cpp +++ b/plugins/GSdx/GSDevice.cpp @@ -32,6 +32,7 @@ GSDevice::GSDevice() , m_weavebob(NULL) , m_blend(NULL) , m_1x1(NULL) + , m_frame(0) { memset(&m_vertices, 0, sizeof(m_vertices)); @@ -143,6 +144,7 @@ void GSDevice::Recycle(GSTexture* t) { if(t) { + t->last_frame_used = m_frame; m_pool.push_front(t); //printf("%d\n",m_pool.size()); while(m_pool.size() > 300) @@ -154,6 +156,16 @@ void GSDevice::Recycle(GSTexture* t) } } +void GSDevice::AgePool() +{ + m_frame++; + while (m_pool.size() > 20 && m_frame - m_pool.back()->last_frame_used > 10) + { + delete m_pool.back(); + m_pool.pop_back(); + } +} + GSTexture* GSDevice::CreateRenderTarget(int w, int h, bool msaa, int format) { return Fetch(GSTexture::RenderTarget, w, h, msaa, format); diff --git a/plugins/GSdx/GSDevice.h b/plugins/GSdx/GSDevice.h index 66a1067162..b2af6ae9e2 100644 --- a/plugins/GSdx/GSDevice.h +++ b/plugins/GSdx/GSDevice.h @@ -66,6 +66,7 @@ protected: struct {size_t stride, start, count, limit;} m_vertices; uint32 m_msaa; DXGI_SAMPLE_DESC m_msaa_desc; + unsigned m_frame; // for ageing the pool virtual GSTexture* Create(int type, int w, int h, bool msaa, int format) = 0; @@ -146,4 +147,6 @@ public: } bool SetFeatureLevel(D3D_FEATURE_LEVEL level, bool compat_mode); // TODO: GSDeviceDX + + void AgePool(); }; diff --git a/plugins/GSdx/GSRenderer.h b/plugins/GSdx/GSRenderer.h index 542e5f65ac..bd2239651d 100644 --- a/plugins/GSdx/GSRenderer.h +++ b/plugins/GSdx/GSRenderer.h @@ -81,6 +81,7 @@ public: { InvalidateTextureCache(); ResetPrim(); + m_dev->Reset(1, 1); } virtual void VSync(int field); virtual bool MakeSnapshot(const string& path); diff --git a/plugins/GSdx/GSRendererHW.h b/plugins/GSdx/GSRendererHW.h index b46d468a48..332c9423db 100644 --- a/plugins/GSdx/GSRendererHW.h +++ b/plugins/GSdx/GSRendererHW.h @@ -467,6 +467,7 @@ protected: __super::VSync(field); m_tc->IncAge(); + m_dev->AgePool(); m_skip = 0; @@ -478,10 +479,14 @@ protected: } } + void InvalidateTextureCache() + { + m_tc->RemoveAll(); + } + void ResetDevice() { __super::ResetDevice(); - m_tc->RemoveAll(); } GSTexture* GetOutput(int i) diff --git a/plugins/GSdx/GSRendererSW.h b/plugins/GSdx/GSRendererSW.h index cb47750e64..f6b09b623c 100644 --- a/plugins/GSdx/GSRendererSW.h +++ b/plugins/GSdx/GSRendererSW.h @@ -49,4 +49,9 @@ public: template void VertexKick(bool skip); + + void InvalidateTextureCache() + { + m_tc->RemoveAll(); + } }; diff --git a/plugins/GSdx/GSTexture.h b/plugins/GSdx/GSTexture.h index 968a648690..ed9bb7f7e2 100644 --- a/plugins/GSdx/GSTexture.h +++ b/plugins/GSdx/GSTexture.h @@ -59,7 +59,11 @@ public: int GetFormat() const {return m_format;} bool IsMSAA() const {return m_msaa;} - + + // frame number (arbitrary base) the texture was recycled on + // different purpose than texture cache ages, do not attempt to merge + unsigned last_frame_used; + bool LikelyOffset; float OffsetHack_modx; float OffsetHack_mody;