From 37e5e64ddc0bd129d8b272396be5c8657f7e3a1d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 1 Jan 2025 23:05:07 +1000 Subject: [PATCH] System: Move state display updates to call sites Fixes black frames when changing settings with runahead/rewind enabled. --- src/core/gpu.cpp | 14 ++------------ src/core/gpu.h | 8 +++++--- src/core/system.cpp | 20 +++++++++++++++++--- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 356bc099a..86a295fda 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -243,7 +243,7 @@ void GPU::SoftReset() UpdateGPUIdle(); } -bool GPU::DoState(StateWrapper& sw, bool update_display) +bool GPU::DoState(StateWrapper& sw) { if (sw.IsWriting()) { @@ -378,10 +378,6 @@ bool GPU::DoState(StateWrapper& sw, bool update_display) UpdateDMARequest(); UpdateCRTCConfig(); UpdateCommandTickEvent(); - - // If we're paused, need to update the display FB. - if (update_display) - UpdateDisplay(false); } else // if not memory state { @@ -395,7 +391,7 @@ bool GPU::DoState(StateWrapper& sw, bool update_display) return !sw.HasError(); } -void GPU::DoMemoryState(StateWrapper& sw, System::MemorySaveState& mss, bool update_display) +void GPU::DoMemoryState(StateWrapper& sw, System::MemorySaveState& mss) { sw.Do(&m_GPUSTAT.bits); @@ -438,12 +434,6 @@ void GPU::DoMemoryState(StateWrapper& sw, System::MemorySaveState& mss, bool upd sizeof(GPUBackendDoMemoryStateCommand))); cmd->memory_save_state = &mss; GPUThread::PushCommandAndWakeThread(cmd); - - if (update_display) - { - DebugAssert(sw.IsReading()); - UpdateDisplay(false); - } } void GPU::UpdateDMARequest() diff --git a/src/core/gpu.h b/src/core/gpu.h index 595d9012a..e7a327865 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -97,8 +97,8 @@ public: void Initialize(); void Shutdown(); void Reset(bool clear_vram); - bool DoState(StateWrapper& sw, bool update_display); - void DoMemoryState(StateWrapper& sw, System::MemorySaveState& mss, bool update_display); + bool DoState(StateWrapper& sw); + void DoMemoryState(StateWrapper& sw, System::MemorySaveState& mss); // Render statistics debug window. void DrawDebugStateWindow(float scale); @@ -216,6 +216,9 @@ public: // Dumps raw VRAM to a file. bool DumpVRAMToFile(const char* filename); + // Kicks the current frame to the backend for display. + void UpdateDisplay(bool submit_frame); + // Queues the current frame for presentation. Should only be used with runahead. void QueuePresentCurrentFrame(); @@ -296,7 +299,6 @@ private: void ReadVRAM(u16 x, u16 y, u16 width, u16 height); void UpdateVRAM(u16 x, u16 y, u16 width, u16 height, const void* data, bool set_mask, bool check_mask); - void UpdateDisplay(bool submit_frame); void PrepareForDraw(); void FinishPolyline(); diff --git a/src/core/system.cpp b/src/core/system.cpp index 768f2e071..8ea4f1325 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1178,6 +1178,10 @@ void System::RecreateGPU(GPURenderer renderer) } ClearMemorySaveStates(true, false); + + g_gpu.UpdateDisplay(false); + if (IsPaused()) + GPUThread::PresentCurrentFrame(); } void System::LoadSettings(bool display_osd_messages) @@ -2390,7 +2394,7 @@ bool System::DoState(StateWrapper& sw, bool update_display) if (!sw.DoMarker("InterruptController") || !InterruptController::DoState(sw)) return false; - if (!sw.DoMarker("GPU") || !g_gpu.DoState(sw, update_display)) + if (!sw.DoMarker("GPU") || !g_gpu.DoState(sw)) return false; if (!sw.DoMarker("CDROM") || !CDROM::DoState(sw)) @@ -2459,7 +2463,14 @@ bool System::DoState(StateWrapper& sw, bool update_display) Achievements::ResetClient(); } - return !sw.HasError(); + if (sw.HasError()) + return false; + + // If we're paused, need to update the display FB. + if (update_display) + g_gpu.UpdateDisplay(false); + + return true; } System::MemorySaveState& System::AllocateMemoryState() @@ -2665,7 +2676,7 @@ void System::DoMemoryState(StateWrapper& sw, MemorySaveState& mss, bool update_d SAVE_COMPONENT("DMA", DMA::DoState(sw)); SAVE_COMPONENT("InterruptController", InterruptController::DoState(sw)); - g_gpu.DoMemoryState(sw, mss, update_display); + g_gpu.DoMemoryState(sw, mss); SAVE_COMPONENT("CDROM", CDROM::DoState(sw)); SAVE_COMPONENT("Pad", Pad::DoState(sw, true)); @@ -2677,6 +2688,9 @@ void System::DoMemoryState(StateWrapper& sw, MemorySaveState& mss, bool update_d SAVE_COMPONENT("Achievements", Achievements::DoState(sw)); #undef SAVE_COMPONENT + + if (update_display) + g_gpu.UpdateDisplay(false); } bool System::LoadBIOS(Error* error)