Commit Graph
88 Commits
Author SHA1 Message Date
Anees Iqbal a6de987639 Runtime: the narrowed attachment-read counter and its per-draw rectangle go; the narrower form is not taken
The UHD 630 numbers answer the question attachment_read_copy_bytes_after_barrier_narrowed was
added to size (9db78abe7d): a form whose memory barrier forgets only the rectangle bounding the
pass's draws' scissors would remove at least half the attachment-read copy bytes, or it is not a
lane. On Intel's Windows driver 101.2145 for the UHD Graphics 630 (Windows 11, the consumer's
x86-64 guest, no feedback loop), whole-boot counts at a test tree with the split:
- desktop boot (130 s, 15,678 copies, 72,587,189,668 bytes): after barrier 56,148,113,276,
  narrowed 25,369,581,904, so the form would remove 30,778,531,372 bytes, 42.4%;
- 40 s 1080p H.264 playback (25,551 copies, 138,558,378,988 bytes): after barrier
  75,057,769,016, narrowed 39,566,419,316, so it would remove 35,491,349,700 bytes, 25.6%.
Both under the planner's 50% bar, so the form is not built and the count that sized it is
deleted (rule 4), with what fed it: shadow::Held's dropped areas, rendered rectangle and
may-write flag, Held::drew and Held::narrowed, held_texels, Area::meet, the per-draw update in
draw() and the scissor_of helper it shared with drawn_through (inlined back as before). Held keeps
one flag for the moment counters. The other five split counters (own pixel, whole texture, first
in pass, after barrier, beyond held) stay: the consumer prints them.

The README's sentence on the counter becomes the measured shares (card, driver, OS; no job ids).
The signatures table loses the field. The device test and the host test drop the narrowed column;
the host test of the narrowed texels goes with the code it tested.

Verified: pending (clippy x3, rustdoc, lavapipe rt suite).
2026-12-04 18:12:41 -08:00
Anees Iqbal 4075d137fa Runtime: the attachment-read copies' bytes parted by read, by moment, and what a narrower form would copy after a barrier
What: six Metrics counters part attachment_read_copy_bytes, the copies a draw makes into a
shadow on a device without the attachment feedback loop (and for a surface plane, a texture in
place over a buffer without the feedback usage, a Direct3D 11 plane, on every device):
- by read: attachment_read_copy_bytes_own_pixel (a slot read only at the fragment's own pixel,
  or a fetched colour attachment) and attachment_read_copy_bytes_whole_texture (every level and
  layer the texture reaches); the two sum to attachment_read_copy_bytes;
- by moment: attachment_read_copy_bytes_first_in_pass (the shadow has held nothing since its
  pass began), attachment_read_copy_bytes_after_barrier (a memory barrier after draws, or a
  fetching draw after draws, left it holding nothing) and attachment_read_copy_bytes_beyond_held
  (it holds something and the draw reads past it); the three sum to attachment_read_copy_bytes;
- attachment_read_copy_bytes_after_barrier_narrowed: for each copy after a barrier, what a form
  whose barrier forgets only the rectangle the pass's draws rendered would have copied: what of
  the copy lies in the rectangle bounding the scissors (cut to Metal's render area) of the
  pass's draws since the shadow began to hold what it held, in the attachment's level and layer,
  plus what of it the shadow did not hold when the barrier dropped it; the whole copy where one
  of those draws may have written memory (Draws::writes_memory, or an indirect command buffer's
  execution), which may reach the image other than as its attachment. At most the after-barrier
  part.
No copy is added, removed or resized.

Why: the consumer's Intel UHD 630 under Windows, which has no feedback loop, counts tens of
gigabytes of these copies in a desktop boot and a video playback. A narrower form, a barrier that
forgets only the rendered rectangle, is a lane only if it would remove at least half the bytes;
the existing two counters cannot say. The rectangle counts from the shadow's first copy after it
held nothing, not from its last copy: a later copy only adds areas, and the areas copied earlier
are stale where the draws between rendered.

How: shadow::Held keeps what it held at the barrier, the rectangle and a may-write flag;
Held::narrowed works out the kept texels by inclusion and exclusion over at most eight held
areas, only at a copy after a barrier. The per-draw cost is one rectangle update for each shadow
of a pass that has one (Held::drew at the draw's end); a pass with no shadow does nothing more.
No speed is measured.

Verified, at dd1913401b (this tree; the message alone changed since):
- lavapipe (llvmpipe, LLVM 23.1.1), job m3-max-86812: the runtime suite under --cfg m2v_cpu_icd,
  1025 passed, 4 skipped. Among them
  d3d11_reads::every_device_parts_the_bytes_it_copies_into_a_direct3d_11_planes_shadow, which
  drives the shadow route on every device through a Direct3D 11 plane (R8Unorm, 16 x 8): an
  own-pixel read under a small scissor, a whole read, a memory barrier, a draw under another
  small scissor, a whole read; it asserts copies 3, bytes 280, own pixel 24, whole texture 256,
  first in pass 24, after barrier 128, beyond held 128, after barrier narrowed 60. And three host
  tests in tests/shadow.rs (moments, the narrowed texels over overlapping held areas, a
  may-write draw, another level or layer; the parts' sums).
- Red control, lavapipe, job m3-max-86813: this tree with the six split adds removed; the
  device test failed with [3, 280, 0, 0, 0, 0, 0, 0] against [3, 280, 24, 256, 24, 128, 128, 60].
- clippy --workspace --all-targets --all-features -D warnings: plain job m3-max-86814,
  --cfg m2v_gpu job m3-max-86815, --cfg m2v_cpu_icd job m3-max-86816. rustdoc -D warnings,
  scripts/api-docs and the signatures check: job m3-max-86817.
- The signatures table is blessed (six Metrics fields); refusal_surface.py wrote no change.
Not run: a device without the feedback loop through any route other than the Direct3D 11 plane.
2026-12-04 18:12:41 -08:00
Anees Iqbal b5ac9fd07b rt: visibility results, one precise occlusion query per mode, copied into the buffer at the pass's end
What: `setVisibilityResultMode:offset:` builds `Boolean` and `Counting`. Each such mode set is one
segment counted by one precise occlusion query (`VK_QUERY_CONTROL_PRECISE_BIT`), begun in the
pass's rendering before the segment's first draw and ended there at the next mode set or the
encoder's end; a segment with no draw begins and ends its query as it ends, so its word is 0.
After `vkCmdEndRendering` the pass copies the counts (`vkCmdCopyQueryPoolResults`, 64-bit, WAIT)
straight into the visibility result buffer's `VkBuffer` at place+offset, one copy for each run of
consecutive offsets in one pool, before the pass's second barrier (recorded or owed), which orders
them before every later command; a Shared buffer's segment end barrier reaches the host, and a
Managed buffer's write and a texture over the buffer in an image of its own are kept as a blit's
write is. `Boolean` writes the count too, nonzero exactly where a sample passed (Metal documents a
nonzero word; the M3 Max writes 1): an accepted difference in docs/API.md section 10, and the
conformance cases compare a `Boolean` word as nonzero alone.

A command buffer takes its queries from occlusion pools of 256 the device lends it
(`crate::visibility`), each query reset on the host (`hostQueryReset`) as the command buffer
retires or drops uncommitted; the device keeps at most 16 pools free and destroys the rest
(`Gauges::occlusion_pools`). `occlusionQueryPrecise` joins the floor's required features (every
venue's profile reports it; Roadmap 2022 requires it), with the README floor table, the
runtime-floor profile's `m2v_runtime_floor` block and the regeneration script's list.

Refusals: Metal's own, each where the mode is set, the encoder's mode unchanged:
`Refusal::NoVisibilityResultBuffer`, `Refusal::VisibilityResultOffset` (not a multiple of 8, or
past the buffer), `Refusal::VisibilityResultOffsetTaken` (Apple documents each offset as set once
per pass; Metal's validation stops it), and `Refusal::ArgumentPlace` at alignment 8 for an offset
at an allocation byte off a multiple of 8 (VUID-vkCmdCopyQueryPoolResults-flags-00823). Gaps, each
counted and a README known gap: `DrawKind::AccumulatedVisibilityResults` (a mode in an
`Accumulate` pass; `Metrics::accumulated_visibility_refused`) and
`DrawKind::VisibilityResultInterrupt` (a command that would end the rendering while a query counts:
a memory barrier after a writing draw, a draw that moves an attachment to the feedback layout, pays
an owed barrier before an attachment read or copies into a shadow, and, bounded, a draw that looks
at textures over a buffer in an image of their own or reaches a Managed buffer with textures over
its device copy; `Metrics::visibility_interrupts_refused`). Every refusal is checked before the
encoder changes state; a segment's first draw may still end the rendering, before its query
begins. `DrawKind::VisibilityResults` is gone. `RenderPassDescriptor::visibility_result_type`
(`VisibilityResultType`, Metal's `visibilityResultType`) is a field now.

Translator: `PrecisionNote::DeviceOcclusionCount`, the static note of a `Boolean` or `Counting`
result (`RenderCommandEncoder::VISIBILITY_NOTE`), quoting Vulkan's "Occlusion Queries" (precise
counts differ between implementations: fragments killed before rasterization, counts multiplied
per colour output) and "Fragment Operations" (`earlyFragmentMultisampleCoverageAfterSampleCounting`);
its codec tag, ARTIFACT_FORMAT_VERSION 588, validation's allowance (unbounded, no tolerance), the
conformance degradation `device-occlusion-count` among the native notes, and docs/API.md's
catalogue. The dead `Feature::CountingVisibility` (no construction site) is removed with its reach
row. The old runtime's `Device::new` is untouched; the runtime-floor test profile now states
`occlusionQueryPrecise`, which re-keys that profile's fingerprint.

Why: the visibility-cut ruling. A guest that sets a mode got a refusal; it now gets its results,
or a typed, counted refusal where the cut does not build the shape (continuations and a combine
are not built).

Verified: cargo fmt; scripts/api-signatures --bless/--check, refusal_surface (0 without reach or
basis), metal-coverage and conformance-coverage regenerated, check_device_profiles (0 findings).
The compile job (fmt, signatures, clippy plain / --cfg m2v_gpu / --cfg m2v_cpu_icd, workspace
Rustdoc -D warnings) and the lavapipe rt suite, with tests/visibility.rs (Boolean and Counting
against the CPU's counts, pool reuse and the 16-pool bound past 17, Metal's refusals, Accumulate,
the barrier and attachment-read interrupts), are named in the lane's report.
2026-11-21 06:16:57 -08:00
Anees Iqbal 9a1c8fe6dc metal2vulkan-rt takes the runtime's name: metal2vulkan-runtime, published
The cutover's last mechanical step. The old runtime is deleted, so its name is free: the crate
moves to crates/metal2vulkan-runtime, its package is metal2vulkan-runtime and its library
metal2vulkan_runtime, and every reference in the tree follows (sources, tests, scripts, CI,
generated tables and docs).

It is now a published crate, as AGENTS.md said it would be once it took the name: version 0.2.0
with the other two, the translator pinned exactly (=0.2.0, as the translator pins the AIR front
end), documentation, keywords and categories, and copies of the repository's four license files,
which the published-crates test now holds equal to the root's for three crates. CI packages it
with the others. Prose that said it was unpublished, or counted two published crates, says three.

AGENTS.md: facts only. The crate table row, the published-crates and version sentences, and the
paragraph on the old runtime, whose name the runtime now carries (listed for the owner).

Made by one script run on this tip. Verified by the job
named in the landing note.
2026-11-20 09:10:02 -08:00
Anees Iqbal 5d725aeec7 Delete metal2vulkan-runtime, with every test and script that read it
The cutover deletes the old runtime: crates/metal2vulkan-runtime and its workspace member go.
Nothing in the workspace depends on it any more: the harness and conformance lost their old arms,
and validation dropped its dependency in its own commit.

Adapted in this commit, so no gate reads the deleted tree:
- CI and scripts/linux-gate-ci: the crate's per-feature clippy group, its `-p` in the Windows
  clippy and the test step, and its private-doc-links row go. Packaging needs no edit: the
  workspace's published crates are now metal2vulkan and metal2vulkan-air.
- The published-crates test lists those two; devtools' carried trees and the five nextest groups
  of the old crate's tests go.
- scripts/api-signatures: the crate leaves CRATES, FLOORS and the header, its self-test trees name
  rt (read by the same rules), and the table is re-blessed (the old crate's 4555 rows go);
  api_signatures.rs pins the three crates left.
- scripts/refusal-surface: the old crate's tree and its sections go (RuntimeGap, AppleOnly,
  Problem and the problem enums it forwards to), with their 87 reach rows, the `--delegations`
  verb and the test that counted the old Problem's delegations; docs/REFUSALS.md is regenerated.
  The basis check now holds rt's refusal enums alone, which it already required.
- scripts/api-cost-coverage goes: it measured only the old crate's surface.
- feature_vocabulary.rs: the old crate's two enable tables go; the Khronos and validation tables
  stay held to the vocabulary.
- The conformance coverage generator's by-hand roots read rt instead of the old crate, and
  docs/CONFORMANCE-COVERAGE.md is regenerated (MTLResourceOptions' row, which only the old crate
  modelled, gives way to rt's MTLCommandBufferError).
- scripts/matrix: the harness times the new runtime alone (`--runtime new`), so the rules that
  judged it against the old one go: the new-over-old budget with its floors (floors.tsv,
  gpu-floors.tsv), ceilings, card variance and status table (status.tsv), the frozen arm, the
  base spread and the timing once more it set off, the re-timed pairs, the five creation rounds
  and the old runtime's parked tests and records. A harness row's time is judged as a cross-GPU
  outlier, with its alone runs as before, and the frame and burst rows by their stored
  instruction counts; the creation rows run once, in their own process. docs/VALIDATION.md's
  matrix section says these rules.

Checked locally (python, no build): signatures.py --check and --selftest, refusal_surface.py
--check, --selftest and --missing-basis, coverage.py --check and --selftest, and scripts/matrix's
49 tests pass. The compile gate (fmt, clippy plain, --cfg m2v_gpu and --cfg m2v_cpu_icd, Windows
clippy for gnullvm and msvc, workspace Rustdoc, packaging, the touched crates' suites on the host
and on lavapipe) runs on this sha as potluck jobs that the landing note names.
2026-11-20 07:01:01 -08:00
Anees Iqbal fa40e8416a RUNTIME 2516: faces turn for a pass whose render area is short of its texture
A pass that reads its own colour attachment (attached reads) turns the texture's two faces
where it can; where it cannot, the texture's texels are copied in before the pass. On the
consumer's desktop walks the passes whose render area is short of the texture (Unturned::Area)
were 71% of all shadow copy traffic: 132.7 M texels/s on the XTX and the Radeon 780M (282
copy-ins/s), 18.9 M/s on the Iris Xe (67%); faces turned 8.2 times a second on the XTX.

- Step 0, counters: attached_read_unswapped_area is now the sum of new fields by sub-cause
  (extent, resolve, shared, memoryless, failing). unfaced_cause checks unfit_for_faces before the
  colour's own verdict, so Area no longer hides a texture that could never take turns.
- Step 1: a Clear or DontCare colour whose pass is short of its texture turns the faces. Before
  the first instance, the face turned to copies from the old face only the texels its clear does
  not rewrite: for a stored Clear, those outside Metal's reach (the area rounded up to whole
  32-pixel tiles, or the whole texture); for any other load, those outside the area. Within those
  it copies only where the faces' standing (shadow_standing) is stale. The turned face's writes
  are bounded by the clear's reach, not by the render area (the clear writes past the area, so a
  bound by the area alone would leave the next turn stale there); shadows::plan takes the pass's
  draw-call fact for it.
- Vulkan: load, store and resolve effects are restricted to the render area
  (VkRenderPassBeginInfo::renderArea; VkRenderingInfo the same).
- New WorkCounts: attached_read_swaps_short_area, attached_read_swap_area_texels, and the
  sub-cause fields. No new Degradation kind; exact in every case, nothing announced.

Tests: a 32x12 area of a 64x16 texture whose clear reaches 32x16, faces made to differ outside
the reach first: the first short turn copies 512 texels (exactly the half outside the reach),
later turns copy 0 with 0 copied in; the busy lane (open command buffer, a copy in every pass)
gives the same bytes; both 0 bytes off Metal's answer.

Verified (areaface lane, m3-max-39298, msi): lavapipe runtime attached_read|face|shadow|standing|
snapshot|carried_draws|reach 251/251, api_signatures + api_surface, clippy plain/gpu/cpu_icd 0,
rustdoc 0. The first run (39276) caught the clear's reach past the area (fixed in the second
commit).
2026-11-16 22:34:55 -08:00
Anees Iqbal ac7dffa3fd RUNTIME 2488: A spliced shadow's staged heads and tails go back as row copies too, one dispatch each where faster
A spliced copy back out of a staging buffer copied its rows' edges into
the arena region (each row's head before its first line boundary and its
tail after its last, which the host step then copies into the pages) as
one vkCmdCopyBuffer region per edge: 2N regions per copy back. On ANV,
which splices every such copy back, and on the RTX 5080 Laptop
(DriverFact::RowCopiesDispatchFaster), the driver records each region as
an operation of its own. That is the cost row_copies.rs removes.

shadow_splice::staged now puts a cut's heads (in `edges`) and its tails
(in `tails`) in separate lists. Each takes the region in the same order as
before (a row's head, then its tail), so the region's layout, the pieces
and the host step are unchanged. For rows of one shape the heads are
equal-sized and equally spaced in both buffers, and so are the tails.
SplicePlan::place makes each list a RowCopies from the staging buffer into
the region (the arena's chunks carry storage usage), beside the whole
lines' RowCopies into the truth. record_spliced records all three; the
encoder takes their stages and uses (ShadowCopy::spliced_stages and
spliced_uses: a texture buffer's shadow is read by every dispatched copy)
and retains every set.

Tests:
- tests::shadow_splice::a_staged_cut_of_equal_rows_is_three_copies_of_rows_of_one_shape_each
  checks that the cut of the validation test's shape, at three phases,
  gives whole lines, heads and tails of one dispatchable shape each.
- The staged cut's byte test also reads the tails.
- runtime_lane::row_copies::a_spliced_shadow_s_lines_heads_and_tails_go_back_as_one_dispatch_each
  (renamed from ..._whole_lines_go_back_as_one_dispatch) asserts 3 row
  copies of 96 regions, 3 dispatched where the fact holds. Before this
  change it was 1 copy of 32.
- The unforced test expects 3 copies where its copy back was spliced,
  else 1.

The three row copies live in Splice.rows (clippy's large_enum_variant refused a 600-byte variant of
SpliceCopies::Staged; nothing boxed). RUNTIME_VERSION 2488 (2487 is the early pin branch's).

Verified: msi m3-max-38042 at 777d9a3412, lavapipe, --cfg m2v_cpu_icd: clippy -p runtime -p validation
--all-targets --all-features -D warnings 0; validation 43/43 (a_spliced_shadow_s_lines_heads_and_tails_
go_back_as_one_dispatch_each: spliced 1, row copies 3, regions 96, 3 dispatched where the fact holds;
the same scenario measured 1 copy at 869519d69f, m3-max-38028); runtime shadow, splice and row-copy
tests 118/118 (a_staged_cut_of_equal_rows_is_three_copies_of_rows_of_one_shape_each: each copy meets
RowsDispatch::new's conditions, so ANV and the 5080 dispatch them: expected, not run). Plain and
--cfg m2v_gpu clippy and rustdoc in m3-max-38043.
2026-11-16 15:23:37 -08:00
Anees Iqbal 566f2da4f9 RUNTIME 2486: A spliced shadow's staged whole lines go back as row copies, one dispatch where faster
RUNTIME 2431 splices a shadow's copy back into host pages where the
device's check of those pages failed or has not answered. Its staged form
(a copy back out of a staging buffer: a 2D texture whose texels start off
their alignment, or a texture buffer) recorded its rows' whole lines as one
vkCmdCopyBuffer region a row, bypassing row_copies.rs, which every other
copy back out of a staging buffer goes through. So on ANV and the RTX 5080
Laptop (DriverFact::RowCopiesDispatchFaster), and the Iris Xe splices
every such copy back, the rows went as N regions again instead of one
dispatch, and WorkCounts::row_copies counted none.
runtime_lane::row_copies::a_shadow_s_staged_rows_go_back_as_one_dispatch
caught it on lavapipe: its device has no record of the check's verdicts,
so the copy back is spliced, and the row copies since were (0, 0) where
(0, 1) was wanted.

SplicePlan::place now makes a staged splice's whole lines a RowCopies from
the staging buffer into the truth (counted, one dispatch where the device
runs it faster); record_spliced records it; the encoder's splice records it
with the copy's stages and uses as that dispatch's (ShadowCopy::spliced_uses:
a texture buffer's shadow read by both the dispatch and the edges' copy),
retains its set, and notes the host step's write as before.

The validation test is split: its clear over the pages is a helper; the
original test keeps its contract, and
a_spliced_shadow_s_whole_lines_go_back_as_one_dispatch runs it on a device
whose check fails (DeviceOptions::fail_in_place_check), asserting the copy
back spliced and its whole lines one row copy, dispatched where faster.

Cause: shadow_splice.rs `splices` splices a copy back into host pages while the in-place check is
failed or pending (RUNTIME 2431, 9ea0a9c1f6); the staged splice recorded its whole lines as
vkCmdCopyBuffer, one region a row (shadow.rs record_spliced), never through RowCopies: N regions
where one dispatch was planned, on every device that splices (the Iris Xe always). RUNTIME_VERSION 2486.

Verified: msi job m3-max-38028, lavapipe, --cfg m2v_cpu_icd: validation 43/43 (runtime_lane::row_copies
all four, a_shadow_s_staged_rows_go_back_as_one_dispatch failing 3/3 before at 51280732aa
(m3-max-37994) and passing now; the new a_spliced_shadow_s_whole_lines_go_back_as_one_dispatch:
shadow_copies_back_spliced == 1, row copies (0, 1)); runtime shadow and splice tests 113/113; clippy
-p runtime -p validation --all-targets --all-features -D warnings 0. Plain and --cfg m2v_gpu clippy
and rustdoc in m3-max-38030.
2026-11-16 15:09:49 -08:00
Anees Iqbal f27f432487 RUNTIME 2451: Shadows: a gated copy in copies from the truth's buffer as its call found it
RUNTIME 2450's test,
dirty_pages_device::a_rebind_before_the_first_submission_encodes_a_gated_copy_in_s_encoder_again,
failed on lavapipe at RUNTIME 2450 and at the tree before it alike
(m3-max-36334): rebind_bytes_no_copy answered
Invalid(Rebind(EncodedUses)), not EncodedUseRebound. A shadow's copy in
left to its batch's submission (Deferred::GatedCopyIn) read the truth's
VkBuffer as its record ran there (ShadowBuffer::Rebound), so it was work
whose step resolves what it records then
(Deferred::resolved_at_its_calls false): its commit held the pages of
every buffer over host pages the command buffer used until it completed
(steps_hold), and a rebind of one meanwhile was refused at the call, as
for a command buffer not yet committed, where Metal's replace is not.
The rebind never reached the encoding again, so RUNTIME 2450's
predicate (Deferred::left_again_by_an_encoding_again for GatedCopyIn)
was inert on that path; the test's control at development's files fails
on the same refusal.

Now a GatedCopyIn captures, at its encoder's call, the VkBuffer of a
truth a rebind may move (GatedCopyIn::from: bytes of a buffer over host
pages, the only such truth a gated copy in reads, a log's; a standing
one's truth only the runtime's commands write), and its record at the
submission copies from it (ShadowCopy::record_gated and record_moves
take it beside the gate; every other caller passes none and reads the
buffer as it is). Its recording then reads nothing of a buffer resolved
later, and Deferred::resolved_at_its_calls answers true for it: the
command buffer lets those pages go at the commit (held weakly until its
first submission), a rebind before that submission is not refused but
encodes the encoder again, whose own gated copy in captures the new
buffer and takes the first's place (RUNTIME 2450), and a rebind after it
leaves the old pages to the command buffer until it completes. A first
gated copy in whose encoder a rebind could not encode again is let go of
with its encoder's failing segments (State::fail_part, before
record_scrubs), so no captured buffer is recorded after its pages went.

Docs: shadow.rs (GatedCopyIn, record_gated), deferred.rs
(resolved_at_its_calls), and attached_read_faces' busy lane, which said
a rebind there is refused.

Verified: cargo fmt only; the job reported with this tip runs RUNTIME
2450's test (which this fix-forward makes pass) and its control.

Degradation kinds added or removed: none.

Verified: m3-max-36366 at fc0e1aee30 (same tree), clippy -D warnings (runtime; m2v_gpu; m2v_cpu_icd runtime+validation) 0 and rustdoc -D warnings 0. The control, RUNTIME 2450s test, the rebind tests and the touched suites on lavapipe run after the merge.
2026-11-16 05:35:25 -08:00
Anees Iqbal 5410cd5cf4 RUNTIME 2450: Shadows: a rebind encodes the encoder of a gated copy in again
An encoder that left a shadow's copy in to its batch's submission
(Deferred::GatedCopyIn: over host pages a consumer logs, the regions its
log decides; or a command buffer's first copy in of a shadow that may
stand across command buffers) kept no log (Unlogged::Segments): no
Segment::records_again test held for it. A rebind, before the command
buffer's first submission, of a buffer over host pages that encoder used
then failed the command buffer with EncodedUseRebound, where Metal
resolves the use at the submission. Keeping the log alone would not do:
the encoding again redoes the copy in for itself (a gate of the log
taken again, a standing decided at the submission, ended_encoders_wrote
answering false while replaying) and leaves a GatedCopyIn of its own, or
records the copy in in place, but finish_replay asked every other
segment to record on the GPU alone, which a gated copy in does not, and
refused the encoding again.

Now Deferred::left_again_by_an_encoding_again answers for GatedCopyIn
too: the encoder keeps its log, its place takes the encoding again
(splice_fits), finish_replay prepares the encoding again's segment as the
commit prepares one (no recording, StepInputs::None), and the batch's
submission records it (submit.rs's record_scrubs, which takes every
unrecorded such segment). The first's goes unrun, retained. A gated copy
in made by the encoding again holds a gate of the log made after the
commit's decisions (DirtyShadows::committed), whose decision is none, so
it copies every region (CopyInGate::regions): a superset of the rows the
log reports changed, read at the submission, after every CPU write before
the commit; the shadow's hold was advanced to the commit's stamp by the
first gate's decision, and its image then holds at least that. Its cost,
one whole copy in, falls only on a rebind of such an encoder. A standing
gate is decided at the submission (stands), as the first's would be. GPU
parts are unchanged: a gated copy in starts none.

Unlogged::Segments now names a GPU-written indirect dispatch's host step
and a scrub. Docs: deferred.rs, rebound_use.rs, encoder.rs, reencode.rs,
shadow.rs (GatedCopyIn).

Test: dirty_pages_device's
a_rebind_before_the_first_submission_encodes_a_gated_copy_in_s_encoder_again:
a kernel inverts a shadowed RGBA8 texture over a logged no-copy buffer
into a plain texture, behind a shared event only the host signals; the
buffer is detached and rebound over other pages, logged by the same log,
before the signal. Asserts the command buffer completes with no error,
the rebind encoded the encoder once, one gated copy in ran (the encoding
again's) and copied every row (dirty_copies_in_gated +1,
dirty_copies_in_whole +1), and the kernel read the new pages' texels. At
development's files it is expected to fail on the error
(EncodedUseRebound).

Degradation kinds added or removed: none.

Verified: m3-max-36334 at a7b5d28822 (same tree), clippy -D warnings of the runtime (all targets and features) 0. Rustdoc, the cfg clippy, both controls, the rebind tests and the touched suites run after the merge.
2026-11-16 05:23:18 -08:00
Anees Iqbal 8562b28fe4 RUNTIME 2446: Shadows: a split merge on the host copies no piece; its kernel skips their columns
A merge on the host past shadow_merge::HOST_WHOLE_BYTES split: its host
step stored the pieces of each row in lines beside the texels, and its
kernel the rest. To keep the kernel off those lines, the GPU copied the
pieces' kept bytes into an arena region and their changed bytes over
them in the kept part: two vkCmdCopyBuffer calls of one region per
piece. On the Iris Xe (ANV) that work cost about 7 to 9 us a region,
growing with the rows, not the bytes: about 0.6 ms for 34 rows
(m3-max-35898) and about 15 ms for 1024 (m3-max-36118: a BGRA8 1023x1024
render target over host pages drew in 17.57 ms a command buffer as a
shadow against 1.26 ms in place, its host step 0.28 ms of it).

Now the kernel takes a column window (bind::ShadowMergeModule: two more
push words, PUSH_BYTES 24; shape_within, shape the whole row): a word
outside the columns is neither read nor written in either store form,
and counts as unchanged in its block. A split merge pushes the words
between each row's pieces where every row's pieces lie at the same
places in it (shadow_merge::columns: whole words, the same head and tail
each row; rows whose pitch is no multiple of the line differ, and those
merges go on the host whole). It records the changed copy and its
dispatches alone, with no save, no mask, two fewer barriers and no arena
region; the host step reads each piece's kept and changed bytes in the
scratch's two parts, which nothing writes after the changed copy.
Removed: HostMerge::saved, ShadowMerge::saves, ShadowCopy::merge_saves,
the merge's region in EncoderCore::merge_on_host, MergeDrain::_region,
and the split's copy uses of the kept part. The bound stays 1 MiB; its
doc comment states the measured costs. Linear merges push the whole row.

Tests:
- bind::shadow_merge's
  a_region_merged_within_columns_leaves_the_words_outside_them: 70 rows
  of 6 words, columns 1 to 4, every word changed; words outside the
  columns keep the current buffer's, in both store forms, and a window
  of every column equals shape.
- shadow_runs' merges_on_the_host_go_whole_up_to_the_bound_and_split_past_it
  also asserts shadow_merge_words_examined: every word of the whole
  merge's rows; for the split, the words between each row's pieces
  alone (height * (row bytes - line) / 4).
- shadow_write_lines' cost test gains a 4K shape: 3839 RGBA16Float texels
  a row, 2160 rows 30720 bytes apart.

The merge module is under no golden table (golden_hashes covers the
fixtures' translations). api_signatures: PUSH_BYTES, shape, and the new
shape_within. Degradation kinds added: none.

Landing note: msi m3-max-36189 at 4b09425f2d (same tree): clippy metal2vulkan + runtime, all targets and features, CLIPPY=0. The API tables, the module tests, rustdoc, clippy m2v_gpu / m2v_cpu_icd, the lavapipe control (development's whole-row kernel fails the split test's words-examined count) and the touched suites, PHOENIX and the Iris re-time follow on development.
2026-11-16 04:32:27 -08:00
Anees Iqbal f93cb22b94 RUNTIME 2440: Shadows: a host step's drains hold none of the program's objects
A shadow's copy back spliced (RUNTIME 2431) and its merge on the host
(RUNTIME 2432) leave their CPU parts, SpliceDrain and MergeDrain, to a
host step in a Deferred::ShadowSplice segment. Each drain held the
truth's Buffer (`_buffer`), and the segment lies in the command buffer's
recorded parts, which its completion does not let go of: only
State::reset clears them, as the CommandBuffer goes. So a no-copy
buffer whose texture's write-back went through a host step kept its
import past the completion for as long as the program kept the command
buffer, where Metal lets go of what the commands used, and runs the
deallocator, at the completion.
tests::encoder_holds::a_no_copy_buffer_a_committed_dispatch_writes_a_texture_over_keeps_its_import_until_completion
failed on development ("the deallocator never ran"): it makes its
texture while the device's check is pending, which splices
(shadow_splice::splices), so the dispatch's write-back merges on the
host.

The rule the drains now rest on: the host step runs before its command
buffer completes, and until then the command buffer holds what its
encoders' commands named (`retained`, retained.rs), the texture among
them, which holds the buffer whose pages the step writes. The runtime
makes no command buffer with unretained references, so that hold is
always there. The drains drop `_buffer` (SplicePlan its buffer, and
ShadowMerge::drain its parameter); what they still hold is the
runtime's own: the merge with its scratch, and the arena's region. The
SAFETY comments and the ShadowSplices doc say what holds the pages.

Degradation kinds added: none.

Verified: see the jobs named in the landing report (the failing test at
the fix and at its parent on lavapipe, at the fix on PHOENIX, the shadow
and hold suites, clippy in three configurations, rustdoc).

Verified: msi m3-max-36002 at 4606d9e40c (same tree): CLIPPY=0, CLIPPY_GPU=0, RUSTDOC=0. Lavapipe control + fix (m3-max-36003) and PHOENIX follow on development.
2026-11-16 03:10:51 -08:00
Anees Iqbal 438fdd4eee RUNTIME 2438: Merge on the host only the lines beside a texture's texels
A shadow's merge in place into host pages, on a device whose stores
write back the lines they end in (the Iris Xe under ANV) or whose check
has not answered, went on the host whole: the host step compared and
stored every byte of the merge's rows. On the Iris that cost 12.7 ms a
merge for a 1920x1080 RGBA16Float draw (17.7 ms a command buffer
against 3.7 ms by the GPU kernel), and the guest's scene has about 73
such shadows.

The merge now splits as the splice of a copy back does:

- Its kernel stores the changed words of each row's bytes in the lines
  that hold the texture's texels alone (ShadowMergeStores::Words, never
  whole blocks).
- The host step merges only each row's bytes in the lines that also
  hold a byte of no row of the texture's: the bytes between the rows and
  around them (shadow_splice::beside_texels; at most a row's first and
  last line).
- Before the kernel the GPU copies those pieces' kept bytes into a
  region of the command buffer's arena, then their changed bytes over
  them in the kept part, so the kernel finds them unchanged and stores
  none of them; the host step compares the region's bytes with the
  changed part's.
- The host step compares 4-byte words and stores a changed word with one
  AtomicU32 store (the changed word where all four bytes differ, else
  the word as it holds it with those bytes changed, as the kernel's
  Words form does); bytes outside whole words go one by one.
- A merge none of whose rows' lines holds such a byte (rows that start
  and end on lines, as the 1920x1080 plane's 15360-byte rows do) goes by
  its kernel alone, with its fetch view and kept image where it has
  them. A merge not cut to its texels' rows stays on the host whole.

The measured contract is the padding: row_padding_writes found the M3
Max, the 5300M and the UHD 630 keeping CPU writes to the bytes between
and around a texture's rows under clears, stores and draws, and over
IOSurfaces under kernels. No probe measured a CPU write to a texel the
commands left inside a line whose other bytes they changed, while the
command buffer runs; the kernel now stores into such lines, so that
write may be put back on the Iris. FAST-PATHS's known gaps record it,
beside the measured contract.

WorkCounts::shadow_merge_bytes_on_host counts the bytes the host steps
compared. Buffer::own_pages_flags gives a buffer's memory type flags,
which the cost test prints for a buffer made as the host scratch is,
beside the host loop's time over plain heap memory and over that
memory (1920x1080, half the texels' red and blue changed).

Tests:
- tests::shadow_splice (pure): the pieces equal the rows' bytes in
  lines beside the texels, found byte by byte, over 9 shapes and 6 page
  phases (wrapping among them); the host loop stores the differing bytes
  alone at every alignment.
- tests::shadow_write_lines: each draw merge's host step compares 16
  bytes a row (the row's last texels, in its padding's line); the cost
  test's 1920x1080 draw no longer merges on the host.
- tests::shadow_runs: the rebind test of host merges puts its pages 16
  bytes into a page, so every row's first and last lines hold bytes
  beside its texels, and asserts the bytes compared (a line a row).

Degradation kinds added: none.

Also (65db6f5b40): the old device-local query, left with no callers, is gone; the probe prints
the scratch's memory flags by name.

Verified (fplend): msi m3-max-35872 at a5289d8132 (same tree as 65db6f5b40): clippy 0, clippy
--cfg m2v_gpu 0, api_signatures + api_surface 15/15, debug and release archives built; 35850:
tests::shadow_splice 5/5 (host pieces against a byte-by-byte answer over 9 shapes x 6 page
offsets; the CPU word loop at every alignment). PHOENIX, lavapipe, rustdoc and the Iris run follow.
2026-11-16 02:29:15 -08:00
Anees Iqbal 518d6d8443 RUNTIME 2432: Shadows: merge on the host over host pages on devices that write lines back
What: a shadow's merge in place into a no-copy buffer's host pages, on a device whose
check of those pages failed, or has not answered, the copies or the shader writes of
texels whose rows end inside a line (the same rule as the copy back's splice), now goes
on the host. Its keep and the copy of the texels the commands left go into two parts of
a Shared scratch (ScratchKind::ShadowHost; the fetch view is not used, so the changed
texels are always copied). The encoder records only that copy, and a host step of a
batch of its own (Deferred::ShadowSplice, now carrying HostWrite::Splice or ::Merge)
compares the parts eight bytes at a time and stores each byte that differs into the
pages with atomic byte stores. Such a texture joins no run of passes (render.rs), so
each pass merges as its encoder ends. Devices where both checks passed keep the
kernel merge.

Why: the Iris probe (m3-max-35510) showed the merge kernel's stores losing CPU writes
to padding bytes in the line that holds each row's last texels, as the copy back did.
A CPU store changes only the bytes it stores, so the bytes the commands left, and
every byte the CPU writes meanwhile, stay. Metal keeps those bytes
(conformance probe row_padding_writes.m).

Where the merge stays on the GPU (FAST-PATHS known gaps): merges recorded between a
pass's instances, before a tile dispatch, into a held command buffer, at a segment's
end, merges through a copy, and the runtime's own Shared memory.

New WorkCounts fields: shadow_merges_on_host, shadow_merge_host_nanos.

Tests: shadow_write_lines now asserts the Draw rounds (keep + merge) put back no byte
and go on the host under unanswered verdicts, and follow the measured verdicts in the
second test. A new test, costs_of_a_write_back_spliced_or_not, prints the median
command-buffer time of a copy back and a merge for 34x34 and 1920x1080 RGBA16Float,
with verdicts unanswered and passed.

Degradation kinds added: none.

Verified (fplend): msi m3-max-35675 at bdb1e2cbae clippy (runtime, all targets/features, -D warnings) 0,
touched unit tests 3/3, api_signatures + fast_paths 34/34; msi 35689 clippy --cfg m2v_gpu 0.
PHOENIX suites (35711), lavapipe, rustdoc and the Iris cost run follow.
2026-11-16 01:05:03 -08:00
Anees Iqbal 9ea0a9c1f6 RUNTIME 2431: Shadows: splice a copy back into host pages on devices that write lines back
What: a shadow's copy back (Step::Back) of a 2D texture's image, or of a texture
buffer's staging buffer, into a no-copy buffer's host pages is spliced where the
device's check of those pages (DmaBuf or Pointer) failed, or has not answered, the
copies or shader writes of texels whose rows end inside a line (Access::Copies or
Access::Writes of RowEnds::InLines, Failed or Pending). The GPU copies only the
columns that fill whole lines of memory (nonCoherentAtomSize): one region a slice
where its rows are a multiple of a line apart, else one a row. Each row's head and
tail columns go by the GPU into a line-aligned region of the command buffer's arena,
and a host step of a batch of its own (Deferred::ShadowSplice, after the work before
it completed) copies them into the pages a byte at a time, as the CPU's stores go.
The encoder notes the truth's writes after the step. A copy whose texels fill whole
lines alone copies back as before; a device where both verdicts passed copies back
as before. New count WorkCounts::shadow_copies_back_spliced.

Why: on the Iris Xe (ANV) a copy of texels into a buffer's rows writes back the
64-byte line holding each row's last texels whole, putting back older values over
the CPU's writes beside them. The lane's probe (m3-max-35510) lost 3,539 to 14,319
bytes a kind in 300 command buffers through a shadow's copy back and merge, where
Metal keeps every such byte (row_padding_writes.m). This breaks Metal's contract on
the guest's bytes; the merge is the next change.

Where the copy stays (docs/FAST-PATHS.md, known gaps): a copy back between a render
pass's instances or before its tile dispatch, into a held pass's command buffer, at
a segment's end recorded at a commit or a host step, of rotated, two-plane, tiled or
heap depth/stencil textures, and into the runtime's own memory.

Tests: tests::shadow_splice (the cut run as GPU and CPU over a map of host bytes:
every texel once, no GPU byte in a shared line, every shape of texel, width, pitch
and phase); tests::shadow_write_lines (the probe made a device test: the guest's
34x34 RGBA16Float target over dma-buf pages, buffer and plane forms, a clear's copies
back put back no byte the CPU wrote beside them and are spliced; and a copy back
spliced exactly as the device's measured verdicts say).

Degradation kinds added: none.

Verified (fplend): msi m3-max-35614 clippy 0, tests 0, signatures 0; 35623 clippy m2v_gpu 0;
lavapipe 35625 clippy m2v_cpu_icd 0, 216 passed, rustdoc 0; PHOENIX 35632 (um790) in-place +
shadow suites 287/287, shadow_write_lines 2/2: under the measured verdicts (Copies and Writes
Passed) 0 spliced; under HostPageTexturePolicy::Shadow (no check, verdicts Pending) every copy
back splices (+300 in 300 rounds, 0 bytes put back). The Iris run follows.
2026-11-16 00:46:56 -08:00
Anees Iqbal d62e1d2bd9 RUNTIME 2382: a heap's decoded-format texture on a shadow route keeps a decoded twin
Under DevicePolicy::exact_answers (HeapAnswerPolicy::Metal) a heap's PVRTC or ETC2 texture on RADV
PHOENIX misses Metal's answer (its BC1 carrier image takes 4096 B @ 4096, Metal answers 128 @ 128
or 2048 @ 128), so it lies in memory of its own as a shadow of the heap's bytes (MemoryShadow;
Shadow or Tiled where those serve). heap_texture_at gave a decoded twin only to the Direct,
HostTransfer, Linear and Hidden routes, so its sampled view fell to the carrier, which has no
sampled usage, and every kernel read and sample was refused, Unsupported(Format) (8 of 8 cases in
m3-max-33467), where Metal samples it and the device can decode it.

A heap's PVRTC, ETC2 or EAC texture on a shadow route (not over the caller's host pages, not
detached) now gets its decoded twin. ShadowCopy::record_gated records the shadow's decode
(ShadowCopies::decode) after a copy in that moved texels, and only then (record_moves answers
whether it moved any); the pass is set at making (Image::decode_after_copies_in) and its kernel is
made in ShadowCopies::prepare at first use, so no making compiles. WorkCounts::shadow_twin_decodes
counts the decodes. 4:2:2 heap shadows stay twinless; heaps over the caller's host pages stay the
documented copies-alone gap. Docs: decoded_twin.rs, pvrtc.rs, etc.rs, degradation.rs, docs/API.md,
docs/FAST-PATHS.md (heap shadows of decoded formats are no longer for copies alone). New device test
runtime_lane/heap_carried_reads.rs. Public surface: WorkCounts (for the lanes) gains
shadow_twin_decodes, blessed in api_signatures.tsv.

Verified: PHOENIX m3-max-33568 (carried binary of the lane tip d5bf9cac82): heap_carried_reads,
a_carried_heap_texture_reads_its_bytes_with_no_commit, pvrtc_texels_read_as_metal_s and
etc_texels_read_as_metal_s pass. Under HeapAnswerPolicy::Metal all 8 cases shadowed; a use takes 1
copy and 1 decode, a second encoder in the same command buffer 0 and 0; kernel reads, samples, blit
out and getBytes equal the texture outside a heap, and samples follow a blit and a replaceRegion.
Under HeapAnswerPolicy::Device: not shadowed, 0 copies, 0 decodes, equal. Without the fix
(33467 at the test commit) all 8 reads were refused. lavapipe (msi 33535): the 4 tests pass. Clippy
x3 running in 33569.
2026-11-15 13:46:15 -08:00
Anees Iqbal 00e1304a7c RUNTIME 2375: Owned kernels: a resource's own moves are made at its first use, never as it is made
What: a shared FirstUse cell (owned_kernel.rs) keeps what a resource's sets of one of the
runtime's own kernels bind as the resource is made; the kernel (once per device, as
owned_kernel's rule says) and the sets are made by make() at the resource's first use, as an
encoder plans a command that uses it (ShadowCopies::prepare), before any of its copies is
recorded. Every record takes them through made(), which debug-asserts that a use made them and
records nothing where none did. Three resources take it:

- the tiled heap texture's moves (HeapTiledCopies), which held this form inline;
- a heap's two-plane extended-range texture's moves (HeapPlaneCopies, RGB10A8_2P_XR10 and its
  sRGB twin, in a heap or over a surface's planes), whose making compiled TwoPlaneTexels;
- a 4:4:4 two-plane YCbCr texture's write shadow's write-back (YCbCrWriteBack), and a render
  shadow's load (YCbCrLoad), whose making compiled YCbCrWrite (and YCbCrConvert's float form):
  a heap set's float storage element makes that shadow as the texture is placed, so the
  texture's making compiled it wherever such a set lived.

Why: Metal's resource creation never waits for anything and compiles no pipeline; on a RADV
APU a compile beside busy GPU work took 10-43 ms in a heap texture's making (the tiled form's
probe). The compile now moves to the first encode that needs the moves, once per device, on
the encoding thread, not on the making's.

Test: first_use's check that no making builds a kernel of the runtime's own
(WorkCounts::owned_kernels_made, per call) covers two more makings while the busy work runs:
an RGB10A8_2P_XR10 texture in a heap, and a YCBCR8_444_2P texture over a surface's plane made
after a kernel that writes through an argument buffer ran (so the device's heap set lives and
its float storage element takes the texture's write shadow), where the device holds textures in
argument buffers. Each is used after (a blit out; a write through its handle), and the line
names the kernels the uses built.

Left: a carried texture's decoded-twin kernels (a 4:2:2 texture's pairs on a device that
converts them, a heap texture's whole decode, a view's second twin) still build at making;
the next change. A multisample heap texture's sample-move trial builds pipelines to decide its
route; a separate follow-up.

Verified (m3-max-33274, msi, at ab77f697ba): clippy of the runtime and validation crates (all
targets, all features, -D warnings) 0; lavapipe 292/292 of first_use, heap*, two_plane*, ycbcr*,
extended_range_planes, shadow*, surface_two_planes and owned*; first_use: the makings built no
kernel, the uses built 3. The PHOENIX runs and clippy in the device configurations follow on
development.
2026-11-15 12:08:30 -08:00
Anees Iqbal cdb708d35f RUNTIME 2373: Heap textures: a tiled heap texture's making builds no kernel; its first use does
What: HeapTiledCopies (a heap texture held as a shadow in Metal's tiles,
AliasRoute::Tiled, and the surface depth textures that use it) no longer
builds the device's TiledTexels kernel or writes its two descriptor sets as
the texture is made. They live in a OnceLock and are made at the texture's
first use, in ShadowCopies::prepare(), which the encoder's plan_shadows calls
before it records any shadow copy. That is the path a converted YCbCr
texture's conversion already takes. dispatch() debug-asserts that the kernel
was made. So the compile moves to the first encode that needs any tiled
shadow, once per device, as owned_kernel.rs's rule says ("made once per
device, when a command first needs it"). That cost is now on the encoding
thread, not on resource creation.

Why: runtime_lane::first_use::new_resources_wait_for_no_gpu_work failed three
times on the Radeon 780M (RADV PHOENIX), always at "new_texture in a heap",
which returned 0.7-0.8 s later, about 65-70 ms after the busy work ended, with
no internal submission. A probe on um790's PHOENIX (9 runs, 3 of them beside
the lane's partition 4/4) showed that this making takes 10-43 ms every time,
while every other making takes about 1 ms. Backtrace samples taken 4 ms into
the call (3 runs) sit in vkCreateComputePipelines under HeapTiledCopies::new,
via Device::owned_kernel(TiledTexels). It is the only timed call that builds a
pipeline. Expected, not verified (the long wait did not reproduce in the probe
runs, nor beside a VRAM hog): the 0.7-0.8 s is that compile waiting in the
driver or kernel for the GPU's in-flight work, on an APU with a 2 GiB carve-out
shared by the lane's parallel processes. Metal's makings compile nothing.

Test: the first-use test records WorkCounts::owned_kernels_made around each
timed call and fails where a making built a kernel. Without this change that
check fails wherever the heap texture takes the tiled route (the 780M:
verified). The test also prints the tiled-heap-texture count and the kernels
the later uses built, as evidence the path ran. The heap texture's copy in and
copy out still read Metal's bytes.

Left alone (main records it): owned_kernel holds the device's owned_kernels
lock across every compile, so a lookup of a kernel already built waits behind
another kernel's compile.

Verified (m3-max-33194, msi, at 01fe19ba22): clippy of the runtime and validation crates (all
targets, all features, -D warnings) 0; lavapipe 132/132 of first_use|heap*|shadow*, including
first_use::new_resources_wait_for_no_gpu_work and every heap_tiled unit test. The PHOENIX runs
(the cause's device) and clippy in the device configurations follow on development.
2026-11-15 11:35:22 -08:00
Anees Iqbal a1175662e7 RUNTIME 2355: Textures over buffers: a buffer of 16 KiB or more holds Metal's allocation, a heap's buffer its heap
A texture over a buffer whose texels run past the length was always a
copy: a shadow image or a staged texture buffer whose bytes past the
length lay in a tail of its own. Metal's texels there are the
allocation's: a buffer of 16 KiB or more holds its length rounded up to
16 KiB (allocatedSize), zero when made, and a heap's buffer reaches its
heap's end, whose bytes are the heap's.

Now a buffer the device makes in the Metal address space with a length
of 16 KiB or more takes that allocation (buffer.rs's metal_allocation):
its VkBuffer and placement are its length rounded up to 16 KiB, which
its first fill clears with the rest (Buffer::clear_first: the host's
clear of a Shared or Managed buffer, the device's fill of a Private
one), with no command of its own. A texture keeps in place the bytes the
buffer's memory holds for it (Buffer::texel_reach: the allocation, a
heap's buffer's heap to its end, a no-copy buffer's length), so such a
texture is made as one inside the length is: an image over the buffer's
memory where the device makes one, a texture buffer viewed in place. The
shader-visible ranges, robustness, copy reach (a blit past the length is
still refused) and exported sizes stay at the length. Heap, no-copy,
wrapped and exportable buffers, and every buffer under 16 KiB, take
their length; past what the memory holds a texture keeps its tail, as
before. The runtime has no buffer allocatedSize; a heap's size and a heap
texture's allocated_size are unchanged.

The tails conformance cases now lie in place: their comments say so,
and the texture buffer case drops its staged-texture-buffer allowance,
which no device can fire there any more (its view starts at 16384).

Tests: buffer_tail_device's last-texel case lies as over a buffer that
holds it inside its length, with no tail; a new case over a 20000-byte
buffer (64x128 packed, ending at 32768) reads zero in the padding as
made, lies as inside the length, lands a kernel's writes past the length
in the buffer's memory, takes no copy where it is an image over the
buffer, and refuses a blit past the length; the heap case lies in the
heap, its kernel writes landing in the heap's other buffer; a new case
over a heap's second buffer keeps its texels past the heap's end in a
tail; the no-copy and 4096-byte cases keep their tails.

Docs: buffer_texture.rs's Tails, linear_plan.rs's Length, docs/API.md's
accepted difference and StagedTextureBuffer entry, and a FAST-PATHS
cost-of-matching-Metal entry for the padding.

Checks: the jobs that compiled and ran this commit are named in the
lane's report.

Evidence (lane jobs): m3-max-32551 (msi): clippy runtime+conformance -D warnings 0; 2632/2632 runtime+conformance; fast_paths +
api_surface 34/34. m3-max-32578 (lavapipe) at the tip: touched 56/56 (buffer_tail_device incl. the allocation, heap and
heap-end cases, texture_placement_device, linear_plan, buffer_texture, degradation_catalogue); runtime+validation partition
1/4 1572/1572. VkMemoryRequirements on lavapipe for a 16385-byte buffer: 32768 (alignment 64). The padding is cleared by the
buffer's existing first fill (no new command). allocatedSize: no buffer API; heap sizes unchanged. The PHOENIX run, the
release creation bench and lavapipe partitions 2-4 follow in the lane. Conformance: buffer-tails cases now in place; the M3
venue's cost records for buffer-tails-* re-bless on development.

Lane commits: d2ee5bca5b (bench), a8f3796f59, ee54952340 (heap cases in a placement heap).
2026-11-15 08:14:12 -08:00
Anees Iqbal b7053280de RUNTIME 2346: 4:2:2 textures over IOSurface planes: an image of their texels, decoded from the pairs in place
A GBGR422 or BGRG422 texture made over a buffer's bytes (Buffer::new_texture_with_iosurface_plane,
a CoreVideo 2vuy or yuvs plane, over a Shared buffer or a no-copy buffer's host pages) had no
decoded twin: twins are attached only to textures whose image is their own for good, so every
dispatch or draw that read or sampled it was refused, with a "needs R8G8B8A8_UNORM SampledImage"
line naming a format every device samples.

Such a texture is now an R8G8B8A8_UNORM image of its texels, the converted shadow a two-plane
YCbCr texture over planes already is (ShadowSource::Converted, its conversion now an enum of the
planes' and the pairs'): its copy in, before the first command of a command buffer that reads it
and after a command wrote the bytes, is one dispatch of the new bind::chroma_convert_module that
reads the pairs where they lie, at any byte of their VkBuffer, through one storage-buffer binding,
and writes Metal's texels (ChromaDecode, exact) through the image's R32_UINT view. Copies, blits
and CPU calls keep moving the plane's bytes. Where the device converts the pairs' format with
Metal's reconstruction (MoltenVK), the copy in is that conversion instead: the plane's rows copied
into the pairs' image, sampled through the conversion (chroma_sample_module) into a scratch,
copied into the image; announced decoded-texel-precision at the copy in's planning. The set binds
the buffer's VkBuffer, so the planning makes it again after a rebind gave the buffer another one,
and each command buffer holds the set it took. The placement query answers OtherShape. A plane
the window cannot take (past maxStorageBufferRange, a last word past the buffer, rows that share
bytes, texels past the buffer; with the device's conversion, a first byte or rows off 4 bytes)
keeps the carrier, its reads refused; FAST-PATHS records it as a known gap.

Per frame, per texture (w x h texels): before, no read ran at all; the texture was an R8G8_UNORM
carrier of the plane, 2 bytes a texel. Now no byte is copied: one dispatch reads the w*h*2 bytes
of pairs in place and writes w*h*4 bytes of texels (1920x1080: 4147200 read, 8294400 written).
Memory: one R8G8B8A8_UNORM image, w*h*4 bytes (1920x1080: 8294400), in the carrier's place; with
the device's conversion also the pairs' image (w*h*2) and the scratch (w*h*4), and per copy in a
w*h*2 copy in and a w*h*4 copy out. Announced carried-decoded-twin (an existing kind) with that
cost. No new Degradation kind, no new WorkCounts field.

A carrier's binding without a twin is now refused NotImplemented(Format) naming the texture's
format (pvrtc::holds_for_copies), not a need of the twin's view format.

Public surface: metal2vulkan::bind::{chroma_convert_module, ChromaConvertModule} added
(api_signatures.tsv blessed, api_surface table); docs/REFUSALS.md regenerated (one more
binding_view site of Format).

Tests: the in-place kernel against ChromaDecode's decode under the interpreter (both orders, first
bytes off a word, odd sizes, rows apart); a carrier's binding refusal (binding_view unit test);
a device test of both formats over a Shared buffer and over host pages reading Metal's measured
bar values (an Apple M3 Max, macOS 27.0.1) and Metal's decode of a random frame written on the
CPU before the next command buffer, OtherShape from the placement query, and the device's
conversion counted and announced where it converts. Verification jobs follow in the lane report.

Evidence (lane jobs): msi m3-max-32240 at 94f603bf35, --cfg m2v_cpu_icd on llvmpipe: 130/130 touched tests, clippy -D warnings 0;
the device test fails without the fix (placement not OtherShape, the read's dispatch refused). PHOENIX gem10 m3-max-32260
(archive m3-max-32241): all 4 cases (GBGR422/BGRG422 over a Shared buffer and over host pages) "Metal's texels, exact"
for the M3's measured bars and a random CPU-written frame; ycbcr_device, ycbcr_refresh, twin_reads 7/7. MoltenVK (device form)
run on the M3 follows.

Lane commits: 735234d5f4, d59f44baa6, 94f603bf35.
2026-11-15 06:48:09 -08:00
Anees Iqbal 948b5e37fb RUNTIME 2306: a texture over a bit-24 buffer that no image lies over reads a shadow of its read twin, not of the copy
A no-copy buffer of Metal's private option bit 24 is a copy of its pages off macOS, beside a read
twin over the pages in place. A slot that only reads a texture over such a buffer binds the
texture's read twin, but only where the twin's texture lies in place over the twin's bytes. Where
it did not (RADV lays no DRM_FORMAT_MOD_LINEAR plane whose rows or first byte are off a multiple
of 256: a window server's 48x48 textures at rows of 192 bytes, its 128x128 ones at rows of 512
from 32 bytes in), the twin's texture was made as a shadow and dropped. The slot then bound the
program's texture, itself a shadow of the copy for the same reason, so its command buffer used the
copy and its commit compared the whole copy with the pages.

Workload reason (reims's appwalk17 desktop walks, numbers only): twin textures not in place
780M 362, RTX 3090 304, Iris Xe 1; copies compared 52,537 (2,897 MB), 43,384 (2,138 MB) and 331
(35 MB); the Iris compared in one walk step only, the one that made its one twin not in place.
Copies compared plus twin slot reads come to about the same total on all three (56,775, 52,277,
54,233): every such read that missed a twin read the copy.

Now the twin's texture is kept as a shadow of the twin's bytes where the program's texture is a
shadow too, and the slots that only read the texture bind it under the same proof as before. The
program's texture lists it beside its own shadow (shadow::texture_copies, held weakly), so draws,
rebound draws, dispatches and resident textures copy it in from the pages in place at its first
use in each command buffer, where they copied the texture's own shadow in from the copy (a shadow
of a copy of Shared memory never stands). Where the pages carry a log of their writes only the
changed rows move. The command buffer names the twin's and the shadow image's keys, never the
copy's, so its commit compares nothing. No store reaches the pages: the twin's one GPU access is
the copy in's read, the shadow is the runtime's own image no call returns, the slots only read it,
and a copy back would write the twin's key, which every encoder refuses.

Discrete devices take it too: their copy lies in system memory (MemoryClass::Shared), as the
pages do, so the shadow's copy in crossed the bus before and crosses it now; what goes is the
CPU's comparison. Cost: an image of the texture's size per such texture while it lives.

- WorkCounts::read_twin_texture_shadows (new field). No new Degradation kind.
- The shadow log's twin line says whether the twin's shadow serves the read slots.
- cfg(test) DeviceShared::linear_pitch_rule_forced: RADV's LINEAR plane rule at Device::unplaced.
- Tests (read_twin_device): the two shapes sampled by a draw and the 128x128 one read by a
  kernel through the twin's shadow (compares 0, a CPU write read next, a fill read back through
  the copy, pages kept); over logged pages the second command buffer copies nothing in and a told
  write moves its rows alone. The screen-sized texture lavapipe lays no image of now reads its
  twin's shadow too.
- Docs: read_twin.rs, shadow_log.rs, API.md and the FAST-PATHS row on bit-24 memory;
  api_signatures.tsv (+1).

Verified (msi lavapipe, m3-max-29778 at 69f0a567b1): clippy plain and --cfg m2v_cpu_icd 0;
read_twin_device, copied_device, copied:: units, texel_rows_device, dirty_pages_device and
waited_reads 73/73; api_signatures and fast_paths 35/35. With RADV's LINEAR rule forced (offset
and pitch multiples of 256): 48x48 at pitch 192 and 128x128 at pitch 512 offset 32 sampled by a
draw and read by a kernel: twin slot reads +1, compares 0, texels the pages', a CPU write read
in the next command buffer; a fill in the same command buffer reads back through the copy with
one compare, pages kept; over a dirty log an unchanged twin copies 0 bytes. Negative control
(serves cut back to in-place only): the 3 new tests fail, the commit compares the copy.
2026-11-14 10:22:01 -08:00
Anees Iqbal aa6209cb10 RUNTIME 2281: dispatch tracking: a part's first command waits to be ordered; host aliases through the quiet
Two exact cuts of the host CPU a compute dispatch spends tracking its uses (compenc's profile of the
Geekbench-shaped one-dispatch-per-encoder chain, --heap: command_reaching/track ~1 us a dispatch).

- tracker.rs EncoderUses: an ordered encoder's part takes in its first command lazily. With nothing
  before it, depend() over the empty map answers no barrier, so the first command keeps a copy of
  its uses and reach and is admitted (inside_uses + admit, barrier none, as before) only when the
  part's second command asks for a barrier; split() drops it. A one-dispatch encoder builds no
  compare list, kept list or inside map. New WorkCounts::commands_ordered_inside.
- encoder.rs track(): each command works out its host-alias uses once, through the encoder's Quiet
  (keys dropped exactly when the aliases' version moves: join, place, unplace, remap) into its kept
  vector, as draws already did; plan_shadows / shadows_used augment only when the shadow sync reads
  the uses (ShadowSync::reads_uses). host_alias_lookups 3.0 -> 0 a dispatch in the steady shape.
No accuracy trade (the same barriers and entries); no Degradation kind.

Verified (hosttrack, msi lavapipe, at b91091c75b = this content on fca34185af):
- m3-max-28861: clippy (runtime, cfg m2v_cpu_icd) 0; tracker::, dispatch_tracking, host_aliases::,
  encoder_fold::, compute_bind_memo 114/114; one-dispatch encoders took in 0, a two-dispatch RAW
  encoder took in 2 with 1 barrier, words right; aliases: steady 0 look-ups, after a no-copy buffer
  over other pages 1, then 0.
- property test: 400 random rounds of order/record/barrier/split (tracked/untracked uses, both
  reaches): lazy gives the same barriers and summaries as eager.
- negative control (both levers bypassed) m3-max-28866: the counter tests fail (exit 100).
- release A/B m3-max-28854 (own target dirs, md5 5c8dfc9f base / 3b929dbd tip, loaded host): --heap
  thread CPU 8871 -> 7647 ns a dispatch (dispatch 5121 -> 4058); plain 8930 -> 8508. Profile share:
  track 10.8% -> 6.6%, EncoderUses::order 7.5% -> 2.0%, augment_into 2.2% -> 0.8%.
Lint and the suites run after landing.
2026-11-14 03:50:11 -08:00
Anees Iqbal b31c23f7c0 RUNTIME 2257: render targets placed apart in one Private placement heap keep no shadows
A game's render targets placed apart in one tracked Private placement heap (reims gameload G2
rtheap: MSAA colour, MSAA depth and a shadow map) were held as shadows on the Iris and the AMD
GPUs, with attached reads through copies, clears in part and sample moves every frame (+34.9 ms a
frame over native on the Iris guest at pin 77). Four causes, each with a test that fails before:

- C (d1eaec0f47, 792ea614de): a heap's images shared memory wherever their keys met, so a
  texture placed apart was taken as attached to another's pass; images now share memory only where
  their bytes meet, and the heap's own shadow images use their whole key's memory.
- B1 (6f54af68e2, e56bb982d7): a multisample heap texture takes the device's own size and
  alignment answer and lies in its image (the 780M asks at most 64 KiB).
- D (f760b95001): a whole clear of a 2D multisample attachment copies nothing in.
- B2 (317d905449): a heap texture's device answer takes the device's alignment up to the heap's
  own (the XTX's MSAA colour answers 256 KiB: 2375680 @ 256K, depth 1179656 @ 128K, shadow map
  393224 @ 128K), the host GPU's real value as the owner's rule for device-describing answers
  states.
New owned fixture hpr_reads (our MSL; regen-air-fixtures): fragment functions reading a device
buffer; its golden and the compile census are re-blessed at the next pin.

Verified (steelbrain/rtheap at 23fc75a899): release lane heap_placed_targets (320x192, 7
heap-placed targets, Device policy, mean of 10 frames), placed vs device-made: XTX 1.619 vs 0.576
ms before, shadows MsaaColor/MsaaDepth/Shadow, to 0.530 vs 0.594 ms, every shadow count 0
(m3-max-27670); 780M 2.150 vs 0.579 to 0.548 vs 0.599 ms (27671). Metal policy
(exact_answers): XTX 2.033 to 0.683 ms, 780M 2.650 to 1.079 ms, shadows kept as the switch says.
Texels and kernel reads equal the device-made frame on every leg. lavapipe green (27676); XTX
(27687) and 780M (27688) every heap_placed*, attached_levels, tracker, heap and shadow test
passes, the other failures only under the carried archive's compile-time paths and the
shadow_standing layer test fixed separately (4d95375fe2). Per-draw walk_costs on the XTX, one run
a side (27834): barriers 304.5 to 275.0 us a frame, no barrier 178.7 to 251.8 us with identical
draw-path counts; an exclusive alternating re-run (27858) decides whether that is noise.
2026-11-13 20:19:07 -08:00
Anees Iqbal aa2256b6e7 Order host-alias uses across queues again: Metal orders textures over one IOSurface across queues
Reverts a5634d48db and 3926d2d8c9, which left the uses the host aliases add out of the
scheduler's order across queues on the strength of host_aliases.rs's line that Metal orders two
textures over one IOSurface across queues only as the program orders them. The conformance probe
probes/cross_queue_surface_order.m measured that case (queue A's long compute write committed
before queue B's blit read of the same bytes, no event between them, three runs each):

- two tracked textures over one IOSurface: B ran after A and read its writes in every run on an
  M3 Max (macOS 27.0.1, m3-max-21812, m3-max-21830), a Radeon Pro 5300M and a UHD 630 (macOS
  26.7.1, m3-max-21850, m3-max-21851); untracked, the same but one run on the 5300M;
- a texture of another surface (control): ran alongside A on the M3 and the 5300M;
- two no-copy buffers over one allocation: B ran alongside A, reading stale or mixed words, on
  all three (8 of 9 runs; the 630 ran it one after the other twice);
- one tracked buffer (control): ordered on the M3; the 5300M and the 630 each took B first once.

So the alias keys' order across queues is the surfaces' order, which Metal keeps; dropping it was
wrong for the consumer's surfaces, whose textures lie over per-texture no-copy buffers.
host_aliases.rs now states those measurements, the plain no-copy buffers' among them, in place of
the M4 line. The freeze the revert reopens (a held batch's making holding other queues' heads
over a shared surface) is answered by the next commit, which lets a batch held for its making give
way across queues, as the x86 Macs' GPUs may take a later commit first.

Until that commit, tests::hold_sites::a_head_over_the_same_host_bytes_through_another_buffer_goes_while_a_batch_is_held
fails as before a5634d48db (m3-max-21752).
2026-11-12 10:29:05 -08:00
Anees Iqbal 1b802ea45a Cross-queue commit order counts a conflict only on a resource both batches name
What: a use the device's host aliases add (host_aliases.rs: a no-copy buffer over the bytes of
another, the consumer's textures of one IOSurface over their plane buffers) is now marked
(`Use::aliased`). The scheduler's order across queues (`Footprint::conflicts`, behind
`Order::is_behind`) leaves marked uses out, so a batch the runtime holds for a reason of its own
(its pipelines' making, a host step, its checks) holds back no later commit of another queue that
meets it only over shared host bytes. A use joined with one its command named stays named (join
and merge keep `aliased` only where both are; `covers` lets no aliased use hold a named one), so
two batches that name one resource still run in commit order, as Metal's tracking orders them.
The tracker's barriers, inside a queue and on the GPU once both are submitted, take aliased uses
as before.

Why: on an Intel Iris Xe, one guest process's compute pipeline took about 3 s to make cold. Its
command buffer kept its place in commit order (held for its making), and five other queues' heads
in each scheduling pass, the window server's frame among them, conflicted with its footprint only
through the alias keys over IOSurface pages they shared (heads_held_for_earlier_commits +5 per
pass, footprints_built +2, the scheduler otherwise idle). The frame's present waits for its
writers' completion, the guest's display pipe allows two unanswered presents, and the guest froze
for 3.1 s. Metal orders two textures over one IOSurface across queues only as the program orders
them (host_aliases.rs's measurement: an M4, macOS 27.0.1, plain and under API validation), so a
later commit of another queue through another resource over those pages does not wait for an
earlier one there; holding it was ours alone.

docs/HOWTO.md's paragraph on copied and same-surface buffers says the same; the order.rs,
scheduler gate and host_aliases.rs docs name the exception.

Tests: tests::hold_sites::a_head_over_the_same_host_bytes_through_another_buffer_goes_while_a_batch_is_held
(the previous commit) failed before this change on lavapipe (m3-max-21752: TimedOut, the fill
waited behind the held dispatch) and is expected to pass after; tests::tracker gains
a_use_the_host_aliases_added_orders_no_batch_across_queues (aliased-only overlaps unordered both
ways, a named key on both sides ordered, a named use joined with an added one of the same range
named); tests::host_aliases expects the added uses marked.
2026-11-12 10:29:05 -08:00
Anees Iqbal d225ee6e2c WIP: attached reads turn a texture's two faces instead of copying (unbuilt)
A texture an attached read samples takes two faces, its own image and a second of the same plan
(the shadow the copy took); a pass that renders it whole without loading it renders the face it
did not present while its draws read the one it did. Counted: texture_faces_made,
attached_read_swaps, attached_read_swap_reads/texels, attached_read_swap_fixes/texels, and the
copies no turn took off by cause (attached_read_unswapped_*).

Not built yet: this commit is for the first compile job; fixes follow.
2026-11-12 06:14:30 -08:00
Anees Iqbal b36e4e70c8 shadows::plan: one use list for a pass's instances, its bounded writes borrowed
A pass's end planned each instance's shadow copies from a new list of the
instance's uses and the attachments', then, where the instance bounds its
colors' writes, collected a second list of the same instance uses and the
other attachments' and cloned each bounded color's uses into a Within, which
EncoderCore::shadows_used cloned again. Now one list's room goes from instance
to instance: the instance's uses, then the attachments'; where it bounds, the
list is cut back to the instance's own uses and the other attachments' go
after. shadow::Within borrows its uses and texels (Within<'a>), so the plan
names the pass's BoundedWrites in place, and shadows_used passes the parts on
as they are unless the device's host aliases augment one of them, then
borrows the augmented lists.

Same uses, same copies, same writes noted (ShadowSet::after reads Within
alone). Measured by end_encoding's instructions a call on lavapipe
(draw_costs compositor --calls).
2026-11-12 05:23:21 -08:00
Anees Iqbal 2a485c9b9e A shadow made before its verdict moves in place with its usage shadow of the bytes
A texture over host pages (or the device's pooled memory) made before its
class's in-place verdict is a shadow that moves in place at a quiet commit
once the verdict passes. The move was refused for good where a binding or a
pass had taken a usage shadow of the texture. In a compositor's frame, a
draw that reads its own pass's color attachment at its own pixel (an
attached read) takes that usage shadow in the first command buffer. So
every target made before the verdict stayed a shadow for the process's
life. Over host pages, each command buffer then copied back every texel
that its passes wrote: on the Radeon 780M, the whole 3840x2400
framebuffer, 9.2M texels a command buffer, in reims's first session.

A usage shadow of a texture over a buffer holds the buffer's bytes as its
truth (ShadowSource::Bytes). An image in place over those bytes is the
same truth, and an aliasing image's uses are uses of those bytes. So such
a usage shadow serves the moved texture exactly as it serves one made in
place. Now only a render shadow, or a usage shadow of another truth, keeps
the texture a shadow (ShadowCopies::copies_bytes).

draw_costs' compositor shape now settles the in-place check after making
its surfaces. A run with a fresh shader cache then measures a first
session after its verdict.

Test: runtime_lane::in_place_textures::a_texture_an_attached_read_copied_before_its_verdict_moves_in_place_too.
2026-11-12 01:55:19 -08:00
Anees Iqbal d277b155e2 Shadows of a tracked Private image stand across command buffers, stale inside a rectangle
What: a usage or attached-read shadow whose truth is a tracked Private or Memoryless image the
runtime made in memory of its own (not shareable, its VkImage never handed out) now stands
across command buffers, as a shadow of a Private buffer's bytes already did
(Backing::PrivateImage, StandingAcross::over_image). A standing also keeps the rectangle its
image is stale in when the command buffer ended with it current there alone, and the next
command buffer's gated copy in moves only those texels (Standings::standing,
GatedCopyIn::standing_copy). The first render pass instance of a pass now bounds its loaded
colors' writes by its draws' scissors as later instances did, so a draw that samples the
texture its pass renders leaves that texture's shadow stale inside the drawn rectangle alone.

Why: on the 780M a 2618x1024 texture read through such a shadow was copied in whole once per
frame although its texels changed only every 4th frame: 2,680,832 texels a frame, about
200-370 us of GPU time, for a draw beyond the texture's usage and for one that samples it in
the pass that renders it through a 64x64 scissor. An image truth never stood (stands_across
took bytes alone), and a one-instance pass's attachment writes were never bounded, so the
shadow lost the truth whole. The copy an attached read takes before any barrier stays: read in
place through the feedback loop it would race the pass's own writes, which Vulkan forbids
(attached_reads.rs now names it).

New WorkCounts fields: shadow_texels_first_copied_in_private_images,
shadow_texels_unskipped_stale_within.

Tests: unchanged_truth_copies now asserts that a frame that changed nothing moves no texel the
shadow holds (0 beyond usage, the scissor's 4096 for the small attached read); image_standing
checks the stale-rectangle copy's texels and counts, the let-go after another write, and the
mip chain (clear level 0, render level 1 sampling the whole texture, then level 2, then sample
every level) with and without a usage shadow, its passes apart and in one command buffer. Run on
lavapipe and RADV PHOENIX after this commit (job ids in the report to main).
2026-11-11 20:30:20 -08:00
Anees Iqbal 07a21899ed Runtime: contents of a detached no-copy buffer answers the caller's pointer of the pages it lay in last
Metal's contents answers the last pointer across a detach (the caller's pointer of the last
replace), and the consumer's host library expects contents unchanged across detach and
replace; the runtime answered None. Buffer::contents now answers that pointer while a no-copy
buffer, a two-copy Managed buffer (either host copy route) or a no-copy heap's buffer is
detached. The runtime itself reads and writes nothing through it: every internal caller takes
the new crate-private mapped_contents, which keeps the old answer (None while detached), and
buffer::Detached keeps the old mapping's address only to answer contents.

Tests: tests::detached_contents (Shared and Managed no-copy buffers, and a no-copy heap's
buffer) maps the pages with no access while detached and runs a blit and a synchronize of the
buffer; managed_copy_device's detach legs and the validation detach lane assert the pointer.
Docs: Buffer::contents, detach.rs, docs/API.md, the runtime README.
2026-11-11 11:22:54 -08:00
Anees Iqbal 5d2c21b79b Runtime: keep the encoding-again take mode; a rebind's segments decide no takes
The before-runs of the GPU-pass rebind leg passed on the pre-fix code
(lavapipe, m3-max-16674 with the draw before the execution, m3-max-16689
with it after): the draw read the bytes. A render pass recorded in a
segment has its shadowed textures' copies planned by its encoder's own core
as the pass ends (render.rs end_pass, shadows::plan), the take among them,
and the segment only records them. GPU-alone compute executions
(gpu_execute) plan no shadows. The segment cores that plan their own
(indirect dispatches, executions recorded from records) are host steps'
recordings, which a rebind does not record again. So no segment a rebind
records again decides a take, and the encoding again's main core already
keeps them (ShadowSync::again).

So this puts back shadow.rs's two modes, State::replaying_takes and
step_takes, and reencode.rs and encoder.rs as development has them. The
shared pool, the give-backs at a splice and Replayed::takes are gone. Kept:
the failed-submission give-back (State::give_back_from, never_runs_from,
place joining a segment's takes into its encoder's), its docs, the loop
gap in FAST-PATHS, and the GPU-pass leg as a regression test, its doc now
saying where the take is decided.
2026-11-11 11:10:11 -08:00
Anees Iqbal 4289823b20 Runtime: work recorded again keeps its tiled takes; a batch that fails at its submission gives them back
A tiled texture's copy taken at use is taken by the first use encoded after
its mark; a recording that never runs must hand its take on or give it back.
Three paths lost it:

- A rebind that encodes an encoder again re-recorded the encoder's segments
  (a render pass recorded on the GPU alone, its shadowed textures' copies
  in the segment) into cores that asked the mark, which the first
  recording had cleared: the pass read a copy nothing made. The same held
  for work on the GPU alone a rebind records again without encoding its
  encoder again.
- A host step whose recording failed, and a vkQueueSubmit that failed,
  failed the command buffer outside fail_part: the takes of the batch and
  the later ones were never given back, so the next use read stale levels.

How:
- shadow.rs: one way to decide. ShadowSync::again (take nothing unmet,
  note nothing) is gone; every recording in place of others is
  ShadowSync::over a shared Replaced pool: a use that meets a decision of
  the replaced recordings keeps its take, any other asks the mark. The
  cores recorded during one turn share the pool, so each decision is met
  once, in order.
- State::replaced_takes (was step_takes and replaying_takes) holds the
  pool while a host step, a rebind's encoding again (the first encoding's
  takes and its segments' recordings' takes, State::takes_of) or a
  rebind's recording again on the GPU alone records. segment_raw hands it
  to every core. A spliced encoding again or segment gives back the takes
  of the first recordings it did not meet (Takes::give_back_unheld); a
  refused one gives back its own takes the first did not hold. The
  encoder's record keeps the encoding again's takes.
- State::place joins a placed segment's takes into its encoder's record,
  and CommandBufferShared::never_runs_from (State::give_back_from) gives
  back the takes of every part from the failed batch on, called beside
  each of the scheduler's three failed() calls.
- docs/FAST-PATHS.md, known gaps: a predicated loop's run again records
  its work apart as a new recording that asks the mark, so a
  did_modify_data during the loop is taken mid-loop and the next use
  after it takes nothing. Keeping the first run's takes (over) would copy
  in again at every run, so it stays a recorded gap.
- docs/API.md and the shadow.rs and reencode.rs module docs say the
  above.

Verified: see the next report (lavapipe before/after, the 780M, lint).
2026-11-11 11:10:10 -08:00
Anees Iqbal 56c25f8b7a Runtime: a host step's recording keeps the takes of the one it replaces; a dropped command buffer gives its takes back
A tiled texture's copy taken at use was lost in two places where nothing ran it:

- Work the commit recorded and a host step records again (an execution of indirect commands the
  CPU wrote since the commit): the step's cores decided by the mark, which the commit's recording
  had cleared, so the recording that runs took no copy and the texture read stale levels. Now the
  step hands the replaced recording's takes to the cores it records into (State::step_takes, read
  by EncoderCore::segment_raw, under the step's turn): ShadowSync::over follows each decision
  that recording made, keeping its take and number, and decides a use it never met by the mark.
  As the step's recording replaces the commit's, a take of the commit's it never met is given
  back (Takes::give_back_unheld). TakeBy::Mark carries the replaced decisions; a core with none
  decides as before.
- A command buffer dropped without a commit kept its encoders' takes. Its drop now gives back
  every take of its ended encoders and of its segments' recordings while its status is still
  NotEnqueued.

Unit test tests::shadow::a_recording_in_place_of_another_keeps_its_takes covers the follow, the
by-mark decision of an unmet use, the give-back of an unmet take and of none kept, and a kept
no-take after did_modify_data. The device legs are in the previous commit. docs/API.md's tiled
texture paragraph says both.
2026-11-11 10:02:16 -08:00
Anees Iqbal 9d024acefe Runtime: a tiled texture's take whose encoder runs nothing is given back
A tiled texture of more than one level over a buffer takes its copy of the
bytes at the first use encoded after its making or a did_modify_data,
which clears its mark. Where that encoder runs nothing because its command
buffer failed before it ran (committed as failed, an encoder a failure
names, a protection fault, a submission that fails EncodedUseRebound or
DetachedBacking, a hang's discard or recovery, a predication record that
drops it), the copy was never taken but the mark stayed cleared, so every
later use read zeros or an older copy until the next did_modify_data.

The take is now given back where the runtime knows its recording will not
run: State::fail_part, the one point every such failure releases a part
through. The mark is an AtomicU64 whose low bit is the mark and whose
upper bits count the takes; LevelsCopy::take returns the take's number,
and give_back(number) sets the mark again only where that take is still
the latest and nothing set the mark since (a later take holds its own
copy; a did_modify_data since already asks for one), so giving back twice,
or after a later take, changes nothing. shadow::Takes now holds each take's
number and a weak hold of the texture's copies; every ended encoder's
record keeps its takes (not only one whose log is kept), and a recorded
segment carries its own core's takes, both given back by fail_part.
ShadowSync::forget gives its takes back by number too.

An encoder split into parts at a host step gives back every take of its
own where any of its parts runs nothing, so a take that ran in an earlier
part is taken again at the next use when only a later batch fails; that
gap is in docs/FAST-PATHS.md's known gaps. docs/API.md and shadow.rs state
the rule.

Tests: tests::shadow gains a unit test of the give-back's rules (latest
take, a later take, a mark set since, twice, forget). The device tests of
the previous commit fail without this change; the runs of both commits are
in the report.
2026-11-11 09:41:44 -08:00
Anees Iqbal eddd9112aa Runtime: an encoder encoded again takes a tiled texture's copy where its first encoding took it
A tiled texture of more than one level over a buffer is a copy of the bytes
taken at use: the first use encoded after its making, a did_modify_data or
a level-0 replace_region clears the texture's mark and records the copy in
and the later levels. A rebind of a no-copy buffer (or heap) the encoder
also named, before its command buffer's first submission, encodes the
encoder again and puts that recording in place of the first, which is never
submitted. The encoding again found the mark already cleared, recorded no
copy, and the texture's levels kept zeros or an older copy for good; a
did_modify_data made after the commit was cleared by the encoding again
instead of the next use.

The decision now belongs to the encoding. ShadowSync notes, in order, what
each first use of a copy taken at use decided (shadow::Takes); the ended
encoder's record keeps that with its log, and the core an encoding again
records into (EncoderCore::replaying, fed by reencode.rs through
State::replaying_takes) takes each copy where the use in its place took it,
never touching the mark. Its forget gives nothing back to the mark either.

Other per-encoding state checked for the same shape: the shadow carry (an
encoding again starts with none and copies the truth in, which earlier
encoders copied back to as they ended; drops-writes shadows are never
carried), gated copy-ins and standings (decided at batch submission, which
sees the recording put in place), heap tiled and multisample sample moves
(planned per recording, no mark), and segments recorded again on the GPU
alone or at a host step (their shadow copies were planned by the encoder,
not decided again). None consumes a mark at encoding.

Verified at the parent (66b00df138), lavapipe, jobs m3-max-16324/16333:
all four tiled_texture_reencode tests fail (levels read zero through the
encoding again; the next use after a did_modify_data took nothing). The
new CPU unit test in tests/shadow.rs covers the decisions directly. Runs
of this commit follow in the report.
2026-11-11 09:11:38 -08:00
Anees Iqbal 395e5c3305 Runtime: a tiled texture's take makes every format's later levels, and its first level is the bytes to the CPU
A tiled texture of more than one level (Buffer::new_tiled_texture) is a copy of the buffer's
bytes taken at use. Two leftovers from that change against what two x86 Macs answer:

1. Its take made the later levels only by the device's blit chain. A format generate_mipmaps
   makes by the compute filter (an extended-range one, an 8-bit sRGB one held as its UNORM twin,
   one without blits or linear filtering) or by the integer picks kept zeros past its first level,
   where Metal makes every level. Now the making keeps generate_mipmaps' own plan of the format
   (shadow::LaterLevels: the blit chain, the compute filter or the picks, announced as that call
   announces them; Kept for a format it leaves or refuses, or a scratch past the device's
   limits). The encoder makes a take's filter or picks run as it plans the copy
   (EncoderCore::later_runs, beside sample_moves: the scratch, the kernels and sets), held by the
   command buffer, and the copy in records it after its copy into the first level, behind a
   barrier, as it records the blit chain: transfers of the image and dispatches over the scratch
   alone, outside any render pass, before the first command that uses the texture. A filter take
   counts in WorkCounts::mipmaps_filtered. mipmap_filter.rs and mipmap_pick.rs split their
   recording into FilterRun and PickRun, which generate_mipmaps and the take share; what
   generate_mipmaps records is unchanged. A run that cannot be made (no room for the scratch)
   fails the command buffer, as a heap texture's sample moves do.

2. Its CPU calls reached every level in the image. On the Macs, getBytes and replaceRegion of
   level 0 address the buffer's bytes, and a replaceRegion there makes the next use take the copy
   again, as didModifyData does. Now level 0 reads and writes the bytes (Texture::level_in_image),
   a write there marks the copy stale, and while the bytes are detached level 0 is refused
   (NotImplemented(DetachedTexelAccess)) as a one-level texture's is. Levels 1 and up stay in the
   image (the GPU reads a replace_region there until the next take), where the Macs' GPU never
   sees such a write: an accepted difference in docs/API.md and the rustdoc. Blits are unchanged.

Tests (tests/tiled_texture_device.rs), each failing before its fix: RGBA8Uint's later levels are
plain Metal's picks exactly after a blit first use, and after a pass into level 1 as the first use
(level 1 cleared over the picks, the rest picked); BGR10XR's later levels are within the compute
filter's bound of the level above, the take counted once in mipmaps_filtered; level 0's get_bytes
reads the bytes before the first use, after a GPU write into level 0 (which the GPU reads) and
after a CPU write of them (which no level sees); a level-0 replace_region writes the bytes (the
rows' padding kept) and the next use takes the copy again, every level made from it. The detached
test now holds level 0 refused while detached and reads the new pages' bytes after a rebind.

Docs: new_tiled_texture's, replace_region's, get_bytes's and did_modify_data's rustdoc,
DetachedTexelAccess, WorkCounts::mipmaps_filtered, shadow.rs's Copies taken at use, the filter and
pick modules, docs/API.md (the tiled texture and an accepted difference), docs/RUNTIME-PORTING.md,
docs/FAST-PATHS.md's known gap narrowed to formats generate_mipmaps leaves or refuses, and
docs/REFUSALS.md regenerated (the MipmapGeneration sites moved). RUNTIME_VERSION and the
runtime-sources pin are left to the landing.

Checked here: cargo fmt. Clippy in three configurations, rustdoc and the device tests run as
cluster jobs on this commit.
2026-11-11 08:37:22 -08:00
Anees Iqbal 8f4a534b01 Runtime: a tiled texture of more than one level is a copy of its bytes taken at use
A mipmapped tiled texture over a buffer (Buffer::new_tiled_texture, more than one level)
read zeros past its first level: its first level was a shadow of the bytes kept in step at
command boundaries and the later levels were never written, so a minified sample of such a
texture drew black. Two x86 Macs (an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under
macOS 26.7.1, measured by the consumer on both SPI forms, Shared and Managed descriptors,
RGBA8Unorm and BGRA8Unorm) take a copy of the bytes at the texture's first GPU use, every
level generated from the first; again at the first use after didModifyData; between those no
CPU write reaches a level, and a GPU write to a level never reaches the bytes or the other
levels.

The texture stays one image of every level (Storage::Shadow), its shadow now a copy taken at
use (ShadowCopies::levels, a LevelsCopy): a stale flag set at the making and by the new
Texture::did_modify_data (Metal's private -[MTLTexture didModifyData]) is taken by the first
command of an encoder that uses any of its levels (its shadow range is every level now), which
records before it the copy of every texel of the first level and the device's blit chain over
the later levels (mipmap_plan's plan, record_blit), as generate_mipmaps makes them, announced
device-filtered-mipmaps. Every other use copies nothing in; nothing is copied back, kept or
merged; a change of the truth never makes it stale; a take whose encoding is left out is given
back. get_bytes and replace_region reach every level in the image; a detach no longer loads
the first level (keep_first_level, keep_first_levels, Writes and TexturesOver::keeping go), as
the image is its own copy. A format the device's blits do not filter has its first level copied
and its later levels left as they are: a FAST-PATHS known gap. The one-level form is unchanged.

Tests (tests/tiled_texture_device.rs, rewritten for the contract): the first use takes bytes
written after the making into every level (a uniform grey, the compositor's shapes and the
probe's 256x256 of 9 levels in both formats); every later level is the 2x2 box of the one
above (a gradient); a first kernel sample at LOD 1 reads the made level (zeros before); a CPU
write after the first use reaches no level and copies nothing; did_modify_data takes the copy
at the next use, not the call (the probe's steps); a blit into level 0 reaches neither the
bytes nor the later levels; a pass into level 1 takes the copy first; detached and rebound
bytes leave every level as taken until did_modify_data.

Docs: new_tiled_texture's and did_modify_data's rustdoc, shadow.rs's Copies taken at use,
docs/API.md, docs/RUNTIME-PORTING.md, docs/FAST-PATHS.md known gaps; the API signature table
blessed (+ Texture::did_modify_data). RUNTIME_VERSION and the runtime-sources pin are left to
the landing.

Checked here: cargo fmt. The device tests, clippy in three configurations and rustdoc run as
cluster jobs on this commit.
2026-11-11 07:11:37 -08:00
Anees Iqbal 92f88a37a2 Heap depth textures: a merge's keep copies the staging buffer, never the heap's bytes as it runs
A keep of a heap's tiled texture with a depth aspect that did not directly
follow its copy in copied the heap's bytes as the keep ran. A CPU write
made while the command buffer ran, after the copy in read the bytes and
before the keep, was then in the keep but not in the image, so the merge
saw the image's value as changed and wrote it over the CPU's write. Metal
keeps such a write of bytes no command touches.

Every copy of such a shadow fills its staging buffer whole
(HeapTiledCopies::record and record_out), and no command writes through
the texture between the shadow's last copy and a keep. So the staging
buffer holds the heap's bytes as the image stands for them: the bytes the
copy in read, or the image's elements as the last copy back or merge
wrote them into the heap. ShadowCopies::record_kept now copies it, after a
barrier from everything before, as the keep right after a copy in already
did. The values the copy in changed (restricted-depth-upload,
drawn-depth-copy) are still written back as stored, and every byte a
command wrote is still merged.

New lane heap_textures::a_heap_depth_texture_keeps_a_cpu_write_made_after_its_copy_in:
- a Shared placement heap's 37x5 Depth32Float texture;
- one command buffer: a blit reads a texel (the copy in), then a Busy spin
  ordered after it, then a blit encoder whose first copy reads the spin's
  published word and whose second writes texel (3, 1), so its keep runs
  after the spin;
- the CPU writes texel (3, 0) where Metal's tiles place it once the spin
  raised its ticket, then releases the spin;
- it checks the CPU's write and the blit's write both survive, and the
  other texels are unchanged;
- where the texture is a tiled shadow, it checks that a keep was counted
  and that it was not a keep right after its copy in.
first_use::Busy gains spin_in, one spin encoded among a command buffer's
other work.

Verification in the tip report.

(cherry picked from commit f6fabc432fcee43bf29f077a44d72120dde8d352)
2026-11-08 15:41:19 -08:00
Anees Iqbal c1f3a3c1e8 Keep a draw whose shadowed textures its instance gathered: draws again and rebound use the same
A render encoder's draw that used a shadowed texture kept nothing to draw again, so every draw
of a pass that samples its own target through its copy took every step: in the 780M glass walk
(w1916) 104,092 of 127,346 unkept draws named a shadow among their reasons, and 12,637 of
225,984 draws were rebound.

The shadowed textures a draw uses are copied around its instance, which gathered them as the
draw took every step (render/shadows.rs), and shadow::join of an equal use changes nothing. So a
draw that uses the same shadowed textures, each as it used it, into the same instance gathers
nothing new. Such a draw is now kept:

- A draw again uses the kept draw's bindings, so its shadows. It counts the kept draw's reads
  through copies (attachment_reads_through_copies, own_pixel_reads), which move from the device's
  shared counters to the encoder's tally, as a draw again counts nothing others share.
- A draw rebound works out its shadows as every step does (RenderLowering::draw_shadows, now
  shared by both), binding a texture of the pass's attachments through its copy
  (Tables::with_attachments), and goes on only where they are the kept draw's, each the same
  shadow used as it was (ShadowUse::used_as: writes, the bounds of writes and reads), else it
  takes every step. A draw moved whose kept draw used no shadow still looks at none.
- A draw that reads a color its pass clears behind its load actions keeps nothing: its copy's
  clear or its split is its own. draws_unkept_shadowed now counts those, snapshots and
  extended-range shadows.

Verification: to follow (clippy, the runtime suite on lavapipe, a lane of kept shadowed draws).
(cherry picked from commit 68955761d2d9e3baa9a865856b82194be9809844)
2026-11-08 15:26:34 -08:00
Anees Iqbal e7757099bf Attached reads: a first copy in whose command writes the truth apart moves what it reads
ShadowSync::before took every texel at a command buffer's first use of a
shadow that may stand across command buffers, so the image would hold
them all for the command buffer's end. A draw that reads, at its own
pixels, the texture its own pass renders over a Private buffer's bytes
(an aliasing image) defeated that twice: the pass renders the shadow's
truth in place right after the copy, so no end leaves the image
standing, and a copy between two render pass instances is decided by no
batch's submission, so no standing can skip it. The walk's glass segment
moved 3,470 whole 3648x2038 copies so (25.8e9 texels, about 27.8M a
frame), each never standing.

Now the term is skipped where the command writes the shadow's truth apart
from it (writes_truth_apart: a use that writes the bytes, as a pass's
color attachment rendered in place does, or another shadow over them
written through): the copy moves what the command needs, an own-pixel
read's scissor a pixel wider each way. It gives up only a standing that a
later copy would have to take back whole; a gated copy before a pass
still moves nothing where the image stands.

Lane: tests::attached_read_standing over a surface plane of a Private
buffer whose image aliases its bytes: two pass-start reads in two command
buffers (a fill between) and a read after a draw and a barrier each copy
in 60 texels (the 8x4 scissor widened), and the bytes they leave are
Metal's answers (the texels from before the pass, the fill, the draw's).
Verified: cargo fmt only so far; the checks and the negative control run
as a potluck job.

(cherry picked from commit d0177e126ec9c2eec7ec502fbb02e8dfde6a445f)
2026-11-08 14:18:05 -08:00
Anees Iqbal 8b664a27a2 Shadow log names every shadow a texture makes; never-stood copies in split by what kept the end from standing
The walk's unskipped copies in are all of a 3648x2038 surface that never
stood, and the shadow log, which named only a texture over a buffer's bytes,
never named it. Two instruments to find out which shadow it is and why no
command buffer's end leaves it standing:

- METAL2VULKAN_LOG_SHADOWS now names each shadow a device makes of a
  texture: a usage shadow (a binding beyond its usage, an attached read, a
  YCbCr texture's writes), with what the texture's own image is (an aliasing
  image over the bytes with or without the feedback loop usage, a shadow, or
  an image of its own); a rotated texture's image of its stored frame and its
  twin; a two-plane extended-range texture's image; a depth or stencil
  texture's tiled twin over a surface plane; and a YCbCr texture's converted
  image and render shadow. A line's truth is the buffer's bytes or the
  texture's own image.
- WorkCounts::shadow_texels_never_stood_{unmet, not_current, dropped,
  partial, end} split shadow_texels_unskipped_never_stood by what last kept a
  command buffer's end from leaving the image standing
  (shadow_standing::Missed): no end met it, an encoder ended with its image
  not holding the truth, what the command buffer carried let it go, the end
  held it in part or stale, or the end records no standing. Each shadow that
  may stand keeps the last one; off the counts it changes nothing.

Verified: cargo fmt only so far; the checks run as a potluck job.
shadow_standing_device now asserts the five sum to never_stood and that a
first read's never-stood texels are all unmet.

(cherry picked from commit 1dd2a2ee2b9c39a2ba7aaeea3e3ad7906fd035f9)
2026-11-08 13:46:25 -08:00
Anees Iqbal ec94c62dce heap depth textures: a merge's keep holds the heap's bytes, not the image's
A 2-slice Depth32Float 64x64 x2 multisample texture in a Shared placement heap
on ANV (Iris Xe, RPL-P, Mesa 26.2.6) lost the samples a blit wrote into one
slice: 16384 of 16384 were off Metal's tiles after the merge back, while a
read straight from the image matched. The heap's bytes held 0xee before the
blit. The copy in hands the image 0xeeeeeeee, a float outside [0, 1], which
Vulkan leaves undefined in a depth image without
VK_EXT_depth_range_unrestricted, and ANV stores 0.0. The merge's keep was
moved out of the image (only drivers announced drawn-depth-copy kept the
heap's bytes), so it held 0.0, and the merge kept the heap's 0xee in every
byte of a written sample that equals 0.0's: a probe found 9155 0xee bytes
left in the slice, the 9134 zero bytes of the samples plus 21 sample bytes
that are 0xee, and no sample whole.

Now a heap's tiled texture with a depth aspect, of any sample count, keeps
the heap's bytes: the staging buffer its copy in filled where the keep
follows it (WorkCounts::shadow_keeps_from_staging), else the heap's bytes
themselves, and plans no moves out of the image for the keep. Every byte a
command wrote is merged whatever the copy in changed; a value the copy in
changed in a texel no command wrote is written back as stored, as a copy back
writes it.

That clamp is the device's: a heap's 32-bit float depth texture whose shadow
copies the heap's bytes into its image now announces restricted-depth-upload
as it is made, on a device without VK_EXT_depth_range_unrestricted whose
driver is not measured to keep such a value (ANV; not MoltenVK, NVIDIA or
lavapipe with the extension). Its declaration, docs/API.md's catalogue and a
device-gap row in docs/FAST-PATHS.md say so.

The measured drawn-depth-copy flag a multisample texture held for its keep
is gone with its one reader; the announcement at making stays.

heap_multisample_textures_keep_their_samples_in_metal_s_tiles now also
checks, for each counted 32-bit float depth texture, restricted-depth-upload
as it is made where the device clamps, and that a blit into one slice or
aspect keeps from staging. Verification in the tip report.

(cherry picked from commit 688e1dcc00ff67979833fdcbaf2f5484057e18a6)
2026-11-08 13:16:59 -08:00
Anees Iqbal 6ef13920d0 Shadow causes for a walk: why a private truth's first copy in moved, and a log of each shadow made
The 780M's glass composites copy large Private IOSurface planes in each command buffer: walk 9286
counted 41.07 M texels first copied in per composite, 37.70 M of them over images an earlier
command buffer left standing, yet only 3 copies in a composite were decided against a standing
(2 skipped) of 84 shadow copies. No count said where the rest were decided, nor why each shadow
over those planes takes no image over the bytes.

- WorkCounts::shadow_texels_unskipped_*: every encoder's first copy in of a Private (or
  Memoryless) buffer's bytes, an IOSurface plane's among them, that moved its texels, by where it
  was decided (shadow_standing::Unskipped): unstanding (its shadow never stands: untracked, a
  heap's, the caller's memory, its VkBuffer handed out, writes dropped), between_instances (a held
  render pass's copies between its instances, inline_splits, which no submission decides),
  after_encoder_writes, recorded_whole (predicated laying, no new VkCommandBuffer),
  command_buffer (at submission: its command buffer reaches unnamed memory or an earlier encoder
  wrote the truth or image), let_go (at submission: the standing let go). With
  shadow_texels_skipped_by_standing they sum to shadow_texels_first_copied_in_private_buffers +
  _private_surfaces. And, but for unstanding, by what the standing held then (shadow_standing::
  LetGo, Standings::let_go): stood, never_stood, unnamed_since, truth_written, image_written; for
  those decided as the encoder records them, by the batches submitted so far.
- METAL2VULKAN_LOG_SHADOWS (default-off diagnostic, shadow_log.rs): one line per shadow a device
  makes of a texture over a buffer's bytes: the call (new_texture_with_iosurface_plane for a
  plane's), format, size, levels, usage, the buffer's storage mode, length and object ID, the
  texels' offset and row pitch, and the reason its shadowed-texture notice gives (announced once
  a device). Two textures over the same bytes name the same object ID and offset.
- Standings::stands is folded into let_go; submit.rs's gate answers where it was decided.
- Tests: shadow_standing_device checks both sums in every leg, and the first read's copy in is
  let_go/never_stood, the read after another queue's fill let_go/truth_written, a read after its
  own command buffer's fill command_buffer, a read once the VkBuffer was handed out unstanding.
- Docs: shadow_standing.rs, WorkCounts, docs/API.md (the log), env_vars REGISTRY; the artifact
  test's note on the variables the runtime reads. api_signatures blessed.

No behaviour changes: counts and a default-off log only. RUNTIME_VERSION not bumped (main's).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit a82491daf4a24ad57845c6e0f62bd53946dc22f8)
2026-11-08 12:18:18 -08:00
Anees Iqbal d119fdeca7 YCbCr conversion: make its staging buffer, sets and refresh at its first conversion
A two-plane YCbCr texture whose planes a function reads in place still made
its conversion's staging buffer (the planes' whole byte range, 24.9 MB for a
4K x420 frame), its kernels' descriptor sets and its refresh as it was made,
though no function of it converted. On the 780M a texture made each frame
paid that every frame.

YCbCrConversion now holds what its making takes and makes the rest at its
first conversion: Encoder::plan_shadows prepares every shadow a command uses
(ShadowCopies::prepare), the one place a copy in is planned. The device's
own conversion is still announced as the texture is made. The converted
image itself is still made with the texture.

Test: ycbcr_in_place_loop::a_texture_read_only_in_place_makes_no_conversion
(no scratch buffer after two sampling dispatches of a texture read in
place; one after its first read()).

(cherry picked from commit 05cb080a878384e254921d0d97b4b7872ee4c175)
2026-11-08 06:29:47 -08:00
Anees Iqbal beaa159d4f Count a tiled texture's shadow as used only where a command uses its first level
shadow::copies_used matched a command's uses to a shadow by its key alone, and
render/shadows.rs took every attachment of a shadowed texture as a use of its
shadow. A tiled texture of more than one level (Buffer::new_tiled_texture) is one
image whose first level alone is a copy of the bytes (shadow_range levels 0..1),
so a command that used only its later levels was planned as a use of the first:
a blit into or out of level k copied level 0 in, and after a write copied it back
or, over a Shared buffer, kept and merged it; generate_mipmaps' chain (read N,
write N+1) left level 0 dirty and merged it back at the end of the encoder, a
merge that stored nothing. WindowServer makes such textures in its first seconds.

ShadowCopies::holds: a use names the shadow where it holds a copy of the truth,
its key in a range that meets shadow_range. copies_used counts only those uses
(and writes only theirs); attachment_shadows and count_colors take an attachment's
shadow only where the attachment's level and layers meet it (held_shadow). Every
other shadow's range covers its whole image (or, for a heap's two-plane texture,
its first level, whose later levels likewise lie in the image alone), so nothing
else changes.

Verified by the device tests of the commit before: see the tip's evidence.

(cherry picked from commit 35d39664702c4d34219226ca2bee6755365737e3)
2026-11-08 02:57:26 -08:00
Anees Iqbal c871b2f328 Name an image shadow's truth as each copy is recorded, so a storage form's swap leaves no shadow on the old image
On the M3 (MoltenVK), tests::self_read_storage::a_fetch_after_a_pinned_reader_renders_through_a_stand_in_from_the_fetch_on
died with SIGSEGV in its second pass, in MVKCmdCopyImage::validate under vkCmdCopyImage
(m3-max-6939, 6950: shadow.rs ShadowCopy::record_gated <- EncoderCore::held_shadow_copies <-
render/inline_splits.rs record_kept <- draw). The first pass's reader samples the target while
the pass renders it, so its slot binding takes the texture's usage shadow
(texture/attached_reads.rs, texture/usage_shadow.rs), whose ShadowSource::Image held the
image's VkImage as it was when the shadow was made. That pass's fetch notes the target for its
storage form, and its commit swapped the image's VkImage for one with STORAGE and destroyed the
first as it completed (texture/storage_form.rs). The second pass's copy into the kept shadow
then named the destroyed image.

ShadowSource::Image now holds the image itself (shadow::ImageTruth, which texture::Image takes
as its own_raw) and each copy names its VkImage as it is recorded. Every image shadow made over
a texture's image goes through texture/view_shadow.rs (a usage shadow, a reinterpreted view, a
view's render shadow), so none keeps the old image after a swap. The swap happens at the commit
of the device's only uncommitted command buffer, so no recording names either image across it;
the regions, formats and identity are the same before and after (the storage form differs only
in STORAGE usage). The storage form docs say so.

Lavapipe and the Iris did not show it: there the reader takes the snapshot path and binds no
usage shadow. A device whose reader splits for want of STORAGE (be1f1c141b notes the form there)
binds the shadow and then takes the swap, so the same use after free is expected there too
(unaudited: only the M3 run shows it).

Verified: on the M3 at df733261f6, m3-max-7009: both self_read_storage tests passed 3 of 3, the
fetch test through both passes (pass 1 [1, 0, 0, 0, 0]); 53 of 53 tests filtered by shadow, usage
and view shadows, storage forms, attached reads, fetch, snapshot, self-read, stand-in and
reinterpretation passed. Negative control: 1a5e185801 alone crashed in pass 1 in 4 of 4 runs
(m3-max-6934, 6939). Lavapipe and clippy --cfg m2v_cpu_icd: gem10 m3-max-7004, follows.

(cherry picked from commit df733261f6)
2026-11-07 21:20:05 -08:00
Anees Iqbal d946043cc5 Lay a heap's one-plane YCbCr rows off 16 bytes as Metal's blits do, sharing bytes
Item 2 laid a heap's one-plane YCbCr texture whose row is not a multiple
of 16 bytes in packed rows and announced heap-one-plane-layout. Metal's
blits lay such a row, where it is 16 bytes or more, the row rounded down
to 16 bytes apart, so consecutive rows share its last row % 16 bytes,
and its copies out read each row whole from there (an Apple M3 Max under
macOS 27.0.1, probes/one_plane_ycbcr_heap_rows.m, m3-max-5064: 10 x 3,
12 x 3, 13 x 7, 20 x 3, 33 x 3 and 100 x 30 at 4:2:2, 10 x 3, 13 x 7 and
33 x 3 at 4:4:4, and a 13 x 7 x 3 array, whose slices lie as its answer
counts them; each last byte written matches this layout's span). That
layout is one we can read, so the runtime now takes it.

heap_plane_layout gives a one-plane plane one_plane_pitch: row - row % 16
for a row of 16 bytes or more in more than one row, a packed row else;
an array's slices stay where the answer counts them. heap_planes returns
the copies into the shadow's image and back out of it apart
(PlaneCopies); a plane whose rows share bytes takes plane_copy_regions,
the copies an IOSurface plane whose GPU rows share bytes takes: into the
image each row whole from its own offset in two regions a slice, the
shared bytes read for both rows; back each byte once, a shared one from
the earlier row. Metal's blits leave the shared bytes from no one row
(the even rows' at 10 x 3, 12 x 3, 20 x 3 and 13 x 7, the later row's at
33 x 3, the earlier row's at 100 x 30); the earlier row's is one of
them, said in docs/API.md's accepted differences.

Still announced heap-one-plane-layout: rows under 16 bytes, which Metal
lays 16 apart past the answer and whose copies out read none of the rows
past the first back, and mipmapped and 3D textures. The notice's doc,
cost and catalogue entry say so.

Tests: tests::heap's a_heap_one_plane_texture_s_rows_lie_as_metal_s_blits
_lay_them (no device) holds the pitches, slice pitches and spans to the
probe's for eight shapes, every texel read into the image from its own
offset, and every byte written back once, a shared one from the earlier
row; the device test heap_one_plane_rows lays 13 x 7, 33 x 3 and a
13 x 7 x 3 array at 4:2:2 and 4:4:4 in the heap's bytes as Metal does
with no notice, and announces a 6 x 3; the lane test makes a 13 x 7 with
no notice and announces a 6 x 3 and a mipmapped one.

(cherry picked from commit ff300cc511502049e318d113015a5e2c14cb4645)
2026-11-07 15:23:32 -08:00
Anees Iqbal 803648acd8 Make a texture buffer over a buffer whose texels run past its length, those texels in a tail
What. Buffer::new_texture of a texture buffer whose texels run past
the buffer's length (inside Metal's allocation rule) is made instead
of returning NotImplemented(TexelsPastBufferLength), as a 2D texture
or array already is. Its texels inside the length are the buffer's
bytes; those past it lie in a tail of its own, a zeroed Shared buffer
the runtime owns, laid out from the functions' first byte (the offset
rounded down to 16, as Metal's kernels read a texture buffer).
- GPU: the texture buffer takes the staged form (StagedTextureBuffer,
  announced): its bindings view the tail as their staging buffer. The
  copy in takes the bytes inside the length from the buffer (none
  where the texels lie wholly past it), the copy back gives only those
  bytes back, and a Shared buffer's merge copies the current part from
  and to the buffer and the tail apart (staged_bytes, which now names
  a texture buffer's staging buffer as well as an image's, and
  record_out, which copies the staging buffer's every byte).
- CPU and blits: as for 2D, each row split at the length
  (Texels::past, whose rebase is now the tail's base, tail_base).
Only an IOSurface plane past its surface stays
NotImplemented(TexelsPastBufferLength); the gap's doc, its reach in
scripts/refusal-surface/reach.tsv, the StagedTextureBuffer catalogue
entry and docs/API.md's accepted difference say so.

Why. Plain Metal makes these: reims-vgpu's tbprobe on both x86 oracle
Macs (jobs m3-max-4019, 4046, 4152) and the M3 Max probe
(probes/texture_buffer_past_length.m, job m3-max-4617), whose paths
read and write the bytes past the length as one memory, as a 2D
texture's. The tail gives the 20000-byte buffer's answer for every
shape, as the 2D tail does.

Tests.
- tests/buffer_tail_device.rs: a texture buffer of 64 R32Uint texels
  from 3968 of a 4096-byte buffer (32 past) and from 4096 (all past):
  as made, after a kernel's write across the length (ob1_texel_buffer)
  and after replace_region past it, a kernel, get_bytes and a blit
  read alike; the buffer's words inside the length are written, every
  other word and 16 buffers around it keep theirs.
- linear_plan unit rows: texture buffers past the length made.
- runtime_lane::buffer_textures: the texture buffer at 3968 is made.
- Conformance: buffer-tails-texture-buffer, 1024 R32Uint texels from
  16384 of a 20000-byte buffer (904 inside): ob1_texel_buffer reads
  and writes, getBytes, replaceRegion, blits from and into it, the
  buffer's bytes; recorded on the M3 Max (3 runs, one outcome, every
  site the model's answer).

Verified:
- M3 Max, macOS 27.0.1: the probe (m3-max-4617) and the recording
  (m3-max-4640): buffer-tails-texture-buffer is made, announcing only
  the staged-texture-buffer notice, and the 2D tail cases still are.
- gem10 (m3-max-4635): clippy of the runtime (all targets, all
  features) and of runtime and validation under --cfg m2v_cpu_icd;
  the runtime's unit tests (70 of 70); the runtime lane on lavapipe
  (172 of 172, the new texture-buffer test among them); the
  buffer_textures, texel_swizzles and degrade_notices validation lanes
  (27 of 27).
- gem10 (m3-max-4662): rustdoc of runtime and conformance; the
  conformance unit tests over the tails, refusal, catalogue and
  accepted-difference rows (20 of 20); a lavapipe replay of the six
  buffer-texture cases, all six announced as the ledger expects.
  Clippy there named the shape test's two constant assertions, now
  const blocks; clippy of runtime and conformance and those unit
  tests again on this tree: m3-max-4688.
- Negative control (m3-max-4662): the runtime's sources at 5020e74ebb
  with these tests and cases fail the new device test with
  NotImplemented(TexelsPastBufferLength), and the replay refuses
  buffer-tails-texture-buffer at case/texture.

(cherry picked from commit f0a3390160064eabb820fbdc4f83822e0492fb5f)
2026-11-07 11:19:37 -08:00
Anees Iqbal 9ee7323e76 Make a 2D texture over a buffer whose texels run past its length, those texels in a tail
What. Buffer::new_texture and new_linear_texture of a 2D texture or a
2D array whose texels run past the buffer's length (inside Metal's
allocation rule, past which Metal answers nil and so does the plan)
are made instead of returning NotImplemented(TexelsPastBufferLength).
The texels inside the length are the buffer's bytes, exactly as
before; those past it lie in a tail of the texture's own: a zeroed
Shared buffer the runtime owns (Texels::tail), laid out from the
texels' first byte, and no other allocation's memory.
- GPU: such a texture is kept as a shadow image (ShadowedTexture is
  announced). The tail is the shadow's staging buffer; its copy in
  takes the bytes inside the length from the buffer, its copy back
  (staging rows clipped by inside_rows) writes only those bytes back
  to the buffer, and a Shared buffer's merge copies the current part
  from and to the buffer and the tail apart (shadow_merge.rs).
- CPU: getBytes and replaceRegion split each row at the length
  (past_runs, write_past).
- Blits: copies that name the texture's bytes split their rows at
  each side's length (RowsCopy::split) and copy the part past it
  from or to the tail; a copy with an ordinary texture goes through a
  scratch buffer of the encoder; synchronizeResource covers the bytes
  inside the length; the extended-range rewrite announces its note
  rather than binding the buffer's words past the length.
Texture buffers and IOSurface planes past the length stay
NotImplemented(TexelsPastBufferLength), whose doc now says so.

Why. Plain Metal makes these textures: reims-vgpu's oracle on the
AMD 5300M and the UHD 630 (4096-byte buffer, 64x16 and 64x17 at rows
of 256, offsets 0, 256 and 2048) and the M3 Max probe
(probes/texels_past_buffer_length.m, job m3-max-4337) for the same
shapes. Under Policy::Dies the refusal ended the consumer's host. The
M3 Max's paths agree that the bytes past the length are one memory:
the next allocation's over a 4096-byte buffer, the allocation's own
zeros over a 20000-byte one, read and written alike by every path.
The tail is the second answer for every shape; docs/API.md's accepted
differences records that the runtime never reads or writes another
allocation there.

Tests.
- tests/buffer_tail_device.rs (m2v_gpu / m2v_cpu_icd): 64x17 over
  4096 bytes, 64x16 at 2048, 64x80 over 20000 bytes (row 78 across
  the length), 64x1 wholly past, a Private buffer's, and a 2D array
  whose second slice is past the length; each path (kernel, blit,
  CPU) reads what each other path wrote, the buffer keeps its bytes,
  and 16 buffers around it keep theirs.
- Unit tests: linear_plan expectations (2D and array past the length
  made, texture buffers refused), RowsCopy::split, inside_rows.
- Conformance: buffer-tails-kernels (scout_read_u / scout_write_u,
  getBytes, replaceRegion, the buffer's bytes) and buffer-tails-blits
  (blits from a buffer across the length and from a texture past it,
  a copy out into a texture, blit and getBytes reads), RGBA8Uint
  16x256 at offset 4096 over 20000 bytes, recorded on the M3 Max
  (3 runs, one outcome, every value the model's).
- The runtime_lane assertion that a 2D array past the length is
  refused now asserts it is made.
REFUSALS.md and CONFORMANCE-COVERAGE.md regenerated.

Verified:
- M3 Max, macOS 27.0.1: probe m3-max-4337 (the shapes above); record
  m3-max-4492 (both cases, 3 runs, one outcome each, every site the
  model's answer); replay on MoltenVK m3-max-4508: buffer-tails-* and
  the four buffer-texture(s)-* cases announced (every value exact).
- gem10, lavapipe (LLVM 23.1.4, 256 bits), m3-max-4509: unit 71/71
  (linear_plan, buffer_texture, blit_plan, tail); device tests under
  m2v_cpu_icd 139/139 (the four buffer_tail_device tests and every
  buffer_texture, shadow and blit test); runtime_lane::buffer_textures
  7/7; conformance replay of the same six cases: all announced.
- Negative control, same job: the runtime's sources at 0e2c70f08f with
  these tests: the four device tests fail at Buffer::new_texture with
  NotImplemented(TexelsPastBufferLength), and both conformance cases
  are refused with it (case/texture, case/work).
- m3-max-4565: clippy -D warnings (runtime and conformance; runtime
  and validation under m2v_cpu_icd), rustdoc -D warnings, unit
  rows_split, buffer_tails, refusal and api_surface tests.

(cherry picked from commit e483e17c6c4d087a50a95cda297cf291934bee54)
2026-11-07 10:44:25 -08:00
Anees Iqbal a57e6c770a Copy a standing shadow in whole at its command buffer's first use
A pass that loads a shadow and draws under a scissor copied in only the
scissor's texels, so the image held only those: a later command of the
same command buffer reading every texel copied them all in again (beyond
what it held), and the command buffer's end, holding less than every
texel, left no standing. On the M3 the padded Private plane's Write frame
(a scissored pass, then a pass sampling the surface whole) planned
9478144 texels in a frame and skipped only the scissor's 262144 (job
m3-max-1937); WriteThenReadApart's writer never stood.

At a command buffer's first use of a shadow that may stand across
command buffers, the copy in takes every texel, as over logged host
pages: it moves nothing where the image stands, and leaves the image
holding every texel for the command buffer's later commands and its end.

The device test adds a pass that draws inside four rows: its load takes
the standing image, and the next command buffer's read stands and holds
the pass's rows over the earlier texels. API.md's catalogue entry says
the scissor cut does not apply to that first use.

Verified: runs next on the M3 with the controls.
(cherry picked from commit 258964cc06d8c4da64866b6991ec8b46906fa504)
2026-11-05 13:14:47 -08:00