diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 19:04:24 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 19:04:24 -0500 |
| commit | 8d832fd10913064e1c8aec74191e3ba8f70211c8 (patch) | |
| tree | e365199d7d86ebf592a5a0dc2f07cda4b74b58a7 /runtime/src/submit_phases.h | |
| parent | 5da3b6be3cefc1499452ba8c8370a50092674d61 (diff) | |
| parent | c50ed94b35b37b697ab9c5fd176f3738480b4db5 (diff) | |
Merge main into rt-title-every-budget (#2122)
#2098 split the every-pass loop of refresh_title_textures by mode: with
LEONIDA_TEXTURE_REFRESH_ASYNC every persistent mapping is polled each
pass and only stale unmapped textures are visited, without it all mapped
or stale ones are. The async branch is kept as main has it.
LEONIDA_TITLE_EVERY_BUDGET_US applies to the synchronous pass, the one
before a submission on the submitting thread; under async the pass runs
on the refresh worker and the limit does not apply (README says so).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/submit_phases.h')
| -rw-r--r-- | runtime/src/submit_phases.h | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/runtime/src/submit_phases.h b/runtime/src/submit_phases.h index 84ea77b02..dfaf8ce95 100644 --- a/runtime/src/submit_phases.h +++ b/runtime/src/submit_phases.h | |||
| @@ -24,12 +24,14 @@ enum Phase : unsigned { | |||
| 24 | shadows, // slot-133 shadow buffers and title windows (ShadowPages::refresh) | 24 | shadows, // slot-133 shadow buffers and title windows (ShadowPages::refresh) |
| 25 | geometry, // GeometryViews::refresh | 25 | geometry, // GeometryViews::refresh |
| 26 | textures, // Device::refresh_title_textures | 26 | textures, // Device::refresh_title_textures |
| 27 | pipelines, // no longer timed (the pre-pass that waited for pipelines is gone); kept for the column order | ||
| 27 | replay, // the rest of execute_now: preparing, recording and submitting the lists | 28 | replay, // the rest of execute_now: preparing, recording and submitting the lists |
| 28 | kCount | 29 | kCount |
| 29 | }; | 30 | }; |
| 30 | 31 | ||
| 31 | inline const char* name(unsigned p) { | 32 | inline const char* name(unsigned p) { |
| 32 | static const char* const names[kCount] = {"wait", "heaps", "shadows", "geometry", "textures", "replay"}; | 33 | static const char* const names[kCount] = {"wait", "heaps", "shadows", "geometry", "textures", "pipes", |
| 34 | "replay"}; | ||
| 33 | return p < kCount ? names[p] : "?"; | 35 | return p < kCount ? names[p] : "?"; |
| 34 | } | 36 | } |
| 35 | 37 | ||
| @@ -40,6 +42,10 @@ struct Totals { | |||
| 40 | std::atomic<std::int64_t> last_log{0}; | 42 | std::atomic<std::int64_t> last_log{0}; |
| 41 | std::atomic<std::uint64_t> presents{0}; // frames the presenter showed (VulkanPresenter), since the last line | 43 | std::atomic<std::uint64_t> presents{0}; // frames the presenter showed (VulkanPresenter), since the last line |
| 42 | std::atomic<std::uint64_t> present_serial{0}; // the same, never reset (LEONIDA_REFRESH_PER_FRAME) | 44 | std::atomic<std::uint64_t> present_serial{0}; // the same, never reset (LEONIDA_REFRESH_PER_FRAME) |
| 45 | // Threads whose innermost Scope is this phase now, and when the first of them entered it (steady_clock). Counted | ||
| 46 | // per phase, since queues submit from several threads: one value would go stale when their scopes overlap. | ||
| 47 | std::atomic<unsigned> active[kCount]{}; | ||
| 48 | std::atomic<std::int64_t> active_since[kCount]{}; | ||
| 43 | std::atomic<std::uint32_t> thread{0}; // the thread of the last submission (the thread sampler reports it apart) | 49 | std::atomic<std::uint32_t> thread{0}; // the thread of the last submission (the thread sampler reports it apart) |
| 44 | }; | 50 | }; |
| 45 | inline Totals& totals() { | 51 | inline Totals& totals() { |
| @@ -86,12 +92,48 @@ inline void add(Phase p, std::uint64_t ns) { | |||
| 86 | struct Scope { | 92 | struct Scope { |
| 87 | Phase phase; | 93 | Phase phase; |
| 88 | std::int64_t start = now_ns(); | 94 | std::int64_t start = now_ns(); |
| 89 | explicit Scope(Phase p) : phase(p) {} | 95 | int outer; // the phase of this thread's Scope around this one, -1 for none |
| 90 | ~Scope() { add(phase, std::uint64_t(now_ns() - start)); } | 96 | explicit Scope(Phase p) : phase(p), outer(innermost()) { |
| 97 | if (outer >= 0) leave(outer); | ||
| 98 | enter(int(p), start); | ||
| 99 | innermost() = int(p); | ||
| 100 | } | ||
| 101 | ~Scope() { | ||
| 102 | const std::int64_t end = now_ns(); | ||
| 103 | add(phase, std::uint64_t(end - start)); | ||
| 104 | leave(int(phase)); | ||
| 105 | if (outer >= 0) enter(outer, end); | ||
| 106 | innermost() = outer; | ||
| 107 | } | ||
| 108 | static int& innermost() { | ||
| 109 | thread_local int phase_of_this_thread = -1; | ||
| 110 | return phase_of_this_thread; | ||
| 111 | } | ||
| 112 | static void enter(int p, std::int64_t at) { | ||
| 113 | Totals& t = totals(); | ||
| 114 | if (t.active[p].fetch_add(1, std::memory_order_relaxed) == 0) t.active_since[p].store(at, std::memory_order_relaxed); | ||
| 115 | } | ||
| 116 | static void leave(int p) { totals().active[p].fetch_sub(1, std::memory_order_relaxed); } | ||
| 91 | Scope(const Scope&) = delete; | 117 | Scope(const Scope&) = delete; |
| 92 | Scope& operator=(const Scope&) = delete; | 118 | Scope& operator=(const Scope&) = delete; |
| 93 | }; | 119 | }; |
| 94 | 120 | ||
| 121 | // The phase that some thread has been in longest, -1 when none is in one. | ||
| 122 | struct Running { | ||
| 123 | int phase = -1; | ||
| 124 | std::int64_t since = 0; | ||
| 125 | }; | ||
| 126 | inline Running running() { | ||
| 127 | Totals& t = totals(); | ||
| 128 | Running r; | ||
| 129 | for (unsigned p = 0; p < kCount; ++p) { | ||
| 130 | if (!t.active[p].load(std::memory_order_relaxed)) continue; | ||
| 131 | const std::int64_t since = t.active_since[p].load(std::memory_order_relaxed); | ||
| 132 | if (r.phase < 0 || since < r.since) r = {int(p), since}; | ||
| 133 | } | ||
| 134 | return r; | ||
| 135 | } | ||
| 136 | |||
| 95 | // After each submission: counts it, and prints the line when the period has passed. One thread wins the line. | 137 | // After each submission: counts it, and prints the line when the period has passed. One thread wins the line. |
| 96 | inline void submitted() { | 138 | inline void submitted() { |
| 97 | Totals& t = totals(); | 139 | Totals& t = totals(); |
| @@ -120,14 +162,15 @@ inline void submitted() { | |||
| 120 | all += total; | 162 | all += total; |
| 121 | } | 163 | } |
| 122 | std::fprintf(stderr, | 164 | std::fprintf(stderr, |
| 123 | "[rt] submit phases t=%.0fs: %llu submissions in %.1f s (%.2f/s, %llu in all), %.2f frames/s; ms per submission " | 165 | "[rt] submit phases t=%.0fs: %llu submissions in %.1f s (%.2f/s, %llu in all), %.2f frames/s; ms per " |
| 124 | "(max): %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f); " | 166 | "submission (max): %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f (%.0f) %s %.2f " |
| 167 | "(%.0f) %s %.2f (%.0f); " | ||
| 125 | "%.0f%% of the wall time\n", | 168 | "%.0f%% of the wall time\n", |
| 126 | process_age(), static_cast<unsigned long long>(n), seconds, double(n) / seconds, | 169 | process_age(), static_cast<unsigned long long>(n), seconds, double(n) / seconds, |
| 127 | static_cast<unsigned long long>(t.all_submissions.load(std::memory_order_relaxed)), | 170 | static_cast<unsigned long long>(t.all_submissions.load(std::memory_order_relaxed)), |
| 128 | double(frames) / seconds, name(0), ms[0], | 171 | double(frames) / seconds, name(0), ms[0], |
| 129 | max_ms[0], name(1), ms[1], max_ms[1], name(2), ms[2], max_ms[2], name(3), ms[3], max_ms[3], name(4), | 172 | max_ms[0], name(1), ms[1], max_ms[1], name(2), ms[2], max_ms[2], name(3), ms[3], max_ms[3], name(4), |
| 130 | ms[4], max_ms[4], name(5), ms[5], max_ms[5], 100.0 * all * 1e-3 / seconds); | 173 | ms[4], max_ms[4], name(5), ms[5], max_ms[5], name(6), ms[6], max_ms[6], 100.0 * all * 1e-3 / seconds); |
| 131 | } | 174 | } |
| 132 | 175 | ||
| 133 | } // namespace leonida::submit_phases | 176 | } // namespace leonida::submit_phases |