A runtime extension. CommandBuffer::commit_and_submit commits as commit
does, with the same checks and refusals. Then, where no submission pass is
under way, the calling thread becomes the passer (Scheduler::
submit_at_commit, Inbox::pass_once_then). It takes in the inbox and submits
the ready heads committed first, in commit order, up to PASS_SUBMISSIONS,
while each needs no host step, no submission check, no group, no storage-
form switch and no rebind (plain_ready with Passer::Committing:
submits_without_the_program's handler exclusion dropped, the rest kept).
Still counted as the passer and outside the state lock, it runs their
submission handlers, then lets go of what the pass held; a last reference
goes through let_go_elsewhere. It then counts out, wakes the scheduler's
thread where it left work or a commit was handed to it meanwhile, and makes
an owed completion turn. The commit is posted with no mark and no wake
(Inbox::post_quietly, Hand::Pass), so the scheduler's thread is not woken
for work the committer takes. A plain transition to Scheduled runs inline
as its batch is published; one with scheduled or submission handlers goes
to its queue's context as before. Called from the runtime's own threads (a
handler on the scheduler's thread or a waiter) it commits as commit does.
Plain commit is unchanged: Metal's commit returns before scheduling.
Submission handlers keep submission order whichever thread runs them.
Each pass that takes batches with submission handlers takes a ticket
under the scheduler's lock, in pass order (State::handler_ticket), and
runs them once every earlier ticket's ran (Turns). This departs from
the design's "handlers then count out": the scheduler's own pass counts
out before running its handlers, so a counted committer alone cannot
keep them in order. The new order test showed it: without the turns its
handlers ran out of commit order in 4 runs of 4.
Counted: WorkCounts::scheduler_passes_at_commit,
batches_submitted_at_commit (the conformance cost's scheduler_ and
batches_ prefixes already cover them). Docs: the method, the scheduler
and inbox module docs, add_submission_handler's thread bullet, the
runtime README's extensions, RUNTIME-PORTING, and FAST-PATHS's "commit
returns at once". api_signatures blessed (3 added); REFUSALS regenerated,
unchanged.
Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu:
- tests::commit_and_submit, 6 runs:
- the submission handler ran on the caller inside the call, reading
Committed, 40 of 40, with the scheduled handler on a handler thread;
- 1000 command buffers from 2 threads alternating commit and
commit_and_submit: handlers in commit order, 362 to 449 of them on a
committing thread;
- a checked head and the one behind it were left to the scheduler's
thread, with 0 batches at commit.
- Negative control: Turns::wait made to return at once failed the order
test 4 of 4 (e.g. 238, 239, 240, 255, 256, 241).
- The runtime suite: 1512 passed.
- clippy -D warnings with and without --cfg m2v_gpu, and rustdoc
-D warnings, clean.
RUNTIME_VERSION and the runtime-sources pin follow at hand-over, on the
lane tip.
(cherry picked from commit 5909e96c63004822e2a22d4cbf27b998f90e75a8)
(cherry picked from commit 40a67ba10398c38f13494fcdf3f64c2925f7eba8)
(cherry picked from commit 4270a52b85cfcd8c5a3cd8ea201b1a731a261eac)