Files
metal2vulkan/crates/metal2vulkan-runtime/examples/host_ab
Anees Iqbal 2d6b322e40 Clear a pass-start read's copy to the clear instead of splitting the pass
A pass that clears a color, begins with a memory barrier over the render
targets and then samples that color's texture split off a first instance of
the clear alone, stored it, loaded it again in the next and copied the read's
texels between (3797c098eb). On the M3 Max under MoltenVK that cost 8 to 12%
of a frame of 60 such passes over a 3840x2400 target, about 17 to 27 us of GPU
time and 11k host instructions a pass.

Before any draw of the pass has recorded, the copy the draw reads holds
nothing but the clear. So where that copy can be cleared to it
(Texture::cleared_copy: the texture's shadow is an image of its own, the
texture a single-sampled 2D one of one level and slice that exactly one
color renders whole, in place, in the image's format, inside the render
area, loading it Clear with no clear whose note the load withholds and no
extended-range route, stand-in or sample planes), the draw stays in the
pass's first instance and the copy in before the pass is a clear of the
shadow's image to the pass's clear value (vkCmdClearColorImage, which Vulkan
converts as the load operation). The shadow then holds the truth nowhere, so
no carry takes it and its next use copies in again. Later draws of the
instance read the same copy. Once a draw has recorded (it may have written
the attachment, which the copy must then hold), a tile dispatch ran or the
pass split, a draw that needs a new such copy splits as before.

- shadow.rs: ShadowUse::cleared and ShadowCopy::clear; ShadowSync::before
  plans the clear in place of any copy in; a clear copies no texel and is
  not counted in shadow_copies; ShadowCopies::cleared_image.
- render/shadows.rs: an instance's gathered clears (InstanceShadows) mark
  its shadows' uses.
- render.rs: the draw's decision (cleared_copies) and its gathering.
- WorkCounts::attachment_read_clears counts the draws that brought new such
  copies, apart from attachment_read_splits and instance_splits_attached_read.

Unverified: not built yet (no local cargo here; the build and the lanes go
through potluck next).

(cherry picked from commit 685063b3af2fbc64100749bf4f641d077780375c)
2026-11-05 02:08:33 -08:00
..