From 3573b09ba0f65160190fea11436c21f4e255e82d Mon Sep 17 00:00:00 2001 From: Oliver Ames Date: Tue, 3 Nov 2026 22:49:14 -0500 Subject: [PATCH] fix(nvn): measure elapsed acquire pacing wait --- dm/games/040074A01BF12000/README.md | 4 ++++ dm/gfx/nvn/hle_nvn.c | 2 +- dm/gfx/tests/t_link_ticks.m | 9 ++++++++- docs/agents/symptoms.md | 1 + docs/reference/frame-rate.md | 7 +++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dm/games/040074A01BF12000/README.md b/dm/games/040074A01BF12000/README.md index f71cb3f4e9..14a34c7325 100644 --- a/dm/games/040074A01BF12000/README.md +++ b/dm/games/040074A01BF12000/README.md @@ -113,3 +113,7 @@ Each step below stopped the boot before its fix: - [A deferred write under a false guard](../../../docs/reference/shaders.md#a-deferred-write-under-a-false-guard): DK and Pauline bright white between Hilltop's rocks, from terrain captured into the environment cube with a placeholder material (issue #1100; fixed by the translator change found on Yoshi and the Mysterious Book, spot not revisited, reporter's test asked). - [MUFU.SIN and MUFU.COS of a large number of turns](../../../docs/reference/shaders.md#mufusin-and-mufucos-of-a-large-number-of-turns): the SSAO's kernel rotation, (0, 0) past 2^20 turns, no ambient occlusion in the lower right: a corner wedge at the top of dynamic resolution (1152x648), a fifth of the picture with the effects at full size. - [Unused border corrections retain sample registers](../../../docs/reference/rendering.md#unused-border-corrections-retain-sample-registers): a SilverStar material spilled 336 bytes a thread for a correction that never ran here, 160 without it; the heavy area's scene pass 5.1 → 3.2 ms on an M1 in handheld with the corrections taken out at build time (PR #1203). Open: not measured again with the function constant that landed. + +### Acquire-wait diagnostic correction + +A 350-second gameplay trace on iPhone 17 Pro Max, using a combined experimental renderer, exposed [incorrect acquire-wait telemetry](../../../docs/reference/frame-rate.md#acquire-wait-telemetry-measures-elapsed-pacing-time). `@wait_ms` now measures elapsed pacing wait. This diagnostic correction changes no rendering or pacing behavior; that phone trace is not verification of this exact source head. diff --git a/dm/gfx/nvn/hle_nvn.c b/dm/gfx/nvn/hle_nvn.c index bc43cef1fc..72466de931 100644 --- a/dm/gfx/nvn/hle_nvn.c +++ b/dm/gfx/nvn/hle_nvn.c @@ -1924,7 +1924,7 @@ NVN(nvnWindowAcquireTexture, NVNwindowAcquireTextureResult, NVNwindow *w, NVNsyn if (pace) { if (last && now_ns() < last + step) sleep_until_ns(last + step); last = now_ns(); } } pace_ns += mtl_snap_acquire_wait(); // ring capacity is waited for at acquire, where the game does not hold its present lock - g_acq_wait_ns += wait; trow(g_frame, "@late_ms", wait ? (now_ns() - at) / 1e6 : 0); + g_acq_wait_ns += pace_ns; trow(g_frame, "@late_ms", wait ? (now_ns() - at) / 1e6 : 0); // The previous present of this texture has not yet been processed by the present thread (display cannot keep up, a whole swapchain round behind): wait for it to be returned, then hand it to the game to draw uint64_t tk = *idx < 4 ? o->ticket[*idx] : 0; if (tk) { uint64_t w0 = now_ns(); nvn_queue_present_wait(tk); nvn_queue_present_release(tk); o->ticket[*idx]=0; g_pq_wait_ns += now_ns() - w0; } diff --git a/dm/gfx/tests/t_link_ticks.m b/dm/gfx/tests/t_link_ticks.m index 2a11acc4b3..457d496463 100644 --- a/dm/gfx/tests/t_link_ticks.m +++ b/dm/gfx/tests/t_link_ticks.m @@ -33,7 +33,7 @@ static int test_clock_gettime(clockid_t clock, struct timespec *t) { module_t *module_of(const void *p) { (void)p; return NULL; } module_t *g_mod; int g_nmod; void svc_thread_dump(void) {} -uint64_t now_ns(void) { return bp_now(); } +uint64_t now_ns(void) { return test_now; } static int checks, failed; #define CHECK(c, label) do { checks++; if (!(c)) { failed++; fprintf(stderr, "FAIL: %s\n", label); } } while (0) // Only the OS wait is replaced: the production wait loop, timeout calculation, @@ -94,6 +94,13 @@ int main(int argc, char **argv) { @autoreleasepool { CHECK(a == 2, "a 60 Hz vsync is two ticks of a 120 Hz link"); CHECK(b == 1, "one own tick per frame: 120 frames a second"); CHECK(c == 2, "two own ticks"); + { // A display-link wait can block even when the fallback deadline is zero. + nvn_present_config(120, 1); win_t win = {.interval = 2}; int idx; + uint64_t start = test_now, wait0 = g_acq_wait_ns; + h_nvnWindowAcquireTexture((NVNwindow *)&win, NULL, &idx); + CHECK(test_now > start && g_acq_wait_ns - wait0 == test_now - start, + "acquire telemetry records elapsed display-link waiting without a fallback deadline"); + } acquire_ticks(120, 1, 2, 1, "display 120 Hz ignores the game's interval"); acquire_ticks(90, 1, 1, 4. / 3, "display 90 Hz preserves fractional ticks"); acquire_ticks(75, 1, 1, 1.6, "display 75 Hz preserves fractional ticks"); diff --git a/docs/agents/symptoms.md b/docs/agents/symptoms.md index 58fa7d5a13..a97acb1b7b 100644 --- a/docs/agents/symptoms.md +++ b/docs/agents/symptoms.md @@ -627,6 +627,7 @@ One line per symptom in the [subsystem references](../reference/): what you see - frames of 30–150 ms as an area loads, with `new pipelines 0` and a long-frame line such as `texture uploads 31 first + 6 re-uploads, 235.0 MB / 23.7 ms`. With `DM_NVN_REUPLOADS=1` the same large texture is re-uploaded many times within a few frames, several times with the same `submission` number, each for a few written pages (`pages written since its upload: 7 of 2466`). → [A texture written while it is drawn read whole at every use](../reference/frame-rate.md#a-texture-written-while-it-is-drawn-read-whole-at-every-use) - in a `sample` of the queue's thread (`NVN queue replay`), `mtl_sub_commit` has much time of its own and in `gw_put`, though a submission writes few pages. A game that makes many small submissions a frame pays it each time: Ocarina of Time makes about 30. → [A submission's commit read the whole storage-write page set](../reference/frame-rate.md#a-submissions-commit-read-the-whole-storage-write-page-set) - the submit thread spends time in `-[AGXTexture newTextureViewWithPixelFormat:…]` under `tex_by_id` and `img_binding` (a `sample` of the process) in a scene that does not change, and the `texture views by texture (vc_get)` line of the memory report counts views made at about half the rate of views reused, while the number of textures holding views stays flat. Ocarina of Time on the Kokiri Forest deck: 121,284 views made against 454,107 reused by frame 5,700, about 40 a frame. → [Texture views made again for render targets initialized again every frame](../reference/frame-rate.md#texture-views-made-again-for-render-targets-initialized-again-every-frame) +- `DM_NVN_TSV` reports zero `@wait_ms` when acquire blocks on a display-link tick, or reports the planned fallback delay instead of the elapsed wait. → [Acquire-wait telemetry measures elapsed pacing time](../reference/frame-rate.md#acquire-wait-telemetry-measures-elapsed-pacing-time) ## NVN objects diff --git a/docs/reference/frame-rate.md b/docs/reference/frame-rate.md index c6074b46c5..a688e3704d 100644 --- a/docs/reference/frame-rate.md +++ b/docs/reference/frame-rate.md @@ -778,3 +778,10 @@ Frame pacing: the host's frame step, engine frame limiters, present intervals an - frame time unchanged (frame p50 33.2 ms, the game's 30 fps step), no red lines, the pictures right; GPU p50 16.65 → 15.65 ms, measured while another session ran a game on the same Mac, so not counted; - the submit thread standing on the deck (85–105 s, per-frame instructions fitted against draws a frame, at 2,180 draws): 73.93 → 73.06 M instructions a frame (−1.2 %), CPU p50 9.40 → 9.18 ms. - PR #2542's own run before PR #2482 (M4 Pro): 84,748 → 1,948 views made by frame 4,200. + +### Acquire-wait telemetry measures elapsed pacing time + +- **Symptom:** `DM_NVN_TSV` reports zero `@wait_ms` when acquire blocks on a display-link tick, or reports the planned fallback delay instead of the elapsed wait. +- **Cause:** `nvnWindowAcquireTexture` accumulated `wait`, computed from the texture's fallback availability deadline, even when display-link pacing took a different path. +- **Fix:** accumulate the already measured `pace_ns`, including snapshot-capacity waiting. Present-queue waiting remains separate in `@pq_wait_ms`. This changes diagnostics only; it does not change the wait, frame rate or presentation policy. The controlled-clock `t_link_ticks` case has a zero fallback deadline and a nonzero display-link wait. +- **Found on:** [Donkey Kong Bananza](../../dm/games/040074A01BF12000/README.md), while analyzing a 350-second physical iPhone 17 Pro Max trace from a combined experimental build. Older `@wait_ms` values must not be treated as measured blocked time. This correction does not establish the cause of its pacing dips or improve performance.