diff --git a/src/util/util_fps_limiter.cpp b/src/util/util_fps_limiter.cpp index 7716500b..61677b01 100644 --- a/src/util/util_fps_limiter.cpp +++ b/src/util/util_fps_limiter.cpp @@ -33,8 +33,8 @@ namespace dxvk { if (!m_envOverride) { m_targetInterval = frameRate > 0.0 - ? NtTimerDuration(int64_t(double(NtTimerDuration::period::den) / frameRate)) - : NtTimerDuration::zero(); + ? TimerDuration(int64_t(double(TimerDuration::period::den) / frameRate)) + : TimerDuration::zero(); if (isEnabled() && !m_initialized) initialize(); @@ -46,8 +46,8 @@ namespace dxvk { std::lock_guard lock(m_mutex); m_refreshInterval = refreshRate > 0.0 - ? NtTimerDuration(int64_t(double(NtTimerDuration::period::den) / refreshRate)) - : NtTimerDuration::zero(); + ? TimerDuration(int64_t(double(TimerDuration::period::den) / refreshRate)) + : TimerDuration::zero(); } @@ -67,22 +67,22 @@ namespace dxvk { auto t0 = m_lastFrame; auto t1 = dxvk::high_resolution_clock::now(); - auto frameTime = std::chrono::duration_cast(t1 - t0); + auto frameTime = std::chrono::duration_cast(t1 - t0); if (frameTime * 100 > m_targetInterval * 103 - m_deviation * 100) { // If we have a slow frame, reset the deviation since we // do not want to compensate for low performance later on - m_deviation = NtTimerDuration::zero(); + m_deviation = TimerDuration::zero(); } else { // Don't call sleep if the amount of time to sleep is shorter // than the time the function calls are likely going to take - NtTimerDuration sleepDuration = m_targetInterval - m_deviation - frameTime; + TimerDuration sleepDuration = m_targetInterval - m_deviation - frameTime; t1 = sleep(t1, sleepDuration); // Compensate for any sleep inaccuracies in the next frame, and // limit cumulative deviation in order to avoid stutter in case we // have a number of slow frames immediately followed by a fast one. - frameTime = std::chrono::duration_cast(t1 - t0); + frameTime = std::chrono::duration_cast(t1 - t0); m_deviation += frameTime - m_targetInterval; m_deviation = std::min(m_deviation, m_targetInterval / 16); } @@ -91,8 +91,8 @@ namespace dxvk { } - FpsLimiter::TimePoint FpsLimiter::sleep(TimePoint t0, NtTimerDuration duration) { - if (duration <= NtTimerDuration::zero()) + FpsLimiter::TimePoint FpsLimiter::sleep(TimePoint t0, TimerDuration duration) { + if (duration <= TimerDuration::zero()) return t0; // On wine, we can rely on NtDelayExecution waiting for more or @@ -100,16 +100,16 @@ namespace dxvk { // spamming QueryPerformanceCounter for performance reasons. // On Windows, we busy-wait for the last couple of milliseconds // since sleeping is highly inaccurate and inconsistent. - NtTimerDuration sleepThreshold = m_sleepThreshold; + TimerDuration sleepThreshold = m_sleepThreshold; - if (m_sleepGranularity != NtTimerDuration::zero()) + if (m_sleepGranularity != TimerDuration::zero()) sleepThreshold += duration / 6; - NtTimerDuration remaining = duration; + TimerDuration remaining = duration; TimePoint t1 = t0; while (remaining > sleepThreshold) { - NtTimerDuration sleepDuration = remaining - sleepThreshold; + TimerDuration sleepDuration = remaining - sleepThreshold; if (NtDelayExecution) { LARGE_INTEGER ticks; @@ -121,14 +121,14 @@ namespace dxvk { } t1 = dxvk::high_resolution_clock::now(); - remaining -= std::chrono::duration_cast(t1 - t0); + remaining -= std::chrono::duration_cast(t1 - t0); t0 = t1; } // Busy-wait until we have slept long enough - while (remaining > NtTimerDuration::zero()) { + while (remaining > TimerDuration::zero()) { t1 = dxvk::high_resolution_clock::now(); - remaining -= std::chrono::duration_cast(t1 - t0); + remaining -= std::chrono::duration_cast(t1 - t0); t0 = t1; } @@ -152,16 +152,16 @@ namespace dxvk { // Wine's implementation of these functions is a stub as of 6.10, which is fine // since it uses select() in NtDelayExecution. This is only relevant for Windows. if (NtQueryTimerResolution && !NtQueryTimerResolution(&min, &max, &cur)) { - m_sleepGranularity = NtTimerDuration(cur); + m_sleepGranularity = TimerDuration(cur); if (NtSetTimerResolution && !NtSetTimerResolution(max, TRUE, &cur)) { Logger::info(str::format("Setting timer interval to ", (double(max) / 10.0), " us")); - m_sleepGranularity = NtTimerDuration(max); + m_sleepGranularity = TimerDuration(max); } } } else { // Assume 1ms sleep granularity by default - m_sleepGranularity = NtTimerDuration(10000); + m_sleepGranularity = TimerDuration(10000); } m_sleepThreshold = 4 * m_sleepGranularity; diff --git a/src/util/util_fps_limiter.h b/src/util/util_fps_limiter.h index 9601dc96..ac3d92c8 100644 --- a/src/util/util_fps_limiter.h +++ b/src/util/util_fps_limiter.h @@ -53,34 +53,34 @@ namespace dxvk { * \returns \c true if the target frame rate is non-zero. */ bool isEnabled() const { - return m_targetInterval != NtTimerDuration::zero(); + return m_targetInterval != TimerDuration::zero(); } private: using TimePoint = dxvk::high_resolution_clock::time_point; - using NtTimerDuration = std::chrono::duration>; + using TimerDuration = std::chrono::duration>; using NtQueryTimerResolutionProc = UINT (WINAPI *) (ULONG*, ULONG*, ULONG*); using NtSetTimerResolutionProc = UINT (WINAPI *) (ULONG, BOOL, ULONG*); using NtDelayExecutionProc = UINT (WINAPI *) (BOOL, LARGE_INTEGER*); dxvk::mutex m_mutex; - NtTimerDuration m_targetInterval = NtTimerDuration::zero(); - NtTimerDuration m_refreshInterval = NtTimerDuration::zero(); - NtTimerDuration m_deviation = NtTimerDuration::zero(); + TimerDuration m_targetInterval = TimerDuration::zero(); + TimerDuration m_refreshInterval = TimerDuration::zero(); + TimerDuration m_deviation = TimerDuration::zero(); TimePoint m_lastFrame; bool m_initialized = false; bool m_envOverride = false; - NtTimerDuration m_sleepGranularity = NtTimerDuration::zero(); - NtTimerDuration m_sleepThreshold = NtTimerDuration::zero(); + TimerDuration m_sleepGranularity = TimerDuration::zero(); + TimerDuration m_sleepThreshold = TimerDuration::zero(); NtDelayExecutionProc NtDelayExecution = nullptr; - TimePoint sleep(TimePoint t0, NtTimerDuration duration); + TimePoint sleep(TimePoint t0, TimerDuration duration); void initialize();