Files
metal2vulkan/docs
Anees Iqbal 9be118cb5b rt: a take answers its zero mark, and the consumer asks for a Private range's zeros
The zero mark (BlockInfo::zeroed): how many of a block's first bytes the runtime itself zeroed
and nothing held since, as the take found them. They read zero; bytes outside the mark are the
consumer's to zero where Metal owes zeros. Nothing is inferred from the driver, the memory type
or a fresh allocation: the runtime zeroes from the front only, on the block-maker thread.

- Each Shared allocation made ahead of need is zeroed whole before it joins the pool (each
  device's first in its making), and its bytes are the allocation's clean ranges; a block carved
  there takes the clean run at its offset as its mark.
- A Shared block given back is zeroed again from its first byte, in steps of 256 KiB, while it
  is kept; a take of it between two steps waits at most for the step that runs (the thread
  starts none while a take waits) and gets the mark as it stands. A kept block's zeroed bytes
  given back to its allocation stay clean. A block given back has mark 0 until then: the
  consumer may have written any byte.
- Device::new_buffer zeroes only a Shared buffer's bytes past the block's mark, and every
  placement lowers the mark to its offset (new_managed_buffer's bytes too).
- Private blocks carry no mark. Device::zero_block_range(block, offset, length) zeroes a range
  of one the consumer holds by a GPU fill on the upload path new_buffer's Private zeroing uses,
  ahead of every later commit; it never waits and is never done at a take. Refusal::
  ZeroRangePastBlock and Refusal::ZeroRangeShared (REFUSALS.md regenerated).
- Metrics: allocations_zeroed, allocation_zeroing_nanos, kept_bytes_zeroed, kept_zeroing_nanos,
  zeroed_bytes_taken, zeroed_bytes_freed (zeroed bytes an idle free gave back before any take),
  block_zero_fills, block_zero_fill_bytes; the replay player keys them; api_signatures blessed.
- README: the consumer contract and the zeroing of kept blocks under the consumer's mappings.

Tests: Ranges' run_at and cut; a Shared block of the made-ahead allocation is marked and reads
zero whole; written, given back and kept, a take after three steps answers three steps' bytes,
zero, the rest as written; a zeroed buffer then zeroes only past the mark and lowers it; given
back again it is zeroed to its end. A Private block written by a kernel, kept and taken again,
zero-filled over its first half, reads zero there to the next command buffer's kernel and the
kernel's words past it; the refusals and NoSuchBlock. The three tests that check kept Shared
bytes stay as written hold the zeroing.

Verification: the check job and device legs run on this commit.
2026-11-18 09:49:56 -08:00
..