Skip to content

Publish coherent presentation-time and display-link history snapshots - #2194

Closed
akratch wants to merge 2 commits into
seedds:mainfrom
akratch:contrib/present-history-20261110
Closed

akratch wants to merge 2 commits into
seedds:mainfrom
akratch:contrib/present-history-20261110

Conversation

@akratch

@akratch akratch commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Drawable callbacks and queue-drop paths write presentation history while guest timing readers inspect it. The sequence number and timing payload were unsynchronized fields, so a reader could observe a torn record; a delayed callback could also replace a newer wrapped generation.

Publish and read each presentation/link descriptor under one private mutex, and reject older wrapped generations. Helpers acquire no renderer or queue locks while holding that mutex. Public timing signatures and the unknown/drop sentinels stay unchanged; no rendering or pacing policy changes.

The portable fixture checks coherent snapshots, missing/wrapped generations and concurrent readers/writers over 48,000 paired publications. All ten checks pass normally and under ThreadSanitizer. Removing only synchronization from the helper produces a TSan race. A CPU-only CI step runs the normal and sanitizer fixtures.

Each change is based on immutable upstream e45694b7. The standalone Mac host builds, six documentation tests pass, and focused LLVM 23.1.5 analysis reports zero new findings with the upstream baseline unchanged. No exact-head game run or iOS gameplay test is claimed. The mechanism was also exercised in a separate OOT Mac integration; that is not a substitute for standalone-head gameplay.

Impact manifests name Breath of the Wild, Pokémon Scarlet and Tears of the Kingdom as affected; Hades is unaffected and profiles without usage manifests remain unknown. Those games were not run here. No game assets or captures are included.

Drawable callbacks, queue-drop paths and timing readers accessed the sequence
number and timestamp fields of shared rings without synchronization. A reader
could combine different generations, and a delayed callback could replace a
newer wrap. Publish and read each record under a private mutex and reject older
generations. Keep all helpers free of renderer/queue lock acquisition; the
public timing signatures and unknown/drop sentinels are unchanged.

Add a portable four-writer/four-reader fixture with 48,000 paired publications,
normal and ThreadSanitizer targets, and a CPU-only CI step. Both ten-check runs
pass. Removing just the synchronization reports a TSan data race. The standalone
Mac host builds, focused LLVM 23.1.5 analysis has no new findings against the
unchanged upstream baseline, and six documentation tests pass.

No rendering or pacing policy changes are included. This proves history
synchronization, not a frame-rate gain or the cause of a gameplay artifact.

Co-authored-by: Adam Kratch <70729875+akratch@users.noreply.github.com>
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation ci Continuous integration and repository settings (.github) labels Nov 10, 2026
Keep the per-game evidence discoverable without duplicating the mechanism.
Runtime code and synthetic fixtures are unchanged from the checked head.

Co-authored-by: Adam Kratch <70729875+akratch@users.noreply.github.com>
kingbumi31 pushed a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
…herent snapshots (seedds)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 pushed a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv)

Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 pushed a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
… pull requests taken on 2026-11-12, the switch table's missing rows

The profile's pso_manifest.tsv was the two-line placeholder, so a packed app started with no list: 116 long frames in its first 75 s at the title on this Mac, each new
pipeline looked up in the bundled archive on the submit thread. It is now mkw/pso/pso_manifest_merged_180.tsv: 15,062 rows (6,827 shaders, 8,002 render pipelines, 222 compute
pipelines, 11 task / mesh pipelines), the nine lists found online on 2026-11-11 with azmasm/switch2mac's at 25ceb457 (71 rows more, 2 of them new here) and the list of the
app's own first start (5,549 rows, 12 new). No other source had moved on 2026-11-12 (Thijs2004/nxnative-mkw b1c5e4e5, MenAtCafe/mkw-neo cfa62ddc, cheemu21/plumber-racer-2
843170ac, pahorema/kartnative 47f2d1d5, pull request seedds#2097 1a4fd59). mkw/test/prep_probe.sh on the merged list with this Mac's archive: 15,062 lines in 1.20 s, 1 pipeline
compiled, no crash.

Pull requests of seedds/nxnative taken in the three commits before this one's parent: seedds#2408 (d82324f, a sparse mapping starts a new texture ID epoch only when it is new),
seedds#2328 (65690e0, mtl_pool_del reads the open flag before g_fence) and seedds#2348 (55773c7, the display link off in fullscreen on a fixed-rate screen whose presents keep turning
late). seedds#2348's presented handler reads its tick through nvn_link_history_get here: this tree has PR seedds#2194's snapshots where the pull request reads g_link_ring. Their effect on
this game, and what was looked at and left out (seedds#2341), is in the game's README.

docs/env_switches.tsv: rows with their meaning for DM_PSO_WHOLE, DM_NVN_IND_SPLIT and DM_NVN_VCONV_KEEP (upstream's text), which the table lacked, so test_env_switches
passes. mkw/env-m2pro-16gb.txt: the comment of the pad says what one player draws at it now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
…herent snapshots (seedds)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv)

Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
… pull requests taken on 2026-11-12, the switch table's missing rows

The profile's pso_manifest.tsv was the two-line placeholder, so a packed app started with no list: 116 long frames in its first 75 s at the title on this Mac, each new
pipeline looked up in the bundled archive on the submit thread. It is now mkw/pso/pso_manifest_merged_180.tsv: 15,062 rows (6,827 shaders, 8,002 render pipelines, 222 compute
pipelines, 11 task / mesh pipelines), the nine lists found online on 2026-11-11 with azmasm/switch2mac's at 25ceb457 (71 rows more, 2 of them new here) and the list of the
app's own first start (5,549 rows, 12 new). No other source had moved on 2026-11-12 (Thijs2004/nxnative-mkw b1c5e4e5, MenAtCafe/mkw-neo cfa62ddc, cheemu21/plumber-racer-2
843170ac, pahorema/kartnative 47f2d1d5, pull request seedds#2097 1a4fd59). mkw/test/prep_probe.sh on the merged list with this Mac's archive: 15,062 lines in 1.20 s, 1 pipeline
compiled, no crash.

Pull requests of seedds/nxnative taken in the three commits before this one's parent: seedds#2408 (d82324f, a sparse mapping starts a new texture ID epoch only when it is new),
seedds#2328 (65690e0, mtl_pool_del reads the open flag before g_fence) and seedds#2348 (55773c7, the display link off in fullscreen on a fixed-rate screen whose presents keep turning
late). seedds#2348's presented handler reads its tick through nvn_link_history_get here: this tree has PR seedds#2194's snapshots where the pull request reads g_link_ring. Their effect on
this game, and what was looked at and left out (seedds#2341), is in the game's README.

docs/env_switches.tsv: rows with their meaning for DM_PSO_WHOLE, DM_NVN_IND_SPLIT and DM_NVN_VCONV_KEEP (upstream's text), which the table lacked, so test_env_switches
passes. mkw/env-m2pro-16gb.txt: the comment of the pad says what one player draws at it now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
…herent snapshots (seedds)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv)

Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
… pull requests taken on 2026-11-12, the switch table's missing rows

The profile's pso_manifest.tsv was the two-line placeholder, so a packed app started with no list: 116 long frames in its first 75 s at the title on this Mac, each new
pipeline looked up in the bundled archive on the submit thread. It is now mkw/pso/pso_manifest_merged_180.tsv: 15,062 rows (6,827 shaders, 8,002 render pipelines, 222 compute
pipelines, 11 task / mesh pipelines), the nine lists found online on 2026-11-11 with azmasm/switch2mac's at 25ceb457 (71 rows more, 2 of them new here) and the list of the
app's own first start (5,549 rows, 12 new). No other source had moved on 2026-11-12 (Thijs2004/nxnative-mkw b1c5e4e5, MenAtCafe/mkw-neo cfa62ddc, cheemu21/plumber-racer-2
843170ac, pahorema/kartnative 47f2d1d5, pull request seedds#2097 1a4fd59). mkw/test/prep_probe.sh on the merged list with this Mac's archive: 15,062 lines in 1.20 s, 1 pipeline
compiled, no crash.

Pull requests of seedds/nxnative taken in the three commits before this one's parent: seedds#2408 (d82324f, a sparse mapping starts a new texture ID epoch only when it is new),
seedds#2328 (65690e0, mtl_pool_del reads the open flag before g_fence) and seedds#2348 (55773c7, the display link off in fullscreen on a fixed-rate screen whose presents keep turning
late). seedds#2348's presented handler reads its tick through nvn_link_history_get here: this tree has PR seedds#2194's snapshots where the pull request reads g_link_ring. Their effect on
this game, and what was looked at and left out (seedds#2341), is in the game's README.

docs/env_switches.tsv: rows with their meaning for DM_PSO_WHOLE, DM_NVN_IND_SPLIT and DM_NVN_VCONV_KEEP (upstream's text), which the table lacked, so test_env_switches
passes. mkw/env-m2pro-16gb.txt: the comment of the pad says what one player draws at it now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
seedds added a commit that referenced this pull request Nov 22, 2026
…snapshots (PR #2194)

Drawable callbacks, queue-drop paths, and timing readers (hle_nvn.c, hle_vi.c) accessed g_pres and g_link_ring without synchronization, creating a data race, torn-read risk across sequence/timestamp fields, and stale-wrap overwrite risk.

Publish and read both history rings under a private leaf mutex in nvn_present_history.h, rejecting older wrapped generations and ignoring ticket 0. Add CPU-only normal and ThreadSanitizer tests (t_present_history, present-history-tsan) and run them in CI.

Co-authored-by: Adam Kratch <70729875+akratch@users.noreply.github.com>
@seedds

seedds commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks @akratch for finding this race and putting together the helper and ThreadSanitizer test!

This landed on main in 7ff0aef (with you credited as co-author), rebased onto current main with a few small updates:

  • Kept PRING defined in dm/gfx/nvn/nvn_mtl.m for the enqueue-time and frame-number rings added since the PR's base, and updated drop_queued_presents_locked() instead of the older present_drop_for_suspend() loop.
  • Guarded ticket 0 consistently in both the presentation-time and display-link history helpers.
  • Integrated t_present_history and present-history-tsan into the existing CPU-only graphics test step in CI, and omitted the Ocarina of Time note and symptom-index entries since this was a general synchronization fix found by code review.

Checked: t_present_history (normal and ThreadSanitizer), t_present_rescue, t_link_ticks, t_present_snap (screen and screen_snap), the documentation and C-lint script tests, and a clean Mac host build. Nothing remains open beyond the standard CI run on main.

@seedds seedds closed this Nov 22, 2026
Aznracer pushed a commit to Aznracer/Mighty-Green-Kokiri-Kid that referenced this pull request Nov 25, 2026
…snapshots (PR seedds#2194)

Drawable callbacks, queue-drop paths, and timing readers (hle_nvn.c, hle_vi.c) accessed g_pres and g_link_ring without synchronization, creating a data race, torn-read risk across sequence/timestamp fields, and stale-wrap overwrite risk.

Publish and read both history rings under a private leaf mutex in nvn_present_history.h, rejecting older wrapped generations and ignoring ticket 0. Add CPU-only normal and ThreadSanitizer tests (t_present_history, present-history-tsan) and run them in CI.

Co-authored-by: Adam Kratch <70729875+akratch@users.noreply.github.com>
(cherry picked from commit 7ff0aef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous integration and repository settings (.github) docs Documentation game: 0400486024DEC000 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