A batch whose host step records indirect commands the GPU may write waited, once otherwise
ready, until every VkQueue completed what was submitted to it by then. A frame of a GPU-culling
renderer (a kernel encodes the draws and their execution range, then several render passes
execute them through the range) paid one GPU round trip per pass: each pass's step waited for
the passes before it in its command buffer, and for other queues' unrelated work, though it
reads only the records and the range the culling wrote. The range read made it worse: it was
read from a copy recorded right before the execution, in the batch of the previous pass.
Now the gate is taken from the hazard state where it can be (scheduler gate_of):
- CommandBufferShared::step_reads names what a batch's host step reads on the host of what the
GPU may write, where each segment whose step waits for the GPU is an execution (outside a block
of command predication) or a render pass of executions whose uses commit bounded: their
records and ranges (Deferred::host_reads, ExecutionRange::host_reads), with their host
aliases. Anything else (an indirect dispatch, a loop's check, a staged gather, an indirect
sparse update) answers None.
- Tracker::last_writes answers, per VkQueue, the value of the last batch that wrote those bytes
of the writes the state holds; None for an untracked resource. The state forgets only what
completed, and a write that let an older entry go waited for it, so once each queue reached its
value every GPU write to those bytes completed and reached the host (every batch ends with the
barrier to the host). Every such writer is submitted by the time the gate is taken: earlier
batches of the line went first, an earlier commit's conflicting batch on another line holds the
head behind it (its footprint holds the step's reads), a later one waits behind it.
- Where either answers None the gate is every queue's last submission, as before.
- The range of executeCommandsInBuffer:indirectBuffer: is read in place where the host maps the
bytes the GPU writes (Buffer::maps_gpu_bytes: not Private, not a Managed host copy on a
discrete device, not a copied host buffer), through Buffer::read_mapped, which holds a no-copy
buffer's pages while it reads 8 bytes so a detach and rebind meanwhile free none of them; a
detached buffer runs nothing. The read is noted at the call as a command that reads the bytes
(no GPU work), so the encoder's order, a detach and the hazard state see it as they saw the
copy's. Other buffers keep the copy.
- WorkCounts::host_step_gates_narrowed counts gates that left out work submitted before them;
the conformance cost tables report it and never gate it (QUEUE_DEPTH: whether a gate falls
below a queue's last submission depends on whether the host had seen the writer complete).
- The HostReplayedIndirectCommands notice's cost, its catalogue entry in docs/API.md, the
scheduler's and indirect_execute's module docs and the execution calls' docs say so.
Tests: tracker a_host_read_waits_for_the_last_writes_of_its_bytes_alone (the writer per queue, no
writer, a covering write on another queue, untracked, a queue past the count, retired). Lane
depth_executions a_frame_s_executions_wait_for_the_culling_alone: a culling command buffer on one
queue, a fill on another queue submitted before the frame, then a frame of two passes that
execute the commands through the range: two host steps, both gates narrowed, both targets hold
each kept chunk's depth. The existing depth_executions test now shares its workload.
No Metal-visible behaviour changes: what the steps read and record is the same; they start
earlier.