Render timing
This commit is contained in:
@@ -130,6 +130,51 @@ bool SystemFrameExchange::WaitForCompletedDepth(std::size_t targetDepth, std::ch
|
||||
});
|
||||
}
|
||||
|
||||
bool SystemFrameExchange::WaitForStableCompletedDepth(
|
||||
std::size_t targetDepth,
|
||||
std::chrono::milliseconds stableDuration,
|
||||
std::chrono::milliseconds timeout)
|
||||
{
|
||||
if (targetDepth == 0)
|
||||
return true;
|
||||
|
||||
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
bool stableWindowStarted = false;
|
||||
std::chrono::steady_clock::time_point stableSince;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (now >= deadline)
|
||||
return false;
|
||||
|
||||
if (CompletedCountLocked() >= targetDepth)
|
||||
{
|
||||
if (stableDuration <= std::chrono::milliseconds::zero())
|
||||
return true;
|
||||
|
||||
if (!stableWindowStarted)
|
||||
{
|
||||
stableSince = now;
|
||||
stableWindowStarted = true;
|
||||
}
|
||||
|
||||
const auto stableDeadline = stableSince + stableDuration;
|
||||
if (now >= stableDeadline)
|
||||
return true;
|
||||
|
||||
mCondition.wait_until(lock, stableDeadline < deadline ? stableDeadline : deadline);
|
||||
continue;
|
||||
}
|
||||
|
||||
stableWindowStarted = false;
|
||||
mCondition.wait_until(lock, deadline, [&]() {
|
||||
return CompletedCountLocked() >= targetDepth;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void SystemFrameExchange::Clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
||||
Reference in New Issue
Block a user