aboutsummaryrefslogtreecommitdiff
path: root/src/device_clock.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/device_clock.hh')
-rw-r--r--src/device_clock.hh49
1 files changed, 49 insertions, 0 deletions
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 <chrono>
+
+// 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<std::chrono::steady_clock,
+ std::chrono::nanoseconds>;
+ 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