Repository navigation
The main submission may keep 32 command allocators in flight, not 8 (from HookLink) - #2090
oliverames wants to merge 2 commits into
Conversation
…fers in flight, not 8: Ocarina of Time's Hyrule Field submits about 20 small batches a frame, and at 8 the submit thread blocked on the oldest about 17 times a frame, 20-25 ms, with the GPU idle for about half of its span. DM_NVN_ALLOC_CAP=8 restores the old cap to compare. Not yet measured on the phone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 9cf41e4)
With the cap at 8 all the allocators were in flight from the first real-time scene after the opening movie and the submit thread had waited on the GPU 17,598 times by the end of an 18-minute run. With HookLink's cap of 32 the same opening used up to 17 allocators and waited 0 times. The forest on one route is not measured. Co-authored-by: dsi-hub <260802842+dsi-hub@users.noreply.github.com>
…keep 32 command allocators in flight, not 8 (from HookLink) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ion takes a visibility buffer only when it counts samples: the pool of 8 no longer runs dry in a game that makes many small submissions a frame (PR #2090) Each main submission took a command allocator of its own from a pool of 8 and a visibility buffer from a ring of 8, and kept both until the GPU had completed it. Since the queue replays a guest submission in pieces, a frame can hold more submissions than the pool: Ocarina of Time makes 28-37 a frame, and with all 8 in flight the submit thread waited for the GPU at the start of the next (17,598 waits in an 18-minute run on an iPhone Duo, about 17 a frame on an iPhone 18 Pro Max, reported in PR #2090; none on an M4 Pro). Metal lets an allocator serve command buffers one after another and asks only that all of them are complete before its reset (MTL4CommandBuffer.h), which the allocator's fence, the last one's, already says; segments of one submission shared one before. So a frame's submissions share one, and the pool holds an allocator per frame in flight. One serves at most 64 submissions, which bounds its memory while no frame ends. A visibility buffer is taken by a submission's first pass that counts samples; with the ring in flight such a pass takes a buffer of its own and does not wait. The pool stays at 8. PR #2090 raised it to 32, which removes the waits at the cost of the command memory of every allocator kept in flight (0.4-0.7 GB on Ocarina of Time by dpadr's measurement in issue #2112). Checked: t_wait_event 103 checks in both encoder modes with Metal validation, with a new case (24 submissions in one frame with the GPU held all encode, none waits, they share an allocator, none takes a visibility buffer); the graphics test list (make run), t_rt_range, t_render_counter_overlap, t_queue_lifetime, t_render_enable_queue, t_nvn, t_capture and test_docs pass; the Mac host builds. No game ran: no local game with a route has shader libraries for chain cb2e91c138e3. Open: a run on a game with occlusion queries, Ocarina of Time's wait count and footprint, and an iPhone run.
|
Thank you for bringing this over and for the Duo numbers. The waits are real, but I landed a different fix for them, fd8188c on main, so I am closing this one. Why not the cap: each allocator kept in flight holds its command memory. In #2112 dpadr measured 31-34 allocators in flight and +0.4 to 0.7 GB on Ocarina of Time with a higher cap, and the phone is where memory is tightest. What landed instead:
It passes the graphics tests, including a case of 24 submissions in one frame with the GPU held, but it has not been run on a game or on a phone. If you can retest on fd8188c on the Duo, the useful numbers are the |
…ion takes a visibility buffer only when it counts samples: the pool of 8 no longer runs dry in a game that makes many small submissions a frame (PR seedds#2090) Each main submission took a command allocator of its own from a pool of 8 and a visibility buffer from a ring of 8, and kept both until the GPU had completed it. Since the queue replays a guest submission in pieces, a frame can hold more submissions than the pool: Ocarina of Time makes 28-37 a frame, and with all 8 in flight the submit thread waited for the GPU at the start of the next (17,598 waits in an 18-minute run on an iPhone Duo, about 17 a frame on an iPhone 18 Pro Max, reported in PR seedds#2090; none on an M4 Pro). Metal lets an allocator serve command buffers one after another and asks only that all of them are complete before its reset (MTL4CommandBuffer.h), which the allocator's fence, the last one's, already says; segments of one submission shared one before. So a frame's submissions share one, and the pool holds an allocator per frame in flight. One serves at most 64 submissions, which bounds its memory while no frame ends. A visibility buffer is taken by a submission's first pass that counts samples; with the ring in flight such a pass takes a buffer of its own and does not wait. The pool stays at 8. PR seedds#2090 raised it to 32, which removes the waits at the cost of the command memory of every allocator kept in flight (0.4-0.7 GB on Ocarina of Time by dpadr's measurement in issue seedds#2112). Checked: t_wait_event 103 checks in both encoder modes with Metal validation, with a new case (24 submissions in one frame with the GPU held all encode, none waits, they share an allocator, none takes a visibility buffer); the graphics test list (make run), t_rt_range, t_render_counter_overlap, t_queue_lifetime, t_render_enable_queue, t_nvn, t_capture and test_docs pass; the Mac host builds. No game ran: no local game with a route has shader libraries for chain cb2e91c138e3. Open: a run on a game with occlusion queries, Ocarina of Time's wait count and footprint, and an iPhone run. (cherry picked from commit fd8188c) In this branch: of the two cases main's t_wait_event.m had gained by then, frame_shares_allocator (this commit's) is taken and event_signal_no_cut is not. That one came with main's 25c2546, its own version of PR seedds#2116, and this branch still carries the pull request's: one of its checks fails here (a wait on the first of two signals is encoded behind the in-flight submission). It comes with 25c2546 at the next update on main. Ocarina of Time on an M5, the scripted walk through Castle Town: see the commit that follows.
… bound is the idle sweep's 600 submissions, the Memory setting no longer moves the hold's bound, and the guard's routine eviction waits as the sweep does Found reviewing the two commits before this one, before either was built: - The hold over its bound was 240 submissions. Ocarina of Time makes 28-37 submissions a frame (PR seedds#2090's measurement; g_fence counts them), so 240 is 7-8 frames, the time the dynamic resolution holds a level before it moves: a layout the game comes back to would still have been let go. The hold over its bound is now 600 submissions, the idle sweep's own wait (16-21 frames), so a takeover is never stricter than the sweep. - The Memory setting moved the hold's bound (half of the planned working set) and the guard's eviction level. With Memory at 16 GB the bound was 6,062 MB and the eviction level 9,699 MB; with 12 GB, 4,547 and 7,274 MB. Ocarina of Time at full screen allocates 7-9 GB, so it would have sat over the bound for good and, at 12 GB, in the guard's eviction, which let go of every unheld sharing entry idle for 16 submissions every 30 frames: the regime that remade its render targets every frame. The hold's bound is the device's again. The guard's routine eviction (its eviction level) lets go of entries idle for 600 submissions; its emergency one (the stop level, guard_evict(1), which t_res_guard checks) still lets go of all that is idle for ALIAS_IDLE. Checked: the Mac host builds (0 errors); test_settings, test_launcher_settings, test_game_profile pass; test_env_switches fails as before this branch's work, on switches of pull requests it carries, not on DM_MEMORY_GB or DM_NVN_IND_SPLIT. Not run in the game yet: the player was playing. To do: the walk from the fixed save, the app at full screen with DM_NVN_ALIAS_KEEP_MB=6000 (over the bound from the start) and with DM_MEMORY_GB=12 and 16, and tests for both paths (t_res_guard with DM_MEMORY_GB, t_alias_takeover with a compressible entry over the bound). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014eD437mxrMnW2UwLZhpwc7
…ion takes a visibility buffer only when it counts samples: the pool of 8 no longer runs dry in a game that makes many small submissions a frame (PR seedds#2090) Each main submission took a command allocator of its own from a pool of 8 and a visibility buffer from a ring of 8, and kept both until the GPU had completed it. Since the queue replays a guest submission in pieces, a frame can hold more submissions than the pool: Ocarina of Time makes 28-37 a frame, and with all 8 in flight the submit thread waited for the GPU at the start of the next (17,598 waits in an 18-minute run on an iPhone Duo, about 17 a frame on an iPhone 18 Pro Max, reported in PR seedds#2090; none on an M4 Pro). Metal lets an allocator serve command buffers one after another and asks only that all of them are complete before its reset (MTL4CommandBuffer.h), which the allocator's fence, the last one's, already says; segments of one submission shared one before. So a frame's submissions share one, and the pool holds an allocator per frame in flight. One serves at most 64 submissions, which bounds its memory while no frame ends. A visibility buffer is taken by a submission's first pass that counts samples; with the ring in flight such a pass takes a buffer of its own and does not wait. The pool stays at 8. PR seedds#2090 raised it to 32, which removes the waits at the cost of the command memory of every allocator kept in flight (0.4-0.7 GB on Ocarina of Time by dpadr's measurement in issue seedds#2112). Checked: t_wait_event 103 checks in both encoder modes with Metal validation, with a new case (24 submissions in one frame with the GPU held all encode, none waits, they share an allocator, none takes a visibility buffer); the graphics test list (make run), t_rt_range, t_render_counter_overlap, t_queue_lifetime, t_render_enable_queue, t_nvn, t_capture and test_docs pass; the Mac host builds. No game ran: no local game with a route has shader libraries for chain cb2e91c138e3. Open: a run on a game with occlusion queries, Ocarina of Time's wait count and footprint, and an iPhone run. (cherry picked from commit fd8188c)
…cator pool lets stand in flight (PR #2469) Since the submissions of one frame share a command allocator (PR #2090), mtl_sub_begin lets ALLOC_MAX * ALLOC_SHARE = 512 submissions stand uncompleted before it waits, while POST_RING still held 128 records, sized for one allocator per submission. Super Mario Party (010036B0034E4000), at 70-80 submissions a frame, committed fence N + 128 while N's feedback had not come yet and aborted with "post ring: the writes of fence N never ran" (two logs: 166777 / 166649, 442682 / 442554). POST_RING is now ALLOC_MAX * ALLOC_SHARE: a slot is reused only after the allocator wait has seen its previous submission complete, and post_complete runs every record up to a fence before it raises g_done, so the abort stays as the check of that invariant. Checked: make -C dm/gfx/tests GAME=010015100B514000 perf-order-cpu perf-order-tsan (195 checks), t_perf_order on Metal (36 checks); test_docs, test_pr_areas; host build. Not run: Super Mario Party (provisional profile; reporter retest), regress.py (constant change off the hot path). Co-authored-by: LNP <90243050+LNPANDY@users.noreply.github.com>
…light, so a counting submission no longer makes and drops one of its own Since a frame's submissions share a command allocator (PR #2090), more counting submissions are in flight than the ring's 8 (VIS_RING = ALLOC_MAX). With the GPU behind, each one made a 64 KiB visibility buffer, added it to the residency set and removed it after the submission: two residency commits through the kernel's GPU driver each. Ocarina of Time on an iPhone 17 went from 8-12 to 25-30 fps in Kakariko Village and Hyrule Field with the ring grown (PR #2536). The ring is sized from the bound mtl_sub_begin already keeps, SUB_FLIGHT_MAX = ALLOC_MAX * ALLOC_SHARE (512), which POST_RING now shares, so it never runs dry; it still grows on demand, only to the most counting submissions in flight at once. vis_in_ring checks this submission's ring buffer in O(1) instead of scanning the ring. t_wait_event gets a case with 24 counting submissions in flight. Fixes #2535 Co-authored-by: Stan Bono <3304418+stan69b@users.noreply.github.com>
…ion takes a visibility buffer only when it counts samples: the pool of 8 no longer runs dry in a game that makes many small submissions a frame (PR seedds#2090) Each main submission took a command allocator of its own from a pool of 8 and a visibility buffer from a ring of 8, and kept both until the GPU had completed it. Since the queue replays a guest submission in pieces, a frame can hold more submissions than the pool: Ocarina of Time makes 28-37 a frame, and with all 8 in flight the submit thread waited for the GPU at the start of the next (17,598 waits in an 18-minute run on an iPhone Duo, about 17 a frame on an iPhone 18 Pro Max, reported in PR seedds#2090; none on an M4 Pro). Metal lets an allocator serve command buffers one after another and asks only that all of them are complete before its reset (MTL4CommandBuffer.h), which the allocator's fence, the last one's, already says; segments of one submission shared one before. So a frame's submissions share one, and the pool holds an allocator per frame in flight. One serves at most 64 submissions, which bounds its memory while no frame ends. A visibility buffer is taken by a submission's first pass that counts samples; with the ring in flight such a pass takes a buffer of its own and does not wait. The pool stays at 8. PR seedds#2090 raised it to 32, which removes the waits at the cost of the command memory of every allocator kept in flight (0.4-0.7 GB on Ocarina of Time by dpadr's measurement in issue seedds#2112). Checked: t_wait_event 103 checks in both encoder modes with Metal validation, with a new case (24 submissions in one frame with the GPU held all encode, none waits, they share an allocator, none takes a visibility buffer); the graphics test list (make run), t_rt_range, t_render_counter_overlap, t_queue_lifetime, t_render_enable_queue, t_nvn, t_capture and test_docs pass; the Mac host builds. No game ran: no local game with a route has shader libraries for chain cb2e91c138e3. Open: a run on a game with occlusion queries, Ocarina of Time's wait count and footprint, and an iPhone run. (cherry picked from commit fd8188c)
…cator pool lets stand in flight (PR seedds#2469) Since the submissions of one frame share a command allocator (PR seedds#2090), mtl_sub_begin lets ALLOC_MAX * ALLOC_SHARE = 512 submissions stand uncompleted before it waits, while POST_RING still held 128 records, sized for one allocator per submission. Super Mario Party (010036B0034E4000), at 70-80 submissions a frame, committed fence N + 128 while N's feedback had not come yet and aborted with "post ring: the writes of fence N never ran" (two logs: 166777 / 166649, 442682 / 442554). POST_RING is now ALLOC_MAX * ALLOC_SHARE: a slot is reused only after the allocator wait has seen its previous submission complete, and post_complete runs every record up to a fence before it raises g_done, so the abort stays as the check of that invariant. Checked: make -C dm/gfx/tests GAME=010015100B514000 perf-order-cpu perf-order-tsan (195 checks), t_perf_order on Metal (36 checks); test_docs, test_pr_areas; host build. Not run: Super Mario Party (provisional profile; reporter retest), regress.py (constant change off the hot path). Co-authored-by: LNP <90243050+LNPANDY@users.noreply.github.com> (cherry picked from commit 6e1f506)
…light, so a counting submission no longer makes and drops one of its own Since a frame's submissions share a command allocator (PR seedds#2090), more counting submissions are in flight than the ring's 8 (VIS_RING = ALLOC_MAX). With the GPU behind, each one made a 64 KiB visibility buffer, added it to the residency set and removed it after the submission: two residency commits through the kernel's GPU driver each. Ocarina of Time on an iPhone 17 went from 8-12 to 25-30 fps in Kakariko Village and Hyrule Field with the ring grown (PR seedds#2536). The ring is sized from the bound mtl_sub_begin already keeps, SUB_FLIGHT_MAX = ALLOC_MAX * ALLOC_SHARE (512), which POST_RING now shares, so it never runs dry; it still grows on demand, only to the most counting submissions in flight at once. vis_in_ring checks this submission's ring buffer in O(1) instead of scanning the ring. t_wait_event gets a case with 24 counting submissions in flight. Fixes seedds#2535 Co-authored-by: Stan Bono <3304418+stan69b@users.noreply.github.com> (cherry picked from commit b515089)
…go on in the block the one before it ended in Since the submissions of a frame share a command allocator (PR seedds#2090), the submit thread no longer waits for one of 8 allocators and up to POST_RING submissions can be in flight. Each took 4 MB arena blocks of its own and kept them for good, so the number of blocks followed the submissions in flight, not the bytes they wrote. kencalx's NX18 fork saw NieR:Automata make 26-28 blocks from about 105 s on (8 before the merge) and hold 100-150 MB more graphics memory. Releasing idle blocks alone gave nothing back: the blocks were in use. - arena_commit / arena_begin: the next submission continues in the block the last one ended in while it has room. The block's fence becomes the later submission's, so it is reused only when every submission that wrote it has completed. DM_NVN_ARENA_SHARE=0 restores a block per submission. - arena_new takes the smallest block that fits and, of those, the one used last, so blocks a peak made stay unused. arena_trim releases those above 4 (ARENA_KEEP_BLOCKS) once no submission used them for 600 submissions (ARENA_IDLE), never one whose fence is above g_done or one a submission is writing. DM_NVN_ARENA_TRIM=0 keeps them. The memory line gives the blocks alive and released. - encode_args_'s patch path read g_cur_arena->gpu after cbuf_slot and cbsize_table, which can move g_cur_arena to a new block: the copy was then bound at the new block and the old offset. Rare with a block per submission; NX18 saw it hang the GPU 1-4 times in 160 s once blocks were shared. The address is now read when the block is taken. - t_arena_trim (a Mac test): growth with the GPU held, idle release, shared blocks and the patched block whose size table goes to a new block. Ported from NX18 commit 63c4e8d64 (kencalx/NX18@63c4e8d) without its memory-trim half, which depends on NX18's memory trim that this tree does not have. NX18's numbers are theirs, not measured here. Checked on a Mac (M2 Pro, macOS 27.3, Xcode 27.3 beta, GAME=0400486024DEC000): the dmhost build, and check_t_arena_trim passes in all four of its runs (17, 17, 14 and 17 checks). Not checked: a game, a device, or the memory figures above, which are NX18's. Co-authored-by: kencalx <105067885+kencalx@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcRaRTbNVNsBJcfGqFidW1
What and why
This brings HookLink's allocator cap upstream. The change is dsi-hub's commit as it stands (cherry-picked, their authorship kept), plus a line in the game note with what I measured on an iPhone Duo.
The main submission could keep 8 command allocators and visibility buffers in flight. Ocarina of Time's Hyrule Field submits about 20 small batches a frame, and HookLink's iPhone 18 Pro Max blocked on the oldest allocator about 17 times a frame while the GPU sat idle for half of it. The cap becomes 32, and
DM_NVN_ALLOC_CAPlowers it again for comparison.I saw the same thing on my Duo with the cap at 8. Through the opening movie the game used 5 allocators and never waited. From the first real-time scene after it (frame 9,900) all 8 were in flight, and by the end of an 18-minute run the submit thread had waited on the GPU 17,598 times. With the cap at 32, the same opening used up to 17 allocators and waited 0 times.
Checked
test_env_switches.pyandtest_docs.pypass. There's no unit test for the cap itself.Docs
docs/reference/<subsystem>.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)dmsh_chain.py --headerwas run anddm/gfx/nvn/dmsh_chain.his part of the change (no chain tool changed)