Commit Graph
35 Commits
Author SHA1 Message Date
Anees Iqbal d8666d430f RUNTIME 2302: render encoders record into the VkCommandBuffer of the encoders before them
A render encoder took a VkCommandBuffer of its own at every open, so a compute, render
and blit step began 2.71 and submitted 4 VkCommandBuffers per step (dispatch_chain
renders, lavapipe). A render encoder with a log of its calls now takes part in the
encoder fold:

- One whose pass records at its end (draws in a secondary) joins the group before it;
  one whose first instance records inline joins none and may lead a group.
- No barrier records inside a pass: a joined render encoder records one barrier from
  everything of the group's earlier encoders (FoldOrder::everything) at its open,
  counted in command_barriers.
- Color groups, rasterization-rate maps and a depth attachment out of GENERAL take no
  group; segments, fence updates and Overwrites end the group after the encoder.
  Logless devices keep one VkCommandBuffer per render encoder.
- A folded member's layout moves go before its group's first part (GroupPlaces).
- A check splits a group with a render member at its pass's submission (as RUNTIME
  2297 does for blits).
- A group's order is built as its second encoder joins, not as its first ends.

A/B (lavapipe, dispatch_chain, per step, base vs tip): renders 2.71 -> 1.35
VkCommandBuffers begun, 4 -> 2 submitted, GPU 119.5 -> 97.7 us; renders-apart
3.71 -> 1.00, 4 -> about 0, 143.6 -> 94.6 us; passes unchanged in buffers, the
encoder's open about 250-480 ns more on the host (the group an inline pass begins),
the whole pass within the host's noise.

Tests: tests::render_fold (device), tests::held_depth, shadow_runs' rebind expectation
(a rebind encodes a group whole). Docs: encoder_fold.rs, API.md, FAST-PATHS known gap
and ANV row.

Verified (msi, lavapipe): the full runtime suite 2683/2684 at c502efba29, the one
failure the race test fixed in ca5042567b; clippy plain and --cfg m2v_cpu_icd, rustdoc,
fast_paths 0. Negative control (the explicit order removed, renderfold-negctl): the
hazard tests fail on their barrier counts; lavapipe shows no wrong texel because it
completes each command as it runs, so the texel proof is a GPU that overlaps work.
2026-11-14 08:59:50 -08:00
Anees Iqbal ca5042567b encoder_fold: the race test waits for the check's failure to be noted, not for its call
a_check_that_fails_a_submission_before_its_group_is_split_keeps_it_failed
let the commit's encodings again go once the check closure signalled from
inside its call. The scheduler notes the failure (State::fail_submission,
which marks the encoders unrunnable) only after the closure returns, so the
encodings again could build their units and splice the blit's in between:
the full lavapipe runtime suite at the render fold's tip (m3-max-29520)
counted 4 encoded again against 3. The blit still ran nothing there (the
failure, noted after the splice, cleared its part), so this is the test's
race, not the product's.

The test now holds the turn until the command buffer's failure is noted
(failure_noted, a test-only reading of State::failure, set under the state
lock after the encoders are marked), then lets the encodings again go.

Verified (msi lavapipe): encoder_fold 22/22; clippy 0 (--cfg m2v_cpu_icd and plain); control
m3-max-29567 (unrunnable marks removed) fails the test (4 vs 3).
2026-11-14 08:56:54 -08:00
Anees Iqbal 38673ec995 RUNTIME 2299: a check that fails a submission before its group is split keeps it failed
A check may run on the scheduler's thread while a commit's encodings again
are pending: the scheduler takes the checks of the batches it holds before
the first submission, which waits for the encodings, is submitted. With a
check split (RUNTIME 2297), a group whose VkCommandBuffer holds commands of
two of Metal's submissions is encoded again apart at the commit; where the
check failed one of those submissions first, the split's splice put the
failed encoders' encodings into parts the failure had cleared, and they ran.
Found by the render fold's check test (a render pass between two compute
encoders: the pass drew).

fail_submission now marks the failed encoders unrunnable, as a rebound or
detached submission's are. The commit's split and a rebind's turn encode no
unrunnable encoder again, and an encoding again whose encoder became
unrunnable meanwhile takes no place while the unit's others take theirs
(before, splice_fits refused the whole unit for a rebound one).

Test: encoder_fold's
a_check_that_fails_a_submission_before_its_group_is_split_keeps_it_failed
holds the command buffer's turn of encodings again (a test-only guard) until
the check failed the blit's submission, then expects the blit's fill not to
have run and the three compute encoders to have.

Verified (msi lavapipe): m3-max-29383 at the tip: clippy -D warnings (runtime, all
features and targets) 0 under --cfg m2v_cpu_icd and plain; runtime fold/rebind/
reencode/check/commit tests 374/375 (the other: a queue_share idle-budget timing test
under load, no check or re-encode, fixed apart); validation submission_checks and
failed_commits 16/16. Negative control m3-max-29384 (unrunnable marks removed): the
new test fails, the blit re-encoded (4 against 3).
2026-11-14 08:08:29 -08:00
Anees Iqbal 8c5a1d592a RUNTIME 2297: fold groups split at Metal's submissions where a check or a rebind fails one
RUNTIME 2293's blit fold records a blit encoder and the compute encoders
around it into one VkCommandBuffer, and those are separate Metal
submissions, which a submission check or a rebind's EncodedUseRebound fails
one at a time. Pin 90's lavapipe suite failed two tests on it (m3-max-29286
at 2293's parent passes; m3-max-29287 at 2293 fails these two):
- submission_checks::a_submission_detached_behind_a_wait_fails_alone: the
  check failed the blit's submission, whose part holds no VkCommandBuffer,
  and its fill ran inside the compute encoder's;
- rebind_reach::a_unit_s_encoder_that_laid_its_first_step_fails_encoded_use_rebound:
  the group could not be encoded again whole (the compute encoder laid its
  unit's first predication step and keeps no log), so the rebind refused
  the blit too, which Metal runs over the new pages.

Now:
- Each encoder notes whether a command of its own recorded into the
  group's shared tail (EncoderCore::in_tail; a group's first encoder always
  does). With a submission check set, the commit encodes again apart only
  those tail encoders, where they span more than one Metal submission and
  each can be re-encoded exactly (log kept, no segment). Otherwise a check
  failing one of those submissions fails all of them (State::widened), so
  the tail runs whole or not at all. Encoders whose commands all lie in
  their own VkCommandBuffers fail with their own submission alone.
- A rebind of a group that cannot be encoded again whole splits it where
  each encoder that cannot lies in a submission the rebind fails anyway
  (State::split_rebound); the group's other encoders are encoded again
  apart and run.
The FAST-PATHS known gap and API.md's committed-as-failed section say what
still differs from Metal: a shared recording that cannot be split fails
every submission whose commands it holds, and a rebind is refused where an
encoder that cannot be re-encoded sits in a submission that still runs.
No application of ours sets a submission check (reims-vgpu does not).

New test: submission_checks::a_check_failing_one_submission_a_shared_recording_holds_fails_each_it_holds.

Verified (msi lavapipe, --cfg m2v_cpu_icd): m3-max-29331 at the tip:
clippy -D warnings (all features and targets, runtime + validation) 0 under
m2v_cpu_icd and plain; 402/402 tests (rebind_reach, submission_checks,
failed_commits, predication, rebinds, indirect, encoder_fold, command_buffer,
fast_paths and pin 90's four). Negative controls on development's runtime
sources (m3-max-29315, 29330): rebind_reach, wcdc and the new test fail.
2026-11-14 07:23:37 -08:00
Anees Iqbal 12cd9c6f79 RUNTIME 2293: blit encoders fold into the shared VkCommandBuffer as compute encoders do
A command buffer that mixes compute and blit encoders (the image workloads:
Photo Filter, HDR, RAW) began a VkCommandBuffer for every blit encoder, which
also ended the compute encoders' fold: dispatch_chain's blits shape (200
one-dispatch compute encoders each followed by a blit copy) went to the queue
as 799 VkCommandBuffers in one vkQueueSubmit (542 begun) on lavapipe, against 1
for compute encoders alone. On ANV each begin costs 16-20 us of host time.

A blit encoder now joins the group of encoders its command buffer's tail holds
by the rules compute encoders follow (encoder_fold.rs): same batch, the earlier
member one part with no segment, no fence update and nothing failing, no
command predication yet, the encoder trail off, protection options 0; a
compute encoder joins where the group's compute encoders are of its dispatch
type (Joining::{Compute, Blit}). Blit commands take the per-command FoldOrder
barrier through track(). What differs for blits:

- Blit encoders now always log their calls (replay.rs), as compute encoders
  do, so a failure that splits a mixed group encodes its running members
  again apart.
- A blit encoder ends a unit of command predication, so a group can hold two
  units' compute encoders: an unbalanced record whose left-out work begins
  past the group's first encoder (State::left_out_from, set by
  leave_out_ended) now splits the group at the commit as a partial failure
  does, the shared VkCommandBuffer never submitted. split_failure and the
  rebind's encoded_together take one check, State::encodes_again_apart: no
  predication, a non-compute encoder, or Predication::alone. A rebind in a
  command buffer that used predication now encodes a group again where each
  member is alone, where before it refused (EncodedUseRebound).
- An encoder whose part writes an ASTC carrier (its second twin's decode goes
  after the part) or notes an Overwrite (judged by its part's summary, which
  a group widens) ends its group. A folded blit's Overwrite goes to the
  group's first part only where every earlier member is a blit encoder that
  named nothing of the texture (Fold::overwrites_join), which is what
  first_overwrites decided before folding.
- Spares tests that need one VkCommandBuffer per blit encoder update a fence
  in each.

Tests (tests::encoder_fold): a compute/blit/compute chain is one
VkCommandBuffer with every copy and read right; an event signal, a dispatch
type change across a blit, predication, a whole-texture overwrite and an ASTC
carrier write each end a group; failures inside a mixed group run exactly
the encoders they leave; an unbalanced End past a group's first encoder
splits it; a rebind encodes a group again in a predicated command buffer.

Also: dispatch_chain gains the `blits` shape (a blit copy after each one-dispatch compute encoder)
and the `copies` shape (a command buffer of blit encoders only).

Verified (blitfold, msi lavapipe): m3-max-29164 at 5845456c61: clippy (runtime, cfg m2v_cpu_icd,
all targets/features, -D warnings) 0; 185/185 including the encoder_fold tests and
a_rebind_encodes_a_group_again_in_a_command_buffer_of_command_predication (the narrowed refusal:
words right, reencodes_refused 0; REFUSALS.md regenerated, unchanged). A/B m3-max-29165 (own target
dirs, md5 c2157758 base 45fdc3e601 / a2214763 tip, ABAB): VkCommandBuffers begun/submitted per Metal
CB, 200 dispatches: blits 542/799 -> 1/1, copies 271/399 -> 1/1, encoders 1/1 -> 1/1; lavapipe GPU
us a dispatch blits 54.98 -> 37.35, copies 9.25 -> 2.36, encoders unchanged; host thread CPU blits
~-1.1 us a dispatch, copies even (logging ~+300 ns a blit encoder paid back by no new
VkCommandBuffer and a shorter commit). No WorkCounts field or Degradation kind. Negative control,
lint in the other configurations and the suites run after landing.
2026-11-14 05:59:35 -08:00
Anees Iqbal 82ef730d1d reencode: take the split units whole, as clippy asks
clippy's drain_collect: draining all of split_units into a new Vec of the same
type; std::mem::take moves them without a new allocation.
2026-11-14 02:06:05 -08:00
Anees Iqbal 7af3c4228a RUNTIME 2272: a failure inside a group of folded compute encoders fails only the encoders it names
RUNTIME 2268 failed a whole group of compute encoders recorded into one
VkCommandBuffer when a failure (commit_failed's From(n) or Set, a fault, a
recording failure) named only some of them. Metal runs every encoder the
failure leaves, so a From(n) inside a group dropped the work of the
encoders before n: a consumer's protection probe (a compute encoder, then
one made under protection options it fails From) read the first encoder's
words as never written.

Now every compute encoder logs its calls (replay.rs), a closed group keeps
its members' logs until the commit, and the commit splits a group its
failure fails in part (State::split_failure): the members that run are
encoded again from their logs, each into VkCommandBuffers of its own, in
the commit's call before the scheduler sees the batches (the rebind's
encode-again path, held by the same mark); the shared VkCommandBuffer is
never submitted and the failed members run nothing. Groups no failure
splits give their logs back at the commit. The split also works in a
command buffer that used command predication where its encoders are alone.
The one remaining difference (docs/API.md section 10, FAST-PATHS known
gaps): a group whose predication unit later laid a loop
(encode_start_while / encode_start_do_while) or left a record unbalanced
still fails whole.

pending_rebind's test reaches its no-log case through an If opened by the
encoder before (Unlogged::Predicated), since compute encoders now always
log; Unlogged::NoCalls's doc and notice text name what logs nothing now.

Cost (dchain, 5080 node CPU, dispatch_chain --host 20 --runs 9 --only
encoders --dispatches 2300, no host-page buffer, ABAB, ns a dispatch):
thread_cpu 3393/3396 -> 3539/3809; commit 113-126 -> 221-223 (logs held
until commit; a follow-up gives them back under one lock and keeps them as
spares); bind 49-50 -> 96-97 (the log itself, stays).

RUNTIME_VERSION 2272: folded groups split at a partial failure.

Verified (dchain): lavapipe full runtime suite at c118ca6fb6 (m3-max-28648)
2581 passed, 1 failed (host_ram_copy_device private-bit, the same at
09068993d6, owned by roip); pending_rebind negative control (guard removed)
fails on VUID-VkDescriptorBufferInfo-buffer-parameter; RTX 5080 208/208
(encoder_fold, rebind, reencode, command_buffer, dispatch, predication,
replay, fence, indirect, compute, failed); negative control at dd286c7304
(m3-max-28590): the four failure tests fail, the consumer-shaped one
included.

Squashed from steelbrain/dchain2 89480ccfd3..c118ca6fb6.
2026-11-14 01:59:11 -08:00
Anees Iqbal d166086d92 RUNTIME 2270: an encoder's open looks at the encoders ended since the open before, not every earlier one
Every compute and render encoder's open built what it starts with (the shadowed textures
its command buffer's ended encoders made resident) from scratch: the command buffer's
joined residency, then each ended encoder not joined yet, one shadows_onto each. The joined
residency advances only where the command buffer's own work reads it, so a command buffer
of n compute encoders walked n(n-1)/2 ended encoders: at Geekbench Fluid's ~2300
one-dispatch encoders a command buffer, the open grew to ~2.9 us a dispatch on lavapipe
(866 ns at 6 encoders), and reims's decodeperf profile (M3, MoltenVK) put
inherited_residency and shadows_onto at 762 of open_compute's 874 samples.

The command buffer now keeps what its next compute and its next render encoder start with,
with the number of ended encoders it took in (State::inherits): an open takes in the
encoders ended since, each once, in the order they ended, and hands out a copy (a count:
the residency's resources are shared until one copy changes). It is let go of where the
joined residency or an ended encoder's residency may change: joined_residency (every read
that joins, the heaps' textures made since, the first submission, a re-encode) and a
re-encode's splice of an encoder's residency. The result is the one the walk made: the
joined residency's shadows first, then each ended encoder's onto them in order, usages and
stages joined as before.

Counted: WorkCounts::ended_residencies_looked_at (an ended encoder's residency looked at for
an open's inherited shadows). Tests (tests::joined_residency): 64 encoders with a read of
the residency after the 32nd look at 62 residencies (the walk: 992); a shadowed texture made
resident for reading, then writing, reaches the next encoder with its usage widened.

RUNTIME_VERSION 2270: an encoder open inherits residency incrementally (the same result).

Also (compenc): dispatch_chain gains --host (each encoder call and the commit timed on the calling thread, commit_and_submit, per-thread CPU on Linux), --binds 4|tex (four buffers, or the Geekbench compute shape: 2 textures, a sampler, an output buffer and setBytes) and --pages (buffers over host pages).

Verified (compenc, msi lavapipe): touched tests 165/165 (m3-max-28544) incl. tests::joined_residency: 64 encoders with a residency read after the 32nd look at 62 ended residencies; a shadowed texture made resident READ then WRITE reaches the next encoder as written. Negative control (drop the slots every open, m3-max-28547): 992 vs 62, fails. Release dispatch_chain --host --only encoders --dispatches 2300 --binds 4, ns a dispatch: open 2862 -> 573, encode 7332 -> 5004, thread CPU 7532 -> 5205 (jobs 28534/28545); ended_residencies_looked_at 1.00 a dispatch. SR-like (6 encoders a CB) unchanged (866 -> 913). Clippy x3 and rustdoc run after landing.

Squashed from steelbrain/compenc d0d524b6de..84b304c5e3.
2026-11-14 01:18:32 -08:00
Anees Iqbal dd286c7304 RUNTIME 2268: record consecutive compute encoders of a command buffer into one VkCommandBuffer
A command buffer of N one-dispatch compute encoders went to the queue as
2N - 1 command buffers (each encoder's primary and a kept barrier command
buffer before it). A compute encoder now records on in the tail of the
compute encoder before it where nothing needs a boundary: same dispatch
type and logging, same batch (no event wait or signal, no host step), the
earlier encoder one plain part (no segment, no fence update, nothing
failing or faulting), no command predication, encoder trail off,
protection options 0.

The barrier between the two is recorded per command by the tracker's own
rule between two encoders of a batch (encoder_fold::FoldOrder), joined with
the encoder's own serial barrier into one vkCmdPipelineBarrier. The folded
encoder's uses and fence waits join the group's first part's summary, so
the batch's plan orders the group as a whole; its own part keeps its fence
updates alone. A rebind encodes a group again whole or not at all; a
failure that fails one encoder of a group fails the group (docs/API.md
section 10, "A command buffer committed as failed"). Counted:
WorkCounts::encoders_folded. FAST-PATHS: the ANV command-buffer row notes
folded encoders begin none.

Also: the dispatch_chain example (gbkern, dchain): a chain of dependent
dispatches by how a command buffer holds them (encoders, serial, raw
barrier, raw split), with each shape's first command buffer's counts.

RUNTIME_VERSION 2268: compute encoders fold into one VkCommandBuffer.

Verified (dchain, at d7e4a9ce51, the same diff before its rebase):
- lavapipe (m2v_cpu_icd): 40 tests incl. 8 new tests::encoder_fold (dependent
  chain, independent encoders take no barrier, dispatch-type change, fence
  update ends a group, commit_failed inside/at a boundary, rebind re-encodes
  a group whole).
- RTX 5080 (m2v_gpu, b5080): 190 touched-family tests; FOLD-CHAIN folded 23,
  begun 1, barriers 17, 0 wrong words.
- 5080 dispatch_chain, encoders shape, GPU us a dispatch: 1000: 8.41 -> 2.92,
  2300: 7.43 -> 2.92 (raw barrier 2.92); vkQueueSubmit per command buffer at
  2300: 1007 -> 44.6 us; command buffers submitted 2N -> 2.
Owed after landing: the negative control (fold barrier removed reads wrong
words), clippy x3, rustdoc, the full lavapipe runtime suite at the rebased tip
(m3-max-28507), the 780M and XTX before/after.

Squashed from steelbrain/dchain f51ba34c37..2f2000cfbc.
2026-11-14 00:57:33 -08:00
Anees Iqbal 490db00052 Re-encode: the encoder's last part read from the back
Clippy's double_ended_iterator_last on 14854f2473's lint job.
2026-11-12 14:03:31 -08:00
Anees Iqbal 6014ad370d Faces: a logged pass turns, and an encoding again meets the faces as first met
While the device has a buffer over host pages, every render pass logs its calls for a rebind,
and a pass with a log, or with an earlier encoder of its command buffer keeping one, turned no
texture (Unturned::Pass): under a consumer that keeps host-page buffers alive, no attached read
ever took the turn and every one copied in.

A logged pass now turns as any other. A rebind's encoding again of the command buffer's encoders
meets the faces as their first encodings met them: the encoding again runs with a thread-local
context of the command buffer and the encoder's parts (with_faces_as_of); a texture a later pass
of the command buffer turned presents the face from before that turn to it (Faces::face), and
the turning pass encoded again takes its turn again (Texture::retake_turn: the shadow of the face
from before the turn held current, no copy in). Any other pass encoded again turns nothing.
TurnPoint drops logs_kept; SwapRecord keeps the face it turned from.

The shadow log (METAL2VULKAN_LOG_SHADOWS) also names, once per shadowed texture, at the first
draw that binds it after its shadow was made: the slot, whether the function fetches, samples or
writes it, and each sampler's min, mag and mip filters (a sampler state's by Metal's names, a
constexpr sampler's as the layout bakes it).

Tests: the runtime's attached_read_faces gains a lane with a host-page buffer alive (a logged
pass turns; a blit and a turning pass behind a shared-event wait, encoded again by a rebind, read
the texels from before the turn), against the same lane beside an open command buffer (the copy
route); the validation crate's runtime_lane::logged_face_turns runs the same under the layer.
Not yet run: dispatched next.
2026-11-12 14:03:30 -08:00
Anees Iqbal f10321aad5 A pass left for its draws' pipelines takes its encoding again once they are made
A render pass whose draw's VkPipeline was still being made as it was encoded records as a segment
of its encoder once the pipeline is made (render/pending.rs). A rate map's reset after that
making finished, before the command buffer's commit or after it while the command buffer waited,
encoded the pass again from its log, and the splice refused it: the segment in its place was
neither one whose pipelines are still being made nor work recorded on the GPU alone. The pass
then drew by the map it took and the reset announced rate-map-reset-unencoded, where Metal's GPU
draws by the map as reset. The rate-mapped multi-draw route made this common: its vertex variant
is made at a pass's first draw, so the reset lanes failed by timing
(a_reset_shows_in_a_pass_not_yet_submitted and a_reset_shows_in_every_pass_not_yet_submitted on
lavapipe, jobs m3-max-22179 and m3-max-22244).

The splice now also takes the place of a render pass left for its draws' or tile dispatches'
pipelines alone and executing no render commands (Deferred::left_for_pipelines,
DeferredPass::left_for_pipelines), made since or not: the encoding again recorded those draws
where it found their pipelines made, or left a segment of its own where they were still being
made, and what the first recording took stays retained, as for a segment still being made.

Verified, before the fix: a diagnostic on lavapipe (job m3-max-22327) waited a second after the
draw and refused the splice in both cases ("keeps false gpu_alone false ... making false"),
shading the identity's 64 by 64 pixels with the notice; without the wait the pipeline was still
being made and the splice took it. The new lane
a_reset_shows_in_a_pass_whose_pipeline_was_made_after_its_draw waits for the making
(WorkCounts::variant_pipelines_made) and checks the half map's 33 by 33 pixels and no notice.
2026-11-12 12:37:47 -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 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 1c14b4b44a Staged gathers take their staging at their host step, not on the calling thread
A gather staged through the CPU (31e642ecc2) took its region of the
command buffer's arena on the encoding thread. A region over 32 KiB is a
chunk of its own: fresh pages imported by pointer on NVIDIA, about 2.3 ms
plus 0.25 ms/MiB, and more where the import thread allocates at the same
time. On the RTX 5080 the contended fill bench's first call took
52.8 ms, of which checks, pieces and the staging decision were 0.3 ms.

The gather is now a Deferred::GatherStage whose batch's host step does
all of its work: it takes the region, fills it by the CPU from the
pages, and records the vkCmdCopyBuffer into the buffer at the copy's
place. Like the staged scatter's GPU copy, it is recorded at its step
(records_at_its_step). Its uses are noted at the call. It still waits
for the work before it where the GPU may write the pages
(Deferred::steps_after_the_gpu_now, read by step_waits).

StagedFill becomes StagedGather. The command buffer's staged list,
staged_unfilled, fill_staged and State::next_encoder go: segments
carry it all now.

A rebind's encoding again replaces a staged gather's segment with a copy
through the imports: Segment::records_again and splice_replay take it
(recorded_by_an_encoding_again). So an encoder with a staged gather
keeps its log, as before.

Tests (host_ram_copy_device, device tests):
- Every staged copy test asserts that the encoding took no staging of
  the arena (Uploads::bytes below the copy's bytes).
- a_rebind_before_the_first_submission_encodes_a_staged_gather_s_encoder_again:
  a staged gather and a fill of a no-copy buffer over a page outside the
  RAM, in one encoder behind an event wait. The buffer is rebound after
  the commit. The command buffer completes with no error, the encoder
  encoded again once, the fill lands in the new page, and the gather's
  bytes are in its buffer.

Not yet verified; the gem10 checks follow this commit.

(cherry picked from commit 0f60b71653f9f7dfe9eaba18976c21eb75dd696d)
2026-11-08 11:44:50 -08:00
Anees Iqbal 48caeeb155 DegradeNotice::command_buffer: the command buffer whose work announced a notice
A consumer that makes some notices fatal (reims-vgpu's ReleasedCommandState,
PrivateResourceOption, HostDeallocatorDelayed) could not tell which command
buffer a notice was about: a ReleasedCommandState announced at a host step on
the scheduler's steps thread ended its whole VM. Now every notice carries the
ID of the command buffer whose work the runtime was doing on the announcing
thread, so the consumer can fail that one command buffer.

What changed:
- CommandBuffer::object_id: an ObjectId, minted at the command buffer's
  making from the process-wide count buffers, textures and heaps use.
- DegradeNotice::command_buffer: Option<ObjectId>, read at the notice's making
  from a thread-local scope (degradation::NoticesFor), as `call` reads the
  call being lowered. The scope is set where the runtime holds the command
  buffer and does its work: the compute and blit encoders' logged funnels and
  their other recording calls and ends, the render lowering's at-call funnel,
  its unit calls, its batches' lowering (on the lowering thread or a drain)
  and its end, the resource state encoder's calls, encoder openings, the
  commit (at the call or queued behind a render end), a batch's submission and
  the storage-form settle that rides on it, host steps, a rebind's encoding
  again, and GPU-time reads. Nested scopes name the innermost.
- None, explicitly, for a recovery of the device (device-recovered), for
  grouped-completion (several command buffers' batches), and inside the
  program's code the runtime calls (exit_guard::program, indirect command
  checks, executed-commands handlers).
- A bind's memoized notices, announced again at each later bind under
  announce_each, are named as that bind's: its command buffer and the call
  being lowered (the call was the first bind's before; same mechanism).
- ObjectId docs, docs/API.md section 9, docs/RUNTIME-PORTING.md; API
  signatures re-blessed (two records: the field and the method).

Tests (runtime crate, device tests):
- notice_command_buffers: an ICB execution recorded at a host step announces
  released-command-state on the steps thread naming the executing command
  buffer; its commit's host-replayed-indirect-commands, on the program's
  thread, names it too; private-resource-option of an ICB made between the
  encoder's calls names none.
- deferred_calls: the call-naming test also checks the command buffer under
  both lowering policies; a new test waits for the lowering thread to announce
  unsized-points after end_encoding and checks the thread, call and command
  buffer, and that a device notice between the encoder's calls names none.
- vertex_conversion_notices: a memoized bind notice (device-nan-encoding)
  announced at a second command buffer's draw names that command buffer and
  its own call index, with bound_notices_made proving the memo was reused.

(cherry picked from commit b4c2ba83ea726229f129a405ce6f432b0bdb0127)
2026-11-08 04:45:15 -08:00
Anees Iqbal 4368a35894 Let a linear run's passes name buffers over host pages; a pass a rebind encodes again alone reloads its run
A pass over a linear attachment rendered apart joined no run where its commands named a buffer
over host pages (render.rs's once rule): a rebind of one encodes the pass again alone, and a
linear run had no keep after such a pass. A consumer's setVertexBytes lands in an upload chunk in
its guest RAM, a no-copy buffer over host pages, so every pass of reims's many_passes merged
alone: 706 passes, 706 merges, 705 scratch reuses (11-05).

Measured at development 0165341336 on RADV 780M, release, the rule forced
(linear_runs::passes_reading_host_pages_form_one_run, m3-max-6078, three runs): 706 passes, 706
through copies, 706 merges recorded and 0 taken over, 705 scratches reused; GPU 47.59 to 47.65 ms,
against 12.27 to 12.30 ms for the same passes over a private texture.

Now such a pass joins. Encoded again alone by a rebind, it leaves its run as before
(RunMerge::leave: the merge it took over records at the pass before it) and copies in, keeps and
merges after itself; where a later pass of the run took its merge over, it then copies the run's
box in again from the surface and keeps it into the run's scratch (RunMerge::keep_after's new
linear arm, LinearMerge::record_reload, recorded by EncoderCore::finish_replay; counted as
WorkCounts::linear_runs_reloaded). The run's later passes render over what the bytes hold then
(the run's box may reach past the pass's own, where the pass opened the run over its whole render
area), and its merge writes only what they change. Attachments over host pages other than the
run's own bytes still keep a pass out.

Docs: pass_runs.rs (Which passes join; Encoded again; keep_after), command_buffer/reencode.rs
(Runs of passes), merge_scratch.rs (order 1), linear_merge.rs (Runs), render.rs. API signatures
blessed (one WorkCounts field).

Tests: linear_runs::passes_reading_host_pages_form_one_run (one run expected);
linear_runs::a_pass_of_a_run_encoded_again_alone_reloads_the_run (six passes behind a
host-signalled event, two of them reading a chunk over host pages that is rebound: both encoded
again, both reloading, five merges, the texels a private texture's). Not yet run.

(cherry picked from commit 2b79be56f39ef529db48090dd3185f795ed3c75e)
2026-11-07 18:12:34 -08:00
Anees Iqbal 241ee2c0d1 Keep and merge a run of passes over one shadowed texture once, not once a pass
What: a render pass whose color is a shadowed texture merged back (its truth a buffer's bytes
another writer may write, such as a no-copy buffer's host pages or a Shared buffer's), loaded and
stored, now joins a run of passes (pass_runs.rs) where it may. The run's first pass copies in (or
takes the carried image) and keeps, as before. Each later pass goes on over the image the pass
before it left (ShadowSync::go_on) and keeps nothing. Each pass leaves its merge to its batch's
submission (Deferred::RunMerge, RunWork::Shadow), and the run's next pass takes it over, so the
merge recorded is the last pass's, compared against the first keep. The run holds the keep's
scratch or kept image (RunHeld::Shadow, its MergeLease) until it ends or the command buffer
commits.

Why: consecutive render passes over one merged-back shadowed texture each copied in, kept and
merged the whole texture. 700 one-rectangle passes over a 1024x1024 BGRA8Unorm texture over host
pages took 1,401 shadow copies and 700 merges.

The rule, structural, with no names: a run ends wherever something other than its own passes
could observe or change the bytes, as in the linear runs' list:
- any encoder between its passes that is not a render encoder;
- a render encoder that names the bytes' buffer or its host range, reaches memory it does not
  name, fences, resolves, writes visibility results, records later or renders over a rate map;
- a render encoder with an attachment over those bytes, or whose draws or attachments take a
  shadowed texture over them (the run's own texture bound to a draw included);
- a signal, a wait or a host step (a new batch), and the command buffer's end;
- for a shadow, the encoder no longer carrying the image (the carry dropped).
A shadowed color joins only when it is loaded and stored, has no stand-in and no planes, belongs
to a pass of one render pass instance that is not inline and not inside a predicated laying, is
laid out as one image's texels at level 0 and slice 0, and merges back.

Encoded again: unlike a linear attachment's run, a shadowed texture's run may hold passes over
host pages, which a rebind before the first submission encodes again. Such a pass leaves its run
(RunMerge::leave). The merge it took over records after all (given back), and the pass copies in,
keeps and merges for itself. Where a later pass took its merge over, it keeps the run's scratch
again after its own merge (RunMerge::keep_after), so that later pass's run merges what the passes
after it change. Run segments now record again (Segment::records_again) and splice. An encoder
encoded again takes no pooled scratch or kept image (ShadowMerge::new's `lent`). A run's merge is
resolved at its calls (Deferred::resolved_at_its_calls), so it holds no host pages past commit;
before this, a rebind of such a run was refused with Rebind(EncodedUses).

Two more changes. A run's keep that a later pass writes outside merges and keeps every texel next,
and a run's pass that needs texels the copy-in did not hold copies every texel in. A merge in whole
blocks stays in blocks where the keep holds the pass's area (stores_blocks), under the same
read-to-store window that shadow.rs's Stored attachments already state.

Counted with the existing counters: shadow_copies, shadow_texels_kept and
shadow_merge_dispatches_planned fall from one per pass to one per run. docs/FAST-PATHS.md records
the run and its costs.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under maclock and memcap:
- tests::shadow_runs (new, all pass):
  - runs_over_host_pages_keep_and_merge_once: 1024x1024 BGRA8Unorm over host pages, rows of 15360
    bytes, with blits, foreign render encoders, reads, CPU byte writes, a signal and an aliasing
    view between runs. Mid-sequence and final reads match a private texture byte for byte, and
    the padding is untouched. Joined: 22 copies, 9 merges. Apart: 112 copies, 54 merges.
  - rebound_passes_leave_their_runs: 3 encoders encoded again, 0 refused, bytes equal.
  - scissored_runs_keep_again_once_and_merge_in_blocks: keeps at passes [0, 1], all in blocks.
- Runtime suites (shadow, merge_scratch, linear_runs): 69 of 69 passed.
- Validation runtime_lane (shadow, padded, linear): 91 of 91 passed.
- Negative controls, each a sabotaged build, source restored and touched after; each fails:
  - go_on off: every pass keeps;
  - follows across encoders: keeps [D0, D8, D9, D10, A11, D12];
  - leave off: 961,469 bytes differ;
  - stores_blocks reverted: every scissored pass keeps.
- Release probe, 700 passes in one command buffer, base a543f6428d against this commit: shadow
  copies 3 against 1,401, texels kept 1,048,576 against 734,003,200, merges planned 1 against 700.
  Commit to completion, runs 1-3: 31.6-35.3 ms against 69.3-99.9 ms. With a 1x1 render encoder
  between every two: 61.6-65.0 ms against 107.4-118.6 ms.
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09), the same probe, runs 1-3: 6.6-10.0 ms against
40.6-43.0 ms, and 9.7-12.3 ms against 44.5-47.1 ms. The same 11 shadow, merge and linear device
tests passed there.
clippy --all-targets --all-features -D warnings passed plain and with --cfg m2v_gpu, and cargo fmt
was run.

(cherry picked from commit bf783428131f46c7289518a50b8505e809ecc8e5)
(cherry picked from commit 99949a4cd08cd042e448484e0b1d2f5da1898db5)
2026-11-03 15:58:53 -08:00
Anees Iqbal 2f9a3a3782 A command buffer joins its ended encoders' resources where its work reads them, not as each ends
Each compute or render encoder's end joined everything it made resident into its command buffer's
residency (Residency::join_encoder: a clone and a hash insert per resource), and each later
encoder's open walked every texture of that union for the shadowed ones. Most command buffers'
work never reads the union: only the commit's and host steps' recordings against every encoder's
resources (CommandBuffer::residency), the resident set of a GPU-alone recording, a texture made in
a heap since, and an encoder encoded again do.

- command_buffer/mod.rs: an encoder's end joins its heaps at once (join_encoder_heaps) and leaves
  its resources in its record; State::joined_residency joins the records not joined yet, in the
  order they ended, at the first read (CommandBuffer::residency, make_resident, fresh_ranges, a
  splice of an encoder encoded again, before the textures its heaps made since). The union holds
  what the eager join made, in the same token order: State::sync_heaps joins the records first
  where a heap made textures, as each encoder's join came before them. The commit's sync of its
  heaps and an encoder's open (State::inherited) read no resource list unless one did.
- residency.rs: each residency lists its shadowed textures' tokens (shadowed), found where an
  open first asks for them (find_shadowed) and each texture looked at once, so making a texture
  resident reads nothing of it, and an open starts with the shadowed textures of the joined union
  and of the records not joined yet, in the order they were made resident, with the joined usage
  and stages, at the cost of their count. The join's resource and heap halves and sync_heaps's
  finding and joining halves are split out.
- WorkCounts::resident_resources_joined counts the joins (api_signatures.tsv blessed: one field).

The records hold what their encoders made resident until the command buffer completes, as before,
and the union goes with them, so nothing lives longer or shorter. The same resources, usages,
stages, tokens, shadows and heaps at every read.

Release numbers, M3 Max (host_ab --only encode, runtime side, median of 3 rounds, µs; before is
this landing without this commit, after with it, two or three interleaved runs each):

                                    before (3 runs)          after (3 runs)
  resident_0 end_call             14.1   11.6   14.9      11.3   14.4   15.1
  resident_256 end_call           34.7   25.6   37.3      11.1   13.3   15.4
  resident_4096 end_call         230.3  152.3  244.3      11.4   14.1   15.5
  resident_moving_4096 end_call  170.5  154.3  248.6      10.7   11.8   15.2
  resident_textures_256 end_call  41.5   29.5   43.1      11.2   13.0   15.3
  resident_textures_4096 end_call 287.8 193.5  294.6      11.5   12.9   15.8
  resident_4096 use_call         346.1  379.3  335.1     326.1  297.3  342.0
  resident_textures_256 use_call  38.0   37.0   36.9      35.1   35.1   37.2
  resident_textures_4096 use_call 450.3 481.0  430.3     409.5  419.6  438.3
  resident_4096 encode/dispatch    1.73   1.32   1.62      1.74   1.65   1.65
  resident_textures_4096 encode    2.20   1.78   1.93      1.93   1.99   1.97
  static encode/dispatch           1.75   1.74   1.61      1.62   1.64   1.60

The end call no longer grows with what the encoder made resident, and the useResources call does
not take the cost instead. A first form of this change looked for a texture's shadow as it was
made resident; that put about 80 µs into resident_textures_4096's use_call (260 to 317 against
188 to 200 before, four interleaved runs each), which is why the shadowed textures are found
where an open first asks for them. Percall's counts are the same with and without this commit;
the calls workload's end_compute allocates 5 a call where it allocated 8.5.

Checks that fail without it, in tests/joined_residency.rs:
- ended_encoders_join_their_command_buffer_s_residency_where_it_is_read: with the second
  encoder's open joining the records (the eager join's timing), its first assert fails (16 joined
  where 0).
- shadowed_textures_made_resident_reach_the_next_encoders_in_order: with find_shadowed looking
  at none, its first assert fails (no shadowed texture inherited).

Verified: the runtime GPU suite on the M3 (1527 passed, 3 skipped); cargo clippy -p metal2vulkan
-p metal2vulkan-runtime --all-targets --all-features -D warnings, with and without --cfg m2v_gpu;
scripts/api-signatures/signatures.py --check.

(cherry picked from commit 18553c295c98dabe4c74fc226be6b45955c0c13a)
(cherry picked from commit ae56cfdfdd2e4cb1e9b189c7ce303d680fbc2b7f)
2026-11-03 03:36:42 -08:00
Anees Iqbal 44d97aaa5e Record each command into the driver's command buffer at the call
Recording at the call replaces the deferred replay, with the pipeline-wait test settling the
device's in-place check that recording at the call made fall inside its run.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29, in order:

* Record each command into the driver's command buffer at the call (6c9d1f4551)

An encoder's command buffers are the driver's VkCommandBuffers from the command
buffer's pool, recorded at each call on the program's thread. The deferral is
gone: the per-command log, the deferred handles, the replays and the recorder
thread, the scheduler's wake of it, the host pages' replay holds, and
WorkCounts::{command_buffers_deferred, command_buffers_replayed,
command_buffers_replayed_inline} (removed public fields; none is read by the
consumer). The slots' routed entry points stay as a counting door:
WorkCounts::commands_replayed counts each command at the call, across every
command buffer (the scheduler's barrier buffers and primaries begun ahead
included, so its totals rise: the drag frame's 1000 -> 1094). A shadow's copy in
over dirty-logged host pages becomes a segment its batch's submission records
(Deferred::GatedCopyIn), so its regions are still decided after the commit's
dirty-log stamp. Rebind re-encode (replay.rs, reencode.rs) is unchanged.
RUNTIME_VERSION 1692.

Verified on the Apple M3 Max (MoltenVK): runtime device suite 1392/1393 twice
(pipeline_wait_order's "a batch waiting for a pipeline holds only the batches
that share its resources" fails under suite load only, a known load flake that
now fails more often; 3/3 alone; the base passed 1395/1395 under the same
load); new recorded_at_the_call::a_fill_is_recorded_at_its_call; the three
dirty_pages_device tests through the gated segment; plain runtime 1145/1145;
conformance plain 1007/1007 (its racy-count test now reads wakes_spared and
command_buffers_submitted); clippy plain and --cfg m2v_gpu; rustdoc.
Release A/B on the M3 (5 interleaved pairs, host load 16-43): drag frame
commit-to-handler p50 3.416 -> 3.386 ms back to back, 4.185 -> 3.671 ms paced
at 60 Hz; encode per draw +7.9% back to back, +15.7% paced (the recording moved
onto the program's thread). Not run: the validation plain suite, the
validation lanes edited, lavapipe; conformance's MoltenVK cost records hold
begin/end/barrier bounds from the narrower count and need re-recording.

* Settle the device's in-place check before the pipeline-wait test frees its no-copy buffer (40c79d69e6)

The test's texture over a no-copy buffer starts the device's check of images
over host pages, whose rounds make internal submissions on the
m2v-in-place-check thread. On MoltenVK freed memory waits for every device-own
submission issued before it went (freed_memory.rs), so a check submission in
flight as the test drops the buffer delays its deallocator
(host_deallocators_delayed 1). That wait is the runtime's documented behaviour;
the unrelated batch holds no reference to the buffer (a temporary backtrace on
the device's internal submissions showed every one from the check thread, none
from barrier buffers, primaries begun ahead or gated copy segments). The test
assumed no other device work was in flight, and recording at the call made the
test about 2.5x faster, so the release fell inside the check's run. The test
now calls settle_in_place_checks (a condition-variable wait, no sleep) before
its work.

Verified on the Apple M3 Max (MoltenVK): with three heavy device tests beside
it, 10/10 pass (5/10 without the settle, each "the deallocator waited for the
import"); alone 5/5; the runtime device suite 1393/1393. Also run there, all
passing: the validation lane device tests record at the call edited
(commands_replayed, detach, hidden_depth, clear_reach, rate_mapped_passes,
frame_costs, and the row_copies/frame_costs_plain measurements).
2026-10-29 15:43:49 +02:00
Anees Iqbal a730cf1e96 Stop a rebind's re-encoded tile dispatch making or waiting for its pipeline
The steps this packet landed as, in order:
- Let a rebind of a pending tile pass's buffer run, and place the pass it leaves
- Say in the rebind rule that a pipeline being made does not hold a rebind off
- Re-pin the runtime sources at the landing tip

Content: the tree of `development` at 7da33c898d, unchanged.
2026-10-26 13:19:21 +02:00
Anees Iqbal 06be826c2f Leave a rebind's re-encoded dispatch its segment instead of waiting for a compile
The steps this packet landed as, in order:
- Re-pin the runtime sources at the landing tip

Content: the tree of `development` at f1bb798795, unchanged.
2026-10-26 13:19:21 +02:00
Anees Iqbal 089cc0a9e0 Encode a unit of predication's encoders again where each encodes again exactly
The steps this packet landed as, in order:
- Bump RUNTIME_VERSION to 1580 and hold `Unit::fresh` to its invariant
- Prove the kept refusal from an ungated dispatch, clear of an unrelated defect

Content: the tree of `development` at a6ffe90b3e, unchanged.
2026-10-26 13:19:17 +02:00
Anees Iqbal 8294000cbf Encode a predicated compute encoder again at a rebind where it was its unit alone
The steps this packet landed as, in order:
- Regenerate docs/REFUSALS.md over the twelfth stack
- Pin the runtime sources and bless the golden table over the twelfth stack

Content: the tree of `development` at 6ca8b9005a, unchanged.
2026-10-26 13:19:07 +02:00
Anees Iqbal 87eb8bc3b7 Reset and mutable rasterization-rate maps, as Metal's GPU reads them
The steps this packet landed as, in order:
- Read a YCbCr texture's 2D-array view as Metal's, and drop packed 4:4:4 writes
- Name bfloat attachments in the unreached-tiles notice
- Let go of each predicated loop run's sets and uploads once the run completed
- Check that a lent descriptor arena takes every set and reuses its reset pools
- Bump the semantics, artifact format and runtime versions for the eighth stack
- Pin the runtime sources of the eighth stack
- Bless the golden hash tables over the eighth stack

Content: the tree of `development` at ee0b90d176, unchanged.
2026-10-26 13:19:06 +02:00
Anees Iqbal a653c11b49 Match Metal's detach timing: per submission, until the handlers ran
Content: the tree of `development` at 281583adb4, unchanged.
2026-10-26 13:19:05 +02:00
Anees Iqbal b94953dfa9 Resolve GPU-alone work's resident set at the first submission, not by recording it again
Content: the tree of `development` at 3f5472f696, unchanged.
2026-10-26 13:19:04 +02:00
Anees Iqbal d218c939a4 Encode again at a rebind an encoder whose only host-page use is its end copy back, and its GPU-alone work
Content: the tree of `development` at 3c7d40aea2, unchanged.
2026-10-26 13:19:04 +02:00
Anees Iqbal 8c96577b40 Record GPU-alone work again at a rebind before the first submission
Content: the tree of `development` at adea9e457c, unchanged.
2026-10-26 13:19:04 +02:00
Anees Iqbal c9b0d74912 Record Vulkan commands off the encoding thread through deferred command buffers the recorder replays
Encoders log their commands into deferred command buffers, and the device's recorder thread replays
them into Vulkan once the command buffer is committed, so the encoding thread no longer calls the
driver for each command. Every recorded command goes through a slot of its device's; the recorder's
queue and the scheduler's inbox are sized for a frame's commits and grow ahead of them on the
recorder's thread; a commit's end allocates nothing; a render pass instance's secondary that nothing
executes is never replayed. The replays' commands are counted by kind, and the recorder's modules
are listed among those that may keep the device's functions.

Folds in:
- Route every command the runtime records through a slot of its device's
- List recorder/mod.rs among the modules that keep the device's functions
- List recorder/thunks.rs among the modules that keep the device's functions
- Record Vulkan commands off the encoding thread: encoders log into deferred command buffers, the
  device's recorder thread replays them once committed
- Grow the recorder's queue ahead of the commits, on the recorder's thread
- Give the scheduler's inbox and the recorder's queue room for a frame's commits from their making
- Count the commands the recorder's replays call, by kind
- Give a commit's tail log its fold's room when its encoder ends
- Never replay a render pass instance's secondary that nothing will execute
- Give new replays room to end each deferred command buffer as it is made, so a commit's end
  allocates nothing

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal 3bb4722d9f Release idle pointer imports where they follow their address, keep deallocator timing Metal's across rebinds and detaches, and cut host-import work
No-copy buffers and host imports now cost the kernel and the encoding thread less, and their
deallocators run in the call Metal runs them in, including when a detach races a commit.

What changes:
- Idle pointer imports. A no-copy buffer's own pointer import is releasable, as its dma-buf
  import was: while only blits read it and no pending command buffer holds it, the residency
  thread releases it after its idle window (2 s, doubling at each import again up to 64 s), and the
  next blit imports it again at the same pointer. Only where the new measured fact
  DriverFact::PointerImportsFollowTheirAddress holds (ANV 26.2.4 on the Iris Xe; lavapipe 26.0.8
  to 26.2.4): there a pointer import reads the pages mapped at its address at each submission, so
  an import again reads what the kept one would. A refused re-import fails the blit's call, typed.
- Deallocator timing. A released import hands its keep-alive and deallocators to the objects a
  command buffer still holds, so they run as that memory is freed (or parked and announced, as a
  kept import's). A committed but unsubmitted command buffer holds a blit's import objects weakly,
  so a rebind or detach before its first submission runs the deallocator in its call, as Metal
  does. A detach racing a commit on another thread runs the deallocator in one of the two calls:
  a let-go mark on the pages and the commit's hold count, both sequentially consistent, make each
  side see the other, and a commit that sees the mark replays its own command buffer at once. The
  live list re-reads a buffer's pages where a detach moved them meanwhile. HostDeallocatorDelayed
  is no longer announced for these races.
- Fewer kernel queries. A no-copy buffer asks the kernel about its mappings (PROCMAP_QUERY) only
  where it makes its own import; a rebind onto a live buffer's bytes lies in that buffer's import
  and asks nothing; /proc/self/maps stays open for the queries (reopened in a forked process).
  Three blit paths that read the caller's buffer as a read apart now read it as blits, so their
  imports stay releasable.
- Fewer rewrites and lookups. A rebind or detach rewrites only the heap slots of textures over the
  bytes it moved; host-page alias lookups visit only the length classes that hold ranges and keep
  each range's overlapping ranges; a binding and a descriptor each read where a no-copy buffer lies
  once.
- Counters (WorkCounts): host_imports_used and host_imports_read_apart (with its six reasons),
  host_imports_kept_for_fds and kept imports by cause (of_heap, rebound, pointer, no_stand_in),
  heap_slots_rewritten, host_mappings_queried (Linux; 0 elsewhere), host_range_lookups,
  host_remaps_reported, host_remaps_over_imports, host_imports_remapped, host_pointer_imports_made
  and _bytes_made, no_copy_lies_read, host_imports_rebound_unlisted, host_rebind_imports_made and
  _covered.
- Docs: docs/HOWTO.md on both kinds of release, the RLIMIT_NOFILE soft limit a program raises
  itself and the new gauges; a FAST-PATHS known gap that a buffer made before a remap reads the new
  pages on drivers whose pointer imports follow their address, where Metal keeps the old ones
  (HostMemory::new's contract forbids such a remap); the rustdoc of host_range_remapped.

Why: ANV over i915 lists every VkDeviceMemory in every execbuffer, and a pointer import costs about
0.19 us an execbuffer; the consumer's guest keeps hundreds of no-copy buffers live and uses few in
a frame. Its swap thread spent 1.54 ms of kernel time a frame querying mappings of a buffer that
joined a live import. And a released import's deallocator unmapped pages under a live userptr,
losing the device.

Verified:
- Iris Xe, a guest-shaped lane of 520 pointer imports and 43 command buffers a frame, the idle
  ones released: objects per execbuffer 536 -> 51, ioctl 4.24-4.31 -> 0.85-1.09 ms a frame,
  scheduler CPU 4.96-5.05 -> 1.33-1.74 ms a frame, frame p50 5.27-5.43 -> 2.70-3.11 ms.
- The fact, probed outside the runtime on the Iris Xe and through tests::pointer_residency on it
  and lavapipe: a kept import read the pages a remap put at its address.
- The detach race on the Iris Xe and RTX 5080 under the validation layer: without the fix 3 of 3
  runs failed (deallocators late or on another thread); with it 12 of 12 runs, 15,360 races, each
  deallocator in the detach or the commit, never late.
- A second no-copy buffer over 2040 scattered mappings: 415-418 us -> 0.3-0.6 us. A rebind with
  1024 other live textures: 4766 -> 49 us. Alias lookups: a draw -5.3% instructions on host-page
  frames (RX 7900 XTX).
- Device and unit tests: freed_memory, pointer_residency, host_residency, blit_holds,
  encoder_holds, host_import_counts, host_aliases (up to 45 passed per run); lanes rebinds,
  rebind_reach, detach, detach_textures, host_memory, no_copy_heaps, dma_buf_imports, draw_work
  (74 passed on lavapipe, 30 on the Iris Xe for the deallocator fixes). clippy -D warnings (plain,
  m2v_gpu, m2v_cpu_icd) and rustdoc.
2026-10-19 00:16:00 +03:00
Anees Iqbal 2423b8de61 Keep the Iris Xe's depth fast: DontCare stores, sampled usage for hierarchical depth, multisampled depth held out of GENERAL
Three measured cost facts for ANV (Mesa 26.2.4) on the Iris Xe of RPL-P (0xa7a0), each a pure fast
path that keeps every texel and the order of every use: no policy switch, notice or ledger row.

What changes:
- DriverFact::DontCareStoreIsOneOfMetals gains a row for this GPU: an attachment a pass stores
  DontCare is Vulkan's DONT_CARE there, as on the UHD 770 and the Radeon 780M.
- New DriverFact::SampledDepthKeepsHiZ. ANV turns off a single-sample depth image's hierarchical
  depth and compression in GENERAL (the layout every runtime image rests in) for an image of
  transfer-source usage, but keeps its write-through form on for one of sampled usage. Where the
  fact holds, a single-sample depth attachment plan the device samples takes SAMPLED too
  (image_plan::hiz_candidate), heap textures and the runtime's own depth images included; the heap
  size answer comes from the same plan. Memory size and alignment are equal with and without it.
- New DriverFact::MultisampledDepthFasterOutOfGeneral. A multisampled depth image renders very
  slowly in GENERAL on this GPU, since the write-through hierarchical depth is single-sample only.
  Where the fact holds:
  - each render pass instance holds a multisampled depth attachment in
    DEPTH_STENCIL_ATTACHMENT_OPTIMAL, moved from GENERAL by a barrier before it and back after
    it (the feedback-loop mechanism, generalized to moved images; WorkCounts
    depth_attachments_moved);
  - the device's own Private multisampled depth texture stays in the attachment layout between
    encoders that only render it (texture/held_depth.rs). The scheduler moves it at encoder
    boundaries, before any encoder that uses it otherwise, as a tracked write of the whole image so
    the hazard tracker orders it against every use on every queue. A pass holds only when nothing
    else in its encoder touches the image; a later use breaking a hold fails the encoder's end
    with a visible internal error. WorkCounts depth_instances_held and held_depths_released.
  - An instance an execution of render commands joins, inline instances and the resolve-after
    instance stay in GENERAL. Layout transitions preserve contents unless the old layout is
    UNDEFINED (Vulkan, Synchronization, Image Layout Transitions).
- New measurement runtime_lane::depth_costs (ignored by default).

Why: in GENERAL these depth attachments lose the hierarchical depth test, so the depth test
rejects no fragment a block at a time; and moving back to GENERAL after every pass costs a full
hierarchical-depth resolve, about 1.95 ms a pass at 1080p with 4 samples.

Verified, release, on the Iris Xe:
- runtime_lane::dont_care_stores: every texel of its twelve kept cases was the earlier or the
  stored one, none other.
- A 1080p heap Depth32Float at 32 layers: 4.72-5.66 -> 0.82-0.87 ms with sampled usage. A 4x
  Depth32Float at 32 layers: 12.14 -> 1.44-1.52 ms moved per instance; held between encoders, 1
  layer 2.56 -> 0.62 ms and 32 layers 4.35 -> 2.38 ms (GPU clock fixed at 300 MHz). Batches that do
  not name the depth showed no CPU difference above noise.
- runtime_lane::msaa_depth_moves 9 of 9 under the validation layer with the counters checked (a
  blit between passes, a resolve in its pass, frames, reads after each pass, two queues ordered by
  an event, a split pass, an argument-buffer read with useResource, an encoder that also binds its
  depth, an indirect-command-buffer execution); the depth, resolve, snapshot, clear-reach,
  memoryless and fence-stage lanes passed. On the Radeon 780M and RTX 3090: msaa_depth_moves 9 of
  9 with the fact off and every counter 0. Runtime unit filters 134 passed.
- The RTX 3090 measured neutral for both depth facts, and the RX 7900 XTX keeps DontCare as STORE
  (not a measured identity), so neither is listed.
- Unaudited: no lane covers a tile dispatch in a held pass.
2026-10-19 00:15:59 +03:00
Anees Iqbal bd21b102f5 Cut a draw's and a pass open's allocations
Compare a draw's graphics key in place, keep a drawing state's routing for the pass colors it last
met, write descriptors from the stack and allocate the set in place, keep a draw's small lists on
the stack, hold what a draw retains by reference in one entry per encoder, find a draw's bind shape
among its state's settles, fill push bytes in place, bound coverage without allocating, gather named
keys only once a draw reaches the resident set, compare viewport compensations as they come, list
argument samplers again only where the device's changed, and keep each pass shape's compatible
render pass on the device (up to 64 shapes). The frame-cost lane bounds a draw at 27 allocations and
a pass open at 14.

Gain: allocations per draw from 67.5 to 24.5 and per pass open from 18 to 13 on RADV, ANV and
lavapipe. Frame CPU on ANV (Iris Xe), clean rounds: 5.66 -> 5.02 ms.

Verified on the original branch: the runtime lanes, 1313 of 1313 on RADV, ANV and lavapipe. This
squashed commit (with the wake fix under it) was not re-tested on its own.
2026-10-14 12:15:47 +03:00
Anees Iqbal 13b279df1b Squash 11203 commits of translator, runtime, and validation work
Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.

- A Cargo workspace of five crates under crates/: metal2vulkan (the
  translator and the metal2vulkan command), metal2vulkan-runtime (the
  Metal API on Vulkan), metal2vulkan-air (the AIR front end),
  metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
  refusals, runtime porting and validation guides.

Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b
2026-10-11 20:09:13 +03:00