Repository navigation
Conversation
|
Hi! This branch is based on a To pick up the fix, merge the current git fetch origin
git merge origin/main
git pushIf the merge has conflicts, ask here if you want help with them. |
…rest Keep an open job at the head of its queue until its producer closes it. Publish sync snapshots at each boundary and retain program serials and texture descriptors until replay is done. Exercise the gap between prefix and suffix with a blocked producer and a second submission.
ab0c091 to
d9bfca4
Compare
Queue an open job before copying the submission and publish immutable nodes at wait and fence boundaries. Keep the open job in queue order while other ready queues can run, and retain program serials without resolving them on the producer. Extend the paused-producer fixture to cover progress on an independent queue. Document the lock contract, M3 Max measurements, current-main regression checks, and the original hitch that still needs an affected-device trace. Validated six queue and ownership fixtures in all four streaming/encoding modes, full Mario Kart World and Catherine routes, and a warmed alternating Mario Kart run. The documentation checks pass; the switch-table check has identical failures on baseline and candidate. Refs #2987. PR #2996. Co-authored-by: Arthur tinseau <65445747+atinseau@users.noreply.github.com>
|
Thanks, Arthur. Your submission-streaming implementation is now on main in 5588e99, with your co-author credit. I retained the queue design, added an assertion that an independent queue progresses while the producer is paused, and corrected the program-pin lock documentation. The six targeted queue and ownership fixtures passed with streaming and threaded encoding each on and off (24 runs). Full Mario Kart World 1.8.0 and Catherine: Full Body checks on a 16 GB M6 passed their routes, with identical shader outputs, no new pipeline-interface failures, and no new red diagnostics. Catherine's screenshots matched closely. The documentation checks passed; the switch-table check reports the same unrelated failures on baseline and candidate. The original 2,917.42 ms M3 Max frame remains unexplained. A native sampler attempt overlapped the first local baseline and timed out, so I did not use that pair's FPS difference as performance evidence. A separate warmed run alternated streaming every 300 frames without the native sampler: neither mode produced a 500 ms stall after the first 100 seconds; the largest frame was 397 ms with streaming off. This does not establish the cause of the original event. Closing this PR because the implementation has landed. #2987 stays open for the original M3 Max trace or an affected-device retest; iOS was not run here. |
…aller screens and seedds#2996; seedds#2912 replaced by upstream's versions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGrCTWig49u9S8ZCH37TUc
…ion lock, so the game's thread no longer waits for the queue replay of the one before Item C-4 asked whether the game's main thread (200-400 ms/s of CPU in the owner's slow windows, 2-4 ms of yields a frame) waits on the host. It does: a `sample` on the Mac (the owner's save, Temple of Time) has the main thread 16.5% in __psynch_mutexwait, 12.4% inside nvn_queue_submit -> pthread_mutex_lock. A submission copied its command lists (nq_flatten) under g_sub_mu, which the queue replay thread holds for the whole translation of each submission (nq_worker), so with 22-30 submissions a frame the game's thread waited for each one the replay had in hand; on an iPhone, with 11-24 ms of replay a frame in busy scenes, the frame was the main thread's work plus the replay's. The rest of the main thread's time is its own: guest code and its waits on the game's own workers (the yields; ModuleSystemWorker). The copy needed the lock only for the first submission's prepare step and for a program no replay had resolved (prog_get is the replay's), and the program pins it shared with the replay had no lock of their own. - nvn_queue_submit: no submission lock for the copy; the prepare step runs under it once (mtl_prepared). - nq_snapshot_object: a program the serial table holds is pinned and copied without it (mtl_prog_snapshot_live, own_prog_pin_live); only one not resolved yet takes the lock to be resolved, as before. - nvn_owner.m: the program pins have a lock of their own (g_pin_mu), taken before g_smu wherever both are held. Tests: check_t_queue_lifetime 43 x2 (a submission whose program is resolved returns while the lock is held, and draws; an unresolved program is left to the lock: new, fails before), t_gfx_suspend 20 (updated deliberately: both submissions now return while the prepare step holds the lock instead of the second waiting for it; nothing commits before the resume, as before), t_nvn 325, t_serial_owner 176, check_t_alias_takeover 48, test_docs. Docs: frame-rate.md "The game's submissions waited for the queue replay's lock", nvn-objects.md (the prepare-step entry's check), symptom index, game note. (cherry picked from commit f923323) Rebased onto main ffb06d6, where submission streaming (5588e99, PR seedds#2996) already copies a streamed submission without the submission lock, pins its programs by serial without resolving them (mtl_prog_snapshot_pin) and gives the program pins their own lock (g_prog_pin_lk). What C-4 still changes: nvn_queue_submit no longer takes the lock at the start of a streamed submission once the prepare step is done (mtl_prepared), so the game's thread no longer waits there for the node the replay has in hand; mtl_sub_stream_on sets its switch up once (pthread_once), as its first read may now come without the lock. Dropped as superseded: mtl_prog_snapshot_live, own_prog_pin_live and g_pin_mu (nvn_owner.h and nvn_owner.m are main's). The whole-submission path (DM_NVN_SUB_STREAM=0, frame capture) keeps main's locking. t_queue_lifetime's case runs when streaming is on and no longer checks the dropped function; the frame-rate.md entry says what streaming already did.
…ion lock, so the game's thread no longer waits for the queue replay of the one before Item C-4 asked whether the game's main thread (200-400 ms/s of CPU in the owner's slow windows, 2-4 ms of yields a frame) waits on the host. It does: a `sample` on the Mac (the owner's save, Temple of Time) has the main thread 16.5% in __psynch_mutexwait, 12.4% inside nvn_queue_submit -> pthread_mutex_lock. A submission copied its command lists (nq_flatten) under g_sub_mu, which the queue replay thread holds for the whole translation of each submission (nq_worker), so with 22-30 submissions a frame the game's thread waited for each one the replay had in hand; on an iPhone, with 11-24 ms of replay a frame in busy scenes, the frame was the main thread's work plus the replay's. The rest of the main thread's time is its own: guest code and its waits on the game's own workers (the yields; ModuleSystemWorker). The copy needed the lock only for the first submission's prepare step and for a program no replay had resolved (prog_get is the replay's), and the program pins it shared with the replay had no lock of their own. - nvn_queue_submit: no submission lock for the copy; the prepare step runs under it once (mtl_prepared). - nq_snapshot_object: a program the serial table holds is pinned and copied without it (mtl_prog_snapshot_live, own_prog_pin_live); only one not resolved yet takes the lock to be resolved, as before. - nvn_owner.m: the program pins have a lock of their own (g_pin_mu), taken before g_smu wherever both are held. Tests: check_t_queue_lifetime 43 x2 (a submission whose program is resolved returns while the lock is held, and draws; an unresolved program is left to the lock: new, fails before), t_gfx_suspend 20 (updated deliberately: both submissions now return while the prepare step holds the lock instead of the second waiting for it; nothing commits before the resume, as before), t_nvn 325, t_serial_owner 176, check_t_alias_takeover 48, test_docs. Docs: frame-rate.md "The game's submissions waited for the queue replay's lock", nvn-objects.md (the prepare-step entry's check), symptom index, game note. (cherry picked from commit f923323) Rebased onto main b633687, where submission streaming (5588e99, PR seedds#2996) already copies a streamed submission without the submission lock, pins its programs by serial without resolving them (mtl_prog_snapshot_pin) and gives the program pins their own lock (g_prog_pin_lk). What C-4 still changes: nvn_queue_submit no longer takes the lock at the start of a streamed submission once the prepare step is done (mtl_prepared), so the game's thread no longer waits there for the node the replay has in hand; mtl_sub_stream_on sets its switch up once (pthread_once), as its first read may now come without the lock. Dropped as superseded: mtl_prog_snapshot_live, own_prog_pin_live and g_pin_mu (nvn_owner.h and nvn_owner.m are main's). The whole-submission path (DM_NVN_SUB_STREAM=0, frame capture) keeps main's locking. t_queue_lifetime's case runs when streaming is on and no longer checks the dropped function; the frame-rate.md entry says what streaming already did.
Closes #2987. Extracts the submission streaming change from #2912 onto
0b5fd6020093.An NVN queue now accepts the submission before the game thread finishes copying it. At each wait or fence, the producer publishes the completed prefix under the queue mutex. A worker that drains that prefix keeps the open job at the head of its queue. It can service other ready queues until the producer publishes the suffix. Program snapshots pin the initialization serial and resolve on replay. Texture snapshots use the existing owner pins. Frame capture and
DM_NVN_SUB_STREAM=0retain whole-submission copying.Mario Kart World race on M3 Max
Mario Bros. Circuit, Mushroom Cup, v1.0. Both graphics modes ran on the same 36 GB Mac on AC power (macOS 27.0.1, Xcode 27.2). The host, game modules, and shader library were built against the stated revision (chain
03a3ac831bfb). All runs used the same starting save, direct race boot, no player input, and a shared private pipeline archive. A separate warm-up race filled the archive before timing.Uncapped, the same PR binary alternated streaming every 300 frames. Each mode ran twice with opposite starting states. For frames 1800–5399, the first 75 frames of each phase were discarded to let timing settle. Each row pools 2,700 frames over 12 phases. FPS is 1,000 divided by mean frame time. Lower frame and GPU times are better.
The streamed half had a lower median frame time in 9/12 matched docked phases and 11/12 handheld phases. Each match compares the same frame range across the two runs with the switch reversed.
Frame medians for matched 300-frame phases (ms)
Separate fixed-setting docked runs
In the first fixed docked pair, the PR improved median and p95 frame time, but its mean FPS fell from 76.79 to 75.50. Frame 2212 took 2,917.42 ms wall time. Its recorded GPU time was 15.09 ms and it created no new pipeline or shader library. The unmodified run’s longest frame was 166.39 ms. The cause of the long frame is unresolved. All frames are included in the fixed-run table.
The fixed comparison was repeated in reverse order after a separate archive warm-up. The longest frame was 20.25 ms on unmodified main and 34.67 ms with streaming. At the 60 fps target, the game selected a two-vsync step for 62/1,800 frames with streaming off and 0/1,800 with it on.
The fixed-setting runs use the full race window (3,600 uncapped frames or 1,800 capped frames). FPS in this table comes from elapsed wall time. Other desktop GPU activity was 10–22% before these runs. Desktop indexing also used CPU. Opposite phase orders reduce scene bias, but opponents and items can still vary between races.
Reproduction
DM_NVN_TSV. UseDM_OPMODE=1for docked orDM_OPMODE=0for handheld. For an uncapped run setDM_FPS_TARGET=0 DM_PRESENT_HZ=0 DM_PRESENT_LINK=0 DM_PRESENT_SCREEN=0 DM_VSYNC_HZ=240.DM_AB=300 DM_NVN_SUB_STREAM=ab, thenDM_AB=300 DM_NVN_SUB_STREAM=ab:0/2. The host logs each active phase asSUB_STREAMorbase. For capped runs, useDM_FPS_TARGET=60and fixedDM_NVN_SUB_STREAM=0/1with the normal presentation settings.Order, lifetime and regression checks
t_wait_eventcase pauses the producer while copying the command after a fence. The GPU completes the preceding copy while the producer is parked. A second submission on the same queue stays pending and reads the first job’s final value after the producer resumes.t_queue_lifetimeparks replay, finalizes and reuses the guest program and texture objects, then checks the rendered pixels. Together witht_wait_event,t_queue_origin,t_render_enable_queue,t_sub_overlap,t_serial_owner, andt_nvn_accel, it passed with streaming both enabled and disabled. The docs and switch checks passed.git nx qtest --all, repeated in keep-going mode to run the rest) had one failure at the OpenGLtest_lod_biaspixel assertion int_gl_imports.m:427on this M3 Max. Unmodified0b5fd602failed the same assertion with the same Metal validation settings. Every other test target completed successfully.scripts/regress.py check --games 0400C3F00006E000 --quickpassed on Mario Kart World, the available local Mac game build and the title from nvn: retest submission streaming in Mario Kart World #2987. Both revisions booted. All 11,559 shaders built on both sides, with no changed MSL, new interface failures, or new RED diagnostics. The harness marked the candidate boot as busy. The existing swizzled-texture CPU fallback also appeared in both race logs.