1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-05 02:52:11 +01:00
dxvk/src/util/util_fps_limiter.h

64 lines
1.4 KiB
C
Raw Normal View History

#pragma once
#include <array>
2021-06-28 19:19:29 +02:00
#include "thread.h"
#include "util_time.h"
namespace dxvk {
/**
* \brief Frame rate limiter
*
* Provides functionality to stall an application
* thread in order to maintain a given frame rate.
*/
class FpsLimiter {
public:
/**
* \brief Creates frame rate limiter
*/
FpsLimiter();
~FpsLimiter();
/**
* \brief Sets target frame rate
* \param [in] frameRate Target frame rate
*/
void setTargetFrameRate(double frameRate, uint32_t maxLatency);
/**
* \brief Stalls calling thread as necessary
*
* Blocks the calling thread if the limiter is enabled
* and the time since the last call to \ref delay is
* shorter than the target interval.
*/
void delay();
private:
using TimePoint = dxvk::high_resolution_clock::time_point;
using TimerDuration = std::chrono::nanoseconds;
2021-06-28 19:19:29 +02:00
dxvk::mutex m_mutex;
TimerDuration m_targetInterval = TimerDuration::zero();
TimePoint m_nextFrame = TimePoint();
uint32_t m_maxLatency = 0;
bool m_envOverride = false;
uint32_t m_heuristicFrameCount = 0;
TimePoint m_heuristicFrameTime = TimePoint();
bool m_heuristicEnable = false;
bool testRefreshHeuristic(TimerDuration interval, TimePoint now, uint32_t maxLatency);
};
}