From 8d30ac462a499d0bde615c260bf9c69146859b9a Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Mon, 28 May 2012 11:31:37 +0200 Subject: [PATCH] Instead of invalidating texcache whenever the graphics configuration dialog gets opened, clean up textures on configuration changes. --- Source/Core/DolphinWX/Src/VideoConfigDiag.cpp | 2 - Source/Core/VideoCommon/Src/RenderBase.cpp | 7 +-- .../Core/VideoCommon/Src/TextureCacheBase.cpp | 46 +++++++++++++++---- .../Core/VideoCommon/Src/TextureCacheBase.h | 19 ++++++-- Source/Core/VideoCommon/Src/VideoConfig.h | 4 +- .../Plugins/Plugin_VideoDX11/Src/Render.cpp | 1 + Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 1 + Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 5 +- 8 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp index c42764c0bb..f5a488a7e8 100644 --- a/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/VideoConfigDiag.cpp @@ -66,8 +66,6 @@ void VideoConfigDiag::Event_Close(wxCloseEvent& ev) g_Config.Save((File::GetUserPath(D_CONFIG_IDX) + ininame + ".ini").c_str()); EndModal(wxID_OK); - - TextureCache::InvalidateDefer(); // For settings like hi-res textures/texture format/etc. } wxString backend_desc = wxTRANSLATE("Selects what graphics API to use internally.\nDirect3D 9 usually is the fastest one. OpenGL is more accurate though. Direct3D 11 is somewhere between the two.\nNote that the Direct3D backends are only available on Windows.\n\nIf unsure, use Direct3D 9."); diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index b98edf1a7d..6f1f9c411a 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -82,9 +82,11 @@ bool Renderer::s_EnableDLCachingAfterRecording; unsigned int Renderer::prev_efb_format = (unsigned int)-1; + Renderer::Renderer() : frame_data(NULL), bLastFrameDumped(false) { UpdateActiveConfig(); + TextureCache::OnConfigChanged(g_ActiveConfig); #if defined _WIN32 || defined HAVE_LIBAV bAVIDumping = false; @@ -130,11 +132,6 @@ 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 bb240d5df3..cc5a0f29b4 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.cpp @@ -42,7 +42,9 @@ GC_ALIGNED16(u8 *TextureCache::temp) = NULL; unsigned int TextureCache::temp_size; TextureCache::TexCache TextureCache::textures; -bool TextureCache::DeferredInvalidate; + +TextureCache::BackupConfig TextureCache::backup_config; + TextureCache::TCacheEntryBase::~TCacheEntryBase() { @@ -59,6 +61,7 @@ TextureCache::TextureCache() SetHash64Function(g_ActiveConfig.bHiresTextures || g_ActiveConfig.bDumpTextures); } +// TODO: Kill shutdown parameter... void TextureCache::Invalidate(bool shutdown) { TexCache::iterator @@ -75,13 +78,6 @@ 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); - - DeferredInvalidate = false; -} - -void TextureCache::InvalidateDefer() -{ - DeferredInvalidate = true; } TextureCache::~TextureCache() @@ -94,6 +90,40 @@ TextureCache::~TextureCache() } } +void TextureCache::OnConfigChanged(VideoConfig& config) +{ + if (!g_texture_cache) + goto skip_checks; + + // TODO: Invalidating texcache is really stupid in some of these cases + if (config.iSafeTextureCache_ColorSamples != backup_config.s_colorsamples || + config.bTexFmtOverlayEnable != backup_config.s_texfmt_overlay || + config.bTexFmtOverlayCenter != backup_config.s_texfmt_overlay_center || + config.bHiresTextures != backup_config.s_hires_textures) + g_texture_cache->Invalidate(false); + + // TODO: Probably shouldn't clear all render targets here, just mark them dirty or something. + if (config.bEFBCopyCacheEnable != backup_config.s_copy_cache_enable || // TODO: not sure if this is needed? + config.bCopyEFBToTexture != backup_config.s_copy_efb_to_texture || + config.bCopyEFBScaled != backup_config.s_copy_efb_scaled || + config.bEFBCopyEnable != backup_config.s_copy_efb || + config.iEFBScale != backup_config.s_efb_scale) + { + g_texture_cache->ClearRenderTargets(); + } + +skip_checks: + backup_config.s_colorsamples = config.iSafeTextureCache_ColorSamples; + backup_config.s_copy_efb_to_texture = config.bCopyEFBToTexture; + backup_config.s_copy_efb_scaled = config.bCopyEFBScaled; + backup_config.s_copy_efb = config.bEFBCopyEnable; + backup_config.s_efb_scale = config.iEFBScale; + backup_config.s_texfmt_overlay = config.bTexFmtOverlayEnable; + backup_config.s_texfmt_overlay_center = config.bTexFmtOverlayCenter; + backup_config.s_hires_textures = config.bHiresTextures; + backup_config.s_copy_cache_enable = config.bEFBCopyCacheEnable; +} + void TextureCache::Cleanup() { TexCache::iterator iter = textures.begin(); diff --git a/Source/Core/VideoCommon/Src/TextureCacheBase.h b/Source/Core/VideoCommon/Src/TextureCacheBase.h index f67ad518c5..d1a8a16ee2 100644 --- a/Source/Core/VideoCommon/Src/TextureCacheBase.h +++ b/Source/Core/VideoCommon/Src/TextureCacheBase.h @@ -27,6 +27,8 @@ #include "CommonTypes.h" +struct VideoConfig; + class TextureCache { public: @@ -100,10 +102,10 @@ public: virtual ~TextureCache(); // needs virtual for DX11 dtor + static void OnConfigChanged(VideoConfig& config); 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 @@ -118,8 +120,6 @@ public: static void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, unsigned int srcFormat, const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf); - static bool DeferredInvalidate; - protected: TextureCache(); @@ -135,6 +135,19 @@ private: typedef std::map TexCache; static TexCache textures; + + // Backup configuration values + static struct BackupConfig { + int s_colorsamples; + bool s_copy_efb_to_texture; + bool s_copy_efb_scaled; + bool s_copy_efb; + int s_efb_scale; + bool s_texfmt_overlay; + bool s_texfmt_overlay_center; + bool s_hires_textures; + bool s_copy_cache_enable; + } backup_config; }; extern TextureCache *g_texture_cache; diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h index d40fbcb99a..7653972ec8 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.h +++ b/Source/Core/VideoCommon/Src/VideoConfig.h @@ -135,8 +135,8 @@ struct VideoConfig bool bEnablePerPixelDepth; int iLog; // CONF_ bits - int iSaveTargetId; - + int iSaveTargetId; // TODO: Should be dropped + //currently unused: int iCompileDLsLevel; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 1c204ddfe1..0dbb4ee25f 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -1111,6 +1111,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons // Enable configuration changes UpdateActiveConfig(); + TextureCache::OnConfigChanged(g_ActiveConfig); SetWindowSize(fbWidth, fbHeight); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 834867c477..54e3db8141 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -1117,6 +1117,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons // Enable configuration changes UpdateActiveConfig(); + TextureCache::OnConfigChanged(g_ActiveConfig); SetWindowSize(fbWidth, fbHeight); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 49fac8b260..eb7b0168a4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -1437,11 +1437,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons GL_REPORT_ERRORD(); g_Config.iSaveTargetId = 0; - // reload textures if these settings changed - if (g_Config.bCopyEFBToTexture != g_ActiveConfig.bCopyEFBToTexture) - TextureCache::ClearRenderTargets(); - UpdateActiveConfig(); + TextureCache::OnConfigChanged(g_ActiveConfig); // For testing zbuffer targets. // Renderer::SetZBufferRender();