Commit Graph
4242 Commits
Author SHA1 Message Date
Anees Iqbal ef7ffb1097 Test: lone_fetch over host pages, as a shared surface's texture lies
A texture over host pages a no-copy buffer imports, rendered by a fetching pass, renders on the M3
through a scratch (no storage form for a texture over bytes); its result must reach the pages before
the command buffer's completion, when another process may sample the surface. Four legs: the lone
passes over tight RGBA16Float rows, over rows 64 bytes apart (a shadow), over BGRA8Unorm, and the
accumulation's layers; the CPU reads the pages after completion. The counts now print inline
instances, shadowed textures and shadow copies.

Not yet run.
2026-11-11 22:35:49 -08:00
Anees Iqbal 99b3c23be2 Test: lone_fetch's instance counts are u32, as draw_primitives takes them
Fixes the build of f51d726f04 (E0308 at the draw). Verified by the next build.
2026-11-11 22:35:49 -08:00
Anees Iqbal ebdd368289 Test: lone_fetch's overlapping layers of one fetching draw
One draw lays 12 copies of a rectangle over the target, each fragment fetching the second color
and halving its red through con_fetch_coverage, so the first color holds 2^-12 where the interlock
orders the overlapping fragments of the draw. The runtime splits consecutive interlocked draws on
MoltenVK, whose draws race under other processes' load; the fragments of one draw it cannot split.

Not yet run.
2026-11-11 22:35:48 -08:00
Anees Iqbal 77f8eb20c7 Test: passes of one color whose fetching draws render it alone
A window server's distance and color filters render a pass of one color, no depth or stencil,
whose fetching draw leaves its subpass no attachment at all where the device fetches through the
pixel interlock; where a draw that does not fetch comes first, the pass runs as two instances, and
on the M3 the color renders through a scratch. lone_fetch renders 24 new targets a round, three
rounds, RG16Float and BGRA8Unorm: a cleared pass with a flag, a loaded pass with the flag and a
fetching halving, a loaded pass of the halving alone, each pixel then a quarter of the flag or the
clear. A third leg: a bitmap's pass whose one draw fetches a cleared, unstored second color and
writes nothing to it.

Not yet run.
2026-11-11 22:35:48 -08:00
Anees Iqbal 1b421bcef9 Test: icon_levels with a fetch in level 0's pass, its storage form at its commit or a later one
The consumer's window-server pyramids take storage forms on the M3 (about one
per two pyramids: storage_forms_taken rose with the level passes in every
window of its boot). Level 0's pass now may fetch its attachment after the
fill (fetch_ordered halving a fill drawn at twice its value), which on the M3
renders through a scratch and notes the icon for its storage form; the icons'
command buffer commits alone, or while another is uncommitted, whose later
commit the switch then rides. storage_forms_taken is printed with the copy
counts.

Verified: the next job runs it.
2026-11-11 22:35:48 -08:00
Anees Iqbal e1db1bd0a3 Test: icon_levels reads each sampled target at its own side
The read-back of the targets the icon was sampled into copied level 0's side
from targets of levels 1 and 2's sides, which the blit refused (lavapipe,
m3-max-18573: both icon_levels tests panicked at the copy's unwrap).

Verified: the next job runs it.
2026-11-11 22:35:48 -08:00
Anees Iqbal 25c3236799 Test: an icon's levels drawn from one another, and a composite of icons and fetches
Two device tests of the shapes a window server's dock rendering takes on an
Apple GPU guest, whose icons on MoltenVK lose their fill:

- tests/icon_levels.rs: a Private RGBA16Float render target of three levels,
  each level in a pass of its own that clears and stores it, all in one command
  buffer; level 0's pass draws the fill, each later level's pass samples the
  texture itself, bound whole: through the texture's copy (tob_sample, whose
  level of detail the runtime cannot bound below the attached level) or in
  place (alv_implicit clamped to level 0, alv_level1). A later command buffer
  samples the icon into targets of each level's size and reads every level
  back; every texel must be the fill. Icons are made and released in rounds.
- tests/fetch_composite.rs: a composite pass that samples an icon and fetches
  its own target in a raster order group, over a Private target and over a
  texture over a Shared buffer's bytes; every pixel must be its draws' answer
  in draw order.

Verified: see the report's job ids (M3 and lavapipe).
2026-11-11 22:35:48 -08:00
Anees Iqbal 0a3e113528 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-11 22:29:54 -08:00
Anees Iqbal ce7f381870 RUNTIME_VERSION 2085: a standing shadow's first copy-in after an earlier pass of its command buffer wrote the texture is recorded inline
The commits before this one.
1. 2078 let a tracked Private image's shadow stand across command buffers. A command buffer's
   first copy-in of such a shadow was handed to its batch's submission (gated as Standing) where
   no command of its own encoder had written the texture yet. Where an earlier encoder of the same
   command buffer had written it, the submission always copied every texel anyway, but the copy
   was already a deferred segment: it got its own VkCommandBuffer, the encoder went on in a
   continuation, and the batch split. The encoder now asks the submission's question as it
   records the copy (State::ended_encoders_write_any, over the summaries stands() reads) and
   records it inline there, still counted Unskipped::CommandBuffer. An encoder encoded again at a
   rebind keeps the submission path.
2. Degradation::HostDeallocatorDelayed's announced cost names the wait 2083 added (every buffer
   bound inside the import goes), as API.md's catalogue entry does
   (tests::degradation_catalogue failed on every device in the pin 44 round).
3. The three replay cases' records (pass-start-barrier-private-read, -sample, -draw-barrier-read)
   gain only the shadow_texels_* counts 2078 began counting for Private images (308, or 1024).
   No whole-set write.

Verified (potluck jobs, on the branch): the three cases are within bounds just before 2078
(m3-max-19075, e51608975b). Lavapipe shadow suites 27/27 at ce1c565bf3, with an in-job negative
control (encoder.rs and command_buffer/mod.rs reverted): 5 -> 8 VkCommandBuffers begun, 1 -> 2
submit infos, 1 copy-in against a standing (19159). M3: image_standing, shadow_standing_device and
attached_read_standing 7/7; whole-set replay with command_buffers_*, submit_infos and
shadow_copies_in_against_standing back within the existing bounds; 8-run contrast old vs fix
binary equal but for the shadow_texels_* relabel (19169). Lavapipe at d13646eea5: 28/28 runtime
tests incl. all degradation_catalogue tests; conformance crate 1043/1043 (19198). Lint at
ce1c565bf3 (19159).
Not run: lint at the tip (cost string, docs and records only); the M3 replay at the tip (19199);
RADV.
2026-11-11 22:28:50 -08:00
Anees Iqbal a65bd229fd Re-bless the three pass-start private cases' shadow_texels counts, a relabelling since 2078
RUNTIME_VERSION 2078 counts the first copy-in of a tracked Private image's shadow by why it moved
its texels (shadow_texels_first_copied_in_private_images, shadow_texels_unskipped_* and
shadow_texels_never_stood_*). These cases made that copy before 2078 too, with nothing counting it,
so their records bound these counts at 0. Only these counts are re-blessed. The command buffers,
submit infos and copies against a standing that 2078 added are gone with the previous commit, and
they stay within the old bounds, unchanged here.

Written by `conformance cost --runs 8 --alone --write` of the three cases on the M3 (m3-max-19169,
at ce1c565bf3). It added the same four shadow_texels_* counts to each record's bounds and composed
counts, and changed nothing else. No whole-set write.

Contrast, the same job: `cost --runs 8 --show` of the three cases, in order and alone, with a binary
built at e51608975b (before 2078) and one built at ce1c565bf3. Every count is equal, except:
- these four shadow_texels_* counts (0 to 308, or 1024 for -sample);
- scheduler_passes, 1 to 0 in five of the six readings;
- fences_made alone, 1 to 2 for -read and -sample.
Both of those were already inside the committed bounds: the whole-set replay at ce1c565bf3 lists
only the four shadow_texels_* counts per case as over.
2026-11-11 22:28:41 -08:00
Anees Iqbal 3b986605e3 The host-deallocator-delayed kind announces the wait for a buffer bound inside the import
RUNTIME_VERSION 2083 made a buffer bound inside its pages' import hold the import, so a no-copy
buffer's deallocator given no keep-alive waits for that buffer to go, and docs/API.md's catalogue
entry said so in its cost. The kind's announced cost (Degradation::HostDeallocatorDelayed's) did
not, and tests::degradation_catalogue::a_runtime_kind_s_entry_states_the_cost_it_announces failed
on every device that runs it (pin 44: Iris, m3-max-19132, and the 780M).

The announced cost now carries the same clause, worded 'every buffer bound inside their import
goes' in both, and the kind's own docs list the case beside the others it waits for.

Verified: the degradation_catalogue tests on lavapipe (see the landing report).
2026-11-11 22:28:41 -08:00
Anees Iqbal 9bf361c113 A copy in after an earlier encoder of its command buffer wrote the truth is the encoder's
A command buffer's first copy in of a shadow that may stand across command buffers went to its
batch's submission (a gated copy, `CopyGate::Standing`) whenever no command of its own encoder
had written what it reads. Where an earlier encoder of the same command buffer had, the
submission's `stands` always found that write and moved every texel anyway, but the copy was
already a deferred segment: the submission recorded it in a VkCommandBuffer of its own and the
encoder went on in a continuation, one more batch-work and one more continuation command
buffer, and one more VkSubmitInfo where the batch split there. Since RUNTIME_VERSION 2078 lets
tracked Private images stand, a pass that reads its own render target after an earlier pass of
the command buffer drew into it takes that path: the conformance cost replay's
pass-start-barrier-private-read and -sample rose from 7 to 10 command buffers begun and from 1
to 2 submit infos on the M3 (replay m3-max-18970 at 010958b7f8; m3-max-19075 at e51608975b,
just before 2078, is within bounds for all three).

The encoder now asks, as it records the copy, what the submission would: whether a command of
an encoder of the command buffer that ended before it wrote the standing's keys
(`State::ended_encoders_write_any`, the same summaries `stands` reads). Where one did, the copy
is recorded in the encoder, ungated, counted `Unskipped::CommandBuffer` as before. An encoder
encoded again at a rebind (`replay.rs`) keeps the old path: the encoders after it are among
those ended then, so its batch's submission decides.

Tests: image_standing's new
a_copy_in_after_an_earlier_pass_of_its_command_buffer_wrote_the_texture_is_decided_there (two
passes in one command buffer, the second an attached read over every pixel: no copy in against
a standing, every texel moved for the command buffer, Metal's reds), and
shadow_standing_device's own-command-buffer leg now also asserts no copy in against a standing.
2026-11-11 22:28:41 -08:00
Anees Iqbal bf442ceb9e 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-11 21:52:34 -08:00
Anees Iqbal 06e0e58543 RUNTIME_VERSION 2084: queues spread over empty VkQueues and an unshared queue gets its own; a device refused for resources comes up on the least queue plan
The commits before this one.
1. Placement: under the default sharing check's answer of no idling (reims's host-timed mode)
   every queue took the round robin's next VkQueue (made % 14) and an unshared queue (a
   compositor's) got no empty one. Queues now take a VkQueue no command queue holds where one
   is free, else the least held; an unshared queue takes an empty one. Counted:
   command_queues_live_most.
2. Least plan: NVIDIA refuses vkCreateDevice when its channels run out with
   VK_ERROR_INITIALIZATION_FAILED or VK_ERROR_OUT_OF_HOST_MEMORY (2080, 620.70.06, measured), and
   the retry covered only INITIALIZATION_FAILED and OUT_OF_DEVICE_MEMORY. It now retries the least
   plan (3 queues, announced metal2vulkan-degrade-least-queue-plan) on those and on
   TOO_MANY_OBJECTS, and refuses (DeviceRefused, naming both attempts) only when that fails too.
3. Tests: nextest profile few-channels (3 threads) for ad-hoc RTX 2080 runs, which hold 10 devices
   of 18 queues (VALIDATION.md); the held-work test's start-based check runs only where the GPU
   writes timestamps.

Numbers (walk-shaped churn, 340 queues in 60 s, compositor unshared): RTX 3090 host-timed
compositor frames over 16 ms 44 -> 0, p99 20.0 -> 3.8 ms, waits behind other queues 556 -> 0
(m3-max-18783); M3 Max frames over 16 ms 188 -> 2, p99 51 -> 10 ms (18785). Channel cost per
queue: 3090 25.2 ms create, 3.7 MiB; 61 full-plan devices per GPU (2080: 10).

Verified (on the branch): clippy all-features, no-feature, m2v_gpu and rustdoc at 6f16b2e0c7
(19007); pure tests 20/20 under few-channels (18928); M3 queue device tests 45/45 (18867);
2080 fill run: the device comes up on the least plan at every refusal code (18967).
Not yet in: the exclusive 3090 rerun of
a_compositor_beside_a_long_queue_keeps_its_latency_once_that_queue_went_long (19010; it failed
its p99 < 5 ms on a shared busy card), 3090 exhaust codes (18925); lavapipe device tests.
2026-11-11 21:51:37 -08:00
Anees Iqbal d3a8fd86ee Doc: NVIDIA's driver refuses a device of its plan with host memory or initialization failed where channels run out
Measured on an RTX 2080 (NVIDIA 620.70.06, job m3-max-18967, the
probe's --fills): beside 60 devices of 3 VkQueues the runtime's device
of 18 was refused with VK_ERROR_OUT_OF_HOST_MEMORY, beside 62 and 64
with VK_ERROR_INITIALIZATION_FAILED, and each time it was made with
its least plan's 3 and announced it (the probe built at bdfc5047d2,
with 86def80883's retry). Before 86def80883 the first answer was
Error::OutOfMemory(Host): the device test failure on the 2080 under
parallel test load (job m3-max-18589).
2026-11-11 21:51:23 -08:00
Anees Iqbal 915222c8e5 Example queue_plan_cost: a fill phase, the runtime's device made where the plan's VkQueues just fit
--fills N,M,... holds that many devices of the least plan's shape, then
makes the runtime's device beside them: what device making answers
where the plan's vkCreateDevice still fits but little more does. To
find which step of device making answered OutOfMemory(Host) on an RTX
2080 under parallel test load, where a GPU filled to the refusal gives
ERROR_INITIALIZATION_FAILED and the runtime's least plan (job
m3-max-18924).
2026-11-11 21:51:23 -08:00
Anees Iqbal a094c7f72a Tests: a nextest profile that runs a GPU of few channels three device tests at a time
On NVIDIA's driver each VkQueue is a channel and a runtime device of
the queue plan takes 18. An RTX 2080 held 10 such devices at once
(job m3-max-18774), so a 16-thread host's default 16 test processes
ask it for 288 VkQueues and the driver refuses the rest; the 3090 and
the 5080 Laptop GPU held 61 (jobs m3-max-18776, m3-max-18775).
--profile few-channels runs three at a time, as the consumer's own
profile does. docs/VALIDATION.md says when to pass it.
2026-11-11 21:51:22 -08:00
Anees Iqbal 3aa410e2ab A device refused for want of resources takes its least plan whatever the code: too many objects and host memory too
vkCreateDevice's answer where the device-specific resources a logical
device needs run out is VK_ERROR_TOO_MANY_OBJECTS (the Vulkan spec,
vkCreateDevice), and a driver short of host memory for the plan's
VkQueues may make a device of fewer: both now take the least plan, as
VK_ERROR_INITIALIZATION_FAILED (NVIDIA's channels) and
VK_ERROR_OUT_OF_DEVICE_MEMORY did. A device refused with both plans
is refused naming each attempt, as before.

Asked for by a device test on an RTX 2080 under parallel test load
(job m3-max-18589) that got OutOfMemory(Host) from
Device::system_default_with, where the least plan's three queues would
have fit: the 2080 held 10 devices of the plan's 18 VkQueues at once,
and 68 of the least plan's 3 (job m3-max-18774).

The pure test of made_within_resources takes each of the four codes.
2026-11-11 21:51:22 -08:00
Anees Iqbal 65c06e2e4c Example queue_plan_cost: each refusal's VkResult, and the runtime's device made while the GPU is full
The exhaust phase now names the VkResult each refusing process got, and
while the processes hold their devices makes one more process's runtime
device of the plan: whether it came up (on its least plan, announced) or
what it answered. --exhaust-only skips the make and hold phases. Asked
for by a device test that got OutOfMemory(Host) from
Device::system_default_with on an RTX 2080 under parallel test load.
2026-11-11 21:51:22 -08:00
Anees Iqbal 0a2cae7b82 Test: the held-work test's Off leg holds on a device that answers GPU times from the host
Under UnsharedIsolationPolicy::Off the unshared queue's command buffer
waits behind all three long ones on the shared VkQueue. The test said
so by its GPU start, which on a device answering GPU times from the
host (MoltenVK 1.4.1 on Apple's GPUs) is its kernel end: on the M3 Max
it read 4.7-75.9 ms against the third's 52.4-75.9 ms, a failure at the
base (8e1d5f42b0, job m3-max-18834) and at the placement fix (job
m3-max-18825). It now says it by the end on every device, and by the
start where the device writes timestamps.
2026-11-11 21:51:22 -08:00
Anees Iqbal b61de84998 Test: the placement churn tests pass clippy
The pure churn simulation counted its makes beside the loop's own index
(explicit_counter_loop); the device churn test looked for an empty
VkQueue with iter().any (manual_contains). Both said once now.
Lint job m3-max-18771 named the two.
2026-11-11 21:51:22 -08:00
Anees Iqbal 3cfcbe6304 FAST-PATHS: reflow the one-graphics-queue gap's new count line 2026-11-11 21:51:22 -08:00
Anees Iqbal 37db40177b Command queues take the VkQueue the fewest live queues hold; unshared ones an empty one under every verdict
A new command queue took the round robin's VkQueue by a creation counter (made modulo the
round robin), which never reuses a slot: a guest makes about 340 queues past NVIDIA's 14 in a
250 s walk, so live queues landed together while other VkQueues stood empty. An unshared
queue (a compositor's) got a VkQueue of its own only where the device shares (an Adaptive
verdict of Idles); under PerQueue, on MoltenVK, and on a device that answers GPU times from
the host (reims-vgpu's, Unchecked) it took the round robin's next, so app queues made later
landed on it every 14th make. Guest walks (reims's logs, read in place): unshared command
buffers behind another queue's batch 1062 in one 3090 walk (39 over 16 ms, longest 33.8 ms),
5 in the next on the same build; 511 on a 2080; 2048 on the M3 (437 over 16 ms).

Now, under every policy and verdict, a command queue takes, as it is made, the round robin's
VkQueue the fewest live command queues hold of those no unshared queue holds, the first in
turn from the counter among equals (queue_share.rs fewest_held, Device::take_round_robin):
one pass over the round robin's VkQueues' counts, atomics alone, at creation only; nothing
scans the command queues. Its claim is made before it reads the unshared count, as an
unshared queue's is made before it reads the live count, both sequentially consistent, so the
two never both succeed. An unshared queue takes one no command queue holds where one is free
(the existing unshared_order, now ungated), else the one the fewest hold.

Counts: WorkCounts::command_queues_live_most (the most command queues the program held at
once: what a walk needs to size the plan by) and unshared_queues_sharing_a_vk_queue (an
unshared queue that found no VkQueue free of other queues). queues_sharing_a_vk_queue keeps
its meaning, the queues made past the round robin's VkQueues; unshared queues now count among
them under every verdict, as they did where the device did not share. QueueLimits notes keep
theirs, an unshared queue's included.

Tests: tests::queue_share's pure churn shaped like a walk (354 made over 14 VkQueues, at most
12 live, an unshared one kept): no queue placed beside a live one while one stood empty and
the unshared one never shared, against a positive count by the old rule; device test
over_a_churn_queues_take_the_least_held_vk_queue_and_unshared_ones_an_empty_one under
Adaptive, PerQueue and untimed Adaptive. The helpers that share a VkQueue on purpose (beside,
the lane's queue_where) keep the queues they make until one lands there.

Docs: QueueSharingPolicy, new_command_queue_unshared, new_command_queue_for_presenting,
queue.rs and queue_share.rs module docs, docs/API.md, the runtime README, FAST-PATHS's queue
sharing row and its known gaps.

Not yet built or run: potluck jobs follow.
2026-11-11 21:51:22 -08:00
Anees Iqbal fa57e96133 Example queue_share: a churn mode, command queues made and dropped as a guest's processes make them
A compositor (unshared with --unshared) committing a draw every 16 ms beside three kept
queues and a churn of queues each made with one long command buffer and dropped 1 to 8
ticks later; --untimed answers GPU times from the host, as a consumer that does so does
not share VkQueues. Prints the compositor's latencies and the device's waits behind
other queues, the measure of the placement change that follows.

Not yet run.
2026-11-11 21:51:22 -08:00
Anees Iqbal 7f762845c3 Example queue_plan_cost: options set field by field (DeviceOptions is non-exhaustive) 2026-11-11 21:51:21 -08:00
Anees Iqbal 07d9391c99 Example: what a device's VkQueues cost the driver to make, drop and hold
A probe for the NVIDIA queue plan's cost: Vulkan devices of 1 to 18 queues made and
destroyed in turn (vkCreateDevice and vkDestroyDevice wall times, slope per queue), held
four at once with nvidia-smi's framebuffer and BAR1 use, the runtime's own device under
each queue limit, and an opt-in exhaust across processes (how many devices of the plan's
and the least plan's shape the GPU holds at once).

Not yet run; numbers follow from potluck jobs.
2026-11-11 21:51:21 -08:00
Anees Iqbal 75eb3bfc97 RUNTIME_VERSION 2083: a buffer bound inside an import holds its keep-alive, counted and announced; memory_frees_paced under the race rule
The commits before this one. Since 2073 a second no-copy buffer over a live import's pages is
bound inside that import instead of importing the pages again (VK_EXT_external_memory_host leaves
a second import undefined). The inside buffer keeps the import, so the import keeps the first
buffer's keep-alive until both are released. With a keep-alive the deallocator still runs at
release, as Metal's does; given none, it is delayed until the inside buffer goes, announced as
host-deallocator-delayed (now naming the inside buffer) and counted
(WorkCounts::host_releases_held_inside; a HostImport counts the buffers bound inside it). API.md
records it as an accepted difference: later than Metal, never early. The keep-alive and
dma_buf_imports lane tests that expected two imports are rewritten (the half-range buffer asks
about no mapping: inside the import or a copy). memory_frees_paced, which lands in a different
replay case each run (other cases' quiet-period frees), is reported under the race rule beside
memory_frees_posted.

Verified (potluck jobs, on the branch at 6e51633beb): M3 4/4 keep-alive tests with the counts at
each step (m3-max-18978); 780M 5/5 (18988); lavapipe 5/5 and 229/229 touched suites (18973); M3
replay: memory_frees_paced over no bound (18992); whole-set contrast d0f800ddd0 (18926) vs base
(18864): the frees did not increase. Lint (fmt, clippy all-features, m2v_gpu, m2v_cpu_icd, rustdoc):
19002. Bisect: 8db2f6f5c8 and 269d7066c4 pass, 4f3bc2e7a3 (2073) fails.
Not run: NVIDIA, XTX, full suites.
2026-11-11 21:51:21 -08:00
Anees Iqbal f2cf35406d Tests: a buffer over half a live dma-buf import's bytes asks about no mapping, inside it or a copy
runtime_lane::dma_buf_imports::a_buffer_that_lies_in_a_live_import_asks_about_no_mapping expected
a buffer over the first half of a live buffer's bytes to make its own import and ask the kernel
about its 32 mappings. Since RV 2073 (one page, one import) a page a live import holds is never
imported again: the half is bound inside the live import, or, where that import's memory is the
first buffer's alone (its own dma-bufs, dedicated to its VkBuffer), a copy of its pages
(copied_over_live_imports). Neither asks about a mapping: the live import's making asked about
them all, and the pages stay writable while imported. The test failed at 945 on the RTX 5080
(m3-max-18801) and the RX 7900 XTX (m3-max-18892): asked 0 where it expected 32, no error.

It now asserts no mapping asked, the half inside the import or a copy (one of the two counts),
no import made over the live one's pages (imports_inside_live unchanged), the half's source
uncalled, and the GPU reading the CPU's bytes through the half.
2026-11-11 21:51:08 -08:00
Anees Iqbal b649078d10 Docs: a buffer bound inside a no-copy buffer's import holds its keep-alive, or its deallocator
The release order RV 2073 brought, in the docs a consumer reads. A no-copy buffer made over part
of a live one's bytes, or over the same bytes as memory of another class, is bound inside the
live one's import (one live import of a page: VK_EXT_external_memory_host leaves a host allocation
imported twice into one device undefined) and holds it, so the live one's keep-alive is dropped
only once both are released and the import is freed. With a keep-alive its deallocator still runs
at its release, as Metal's; given none, the deallocator waits for the free, announced as
host-deallocator-delayed.

- API.md: the host-deallocator-delayed entry names the cause and its cost; section 10 (Heaps and
  memory) records the keep-alive's later drop as an accepted difference, with
  WorkCounts::host_releases_held_inside.
- HOWTO, "Unmapping host memory": the order for a buffer over part of another's bytes.
- The runtime README's no-copy paragraph and KeepAlive's doc name it.
2026-11-11 21:51:08 -08:00
Anees Iqbal 1badfbfffc Keep-alives: a buffer bound inside an import holds it; count those releases, test them on every device
Since RV 2073 (cfd7bc829e, one page one import) a no-copy buffer made over part of a live one's
bytes, or over the same bytes as memory of another class, is bound inside the live one's import
(Device::bind_in_import, Placement::in_import holding the import) instead of importing the pages
a second time. It holds that import until it goes, so the first buffer's release is outlived: its
keep-alive is kept by the import, or, given none, its deallocator waits for the free. That is the
order the single import needs (it maps the pages the first buffer's keep-alive keeps), but the two
lane tests still expected the second buffer to be an import of its own: on the M3, where the
texture's image is a shadow, each waited 60 s for a keep-alive that goes only once the second
buffer goes (m3-max-18537, bisected: 269d7066c4 passes in m3-max-18841, 4f3bc2e7a3 fails in
m3-max-18861).

- HostImport counts the buffers bound inside it (Inside, one per buffer however many clones of its
  placement share it). A release that keeps a keep-alive, or delays a deallocator, while one lives
  is counted: WorkCounts::host_releases_held_inside (new). The delayed deallocator's announcement
  names that cause instead of a texture's command buffer.
- keep_alives.rs: a_kept_keep_alive_covers_later_buffers_over_its_bytes and
  a_narrower_live_buffer_covers_no_wider_released_one branch on whether the second buffer lies
  inside (object_churn.buffers_bound_in_import), watch the kept keep-alive stay, and show both
  keep-alives go once the second buffer is released, printing the counts at each step;
  a_buffer_inside_an_import_holds_a_deallocator_given_no_keep_alive (new) shows the deallocator
  given no keep-alive runs after the inside buffer's release, counted and announced once.
- host_ab prints the new count; api_signatures blessed for the field.

(The commit before this one names its test wrongly: the race rule's rows are held by
a_count_that_says_which_thread_arrived_first_is_never_gated.)
2026-11-11 21:51:08 -08:00
Anees Iqbal 63a27d0025 Cost: memory_frees_paced is reported under the race rule, beside memory_frees_posted
RV 2071 added WorkCounts::memory_frees_paced, the frees of the runtime's own background threads
(the free thread, the residency thread, a guest RAM's threads) that waited after the free before
them. Every cost record bounded it at 0 (measured before it existed), and the whole-set replay at
43d2308170 on the M3 (m3-max-18632) put it at 1 on fresh-buffer-private and 2 on
fresh-texture-2d-rgba8unorm-shared.

Those frees are not the cases' work: run alone and as a pair, eight runs each, neither case counts
a free of any kind (m3-max-18854). The paced frees land in their window from the background
threads' timed frees (the quiet period's, which memory_frees_posted already reports, and the idle
windows'), and whether one waited depends on how soon it came after the one before. The tip's
whole-set measurement (m3-max-18574) moved it between runs of one case: depthstencil-depth-codes
0..2, read-write-tier-round-trip-uint 0..1. A re-bless of the two records would not hold, so the
count joins the race rule with its reason (PACED); racy_counts_are_reported holds it there.
2026-11-11 21:51:07 -08:00
Anees Iqbal 71874aefa2 Tests: the spares' burst test reads its counts once each command buffer is done, never polling
command_buffers_the_spares_hold_fall_back_after_a_burst_freed_on_the_free_thread took 32 s on
lavapipe: it polled the spares' count until a guessed condition held, up to 30 s each, and for
a command buffer of 2 encoders the guess (one encoder's count plus one) never held, the pool
holding 3 after both (2 primaries and its secondary, as after one encoder and its barrier's
command buffer). A broken fall-back would have waited out the 30 s of the last poll as well
before failing.

The polls had nothing to wait for: a command buffer's wait returns once its completion's
transition ran, the gate's hold going after it (Transition::run, command_buffer/gate.rs), its
pool's give-back and begin ahead included, and fills() then drains the frees that give-back
posted. So each count is final once fills() returned, and the test reads it there. held_once,
used by this test alone, goes. The assertions are unchanged: freed on the free thread alone,
the burst's count at least one encoder's plus half the burst, and after the load fell back at
most one encoder's plus two.
2026-11-11 21:51:07 -08:00
Anees Iqbal bc08cf1c54 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-11 21:50:32 -08:00
Anees Iqbal 87399f4100 RUNTIME_VERSION 2082: no guest RAM page is imported twice while a chunk's or an object's import is in flight, and a rebind's import is noted
The commits before this one.
1. In-flight claims. 2080's straddle copy and held-back chunk read only finished state, so an
   object made while a chunk's import was in flight, or a chunk imported while an object's own
   import was between its checks and its note, imported the same pages twice. Each RAM the
   device uses now keeps the claims of objects' own imports in flight (Device::claim_ram_pages,
   held through the import until it is noted). A chunk's import is marked in flight only under
   those claims and is held back where a claim meets its pages. Whichever starts first, the other
   never imports the same page; the loser is a copy (CopiedBecause::OverRamChunk).
2. Rebinds. A rebind's own import of its new pages was placed but never noted in the alias
   registry, so once its claim dropped a chunk could still be imported over the rebound buffer's
   pages. It is now noted with a hold (no key joined), and a rebind onto bytes a rebound buffer's
   import holds lies in that import instead of importing them a second time.

Tests (lavapipe, on the branch): the two in-flight tests, which hold a chunk's import or an
object's gate with test-only pauses, failed 3/3 before the fix (m3-max-18881) and pass 3/3 with
it. The rebind test's negative control fails (the chunk imported over the rebound buffer's
import; 18968, 19006). The host_ram, aliases, copied, rebind, dma_buf, residency and host_import
sets pass 260/260, and the whole lavapipe runtime suite passed but for two failures since fixed
on development (19006, 19034). host_import_counts' rebind test now asserts one import
(..._shared_over_bytes_it_holds). Lint (clippy plain, m2v_gpu, m2v_cpu_icd; rustdoc) clean.
Not yet in at landing: the suite rerun at the rebased tip (19047); no GPU device runs of this item.
2026-11-11 21:49:32 -08:00
Anees Iqbal 41b54edde6 Rebind: the noted import joins no key; a rebind onto a rebound buffer's bytes lies in its import
b5bfbaf377 noted a rebound buffer's own import with join, which gives the buffer the memory's
key: host_aliases.rs keeps the memory a rebound buffer takes unjoined ("Not joined"). It is now
noted with hold, as a heap's own import is, joining no key, and so is the live import a rebind's
new pages lie in (shared by bytes another buffer's note holds), so that the note stays while any
buffer lies in it.

With the import noted, a rebind onto bytes a rebound buffer's import holds lies in that import
(one page, one import) where it imported them a second time before.
host_import_counts::a_rebind_s_import_is_unlisted_until_a_command_buffer_uses_it_and_covered_
over_bytes_lain_over (m3-max-18968: [2, 1, 2] expected, the second rebind making no import)
asserted that second import; it is renamed ..._and_shared_over_bytes_it_holds and asserts one
import, none covered, unlisted until the first command buffer. host_aliases.rs's docs say the
bytes rebound onto are looked up and shared as those made over.
2026-11-11 21:49:23 -08:00
Anees Iqbal 711b74238b Rebind: an import of the new pages of the buffer's own is noted, as a making notes one
rebind_host_pages placed the new pages in the alias registry (aliases.place) but never noted
their import, so held_back could not see it: a guest RAM chunk holding some of a rebound
buffer's own imported pages was imported over them, the same pages imported twice
(a_rebind_s_own_import_holds_its_chunk_back_while_it_lives).

After the rebind leaves the memory it was made over, an import of the new pages of its own (not
a copy, not bound in a chunk or inside another import, not a read-only view) is noted as a
making notes one: join for a buffer, hold for a heap's own buffer. The rebind's claim of guest
RAM pages (Device::claim_ram_pages) now lasts until that note, so no chunk's import slips in
between the import and the note.
2026-11-11 21:49:23 -08:00
Anees Iqbal 79424a7169 Tests: a rebind's own import holds its chunk back while it lives
A buffer rebound onto two runs of a chunk not imported yet imports its new pages itself. While
that import lives, the next object over the chunk's other pages must not import the chunk (one
page, one import): it takes its own path, counted held back; once the rebound buffer went, the
next object imports the chunk and is bound there. rebind_host_pages places the new pages in the
alias registry (aliases.place) but never notes their import (join or hold), so held_back cannot
see it and the chunk is imported over them: this test is expected to fail here.
2026-11-11 21:49:23 -08:00
Anees Iqbal 88af28874e Host RAM: an object's own import claims its RAM pages until noted; chunks mark in flight under the claims
The straddle copy (f083e9c806) and the held-back chunk (c55501db1b) each read only finished
state: an object's check read made chunk imports alone (chunks_hold_any), and a chunk's check
read noted object imports alone (the alias registry). So an object made while a chunk's import
was in flight, or a chunk imported while an object's own import was between its checks and its
note, imported the same pages twice. Both tests of 1d77522508 showed it on lavapipe, 3 runs of
3 each (m3-max-18881): imports_inside_live 1.

Each RAM the device uses now keeps the claims of objects' own imports in flight. An object's
making and a rebind claim their window's RAM pages (Device::claim_ram_pages) where no chunk binds
them, and hold the claim through their import until it is noted: where a chunk's import, made or
in flight, holds some of the pages, nothing is claimed and the object is a copy
(CopiedBecause::OverRamChunk, as for a made one). A chunk's import is marked in flight only under
the RAM's claims (RamOnDevice::chunk takes them before the chunk's lock, as a claim does, and
looks at the chunk again), and is held back where a claim meets its pages (held_back), as where a
noted import does. Whichever starts first, the other never imports the same page.

Docs: host_ram.rs's one-import bullet; the OverRamChunk cause, copied_over_live_imports and
docs/API.md's copied-host-pages entry say made or in flight.
2026-11-11 21:49:22 -08:00
Anees Iqbal 2172b1e1bc Tests: no page imported twice while a chunk's or an object's import is in flight
Two deterministic tests, each holding one import in flight by a handshake rather than by timing:
- an object over two runs inside a chunk made while the chunk's import, marked in flight
  (Import::Making), is held by a test-only pause (RamSource::making_pause, called in
  RamOnDevice::chunk before the import is made);
- the reverse: the chunk imported by its first object while an object over two other runs of the
  chunk is held in its gate, after its checks and before its own import.
Each asserts imports_inside_live 0 and that the objects read the RAM's bytes. The chunk check
(chunks_hold_any) reads only made chunk imports, and held_back reads only noted imports, so at
this commit both are expected to fail: a page imported twice.
2026-11-11 21:49:22 -08:00
Anees Iqbal 938ec37659 Tests: a Private export after a dma-buf import is device-local only where the control's is
The export test asserted a device-local type for both exports on every device. On a Radeon 780M
(RADV, m3-max-18941) the control, a device that imported no dma-buf, already places a Private
exportable buffer in type 2 (HOST_VISIBLE | HOST_COHERENT), so the test failed there with the
import's export where the control's lies. It now asserts the control's flags and no overflow on
every device, and a device-local type where the control's is one (the RTX 3090, ANV).
2026-11-11 21:49:22 -08:00
Anees Iqbal 5f72e080c5 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-11 21:37:15 -08:00
Anees Iqbal cdbfec92d9 RUNTIME_VERSION 2081: the command-buffer spares keep their bound of 4096 under load
The commit before this one. The spares held 4097 command buffers against HELD = 4096 in a loaded
lavapipe runtime suite. CommandPool::past(keep) kept one secondary even where keep was 0, so a
pool given back while another pool trimmed to the bound was out with its frees waiting on a slow
free thread kept one past the bound. Spares::begin_ahead made a new primary in a pool holding none
with no bound check. Both now keep the bound: past() honours keep exactly, and a pool whose begin
ahead would make its primary goes out only where the spares and what is out stay within HELD. On
ANV below Xe-HP each spare command buffer holds a 64 KiB block of the binding-table pool, so the
bound is the product's.

Verified (potluck jobs, lavapipe, on the branch at 63a732359c): the forced interleaving test
a_pool_given_back_while_the_bound_is_out_freeing_keeps_none_past_it holds exactly 4096 before and
after a begin ahead; all 19 spares tests pass (m3-max-18938); full runtime suite 2228/2229 with all
spares tests passing (18945; the one failure was the exit_guard scan, fixed in 2e71b1818a).
Negative controls: the product as at the base fails the new test at 4097, 4098 after the begin
ahead (18990); with the first fix alone, 4097 after the begin ahead (18948). Lint (fmt, clippy
plain, m2v_gpu, m2v_cpu_icd, rustdoc): 18942.
Not run: GPU devices (ANV, RADV, NVIDIA, M3); release-mode timing (off the hot path).
2026-11-11 21:36:16 -08:00
Anees Iqbal 9958615931 Spares: a pool given back and a begin ahead keep the bound of HELD command buffers
The spares held 4,097 command buffers against their bound of 4,096 in a loaded lavapipe
runtime suite (tests::spares::device::command_buffers_alive_at_once_leave_the_spares_holding_at_most_held),
while the test passed alone. The product exceeded its bound; the test read nothing early.

Two places added command buffers past HELD:
- CommandPool::past(keep) always kept one secondary (and never freed the primary begun
  ahead), even where keep was 0. A pool given back while another pool trimmed to the bound
  was out of the spares, its frees waiting on the device's free thread (slow under load),
  computed keep = 0 and kept its secondary anyway: HELD + 1 once both came back. past()
  now frees, past keep, secondaries down to one, then primaries, then that secondary, then
  the primary begun ahead.
- Spares::begin_ahead made a new primary in a pool holding none and kept it again with no
  bound check. take_to_begin moves onto CommandPools: a pool whose begin makes its primary
  goes out only where the spares and what is out hold fewer than HELD, counted out with
  the primary it makes so a give-back meanwhile keeps the bound with it.

On ANV below Xe-HP each spare command buffer holds a 64 KiB block of the binding-table
pool, so the bound is the product's to keep.

Test: the free thread's test hold now also holds a spare pool's frees.
tests::spares::device::a_pool_given_back_while_the_bound_is_out_freeing_keeps_none_past_it
forces the interleaving: the free thread held, a command buffer of HELD + 64 blit
encoders (its pool trimmed to HELD, out freeing), then one of one encoder, then the hold
released; the spares must hold HELD, and still after a begin ahead in the newest pool
(which holds no primary). Unit tests cover past() and take_to_begin's room and count.
2026-11-11 21:36:06 -08:00
Anees Iqbal 36bfd48bba 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-11 21:24:48 -08:00
Anees Iqbal 2e71b1818a Test: the per-thread makings test, which starts a thread, lives in src/tests
exit_guard's threads_and_the_program_s_code_go_through_the_guard scans the runtime's sources for
thread starts outside exit_guard.rs, skipping src/tests/ alone. 73d706151e put
a_thread_s_makings_are_its_own_and_those_it_waited_for, which starts a thread, in churn_counts.rs's
own test module, so the scan failed on development ("threads started elsewhere:
churn_counts.rs: thread::spawn(..)"; lavapipe runtime suite, m3-max-18945). The test moves
unchanged to src/tests/churn_counts.rs; the items it uses are pub(crate). Test-only: no runtime
behaviour changes.
2026-11-11 21:24:09 -08:00
Anees Iqbal 7c1a963111 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-11 21:21:19 -08:00
Anees Iqbal ff9cf4c89e RUNTIME_VERSION 2080: dma-buf imports skip the type NVIDIA refuses, and no guest RAM page is imported twice
The commits before this one, two changes.

1. dma-buf memory type order (c267e94e74, refined in 85041aa633). NVIDIA's 620.70.06 lists a
   udmabuf of host pages as type 0 (system memory, no flag) and type 4 (host-visible, coherent,
   cached). It refuses every import as type 4, and once it has refused one, it refuses every
   later exportable device-local allocation for the device's life. So every Private exportable
   buffer after the first Shared import overflowed into system memory. The runtime never maps a
   dma-buf import, so system-memory types the host maps (HOST_VISIBLE without DEVICE_LOCAL) now
   go last, and device-local types keep their class's order. NVIDIA imports as type 0 without
   the refused attempt. ANV, RADV and lavapipe keep the class's order: the refinement exists
   because the first form moved ANV's Shared imports from its coherent cached type 2 to type 0.
2. One live import per guest RAM page (ea4bbb5fa3, 53501197a8). A guest RAM chunk is held back
   while a live import of an object's own holds its pages (host_ram_chunks_held_back). An object
   across two imported chunks, or over a live chunk's pages that no resolver routed, is a copy of
   its pages (CopiedBecause::OverRamChunk, announced as copied-host-pages), at its making and at
   a heap's rebind, never a second import (VK_EXT_external_memory_host issue 6 leaves that
   undefined). reims's walks on the 2080 and 3090 met it at boot: imports_inside_live = 1, a
   2 MiB heap across a 64 MiB chunk's end.

Verified (potluck jobs, on the branches):
- Export: lavapipe and Iris Xe ANV at be0cd3e124 (m3-max-18858): ANV's order equals the class
  order for every class and both sources, Shared/WriteCombined/Managed type 2 and Private type 0;
  lavapipe 27/27, the memory unit tests included. The 3090 export test failed before the change
  (type 0, one overflow each).
- RAM: the straddle and rebind negative controls (the chunk check disabled) fail as they should:
  the straddling heap gives one pointer import and imports_inside_live 1. With the fix, 141/141
  pass across the host_ram_device, aliases, copied, rebind, one_import and dma-buf sets on lavapipe
  (m3-max-18807). Lint (clippy plain, m2v_gpu, m2v_cpu_icd), rustdoc, api_signatures, api_surface
  and refusal_surface are clean (18863, 18901).
Not yet in at landing: the 3090 (18803, at d8944892df), XTX (18859) and 780M (18941) export runs
at be0cd3e124.
2026-11-11 21:20:20 -08:00
Anees Iqbal e93baf2b6b Tests: a rebind onto runs a live chunk holds is a copy, the gate not asked
The rebind onto two runs that the first chunk's live import held asked the gate and, admitted,
would have imported those pages a second time; since f083e9c806 it is a copy
(CopiedBecause::OverRamChunk), the gate unasked, and the lavapipe suite (m3-max-18714) failed
a_rebind_onto_several_runs_takes_the_gate_and_the_copy_where_it_refuses on 'the gate asked once'.
That test now rebinds onto runs of the second chunk, which no import holds, so it still covers
the gate's path; a new test covers the rebind onto a live chunk's runs: a copy, no import of its
own, none over a live import's pages, its bytes read and a fill through it written back.
2026-11-11 21:20:02 -08:00
Anees Iqbal ab316b4b1a Tests: the straddling heap's chunk-importing buffers lie away from its pages
The buffer that imported the second chunk lay inside the heap's pages (64 KiB into the chunk,
the heap reaching 1160 KiB into it), so the heap met that buffer's live import and was a copy
for it (CopiedFor::OverImport) with or without the chunk check: the lavapipe negative control
(m3-max-18714, the chunk check disabled) passed. The second chunk is now imported by a buffer at
96 MiB, past the heap's end, so only the chunk check makes the heap a copy.
2026-11-11 21:20:02 -08:00
Anees Iqbal 53501197a8 Host RAM: an object across two imported chunks is a copy, never a second import
A no-copy object whose pages cross the end of a guest RAM's chunk, the chunks on both sides
imported, is bound in neither: route_runs answers Runs, and the object took the gate's path
and imported its own pages, the same host addresses as the two live chunk imports
(VK_EXT_external_memory_host leaves that undefined; imports_inside_live counted it). The
consumer's walks hit it at boot on the 2080 and the 3090: a 2 MiB heap from 0x3f22000 into a
64 MiB chunk, 0xde000 bytes in the first chunk and 0x122000 in the next.

Such an object, and one over a live chunk's pages that no resolver routed, is now a copy of its
pages (CopiedBecause::OverRamChunk, counted in copied_over_live_imports, announced as
copied-host-pages, the gate not asked), at its making and at a heap's rebind. Chosen over:
- aligning chunk imports to objects: the chunks are imported ahead, before the objects over
  them exist, and objects lie anywhere;
- one import over both chunks: each chunk's import already binds objects when the straddling
  one comes, and swapping it would move every bound object;
- a sparse binding of both chunks' memory: heaps place resources at any offset, and not every
  device binds sparse buffers.
A copy costs one copy of the object's pages per commit, the rare edge object alone (one per
chunk end an object crosses).

Test: a_heap_across_two_imported_chunks_is_a_copy_and_imports_nothing (the consumer's shape:
both chunks imported by a buffer each, then a 2 MiB heap from 0xde000 before the first chunk's
end): one copy, no pointer import, imports_inside_live 0, the gate not asked; a buffer placed
across the chunks' end reads the RAM's bytes and a fill through it reaches them.
2026-11-11 21:20:02 -08:00