Ensure correct first-frame timing
This commit is contained in:
parent
6e859f0c1a
commit
d879fffb4a
|
|
@ -47,11 +47,9 @@ Scheduler::Scheduler(const Device& device_, StateTracker& state_tracker_)
|
|||
: device{device_}, state_tracker{state_tracker_},
|
||||
master_semaphore{std::make_unique<MasterSemaphore>(device)},
|
||||
command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} {
|
||||
|
||||
#ifdef _WIN32
|
||||
high_res_timer = std::make_unique<HighResolutionTimer>();
|
||||
#endif
|
||||
|
||||
AcquireNewChunk();
|
||||
AllocateWorkerCommandBuffer();
|
||||
worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); });
|
||||
|
|
|
|||
|
|
@ -122,17 +122,14 @@ public:
|
|||
if (Settings::values.use_speed_limit.GetValue() && target_fps > 0.0) {
|
||||
const auto frame_duration = std::chrono::duration<double>(1.0 / target_fps);
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (next_frame_time == std::chrono::steady_clock::time_point{} || now > next_frame_time + frame_duration) {
|
||||
if (next_frame_time == std::chrono::steady_clock::time_point{}) {
|
||||
next_frame_time = now + std::chrono::duration_cast<std::chrono::nanoseconds>(frame_duration);
|
||||
}
|
||||
if (now < next_frame_time) {
|
||||
std::this_thread::sleep_until(next_frame_time);
|
||||
now = std::chrono::steady_clock::now();
|
||||
while (now > next_frame_time) {
|
||||
next_frame_time += std::chrono::duration_cast<std::chrono::nanoseconds>(frame_duration);
|
||||
}
|
||||
std::this_thread::sleep_until(next_frame_time);
|
||||
next_frame_time += std::chrono::duration_cast<std::chrono::nanoseconds>(frame_duration);
|
||||
if (now > next_frame_time) {
|
||||
next_frame_time = now + std::chrono::duration_cast<std::chrono::nanoseconds>(frame_duration);
|
||||
}
|
||||
}
|
||||
if (tick >= master_semaphore->CurrentTick()) {
|
||||
Flush();
|
||||
|
|
|
|||
Loading…
Reference in New Issue