diff options
| author | Nicolas James <nj3ahxac@gmail.com> | 2026-04-06 12:18:10 +1000 |
|---|---|---|
| committer | Nicolas James <nj3ahxac@gmail.com> | 2026-04-06 12:18:10 +1000 |
| commit | a9a083ea5c649498d2f12e611dbc7c767d152130 (patch) | |
| tree | e67cfd11bc37a4faa0f1fbd448e66307cd75a624 /src/strategies/low_latency2/swapchain_monitor.hh | |
| parent | fcdac1c3287d314d7127516d56f0dec788392063 (diff) | |
Add WIP refactored reflex impl
Diffstat (limited to 'src/strategies/low_latency2/swapchain_monitor.hh')
| -rw-r--r-- | src/strategies/low_latency2/swapchain_monitor.hh | 72 |
1 files changed, 72 insertions, 0 deletions
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 <vulkan/vulkan.h> + +#include <chrono> +#include <condition_variable> +#include <deque> +#include <memory> +#include <mutex> +#include <thread> + +#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<std::deque<Submission>> pending_submissions{}; + + // A pairing of semaphore -> submissions. + // If the Submissions completes then signal the bundled semaphore. + struct SemaphoreSubmissions { + WakeupSemaphore wakeup_semaphore{}; + std::unique_ptr<std::deque<Submission>> submissions{}; + }; + std::optional<SemaphoreSubmissions> 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<std::deque<Submission>> submissions); +}; + +} // namespace low_latency + +#endif
\ No newline at end of file |
