Skip to content

nvn/pipelines: a non-compiling call waits for another thread's archive lookup of the same base, so a draw during a background lookup takes its stand-in instead of compiling its base - #2770

Closed
stan69b wants to merge 1 commit into
seedds:mainfrom
stan69b:pr/oot-sleep-c-look-wait

Conversation

@stan69b

@stan69b stan69b commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What

pso_build_ex with compile 0 (a draw asking whether its base or its pulling base is made or archived, a prewarm task) returned nil at once when another thread held that base's job, so that it would never wait for the Metal compiler. A job's owner first only looks in the archives, which takes milliseconds, and a non-compiling owner does nothing else. So a draw that came during another thread's lookup of its pulling base found no stand-in. Its own base was already known missing, so it compiled that base on the submit thread.

The prediction's background base lookups (pso_bg_look, #2677) make the race happen every time: they look up the bases of the draws that come next in the same submission, milliseconds before those draws.

Fix: the owner leaves a second group, PbaseBuild.looked, once it has looked in the archives (with the base it found in found), before the compaction's capture and before any compile. A non-compiling call that finds another thread's job waits on looked and takes found. When the lookup found nothing it returns nil as before, without waiting for the compile. The wait is one archive lookup at most.

Evidence

The owner's play of Ocarina of Time on an iPhone 17 (2026-11-14), builds with #2677's background lookups: single draws waited 0.3–1.8 s on first visits (draws that waited: pulling base not made yet 1 / 861 ms, 2 / 1,081 ms, 8 / 1,786 ms per 300 frames) while the background lookups found every base they looked for (21 of 21). The build without them: 1 / 95 ms.

Mac (M4), Ocarina of Time v131072: an unattended route from a Kakariko save, out to Hyrule Field and back, as a first visit (no recorded pipeline list), with an archive holding only the pair prebuild's pulling bases (what the phone's bundled archive holds). Hosts on the phone tree (be8db251 + #2677's commits), one run each:

host draws that waited predictions submit-thread pipeline time
without #2677's prediction changes (53cbb99, background lookups) 258 / 44.1 s 6,735 47.8 s
with them 214 / 32.0 s 321 32.3 s
with them and this fix 216 / 29.5 s 341 29.8 s

On the Mac the fix makes no measurable difference. An archive lookup takes well under a millisecond there, so the race's window is small; the waits left are draws whose pulling base no archive holds. The race shows on the phone, where a lookup takes about 10 ms. Not run: the phone (none was available for this change).

Checked

  • t_pso_look_wait, new, 9 checks: a non-compiling call during another thread's 200 ms lookup takes the base it found and compiles nothing (fails without the fix: nil at once); during a lookup that finds nothing, followed by a 2 s compile, it returns nil after the lookup; a non-compiling owner still marks a missing base.

  • t_pso_pending 66, t_pso_stall 73, t_pso_archive 362, t_pso_depth_stencil 301, t_pso_prewarm 64, t_pso_warm 123, t_pso_bundle 83, t_pso_msaa 34; on the phone tree with OoT-30 C: base lookups of predicted keys in the background, a takeover that looks at each entry once, submissions copied without the submission lock #2677: t_pso_bg_look 14, t_pso_look_wait 9, t_pso_pending 57.

  • test_docs; lint_c.py tidy: nothing above the baseline (LLVM 21 on this Mac).

  • regress.py check: not run. The only game this Mac can run it on is Ocarina of Time, which has no smoke route, so the check would be its shader chain alone, which this change does not touch (Echoes of Wisdom and Super Mario 3D All-Stars stop with ERROR on their baseline: their shader packages predate keyed records). regress.py impact names Breath of the Wild, Pokémon Scarlet and Tears of the Kingdom (every NVN game through the pipeline archive), none of which this Mac has. The route run with the fix booted Ocarina of Time and walked the whole route with no crash; its only [RED] line is the one every run of this setup prints (c1_full.tsv stale for these Mac libraries), the same as the run without the fix.

New reference entry: docs/reference/frame-rate.md, "A draw that came during another thread's archive lookup compiled its base"; symptom index updated.

@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 15, 2026
stan69b pushed a commit to stan69b/nxnative that referenced this pull request Nov 15, 2026
…sults

Memory: the combined phone builds' extra 300-500 MB is the shadow target's 288 MB pool held twice (PR seedds#2775), and on the Mac no added host change holds more (C-2's table). Frame rate: a draw that came during another thread's archive lookup compiled its base on the submit thread (PR seedds#2770), and the stuck slow state's next step is a phone A/B of the build with the new lines.
stan69b pushed a commit to stan69b/nxnative that referenced this pull request Nov 15, 2026
A-1 done on the Mac, phone not measured (PR seedds#2775): a memory pool's Finalize takes the serial entries naming its textures, so the old 288 MB shadow heap goes at the field load
A-2 done: phone build oot-sleep-a fddbb950
B-1 done: the overnight A/B (fix2 1/8 stuck, a2 4/8, all1 3/8; verdict not established) in the game note
B-2 partial: the main thread waits and host threads lines are in; the stuck state's cause is open; no phone test (the batch started after 09:00)
B-3 done: oot-sleep-all 57c9267a (fix2 + 53cbb99 + C-3 + C-1 + A-1 + B-2), app built, not installed; the game note's open items; regress.py check PASS on Ocarina of Time
C-1 done, phone not measured (PR seedds#2770): a non-compiling pipeline call waits for another thread's archive lookup of the same base
C-2 done (measurement, no commit): on the Mac no added host change holds more memory
C-3 done: phone build oot-sleep-c 5dd697c2, 53cbb99 and C-3 kept
…'s archive lookup of the same base, not only returns nil, so a draw that comes during a background lookup takes its stand-in instead of compiling its base on the submit thread

pso_build_ex with compile 0 (a draw asking whether its base or its pulling base is made or archived, a prewarm task) returned nil at once when another thread held that base's job, so that it would never wait for the Metal compiler. A job's owner first only looks in the archives, which takes milliseconds, and a non-compiling owner does nothing else. A draw that came during such a lookup of its pulling base found no stand-in; its own base was already known missing, so it compiled that base on the submit thread.

The prediction's background base lookups (pso_bg_look, PR seedds#2677) make the race happen every time: they look up the bases of the draws that come next in the same submission, milliseconds before those draws. On the owner's iPhone 17 play of 2026-11-14 the builds with them had single draws waiting 0.3-1.8 s on first visits ("draws that waited: pulling base not made yet" 1 / 861 ms, 2 / 1,081 ms, 8 / 1,786 ms per 300 frames, while the background lookups found every base: 21 of 21), against 1 / 95 ms on the build without them.

- PbaseBuild.looked / found: the owner leaves looked once it has looked in the archives (or skipped them for a base known missing), with the base it found, before the compaction's capture and before any compile.
- A compile 0 call that finds another thread's job waits on looked and takes found; when the lookup found nothing it returns nil as before, without waiting for the compile.

Mac, M4, Ocarina of Time v131072, an unattended route from a Kakariko save (out to Hyrule Field and back), a first visit (no recorded pipeline list), the archive holding only the pair prebuild's pulling bases (as the phone's bundled archive), hosts on the phone tree (be8db251 + seedds#2677's commits), one run each: draws that waited 214 / 32.0 s without the fix, 216 / 29.5 s with it. On the Mac an archive lookup takes well under a millisecond, so the race's window is small there and the waits left are draws whose pulling base no archive holds; the race shows on the phone, where a lookup takes about 10 ms. Not run: the phone (no phone in this batch).

Checked: t_pso_look_wait 9 checks, new (fails without the fix: the call during a 200 ms lookup returned nil at once); t_pso_pending 66, t_pso_stall 73, t_pso_archive 362, t_pso_depth_stencil 301, t_pso_prewarm 64, t_pso_warm 123, t_pso_bundle 83, t_pso_msaa 34; test_docs; lint_c.py tidy (nothing above the baseline). regress.py: not run. The only game this Mac can run it on is Ocarina of Time, which has no smoke route, so the check is its shader chain alone, which this change does not touch; the route runs above booted the game with the change.

New reference entry: docs/reference/frame-rate.md, "A draw that came during another thread's archive lookup compiled its base"; symptom index updated.

(cherry picked from commit 51a1de4)
stan69b pushed a commit to stan69b/nxnative that referenced this pull request Nov 16, 2026
…sults

Memory: the combined phone builds' extra 300-500 MB is the shadow target's 288 MB pool held twice (PR seedds#2775), and on the Mac no added host change holds more (C-2's table). Frame rate: a draw that came during another thread's archive lookup compiled its base on the submit thread (PR seedds#2770), and the stuck slow state's next step is a phone A/B of the build with the new lines.
(cherry picked from commit 68c2ef3)
@stan69b
stan69b force-pushed the pr/oot-sleep-c-look-wait branch from 51a1de4 to b830eda Compare November 16, 2026 15:28
seedds added a commit that referenced this pull request Nov 16, 2026
Prediction synchronously looked up and specialized pulling stand-ins on the
submit thread, including keys that were never drawn. Move the base lookups
to background workers and reuse the process-wide base/miss caches. Take only
C-3 from PR #2677; submission copying, storage takeover and sampling remain
separate.

Give each prediction a retained budget, charged under the pending-table lock
only when a guess is admitted. Reserve a slot while its draw waits so a
background admission cannot replace the completed pipeline before that draw
takes it. Sample admission/completion/steal counts coherently for diagnostics.
The full-table fixture reproduced wrong-pipeline delivery before reservation.

Checked together with PR #2770 on Apple M4 Pro, macOS 27.2.1: lookup 9,
background lookup 17, pending 92, stall 110, depth/stencil 228/231/228/231;
docs 6; clang-tidy LLVM 23.1.5 with no baseline increase; unsigned iOS
production-project compile/link fixture with synthetic inputs.

Full regress.py check: NieR Automata 010056B015FE8000, 220 seconds per side,
1,225/1,225 shaders each, no changed MSL, interface changes or new RED kinds;
PASS. This light NVN title covers the shared archive path. Both runs were
busy, so their timing is not a performance qualification. iPhone testing was
waived by the owner on 2026-11-17; phone benefit remains unverified.

Co-authored-by: Stan Bono <3304418+stan69b@users.noreply.github.com>
seedds added a commit that referenced this pull request Nov 16, 2026
A non-compiling pipeline lookup returned nil when another thread owned the
same base's job. A draw could therefore miss an archived pulling stand-in
and compile its own base on the submit thread.

Publish the archive result through a separate completion group before any
compaction capture or compile. A non-compiling waiter takes that result,
or returns nil on a completed archive miss, without waiting for compilation.
Keep the compiling completion path unchanged. Include the reciprocal OoT
finding and the optional matched phone comparison.

Checked with the corrected background predictor: lookup-wait fixture 9,
background lookup 17, pending 92, stall 110, depth/stencil 228/231/228/231;
docs 6; clang-tidy with no baseline increase; unsigned iOS compile/link
fixture; full NieR Automata regression PASS (1,225 shaders, 220 seconds per
revision, no new RED or interface changes). The Mac runs were busy and do
not establish a gain. The owner waived the iPhone retest on 2026-11-17;
phone performance remains unverified.

Co-authored-by: Stan Bono <3304418+stan69b@users.noreply.github.com>
@seedds

seedds commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Landed on origin/main as edc7eff9, following the corrected background-lookup commit 9d3a5836 from PR #2677.

The non-compiling waiter now uses a separately published archive result before any compaction capture or compile. Code and final diff were reviewed. Stan Bono is credited on both commits as Co-authored-by: Stan Bono <3304418+stan69b@users.noreply.github.com> because meaningful PR code, design and diagnosis were retained; identity was verified with GitHub's user API.

Validation: lookup-wait 9, background lookup 17, pending jobs 92, stall 110, depth/stencil 228/231/228/231; documentation 6; generated symptom index current; clang-tidy LLVM 23.1.5 with no baseline increase; unsigned production iOS compile/link fixture with synthetic inputs. After the clean rebase onto 44d67fb, lookup 9, background 17, pending 92, the upstream arena fixture 42 and documentation 6 passed again, as did unsigned iOS compilation. Range-diff confirmed both patches were unchanged by rebase.

The full NieR regression below used the earlier main base 60284e7 and the reviewed combined implementation. NieR was chosen as a light NVN archive title (1,225 shaders), covering the common pipeline path. Both runs were explicitly busy; screenshots at 100/180 seconds were reviewed and show the same flight sequence with formation/timing differences and no obvious new missing geometry. The shared measurement lock serialized game runs.

Full regression report

regress.py check (full): PASS

Baseline 60284e7901cb4acd0e057d99fdf5560e0cd8e2fe 60284e7, candidate worktree 60284e7 (+ uncommitted changes); Apple M4 Pro, macOS 27.2.1, Xcode 27.2; 470.6 s

game status shaders (base → cand) newly failing newly building changed MSL interface (new / known) boot fps p50 frame p99 ms peak MB prepare s new RED
NieR Automata The End of YoRHa Edition 010056B015FE8000 PASS 1225/1225 → 1225/1225 0 0 0 0 / 0 ok 59.9 → 59.9 17.18 → 17.2 2346 → 2332 0.16 → 0.09 0

NieR Automata The End of YoRHa Edition 010056B015FE8000: PASS

  • screenshots (s: dHash bits / RGB diff / baseline noise): 100: 17/5.12/0, 180: 13/5.71/0
  • baseline: exit None, first frame 0.8 s, max frame 13111, reached True, prepare 0.16 s, prebuild 12.0 s (902 built, 0 failed), fps 59.9, p50/p99 16.66/17.18 ms, peak 2346 MB, busy Mac
  • candidate: exit None, first frame 0.8 s, max frame 13087, reached True, prepare 0.09 s, prebuild 13.9 s (902 built, 0 failed), fps 59.9, p50/p99 16.67/17.2 ms, peak 2332 MB, busy Mac
  • time: chain 3.2 s, smoke 467.2 s
  • Should it exist? Yes. An available archive base was reported absent solely because another thread owned its lookup; the lookup fixture reproduces the mechanism. The background admission review also reproduced a full-table handoff returning the wrong pipeline before consumer reservation.
  • Confidence: high in the host synchronization fixes; phone improvement remains unverified.
  • Binding: general host, already the loosest correct binding; no game/build conditions.
  • Workaround: none; fixes lookup publication, budget lifetime and pending-result ownership.
  • From-scratch design: yes: separate lookup/compile completion, per-prediction budgets and reserved consumer ownership.
  • Performance: expected to avoid draw-time compiles when the concurrent lookup finds the archived stand-in; phone benefit remains unmeasured and busy Mac timings establish no gain. Estimated added predictor bookkeeping is about 1–2 KiB per unique predicted base from the 784-byte key and hash-table capacity.
  • Regression level: moderate shared synchronization risk; one light game, NieR, full route PASS. Other games were not run for this change; no heavy OoT Mac regression was needed to cover the shared path.

Remaining: the owner explicitly waived the iPhone retest for landing on 2026-11-17; it was not run, and phone performance remains unverified. The optional route remains in the game note. No further #2770 implementation work or replies are awaited. PR #2677's independent submission-copy, takeover and sampler work remains separate.

@seedds seedds closed this Nov 16, 2026
stan69b pushed a commit to stan69b/nxnative that referenced this pull request Nov 18, 2026
…sults

Memory: the combined phone builds' extra 300-500 MB is the shadow target's 288 MB pool held twice (PR seedds#2775), and on the Mac no added host change holds more (C-2's table). Frame rate: a draw that came during another thread's archive lookup compiled its base on the submit thread (PR seedds#2770), and the stuck slow state's next step is a phone A/B of the build with the new lines.
(cherry picked from commit 68c2ef3)
stan69b pushed a commit to stan69b/nxnative that referenced this pull request Nov 24, 2026
…sults

Memory: the combined phone builds' extra 300-500 MB is the shadow target's 288 MB pool held twice (PR seedds#2775), and on the Mac no added host change holds more (C-2's table). Frame rate: a draw that came during another thread's archive lookup compiled its base on the submit thread (PR seedds#2770), and the stuck slow state's next step is a phone A/B of the build with the new lines.
(cherry picked from commit 68c2ef3)

Rebased onto main ffb06d6, whose note now has the archive-lookup retest
section (waived for landing) and the reference entry for the shadow target's
pool (13c35e9): the first-visits line now reads resolved in the host with
the phone benefit unverified and links that section, and the +340-380 MB line
links the memory.md entry instead of repeating its Mac measurements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation 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