aboutsummaryrefslogtreecommitdiff
path: root/src/strategies/low_latency2/swapchain_monitor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/strategies/low_latency2/swapchain_monitor.cc')
-rw-r--r--src/strategies/low_latency2/swapchain_monitor.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/strategies/low_latency2/swapchain_monitor.cc b/src/strategies/low_latency2/swapchain_monitor.cc
index a70fa6c..7442eec 100644
--- a/src/strategies/low_latency2/swapchain_monitor.cc
+++ b/src/strategies/low_latency2/swapchain_monitor.cc
@@ -35,33 +35,33 @@ void SwapchainMonitor::do_monitor(const std::stop_token stoken) {
for (;;) {
auto lock = std::unique_lock{this->mutex};
this->cv.wait(lock, stoken,
- [&]() { return this->semaphore_spans.has_value(); });
+ [&]() { return !this->pending_signals.empty(); });
// Stop only if we're stopped and we have nothing to signal.
- if (stoken.stop_requested() && !this->semaphore_spans.has_value()) {
+ if (stoken.stop_requested() && this->pending_signals.empty()) {
break;
}
// Grab the most recent semaphore. When work completes, signal it.
- const auto semaphore_span = std::move(*this->semaphore_spans);
- this->semaphore_spans.reset();
+ const auto pending_signal = std::move(this->pending_signals.front());
+ this->pending_signals.pop_front();
// If we're stopping, signal the semaphore and don't worry about work
// actually completing.
if (stoken.stop_requested()) {
- semaphore_span.wakeup_semaphore.signal(this->device);
+ pending_signal.wakeup_semaphore.signal(this->device);
break;
}
// Unlock, wait for work to finish, lock again.
lock.unlock();
- for (const auto& frame_span : semaphore_span.frame_spans) {
+ for (const auto& frame_span : pending_signal.frame_spans) {
if (frame_span) {
frame_span->await_completed();
}
}
-
lock.lock();
+
using namespace std::chrono;
if (this->present_delay != 0us) {
const auto last_time = this->last_signal_time;
@@ -75,7 +75,7 @@ void SwapchainMonitor::do_monitor(const std::stop_token stoken) {
}
lock.unlock();
- semaphore_span.wakeup_semaphore.signal(this->device);
+ pending_signal.wakeup_semaphore.signal(this->device);
}
}
@@ -94,12 +94,19 @@ void SwapchainMonitor::notify_semaphore(const VkSemaphore& timeline_semaphore,
}
// Signal immediately if we have no outstanding work.
- if (this->pending_frame_spans.empty()) {
+ if (std::ranges::all_of(this->pending_frame_spans,
+ [](const auto& frame_span) {
+ if (!frame_span) {
+ return true;
+ }
+ return frame_span->has_completed();
+ })) {
wakeup_semaphore.signal(this->device);
+ this->pending_signals.clear();
return;
}
- this->semaphore_spans.emplace(SemaphoreSpans{
+ this->pending_signals.emplace_back(PendingSignal{
.wakeup_semaphore = wakeup_semaphore,
.frame_spans = std::move(this->pending_frame_spans),
});