Repository navigation
Conversation
… background, not on the replay thread Symptom: single frames of 50-130 ms every few minutes while walking in a scene whose pipelines the archive holds but for one or two never drawn before (Ocarina of Time, Hall of Fallen Foes, M4 Max, 2560x1440: 6 in 40 minutes). The GPU is at 10 ms and the frame's own pipeline work is under 1 ms, but the submit thread's wall time is 50-117 ms against about 5 ms of CPU time. Cause: DM_HITCH_DUMP shows the guest's main thread waiting for g_sub_mu in nvn_queue_submit and the replay thread, which holds it, in draw -> pso_get -> pso_build_ex (or hybrid_get) -> arch_lookup -> newSpecializedFunction -> MTLCompilerScheduler::buildRequest. A draw whose pipeline is not built first asks for its base without compiling and then for its stand-in's, and both searched the archives on the replay thread. A search that finds nothing needs Metal's compiler scheduler to specialize the base's functions, behind the compile the background is running for the previous never-drawn pipeline: 17-40 ms with an idle compiler, up to 150 ms behind a compile. The windows' `found none` time matched the stalls. Fix: pso_build_ex takes compile 2, the base only if it is made (g_pbase): no archive search, no compile, nothing marked missing, no wait for another thread's lookup. A draw's first look for its pipeline's base and for its stand-in's uses it. The search of the others and the compile of what the archives lack are the background's, through hy_base_kick and pso_pend_demand as before. A draw of a shader with a pulling entry that has neither pipeline yet is skipped (pso_get returns nil, as it does for a slice-merged pass's pipeline not built yet) and asks again at its next use, for at most 250 ms a key; then it builds its pipeline as before. The pipelines line counts the skipped draws and the keys built after the 250 ms. All of this is off by default and DM_PSO_LOOKUP_BG=1 turns it on: a skipped draw that is not repeated (one into a target that is drawn once) stays missing until its target is drawn again, and that has not been compared against screenshots or tried on another game. A draw of a shader with no pulling entry still compiles on the replay thread when its base is not made: unchanged. Measured: the same walk and archive state, 6 stalls of 50-127 ms in two runs of 22 and 18 minutes before; none over 30 ms in 40 minutes with DM_PSO_LOOKUP_BG=1, outside the harness's own screenshots and the area load. The first opening of the pause menu, 23 pipelines never drawn before: 123 draws skipped, one frame of 215 ms from the 4 draws of shaders with no pulling entry. The skipped draws were not compared against screenshots, so a missing element on a first sight is possible, which is why it is off by default. Checked: new t_pso_first_sight (with DM_PSO_LOOKUP_BG=1, and --inline for the default) and cases 4 and 5 of t_pso_look_wait; t_pso_pending, t_pso_bg_look, t_pso_demand_record, t_pso_depth_stencil, t_pso_msaa, t_pso_warm, t_pso_race, t_pull, t_pull_inv and t_pend_index pass as on main; t_pso_stall fails on main too. The docs (test_docs.py) pass; test_env_switches.py fails as on main. M4 Max, macOS 27.3. Only Ocarina of Time was run; the iPhone was not. clang-tidy was not run (not installed here).
d26f23e to
ede3477
Compare
|
Thanks @adurham for the thorough diagnosis, stack traces, and measurements here. We're going to pass on this PR and close it rather than landing an opt-in draw-skipping path. Dropping draws for up to 250 ms risks visible pop-in and permanent missing content on targets that are only drawn once (such as cached shadows, lightmaps, UI atlases, or screen captures), and can also break depth-prepass pairing, occlusion queries, or shader writes. (Slice-merged passes are different because they split the pass and immediately draw in a normal pass rather than dropping the draw.) Because skipping draws isn't safe to make the default across games, we'd rather not carry it behind an environment switch. While reviewing the diff against the pipeline lookup, hybrid stand-in, prediction, and draw paths in What's still open: the underlying hitch you tracked down is real. A direction that avoids ever dropping draws would be to index the bundled pipeline archive ( |
What and why
Single frames of 50-130 ms every few minutes while walking in a scene whose pipelines the archive holds but for one or two never drawn before (Ocarina of Time, Hall of Fallen Foes, M4 Max, 2560x1440: 6 in 40 minutes). The GPU is at 10 ms and the frame's own pipeline work is under 1 ms, but the submit thread's wall time is 50-117 ms against about 5 ms of CPU time.
DM_HITCH_DUMP(with the host threads, #3131; the same stacks can be had fromsample) shows the guest's main thread waiting forg_sub_muinnvn_queue_submitand the replay thread, which holds it, indraw → pso_get → pso_build_ex(orhybrid_get)→ arch_lookup → newSpecializedFunction → MTLCompilerScheduler::buildRequest. A draw whose pipeline is not built asks for its base without compiling, then for its stand-in's, and both searched the archives on the replay thread. A search that finds nothing needs Metal's compiler scheduler to specialize the base's functions, behind the compile the background is running for the previous never-drawn pipeline: 17-40 ms idle, up to 150 ms behind a compile. The windows'found nonetime matched the stalls.g_pbase_missalready makes each missing base cost this once a process; this moves the one search off the replay thread, in the direction of PR #2677's background lookups for predictions.With
DM_PSO_LOOKUP_BG=1(off by default),pso_build_extakescompile2, the base only if it is made (g_pbase): no archive search, no compile, nothing marked missing, no wait for another thread's lookup. A draw's first look for its pipeline's base and its stand-in's uses it. The search of the others and the compile of what the archives lack are the background's, throughhy_base_kickandpso_pend_demandas before. A draw of a shader with a pulling entry that has neither pipeline yet is skipped (pso_getreturns nil, as it does for a slice-merged pass's pipeline not built yet) and asks again at its next use, for at most 250 ms a key; then it builds its pipeline as before. Thepipelines up to frameline counts the skipped draws and the keys built after the 250 ms. A draw of a shader with no pulling entry still compiles on the replay thread when its base is not made: unchanged.Why it is opt-in: a draw skipped for up to 250 ms on the first sight of a pipeline is a missing element where before it was a stall of 17-150 ms. "Asked again at its next use" only helps a draw that is repeated every frame; one into a target that is drawn once stays missing until the target is drawn again. I did not compare skipped draws against screenshots, and I ran one game on one Mac: the first opening of Ocarina of Time's pause menu (23 pipelines never drawn before) skipped 123 draws and had one 215 ms frame from the 4 draws of shaders with no pulling entry. Flipping the default is the follow-up, once that and a second game are checked.
Reference entry:
docs/reference/frame-rate.md, "A draw's first look for its pipeline's base searched the archives on the replay thread"; game note: Ocarina of Time, Frame rate.Checked
t_pso_first_sight(withDM_PSO_LOOKUP_BG=1, and--inlinefor the default) and cases 4 and 5 oft_pso_look_wait;t_pso_pending,t_pso_bg_look,t_pso_demand_record,t_pso_depth_stencil,t_pso_msaa,t_pso_warm,t_pso_race,t_pull,t_pull_inv,t_pend_indexpass as on main;t_pso_stallfails on main too.test_docs.pypasses;test_env_switches.pyfails as on main. clang-tidy was not run (not installed on the machine).DM_PSO_LOOKUP_BG=1, outside the harness's own screenshots and the area load.regress.py check --games: not run; only Ocarina of Time is installed on this machine. With the switch off, the one change to every game's path is thatpso_build_exreads acompilevalue of 2 as the known-only mode, which no existing caller passes.Front ends
Nothing a front end has to act on.
Docs
docs/reference/frame-rate.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)Written with AI: Claude (Hermes Agent) · Responsibility: Adam Durham