A host step waits for the batches that wrote what it reads, not every queue's work
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.
This commit is contained in:
1 parent
5c3d492b4d
commit
2724757bbf
16 files changed
+545
-150
No files matched your search
+9
-7
@@ -2335,12 +2335,14 @@ bound.
|
||||
may name past four pass 256 (the states: every live one made with `supportIndirectCommandBuffers`,
|
||||
or the encoder's where the buffer inherits it), where they run with one and its commands times the
|
||||
states past twelve pass 512, and where its commands times its states pass 32,768. Every other
|
||||
execution runs on the GPU alone and announces nothing. Cost: one GPU-to-CPU round trip per
|
||||
execution: its command buffer's work before it, and every batch submitted before that on any
|
||||
queue, completes before the CPU records its commands from their records, on a thread of the
|
||||
runtime's, and submits the rest; meanwhile the device's other batches go, but for a later one
|
||||
that shares a resource the execution may reach (one made resident, the records), and the first
|
||||
command of a threadgroup size or threadgroup lengths its pipeline state has not dispatched makes
|
||||
execution runs on the GPU alone and announces nothing. Cost: a GPU-to-CPU round trip: the
|
||||
batches that last wrote its records and its range complete before the CPU records its commands
|
||||
from their records, on a thread of the runtime's, and submits the rest, so a command buffer's
|
||||
executions behind one writer wait for it once (where Metal tracks neither, or the step reads
|
||||
more, as inside a block of command predication: its command buffer's work before it, and every
|
||||
batch submitted before that on any queue); meanwhile the device's other batches go, but for a
|
||||
later one that shares a resource the execution may reach (one made resident, the records), and
|
||||
the first command of a threadgroup size or threadgroup lengths its pipeline state has not dispatched makes
|
||||
that VkPipeline then, as does a render command's draw of a state the CPU set on none of the
|
||||
commands. The commands run in the large-buffer form (their range-limited buffer slots at device
|
||||
addresses, with in-shader bounds checks), whose variants the commit compiles for every pipeline
|
||||
@@ -4876,7 +4878,7 @@ each item named states the rule in full.
|
||||
as `commit` records them, and `commit` returns what a command refuses; but for a buffer the
|
||||
command buffer made resident for writing, as a route met after the commit may still write the
|
||||
records before they run (another queue's command buffer the work waits for through an event,
|
||||
whose writes Metal runs), the host step records them once the work before it completed, and the
|
||||
whose writes Metal runs), the host step records them once the work that wrote them completed, and the
|
||||
command buffer fails at that batch's submission only where they are still refused
|
||||
(`WorkCounts::commit_refusals_held`).
|
||||
- **A render execution's range read from a buffer is read before its pass**
|
||||
|
||||
Reference in new issue
Block a user