Skip to content

nvn/timestamps: leave out the GPU's wait for translation between submits - #2491

Closed
bymaxmarc wants to merge 1 commit into
seedds:mainfrom
bymaxmarc:pr/timestamp-submit-lag
Closed

bymaxmarc wants to merge 1 commit into
seedds:mainfrom
bymaxmarc:pr/timestamp-submit-lag

Conversation

@bymaxmarc

Copy link
Copy Markdown
Contributor

What and why

Nintendo Switch Sports Resort's (04008E001F098000, v65536) dynamic resolution fell to 854x480-1280x720 in a table tennis match and stayed there for minutes (560 of 600 frames at 854x480), while its GPU p50 stayed about 12 ms, the same as at full size. Whether it fell was chance, and a fall was for good.

Cause: a Switch GPU starts a submission as soon as the previous one ends, or when the game submits it if that is later. The host translates a submission after the game submits it, and the GPU waits for that too. The game submits a frame's three submissions within 0.2 ms, and the GPU then waited 1.3-2.6 ms before each, so its frame-start TIMESTAMP_TOP and frame-end TIMESTAMP spanned about 14.3 ms for about 12 of GPU work. agl's dynamic resolution steers by that span, and no resolution shortens the host's translation. The wait between the command buffers of one submission was already left out (seg_idle_before).

The change (every game; host only, no shader or pipeline archive rebuild): sub_lag in nvn_mtl.m places each submission where the Switch would have run it, at the later of the previous one's end there and its ready time (the game's nvnQueueSubmitCommands, or the passing of a queue wait it was held for: mtl_sub_ready), and its reports move back by the difference. Reports never move before the game submitted, so the game's own waits stay in. Out of order, with no ready time, or with its first command buffer's feedback missing, nothing moves. DM_NVN_GPU_TS=segment_submit_gaps keeps the wait (the earlier default).

Ruled out: a heap stamp per report made agl's per-pass reports exact but left the span and the fall; taking out every gap between the submissions of a guest frame failed, as the game presents a frame after submitting part of the next.

Reference entry: The GPU's wait for the host's translation between submissions; DM_NVN_GPU_TS's row; the game note. The symptom quotes the game upscaler input over 600 presents log line, which is added by the separate PR nvn/upscaler: count the frames rendered at each upscaler input size.

Checked

  • Tests: t_counter_clock (34 checks; with segment_submit_gaps the 8 placement checks fail). make -k -C dm/gfx/tests GAME=010015100B514000 run on this branch: all pass (t_counter_clock 34 / 0). dm/tools/tests test_docs, test_env_switches, test_pr_areas.
  • Games run: Nintendo Switch Sports Resort (04008E001F098000, v65536), M2 Max, the host from this change on the fork's branch, the playtest save's table tennis route, 330 s, 1280x720 window: the frame's span about 12.1 ms (14.3 before); DM_UPSCALER=game full size in 92% of the frames and back within 600 presents after a fall (four runs before: 75%, 98%, 33%, 44%); DM_UPSCALER=metalfx with DM_PRESENT_UPSCALE=metalfx 99.4% against 61%, MetalFX scalers made 13 times against 34. Frame time p50 16.0-16.3 / p95 20-24 ms and GPU p50 about 12.0 / p95 13.6 ms at full size, as before. Avioneta's tutorial (GPU 27.6 ms a frame): 30 fps at 854x480 with and without. In an 11-minute session on 2026-11-12 with a build of the fork's branch that has this change and the fork's other fixes (not the keep-busy switch), a player played two-player skate (the practice zone, then leaving it) and two-player Avioneta with no crash.
  • Not checked: regress.py check (every game's timestamp reports go through this change; no other game was run), lint_c.py tidy (no LLVM release on this Mac), iOS (the encode thread).
  • Devices and OS: M2 Max, macOS 27.2.

Docs

  • The finding is in its game note or its docs/reference/<subsystem>.md entry, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • A chain tool changed: not applicable
  • No game files, keys or data extracted from a game in the change or the attachments

@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation game: 04008E001F098000 A game labels Nov 12, 2026
Symptom: Nintendo Switch Sports Resort's (04008E001F098000, v65536) dynamic
resolution fell to 854x480-1280x720 in a table tennis match and stayed there
for minutes (560 of 600 frames at 854x480), while its GPU p50 stayed about
12 ms, the same as at full size: the picture was upscaled from a quarter of
the pixels or less. Whether it fell was chance, and a fall was for good: of
four runs of the route, one held full size.

Cause: a Switch GPU starts a submission as soon as the previous one ends, or
when the game submits it if that is later. Here the host translates a
submission after the game submits it, and the GPU waits for that too. The
game submits a frame's three submissions within 0.2 ms (from two threads;
the submit lock waits were 0-0.7 ms), and the GPU then waited 1.3-2.6 ms
before each. Its frame-start TIMESTAMP_TOP (first submission) and frame-end
TIMESTAMP (third) spanned about 14.3 ms for about 12 of GPU work. agl's
dynamic resolution steers by that span, and no resolution shortens the
host's translation, so once a long frame took it down the span stayed over
its threshold at every size. The wait between the command buffers of one
submission was already left out (seg_idle_before).

Fix (every game; host only, no shader or pipeline archive rebuild): sub_lag
in nvn_mtl.m places each submission where the Switch would have run it, at
the later of the previous one's end there and its ready time, and its
reports move back by the difference. The ready time is the game's
nvnQueueSubmitCommands (nvn_queue_submit, recorded on the queue job), or the
passing of a queue wait the submission was held for (mtl_sub_ready). Reports
never move before the game submitted, so the game's own waits stay in, and a
lag is at most the time from the submit to the GPU's start. Out of order,
with no ready time, or with its first command buffer's feedback missing,
nothing moves. DM_NVN_GPU_TS=segment_submit_gaps keeps the wait (the earlier
default).

Ruled out on the way: timestamp reports at their own place in the stream (a
heap stamp per report) made agl's per-pass reports exact but left the span
and the fall; taking out every gap between the submissions of a guest frame
failed, as the game presents a frame after submitting part of the next.

Checked: t_counter_clock (34 checks; with segment_submit_gaps the 8
placement checks fail); make -C dm/gfx/tests GAME=010015100B514000 run on
this branch; test_docs, test_env_switches, test_pr_areas. In the game on an
M2 Max (the host from this change on the fork's branch, the playtest save's
table tennis route, 330 s, 1280x720 window on a 75 Hz screen): the frame's
span about 12.1 ms; DM_UPSCALER=game full size in 92% of the frames and back
within 600 presents after a fall; DM_UPSCALER=metalfx with
DM_PRESENT_UPSCALE=metalfx 99.4% against 61% without, MetalFX scalers made
13 times against 34. Frame time p50 16.0-16.3 / p95 20-24 ms and GPU p50
about 12.0 / p95 13.6 ms at full size, as without. Avioneta's tutorial (GPU
27.6 ms a frame): 30 fps at 854x480 with and without, same frame and GPU
times. In an 11-minute session on 2026-11-12 with a build of the fork's
branch that has this change and the fork's other fixes (not the keep-busy
switch), a player played two-player skate (the practice zone, then leaving
it) and two-player Avioneta with no crash. Not run: other games, regress.py,
lint_c tidy (no LLVM release here), iOS (the encode thread).

Docs: frame-rate.md (The GPU's wait for the host's translation between
submissions), DM_NVN_GPU_TS's row, the game note, symptom index regenerated.
@bymaxmarc
bymaxmarc force-pushed the pr/timestamp-submit-lag branch from ecd5f6b to 29dc65b Compare November 13, 2026 16:41
seedds added a commit that referenced this pull request Nov 15, 2026
…r translation between submissions leaves the span a game's dynamic resolution reads (PR #2491)

Timestamp reports already left out the gaps between command buffers of one
submission (seg_idle_before), but not the GPU's wait for the host's
translation between submissions. agl's dynamic resolution steers by the span
between its frame-start and frame-end reports, so on a slow host it read the
translation as GPU time: Switch Sports Resort on an M2 Max read 14.3 ms where
the GPU took 12.1 ms and stepped down to 854x480 in 560 frames of 600 (PR
author's measurement).

Reports now follow one timeline in fence order: each submission starts at the
later of the timeline's end and the time it was ready (the queue's submit time
or the end of a held wait, mtl_sub_ready), and its reports move back by how
much later the real GPU started it (sub_place, place_back). A report never
moves before its submission was ready, nor later than the GPU ran it. A
submission that cannot be placed (no first feedback, no ready time) stays
where it is, and the timeline goes on from its end, so no later report reads
earlier than one of its own. DM_NVN_GPU_TS=segment_submit_gaps keeps the old
reports.

t_counter_clock: 37 checks, 11 of them fail with segment_submit_gaps. regress
check on an M4 Pro (macOS 27.2.1), main against this: Mario Kart World 60.0
fps, p99 20.63 against 20.62 ms (its scene stayed 2560x1440, so its dynamic
resolution was not exercised); Breath of the Wild 59.7 against 59.8 fps;
both PASS, no new red line.

Co-authored-by: bymaxmarc <354601562+bymaxmarc@users.noreply.github.com>
@seedds

seedds commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Landed on main as c4aa24c, with you as co-author. Thanks for the diagnosis and the Switch Sports Resort measurements.

What changed from the PR:

  • One GPU timeline in fence order. Each submission starts at the later of the timeline's end and its ready time (your mtl_sub_ready plumbing, kept as you wrote it). Its reports move back by how much later the real GPU started it (sub_place, place_back). The same rule covers the gaps between command buffers (seg_idle_before) and between submissions. A report never moves before its submission was ready, and never later than the GPU ran it.
  • Skip fix. In the PR, a submission that could not be placed (no first feedback, or no ready time) let the next submission be placed over it. The timeline now goes on from that submission's end, so no later report reads earlier than one of its own.
  • g_lag_mu is gone: post_run already runs under g_post_mu.
  • The reference entry no longer quotes the log line from nvn/upscaler: count the frames rendered at each upscaler input size #2490, which has not landed.
  • t_counter_clock: 37 checks. 11 of them fail with DM_NVN_GPU_TS=segment_submit_gaps, which keeps the old reports.

regress.py check on an M4 Pro, main against this change:

  • Mario Kart World: 60.0 fps both, p99 20.63 against 20.62 ms. Its scene stayed at 2560x1440 in every profiled frame, so its dynamic resolution was never exercised.
  • Breath of the Wild: 59.7 against 59.8 fps.
  • Both PASS, no new red line.

The resolution benefit so far rests on your Switch Sports Resort runs. If you can rerun that on main on the M2 Max and post the time at full resolution, that would confirm it for the version that landed.

@seedds seedds closed this Nov 15, 2026
Kayyluhh added a commit to Kayyluhh/nxnative that referenced this pull request Nov 15, 2026
…#2341's held-commit time, which also raises the submission's ready time (seedds#2491's timeline) to the release, since its wait was taken ahead of the game's signal
bymaxmarc added a commit to bymaxmarc/nxnative that referenced this pull request Nov 17, 2026
Main landed two of the branch's changes in its own versions, which are taken
whole: the Switch 2 Mii stand-in (15316fd, PR seedds#2488: one shared
<DM_TEMP>_sysdata/mii directory) and the timestamp reports on one GPU
timeline (c4aa24c, PR seedds#2491: sub_place / place_back). The branch's own
hle_mii.c, hle_fs.c, t_mii_sysdata.c, nvn_queue.inc, t_counter_clock.m and
its timestamp code in nvn_mtl.m are dropped, and the game note, symptoms,
frame-rate.md and services.md lines for them are main's.

Kept and adapted to main: compute pipelines built off the replay thread
(cps-async: CpsJob beside main's NvShader fields, cps_build through main's
dev_cps compile gate, the slow-compile watch around main's plain_rps, cps_get
before main's loop containment and dispatch_), the GPU keep-busy switch
DM_NVN_GPU_BUSY, CMDSTAT's control memory (its dump at the first null-pool
buffer after main's physical pool check), the upscaler size log, the present
minify filter, scripted swings (main's object-per-source host Makefile needs
no header list) and the HLE_FORCE uniqueness test.

The pipeline archive split (compile_split, LEFT_OUT_EXIT) is dropped: it no
longer applies to main's pso_offline.py (prewarm-host, vol_space), so
pso_offline.py, its tests, build_ipa.sh, the NSP script and their docs are
main's.

Kept from the branch beyond those: the 9 task / mesh pipelines of other
sports in the prewarm list and the two Switch Sports Resort notes on model
heaps in memory.md.
bymaxmarc added a commit to bymaxmarc/nxnative that referenced this pull request Nov 18, 2026
Symptom: Nintendo Switch Sports Resort (04008E001F098000, v65536) looks
blurry for stretches of play, and nothing in the log said at what resolution
it was rendering: the upscaler lines appear only when MetalFX makes a scaler
for a new size, and not at all with the game's own upscaler.

Cause: no record of a game's dynamic resolution frame by frame.

Change (diagnostic, no behaviour change): for a game whose profile names
upscaler shaders (DM_GAME_UPSCALER_KEYS), each dispatch of one notes its
input rectangle (push constants, as up_mfx_encode reads them), with
DM_UPSCALER=game or metalfx alike; each present takes the last size noted
since the previous one, or none (full size). Every 600 presents one line,
`game upscaler input over 600 presents: none (full size) N, WxH n, ...` (8
sizes, the rest as other sizes), once the game has upscaled at all.

What it showed (M2 Max, Switch Sports Resort's pointer calibration screen,
DM_UPSCALER=game, one 150 s run): most windows at full size (2560x1440) at a
GPU p50 of about 12.4 ms, then windows at 854x480-1280x720 (one with 333
frames at 854x480) while the GPU p50 stayed 12.2-12.4 ms; that led to the
timestamp change of PR seedds#2491 (landed as c4aa24c: the GPU's wait for the
host's translation between submissions).

Checked: t_upscaler_mfx with GAME=040074A01BF12000 (a profile with upscaler
keys; DM_UPSCALER=metalfx with and without the encoding thread, and game):
an unnamed shader notes nothing, the named one notes 2134x1200, the present
takes it (3 new checks); make -C dm/gfx/tests GAME=010015100B514000 run on
this branch; test_docs, test_env_switches, test_pr_areas. Not run: lint_c
tidy (no LLVM release here), the iPhone.

Docs: the game note lists the sizes and names the line, and the reference
entry (The GPU's wait for the host's translation between submissions) quotes
it for its 560 frames of 600 at 854x480; symptom index regenerated.
@bymaxmarc

Copy link
Copy Markdown
Contributor Author

Reran it on main on the M2 Max. On this route, the version that landed does not keep full size.

Setup

  • Machine: Apple M2 Max, macOS 27.2.1.
  • Build: main at e4b0d9b, as a Mac app.
    • The frames per input size come from nvn/upscaler: count the frames rendered at each upscaler input size #2490's log line, applied to this build only.
    • Main stops building this game at the shader split since 8d62601: 36 rows of the profile's shader_map.tsv differ from the new split in file index and first-appearance column, with the same stage and key pairs. For this build I used the split's table; the profile needs splitting again.
  • Settings: the player's, DM_UPSCALER=metalfx and DM_PRESENT_UPSCALE=metalfx, in a 1280x720 window (2560x1440 drawable, so the present is not scaled). No DM_NVN_GPU_BUSY and no Switch 2 controllers.
  • Route: the playtest save's table tennis route.
    • Menus, match settings, then the pointer calibration, passed with X.
    • About 280 s in the match, at the first serve with no input.
    • 420 s per run, 29 windows of 600 presents in the match.
    • Runs alternated: main's default, DM_NVN_GPU_TS=segment_submit_gaps, default, segment_submit_gaps.

Results

Run Full size (2560x1440) in the match Frame p50 / p95 GPU p50 at full size GPU p50 at 854x480
default 1 28.2% 16.67 / 16.8 ms 11.8 ms 14.5 ms
default 2 27.6% 16.67 / 16.8 ms 12.0 ms 14.2 ms
segment_submit_gaps 1 40.3% 16.67 / 16.9 ms 12.3 ms 14.5 ms
segment_submit_gaps 2 55.3% 16.67 / 16.9 ms 12.8 ms 14.5 ms
  • In every run, both default and segment_submit_gaps, the match starts at full size and falls to 854x480 after 25-90 s.
    • With the default, the falls lasted about 180 s and 200 s.
    • With segment_submit_gaps, the falls that ended before the run did lasted 60-80 s.
    • It climbs back to full size each time and then falls again.
  • In the match, 854x480 is 62-64% of the frames with the default and 41-49% with segment_submit_gaps.
  • The rate held 60 fps throughout: frame p50 16.67 ms in every window.
  • The span the game steers by is not logged on main, so I have no number for it.
  • Unlike nvn/timestamps: leave out the GPU's wait for translation between submits #2491's earlier measurement (99.4% full size with these settings), the landed reports did not keep this match at full size here. These runs also do not show them doing better than segment_submit_gaps.

GPU time at 854x480

  • With DM_UPSCALER=metalfx, the GPU time per frame is higher at 854x480 (about 14.2-14.5 ms) than at full size (about 11.8-12.8 ms) in all four runs.
  • It is not the MetalFX scaler's cost. I checked with DM_UPSCALER=game on main plus a few local changes: 8 more runs on the same route, alternating metalfx and game, with and without a GPU keep-busy load. Every run shows the same pattern, with GPU p50 about 13.6-14.0 ms at 854x480 against 11.0-13.5 ms at full size.
  • Full-size share in the match, two runs each: metalfx 51% / 11%, game 56% / 58%, with keep-busy metalfx 57% / 53% and game 35% / 45%. The spread between runs of one setting is as large as the differences between settings, so the upscaler does not decide the falls.

The profile fix is a re-split with main's shader_split.py (only those 36 rows change); I can open a PR for it if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 04008E001F098000 A game nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants