Files
metal2vulkan/docs
Anees Iqbal ea8e7843b7 rt: scheduled handlers run on the submit thread, before their submission, and wake no thread
The consumer adds a scheduled handler to every command buffer. The submit thread handed each
command buffer's scheduled handlers to the completion thread (Done::scheduled), and where that
thread waited on the GPU the hand-over was a host vkSignalSemaphore of its wake timeline, on
every submission. On NVIDIA a host signal per submission measured 103-117 us of CPU a command
buffer on an RTX 3090 (the waits probe's rt arm, job 47928), against 2.9-3.5 us for every single
wait form, rt's own steady-state WAIT_ANY included.

Now the submit thread, which already marks a command buffer scheduled as it joins a submission,
runs its scheduled handlers itself once it has dropped its lock, in queue order, before that
submission goes to the driver and before any of those command buffers is handed on as ended.
So the status reads Scheduled and the kernel times are set in the handler, a command buffer that
ends before it joins a submission runs none, as before, and the scheduled handlers run before the
completed ones by construction. Done::scheduled, its list and the completion thread's branch for
it are deleted.

A handler on the submit thread may not call what waits for that thread to submit. The four
internal sites that do (Work::room, Work::capture, Work::stage and the readback's flush and
Done::wait) give the public entries that reach them; each is now Refusal::InScheduledHandler in a
scheduled handler, on every device and whatever the runtime holds: commit; wait_until_scheduled,
wait_until_completed and SharedEvent::wait_until_signaled_value; replace_region, upload_region,
get_bytes and zero_block_range; new_managed_buffer, and new_buffer zeroing a buffer in a Private
block. The one consumer's scheduled handler makes none of these calls, and a guest's
addScheduledHandler block runs in the guest. Quiesce in a scheduled handler answers false at once
(neither the submit thread nor the completion thread, which the submit thread stops as it ends,
is waited for), and a device whose last handle drops there tears down on the reaper, as from a
completed handler.

For a consumer: CommandBuffer::wait_until_scheduled and wait_until_completed now return
Result<(), Error>, and SharedEvent::wait_until_signaled_value returns Result<bool, Error>
(api_signatures.tsv blessed); docs/REFUSALS.md regenerated; the README's contract says where each
kind of handler runs, what a scheduled handler may do, and that it holds its queue's later
submissions while it runs.

Tests: every_device_tears_down_from_a_scheduled_handler,
every_device_answers_false_to_a_quiesce_in_a_scheduled_handler, and
every_device_refuses_each_call_that_waits_for_the_submit_thread_in_a_scheduled_handler (each
refused entry by name, the allowed calls, the status and kernel times in the handler, and the same
calls answering once it has returned). Verified by the next jobs.
2026-11-18 13:36:21 -08:00
..