Files
metal2vulkan/crates
Anees Iqbal 80ef3ea24e Runtime: a texture's attachment views bounded, the least recently used idle one evicted
A texture kept an image view for each level, first layer and layer count a pass rendered into,
for its whole life and with no bound (the field's doc said levels times slices, but the key
holds the layer count, so an N-slice array could keep N(N+1)/2 a level). Now a texture keeps at
most one view for each level and slice (each depth plane of a 3D texture's levels) and one more
a level (texture.rs attachment_bound): a cube's six faces one by one and its six layered fit.
A view made past the bound first evicts the least recently taken views that no command buffer
holds, to the reaper, until the bound has room (texture.rs evict_idle); where command buffers in
flight hold every one it evicts none, so the list holds the bound and what work not yet retired
holds past it.

How a view a command buffer in flight uses is known never to be evicted:
- Each view is an Arc (texture.rs AttachmentView). The texture's list holds one count; a take
  (texture.rs attachment_view) clones another only under the list's lock, into the pass's
  Attachment::held (texture.rs:406).
- The pass's begin keeps that Arc in its command buffer's kept list before the pass records
  (render_encoder.rs:935 for each target, :940 for each resolve; command.rs:1701
  hold_attachment_view into kept.rs:256 ByKind::attachment_views, via Kept::hold, kept.rs:191).
  A stencil target that targets() skips shares the depth target's view, which the pass checks
  (pass.rs DepthStencilViews).
- That list is cleared only at the command buffer's retirement (command.rs:2124, in retire) or
  at the drop of one never committed (command.rs:2201), before the texture list
  (kept.rs:264).
- Eviction takes only a view whose strong count is 1, the list's own (texture.rs:386), counted
  under the same lock, so no other hold can appear while it decides.
Between the take and the keep, the pass's own Attachment holds a count, so a view is never seen
idle in that window.

Docs: the field's, the attachment call's, Gauges::attachment_views' and the runtime README's
pass section now state the key and the bound. The kept-list size note counts eight lists.

Verification is in the jobs named where this lands; the device tests of the previous commit
are red without this change.
2026-12-02 08:36:02 -08:00
..