From ccbc1feb0bc7c63cb6c06434d4d0620bef3ac67e Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sat, 19 Jun 2010 16:22:24 +0000 Subject: [PATCH] D3D9: Fix issue where the shader caches were lost whenever the render window was resized. Add some error logging to LinearDiskCache. + some minor cleanup. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5747 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/LinearDiskCache.cpp | 27 ++++++++++++++++--- Source/Core/VideoCommon/Src/Render.h | 2 -- .../Plugin_VideoDX9/Src/Debugger/Debugger.cpp | 2 -- .../Plugin_VideoDX9/Src/DlgSettings.cpp | 4 +-- .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 3 +++ .../Plugin_VideoDX9/Src/PixelShaderCache.h | 3 +-- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 11 +++++--- .../Plugin_VideoDX9/Src/VertexShaderCache.cpp | 6 +++-- .../Plugin_VideoDX9/Src/VertexShaderCache.h | 2 +- Source/Plugins/Plugin_VideoDX9/Src/main.cpp | 4 --- .../Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp | 4 +-- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 5 ---- 12 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Source/Core/Common/Src/LinearDiskCache.cpp b/Source/Core/Common/Src/LinearDiskCache.cpp index 372628d4da..e5f3fb1d32 100644 --- a/Source/Core/Common/Src/LinearDiskCache.cpp +++ b/Source/Core/Common/Src/LinearDiskCache.cpp @@ -46,6 +46,11 @@ bool LinearDiskCache::ValidateHeader() { } int LinearDiskCache::OpenAndRead(const char *filename, LinearDiskCacheReader *reader) { + if (file_) + { + ERROR_LOG(VIDEO, "LinearDiskCache trying to open an alredy opened cache"); + return 0; + } int items_read_count = 0; file_ = fopen(filename, "rb"); int file_size = 0; @@ -143,11 +148,25 @@ void LinearDiskCache::Append( } void LinearDiskCache::Sync() { - fflush(file_); + if (file_) + { + fflush(file_); + } + else + { + ERROR_LOG(VIDEO, "LinearDiskCache trying to sync closed cache"); + } } void LinearDiskCache::Close() { - fclose(file_); - file_ = 0; - num_entries_ = 0; + if (file_) + { + fclose(file_); + file_ = 0; + num_entries_ = 0; + } + else + { + ERROR_LOG(VIDEO, "LinearDiskCache trying to close an alredy closed cache"); + } } diff --git a/Source/Core/VideoCommon/Src/Render.h b/Source/Core/VideoCommon/Src/Render.h index 37350e08c4..31127fdeb7 100644 --- a/Source/Core/VideoCommon/Src/Render.h +++ b/Source/Core/VideoCommon/Src/Render.h @@ -49,8 +49,6 @@ public: static void ResetAPIState(); static void RestoreAPIState(); - static void ReinitView(); - static void SetColorMask(); static void SetBlendMode(bool forceUpdate); static bool SetScissorRect(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Debugger/Debugger.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Debugger/Debugger.cpp index 99d9944170..27f40dd326 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Debugger/Debugger.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Debugger/Debugger.cpp @@ -333,12 +333,10 @@ void GFXDebuggerDX9::OnClearTextureCacheButton(wxCommandEvent& event) void GFXDebuggerDX9::OnClearVertexShaderCacheButton(wxCommandEvent& event) { - VertexShaderCache::Clear(); } void GFXDebuggerDX9::OnClearPixelShaderCacheButton(wxCommandEvent& event) { - PixelShaderCache::Clear(); } void UpdateFPSDisplay(const char *text); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp b/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp index fb9b89f4b9..d83abe7ec9 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/DlgSettings.cpp @@ -297,8 +297,8 @@ void GFXConfigDialogDX::CreateGUIControls() m_OverlayFPS = new wxCheckBox( m_PageAdvanced, ID_OVERLAYFPS, wxT("Overlay FPS Counter"), wxDefaultPosition, wxDefaultSize, 0 ); m_CopyEFB = new wxCheckBox( m_PageAdvanced, ID_ENABLEEFBCOPY, wxT("Enable EFB Copy"), wxDefaultPosition, wxDefaultSize, 0 ); m_EnableHotkeys = new wxCheckBox( m_PageAdvanced, ID_ENABLEHOTKEY, wxT("Enable Hotkey"), wxDefaultPosition, wxDefaultSize, 0 ); - m_Radio_CopyEFBToRAM = new wxRadioButton( m_PageAdvanced, ID_EFBTORAM, wxT("To Ram"), wxDefaultPosition, wxDefaultSize, 0 ); - m_Radio_CopyEFBToGL = new wxRadioButton( m_PageAdvanced, ID_EFBTOTEX, wxT("To Texture"), wxDefaultPosition, wxDefaultSize, 0 ); + m_Radio_CopyEFBToRAM = new wxRadioButton( m_PageAdvanced, ID_EFBTORAM, wxT("To RAM (accuracy)"), wxDefaultPosition, wxDefaultSize, 0 ); + m_Radio_CopyEFBToGL = new wxRadioButton( m_PageAdvanced, ID_EFBTOTEX, wxT("To Texture (performance, resolution)"), wxDefaultPosition, wxDefaultSize, 0 ); m_WireFrame = new wxCheckBox( m_PageAdvanced, ID_WIREFRAME, wxT("Enable Wireframe"), wxDefaultPosition, wxDefaultSize, 0 ); m_EnableRealXFB = new wxCheckBox( m_PageAdvanced, ID_ENABLEREALXFB, wxT("Enable Real XFB"), wxDefaultPosition, wxDefaultSize, 0 ); m_EnableXFB = new wxCheckBox( m_PageAdvanced, ID_ENABLEXFB, wxT("Enable XFB"), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index a57481b5dc..83f40354e8 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -258,6 +258,9 @@ void PixelShaderCache::Init() if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX))) File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX)); + SETSTAT(stats.numPixelShadersCreated, 0); + SETSTAT(stats.numPixelShadersAlive, 0); + char cache_filename[MAX_PATH]; sprintf(cache_filename, "%sdx9-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX), globals->unique_id); PixelShaderCacheInserter inserter; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h index 40ace0b67c..2e32e40b75 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h @@ -54,11 +54,10 @@ private: static PSCache PixelShaders; static const PSCacheEntry *last_entry; - + static void Clear(); public: static void Init(); - static void Clear(); static void Shutdown(); static bool SetShader(bool dstAlpha); static bool InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 8b494d848b..b67add58ae 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -225,8 +225,12 @@ void SetupDeviceObjects() VertexShaderManager::Dirty(); PixelShaderManager::Dirty(); TextureConverter::Init(); - // Tex and shader caches will recreate themselves over time. + + // To avoid shader compilation stutters, read back all shaders from cache. + VertexShaderCache::Init(); + PixelShaderCache::Init(); + // Texture cache will recreate themselves over time. } // Kill off all POOL_DEFAULT device objects. @@ -241,8 +245,8 @@ void TeardownDeviceObjects() D3D::font.Shutdown(); TextureCache::Invalidate(false); VertexLoaderManager::Shutdown(); - VertexShaderCache::Clear(); - PixelShaderCache::Clear(); + VertexShaderCache::Shutdown(); + PixelShaderCache::Shutdown(); TextureConverter::Shutdown(); } @@ -499,7 +503,6 @@ void CheckForResize() { Sleep(10); } - if (EmuWindow::GetParentWnd()) { diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp index 08f9a13b02..7bb5c36bd3 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp @@ -214,6 +214,9 @@ void VertexShaderCache::Init() if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX))) File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX)); + SETSTAT(stats.numVertexShadersCreated, 0); + SETSTAT(stats.numVertexShadersAlive, 0); + char cache_filename[MAX_PATH]; sprintf(cache_filename, "%sdx9-%s-vs.cache", File::GetUserPath(D_SHADERCACHE_IDX), globals->unique_id); VertexShaderCacheInserter inserter; @@ -234,7 +237,7 @@ void VertexShaderCache::Clear() void VertexShaderCache::Shutdown() { - for (int i = 0; i<3;i++) + for (int i = 0; i < 3; i++) { if (SimpleVertexShader[i]) SimpleVertexShader[i]->Release(); @@ -245,7 +248,6 @@ void VertexShaderCache::Shutdown() ClearVertexShader->Release(); ClearVertexShader = NULL; - Clear(); g_vs_disk_cache.Sync(); g_vs_disk_cache.Close(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h index 256402a684..e855ecd3a7 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h @@ -49,10 +49,10 @@ private: static VSCache vshaders; static const VSCacheEntry *last_entry; + static void Clear(); public: static void Init(); - static void Clear(); static void Shutdown(); static bool SetShader(u32 components); static LPDIRECT3DVERTEXSHADER9 GetSimpleVertexShader(int level); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 8a8ff2330a..589b5b19e8 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -287,9 +287,7 @@ void Video_Prepare() Fifo_Init(); VertexLoaderManager::Init(); OpcodeDecoder_Init(); - VertexShaderCache::Init(); VertexShaderManager::Init(); - PixelShaderCache::Init(); PixelShaderManager::Init(); CommandProcessor::Init(); PixelEngine::Init(); @@ -307,9 +305,7 @@ void Shutdown() CommandProcessor::Shutdown(); VertexManager::Shutdown(); VertexLoaderManager::Shutdown(); - VertexShaderCache::Shutdown(); VertexShaderManager::Shutdown(); - PixelShaderCache::Shutdown(); PixelShaderManager::Shutdown(); TextureCache::Shutdown(); OpcodeDecoder_Shutdown(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp index f7eec49deb..55c5149cbf 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GUI/ConfigDlg.cpp @@ -448,8 +448,8 @@ void GFXConfigDialogOGL::CreateGUIControls() m_StaticBox_EFB = new wxStaticBox(m_PageAdvanced, ID_STATICBOX_EFB, wxT("EFB Copy")); m_CheckBox_DisableCopyEFB = new wxCheckBox(m_PageAdvanced, ID_CHECKBOX_DISABLECOPYEFB, wxT("Disable")); - m_Radio_CopyEFBToRAM = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTORAM, wxT("Copy EFB to system RAM (real)")); - m_Radio_CopyEFBToGL = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTOGL, wxT("Copy EFB to GL texture (hack)")); + m_Radio_CopyEFBToRAM = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTORAM, wxT("To RAM (accuracy)")); + m_Radio_CopyEFBToGL = new wxRadioButton(m_PageAdvanced, ID_RADIO_COPYEFBTOGL, wxT("To GL texture (performance)")); // Utility sbUtilities = new wxStaticBoxSizer(wxVERTICAL, m_PageAdvanced, wxT("Utilities")); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 47008ed628..34c5a5acca 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -571,11 +571,6 @@ void Renderer::ResetAPIState() void UpdateViewport(); -void Renderer::ReinitView() -{ - -} - void Renderer::RestoreAPIState() { // Gets us back into a more game-like state.