From 1f0663c1a870ccf3928bd24f27613a1e0f154abb Mon Sep 17 00:00:00 2001 From: "baby.lueshi" Date: Tue, 8 Feb 2011 03:47:59 +0000 Subject: [PATCH] Defer texture invalidation to the video thread from the video configuration dialog. Should fix issue 4069 git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7108 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/RenderBase.cpp | 6 ++++++ Source/Core/VideoCommon/Src/TextureCacheBase.cpp | 11 ++++++++--- Source/Core/VideoCommon/Src/TextureCacheBase.h | 3 ++- Source/Core/VideoCommon/Src/VertexManagerBase.cpp | 2 -- Source/Core/VideoUICommon/Src/VideoConfigDiag.cpp | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index 459edee708..d822d8f02d 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -31,6 +31,7 @@ #include "MainBase.h" #include "VideoConfig.h" #include "FramebufferManagerBase.h" +#include "TextureCacheBase.h" #include "Fifo.h" #include "Timer.h" #include "StringUtil.h" @@ -109,6 +110,11 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect g_renderer->Swap(xfbAddr, FIELD_PROGRESSIVE, fbWidth, fbHeight,sourceRc,Gamma); Common::AtomicStoreRelease(s_swapRequested, false); } + + if (TextureCache::DeferredInvalidate) + { + TextureCache::Invalidate(false); + } } void Renderer::CalculateTargetScale(int x, int y, int &scaledX, int &scaledY) diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp index af53b0184b..47d2cf56c8 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -26,7 +26,7 @@ TextureCache *g_texture_cache; u8 *TextureCache::temp = NULL; TextureCache::TexCache TextureCache::textures; -Common::CriticalSection TextureCache::texMutex; +bool TextureCache::DeferredInvalidate; TextureCache::TCacheEntryBase::~TCacheEntryBase() { @@ -53,7 +53,6 @@ TextureCache::TextureCache() void TextureCache::Invalidate(bool shutdown) { - texMutex.Enter(); TexCache::iterator iter = textures.begin(), tcend = textures.end(); @@ -68,7 +67,13 @@ void TextureCache::Invalidate(bool shutdown) if(g_ActiveConfig.bHiresTextures && !g_ActiveConfig.bDumpTextures) HiresTextures::Init(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str()); SetHash64Function(g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures); - texMutex.Leave(); + + DeferredInvalidate = false; +} + +void TextureCache::InvalidateDefer() +{ + DeferredInvalidate = true; } TextureCache::~TextureCache() diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.h b/Source/Core/VideoCommon/Src/TextureCacheBase.h index 0667eb78a2..c8cb25134e 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.h +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.h @@ -75,6 +75,7 @@ public: static void Cleanup(); static void Invalidate(bool shutdown); + static void InvalidateDefer(); static void InvalidateRange(u32 start_address, u32 size); static void MakeRangeDynamic(u32 start_address, u32 size); static void ClearRenderTargets(); // currently only used by OGL @@ -89,7 +90,7 @@ public: static void CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, bool bScaleByHalf, const EFBRectangle &source_rect); - static Common::CriticalSection texMutex; + static bool DeferredInvalidate; protected: TextureCache(); diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp index 7b07430c8f..84c53b3ebf 100644 --- a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp @@ -158,9 +158,7 @@ void VertexManager::AddVertices(int primitive, int numVertices) void VertexManager::Flush() { - TextureCache::texMutex.Enter(); g_vertex_manager->vFlush(); - TextureCache::texMutex.Leave(); } // TODO: need to merge more stuff into VideoCommon to use this diff --git a/Source/Core/VideoUICommon/Src/VideoConfigDiag.cpp b/Source/Core/VideoUICommon/Src/VideoConfigDiag.cpp index 7462225421..7a079d3e5b 100644 --- a/Source/Core/VideoUICommon/Src/VideoConfigDiag.cpp +++ b/Source/Core/VideoUICommon/Src/VideoConfigDiag.cpp @@ -59,7 +59,7 @@ void VideoConfigDiag::Event_Close(wxCloseEvent& ev) EndModal(wxID_OK); - TextureCache::Invalidate(false); // For settings like hi-res textures/texture format/etc. + TextureCache::InvalidateDefer(); // For settings like hi-res textures/texture format/etc. } // TODO: implement some hack to increase the tooltip display duration, because some of these are way too long for anyone to read in 5 seconds.