diff options
Diffstat (limited to 'src/strategies')
| -rw-r--r-- | src/strategies/low_latency2/queue_strategy.cc | 9 | ||||
| -rw-r--r-- | src/strategies/low_latency2/queue_strategy.hh | 3 | ||||
| -rw-r--r-- | src/strategies/low_latency2/swapchain_monitor.cc | 27 | ||||
| -rw-r--r-- | src/strategies/low_latency2/swapchain_monitor.hh | 7 |
4 files changed, 26 insertions, 20 deletions
diff --git a/src/strategies/low_latency2/queue_strategy.cc b/src/strategies/low_latency2/queue_strategy.cc index a020c0d..e3ed808 100644 --- a/src/strategies/low_latency2/queue_strategy.cc +++ b/src/strategies/low_latency2/queue_strategy.cc @@ -29,15 +29,14 @@ static void notify_submit_impl(LowLatency2QueueStrategy& strategy, const auto [iter, inserted] = strategy.frame_spans.try_emplace(present_id); if (inserted) { iter->second = std::make_unique<FrameSpan>(std::move(handle)); + // Add our present_id to our ring tracking if it's non-zero. + if (present_id) { + strategy.stale_present_ids.push_back(present_id); + } } else { iter->second->update(std::move(handle)); } - // Add our present_id to our ring tracking if it's non-zero. - if (inserted && present_id) { - strategy.stale_present_ids.push_back(present_id); - } - // Remove stale present_id's if they weren't presented to. if (std::size(strategy.stale_present_ids) > LowLatency2QueueStrategy::MAX_TRACKED_PRESENTS) { diff --git a/src/strategies/low_latency2/queue_strategy.hh b/src/strategies/low_latency2/queue_strategy.hh index 6d41027..2a03c91 100644 --- a/src/strategies/low_latency2/queue_strategy.hh +++ b/src/strategies/low_latency2/queue_strategy.hh @@ -16,6 +16,9 @@ class QueueContext; class LowLatency2QueueStrategy final : public QueueStrategy { public: + // It's possible that our tracking for present_ids grows without a limit if + // present isn't called. To guard against this, we store the last unique + // MAX_TRACKED_PRESENTS and use it to evict stale submissions. static constexpr auto MAX_TRACKED_PRESENTS = 50; // Mapping of present_id's to submissions. Grabbed later by the device 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), }); diff --git a/src/strategies/low_latency2/swapchain_monitor.hh b/src/strategies/low_latency2/swapchain_monitor.hh index 837f8e4..a5f8362 100644 --- a/src/strategies/low_latency2/swapchain_monitor.hh +++ b/src/strategies/low_latency2/swapchain_monitor.hh @@ -26,16 +26,13 @@ class SwapchainMonitor final { void signal(const DeviceContext& device) const; }; - // An empty vector here represents our 'no work' state. std::vector<std::unique_ptr<FrameSpan>> pending_frame_spans{}; - // A pairing of semaphore -> submissions. - // If the Submissions completes then signal the bundled semaphore. - struct SemaphoreSpans { + struct PendingSignal { WakeupSemaphore wakeup_semaphore{}; std::vector<std::unique_ptr<FrameSpan>> frame_spans{}; }; - std::optional<SemaphoreSpans> semaphore_spans{}; + std::deque<PendingSignal> pending_signals{}; protected: const DeviceContext& device; |
