Commit Graph
5633 Commits
Author SHA1 Message Date
Anees Iqbal bb21c14865 compute/live: name SamplerState where the debug check takes it, so a release build imports nothing unused
check_whole, the only user of SamplerState in compute/live.rs, is cfg(debug_assertions), so a
release build under --cfg m2v_gpu warned 'unused import: SamplerState' (live.rs:94), an error
under -D warnings (seen by the gbgap and ratemap3b lanes' release builds). The signature names
the type by its path and the import goes.

Verified: see the landing check job.
2026-11-15 11:44:21 -08:00
Anees Iqbal db50e74588 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-15 11:42:38 -08:00
Anees Iqbal 7098431fe0 RUNTIME 2374: Dirty pages: a command's run of uses of one key is noted at once
DirtyCommit::note did all its work once a use. A host RAM copy over 128 chunks of a RAM with
a log names 2048 writes, and each chunk's key has a log of its own (RamOnDevice::chunk_key):
each write searched `host` for its log (one entry a chunk's log, about 128), took a Vec of its
own in `reported`, looked its key up in the imports and upgraded the log's Weak again, and put
its key in `used` again. On msi's lavapipe that was 179 us of a 290 us call (release probe,
m3-max-33184, the layer bench's logged case).

note now takes each run of consecutive uses of one key at once: the key goes into `used` once;
its logs are looked up and upgraded, and their places in `host` found, once, at the run's first
write; each kept write's reported logs are a range of one flat list (reported_hosts) that the
run's writes share, so no write takes a Vec of its own. Each write is still kept apart (the
seen check of the last 8, `written`, WRITES) and noted in its logs' ranges (HOST_RANGES, the
whole past it) as alone: written, host, what report_host_writes tells and when are as before.
wrote_host is split into host_place and wrote_at; wrote_unreported reads a write's logs through
its range.

Test: runs_of_one_key_note_exactly_as_their_uses_one_by_one notes 300 generated command
buffers (runs, keys named twice, reads, repeated writes, keys of no log and of two, logs past 64
ranges) and one past 4096 writes and keys, through note and through note_each (the uses one by
one, test-only), and asserts the same NotedWrites: each write with its logs, the keys used, the
overflows and each log's ranges.

The test's evidence bound asks for more than 30 logs written whole past 64 ranges (the rounds
give 43).

Verified: m3-max-33195 (msi, at 65498cb639): the runtime crate on lavapipe 2822/2823 (the one
failure the test's own bound, lowered in d99df37c6a), clippy plain, m2v_gpu and m2v_cpu_icd 0,
Rustdoc 0; m3-max-33205 (at d99df37c6a): 49/49 dirty and host_ram_copy tests, clippy cpu-icd 0.
Release A/B (m3-max-33196, msi lavapipe, 3 interleaved pairs, the same probe on both, us a call,
128 chunks of a logged RAM): note_dirty 200.4/204.1/196.6 -> 75.8/86.6/79.7, the call 324.1 ->
204.4 mean; unlogged unchanged; the log told 4096 runs a copy in every run.
2026-11-15 11:41:52 -08:00
Anees Iqbal 79adf9aef7 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-15 11:36:03 -08:00
Anees Iqbal cdb708d35f RUNTIME 2373: Heap textures: a tiled heap texture's making builds no kernel; its first use does
What: HeapTiledCopies (a heap texture held as a shadow in Metal's tiles,
AliasRoute::Tiled, and the surface depth textures that use it) no longer
builds the device's TiledTexels kernel or writes its two descriptor sets as
the texture is made. They live in a OnceLock and are made at the texture's
first use, in ShadowCopies::prepare(), which the encoder's plan_shadows calls
before it records any shadow copy. That is the path a converted YCbCr
texture's conversion already takes. dispatch() debug-asserts that the kernel
was made. So the compile moves to the first encode that needs any tiled
shadow, once per device, as owned_kernel.rs's rule says ("made once per
device, when a command first needs it"). That cost is now on the encoding
thread, not on resource creation.

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

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

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

Verified (m3-max-33194, msi, at 01fe19ba22): clippy of the runtime and validation crates (all
targets, all features, -D warnings) 0; lavapipe 132/132 of first_use|heap*|shadow*, including
first_use::new_resources_wait_for_no_gpu_work and every heap_tiled unit test. The PHOENIX runs
(the cause's device) and clippy in the device configurations follow on development.
2026-11-15 11:35:22 -08:00
Anees Iqbal 8bd796ce4f Bench: the layer's download over every chunk of a RAM whose writes a log keeps
A VMM keeps a log of its guest RAM's writes on a discrete GPU, so a download into that RAM
records each command's uses for the commit's report to the log (DirtyCommit::note): a cost the
layer bench's RAM, which had no log, never showed. host_ram_layer_encode_bench now runs its
two cases (the layer in one chunk and over every chunk), lets that RAM go (its keep-alive
dropped, so two RAMs' pages are never held at once), then runs the layer over every chunk of a
second fresh RAM with a log (HostRam::with_dirty_pages of LayerLog, which counts the runs it is
told), alone and beside a fill as the others, and prints the runs the log was told a copy: the
evidence the logged path ran.

The case's body is layer(), shared by the three. host_ram_device gains fresh_logged_ram_in, a
fresh RAM with a log, beside fresh_ram_in (fresh_host_ram_of makes the RAM for both).
2026-11-15 11:28:16 -08:00
Anees Iqbal 87e6846abd 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-15 11:27:52 -08:00
Anees Iqbal ccf9d5847a RUNTIME 2372: Encoders: a command's joined runs go into the part's tracked uses at once, as note leaves them
order_joined's Joins::of copied every use of a joined run's kept tail into a `noted` list grown
from empty, and took each run's hull twice by folding whole uses; note then walked those uses one
by one (a map entry, a find over the key's ranges, a clone, the room for 9 at the second), though
Joins already holds the run's key new to the part and named once by the command. At a host RAM
copy over 128 chunks (2049 uses, 128 runs of 16) that was about 25 us in Joins::of and 25 us in
note a copy on msi's lavapipe (release probe, m3-max-33112).

Joins now keeps, for each joined run, its key and the list note leaves of it from none (the hull
of its first 9 + 8m uses, then each after, in one Few with room for 9 past the first, as note
reserves), and `noted` holds only the uses no run joined. order_joined orders by `ordered` and
notes `noted` through order_as as before, then puts each joined key's list into the part at once
(note_kept), the map reserved for them. A run's hull is the first's range hulled with the last's
(their bytes past each other: the first's start to the last's end) with the reads and writes of
all folded, no use moved per step. A run with an empty range is not joined (joins), so note's
merge of equal ranges never meets a joined run, and empty ranges order as before.
order, inside_uses and admit are unchanged; the plain path takes none of this.

Test: runs_of_9_and_20_uses_join_exactly_and_one_with_an_empty_range_does_not (a 20-use run that
note collapses at its 9th and 17th, a 9-use run, a buffer use; after a command and as the first;
ordered and not) asserts equal barriers, summaries and the next encoder's cross-queue plan against
order, and that the run with an empty range is not joined. The 600-round
runs_of_one_key_joined_order_exactly_as_their_uses keeps asserting the same over random commands.

Verified: m3-max-33153 (msi, at 83e47c807a): the runtime crate on lavapipe 2823/2823, clippy
plain, m2v_gpu and m2v_cpu_icd 0, Rustdoc 0. Release A/B (m3-max-33160, msi lavapipe, 3
interleaved pairs, the same probe on both, us a call at 128 chunks): note 25.7/23.2/29.3 ->
4.0/4.3/4.5; Joins::of unchanged (about 27); the call 132.0 -> 115.1 mean; one chunk unchanged.
2026-11-15 11:27:11 -08:00
Anees Iqbal b255317a37 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-15 11:26:06 -08:00
Anees Iqbal 09aee83953 RUNTIME 2371: Compute: a state keeps 16 plans; a lookup compares the latest four in place and keys only the rest
A dispatch takes what its state planned for its bind state's shape and class of grids while the
state keeps it among its latest PLANNED. A stream of dispatches over buffers of several length
classes in grids of several classes cycles more pairs than 4: the bench's moved, heap, ragged
shape of three length classes cycles 6 through 4 entries, so a fifth of its dispatches planned
again (plan_now 4.0% of the encoding thread on msi lavapipe, m3-max-33099). In the consumer's
profile of its compositor's fix-index encoder on the XTX (hvP2, at 2cdfa840b5) plan_now,
BindState::shape and position_of_shape were 25.2% of dispatch_threads, 64% of its dispatches
planned and 47% made their shape anew.

PLANNED goes from 4 to 16. Each Planned carries its shape's key beside its used resources
(BindShape::key_beside_used). A lookup (position_of, used by planned_shape and planned_of)
compares the latest IN_PLACE = 4 entries in place, as the state compared its four before; only
where none is the state's shape does it work out the state's key (which folds every argument
sampler's) and compare whole only the remaining entries of that key. planned_for's fallback,
past the Arc match, compares whole only entries of the shape's key. PLANNED's doc states the
bound: about 290 bytes an entry, and at most PLANNED entries' variants and region pipelines kept
past the state's memos. The dispatch_chain bench's --classes takes up to 12.

Test: grid_classes::shapes_and_classes_in_turn_each_plan_once (six shape-class pairs in turn for
six rounds: each plans at its first dispatch alone, every later one takes its plan, every slice
Metal's words); at PLANNED=4 it fails (grid_classes.rs:346).

Verified at 9b5717e840 (m3-max-33158, msi): clippy plain, m2v_cpu_icd and m2v_gpu 0, Rustdoc 0,
106 lavapipe tests of the compute paths, the PLANNED=4 control failing. Profile (m3-max-33180,
msi lavapipe): 48 samplers, 3 classes: no key pass, plan_now gone; 12 classes (24 pairs): the
keyed path runs. XTX A/B (m3-max-33162, 5 interleaved rounds, load 23, median ns a dispatch,
dev 0ab6927fce / this): no samplers 3 classes 4448/4272; 48 samplers 3 classes 5180/5122, 12
classes 7708/6423; 200 samplers 3 classes 6408/6435 (flat); plain 3753/3554; no samplers 12
classes noisy (median 6151/6547, min 5839/5220, least encode+commit 6166/5543).
dispatches_planned_as_before 0.80 -> 1.00 at 3 classes; at 12 classes 0.61 reused where dev
planned every dispatch.
2026-11-15 11:25:26 -08:00
Anees Iqbal 0ab6927fce 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-15 11:02:00 -08:00
Anees Iqbal c76dec3f57 RUNTIME 2370: Host RAM copies: a copy's imports name their chunks in one flat list, and a made chunk's import is taken without a list of its own
copy_imports built, per chunk, a Vec in a BTreeMap of the import indices that hold the chunk's
bytes, and for_copy returned a one-element Vec for every made chunk: at 128 chunks two heap
allocations a chunk on every copy, the kept plan's reuse included, before the plan's serials
and maps were compared.

CopyImports::of_chunk (and KeptPlan's copy of it) is now one Vec of (chunk, import index) pairs
in the imports' order, sized for one import a chunk up front. copy_imports takes a made chunk's
import itself, after take_for_copies still moved the window past every chunk left, and
for_copy handles only chunks not made. The reuse compares the two lists as before (same
imports in the same order, each holding the same chunks). The full path sorts a copy of the
pairs by chunk (stable, so each chunk's imports keep their order) and looks a piece's chunk up
in it (imports_of), in place of a table of every chunk's slice.

Test: each_chunk_s_imports_are_found_by_chunk_in_the_order_they_were_given checks imports_of
against the old per-chunk map over 200 generated import lists. The device tests of both copy
paths cover the rest.

Verified: m3-max-33083 (msi, at 9b59c25348): the runtime crate on lavapipe 2821/2821, clippy
plain, m2v_gpu and m2v_cpu_icd 0, Rustdoc 0. Release split at 128 chunks (m3-max-33086, msi
lavapipe, before/after interleaved, the same phase probe on both, us a call): copy_imports
23.1/25.1 -> 4.9/5.1, the reuse's compare 6.7/6.9 -> 2.5/1.9, the imports' drop 4.6/4.0 ->
0.8/0.9; the layer's call 156.7 -> 133.9 mean; one chunk unchanged (one slot).
2026-11-15 11:01:19 -08:00
Anees Iqbal 1328c20270 parity: the corpus path comes from the validation directory at run time, not the build machine's
corpus() joined env!("CARGO_MANIFEST_DIR"), baked at build time, so a carried test archive run
on another node read no Metal records (parity::sequences::lane::sequences_0..7 'no Metal record'
off msi, regr98's 31742). It now joins metal2vulkan_devtools::validation_dir(), as the
runtime lane's corpus readers do.

Verified: see the landing check job.
2026-11-15 10:54:57 -08:00
Anees Iqbal 48ce52b1b9 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-15 10:54:00 -08:00
Anees Iqbal 421ee18512 RUNTIME 2369: Compute: a dispatch holds its pipeline state, variant objects and pipelines by address first
Each compute dispatch held its pipeline state, its variant's objects and each region's
VkPipeline by another reference (an Arc clone) that Retained::shared then dropped where the
encoder held the object lately, as it does for every dispatch of the objects of the one before
it: an atomic increment and decrement of each object's count, on lines other threads touch too.
In the consumer's profile of its GL fix-index encoder Retained::shared was 3.3% of
dispatch_threads, 2.8% its own.

Retained::shared_of holds an object by the caller's reference, cloning it only where the encoder
does not hold it lately, the same address test shared makes (EncoderCore::retain_shared_of,
ComputePipelineState::retain_in); compute's record holds its three kinds so, and keeps a
reference to the variant's objects rather than a clone of them. ComputePipelineState::held,
unused now, is gone.

Tested: tests::retained's new a_hold_by_reference_takes_another_only_where_none_is_held_lately
(holds and strong counts of shared_of alone and mixed with shared, and the push-out of the eight
looked among).

Verified at 1480a5352c (msi-laptop-w3657): m3-max-33061 clippy plain 0, lavapipe 332 tests of
retained|held|holds|compute|dispatch|grid_|pending passed; m3-max-33066 clippy m2v_cpu_icd 0,
m2v_gpu 0, Rustdoc 0. XTX A/B (m3-max-33058, radeon, 5 interleaved rounds, load 17-23, median
ns a dispatch, dev f452591afc vs the cut on it): 200 samplers 6074/6156, 48 samplers 4738/4641,
none 4398/4357, moved heap 3493/3470: no measurable change in the bench, where the counts stay
in one thread's cache; the in-situ gain is expected only, for the consumer's next profile.
2026-11-15 10:53:14 -08:00
Anees Iqbal 981d3f5f4b 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-15 10:44:16 -08:00
Anees Iqbal 2332ae096e RUNTIME 2368: Host RAM copies: a kept plan's table goes into a buffer of its own at its first reuse, which each reuse binds
Each copy by a kept plan uploaded the plan's table into its command buffer's arena: 8100
entries of 16 bytes for a layer, past the arena's 32 KiB so a chunk of its own (a new Shared
buffer) and a 130 KB copy, 22.5 us of a 74 us call at 1 chunk and of 191 at 128 (probe
m3-max-32988, steelbrain/dl2-probe4, not landed), for bytes the plan held and never changed.

KeptPlan keeps them in a buffer of its own (table_kept, a OnceLock), made at its first reuse
by KeptPlan::table_buffer: the arena's class (Shared, default cache, untracked, by
unzeroed_buffer_with, so the GPU reads it from the same memory), written once before any
command reads it and never again. record_dispatches takes the table as bytes to upload (the
full path, as before) or as that buffer (Table::Kept), which each command buffer that binds
it retains, so a plan the LRU or the RAM's end lets go of frees it once they complete. Two
encoders' first reuses at once keep the one set first. A plan never reused makes none. The
tables count in MOST_PLAN_BYTES already, so the device memory kept is at most that and each
buffer's rounding. A recovery carries the RAM's use to a new RamOnDevice on the next
generation (RamUseCell::carry), whose plans start anew, so no old generation's table is bound.
New counter WorkCounts::host_ram_copy_tables_kept; api_signatures.tsv blessed; the module
docs, KeptPlan's and HOWTO's say what memory the plans keep.

Tests (device): a_plan_keeps_its_table_in_a_buffer_from_its_first_reuse (planned, first reuse
keeps it +1, later reuses +0, bytes each time); a_kept_table_a_command_buffer_bound_outlives_
its_plan (command buffers held by a shared event bind it, eight other copies push the plan
out, the bytes after the signal); a_recovery_starts_a_ram_s_plans_and_their_tables_anew
(recover_for_test: the first reuse after keeps a table of its own).

Verified: m3-max-33015 (msi, at 612f09e48a): the runtime crate on lavapipe 2811/2811, clippy
cpu-icd, plain and gpu configurations clean, Rustdoc clean; the API tests 15/15 (m3-max-33048),
whose recovery test printed no skip line. Medians (m3-max-33017, msi, before/after interleaved,
us per call): one chunk, copy alone 60.6/59.6 -> 44.4/41.6, the copy after a fill 58.1/58.2 ->
44.3/41.6; 128 chunks about 10 us lower on average, within the runs' spread.
2026-11-15 10:43:31 -08:00
Anees Iqbal cb44fd0030 dispatch_work: a grid of the planned one's class takes its plan, and a ragged grid plans again
RUNTIME 2363 lets a dispatch of another grid of the class a plan was made for (pipeline::GridClass:
form, threadgroup size, whole, one row) take that plan where it names the very variant for the
grid. dispatches_take_what_their_state_planned_for_the_same_shape still expected the step
"the grid" (THREADS to 2*THREADS at the same threadgroup size: both whole, one row) to plan again,
and failed at dispatch_work.rs:516 on lavapipe (found by the synchaz lane, m3-max-33014/33033).

The step now expects the first grid's plan (planned 1, settled 0), and a new step dispatches a
ragged grid (1.5 threadgroups, another class) of the same shape, which must plan again. The later
steps move up two threadgroups to make room for its words; the doc says what the test checks now.

Verified: runtime_lane::dispatch_work on lavapipe and validation clippy (plain and m2v_cpu_icd)
in the potluck job that reports this tip.
2026-11-15 10:37:54 -08:00
Anees Iqbal 5ac7852e20 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-15 10:37:42 -08:00
Anees Iqbal 85a91d182c RUNTIME 2367: Queue plan: a device made with its least plan reserves what its plan reserves, no more
The 2080 round 9ce951f521-1115-0907 failed
reserved_queues::a_device_with_no_queue_to_spare_reports_the_reserved_queue_absent:
"11 asked, 11 reserved; no message", where queue_plan(families, u32::MAX)
spares 10 (NVIDIA's graphics family of 16 less the round robin's floor of
four and presenting's two). Asked for 11, the plan takes 4 + 2 + 10 plus the
staging and fill queues, 18 VkQueues; the driver refused that for want of
channels (um790's kernel log: "kchannelAllocMem_GM107: Could not create
Channel" 19 times at 10:01 and 13 at 10:02, while the 780 s run that ended
10:04:38 was at the test), and made_within_resources took least_queue_plan:
queue_plan_within(families, options.reserved_queues, {1, 0}), a round robin
of one and reserved min(15, 11) = 11. 11 is what only that path gives.

So a device short of resources gave the caller more reserved queues than the
same device given them, and skipped the reserved-queues-absent message,
though the least plan's notice and the runtime README say it keeps the
plan's reserved queues. least_queue_plan now reserves as many as the
device's own plan (within options.queue_limits) reserves; its round robin
of one always leaves room for them, so no fewer either.

Tests:
- queue_limits::the_least_plan_reserves_what_the_plan_reserves: every
  family shape, reservation (0 to u32::MAX), limit and cached flag; fails
  without the fix on NVIDIA's shape asked for 11 (11 against 10) and on a
  family of 24.
- reserved_queues::a_device_made_with_its_least_plan_reserves_what_its_plan_spares:
  the plan refused through refuse_next_devices(1), the device asked for
  spare + 1 takes its least plan (its notice heard, round robin 1) and
  reserves spare, reporting the rest absent; refused where the least plan
  takes no fewer (lavapipe, RADV).
- The test sink records each message's id name with its text, so the
  least plan's notice is matched by its code.

Docs: the degrade catalogue (docs/API.md), LeastQueuePlan's rustdoc and the
runtime README's "A driver short of resources" say the reserved count is the
plan's.

Also: queue_share_device's pinned test takes a stay the sharing rule
explains, as its siblings do (test only).

Verified (msi, m3-max-33039): clippy plain 0; lavapipe reserved_queues,
least_queue_plan, queue_limits and the pinned test 16/16. The 2080 run
follows on development.
2026-11-15 10:37:01 -08:00
Anees Iqbal 30331a477f kept_textured: the spun copies wait for the spin through a fence
Under METAL2VULKAN_LANE_VALIDATION=sync on lavapipe,
runtime_lane::kept_textured::a_kept_heap_draw_reads_what_an_earlier_command_buffer_wrote
failed on 1024 reports (512 copies, two cases): "vkCmdCopyBufferToImage(): READ_AFTER_WRITE
hazard detected. vkCmdCopyBufferToImage reads VkBuffer ..., which was previously written by
vkCmdDispatch", copy regions from offset 64, 64 bytes each.

spun_copies encodes the spin's dispatches, which store their count in the source buffer's
first word (bytes 0..4), and then copies the texels from bytes 64 on. Its premise ("so the
copies follow the spin") was Metal's whole-resource tracking of the buffer. The runtime orders
a tracked buffer by the bytes, as its README's "Hazards" says:

  The runtime orders a tracked buffer by the bytes a command reaches: those its translation
  proves a shader reads or writes, else from the bound offset to the buffer's end. Vulkan's
  synchronization validation takes a shader's buffer as accessed over its whole descriptor,
  which spans those bytes widened to 16-byte granules from the device's offset alignment, so
  it reports hazards between commands whose bytes are apart, as it does between untracked
  uses Metal leaves to the program; no order of either changes a result.

So on the runtime the copies did not follow the spin, and the test lost the delay it was built
on (the frame's kept draws waiting for an earlier command buffer's late writes). The layer
reported the copies' reads against the dispatch's whole descriptor.

The spin's encoder now updates a fence and the copies' blit encoder waits for it: an order
Metal keeps too (redundantly, beside its tracking), and one the runtime records as a barrier
from the spin's compute stages (fence.rs, the tracker). The copies follow the spin on both,
and the layer sees that barrier. Spin::encode takes the fence to update; Spin::new's timing
runs pass none.

Before: m3-max-32985 (msi, lavapipe, sync, at 3945a91289) failed the test with the reports
above. The proof run of this tip is in its landing report.
2026-11-15 10:22:18 -08:00
Anees Iqbal f67343b44e address_maps: the alpha-code rounds note their dispatches' apart writes
Under METAL2VULKAN_LANE_VALIDATION=sync on lavapipe,
runtime_lane::address_maps::every_alpha_code_of_a_texture_whose_alpha_reads_one_reads_one
failed on 65280 reports (255 pairs a round, 256 rounds) of one record-time hazard:
"vkCmdDispatch(): WRITE_AFTER_WRITE hazard detected. Shader stage VK_SHADER_STAGE_COMPUTE_BIT
writes to VkBuffer ..., which was previously written by another vkCmdDispatch command", binding
0 of rrp_sw_read_f.

Each round's 256 dispatches write o[0], a float4: 16 bytes each, CODE_STRIDE (256) bytes
apart, in one tracked buffer. The runtime binds the slot over the buffer and orders a tracked
buffer by the bytes the translation proves a shader writes (runtime README, "Hazards"). The
layer takes the whole descriptor as written. Writes that share no byte make no data race
(Vulkan's Memory Model appendix), so no order of them changes a byte, and the claim the test
stated (layer_reported_nothing_at_all) was wider than what the runtime promises.

Each round now notes its 256 writes (NotedWrites, one per round: the rounds write the same
bytes again, after the previous round's wait) and states
layer_reported_nothing_but_apart_writes, which lets a write after write between noted writes
pass only where no two of them share a byte.

Before: m3-max-32985 (msi, lavapipe, sync, at 3945a91289) failed the test with the reports
above. The proof run of this tip is in its landing report.
2026-11-15 10:22:18 -08:00
Anees Iqbal b815e51395 Hazard parser: read a transfer command's access as the layer words it at recording
Under METAL2VULKAN_LANE_VALIDATION=sync on lavapipe,
runtime_lane::memoryless_uses::memoryless_compute_and_blit_uses_fail_as_metal_s failed in
its "unused" case on one write after write the layer reported as the fill was recorded:

  vkCmdFillBuffer(): WRITE_AFTER_WRITE hazard detected. vkCmdFillBuffer writes to dstBuffer
  VkBuffer 0x700000000070, which was previously written by vkCmdDispatch.

The fill writes mark 3 (bytes 12..16) and store_const the mark at 8 (bytes 8..12). The test
notes both, so the report is of the apart form its claim already lets pass (8 of the run's 9
reports passed so). The lane's hazard parser (parity::sequences::hazards::parse) wanted
"VkBuffer " right after "writes to " and returned None for the parameter name ("dstBuffer")
that the layer puts before the memory in a transfer command's record-time wording. The runtime
now records the blit encoder after the compute encoder in one VkCommandBuffer, so the layer
reports the pair as recorded and no longer in the submission form the parser read.

parse() now skips one word between the verb and "VkBuffer "/"VkImage ". parity::sequences'
lane reads the layer's hazards through the same parser, so it gains the record-time transfer
wording too.

Tests: the_lane_reads_the_layers_hazards parses the exact record-time fill wording above and
a read of a "srcImage VkImage"; apart_writes' a_fill_and_a_dispatch_apart_pass_either_way_round
judges the record-time fill wording apart. Both fail without the parser change.

Before: m3-max-32985 (msi, lavapipe, sync, at 3945a91289) failed the test with the message
above. The proof run of this tip is in its landing report.
2026-11-15 10:22:18 -08:00
Anees Iqbal f452591afc 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-15 10:15:32 -08:00
Anees Iqbal ab139e4b6e RUNTIME 2366: Runtime FALLBACK repro bundle at a creation refusal (default-off diagnostic)
What: metal2vulkan-runtime writes the FALLBACK repro bundle the command line
writes for its own failures when it refuses a library or pipeline creation,
where METAL2VULKAN_REPRO_DIR names a directory (unset, nothing is written).

- The CLI's bundle writer moves into the library as the hidden crate-root
  module metal2vulkan::repro (feature serde), shared by the binary and the
  runtime. A bundle's directory is named by its content
  (metal2vulkan-repro-<16 hex>), written under a temporary name and renamed,
  so an identical failure is written once, across threads, processes and
  runs. The CLI's own bundles keep their files (input, profile.json, the
  descriptor files, repro.sh, repro-command.txt, failure.txt); only the
  directory's name changed, so a bundle written before still replays.
- The CLI takes --device FILE in place of --profile: the JSON of a
  DeviceDescription and DevicePolicy (ReproDevice), which builds the
  runtime's own compile device.
- The runtime hooks each creation where its refusal returns: a library of a
  metallib, a function's lookup, every compute and tile state
  (ComputePipelineState/TileState::create_adding: creations, added binary
  functions, archive adds) and every render state
  (GraphicsState::create_reflecting). It bundles Unsupported, NotImplemented
  and Compile refusals but a cancelled compile and a name the library lacks
  (Metal's own nil); never Invalid/Nil/MetalError. The bundle holds the
  library's bytes, device.json, the request as the CLI's options and
  descriptor files, and failure.txt with the call, the refusal and what the
  command does not replay. That list comes from a full destructuring of the
  compute, tile and render descriptors (and the stage functions): a new
  descriptor field fails to compile in repro.rs until it is replayed or
  listed.
- Bounded: at most 32 bundles and 256 MiB per process; past either nothing
  more is written and one line says so. Written on the refusing thread; the
  call returns the same refusal; a write failure is said once. Each bundle
  is named in one line through the device's message sink (id name
  metal2vulkan-repro). The runtime's metal2vulkan dependency gains serde.
- Not bundled: mesh states (no CLI mesh path), a dispatch's or draw's later
  variant, driver VkPipeline makings, Metal-source libraries.

Docs: env_vars registry, README CLI, docs/HOWTO.md section 4, the runtime
README's Errors section, the CLI help.

Tests: runtime CPU tests of the bounds (a tally with the seam's limits);
a lavapipe/GPU device test (ob3_stage_input with no stage-input descriptor:
one bundle with the expected parts and command, device.json rebuilding the
runtime's compile device by profile fingerprint and answering the same
refusal, none for a second identical refusal or a missing name, none
without a directory); CLI tests replaying library-written runtime bundles
(compute, and render with a vertex descriptor) through repro.sh to the same
FALLBACK, and --device compiling what --profile does.

Verified at ae56b195e9 (msi, m3-max-32986): metal2vulkan cli,
api_surface and api_signatures 25 passed; runtime repro tests 9 passed;
clippy -p metal2vulkan -p metal2vulkan-runtime all targets, all features
0. Lavapipe (m3-max-32978): repro_device writes one bundle that the
CLI replays to the same refusal; a second identical refusal writes
nothing.
2026-11-15 10:14:52 -08:00
Anees Iqbal 2cdfa840b5 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-15 10:13:55 -08:00
Anees Iqbal 1d2dbcbfc5 RUNTIME 2365: Compute: an encoder's dispatch takes the device's sampler states only where it needs them
Every compute encoder dispatch that settled (no memo entry held) listed
every live sampler state of the device (argument_samplers_at: a lock,
an Arc clone of each, and their drop), though its kept bind state
already listed them at the count of their slots' changes that held, and
a variant with no set-1 arrays binds none of them. In the consumer's
profile of its GL fix-index encoder that listing was 4.7% of
dispatch_threads, beside the states' drop.

A compute encoder's dispatch now takes them as a draw does
(sampler::ArgumentSamplers): only where the kept listing is not of
every live state at the count that holds (then compared state by state,
as before), where the variant has set-1 arrays (fitted and written to
the heap, as before), where a notice names a state of pixel coordinates,
or where a parked memo entry of such a variant goes on in the next
encoder (restamp). SettledDispatch::argument_samplers is None where
none were taken; a heap dispatch without them is an internal error,
not a silent empty listing. The memo's count of slot changes is the
taken states' where it took them, else the one the kept listing holds
at.

WorkCounts::argument_samplers_taken now counts compute dispatches'
takes too (its doc says so); no new field, no new Degradation kind.

Verified: not yet built; the next job builds and tests it.

Verified (msi, lavapipe, m3-max-32979 at 421c3c4d65): clippy plain 0;
compute, dispatch, grid, region widths, partial threadgroups, flat
simdgroups, sampler, argument and heap trimmed tests 163/163, including
compute_sampler_listing (argument_samplers_taken moves only after a state
is made or goes; every dispatch's words are Metal's).
2026-11-15 10:13:12 -08:00
Anees Iqbal 3945a91289 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-15 10:07:22 -08:00
Anees Iqbal 0ffe55a639 RUNTIME 2364: Encoders: a command's runs of one resource's bytes past what the order keeps are ordered as one use, exactly as their uses
A host RAM copy names each chunk it touches by up to 16 ranges (MOST_RANGES), 2049 uses for
a layer over 128 chunks, and the encoder's order paid for each: note 45 us, touch_reaching
27 us and wait_first 11 us of a 200 us call on msi, and the next command took the copy in
for another 150 us (inside_uses, merge's sort and finds, admit's finds). Probes m3-max-32845
and m3-max-32862, branch steelbrain/dl2-probe3 (not landed).

EncoderCore::track now orders a command by EncoderUses::order_joined. A run of more than
ENTRIES_PER_KEY consecutive tracked uses of one key's bytes, each past the one before, of a
key the command names nowhere else and the part holds no entry of (in its order, after the
part's first command is taken in, nor in its tracked uses), is compared, waited and taken
in as one use, its hull with the reads and writes of all: admit collapses the run's entries
into exactly that entry, and the comparison meets no entry of the key either way. The part
notes it as note leaves it from no entries: the hull of its first 9 + 8m uses, then each
after. So every barrier, the order and the encoder's summary are the same as order makes of
the uses; anything else goes through order unchanged. note_dirty, shadows.wrote, skips, the
twin check, owed.pay and the fold's order keep the command's own uses; inside_uses, admit and
note are unchanged. touch_reaching skips a use whose key and naming the use before it had
(its insert and name are idempotent; its per-position cache is kept for every use).

Tests: tracker, runs_of_one_key_joined_order_exactly_as_their_uses (600 generated encoders,
ordered and not, keys holding none to more than 8 entries before runs, runs off by an empty
range, a range not past the one before, an untracked use, a key named twice; per-command
barriers, summaries and the cross-queue plan of a following encoder equal; more than 300
commands joined); device, copies_over_a_long_scatter_s_pages_and_gaps_in_its_encoder_keep_
their_order and a_long_scatter_reports_each_run_to_the_ram_s_log_and_no_page_between_them.

Verified: m3-max-32906 (msi) clippy plain, m2v_gpu, m2v_cpu_icd 0,
rustdoc 0; m3-max-32926 the whole runtime crate on lavapipe 2806/2806;
runs_of_one_key_joined_order_exactly_as_their_uses: 600 generated
encoders, order and order_joined equal on every barrier, summary and the
next encoder's plan; sync_coverage 7/7 (m3-max-32907). Release medians
(m3-max-32909, msi loaded, interleaved), 128 chunks: the fill after the
copy 194.8/194.1 -> 27.9/26.5 us, the copy after a fill 459.0/442.1 ->
275.9/259.8 us.
2026-11-15 10:06:41 -08:00
Anees Iqbal 291635393a 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-15 10:05:37 -08:00
Anees Iqbal ac0229e5d7 RUNTIME 2363: Compute: a direct dispatch takes what another grid of its class planned
A compute pipeline state kept what its latest direct dispatches planned
(Planned: the variant, its plan and its regions' made VkPipelines) keyed
by the exact dispatch, so a guest's fix-up stream of dispatchThreads:
calls of a thread per element, one width after another, planned every
dispatch again: settle_direct, settle_flat and Variant::plan's LRU hash
and compare of the bind shape two or three times, a new Planned whose
regions' pipelines were looked up again, and plans of other shapes
pushed out of the four kept, so the shape was made again too. In the
consumer's profile of its GL fix-index encoder on an RX 7900 XTX that
was plan_now 17.8% of dispatch_threads, region lookups about 6%, and
BindState::shape 5.3% beside position_of_shape 2.3%.

A grid's class (pipeline::GridClass) is its dispatch form, its
threadgroup size, and whether it is a whole number of threadgroups and
one row in threadgroups of one row: what settle_direct chooses its
branch by (flat_direct and partial_direct now read those from the
class). Where every region a plan plans has the call's threadgroup size
(a flat variant's one region, a partial-threadgroups variant's
threadgroups, a whole grid's chunks), every variant key the branch makes
is a function of the plan and that local size, and the grid's size
reaches it only through the device's limits. So a Planned of the bound
form on a flat or partial-threadgroups variant, or of a whole grid,
serves the other grids of its class, after its plan names its very
variant for the new grid (BindingPlan::dispatch_variant, which checks
the grid against those limits each time); otherwise the dispatch plans
as any and meets the same refusal. A ragged grid's exact split keeps
the exact key. The call's own grid is what record instantiates; the
dispatch memo and the kept commands (Instantiated) keep their dispatch,
since their commands are the grid's.

New count: WorkCounts::dispatches_planned_across_grids, those of
dispatches_planned_as_before of another grid of the class.

Verified: not yet built; the next job builds and tests it.

Verified (msi, lavapipe, m3-max-32955 at ccfcc384b3): clippy plain 0;
api_signatures and api_surface 15/15; compute, dispatch, grid, region
widths, partial threadgroups and flat simdgroups 90/90; grid_classes reads
every dispatch back against Metal's answer and counts 20 cross-grid plans
a kernel; an over-limit grid of a planned class is refused as before.
Negative controls: reuse with the check skipped fails both tests.
2026-11-15 10:04:56 -08:00
Anees Iqbal 59932b32ba dma_buf_imports: is_multiple_of in the shared source's alignment check
Clippy (--cfg m2v_gpu and --cfg m2v_cpu_icd, -D warnings) refused the manual
modulo in Memfd::shared_source (clippy::manual_is_multiple_of), red in
m3-max-32936 for development b1c6b40570. Same check, its method form.

Verified: cargo fmt; clippy of metal2vulkan-validation in all three
configurations in the msi job that follows.
2026-11-15 09:59:10 -08:00
Anees Iqbal b1c6b40570 submit_per_import: held buffers as pieces of one shared dma-buf file
A third held-for-good kind: the n buffers' source answers each request with
a piece of one udmabuf of their whole memfd (DmaBufRequest::shared_files, as
a consumer's group of views is), so the device imports the file once and
binds each buffer at its piece (Memfd::shared_source). Against the own
dma-buf rows it shows whether a shared file costs RADV's submissions one
listed entry, whatever its pieces; the lines now print the pieces joined and
the shared files live, the evidence the join path ran.

Verified: cargo fmt; run on gem10's PHOENIX in the probe job that follows.
2026-11-15 09:49:50 -08:00
Anees Iqbal 1db2624115 submit_per_import: a phase of imports held for good
The dma-buf phases held at most 64 imports live (136 for 1000): their
buffers are read by blits alone, so the residency released those past the
most it keeps on a device whose held imports cost every submission. A
guest's imports are bound and stay (the HawkPoint Launchpad walk held 363
buffer dma-bufs and 163 image ones). Each kind now runs again with every
buffer's Metal address read (Buffer::gpu_address), which keeps each import
held for good, so a phase holds all n live and its line gives the per-entry
cost at the walk's counts.

Verified: cargo fmt; run on gem10's PHOENIX in the probe job that follows.
2026-11-15 09:36:16 -08:00
Anees Iqbal 5aad56bc82 submit_per_import: print each VkSubmitInfo's time in vkQueueSubmit
The SUBMIT-PER-IMPORT lines now carry the VkSubmitInfos a phase submitted and
WorkCounts::batch_submit_nanos over them: the driver's time per submission
beside the kernelStart-to-kernelEnd percentiles, so a phase's per-import cost
reads in the same unit as a walk's WorkCounts (perdraw8: the HawkPoint walk's
scheduler spent 390 us per VkSubmitInfo in RADV's vkQueueSubmit).

Verified: cargo fmt; built and run in the gem10 PHOENIX probe job.
2026-11-15 09:29:26 -08:00
Anees Iqbal e4daf97233 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-15 09:20:33 -08:00
Anees Iqbal 0b6f72ac29 RUNTIME 2362: Scheduler: a copy queue's command buffer keeps commit order behind a held batch
What: a head on a queue made for copies (Device::new_command_queue_for_copies) no longer
goes before an earlier-committed batch of another queue it conflicts with because that
batch gives way. The order's comparator (scheduler/mod.rs is_behind) treats a held batch
that gives way as one that keeps its place when the head's queue keeps commit order
(Standing::commit_order, from CommandBufferShared::keeps_commit_order: the queue's kind,
set by the copy queue's constructor). Such a head waits behind it in the scheduler when
tracker::ordered says the two conflict, whether the held batch waits for its pipelines'
making, a host step or its checks. Once the held batch is submitted, the tracker orders the
copy after it on the GPU: the copy engine's VkQueue waits for the other VkQueue's timeline,
or a barrier where they share one. There is no wait on the host. A copy that shares nothing
with the held batch still goes. Unchanged:
- plain queues keep the give-way exactly as before (order.rs, Held batches give way), so the
  Iris Xe compositor case is untouched;
- a held batch ON a copy queue stands to a later plain queue's commit as any held batch does
  (the rule is the head's);
- a batch held for an event value or a binary semaphore's signal the program has not given
  holds back no copy (Stops).

Why: the copy queue's documented promise is that a copy reading what another queue's
command buffer committed before it wrote waits for that command buffer on the GPU. A
command buffer of a blit and a new pipeline's first dispatch, held for the pipeline's
making, gave way to a copy committed right after it on the copy queue. The copy ran first
and read the bytes from before the blit: the consumer's copy queue on an RTX 2080, and a
plain second queue on MoltenVK, round 0 only, always the new pipeline's first dispatch. The
give-way rule (b46459080d) stays for plain queues, where real Macs disagree; the copy queue
is a runtime extension whose contract is ours.

Docs: order.rs (But not to a queue made for copies, No deadlock), the scheduler's Tracking
paragraph and is_behind, new_command_queue_for_copies (what holds exactly, the reverse
direction, and that on a device that answers None a plain queue used instead gives way, so a
caller orders such a copy with an event), the runtime README's copy-queue and pipeline-wait
passages, docs/API.md's pipeline-wait passage, pending_dispatch.rs,
WorkCounts::heads_held_for_earlier_commits, and the hold_sites module docs.

Verified: lavapipe before (the previous commit's copy-queue leg) and after, reported with
the tip.

Verified (lavapipe, the copy queue on the round robin VkQueue): at
87ab2111b0 (m3-max-32839) the copy-queue leg fails, reading the bytes
from before the blit; at 404352e262 (m3-max-32840) hold_sites,
dispatch_pending, pipeline_wait_order, held_step_order and copy_queue
16/16, clippy m2v_cpu_icd 0.
2026-11-15 09:19:49 -08:00
Anees Iqbal 177ff2240b 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-15 09:16:59 -08:00
Anees Iqbal f10e9d8c90 RUNTIME 2361: Host RAM copies: a repeated copy's call finds its kept plan as it merges the runs given, and makes no vector of them
On a repeated copy by a kept plan, a third of the encode was the call's own work on its
runs before the plan was even looked up: runs.to_vec, merged into a second vector, boxed,
in_words, then compared with the plan's at the recording (probe m3-max-32752, msi: 66.8 of
97.1 us at 1 chunk, 51.2 of 233.0 at 128 chunks).

The four calls (copy_from_host_ram, copy_to_host_ram, copy_runs_from_host_ram,
copy_runs_to_host_ram) now give HostRamCall::new their runs as given (Given: laid one after
another from an offset, or each at its own byte). It looks for a plan of the same direction,
form and buffer key (RamCopies::kept_for) and compares the given runs with the plan's while
it merges them (merges_to): each run checked as merged checks it, joined as merged joins
it, each joined run compared with the plan's next, a run laid past u64 refused as
one_after_another refuses it. Merged runs, checked and in_words are functions of the given
runs alone, and a plan exists only for checked runs copied by words, so a match is exact.
On a match the call shares the plan's runs (HostRamCall.runs and KeptPlan.runs are now
Arc<[Run]>) and names the plan (HostRamCall::kept); else it builds its runs as before, and
a plan kept of it shares them instead of cloning them.

The recording takes a named plan only while the RAM keeps that very plan
(RamCopies::keeps, by Arc identity): one the LRU bound or anything else let go of before
the copy records (an encoding again at a rebind, say) takes the copy to the full path
over the call's shared runs. A call that named none looks one up as before. Every dynamic
check of record_kept is unchanged.

Second, takes() no longer joins every chunk's ranges for copy_take: copy_take's signature
is unchanged in its types (device, importer, slot, ranges: &[Range<u64>]) but ranges are
now the chunk's ranges as touched_ranges gives them, and copy_take joins them
(copy::alone_ranges) itself, only past its made() check, where it reads them. Same
answers: the joined ranges were read only on that branch. (probe: 9.2 us a call at 1
chunk, whose ~4100 ranges were joined though the chunk was made; 40.3 at 128.)
chunk(), take(), took() and after_take are untouched.

Tests: unit, runs_merged_as_they_are_compared_match_the_kept_runs_exactly_as_merged_gives_them
(random runs of both forms with joins, empty and off-word runs, runs laid past u64,
against their merge, one run more, the last fewer, the merge of the runs less their last,
each run changed); device, the repeated-copy test gains runs at their own bytes, and
a_named_plan_the_ram_let_go_of_before_the_recording_is_not_taken (eight copies' plans
push the named one out, a rebind encodes the encoder again: no reuse, the bytes right).

Verified at 96e281ba59 (msi, m3-max-32802): host_ram tests on lavapipe
106/106, clippy plain, m2v_gpu and m2v_cpu_icd 0, rustdoc 0; the named
plan let go of before recording is not taken (negative control fails).
Release medians (m3-max-32803, lavapipe, interleaved, 200 of 200 copies
by a kept plan): layer in 1 chunk 99.1/94.0 -> 59.7/58.1 us, over 128
chunks 248.9/282.6 -> 176.9/197.0 us.
2026-11-15 09:16:17 -08:00
Anees Iqbal 9dd5e78f60 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-15 09:11:16 -08:00
Anees Iqbal 5ba7afd9d4 RUNTIME 2360: Shader cache: no default directory makes a memory-only device, never a failed one
With no caller directory and no home (USERPROFILE on Windows, HOME elsewhere),
default_directory answered Err and CacheSetup::of turned it, and any failure to
open the default path, into Error::ShaderCache, so every device creation and
adoption failed. Metal never fails device creation over its shader cache, and
the default is the runtime's choice, not the caller's (owner rule 2).

- The Windows default is %LOCALAPPDATA%\metal2vulkan (the local application
  data folder, read from the environment; no new dependency). XDG_CACHE_HOME and
  USERPROFILE are no longer read there.
- default_directory takes its environment as a closure (CacheSetup::of_in), so
  a test feeds its own without touching the process's.
- Where the caller names no directory and the default does not exist or cannot
  be made or written, the device keeps its cache in memory alone: the Store has
  no directory, every lookup is absent, every write is refused with no
  filesystem call, the scans do nothing, and writers ask has_directory first so
  nothing is encoded for it (a translated function still is: its encoded length
  weighs it in the memo). The device says so once as it is made, as the existing
  degrade notice ShaderCacheEntryNotWritten naming why; each entry it does not
  write counts in write_failures. The driver's pipeline cache data is not read
  back, and the device checks' verdicts are not encoded.
- A directory the caller names that cannot be used is still Error::ShaderCache.
- Device::shader_cache_directory answers Option<&Path>: None for such a device.

Docs: the shader_cache module docs, ShaderCacheOptions::directory,
write_failures, Error::ShaderCache, the degradation's declaration and its
docs/API.md entry, the runtime README (Windows default, error table), HOWTO,
create.rs's list of environment variables. api_signatures re-blessed;
docs/REFUSALS.md regenerated (a refusal's site function renamed).

Tests: tests::shader_cache's default-directory and no-directory-store unit
tests (plain gate), and the lavapipe/GPU device test
shader_cache_no_directory: a device made with an empty environment and no
caller directory is made, has no directory, makes four render states with two
functions translated once, writes nothing, and its notice is heard once.

Verified (msi): m3-max-32796 clippy plain 0, 67/67 shader_cache and
degradation tests, api_signatures 0, clippy x86_64-pc-windows-gnullvm 0;
m3-max-32797 (lavapipe) clippy m2v_cpu_icd 0, 61/61 shader_cache and
in_place_check, including the no-directory device test.
2026-11-15 09:10:25 -08:00
Anees Iqbal 9ce951f521 store_out_device: the stencil store test keeps three queues live, so it takes the queue plan
Its three faulting passes each take a queue of their own, and the earlier
queues stay live to the test's end, past the runtime tests' default limit
of two (lavapipe, job m3-max-32737: the device's panic names the limit).
plan_device, as the resolve tests use.
2026-11-15 08:57:17 -08:00
Anees Iqbal d3702a9758 Device tests: a Stencil8 attachment stores, resolves and faults as Metal's
A Stencil8 texture on a device without S8_UINT is held in a combined
depth/stencil image; these tests run the shapes the consumer's tests died
at on Intel's UHD 630 under Windows, and a plain draw into such a target.

- store_out_device: a Stencil8 texture at the start of a placement no-copy
  heap of bit 24 stored at Store (descriptor's and encoder's) faults its
  command buffer; at DontCare and a late CustomSampleDepthStore it
  completes. A 4-sample Stencil8 attachment resolving into it at
  MultisampleResolve (descriptor's and encoder's) and
  StoreAndMultisampleResolve faults; attached unresolved it completes. The
  pages keep their bytes. Each prints the format its image is held in.
- stencil_target: a Stencil8 target cleared to 0x5a, drawn into over its
  left half with a Replace of reference 0xa5, and stored reads 0xa5 and
  0x5a by halves through a copy; a later pass that loads and stores it
  keeps every byte, so the hidden depth aspect's DONT_CARE disturbs no
  stencil byte. Prints the image's format.

Verified: compiled and run in the jobs named in the lane's report (the
UHD 630 under Windows and lavapipe).
2026-11-15 08:57:17 -08:00
Anees Iqbal c119a60d91 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-15 08:47:00 -08:00
Anees Iqbal 4781b54e6e RUNTIME 2359: image_plan: a depth-only or stencil-only texture held combined is an attachment of its image
A Stencil8 texture on a device without S8_UINT (Intel's UHD 630 under its
Windows driver 101.2145, and the roadmap-2022, vk12-floor and
lunarg-desktop-baseline-2023 profiles) is held in D32_SFLOAT_S8_UINT or
D24_UNORM_S8_UINT (FormatEmulation::StencilInCombined), which the format
table admits for DepthStencilAttachment and documents as exact. plan_held
kept the attachment mapping only where its format was the direct one
(S8_UINT), so the image took no DEPTH_STENCIL_ATTACHMENT usage, RenderTarget
went unavailable, and the render pass refused the texture as needing
D32_SFLOAT_S8_UINT as a depth/stencil attachment, which the device has.
The consumer's store and resolve of a Stencil8 attachment died there.

The attachment filter now also admits the combined-aspect emulations
(DepthInCombined, StencilInCombined); the RenderTarget branch compares the
image's format with the attachment mapping's rather than the direct
format, and a memoryless plan takes the mapping's format. Colour formats
and direct depth/stencil formats plan as before (their attachment format
is the direct one). render_target.rs already renders such an attachment:
the hidden depth aspect is DONT_CARE both ways.

Test: tests/image_plan.rs
a_depth_or_stencil_format_held_combined_is_an_attachment_of_its_combined_image
feeds the planner the UHD 630's formats (no S8_UINT, no D16_UNORM_S8_UINT;
the combined formats render, sample and copy optimally, with no BLIT_DST
and no linear features) over the uhd770 profile: Stencil8 and Depth32Float
without D32_SFLOAT, 1 and 4 samples and memoryless, are D32_SFLOAT_S8_UINT
depth/stencil attachments with nothing unavailable.

Verified (m3-max-32701, msi): clippy plain 0; the runtime unit suite
1593 passed; with image_plan.rs restored to its parent, the new test
fails (Stencil8 planned D32_SFLOAT_S8_UINT with TRANSFER_SRC|TRANSFER_DST
only, RenderTarget unavailable).
2026-11-15 08:46:20 -08:00
Anees Iqbal 771dd124e8 tests: the replay modules' extended products are all 32-bit
the_replay_modules_test_overflow_by_a_products_high_word counted every
OpUMulExtended (8 in the flat dispatch, 11 in the preprocess). Since
the builder makes each 64-bit extended product from four 32-bit ones,
the five u64 products count four each: 23 and 26, every one 32-bit.
The test now counts them by width and wants no 64-bit form, so a
64-bit OpUMulExtended coming back into either module fails it.

Found red by the msi run of the metal2vulkan suite at 71ec267314
(job m3-max-32642: 3617 passed, this one failed with 26 where it
wanted 11 on the preprocess). Verified by the follow-up job named in
the report.
2026-11-15 08:44:50 -08:00
Anees Iqbal 29d0f9263e fresh_pages: a cleared long buffer's cleared bytes are its 16 KiB allocation
Step 2 (a1175662e7) gives a runtime buffer of 16 KiB or more Metal's allocation,
its length rounded up to 16 KiB, and the host clears all of it so that a texture
over the buffer reads zero past the length. Two fresh_pages expectations still
counted the length rounded to 16: the recycled buffer in
a_long_buffer_made_right_after_a_filled_one_reads_zero (red on lavapipe, partition
2: 33570816 cleared, 33558544 expected) and the cleared class in
a_long_new_buffer_reads_zero_with_nothing_written (the RADV leg, where no class
takes fresh pages). Both now expect the length rounded up to METAL_PAGE.

Test-only: the runtime-sources pin skips tests, so it is unchanged.
2026-11-15 08:42:56 -08:00
Anees Iqbal 1ba1330549 SPIR-V builder: a 64-bit extended product from four 32-bit ones
Every 64-bit OpUMulExtended and OpSMulExtended the builder would emit
is now built from four 32-bit OpUMulExtended of the operands' halves,
summed in 64-bit adds and shifts; signed, the high word subtracts
each operand where the other is negative. The struct result is the
same, so every caller (mul_hi, the flat indirect-dispatch derivation's
checked multiply, the replay preprocess) keeps its shape.

Why: Intel's Windows driver 101.2145 on the UHD Graphics 630 answers
garbage high words for both 64-bit forms, different from run to run,
while its 32-bit forms and its 64-bit UDiv and UMod are exact
(measured by the runtime's host_step_reads device test in job
m3-max-32600). The flat indirect-dispatch derivation's overflow check
read those garbage high words as overflow, zeroed the command and
reported ReplayFaults::GROUP_COUNT, so indirect dispatches and ICB
executions ran nothing on that device. The leaf is unconditional:
both forms are exact everywhere, and a per-driver key would leave
any missed construction site broken.

SEMANTICS_VERSION 2123 -> 2124: modules with a 64-bit mul_hi or a
flat dispatch derivation change their words.

Verified: the CPU interpreter test
sixty_four_bit_extended_products_are_exact_from_halves (both signs,
scalar and two-lane vectors, 121 operand pairs including 0, 1, -1,
i64::MIN, i64::MAX and u64::MAX, against i128/u128 products, and only
four 32-bit MulExtended in the module) is dispatched with this
commit; the device run on the mini follows.
2026-11-15 08:31:57 -08:00
Anees Iqbal 509a9c4c4e tests: a kernel's 64-bit multiply (low word) beside its mul_hi forms
The wide-math device test also stores `mul i64 x, y` for large
operands, to show whether the 64-bit OpIMul is exact on the device
whose 64-bit OpUMulExtended and OpSMulExtended high words are wrong.
Not yet run; the next mini run measures it.
2026-11-15 08:31:57 -08:00
Anees Iqbal 3500934fa6 tests: signed 64-bit and 32-bit mul_hi beside the unsigned 64-bit one
On the UHD 630 (m3-max-32592) the unsigned 64-bit mul_hi answers garbage high
words while 64-bit division and remainder are exact, and the flat dispatch
reports ReplayFaults::GROUP_COUNT. The fix's encoding depends on which widths
and signs the driver multiplies right; this measures them.

Verified: m3-max-32592 (UHD 630).
2026-11-15 08:31:57 -08:00