Commit Graph
71 Commits
Author SHA1 Message Date
Anees Iqbal dfda37628d RUNTIME 2311: ICB records lie in pooled memory where a held pointer import taxes every submission
What: DevicePolicy gains indirect_records (IndirectRecordsPolicy, a runtime
choice no profile carries). Under the default, Untaxed, an indirect command
buffer's records and overflow slots take fresh pages of the runtime's own
(a pointer import held for the buffer's life) only where the device's import
tax check has not found that a held pointer import costs every submission, or
has not answered; where it has (RADV, ANV on i915), they lie in pooled
host-visible memory as the runtime's other buffers do. Under Carried, which
exact_answers() selects, they lie in fresh pages wherever the device imports
host pointers, as before, so a recovery keeps them. A recovery of a taxed
device under the default loses pooled records and rewrites them as a new
buffer's (carry.rs's existing pooled path); the device-recovered notice
already counts such buffers ("N indirect command buffers, M of them whose
records were lost"), as on a device without pointer imports and for
device-local records on discrete GPUs. No new Degradation kind.

Why: on a Radeon 780M (RADV, Mesa 26.2.6, Linux 7.3.3) beside a guest game
whose ICB records were the process's only pointer imports (3 buffers, 19.6 MB),
the submission thread had 5 windows of 65-140 ms in 12 s in which every
amdgpu_cs_ioctl waited in mmu_interval_read_begin or returned EAGAIN (373 of
the run's 382 failed calls, retried at once by libdrm). RADV lists every
imported memory in every CS, amdgpu re-faults every userptr page each CS and
adds the CS fence to every listed BO, so a page migration of one of those
pages (kcompactd, khugepaged, and the runtime's own block making in direct
compaction) waits in amdgpu_hmm_invalidate_gfx for all the process's GPU work
in flight while every submission waits behind it. With no userptr BO listed,
compaction migrates pages without waiting on any fence.

Docs: the FAST-PATHS ledger row (default, switch, the recovery cost, the
measured chain), API.md's device-recovered text, HOWTO's residency section,
fresh_pages.rs, indirect_command_buffer.rs and carry.rs, the conformance
crate's Policy::Exact list. API: signatures blessed, api_surface row,
REFUSALS.md regenerated.

Tests: tests::icb_records_policy (Linux, cpu_icd/gpu): the import tax forced
Holds/Fails; under Untaxed+Holds the records lie in pooled memory, no fresh
pages made, a recovery moves them and its notice counts 1 lost; under
Untaxed+Fails and Carried+Holds in the runtime's own pages, kept, 0 lost. The
translator's fast_paths names the choice, checks it keys no profile and that
exact_answers() takes Carried. icb_carry_race's own-pages cases run on a
Carried device (device_recovery::carried_device), so they assert the carry of
own pages whatever the device's verdict.

RUNTIME_VERSION moves: where records lie and what a recovery keeps change on taxed devices.
New public items: metal2vulkan::device::IndirectRecordsPolicy { Untaxed, Carried } and
DevicePolicy::indirect_records.

Verified, msi m3-max-30127 at cba1ec585a (the fix plus a test-only fix: DevicePolicy is
non-exhaustive, so the tests set the field on a copy):
- clippy -D warnings --all-targets --all-features: metal2vulkan + runtime plain 0, runtime
  --cfg m2v_cpu_icd 0;
- translator tests 49/49 (fast_paths with the new choice, its no-profile key and exact_answers
  tests, api_surface, api_signatures);
- runtime under cpu_icd on llvmpipe 34/34: icb_records_policy, icb_carry_race, icb_records_home,
  indirect_command_buffer*, device_recovery_every_kind, device_recovery_carry.
ICB-RECORDS lines:
- Untaxed with the tax forced Holds: records not in own pages, 0 fresh-page buffers, the
  carry moved them, notice "1 of them whose records were lost";
- Untaxed with the tax forced Fails: own pages, 2 fresh-page buffers, kept;
- Carried with the tax forced Holds: own pages, 2, kept.
Workload proof owed: reims's traced loaded-desktop walk on the 780M (per-CS get_user_pages 0, no
-EAGAIN windows).
2026-11-14 12:49:09 -08:00
Anees Iqbal 5dd3668a4f RUNTIME 2294: indirect command buffer records are placed by first use on discrete GPUs
On a device without unified memory, an indirect command buffer's records
lived in host-visible system memory. A kernel writing 8192 records and the
render encoder executing them both crossed the PCIe link: on a 3090 behind
an x4 link, 17 ms and 26 ms a frame at the link's ceiling, where device
memory takes about 0.004 and 0.03 us a command.

Now the first use decides where the records live:
- a GPU use (an encoder executing, encoding through an argument buffer, or a
  blit resetting, copying or optimizing it) places them in device memory,
  written with a header and zeroed flags through the staging queue;
- a Shared buffer's first host access moves them to host memory once, while
  no unfinished command buffer holds them: an empty move when the GPU wrote
  nothing, else one copy waited for;
- a host access while a command buffer holds them, and every host access of
  a Private buffer, is staged through the staging queue (read back, written
  back), counted and announced once per device as the new
  `staged-indirect-records` (performance) degradation.
The host never writes device memory. Every encoder use takes a hold that
its command buffer drops at completion.

Counters: icb_records_moved_to_host, icb_record_bytes_moved,
icb_records_staged_accesses. docs/API.md has the catalogue entry; the API
table is re-blessed.

Tests: src/tests/icb_records_home.rs (GPU-encoded Shared records stay on the
device across executions; CPU-encoded move once with no bytes; a getter
after a GPU encode moves the bytes; Private records never move; a held
buffer stages until its holder completes; a blit reset between GPU encodes
keeps them on the device, with a reset-then-execute negative control) and
a runtime-lane test for the Private form's notice. Verification: the msi
build, clippy and the lavapipe and 5080 runs follow in the next commits'
messages.

Also: examples draw_reads (the GPU time a draw pays for reading its own data: bytes, a bound buffer,
a pointer resolved in the resident set) and icb_reads (an ICB's records' cost on the GPU and host,
GPU- and CPU-encoded, Shared and Private). Follow-ups folded in: placing fills only the storage's
bytes; a setter's in-place access allocates nothing and its batch carries the access in two words.

New Degradation kind: staged-indirect-records (Performance, once per device; docs/API.md catalogue:
touch a Shared ICB from the CPU before the GPU uses it, or use Shared rather than Private for CPU
access). New WorkCounts: icb_records_moved_to_host, icb_record_bytes_moved,
icb_records_staged_accesses. api_signatures.tsv re-blessed; refusal surface unchanged.

Verified (arenavram): msi m3-max-29217 at bd9994a6a3: clippy plain (runtime + validation, all
targets/features, -D warnings) 0; lavapipe ICB/indirect/degradation/carry tests 65/65. m3-max-29188 at
0980b78c47: clippy plain/m2v_gpu/m2v_cpu_icd 0, rustdoc 0, lavapipe 65 + icb_records_home 6 +
catalogue/sites + 30 lane tests, api tables 15/15. 5080 (m3-max-29179) at 87ea86309b: 95/95 incl. the
6 icb_records_home tests (GPU-encoded Shared stays, 0 moves; CPU-encoded moves once, 0 bytes; getter
after a GPU write moves with bytes; Private never moves and is staged; held then staged then moved;
blit reset between GPU encodes, with a negative control) and
runtime_lane::blits::private_indirect_records_follow_the_memory_model. 3090 A/B m3-max-29178 (base
17a0355935 md5 cac5b460 / tip 87ea86309b md5 4322acb2, two alternated rounds, 8192 commands):
GPU-encoded Shared encode 0.448 -> 0.0039 us a command, execute 3.03 -> 0.031; link rx about 3-4 GB
-> 12 MB a shape run; tip counts moved 0, staged 0. CPU setters on lavapipe: base vs tip within
noise at bd9994a6a3 (not separable; not shown zero). The suites run after landing.
2026-11-14 06:14:41 -08:00
Anees Iqbal 76855fc0ba SEMANTICS_VERSION 2106, ARTIFACT_FORMAT_VERSION 522, RUNTIME_VERSION 2256: GPU-written indirect command buffers that inherit the encoder's buffers run on the GPU; write routes reach the indirect command buffers of their own command kind
A GPU-encoded indirect command buffer whose records inherit the encoder's buffers took the host
step: the render GPU form refused inherit_buffers (DrawReplayRule::InheritedBuffers) and the compute
GPU form had no inherited-bytes path, so every frame read the records back and replayed them on the
host (gameload's icb: 8,192 indexed draws, ~44 ms of host step a frame on the Iris against 0.29 ms
natively).

- Render (da75a4602f..f3745fd69c): a draw replay's variant takes the encoder's vertex and fragment
  buffers by index as its parent buffers, resolved to device addresses past the parent's record;
  inline bytes (set*Bytes) are planned at their slots; an unaddressed inherited buffer keeps the
  host step with its cause named (parent_entries refuses it rather than writing a zero entry). The
  executor's draw preprocess binds the encoder's vertex buffers.
- Compute (7c148c3995..0a68ac5f15): a GPU-written buffer of dispatches that inherits the encoder's
  kernel buffers runs on the GPU the same way; the new fixture icb_inherited_dispatches (our MSL) and
  its golden.
- Route kinds (2d9f4ac597..2e206952c2): every route of a command buffer joined every indirect command
  buffer it made resident for writing, so a compute ICB's writer (DISPATCH|RESET) refused the render
  ICB's GPU form in the same command buffer (DrawReplayRule::Operations): gameload -b's render ICB
  host-stepped although nothing refused its own shape. A write route now reaches only the ICBs of its
  command kind (render or compute); CommandWrites carries the kinds (ARTIFACT_FORMAT 522).
- host-replayed-indirect-commands is announced once per cause instead of once per device
  (a660b2fe8d), naming the rule that keeps a pass from the GPU form, as copied-host-pages announces
  per reason; no new Degradation kind or WorkCounts field.

Verified on the branch (steelbrain/icbinherit2 at a660b2fe8d): clippy plain, m2v_gpu and
m2v_cpu_icd and rustdoc exit 0 (27886); runtime suite 1538/1539, the one failure the catalogue text
RUNTIME 2253 already fixed on development (27884); lavapipe ICB and notice lanes 214/219 with
render_inherited_buffers, compute_inherited_buffers, write_routes, written_commands and the
beside test (inherited and own buffers: cold (8,8,0), warm (8,8,0,0), pixels as alone) passing, the
5 failures failing the same at the branch's base (27926, 27927); before route kinds the beside
test fails as designed, (0,0,8) against (8,8,0) (27764); XTX 90/101 at 60c85035e3 (27853), the 11
failures fixture paths under msi's compile-time path only, all 11 passing on lavapipe (27807).
2026-11-13 20:11:00 -08:00
Anees Iqbal cbd2898434 RUNTIME 2249: a recovery's carry of pooled ICB records waits out the setters' unlocked writes; getters hold the overflow slots; reset GPU time counted
RUNTIME 2225 and 2242 let an indirect command buffer's setters write without the lock. RUNTIME
2247 put the records in the runtime's own imported pages wherever the device imports host
pointers, so every carry there keeps the pages, the pointer and the records (Kept; the carry's
forget_keys sends the next named set under the lock), and an unlocked write needs no tracking.
Records that still lie in pooled memory (a device without host-pointer import, or a failed
import) move at a recovery (Lost, every command reset), and an unlocked write could hold their
old pointer across the carry's release: a use-after-free.

- Pooled records only: each unlocked setter call counts itself with one read-modify-write
  (decided per ICB at creation, counted_write #[cold]); the carry waits the count out before it
  releases the old parts. Own-pages records write as before RUNTIME 2247, behind one branch.
- A getter's read of the slots past the records (overflow) holds their parts, as record reads do.
- WorkCounts::indirect_record_reset_gpu_nanos: the GPU time of each resetCommandsInBuffer
  dispatch, timed with the rate-map pieces' timestamp slots (a third kind), read when the command
  buffer lets go of what it retained; no sync added; 0 where timestamps are absent or wait for
  every queue's.
- set_each's setters run inlined in its loop (#[inline(always)] on set_one): the consumer saw the
  set passed by pointer read wide after narrow writes (a store-forwarding stall).
- HOWTO: each live ICB's records are one held import.

Verified (carryrace, 13fd624294 on 31a07f2867, msi lavapipe):
- Suite 27209: 92/92 (ICB carry race, reset timing, rate-mapped, indirect, executions, device
  recovery, fresh pages, no pointer import, recycling); pooled tests print Lost, own pages Kept;
  the reset timing read 0 ns for a copy alone and 1.28 ms for a reset.
- Negative controls: with the count off, the carry-waits test fails (the recovery ended while an
  unlocked write held the records' bytes); with bytes read at batch creation and no getter hold,
  the unlocked-set and getter tests crash (SIGSEGV).
- Bench 27171 (Core Ultra 9 275HX, one core, least of 3 passes), 256 commands, development
  before 2247 / 2247 / this: compute set_compute_command 70.8-74.8 / 70.8-72.4 / 71.2-71.9 ns;
  full slot 95.9-106.1 / 98.1-100.6 / 102.4-105.8; draw only 32.4-33.5 / 32.4-32.9 / 33.3-34.0.
  Pooled path with the count +35 ns a command. Inlined set_one: batched render rows -10 ns, compute
  -3 to -4 ns. Submissions with 0 / 64 / 256 live ICBs: 104.8 / 99.6 / 100.3 us median.
- API tests 15/15, rustdoc 0. Clippy's only errors at this base are development's 2248 lints in
  render.rs and render/fan_out/tests.rs, untouched here.

RUNTIME_VERSION 2248 -> 2249.
2026-11-13 16:38:21 -08:00
Anees Iqbal 0ee5fb1b9b RUNTIME 2247: an indirect command buffer's records lie in the runtime's own pages, so a device recovery keeps them
A device recovery's carry of an indirect command buffer whose records lay in pooled host-visible
memory moved them to new memory and reset every command (a lost device's mapped memory has
undefined contents), where Metal keeps a Shared buffer's records across its GPU's restart. On ANV
(i915), whose held host-pointer imports cost every submission, the runtime's own small buffers
never lay in imported pages, so every ICB took that path. The consumer's test (four senders
setting nil vertex and fragment buffers while the device recovers, Iris Xe) read back a suffix of
a command's sets as 0 in 10/10 runs, at pin 75 and with RUNTIME 2245 alike.

Now the records (Device::records_buffer, FreshPages::Always) and the slots past them lie in fresh
pages of their own at any length, whatever a held import costs, where the device imports host
pointers into the Shared class's best type. The carry imports the same pages again
(Contents::Kept): records and contents pointer as they were, the CPU's and the GPU's writes kept.
Such a buffer is parked and taken again as a pooled one is. Only a device without the import, or
a failed import, keeps the pooled placement and its reset, which the recovery notice counts.
docs/API.md's recovery section says so.

Cost: one held import per live ICB, about 0.35 us a submission on ANV i915 (submit_check.rs's
measured figure), by its pages on RADV; an import at creation 17-43 us where no parked one is
taken (fresh_pages.rs).

Verified (carryrace, 362d920e11 on acb4c6780d, msi lavapipe):
- icb_carry_race::a_recovery_keeps_the_commands_the_cpu_encoded (a compute command whole and 64
  render commands' four nil buffers, recover, read back, run): base + test (27027) prints Lost and
  fails (command 0 read [None x4] where [64, 80, 96, 112] was set); the fix (27028) prints Kept,
  80/80 with the ICB, executions, recovery, fresh-page, no-pointer-import and recycling tests.
- Owed: clippy in three configurations, rustdoc, the N-ICB submission cost, the consumer's Iris test.

RUNTIME_VERSION 2246 -> 2247.
2026-11-13 15:51:44 -08:00
Anees Iqbal 71e088b900 RUNTIME 2245: an ICB setter's write under the lock reads the records' bytes under it
RUNTIME 2242 (20d04dbd5e) made an indirect command buffer's setter read the records' storage
pointer once, when its batch is made, and edit_locked wrote through that pointer after taking
the `pipelines` lock. A setter that waited on the lock while a device recovery carried the buffer
then wrote into the lost generation's memory, which the recovery had already released (records
lost, every command reset), and recorded its state in the carried table: the write was lost and
the table and record disagreed, or the process faulted. Before 2242 the edit read the bytes
under the lock.

Now edit_locked reads the records' bytes after it takes the lock. A test-only hook
(hold_next_set, under test with m2v_gpu or m2v_cpu_icd) holds a set after its batch is made.

Verified (carryrace, c7ea201189 on 522a8245e2, msi lavapipe llvmpipe):
- tests::icb_carry_race::a_locked_set_held_across_a_recovery_lands_on_the_recovered_records:
  a first dispatch (locked) held across recover_for_test lands on the recovered records
  (locked/unlocked writes moved by 1/0), answers its threads and runs once its state and
  buffers are set. ICB + recovery suites 26930 TESTS=0 (48 passed); wider with executions 26942
  ICB_SUITE=0 (55 passed).
- Negative control (26931, the batch's pointer put back): the new test dies with SIGSEGV
  (NEG_TESTS=100); the recovery's notice says the records were lost (every command reset).
- The unlocked setters' race with a recovery's release (use-after-free) is not fixed here; it
  follows.

RUNTIME_VERSION 2244 -> 2245.
2026-11-13 15:17:25 -08:00
Anees Iqbal 20d04dbd5e RUNTIME 2242: an ICB's setters write through one batch, mostly without the lock; set_render_command and set_compute_command
An indirect command buffer's CPU setters, after RUNTIME 2238's dense table and one hold: every
setter write now goes through one per-command batch (one storage pointer, one count of the writes
made without the lock), written into in place rather than handing back a ~180-byte plan (which
made a first form slower than before). The written flag (SEMANTICS 2097) is set in the one write
helper, write_field, by the rule unchanged: every setter write sets it, a write of the reset
record clears it. A draw, a dispatch, a set barrier and a cleared barrier the edits' summary
already holds, like a buffer slot before, take no lock where the GPU may not have written the
buffer, checked against an atomic mirror of the summary set under the lock; a pipeline state the
command already names is set again with no lock and no CallHold (an atomic (id, serial, kind)
mirror per command; a recovery's carry forgets it, so the next set redoes every check). New
public calls IndirectCommandBuffer::set_render_command / set_compute_command (an index and a list
of sets, no handle and no Arc clone; index and kind refusals at place 0) and the handle's
set_each; borrowed RenderAt/ComputeAt views. docs/API.md says which setter writes take no lock;
the carry docs say a write made without the lock does not wait for a carry (as buffer slots'
did; a set racing a device recovery may write through the old mapping).

Verified (icbset, f403b6e922 on 33de04117d), ns a command, median, 16384 commands, msi lavapipe
(26658, two passes), development e93b3f192e -> tip: full render slot 142.6/147.6 -> 100.7/100.1;
compute slot 119.3/123.0 -> 77.5/77.5; three fields 77.1/78.8 -> 71.8/71.9; draw only 43.5/43.9 ->
34.0/34.0; set_render_command 94.7, set_compute_command 78.9. 780M (26754, 256 commands): full
slot 154.3/167.7 -> 111.0/117.0, compute 123.3/122.7 -> 93.1/87.8. lavapipe ICB set 154/154,
including a test of which way each write went and set_each/set_render_command against one setter
at a time; negative control (a whole-record read-modify-write in write_field) fails the
strengthened two-thread test (26658). 780M: the 6 ICB device tests and set_states pass. clippy
plain / --cfg m2v_gpu / --cfg m2v_cpu_icd and rustdoc 0 (26682, 26756).

RUNTIME_VERSION 2241 -> 2242.
2026-11-13 14:24:31 -08:00
Anees Iqbal 67fb4a7902 SEMANTICS 2097 / RUNTIME 2239: an ICB's blit reset writes only the commands written since the last
An indirect command buffer's records live in Shared host memory by design (the host step reads
them on the CPU, and plain Metal lets the CPU write a Private ICB's commands), so a blit's reset
of a whole ICB was a vkCmdFillBuffer over every record across the link: on the consumer's Modern
Rendering sample (45k commands, 101 MB of records) 56.9 ms of GPU time a frame on an RTX 2080
over PCIe x4, against 0.26 ms for the same fill in device-local memory, while the sample writes
~1.3k commands a frame.

Each command now has a u32 written flag in an optional tail after the records (16 +
capacity*2248 + 4*i; CommandBuffer::initialize and decode unchanged). The lowered encode
operations and copy_command store 1 through the contained wide_at (no tail: the sink; a faulting
operation stores nothing); the CPU setters and edit mark it, and a CPU write of the reset record
(reset_with_range) clears it; a blit copy fills the destination's flags with 1. A blit reset is
one dispatch of the new owned kernel bind::icb_reset_module per run of commands, a workgroup a
command that zeroes a flagged record with 8-byte stores and clears its flag; the overflow clear
stays a fill. The carry copies the whole storage, flags included; a lost carry rewrites the header
and zeroes the flags.

Verified (radvcompile, at 273dbba28c on 045c6fedf9):
- 2080 (26425, 26442; 45k commands): old reset 56.8-56.9 ms in every shape; flagged reset 0
  written 0.256 ms, ~1.3k written 1.736 ms, all written 60.47 ms (+6.5%: 8 bytes is the widest
  store every record allows; recorded in blit_indirect.rs "What a reset costs"). A culling-shaped
  encode kernel (45k render commands, 3 operations each): 19.80 -> 20.11-20.16 ms.
- msi 26494: engine and interpreter round trips with flag asserts and the reset kernel's tests
  59/59, runtime unit tests 1536/1536; clippy workspace all features, each feature alone, runtime,
  --cfg m2v_gpu all 0; rustdoc -D warnings and the API reference check 0.
- RTX 5080 (26478, the change before the rebase): 281/282, both new device tests passing
  (a_reset_resets_what_each_writer_wrote_since_the_last on the host step;
  an_execution_on_the_gpu_alone_runs_what_a_reset_left); the one failure, a getter test's old fill
  count, fixed in this commit. Negative control (26505, the kernel's flag store removed): both new
  tests fail. A device rerun at the landing tip is queued.

SEMANTICS_VERSION 2096 -> 2097 (the lowered encode operations store the flag), RUNTIME_VERSION
2238 -> 2239.
2026-11-13 13:16:16 -08:00
Anees Iqbal ed9b745d20 RUNTIME 2238: an ICB's per-command pipeline states in a dense table, and one hold a pipeline set
An indirect command buffer's CPU setters cost ~290 ns a command in the runtime alone on lavapipe
(the consumer's icb_slots_cost at pin 72: 16384 render commands of 5 fields; a Mac does ~5 ns),
the largest frames CallHold's drop, the setters' edit, and a BTreeMap<u32, CommandState> insert per
command. Two cuts:
- The per-command state is a dense table: a u32 a command indexing a small table of distinct
  CommandStates, each counted by the commands that name it (set_states.rs); a set checks the last
  state it set, then a map. A recovery's carry walks the distinct states. An entry goes when its
  count reaches 0, so nothing is held past what the map held.
- A render or compute pipeline set took 4 CallHolds (the setter's, program(),
  can_encode_indirect_commands(), indirect_command_writes()), 8 mutex takes; it now takes one, and
  a set of a state the table already names reads no program at all.
Also: icb_encode_bench gains a full render slot (pipeline + 2 vertex + fragment + draw) and a
compute slot (pipeline + 2 kernel buffers + dispatch) a command.

Verified (icbset, msi lavapipe release, one A/B job m3-max-26475, binaries alternated, two passes,
host load ~20 so passes drift; median ns a command at 16384 commands): full render slot base
232.7/291.6 -> dense 215.7/253.9 -> + one hold 135.2/185.8 (-42%/-36%); compute slot 212.0/263.4 ->
196.8/217.6 -> 116.6/151.5 (-45%/-42%). ICB, released-program, write-route, recovery and kept tests
on lavapipe running (26484) at the branch tip. The batched setter (set_each) and the unlocked
action/pipeline setters follow after the ICB reset's dirty flags land.

RUNTIME_VERSION 2237 -> 2238.
2026-11-13 13:03:06 -08:00
Anees Iqbal 986f7c3249 ICB: edit maps a refused field in place, as on development
Through a shared fn (field_error), the draw's edit was about 1 ns slower
(tests::icb_encode_bench on lavapipe, msi, P-cores): the closure stays in
edit, and field_error serves edit_unlocked alone.

Quiet run (job 25690, load 1.5), dev 330ca5a282 against this, three rounds:
three fields 91.9-92.2 -> 74.5-75.5 ns (16384 commands), 85.8-87.0 ->
67.4-70.6 ns (256); draw only 42.1-43.0 -> 43.2-43.7 ns (16384), 40.2-41.6
-> 40.3-41.3 ns (256) past a first round of 46.8.
2026-11-13 08:52:23 -08:00
Anees Iqbal a3127ef9c7 ICB: the unlocked writes counted apart, the locked ones by a load and a store again
The lock-free buffer setters made every write under pipelines count itself
by an atomic add (a locked instruction), so the unlocked writes would not
lose one; a draw took 45.9 ns a command on development and 49.7 with the
lock-free setters (lavapipe, msi, job m3-max-25413). The unlocked writes
now add to a counter of their own, the locked ones count as before, and
cpu_writes() answers the sum: each part only grows, so a change of either
moves it.

Verified: cargo fmt; measured next.
2026-11-13 08:52:23 -08:00
Anees Iqbal 67c98e656c ICB: a buffer slot's write takes edit_slot, edit the locked write alone
The unlocked branch at the top of edit slowed the setters that take the
lock: on lavapipe (msi, jobs m3-max-25314, 25351, 25384) a draw took 45.8
ns a command on development and 50.4 to 51.9 with the lock-free buffer
setters. The buffer's set_buffer now calls edit_slot (unlocked on a buffer
the GPU may not have written, else edit), and edit is development's
locked write.

Verified: cargo fmt; measured next.
2026-11-13 08:52:22 -08:00
Anees Iqbal 3a7eea4cf5 ICB buffer setters write without the buffer's lock
A buffer slot's setter on a buffer the GPU may not have written names no
state and adds nothing to what the records may hold, so only the count
of the CPU's writes and the kept recordings of its chunk follow it. It
now writes the field without pipelines' lock:

- the chunk is noted in UnlockedWrites (a flag a chunk and one for any),
  published before the write is counted;
- cpu_writes counts every write by an atomic add (Release), under the
  lock or not (a load and a store under the lock alone no longer count
  every write once writers race);
- KeptChunks::settle forgets the noted chunks, as a locked write forgets
  them, at the next look: kept_chunks reads the count before it settles,
  so every write the count counts is forgotten and one it does not moves
  the count; keep_chunk keeps nothing of a chunk a note still names.

Writes of the same command from two threads at once are the program's
race, as on Metal; the SAFETY comments say so.

Probe (job 24544, Iris Xe host, icb_encode_bench, earlier base): the
lock-free path with every count an atomic add took two buffer setters
from 117 to 82 ns a command and three fields from 216/192 to 164 ns.
Before/after on this commit follows.

Test: kept_commands' a_write_without_the_lock_is_forgotten_at_the_next_settle.
2026-11-13 08:52:22 -08:00
Anees Iqbal 2c21b3e6f1 A recovery carries indirect command buffers, visible function tables and argument encoders; one test over every kind
What: a device's recovery now carries the three kinds a program makes that it left the lost
generation's, so each is the same object on the new VkDevice, as Metal keeps its objects:
- An indirect command buffer (`indirect_command_buffer/carry.rs`). Its records' storage and its
  slots past them are buffers of the runtime's own whose `contents` pointer no program holds,
  carried as such (`Buffer::carry_runtime`): in the runtime's own pages, the same pages and the
  records as they are; in pooled host-visible memory, new memory, the records lost with the
  VkDevice (vkspec 5.2.3), written again as a new buffer's: its header, every command reset.
  The program each command's state runs is the state's program there (made by the state's
  carry, after it), or a released state's made again there, as are the programs it keeps for
  GPU-written records (`released_programs.rs`); its kept chunk recordings go; the new
  generation's keepers list it where the GPU may write it. Its records ID, address,
  gpuResourceID, uniqueIdentifier and label are the line's and stay.
- A visible function table (`function_table/carry.rs`), after its pipeline state: its words
  buffer carried the same way; where it went to new memory, the words written again from a
  host copy the table now keeps of what the CPU wrote (`TableShared::writes`), so its entries
  call what they called; listed among the new generation's tables. A table whose state stays
  the lost generation's stays with it.
- An argument encoder: it holds no Vulkan object, so its device becomes a `LineDevice`, the
  handle carried; `ArgumentEncoder::device` answers the generation handle by value (it answered
  a borrow).
The registry keeps both buffer kinds weakly (`Carry::indirect_command_buffer`,
`Carry::function_table`), the recovery carries them after the pipeline states, and its notice
counts them (`", and N indirect command buffers, M of them whose records were lost (every
command reset)"`, `", and N visible function tables with their entries"`). The docs of what a
recovery carries and leaves say so: `RuntimeGap::MadeBeforeRecovery`,
`Degradation::DeviceRecovered`, docs/API.md, the runtime's README, `device/carry.rs`.

Why: after a 3090 recovery, `resetCommandsInBuffer:withRange:` on an indirect command buffer
made before it was refused (`MadeBeforeRecovery`) thousands of times and every later command
buffer of the pass failed, where Metal's buffer goes on. The whole class at once: every kind a
program can make, each with its carry status, was listed for the change (none other was left
uncarried that holds only what the program could make again; sparse heaps and textures and
pooled `Shared` buffers stay left, as documented).

Test: `device_recovery_every_kind::every_kind_of_object_made_before_a_recovery_serves_after_it`
makes one of each kind (a queue, a `Private` buffer, a heap and a placed buffer, a texture, an
event, a shared event, a fence, a sampler state, a depth/stencil state, a library and function,
a compute and a drawing state, an address pool, a rasterization rate map, a binary archive, a
dynamic library, an indirect command buffer of dispatches executed before and one of draws, an
argument encoder, a visible function table called before), recovers, uses each on the next
generation by command buffers that complete (the indirect buffers reset by a blit and encoded
again, the table called and set, the encoder writing), and ends with the lost VkDevice gone
while all live. Helpers made `pub(super)` in the pipelines and states recovery tests.

Verified, at the change on a0b85d89d4: the every-kind test passes on lavapipe (msi, nextest, one process a
test, with the 41 other recovery, indirect-command-buffer and released-program tests), on the
Radeon 780M (RADV) and the Iris Xe (ANV), 42 of 42 each, and the RTX 3090 (41 of 42: the exportable test's
DmaBuf re-export inode, which development fails the same way there). Its negative control, the
product's sources at bfcd63c5e2 and the test kept, fails at the notice's count of the indirect
command buffers (lavapipe). The validation lanes `function_tables` and `argument_buffers`
(the argument encoder's device): 28 of 28 on the 780M, the Iris Xe and the 3090. Clippy of
the runtime, validation and conformance (all targets and features, --cfg m2v_gpu and
m2v_gpu_hazards): no message. The API signatures check passes (`ArgumentEncoder::device`
blessed); docs/REFUSALS.md is unchanged.
2026-11-13 00:37:07 -08:00
Anees Iqbal ae77d1b882 ICB setters: cpu_writes counted by a load and a store under the lock; write_field reads the stage-in region and lengths only for an action
reims measured a render ICB's encode at 120-130 ns a command in the runtime alone (a guest's
16384-command commit about 11 ms on the 780M against 0.06-0.1 ms natively). The release bench
(tests::icb_encode_bench, the same loop: indirect_render_command_at, a vertex buffer, a fragment
buffer, a draw) profiled on the Iris Xe of RPL-P's host (i9-13900H) put 44-48% of the self time
in IndirectCommandBuffer::edit, three quarters of it on its three locked instructions: the
pipelines lock, cpu_writes' fetch_add and the unlock, each waiting for the setter's stores.

- cpu_writes: every writer holds pipelines, so a Relaxed load and a Release store count it, with
  no locked instruction; it stays an AtomicU64 its readers (indirect_execute.rs,
  render/executions.rs) load with Acquire without the lock, as before.
- CommandRecord::write_field read the stage-in region and the first two threadgroup lengths
  (the record's tail line) for every field; only an action's checks use them, so they are read
  there alone. The refusals are unchanged: RecordView::new still validates the record first.

Measured once each (least of 20 loops of 16384 commands, ns a command): three fields 150.8 ->
117.7 (median 162.9 -> 120.7), a draw alone 61.7 -> 56.6, a 256-command buffer whose records fit
in L2 137.3 -> 113.1; the command alone 11-15 either way. No behaviour changes: what a setter
writes, refuses and counts is the same.
2026-11-12 21:03:48 -08:00
Anees Iqbal c7362776d0 Let carried textures' and pipeline states' parts go at the lost generation's rest
What: a recovery's carried textures and pipeline states let go of their
parts on the lost generation once it comes to rest, as buffers already
did, so the lost VkDevice goes while they live.

- device/carry.rs: LetGo<T>, the let-go cell MadeOn was (MadeOn is now
  LetGo<Device>), and PartsCalls/CallHold, one guard generalised from the
  buffer's calls and HeldParts: a call outside command buffers' work counts
  itself, and a release at rest waits for the last call to end. Buffers
  use it unchanged in behaviour (Buffer::held_parts, LostBuffer,
  LostPlaced, LostHost).
- Pipeline states: StateShared.program and ProgramLink.program are LetGo
  cells. The carry hands the lost generation a LostProgram, which drops
  the state's program there in place at rest (its variants' objects,
  plans, makings and its Device). reached() skips programs let go of. The
  state keeps its own copy of its label, so label()'s borrow outlives the
  program. Holds: the public state methods that reach the program,
  program(), Debug, and the argument encoder's and indirect commands' set
  paths.
- Textures: TextureShared's per-generation parts (storage, moved,
  pending_move, usage_shadow(_making), faces, snapshot, kept_backings,
  render_shadow, facts, planes_in_place) move into Parts in a LetGo cell,
  read through Deref. The carry hands the lost generation a LostTexture.
  At rest it leaves the texture's slot in the lost generation's table and
  heap sets, hands the caller's range token to the parts on the next
  generation, and drops the parts in place. Parts with a handed-out VkImage
  (Texture::vk_image) stay until the texture goes. Texture::s() skips parts
  let go of. Holds: the public texture methods that reach parts, and
  vk_image; a view's hold holds its root texture too. slot_keeper names a
  texture buffer's generation by its texel views, not by the buffer's
  serving generation.
- WorkCounts::lost_programs_released and lost_textures_released, counted
  on the line.
- Public signatures: ComputePipelineState::device,
  RenderPipelineState::device, FunctionHandle::device and
  VisibleFunctionTable::device now answer an owned Device. The last two
  also borrowed from the state's program. Command-buffer paths use the
  crate-private borrowing generation(). api_signatures is blessed.
- Docs: the carry module docs (device, pipeline, texture), docs/API.md's
  recovery entry, the runtime README's recovery paragraph, vk_image's doc.
- Tests: the four recovery tests in 99dbc69666 also assert the counters.

Why: a carried texture kept its images on the lost generation, and a
carried state its program there, until the object went, so the lost
VkDevice lived as long as any of them. A long-lived program kept it for
good.

Verified: cargo check of the workspace, all targets and features, under
no cfg, m2v_gpu and m2v_cpu_icd, clean but for one validation call site
fixed here (jobs m3-max-23824, 23852). The lavapipe lane (the tests of
99dbc69666 before and after), the suite, lint and the 780M run follow.
2026-11-12 19:32:06 -08:00
Anees Iqbal 0f400463bf Say the device handle is owned, as Metal's device answers a retained one
What: the 14 device() accessors that answer an owned handle say so in
their docs, after Metal's retained device; the rest of each doc stands.

Why: the docs should name the change a caller sees (an owned Device where
a borrow was).

Verified: docs only; the lane and lint that follow build them.
2026-11-12 18:11:56 -08:00
Anees Iqbal 2b8b56617d An object a recovery carries answers the caller's own device handle
What: the public device() of every object whose borrow reached a handle a
recovery lets go of answers an owned Device, a clone of the generation
handle it read: Buffer, Texture, Heap, IndirectCommandBuffer, Event, Fence,
SamplerState, Library, Function, DepthStencilState, AddressPool,
DynamicLibrary, BinaryArchive and SharedTextureHandle (whose device is its
texture's). The runtime's own reads keep a borrow through a crate-private
generation() on the types they read it of (Buffer, Texture, Heap,
IndirectCommandBuffer, SamplerState, Function, BinaryArchive): 301 call
sites, so no hot path pays a clone. Each changed item's doc says the handle
is the caller's and keeps its generation, VkDevice included, while held,
past a recovery that carries the object on; MadeOn's doc states that no
borrow of it reaches the program. The validation lane's four callers that
passed the borrow on take a reference of the handle. Signature table
re-blessed (14 rows).

Why: these accessors answered a borrow into device/carry.rs's MadeOn (a
Buffer's or Event's parts, or a LineDevice's GenerationLink), whose
let_go drops that Device at the lost generation's rest while the object
lives. Safe code that held the borrow across a recovery and that rest read
a dropped Device. Metal's device property answers a retained device. The
other objects' device() (queues, command buffers, argument encoders, rate
maps, pipeline states and their function tables) answer a borrow of a
handle the object owns for its life, which no recovery lets go of.

Verified: the lane that follows runs tests::device_recovery_handles before
(it fails: one live VkDevice while the borrow is held) and after the fix;
a workspace check of the accessor change was clean under the plain cfg and
found the four validation callers under m2v_gpu and m2v_cpu_icd (job
m3-max-23584 on a probe commit).
2026-11-12 18:11:56 -08:00
Anees Iqbal 6b79a77730 A recovery carries drawing and mesh pipeline states
What: a drawing state (a mesh one, and a twin of a color group, a single-sample or a factor-scaling
state among them) keeps a chain of programs per generation as a compute state does
(pipeline/carry.rs): its StateShared Deref reaches the program of the generation whose command
buffer's work the thread does, else the last; its ID, uniqueIdentifier, label and sampler numbers
stay. Each state is kept by its generation's carry registry (GraphicsState::kept at the end of a
render or mesh creation, with its color groups' twins); the recovery carries them after the compute
states (pipeline/render/carry.rs): its base variant, and its large-buffer form's, made again from
the pipelines its creation compiled or the live variants of them the new generation holds, no
translation; then, under the new generation's reach (NoticesFor::of_generation), its neutrals, its
predicted first draw's VkPipeline handed to the pool with nothing waiting for it
(make_at_creation(false)), and its depth stand-in copies. Its descriptors, keys, label and twins are
kept; its other variants, plans, settles and routings are made as its draws need them. A failed
making is counted and refused where bound (RemadeAfterRecoveryFailed) through
RenderPipelineState::bound_device, at set_render_pipeline_state (encoder, call checks, indirect
command buffer) and an argument encoder's render word; a tile state's bind now answers its kernel's
failed making the same way. A state is made again only where both generations compile alike
(compiles_alike, the profile fingerprint the memo carry checked already); else its making is refused
as failed. Docs: device/carry.rs, pipeline/carry.rs, MadeBeforeRecovery (render states no longer
listed refused) and RemadeAfterRecoveryFailed, the DeviceRecovered cost (degradation.rs and API.md,
equal), API.md's recovery entry, the runtime README; REFUSALS.md regenerated.

Why: drawing states made before a recovery were refused where bound after it; Metal's go on.

Verified: see the lane run reported with this sha (the test commit before it fails, this one
passes), with the recovery's wall time for 0, 200 compute and 200 drawing states.
2026-11-12 17:13:53 -08:00
Anees Iqbal 98db2b33e6 A recovery carries compute and tile pipeline states
What: a compute state (and so a tile state's kernel) keeps a chain of programs, one per
generation (pipeline/carry.rs): the state object, its ID, uniqueIdentifier, label and sampler
numbers stay, and its Deref reaches the program of the generation whose command buffer's work the
thread does, else the last. Each state is kept by its generation's carry registry; the recovery,
after the textures, makes its program again on the new generation: the base variant's objects
from the pipeline its creation compiled (Variant::of with the compiled pipeline, or the live
variant the new memo already holds), no translation, and the VkPipeline its creation predicted
queued on the making pool with no wait (make_predicted with waited false). The lost generation's
memo of compiled functions and pipelines is carried first where both generations' profile
fingerprints match (PipelineMemo::carry_from), so later variants and creations translate nothing
again. A state whose making there fails stays the lost generation's, is counted by the notice and
refused where bound with the new RuntimeGap::RemadeAfterRecoveryFailed (compute encoder,
argument encoder and indirect command buffer checks, through ComputePipelineState::bound_device).
The notice says how many states were made again and how many failed. An indirect command
buffer's depth/stencil check now matches the state by its line too, as the encoders' do since the
regression fix. Docs: carry.rs, MadeBeforeRecovery, the new gap, the DeviceRecovered cost
(degradation.rs and docs/API.md, equal), the runtime README; REFUSALS.md, reach.tsv and the API
signature table regenerated.

Why: compute and tile states made before a recovery were refused where bound after it; Metal's
go on.

Verified: see the lane run reported with this sha (the test commit before it fails, this one
passes), with the recovery's wall time for 0 and 200 live states.
2026-11-12 16:45:38 -08:00
Anees Iqbal a610b58b8a A replayed draw whose making outlasts the commit's bound leaves its pass to the host step
The last draw dropped for its making's time: a draw of an execution's replay at commit (render
commands the CPU writes) whose pipeline the replay began itself and that was still being made at
the command buffer's bound recorded nothing. Metal cannot encode a draw before its pipeline
exists, so every encoded draw runs.

Now the replay at commit stops there, keeps the making on the command buffer
(CommandBuffer::leave_unmade), and the pass takes it into the makings its host step waits for
(DeferredPass::left_for_makings): the commit leaves the pass to the host step with its
pipelines pending, as it already did for a pass whose settled makings were still being made, and
the step records it from the records as they stand then once the making lands. A replay inside
a host step waits for its making until made, on the step's thread. record_on_gpu declines to
the host step the same way. The commit still returns at its bound at most.

Removed: DrawDroppedStillMaking, WorkCounts::draws_dropped_still_making,
CommandBuffer::drop_late_draw, RenderLowering::drop_late_replayed_draw, the execution's encoder
place that only named the dropped draw, and the open-gap text in FAST-PATHS row 43, API.md (the
bullet and the catalogue entry), the runtime README and the PipelineWaitPolicy docs
(api_signatures.tsv -2). The IndirectCommandCheck and executed-commands docs name the new case
in which an execution read at commit is read and checked again in its host step.

The gap's test flips: a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_renders_once_made
(commit returns after the bound and before the 10 s watchdog; the command buffer is not complete
a second past its bound while another queue completes; once the hold goes it completes with the
rectangle drawn and nothing dropped). Checked by the lint and lavapipe jobs reported with it.
2026-11-12 16:01:25 -08:00
Anees Iqbal f30d2c42a2 IcbShared states its Send and Sync, so a handler that keeps its reports builds at the default limit
The validation crate's release build of its tests under --cfg m2v_cpu_icd stopped building on
development (155027095f, job m3-max-22422): runtime_lane/indirect_host_steps.rs's executed-commands
handler keeps the reports it is handed (Arc<Mutex<Vec<ExecutedCommands>>>), and proving its
capture Send and Sync walked from the reports down an indirect command buffer's fields past
rustc's default recursion limit of 128 (recursion_depth_exceeding_limit, an error under
-Dwarnings). A program's crate that writes such a handler meets the same walk.

IcbShared now implements Send and Sync by hand, as Deferred does, with a constant that makes the
compiler prove each of its fields Send and Sync, naming every field, so a field added fails the
build until it is proved too. The walk from a consumer's types ends at an indirect command buffer's
shared state. Chosen over #![recursion_limit = "256"] on the validation crate: that would hide the
walk from the lanes alone, while every program's crate keeps the default limit.

tests/consumer_auto_traits.rs gains a_handler_keeps_the_reports_it_is_handed_at_the_default_recursion_limit,
the handler written as the lane writes it, in a function of its own as the file's other checks are.
2026-11-12 12:57:17 -08:00
Anees Iqbal 6d9bc9f096 RuntimeGap::IndirectRenderCommands names the rule that refused it (IndirectRule)
One gap stood for a dozen rules: an execution of the other encoder kind's commands, a range a
draw of the encoder may write, a command's memoryless texture slot, a color in another format,
the shader-side depth test, a shadowed texture the call did not gather, residency past the call
meeting a shadow's truth, an emulated mesh command's ordering, a memoryless attachment read past
the pass, and on an Apple10 device the render states the commands set themselves. A consumer's log
said "IndirectRenderCommands" for all of them, so a report could not say which one a program met
(a public GPU-culling sample's host step on an RX 550 did not).

The variant now carries IndirectRule (public, non-exhaustive, Copy), one value per site, and the
error's text prints it: "not implemented in the runtime yet: IndirectRenderCommands(UngatheredShadow)".
A family row of indirect render commands names FamilyRow, the summary of the others. No
behavior changes: every site refuses where it did, typed as before.

Tests that expected the gap now expect its rule: the other encoder kind (render_executions,
indirect_command_buffers), a range a draw wrote (render_executions), residency past the call
(buffer_texture_renders), mesh ordering (mesh_commands) and the Apple10 states (state_ids,
command_render_states, families). docs/REFUSALS.md and api_signatures.tsv regenerated.

A consumer that names RuntimeGap::IndirectRenderCommands names a rule now, or matches
IndirectRenderCommands(_).
2026-11-12 04:10:12 -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 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 ab8651ae38 Run a device call again on the serving generation where its own was lost under it
tests::device_recovery::each_recovery_announces_its_own_wait failed on the M3
in 10 of 30 runs at 2fed3c2453 (m3-max-7120): a waiter thread's
`device.new_buffer(..)` returned NotImplemented(MadeBeforeRecovery) while
another thread recovered the device. A public call of a root handle took the
serving generation (Device::current -> Line::current), the recovery marked it
lost, and the call's own check of the loss (new_buffer_placed's is_lost) then
refused it through lost_refusal, whose line had gone past the generation. The
call came from the device the program holds, which Metal keeps across a
recovery: it must not be refused because the generation it took was lost
while it ran (rule 2).

The device's public calls now run through Device::at_serving: a run refused
for its generation's loss (DeviceLost, or MadeBeforeRecovery as lost_refusal
answers it) where the line went past that generation runs again on the one
serving next. A run refused so kept nothing, so the call runs whole again.
Each run is on a later generation than the one before, after its recovery,
which Line::current waits for, announced past RECOVERY_NOTICE as before; a
line that cannot recover still answers the loss, and a thread command
buffers' completion depends on, whose calls reach the lost generation, is
answered as before (no retry). A call refused for an object of an earlier
generation while its own generation serves is answered as before.

The calls that consume arguments a refused run could not hand to a second
one (host memory and its deallocator or keep-alive, a range token, a buffer
descriptor's contents) run through Device::at_serving_taking: they go to the
generation once it is not lost, else to the next, and from there a loss of
it follows the call: the thread's RunsOn scope makes Device::is_lost answer
false for that generation to the call's own checks, so the call completes on
it as one the loss came after, its object made before the recovery. The two
texture calls with a range token make the texture through at_serving and keep
the token on it after (their _now forms, used by nothing else, are gone). The
calls that wrap the consumer's own Vulkan objects (new_texture_with_vk_image,
_plane, new_buffer_with_vk_buffer) are unchanged: those objects belong to the
VkDevice the caller made them on.

Tests: device_recovery gains a call whose first run meets a recovery and runs
again on the next generation, and a taking call that completes on the
generation lost after it took its arguments. Docs: the runtime README's lost
device section, API.md's device-recovered notice, line.rs's module docs.

(cherry picked from commit 3af6741dcf79b99a608ea0a464b98734dac52ba5)
2026-11-08 00:14:43 -08:00
Anees Iqbal ec9706e6e3 Survive the loss of the VkDevice: the device is a line of generations
Metal's MTLDevice survives a GPU recovery; the runtime's device refused every
call with DeviceLost from the first loss on, and the consumer ends its VM at
the first refusal. Now a device the runtime made is a line of generations
(device/line.rs), each a DeviceShared over its own VkDevice, and the first call
that needs the device after a loss makes a new VkDevice of the same physical
device, options, queue families and extensions.

- Two kinds of handle. The program's device (and its clones) is a root handle:
  it holds the line, pins no generation, and every public Device call goes to
  the generation that serves (each public method forwards to its *_now body).
  Objects hold generation handles, so their Vulkan calls, drops included, reach
  their own VkDevice alone. A generation handle's check is one relaxed load of
  the line's generation (Device::generation_serves).
- A draw pays nothing for it. A command buffer takes its generation once, as
  it is made (CommandBuffer::generation); its encoders' per-draw reaches (work
  counts, fresh-unwritten and alias records, sampler-slot changes, attachment
  read notices) read it there, not through a device handle's kind. A bind's
  device check is one compare of the cells the two handles hold, inlined, its
  refusal (Device::foreign) out of line.
- The state machine (Live, Lost, Failed): the claiming call recovers, every
  other call waits (a notice past 10 s, waiting on); threads command buffers'
  completion depends on never wait. Recovery: the lost generation's command
  buffers in flight fail through its completion path, its queues drain under
  their locks, create_on makes the next VkDevice, the queues are retired.
- Command-buffer answers, as a real loss is one more hang: the oldest
  incomplete batch's command buffer fails GpuHang (exact on one VkQueue; on two
  or more the queue whose oldest incomplete batch was submitted first, said so
  in the notice), counted against its queue so the second revokes it
  (AccessRevoked); the others GpuRecoveryVictim; one committed on the hang's
  queue before the recovery runs nothing and completes with no error; one made
  before and committed after fails GpuRecoveryVictim. One loss names one hang:
  a batch that went to the driver just before the loss and reached the lost
  device's completion after the loss took the pending batches fails with it,
  as a victim (its own wait need not fail: the test hook's VkDevice runs it),
  and no later failure of the lost device names a second hang.
- Command queues survive: a queue is a root handle and a cell of its place on
  one generation (VkQueue, slots, pools, hangs), which a recovery retires and
  the next command buffer re-makes; label and GPU-error count go on.
- Objects made before a recovery are refused where they meet the new VkDevice
  or need their lost one: RuntimeGap::MadeBeforeRecovery, at the 38 lost-device
  checks (Device::lost_refusal) and at every foreign-object check of one line
  (Device::foreign). DeviceLost stays for a device the consumer made.
- Carried across generations: the address space, resource IDs and the passing
  holds a making waits out before it takes one, unique identifiers, counters
  and the announced notice kinds.
- A device handle is an enum of the two kinds (24 bytes, was 16): the shadow
  merge's copy-back dispatch, which holds handles, is boxed (clippy's
  large_enum_variant).
- Device::recover_for_test (public, documented) runs the whole path with no
  GPU fault; RuntimeGap::AdoptedDeviceRecovery on an adopted device.
- Degradation::DeviceRecovered (device-recovered), announced at each recovery
  with the culprit and its time. WorkCounts::vk_devices_live, vk_devices_made,
  device_recoveries: two VkDevices while objects of the lost one live, one
  after.

Docs: docs/API.md catalogue entry, the runtime README's device-loss section,
FAST-PATHS known gap (a make whose own submission first meets the loss is
refused DeviceLost), docs/REFUSALS.md regenerated (refusal_surface.py names a
forwarded body's sites by its public method), api_signatures blessed.

Tests: runtime_lane::device_recovery (hang and victims, command buffers on
their way to the driver at a recovery, MadeBeforeRecovery and the VkDevice
bound, revocation at the second hang, a command buffer made before fails as
victim, all under the validation layer; a recovery that finds nothing of the
queue scheduled names no hang, its command buffers victims),
tests::device_recovery (the hold of the hang's queue between a loss and the
recovery), detach_lost and the MoltenVK lost-device lanes updated to the
recovery's answers.

Verified:
- lavapipe: runtime suite and touched validation tests 1850/1850, surface
  19/19 (m3-max-5695, gem10, before the rebase onto 7e039f062a); on
  7e039f062a, before the one-hang fix, 1853/1853, surface 19/19, clippy clean
  (m3-max-6150, ms01). This tree: clippy clean (m3-max-6278, msi).
- RADV RX 7900 XTX: 81/81 touched device tests (m3-max-5709). Iris Xe (ANV):
  80/81 (m3-max-5766), the 81st kept_images, which fails so at development
  too and the last of these three commits fixes; the recovery tests alone 3
  rounds of 3 (m3-max-5852). RTX 5080 Laptop GPU: 80/81 (b5080 entry
  devloss-devloss-tip1-nine-163410), the 81st the test's own 20 s bound on
  the recovery, which took 39.5 s beside another entry; the test now prints
  the recovery beside the device's first making and bounds neither.
- MoltenVK on the M3 Max: the device_recovery tests 8 rounds of 8
  (m3-max-6135); with the one-hang fix 12 of 12 (m3-max-6242), where without
  it 3 rounds of about 20 failed with a command buffer Completed after the
  hang (m3-max-6219, m3-max-6233). The RTX 5080 failed the second-hang test
  so in 2 runs of 3 (devloss-devloss-rec-alone-170457).
- Recovery time, alone, under the validation layer: llvmpipe 29.9 ms, RX 7900
  XTX 20.4 ms, Iris Xe 15 to 21 ms (its first making 30 to 41 ms), M3 Max
  (MoltenVK) 35 to 40 ms (42 to 50 ms), RTX 5080 530 to 559 ms (602 to 635
  ms). VK_EXT_device_fault listed: llvmpipe 0, XTX 1, Iris 0, 5080 1.
- Per draw (draw_costs, release, --heap, M3 Max, base 7e039f062a and the tip
  alternating, 4 rounds, m3-max-6121): instructions a draw ws +0.03%, many
  -0.05%, 10k -0.31%; draw_primitives +10, +8 and -26 of 17,172, 11,245 and
  7,736 a call; each set_* call +3 to +4 (of 425 to 860); a command buffer's
  creation +170 to +370, an encoder's end +120 to +390.

(cherry picked from commit 3d7758c074fc9895d5d6c9766604c6c4eae9166d)
2026-11-07 18:38:26 -08:00
Anees Iqbal 8e65408e85 Resolve the runtime's broken private intra-doc links, and lower its ceiling to 0
CI's private intra-doc link step reported 148 for metal2vulkan-runtime on
macOS and 149 on Linux at 3b176b8bd4, against a ceiling of 70, so the step
was red on both runners:

- 119 links whose explicit target is the item their label already
  resolves to (`redundant_explicit_links`): 73 from the `degradations!`
  macro, one per precision-note kind's `PrecisionNote::<note>` link, and
  46 written by hand. The target is dropped; the rendered link is the same.
- 17 links to `RenderCommandEncoder::<method>` for methods that are the
  lowering's (`RenderLowering`) since the program's encoder was put in
  front of it: assemble, begin_current_draws, begin_inline_split,
  finish_replay, flush_inline, gathering, group_turn, inline_begin (2),
  inline_split, plan_one, replaying, settle_draw, settle_draws,
  snapshot_fallback, snapshot_wanted and watched. Each links
  `RenderLowering::<method>`.
- render.rs: `check_tile` (a `ShapeInputs` method) linked
  `Self::kept_imageblock_bytes`, and `kept_imageblock_bytes` (a
  `RenderLowering` method) linked `Self::pass_sample_length`; each links
  the other type's method by its type. The `plain_drawn` field linked its
  sibling field `replay_plain` by its bare name; it links `Self::replay_plain`.
- scheduler: `Order::behind` is `Order::is_behind`.
- event_timeline.rs: `Signal::after` is the `after` field of the
  `Signal::Kept` variant.
- pipeline/libraries.rs: `GraphicsContent` is linked by its path in the
  sibling module (`super::graphics`).
- Items built for tests alone are named without a link, as the translator's
  `DIRECT_ARGUMENTS_FROM_AIR` is: `Allocations::limit_to`,
  `patched_slot_uses` and `state_locks`.
- exit_guard.rs: the module docs describe both exits, but `end_at_once`
  and `AT_ONCE_NOTICE` are built on Linux with the GNU C library alone and
  `BOUND` and `MAKING_BOUND` everywhere else, so each runner failed on the
  other's; the four are named without a link.

Docs only; no behaviour changes, so no version moves. The runtime-sources
pin moves with these files; the stack re-pins it.

Verified (potluck): the counts before are from `RUSTDOCFLAGS=-Dwarnings
cargo doc -p metal2vulkan-runtime --all-features --no-deps
--document-private-items` on the M3 (macOS 27) and msi-laptop (Linux).

(cherry picked from commit b4d88f87c6d6fa4c1dfc3fa9774b2fc540c6b297)
2026-11-05 17:12:18 -08:00
Anees Iqbal 40a1558ff6 Decode a host step's records in place, through RecordView::record_into
A host step decoded each record (CommandRecord::decode: a record made, then moved out of its
Result, its Option and the filter, and into the pair the list holds) and pushed it: about 3 KB
moved several times a record, 5001 records a frame on the replayed textured page, where the
decodes' and pushes' moves were 37 of the steps thread's _platform_memmove samples in a 6 s window
on the M3 at 43114cb72b.

RecordView::record_into (new, public) writes a record's every field over a record the caller
holds, as `*record = view.record()` leaves it; record() is it over a default record. The
runtime's reads (written_records_of, decode_written) push each record's slot first and decode
into it (push_written), dropping it to None where it does not decode or the descriptor does not
allow it, as before. API table: one line added, RecordView::record_into; nothing removed.

Verified (M3, potluck): indirect_commands::tests::records::
a_field_written_alone_is_the_record_encoded_again also writes each of its 20 000 records over the
last round's with record_into and finds it equal to decode's; the translator's indirect_commands
tests 41/41. Negative control: record_into leaving the imageblock size as the record held it
fails it (and 4 other tests that decode through record()). Timing, the replayed textured page,
against 43114cb72b, interleaved, two rounds of 3 frames: warm host_step_ms 27.8-29.9 ->
26.0-27.4, encoding to completion 58.4-61.5 -> 56.7-59.3 ms, pixels e3306dc52a1c9e86 at every
frame of both. Sampled: the reads' moves 37 -> 10 samples (2069 and 2070). The runtime's suite
1656/1656 and the residency and draw lanes 248/248 with --cfg m2v_gpu; the frame-cost lane
passes (19.39 allocations a draw, bound 20; release 7.55, bound 9). clippy -D warnings with
--cfg m2v_gpu over the translator, the runtime and validation; api_signatures blessed.

(cherry picked from commit b960f51b05a1dac33816b96fd88d04a8565ae02c)
2026-11-05 06:06:01 -08:00
Anees Iqbal 259615b94d Name a host step's render and compute states beside the records it read, in place
A host step read each command's record (a CommandRecord, about 3 KB: its four stages' 32 buffer
slots) into a list, named each record's state into a second, then zipped both into a third list
of (record, state) pairs; an execution recorded apart flattened that into a fourth, and replay
moved each pair out by value. On the replayed textured page (5001 records a frame) those moves
were most of the steps thread's _platform_memmove on the M3 (106 samples of 2039 in a 6 s window
at 3a4b3e74e2: named_commands' collect 29, replay's moves by value 19, record_kept's flatten 13).

The records are now read into the list they are returned in, each beside an unnamed state
(WrittenRecords<S>), and step_states / step_render_states name each state in place; record_apart
replays the host step's list or the CPU's through one iterator of references, and replay and
resolutions take the commands by reference (the state an Arc clone, as the encoder's already
was).

Verified (M3, potluck): Timing, the replayed textured page on the M3 (5001 draws a frame), this
commit with the one before (they were measured together), against 3a4b3e74e2, interleaved, two
rounds of 3 frames: warm host_step_ms 33.7-35.3 -> 28.5-30.9, encoding to completion 66.6-70.3 ->
59.6-63.8 ms, peak resident 309-311 -> 289-291 MB, pixels e3306dc52a1c9e86 at every frame of both.
Sampled (macOS sample, 6 s, steps thread): _platform_memmove 106 -> 94 samples in a window of 32
frames -> 43 (named_commands' collect 29 -> 0, replay's moves by value 19 -> 0, record_kept's
flatten 13 -> 0; the decode's 18 and the reads' pushes 22 stay). The runtime's suite 1656/1656 with
--cfg m2v_gpu; the frame-cost lane passes (debug 19.38 allocations a draw, bound 20; release 7.55,
bound 9); the residency and draw lanes 247/248, the one other
(indirect_executions::...as_its_dispatch_17) stalled past 180 s once and passed in 4.6 s on a rerun
of its 64 shards (64/64). clippy -D warnings with --cfg m2v_gpu over the translator, the runtime and
validation.

(cherry picked from commit 63248dfbbfd5f8b97ea0edce88313dc8260f80f3)
2026-11-05 06:06:01 -08:00
Anees Iqbal 8fcff2117f Put a host step's copy of a chunk's records off where they changed at two steps in a row
On the 5080, a page whose GPU-written records change at every frame (replayed_frames at K=0,
5000 records, CHANGE_EACH) paid about 0.9 ms more a host step than the baseline: base 19.15 ms,
the tip 20.05, means of 3 interleaved runs of 22 warm frames each (b5080 entry icb-p-010218).
The same tip with the host step's keeping cut off (no comparison, no copy) ran 19.31. perf of
the steps thread put the difference in memmove: each step copied every chunk's records, 11 MB,
into the copy the next step compares with, 575 KB a chunk, past the caches (h 501 Mcycles of
memmove against 416 with no keeping). The comparison itself is a few hundred microseconds less
than that and the single read (ff4610cd46) already left one read a record.

A host step that records inline now copies a chunk's records only where it needs them
(kept_commands::StepCopy, held in each chunk's state beside the bytes it last read):

- where the records hold the bytes the last step read, it records from those bytes and copies
  nothing (ReadFrom::Held);
- where they changed since, it copies them again, as before;
- where they changed at the step before too, it reads them in place, record by record, as an
  execution that keeps nothing does (ReadFrom::InPlace, RecordSource::Storage), and copies them
  at one step in eight only (COPY_EVERY), each chunk at a step of its own among the eight, until
  a comparison finds them as the step before read them. A CPU write to the chunk, or a recording
  of it kept or forgotten, starts it over.

So records that change at each step are copied for an eighth of their chunks a step, and a chunk
whose records stop changing is copied again within eight steps and compared at the next. What a
step keeps is unchanged: a chunk is kept only where its records compared equal, byte for byte.
WorkCounts::host_step_chunk_copies_put_off counts the chunks read in place.

Tests: kept_commands::tests::records_that_change_at_each_step_are_copied_at_one_step_in_eight_a_chunk
(the schedule: chunk 0 copied at steps 0, 1, 10, 18, 26, chunk 7 at 0, 1, 3, 11, 19, 27, one
chunk in eight a step from step 3, a held comparison and a write start it over). The kept-steps
lane's changing case asserts each chunk's copy put off from the records' second change on, each
record still read once (indirect_record_bytes_copied), the pixels a fresh page's, and that once
the records hold again a step within ten records apart and keeps every chunk, the next running
them kept. replayed_frames' split prints host_step_chunk_copies_put_off and
indirect_record_bytes_copied.

Verified: nothing yet; the M3 clippy, units and lanes, the negative control (always copy) and the
5080 timings follow.

(cherry picked from commit cd7b2a7e74f2a6aeef4e8080689bb4bab50c0a2f)
2026-11-05 02:08:25 -08:00
Anees Iqbal 40e884bd85 Box the kept arm of Keeps and read a step's copies as fixed-size records
Clippy (m3-max-586 at ff4610cd46): Keeps::Kept was 784 bytes against 24 for Inline
(large_enum_variant), and chunks_exact of a constant length is as_chunks. Behaviour is
unchanged.

(cherry picked from commit ae5b372e7a66aac5ea762ae4c020abd915e0ee24)
2026-11-05 02:08:25 -08:00
Anees Iqbal 3ab5303945 Have a host step that records inline read its records once, into the copy it keeps
A step whose records change at each frame copied every chunk's records for the next step's
comparison (written_bytes_into) and then read each record again to decode it (record_now):
11 MB copied twice a frame on a page of 5000 commands. On the 5080, three interleaved runs at
K=0 with records changing every frame stepped 19.6 ms on average against 19.0 ms at
04115e977f, with libc's copy at 13.4% of the steps thread's cycles against 11.2%.

steady now hands such a step StepReads, what it reads its records into, chunk by chunk:
the bytes the last step read where it has them, else a fresh copy, and a chunk whose kept
recording's records hold reads those. The inline recording decodes its records from those
copies (IndirectCommandBuffer::written_records_in), and keeps them for the next comparison
once it recorded. keeping answers Keeps: kept, or inline with or without reads.

WorkCounts::indirect_record_bytes_copied counts the bytes copied out of a buffer's record
storage. The kept_steps lane's changing frames now expect each record copied once (DRAWS x
COMMAND_BYTES); copying them again besides fails it.

Not built or run yet.

(cherry picked from commit ff4610cd4660b94835af7841e24114d6ee89fae2)
2026-11-05 02:08:25 -08:00
Anees Iqbal 347b9870c4 Keep a host step's chunks only where two steps read the records alike, and copy the residency once an execution
A host step that compared a kept chunk's records and found them changed recorded every chunk
apart again, each into a secondary of its own, to keep: on the replayed-frames page at 5000
resident pairs on the M3 that cost 23.3 ms a step where the records changed at each frame,
against 18.3 ms recorded inline (one binary, keeping switched off by a temporary patch). Phase
timers put the difference in a copy of the residency per chunk and its drop (2.9 ms over 20
chunks), a fresh 11 MB copy of the records (about 1.1 ms more read), resolutions and contexts.

Two changes:

- RenderExecution::steady decides before recording. A step keeps chunks only where the records
  hold, chunk by chunk, the bytes a kept recording was made from or else those the last step
  read, compared whole. Else the execution records inline, as before keeping, and each chunk's
  records are copied into the bytes the last step read (IndirectCommandBuffer::
  written_bytes_into, no new pages after the first), for the next step's comparison; a recording
  whose records changed is forgotten and counted recorded again. So records that change at each
  step cost the step one copy of them beside today's inline recording, and a step records apart
  and keeps only what two steps read alike. The chunk store keeps those bytes per chunk
  (KeptChunks::look_up_step, read); a chunk recorded apart keeps them as its recording's bytes,
  copying nothing again.
- The chunks an execution records apart carry the encoder's residency from one to the next with
  the bind state (replay_encoder takes it owned), so an execution copies the command buffer's
  residency once, as one recorded inline does.

The kept-steps lane now counts chunks recorded apart to keep (WorkCounts::kept_contexts_made):
the first frame records inline, the second apart, the third runs kept; a records change records
inline, then apart, then kept; another input's change records apart at once; and records that
change at each step record inline each frame, keeping nothing, each frame drawing what a fresh
page draws.

Verified: clippy, plain and under --cfg m2v_gpu, on this Mac. The lanes and the page's timings
on the M3 follow.

(cherry picked from commit b9b1c0aab9728e57e517cb6f0abdfc1df44e9b03)
2026-11-05 02:08:23 -08:00
Anees Iqbal 042ec0a481 Keep a host step's recordings of GPU-written render commands, compared with the records
A host step of a render execution whose records the GPU may write recorded every command at
every step: about 12 to 17 ms for the replayed-frames page's 5000 indexed draws on the M3, every
frame, though the page's records are the same bytes each frame. The step now keeps its chunks as
commit keeps the CPU's (render/executions/kept.rs, kept_commands.rs): from a chunk's second step
on it records the chunk apart into a context of its own and keeps it with a copy of the bytes of
its records; a later step runs the kept recording where the records hold those bytes now,
compared whole, and its key is equal, and records it again otherwise. No write forgets such a
chunk: the comparison decides.

The key is everything the recording reads beside the records: the RenderKey commit's chunks use
(inherited pipeline state, pass shape and layout, encoder state, scissors, amplification,
attachments among the resident resources, the resident set compared whole once a list), plus the
inherited tables' buffers by key with offsets and attribute strides (new: commit's chunks need
tables that bind nothing), plus KeptChunk::runs_again's checks (each address named resolves as it
did, no no-copy buffer moved, nothing detached, everything held alive). The step keeps only where
the commands inherit the pipeline state and the inherited tables bind buffers alone; a record
barrier makes its chunk not plain instead of ruling the execution out. Its chunks draw in the
large-buffer form, as the step's other draws do. The step's round trip stays: the records are
known only once the work before them completed.

Counters: WorkCounts::host_step_chunks_kept, host_step_chunks_recorded_again,
host_step_records_compared and host_step_compare_nanos (api_signatures rows added). The
replayed_frames lane prints them and a hash of the target's pixels per frame (a blit copies the
target out); the new kept_steps lane changes one input at a time (the records the GPU wrote, the
inherited buffer and its offset, the inherited state, the scissor, the resident set, the buffer
an index address names at the same address, the inherited no-copy buffer's pages) and checks a
re-record, the pixels of a page that kept nothing, and keeping again after. FAST-PATHS' entry on
kept recordings states the host step's.

Verified: cargo check and clippy -D warnings, all features, plain and --cfg m2v_gpu, for the
runtime and validation crates; api_signatures/api_surface 15/15; fast_paths 19/19; the runtime's
kept and indirect-command unit tests 32/32. The device tests (kept_steps, replayed_frames,
the ICB lane modules) are not run yet.

(cherry picked from commit 9b3d13a6d22fba484cce4923fd87ad503f7bc060)
2026-11-05 02:08:23 -08:00
Anees Iqbal cc6b083fc2 Let what every write route of a command buffer may write reach every buffer it made resident for writing
What: what an indirect command buffer's records may hold (WrittenCommands, command_writes) took a
writer's writes only from the encoder that made the buffer resident for writing (Writers: the
state set then, each set after, and that encoder's executions). The routes that mark the buffer
(write_routes.rs) were already the command buffer's. Routes now keeps what all of its routes may
write (states set in any encoder, before the residency or after it, and what executed buffers'
records may name) and adds it to every buffer made resident for writing, at the call that brings
either; an encoder opens with what the ended ones met. For two encoders open together (a parallel
render encoder's) the commit adds what each did not see of the other, and the followers that
sets off are marked outside the command buffer's lock, as the commit's marks are. Writers is
gone: Routes holds a superset of what it held.

Why: Metal runs what a kernel wrote with the buffer resident for writing in any encoder of the
command buffer, before the kernel's or after it (the probe icb_routed_writes.m, M3 Max, macOS
27.0.1). The marks matched that; the summary did not, and an execution of a buffer that inherits
the encoder's state decides on the summary whether the GPU alone runs it, as draws of the one
primitive type it allows. With the residency in another encoder than the kernel's, the GPU alone
ran the kernel's point as a draw of the CPU's triangles, which drew nothing (the previous commit's
lane). The bug is older than the write routes: the summary was per encoder before them too.

What it moves: an execution of a buffer whose command buffer sets, in another encoder than the
one that made the buffer resident, a state that may write what the GPU-alone forms rule out: a
render execution takes the host step where that state may write more than draws of one primitive
type, buffers, resets and cleared barriers; a compute execution in a concurrent encoder orders its
commands where it may set a barrier, and a checked one calls its check where the records may name
a state that may encode. The lanes that made a buffer writable with a state set in an encoder of
its own (indirect_host_steps::encoding_state_set: icb_replay_encode's, which may set pipelines,
dispatch, set threadgroup lengths and barriers) showed it: with it, 6 of the 480 tests of the 40
modules changed (render_merged_executions' GPU forms into a shadowed target took the host step,
6 executions; five dispatch_executions tests saw barriers, check calls and a host step), all
others as before, resident_draws among them (its writer and residency share an encoder: no host
step on its write path, its chunks kept). Those lanes are about the GPU-written path, not about
what the state writes, so the lever now sets icb_reset_encode's state (resets alone, which no
GPU-alone form rules out).

Docs: written_commands.rs and write_routes.rs module docs, IndirectCommandBuffer::command_writes,
render/executions/gpu.rs, the runtime README and docs/API.md section 10.

How verified (debug, --cfg m2v_gpu, M3 Max under MoltenVK): runtime_lane::write_routes passes
(it failed before this commit: After and Before drew no point); the 39 ICB lane modules and
write_routes, 480 tests, pass with the reset lever; the runtime's
tests::write_routes_device::a_route_reaches_every_buffer_its_command_buffer_made_writable (new:
a later encoder's state, one set before the residency, and a parallel encoder's at the commit)
and tests::written_commands pass; clippy -D warnings with --cfg m2v_gpu is clean.

(cherry picked from commit 7d13a4dee21162a972b40fd9868e3e2f9112a677)
(cherry picked from commit 13b9646e48b767defdd189bf156a2a9130b3b857)
2026-11-04 18:50:27 -08:00
Anees Iqbal f35128eb43 Mark an indirect command buffer at the call that completes a write route, and let the routes go at the commit
The write routes marked a buffer at its command buffer's commit. An execution's segment is cut
into a part of its own, which waits for the work before it, as it is encoded
(`Segment::host`, from `gpu_written` then), so an execution encoded after the writer in the same
command buffer, in its encoder or a later one, was recorded with the writer's part and ran the
CPU's records: indirect_host_steps' commands_a_kernel_writes_run_after_it and 19 other lanes
drew nothing.

The routes now mark at the call that completes the pair: a write use where a state that may
encode, or an execution whose records may name one, was met in the command buffer; such a state
set, or such an execution encoded, where a write use was. An encoder opens with what its command
buffer's ended encoders met (`Routes::carried`), so a later encoder's execution is encoded as one
the GPU may write, as it was when a write use marked the buffer at its call. The commit still
decides again from what the records name then, and still leaves the followers.

The command buffer's routes held each buffer made resident for writing or executed until the
command buffer itself dropped, past its completion: a released buffer's range and resource ID
stayed taken (indirect_command_buffers' buffer_identifiers_follow_metal_s_encoders,
resource_ids' an_indirect_command_buffer_s_id_is_held_as_metal_holds_it). The commit now clears
them once it decided; what it leaves unmarked is held until completion, as before.

Docs: the gpu_written contract, write_routes.rs, docs/API.md and the runtime README say when.

Verified with the lane commit after this one (debug, --cfg m2v_gpu, this M3 Max on MoltenVK):
the 39 lane modules that execute indirect command buffers, 479 tests, all pass, where B alone
failed 35; the runtime's written_commands, degradation, degradation_catalogue and
degradation_sites unit tests pass; fmt; clippy -D warnings of the runtime and validation crates,
all targets and features, under --cfg m2v_gpu.

(cherry picked from commit e8e85c6936ecc731fa557440033ac9d3e40953e2)
(cherry picked from commit 106af168144e7a76fcc5366e39fec10a3693611c)
(cherry picked from commit 38605155f851abdf697c818c5387c1980af6a0bd)
2026-11-04 18:50:27 -08:00
Anees Iqbal 66c9163ce3 Mark an indirect command buffer written by the GPU only where a route that may write its records meets it
A write residency of an indirect command buffer (useResource:usage: with MTLResourceUsageWrite)
marked it written by the GPU at the call, whatever the encoder's functions could do. Every
execution of it then waited for the work before it and was recorded by a host step, and kept no
chunk. A page whose kernel only counts, with the buffer made resident for writing, paid the host
step every frame (51 to 61% of the write frame in the kept-steps measurement), though no function
of it can reach a record: a function writes records only through an indirect-command operation.

The mark now comes from the routes that can write records (write_routes.rs), decided by
structure alone:
- the commit of a command buffer that made the buffer resident for writing in any of its compute
  or render encoders (residency is the command buffer's) and also set, in any of them, before or
  after, a pipeline state whose functions' indirect_command_writes is not empty (the translator's
  answer from their AIR: the indirect-command operations their bodies may call, every one where a
  body makes a call the translator cannot see into), or executed commands whose records may name
  such a state;
- after a commit that found neither, the first CPU or GPU write that leaves such a state in the
  records of a buffer it executed (the executed buffers hold the commit's unmarked buffers weakly
  until then, released as the command buffer completes; the marks run once the setter let its
  locks go);
- a blit's copy into the buffer or reset of a range in it, at the call, as before.
A heap holds no indirect command buffer and residency sets are refused, so neither is a route.
The mark is for good, as before. It keeps the route that met the buffer first, which the
host-replay notice names: for a state, its functions' names and the kinds of indirect-command
operation they may call; else the route. WorkCounts::indirect_write_residencies_unmarked counts
each commit's write-resident buffers it left unmarked.

The resident_draws fixture gains rd_encode, a kernel that may reset a command and resets none,
regenerated with scripts/regen-air-fixtures; the lane's `encode` path uses it, off the measured
paths.

Docs: the gpu_written contract, the runtime README, docs/API.md (the catalogue's
HostReplayedIndirectCommands trigger and cost, and the contract), the module docs that named the
old rule. api_signatures.tsv blessed (one field).

Verified (debug, --cfg m2v_gpu, this M3 Max on MoltenVK): the resident_draws lane's three tests
pass: a kernel that cannot encode (rd_touch) leaves the buffer unmarked, with no host step in any
of three frames, its two chunks run from the kept recording in the third, one unmarked residency
counted a commit, and the read path's pixels; a kernel that may encode (rd_encode) marks it at the
first commit, a host step every frame, no chunk kept, the same pixels, and the notice names
rd_encode and its reset; every path draws the encoder's pixels. Negative control (neg.py: every
state counted as calling no operation, and no executed buffer's records as naming one): the
encoding test fails (no host step in frame 0), the other passes. The runtime's written_commands
(a new test of the followers), degradation, degradation_catalogue and degradation_sites unit tests
pass. fmt; clippy -D warnings of the runtime and validation crates, all targets and features,
under --cfg m2v_gpu.

(cherry picked from commit 6e1b62a03039dd81a2005afa26a3001de2064110)
(cherry picked from commit 13dac865f4096559a5b97841d893e1da02e160ec)
(cherry picked from commit 862a72c76e82b657ef158ee1c7cbf789240ea745)
2026-11-04 18:50:27 -08:00
Anees Iqbal 27f052e7ec Read an inline ICB execution's records a chunk at a time, each run collected once
An execution of commands the CPU re-encoded before it is a first execution, which records
inline. A consumer that sets every command again before each execution has only those. Before,
such an execution read its whole range's records at commit before it recorded any:
IndirectCommandBuffer::read_records collected them into a Vec grown by doubling, named_records
zipped them with their states into a second, and Execute::commands and RenderExecution::commands
wrapped each in Some into a third. A CommandRecord holds 4 stages of 32 buffer bindings, about
3 KB, so 16384 commands are some 50 MB a copy, out of the cache by the time they are recorded.
On the RTX 5080 laptop, compute n=16384 all re-encoded committed in 64.8 and 67.7 ms with
a54756c6a4 against 48.6 and 47.8 ms for its parent, which recorded each 256-command chunk apart
in a kept context.

Now:
- kept_commands::pieces gives the runs of an inline range an execution reads and records in
  turn: its chunks of 256, or the range whole where every command must be seen before any is
  recorded (the caller's check where it may see something, and the command buffer's
  executed-commands handlers, which hear of the execution once) and for the host step, which
  reads the records as the GPU and the CPU left them.
- Execute::record and RenderExecution::record read a piece, announce the commands of it that
  run otherwise than Metal's may, call the check, report to the handlers and record it, before
  they read the next. The host step's read is written_commands, as before. A kept render
  execution's rest of the range, after a chunk that is not plain, reads a chunk at a time too.
- read_records makes its lists at their length and takes each record as its caller holds it;
  named_records names the states in place in the list it returns, and the commit path records
  from that list, with no Option a command.
- WorkCounts::indirect_record_runs_read counts the runs of records read at once
  (api_signatures.tsv).
- Degradation::ReleasedCommandState is announced once a piece, as a kept execution announces it
  once a chunk.
- Docs: the "When." bullets of indirect_execute.rs and render/executions.rs, and pieces' own.

Tests:
- kept_commands::tests::pieces_are_the_chunks_or_the_range_whole.
- runtime_lane::kept_commands::an_inline_execution_reads_its_records_a_chunk_at_a_time (render,
  600 commands, [records read, runs read]): the first execution [600, 3]; with a check that sees
  (draws of points) [600, 1], the check called with 600 commands.
- an_inline_compute_execution_reads_its_records_a_chunk_at_a_time: [600, 3]; with an
  executed-commands handler [600, 1], the handler hearing once of commands 0 to 599.

Verified:
- On the M3 Max, debug (--cfg m2v_gpu), nextest -j 8 over every runtime_lane module that
  executes an indirect command buffer: 39 modules, 477 tests, all pass.
- Negative control, debug (pieces gives every range whole): both new lane tests fail at "the
  first execution, a chunk at a time" ([600, 1] where [600, 3] is expected).
- metal2vulkan-runtime kept_commands::tests 3/3; fmt --check; clippy -D warnings (runtime and
  validation, all targets and features, m2v_gpu).
- M3 Max, release, Time Profiler of execution_costs compute n=16384 all re-encoded, 2 untimed
  and 20 timed executions, inclusive CPU, lane 7583fe5d99 (keeps from the first execution) /
  d75cb04ac8 (before) / this change: CommandBuffer::commit 1077 / 1186 / 928 ms (49.0 / 53.9 /
  42.2 ms an execution), IndirectCommandBuffer::records 274 / 336 / 142 ms, memmove 213 / 297 /
  117 ms. execution_costs on this loaded host, commit medians of two rounds: compute n=16384
  all re-encoded 47.65, 47.00 / 52.93, 57.44 / 44.32, 42.98 ms; compute n=1024 all re-encoded
  8.34, 3.48 / 3.05, 3.95 / 3.82, 3.26 ms; render n=1024 all re-encoded 2.31, 6.59 / 2.49,
  2.97 / 2.07, 2.19 ms. The M3's render n=16384 all re-encoded row is load-dominated (ranges
  reaching 77, 97 and 156 ms), so the 5080's below is that row's evidence.
- RTX 5080 laptop (NVIDIA), release, execution_costs compute and render, 2c542021bf (parent),
  a54756c6a4 (before) and a54756c6a4 with this change's runtime part, interleaved, commit
  medians of two rounds: compute n=16384 all re-encoded 47.01, 46.41 / 63.07, 61.83 / 44.24,
  43.79 ms; render n=16384 all re-encoded 39.96, 39.38 / 56.40, 56.27 / 36.88, 36.89 ms;
  compute n=1024 all re-encoded 2.86, 2.82 / 3.15, 3.10 / 2.66, 2.70 ms; render n=1024 all
  re-encoded 2.40, 2.46 / 2.52, 2.47 / 2.23, 2.23 ms; the one re-encoded and unchanged rows
  within 0.1 ms of each other but one 0.97 ms reading of this change's compute n=1024 one
  re-encoded (its range 0.68 to 0.97, the other round 0.73).

Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes.

(cherry picked from commit 678b2925c08269249a1aad3ef3d126d94bbf460a)
(cherry picked from commit 327cb5f3837ae38e055a4273e5254987601e43cf)
2026-11-03 15:58:55 -08:00
Anees Iqbal 24dc3f20bb Keep an ICB range's chunks from their second execution, and forget a written chunk in one store
A range's first execution no longer pays for keeping. Before, every execution of CPU-encoded
commands recorded each 256-command chunk apart, in a KeptContext of its own (a command pool, a
descriptor arena and uploads), so it could run that recording again later, even when no later
execution came. Now a chunk is recorded to keep only from its second execution with no write
reaching it since. The first execution since a write records inline, as before 922caf3199, and
keeps nothing. A consumer that re-encodes every command each frame now pays nothing for keeping.

- kept_commands.rs: KeptChunks notes which chunks an execution that may keep its commands ran
  since a write last reached them. look_up answers each chunk of a range as Kept::Recording (a
  kept recording), Kept::Again (run before, nothing kept) or Kept::First, and notes each as run.
  IndirectCommandBuffer::kept_chunks answers None, so the execution records inline, when every
  chunk is First. When some chunks are kept and others are not, a First chunk records apart from
  its command buffer's own pool and arenas, with no KeptContext, and is not kept. An Again chunk
  records apart in a KeptContext and is kept.
- KeptChunks is dense: one ChunkState per chunk (kept recording, stepped, seen) up to the
  furthest chunk looked up, plus a flag for whether any chunk holds a state. KeptChunks::wrote
  costs one store per chunk the written range covers, whatever the number of kept chunks, and
  returns at once while no chunk holds a state. Before, it ran BTreeMap/BTreeSet::retain over
  every kept and stepped chunk on each setter call.
- WorkCounts::kept_contexts_made counts the KeptContexts made (api_signatures.tsv).
- Docs: kept_commands.rs, render/executions/kept.rs, indirect_execute/kept.rs and
  docs/FAST-PATHS.md (the kept-recordings row).
- examples/icb_setters.rs --kept now executes three times before each repetition: the first
  keeps nothing, the second records every chunk to keep, and the third runs all of them from
  those recordings.

Tests:
- runtime_lane::kept_commands asserts kept_contexts_made beside the records read and the chunks
  and commands kept.
  - A once-executed range makes no context: [N, 0, 0, 0].
  - Its second execution keeps every chunk: [N, 0, 0, 3].
  - Its third runs them: [0, 3, N, 0].
  - After a write, the written chunk records inline again and the next execution keeps it.
- kept_commands::tests::a_write_costs_the_chunks_it_covers asserts the count of chunk states
  wrote() looks at.

Verified on the M3 Max:
- Debug device lanes (--cfg m2v_gpu, nextest), with the live compute flags fix from stack22
  applied locally (not part of this commit): every runtime_lane module that executes an indirect
  command buffer (39 modules, 471 tests) pass.
- Negative control for the ruling (each chunk keeps from its first execution), debug:
  3 of the 5 kept_commands tests fail, a first execution making 3 contexts where 0 are expected
  and a written chunk making 2.
- Negative control for wrote() (it walks every chunk state): a_write_costs_the_chunks_it_covers
  fails, looking at 1000 states where 1 is expected.
- Unit tests: kept_commands::tests 2/2 and metal2vulkan tests::fast_paths 19/19.
- cargo fmt --check and clippy -D warnings (runtime and validation, all targets and features,
  --cfg m2v_gpu) are clean.
- icb_setters compute --kept (release, instructions per command, median of 30, two runs each):

  | | before (2c542021bf) | after |
  |---|---|---|
  | compute command, nothing kept | 2528.7 / 2529.1 | 2428.1 / 2427.7 |
  | compute command, 64 chunks kept | 5947.8 / 5945.5 | 2586.5 / 2583.9 |
  | set_kernel_buffer, 64 chunks kept | 1129.6 / 1129.6 | 456.9 / 456.3 |

  With three executions, the third runs all 64 chunks from kept recordings (the
  bench prints [64]), at 2583.9 and 456.3 instructions.
- conformance cost --alone indirect-render-commands-inherited-state reads arena_pools_made 1,
  argument_objects_retained 2 and argument_tables_retained 1, the recorded bounds. With a first
  execution's KeptContext these read 3, 6 and 3 (the cost run that held its record back).
- execution_costs (release) on a loaded host: wall times are dominated by host load. An earlier
  pair of runs read the first execution as slower (render n=1024 all re-encoded commit 2.88 to
  6.55 ms), but the parent then read 6.55 ms itself under the same load. Time Profiler, test
  thread CPU, same case and count, this change on 2b55ab415e against its parent:
  - render n=1024 one re-encoded, 300 executions: 611 to 610 ms;
  - compute n=1024 all re-encoded, 80 executions: 336 to 333 ms;
  - render n=1024 all re-encoded, 120 executions: 782 to 859 ms. This is the inline path's
    whole-range read: RenderExecution::commands collects the range into a second
    Vec<Option<Command>> (memmove 0 to 25 ms in RenderExecution::record), and render_records
    reallocates as it grows. The same profile has IndirectCommandBuffer::edit, whose code is
    the same in both builds, up 31 to 40 ms, so part of the difference is load.
  A later run of this commit's tree read render n=1024 all re-encoded at 2.37 ms commit, one re-encoded
  at 0.61 ms, and compute n=1024 all re-encoded at 3.49 ms.

Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes.

(cherry picked from commit a54756c6a4f7fbe9ae82d732e8de46a19f4f86e5)
(cherry picked from commit 71e798c081648ea3818abbffc7538a3061456c75)
2026-11-03 13:34:02 -08:00
Anees Iqbal be686f18a0 Write an indirect command's field in place, adding to what its records hold only what is new
Each Metal-shaped setter (IndirectCommandBuffer::edit) paid about 2000
instructions, almost all for bookkeeping around a write that costs 130-213. It
copied the whole 2248-byte record out of the mapped storage (zeroed, then
moved through a Result), wrote the field into the copy, copied the field back,
decoded the copy again for its action and barrier, looked the command up in
the per-command BTreeMap of states (16384 entries), then took the summary's
own mutex to add what usually was there already. The 41% of its time in
memmove and 30% in edit's own copy loops were those copies. The BTreeMap
lookup came in with 565fbd9153 (kept recordings): with the dense Vec before
it, 9ec100ba7c and b7652d85a2 measure 8652.5 instructions a render command
and 565fbd9153 measures 10501.9.

Now, under the one hold of `pipelines` the write already took:

- The field goes straight into the mapped record. CommandRecord::write_field
  validates the record and writes the field's words there, as it did into the
  copy, and leaves the record unchanged on a refusal. Readers that read
  records together with states (read_records) still read under the same lock.
- The records' address is read from the storage once, at creation. The
  storage is runtime memory, never a heap's, a mirror or host pages, so its
  mapping is fixed for its life. Before, contents() cost about 65
  instructions on every call.
- CommandStates::added keeps what the CPU's edits have added to
  WrittenCommands so far. The summary only grows, so an add that is already
  covered changes nothing, in the summary or in any buffer a blit copied the
  records into. Such an add is skipped. The record is read for its action and
  barrier only where the edit can change them (an action or barrier field), or
  where the GPU may have written the records (gpu_written, set at the encoding
  call, before any GPU work that may write them is committed). Otherwise every
  action and barrier in a record was left by an edit that already added it.
  The state lookup happens only on the rare add that grows the summary. Only
  an edit puts a state in CommandStates, and it adds that state, so the lookup
  is needed nowhere else.

Every refusal, and the order of refusals, is unchanged; the setters' checks
are untouched. The records, what the records may hold, the CPU-write count and
the kept-chunk invalidation are as before. One case reads differently: when
the GPU races a setter's edit and leaves the record undecodable, the state the
setter would have set is now not set. The parent set it and then returned the
same internal error.

Verified on the M3 Max (MoltenVK, release, examples/icb_setters), median of 5
runs x 6 repetitions x 16384 commands, runs interleaved with the parent's
e3444f3273 build:
- render command: 10351.4 -> 2667.9 instructions; 590.1 -> 234.9 ns (runs
  194.9-272.3); 2110 -> 732-971 cycles.
- compute command: 10177.2 -> 2528.7 instructions; 583.6 -> 128.8 ns (runs
  116.4-186.3).
- per call, one pass of the call over the buffer: set_vertex_buffer 2003 ->
  446, set_fragment_buffer 2002 -> 444, draw_primitives 2096 -> 634,
  set_render_pipeline_state 2288 -> 751, set_kernel_buffer 1998 -> 441,
  concurrent_dispatch_threadgroups 1996 -> 534, set_compute_pipeline_state
  2243 -> 718 instructions.
- Time Profiler, render: before, _platform_memmove 41.5% self, edit 29.0%,
  write_field 6.2%, pthread_mutex_lock 3.4%, OwnBytes::shape 3.2%,
  RecordView::new 3.0%, WrittenCommands::add 2.1%. After, edit 25.1%,
  RecordView::new 24.1% (write_field's validation, the first touch of each
  record's lines), set_buffer 13.8%, write_field 10.6%,
  pthread_mutex_lock 9.1%. No memmove; WrittenCommands::add and
  Buffer::contents are gone.

tests::indirect_command_buffer_device (device tests, m2v_gpu/m2v_cpu_icd)
runs a model of the parent's setter beside the buffer. The model writes the
field with write_field into a copy of the record as it stands, then adds the
record's writes and named state every edit. The mix covers render and compute
commands, fields that add something and fields that add nothing, refusals and
taken calls mid-command (PipelineWithoutSupport, ForeignObject, a slot at the
limit, IndexBufferRange, CommandType, RenderState, an imageblock past 16 bits),
a threadgroup length landing on the next command and one past the record, a
command's reset and a range's, a GPU-left draw after written_by_gpu, a record
that does not decode, and a blit-copy target's summary. After every call the
storage bytes, both summaries and cpu_writes must equal the model's. Verified:
both tests pass here and, as the same file, on the parent e3444f3273. Two
negative controls fail as they should: ignoring gpu_written misses the
GPU-left primitive type and draw, and ignoring the set state misses PIPELINE.
clippy --all-targets --all-features -D warnings passes, plain and under
--cfg m2v_gpu; rustdoc -D warnings passes. Named::union becomes pub(crate)
for the bookkeeping.

(cherry picked from commit df69cd7b7a60e1d054ba2786494e6668ed64d8de)
(cherry picked from commit d507c878497317b071b50c0f0160cc6ec715f190)
2026-11-03 11:48:37 -08:00
Anees Iqbal e51a3fa56d Name an ICB's per-command map CommandStates, not Commands
The kept recordings of unchanged indirect commands (four commits back) named the buffer's map of
the states the CPU set, and of its kept chunks, Commands. tests::exit_guard's
only_the_listed_modules_keep_the_device_s_functions reads the sources for copies of the device's
functions and takes Commands for the generated-commands table that holds them, so it failed at
indirect_command_buffer.rs's pipelines: Mutex<Commands>. The map holds no device function; its
name now says what it holds.

Verified: --cfg m2v_gpu, metal2vulkan-runtime's tests::exit_guard and kept_commands tests (42)
pass; the exit-guard test failed on the commit before (the M3 Max run of the runtime's lib, 1,830
of 1,831 passing).

Needs no version bump: a private rename.

(cherry picked from commit 93c48b72a7a094d6c7cee93192070f7f99e77dea)
(cherry picked from commit 831d54138016d0373b51e7c033e4c7665dbd65ce)
2026-11-03 09:25:30 -08:00
Anees Iqbal 185bbd6328 Host steps: record off the scheduler's thread, order by what the execution reaches, make only named states
A batch executing indirect commands the GPU may write waits for its gate, then its host step
records the commands from their records. Three costs fell on every other queue meanwhile:

- The step ran on the scheduler's thread, which submitted nothing while it recorded (thousands
  of draws take milliseconds).
- Its footprint was unknown (tracker::ordered's None), so every later batch of another queue that
  made a tracked use was held behind it until it was submitted.
- At commit, the render settle made a VkPipeline for every live state that supports indirect
  command buffers, times the topology class's primitive types (1,280 lookups and 513 makings for
  256 live states on the measured frame), and the step waited for all of them, up to the command
  buffer's bound.

Now:

- The scheduler hands each step to a steps' thread (scheduler/steps.rs, started at the first
  step, user-interactive like the scheduler's, recording inline where the host cannot start it),
  which records the steps in order, each a section of the exit guard, and wakes the scheduler.
  The batch is marked as stepping meanwhile (CommandBufferShared::begin_step/end_step), so it
  waits and no pass hands it over twice.
- commit bounds a step's uses where it can (Segment::bound): for a compute execution, the
  resources the command buffer made resident and the ICB's storage (and an indirect range's
  copy); for a render pass, the pass's own uses, the resident resources and each execution's
  storage. CommandBufferShared::footprint uses that bound, so only a later batch sharing one of
  those is held. An execution that inherits buffers, is gated or preprocessed, reaches tile
  memory, has shadows or lends visibility stays unbounded (None), as before.
- The render settle makes the states the CPU set on the executed commands
  (IndirectCommandBuffer::set_render_states, each state once), or the inherited one. A draw of a
  state a GPU-written record names that no settle made is begun at the step, made on its thread
  or handed to the device's pool and waited for until the command buffer's bound, as before; it
  holds no other queue's batch, and it is counted.

On the kept recordings of the commit before (item 1), set_render_states reads the states the CPU
set from the buffer's per-command map (Commands::states, a range of it), each state once.

New counters: WorkCounts::host_steps_recorded, host_step_nanos, and host_step_pipelines_made
(the VkPipelines a step began itself, made on its thread or handed to the device's pool and
waited for: counted at the variant's making on the step's thread and at pipeline_pooled).
The degrade notice host-replayed-indirect-commands states the new cost (degradation.rs and
docs/API.md, same text).

Verified on the M3 Max (MoltenVK 1.4.2), release, runtime_lane::host_replay_frames (the next
commit: 256 live states, an ICB of 5000 draws naming 4, made resident for writing by a compute
pass each frame, and a presenter clearing a texture on another queue every 8.33 ms), the parent
and this tree run alternately twice, 60 frames each after 4 cold ones, on a loaded host:
- the presenter: 80 of 244 and 73 of 192 ticks presented before (commit to completion median
  16.9 and 16.4 ms, p90 40.8 and 23.7 ms), 186 of 186 and 185 of 189 after (1.13 and 1.13 ms,
  p90 1.49 and 2.23 ms); heads held behind earlier commits 23 and 13 before, 0 after;
- the first frame's commit: 377 and 168 ms before (513 variant pipelines made, 1,284 looked
  up), 5.3 and 5.1 ms after (9 made, 24 looked up); a steady commit 2.38 and 2.33 ms before,
  0.14 ms after;
- the frame itself (commit to the last completion): median 28.7 and 24.4 ms before, 23.3 and
  24.6 ms after, within the host's noise; the host step takes about 20 ms of it
  (host_step_nanos), recording the 5000 draws.
The consumer's ICB repro (one state, 5001 draws, the ICB made resident for writing, another
queue's one-dispatch command buffers meanwhile), same runs: that queue's commit to completion at
the 99th percentile 53.5 and 24.3 ms before, 2.96 and 3.71 ms after, 140 and 119 command
buffers in 40 frames before, 2,281 and 2,062 after; the frame alike (21 to 26 ms).
Tests: runtime_lane::render_executions::
a_host_step_makes_the_pipeline_of_a_state_only_a_gpu_written_record_names (a blit-copied record
naming a state, of another variant, that the CPU set on no executed command: both commands draw,
the step's beginning of that state's VkPipeline is counted, and the step's time).

--cfg m2v_gpu under the validation layer, on this tree before the pipeline_pooled count and the
test: 234 tests of the indirect_*, kept_*, render_executions, render_gpu_executions,
render_merged_executions, mesh_commands and executions lanes; 1,644 tests of the runtime crate's lib and the
commands_recorded, dispatch_executions, generated_executions, kept_variants, device_commands,
queue_order, submission_checks and grouped_submissions lanes. clippy -D warnings, plain and
--cfg m2v_gpu; rustdoc -D warnings; scripts/api-signatures --check.

Needs a RUNTIME_VERSION bump (what a run submits, when, and its counts) and a runtime-sources
pin.

(cherry picked from commit 4b05004999403684a2bdf4f3994108b53c7dc776)
(cherry picked from commit 3831ba7e1298203779597feb0ea2943f77f9f5df)
2026-11-03 09:25:30 -08:00
Anees Iqbal 565fbd9153 Run unchanged indirect commands from kept recordings, chunk by chunk
An execution of an indirect command buffer read, decoded and recorded every
command again at every commit, so an unchanged execution of 16384 draws cost
about 44 ms of commit on the M3 Max and 64 ms on the RTX 5080 laptop, where
Metal's costs 2 ms. A profile of the render case put a third of it in the
records' decode and moves and the rest in recording the draws.

Now an execution of commands the CPU encoded records them in chunks of 256
(kept_commands.rs). A render chunk records into a secondary of its own, begun
for simultaneous use against the instance's compatible pass, through an
encoder over a core of its own whose effects the pass's core takes
(EncoderCore::capture, absorb); a compute chunk records as a segment of its
own, behind a barrier from everything before. Each chunk takes its command
pool, descriptor arena and uploads from a context of its own, lent to the
command buffer while it records and held by every command buffer that runs
it. A chunk whose recording is plain (every draw passes draw_again's keep
test but for being replayed, no step outside its command buffer, nothing its
command buffer alone holds, no released state) is kept on the buffer with
what it was recorded from: the encoder's inputs (RenderKey, ComputeKey: the
inherited state, the pass's compatible pass, shape, extent and sample
positions, the encoder's state and scissors, the resident resources), each
address its commands named and what it resolved to, and the no-copy moves.
A later execution of the chunk under equal inputs, every address resolving
as before, nothing detached and every held object alive, runs the kept
command buffer and notes its uses, keys, holds and executions again
(EncoderCore::run_kept), reading no record. Every CPU write of a command
forgets its chunk under the lock the write takes; the buffer's first GPU
write forgets them all; a recording from records written meanwhile is not
kept. A chunk that is not plain records the rest of the range as before and
is noted, so later executions of it record as before until a write reaches
it. The buffer's per-command state moves to a map, so a buffer of commands
never encoded holds nothing for them.

WorkCounts::indirect_chunks_kept and indirect_commands_kept count the kept
path. docs/FAST-PATHS.md's known gaps list the executions that still record
every command at every commit.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under the
validation layer: runtime_lane::kept_commands, 5 tests: unchanged render
commands run 3 kept chunks of 600 commands reading no record, into another
target and twice in one pass; a command written again or reset records its
chunk alone; a blit's reset runs no kept chunk and its commands draw nothing;
another residency or range records again; compute commands the same, with a
command written again and a blit reset. 446 of 448 tests of the 33 lanes
that execute indirect commands pass; the two others
(extended_range_blends half outputs, padded_loads loading pass) are among
the MoltenVK reds the parent already has. clippy -D warnings, plain and
--cfg m2v_gpu, for the runtime and validation crates; the runtime's
kept_commands unit test; the translator's fast_paths, api_signatures and
api_surface tests.

Needs a RUNTIME_VERSION bump and a runtime-sources pin.

(cherry picked from commit 21b9438ec5b8cbf7a1e79c5dfbf84cdad7b43d91)
(cherry picked from commit 922caf3199378b029bafc201429f80b0d43bb048)
2026-11-03 09:25:29 -08:00
Anees Iqbal 3cb648543f Take the indexed draw a buffer of DRAW alone runs as nothing
The steps this packet landed as, in order:
- Re-derive the generated documents at the landing tip
- Record the runtime sources' hash after the indexed draw on a DRAW-only buffer

Content: the tree of `development` at 4d0b93e5a3, unchanged.
2026-10-26 13:19:20 +02:00
Anees Iqbal d83182d197 Record the runtime sources' hash after the two indirect over-refusals
The steps this packet landed as, in order:
- Stop claiming two indirect calls are refused when the runtime takes them

Content: the tree of `development` at 161fd37a49, unchanged.
2026-10-26 13:19:20 +02:00
Anees Iqbal 04bc130a4c Make the indirect buffer and bind counts plain Metal makes, and refuse only what its process does not survive
The steps this packet landed as, in order:
- Measure the slots past the records before anything is taken, and read the taken calls at commit
- Bless the public signature table after the bind-count refusal's variant
- Take runtime version 1605 and re-derive the generated documents at the rebase tip

Content: the tree of `development` at 7f47d5fffe, unchanged.
2026-10-26 13:19:19 +02:00
Anees Iqbal 26c7aad1d0 Name the device and release behind twenty-one forwarded refusals' measurements
Content: the tree of `development` at ead49055ec, unchanged.
2026-10-26 13:19:18 +02:00
Anees Iqbal 1366be1718 Read the problems a Problem forwards to, and hold each to a basis
The steps this packet landed as, in order:
- Keep the quoted Metal messages out of rustdoc's link syntax
- Record the runtime sources' hash after the sub-problem basis lines

Content: the tree of `development` at 3ade9d9999, unchanged.
2026-10-26 13:19:18 +02:00
Anees Iqbal ce22858836 Move the fill's empty pattern and the unstrided indirect buffer out of Invalid
Content: the tree of `development` at cac3120433, unchanged.
2026-10-26 13:19:17 +02:00