mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 22:05:38 +00:00
System: Rework some throttler/vsync logic
This commit is contained in:
parent
b698ff1fff
commit
54c2447ff3
|
@ -930,7 +930,7 @@ void System::PauseSystem(bool paused)
|
|||
else
|
||||
{
|
||||
Host::OnSystemResumed();
|
||||
g_host_display->SetVSync(ShouldUseVSync());
|
||||
UpdateDisplaySync();
|
||||
ResetPerformanceCounters();
|
||||
ResetThrottler();
|
||||
}
|
||||
|
@ -1249,6 +1249,7 @@ bool System::Initialize(bool force_software_renderer)
|
|||
s_frame_number = 1;
|
||||
s_internal_frame_number = 1;
|
||||
|
||||
s_target_speed = g_settings.emulation_speed;
|
||||
s_throttle_frequency = 60.0f;
|
||||
s_frame_period = 0;
|
||||
s_next_frame_time = 0;
|
||||
|
@ -2064,30 +2065,7 @@ void System::ResetThrottler()
|
|||
|
||||
void System::Throttle()
|
||||
{
|
||||
// Allow variance of up to 40ms either way.
|
||||
#ifndef __ANDROID__
|
||||
static constexpr double MAX_VARIANCE_TIME_NS = 40 * 1000000;
|
||||
#else
|
||||
static constexpr double MAX_VARIANCE_TIME_NS = 50 * 1000000;
|
||||
#endif
|
||||
|
||||
// Use unsigned for defined overflow/wrap-around.
|
||||
const Common::Timer::Value time = Common::Timer::GetCurrentValue();
|
||||
const double sleep_time = (s_next_frame_time >= time) ?
|
||||
Common::Timer::ConvertValueToNanoseconds(s_next_frame_time - time) :
|
||||
-Common::Timer::ConvertValueToNanoseconds(time - s_next_frame_time);
|
||||
if (sleep_time < -MAX_VARIANCE_TIME_NS)
|
||||
{
|
||||
// Don't display the slow messages in debug, it'll always be slow...
|
||||
#ifndef _DEBUG
|
||||
Log_VerbosePrintf("System too slow, lost %.2f ms", (-sleep_time - MAX_VARIANCE_TIME_NS) / 1000000.0);
|
||||
#endif
|
||||
ResetThrottler();
|
||||
}
|
||||
else
|
||||
{
|
||||
Common::Timer::SleepUntil(s_next_frame_time, true);
|
||||
}
|
||||
}
|
||||
|
||||
void System::RunFrames()
|
||||
|
@ -2210,12 +2188,7 @@ void System::UpdateSpeedLimiterState()
|
|||
}
|
||||
}
|
||||
|
||||
const bool video_sync_enabled = ShouldUseVSync();
|
||||
const float max_display_fps = (!IsRunning() || m_throttler_enabled) ? 0.0f : g_settings.display_max_fps;
|
||||
Log_InfoPrintf("Target speed: %f%%", target_speed * 100.0f);
|
||||
Log_InfoPrintf("Using vsync: %s", video_sync_enabled ? "YES" : "NO");
|
||||
Log_InfoPrintf("Max display fps: %f (%s)", max_display_fps,
|
||||
m_display_all_frames ? "displaying all frames" : "skipping displaying frames when needed");
|
||||
Log_VerbosePrintf("Target speed: %f%%", s_target_speed * 100.0f);
|
||||
|
||||
if (IsValid())
|
||||
{
|
||||
|
@ -2235,23 +2208,36 @@ void System::UpdateSpeedLimiterState()
|
|||
ResetThrottler();
|
||||
}
|
||||
|
||||
g_host_display->SetDisplayMaxFPS(max_display_fps);
|
||||
g_host_display->SetVSync(video_sync_enabled);
|
||||
// Defer vsync update until we unpause, in case of fullscreen UI.
|
||||
if (IsRunning())
|
||||
UpdateDisplaySync();
|
||||
|
||||
if (g_settings.increase_timer_resolution)
|
||||
SetTimerResolutionIncreased(m_throttler_enabled);
|
||||
|
||||
// When syncing to host and using vsync, we don't need to sleep.
|
||||
if (syncing_to_host && video_sync_enabled && m_display_all_frames)
|
||||
if (syncing_to_host && ShouldUseVSync() && m_display_all_frames)
|
||||
{
|
||||
Log_InfoPrintf("Using host vsync for throttling.");
|
||||
m_throttler_enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void System::UpdateDisplaySync()
|
||||
{
|
||||
const bool video_sync_enabled = ShouldUseVSync();
|
||||
const float max_display_fps = m_throttler_enabled ? 0.0f : g_settings.display_max_fps;
|
||||
Log_VerbosePrintf("Using vsync: %s", video_sync_enabled ? "YES" : "NO");
|
||||
Log_VerbosePrintf("Max display fps: %f (%s)", max_display_fps,
|
||||
m_display_all_frames ? "displaying all frames" : "skipping displaying frames when needed");
|
||||
|
||||
g_host_display->SetDisplayMaxFPS(max_display_fps);
|
||||
g_host_display->SetVSync(video_sync_enabled);
|
||||
}
|
||||
|
||||
bool System::ShouldUseVSync()
|
||||
{
|
||||
return (!IsRunning() || (m_throttler_enabled && g_settings.video_sync_enabled && !IsRunningAtNonStandardSpeed()));
|
||||
return g_settings.video_sync_enabled && !IsRunningAtNonStandardSpeed();
|
||||
}
|
||||
|
||||
bool System::IsFastForwardEnabled()
|
||||
|
|
|
@ -230,6 +230,9 @@ void Throttle();
|
|||
void UpdatePerformanceCounters();
|
||||
void ResetPerformanceCounters();
|
||||
|
||||
/// Resets vsync/max present fps state.
|
||||
void UpdateDisplaySync();
|
||||
|
||||
// Access controllers for simulating input.
|
||||
Controller* GetController(u32 slot);
|
||||
void UpdateControllers();
|
||||
|
|
Loading…
Reference in a new issue