TexCache: clean up frameCount handling

This commit is contained in:
degasus 2014-05-19 18:31:38 +02:00
parent 6ba613fbd3
commit 1c98a43203
4 changed files with 16 additions and 8 deletions

View File

@ -851,7 +851,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
OSD::DrawMessages(); OSD::DrawMessages();
D3D::EndFrame(); D3D::EndFrame();
TextureCache::Cleanup(); TextureCache::Cleanup(frameCount);
// Enable configuration changes // Enable configuration changes
UpdateActiveConfig(); UpdateActiveConfig();

View File

@ -1715,7 +1715,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
} }
// Clean out old stuff from caches. It's not worth it to clean out the shader caches. // Clean out old stuff from caches. It's not worth it to clean out the shader caches.
TextureCache::Cleanup(); TextureCache::Cleanup(frameCount);
// Render to the framebuffer. // Render to the framebuffer.
FramebufferManager::SetFramebuffer(0); FramebufferManager::SetFramebuffer(0);

View File

@ -22,6 +22,7 @@
static const u64 TEXHASH_INVALID = 0; static const u64 TEXHASH_INVALID = 0;
static const int TEXTURE_KILL_THRESHOLD = 200; static const int TEXTURE_KILL_THRESHOLD = 200;
static const int RENDER_TARGET_KILL_THRESHOLD = 3; static const int RENDER_TARGET_KILL_THRESHOLD = 3;
static const u64 FRAMECOUNT_INVALID = 0;
TextureCache *g_texture_cache; TextureCache *g_texture_cache;
@ -136,13 +137,17 @@ void TextureCache::OnConfigChanged(VideoConfig& config)
backup_config.s_efb_mono_depth = config.bStereoEFBMonoDepth; backup_config.s_efb_mono_depth = config.bStereoEFBMonoDepth;
} }
void TextureCache::Cleanup() void TextureCache::Cleanup(int _frameCount)
{ {
TexCache::iterator iter = textures.begin(); TexCache::iterator iter = textures.begin();
TexCache::iterator tcend = textures.end(); TexCache::iterator tcend = textures.end();
while (iter != tcend) while (iter != tcend)
{ {
if (frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount && if(iter->second->frameCount == FRAMECOUNT_INVALID)
{
iter->second->frameCount = _frameCount;
}
if (_frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount &&
// EFB copies living on the host GPU are unrecoverable and thus shouldn't be deleted // EFB copies living on the host GPU are unrecoverable and thus shouldn't be deleted
!iter->second->IsEfbCopy()) !iter->second->IsEfbCopy())
{ {
@ -159,7 +164,7 @@ void TextureCache::Cleanup()
{ {
auto rt = render_target_pool[i]; auto rt = render_target_pool[i];
if (frameCount > RENDER_TARGET_KILL_THRESHOLD + rt->frameCount) if (_frameCount > RENDER_TARGET_KILL_THRESHOLD + rt->frameCount)
{ {
delete rt; delete rt;
render_target_pool[i] = render_target_pool.back(); render_target_pool[i] = render_target_pool.back();
@ -277,7 +282,7 @@ static u32 CalculateLevelSize(u32 level_0_size, u32 level)
// Used by TextureCache::Load // Used by TextureCache::Load
static TextureCache::TCacheEntryBase* ReturnEntry(unsigned int stage, TextureCache::TCacheEntryBase* entry) static TextureCache::TCacheEntryBase* ReturnEntry(unsigned int stage, TextureCache::TCacheEntryBase* entry)
{ {
entry->frameCount = frameCount; entry->frameCount = FRAMECOUNT_INVALID;
entry->Bind(stage); entry->Bind(stage);
GFX_DEBUGGER_PAUSE_AT(NEXT_TEXTURE_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_TEXTURE_CHANGE, true);
@ -873,7 +878,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
entry->type = TCET_EC_VRAM; entry->type = TCET_EC_VRAM;
} }
entry->frameCount = frameCount; entry->frameCount = FRAMECOUNT_INVALID;
entry->FromRenderTarget(dstAddr, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat); entry->FromRenderTarget(dstAddr, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat);
} }

View File

@ -87,7 +87,10 @@ public:
virtual ~TextureCache(); // needs virtual for DX11 dtor virtual ~TextureCache(); // needs virtual for DX11 dtor
static void OnConfigChanged(VideoConfig& config); static void OnConfigChanged(VideoConfig& config);
static void Cleanup();
// Removes textures which aren't used for more than TEXTURE_KILL_THRESHOLD frames,
// frameCount is the current frame number.
static void Cleanup(int frameCount);
static void Invalidate(); static void Invalidate();
static void InvalidateRange(u32 start_address, u32 size); static void InvalidateRange(u32 start_address, u32 size);