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

[util] Add helper to get time point from raw counter value

This commit is contained in:
Philip Rebohle 2022-09-15 14:55:59 +02:00
parent c1ab09a048
commit e019edc8c3

View File

@ -19,9 +19,12 @@ namespace dxvk {
using time_point = std::chrono::time_point<high_resolution_clock>;
static inline time_point now() noexcept {
return get_time_from_counter(get_counter());
}
static inline time_point get_time_from_counter(int64_t counter) {
// Keep the frequency static, this doesn't change at all.
static const int64_t freq = get_frequency();
const int64_t counter = get_counter();
const int64_t whole = (counter / freq) * period::den;
const int64_t part = (counter % freq) * period::den / freq;
@ -45,12 +48,16 @@ namespace dxvk {
};
#else
struct high_resolution_clock : public std::chrono::high_resolution_clock {
static inline time_point get_time_from_counter(int64_t counter) {
return time_point() + duration(counter);
}
static inline int64_t get_frequency() {
return period::den;
}
static inline int64_t get_counter() {
return dxvk::high_resolution_clock::now().time_since_epoch().count();
return now().time_since_epoch().count();
}
};
#endif