Skip to content

Commit

Permalink
System: Move state display updates to call sites
Browse files Browse the repository at this point in the history
Fixes black frames when changing settings with runahead/rewind enabled.
  • Loading branch information
stenzek committed Jan 1, 2025
1 parent f3b7686 commit 37e5e64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
14 changes: 2 additions & 12 deletions src/core/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void GPU::SoftReset()
UpdateGPUIdle();
}

bool GPU::DoState(StateWrapper& sw, bool update_display)
bool GPU::DoState(StateWrapper& sw)
{
if (sw.IsWriting())
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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);

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions src/core/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class GPU final
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);
Expand Down Expand Up @@ -216,6 +216,9 @@ class GPU final
// 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();

Expand Down Expand Up @@ -296,7 +299,6 @@ class GPU final

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();
Expand Down
20 changes: 17 additions & 3 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
Expand All @@ -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)
Expand Down

0 comments on commit 37e5e64

Please sign in to comment.