1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-05 01:24:14 +01:00

[util] Add helper to compute display refresh related stuff

This commit is contained in:
Philip Rebohle 2022-09-15 14:56:17 +02:00
parent e019edc8c3
commit 3543673c5c

View File

@ -12,4 +12,32 @@ namespace dxvk {
rgba[2] = (float)((color & 0x000000ff)) / 255.0f;
}
/**
* \brief Computes refresh period for a given display refresh rate
*
* \param [in] numerator Numerator of refresh rate
* \param [in] denominator Denominator of refresh rate
* \returns Refresh period, in nanoseconds
*/
inline auto computeRefreshPeriod(uint64_t numerator, uint64_t denominator) {
using unit = std::chrono::nanoseconds;
unit::rep ns = unit::rep(unit::period::den * denominator)
/ unit::rep(unit::period::num * numerator);
return unit(ns);
}
/**
* \brief Computes refresh count within a given time period
*
* \param [in] t0 Start time
* \param [in] t1 End time
* \param [in] refreshPeriod Refresh period
* \returns Number of refreshes between t1 and t0
*/
template<typename TimePoint, typename Duration>
uint64_t computeRefreshCount(TimePoint t0, TimePoint t1, Duration refreshPeriod) {
auto duration = std::chrono::duration_cast<Duration>(t1 - t0);
return duration.count() / refreshPeriod.count();
}
}