From 59289c6fcd79e52a4395451f61851661c417dbb3 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Sun, 12 Apr 2026 18:45:49 +1000 Subject: LowLatency2: Check semaphore value before signalling --- src/strategies/low_latency2/semaphore_signal.hh | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/strategies/low_latency2/semaphore_signal.hh (limited to 'src/strategies/low_latency2/semaphore_signal.hh') diff --git a/src/strategies/low_latency2/semaphore_signal.hh b/src/strategies/low_latency2/semaphore_signal.hh new file mode 100644 index 0000000..e1e1439 --- /dev/null +++ b/src/strategies/low_latency2/semaphore_signal.hh @@ -0,0 +1,41 @@ +#ifndef SEMAPHORE_SIGNAL_HH_ +#define SEMAPHORE_SIGNAL_HH_ + +#include "device_context.hh" + +#include +#include + +// The VK_NV_low_latency2 extension supports a monotonically increasing +// semaphore value. Monotonically increasing != strictly increasing. We have to +// support a sequence with repeating values like 0, 1, 1, 1, 1, 2, 3. Vulkan +// timeline semaphores do NOT support signalling <= its current value. While the +// frame pacing isn't going to do anything in the case of repeating values (we +// expect a global frame counter), it can happen in the case of swapchain +// recreation or incomplete frames. This tiny class wraps a timeline semaphore +// and associated value. It double checks that we haven't already signalled the +// value. + +// TODO we _might_ want to make it so the destructor calls .signal(). This +// would make it impossible to drop semaphores and cause hangs. However, +// there are only a few places this can happen and I want to keep things +// explicit for now. + +namespace low_latency { + +class SemaphoreSignal { + private: + const VkSemaphore semaphore{}; + const std::uint64_t value{}; + + public: + SemaphoreSignal(const VkSemaphore& semaphore, const std::uint64_t& value); + ~SemaphoreSignal(); + + public: + void signal(const DeviceContext& device_context) const; +}; + +}; // namespace low_latency + +#endif -- cgit v1.2.3