What. A fragment function that fetches a color in the storage form (the
ordered pixel interlock's storage image of the attachment) reads that image
once per invocation, in its entry hook before the body (fragment::emit_entry,
EmitCx::fetched), and every use of the color input takes that texel. Before,
each use read the image again at the use.
Why. The coverage chain's discarding fill (dsx_coverage_chain's
chain_color_discarding) tests its fetched coverage for its discard, then
multiplies its color by it: two uses, so the body read the raster-ordered
image, branched on it, then fenced and read it again. On MoltenVK on the M3
Max (MoltenVK 1.4.2, macOS 27.0.1), while other work ran on the GPU, Apple's
GPU lost the color the function wrote through its output in whole 8x4 blocks:
runtime_lane::framebuffer_fetch::coverage_chain failed 4 of 60 runs (and 9 of
90, 12 of 90 in earlier batches). With one read, 0 of 60, whether the discard
demotes or is predicated; a form that read the image twice with no branch
between the reads also lost nothing (0 of 150). Metal hands the function one
value of the attachment, so one read is its semantics, and it keeps the
image's accesses in the interlock to that read and the writes at the returns.
Test. tests::engine_fragment::a_fetched_color_is_read_once_before_the_body:
chain_color_discarding reads the coverage's image once, in the first block,
on every committed profile that orders fetch through the interlock (two reads
without the change).
(cherry picked from commit 3917662cbbb5d214ceb7a4f8c8631a71679a2849)