Metal's contract for a Managed buffer (MTLBuffer.h, didModifyRange:): a CPU write makes the range
undefined for the GPU until a didModifyRange: and a commit of the command buffer that reads it,
and it does not reach a command buffer committed before. The capture ring met that by copying
the bytes on the committing thread into 64 MiB of Shared staging, and the commit then waited for
the GPU whenever the ring was full. One recording on an RTX 3090 waited 258 times for 6.7 s
(m3-max-53409). The ring also kept a Managed buffer over an imported dma-buf, a block the runtime
does not map, refused (Refusal::ManagedBlockNotShared). On the XTX that refusal bound nil 2,804
times, and 28.8 million draws were then refused.
The planner ruled one form. The commit records the copy-in into a command buffer of its own:
vkCmdCopyBuffer of each named range from the consumer's block into the device copy, ahead of the
command buffer's commands in its submission, after the copies back owed to textures over the
ranges and before the copies into them. Vulkan's host write ordering guarantee makes the
consumer's writes made before the submission visible to the copies. The copy reads the bytes as
it runs, so a write after the commit may reach it, which Metal leaves undefined. The copy-in
holds each consumer's block and device copy until the command buffer retires.
What goes with the ring:
- capture.rs keeps the named ranges and the copy-in, and loses the ring, Chunk, Overflowed and
the staging blocks of its own;
- submit.rs loses the commits' turn (capture now records under the work lock), the streams of
ring-fulls, the waits and the ring's spans;
- the counters lose capture_waits, capture_streams, capture_overflows, capture_overflow_bytes,
capture_copy_nanos, capture_wait_nanos, Gauges::capture_bytes and the capture ring's site, and
managed_bytes_captured counts the bytes the copies take;
- the player's report and the API table lose the same fields.
A Managed buffer's bytes may be in any Shared block, mapped or not: contents is None over an
import. A Private block is refused as Refusal::ManagedBlockPrivate, since a Managed buffer has a
CPU-side copy ("the data pointer of this buffer's shared copy", MTLBuffer.h) and a Private block
has no pages the consumer can write. docs/REFUSALS.md is regenerated. The rt README's memory
contract says when the copy runs, and its known gap of the ring's waits goes.
Tests:
- the snapshot tests now hold the header's contract: write, didModifyRange:, commit, and that
command buffer reads the bytes, here also behind an event wait with the consumer's handles
gone before it runs. Nothing is asserted of a write under a pending command buffer;
- the ring's tests go;
- a range of three 16 MiB units arrives whole at one commit, with no staging and no allocation;
- a Managed buffer over an imported, unmapped dma-buf (Shared, contents None) reads what the
consumer wrote through its own mapping, on a two-copy card and on a unified one;
- a Managed buffer over a Private block is refused;
- the first named range allocates nothing at any site;
- the commit's lock-wait test marks the start of its count with a test-only flag, where it read
the turn.
Verified: see the check job named in the landing.