Prepare for deferred waits

This commit is contained in:
Henrik Rydgård committed 2023-12-18 17:15:56 +01:00
1 parent 7f075dc9fe
commit 97e0f6dc94
4 files changed
+40 -11

No files matched your search

+27
View File
@@ -32,6 +32,17 @@
FrameTiming g_frameTiming;
void WaitUntil(double now, double timestamp) {
#ifdef _WIN32
while (time_now_d() < timestamp) {
sleep_ms(1); // Sleep for 1ms on this thread
}
#else
const double left = timestamp - now;
usleep((long)(left * 1000000));
#endif
}
inline Draw::PresentMode GetBestImmediateMode(Draw::PresentMode supportedModes) {
if (supportedModes & Draw::PresentMode::MAILBOX) {
return Draw::PresentMode::MAILBOX;
@@ -50,6 +61,22 @@ void FrameTiming::Reset(Draw::DrawContext *draw) {
}
}
void FrameTiming::DeferWaitUntil(double until, double *curTimePtr) {
_dbg_assert_(until > 0.0);
waitUntil_ = until;
curTimePtr_ = curTimePtr;
}
void FrameTiming::PostSubmit() {
if (waitUntil_ != 0.0) {
WaitUntil(time_now_d(), waitUntil_);
if (curTimePtr_) {
*curTimePtr_ = waitUntil_;
}
waitUntil_ = 0.0;
}
}
Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw, int *interval) {
Draw::PresentMode mode = Draw::PresentMode::FIFO;