From e0f7daf292db65d8aa492b6bc29ad245a9f83a2d Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Sun, 15 Feb 2026 12:52:19 +1100 Subject: Implement anti lag 1 / whatever nvidia reflex equivalent is --- src/queue_context.hh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/queue_context.hh') diff --git a/src/queue_context.hh b/src/queue_context.hh index 3df6af4..6a71754 100644 --- a/src/queue_context.hh +++ b/src/queue_context.hh @@ -2,6 +2,7 @@ #define QUEUE_STATE_HH_ #include "context.hh" +#include "device_context.hh" #include "timestamp_pool.hh" #include @@ -14,8 +15,6 @@ namespace low_latency { -class DeviceContext; - class QueueContext final : public Context { public: DeviceContext& device_context; @@ -23,6 +22,8 @@ class QueueContext final : public Context { const VkQueue queue; const std::uint32_t queue_family_index; + // I used to use these to signal when we could read timestamps until + // I realised you could use hostQueryReset. std::uint64_t semaphore_sequence = 0; VkSemaphore semaphore; @@ -30,14 +31,17 @@ class QueueContext final : public Context { std::unique_ptr timestamp_pool; + private: + static constexpr auto MAX_TRACKED_TIMINGS = 50; // Potentially in flight queue submissions struct Submission { const std::unordered_set signals; const std::unordered_set waits; - const std::uint64_t sequence; const std::shared_ptr start_handle; const std::shared_ptr end_handle; + + bool end_of_frame_marker = false; }; std::deque> submissions; @@ -48,7 +52,6 @@ class QueueContext final : public Context { struct Timepoint { const QueueContext& context; const std::shared_ptr handle; - const std::uint64_t sequence; }; const Timepoint start; @@ -56,6 +59,20 @@ class QueueContext final : public Context { }; std::deque> in_flight_frames; + struct Timing { + + DeviceContext::Clock::time_point_t gpu_start; + DeviceContext::Clock::time_point_t gpu_end; + + // Distance between the last gpu_end and this one. + // So one entire go around, including all cpu and gpu. + DeviceContext::Clock::time_point_t::duration frametime; + }; + std::deque> timings; + + private: + void process_frames(); + public: QueueContext(DeviceContext& device_context, const VkQueue& queue, const std::uint32_t& queue_family_index); @@ -63,18 +80,19 @@ class QueueContext final : public Context { public: void - notify_submit(const VkSubmitInfo& info, const std::uint64_t& sequence, + notify_submit(const VkSubmitInfo& info, const std::shared_ptr head_handle, const std::shared_ptr tail_handle); - // TODO submit2 + void + notify_submit(const VkSubmitInfo2& info, + const std::shared_ptr head_handle, + const std::shared_ptr tail_handle); void notify_present(const VkPresentInfoKHR& info); public: - // Computes the amount we should delay... - using duration_t = std::chrono::steady_clock::duration; - std::optional get_delay_time(); + std::optional get_sleep_until(); }; }; // namespace low_latency -- cgit v1.2.3