From a81631b58e3a77f8d088c574fc048f3fb37a7c51 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Fri, 30 Dec 2011 20:16:12 -0800 Subject: made savestates synchronous and immediate. this allows saving or loading while the emulator is paused, fixes issues where savestate hotkeys would get ignored if pressed too close together, might speed up savestates in some cases, and hopefully makes savestates more stable too. the intent is to replace the haphazard scheduling and finger-crossing associated with saving/loading with the correct and minimal necessary wait for each thread to reach a known safe location before commencing the savestate operation, and for any already-paused components to not need to be resumed to do so. --- Source/Core/VideoCommon/Src/MainBase.cpp | 54 +++++++++----------------------- 1 file changed, 15 insertions(+), 39 deletions(-) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index 0b1258a662..85fbc3d8e9 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -169,8 +169,7 @@ u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 return 0; } -static volatile u32 s_doStateRequested = false; - + void VideoBackendHardware::InitializeShared() { VideoCommon_Init(); @@ -183,52 +182,29 @@ void VideoBackendHardware::InitializeShared() s_AccessEFBResult = 0; } -static volatile struct -{ - unsigned char **ptr; - int mode; -} s_doStateArgs; - -// Depending on the threading mode (DC/SC) this can be called -// from either the GPU thread or the CPU thread -void VideoFifo_CheckStateRequest() +// Run from the CPU thread +void VideoBackendHardware::DoState(PointerWrap& p) { - if (Common::AtomicLoadAcquire(s_doStateRequested)) - { - // Clear all caches that touch RAM - TextureCache::Invalidate(false); - VertexLoaderManager::MarkAllDirty(); - - PointerWrap p(s_doStateArgs.ptr, s_doStateArgs.mode); - VideoCommon_DoState(p); + // Clear all caches that touch RAM + TextureCache::Invalidate(false); + VertexLoaderManager::MarkAllDirty(); - // Refresh state. - if (s_doStateArgs.mode == PointerWrap::MODE_READ) - { - BPReload(); - RecomputeCachedArraybases(); - } + VideoCommon_DoState(p); - Common::AtomicStoreRelease(s_doStateRequested, false); + // Refresh state. + if (p.GetMode() == PointerWrap::MODE_READ) + { + BPReload(); + RecomputeCachedArraybases(); } } -// Run from the CPU thread -void VideoBackendHardware::DoState(PointerWrap& p) +void VideoBackendHardware::PauseAndLock(bool doLock, bool unpauseOnUnlock) { - s_doStateArgs.ptr = p.ptr; - s_doStateArgs.mode = p.mode; - Common::AtomicStoreRelease(s_doStateRequested, true); - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread) - { - while (Common::AtomicLoadAcquire(s_doStateRequested) && !s_FifoShuttingDown) - //Common::SleepCurrentThread(1); - Common::YieldCPU(); - } - else - VideoFifo_CheckStateRequest(); + Fifo_PauseAndLock(doLock, unpauseOnUnlock); } + void VideoBackendHardware::RunLoop(bool enable) { VideoCommon_RunLoop(enable); -- cgit v1.2.3 From 2be579e8bad372e7a7433a7d6300939ecef4c654 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Sun, 1 Jan 2012 12:46:02 -0800 Subject: fixed some graphics problems with loading savestates (for example, wrong colors on title screen of metroid prime 3) --- Source/Core/VideoCommon/Src/MainBase.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index 85fbc3d8e9..4df2361ea9 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -185,10 +185,6 @@ void VideoBackendHardware::InitializeShared() // Run from the CPU thread void VideoBackendHardware::DoState(PointerWrap& p) { - // Clear all caches that touch RAM - TextureCache::Invalidate(false); - VertexLoaderManager::MarkAllDirty(); - VideoCommon_DoState(p); // Refresh state. @@ -196,6 +192,11 @@ void VideoBackendHardware::DoState(PointerWrap& p) { BPReload(); RecomputeCachedArraybases(); + + // Clear all caches that touch RAM + // (? these don't appear to touch any emulation state that gets saved. moved to on load only.) + TextureCache::Invalidate(false); + VertexLoaderManager::MarkAllDirty(); } } -- cgit v1.2.3 From ae242e5675b71c6c7019b31bde0abd61ba8be875 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Sun, 1 Jan 2012 13:52:31 -0800 Subject: added some missing VideoBackendHardware data to savestates. I think this makes savestates more stable (fewer "GFX FIFO: Unknown Opcode" errors) in dual core mode. also added some extra verification markers around here, to potentially give better info on future version mismatches --- Source/Core/VideoCommon/Src/MainBase.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index 4df2361ea9..df29fef606 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -186,6 +186,14 @@ void VideoBackendHardware::InitializeShared() void VideoBackendHardware::DoState(PointerWrap& p) { VideoCommon_DoState(p); + p.DoMarker("VideoCommon"); + + p.Do(s_swapRequested); + p.Do(s_efbAccessRequested); + p.Do(s_beginFieldArgs); + p.Do(s_accessEFBArgs); + p.Do(s_AccessEFBResult); + p.DoMarker("VideoBackendHardware"); // Refresh state. if (p.GetMode() == PointerWrap::MODE_READ) -- cgit v1.2.3 From 8bed27a3d1e3044d8e3ce02c17b6bd07b8130e80 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Mon, 28 May 2012 11:37:14 +0200 Subject: Enable hires textures even when texture dumping is enabled. Remove some deprecated code. --- Source/Core/VideoCommon/Src/MainBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index df29fef606..cb6dc7ae5b 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -203,7 +203,7 @@ void VideoBackendHardware::DoState(PointerWrap& p) // Clear all caches that touch RAM // (? these don't appear to touch any emulation state that gets saved. moved to on load only.) - TextureCache::Invalidate(false); + TextureCache::Invalidate(); VertexLoaderManager::MarkAllDirty(); } } -- cgit v1.2.3 From 2df0c31d13372bc29d488cf7e80d4adb9cf28b46 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 21 Dec 2012 21:04:53 +0100 Subject: add invalid flag for BPStructs (fix issue 5790) this flag will be set on loading a state and checked before every rendering. --- Source/Core/VideoCommon/Src/MainBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index cb6dc7ae5b..b5e72b1d8d 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -198,7 +198,7 @@ void VideoBackendHardware::DoState(PointerWrap& p) // Refresh state. if (p.GetMode() == PointerWrap::MODE_READ) { - BPReload(); + BPInvalidate(); RecomputeCachedArraybases(); // Clear all caches that touch RAM -- cgit v1.2.3 From ffddfd8662bda4fedcfcc8cad73f02bd7a522925 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 22 Dec 2012 17:30:13 +0100 Subject: do only invalid hashes instead of all textures on loading this is a hack, but only the gpu thread is allowed to call ogl commands suggestion: create an unused texture cache, so we can move all textures there --- Source/Core/VideoCommon/Src/MainBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index b5e72b1d8d..6e0fb530db 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -203,7 +203,7 @@ void VideoBackendHardware::DoState(PointerWrap& p) // Clear all caches that touch RAM // (? these don't appear to touch any emulation state that gets saved. moved to on load only.) - TextureCache::Invalidate(); + TextureCache::InvalidateHashes(); VertexLoaderManager::MarkAllDirty(); } } -- cgit v1.2.3 From bd0abb3d2fe5047554bb6b87fa8e3f6aa3f42e0b Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 23 Dec 2012 13:32:23 +0100 Subject: revert last commit, add CheckInvalidState to VideoBackend --- Source/Core/VideoCommon/Src/MainBase.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/Src/MainBase.cpp') diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index 6e0fb530db..726ef71b38 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -180,6 +180,7 @@ void VideoBackendHardware::InitializeShared() memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs)); memset(&s_accessEFBArgs, 0, sizeof(s_accessEFBArgs)); s_AccessEFBResult = 0; + m_invalid = false; } // Run from the CPU thread @@ -198,16 +199,25 @@ void VideoBackendHardware::DoState(PointerWrap& p) // Refresh state. if (p.GetMode() == PointerWrap::MODE_READ) { - BPInvalidate(); + m_invalid = true; RecomputeCachedArraybases(); // Clear all caches that touch RAM // (? these don't appear to touch any emulation state that gets saved. moved to on load only.) - TextureCache::InvalidateHashes(); VertexLoaderManager::MarkAllDirty(); } } +void VideoBackendHardware::CheckInvalidState() { + if (m_invalid) + { + m_invalid = false; + + BPReload(); + TextureCache::Invalidate(); + } +} + void VideoBackendHardware::PauseAndLock(bool doLock, bool unpauseOnUnlock) { Fifo_PauseAndLock(doLock, unpauseOnUnlock); -- cgit v1.2.3