From 681bd5096ee416b50dd7338de30af7b3db385a36 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Sun, 29 Mar 2026 20:44:23 +1100 Subject: Implement Reflex - break AntiLag in the process. Remove AntiLag1. WIP --- src/device_clock.hh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/device_clock.hh (limited to 'src/device_clock.hh') diff --git a/src/device_clock.hh b/src/device_clock.hh new file mode 100644 index 0000000..a52c59c --- /dev/null +++ b/src/device_clock.hh @@ -0,0 +1,49 @@ +#ifndef CLOCK_HH_ +#define CLOCK_HH_ + +#include + +// This header provides a DeviceClock that abstracts away the Vulkan details of +// comparing CPU and GPU times. + +namespace low_latency { + +class DeviceContext; + +class DeviceClock final { + public: + // FIXME this is bad, see now(). + using time_point_t = std::chrono::time_point; + const DeviceContext& device; + + public: + std::uint64_t host_ns; + std::uint64_t error_bound; + std::uint64_t device_ticks; + + public: + DeviceClock(const DeviceContext& device); + DeviceClock(const DeviceClock&) = delete; + DeviceClock(DeviceClock&&) = delete; + DeviceClock operator=(const DeviceClock&) = delete; + DeviceClock operator=(DeviceClock&&) = delete; + ~DeviceClock(); + + public: + // WARNING: This *MUST* be used over std::chrono::steady_clock::now if + // you're planning on comparing it to a device's clock. If it isn't, the + // timestamps might from different domains and will be completely + // nonsensical. + // FIXME we should be able to fix this with a tiny wrapper class of + // time_point_t that enforces typesafety. + static time_point_t now(); + + public: + void calibrate(); + time_point_t ticks_to_time(const std::uint64_t& ticks) const; +}; + +} // namespace low_latency + +#endif \ No newline at end of file -- cgit v1.2.3