Files
metal2vulkan/crates/metal2vulkan-runtime/examples
Anees Iqbal e5c37ecc62 Read a self-read through a snapshot of a color's own image where its image lacks STORAGE, pinning the instances through it
On the Iris Xe (m3-max-5702, the self_reads lane) a surface in place over host pages split every
reading draw: 30 splits a frame, 224M texels copied in, 19.5 to 26 ms of GPU a frame, where its
shadow took the snapshot (4.2 to 4.8 ms). Its image lacks STORAGE (the device's check failed
storage writes over its pages), so snapshot_wanted fell back: a later framebuffer fetch of the
color would render it through a stand-in for the whole pass, copied in before the pass, which a
snapshot draw reading the texture's own image would not see.

A draw now reads such a color through a snapshot of its own image all the same, pinning it
(RenderLowering::pins_own_attachment), where nothing the pass's end decides from the whole pass
changes what the instances through the draw render: the pass's first instance recorded inline,
no stand-in, memoryless color or depth/stencil attachment in the pass, every color stored Store,
no tile dispatch, execution, color groups or extended-range shadows, a draw that fetches nothing
and needs no hidden depth. A stand-in arriving after a pin freezes the pins (no later draw pins),
and the pass's end then renders the instances through the last pinned one with the colors' own
images, takes each stand-in's copy of its attachment after the last of them (and a merged
color's keep after that copy), keeps the reloads after them alone and joins no run of passes:
as after an instance recorded inline (render/inline_first.rs).

Counted: WorkCounts::reading_draws_pinned, WorkCounts::stand_ins_after_pins.

Tests: tests::self_read_storage: a private target without STORAGE pins its first pass's reader
and then takes its storage form; a pass whose pinned reader is followed by a fetch of the target
keeps the reader's pixels and halves the fetched ones (a stand-in for the whole pass would leave
the reader the red before the pass).

The self-read cost lane (runtime_lane::attachment_read_costs::self_reads) prints the readers
pinned per frame.

Verified:
- Iris Xe (ANV, Mesa 26.2.6), m3-max-6011: tests::self_read_storage passed both. A private
  BGRA8Unorm target without STORAGE gave (splits, snapshotted, pinned, stand-ins after pins,
  storage forms) = [0, 1, 1, 0, 1] in its first pass and [0, 1, 0, 0, 0] in later passes. A
  fetch after a pinned reader gave [0, 1, 1, 1, 1] in pass 0, with the reader's pixels the pass's
  red and the fetched ones halved.
- lavapipe takes no snapshot path. There, both tests check the split branch ([1, 0, 0, 0, 0]);
  193 filtered lavapipe tests passed in m3-max-5964.
- Clippy plain, --cfg m2v_cpu_icd and --cfg m2v_gpu, and rustdoc -D warnings, for runtime and
  validation: clean (m3-max-5964).
- The Iris lane frame: the device's render-target check now fails over host pages (the next
  commits), so the surface is a shadow and its readers take the snapshot unpinned: 3.94-3.97
  ms/frame on development and on this commit alike (m3-max-6068, three rounds each, each process
  checking on a fresh cache). Pins apply there to a private target without STORAGE and to a
  render target over pages whose check passed.

(cherry picked from commit e0799938e01c14d6b087ce7442bf9acfe3171b1c)
2026-11-07 19:55:49 -08:00
..