From a9a083ea5c649498d2f12e611dbc7c767d152130 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Mon, 6 Apr 2026 12:18:10 +1000 Subject: Add WIP refactored reflex impl --- src/strategies/low_latency2/swapchain_monitor.hh | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/strategies/low_latency2/swapchain_monitor.hh (limited to 'src/strategies/low_latency2/swapchain_monitor.hh') diff --git a/src/strategies/low_latency2/swapchain_monitor.hh b/src/strategies/low_latency2/swapchain_monitor.hh new file mode 100644 index 0000000..9031bbb --- /dev/null +++ b/src/strategies/low_latency2/swapchain_monitor.hh @@ -0,0 +1,72 @@ + +#ifndef SWAPCHAIN_MONITOR_HH_ +#define SWAPCHAIN_MONITOR_HH_ + +#include + +#include +#include +#include +#include +#include +#include + +#include "submission.hh" + +namespace low_latency { + +class DeviceContext; + +class SwapchainMonitor final { + private: + struct WakeupSemaphore { + VkSemaphore timeline_semaphore{}; + std::uint64_t value{}; + + public: + void signal(const DeviceContext& device) const; + }; + + std::unique_ptr> pending_submissions{}; + + // A pairing of semaphore -> submissions. + // If the Submissions completes then signal the bundled semaphore. + struct SemaphoreSubmissions { + WakeupSemaphore wakeup_semaphore{}; + std::unique_ptr> submissions{}; + }; + std::optional semaphore_submission{}; + + protected: + const DeviceContext& device; + + std::mutex mutex{}; + std::chrono::microseconds present_delay{}; + bool was_low_latency_requested{}; + + std::condition_variable_any cv{}; + std::jthread monitor_worker{}; + + void do_monitor(const std::stop_token stoken); + + public: + SwapchainMonitor(const DeviceContext& device); + SwapchainMonitor(const SwapchainMonitor&) = delete; + SwapchainMonitor(SwapchainMonitor&&) = delete; + SwapchainMonitor operator=(const SwapchainMonitor&) = delete; + SwapchainMonitor operator=(SwapchainMonitor&&) = delete; + ~SwapchainMonitor(); + + public: + void update_params(const bool was_low_latency_requested, + const std::chrono::microseconds delay); + + void notify_semaphore(const VkSemaphore& timeline_semaphore, + const std::uint64_t& value); + + void attach_work(std::unique_ptr> submissions); +}; + +} // namespace low_latency + +#endif \ No newline at end of file -- cgit v1.2.3