Commit Graph
181 Commits
Author SHA1 Message Date
Anees Iqbal 2163335121 RUNTIME 2393: a dma-buf source is asked once per texture after its standing refusal
A texture over a no-copy buffer's pages imported as dma-bufs tries its image in place with each
of its plans (wider usages first, its own last) and asks the caller's source for each plan's
pages. On RADV PHOENIX (Mesa 26.2.6) an RGBA8Unorm ShaderRead texture tries four, so a source
that refuses pages past udmabuf's list_limit was asked four times for the same pages
(texture_shadow_bench, m3-max-33878: source calls 4.00, refused 4.00 a texture); a consumer's
trace logged 1,620 such refusals over 765 textures, 367 ms in all.

The runtime cannot infer that one refusal answers a wider range: a source may accept exactly a
range it keeps a dma-buf of, or a wider one split otherwise. So the source marks it: a new public
DmaBufStandingRefusal (a runtime extension), returned as its io::Error, stands for every range
that holds the refused one for the rest of that texture's making. bind_dma_buf_image reads it into
DmaBufRefusal::Source { stands }, and in_place_image refuses each later plan whose request holds
such a range with that refusal, its unbound image released, the source unasked. Plain errors
behave as before: each plan is asked.

Documented in DmaBufSource's and DmaBufStandingRefusal's rustdoc, docs/HOWTO.md's dma-buf section
and the runtime README; api_signatures blessed (the type, new, Display, Error). REFUSALS.md
regenerated, unchanged.

Test: tests/dma_buf_standing_refusal.rs, on a device that imports no host pointer: a source of
plain refusals is asked once per plan, a standing one once, and one that refuses plainly then
gives the pages makes the texture in place on the second ask.

With it, a test-only release bench (ignored, --cfg m2v_gpu, Linux with /dev/udmabuf), tests/texture_shadow_bench.rs: an RGBA8Unorm ShaderRead texture over a no-copy buffer of a sealed memfd's pages, in place over one dma-buf against a shadow over more runs than one udmabuf lists, used by one or two dispatches that read or sample every texel and dropped, at four sizes, with a blit and a Private sample as references, printing host, GPU and CPU time, submission counts and the WorkCounts of each part. Its source marks its list_limit refusal as standing.

Verified: compiled in m3-max-33918 (msi, release lib-test archive under --cfg m2v_gpu). Running at landing: lavapipe (dma_buf*, no_pointer_import, host_residency, texel_rows, texture_placement) in 33918, clippy x3 next, and a PHOENIX run of the new test and the bench (the 4 -> 1 asks on RADV expected, unverified). The bench's numbers (PHOENIX m3-max-33878 um790, 33898 gem10) came from 2fe80f0a64 and d06fa76b74.
2026-11-15 15:31:24 -08:00
Anees Iqbal c2206c14b0 RUNTIME 2389: Device::import_shared_dma_buf imports a shared dma-buf ahead and keeps it while a handle lives
A runtime extension (Metal has none). A guest's buffers over pieces of one shared file of guest RAM
were each imported as their own dma-buf import and freed with the buffer, so a compute loop that
made and dropped no-copy buffers paid an import and a free per command buffer, and on RADV each
import maps its pages at once (the next submission's CS waits for the page-table job).
Device::import_shared_dma_buf(file, options) (unix) imports the whole dma-buf on the caller's
thread, or joins the device's live import of it, and returns a SharedDmaBufImport; while a handle
lives, the file's entry in the device's map keeps the import, so buffers over its pieces join it
instead of importing again, and it is freed once its last buffer, heap and handle have gone (one
kept import per file a live handle names, per generation). The class comes from `options` as a
no-copy buffer's (Private, Memoryless and undefined options refused, Invalid StorageMode); the
import takes the type a no-copy buffer of that class would get first, so pieces join it.
Refusals use the existing kinds (Unsupported HostMemory, OutOfMemory). A device's recovery lets go
of the lost generation's kept holds and seeds the new one's map, whose first buffer imports the
file again; nothing is imported on the recovering thread. A device without a dma-buf importer
keeps nothing (Debug: imported false). The handle imports whether or not the device's buffers over
those pages take the dma-buf route: on a device that takes the pages' pointer it is one listed
dma-buf a submission for nothing. WorkCounts::dma_buf_shared_imports_kept gauges the kept imports;
the handle's import counts in dma_buf_imports. Docs: rustdoc, dma_buf.rs Shared files, HOWTO
dma-buf section, the runtime README extensions and unix-only lists. REFUSALS.md: the StorageMode
site moved to host_class, which the no-copy call and this one share.

Public surface: Device::import_shared_dma_buf, SharedDmaBufImport (Send + Sync, consumer_auto_traits)
and WorkCounts::dma_buf_shared_imports_kept, blessed in api_signatures.tsv.

Verified: m3-max-33745 at the lane tip 856a1fabae: clippy plain, m2v_gpu, m2v_cpu_icd 0; rustdoc 0;
lavapipe runtime suite 2836 passed. Device tests (lavapipe): three buffers made and dropped in turn
take imports 1 / joined 3 with the handle, imports 3 / joined 0 without; a handle keeps a live
buffer's import; recovery imports nothing and the next buffer's import stays kept; Private refused.
Churn bench, PHOENIX (RADV 780M, release, interleaved, 450 command buffers an arm, a8f297bf11, the
same code but the count): no handle 1 import + 1 free a command buffer, call median 820-907 us, GPU
start median 3026-3037 us; handle kept 0 imports, 0 frees, 1 join, call median 25-69 us, GPU start
median 104-145 us.
2026-11-15 14:48:09 -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 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 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 8ba1fd7d67 RUNTIME 2358: Host RAM copies: a repeated copy takes the plan kept of it, where its buffer, the device's figures and its imports are the plan's
A copy by dispatches spent most of its encode on work that depends only on its runs, its
buffer and the imports it reads through: cutting the runs into pieces, the chunks' ranges,
the pieces' places in the imports, the table and the dispatches. A consumer repeats the same
copy (a surface's same runs) every frame.

Such a copy's plan is now kept per RAM per device (RamCopies, which ChunkKeys becomes):
direction, runs' form, buffer key (object id, device generation, length), the runs, the
blit_at VkBuffer and byte, the device's figures (window, alignment, workgroups, array), the
span and total, the chunk ranges and joined ranges, the import serials in order with the
chunk-to-imports map, the table and the dispatches. The next copy with the same key (runs
compared element by element, no hash trusted) takes the table and dispatches where:
- blit_at gives the same VkBuffer and byte (a rebind or a new VkBuffer plans anew);
- the device's figures are the same;
- every chunk takes at once (copy_take Now for all; else the full path stages it);
- copy_imports gives the same imports, by serial number, in the same order, with the same
  map. RamChunk now carries a serial from a process-wide counter, never reused, so a chunk
  released, given back or imported again has a new one. Plans keep numbers, not Arcs.
Every step a copy takes each time still runs: blit_at, copy_wrote, the takes, copy_imports,
the upload, the binds, the uses and the counts. Where the plan does not hold, what it took
(blit, takes, imports) goes to the full path, which takes none twice: a chunk released
between the takes and the imports plans over the imports it got.

Bounds: 8 plans and 4 MiB per RAM per device, the one taken longest ago dropped first; a
plan over 4 MiB is not kept. Counter: WorkCounts::host_ram_copy_plans_reused.

stages() is split into takes() and Takes::staging() so both paths share the takes;
record_dispatches() is the dispatch tail both paths record through.

Tests: unit, the bounds; device (lavapipe): a repeated copy takes its plan and a run
changed, the other direction, another buffer offset, another buffer, a rebound no-copy
buffer each plan anew; a chunk let go of (idle, given back) makes the next copy plan anew
and the one after take the new plan; a new use of the RAM plans anew; a kept plan's copy
is ordered after a fill of its buffer and after a scatter into its pages in the same
command buffer.

The plan also holds the buffer's host pages weakly and compares them by
identity: lavapipe gave a rebound buffer's new VkBuffer the destroyed
one's handle value (m3-max-32579), so a handle match alone cannot see a
rebind. The plan names no VkBuffer; the binds take the live one on every
call. The pages copy's kernel is looked up only where a copy goes by
dispatches, as before. The layer bench says how many copies a kept plan
recorded.

Measured (release, msi lavapipe, m3-max-32581, before d0ef5e0145 and
after, one job, median us a call over 8100 single-page runs): layer in 1
chunk 373.9 -> 139.1, over 128 chunks 859.8 -> 323.4; at 0bae61504a
(m3-max-32615) 200 of 200 copies by a kept plan.

Verified at 0bae61504a (m3-max-32610): host_ram tests on lavapipe
103/103, clippy plain, m2v_gpu and m2v_cpu_icd 0, rustdoc 0. Negative
control (m3-max-32579): with the serial compare removed, the let-go test
fails (a reuse happened).
2026-11-15 08:30:44 -08:00
Anees Iqbal ef64727c7a RUNTIME 2345: Host RAM: a first gather over bytes some use may write is staged in a part of its own, never through imports made or waited for on the encoding thread
stages() staged a gather over chunks the device's thread imports only where no use but a
copy's read may write its host bytes (RamOnDevice::written_over). That holds for the whole copy
as soon as one chunk it touches had a scatter recorded (copy_wrote, never cleared) or a buffer
over host pages lies over its bytes, so a first fill over a fresh RAM after any download into one
of its chunks took the imports' path: for_copy imported each chunk not imported yet on the
encoding thread (the ahead plan imports no range alone). A consumer's decoder waited 1.73 s
for 124 such imports on an RTX 3090 (each pins 64 MiB of fresh pages).

Such a gather is now staged as one over a chunk that takes no import is when written: in a part
of its own (Staging::after_the_gpu), its host step after the work before it in its command buffer
completed, on the steps' thread. Its encoder keeps no log (an encoding again through the imports
would start no part, so its parts would not be the first's). Docs: copy.rs, deferred.rs,
docs/HOWTO.md.

Tests: host_ram_copy_device::a_first_gather_over_chunks_a_scatter_wrote_waits_for_no_import (a
scatter then a gather in one encoder over two chunks not imported, the thread's imports held in
flight): the gather is staged, waits for no import, imports no range, reads the scatter's bytes;
two later fills of its pages (a later encoder, a later command buffer) land after its read.
Benches (ignored, release): host_ram_first_fill_spread_bench, host_ram_layer_encode_bench.

Evidence (lavapipe, msi): negative control m3-max-32190 (the test against the parent's copy.rs
fails: not staged, 600 ms waiting on two paused imports); with the fix all 92 host_ram tests pass
(32190); clippy cpuicd -D warnings clean and the extended test pass at the tip (32210). First-fill
bench after a 1-page download: before staged 0, 121 chunks imported on the encoding thread, call
1369 us (32174); after staged 1, 0 import waits, 0 chunks imported by the copy, call 328 us (32210).
The 3090 run follows.

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

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

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

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

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

Verified, msi m3-max-30127 at cba1ec585a (the fix plus a test-only fix: DevicePolicy is
non-exhaustive, so the tests set the field on a copy):
- clippy -D warnings --all-targets --all-features: metal2vulkan + runtime plain 0, runtime
  --cfg m2v_cpu_icd 0;
- translator tests 49/49 (fast_paths with the new choice, its no-profile key and exact_answers
  tests, api_surface, api_signatures);
- runtime under cpu_icd on llvmpipe 34/34: icb_records_policy, icb_carry_race, icb_records_home,
  indirect_command_buffer*, device_recovery_every_kind, device_recovery_carry.
ICB-RECORDS lines:
- Untaxed with the tax forced Holds: records not in own pages, 0 fresh-page buffers, the
  carry moved them, notice "1 of them whose records were lost";
- Untaxed with the tax forced Fails: own pages, 2 fresh-page buffers, kept;
- Carried with the tax forced Holds: own pages, 2, kept.
Workload proof owed: reims's traced loaded-desktop walk on the 780M (per-CS get_user_pages 0, no
-EAGAIN windows).
2026-11-14 12:49:09 -08:00
Anees Iqbal 738d3fb2ba RUNTIME 2291: the host residency counts a shared dma-buf file once and releases its pieces together
With buffers grouped into shared dma-buf files (RUNTIME 2290), the residency
still counted and released one buffer at a time. On RADV a shared file's
import leaves the submissions' list only with its last holder, so releasing a
piece of a file other buffers still hold took nothing off the list and cost a
VkBuffer and a bind at the piece's next use. The 780M run of the shared_files
example (job m3-max-29062) released and rejoined 936 of 1,000 pieces of one
file that way, once the cap of 64 applied.

Now every pass groups the releasable imports by the shared files their pieces
lie in (union-find over the files each holds), and a group goes whole or not
at all: every member released together under all their locks (taken in
address order; no other path holds two), and only where every hold of each of
its files is a member's, so that the release frees each file's import. A file
a heap, a buffer kept for good or a command buffer still holds stays imported
with all its pieces. The cap counts the imports on the device's list: a
group's files once each plus each import of its own. The wake trigger counts
each import's listed weight, less a gap the last pass found (pieces past a
file's first), so pieces of one file wake no thread; the periodic pass
catches what a race misses.

Tests: src/tests/host_import_groups.rs (no device): grouping, joining through
an import over two files, a file held elsewhere, holds read apart.
src/tests/dma_buf_shared_files.rs (device, no-pointer route): four buffers
over one file past a cap of 1 see no release and no import again over three
rounds of blits; the negative control, four buffers of their own dma-bufs,
has three released past the most and imported again; two files of two
buffers have the least recently read file's pieces released together, its
import freed once, the other file's kept, and once one of its buffers is
exposed the other is released no more, even forced.

Verified (dmagroup, msi lavapipe --cfg m2v_cpu_icd, no-pointer device): m3-max-29116 at the same
content: 102/102 (dma_buf, host_residency, host_import_groups, pointer_residency, no_pointer_import,
host_ram_dma_buf, host_aliases, dropped_uncommitted, chunks_cover, copied dma-buf tests). 4 buffers
over one file, cap 1: released 0, past the most 0, imported again 0 over three rounds; negative
control (4 own dma-bufs, cap 1): 3 released past the most, 6 by the end, 3 imported again; two files
of two buffers, cap 1: the least recently read file's 2 buffers released together, shared imports
live -1, an exposed buffer's file not released. m3-max-29139: clippy cpuicd/plain/m2v_gpu 0,
private-items rustdoc 0, touched tests 12/12. No WorkCounts field, Degradation kind or API change.
2026-11-14 05:56:32 -08:00
Anees Iqbal 4cdae42a8f HOWTO: which calls block their thread while a runtime-suspended GPU resumes
Rewrites the runtime-D3 host note of section 8 in place from d3wake's probe on an RTX 5080
Laptop GPU (driver 615.71.09, Linux 7.2; b5080 entry d3wake-probe-050814, probe branch not landed):
bare Vulkan calls made after 25 s idle with the GPU suspended hold their thread for the resume
(empty vkQueueSubmit 982 ms, a host write to device-local memory 986 ms, a device-local
vkAllocateMemory 988 ms, a pool reset and the recording of 8192 dispatches 987 ms); `commit`
returns in 0.03-0.43 ms and the resume lands on the scheduler thread's submit
(batch_submit_nanos 979-986 ms); a commit that records a CPU-written indirect command buffer on
its own thread holds it 951-952 ms (arenavram's entry); commit_and_submit and the making of an
object that takes a new device-local allocation are stated as expected, not measured.

Drops the old advice to set the PCI device's power/control to `on` (a runtime-PM setting the
runtime must not ask of its users). Docs only: no product change.
2026-11-14 05:20:50 -08:00
Anees Iqbal 045ae9caa8 RUNTIME 2290: pieces of a shared dma-buf file bind in one import of the file
On RADV every guest no-copy buffer and heap is a dma-buf import of its own
(the shared mapping's pointer is refused), and RADV lists every import in
every submission: the 780M's vkQueueSubmit cost ~0.45 us per live import
(the consumer's Super Resolution: ~1,010 imports, p50 531 us a submit).
The lever agreed with the consumer: a source answers pieces of files it
shares, and the runtime imports each file once.

- DmaBufChunk is { file: Arc<OwnedFd>, offset, length } (was { fd, length }).
  A chunk at offset 0 whose Arc the runtime alone holds (Arc::try_unwrap) is
  a dma-buf of its own, imported exactly as before; any other is a piece of
  a shared file (dma_buf.rs Piece).
- DmaBufRequest gains `alignment` (the host page, a plain dma-buf buffer's
  memory alignment, asked once, or the granule where the request may split)
  and `shared_files` (false for an image's dedicated import, a guest RAM's
  chunk and its probe, and a list of runs: those take a dma-buf of its own
  at offset 0, as before). A misaligned piece, or one past its file, is
  misuse (Invalid, Problem::DmaBuf).
- Each device generation keeps DmaBufFiles: the address of the file's Arc
  (never the inode) -> Weak<DmaBufFile>, one import of the whole dma-buf,
  dedicated to nothing, made with no lock held and entered under a leaf
  lock (a racer's import freed). Each buffer's DmaBufPages holds one Arc
  per piece; the last holder takes it out of the map under the lock
  (Arc::into_inner) and frees it through its own device handle.
- A plain buffer binds at its piece's offset (Placement::dma_buf takes the
  offset), a sparse one each piece at its memory offset.
- Residency keeps pieces: a dup of an own descriptor (counted against the
  fd budget, as before), an Arc clone of a shared file (no descriptor).
- import_dma_buf borrows the descriptor (it always handed the driver a
  dup).
- WorkCounts: dma_buf_pieces_joined, dma_buf_shared_imports_live (new);
  dma_buf_imports counts imports made (own chunks and first pieces).

Tests: tests/dma_buf_pieces.rs (Piece classification, the map's holds, no device);
tests/dma_buf_shared_files.rs (device: four buffers over one file -> one import, three joined,
bytes and fills in their pieces, freed with the last; the negative control of own files; two pieces
of one file in a sparse buffer at their offsets; release and import again; a misaligned piece
refused). Example shared_files: the 780M submit-cost A/B (own files, 8 a file, 1000 a file).
Docs: dma_buf.rs module, with_dma_buf (a shared-file import is never dedicated: where a device
needs that, the buffer is a copy, the source not asked again), HostRam::with_dma_buf, HOWTO,
runtime README; api_signatures.tsv; REFUSALS regenerated (unchanged).

Public API change (runtime): DmaBufChunk { file: Arc<OwnedFd>, offset, length } (+Clone), was
{ fd, length }; today's behaviour is `file: Arc::new(fd), offset: 0` with no clone kept.
DmaBufRequest gains `alignment` and `shared_files`. No Degradation kind.

Verified (dmagroup, msi): m3-max-29050 at 51e7f6b569: tests 72/72 on lavapipe (--cfg m2v_cpu_icd;
Mesa 26.2.4 takes the no-pointer dma-buf route with /dev/udmabuf), clippy -p runtime -p validation
--all-features --all-targets -D warnings plain 0 and m2v_cpu_icd 0, example builds (release). Seen:
4 buffers over one file -> imports 1, joined 3, shared live +1; own files -> imports 4, joined 0;
sparse reverse-order pieces -> one import, bytes in order; misaligned (2048 vs 4096) -> Invalid
DmaBuf, nothing imported. The 780M submit-cost A/B runs after landing.
2026-11-14 05:12:55 -08:00
Anees Iqbal c3a2623c6f RUNTIME 2280: a pass's store-out into bit-24 memory faults its command buffer off macOS
Measured on the M3 Max under macOS 27.0.1 (plain Metal, probes/readonly_encode_answers.m, jobs
m3-max-28796/28797, 2 runs a shape, against writable controls, every pair agreeing), memory made
with Metal's private option bit 24:
- a pass storing an attachment there (Store / StoreAndMultisampleResolve), resolving into it
  (descriptor or a late store action) or storing a CustomSampleDepthStore depth there fails its
  command buffer with PageFault (~14-15 ms), its event signal fires, the pages stay unchanged;
- a kernel texture write and a blit copy into a texture over it complete with the write dropped;
- replaceRegion of a texture over it writes the pages (they stay CPU-writable);
- command buffers after the fault (same queue, a new queue, 100 ms on) complete.

Off macOS the runtime completed the store-outs. Now store_out.rs, at the pass's end once store
actions settle: an attachment stored or a resolve target actually resolved into over memory whose
GPU writes are dropped (Buffer::drops_writes of the texture's buffer or heap bytes) calls
EncoderCore::fault(PageFault): the pass and every encoder after it run nothing, every event signal
fires, the fault counts toward the queue's revocation as other faults do. DontCare, an unresolved
resolve texture and writable memory complete. A cfg(test) switch store_out_unfaulted serves the
negative control. Docs corrected in place from the measurement: read_only_view.rs, PRIVATE_BIT
(values.rs), capabilities.rs, the host_page_writes cases' notes, the FAST-PATHS known-gap row, API.md,
HOWTO.md. No refusal, public type, Degradation kind or WorkCounts field changes.

Verified (rocontract, msi lavapipe m3-max-28813): clippy (runtime, cfg m2v_cpu_icd) 0;
store_out_device 6/6 (colour Store with the buffer twinned and untwinned, resolve-into descriptor and
late, depth CustomSampleDepthStore descriptor and late, Store in a bit-24 no-copy heap all fault; the
completing shapes complete; the next command buffer completes and reads the pages); negative control
(fault off): the Store completes. The suites run after landing.
2026-11-14 03:29:43 -08:00
Anees Iqbal cbd2898434 RUNTIME 2249: a recovery's carry of pooled ICB records waits out the setters' unlocked writes; getters hold the overflow slots; reset GPU time counted
RUNTIME 2225 and 2242 let an indirect command buffer's setters write without the lock. RUNTIME
2247 put the records in the runtime's own imported pages wherever the device imports host
pointers, so every carry there keeps the pages, the pointer and the records (Kept; the carry's
forget_keys sends the next named set under the lock), and an unlocked write needs no tracking.
Records that still lie in pooled memory (a device without host-pointer import, or a failed
import) move at a recovery (Lost, every command reset), and an unlocked write could hold their
old pointer across the carry's release: a use-after-free.

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

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

RUNTIME_VERSION 2248 -> 2249.
2026-11-13 16:38:21 -08:00
Anees Iqbal 18060aa638 RUNTIME 2234: warm: a refusal for good is kept, and a later pass answers its record at once
A warm pass made every record's creation again at every boot, refusals
included: on the Iris Xe under ANV six Cycles kernels past the stage bound
its driver compiles intact (Unsupported{StageSize}) cost 1.4-2.4 s of
warm-thread work a boot, one record 1397 ms before its refusal. Nothing kept
the refusal: it is decided in the translation, after the shader cache's
lookup missed, and only translations are stored.

Now a warm creation's failure that is a fact of the record on this device
(a typed refusal, Error::Unsupported, or a translator outcome the translator
states permanent for its input; never a missing input, a deadline, a
cancellation, a failed host allocation, out of memory or a lost device) is
kept in the build's directory, named by the record's bytes and the driver's
identity (vendor, device, driver version, pipelineCacheUUID) under the
profile fingerprint and RUNTIME_VERSION (shader_cache/warm_refusals.rs). A
later pass looks the record up there before reading it and answers it as
failed of the same kind at once, counted in the new
WarmStatistics::records_failed_before and announced as before. The
program's own creation still translates and meets the refusal itself.

Tests: warm::a_refusal_for_good_answers_a_later_pass_at_once (a 256 KiB
private array every device refuses: a later device over the directory
answers it with no stage decoded and no lookup; an Invalid failure is made
again by each pass), pass::only_a_refusal_for_good_is_kept,
shader_cache::a_warm_refusal_is_found_by_its_own_driver_only,
warm_refusals' frame test.

Why: on the Iris (ANV, pin 71) every boot's warm pass retried 6 records refused StageSize /
DriverDefect, 1.4-2.4 s of warm-thread work a boot (one record 1397 ms). Verified (warmskip, msi,
lavapipe, at cedc049cf1 on 86d362e2aa): warm and shader_cache tests 73/73 (26206); negative control
with the lookup disabled fails, records_failed_before 0 (26215); clippy plain 26209, m2v_gpu 26224,
m2v_cpu_icd 26216, rustdoc -D warnings 26225, all 0.

RUNTIME_VERSION 2233 -> 2234 (the warm pass answers kept refusals).
2026-11-13 11:49:37 -08:00
Anees Iqbal c50b66ab6e NVIDIA computes half on its 16-bit instructions under the float controls
DriverWorkaround::HalfConversionPairFolded (every NVIDIA_PROPRIETARY GPU)
made narrow::controlled_modes return None, so NVIDIA's profiles lost the
16-bit float controls altogether: quantize_form was Converted and
f16_arithmetic None, a half + - * was computed in f32 and "rounded" by an
FConvert pair the driver folds away, spirv::half_hold never ran, and a
half / and sqrt were f32. The workaround is the pair's alone: NVIDIA's
compiler folds an OpFConvert 32->16 and its widening back into the 32-bit
value; it reports RTE, DenormPreserve and SignedZeroInfNanPreserve for
Float16 (independence ALL), under which its 16-bit instructions and a
single conversion are Metal's by the Vulkan spec (owner rule 1: the
device's native form is the only form).

- narrow::half_controls(p): shaderFloat16 and every mode of
  controlled_modes, which no longer reads the workaround.
- narrow::quantize_form: Controlled (the decorated pair under the
  controls) only where the driver keeps the pair; NVIDIA stays Converted,
  so an f32 result rounded to half through a round trip is still the
  device's conversion, recorded NativeHalfConversion.
- What keyed on Controlled but is no round trip now keys on the controls
  (ArithPlan::controls, ModuleBuilder::half_controls): a half + - *
  (f16_arithmetic), / (divide::native), sqrt (math::float_fn), the half
  fma route (fma::half_route), spirv::half_hold, and in compile.rs the
  declaration of the modes and the widening/narrowing note. The modes are
  declared for a pair only where the pair is Controlled.
- Unchanged: blend's half_of, round, round_texel and the bit conversions
  follow the rounding form.

Docs: narrow.rs, half_hold.rs, divide/math/fma, the workaround's doc,
PrecisionNote::NativeHalfConversion, docs/API.md's
native-half-conversion entry and docs/HOWTO.md say NVIDIA computes under
the controls and keeps the native conversion for the round trip only.

Tests:
- tests::engine_native_half::nvidia_computes_half_on_16_bit_floats_under_the_float_controls:
  nvidia-rtx50-linux, nvidia-rtx5080-laptop and the 5080 laptop's
  description with an RTX 2080's (0x1E87) and an RTX 3090's (0x2204)
  device ID emit 16-bit OpFAdd/OpFMul for a half sum, product and chain,
  declare the three 16-bit modes, require their properties, record no
  NativeHalfConversion, pass L3, and round each operation on the
  interpreter; a half narrowed and widened alone stays the noted round
  trip. Negative control: the 2080 description without
  shaderRoundingModeRTEFloat16, and Pascal (no shaderFloat16), emit no
  16-bit instruction or mode and record the note.
- Existing tests that pinned NVIDIA's widening note or keyed on
  Controlled for the controls follow the split.
- runtime_lane::native_maths::half_arithmetic_under_the_float_controls_answers_metals
  (device): a half sum, difference, product and product plus a third
  operand over 4096 threads equal Metal's per-operation half answers
  exactly where the module declares the controls; it prints how many
  words the f32 computation (the folded pairs' answer) differs at.
  half_rounding_answers_within_its_recorded_bound now expects the sum
  Metal's and the round trip noted on a driver that folds it.
2026-11-13 09:14:25 -08:00
Anees Iqbal 72562e193a The pre-import placement's docs, and its test compares refusals too
What: Buffer::texture_placement, TexturePlacement::InPlace, InPlaceRefusal and route.rs say
what the query answers before it makes images and what host_pages_texture_placement answers
before the buffer; docs/API.md, docs/HOWTO.md and the runtime README name the new query. The
test compares both calls' results, refusals included (a plane past the buffer's length is
refused as PastBuffer by both, not answered PastLength), and asks rows of 8 bytes too.

Why: lavapipe m3-max-24732: every shape both queries decide answered alike (CheckFailed by
pointer, Unchecked over dma-bufs, InPlace elsewhere), but the past-length shape is a refusal
of both calls, which the test unwrapped.

Verified: pending the lavapipe run.
2026-11-13 00:43:10 -08:00
Anees Iqbal 8bc2e7e1ac Keep the content directory's large records as content-defined chunks, each shared run once
NVIDIA's pipeline cache data (620.70.06, an RTX 3090) held one 1,851,552-byte section, the same
bytes, in 3,565 of um790's records: its 11,853 NVIDIA records were 8,061 MB. A read-only measure
of that node's 42,860 records (cut as below, averages of 16, 32 and 64 KiB) stores them in 296 MB
at 32 KiB (NVIDIA's in 180 MB, 2.2%); 64 KiB keeps each shared run's end chunks apart (634 MB),
16 KiB doubles the files a read opens for 1.3x the bytes.

shader_cache/chunks.rs (new), store.rs, driver.rs:
- A content record of 256 KiB or more is cut by a gear rolling hash (FastCDC's normalized cut,
  8 KiB to 128 KiB around 32 KiB): boundaries from the bytes alone, nothing of any driver's
  format read. Each chunk is kept once at <root>/chunks/<2 hex>/<SHA-256>, outside <root>/v1, so
  a build whose scans know nothing of chunks never removes one. The record's file is a manifest
  (M2VCHNK1, length, count, each chunk's SHA-256 and length, its own SHA-256); a read joins the
  chunks and the record's decoder checks it end to end as before (a driver record's checksum, a
  library's content hash). A missing or short chunk is a miss; the next write brings it back,
  and a chunk whose bytes are not its digest's is written again. Smaller records stay whole.
- Crash-safe: every chunk (temporary + rename) before the manifest's rename. An advisory lock
  (std File::lock, <root>/chunks/lock): writers hold it shared from their first chunk look to
  their manifest's rename; the cleanup takes it exclusively with try_lock and removes only
  chunks no manifest names. Neither waits: a writer that meets a cleanup writes its record
  whole.
- Bounded cleanup, in the scans the store makes already: the sweep at device creation where no
  cleanup ran yet or the chunks grew past 110% of what the last kept, and after a cap scan that
  freed chunks. It reads each content record's first 8 bytes (a manifest whole) and lists the
  chunks once. The chunks count against the cap; a removed manifest frees the chunks only it
  named.
- Upgrade: driver::VERSION 3 -> 4, its frame's magic M2VPPLC -> M2VPPL4 (an older build names
  and frames otherwise, never misreads one). The old records are removed by
  Store::sweep -> Chunks::due (no state yet) -> Chunks::cleanup -> Chunks::manifests, which
  removes each content record whose magic is in driver::RETIRED. Each family pays one cold
  making after the upgrade. The validation lanes read the new magic.
- Linux reads: every chunk opened first and posix_fadvise(WILLNEED) on each, so cold chunks
  are read together.

Tests (tests::shader_cache_chunks, 8): round trip and the 256 KiB bound; a shared 1.5 MiB run
kept once (the second record wrote 95,310 of 1,580,864 bytes); no manifest when its chunks
cannot be written; a missing or damaged chunk; the sweep removing a synthetic v3 tree (four
M2VPPLC records, one of 2 MiB), unnamed chunks and a dead writer's temporary; a writer's
shared lock putting the cleanup off; a cleanup's lock making a writer write whole; the cap
evicting the older record with its own chunks.

Verified on msi (m3-max-24179, at this tree's code): clippy -D warnings all features, rustdoc,
shader_cache tests 44 passed, the runtime suite 1512 passed.

Load time, release mode on um790 (NVMe), a store load with a SHA-256 decode in both
(m3-max-24178; the SHA-256 of 1.85 MB alone is 0.80 ms), median of 20 cold (every file dropped
from the page cache) and 200 warm:
- 1.7 MB, 40 chunks (NVIDIA p90): cold 1.56 ms whole, 1.47 ms chunked; warm 0.77 / 0.95 ms.
- 2.5 MB, 67 chunks (worst): cold 2.07 / 2.62 ms (+0.55 ms; one of 20 at 12.1 ms); warm
  1.12 / 1.44 ms (+0.32 ms).
- 20 families sharing the section, all cold, in turn: per family median 0.86 ms whole,
  1.13 ms chunked (first 0.94 / 1.65 ms); whole's slowest 138.6 ms, chunked's 1.18 ms.
A family's later makings on the device use its live cache and read nothing.
2026-11-12 21:10:10 -08:00
Anees Iqbal cbe64ff91b warm: a failed creation is announced once per kind, naming the kind and nothing of the shader
What: a record whose creation fails on Device::warm is still counted and dropped, and the first
failure of each kind a device meets is now announced through its message sink (else stderr) as
the warning metal2vulkan-warm-record-failed, as the first unread record is. The kind
(warm::pass::failure_kind) is the runtime error's variant and, for a translator refusal, its
feature and what it needs, e.g. Compile(Unsupported{Lowering(Access); NotImplemented}); for an
input error, its class. Never a symbol, location or message, which can name the record's
shaders. Past 32 kinds a device counts later ones alone.

Why: pin 62's warm pass failed 124 of ms01's records and 90 of um870's and said nothing: the pass
counted them and dropped them, so the walk's summary line was the only trace, and naming the
class took a replay with a temporary print (all 124 on ms01 were
Unsupported{Lowering(Access); NotImplemented}, fixed by SEMANTICS_VERSION 2070). The next such
regression names its kind in the consumer's log.

Tests: a_failure_kind_names_nothing_of_the_shader (a refusal with a symbol and a function
location renders as its variant, feature and needs only), and the device test
a_failed_creation_is_announced_once_by_its_kind_and_the_pass_goes_on (two records Metal refuses
alike around a render record: 2 failed, 1 warmed, the warning heard once, naming the kind the
program's own creation meets and not the kernel's name). The runtime README and docs/HOWTO.md
say so.
2026-11-12 18:59:46 -08:00
Anees Iqbal 5039015420 An import several no-copy buffers over the same bytes lie in stays releasable
A no-copy buffer made over exactly the bytes a live one covers lies in that
buffer's import (host_aliases.rs, "One memory, one import"). Until now its
making read the import apart (ReadApart::SecondBuffer), which keeps a
releasable import imported for good. Such a buffer reads the import the way
the first one does, through the import: its blits take the import's objects,
imported again where released, and any other read of it exposes the import
just as a read of the first buffer would. So the import now stays releasable
while every read of each buffer in it was a blit's, or there was none. A
buffer that is never read, made only to keep the bytes imported, keeps the
import no more than a buffer read only by blits does.

Why: on the RX 7900 XTX (RADV), a guest's 3D benchmark kept 1,000 to 1,330
dma-buf imports live. RADV lists every one of them in every kernel submission,
at 0.43 to 0.44 us each (docs/FAST-PATHS.md, known gaps). Of those imports,
1,262 were held for good, and every held one had a second buffer lying in it.
The consumer keeps a holder for each view of guest pages: a no-copy buffer
over the whole view that nothing reads, with the block's buffer lying in its
import. The frames named about 0.6 imports per command buffer, while the
scheduler thread spent 0.63 to 0.90 s of each second in vkQueueSubmit, at
0.835 ms per call. Our own blocks on that device are plain VRAM, which RADV
makes local and lists in no submission.

What still keeps such an import imported for good:
- a no-copy heap's own bytes lying in it: the heap's placed buffers'
  addresses are the heap's, handed out without any read of the import noted;
- a rebound buffer lying in it, as a rebind's own import is kept;
- a buffer bound inside its memory with a VkBuffer of its own;
- a buffer made to share its buffer's range (BufferDescriptor::range_of),
  which is handed that buffer's address.

Counters: the gauge host_imports_read_apart_second_buffer is split into
host_imports_read_apart_inside, _shared_range, _heap and _rebound. The new
host_imports_joined_releasable counts the buffers that came to lie in a
releasable import beside another and left it releasable; a walk shows the
path ran when it is non-zero. host_residency.rs ("Several buffers in one
import"), host_aliases.rs, the WorkCounts docs, docs/HOWTO.md and the API
signature table say so.

Test: tests::host_residency::an_import_two_buffers_lie_in_is_released_while_idle_and_read_right_again.
It makes a never-read holder and a second buffer over the same 4 pages of a
udmabuf-backed memfd. Joining keeps the import releasable (nothing held for
good, no read apart) and imports nothing new. Read by a blit, the import is
released. The file's writes made while it is released are read by the next
blit through the second buffer, imported again from the kept descriptors. It
is released again. Then a kernel binds the second buffer, makes the holder
resident (useResource:, as Metal reaches a no-copy buffer through an address
only once a command buffer used it) and loads the holder's Metal address from
set_bytes; the binding imports the import again for good. The words the kernel
reads through the address, and the words it writes through it, are checked
against the pages. The source is called once, and the import leaves the gauges
once its buffers go.
host_import_counts now expects a second buffer over the same bytes to read
nothing apart.

Verified (the runtime's debug test binary, --cfg m2v_gpu, not a release build):
- m3-max-23710 (msi-laptop): cargo clippy --workspace --all-targets
  --all-features -D warnings, the runtime's clippy under --cfg m2v_gpu, and
  the runtime's rustdoc with -D warnings: clean.
- m3-max-23713 (msi-laptop): the API signature tests, 16 passed; the
  runtime's suite, 1502 passed, 6 skipped; on lavapipe (--cfg m2v_cpu_icd)
  the host_import_counts, host_residency, pointer_residency and host_aliases
  tests, 39 passed.
- m3-max-23761 (Radeon 780M, RADV PHOENIX): the host_residency and
  host_import_counts device tests, 15 passed, the new test among them ("1
  chunks of two buffers released twice, imported again twice"). The negative
  control, the same binary with a joining buffer reading the import apart as
  before, fails the new test at "the second buffer kept the import for good"
  (held for good 1, expected 0).
The lint and suite jobs ran one commit before the test's last change (the
holder made resident before the kernel reads through its address), a
test-only change that the 780M run's binary carries.
2026-11-12 18:52:11 -08:00
Anees Iqbal dc859fee56 Residency: host_imports_resident counts releasable imports alone; host_imports_held_for_good the rest
What: an import a read other than a blit's keeps for good (Residency::held_for_good) leaves the
host_imports_resident gauge and joins a new gauge, host_imports_held_for_good, as it already left
the device's count against its most (Shared::resident). Every move of an import's memory (a
release, an import again, let_go, the drop) now goes through one place, Residency::holds_memory,
which counts it as releasable or as kept for good, by the flag under the state lock, as the most
was counted. WorkCounts docs, host_residency.rs's Counted list and HOWTO.md say so; the API table
and host_ab's list name the new field.

Why: host_imports_resident's doc said 'the imports the device may release', but it went down only
at a release, a let_go or a drop, so it also counted every import kept for good. A guest walk on the
RX 7900 XTX showed about 1,040 'resident' beside a cap of 64 releasable imports, which read as the
cap failing. The two gauges show both numbers without subtracting.

Verified: the dma-buf and pointer residency tests now check the exposure step moves the import from
one gauge to the other, and that a gone import leaves both (job ids in the report).
2026-11-12 16:15:25 -08:00
Anees Iqbal 6e3b5d4795 Guest RAM: a copy over a chunk that takes no import goes through the CPU always
On ANV an object over a listed chunk keeps its own import (residency flat), which holds
the chunk back from the copies over it, as an object's pointer import at the RAM's own
addresses does on every device. copy_take answered such a chunk ThroughCpu, but
stages() still declined a gather some use may write the bytes of (an object lies over
them) and any copy that also touched a chunk it would import (Waits); those went to
the chunk's import and failed with the invariant "a guest RAM chunk a live import of an
object's own holds pages of" (a consumer's IOSurface block on the Iris Xe).

Now copy_take answers CopyTake::CpuOnly for a chunk the device refuses or objects' own
imports hold back, and stages() stages every copy over one, whatever else it touches
(Staging). A gather over such a chunk whose host bytes some use but a copy's read may
write takes a part of its own (Deferred::gpu_written for its GatherStage), so the work
before it in its command buffer is submitted and completed before its host step reads
the pages; its uses are noted again at that part's start, where its copy lies, and it
counts as a gated fill. An encoder holding a gather over such a chunk keeps no log
(Deferred::recorded_by_an_encoding_again), since an encoding again would copy it
through the imports.

Docs: copy.rs ("First touch", stages, record_staged, Staging), host_ram.rs
(CopyTake::CpuOnly, copy_take), deferred.rs, HOWTO.md.
2026-11-12 15:29:42 -08:00
Anees Iqbal bf9e921058 Guest RAM: on ANV an object over a listed chunk keeps its own path
7536aa8c75 had an object over a listed chunk not imported import the chunk where the
device's barriers do not order two imports of the same pages (ANV), or where the
object had no source of dma-bufs. With a consumer's run resolvers on every object, that
pins every 512 MiB chunk any object lies in, the residency regime RV 2144 left. Back to
RV 2144's object path on every listed plan: the object takes its own path (its import
of dma-bufs alone where the aliases are ordered, 345302afc2). On ANV its own import
still holds the chunk back from the copies over it; the CPU path that takes those
copies follows separately.

The beside test now runs where the device orders the aliases only, and the listed
idle test's first object takes its own import on every driver, as before.
2026-11-12 15:22:57 -08:00
Anees Iqbal f7941289d2 Guest RAM: an object a listed RAM routes outside its chunks imports its dma-bufs alone
The object's own path on a listed plan whose device orders two imports of the same
pages (7536aa8c75) took its pointer first wherever the device takes it, as every own
import does (lavapipe takes a shared mapping's pointer; RADV refuses it, so its imports
there were dma-bufs already). An import of the pointer at the RAM's own addresses holds
the chunk back (one page, one import), so the copies over the chunk could still not
import it. Now pages a guest RAM routes that no chunk binds in, where the RAM's chunks
may be imported beside them (Routed::own_dma_bufs: listed plan, ordered aliases), are
imported as the caller's dma-bufs alone, never by the pointer and the gate not asked,
as pages beside live dma-buf imports are since RV 2134; a failed import of them is a
copy. At the buffer's making and at a rebind.

Found by the new test on lavapipe (m3-max-22946): the object's own import was
ImportedByPointer where the test expects ImportedAsDmaBuf.
2026-11-12 15:22:57 -08:00
Anees Iqbal 9c35a3407d Guest RAM: a listed chunk is imported beside objects' own dma-bufs; on ANV objects import it
Since RV 2144 an object over a chunk not imported on a listed plan takes its own path,
outside the RAM's routing. At the RAM's own addresses its import is noted in the
aliases registry, which held the chunk back (RamOnDevice::held_back): the chunk could
not be imported while the object lived, and a copy by runs over it that no CPU stage
takes (a gather over bytes an object lies over) failed with "a guest RAM chunk a live
import of an object's own holds pages of" (a consumer's IOSurface block on the Iris Xe,
Mesa 26.7.2; on the 780M the hold-backs went from 4 to 45 in a walk once every object
got a run resolver, the copies falling to run lists).

Two cases, by whether the device's barriers order blits through two imports of the
same pages:
- They do (RADV, lavapipe): held_back now answers Held::{Free, BesideDmaBufs, Back}.
  Where every live import holding the chunk's pages is of dma-bufs and the plan is
  listed, the chunk is imported beside them as one dma-buf of the RAM's source, never
  by its pointer (import_chunk's new beside flag drops the pointer fallback): two
  aliases of external memory, ordered by the host bytes they lie over, the rule
  Device::imports_beside applies to objects' own dma-bufs since RV 2134. Counted as
  ObjectChurn::dma_buf_imports_beside_live, not host_ram_chunks_held_back. Imports of
  a pointer, and claims in flight, still hold the chunk back.
- They do not (ANV, AliasedImportBlitsUnordered): the chunk's import beside an
  object's would be unordered, so an object there takes the chunk's import (made or
  waited for), as it did before RV 2144 and as on plans that import ahead. So does an
  object with no source of dma-bufs of its own pages, whose own import would be of its
  pointer. for_object takes the object's `sourced` (HostWindow::source) through
  bind_in_chunk.

Docs: host_ram.rs (module, Held, held_back, for_object, copy_take, import_chunk,
use_host_ram), WorkCounts::host_ram_chunks_held_back and chunk_bound_buffers_made,
ObjectChurn's two import counters, HOWTO.md.
2026-11-12 15:22:57 -08:00
Anees Iqbal cc694355b1 Residency: a device test of the release past the most, and the guide's and HostMemory's words for it
past_the_most_resident_the_least_recently_read_import_is_released: with the most held at two
(Device::keep_resident_host_imports), three dma-buf imports read in turn; one released past the
most, the least recently read; the other two read with no import again; the released one's next
blit imports it again and reads the file's writes made meanwhile. It prints the free's and the
import again's times. HOWTO.md and HostMemory::with_dma_buf say a device whose held imports cost
every submission keeps at most 64 resident.
2026-11-12 13:49:23 -08:00
Anees Iqbal 27cd4bccc0 Guest RAM: on a listed plan an object over a chunk not imported takes its own path and asks for no chunk
On a device whose plan is listed (each held import costing every submission and the RAM's
chunks its dma-bufs: RADV, ANV where the import tax holds), an object over a chunk whose import
was not made was bound in an import of its own run and asked the device's thread for the chunk,
which faulted in and imported the whole chunk: udmabuf allocates every page of it and keeps them
after the import is freed, so attaching runs to every no-copy object would make the guest RAM
under every object resident chunk by chunk (12.3 GiB of a 16 GiB guest on the 780M before the
listed plan). Now such an object is bound in the chunk only where its import is made, and
otherwise takes its own path, as over memory no RAM holds: no run import, no ask. Chunks are
imported for the copies over them, and the objects over them after that lie in them. Plans that
import ahead (NVIDIA, host-pointer chunks) are unchanged.

Removed with the object path: RunAgain, Routed::run_again, Placement::over_ram_run, the
residency's AgainFrom::RamRun with Device::ram_run_in_chunk and ram_run_alone_again, and
WorkCounts::run_bound_buffers_made (an object is never bound in a run import now; copies keep
their ranges alone and run_imports_live). Docs: host_ram.rs, host_residency.rs, copy.rs,
HostMemory::with_runs, driver_defects.rs, WorkCounts, HOWTO.md; the API signatures table
re-blessed.

Tests: the listed tests now import their chunks by copies; the first object over a chunk not
imported, with a source of its own pages as a consumer's come, takes its own import, no chunk
imported and none asked of the RAM's source, and the objects over a chunk a copy imported lie in
it. The other host RAM tests lose their run-bound terms (0 on every plan they run).
2026-11-12 13:45:59 -08:00
Anees Iqbal ad402b548e Every VkPipeline the runtime makes is named for the validation layer's messages
Where the instance reports messages (VK_EXT_debug_utils), each pipeline now carries a debug
name, which the layer prints after its handle. Until now only a raster-order pipeline was named,
so a synchronization report could not tell a program's kernel from one of the runtime's own.

- A program's pipelines are named by its Metal functions' names, in pipeline order, joined by
  " + ". Each variant's objects keep them (`VariantObjects::name_pipelines`), set where a
  compute variant is made (`pipeline/mod.rs`) and at each render variant's making
  (`RenderVariant::of`). A pipeline library is named the same, with its part in parentheses.
  An indirect-bindable replay pipeline takes its variant's names.
- The runtime's own pipelines are named "metal2vulkan: " and the kernel or step: each owned
  kernel by its module (for example "metal2vulkan: PagesCopy(Gather)"), the split, merge,
  resolve, copy and plane steps by their kind, the in-place check's draw, and the priming's
  kernels beside its pipeline.
- A raster-order pipeline keeps its name alone, since the validation crate's lanes match it whole
  (`raster_order_gap.rs`).
- A name is worked out only where the instance reports messages
  (`DeviceShared::name_pipeline` takes a closure), and nothing reads it: it is a diagnostic,
  and no translation or runtime path depends on it.

Why now: a sync-validation run on the XTX (SYNCVAL_SHADER_ACCESSES_HEURISTIC) reported 45
WRITE_AFTER_WRITE hazards. All were vkCmdDispatch after vkCmdDispatch, on one pipeline, at storage
binding 1 of a pushed set 0.

What the code points to, which the next run's names will confirm or not:
- The runtime's pushed kernels are RowsCopy, PagesCopy and the shadow copies and merges. Of
  those, the ones whose binding 1 is a written storage buffer are PagesCopy(Gather), RowsCopy
  and ShadowCopyBack.
- Only PagesCopy(Gather) records several dispatches in a row with one pipeline in one command:
  one per guest RAM chunk the runs touch (`host_ram/copy.rs`). Every one of them binds the same
  window of the destination buffer at binding 1.
- That path is taken only when no destination byte is written twice (`twice()`; a gather whose
  runs share a buffer byte takes regions instead), so those dispatches write disjoint words.
  The tracker orders the copy as one command over its whole span.
- The heuristic counts each dispatch as writing its whole bound range. So these would be
  reports of disjoint writes, not a missing barrier.
- Guest kernels push set 0 too, so a program's kernel in a concurrent compute encoder is not
  ruled out. That is what the names settle.

Docs: HOWTO section 8 says what the names are.
2026-11-12 12:10:05 -08:00
Anees Iqbal aa2256b6e7 Order host-alias uses across queues again: Metal orders textures over one IOSurface across queues
Reverts a5634d48db and 3926d2d8c9, which left the uses the host aliases add out of the
scheduler's order across queues on the strength of host_aliases.rs's line that Metal orders two
textures over one IOSurface across queues only as the program orders them. The conformance probe
probes/cross_queue_surface_order.m measured that case (queue A's long compute write committed
before queue B's blit read of the same bytes, no event between them, three runs each):

- two tracked textures over one IOSurface: B ran after A and read its writes in every run on an
  M3 Max (macOS 27.0.1, m3-max-21812, m3-max-21830), a Radeon Pro 5300M and a UHD 630 (macOS
  26.7.1, m3-max-21850, m3-max-21851); untracked, the same but one run on the 5300M;
- a texture of another surface (control): ran alongside A on the M3 and the 5300M;
- two no-copy buffers over one allocation: B ran alongside A, reading stale or mixed words, on
  all three (8 of 9 runs; the 630 ran it one after the other twice);
- one tracked buffer (control): ordered on the M3; the 5300M and the 630 each took B first once.

So the alias keys' order across queues is the surfaces' order, which Metal keeps; dropping it was
wrong for the consumer's surfaces, whose textures lie over per-texture no-copy buffers.
host_aliases.rs now states those measurements, the plain no-copy buffers' among them, in place of
the M4 line. The freeze the revert reopens (a held batch's making holding other queues' heads
over a shared surface) is answered by the next commit, which lets a batch held for its making give
way across queues, as the x86 Macs' GPUs may take a later commit first.

Until that commit, tests::hold_sites::a_head_over_the_same_host_bytes_through_another_buffer_goes_while_a_batch_is_held
fails as before a5634d48db (m3-max-21752).
2026-11-12 10:29:05 -08:00
Anees Iqbal 1b802ea45a Cross-queue commit order counts a conflict only on a resource both batches name
What: a use the device's host aliases add (host_aliases.rs: a no-copy buffer over the bytes of
another, the consumer's textures of one IOSurface over their plane buffers) is now marked
(`Use::aliased`). The scheduler's order across queues (`Footprint::conflicts`, behind
`Order::is_behind`) leaves marked uses out, so a batch the runtime holds for a reason of its own
(its pipelines' making, a host step, its checks) holds back no later commit of another queue that
meets it only over shared host bytes. A use joined with one its command named stays named (join
and merge keep `aliased` only where both are; `covers` lets no aliased use hold a named one), so
two batches that name one resource still run in commit order, as Metal's tracking orders them.
The tracker's barriers, inside a queue and on the GPU once both are submitted, take aliased uses
as before.

Why: on an Intel Iris Xe, one guest process's compute pipeline took about 3 s to make cold. Its
command buffer kept its place in commit order (held for its making), and five other queues' heads
in each scheduling pass, the window server's frame among them, conflicted with its footprint only
through the alias keys over IOSurface pages they shared (heads_held_for_earlier_commits +5 per
pass, footprints_built +2, the scheduler otherwise idle). The frame's present waits for its
writers' completion, the guest's display pipe allows two unanswered presents, and the guest froze
for 3.1 s. Metal orders two textures over one IOSurface across queues only as the program orders
them (host_aliases.rs's measurement: an M4, macOS 27.0.1, plain and under API validation), so a
later commit of another queue through another resource over those pages does not wait for an
earlier one there; holding it was ours alone.

docs/HOWTO.md's paragraph on copied and same-surface buffers says the same; the order.rs,
scheduler gate and host_aliases.rs docs name the exception.

Tests: tests::hold_sites::a_head_over_the_same_host_bytes_through_another_buffer_goes_while_a_batch_is_held
(the previous commit) failed before this change on lavapipe (m3-max-21752: TimedOut, the fill
waited behind the held dispatch) and is expected to pass after; tests::tracker gains
a_use_the_host_aliases_added_orders_no_batch_across_queues (aliased-only overlaps unordered both
ways, a named key on both sides ordered, a named use joined with an added one of the same range
named); tests::host_aliases expects the added uses marked.
2026-11-12 10:29:05 -08:00
Anees Iqbal ed8b9a137b A texture that renders over padded rows in ordered memory is in place where the device's check of renders passed
linear_plan::holding refused every texture that renders over rows with
bytes between them, ordered memory too (a Private buffer, a Managed one's
own copy on a discrete GPU), since Vulkan lets a render pass's load and
store read and write back any byte of the attachment's subresource. So
each such render target was a shadow (BytesBetweenRows): 32 Managed
textures at rows of 152 in 256 on reims's XTX walk.

Now holding takes renders_kept: Device::ordered_renders_kept answers it
where the device's policy takes images in place and its check of renders
over its pooled memory (PagesClass::Pooled, Access::Renders, the texels'
row ends) passed. That check renders into a linear image over padded
rows, through its moves into the layouts a render takes, a pass that
clears and stores it and a draw over its last column, while the CPU
writes the bytes beside its texels, and passes only where every byte but
a texel keeps what was last written: the owner's per-driver check, the
same that takes images in place over host pages and pooled memory. In
ordered memory no other agent writes those bytes meanwhile. The texture
is then the device's linear image made PREINITIALIZED (Between::Kept),
as one that only reads; a pending verdict starts the check, and a
texture made meanwhile is a shadow. The pooled move path asks the same.

Docs: the shadowed-texture notice (API.md), HOWTO, the degradation's
declaration and linear_texture_bytes_per_row's doc say so.

Verified: cargo fmt; unit test linear_plan::ordered_writes_let_a_
texture_that_renders_nothing_hold_its_rows_padding covers renders_kept
(kept in ordered memory, refused outside it and over shared rows);
device runs of tests::ordered_renders follow.
2026-11-12 08:57:13 -08:00
Anees Iqbal 605a99f639 A texture over a Private buffer at a pitch the driver takes only explicitly is in place: the GPU keeps its bytes
A Between::Kept texture (bytes only the runtime's ordered commands write; no render target) whose
pitch the device's linear image does not lay on its own now takes route 2, the DRM explicit-pitch
image (VK_EXT_image_drm_format_modifier, DRM_FORMAT_MOD_LINEAR), over the buffer's own memory,
where the driver's reported rowPitch equals the buffer's pitch at offset 0 and the image fits.
Checked per texture. Such an image starts UNDEFINED (VUID-VkImageCreateInfo-initialLayout-12478:
PREINITIALIZED only with TILING_LINEAR; 01443 for external memory), and 7.1.1 lets the move out of
UNDEFINED discard its range, so the first move keeps the bytes on the GPU: one span copied out to
a scratch buffer, the move UNDEFINED -> GENERAL, the span copied back, in one ordered sequence.
The submission taking a keep waits on every other queue's last submitted work, so the keep follows
every earlier access to the span; later work waits through the first move's owners. Afterwards the
image and the buffer alias as a linear resource (glossary, DRM_FORMAT_MOD_LINEAR; 12.11).

Counted: WorkCounts::first_moves_kept, first_move_bytes_kept.
2026-11-12 04:26:42 -08:00
Anees Iqbal 3e5293679e minimumLinearTextureAlignment: every usage's pitch, at least the device's line
The answer was, per format, the smallest power of two from 16 at which
a ShaderRead texture of every probed width took its in-place image. Two
things it did not cover:

- A texture that renders or that a shader writes takes the same
  in-place image with those usages, whose linear layout the driver may
  pitch otherwise. The probe now tries reading, reading and rendering,
  and reading and a shader's writes (USAGES), and answers the largest of
  the usages that ever lie in place (a usage the format's linear images
  cannot take has none).
- The device's check of images in place measures lines of
  nonCoherentAtomSize bytes (in_place::RowEnds), and on the Iris Xe its
  renders and writes of texels that share a line with bytes beside them
  fail (the line holding a row's last texels is written back whole). ANV
  answered 16 against a 64-byte line, so a guest that laid a render
  target out at 16 put its texels in a line with bytes before them: a
  shadow. The answer is now at least nonCoherentAtomSize, "the size and
  alignment in bytes that bounds concurrent access to host-mapped device
  memory" (vkspec, Limits) (placed_answer). At it, a texture whose rows'
  bytes fill whole lines shares none with other bytes. Rows whose bytes
  are no multiple of the line keep their padding in their last line at
  any alignment, so on ANV those stay shadows for renders and writes
  whatever the answer; the docs say so.

Metal's 16 stays where the device imports no host pages, for a format
no usage brings in place, and where a probe failed. The record's VERSION
goes to 2, so no answer of the old probe is read again. Expected answers
(the venues' read answers with the line): ANV 16 -> 64, lavapipe 64,
RADV 256, MoltenVK 16 (its line is 16).

Tests: tests::linear_alignment's the_answer_is_the_usages_largest_and_
at_least_the_line (the rule over every committed profile's line, ANV's
16 before and 64 after); the lane's render-target test (previous commit)
gains the same texture at Metal's 16, a shadow wherever the check failed
such renders.
2026-11-12 04:08:33 -08:00
Anees Iqbal 946ee6e0b6 Device::linear_texture_bytes_per_row: the driver's own linear pitch for a 2D texture
A texture over a buffer whose rows hold bytes between them is the
device's linear image in place (route 1, and Between::Kept for a buffer
only the device's ordered commands write) only at the pitch the driver
itself reports for that image (vkGetImageSubresourceLayout's rowPitch);
the alias checks it exactly. A caller laying out rows had no way to ask
for that pitch: minimum_linear_texture_alignment_for_pixel_format
answers the alignment of images over host pages (16 where the device
imports none), and a pitch rounded up to it can miss the driver's.

The new query (a runtime extension, no Metal counterpart) plans the
image as the texture's making does (declared_plan), makes the plan's
linear image unbound, reads its rowPitch, and releases it. It answers
None where the texture is not one 2D level, layer and sample, or where
the device has no linear image of the plan.

Test (kept_padding.rs): at the answered pitch the texture over a
Private buffer is in place; at each other padded pitch it is a shadow.
Docs: the runtime README beside the alignment query, HOWTO beside the
kept-padding sentence; api_signatures.tsv.

Verified: not yet built; the lavapipe job and one GPU run follow.
2026-11-12 03:56:50 -08:00
Anees Iqbal 42e11abcd4 Textures over buffers only the device's ordered commands write hold their rows' padding in place
What: a texture that renders nothing over a buffer of the runtime's own memory whose rows lie
with the buffer's bytes between them is now the device's linear image, made PREINITIALIZED, at
the buffer's pitch, where only the device's commands, in the runtime's order, write those bytes:
a Private buffer, and a Managed buffer's own on a device without unified memory (a two-copy
no-copy buffer's device copy, or one with its own host copy), not one whose VkBuffer was handed
out or whose memory is exportable (Buffer::gpu_bytes_ordered). linear_plan::holding answers what
an image may hold besides the texels (Between::{Nothing, Unobserved, Kept}); Kept takes route 1
alone: the linear image whose rowPitch the driver reports equal to the buffer's
(vkGetImageSubresourceLayout, aliases with within_padding). No DRM_FORMAT_MOD_LINEAR image at
Metal's pitch, no image over exportable memory or in exportable blocks, as each is made
UNDEFINED. A render target stays a shadow. Counted: WorkCounts::kept_padding_aliases.

Also two pairs of counts of what the program asks of a two-copy Managed buffer, beside the bytes
the runtime copies: managed_ranges_modified and managed_bytes_modified (did_modify_range),
managed_resources_synchronized and managed_bytes_synchronized (synchronize_resource), to compare
with managed_bytes_copied_in and managed_bytes_copied_out.

Why: the RTX 2080 guest census (reims's v302 run) made 230 textures over Managed buffers, 200 of
them RGBA8 ShaderRead|ShaderWrite at 3884, 4208 and 2448 texels a row with rows rounded up to
256 bytes, every one a shadow for its padded rows ("its rows lie N bytes apart"): 2.52 G shadow
texels first copied in, 1.26 G kept, 1.26 G words examined by merges back. Owner's rule:
in place where possible, a shadow only where impossible. Main approved the route and its
conditions.

Basis (Vulkan 1.4, docs/API.md's shadowed-texture entry): 7.1.1 Image Layout Transitions, "Image
layout transitions may perform read and write accesses on all memory bound to the image
subresource range ... If the old layout matches the current layout of the image subresource
range, the transition preserves the contents of that range": the image's one transition is its
first move, PREINITIALIZED to GENERAL, out of the layout it is in, ordered after and before every
write of those bytes, as only the device's ordered commands write them. 12.11 Memory Aliasing:
"Buffers, linear tensors, and linear image subresources are considered host-accessible
subresources when they are in any of these layouts: VK_IMAGE_LAYOUT_PREINITIALIZED,
VK_IMAGE_LAYOUT_GENERAL ... If two aliases are both host-accessible, then they interpret the
contents of the memory in consistent ways, and data written to one alias can be read by the other
alias." VkSubresourceLayout's "size includes any extra memory that is required based on
rowPitch" puts the padding inside the range. A kernel's writes may change the padding as on the
x86 Macs (in_place::Padding::Free); a render pass's load and store "may read and write back" it,
so render targets keep the shadow.

Verified: not built yet. tests::kept_padding (a Private buffer at 416, 448 and 512 bytes a row,
the buffer read back whole after the image's first move; a Managed two-copy texture changed in
one row through did_modify_range, then a blit-written row synchronized out, every byte between
rows as given, against a Shared buffer's shadow), tests::linear_plan's holding cases and
tests::texture_placement run on lavapipe next, then one RTX 3090 run.
2026-11-12 03:56:50 -08:00
Anees Iqbal 0d144ec0de Pooled memory: no bound on a texture's bytes; ShadowCause::LinearCost is gone
The owner, through reims: zero copy, in place where possible, shadow copies a fallback and never
a first option. A tracked texture over a Private buffer of the runtime's pooled memory whose rows
the device's own linear image lays out otherwise was a shadow past 48 KiB to its pitch
(TextureShadowReason::LinearCost), a speed choice measured on an Iris Xe alone that shadowed 1001
of an RTX 2080 guest boot's 1366 textures. It now takes its DRM_FORMAT_MOD_LINEAR image at Metal's
pitch at any size, wherever the device makes one and its check of the pooled memory passed, as a
texture over a Shared buffer already did; it is a shadow only where the device makes no such
image (its format, usage, pitch or limits), its policy is HostPageTexturePolicy::Shadow, or the
check failed or is pending (a pending one still moves in place once it passes).

Removed with the bound: in_place::POOLED_PITCHED_BYTES, ShadowCause::LinearCost and the public
TextureShadowReason::LinearCost (a breaking change of metal2vulkan-runtime's surface:
api_signatures.tsv loses its variant), texture_spans.rs (the runs of bytes textures were made
over, which only the bound read) and the moves it fed (MoveAfter::Aliases, LoneShadow, the
buffer's note and wait), Texels::only_commands_write (the bound's alone), the bench behind the
bound (runtime_lane::pooled_draw_costs, its crossover additions included) and
aliased_surfaces' cost bench. aliased_surfaces' first check now asserts every texture over one
surface's bytes takes the image at Metal's pitch, the first included, and a read copies nothing;
its one-after-another check, about the first texture's shadow, is gone. storage_over_buffer is
one function again (REFUSALS.md regenerated for the name). API.md, HOWTO.md, FAST-PATHS.md (the
in-place row) say "at any size".

RUNTIME_VERSION is not bumped here: the landing bumps it and re-pins the runtime sources.
2026-11-12 01:50:58 -08:00
Anees Iqbal ba69642609 Copied buffers: a comparison splits across up to eight threads, not four
A copy's comparison of 4 MiB or more (a commit's copy in with no base, whose
pages carry no log, and a comparison with a base) ran on up to four threads, the
calling one among them. On the RTX 5080 Laptop GPU's host (a Core Ultra 9
275HX) eight cut the commit of a kernel-read pass over 256 MiB from 11.2 to
8.4 ms (12.3 to 14.1 GB/s), 64 MiB from 2.9 to 2.2 ms, a copy in after the CPU
rewrote every float of 256 MiB from 30.3 to 17.0 ms (6.6 to 9.0 GB/s), and the
merge back of a 256 MiB kernel-write from 65 to 41 ms with the stores of
27c4a1ae46 (copied_bandwidth_bench's copied-t8 rows at 31333d4bf4, b5080
entry nvcopybw-nvcopybw-5080-ab-234252); on the RTX 3090's host (a Ryzen 7
7840HS) the 256 MiB kernel-read commit from 14.0 to 11.9 ms and the 64 MiB
kernel-write merge back from 11.2 to 8.8 ms (m3-max-19454). A host that runs
fewer threads at once runs that many.

SPLIT_THREADS is now 8, so a device's comparisons (one at a time under its
copies' lock) hold at most seven more threads at once. The bandwidth bench's
contrast row is now four threads (copied-t4); copied_256_bench_eight_threads,
which measured what is now the default, is gone. Docs say eight.

Tests: run after this commit (copied tests on a host without AVX-512, lavapipe).
2026-11-12 00:47:30 -08:00
Anees Iqbal 13d05be0a4 Copied buffers: a comparison splits across threads from 4 MiB, not 16
SPLIT_BYTES, the fewest bytes each thread of a split comparison takes, goes
from 8 MiB to 2 MiB. A merge back runs about 1.75 GB/s a thread on the RTX 5080
Laptop GPU's host (copied_bandwidth_bench, b5080 entry nvcopybw-bw-before-222944),
so a 16 MiB copy the GPU rewrote merged back on two threads in 4.2-4.5 ms of a
5.4-6.4 ms pass (2.6-3.1 GB/s); a run of 2 MiB takes about a millisecond a
thread, against tens of microseconds to start one. The thread count stays at
most four.

Docs: HOWTO, API and FAST-PATHS said a comparison of a copy with a base of 16 MiB
or more splits; now 4 MiB or more, with a base or without (the copy in with no
base splits since d33e19bc70).

Tests: the split tests take 4 x SPLIT_BYTES (a_comparison_split_across_threads_...,
a_copy_in_with_no_base_splits_...), now 8 MiB. Not run yet.
2026-11-12 00:47:30 -08:00
Anees Iqbal d3a347a1e1 Submission checks: the stall bound's measure; Xid 13 in the host note
On the RTX 3090 (NVIDIA 620.70.06), eight processes of the extra-queues test at once, 6 rounds
(m3-max-19109, the bound built in): 5 of 48 processes' checks met a submission that had not
completed at 10 s, each announced, its verdicts Unchecked, and every process ended (95 of 96 exit
0; the one exit 101 is the process of an Xid 32, whose own wait on its extra compute queue's fence
failed). Every other process's longest wait for a check submission was 1.3 to 12.0 ms; lavapipe's
0.05 ms (m3-max-19057). The same run logged Xid 13 (a compute class c7c0 exception) in one more
process, with no channel-ID allocation failure in the kernel log around it.
2026-11-11 22:43:20 -08:00
Anees Iqbal 430ab46902 The video interop tests run alone on Linux; a host note on the RTX 3090's pushbuffer errors
On an RTX 3090 behind a Thunderbolt 3 bridge (NVIDIA 620.70.06, Linux 7.3.3), six processes of
tests::video_interop::extra_queues_are_made_or_reported_and_the_video_features_enabled at once
(job m3-max-18786) met Xid 69 (class c797, offset 0x1b0c SET_REPORT_SEMAPHORE_D, ErrorCode 0xc,
data 0x2001c00d, itself a valid method header: the GPU read the method stream one word short) in
one process and Xid 32 (intr0 0x40000, PBENTRY) twice in another, 37 ms apart; two copies' empty
submission on the extra compute queue failed its fence wait, and one copy's submission checks
waited on their fence with no end. No PCIe error was logged then. The faulting processes of the
first report (um870, m3-max-18368) were video_interop tests too.

What was ruled out: every runtime VkQueue use holds that queue's lock (the queues audit), and a
probe that tracked each thread inside vkQueueSubmit, vkQueueWaitIdle, vkQueueBindSparse and
vkDeviceWaitIdle per VkQueue saw no two threads on one queue in 240 processes of the same shape
(m3-max-18977: 10 variants x 4 rounds x 6 copies: checks off, merge off, import tax off, no extra
queues, no video extensions, the test's submissions off, the validation layer). None of those
240 met the Xid either, so the variants decide nothing; 1 of the 18 earlier processes did.
Recorded as a host note (HOWTO.md), and the four tests run alone on Linux (.config/nextest.toml),
so no other process makes a device beside theirs.

Not run: a check that running alone avoids the error (it is too rare to show in a short run).
2026-11-11 22:43:20 -08:00
Anees Iqbal 84b6b4295b Copied host buffers copy in again as a batch waits out an event its commit came before
A commit copies into each copied host buffer the bytes the CPU changed in
its pages, before any of the command buffer's work is submitted. A batch
that waits for an event runs its commands only once the event reaches
the value, and on Metal those commands read the pages as they stand
then. So a CPU write made after the commit and before the host's signal
(or before a later command buffer's signal) never reached the copy, and
the waiting command buffer read the bytes from before it.

The commit now notes, before its copy in, the batches that wait for an
event value not yet reached (CopiesAgain::unreached, from each event's
timeline). When the scheduler submits such a batch, which it does only
once the wait is met, submit_batch first copies in again
(copy_in_again): the copies the command buffer reaches, as at the
commit, take the CPU's changes since. This runs with no lock of the
command buffer held, since a copy over logged pages waits for the log's
publication. A batch with no wait, or whose every wait was already
reached at the commit, copies nothing more. The new counter is
WorkCounts::copied_copy_ins_after_waits.

The same mechanism serves a reader held by an event across queues: the
signal of a batch submitted while a copy is live is seen only at its
completion turn, after the merge back. The FAST-PATHS gap that listed
event-ordered reads across queues as stale now says the held reader
copies in again; that case is expected from the code and not run.

Docs: copied.rs (Coherence, the two-memories bullet, copy_in),
dirty_pages.rs (stamps), HOWTO (copied host buffers), FAST-PATHS (cost
row and gap), api_signatures.tsv (the new field).

Verified: waited_reads in the jobs named in the report. The copied leg
fails at cae2e24b4d and passes here; the no-wait copied leg makes 0
copies in again.
2026-11-11 22:35:50 -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 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
Anees Iqbal ea4bbb5fa3 A guest RAM chunk waits while a live import of an object's own holds its pages
reims's pin 42 walks on the RTX 2080 counted imports_inside_live = 1 at boot, once in each of
two walks, in the second the device's thread imported its first chunks ahead (with a 2 MiB
pointer import and host_imports_kept_of_heap in the same second). A no-copy heap made over the
RAM's pages before use_host_ram (or with no run resolver) imports its own pages outside the
RAM's routing, and the thread's import of the chunk holding them then imported those pages a
second time, which VK_EXT_external_memory_host leaves undefined (issue 6).

Now RamOnDevice::chunk holds the chunk back while HostAliases::within finds a live import over
its span (RamOnDevice::held_back): no import, the device's thread marks it tried, an object
over it falls back to the paths of memory no RAM holds (its own import, inside the live
import, or a copy), and copy_take sends copies over it through the CPU. Once every such import
over the chunk went, the next object over it imports it. Counted:
WorkCounts::host_ram_chunks_held_back (api_signatures updated).

Docs: host_ram.rs's module doc no longer describes pointer chunks' runs imported alone (the
2073 fix made those dma-buf-only); it states the held-back chunk. host_aliases.rs,
churn_counts.rs's imports_inside_live and HOWTO's guest RAM paragraph say the same.

Test: host_ram_device::a_chunk_a_live_import_made_before_the_use_holds_waits_for_it_to_go
(a heap over the first chunk made before the use; the thread and a buffer's take hold the
chunk back, the buffer imports its own pages and reads the RAM's bytes, no import inside a
live one; once both went, the next buffer is bound in the chunk).
2026-11-11 21:20:02 -08:00
Anees Iqbal f9999c588c HOWTO: a quiet commit leaves none of its work to be recorded after it
The quiet-commit definition, where a shadow made before its verdicts (or a pooled texture's
shadow of its linear cost) moves in place, named only the uncommitted command buffers, events
and textures bound by ID. The commit also takes the move only where every batch before it was
submitted, every encoder of it may run, and none of its work is left to record after the commit
(command_buffer/storage_form.rs takes_storage_forms; Device::storage_form_switch). Found on
lavapipe: a diagnostic run (m3-max-18654, scratch prints, never landed) showed four compute-only
commits declining the move, each with recorded segments, and a blit's commit taking it
(moved 1, freed 1, the next read copying nothing).
2026-11-11 20:59:50 -08:00
Anees Iqbal 8cb5400e78 Pooled bound: a texture over bytes another texture was made over takes the image at its pitch
A guest's window server makes dozens of textures over each of its large Private surfaces (other
formats of the same bytes, and a new texture each frame), and past the pooled bound each was a
shadow of its linear cost of its own (216 on a Radeon 780M at a login, 1022 in 13 s on an Iris Xe).
storage_over_buffer decided each texture alone: pooled_pitched_image answered LinearCost for any
tracked texture over a Private buffer past 48 KiB, so every texture over the same bytes made a
full image of its own, copied every texel in at its first use, copied in again after a write
through any other (which lets go of its standing) and copied back whole after a kernel's write.
The shadow log names the buffer's object, not the texture's, so one object's two lines 22 ms apart
are two textures over the same surface, a frame apart.

The bound weighed one texture over the bytes. A buffer now notes the runs of bytes textures were
made over (texture_spans.rs, at most 8 runs, joined where they meet), whether those textures
still live: a texture over bytes another texture was made over takes the DRM_FORMAT_MOD_LINEAR
image at Metal's pitch at any size, as over CPU-visible memory, and the first texture's shadow of
its linear cost moves to that image once another texture is made over its bytes, through the
existing pooled move (wait_to_move_in_place: at the next quiet commit, with no copy). Both forms
give Metal's answer; the textures alias the bytes as Metal's do. The bound has no FAST-PATHS row:
it chooses between two exact speeds (6717cac4ea). API.md, HOWTO and the LinearCost docs say so.

Verified: cargo fmt; builds and device runs follow as potluck jobs.
2026-11-11 20:59:46 -08:00
Anees Iqbal b11e59ec86 Records carry a compute state's dispatches, and the warm pass makes their pipelines
A compute state whose descriptor requires no threadgroup size predicts no
VkPipeline at its creation: the local size and the threadgroup memory
lengths are the dispatch's own calls, so its creation's record made none of
its dispatches' pipelines on a later warm pass, and each was a cold driver
compile at the program's first dispatch of its shape (the 12.7.6 kernels'
case in FAST-PATHS).

Now, where the device hands records over, a compute state's direct dispatch
(dispatchThreadgroups: or dispatchThreads:) whose regions' pipelines were not
all made hands the hook one more record: the creation's descriptor, as its
own record holds it, and the dispatch (its threadgroup, a dispatchThreads:
grid reduced to one whole threadgroup and its ragged edge per axis, and the
encoder's threadgroup memory lengths). Each such dispatch once per state, at
most 16 a state (pipeline/dispatch_record.rs). A warm pass that creates such a
record's state then plans the dispatch as a creation's prediction plans its
first one (nothing bound but the default samplers), with the recorded
lengths, settles its variant as a dispatch does, and makes each region's
VkPipeline on the pass's thread, so their driver data lands in the records
under the names the program's dispatch of that shape asks for.
WarmStatistics::dispatch_pipelines_warmed counts them. Indirect dispatches,
dispatches of a threadgroup range and tile dispatches record nothing.

Records are immutable, one per dispatch shape, so a consumer keeps each once
and needs no rule for which supersedes which. The record format moves to 7:
a compute record's bytes now end in its dispatch list (count, then each
dispatch), so a format-6 record reads as none. The codec bounds the list at
16 dispatches and 31 lengths each, both when writing and when reading.

Tests: warm_record round-trips a compute record with a dispatchThreadgroups:
and a ragged dispatchThreads: carrying two threadgroup lengths, and bounds the
list (more than 16 is unwritable; bytes claiming 17, resealed, are no record;
16 read back). The device test
a_warm_pass_makes_the_pipelines_of_the_dispatches_its_records_name records a
state's creation and first dispatch, checks that the same dispatch again and a
grid of the same edge make and record nothing, warms both records on a
device over the same directory (dispatch_pipelines_warmed equals the regions
the recording dispatch made), and checks that the program's first dispatch
there hands each of its makings the driver cache the pass filled
(caches_shared) and translates nothing. A control device warmed with the
creation's record alone makes no dispatch pipeline and shares no cache.
Verification is in the report to main (potluck lint and lavapipe jobs).

Docs: the runtime README, HOWTO and FAST-PATHS ("Made again before the
program asks") describe the dispatch records; api_signatures gains the
WarmStatistics field.
2026-11-11 19:10:38 -08:00
Anees Iqbal b3a9bda684 Docs: copied-host-pages names pages a live import holds some of; listed runs alone described where they stay
API.md's copied-host-pages entry gains the over-a-live-import cause
(copied_over_live_imports, announced once per device as the others are).
HOWTO's listed-plan paragraph described its runs alone "as above", text
the previous commit removed: it now says what a listed RAM's run import is
(a dma-buf), what it costs, how it orders, and that MoltenVK and ANV import
the chunk instead.
2026-11-11 19:01:50 -08:00
Anees Iqbal d76f7f7ee7 One page, one import: no run of a guest RAM chunk imported alone by its pointer
An object over a chunk not imported yet, and a copy over one, was bound in
an import of its own run alone, made by the run's host pointer while the
device's thread imported the whole chunk by its pointer: two live imports
of the same host addresses, the run's freed while the chunk's lived.
VK_EXT_external_memory_host leaves the same host allocation imported twice
undefined (issue 6). Runs are now imported alone only on a listed plan,
whose chunks and runs are dma-bufs of the RAM's source, and a run's import
never falls back to its pointer. Elsewhere every object and copy over a
chunk lies in its one import, made or waited for, as on MoltenVK and ANV.
The price is a making that waits for a chunk the window has not reached.

imports_inside_live now counts every import made over host addresses a
live import holds: a no-copy object's own import over another's (heaps
included) or over a live chunk import at the same addresses, and a
chunk's import over a live no-copy import, on the making and rebind
paths. A new evidence counter, imports_over_ram_chunk_pages, counts a
view's own import whose guest RAM pages a live chunk import holds at the
RAM's addresses. host_ab prints both and buffers_bound_in_import.

Not yet verified: built and tested next on lavapipe.
2026-11-11 19:01:50 -08:00
Anees Iqbal 2abe74f6f1 Docs: say what an in-place dma-buf texture lists now, without the history
The host_residency module doc and HOWTO section 6 told what a guest surface
listed before the in-place texture stopped pinning its buffer's import; docs
say what is true now. Text only.
2026-11-11 17:14:20 -08:00
Anees Iqbal 9b2ef7c237 A texture in place over a dma-buf import leaves the buffer's import releasable
RADV lists every imported VkDeviceMemory in every kernel submission, about
0.43 us each on the Radeon 780M and the RX 7900 XTX (a from-scratch Vulkan
probe, Mesa 26.2.6, Linux 7.3.3: 64, 256 and 512 dma-bufs held cost 31.5,
111 and 229 us an empty vkQueueSubmit against 7.2 with none). A consumer's
guest surface is a no-copy buffer over its pages and a texture in place over
the buffer: on RADV the texture is a DRM_FORMAT_MOD_LINEAR image in a
dedicated import of a dma-buf of its own pages, and making it read the
buffer's import apart (ReadApart::Texture), which kept the buffer's import
for good. So each surface listed two imports in every kernel submission for
its whole life.

The image asks the buffer's source for its own pages and binds none of the
buffer's memory, so its making now reads the buffer's dma-buf pages as a
blit does (HostImport::blit_pages: imported again where released, left
releasable), and the in-place watch a rebind reads takes the texels' offset
from the buffer's place in its host pages (Buffer::offset_in_host_pages),
not from their import. The buffer's import is then released after its idle
window like any blit-only one; the texture's image keeps its own import.
Pointer-imported pages, shadows and texel views still read the import apart:
they bind or read the buffer's memory.

Test: tests/host_residency.rs
a_texture_in_place_over_a_dma_buf_import_leaves_it_releasable: the buffer
under an in-place texture is released (its chunks leave
dma_buf_memories_live, the image's import stays), the texture reads the
CPU's writes made meanwhile without importing anything, and the buffer's
next blit imports it again. Without the change the release never comes.
Docs: host_residency.rs, HostMemory::with_dma_buf, HOWTO.md.
2026-11-11 17:14:20 -08:00