Files
metal2vulkan/docs
Anees Iqbal f2fc42a95d Show a command buffer's kernel start only with its end, waiting or not
`kernelStartTime` answered the host time the scheduler began submitting the first batch as soon
as it began, while `kernelEndTime` answered 0 until the last batch was submitted: a start without
an end for as long as the submission took, and for as long as a command buffer that waits for an
event after its first batch waited. Metal shows neither before both. A Swift probe on the M3 Max
under macOS 27.0.1 (a potluck job, committed nowhere) read each command buffer's pair, start
first, from its commit until it completed: 3,900 to 240,000 reads of each of six that waited for
nothing, and 4.6 to 4.7 million over 200 ms of each of eighteen that waited for an
`MTLSharedEvent` the host signalled or an `MTLEvent` another queue's command buffer signalled,
after a blit encoder, before one, or alone. None answered a start and no end. The waiting ones
answered both 0, `Committed`, until 50 to 160 us after the signal, then both; their start was
13 to 39 us after the commit, from before the wait.

`kernel_start_time` now reads `KernelTimes::shown_start`: 0 until the end is stored, the start
then (the end loaded first, acquire; the start is stored before the end on every path). The
scheduler's own reads (whether to begin, a recovery's window, the GPU times' life check) keep the
stored start, `KernelTimes::start`, so no scheduler file changes. Where the first command waits
for the event, the runtime's start is that batch's submission after the signal, where Metal's is
about the commit: recorded among docs/FAST-PATHS.md's known gaps.

The users of the old order move to Metal's semantics:
- rebind_reach's four held-buffer cases waited for `kernel_start_time() != 0` as the sign that
  the batch before the wait was submitted, which now never shows while it waits (they timed out
  at 60 s with 86701a2e00). They wait instead for the device's batches submitted to rise
  (`WorkCounts::batches_with_none_pending` and the three fields after it, which count a batch as
  it is submitted or held, at the place in `submit_batch` where the start was stored), through
  `property_reads::first_batch_submitted`; `walk`'s check that nothing was submitted before the
  event reads the same count.
- property_reads_wait_for_no_submission_and_no_busy_work counted a read inside the submission as
  one that answered a start and no end. A read inside is now one begun after the kernel start
  and returned before the kernel end, on their clock (`host_time`), judged once the end shows
  from the most recent 2^16 reads each thread keeps; and the test asserts that no read of either
  thread answered a start and then no end.
- New: property_reads' kernel_times_show_neither_while_their_command_buffer_waits_for_an_event,
  for both kinds of event: after the batch before the wait was submitted (the count), 50 ms of
  reads answer neither time and `Committed`; after the signal no read answers a start alone, and
  the start lies before the signal, the end after it.
- New: tests::gpu_time::a_kernel_start_shows_with_its_end_alone.

Tests: those above on MoltenVK (M3 Max, --cfg m2v_gpu) and lavapipe (--cfg m2v_cpu_icd); the
negative control is `kernel_start_time` reading the stored start again, under which both
property_reads tests and the unit test fail.

(cherry picked from commit 2ce15a20927a8f7a44c1bc7ee70869977a88d702)
2026-11-05 11:25:47 -08:00
..