Files
metal2vulkan/docs
Anees Iqbal 61a367cb51 Weigh a self-read's two forms at the coverage least favourable to each
A draw that reads its pass's private texture at its own pixels after a barrier takes a snapshot
drawn in its subpass or splits the render pass instance; both are exact. The area rule weighed the
snapshot as if the draw covered its whole scissors (20 bytes of the split's copy a pixel) against
the split's copy alone, so a reader through no scissor over a large target always split. The
consumer's guest draws its self-reads that way: on the Iris Xe its 3662x2039 desktop's 30 readers a
frame took 10.9 to 17.4 ms of GPU time split (selfread's jobs 6068 and 5702), against about 1 ms
through snapshots.

What a draw covers is unknown when it records. Measured with both forms forced (a scratch build,
e3792c8f2e, never landed; 30 readers a frame over private BGRA8Unorm targets of 1280x720 to
3662x2039, no scissor):
- A split costs a fixed 5 to 18 us besides its copy, which is every texel here: the cut is the
  readers' and fills' scissors, the whole target (30 x W x H texels copied a frame, job 6674).
- A snapshot costs a fixed 9 to 16 us (two barriers and the second draw) and then grows with the
  pixels the draw covers.
- Snapshot over split, reader covering 1.5% / 100% of the target: Iris Xe 0.09-0.33 / 1.04-1.28
  (jobs 6656, 6674, ms01); Radeon 780M 0.11-0.24 / 2.4-2.8 (6758, um790); RX 7900 XTX
  0.25-0.43 / 1.3-2.1 (6822, gem10).

The rule now weighs each form at the coverage least favourable to it and takes the one whose cost
there is the smaller multiple of the other's: the snapshot where
READER_COST * (READER_COST + pixels * SNAPSHOT_PIXEL_COST) <= (READER_COST + bytes)^2, with the
fixed cost READER_COST a mebibyte of the copy (both forms' measured fixed costs on the iGPUs) and
SNAPSHOT_PIXEL_COST still 20 (measured about 14 on the Iris Xe, 20 on the 780M, 21 on the XTX).
Every reader the old rule gave the snapshot keeps it (the old rule is the case where the snapshot
over its whole scissors costs no more than the copy). New snapshots: a 4-byte color's readers
through scissors of up to two fifths of the target at any size (was a fifth), and at any area from
1024x768 (786,432 pixels; an 8-byte color's from 256x256). By the measurements above the rule
picks the snapshot in every no-scissor cell on all three GPUs, the form whose worst case is the
smaller multiple there; the cost is up to 1.28x (Iris Xe), 2.8x (780M) and 2.1x (XTX) for a reader
covering the whole target, against 3x to 11x saved for sparse ones. Small scissors covered whole
keep the snapshot they had, up to 2.1x on the Iris Xe (FAST-PATHS says so).

Both forms are exact, so this is a cost choice with no accuracy side: no ledger row, the
attachment-read paragraph of docs/FAST-PATHS.md restated.

- render/snapshot.rs: snapshot_within and READER_COST; the module docs' area rule.
- tests/snapshot_area.rs: the consumer's shape, the size thresholds (786,432 and 65,536 pixels
  exactly), two fifths at any size, and every old snapshot kept. Fails on the old rule.
- runtime_lane::snapshot_reads: an RGBA8Unorm reader through a quarter of the 32x32 target now
  takes the snapshot where the device takes the path (was a split).
- runtime_lane::attachment_read_costs::snapshot_area_costs: the measurement, the rule's form on
  the default device against the split with fragmentShaderPixelInterlock withheld. The composite
  workload's window readers now take the snapshot; its docs say so.

(cherry picked from commit 65d58b231d38ad2c2ac22f8e448be3a48491bf9a)
2026-11-07 20:50:32 -08:00
..