|
|
@ -115,29 +115,24 @@ public: |
|
|
/// Waits for the given GPU tick, optionally pacing frames. |
|
|
/// Waits for the given GPU tick, optionally pacing frames. |
|
|
void Wait(u64 tick, double target_fps = 0.0) { |
|
|
void Wait(u64 tick, double target_fps = 0.0) { |
|
|
if (Settings::values.use_speed_limit.GetValue() && target_fps > 0.0) { |
|
|
if (Settings::values.use_speed_limit.GetValue() && target_fps > 0.0) { |
|
|
auto frame_duration = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1.0 / target_fps)); |
|
|
|
|
|
auto now = std::chrono::steady_clock::now(); |
|
|
|
|
|
if (now < next_frame_time) { |
|
|
|
|
|
std::this_thread::sleep_until(next_frame_time); |
|
|
|
|
|
next_frame_time += frame_duration; |
|
|
|
|
|
} else { |
|
|
|
|
|
next_frame_time = now + frame_duration; |
|
|
|
|
|
|
|
|
if (last_frame_time == std::chrono::steady_clock::time_point{}) { |
|
|
|
|
|
last_frame_time = std::chrono::steady_clock::now(); |
|
|
|
|
|
} |
|
|
|
|
|
auto frame_duration = std::chrono::duration<double>(1.0 / target_fps); |
|
|
|
|
|
auto elapsed = std::chrono::steady_clock::now() - last_frame_time; |
|
|
|
|
|
auto sleep_time = frame_duration - elapsed; |
|
|
|
|
|
auto sleep_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(sleep_time).count(); |
|
|
|
|
|
if (sleep_time_ms > 0) { |
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_time_ms)); |
|
|
} |
|
|
} |
|
|
|
|
|
last_frame_time = std::chrono::steady_clock::now(); |
|
|
} |
|
|
} |
|
|
if (tick > master_semaphore->CurrentTick() && !chunk->Empty()) { |
|
|
|
|
|
|
|
|
if (tick > 0) { |
|
|
|
|
|
if (tick >= master_semaphore->CurrentTick()) { |
|
|
Flush(); |
|
|
Flush(); |
|
|
} |
|
|
} |
|
|
master_semaphore->Wait(tick); |
|
|
master_semaphore->Wait(tick); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Resets the frame pacing state by setting the next frame time. |
|
|
|
|
|
void ResetFramePacing(double target_fps = 0.0) { |
|
|
|
|
|
if (target_fps > 0.0) { |
|
|
|
|
|
auto frame_duration = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1.0 / target_fps)); |
|
|
|
|
|
next_frame_time = std::chrono::steady_clock::now() + frame_duration; |
|
|
|
|
|
} else { |
|
|
|
|
|
next_frame_time = std::chrono::steady_clock::time_point{}; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Returns the master timeline semaphore. |
|
|
/// Returns the master timeline semaphore. |
|
|
@ -282,7 +277,7 @@ private: |
|
|
std::condition_variable_any event_cv; |
|
|
std::condition_variable_any event_cv; |
|
|
std::jthread worker_thread; |
|
|
std::jthread worker_thread; |
|
|
|
|
|
|
|
|
std::chrono::steady_clock::time_point next_frame_time{}; |
|
|
|
|
|
|
|
|
std::chrono::steady_clock::time_point last_frame_time{}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
} // namespace Vulkan |
|
|
} // namespace Vulkan |