From 0d8a1a411ad53f36157354d3a9001f3994876bc0 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Thu, 12 Mar 2026 23:37:18 +1100 Subject: Fix leaks via owner class wrappers on some vulkan objects --- src/timestamp_pool.hh | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/timestamp_pool.hh') diff --git a/src/timestamp_pool.hh b/src/timestamp_pool.hh index 8e336d5..67b34de 100644 --- a/src/timestamp_pool.hh +++ b/src/timestamp_pool.hh @@ -33,13 +33,50 @@ class TimestampPool final { // We reuse these when they're released. struct QueryChunk final { private: - using free_indices_t = std::unordered_set; static constexpr auto CHUNK_SIZE = 512u; public: - VkQueryPool query_pool; + struct QueryPoolOwner final { + private: + const QueueContext& queue_context; + VkQueryPool query_pool; + + public: + QueryPoolOwner(const QueueContext& queue_context); + QueryPoolOwner(const QueryPoolOwner&) = delete; + QueryPoolOwner(QueryPoolOwner&&) = delete; + QueryPoolOwner operator=(const QueryPoolOwner&) = delete; + QueryPoolOwner operator=(QueryPoolOwner&&) = delete; + ~QueryPoolOwner(); + + public: + operator const VkQueryPool&() const { return this->query_pool; } + }; + std::unique_ptr query_pool; + + using free_indices_t = std::unordered_set; std::unique_ptr free_indices; - std::unique_ptr> command_buffers; + + struct CommandBuffersOwner final { + private: + const QueueContext& queue_context; + std::vector command_buffers; + + public: + CommandBuffersOwner(const QueueContext& queue_context); + CommandBuffersOwner(const CommandBuffersOwner&) = delete; + CommandBuffersOwner(CommandBuffersOwner&&) = delete; + CommandBuffersOwner operator=(const CommandBuffersOwner&) = delete; + CommandBuffersOwner operator=(CommandBuffersOwner&&) = delete; + ~CommandBuffersOwner(); + + public: + VkCommandBuffer operator[](const std::size_t& i) { + assert(i < CHUNK_SIZE); + return this->command_buffers[i]; + } + }; + std::unique_ptr command_buffers; public: QueryChunk(const QueueContext& queue_context); -- cgit v1.2.3