diff options
| author | 2023-06-07 21:38:28 -0400 | |
|---|---|---|
| committer | 2023-06-07 21:44:42 -0400 | |
| commit | 2e1e7254436b032f133372c76d9484aa756d56df (patch) | |
| tree | ce55efc11d5dee53a87532b77ce85d3e0d2b2a76 /src/core/core_timing.cpp | |
| parent | (wall, native)_clock: Add GetGPUTick (diff) | |
| download | yuzu-2e1e7254436b032f133372c76d9484aa756d56df.tar.gz yuzu-2e1e7254436b032f133372c76d9484aa756d56df.tar.xz yuzu-2e1e7254436b032f133372c76d9484aa756d56df.zip | |
core_timing: Fix SingleCore cycle timer
Diffstat (limited to 'src/core/core_timing.cpp')
| -rw-r--r-- | src/core/core_timing.cpp | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index e57bca70a..4f0a3f8ea 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -20,7 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | namespace Core::Timing { | 21 | namespace Core::Timing { |
| 22 | 22 | ||
| 23 | constexpr s64 MAX_SLICE_LENGTH = 4000; | 23 | constexpr s64 MAX_SLICE_LENGTH = 10000; |
| 24 | 24 | ||
| 25 | std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback) { | 25 | std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callback) { |
| 26 | return std::make_shared<EventType>(std::move(callback), std::move(name)); | 26 | return std::make_shared<EventType>(std::move(callback), std::move(name)); |
| @@ -65,7 +65,7 @@ void CoreTiming::Initialize(std::function<void()>&& on_thread_init_) { | |||
| 65 | on_thread_init = std::move(on_thread_init_); | 65 | on_thread_init = std::move(on_thread_init_); |
| 66 | event_fifo_id = 0; | 66 | event_fifo_id = 0; |
| 67 | shutting_down = false; | 67 | shutting_down = false; |
| 68 | ticks = 0; | 68 | cpu_ticks = 0; |
| 69 | const auto empty_timed_callback = [](std::uintptr_t, u64, std::chrono::nanoseconds) | 69 | const auto empty_timed_callback = [](std::uintptr_t, u64, std::chrono::nanoseconds) |
| 70 | -> std::optional<std::chrono::nanoseconds> { return std::nullopt; }; | 70 | -> std::optional<std::chrono::nanoseconds> { return std::nullopt; }; |
| 71 | ev_lost = CreateEvent("_lost_event", empty_timed_callback); | 71 | ev_lost = CreateEvent("_lost_event", empty_timed_callback); |
| @@ -170,20 +170,12 @@ void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, | |||
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | void CoreTiming::AddTicks(u64 ticks_to_add) { | 172 | void CoreTiming::AddTicks(u64 ticks_to_add) { |
| 173 | ticks += ticks_to_add; | 173 | cpu_ticks += ticks_to_add; |
| 174 | downcount -= static_cast<s64>(ticks); | 174 | downcount -= static_cast<s64>(cpu_ticks); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | void CoreTiming::Idle() { | 177 | void CoreTiming::Idle() { |
| 178 | if (!event_queue.empty()) { | 178 | cpu_ticks += 1000U; |
| 179 | const u64 next_event_time = event_queue.front().time; | ||
| 180 | const u64 next_ticks = Common::WallClock::NSToCNTPCT(next_event_time) + 10U; | ||
| 181 | if (next_ticks > ticks) { | ||
| 182 | ticks = next_ticks; | ||
| 183 | } | ||
| 184 | return; | ||
| 185 | } | ||
| 186 | ticks += 1000U; | ||
| 187 | } | 179 | } |
| 188 | 180 | ||
| 189 | void CoreTiming::ResetTicks() { | 181 | void CoreTiming::ResetTicks() { |
| @@ -194,14 +186,14 @@ u64 CoreTiming::GetClockTicks() const { | |||
| 194 | if (is_multicore) [[likely]] { | 186 | if (is_multicore) [[likely]] { |
| 195 | return clock->GetCNTPCT(); | 187 | return clock->GetCNTPCT(); |
| 196 | } | 188 | } |
| 197 | return ticks; | 189 | return Common::WallClock::CPUTickToCNTPCT(cpu_ticks); |
| 198 | } | 190 | } |
| 199 | 191 | ||
| 200 | u64 CoreTiming::GetGPUTicks() const { | 192 | u64 CoreTiming::GetGPUTicks() const { |
| 201 | if (is_multicore) [[likely]] { | 193 | if (is_multicore) [[likely]] { |
| 202 | return clock->GetGPUTick(); | 194 | return clock->GetGPUTick(); |
| 203 | } | 195 | } |
| 204 | return Common::WallClock::CNTPCTToGPUTick(ticks); | 196 | return Common::WallClock::CPUTickToGPUTick(cpu_ticks); |
| 205 | } | 197 | } |
| 206 | 198 | ||
| 207 | std::optional<s64> CoreTiming::Advance() { | 199 | std::optional<s64> CoreTiming::Advance() { |
| @@ -314,14 +306,14 @@ std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const { | |||
| 314 | if (is_multicore) [[likely]] { | 306 | if (is_multicore) [[likely]] { |
| 315 | return clock->GetTimeNS(); | 307 | return clock->GetTimeNS(); |
| 316 | } | 308 | } |
| 317 | return std::chrono::nanoseconds{Common::WallClock::CNTPCTToNS(ticks)}; | 309 | return std::chrono::nanoseconds{Common::WallClock::CPUTickToNS(cpu_ticks)}; |
| 318 | } | 310 | } |
| 319 | 311 | ||
| 320 | std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { | 312 | std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { |
| 321 | if (is_multicore) [[likely]] { | 313 | if (is_multicore) [[likely]] { |
| 322 | return clock->GetTimeUS(); | 314 | return clock->GetTimeUS(); |
| 323 | } | 315 | } |
| 324 | return std::chrono::microseconds{Common::WallClock::CNTPCTToUS(ticks)}; | 316 | return std::chrono::microseconds{Common::WallClock::CPUTickToUS(cpu_ticks)}; |
| 325 | } | 317 | } |
| 326 | 318 | ||
| 327 | } // namespace Core::Timing | 319 | } // namespace Core::Timing |