Merge pull request #13485 from jordan-woyak/timer-dualcore-fix

CoreTiming: Fix Precision Frame Timing in Dual Core mode on Windows.
This commit is contained in:
JosJuice 2025-04-05 08:52:32 +02:00 committed by GitHub
commit 2d1671a863
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

@ -373,22 +373,28 @@ TimePoint CoreTimingManager::GetTargetHostTime(s64 target_cycle)
void CoreTimingManager::SleepUntil(TimePoint time_point)
{
const TimePoint time = Clock::now();
if (time >= time_point)
return;
if (m_use_precision_timer)
m_precision_timer.SleepUntil(time_point);
else
std::this_thread::sleep_until(time_point);
const bool use_precision_timer = m_use_precision_timer.load(std::memory_order_relaxed);
if (Core::IsCPUThread())
{
const TimePoint time = Clock::now();
if (use_precision_timer)
m_precision_cpu_timer.SleepUntil(time_point);
else
std::this_thread::sleep_until(time_point);
// Count amount of time sleeping for analytics
const TimePoint time_after_sleep = Clock::now();
g_perf_metrics.CountThrottleSleep(time_after_sleep - time);
}
else
{
if (use_precision_timer)
m_precision_gpu_timer.SleepUntil(time_point);
else
std::this_thread::sleep_until(time_point);
}
}
void CoreTimingManager::Throttle(const s64 target_cycle)

View File

@ -159,7 +159,7 @@ public:
// Throttle the CPU to the specified target cycle.
void Throttle(const s64 target_cycle);
// May be used from any thread.
// May be used from CPU or GPU thread.
void SleepUntil(TimePoint time_point);
// Used by VideoInterface
@ -216,8 +216,9 @@ private:
int DowncountToCycles(int downcount) const;
int CyclesToDowncount(int cycles) const;
bool m_use_precision_timer = false;
Common::PrecisionTimer m_precision_timer;
std::atomic_bool m_use_precision_timer = false;
Common::PrecisionTimer m_precision_cpu_timer;
Common::PrecisionTimer m_precision_gpu_timer;
};
} // namespace CoreTiming