From 5e3837cadac73ba5b7d4085cddc48b0e816d826a Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Tue, 31 Mar 2026 16:15:00 +1100 Subject: Fix vram leak in Cyberpunk 2077, reduce duplicated logic + general cleanup --- src/queue_context.hh | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'src/queue_context.hh') diff --git a/src/queue_context.hh b/src/queue_context.hh index be73adc..2abd44c 100644 --- a/src/queue_context.hh +++ b/src/queue_context.hh @@ -16,10 +16,6 @@ namespace low_latency { class QueueContext final : public Context { private: - // The amount of queue submissions we allow tracked per queue before - // we give up tracking them. This is neccessary for queues which do not - // present anything. - static constexpr auto MAX_TRACKED_SUBMISSIONS = 50u; static constexpr auto MAX_TRACKED_PRESENT_IDS = 50u; public: @@ -70,15 +66,41 @@ class QueueContext final : public Context { // and notify our device that it needs to watch for when this completes. // We give it our submissions. Now, it's out of our hands. We remove the // present_id_t mapping when doing so. - struct Submission { - std::shared_ptr head_handle, tail_handle; - DeviceClock::time_point_t cpu_present_time; + + class Submissions final { + // The amount of queue submissions we allow tracked per queue before + // we give up tracking them. This is neccessary for queues which do not + // present anything. + static constexpr auto MAX_TRACKED_SUBMISSIONS = 50u; + + struct Submission final { + std::shared_ptr head_handle, tail_handle; + DeviceClock::time_point_t cpu_present_time; + }; + std::deque> submissions; + + public: + Submissions(); + Submissions(const Submissions&) = delete; + Submissions(Submissions&&) = delete; + Submissions operator=(const Submissions&) = delete; + Submissions operator=(Submissions&&) = delete; + ~Submissions(); + + public: + void add_submission(const std::shared_ptr head, + const std::shared_ptr tail, + const DeviceClock::time_point_t& now); + + // Non-blocking - true if this submission has completed on the GPU. + bool has_completed() const; + // Blocking wait until the last submission has completed. + void await_completed() const; }; - using submissions_t = - std::shared_ptr>>; using present_id_t = std::uint64_t; - std::unordered_map unpresented_submissions; + using submissions_ptr_t = std::shared_ptr; + std::unordered_map unpresented_submissions; // We might be tracking present_ids which aren't presented to - and as a // result we don't ever clear those Submissions. So manually evict them by -- cgit v1.2.3