Commit Graph
7132 Commits
Author SHA1 Message Date
Anees Iqbal a044cc211d rt: the kept lists are boxed, so a retiring command buffer's item stays small; the handles' unused is goes
The kept-object lists made Item::Command larger than clippy's large_enum_variant allows. The
box travels with the lists between the queue's spares and the next command buffer, so a
recording makes no allocation for it once the queue has one spare per slot. Texture::is and
SamplerState::is have no caller left: a bind compares the handles' addresses.
2026-11-18 11:51:55 -08:00
Anees Iqbal 0a2f14fccb rt: a bind borrows what the command buffer keeps; a kernel variant is found with no lock
The setters cloned the object they bound (a buffer, texture, sampler state or pipeline state)
and dropped the one the slot held: two locked instructions per call. At the census's worst
frame (9,162 bind writes) that is about 9 ms on the RX 7900 XTX, where a locked instruction
between two recorded commands flushes the write-combining command stream (about 490 ns).

What changes:

- A command buffer keeps each object its encoders set, bind, declare or copy once, as Metal's
  command buffer retains each object once (crate::kept): one list per kind and a set of their
  addresses, cleared as the command buffer retires (on the completion thread, off the encode
  path). The emptied lists go back to the queue with the command buffer's slot and the next
  command buffer made takes them, so they keep their capacity between recordings.
- The first use of an object in a recording takes its one reference. A binding slot, and the
  encoder's pipeline state, borrow the kept object (kept::Lent: the same Arc, never dropped)
  and change no count; the command buffer cannot commit while its encoder, which holds the
  borrows, is open. A repeat bind of an object already kept executes no locked instruction and
  no allocator call, and binding the object a slot already holds (the same offset for a
  buffer) returns at once and leaves the encoder's facts as they are.
- A buffer is kept as the object (its block and device copy with it), where the recording kept
  its block and device copy before; a heap's block (useHeap:) is still kept as a block.
- A kernel's first 8 VkPipeline variants each fill a cell of their own (a OnceLock) that a
  dispatch reads with no lock; only the making of a variant takes the kernel's lock, and
  variants past the 8 go in a list under it. A lookup builds no variant: the threadgroup memory
  lengths go into a list the encoder keeps, and the Variant is made only for a new pipeline.
- The harness gains bind_2000, in both runtimes: draw_2000's 2,000 draws, each with its vertex
  buffer and a fragment texture set before it, both alternating between two objects, so the
  matrix times what binds cost. A draw's plan may now bind fragment textures
  (setFragmentTexture:atIndex: in both runtimes' harness encoders).

The rt README's command-buffer paragraph and the queue's and setters' docs say what is kept.
Test: tests::kept (an object kept once, 1,000 further uses and 1,000 borrows' copies leave its
count at the list's one reference, and clearing gives it back).
2026-11-18 11:51:55 -08:00
Anees Iqbal a7a799fedb rt tests: the busy hold is the test's own batch that waits on the semaphore, not a product seam
The seam CommandBuffer::wait_semaphore_for_test put test-only code behind a cfg gate in product
sources, which this tree does not keep. The hold is now the test's own: Busy::new submits on the
runtime's VkQueue, under its lock, one batch that waits for the timeline semaphore to reach 1.
A semaphore wait's second synchronization scope covers every command later in submission order,
so each busy command buffer rt then submits is in flight and cannot complete before the host
signals the semaphore after the test's checks. Busy waits for that batch's fence before it
destroys the semaphore. command.rs and submit.rs are back as development has them.

Verified: cargo fmt; the check job (lavapipe with the validation layer) and the 3090 runs follow.
2026-11-18 11:36:54 -08:00
Anees Iqbal d85fb11862 rt tests: busy work waits on a timeline semaphore the host signals, not on a host-set event
The held-group tests' busy command buffers waited with vkCmdWaitEvents for a VkEvent the host
set after its checks, while those command buffers were pending. Vulkan forbids that:
VUID-vkSetEvent-event-09543 (an event must not be waited on by a command buffer in the pending
state when it is set), and the queue forward-progress section requires host-signalled events to
be signalled before the command buffer waits on them. The validation layer reported it on
lavapipe (VUID-vkCmdWaitEvents-srcStageMask-01158), and a driver that times out such a stall may
lose the device.

The busy submission now waits for a timeline semaphore to reach 1, which the host signals with
vkSignalSemaphore after the last check: a wait before its signal, which Vulkan defines for
timeline semaphores. rt's events never submit a wait whose signal is not submitted (the submit
thread holds such a segment), so a test-only seam, CommandBuffer::wait_semaphore_for_test,
adds a raw timeline wait to the current segment's submission (Segment::test_waits, staged with
the segment's other waits). Both exist only under the device test cfgs. The busy work is still
submitted and in flight and completes only after the host's signal, so what the tests count is
unchanged: rt's submissions, the group held behind three in flight, and completion order (a later
submission's signal covers every command before it in submission order).

Also a new test: two command buffers made and enqueued in order on one thread, the second
encoded and committed there, the first encoded and committed on a second thread afterwards. The
second waits behind the first, they complete in enqueue order, and each has its own status,
handlers and GPU times.

Verified: cargo fmt only so far; the check job runs clippy, the command device tests on
lavapipe with the validation layer, and the 3090 runs.
2026-11-18 11:36:53 -08:00
Anees Iqbal 5bf0033062 validation corpus: the authored compile census re-blessed at semantics version 2181
The census at dcd21a647e (m3-max-47614, exit 0) changed only the artifacts_at row's product
fingerprint: 990328afe1 (2180) and 727df9b7ed (2181) changed the translator. No case's
classification or outcome changed. The golden hash table at the same tip (m3-max-47613) blessed
with 0 rows removed and 0 added.
2026-11-18 11:30:14 -08:00
Anees Iqbal 5749d7c461 matrix: the UHD 630's zero_products allowance waits for the step's reach
a3eb19eaa5 landed before the ruling that holds it. One UHD job first measures whether the
1/1024 s grid of that row's GPU time is a duration threshold (zero_products at 1/2, 1/4 and 1/8
of its threads off the grid, alu at 2x and 4x on it), in which case the harness row is shrunk
below the threshold on every card and no card-keyed allowance is needed; or the kernel's shape,
in which case it goes back to the planner. The allowance re-lands as written if the job says it
is needed.

Verified: the change removes exactly a3eb19eaa5's lines (git revert of that commit).
2026-11-18 11:28:15 -08:00
Anees Iqbal d567dd503f matrix: the UHD 630's zero_products row allows one step of its GPU time's 1/1024 s grid
On the UHD 630 (8086:3e9b) zero_products' GPU time, two GPU timestamps under one calibration,
moves in steps of 1/1024 s (976.6 us) on both runtimes: of the readings in hand (m3-max-47184,
47250, 47436, 47449), the new runtime's 26 sit 7.2 to 26.1 us past a step and the old
runtime's 6 sit 58 to 71 us before one, where no other UHD row of 5 ms or more sits on it (0 of
16 per row on the new runtime, 0 of 6 on the old). Eight of its dispatches back to back in one
command buffer (47606) moved by eight steps, so each dispatch takes whole steps. The planner
ruled the row quantised on that card: its judgement allows one step. One step over old's
19.46 ms is a ratio of 1.05, so HARNESS_CEILINGS gives the row 1.05: under the budget's 1.03
its limit is 1.08, which one step (1.05) passes and two (1.10) fail. Judgement only; no product
code changes.

Verified: test_results.py, with the counter-window fix's check (job named with this sha).
2026-11-18 11:27:09 -08:00
Anees Iqbal f32e1b5213 validation: the reset counting test counts once the device's view check answered
a_reset_resets_what_each_writer_wrote_since_the_last failed on lavapipe in two matrices
(0bd215eee3, m3-max-45553; e632e01478, m3-max-47186): a reset's window of the device's
recorded commands read three dispatches where the reset records one. The device's view check
starts as the device is made, on a thread of its own, and makes each of its timed dispatches in
an internal submission whenever no batch is in flight (view_check.rs, Device::submit_internal_if_idle),
recorded through the device's own functions, so counted among commands_recorded; the test's
windows hold such idle moments between its command buffers. Two of its arms landed in a window.
The test now settles the check first, as the other counting tests in runtime_lane do
(commit_work.rs, dispatch_executions.rs, mesh_commands.rs, rebinds.rs). The old runtime is
unchanged.
2026-11-18 11:27:09 -08:00
Anees Iqbal 365cc2c7d0 rt tests: the float arena kernel's sums go through one pointer indexed by the counter
7ed9b610fd still failed on lavapipe (47610): the census held
barrier.lockstep.emulated.simdgroup. The command line on lavapipe's profile placed it in the
third loop alone (47622: the kernel without that loop has the program's two barriers and no
other). That loop stored each sum at out[w + j], an addition of two values the order does not
prove free of wrapping, so it found the store and itself in another iteration as a pair. The
sums now go through out + w, one pointer in every thread, indexed by the loop's counter, as the
first two loops index theirs.
2026-11-18 11:24:54 -08:00
Anees Iqbal b9f226c4bd rt tests: the float arena kernel leaves no pair to lockstep
every_device_runs_a_float_arena_that_fills_the_threadgroup_memory_limit failed on lavapipe:
its census lacked access.threadgroup.store.floats and held
barrier.lockstep.emulated.simdgroup. The lockstep order found pairs in the kernel: its loops
are bounded by params[0], a loaded word with no range, so the analysis reads no loop counter
and two threads of one SIMD group may meet within a loop; and the second loop's stores to
out[w + j] follow the first loop's to out[k] with no barrier between, where two such threads
could meet at one word (a loop runs once in a thread past the region). Where the entry
reconverges maximally on 32-lane subgroups, as on the GPUs the test passed on, those barriers
are subgroup barriers and the kernel keeps its tier; on lavapipe they are emulated SIMD-group
barriers, the kernel runs on the emulated tier, and an emulated tier's arena keeps composed
u32 words (choose_words), as designed. So the product was right and the test assumed a kernel
without lockstep pairs.

The kernel now masks params[0] to 18 bits (every device's limit is fewer words), which bounds
each loop's counter, and a device-memory barrier stands between the two loops. The test
asserts that the census holds no lockstep barrier before it checks the float-word accesses,
so a kernel that gains a pair says why.
2026-11-18 11:24:54 -08:00
Anees Iqbal dcd21a647e rt README: NVIDIA's host-visible allocation cost, next to the free hold
The planner's ruling on the pool trace: no reserve change, and the cost of a
take longer than the pool's allocations is recorded as NVIDIA's. Figures:
the r4 pool trace on the RTX 3090 (job m3-max-47374): Shared allocations on
the consumer's threads 0.137 ms per MiB (253, 12,436 MiB, 1.71 s), Private
0.033 ms per MiB (123, 5,752 MiB); six Shared takes of 547-548 MiB at about
70 ms each; Shared takes past 16 MiB 1.46 s of the 210 s play. The RTX 2080's
first-take probe: host-visible 64 MiB in 12.7-19 ms in every form (plain,
device address, dedicated; cached or uncached).
2026-11-18 11:14:38 -08:00
Anees Iqbal 34a40aedbb rt: the capture ring is made at the first didModifyRange, off every commit; the staging rings are not zeroed
The device's first capture of Managed ranges made the 64 MiB capture ring
inside the commit's turn (submit.rs capture), which every commit with commands
takes first (command.rs commit). Region::new allocates it (vkAllocateMemory of
the Shared type) and wrote all 64 MiB, so every other thread's commit waited
for one host-visible allocation and memset: on NVIDIA about 13-19 ms plus
about 2.4 ms (the 2080's 64 MiB figures; not measured on this path).

Now the device's first named range (Work::modify, from
Buffer::did_modify_range, which new_managed_buffer and replace_region over a
Managed buffer call) makes the ring on the naming thread with no lock held, and
installs it under the work lock; a second maker that lost the race frees its
own. The capture always finds the ring: a range is named only after it exists.
A failure to make it is "cannot run at all", so did_modify_range returns it
(Limit::MemoryAllocations, Error::Vulkan), and its callers' docs say so.
docs/REFUSALS.md does not change (regenerated).

Region::new no longer zeroes its bytes, for the capture ring nor the 16 MiB
staging region. The memset only made the pages resident; nothing read the
zeros. What makes that safe: every user writes a span before anything reads
it. An upload (replace_region, a capture) writes the packed rows or the
captured range on the host, then the GPU copies exactly those bytes; a
readback (get_bytes) has the GPU copy write the packed rows, and the host
reads those rows once it completes. A span is reused after wrap without being
zeroed again, so the zeros never held past each span's first use anyway.

Test (src/tests/managed.rs, device cfgs, devices with a device copy): with the
ring's making parked on the naming thread, another thread's commit of a
command buffer with commands completes; then the named range reaches the
device copy at the naming thread's commit. Without the fix the naming thread
parks inside its commit, holding the turn, and the other commit times out.
2026-11-18 11:14:37 -08:00
Anees Iqbal 3578d67519 rt: the parameter ring makes a block off its lock, one take at a time
Ring::take held the device's ring lock across make(): vkAllocateMemory of a
2 MiB block of the ring type, its bind and vkMapMemory. Every encoder's ring
write when its chunk fills takes that lock (ring.rs Writes::write), and so does
the completion thread's retire of every command buffer (command.rs retire ->
Writes::give_back) and the drop of one never committed. So a draw or dispatch
encoding on another thread, and every completion, could wait out a driver
allocation they did not ask for.

Now a take that finds no free chunk marks the ring as making and makes the
block without the lock. A take that finds no chunk while a block is being made
waits on the ring's condvar for that block, or for chunks given back, so two
takes that meet make one block between them: the ring still holds exactly what
the command buffers in flight at once have needed, as before (no cap; kept for
the device's life). A give-back wakes the waiters only while a block is being
made.

Test (src/tests/ring.rs, device cfgs): with every chunk taken, a take parked
where it makes the block leaves the ring's lock free; a give-back on another
thread returns meanwhile; a second take that meets it makes no block of its
own (one block between them); a fill past the ring's chunks makes one block,
and chunks given back are taken again before any further block. Without the
fix the first assertion fails (the parked maker holds the lock).
2026-11-18 11:14:37 -08:00
Anees Iqbal 727df9b7ed translator tests: the old runtime's render descriptor key under semantics version 2181
The key hashes SEMANTICS_VERSION, which dea9557af8 bumped, so its pinned value moves; the
fixture's bytes are unchanged.

Verified: m3-max-47540 printed the new key (4de8f0fc...) as the test's left side, at
843e955885; golden_hashes_match_the_table passed there.
2026-11-18 11:13:29 -08:00
Anees Iqbal 0d82f05170 validation: the runtime-sources pin for the grid tile edge test under its ragged flag
The pin hashes the translator sources the old runtime is built from, SEMANTICS_VERSION
included, which dea9557af8 bumped. Recomputed from the tree.
2026-11-18 11:13:29 -08:00
Anees Iqbal 4b781a949c translator: a grid tile tests its edge only inside a branch on its region's ragged flag
On Device::from_queries' profile a kernel that runs its grid in tiles compared every
invocation's position with the grid's last thread before its body, on every dispatch. The
test now sits inside one uniform branch on the region's NONUNIFORM flag, which rt (and the
binder) already set for every region of a grid its workgroups do not divide: a ragged
dispatch runs today's test, and every other dispatch (a grid the workgroups divide, an
indirect dispatch) branches past it, its body deriving its position only where it reads it.
One pipeline serves both, so there is no added compile or first-use wait. Device::new's
profile has no grid tiles, so its modules are unchanged.

The branch is also what keeps a driver's scheduler from spreading a kernel's pushed-word
loads through its body: a form that dropped the branch lost 17-55% on a many-binding row on
RADV and the UHD 630.

SEMANTICS_VERSION 2180 -> 2181. The grid tile tests now run each grid flagged and
unflagged: flagged, no invocation past the grid stores; unflagged, a ragged grid's do, so
the flag alone guards the test.

Verified at the same change on 69af14bd22 (12f3602f1d): lint, the translator suite and rt on
lavapipe (m3-max-47411); rt's device tests 249/249 on the Iris (47443), the 7900 XTX and the
RTX 2080 (47498). Compiled code: the flag test is a wave-level scalar branch over the decode
and compare on RADV (7900 XTX, 47462) and a uniform branch on ANV (Iris, 47407); the
many-binding row's pushed-word loads stay together under one wait. Harness compute rows
against 69af14bd22, losses re-timed alone: UHD 630 (47436, 47449), Iris (47407), 7900 XTX
(47408, 47441), RTX 2080 (47408, 47441), RTX 3090 (47409, 47461), RX 550 and 780M (47406).
2026-11-18 11:13:29 -08:00
Anees Iqbal a914d524ea Re-derive the generated documents at the landing tip
They are generated from the whole case set, and the set grew on `development`
while this branch was in flight, so the copy committed here counted a smaller
one.

Verified: regenerating at this tip leaves no change beyond the `Generated at`
stamp.
2026-11-18 11:05:35 -08:00
Anees Iqbal 9d966c54df rt: a tally adds only the metrics it counted
The encoder change's tally visited all 25 metrics at each add, at every
encoder's end and again at every commit: on a burst of command buffers of one
dispatch each that is two 25-step loops per command buffer. On the Iris Xe
host (job m3-max-47513, i9-13900H pinned to its performance cores) burst_2000
took 29,285 user-space instructions per command buffer at bfaf8ca194 against
28,581 at 69af14bd22, with the encode time the same (5,852 against 5,788 ns).

The tally now keeps a bit per metric counted, and the add visits those alone:
one atomic add for each metric counted, none for a tally that counted
nothing (a commit with no command between its encoders). Expected to take
the per-command-buffer instructions back under the tip's; to be measured.
2026-11-18 11:04:48 -08:00
Anees Iqbal d2436a1887 rt: clippy's findings on the encoder change
The single-copy barrier lists are slices already (no borrow), and the region
bytes' refusal goes back to ok_or: the value is a plain enum with no
allocation, so building it eagerly costs nothing (clippy's
unnecessary_lazy_evaluations). The commit before said ok_or_else; this one
is what holds.

Verified: m3-max-47464 at 68f4c7c829 compiled, rt tests 97 passed, the rt
device tests on lavapipe 251 passed (both new counter tests among them),
conformance 1053 passed; clippy x3 reported these three findings only.
2026-11-18 11:04:48 -08:00
Anees Iqbal 6e661ec239 rt: an encoder's draws, dispatches and copies execute no locked instruction
On RADV a recorded command lies in write-combining memory, and any locked x86
instruction between two recorded commands flushes it: a probe with no rt code
in the loop (raw vkCmdDraw on the RX 7900 XTX) cost about 490 ns more per draw
with one locked instruction between draws, about the same with two, and
nothing with a plain increment; NVIDIA showed no difference. rt's draw path
executed 3.6 locked instructions per draw on draw_2000 and 12.6 per dispatch
on dispatch_chain (mem_inst_retired.lock_loads on the Iris Xe host), which put
draw_2000 at about 567 ns per draw on the XTX against the old runtime's 124 to
143 ns.

What changes:

- Each encoder (render, compute, blit) holds the device's core, cloned once
  when the encoder opens. A command borrows it and the pipeline state; neither
  is cloned or dropped per draw, dispatch or copy.
- Per-command counts (passes, barriers, pushes, pushes held, ring writes,
  dispatches without effects, synchronizes) go into the recording's tally, a
  plain array that the device's counters take once, at the encoder's end
  (CommandBuffer::close_encoder), and at commit for what was recorded between
  encoders. The README's counters paragraph and Counters' doc say so.
- What a draw learns from its bindings is kept until the pipeline state or a
  binding changes: the vertex-buffer list, the vertex-buffer offset checks, the
  alignment checks, whether a bound texture is of an image the pass renders,
  whether a reached buffer has a device copy or a written texture is over one,
  and whether it writes what the host reads. A dispatch keeps the same for its
  kernel: alignments, the Managed reach and the host write. The push bytes of
  a draw are filled again only when what they carry changes.
- The recording filters vertex-buffer binds: a binding already bound to the
  same buffer and offset in the current Vulkan command buffer is not bound
  again. Vulkan keeps the binding across renderings and pipeline binds of one
  command buffer; the filter resets when a segment begins its command buffer.
- Error values are built only on the error path (later_kernel takes a
  closure; region bytes use ok_or_else). A buffer copy's barriers for one
  region are on the stack.

What marks the kept facts stale, in the render encoder: a different
pipeline state; setVertexBuffer/setFragmentBuffer (a buffer or none);
set*BufferOffset; set*Bytes; set*Texture. Push bytes only: set*SamplerState,
a pass's feedback moves, and a change of the shadow slots an attachment read
uses. In the compute encoder: a different pipeline state; setBuffer;
setBufferOffset; setBytes where the slot held a buffer (bytes are aligned and
of no Managed or Shared buffer); setTexture; useResource. A different module of
the same state (partial, emulated, tiles) finds the Managed and host facts
again. Outside the encoder nothing changes a kept fact: each is of the bound
objects (a buffer's device copy, storage mode, length and address, a texture's
image, storage and format) and of the pass, which do not change while bound.
What can change outside the encoder between two commands is read again at
every draw and dispatch and never kept: the device's count of textures over a
buffer in images of their own (an atomic load), and a Managed buffer's textures
over its device copy (an atomic load), for every buffer a kept fact says has a
device copy and for the index buffer. A new segment's command buffer resets the
vertex-bind and push filters.

Paths that still execute a locked instruction or call the allocator:
- setters: each bind clones the bound object (buffer, texture, sampler,
  pipeline state) and drops the one it replaces, and the command buffer's
  first keep of an object clones it; the next stage makes the tables refer to
  the command buffer's kept lists;
- the first dispatch after a compute pipeline state or a threadgroup memory
  length changes: the variant lookup takes the kernel's variant lock and
  builds the variant's length list;
- the first use of a kernel's partial or emulated module, of a content's line
  pipeline (RenderCompiled::pipeline's lock for line topologies), and of a
  fence on a queue;
- attachment reads: the feedback moves and the shadow copies (their lists,
  ordered_command, and the copied-bytes counters);
- Managed buffers with textures over their device copy: the backs (the
  entries lock), wrote_managed and wrote_texture_managed (a clone on the first
  write of a segment, the entries lock);
- textures over a buffer in images of their own while any lives: the overs
  list and their copies;
- a segment's begin and close (the core's clone, the recorder pool), a new
  64 KiB parameter-ring chunk (the ring's lock), the hazard marks' growth past
  their highest id so far, and a synchronize of a Managed texture (a copy per
  level and slice).

Tests: every_device_counts_an_encoders_draws_at_its_end (2,000 draws move none
of the device's counters while the encoder is open; its end adds the pass, the
push and 1,999 pushes held) and every_device_counts_an_encoders_dispatches_at_its_end
(2,000 dependent dispatches; the end adds the pass, 1,999 barriers, the push
and 1,999 pushes held).
2026-11-18 11:04:48 -08:00
Anees Iqbal 1e8e5974fc REPLAY-STREAM: section 6 names the writes at a completion
The comparison point takes the GPU's bytes at a completion only for 4 KiB chunks wholly inside
GPU-only ranges, and a recorder may record what a command buffer's GPU work stored in memory the
CPU shares as writes after its commit: which chunks are compared, the Managed rule, why the
player's waits make them change nothing, and the restore they let a stream carry. The planner's
text, verbatim, for the recorder change that lands with it.

Doc only; no test reads this section.
2026-11-18 10:57:59 -08:00
Anees Iqbal c3eaeb5a68 rt tests: busy work waits on an event the host sets after the checks, not on enough fills
The held-group tests keep a queue's three submissions in flight with busy command buffers
and check what the queue holds behind them. The busy work was fills, escalated from 16 to
4,096 per command buffer, retried when the work ended before the checks: a timing bet that
a fast card or a loaded host beat (the second-queue test failed on a 3090 at command.rs:1078).

Each busy command buffer now waits on the GPU for a VkEvent only the host sets
(vkCmdWaitEvents with the host stage as its first scope, valid outside a render pass for an
event set after submission), then fills once. It is submitted and cannot complete until the
test opens the event after its last check, so the checks need no retry. Busy owns the event
and opens and waits for its work on drop, so a failed check does not leave work waiting.
behind_busy, the second-queue test and the three-in-flight test use it; the FILLS rounds and
the ran retries are gone, their conditions now assertions. Each behind_busy body opens the
busy work before it waits for anything queued behind it.

Verify: clippy under --cfg m2v_gpu, rt's command device tests on lavapipe, and the three
tests 20 times each on one fast card.
2026-11-18 10:56:18 -08:00
Anees Iqbal 181dae8452 replay: the wait's doc names rt's wait_until_completed, which the bounded-wait source test does not match
device_waits_exist_only_in_the_bounded_wait_module fails on any file outside gpu/wait.rs that spells
one of Metal's or Vulkan's unbounded waits, comments included. 0463eb6d2d's doc comment on
wait_for spelled Metal's method name, so the test failed on lavapipe in the matrix at e632e01478
(m3-max-47186). The comment now names the runtime method the code calls.

Verified: the test's five patterns, grepped over the validation crate's src and tests, match no
file outside src/gpu/wait.rs.
2026-11-18 10:49:51 -08:00
Anees Iqbal 45b9c4550b rt: a buffer argument bound to nothing reads the nil buffer, 64 KiB of zeros
What: the parameter ring keeps one chunk as the nil buffer (ring::Ring::nil). It takes the chunk
at the first ask, zeroes it from the host and keeps it for the device's life. The chunk is 64 KiB
at a multiple of 16, like every chunk, so it meets any buffer argument's alignment. A dispatch's
alignment check (encoder.rs, check_alignments) gives the nil buffer's address where an argument
its kernel reaches is bound to nothing, and the parameter block takes that address in place of 0.
A draw does the same, its check loop giving the address that fill_push and the tables' address
take (render_encoder.rs). This holds on every device, with no gate. The runtime README's buffer
bullets say so, and that reads past the 64 KiB and writes through a nil argument aren't covered.

Why: Metal's nil buffer reads zeros. The pushed 0 made a read through such an argument a read of
address 0.

Verified:
- rt clippy with all features, with --cfg m2v_gpu and with --cfg m2v_cpu_icd clean; the rt host
  tests 95 of 95 (job 47272, at dd8b58f4f1, this change before its rebase onto 11dc2d46d5).
  Rebased on 11dc2d46d5: the same three clippy runs clean, the rt host tests 97 of 97 (47369).
- The new device test (a kernel of 64 threads reads words t and 16320 + t of an unbound buffer
  argument; all 128 words land as zeros, and the command buffer completes with no error) and the
  rest of the rt device suite, 243 of 243 with the validation layer on and no validation error:
  RX 550 (47468), RTX 3090 (47344), Iris Xe (47345), lavapipe (47346).
- The control, built with the unbound argument's address pushed as 0 as before the change, fails
  the new test on lavapipe without reaching its assertions (47347).
2026-11-18 10:45:35 -08:00
Anees Iqbal 3ccb75646a Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-18 10:45:17 -08:00
Anees Iqbal 990328afe1 translator: from_queries' profile contains no threadgroup access, and an arena of whole float words is a float array
What: a new profile fact, device::profile::ThreadgroupMemory, says whether an access of
threadgroup memory is contained. Device::new's profile keeps Contained, byte for byte: a load past
an arena reads zero, a store past it is dropped, and a typed threadgroup object's dynamic index is
clamped to its level. Device::from_queries' profile takes Native: no threadgroup access is
contained, and an access past a kernel's threadgroup memory is undefined, as in Metal. One
predicate, lower::access::local's contained(), decides it at the six sites that contained one:
an arena's loads and stores, its atomics, memory intrinsics, pointer cells and imageblock, and a
typed threadgroup object's index. Device memory's containment is unchanged.

On the Native profile, a kernel's arena whose every access is a whole, aligned float word (a float
or a vector of 2 to 4, at an offset its alignment makes a multiple of 4, with no atomic, no memory
intrinsic and no access of another type: memory::Leaf::float_words) is a float array of its own
whole words, at least four (memory::arena::FLOAT_LEAST). Each access is one typed load or store per
lane at its word index, with no bounds compare, no select and no bitcast. Every other arena stays
the u32 array of composed words, unchecked on this profile. The census names the float form's
accesses access.threadgroup.load.floats and access.threadgroup.store.floats.
SpecOp::ISub, which only the contained arena's bound used, is deleted.

docs/API.md's threadgroup memory bullet says so. The runtime README's contract states that an
access past threadgroup memory is undefined, as in Metal, and that the runtime does not confine
it. SEMANTICS_VERSION 2180; the old render key's pin moves with it.

Why: Metal leaves an access past threadgroup memory undefined, so containing it changes nothing a
correct program observes. Containment cost GPU time on every card measured: each access paid a
bounds compare and a select, and each composed word paid its bitcasts.

Verified (A = before this change, D = this change, both on from_queries):
- GPU p50 of the harness rows whose kernels use threadgroup memory or SIMD-group operations,
  D over A, the median over 6 rounds of each. threadgroup_floats is a float scan that the probe
  harness adds. No other row's kernel declares threadgroup memory (workloads.metal).
  - UHD 630 (job 47289): threadgroup_scan 0.972, threadgroup_floats 0.892, simd_reduce 1.000,
    vote_loop 1.000.
  - Iris Xe (47290): threadgroup_scan 0.965, threadgroup_floats 0.919, simd_reduce 1.000,
    vote_loop 1.000.
  - Each arm's spread (its largest run over its smallest) is at most 1.013 on both cards.
- Driver compile per kernel on the UHD 630, the median of 5 cold processes per arm, each with a
  fresh store and driver cache and the module bytes salted (47319). Every process exited 0. D over
  A: the float scan 0.716, the typed scan 0.945, the SIMD reduce 0.951; the two kernels whose
  modules are the same in both arms 0.998 and 1.062.
- The same on the Iris Xe (47349): the float scan 0.678. The typed scan (1.108) and the SIMD
  reduce (1.19) are inside the run-to-run spread of 1.164 that a module equal in both arms shows.
- Cold plays of a replay stream up to frame 216, 4 per arm, with the arms alternated. Every
  threadgroup kernel matched by function identity, 16 of 16 in each arm.
  - RTX 2080 (47294): GPU 378.1 ms in A, 307.9 ms in D; driver 1154.8 ms against 1158.8 ms.
    The 128-wide kernels: 0.634 (18 dispatches) and 0.793 (65). The 64-wide kernels: 0.808 to
    0.959. The 1024-wide kernel: 0.933. The 395-dispatch kernel: p50 1.010, its total 0.996.
  - Radeon 780M (47295): GPU 127.8 ms in A, 116.8 ms in D; driver 234.7 ms against 202.6 ms.
    Every kernel's p50 is at or under A's: the 128-wide kernels 0.826 (18 dispatches), 0.799 (65)
    and 0.966 (5); the 64-wide kernels 0.815 to 0.938; the 1024-wide kernels 0.981 and 0.978;
    the 395-dispatch kernel p50 0.981, its total 1.006.
- Rebased on 11dc2d46d5: clippy with all features and with --cfg m2v_gpu clean; the translator's
  and the new runtime's whole suites 3831 of 3832, the one failure the old render key's pin, which
  SEMANTICS_VERSION 2180 moves; re-pinned here, it passes (47341). The golden-hash tests among them pass unchanged.
- No test of this change asserts what an access past threadgroup memory does. The containment
  tests of Device::new's profile stand.
2026-11-18 10:44:29 -08:00
Anees Iqbal f811e7cc2d replay: delete the unbound-buffer-read counter, whose reflection decoded each pipeline state's AIR again inside the play's pipeline time
The counter (74fe5e67ca) asked the translator for each pipeline state's reflection to learn its
used buffer arguments. From a Function source that reflection decodes and specializes the
kernel's AIR a second time, inside the backend call the player books as pipeline cost, so every
play paid it: on b3 on the 780M, pipeline time 11.9 s against 1.5 s at f0df30b6ba with the same
403 translations (exclusive A/B, 47329). Its follow-up is dropped, so the count, its report line,
its per-frame counter, its test and its paragraph in REPLAY-STREAM.md go.

Verified: see the exclusive A/B in the hand-over (b3, 780M, development's tip against this).
2026-11-18 10:15:38 -08:00
Anees Iqbal 69af14bd22 rt: a texture over a buffer keeps in place where its linear tiling lacks only image blits
check_over put a texture over a Shared buffer in place only where the format's linear tiling had
every feature of its optimal tiling that the usage uses, and counted BLIT_SRC and BLIT_DST among
them. The runtime records no image blit: a blit encoder's copies and fills are transfers. Mesa's
Apple-GPU driver (KosmicKrisp, Mesa 26.3.1) on an M3 Max offers RGBA8Unorm's linear tiling every
feature but BLIT_DST (linear 0x40018000d403, the optimal features the usage keeps 0xdc01, missing
0x800, job m3-max-47342), so tests::over's every_device_holds_a_texture_over_a_buffer_in_place
copied at width 1 where the device's own layout fits. The kept features are now the transfers,
sampling and its linear filter, a shader's storage access, and rendering.
2026-11-18 10:09:07 -08:00
Anees Iqbal 0d20ded2fe rt tests: a command buffer's GPU start may equal its end, as Vulkan allows
Vulkan orders timestamps (a later one is never lower) and lets a device write one at any
logically later point; Metal documents gpuStartTime <= gpuEndTime. Mesa's Apple-GPU driver
(KosmicKrisp, Mesa 26.3.1) asks Metal for relaxed timestamp granularity on a compute encoder, so
the two timestamps around a command buffer with no render pass read one value: on an M3 Max,
tests::command's every_device_retires_a_group_in_commit_order_each_with_its_own_times and
every_device_takes_again_the_slot_of_a_command_buffer_that_never_ran failed on start == end
(job m3-max-47313). The two tests now hold 0 < start <= end; the order across the group stays
strict. Product code is unchanged. The README's known gaps name the driver's answer.
2026-11-18 10:07:27 -08:00
Anees Iqbal 263077505e Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-18 10:03:30 -08:00
Anees Iqbal 11dc2d46d5 translator: a removed argument's read takes zero and writes no status on from_queries' profile
What: a read of a texture, sampler or threadgroup memory argument the pipeline's function
constants removed (the absent read, lower::access::absent, and texture::AbsentArgument) takes the
same zero of its result's type as before: a read's zeros and a query's size of 0, which the nil
texture, set 1's element 0, answers too, with a write of a removed texture dropped. A new profile
fact says whether it also marks the command buffer's status (device::profile::AbsentReads):
Device::new's profile keeps Marked (StatusBits::ABSENT_ARGUMENT_READ, the ExecutionStatus fact,
its push field or binding), byte for byte; Device::from_queries' takes Nil, where the read marks
nothing and the stage states no AbsentArgumentRead or ExecutionStatus fact, no
ExecutionStatusAddress push field and no status binding. One form per profile, so it holds on
every stage: a fragment function's read, which the replay recordings name, and a kernel's, whose
pipeline the translator refused before on from_queries' profile (IdentityDomains: the status
word's push field is outside what the identity domains admit), now run. The
fact keys from_queries' fingerprint; Device::new's renders its fields alone, unchanged.
docs/API.md's degrade entry and ExecutionStatus bullet say so. SEMANTICS_VERSION 2179.

Why: Metal gives such a read no value, and its compiler drops or folds it; the new runtime writes
no ExecutionStatus words, so the status a read marked was a refusal of the whole pipeline.

Verified:
- f0c676d4f7, this change before its rebase onto a47fc3e69d: clippy with all features and with
  --cfg m2v_gpu clean, the focused tests 66 of 66 (job 46992). The rt device tests of a fragment
  function's and a kernel's read of a removed texture pass with the validation layer on and no
  validation error on the RX 550 (47027), the RTX 3090 (47028) and the Iris Xe (47029); the
  control, built without the change, fails both (47030).
- Rebased on a47fc3e69d: clippy with all features and with --cfg m2v_gpu clean; the touched tests
  (absent, function constants, profile, golden, render descriptor keys, public fixtures,
  fingerprints) 257 of 258, the one failure the old render key's pin, which SEMANTICS_VERSION
  2179 moves; re-pinned here, it passes (47245).
2026-11-18 10:02:42 -08:00
Anees Iqbal 3e117449f2 rt: count a submission before vkQueueSubmit2, so whoever sees its work complete sees it counted
The submit thread counted `Metrics::submissions` (and `submit_infos`) after vkQueueSubmit2
returned. The work can complete before the call returns (lavapipe runs it at once), and a thread
waiting on it, such as a texture read's wait on its upload, goes on to read the metrics while the
submit thread has not yet counted. Under load the late count lands in the next counted window:
tests::pass::on_device::every_device_clears_loads_and_stores_render_attachments failed on
lavapipe at random, at pass.rs:359 and at pass.rs:419 (left (2, 1, 1), right (1, 1, 1)), each
window opening just after a texture read. The metric's contract is vkQueueSubmit2 calls, which the
count before the call keeps; a failed call loses the device either way.

Verified on lavapipe under load (job m3-max-47252, msi): four loops of the pass test beside two
loops of the rest of rt's device suite (8 threads each, LP_NUM_THREADS=1). With the old count
(HEAD~1's submit.rs) the test failed within 5 s, at pass.rs:437 (left (2, 2, 2), one submission
more); with the count before the call it ran 14,850 times in 425 s with no failure. Clippy
(--cfg m2v_cpu_icd, all targets, all features) is clean.
2026-11-18 09:52:47 -08:00
Anees Iqbal 921afdae2f replay: the player zeroes a stream's block from its take's zero mark, and the zero-once test counts the bytes the takes found zero
The zero mark (1823e99d4d) makes rt::Device::new_buffer skip the bytes a take
found zero, so the player's zeroing of a fresh block counted fewer bytes_zeroed
and the zero-once test's count failed on the 2080 (m3-max-47124) while its
checksum held. The player now zeroes from block.zeroed, as the mark's contract
says (bytes past the mark are the consumer's to zero), and the test counts the
bytes inside the marks (zeroed_bytes_taken) with the bytes the buffers zeroed.
2026-11-18 09:49:56 -08:00
Anees Iqbal 2e6acecbab rt tests: the zero-mark test prints the process's resident bytes across the next allocation made and zeroed ahead
A take that leaves the Shared class under 8 MiB free has the block-maker thread make and zero
its next allocation; on Linux the test prints /proc/self/statm's resident bytes before the take
and once the allocation is zeroed, the host pages that zeroing (and the driver's allocation)
committed. A print only; nothing asserts on it.
2026-11-18 09:49:56 -08:00
Anees Iqbal 9be118cb5b rt: a take answers its zero mark, and the consumer asks for a Private range's zeros
The zero mark (BlockInfo::zeroed): how many of a block's first bytes the runtime itself zeroed
and nothing held since, as the take found them. They read zero; bytes outside the mark are the
consumer's to zero where Metal owes zeros. Nothing is inferred from the driver, the memory type
or a fresh allocation: the runtime zeroes from the front only, on the block-maker thread.

- Each Shared allocation made ahead of need is zeroed whole before it joins the pool (each
  device's first in its making), and its bytes are the allocation's clean ranges; a block carved
  there takes the clean run at its offset as its mark.
- A Shared block given back is zeroed again from its first byte, in steps of 256 KiB, while it
  is kept; a take of it between two steps waits at most for the step that runs (the thread
  starts none while a take waits) and gets the mark as it stands. A kept block's zeroed bytes
  given back to its allocation stay clean. A block given back has mark 0 until then: the
  consumer may have written any byte.
- Device::new_buffer zeroes only a Shared buffer's bytes past the block's mark, and every
  placement lowers the mark to its offset (new_managed_buffer's bytes too).
- Private blocks carry no mark. Device::zero_block_range(block, offset, length) zeroes a range
  of one the consumer holds by a GPU fill on the upload path new_buffer's Private zeroing uses,
  ahead of every later commit; it never waits and is never done at a take. Refusal::
  ZeroRangePastBlock and Refusal::ZeroRangeShared (REFUSALS.md regenerated).
- Metrics: allocations_zeroed, allocation_zeroing_nanos, kept_bytes_zeroed, kept_zeroing_nanos,
  zeroed_bytes_taken, zeroed_bytes_freed (zeroed bytes an idle free gave back before any take),
  block_zero_fills, block_zero_fill_bytes; the replay player keys them; api_signatures blessed.
- README: the consumer contract and the zeroing of kept blocks under the consumer's mappings.

Tests: Ranges' run_at and cut; a Shared block of the made-ahead allocation is marked and reads
zero whole; written, given back and kept, a take after three steps answers three steps' bytes,
zero, the rest as written; a zeroed buffer then zeroes only past the mark and lowers it; given
back again it is zeroed to its end. A Private block written by a kernel, kept and taken again,
zero-filled over its first half, reads zero there to the next command buffer's kernel and the
kernel's words past it; the refusals and NoSuchBlock. The three tests that check kept Shared
bytes stay as written hold the zeroing.

Verification: the check job and device legs run on this commit.
2026-11-18 09:49:56 -08:00
Anees Iqbal ca184e3e6d rt: an image-only kernel's tile over a deep grid takes the depth nearest the threadgroup's
An image-only kernel runs a grid more than one deep in 256-thread tiles, a VkPipeline each. The
tile came from the grid's extents alone (the translator's grid_tile, the shallowest first), so
threadgroups of 8x8x4 over 512x512x16 ran in 128x2x1 tiles: 1.8-2.3x the old runtime's GPU time on
the UHD 630, Iris, RX 7900 XTX and RTX 2080, against 0.88-1.23x for the guest's own 8x8x4.

The tile is now picked from the grid and the call's threadgroup size (encoder::image_tile): of the
45 tiles, the fewest threads launched, then the fewest tiles partly past the grid, then the depth
nearest the threadgroup's (the shallower of two as near), then the most square in x and y, then
the wider. Threadgroups of 8x8x4 over a grid 8x8x4 tiles divide run in 8x8x4; threadgroups one
deep in 16x16x1, the square pipeline made with the state. Grids one deep keep the square. A pure
function of the grid and the threadgroup size, the same on every device; the bound of 46
pipelines per image-only kernel is unchanged. Tiling kernels keep grid_tile.

Tests: choice.rs states the order over guest shapes and grids.
2026-11-18 09:43:26 -08:00
Anees Iqbal fbdaa5fb9a harness: deep rows at other threadgroup sizes, and deep layers that read their own source
Rows for the deep image tile's choice, beside sampling_deep_512x512x16 (threadgroups of 8x8x4):
- sampling_deep_512x512x16_8x8x1, _16x16x1 and _4x4x4: the same work, sample_down_layers over
  512x512x16, in threadgroups of 8x8x1, 16x16x1 and 4x4x4;
- sampling_distinct_64x64x16 and sampling_distinct_512x512x16, in threadgroups of 8x8x4, through
  a new fixture kernel, sample_down_distinct: layer z is a 2x downsample of its own rows of the
  source into its own rows of the destination, so no two layers read the same texels.
  sample_down_layers samples the same source texels on every layer, which gives a tile deep in z
  cache reuse across layers that a kernel reading distinct layers does not get.

Each is checked against its CPU reference. MSL in fixtures/public/harness/workloads.metal,
compiled with scripts/regen-air-fixtures --dir harness on the M3 (job m3-max-47067; the
TOOLCHAIN is unchanged).
2026-11-18 09:43:26 -08:00
Anees Iqbal a47fc3e69d translator: an argument buffer's texture index is masked to the set-1 image arrays
What: under the identity domains (Device::from_queries' profile alone; Device::new never takes
them, so its modules are unchanged), the handle of a texture whose resource ID an argument buffer
holds is the ID's low word masked to its low 16 bits (IDENTITY_TEXTURES - 1, the two image
arrays' 65,536 elements, a power of two the compiler checks): one OpBitwiseAnd a handle. A bad ID
reads the element at index & 0xFFFF, never one outside the arrays. Nothing else changes: a slot's
index is the runtime's own push (SlotGuestBase), a constexpr sampler's too (ConstexprSampler), and
an argument buffer's sampler is not lowered under these domains, so the sampler arrays stay at
4,000 with no mask. docs/API.md, where that sampler's refusal is listed, and RESOURCE-ID.md say
the change that first lowers one masks its index the same way. The new runtime's README records,
among the known gaps of memory blocks, that a shader uses a buffer's gpuAddress unchecked, so a
stale one can still fault the device. SEMANTICS_VERSION 2178: from_queries' translations of such a
texture change (2177 is the unlanded float-array branch's).

The feedback elements (index + 65,536 in the sampled array, where the device reads attachments):
only a draw's push of a texture slot's index reaches them. The render encoder builds no
useResource: or useHeap:, so no draw makes an argument buffer's texture resident, and Metal reads
an argument buffer's texture only once it is resident; the mask keeps every argument-buffer index
below 65,536 besides. So an argument-buffer texture that is also the pass's attachment is never
offset to its feedback element: the shader reads element index, as before, a read Metal leaves
undefined while the texture is not made resident (only the compute encoder has use_resource and
use_heap).

Why: the ID is the program's word, and an index past the arrays fetches a descriptor outside
them.

Verified:
- Check 46942 (msi) at this change on 98efd4de50: clippy, all features, 0; clippy under
  m2v_gpu 0; the identity, golden, old render key, resource ID and public fixture tests 86 of 87,
  the one failure the old render key, pinned here at 64b84e0f... from that run (SEMANTICS 2178).
- Final check 47056 (msi) at this tree (as 5794117bcb): clippy, all features, 0; clippy under
  m2v_gpu 0; the same tests 87 of 87, the old render key at its pin among them.
- Words per identity texture kernel (base d392d453d6, 46865 -> this change, 46942): without an
  argument buffer 829 -> 829; with one 1172 -> 1191; without robustImageAccess2 942 -> 942 and
  1368 -> 1387.
- Negative control 46864: with the mask taken out, the identity test of IDs 65,536 past the
  arrays fails (rc 100); with it, passes.
- The rt device test, ID 0x1_0005 reading element 5 (index 5 and 5 + 0x1_0000 both answer
  7 x 3 and the texel): RX 550 46854, XTX 46855, RTX 3090 46856, Iris Xe 46857, all pass.
- Harness module hashes, every compute row, the mask (8d9317bef0) against its base (d392d453d6),
  the same harness: XTX 46951 19 of 19 equal; RTX 3090 46952 19 of 19 equal.
2026-11-18 09:37:25 -08:00
Anees Iqbal e38d800b23 rt README: the UHD 630's slower loaded pass that samples another texture, a known gap
A time-boxed look at the copy form's nc rows (a pass that loads its target and samples another
texture, no copy), which core found slower than the old runtime on the UHD 630. Timed in one
exclusive job (m3-max-47162: harness, release, four rounds, GPU p50 a pass, on probe rows over
the clear form, 774dcebda2): 688.6 against 617.8 us as the pass's first draw and 923.5 against
831.8 us after a plain draw, at 1920 x 1080. The target's move out of shader-read-only and back
is not the cause: the same rows with a RenderTarget-only target, which no barrier moves, take
700.7 and 911.6 us. The sampled texture (and a shadow) is read in SHADER_READ_ONLY_OPTIMAL, of
SAMPLED and TRANSFER usage only, with no storage, mutable-format or feedback usage. The cause is
unknown and recorded as a known gap, beside the faster clearing pass (666.9 against 870.7 us).
2026-11-18 09:28:59 -08:00
Anees Iqbal e632e01478 rt README: the cleared target's first read through the shadow's clear, re-timed on the UHD 630
The known gap gave a pass that clears its target and reads it at its first draw as 10.5% slower
than the old runtime at 3648 x 2038 (4,635.1 against 4,195.7 us), the copy of a cleared target.
With the clear of the shadow in its place, re-timed on the UHD 630 (harness, release, four rounds,
GPU p50 a pass, old and new runtimes in one exclusive job, m3-max-47088, on the probe rows over
a5f3159c76, the same code as 4780d85bf8): 4,200.8 against 4,159.4 us (+1.0%), and 1,095.3 against
1,109.1 us at 1920 x 1080 (-1.2%). The same runs give the other rows: after a barrier 4,836.4
against 5,429.4 us, the first read of a loaded target 3,849.6 against 4,218.2 us, the pass
reading another texture 2,341.2 and 644.2 us. The r3 and b3 frame figures were counted before
the clear, so they bound the copies from above.
2026-11-18 09:27:32 -08:00
Anees Iqbal 385ad1b349 rt: Target::clear_color reads the union only for a colour attachment the pass clears
Clippy's unnecessary_lazy_evaluations asked for then_some, which would read the clear value's
colour eagerly, also of a stencil attachment whose value holds only depth and stencil; an early
return keeps the read where it is a colour's. Verified by the next check job.
2026-11-18 09:19:02 -08:00
Anees Iqbal 4780d85bf8 rt: the pass's first draw reads what its pass cleared through a clear of the shadow
On a device without the attachment feedback loop, a draw that reads an attachment of its own
pass copies what it reads into the image's shadow first. At the pass's first draw, where the pass
cleared the attachment, the rendered level and layer holds only the clear colour inside the
render area, and the copy cost more there than anywhere (about 81 us a MiB at 3648 x 2038 on the
UHD 630, against about 50 for a loaded target: the cleared target moving to the transfer layout).

Where no draw of the pass has been recorded yet (RenderCommandEncoder::pass_drew, any draw of any
pipeline), the attachment's load cleared it, the shadow is of the attachment view's format (so
vkCmdClearColorImage converts the pass's clear value as the load did), and every area the draw
reads of the rendered level and layer lies in it alone and inside the render area
(shadow::clears), the shadow's level and layer is cleared to the pass's clear value
(Target::clear_color) between the same two barriers, in place of the copy; the image's rendered
level and layer stays in the attachment layout. Areas of other levels or layers are still copied,
and a target cleared and then drawn copies as before. Only the read areas are held, as for a copy.

Tests: host tests of shadow::clears and Area::reaches; the device test
every_device_reads_its_cleared_attachment_at_its_pass_first_draw (no copy counted and every pixel
the clear colour read, at the pass's first draw; one copy of the whole target after one draw); the
attachment-read and levels device tests now count one copy each on the copy form, the first read
and the rendered level being the clear's.
2026-11-18 09:19:02 -08:00
Anees Iqbal 9bf8aeafde rt: a command buffer keeps a view it uses after its parent
keep_texture kept each texture once by its id, which a view shares with its parent so the
hazard sets treat them as one texture. A view used after its parent was therefore not kept: the
command buffer held the parent (which a view holds, not the other way round), and a view the
program released while the command buffer was pending dropped at once, vacating its element of
set 1 and giving its image views (a shadow view among them) to the reaper while work could still
read them. Metal's command buffer retains every object its encoders use.

It now keeps each object once by identity (Texture::is, the inner Arc), a view apart from its
parent. What reads the kept list by id is unchanged in effect: the over copies' lookup finds a
texture over a buffer of that id, whose copy a view and its parent share, and the submit
thread's take of a Managed over's copy in is taken once per id, a second take finding none.

Test: tests::view::every_device_keeps_a_view_bound_after_its_parent_until_its_command_buffer_retires,
a blit out of the parent and then out of its view, held behind an event wait; the view is
released, and while the command buffer is pending the textures and descriptor slots gauges keep
it; once it completes they fall by one each.
2026-11-18 09:17:11 -08:00
Anees Iqbal d92119383c AGENTS.md: the null descriptor is an eighth query-chosen form
The owner approved it on 2026-11-18, typed in the planner's session, verbatim: "I approve it", on the planner's question "allow it as an eighth query-chosen form". Rule 2's list now holds eight: a device without the nullDescriptor feature gives every element of the texture and sampler arrays that no resource owns a small zero image or the default sampler, recorded as a known gap. The closing sentence (a second form chosen by anything else is not allowed) is kept. Docs only; the form itself is not built yet (it waits for the Mac lane).
2026-11-18 09:07:44 -08:00
Anees Iqbal cdb7603d3a replay tests: an open encoder's state and bound buffers as a struct, for clippy's type complexity
Check 46885 failed clippy on the unbound-read counter's encoder map. The map now holds an
Encoder struct; behaviour unchanged.
2026-11-18 09:01:28 -08:00
Anees Iqbal 0463eb6d2d replay: a placement waits for the commits that named its index's holders, which count once retired
Under the owner rule the runtime gives a held index to the newer object, so a placement while
an earlier holder's work runs takes the element from under that work, which Metal leaves the
program never to do (docs/RESOURCE-ID.md); the program's own timing kept that duty, and the
player, the runtime's consumer here, now keeps it. Each index is owed to the last commit that
named an object holding it, live or released (a released one's uncommitted users owe it at their
commit; a command buffer released uncommitted owes nothing), and a placement there, named, lowest
or highest, first waits for that commit. The `indices named` line counts the waits and their
time.

A commit counts done once its completed handler has run: the runtime sets a command buffer's
status before it drops what the command buffer held, and runs the handlers after, so the status
alone could find the work done while the runtime still held the old holder.

Verified: the ledger's unit test an_index_is_owed_to_the_commits_that_named_its_holders (to run
in the lane's check). The device test that holds work in flight comes after the reruns.
2026-11-18 09:01:28 -08:00
Anees Iqbal 74fe5e67ca replay: count the draws and dispatches whose pipeline reads a buffer argument nothing is bound to
A read of an unbound buffer argument is undefined in Metal; under the new runtime a draw that
makes one reads address 0 and loses the device. Whether release programs make such reads is a
count the player can take: each pipeline state's used buffer arguments come from the
translator's reflection of its descriptor (isUsed), and each encoder's bound indices from its
setBuffer, setBuffers and setBytes calls per stage (a nil buffer unsets one) until endEncoding.
The backend reports an `unbound buffer reads N: ...` line (the states, the unreflected ones, the
first eight by position and frame) and `unbound_buffer_reads` per frame.

Verified: the unit test a_draw_reading_a_buffer_argument_nothing_is_bound_to_is_counted (to run
in the lane's check).
2026-11-18 09:01:28 -08:00
Anees Iqbal 653fc39b78 replay: the new runtime's pushes and the pushes its command buffers held, per frame 2026-11-18 09:01:28 -08:00
Anees Iqbal c0681c4f6a command-replay: the module doc names the ids status 2026-11-18 09:01:28 -08:00
Anees Iqbal 71a22fc2be command-replay: a play that ends with differing IDs exits 3 with an ids line, apart from a stopped run
A run that played every frame but whose objects' gpuResourceID differ from
the recording's exited 1 with an 'error ids' line, the status of a run that
stopped: two clean plays read as crashes. It now ends 'ids: played to the
end; ...' and exits 3; docs/REPLAY-STREAM.md says so.
2026-11-18 09:01:28 -08:00