aboutsummaryrefslogtreecommitdiff
path: root/src/queue_context.hh
diff options
context:
space:
mode:
authorNicolas James <nj3ahxac@gmail.com>2026-02-15 12:52:19 +1100
committerNicolas James <nj3ahxac@gmail.com>2026-02-15 12:52:19 +1100
commite0f7daf292db65d8aa492b6bc29ad245a9f83a2d (patch)
tree5463fb6a6d2f22dfd6442252301672860823d0d1 /src/queue_context.hh
parent0deb469d5a7c9a16179139dcff74a54aac1791a0 (diff)
Implement anti lag 1 / whatever nvidia reflex equivalent is
Diffstat (limited to 'src/queue_context.hh')
-rw-r--r--src/queue_context.hh36
1 files changed, 27 insertions, 9 deletions
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 <vulkan/utility/vk_dispatch_table.h>
@@ -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<TimestampPool> timestamp_pool;
+ private:
+ static constexpr auto MAX_TRACKED_TIMINGS = 50;
// Potentially in flight queue submissions
struct Submission {
const std::unordered_set<VkSemaphore> signals;
const std::unordered_set<VkSemaphore> waits;
- const std::uint64_t sequence;
const std::shared_ptr<TimestampPool::Handle> start_handle;
const std::shared_ptr<TimestampPool::Handle> end_handle;
+
+ bool end_of_frame_marker = false;
};
std::deque<std::shared_ptr<Submission>> submissions;
@@ -48,7 +52,6 @@ class QueueContext final : public Context {
struct Timepoint {
const QueueContext& context;
const std::shared_ptr<TimestampPool::Handle> handle;
- const std::uint64_t sequence;
};
const Timepoint start;
@@ -56,6 +59,20 @@ class QueueContext final : public Context {
};
std::deque<std::unique_ptr<Frame>> 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<std::unique_ptr<Timing>> 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<TimestampPool::Handle> head_handle,
const std::shared_ptr<TimestampPool::Handle> tail_handle);
- // TODO submit2
+ void
+ notify_submit(const VkSubmitInfo2& info,
+ const std::shared_ptr<TimestampPool::Handle> head_handle,
+ const std::shared_ptr<TimestampPool::Handle> 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<duration_t> get_delay_time();
+ std::optional<DeviceContext::Clock::time_point_t> get_sleep_until();
};
}; // namespace low_latency