summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2025-04-05 08:52:32 +0200
committerGitHub <noreply@github.com>2025-04-05 08:52:32 +0200
commit2d1671a863efed9fee3042b77a79bcac4d52fcf4 (patch)
tree523289ac90c132eefcf6106678fde230c794c486
parentedb1db7400421162a15c10c8936e81e7c29f4c80 (diff)
parent06afa0036a27bdad5700ce44776d795e7d43ee6b (diff)
Merge pull request #13485 from jordan-woyak/timer-dualcore-fix
CoreTiming: Fix Precision Frame Timing in Dual Core mode on Windows.
-rw-r--r--Source/Core/Core/CoreTiming.cpp24
-rw-r--r--Source/Core/Core/CoreTiming.h7
2 files changed, 19 insertions, 12 deletions
diff --git a/Source/Core/Core/CoreTiming.cpp b/Source/Core/Core/CoreTiming.cpp
index b0aca0168a..067587ede6 100644
--- a/Source/Core/Core/CoreTiming.cpp
+++ b/Source/Core/Core/CoreTiming.cpp
@@ -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)
diff --git a/Source/Core/Core/CoreTiming.h b/Source/Core/Core/CoreTiming.h
index 8200da3ded..f0ed02ea64 100644
--- a/Source/Core/Core/CoreTiming.h
+++ b/Source/Core/Core/CoreTiming.h
@@ -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