Commit Graph
4866 Commits
Author SHA1 Message Date
Anees Iqbal c43b79bdfd RUNTIME_VERSION 2155: a fence goes on past its device's recovery
The two commits before this one. A fence made before a device recovery held its generation's device handle, so
waitForFence:, waitForFence:beforeStages: and updateFence: of the next generation refused it (MadeBeforeRecovery):
a consumer's boot after two GPU recoveries on a 780M counted 15,389 + 9,115 such refusals, and its encoders faulted
at the first. A fence has no Vulkan object, only an identity key, so it now holds the device's root handle
(Device::root): update_fence and wait_for_fence of any generation take it, and it no longer keeps the lost VkDevice
alive.

Verified (on the branch): lavapipe (m3-max-22931): device_recovery::a_fence_goes_on_past_a_recovery fails at the test
commit (Err(MadeBeforeRecovery) at update_fence) and passes with the fix, with all 17 device_recovery* tests;
clippy plain, m2v_gpu, m2v_cpu_icd (22933-22935).
2026-11-12 15:03:16 -08:00
Anees Iqbal e05beb832d A fence goes on past its device's recovery
What: a fence holds a root handle of its device (Device::root) rather than the generation
it was made on. A fence has no Vulkan object, only the key the tracker orders on, so
update_fence and wait_for_fence of any generation's encoder now accept a fence made before
a recovery (check_device matches a root handle by its line); an update made on a lost
generation went with that generation's work, so a wait on the next one finds none, as for a
fence never updated there. The fence no longer keeps the lost VkDevice alive. Docs: fence.rs
module and item docs, carry.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs
and docs/API.md), the runtime README. REFUSALS.md regenerated: unchanged.

Why: after a 780M gfx ring timeout and a recovery, a guest's waitForFence: calls were
refused NotImplemented(MadeBeforeRecovery) about 2,000 times; Metal's fence goes on.

Verified: see the lane run reported with this sha (the test commit before it fails, this
one passes).
2026-11-12 15:02:41 -08:00
Anees Iqbal cc357e23c5 Test that a fence made before a recovery goes on after it
What: a device test (m2v_gpu / m2v_cpu_icd, beside the other carry tests; the loss is
marked by Device::recover_for_test) that makes a fence and a Private buffer, recovers, then
in one command buffer fills the buffer and updates the fence in a blit encoder and waits for
the fence in a later one. It expects every call to be accepted, the command buffer to
complete, the label kept, and one live VkDevice while the fence lives.

Why: a fence held the generation it was made on, so after a recovery update_fence and
wait_for_fence were refused NotImplemented(MadeBeforeRecovery) (about 2,000 refused fence
waits in one guest run after a 780M ring timeout), and the fence kept the lost VkDevice
alive. Metal's fence goes on. This test fails until a fence is no generation's.

Verified: not yet run; the fix's commit carries the run.
2026-11-12 15:02:41 -08:00
Anees Iqbal ff0db5688b 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-12 15:00:38 -08:00
Anees Iqbal 4ff7bb727c RUNTIME_VERSION 2154: a recovery carries Private heaps with the buffers placed in them
The two commits before this one. After a device recovery a heap made before it stayed with the lost generation, so
its newBufferWithLength:options:offset:, newBuffer and newTexture were refused (MadeBeforeRecovery) where Metal makes
them (a guest's heap sub-allocations after an amdgpu soft recovery on an RX 550). Each live heap is now carried
(Heap::carry): a Private heap's own buffer is made again in new memory placed so its textures can lie there too,
zeroed, keeping its ObjectId, address, range, range token and label; each live buffer placed in it gets a link on the
new generation at the same offset, keeping its identity, its old link letting go of the lost generation at rest; the
heap's textures made before stay refused and are forgotten by the heap; the carried heap is in the new generation's
registry, so a later recovery carries it again. Shared, no-copy and sparse heaps stay as they were. The recovery
notice counts carried Private heaps (bytes, buffers) and left heaps by kind, and splits "buffers over the caller's
or exportable memory" into buffers over the caller's VkBuffer and buffers in exportable memory. Docs: carry.rs,
degradation.rs and API.md's device-recovered cost, MadeBeforeRecovery, the runtime README.

Verified (on the branch): lavapipe, m2v_cpu_icd (m3-max-22922): device_recovery_heap::a_recovery_carries_private_heaps_with_their_buffers
fails at the test commit (no heaps in the notice) and passes with the fix, with all 16 device_recovery* tests: a
Private placement heap and a Private automatic heap, one buffer placed in each, identities kept, bytes zero;
new_buffer_at_offset, new_buffer and new_texture after the recovery work; the texture made before is refused;
use_heap commits; used_size drops by exactly one buffer on release; the lost VkDevice goes once the old texture is
dropped. clippy plain, m2v_gpu, m2v_cpu_icd (22923-22925). No real GPU recovery was run (recover_for_test).
2026-11-12 15:00:00 -08:00
Anees Iqbal b10839e2b2 A recovery carries Private heaps with the buffers placed in them
What: a device's recovery now carries each live heap to the new VkDevice (Heap::carry,
called from Device::carry_to after the buffers, or by a heap's maker where the recovery
took the generation first). A Private heap's own buffer is made again in new memory placed
where the heap's textures can lie (place_heap_buffer), zeroed as a carried Private buffer
is, keeping its ObjectId, hazard key, Metal address and range, range token, label and
purgeable state; the heap is registered by its key there and kept in the new generation's
registry for a later recovery. Each live buffer placed in it gets a new link on the new
generation (Buffer::carry_placed) at the same offset of the carried bytes, with the same
ObjectId, address, label and a shared aliasable flag; its old link lets go of its live-list
entry and device handle at the lost generation's rest (LostPlaced). A placed buffer's drop
gives an automatic heap's range back only from the link carried to last, so a carried
buffer frees its range once. A buffer placed while the heap is being carried carries itself
under the heap's placed lock. The heap's textures made before stay the lost generation's
(no recovery carries a texture); the heap forgets them (keeping their numbering), so a
use_heap on the new generation never makes an old image resident. Shared heaps (their bytes
are pooled host-visible memory, never the runtime's own pages), no-copy heaps and sparse
heaps stay left, with their buffers.

The recovery notice now counts carried heaps ("N `Private` heaps (B bytes) with the M
buffers placed in them") and left heaps by kind, and splits the old "buffers over the
caller's or exportable memory" into "buffers over the caller's `VkBuffer`" and "buffers in
exportable memory" (Left::Caller / Left::Exported). Docs: carry.rs module docs, the
Buffer::carry docs, heap.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs
and docs/API.md), the runtime README. REFUSALS.md regenerated: unchanged.

Why: after a GPU recovery a guest's MTLHeap newBufferWithLength:options:offset: was refused
NotImplemented(MadeBeforeRecovery) and the guest got nil; Metal's heap goes on.

Verified: see the lane run reported with this sha (the test commit before it fails, this
one passes).
2026-11-12 14:59:22 -08:00
Anees Iqbal d82bb79981 Test that a recovery carries Private heaps with their buffers
What: a device test (m2v_gpu / m2v_cpu_icd, as the other recovery tests: the loss is
marked by Device::recover_for_test, no GPU fault) that makes a Private placement heap and
a Private automatic heap, places a buffer in each, makes a texture in the automatic heap,
then recovers. It expects the recovery notice to count both heaps and their buffers, the
heaps and buffers to keep their ObjectId, Metal address and label on the new generation
with their bytes zero, new buffers and textures made in them to serve, the texture made
before to stay refused (MadeBeforeRecovery), a use_heap on the new generation to commit,
a carried automatic buffer's release to give its range back once, and the lost VkDevice
to go with the texture left on it. The carry test's fill/read/live_vk_devices helpers are
shared with it.

Why: after a GPU recovery a guest's MTLHeap newBufferWithLength:options:offset: was
refused NotImplemented(MadeBeforeRecovery): no recovery carried heaps. Metal's heap goes
on. This test fails until heaps are carried.

Verified: not yet run; the fix's commit carries the run.
2026-11-12 14:59:22 -08:00
Anees Iqbal bed1a85978 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-12 14:57:09 -08:00
Anees Iqbal bb83990546 SEMANTICS_VERSION 2063, ARTIFACT_FORMAT_VERSION 509, RUNTIME_VERSION 2153: a heap texture's chosen constexpr samplers are one sampler array
The four commits before this one. A heap sample whose sampler is one of several constexpr candidates with
consecutive handles branched into one arm per candidate (8 on a guest path tracer's kernels: 1.82M of one kernel's
4.5M words). Where the device has non-uniform sampled-image indexing (which heap images already need), the
candidates are now one set-0 array of immutable samplers (ResourceKind::SamplerArray / BindingSource::SamplerArray),
indexed NonUniform by the handle's candidate number, zero outside the array as the switch's null arm. Candidates
that differ only in reading one texel merge: the element's sampler word decides that test (OneTexel::Table), and the
raw emulation reads each element's state word from a constant table (State::Table). Same answers: each element is
exactly the sampler its arm used. Elsewhere, and for non-consecutive handles, the switch stays. Runtime: per-element
immutable samplers in the shared layouts, the set-0 hash and the pushed set 0. Docs: API.md section 5, api tables,
REFUSALS.

Verified (on the branch): nextest -p metal2vulkan (m3-max-22886) 4997/4998, the golden failure the pending SV 2061
cells of the old base (blessed at pin 59), none moved by this change; lint (m3-max-22911); lavapipe lane
(m3-max-22900) 30/30 with the new heap_sampler_array device test (each lane equals its sampler alone and the
address-mode definition, a linear mirrored third sampler taking the word-decided path); census over 3,781 rows
(m3-max-22912): 0 defects, amd-780m-radv 3374 translated (slowest 537 ms, peak 279 MiB), vk12-floor 1647 unchanged.
Guest kernels (780m profile, m3-max-22884): words -15% to -21% (4,495,595 -> 3,809,280 on the largest), every site
on the array (106/106, 176/176), translate+validate peak 506 -> 433 MiB. Create time on the 780M (m3-max-22898)
pending.
2026-11-12 14:56:30 -08:00
Anees Iqbal 1464364166 A sampler array merges candidates that differ in reading one texel: the element's word decides
The 8 constexpr samplers a heap sampling chooses among in the large
kernels are 4 nearest and 4 linear; their arms differed only in
Sampling::one_texel (Always for nearest, Never for linear), so the
array never formed (106 sites in one kernel, 176 in another, each
switch of 8 arms kept; probe print on the 780M profile).

OneTexel::Table(n) states that the word of the constexpr sampler at
the array element the handle names decides whether the sampling reads
one texel, as OneTexel::Word does for a runtime slot. The array now
carries each element's SamplerWord (ConstexprArray::words), which both
that test and the raw emulation's word (heap_raw::State::Table, now its
element count) read through emit::array_word. The tests' third sampler
is linear, so the device test checks the word-decided reads.
2026-11-12 14:55:48 -08:00
Anees Iqbal 90394ab704 Tests: the chosen-sampler kernels name their lane selector apart from the argument buffer 2026-11-12 14:55:47 -08:00
Anees Iqbal 3a734e18d4 Heap raw facts: a sampler array's table states no runtime sampler, as a constant state 2026-11-12 14:55:47 -08:00
Anees Iqbal da3cea7633 A heap texture's chosen constexpr samplers are one sampler array, not a switch
A heap texture sampled through one of several constexpr samplers that a
sampler handle names at run time (a table of constexpr samplers read at a
computed index) was a switch-at-use with one arm per candidate: each arm
its own heap sampling and raw-texel emulation. On large kernels that
multiplies the sampling code by the candidate count.

Where every candidate is a constexpr sampler, their handles are
consecutive, each candidate's sampling is the same but for its sampler
and the state its raw emulation follows, the use is not tangled, and the
device indexes a sampler array non-uniformly
(shaderSampledImageArrayNonUniformIndexing, which heap textures already
need), the sampling is now one sampling through a set-0 array of the
candidates' samplers (ResourceKind::SamplerArray,
BindingSource::SamplerArray): element handle - first, NonUniform, its
immutable samplers each made as the heap sampler of that candidate alone
would be (DescriptorBinding::immutable_samplers, listed per stage in
StageInterface::sampler_arrays). A handle outside the array reads zero,
as the switch's null arm. The raw emulation reads the element's sampler
word from a constant table at the same index (heap_raw::State::Table),
through the runtime-word path. Elsewhere the switch stays.

The runtime bakes one sampler per element into the set layout, pushes
each element's own sampler where set 0 is pushed, and keys the set-0
shape on them.

Tests: the array form on every profile with the sampled heap (one
sampled image, L3), the switch kept for non-consecutive handles, each
element equal to the immutable sampler of the candidate sampled alone and
never written by the plan, and a device test (lavapipe under
m2v_cpu_icd) that each lane reads what its sampler alone reads and what
the address modes define.

Docs: API.md section 5, the sampler module doc, api_signatures,
api_surface, REFUSALS regenerated.
2026-11-12 14:55:47 -08:00
Anees Iqbal 2f4a0a3a95 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-12 14:38:28 -08:00
Anees Iqbal 541403865a RUNTIME_VERSION 2152: a rate-mapped draw skips the regions its viewport and render area leave no pixel
The commit before this one. A rate-mapped draw recorded every region, even one whose scissor is empty after the cut
to the guest viewport and render area. Those are no longer recorded (rate_mapped_pass.rs draws()); where no region
keeps a pixel, the first region alone is recorded through its empty scissor so the vertex function still runs.
Exact: the scissor test drops every fragment of a skipped region, and vertex side effects are already refused for
plans of more than one region. Docs: rate_mapped_pass.rs, regions.rs, API.md, FAST-PATHS.md.

Verified (on the branch): rate_mapped_passes 12/12 on Iris Xe (m3-max-22799) and lavapipe (m3-max-22766); new
a_viewport_over_part_of_the_screen_draws_only_the_regions_it_reaches (left quarter: 12 of 36 regions, pixels equal
to the region-by-region indirect draw). Iris cost lane (3840x2160 map, 2,624 regions) hashed before and after: full
viewport 215d7bad5f31fed5 both, quarter viewport e977c7565cdeff42 both; quarter viewport 164 -> 39 multi-draws per
guest draw, GPU 175 -> 33 ms (light draws), 968 -> 217 ms (dense). Full-screen draws unchanged.
2026-11-12 14:37:45 -08:00
Anees Iqbal bcfec16960 A rate-mapped draw skips the regions its viewport and render area leave no pixel
Each draw of a rate-mapped pass was recorded once per region of the map's plan, even where the
region's scissor, cut to the pixels whose centres lie in the guest's viewport and to the render
area, held no pixel. Such a recording shades nothing (the scissor test discards every fragment),
and its vertex function repeats nothing observable (a plan of several regions refuses a vertex
function that writes memory), so it is now left out. Where the cut leaves no region a pixel, the
first region alone is still recorded through its empty scissor, so the vertex function runs as
Metal's does. A draw whose viewport covers part of the screen now records only the regions it
reaches; one over the whole screen records what it did.

The new lane test draws the case's fullscreen triangle over a 256-pixel map at the falling
quality with a viewport over the screen's left quarter: fewer regions than the whole screen's,
from an indirect buffer region by region, and the direct (batched) draw shades bit for bit the
same pixels, inside the left half of the physical columns.
2026-11-12 14:37:06 -08:00
Anees Iqbal d3ef04535d 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-12 14:36:17 -08:00
Anees Iqbal 6f29ec3f67 RUNTIME_VERSION 2151: GPU times from the host start at the first submission that carried the work
The commits before this one. On a device made with DeviceOptions::gpu_times_from_host, a command buffer's
GPUStartTime was its kernel end, the call of its LAST submission, so a command buffer whose batches went as several
submissions dropped its earlier work from its GPU window (a consumer's profile: 2-8 s of work reported as 0-240 ms,
kernel end to GPU start 0.00 ms). KernelTimes now records the first driver submission call that carried a batch of
the command buffer (its own vkQueueSubmit or its group's call); the host-clock start is that call where it came
before the kernel end, else the kernel end as before, raised to the queue's latest GPU end where later. A command
buffer of one submission answers as before; devices that write timestamps were already right. Docs: gpu_time.rs,
gpu_start_time, DeviceOptions::gpu_times_from_host, the GpuTimesFromHost cost text and its API.md entry. Also: the
queue-times test holds heads, kernel starts and ends, and returns each in commit order (grouped batches can return
from one call).

Verified (on the branch): runtime_lane::gpu_times::a_command_buffer_of_two_submissions_is_timed_from_its_first_work_to_its_last
(a fill, a wait for an event the host signals 200 ms after the commit, a fill; timestamps and host times): lavapipe
(m3-max-22756) fails before the fix with host times (start +0.376 ms after the signal, the kernel end) and passes
after (-199.8 ms); Radeon 780M (m3-max-22792) passes both ways. lavapipe gpu_time + kernel_end_device 16/16, lane
gpu_times 12/12 (22782), degradation catalogue 17/17 (22797); 780M lane gpu_times 12/12, runtime 16/16 (22811).
Lint (m3-max-22812): clippy every feature, m2v_gpu, m2v_cpu_icd, rustdoc, api tests.
2026-11-12 14:35:38 -08:00
Anees Iqbal 037bae0cd6 Test: queue times come in commit order, grouped batches returning from one call
queue_times_are_noted_in_the_order_of_a_queue_s_submissions_and_only_where_asked
held each command buffer's kernel start after the return of the one
before it. Batches that wait in a group for one kernel submission begin
and are held before the call that carries them all returns: on the 780M
(RADV, job 22793) the second and third of three back-to-back fills
returned from one call, the third's kernel start 66 us before it. The
test now holds heads, kernel starts and ends, and returns each in commit
order.

Verified: pending the 780M rerun.
2026-11-12 14:35:01 -08:00
Anees Iqbal 1b1ebfd055 GPU times from the host start at the first submission that carried the work
A command buffer whose work went as several submissions (a wait for an
event the host signals, an execution its host step records) answered,
on a device made with gpu_times_from_host or a driver whose timestamps
wait for every queue's, the call of its LAST submission (its
kernelEndTime) as its GPUStartTime: its window missed the work of its
earlier submissions. Metal's GPUStartTime and GPUEndTime span the whole
command buffer's GPU work. A consumer that answers GPU times from the
host read windows of 0 to 240 ms on an Iris Xe for command buffers whose
kernel start to end spanned 2 to 8 s, each GPU start at the kernel end.

KernelTimes keeps the call of the first driver's submission that carried
a batch of the command buffer (the batch's own vkQueueSubmit, or its
group's), and the host-clock start is that call where it came before
the kernel end, else the kernel end as before, or the queue's latest GPU
end where later. A command buffer whose work went as one submission
answers as before. Devices that write timestamps already started at the
first batch's timestamp (lavapipe, job 22670: GPU start 173 ms before
the signal its second batch waited for).

Docs: gpu_time.rs (the host-clock bullet, rule 2), gpu_start_time,
DeviceOptions::gpu_times_from_host, the GpuTimesFromHost notice's cost
and its API.md entry.

Verified: pending lavapipe before and after, the 780M, lint.
2026-11-12 14:35:01 -08:00
Anees Iqbal d5a91164c8 Test: the two-submission command buffer's times, also with GPU times from the host; drop the making split
The lane test runs on the device as made and on one made with
gpu_times_from_host, whose GPU start is answered from the host's clock:
there a command buffer whose work goes as two submissions must start
before the host's signal its second waits for, as its first fill's work
ran then. The runtime test of a command buffer a pipeline's making
splits goes: on lavapipe its batches went as one submission at the
commit (kernel end 299.9 ms before the hold's end, job 22710), so it
tested no split.

Verified: pending the lavapipe run at this commit and the fix after it.
2026-11-12 14:35:00 -08:00
Anees Iqbal 672a406767 Test: a command buffer a pipeline's making splits is timed from its first work to its last
A command buffer whose draw's pipeline is still being made at its commit
(PipelineWaitPolicy::Exact, the pool's test hold dropped 300 ms after the
commit) goes as more than one submission: the fill before the pass at
once, the pass once its host step recorded it. Its GPU start must be the
fill's, before the hold went, and its end after it. Run with the merge
check as found and forced to hold, so its batches may wait in a group.

Verified: pending the lavapipe and 780M runs.
2026-11-12 14:35:00 -08:00
Anees Iqbal bef09b0369 Test: a command buffer of two submissions is timed from its first work to its last
A command buffer whose work goes as two submissions 200 ms apart (a fill,
a wait for a shared event the host signals 200 ms after the commit, a
fill) must answer Metal's GPUStartTime at its first fill, before the
signal, and its GPUEndTime at the second, after it. A guest profile on
an Iris Xe read GPU start..end spans of 0 to 240 ms for command buffers
whose kernel start..end spanned 2 to 8 s, the GPU start at the kernel
end.

Verified: pending the lavapipe and 780M runs.
2026-11-12 14:35:00 -08:00
Anees Iqbal 47d48eb4c1 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-12 14:34:43 -08:00
Anees Iqbal c86f4c2f9e RUNTIME_VERSION 2150: a texture turns no face after an execution of indirect commands in its command buffer
The three commits before this one. A pass that turns a texture's faces rewrites its heap elements; an execution of
an indirect command buffer earlier in the same command buffer records its commands at the commit or in a host step,
after the pass opened, and had bound no heap set when the turn was decided, so it read the face the pass turned to
(stale texels) though it runs before the pass. defer_execution (compute and render) now marks the command buffer's
heap use as executing later (HeapUse::executes_later), and the turn point asks HeapUse::may_bind (bound or later):
such a pass turns nothing (Unturned::Busy) and copies in, as after an earlier heap bind. HeapUse::bound is
unchanged. Docs: faces.rs. An encoding again hands no face-resolving work to another thread (audited: replays run
on the rebind's thread inside the faces-as-of context; the scheduler's later segments resolve nothing).

Verified (on the branch): attached_read_faces::an_execution_before_a_clearing_pass_reads_the_texels_from_before_it
(an execution reading the texture through an argument buffer, then a clearing pass) fails without the fix (the pass
turns; the execution reads 0x40 and 0) and passes with it (busy 1, swaps 0, 180 texels copied in; reads 0x50 and
0x20) on lavapipe (m3-max-22819) and M3 / MoltenVK (m3-max-22818); clippy plain, m2v_gpu, m2v_cpu_icd
(22820-22822).
2026-11-12 14:34:03 -08:00
Anees Iqbal 409c7f6ac2 Faces test: the face a turn would take holds the first read's 0x40, and nothing outside it
The execution test's comments said the other face holds 0x10 outside the
rectangle; the first read copies in only what its draw reads, so it holds no
texel of the texture there (lavapipe read 0, m3-max-22819). Comments only.
2026-11-12 14:33:27 -08:00
Anees Iqbal 644e670dd9 A texture turns no face after an execution of indirect commands in its command buffer
What: an encoder that leaves an execution of indirect commands to record later
(compute and render, defer_execution) notes it on its command buffer's heap
use (HeapUse::executes_later), and a pass's turn point takes that as bound
heaps (HeapUse::may_bind): the turn is refused (Unturned::Busy) and the pass
copies in, as where an earlier command bound a heap set. Docs: faces.rs
(When, Unturned::Busy, TurnPoint).

Why: a turn writes the texture's heap set elements again, so it is refused
where a command of the command buffer bound a heap set: such a command runs
before the turning pass and would read the new face through the texture's ID.
An execution's commands are recorded by the commit or a host step, after the
pass opened, so they bound no heap set yet when the turn was decided, and read
the face the pass turned to (stale texels) through an argument buffer naming
the texture. An encoder encoded again after a rebind leaves its execution to
record later as its first encoding did, so the turn its pass decided is
refused alike.

Verification: the previous commit's test, without and with this change, on
lavapipe and one device; results go with the hand-off.
2026-11-12 14:33:27 -08:00
Anees Iqbal c263c377ac Test: an execution before a clearing pass reads the texels from before it
What: attached_read_faces gains a third test. In one command buffer, a compute
encoder executes an indirect command buffer whose command (rt_heap_zero) reads
the texture through an argument buffer naming its resource ID, at a texel
inside the rectangle and one outside; then a pass clears the texture and reads
it. The faces were made earlier, so the texture's own face holds 0x50/0x20 and
the other face 0x40/0x10. The test asserts that the command reads 0x50 and
0x20 (Metal's answer: the texels from before the pass), that the pass turns
nothing (busy), and that the pass leaves its own texels.

Why: the commit records an execution's commands, so they bind the heap sets
after the pass opened. A turn there rewrites the texture's heap elements to
the face it turns to, and the command, which runs before the pass on the GPU,
reads that face's stale texels. The turn is refused only where a command of
the command buffer bound a heap set by then, which an execution's command has
not.

Verified: see the next commit, whose fix this test checks.
2026-11-12 14:33:27 -08:00
Anees Iqbal 1125fb62d2 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-12 14:09:13 -08:00
Anees Iqbal 2b49475f91 RUNTIME_VERSION 2149: a merged color's keep follows its copy in after an inline first instance
The two commits before this one. A render pass whose attachment a draw fetches through a scratch (the image over
host pages can't take STORAGE) and whose first instance records inline gets the stand-in's copy in only after that
first instance; the linear merge's keep was still recorded before the pass, so it snapshotted whatever the scratch
already held. From the second round on the scratch is the previous round's recycled image, so the merge dropped
every word the later instances wrote that matched those stale bytes: the fetching draws' output was lost (a
guest's Dock icons drawn as rims on MoltenVK). The keep is now recorded right after the copy in, at both places
that record it (keep_in_pass). Docs: render/inline_first.rs, linear_merge.rs.

Verified (on the branch): M3 / MoltenVK (m3-max-22709): the new fetch_composite case
a_loaded_srgb_composite_over_host_pages_through_a_scratch_keeps_every_draw (RGBA8Unorm_sRGB over host pages,
loaded, always through the scratch) fails without the fix (round 1: 3072 wrong pixels, 4 instances, 1 inline pass,
1 linear merge) and passes with it, with the other 3 cases; lavapipe (m3-max-22715) 4/4 (input attachments, route
unchanged); clippy plain, m2v_gpu, m2v_cpu_icd (22712-22714). The case relies on the recycled scratch keeping the
previous round's bytes, as MoltenVK's does.
2026-11-12 14:08:32 -08:00
Anees Iqbal 663c564484 A merged color's keep follows its copy in after an inline first instance
What: where a pass's first render pass instance records inline, a color over a
buffer's bytes rendered through a stand-in (a fetched texture's scratch) is
copied in right after that instance, as before; its linear merge's keep was
recorded before the pass. It is now recorded right after that copy
(LinearMerge::keep_in_pass), in both places that record the copies after the
inline instances (a pass recorded at its end, and one that records later), as
the keep after a pin already was. Docs: render/inline_first.rs and
linear_merge.rs's keep_in_pass.

Why: the keep taken before the copy in held whatever the stand-in's image held
then, and the merge after the pass writes only the words that differ from the
keep, so it dropped every word the later instances wrote that equalled it. On
MoltenVK the scratch was the previous round's image, recycled with that round's
pixels, so a pass that drew the same pixels again lost everything after its
first instance, a compositor's fetching draws among them. Nothing ties it to
MoltenVK: any device whose recycled or fresh scratch holds bytes equal to
what the later instances write loses them.

Found by ratemap (the candidate fix, unbuilt); applied here on development.

Verification: the previous commit's sRGB case, on the M3 (MoltenVK) without
and with this change, and on lavapipe; results go with the hand-off.
2026-11-12 14:07:55 -08:00
Anees Iqbal e5b8db79f6 Test: a loaded sRGB composite over host pages renders through a scratch and keeps every draw
What: fetch_composite gains a target format, and a case whose target is
RGBA8Unorm_sRGB over a no-copy buffer's host pages, loaded from what the CPU
wrote there. On a device that fetches through storage such a target always
renders through a scratch: the fetching draws read and write it through an
unsigned-integer view no texture's image is made mutable to. The pass's first
icon records inline into the target itself; the scratch arrives with the first
fetch, takes the target's texels after that instance, and the words the later
instances change are merged back into the pages (linear_merge.rs). Codes are
the device's own sRGB conversions, compared within one code. Where the target
is in place and the device fetches through storage, the case also asserts that
a linear merge ran, so it checks the scratch route rather than another. Each
round reports its inline passes and linear merges with the pixels.

Why: fix (1) made the RGBA16Float target over host pages fetch in place on
MoltenVK, so the existing case no longer reaches the scratch route, which lost
the fetching draws' output there (the second round kept the CPU's background
wherever an instance after the first drew). The sRGB target forces that route.
In the second round the scratch is the first round's image, recycled, still
holding that round's pixels, which is what the merge's keep read.

Verified: see the next commit, whose fix this test checks.
2026-11-12 14:07:54 -08:00
Anees Iqbal 66e521a807 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-12 14:05:00 -08:00
Anees Iqbal 4cf7196a0c RUNTIME_VERSION 2148: a logged pass turns its faces, and an encoding again meets the faces as its first encoding did
The five commits before this one. A render pass that logs its calls (while a host-page buffer is alive) was given
Unturned::Pass, and so did a pass after an earlier logged encoder: its attached reads copied in where they could
turn faces. Now a logging pass turns as it would unlogged. Each encoding again (command_buffer/reencode.rs: a
replay, and work recorded on the GPU alone) runs inside a context naming its command buffer and the encoder's
parts, so Faces::face() gives the face from before any turn a later part of the same command buffer made, and the
turning pass encoded again retakes its turn (Texture::retake_turn) with no copy in. Under METAL2VULKAN_LOG_SHADOWS
(default off) each shadowed texture gets one line at the first draw that binds it: its slot, whether the function
fetches, samples or writes it, and each sampler's filters. Docs: faces.rs, face_swap.rs, reencode.rs, work_counts,
API.md, env_vars.rs.

Verified (on the branch, at ca76fa2ebf): lavapipe (m3-max-22636) runtime attached_read|face|reencode|rebind 80/80,
validation 141/141, sync validation 25/25; Radeon 780M (m3-max-22667) runtime 80/80, lane 26/26, sync
logged_face_turns 1/1. New tests attached_read_faces::a_logged_pass_turns_and_its_encoding_again_meets_the_faces_as_first_met
and runtime_lane::logged_face_turns: the logged pass swaps with 0 texels copied in (180 before); a rebind encodes 2
encoders again, none refused, 0 copied in; pixels byte-equal to the copy route. With the context switched off the
lane fails (EncodedUseRebound). Lint (m3-max-22674): fmt, clippy default/gpucfg/cpuicd, rustdoc.
2026-11-12 14:04:15 -08:00
Anees Iqbal 8b58dcca6f Faces tests: the copy route's lane runs with no rebind
A rebind of its buffer is refused (EncodedUses), as the runtime holds a command buffer's pages
until it completes where a host step records part of it: that lane's pass's first copy in goes to
its batch's submission (shadow_standing.rs, GatedCopyIn). A throwaway probe on lavapipe showed the
turned lane's rebind made and the copy route's refused, with no shadow_texels_unskipped count
moved (a gated copy). The copy route's lane now runs the same command buffer with no rebind, and
the turned lane's bytes, through the encoding again, are compared with it. The passes' corners
from the pages stay; the earlier commit's reason for them was wrong.
2026-11-12 14:03:31 -08:00
Anees Iqbal 292071246c Faces tests: every lane pass takes its corners from the pages
The first run (gem10, lavapipe, job m3-max-22514) refused the rebind with EncodedUses in both new
tests: the turning pass was the first draw to read its corners from a buffer, and its pipeline
variant was still being made at the commit. Every pass of the lane now takes its corners from the
pages, so the variant is made before the command buffer behind the wait.
2026-11-12 14:03:31 -08:00
Anees Iqbal 490db00052 Re-encode: the encoder's last part read from the back
Clippy's double_ended_iterator_last on 14854f2473's lint job.
2026-11-12 14:03:31 -08:00
Anees Iqbal 834819bdb6 Shadow log: the first-draw line names its samplers (the format's argument was misnamed)
Caught by the lint job's build of 981a131409 (E0425); not yet built again.
2026-11-12 14:03:31 -08:00
Anees Iqbal 6014ad370d Faces: a logged pass turns, and an encoding again meets the faces as first met
While the device has a buffer over host pages, every render pass logs its calls for a rebind,
and a pass with a log, or with an earlier encoder of its command buffer keeping one, turned no
texture (Unturned::Pass): under a consumer that keeps host-page buffers alive, no attached read
ever took the turn and every one copied in.

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

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

Tests: the runtime's attached_read_faces gains a lane with a host-page buffer alive (a logged
pass turns; a blit and a turning pass behind a shared-event wait, encoded again by a rebind, read
the texels from before the turn), against the same lane beside an open command buffer (the copy
route); the validation crate's runtime_lane::logged_face_turns runs the same under the layer.
Not yet run: dispatched next.
2026-11-12 14:03:30 -08:00
Anees Iqbal 7926fa6e66 SEMANTICS_VERSION 2062: the predicated walk's size estimate charges what the walk emits
The commit before this one. The emulated-simdgroup variant (a dispatch whose threadgroup leaves a partial
simdgroup) took its size forecast from divergent::extra_words: 512 words per AIR block and 12 per operand use, about
15M words on a large kernel, so two kernels of a guest's path tracer (4.0M and 4.5M words emitted) were refused
LimitExceeded(SpirvWords) before emission, where Metal makes them. The estimate now charges each construct the walk
emits beyond the plain walk, from the structured tree (guards per segment, syncs and their guarded stores, reloads
of demoted uses, flag and vote words per walked loop, arm sequencing per walked branch); each constant names the
emitter code it bounds. Translation results change: modules that were refused now translate.

Verified (on the branch): nextest -p metal2vulkan --all-features (m3-max-22642) 3500/3501, the one failure
golden_hashes from SEMANTICS_VERSION 2061's pending re-bless (blessed since at pin 59; this commit changes no
emitted word); the shared test helpers assert estimate >= emitted on every Emulated-tier or walked module the
engine suites build; a_large_predicated_body_compiles_under_a_cap_it_fits (old forecast ~20x emitted). Lint
m3-max-22643. Release translation, amd-780m-radv profile (m3-max-22644): the two kernels' emulated variants at
1.64 s / 256.6 MiB and 1.99 s / 287.4 MiB, within 20 s / 500 MiB. Census over the 3,781 simd/quad/barrier rows
on vk12-floor (m3-max-22649) pending.
2026-11-12 13:57:58 -08:00
Anees Iqbal 2464994609 Predicated walk estimate: charge each construct the walk emits, from the structured tree
The size estimate of a kernel walked predicated (the emulated simdgroup tier, or a workgroup
synchronization in divergent control flow) charged 512 words per AIR block and 12 per operand
use. A large kernel's forecast was several times its emitted size, so its emulated-simdgroups
dispatch variant was refused LimitExceeded(SpirvWords) before emission although its module
fits the cap (4.04M words emitted against a forecast over 2^24).

The charge is now a bound derived from what the walk emits beyond the plain walk:
- per AIR block (divergent::extra_words): the live load before a guarded block, one `if live`
  per guarded segment (synchronizations + 1), per synchronization its predicated form and the
  guarded store of its demoted result, one load per use a guarded segment may reload (counted
  with the demotions), and the walk's frame once;
- per statement of the structured tree (structurize::emit::construct_words, measured at the
  end of planning from the same view emission structurizes): the live-select stores of
  selector and pending writes, the flag stores of break and continue, the live store of a
  divergent return, the guard of a statement run as it is, the condition reload, literal
  comparisons and sequential or guarded arms of a walked branch, and a walked loop's flags,
  exit test and workgroup vote.
Each constant names the emitter code it bounds.

The shared test helpers (typed_module_with, compile_kept) now check that the estimate bounds
the emitted words of every module of the emulated tier or the predicated walk the engine tests
build, and a large predicated body (256 diamonds after a divergent simdgroup sum) compiles under
a cap of eight times its emitted words.
2026-11-12 13:57:21 -08:00
Anees Iqbal 86d01646ae Re-bless the golden tables at 05a719a9d2
34 golden-hash rows move: the heap-reading kernels (a4_heap_sample, a4_heap_textures, cfb_ts_copy_held and the
other rows whose float reads, samples, gathers or queries may meet a raw-texel heap texture) now carry
SpecKey::HeapRawTextures's specialization constant and one OpLogicalAnd per raw-arm site (SEMANTICS_VERSION 2061).
That change's own run (m3-max-22504) showed golden_hashes failing for exactly those rows. No engine golden,
printout or inventory row moves.

Verified: bless on the M3 at 05a719a9d2 (m3-max-22661): golden hashes blessed, engine goldens pass; merged check at
the same sha on msi (m3-max-22658): clippy every crate with --cfg m2v_gpu, api_signatures, api_surface,
fast_paths 43/43, rustdoc -D warnings.
2026-11-12 13:56:56 -08:00
Anees Iqbal 05a719a9d2 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-12 13:52:25 -08:00
Anees Iqbal 0c348e0f95 RUNTIME_VERSION 2147: a render target in place over host pages takes the storage usage without the feedback-loop usage
The three commits before this one. An image in place over host pages tried STORAGE only together with the
attachment feedback-loop usage, so on a device without VK_EXT_attachment_feedback_loop_layout (MoltenVK) a
framebuffer over host pages never got STORAGE, and every draw that reads its attachment through the pixel interlock
went through the fetch-through-scratch route. The in-place plans now try both usages, the feedback-loop usage alone,
then STORAGE alone, each only where the linear tiling has the usage's format features, the image still lies at the
texels' pitch, and (for STORAGE) the device's in-place check for shader writes passed. Devices with the feedback
loop keep their order. The scratch route's own loss on MoltenVK stays an open bug (the test's over-host-pages case
reproduces it where the scratch is taken).

Verified (on the branch): M3 / MoltenVK (m3-max-22641): fetch_composite's new over-host-pages case (RGBA16Float
RenderTarget|ShaderRead over a no-copy buffer, loaded, icon and fetch draws, two rounds): before, STORAGE false,
4 render pass instances, round 1 with 3072 wrong pixels (the fetch draws' output lost); after, STORAGE true, 1
instance, 0 wrong pixels in both rounds; in_place_storage shows STORAGE on RGBA8, BGRA8, RGBA16F and R8 in place.
lavapipe (m3-max-22639) 4/4 (it fetches through input attachments, route unchanged). Lint running (22645-22647).
2026-11-12 13:51:46 -08:00
Anees Iqbal ece1bf461d Test: the loaded composite writes its background before each round, and reports the route with the pixels
The second round loaded what the first left, which its fetches halved again: the
expected pixels are each round's over the background, so the CPU writes it before
each. The route check joins the pixel failures, so a run that takes the scratch
route shows its pixels too.
2026-11-12 13:51:08 -08:00
Anees Iqbal 7d9e8ce385 A render target in place over host pages takes the storage usage without the feedback loop usage
What: an image in place over host pages of a texture that renders tried the
storage usage only together with the feedback loop usage
(VK_EXT_attachment_feedback_loop_layout). It now tries, widest first, both
usages, the feedback loop usage alone, then the storage usage alone, each
where the device makes the image in place with it (its linear tiling has the
usage's format features, and the image lies at the texels' pitch in their
memory, as before), the storage usage still only where the device's check
passed for a shader's writes of its texels over the pages.

Why: MoltenVK has no feedback loop layout, so there a guest's framebuffer
surface over host pages (RGBA16Float, RenderTarget | ShaderRead) never took
STORAGE, and every pass that fetched it in the pixel interlock rendered
through a scratch image, where the fetching draws' output was lost: the
Dock's icons drawn as rims, the Finder sidebar's glyphs washed out (reims's
A/B on the M3: declaring ShaderWrite, which gives the image STORAGE, drew
both right). Devices with the feedback loop usage keep their order: both,
then the feedback loop usage alone, as before. The scratch route's own loss
stays a separate fix.

The in-place storage test now allows the storage usage without the feedback
loop usage; the docs of the in-place image, the storage form and
in_place::storable say a fetching draw reads the texture in place through it.

Verified: see the report's job ids (fetch_composite's over-host-pages case on
MoltenVK before and after, and on lavapipe).
2026-11-12 13:51:08 -08:00
Anees Iqbal 1663f1a5ff Test: a loaded composite of icons and fetches over a no-copy buffer's host pages
What: fetch_composite gains a third home for its target, a texture over a
no-copy buffer's host pages, loaded from what the CPU wrote there, as a
guest's framebuffer surface is (RGBA16Float, RenderTarget | ShaderRead).
Where the image lies in place, the device's check passed for a shader's
writes of its texels and the device fetches through storage, the test
asserts that the image took the storage usage, so the pass fetches the
target in place rather than through a scratch image; and, as for the other
homes, every pixel must be its draws' answer in draw order.

Why: on MoltenVK such a target's in-place image took the storage usage only
together with the feedback loop usage, which MoltenVK lacks, so every
fetching pass over a guest's framebuffer went through the scratch route,
where the fetching draws' output was lost (the Dock's icons drawn as rims).

Verified: see the next commit, whose fix this test checks.
2026-11-12 13:51:08 -08:00
Anees Iqbal 5ef4a9f432 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-12 13:50:38 -08:00
Anees Iqbal 6bf7e13e91 RUNTIME_VERSION 2146: a device whose held imports cost every submission keeps at most 64 releasable imports resident
The three commits before this one. On a device whose submission check found a per-import cost
(pointer_imports_tax_submissions: about 0.45 us a submission per held import on the 780M), at most RESIDENT_MOST = 64
releasable imports stay resident; past it the residency thread wakes at once rather than at its 500 ms tick and
releases the least recently read idle imports, paced. New counter WorkCounts::host_imports_released_over_most
(api_signatures row). HOWTO.md and HostMemory::with_dma_buf describe the cap.

Verified (on the branch): lavapipe (m3-max-22599) host_residency, pointer_residency, dma_buf_import_cycles,
host_ram_dma_buf 32/32; Radeon 780M (m3-max-22634) the same modules 31/31, with the new device test
past_the_most_resident_the_least_recently_read_import_is_released (most 2 over three buffers: exactly the least
recently read released, the others read with no re-import, the released one's next blit reads a file write after one
re-import). One release and re-import on the 780M: 37.5 us free + 153.6 us encode, ~0.19 ms. Lint green at the
pre-stack base 7f1e5d7151 (m3-max-22547); development's checks cover the tip.
2026-11-12 13:50:00 -08:00
Anees Iqbal c7f9c44530 Residency: the resident count's decrement takes try_update, fetch_update's new name
Found by the lint job (22525) on msi: fetch_update is deprecated on this toolchain.
2026-11-12 13:49:23 -08:00