What: scheduler/steps.rs had one thread per device record every host step of every queue, in
hand-over order. It now hands each step to a free thread of a pool, or starts one for it below
THREADS (8); past the cap a step waits for the first thread free, in hand-over order. The first
thread stays until the scheduler stops, as the one thread did; each later one ends after 2 s with
no step. All start at the user-interactive class, each step is still a section of the exit guard,
and where the host cannot start the first thread the scheduler's thread records the step itself,
as before.
Why: the consumer (one device for every guest process) saw WindowServer's present wait 13.6 s in
the host after the page's context had closed. A page's render-bundle ICB execution was recording
a seconds-long host step, and any command buffer whose draw or dispatch has a pipeline still
being made takes a host step too (deferred.rs: RenderPass with making(), Pending), which queued
behind the page's on the one thread. A dead context's step keeps recording, as its command buffer
holds what it uses.
Order is still the scheduler's: only a line's head is handed over, marked stepping until its step
ends, so a logical queue's steps are recorded one at a time in its order, and a head that waits
for an event value, or is behind an earlier commit's conflicting batch (order.rs), is not gated
or handed over (gate_heads takes `behind`).
Audit of what assumed one step at a time device-wide:
- kept chunks (kept_commands.rs): no host step uses them (render executions keep only when
!step, compute executions only when states.is_none());
- upload and descriptor arenas: per command buffer (State::uploads, State::descriptors); their
spares are the device's, under a lock; the command pool is per command buffer, recorded under
its `reencoding` turn, which host_step takes;
- pipeline making: the pool, the budget's turns and the making maps already serve concurrent
encoders; the in_host_step()-gated branches (Urgency::HostStep, keep_room skipped, kept
variants not taken back, takes_multi_variable_dynamic, make_at_creation skipped, sampler-set
count) read a thread-local, so they hold per thread; kept.rs StepNumbers is thread-local and
per command buffer, whose steps stay sequential, `made` handed on through end_step and the
scheduler's locks;
- residency: a command buffer's own value, its address index made per residency;
- the scheduler's wake and hand-over: record() marks the inbox under its lock and wakes, as a
committing thread does; begin_step/end_step are the command buffer's atomics; post pushes
under the steps' lock;
- the exit guard: sections are counted per thread and in atomics, HOST_STEPS is thread-local,
called() is atomic; many sections at once were already normal;
- interior mutability used by the steps thread alone: none besides the steps' own state (every
shared object is Sync and shared with committing threads already);
- notices: every-occurrence notices announced inside steps (each_in_order) of two queues may now
interleave; Metal orders nothing between such queues.
Docs: the scheduler's "Host steps" section, left.rs, WorkCounts' host-step counters, kept.rs,
RecordsRead::HostStep and FAST-PATHS.md's pipeline-wait row say steps' threads. The
host-replayed-indirect-commands notice already says only resources the execution may reach hold
later batches back, so it is unchanged.
Verified on the M3 Max (MoltenVK, --cfg m2v_gpu, maclock+memcap), with the next commit's lane
test runtime_lane::steps_apart::another_queue_goes_on_while_a_host_step_records: before, queue
B's own stepped command buffer did not complete within 10 s while queue A's step was held (A's
objects kept, and released); after, 18.6 / 18.9 ms in debug. Its ordered checks (a step after
an event A signals, and a pass into A's target) begin only after A's step ends, before and after.
Negative control: THREADS = 1 fails the test again (Stepped, kept and released); restored and
touched. Release, A a real 5000-draw step (2.7 to 5.0 s), B's stepped kind went from 3580 ms
(released: 3359) to p50 1.49 / max 15.6 ms (released: 1.65 / 40.4); idle 1.32 ms p50.
Runtime tests::(scheduler|inbox|host_step|waiter_submits|commit_and_submit|completion_order|
unsubmitted|pipeline_wait_order|blit_order): 50 passed. Lane cases (indirect, kept,
*executions, *host_steps, submi*, steps_apart, resident_draws, event_round_trips,
command_queues): 272 passed. clippy --workspace --all-targets --all-features -D warnings, plain
and with --cfg m2v_gpu: clean.
(cherry picked from commit e15fd6752fe4f714b73dab0ee72d15fce686f3d7)
(cherry picked from commit 229f407b2abe2de5b85bf3d98b2080d0a0667e9d)