2019-11-26 01:45:45 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <cstdint>
|
|
|
|
|
2019-11-26 16:05:44 +01:00
|
|
|
#if defined(_WIN32) && !defined(__WINE__)
|
2019-11-26 01:45:45 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2019-11-26 16:05:44 +01:00
|
|
|
#if defined(_WIN32) && !defined(__WINE__)
|
2019-11-26 01:45:45 +01:00
|
|
|
struct high_resolution_clock {
|
|
|
|
static constexpr bool is_steady = true;
|
|
|
|
|
|
|
|
using rep = int64_t;
|
|
|
|
using period = std::nano;
|
|
|
|
using duration = std::chrono::nanoseconds;
|
|
|
|
using time_point = std::chrono::time_point<high_resolution_clock>;
|
|
|
|
|
|
|
|
static inline time_point now() noexcept {
|
|
|
|
// Keep the frequency static, this doesn't change at all.
|
|
|
|
static const int64_t freq = getFrequency();
|
|
|
|
const int64_t counter = getCounter();
|
|
|
|
|
|
|
|
const int64_t whole = (counter / freq) * period::den;
|
|
|
|
const int64_t part = (counter % freq) * period::den / freq;
|
|
|
|
|
|
|
|
return time_point(duration(whole + part));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int64_t getFrequency() {
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
|
|
|
|
return freq.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int64_t getCounter() {
|
|
|
|
LARGE_INTEGER count;
|
|
|
|
QueryPerformanceCounter(&count);
|
|
|
|
|
|
|
|
return count.QuadPart;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#else
|
2019-11-26 16:05:44 +01:00
|
|
|
using high_resolution_clock = std::chrono::high_resolution_clock;
|
2019-11-26 01:45:45 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|