diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp index eb7b537a61..d4c695b27f 100644 --- a/Source/Core/Core/CoreTiming.cpp +++ b/Source/Core/Core/CoreTiming.cpp @@ -101,8 +101,7 @@ void CoreTimingManager::Init() m_is_global_timer_sane = true; // Reset data used by the throttling system - m_throttle_last_cycle = 0; - m_throttle_deadline = Clock::now(); + ResetThrottle(0); m_event_fifo_id = 0; m_ev_lost = RegisterEvent("_lost_event", &EmptyTimedCallback); @@ -175,11 +174,17 @@ void CoreTimingManager::DoState(PointerWrap& p) }); p.DoMarker("CoreTimingEvents"); - // When loading from a save state, we must assume the Event order is random and meaningless. - // The exact layout of the heap in memory is implementation defined, therefore it is platform - // and library version specific. if (p.IsReadMode()) + { + // When loading from a save state, we must assume the Event order is random and meaningless. + // The exact layout of the heap in memory is implementation defined, therefore it is platform + // and library version specific. std::make_heap(m_event_queue.begin(), m_event_queue.end(), std::greater()); + + // The stave state has changed the time, so our previous Throttle targets are invalid. + // Especially when global_time goes down; So we create a fake throttle update. + ResetThrottle(m_globals.global_timer); + } } // This should only be called from the CPU thread. If you are calling @@ -382,6 +387,12 @@ void CoreTimingManager::Throttle(const s64 target_cycle) } } +void CoreTimingManager::ResetThrottle(s64 cycle) +{ + m_throttle_last_cycle = cycle; + m_throttle_deadline = Clock::now(); +} + TimePoint CoreTimingManager::GetCPUTimePoint(s64 cyclesLate) const { return TimePoint(std::chrono::duration_cast
(DT_s(m_globals.global_timer - cyclesLate) / diff --git a/Source/Core/Core/CoreTiming.h b/Source/Core/Core/CoreTiming.h index 1a860c5fa5..6bf5f908c3 100644 --- a/Source/Core/Core/CoreTiming.h +++ b/Source/Core/Core/CoreTiming.h @@ -185,6 +185,8 @@ private: s64 m_throttle_clock_per_sec; s64 m_throttle_min_clock_per_sleep; + void ResetThrottle(s64 cycle); + int DowncountToCycles(int downcount) const; int CyclesToDowncount(int cycles) const; };