System: Set realtime constraints on MacOS

Significantly improves frame timing/pacing, now it is a
flat line on my 2023 MBP like other platforms.
This commit is contained in:
Stenzek 2024-09-13 20:23:57 +10:00
parent ac0b0ccaad
commit 294e8c9201
No known key found for this signature in database
1 changed files with 13 additions and 0 deletions

View File

@ -3412,6 +3412,19 @@ void System::UpdateSpeedLimiterState()
if (g_settings.increase_timer_resolution)
SetTimerResolutionIncreased(s_throttler_enabled);
#ifdef __APPLE__
// To get any resemblence of consistent frame times on MacOS, we need to tell the scheduler how often we need to run.
// Assume a maximum of 7ms for running a frame. It'll be much lower than that, Apple Silicon is fast.
constexpr u64 MAX_FRAME_TIME_NS = 7000000;
static u64 last_scheduler_period = 0;
const u64 new_scheduler_period = s_optimal_frame_pacing ? s_frame_period : 0;
if (s_cpu_thread_handle && new_scheduler_period != last_scheduler_period)
{
s_cpu_thread_handle.SetTimeConstraints(s_optimal_frame_pacing, new_scheduler_period, MAX_FRAME_TIME_NS,
new_scheduler_period);
}
#endif
}
void System::UpdateDisplayVSync()