(wall, native)_clock: Add GetGPUTick

Allows us to directly calculate the GPU tick without double conversion to and from the host clock tick.
This commit is contained in:
Morph 2023-05-28 17:45:47 -04:00
parent 9dcc7bde8b
commit 907507886d
7 changed files with 47 additions and 12 deletions

View file

@ -32,6 +32,10 @@ public:
return GetHostTicksElapsed() * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den;
}
u64 GetGPUTick() const override {
return GetHostTicksElapsed() * NsToGPUTickRatio::num / NsToGPUTickRatio::den;
}
u64 GetHostTicksNow() const override {
return static_cast<u64>(SteadyClock::Now().time_since_epoch().count());
}
@ -52,12 +56,12 @@ std::unique_ptr<WallClock> CreateOptimalClock() {
#ifdef ARCHITECTURE_x86_64
const auto& caps = GetCPUCaps();
if (caps.invariant_tsc && caps.tsc_frequency >= WallClock::CNTFRQ) {
if (caps.invariant_tsc && caps.tsc_frequency >= WallClock::GPUTickFreq) {
return std::make_unique<X64::NativeClock>(caps.tsc_frequency);
} else {
// Fallback to StandardWallClock if the hardware TSC
// - Is not invariant
// - Is not more precise than CNTFRQ
// - Is not more precise than GPUTickFreq
return std::make_unique<StandardWallClock>();
}
#else