Over host pages whose consumer logs every write, a pass replacing every texel takes the gated
merge, stored in whole 256-byte blocks; a loading, storing pass's attachment merges in whole
blocks of its area's rows; a kernel's and a blit's partial writes stay word by word, and
docs/FAST-PATHS.md says why.
One work packet, landed as 6 commits on archive/development-linear-2026-10-29, in order:
* Merge back a pass replacing every texel of a shadow over logged host pages (3b5b3b9b51)
A command that replaces every texel of a shadowed texture (ShadowUse::overwrites,
a cleared pass among them) took no copy in and no keep, and its copy back wrote
every texel it moved into the buffer's bytes: on a discrete GPU, 6 MB per
host_ab drag frame across PCIe for the 23 cleared 256x256 surfaces, whatever
changed. Over host pages whose consumer logs every write to them
(ShadowCopies::logged), such a command now takes the merge a command that
leaves texels in place takes: its gated copy in (only the rows the log reports
changed since the image's last copy, every row where the log cannot say), the
keep, the command, and the merge, which stores only the words the command
changed against the keep (shadow.rs, overwrites_unkept, and the module's
**Overwrites over logged pages**).
Metal's bytes: the gated copy in is decided once the log published the stamp
the command buffer asked at its commit, so the image and the keep hold the host
bytes as of the commit, every CPU write before it included, and a word the
merge leaves already holds the value the command wrote. A byte another writer
writes after the commit is one the command writes too, a race Metal leaves
unordered. Without a log the image may lag the CPU's writes, so there the copy
back stays a plain copy, as before. No switch: no byte differs from Metal's.
RUNTIME_VERSION development's 1692 + 1 = 1693 (renumbered at landing).
Verified on the M3 Max (MoltenVK), tests::dirty_pages_device:
- a_pass_replacing_a_logged_render_target_merges_back_the_words_it_changed:
frame 1, 0 texels copied back and 1 merge; frame 2, the gated copy in takes
the told row alone (256 bytes), the told CPU row the pass clears back to the
image's old black ends black (Metal's), and a CPU row the log left out, which
the pass clears to the black the keep held, keeps the CPU's 0x50 bytes: only
changed words are stored.
- a_pass_replacing_an_unlogged_render_target_copies_it_back: 4096 texels copied
back plainly and no merge, two frames.
Sabotage 1 (overwrites_unkept ignoring the log): the logged test fails (4096
texels copied back, 0 merges). Sabotage 2 (keep and merge without the copy in):
it fails on Metal's bytes (row 0 [16,16,0,16], want [255,0,0,255]). Restored:
dirty_pages_device, shadow, shadow_host_writes, shadow_merge_read,
shadow_carried_read, render::shadows and degradation tests 57/57 under
--cfg m2v_gpu; clippy plain and --cfg m2v_gpu (runtime) clean; rustdoc
-D warnings for the runtime clean.
* Store an overwriting pass's merge over logged pages in whole 256-byte blocks (d34f373d52)
Over host pages whose consumer logs every write to them, a command that
replaces every texel of a shadow (ShadowUse::overwrites, a cleared pass among
them) is merged back word by word since 3b5b3b9b51: only the words it changed
against the keep are stored. Where those changes are scattered, every warp's
store leaves gaps between words, which an RTX 5080 storing into host memory
over PCIe charges hundreds of times for (bind::shadow_merge's module docs:
590 ms against 0.85 ms per 8 MiB), where the plain copy back it replaced stored
every texel without gaps.
The merge kernels (bind::shadow_merge_module, shadow_merge_image_module and
its kept-image form) take a store form, bind::ShadowMergeStores { Words,
Blocks }. In the block form, the 64 words a workgroup takes in one step are one
256-byte block (ShadowMergeModule::BLOCK_BYTES), marked in workgroup memory
where a word of it changed (clear, barrier, atomic or, barrier); a marked block
is stored whole, a word it left as read, and no other block is read or written.
The form is chosen by structure, with no switch: blocks exactly for the merge
of a command that replaces every texel, cut to the texels' rows (so every word
it examines is texels' bytes, none between rows or past the last texel); every
other merge (partial writes, two ways, a linear attachment's) keeps the words.
That is Metal's answer: the command wrote every byte of every such block, as
the plain copy back stored them all, so a word it left is stored with the value
the merge reads, which differs from the command's only by another writer's
write since the commit, a race with the command's own write. A scratch made for
one kind of command is kept again only for the same kind; a command of the
other kind merges it and takes a new one. WorkCounts gains
shadow_merge_dispatches_in_blocks. RUNTIME_VERSION 1693 + 1 = 1694.
Public API: bind::ShadowMergeStores (new), shadow_merge_module /
shadow_merge_image_module / shadow_merge_kept_image_module take it,
ShadowMergeModule::BLOCK_BYTES, WorkCounts::shadow_merge_dispatches_in_blocks
(api_signatures re-blessed, api_surface lists the enum).
Verified on the M3 Max (MoltenVK):
- tests::dirty_pages_device::a_scattered_overwrite_of_logged_pages_merges_back_in_whole_blocks:
a 1024x1024 target over 4 MiB of logged pages, the CPU's texels (told to the
log) grey at every other texel; a pass clearing to black (one pixel drawn
red) merges 8 of 8 dispatches in whole blocks and leaves the pass's bytes, the
CPU's grey texels black; a pass loading and drawing black everywhere changes
the same words and merges in words (0 of 8 in blocks), same bytes. GPU time
median: blocks 1.318 ms (4 MiB stored), words 1.096 ms (2 MiB stored).
- Sabotage (never choose blocks): that test fails (0 of 8 in blocks).
- Device tests dirty_pages_device, owned_pushes, shadow, shadow_host_writes,
shadow_merge_read, shadow_carried_read, render::shadows: 42/42.
- Interpreter tests of both forms (ported from the measurement branch): equal
bytes in both forms and orders, two barriers per invocation in blocks, and a
current buffer holding only the first block, so any access to an unchanged
block traps; bind::shadow_merge*, owned_divisions, api_surface,
api_signatures 26/26.
- clippy workspace plain and runtime --cfg m2v_gpu, rustdoc -D warnings.
* Re-pin the runtime sources at the landing tip (44c96cfdf8)
* Merge a loading, storing pass's attachment back in whole blocks of its area's rows (2fcdb470fe)
A render pass that loads a shadowed color attachment and stores it, changing
it only inside its draws' scissors (ShadowUse::area), merged back to the
buffer's bytes word by word: only the words it changed against the keep. Where
those changes are scattered, a GPU storing into host memory over PCIe pays for
every separate run of words in a 64-byte host line (about 180 ns each on an RTX
5080, serialized: 88 to 102 ms for every other word over 4 MiB, against 0.4 ms
in whole blocks).
Metal itself rewrites such texels. Measured on this M3 Max's Metal (macOS
27.0.1, an ObjC harness, not MoltenVK): a 512x256 RGBA8Unorm texture over a
no-copy Shared buffer, 300 passes each loading and storing it and drawing one
pixel (a long fragment loop, about 2.9 ms of GPU time each), while a CPU thread
wrote a fresh value to every other texel over and over and checked that each
read back its last write. For points at (70,70), (200,130), (10,10) and
(100,33), the other 1023 texels of the 32x32 tile holding the point reverted to
an older value in 157 to 229 of the 300 passes each; no texel of any other
tile reverted, inside the render area (renderTargetWidth 384) or past it. A
kernel writing the same texel reverted none (0 of about 1.1e9 checks). So a CPU
write to a texel such a pass leaves inside its render area, made while it runs,
is not kept on Metal either.
ShadowUse gains tile_stores: a color the pass loads and stores inside its
bounded area (render/shadows.rs), joined like area (a draw's write through the
texture another way clears it, a read keeps it). shadow::stores_blocks takes it
with the overwrites rule, and MergeFor::overwrites becomes MergeFor::blocks
(KeptArea::for_overwrite -> in_blocks, ShadowMerge's flag alike): the merge of
such a pass, when its keep is the pass's area, is cut to that rectangle's rows
and stores whole 256-byte blocks (bind::ShadowMergeStores::Blocks), each
holding a changed word as one store, no other block, nothing outside the rows.
Over any merged-back bytes, logged or not: a block's unchanged words are stored
with the value the merge reads, so only a write between that read and the
store is undone, a shorter window than a tile's load to store. A block can
reach past the tiles the draws reach (64 RGBA8 texels of a row, two 32-texel
tiles), never past the rectangle. Docs: shadow.rs **Stored attachments**,
shadow_merge.rs, bind::shadow_merge, WorkCounts::shadow_merge_dispatches_in_blocks,
API.md (shadowed-texture entry), FAST-PATHS known gap (now the partial writes
of kernels and blits). RUNTIME_VERSION 1695 + 1 = 1696.
Verified on the M3 Max (MoltenVK):
- tests::shadow::a_pass_storing_its_loaded_area_merges_in_whole_blocks (new):
blocks for a bounded loaded-and-stored pass; words unbounded, without tile
stores, or joined with a draw's write; a read keeps them. Sabotage (never
tile stores): FAIL; restored: PASS.
- tests::dirty_pages_device::a_scattered_overwrite_of_logged_pages_merges_back_in_whole_blocks:
the Load pass drawing every texel now merges 8 of 8 in blocks (the old form
asserted 0), same bytes; GPU time median 1.078 ms (clear leg 1.860 ms).
- tests::dirty_pages_device::a_pass_storing_its_loaded_area_keeps_a_cpu_write_beside_it
(new): a Load pass drawing a 64x64 square over 4 MiB of logged pages while a
CPU thread writes three texels beside it (the next block of its rows, far
right, below) from before the commit to after the completion: 8 of 8 in
blocks, 12.4 million CPU writes, each texel ending with the CPU's last write,
every other byte Metal's.
- Device tests dirty_pages_device, shadow*, owned_pushes, render::shadows: 45/45.
RUNTIME_VERSION 1696 -> 1697 (renumbered at landing). Metal's own tile stores measured on the Apple M3 Max with an ObjC harness: 300 Load+Store passes drawing one point while a CPU thread rewrote every other texel; the 1023 other texels of the drawn 32x32 tile reverted in 157-229 of 300 passes, no texel in any other tile did, and a compute kernel writing the same texel reverted none in ~1.1e9 checks. A 256-byte block can reach the neighbouring tile within the scissor rectangle (64 RGBA8 texels), never beyond the rectangle: documented in shadow.rs's "Stored attachments".
* Re-pin the runtime sources at the landing tip (3da7eb9189)
* Say why a kernel's and a blit's partial writes merge back word by word, never in blocks (2e2e238346)
The owner decided (10-29) to keep whole-block merges out of kernels' and
blits' partial writes. Blocks rewrite the unchanged bytes inside each
256-byte block with the value the merge read, undoing a CPU write made
meanwhile. Metal keeps such a write beside a kernel's write: on the M3 Max
(macOS 27.0.1, an ObjC harness over a no-copy Shared buffer), a kernel
writing one texel lost none of a CPU thread's writes to the texels around
it in about 1.1e9 checks. A pass that loads and stores its attachment
rewrites the whole 32x32 tile it draws in (157 to 229 of 300 passes), which
is why only those passes, and commands that write every texel, take blocks.
Blits weren't measured; they keep the kernel's rule.
FAST-PATHS' known gap for the word-by-word merge now says so. Docs only: no
runtime source changes, so the runtime-sources pin doesn't move.