More precise std::chrono throttle implementation.

This commit is contained in:
Idiot 2023-07-06 14:53:07 -05:00 committed by BearOso
parent 12e7f0d21f
commit faaf900eb7
2 changed files with 30 additions and 4 deletions

2
external/glslang vendored

@ -1 +1 @@
Subproject commit 9c7fd1a33e5cecbe465e1cd70170167d5e40d398 Subproject commit 3ebb72cc7429f0ab8218104dc3687c659c0f364d

View File

@ -25,18 +25,44 @@ void Throttle::wait_for_frame()
std::this_thread::sleep_for(time_to_wait); std::this_thread::sleep_for(time_to_wait);
} }
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
void Throttle::wait_for_frame_and_rebase_time() void Throttle::wait_for_frame_and_rebase_time()
{ {
#ifdef _WIN32
static HANDLE timer = nullptr;
if (timer == nullptr)
timer = CreateWaitableTimer(nullptr, true, nullptr);
#endif
auto time_to_wait = remaining(); auto time_to_wait = remaining();
if (time_to_wait < -frame_duration_us / 10) if (time_to_wait < -frame_duration_us / 10)
reset(); reset();
if (time_to_wait.count() > 0) if (time_to_wait.count() > 1000)
{ {
std::this_thread::sleep_for(time_to_wait); #ifdef _WIN32
advance(); LARGE_INTEGER li;
li.QuadPart = -(time_to_wait.count() - 1000) * 10;
SetWaitableTimer(timer, &li, 0, nullptr, nullptr, false);
WaitForSingleObject(timer, INFINITE);
#else
std::this_thread::sleep_for(time_to_wait - 1000);
#endif
} }
time_to_wait = remaining();
while (time_to_wait.count() > 0)
{
std::this_thread::yield();
time_to_wait = remaining();
}
advance();
} }
void Throttle::advance() void Throttle::advance()