System: Set time constraints for GPU thread on MacOS

Fixes erratic frame times.
This commit is contained in:
Stenzek 2025-01-13 19:51:33 +10:00
parent d3854d095e
commit 0dc257abe4
No known key found for this signature in database
3 changed files with 14 additions and 5 deletions

View File

@ -296,7 +296,7 @@ bool Threading::ThreadHandle::IsCallingThread() const
#ifdef __APPLE__ #ifdef __APPLE__
bool Threading::ThreadHandle::SetTimeConstraints(bool enabled, u64 period, u64 typical_time, u64 maximum_time) bool Threading::ThreadHandle::SetTimeConstraints(bool enabled, u64 period, u64 typical_time, u64 maximum_time) const
{ {
const mach_port_t mach_thread_id = pthread_mach_thread_np((pthread_t)m_native_handle); const mach_port_t mach_thread_id = pthread_mach_thread_np((pthread_t)m_native_handle);
if (!enabled) if (!enabled)

View File

@ -58,7 +58,7 @@ public:
#ifdef __APPLE__ #ifdef __APPLE__
/// Only available on MacOS, sets a period/maximum time for the scheduler. /// Only available on MacOS, sets a period/maximum time for the scheduler.
bool SetTimeConstraints(bool enabled, u64 period, u64 typical_time, u64 maximum_time); bool SetTimeConstraints(bool enabled, u64 period, u64 typical_time, u64 maximum_time) const;
#endif #endif
protected: protected:

View File

@ -3558,11 +3558,20 @@ void System::UpdateSpeedLimiterState()
constexpr u64 MAX_FRAME_TIME_NS = 7000000; constexpr u64 MAX_FRAME_TIME_NS = 7000000;
static u64 last_scheduler_period = 0; static u64 last_scheduler_period = 0;
const u64 new_scheduler_period = s_state.optimal_frame_pacing ? s_state.frame_period : 0; const u64 new_scheduler_period = s_state.optimal_frame_pacing ? s_state.frame_period : 0;
if (s_state.cpu_thread_handle && new_scheduler_period != last_scheduler_period) if (new_scheduler_period != last_scheduler_period)
{ {
s_state.cpu_thread_handle.SetTimeConstraints(s_state.optimal_frame_pacing, new_scheduler_period, MAX_FRAME_TIME_NS, if (s_state.cpu_thread_handle)
{
s_state.cpu_thread_handle.SetTimeConstraints(s_state.optimal_frame_pacing, new_scheduler_period,
MAX_FRAME_TIME_NS, new_scheduler_period);
}
const Threading::ThreadHandle& gpu_thread = GPUThread::Internal::GetThreadHandle();
if (gpu_thread)
{
gpu_thread.SetTimeConstraints(s_state.optimal_frame_pacing, new_scheduler_period, MAX_FRAME_TIME_NS,
new_scheduler_period); new_scheduler_period);
} }
}
#endif #endif
} }