upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorMoonEyes <ducoinbenjamin@yahoo.fr>2026-11-28 18:54:20 +0100
committerGitHub <noreply@github.com>2026-11-28 18:54:20 +0100
commitbfbd6af341b856b45e6ccfb65b8c51fceaeb6e7c (patch)
tree4eeed41c2e9ce57fd8d21f23530569047fef52f9 /runtime/src
parent3107c8a2a8adbbfe588c6022085bc41c4fe09a81 (diff)
parentcf5127e811cde0d53cf6c3b262703dd00b9b5198 (diff)
Merge pull request #2025 from IlyassRS3/perf/rt-retire-tickets-early-break-and-sem-cache
runtime: early-exit pending_through and cache semaphore completions in RetireTickets
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/retire_tickets.h51
1 files changed, 49 insertions, 2 deletions
diff --git a/runtime/src/retire_tickets.h b/runtime/src/retire_tickets.h
index 675460cac..318db5597 100644
--- a/runtime/src/retire_tickets.h
+++ b/runtime/src/retire_tickets.h
@@ -1,5 +1,7 @@
1#pragma once 1#pragma once
2 2
3#include <array>
4#include <cstddef>
3#include <cstdint> 5#include <cstdint>
4#include <deque> 6#include <deque>
5#include <utility> 7#include <utility>
@@ -16,17 +18,56 @@ template<class Semaphore>
16class RetireTickets { 18class RetireTickets {
17public: 19public:
18 void record(std::uint64_t ticket, Semaphore semaphore, std::uint64_t value) { 20 void record(std::uint64_t ticket, Semaphore semaphore, std::uint64_t value) {
21 if (pending_.empty()) {
22 monotonic_ = true;
23 } else if (ticket < pending_.back().ticket) {
24 monotonic_ = false;
25 }
19 pending_.push_back({ticket, semaphore, value, false}); 26 pending_.push_back({ticket, semaphore, value, false});
20 } 27 }
21 28
22 template<class Query> 29 template<class Query>
23 std::uint64_t completed(Query&& query) { 30 std::uint64_t completed(Query&& query) {
31 // Cache the highest timeline value confirmed done per semaphore in this pass so
32 // repeated or lower values on the same queue skip redundant Vulkan counter queries.
33 std::array<std::pair<Semaphore, std::uint64_t>, 8> confirmed{};
34 std::size_t confirmed_count = 0;
35 std::size_t next_evict = 0;
36
24 while (!pending_.empty()) { 37 while (!pending_.empty()) {
25 const Entry& front = pending_.front(); 38 const Entry& front = pending_.front();
26 if (!front.idle && !query(front.semaphore, front.value)) break; 39 if (!front.idle) {
40 bool already_done = false;
41 for (std::size_t i = 0; i < confirmed_count; ++i) {
42 if (confirmed[i].first == front.semaphore) {
43 if (front.value <= confirmed[i].second) already_done = true;
44 break;
45 }
46 }
47 if (!already_done) {
48 if (!query(front.semaphore, front.value)) break;
49 bool updated = false;
50 for (std::size_t i = 0; i < confirmed_count; ++i) {
51 if (confirmed[i].first == front.semaphore) {
52 if (front.value > confirmed[i].second) confirmed[i].second = front.value;
53 updated = true;
54 break;
55 }
56 }
57 if (!updated) {
58 if (confirmed_count < confirmed.size()) {
59 confirmed[confirmed_count++] = {front.semaphore, front.value};
60 } else {
61 confirmed[next_evict] = {front.semaphore, front.value};
62 next_evict = (next_evict + 1) % confirmed.size();
63 }
64 }
65 }
66 }
27 if (front.ticket > completed_) completed_ = front.ticket; 67 if (front.ticket > completed_) completed_ = front.ticket;
28 pending_.pop_front(); 68 pending_.pop_front();
29 } 69 }
70 if (pending_.empty()) monotonic_ = true;
30 return completed_; 71 return completed_;
31 } 72 }
32 73
@@ -34,8 +75,13 @@ public:
34 // that must have them done (and may not hold the lock that guards this object while it waits) waits for. 75 // that must have them done (and may not hold the lock that guards this object while it waits) waits for.
35 std::vector<std::pair<Semaphore, std::uint64_t>> pending_through(std::uint64_t ticket) const { 76 std::vector<std::pair<Semaphore, std::uint64_t>> pending_through(std::uint64_t ticket) const {
36 std::vector<std::pair<Semaphore, std::uint64_t>> out; 77 std::vector<std::pair<Semaphore, std::uint64_t>> out;
78 if (pending_.empty() || (monotonic_ && ticket < pending_.front().ticket)) return out;
37 for (const Entry& entry : pending_) { 79 for (const Entry& entry : pending_) {
38 if (entry.ticket > ticket || entry.idle) continue; 80 if (entry.ticket > ticket) {
81 if (monotonic_) break;
82 continue;
83 }
84 if (entry.idle) continue;
39 bool merged = false; 85 bool merged = false;
40 for (auto& [sem, val] : out) { 86 for (auto& [sem, val] : out) {
41 if (sem == entry.semaphore) { 87 if (sem == entry.semaphore) {
@@ -65,6 +111,7 @@ private:
65 }; 111 };
66 std::deque<Entry> pending_; 112 std::deque<Entry> pending_;
67 std::uint64_t completed_ = 0; 113 std::uint64_t completed_ = 0;
114 bool monotonic_ = true;
68}; 115};
69 116
70} // namespace leonida 117} // namespace leonida