Files
metal2vulkan/crates
Anees Iqbal 1cfa70ee32 RUNTIME 2429: Scheduler: run each pass's submission handlers right after that pass, not at the round's end
What: the scheduler thread's round made a pass, then kept passing while commits kept arriving
(Inbox::look_again), and only after the last of those passes ran the after-work: storage-form
settles, the owed completion turn, the submission handlers in their Turns tickets, and the holds.
Now Inbox::pass_each runs each pass's after-work once that pass let go of the lock and counted
out, before the look that may pass again (round() -> let_go per pass). Inbox::pass,
which only the tests called, is gone; they go through pass_each by a test-only trait.

Why: a command buffer's transition to Scheduled waits for its submission handlers
(run_scheduled, while state.submitting), and its queue's context line waits behind that
transition, so the completion of the queue's earlier command buffer was posted that much late.
reims's exacttail trace (780M, RADV, Exact, ca6259f7d1) saw the scheduler on CPU for 1.2-6.3 ms
of back-to-back passes (240-267 us per submit info), up to 22 ms on a first open, with the
handlers waiting for all of it. The scheduler and Inbox docs already said the handlers run right
after their pass; the code did not.

Also: commit_and_submit's own pass now counts why it left its command buffer to the scheduler
thread (WorkCounts::scheduler_at_commit_left_*). Two of the counts are for when it made no pass:
the commit was already taken in, or a pass was under way. The rest are for a pass that ran and
submitted nothing, by why its command buffer's first batch stayed in the order: gone, behind its
own queue, behind another queue, an event wait, checks, a host step, a binary wait, an unshared
hold, or other. reims's counts show the 780M making ~7.5k at-commit passes a window that submit
almost nothing. Which condition leaves those batches is open; these counts are meant to answer it
in the next walk. The predicates plain/plain_ready now answer why (LeftAtCommit) instead of a
bool.

Checks: tests::submission_turns holds the scheduler's pass in a submission (Point::FirstWork)
while another queue commits. The first command buffer's submission handler must run before the
later commit's submission is called (its kernel_end_time). Under the old round, the handler ran
after it. The test runs under CompletionPolicy::Exact and ::Grouped. tests::inbox has a unit test
of pass_each's order (pass, after, pass, after) that also shows the thread is uncounted during
its after-work.

The second caller of Scheduler::submit_at_commit (a commit_and_submit whose last render
encoder's end the lowering thread lowered) names its command buffer too.

Verified (complat): msi m3-max-35593 build 0, clippy -p metal2vulkan-runtime --all-targets
--all-features -D warnings 0, unit nextest (inbox|scheduler|left::|work_counts|completion)
44/44, api-signatures --check 0. The device check and its negative control run on lavapipe
(35596/35597) after landing.
2026-11-16 00:27:19 -08:00
..