1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-04 17:52:10 +01:00
dxvk/src/util/util_fps_limiter.h
Philip Rebohle 04d558cf2e [util] Make frame rate limiter enablement heuristic more robust
Allow for more buffering to happen in order to not enable the limiter
too eagerly.
2024-09-02 17:50:47 +02:00

64 lines
1.4 KiB
C++

#pragma once
#include <array>
#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;
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);
};
}