From 0deb469d5a7c9a16179139dcff74a54aac1791a0 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Sat, 14 Feb 2026 14:05:26 +1100 Subject: commit wip --- src/timestamp_pool.hh | 63 ++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'src/timestamp_pool.hh') diff --git a/src/timestamp_pool.hh b/src/timestamp_pool.hh index a4aa429..f69b06f 100644 --- a/src/timestamp_pool.hh +++ b/src/timestamp_pool.hh @@ -40,65 +40,70 @@ #include #include +#include namespace low_latency { class QueueContext; class TimestampPool final { - private: - static constexpr auto TIMESTAMP_QUERY_POOL_SIZE = 512u; - static_assert(TIMESTAMP_QUERY_POOL_SIZE % 2 == 0); - private: QueueContext& queue_context; - // VkQueryPool with an unordered set of keys available for reading. - using available_query_indicies_t = std::unordered_set; + // A chunk of data which is useful for making timestamp queries. + // Allows association of an index to a query pool and command buffer. + // We reuse these when they're released. + struct QueryChunk final { + private: + using free_indices_t = std::unordered_set; + static constexpr auto CHUNK_SIZE = 512u; - struct Block { + public: VkQueryPool query_pool; - std::unique_ptr available_indicies; + std::unique_ptr free_indices; std::unique_ptr> command_buffers; - }; - std::vector blocks; // multiple blocks - // A snapshot of all available blocks for reading after each poll. - std::vector>> cached_timestamps; + public: + QueryChunk(const QueueContext& queue_context); + QueryChunk(const QueryChunk& handle) = delete; + QueryChunk(QueryChunk&&) = delete; + QueryChunk operator=(const QueryChunk& handle) = delete; + QueryChunk operator=(QueryChunk&&) = delete; + ~QueryChunk(); + }; + std::unordered_set> query_chunks; public: - // A handle represents two std::uint64_t blocks oftimestamp memory and two - // command buffers. + // A handle represents a VkCommandBuffer and a query index. + // Once the Handle goes out of scope, the query index will be returned + // to the parent pool. struct Handle final { private: friend class TimestampPool; private: - available_query_indicies_t& index_origin; - const std::size_t block_index; + const std::weak_ptr origin_chunk; public: const VkQueryPool query_pool; const std::uint64_t query_index; - const std::array command_buffers; + const VkCommandBuffer command_buffer; public: - Handle(TimestampPool::available_query_indicies_t& index_origin, - const std::size_t block_index, const VkQueryPool& query_pool, - const std::uint64_t query_index, - const std::array& command_buffers); + Handle(const std::shared_ptr& origin_chunk, + const std::uint64_t& query_index); Handle(const Handle& handle) = delete; Handle(Handle&&) = delete; Handle operator=(const Handle& handle) = delete; Handle operator=(Handle&&) = delete; - ~Handle(); // frees from the pool + ~Handle(); public: - void setup_command_buffers(const VkuDeviceDispatchTable& vtable) const; - }; + void setup_command_buffers(const Handle& tail, + const QueueContext& queue_context) const; - private: - Block allocate(); + std::optional get_ticks(const TimestampPool& pool); + }; public: TimestampPool(QueueContext& queue_context); @@ -109,12 +114,8 @@ class TimestampPool final { ~TimestampPool(); public: - // Hands out a Handle with a pool and index of two uint64_t's. + // Hands out a Handle! std::shared_ptr acquire(); - - void poll(); // saves the current state for future get's. - - std::uint64_t get_polled(const Handle& handle, const bool hack = false); }; } // namespace low_latency -- cgit v1.2.3