Commit Graph
141 Commits
Author SHA1 Message Date
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
Anees Iqbal edbd81a4df Docs: a copied host buffer's device base, its host blocks and its reads back on the staging queue
FAST-PATHS' base bullet gives the host's uncached reads of a device base (9-16 us a block
awake, 170-206 us idle on the RTX 5080 Laptop GPU's host), the blocks kept on the host, the
read back of 32 blocks or more on the staging queue with the crossover bench's figures on
the 5080 and the RX 7900 XTX, the GPU's wake from power-down a copy may wait for, and the
first and later merges back of a 256 MiB copy both sides wrote whole. Its cost bullet gives
the quiet gem10 run's figures (job 17408), and its kernel bullet the 5080's pass figures
(job 17417). HOWTO and API.md name copied_base_host_blocks and
copied_base_blocks_read_back.

Earlier commits 4af4a8665b and 7a93903404 carried doc edits with their code (the split's
sentence in API.md and HOWTO, copied.rs's cost bullet).
2026-11-11 15:32:27 -08:00
Anees Iqbal d2f862c193 Copied host buffers: a split comparison's threads take their runs with the runs' lock let go
The pull loop's while-let held the lock of the runs' iterator through each run's work,
so the threads took their runs one after another. The lock is now let go before the
work, as a let statement drops its temporaries.
2026-11-11 15:32:23 -08:00
Anees Iqbal fbbf6322a1 Runtime tests: the 256 MiB copied bench prints the bytes copied in and merged back, and their rate 2026-11-11 15:32:22 -08:00
Anees Iqbal 8ddde3eec8 Docs: where a copied buffer's base lies, as copied_base_type decides it (a heap of 1 GiB or more) 2026-11-11 15:32:21 -08:00
Anees Iqbal 755656ccd8 Docs: a copied host buffer's base is made at its first writer, tagged per 1 KiB, its bytes in VRAM where a resizable BAR has room
HOWTO's copied-buffer section and API.md's copied-host-pages notice say what a copied
buffer holds beyond its copy and which WorkCounts count it.
2026-11-11 15:32:18 -08:00
Anees Iqbal f0cdff884d Runtime: a two-copy buffer's rebind makes a new host copy; a texture leg; the docs
A rebind of a Managed no-copy buffer with a device copy makes a new host copy
of the new pages as the making does (an import made as HostCopy, never a
copied.rs copy, or the pages alone), in place of the old, which goes once
nothing holds it, and copies the pages in whole: a rebind whose import the
gate refuses no longer stacks a copied host buffer under the device copy.

Tests: a texture over a two-copy buffer follows its device copy (its GPU
reads after the making, did_modify_range and replace_region, and its
synchronize_resource).

Docs: the runtime's guide (the memory model, host memory without a copy,
host_backing, the recovery), docs/API.md (the two-copy paragraph beside the
Managed device-copy textures, which now reach only buffers that lie in their
pages, and device-memory-overflow), HOWTO (copied host buffers: a two-copy
buffer is never one; did_modify_range is the contract).
2026-11-11 11:22:53 -08:00
Anees Iqbal 63bbaa086d Submission checks: remove the follows check; release idle pointer imports where a held one costs
The device's submission checks ran a "follows" check at every Linux device's creation: they
imported two pages of their own by pointer, submitted a copy, mapped new anonymous pages over
the first page (mmap MAP_FIXED) while that import lived, copied again, and only then freed the
import. That remap under a live host-pointer import is outside VK_EXT_external_memory_host's
contract ("Whether device memory objects imported from a host pointer hold a reference to their
payload is undefined ... the application must ensure that the imported memory range remains
valid and accessible for the lifetime of the imported memory object"), so the verdict rested on
undocumented driver behaviour, and it ran on every device's making.

Its one reader was the idle release of a no-copy buffer's pointer import (host_residency.rs,
Again::pointer). Under HostMemory::new's contract the pages at the pointer stay the same while
the buffer lives, so an import again at the same pointer reads what the kept one read on every
driver: "follows" mattered only for remaps that break the contract. The release is now gated on
what it is for, the per-submission cost of a held import, which the existing import tax check
measures (32 imports of 16 MiB in all held through timed submissions):
- RADV and ANV on i915 pay it: idle pointer imports are released, as before.
- NVIDIA's driver (RTX 5080 Laptop GPU, 615.71.09: 2.1-2.2 us a submission with and without
  held imports) and MoltenVK pay none: pointer imports stay imported, as before on NVIDIA, now
  because a release would save nothing and cost the next blit an import.
- lavapipe, which the follows check answered yes on, is released only where its tax check
  answers Holds.
Buffers made before the check answered keep their imports, as before.

Changes:
- submit_check.rs: the follows check is gone (its remap, its bound buffer, its copy command
  buffer, Check::Follows). A record holds two verdicts; CHECK_VERSION 6 -> 7, so earlier records
  are never read and every driver measures again. The checks' pool no longer resets command
  buffers (only the copy was re-recorded).
- Public API, breaking: Device::pointer_imports_follow_their_address is removed. A hidden lane
  accessor, Device::releases_idle_pointer_imports, says whether the device releases idle pointer
  imports. api_signatures.tsv re-blessed for both. reims-vgpu's no_copy_remap_linux.rs test
  called the removed method (main is telling reims).
- Docs: HOWTO section 6, the FAST-PATHS known gap about remaps (now: what a no-copy buffer reads
  after a remap under it is unspecified; a released import's next blit imports the new pages; the
  RADV file-page loss stays), the RADV per-page cost gap's gate, Device::host_range_remapped,
  host_memory.rs, host_residency.rs, KeptBecause and WorkCounts docs, the validation lane.
- Tests: the pointer residency and unmap-order tests hold the device to the release
  (SubmitChecks::force on the import tax), so the release path runs on every Linux device
  whatever load does to the check; a new test checks the natural gate
  (an_idle_pointer_import_is_released_where_held_imports_cost_submissions), and a new device test
  checks a device's checks make and bind no buffer and free every import by their answer
  (a_device_s_checks_map_no_pages_over_a_live_import: on Linux it fails with the follows check,
  which made and bound two buffers).

RUNTIME_VERSION is not bumped here (bumped and re-pinned at landing).
2026-11-11 09:32:34 -08:00
Anees Iqbal daf963ab80 Docs: on NVIDIA, a device kept to the exit can fault in the driver's own exit handler
What: FAST-PATHS's known gap of NVIDIA exits now names the cause and the measured rates, and
HOWTO (section 8), the runtime README (at the process's exit) and API.md's accepted differences
tell consumers to drop the runtime's devices before the process exits on that driver.
exit_guard.rs and tests/exit_guard.rs, comments only, say that the 5080's fault in
libnvidia-glvkspirv.so also comes with no making in progress.

Why: reims-vgpu's test an_adopted_device_starts_its_in_place_check (device kept in a static,
check waited for to its end, then the test process exits) died with SIGSEGV after "ok" on the
RTX 3090. Reproduced with the runtime alone (a scratch example: device made on a named thread with
an empty shader cache of its own, in-place check started and waited for, device kept, main
returns). Every core shows the same thing: a worker thread of NVIDIA's driver, started from the
thread that made the device and so carrying its name, faulting at libnvidia-glvkspirv.so+0x363a8
(`mov 0x18,%rax; ud2`, a null dereference trap) while the main thread runs libEGL_nvidia.so's exit
handler inside exit(). No runtime thread was in a section or in the driver. reims's two cores
on that node (pids 106291, 170154) faulted on a thread named after the test thread, which libtest
joins before printing "ok", so a thread the driver started.

How verified (RTX 3090, NVIDIA 620.70.06, 8 processes at once, 80 exits each):
- exit right after the check ended, device kept: 6/80 SIGSEGV (potluck m3-max-16257)
- exit 3 s after the check ended: 0/80 (m3-max-16279)
- device dropped before the exit: 0/80 (m3-max-16280)
- no check, exit right after creation / 6 s after: 0/80 each (m3-max-16278, m3-max-16277)
- lavapipe (Mesa 26.2.6), exit right after the check: 0/20 (m3-max-16283)
Vulkan has no call that waits for the driver's worker, and a dropped device leaves none, so
the remedy is the consumer's drop, documented; no runtime behaviour changes.
2026-11-11 09:04:14 -08:00
Anees Iqbal c5bd14c18c HOWTO: an import's last holder can be a texture's image; the measured unmap failure is ANV's
Two claims of "Unmapping host memory" cut to their evidence: with neither a deallocator nor a
keep-alive, a texture released while a command buffer submitted before may read it holds the import
until that command buffer completed (HostMemory::new's contract says so); and the failed
submission with the device lost after an unmap is ANV's (host_residency.rs's measurement), not
measured on RADV.

Verified: docs only.
2026-11-11 09:03:24 -08:00
Anees Iqbal b1a1c67f68 Host memory: state when a program may unmap a no-copy object's pages, and test the order
A Radeon 780M under Linux 7.3.3 oopsed in amdgpu's mmu notifier (amdgpu_hmm_invalidate_gfx,
LIST_POISON2 in a bo_va's status list) while a consumer's thread unmapped a view whose pointer import
was still alive; the consumer dropped the import after the unmap. VK_EXT_external_memory_host
(VkImportMemoryHostPointerInfoEXT): "the application must ensure that the imported memory range
remains valid and accessible for the lifetime of the imported memory object". vkFreeMemory: a
bound buffer or image may hold the payload until it is destroyed. So the objects go first and the
pages after.

The runtime already keeps that order, and this commit changes no behaviour. A no-copy object's
keep-alive is dropped, and with none its deallocator runs, only after its import's vkFreeMemory
returned, on whichever thread freed it. That covers the releasing thread, a queue's thread at the
completion of the last command buffer that held it, a handler thread where a keep-alive alone
waits, and the import made again after the residency thread released it while idle. Imports never
go to the free thread. The one exception is a buffer lying in another live buffer's import, whose
own contract keeps the pages mapped.

The order was spread across private module docs. It now has one statement where consumers read:
- docs/HOWTO.md, "Unmapping host memory": the spec's rule, each object's signal, the threads that
  free imports or submit over them, and what an unmap made first did;
- the runtime README's host-memory bullet;
- the rustdoc of HostMemory::new (the spec's rule, and when a command buffer lets go: after its
  completed handlers, before wait_until_completed returns), Deallocator, KeepAlive and
  Device::host_range_remapped. That call's "they may be unmapped" read as a licence to unmap under
  a live buffer; it now says the call does not mend that.

New device test tests/unmap_order.rs (Linux, m2v_cpu_icd or m2v_gpu):
- 48 rounds. Each round covers a released buffer, a buffer released while a committed copy of it
  waits for an event, and (where pointer imports follow their address) a buffer whose import was
  released while idle and made again by a blit. Each case runs with a keep-alive and with a
  deallocator.
- Another thread submits copies between the device's own buffers throughout.
- Each signal reads WorkCounts::host_imports_live, which must already be back at its baseline,
  then unmaps the pages.
- It asserts that the held cases signalled on a runtime thread and not before the event, that the
  idle releases and imports again counted 96 each, and that every command buffer completed with no
  device loss or recovery.
2026-11-11 09:03:24 -08:00
Anees Iqbal a41f025ebd Runtime: a dma-buf import that backs one buffer alone is retried dedicated to it
NVIDIA's 615.71.09 (RTX 5080 Laptop) refuses an import of a small udmabuf
dedicated to nothing (ERROR_OUT_OF_DEVICE_MEMORY: one 4 KiB page refused,
64 KiB taken, measured by a probe) and takes the same page dedicated to its
buffer. Two device tests failed there: a guest RAM's use asked the driver
with its first page, the refusal was remembered for the device's life, and
every chunk was then copied; a no-copy buffer's 16 KiB window was copied.

- memory.rs: import_dma_buf takes what the memory backs (DmaBufFor): an
  image (dedicated to it), shared memory (dedicated to nothing), or one
  buffer alone for its life, tried dedicated to nothing in every type and,
  where the driver refuses each, dedicated to the buffer in every type.
  That is Vulkan's documented form for one buffer's memory; no driver name
  or size rule decides it.
- dma_buf.rs: chunks_buffer/import_chunks pass the buffer where the caller
  binds nothing else in the import and the buffer is not sparse: a no-copy
  buffer's own import (never a heap's), its residency re-import, a copy's
  list of a RAM's runs, and the page a RAM's use asks the driver with. A
  RAM's chunk or run is never dedicated: its objects' buffers bind in it.
- A RAM's dma-buf refusal is remembered only where it lasts
  (not_importable: the driver refuses the dma-buf itself, or no type takes
  it); memory that ran out is that import's alone.
- WorkCounts::dma_buf_buffer_imports_dedicated counts the dedicated retries.
- Tests: two stand-in driven device tests (a no-copy page refused
  undedicated takes a dedicated import; a RAM's page is asked dedicated and
  the RAM listed while chunk refusals for want of memory are not
  remembered); the three remembered-refusal tests use the lasting
  ERROR_INVALID_EXTERNAL_HANDLE; the two NVIDIA-failing tests print the
  dedicated count.
- Docs: FAST-PATHS's NVIDIA dma-buf gap, HOWTO, the counters' docs.

Verification: in the following jobs (3090, 5080, PHOENIX, clippy x3).
2026-11-11 06:56:33 -08:00
Anees Iqbal addc45b2e1 Dma-buf imports fall back to the dma-buf's other memory types; NVIDIA imports a udmabuf as its type 0
On NVIDIA (RTX 3090, 620.70.06; RTX 5080 Laptop, 615.71.09) every
import of a udmabuf failed, so a no-copy buffer over sourced memory on a
device that imports no pointer was a copy ("their import failed"), and a
guest RAM's chunks there were never imported (the RAM not listed, its
objects copies): host_ram_dma_buf::without_pointer_imports_a_ram_s_chunks_are_its_dma_bufs
and no_pointer_import::without_pointer_imports_a_sourced_no_copy_buffer_lies_in_its_dma_bufs
failed on both GPUs in the round at b4cd0f9f91.

Cause, from a probe on the 3090 (job m3-max-15245, branch
steelbrain/hkhostmem-2-probe, not for landing): vkGetMemoryFdPropertiesKHR
answers memoryTypeBits 0x11 for a udmabuf of a sealed memfd, types 0
(heap 1, no property flag) and 4 (heap 1, host-visible, coherent and
cached). The import into type 4 answers ERROR_OUT_OF_DEVICE_MEMORY with
or without a dedicated allocation and the device-address flag; into
type 0 it succeeds in all four forms, for one page and for 16. The
runtime asked only the class's types (Shared requires host-visible
coherent memory), so it tried type 4 alone.

Fix: import_dma_buf tries dma_buf_candidates: the class's candidates
first, unchanged, then every other type the dma-buf and the resource
allow that the runtime may allocate and that is neither protected nor
lazily allocated. The runtime never maps a dma-buf import (the CPU uses
the caller's mapping), so a type the host does not map serves it. On
drivers whose class types import the dma-buf (RADV, lavapipe, ANV) the
order and the result are as before.

The docs that said NVIDIA refuses every udmabuf now speak of a driver's
refusal; the tests' stand-in for one is unchanged.

Tests: tests::memory::dma_buf_imports_try_the_class_s_types_then_the_dma_buf_s_others
(the 3090's types). The two device tests are unchanged: they hold on
NVIDIA once its driver imports the udmabuf.
2026-11-11 05:37:06 -08:00
Anees Iqbal ac0fcfa7fd Docs: a texture over dma-buf pages bound at its texels' offset, where the driver answers another plane offset
What: HOWTO's dma-buf section and API.md's in-place and shadow-cause paragraphs say when a texture
over dma-buf pages takes an image of a plane at offset 0 bound at the texels' offset (a driver
that lays the explicit plane out at another offset, Honeykrisp's answer; an image that requires
no dedicated allocation, which RADV requires, and whose alignment divides the offset), counted in
WorkCounts::dma_buf_images_at_offset; WorkCounts::dma_buf_image_memories_live says such an import
is no dedicated one.

Verified: tests::dma_buf_plane_offset on RADV PHOENIX (requires a dedicated allocation: the
forced route is refused, the texture a shadow that reads its texels) and on lavapipe (Mesa
26.2.6: the forced route binds at offset 2048, in place, and reads its texels and the CPU's later
bytes).
2026-11-11 05:10:15 -08:00
Anees Iqbal 1f7b2a67cf No-copy memory with no dma-buf source is a copy on a device without VK_EXT_external_memory_host
On a device that imports no host pointer but imports dma-bufs (Honeykrisp
on Asahi lists no VK_EXT_external_memory_host), a no-copy buffer or heap
over memory with no source of dma-bufs was refused, naming the extension.
Metal makes such a buffer, and in place is impossible there, so it now
takes the copy a refused pointer with no source takes on RADV
(CopiedFor::DeviceRefused): announced as copied-host-pages, counted in
copied_host_buffers_device_refused, with every copy's coherence.

How: host_window marks such pages pointerless (the device imports no
pointer, the memory is not dma-buf-only). buffer_over_host_parts no
longer takes the no-route refusal for them, so they reach
import_by_pointer, whose not_importable answer is the device's refusal;
a source that fails counts as the device's refusal there too, as on
RADV. Rebinds to such memory, a guest RAM with no source, and every
no-copy object on a device with neither route stay refused, naming the
extension. The in-place check no longer makes its pointer-class buffer
on a device that imports no pointer (it would be an announced copy now);
its verdict there stays lasting, as before.

Docs: the copied-host-pages detail, CopiedFor, CopiedBecause and the
counter, copied.rs, host_memory.rs, the no-copy buffer and heap calls,
imports_shared_host_pointers, host_ram/copy.rs, the runtime README, the
API catalogue and HOWTO section 6. docs/REFUSALS.md regenerated:
unchanged, as the extension's refusal sites all remain.

Verified by the device test in the previous commit (lavapipe and the
780M, see the hand-off).
2026-11-11 04:09:01 -08:00
Anees Iqbal fcd4dfdc36 HOWTO section 7: what an opaque file descriptor's import names, in a shared block or not
What: docs/HOWTO.md section 7 says how CUDA and another VkDevice import export_memory_fd's
descriptor: ExportedMemory's allocation_size as the import's size, the dedicated flag only where
`dedicated`, the buffer at `offset` for `length` bytes, and that a buffer outside a dedicated
allocation lies at an offset in a block other exportable buffers share, which the import reaches
whole.

Why: the previous commits keep an exportable buffer out of a dedicated allocation where the
driver only prefers one, so on NVIDIA its export now answers dedicated false, a non-zero offset and
the block's size where it answered dedicated true, offset 0 (or the aligned byte's lead) and the
buffer's own size. ExportedMemory and Buffer::export_memory_fd already carried those fields and
said so; the guide showed only the dma-buf import. No API change.

Verified: docs only. cargo fmt --all.
2026-11-11 03:56:01 -08:00
Anees Iqbal d203c0b5f4 Runtime: an exportable buffer takes a dedicated allocation only where the device needs one
What: exportable_buffer's buffer is its own dedicated allocation where the device exports
such memory only so (DEDICATED_ONLY) or requires one (requiresDedicatedAllocation); a
driver's preference (prefersDedicatedAllocation) alone no longer makes one, so the buffer
lies in the block exportable buffers of its handle type share. Docs: exported_memory.rs
(module and Device::new_exportable_buffer), memory.rs (module, NoImage::Dedicated),
texture.rs, the runtime README and docs/HOWTO.md section 7 say the same.

Why: no image may be bound to a dedicated allocation (VUID-vkBindImageMemory-memory-10926)
and a texture over an exportable buffer is an image in its memory, so on NVIDIA (reims's
RTX 5080 Laptop, 615.71.09) every texture over the consumer's exportable caches was a
shadow, ShadowCause::Unchecked (2862 of 4112 IOSurface-plane shadows; 12.4 MB copied in per
plane use, 30 MB back per composite). The owner's rule: a texture over exported memory stays
in place even if slower; a shadow only where in place is impossible.

Verification pending (parked for the 780M regression): tests::export_dedication on the
3090 at c63787840b (the measurement and negative control) and at this commit; clippy and
the 5080 entry still to run. cargo fmt --all.
2026-11-11 03:56:00 -08:00
Anees Iqbal 02a64274c5 Pages with no route of their own may still lie in a guest RAM's chunk
On a device that imports no host pointer, an object over a guest RAM the device uses
(HostMemory::with_runs) with no dma-buf source of its own was refused by host_window before its
runs were routed to the RAM's chunk, so tests::host_ram_dma_buf::
without_pointer_imports_a_ram_s_chunks_are_its_dma_bufs failed on the Radeon 780M (RADV) and on
lavapipe (jobs m3-max-14705 and m3-max-14707): "HostMemory needs ExtExternalMemoryHost" at the
object, after the RAM was taken.

host_window no longer refuses; HostWindow::no_route is the refusal of pages with no route of their
own (not their pointer, no usable source, no copy), the same as before: naming
VK_EXT_external_memory_host on a device without it, not_importable elsewhere. A no-copy buffer,
heap or rebind with no runs is refused with it at once, as before; one with runs is refused with it
only where its pages lie in no chunk and an import of its own is needed. On a device that imports
pointers, by_pointer holds wherever the import alignment covers the range, so nothing changes
there; only where it does not (an alignment past the host page) may such an object now bind in a
chunk instead of being refused.

Docs: the no-copy buffer and heap refusals and HOWTO section 6 say a chunk-bound object needs no
source of its own.
2026-11-11 03:34:56 -08:00
Anees Iqbal 12a8a907bc No-copy buffers on a device without VK_EXT_external_memory_host take the dma-buf route
On a driver that lists no VK_EXT_external_memory_host but imports dma-bufs (Honeykrisp on Asahi, as
the consumer reported: a macOS guest's newBufferWithDescriptor answered nil, "HostMemory needs
ExtExternalMemoryHost", 704 times in one boot), every no-copy buffer, heap and guest RAM was
refused: Importer::new refused before the dma-buf route was looked at, and the importer held the
host-pointer extension's functions unconditionally.

The importer now holds the pointer import as an option (host_memory.rs's PointerImport: its
functions, page and minImportedHostPointerAlignment, and memory_types). Importer::new refuses only
where the device imports neither pointers nor dma-bufs (the pointer's refusal, naming the
extension, as before); a device with dma-bufs alone gets an importer whose pointer refusal stands
for every pointer (Importer::pointer_import). Every pointer-import site takes a PointerImport, so a
device without one never makes a host-allocation object: buffer_descriptor.rs (import_by_pointer,
import_pointer, import_pointer_again, import_backing), host_shared_pointers.rs (false there),
fresh_pages.rs and the page-buffer blocks (none there), the submission checks (unchecked there),
host_ram.rs's chunk import by pointer. The unit an import's pages round out to is
Importer::unit: the host page and the import alignment where the device imports pointers, the host
page alone where it imports dma-bufs. Every device that imports pointers keeps the same calls.

On a device that imports no pointer:
- a no-copy buffer, heap or rebind over memory with a source is bound in imports of its dma-bufs;
  memory with none is refused, naming VK_EXT_external_memory_host (host_window), as it was;
- memory of Metal's private option bit 24 that the runtime copies anyway (no read-only view on
  Linux) is no longer refused for lack of an import route, on any device;
- a guest RAM with a source is taken and listed (its chunks its dma-bufs, imported on demand), the
  pointer never tried; one with no source is refused, naming the extension, as it was;
- supportsResourceDetachBacking answers whether the device makes no-copy buffers (it has an
  importer), not whether it lists the extension.

Docs: the runtime README, HOWTO section 6 and the RAM copies' refusal, RUNTIME-PORTING, the
module docs of host_memory.rs, dma_buf.rs and host_ram.rs, HostBacking::ImportedAsDmaBuf, and the
refusal lists of the no-copy buffer, heap, RAM and RAM copy calls. docs/REFUSALS.md regenerated
(the HostMemory refusal's sites: PointerImport's and no_pointer_refusal).

Verified: the next commit's device tests (RADV on the Radeon 780M, lavapipe), which fail at the
base with the refusal; job ids in the branch's report.
2026-11-11 03:34:56 -08:00
Anees Iqbal 7d17fb1882 Guest RAM: a refused dma-buf keeps run lists and listed plans off the driver
Three follow-ups to remembering a driver's refusal of a guest RAM's dma-buf
(3fe18c4efd):

1. Run-list imports consult the remembered refusal. ram_runs_as_dma_buf now
   returns not-importable, the source of run lists unasked, once the device
   remembers a refusal, and remembers the driver's own refusal of a list's
   dma-buf the same way a span's is (the source's failures stay the list's
   alone). Before, every copy over a chunk not imported asked the source of
   run lists again and paid a udmabuf and a failed import.

2. A RAM's plan asks the driver before it lists the RAM. Plan::listed means
   the RAM's chunks are its dma-bufs; it was chosen from the import tax alone,
   so on a taxed driver that refuses udmabufs (NVIDIA 615.71.09) the RAM got
   512 MiB chunks imported by pointer, none ahead. ram_plan now, where the plan
   would be listed, asks the driver with the RAM's first host page
   (Device::ram_takes_dma_bufs: ram_span_as_dma_buf over one page, released at
   once, the precedent being shared_refused's one-page question), and lists the
   RAM only where the driver took it. A refusal there is counted and
   remembered, so the RAM and every RAM after it keep 64 MiB chunks imported
   ahead by pointer. Re-choosing a live RAM's plan was rejected: its chunk
   geometry and its thread are fixed when the use begins. discard_import takes
   the raw VkBuffer so the question's import can be released.

3. The listed tests (where_each_listed_import_costs..., where_the_ram_fits...,
   the two tile tests through copies_by_lists) no longer expect dma-buf imports
   wherever the measured tax holds. They force the tax held, so the listed path
   runs on every device in every run, and read the plan the device chose
   (Device::host_ram_chunks), asserting it is listed exactly where the device
   imports dma-bufs and the driver took the use's page. The resident test now
   allows the use its one page.

Tests:
- a_driver_s_refused_dma_buf_sends_copies_past_the_source_of_run_lists (new):
  stand-in refusal set after a listed use; the first copy asks the source of
  run lists once and the source of dma-bufs not at all, the second asks
  neither (fails without the consult or without remembering a list's refusal).
- a_driver_s_refusal_as_the_use_begins_keeps_the_ram_s_chunks_short (new):
  stand-in refusal before the use; the RAM is not listed, the source asked for
  the first page only, the refusal counted once (fails without 2).
- a_driver_s_refused_dma_buf_sends_the_device_s_later_chunks_to_their_pointer:
  the stand-in now refuses after the use; a RAM used after the refusal is not
  listed and its source is unasked.
- The route test reads the use's question and the plan.

Docs: host_ram module, use_host_ram, WorkCounts, HOWTO and the FAST-PATHS
NVIDIA dma-buf row describe the question and the remembered refusal.

Verification: in the follow-up message (gem10 lavapipe suite and negative
controls; 5080 release).

(cherry picked from commit 77f336e98c2a31aa56e45c5eb7659fa28f6f3ad6)
2026-11-09 11:39:45 -08:00
Anees Iqbal 3fe18c4efd Guest RAM: a driver's refusal of a span's dma-buf is remembered for the device's life
Counting the refusal left its cost: on a device whose import tax holds and whose driver refuses
every udmabuf (NVIDIA 615.71.09, FAST-PATHS), every guest-RAM chunk asked the source for a dma-buf,
failed vkAllocateMemory, let go of one descriptor (the driver closes the clone it was handed) and
only then took its pointer.

ram_span_as_dma_buf now tells the source's failures (an error, or an answer of other lengths:
that span's alone, counted) from the driver's (anything once the source answered one dma-buf of
the span: its memory types, the buffer, the import, the bind). A driver's refusal is counted once
and remembered in the device's RamSource; every later span is refused at once, unasked and
uncounted, and takes its pointer. The decision reads the device's own answer, never its identity.
A transient failure of the driver's (memory that ran out) is remembered the same way, recorded in
FAST-PATHS' NVIDIA row.

Tests: a_driver_s_refused_dma_buf_sends_the_device_s_later_chunks_to_their_pointer forces the tax
held and refuses every dma-buf import through a test stand-in for the driver (Memory::import_refusal,
cfg(test), answered where the driver's import would run), on every device that imports dma-bufs:
two chunks, the source asked once, the failed count 1, the second chunk by its pointer. The route
test, where the driver itself refused (NVIDIA's), makes a buffer over the RAM's second chunk and
asserts the same with the real driver. Without the remembering both ask the source a second time.

(cherry picked from commit abddf2d2f1ed16a5ee6407cae04f7e10dfffb736)
2026-11-09 11:05:12 -08:00
Anees Iqbal 98729ad0de Guest RAM: a chunk's dma-buf the driver refuses is counted; the route test forces the tax held
On the RTX 5080 (NVIDIA 615.71.09) pin 29's runtime half failed
host_ram_dma_buf::a_ram_with_a_source_takes_the_route_its_device_s_checks_choose: that process's
import tax answered Holds, the chunk went dma-buf first, the source was asked, and no dma-buf was
imported. A probe printed the refusal: vkGetMemoryFdPropertiesKHR gives the udmabuf types 0x9,
the buffer takes 0x1f, and vkAllocateMemory answers ERROR_OUT_OF_DEVICE_MEMORY (the refusal
FAST-PATHS already records for NVIDIA). import_chunk dropped that error and took the pointer, as
it should, but nothing counted it, and the test held every taxed device to a dma-buf import.

- WorkCounts::host_ram_dma_buf_imports_failed counts a guest RAM span's dma-buf that failed on a
  device that imports dma-bufs (the source failed or answered other lengths, or the driver
  refused it); ram_span_as_dma_buf counts it past its device check.
- The route test (now where_the_import_tax_holds_a_chunk_takes_its_dma_buf_first) forces the tax
  held, as the pointer-first test forces it not held, so the taxed route runs on every device in
  every run, not only in a process whose check measured a tax. It asserts the source asked once
  for the chunk, and the dma-buf imported or refused and counted, the pointer then taking it; it
  prints the verdict the device measured beside it.
- HOWTO, FAST-PATHS' NVIDIA dma-buf row, host_ram's docs and the API signature table name the
  count.

Verified: the probe at 3f3ca70d32 on the 5080 (b5080 t entry exitcrash-dmabuf-100324): with the tax
forced held, 2 of 2 runs failed the old assertion with the refusal above; quiet runs measured the
tax not held (3 of 3). This commit's own runs are in the next evidence.

(cherry picked from commit a6ccb78810867a4d567892feee4b3b56ba1af834)
2026-11-09 11:05:12 -08:00
Anees Iqbal 7ed49fd04d RADV fuses float arithmetic into a half conversion: the pipeline records NativeHalfConversion
On the Radeon 780M (RADV PHOENIX) runtime_lane::half_conversions failed its product kernel:
2.6822087e-7 * 1.0000001 answered half 0x0005 where Metal's half of the float product is
0x0004, with notes only [NativeNanEncoding] (radvruns job 11026, 2 of 2 runs). The module
rounds under the float controls (QuantizeForm::Controlled), which make the conversion Metal's,
so it recorded no conversion note. RADV_DEBUG=shaders on the 780M (job 11121) shows why: ACO
compiles the product's OpFMul and the narrowing, both decorated NoContraction, as one
v_fma_mixlo_f16 v2, v1, v0, neg(0), rounding the exact product to half once where Metal rounds
the float product; the sum kernel's narrowing is one v_fma_mixlo_f16 1.0, a, b too.

That is the device's own rounding (rule 1), so the fix is the note, not Metal's bits:

- DriverWorkaround::HalfConversionFusedWithArithmetic, keyed on RADV on every GPU (the others
  unmeasured), as NVIDIA's HalfConversionPairFolded is keyed on its driver.
- narrow::rounds_arithmetic: whether a module rounds to half, through a conversion pair, the
  result of an f32 OpFAdd, OpFSub, OpFMul, OpFmaKHR or GLSL Fma.
- compile_kept records PrecisionNote::NativeHalfConversion where the module takes the
  controlled conversion, the profile carries the workaround and rounds_arithmetic holds. The
  controlled form itself stays: a loaded float's conversion is exact there and records nothing.
- Tests: radv_carries_the_fused_half_conversion (every committed RADV profile carries it, no
  other does, and RADV keeps the controlled form) and
  a_controlled_rounding_of_arithmetic_is_noted_where_the_driver_fuses_it (a float sum, product
  and fused multiply-add rounded to half record the note on every RADV profile and not on ANV;
  a loaded float narrowed alone records it on neither). Both fail with compile.rs and derive.rs
  at the base.
- The note's doc, the API guide's catalogue entry, HOWTO, the narrow module doc, the lane's doc
  and the signature table name the new variant.

(cherry picked from commit 799d39233c4e0ae2a18a716e794db8f67405ff00)
2026-11-09 03:12:03 -08:00
Anees Iqbal f36d32dfd3 No-copy memory whose pointer the device refuses and whose source fails is a copy, as with no source
On RADV a no-copy buffer or heap over shared memory (a memfd mapping) made with no dma-buf
source is a copy of the pages since 3f69d1af77, but one made with a source that fails was
still refused (Unsupported, HostMemory): source_failure kept the dma-bufs' refusal unless the
pointer's refusal was the runtime's unpinnable one, and the caller marked it not the device's.
Metal makes a no-copy buffer over any page, and rule 2 lets only what Metal refuses or what
cannot run fail; the pages are readable, so the copy runs.

buffer_over_host_memory now carries whether the device was asked the pointer: where it refused
it (not_importable) and no dma-buf of the pages served either (the source failed, or the device
refused its dma-bufs, refused()), the outcome is the device's refusal, as with no source: a copy,
announced and counted as copied_host_buffers_device_refused. Unchanged: the unpinnable path
(copied as Failed), misuse (chunks that break the source's contract stay Invalid, DmaBuf), a lost
device, memory imported only as dma-bufs and windows the import alignment does not cover (no
pointer asked: still refused, as without a source), and rebinds (refused without a working
source, as before).

Docs: CopiedFor and CopiedBecause::DeviceRefused, the copied-host-pages detail and catalogue
entry (degradation.rs, docs/API.md), WorkCounts::copied_host_buffers_device_refused, copied.rs,
dma_buf.rs's refusals, HostMemory::with_dma_buf, imports_shared_host_pointers, the runtime
README and HOWTO section 6 and Copied host buffers.

Tests: copied_device's shared-memory test makes a second buffer, with a source that fails, over
pages of its own: on a device that refuses shared memory's pointer a copy counted as the
device's refusal, the source called once; elsewhere the pointer's import, no source called. The
runtime lane dma_buf_imports (renamed shared_memory_without_a_working_source_is_a_copy_and_
misuse_refused) expects the failing source's copy on RADV, over a view of its own.

Verified: cargo fmt only; the 780M runs (with a negative control on the base's
buffer_descriptor.rs) are dispatched next.

(cherry picked from commit a30909d44aec64136e29f57b5a5dacca8568d3bc)
2026-11-09 00:34:52 -08:00
Anees Iqbal e22f367533 HOWTO section 7: the RX 550's missing extension as listed, not by generation
6ff21171d8's message said RADV enables VK_EXT_image_drm_format_modifier
on GFX9 and later only; that was inferred, not measured. Measured
(m3-max-10378, vulkaninfo on um790, Mesa 26.2.6): the RX 550 (POLARIS12)
lists VK_EXT_external_memory_dma_buf and VK_EXT_queue_family_foreign but
no VK_EXT_image_drm_format_modifier; the 780M (PHOENIX) and lavapipe
list all three. The line now says that. Doc only.

(cherry picked from commit 617becef4f0d68a14d0ff85ce0b15c5e07f81e0a)
2026-11-08 18:30:28 -08:00
Anees Iqbal 006d43ecb0 HOWTO section 7: the RX 550's dma-buf planes are shadows for want of VK_EXT_image_drm_format_modifier
RADV enables VK_EXT_image_drm_format_modifier on GFX9 and later only, so
the RX 550 (POLARIS12) has no DRM_FORMAT_MOD_LINEAR image to import a
dma-buf export's memory into: its dma-buf planes stay announced
shadows. Doc only.

(cherry picked from commit 6ff21171d8d228d1e22bdb072b65f67c85784187)
2026-11-08 18:30:28 -08:00
Anees Iqbal 7b29073f8c A dma-buf export's texture goes in place through its own dma-buf where no image binds in the memory
On RADV the runtime's memory exported as a dma-buf takes no image of a
texture's: the format query takes the dma-buf handle type for no
linear image, and its DRM_FORMAT_MOD_LINEAR image requires a dedicated
allocation (VUID-vkBindImageMemory-image-01445), so the 780M's VA-API
frames' planes were announced shadows (m3-max-10261, 10304). Binding
an image naming another handle type there is no way out: the layer
checks each type of the memory's export set against the bound image
(VUID-VkExportMemoryAllocateInfo-handleTypes-09860, m3-max-10339).

As the last step before the shadow, on any device that does it, the
texture's image is the runtime's route for images over dma-bufs
(Device::dma_buf_image): a DRM_FORMAT_MOD_LINEAR image whose explicit
plane lies at the texels' offset in the memory with Metal's pitches,
bound to a dedicated import of that memory's own dma-buf:

- dma_buf.rs: explicit_plane_image (shared with dma_buf_image_unbound),
  exported_dma_buf_image_unbound (the format query with DMA_BUF
  importable, the driver's layout, the image's memory within the
  memory and of its type) and bind_exported_dma_buf_image:
  vkGetMemoryFdKHR(DMA_BUF) of the memory (Device::dma_buf_of, as
  export_memory_dma_buf makes one), vkGetMemoryFdPropertiesKHR, the
  dedicated import at the image's size (01433; the import's type is
  among the image's, 02989; bound at offset 0, 02628), of the memory's
  own type. Vulkan imports a payload into the instance that exported it
  (VkImportMemoryFdInfoKHR, fd-00668). import_dma_buf hands the driver
  a duplicate and closes ours either way. The import is a DmaBufPages
  of no source (of_exported), freed after the image, live in
  WorkCounts::dma_buf_image_memories_live; each image is counted in the
  new WorkCounts::exported_dma_buf_images.
- texture.rs: exported_dma_buf_alias, after alias_unbound's refusal of
  the image in the memory (a shared block's, or a buffer's dedicated
  allocation): only for the runtime's dma-buf exports, only on a
  refusal (a pending or failed verdict stands), under the device's
  check of that memory; the image must hold exactly Metal's texels to
  the buffer's end (linear_plan::aliases). alias_image binds it
  (exported_dma_buf_texture_image: the buffer's memory held, the first
  move acquiring from VK_QUEUE_FAMILY_FOREIGN_EXT into GENERAL as an
  image over dma-buf pages does), alias_image_made answers it unbound.
  Devices whose image binds in the memory (ANV, lavapipe) keep that
  path unchanged.
- in_place_check.rs: the ExportedDmaBuf class takes a dma-buf's
  dedicated allocation too, and its textures take this route wherever
  the image in the memory is refused, so its verdicts (reads: a CPU
  write through the buffer's mapping read through the import's image;
  writes and renders the other way) measure it. CHECK_VERSION 13 -> 14:
  13's records kept ExportedDmaBuf Unchecked as a cause that lasts.

Test: exported_textures'
a_dma_buf_export_s_planes_go_in_place_through_its_own_dma_buf_where_no_image_binds_in_it
asks the device itself (the format query and the image's dedicated
requirement) whether a plane's image binds in the memory; where none
does and the device makes DRM_FORMAT_MOD_LINEAR images, each plane must
be in place through the import (counted) or a CheckFailed shadow, never
Unchecked; the buffer's export is a dma-buf (fdinfo exp_name); one
import live per such image, none once the textures go; no VUID. The
NV12 test reads such an image's memory plane (09433). The RX 550
enables no VK_EXT_image_drm_format_modifier: its planes stay announced
shadows.

Docs: API.md's shadow rule, HOWTO section 7, the runtime README, the
module docs.

Verification follows: the 780M, the RX 550, lavapipe and the Iris Xe
under the layer, then the 5080 through an entry.

(cherry picked from commit c2e90e2321937067d38cebc5b342f651a638b064)
2026-11-08 18:30:28 -08:00
Anees Iqbal 5ebe1d32aa Revert the dual dma-buf export and the opaque-descriptor naming
Reverts 1acb4f1fbf, 07d9fcac79, 6a6523d2bf, 4a13dfe5bc and 239d8ff9bb
as one fix-forward commit; the tree is b4331408bd's again.

An image naming an opaque file descriptor in a block exported as
DMA_BUF | OPAQUE_FD went in place on the RX 550 (m3-max-10339 at
239d8ff9bb), but the validation layer reported
VUID-VkExportMemoryAllocateInfo-handleTypes-09860 at each bind: it asks
vkGetPhysicalDeviceImageFormatProperties2 for the bound image with each
handle type of the memory's export set, and RADV supports no dma-buf
linear image. Its DRM_FORMAT_MOD_LINEAR dma-buf image requires a
dedicated allocation. So no image in a shared block exported as a
dma-buf is clean under the layer there, whatever else the block
exports, and the block goes back to exporting the dma-buf alone, with
no opaque naming and no counter of it. The next commit takes the
DmaBuf route instead: the block's own dma-buf, imported as memory
dedicated to the texture's image.

(cherry picked from commit af8bda811b4ba9a7816965d2f3bf1fd710d1e40e)
2026-11-08 18:30:28 -08:00
Anees Iqbal 0b1dd0fc36 An image over a dma-buf block names a type the block is exported as, with no image-side compatibility test
On the 780M (m3-max-10304 at 07d9fcac79) the image naming an opaque
file descriptor over a block exported as DMA_BUF | OPAQUE_FD was
refused only by the image-side compatibility test this branch added:
RADV's format query lists compatibleHandleTypes 0x1 (the opaque type
alone) for its opaque linear images. That test was stricter than
Vulkan:

- VUID-VkExportMemoryAllocateInfo-handleTypes-09860: the export set's
  bits must be compatible "as reported by ...
  VkExternalImageFormatProperties, or VkExternalBufferProperties"; the
  buffer query answers them so (FdExport::new).
- VUID-VkImageCreateInfo-pNext-00990: an image's handleTypes lie in its
  own compatibleHandleTypes; the image names one type.
- VUID-vkBindImageMemory-memory-02728: the memory's export set includes
  one of the image's types.

So the test goes (LinearRefusal::Incompatible and
ModifierMemory::shared_with with it). What stays, per handle type the
image names: the format query reports it EXPORTABLE, not
DEDICATED_ONLY; the image made requires no dedicated allocation
(VkMemoryDedicatedRequirements); its memoryTypeBits take the block's
type and its alignment is met at the texels' offset (alias_unbound_in's
aliases check); and the in-place check measures that exact image, under
the layer, before a texture takes it. The VUIDs are cited where the
export set (FdExport::new) and the image's handle type (alias_unbound)
are decided. Docs follow: API.md's shadow rule, HOWTO section 7, the
in_place.rs module doc.

Verification: the 780M, the RX 550, lavapipe and the Iris Xe next, then
the 5080 through an entry.

(cherry picked from commit 239d8ff9bbd4477d784f4ccc815ebf8af53dcad0)
2026-11-08 18:30:28 -08:00
Anees Iqbal 6d5c7b8e92 A dma-buf block's images name an opaque file descriptor where the device takes no dma-buf image in a shared block
On the 780M (RADV PHOENIX) the runtime's memory exported as dma-bufs
kept every texture a shadow: the device's image format query refuses
the dma-buf handle type to a plain linear image and takes it for a
DRM_FORMAT_MOD_LINEAR image only in a dedicated allocation, so the
in-place check of that memory made no image and its verdicts stayed
Unchecked (m3-max-10261). RADV takes an opaque file descriptor for the
same images in a shared block (the opaque-descriptor planes are in
place there, alignment 256).

The remedy, decided from documented queries alone:

- exported_memory.rs: FdExport::new asks
  vkGetPhysicalDeviceExternalBufferProperties for the dma-buf and the
  opaque handle types with the runtime's buffer usage. Where the
  dma-buf's compatible types hold the opaque one, and the opaque one is
  exportable, not DEDICATED_ONLY, and compatible with both, a shared
  block of dma-bufs is allocated exportable as DMA_BUF | OPAQUE_FD
  (Memory::export_dma_bufs_as). Elsewhere, and for a buffer's dedicated
  allocation, it stays the dma-buf alone. The buffer still names the
  dma-buf type (VUID-vkBindBufferMemory-memory-02726 needs one in
  common) and export_memory_dma_buf is unchanged: vkGetMemoryFdKHR of
  the dma-buf type, a dma-buf of the same memory.
- memory.rs: Exported carries the export set beside the handle type;
  bound_memory answers the set.
- texture.rs: alias_unbound tries the image naming the dma-buf type,
  then, where the block exports both, the one naming the opaque type,
  each through the same linear-then-DRM_FORMAT_MOD_LINEAR route
  (alias_unbound_in). An image takes a handle type only where
  vkGetPhysicalDeviceImageFormatProperties2 with that type reports it
  exportable, not DEDICATED_ONLY, and lists every type the block is
  exported as among its compatible types (external_image_limits,
  modifier_image_limits; LinearRefusal::Incompatible). Where neither
  takes it, the shadow and its notice name both refusals.
- in_place.rs: the class follows the memory (ExportedDmaBuf for any
  block of dma-bufs); the check's own textures go through the same
  route, so its verdicts are of the image a texture names.
  CHECK_VERSION 13 -> 14: 13's records kept ExportedDmaBuf Unchecked as
  a cause that lasts.
- WorkCounts::exported_dma_buf_images_named_opaque_fd counts the images
  that name the opaque type over a dma-buf block (api_signatures.tsv).

Test: exported_textures'
a_dma_buf_block_s_planes_name_an_opaque_fd_where_its_images_take_no_dma_buf_in_a_shared_block
asks the buffer and image queries itself, apart from the runtime: it
asserts the block's export set matches the buffer queries, the
buffer's export is a dma-buf (fdinfo exp_name), and, where the block
exports both and the dma-buf type takes no image of the plane's format
in a shared block, each plane is in place naming the opaque type
(counted) or a shadow of a byte the check found changed, never
Unchecked; no VUID under the layer. Without the change it fails on
RADV: the block exports the dma-buf alone where the buffer queries
answer both.

Docs: API.md's shadow rule, HOWTO section 7, the runtime README and the
module docs.

Verification: to run on the 780M, the RX 550 and lavapipe, then the
5080 through an entry.

(cherry picked from commit 1acb4f1fbf1fd4df8fcee2948417dcc089909fe4)
2026-11-08 18:30:27 -08:00
Anees Iqbal 85465062e2 HOWTO section 7: where a texture over an exported frame's plane lies in place
Names the rule the runtime applies to each plane's linear image (the
plain one first, else DRM_FORMAT_MOD_LINEAR), made for the export's
handle type: the image format query takes that handle type, not in a
dedicated allocation alone; the plane's byte in the memory is a multiple
of vkGetImageMemoryRequirements' alignment; vkGetImageSubresourceLayout
answers offset 0 and the plane's row pitch, its size fitting; and the
device's in-place check of that exported memory passed. The shadow's
causes otherwise, and the measured alignments for a 3840x2160 NV12
frame: 64 on lavapipe (m3-max-10165), 256 on the RX 550 under RADV with
opaque descriptors (m3-max-10151), whose dma-buf planes are shadows.

(cherry picked from commit 15affc37f6910f8ea7bababe1bcb5c69d5ae7d5c)
2026-11-08 17:00:48 -08:00
Anees Iqbal 3f69d1af77 No-copy buffers and heaps whose pointer the device refuses, with no dma-buf source, are copies
On RADV (amdgpu userptr takes anonymous private pages only) a no-copy buffer over shared memory,
a memfd mapping among it (QEMU's memory-backend-memfd,share=on guest RAM), made with no source of
dma-bufs of its pages, was refused (Unsupported, HostMemory), where Metal makes a no-copy buffer
over any page. Device::buffer_over_host_memory now makes it over a copy of the pages instead
(copied.rs), announced (copied-host-pages, its detail naming the device's refusal) and counted
(WorkCounts::copied_host_buffers_device_refused, of copied_host_buffers_made). A no-copy heap's own
buffer takes the same path. The import with a source is unchanged: the source is still called
first, and a copy follows its failure only as before. A rebind to such memory without a source is
still refused (its own import path), as HOWTO section 6 now says.

Docs: the runtime README, HOWTO sections 6 and Copied host buffers, HostMemory::new,
Device::imports_shared_host_pointers, the copied-host-pages catalogue entry and copied.rs's opening.
docs/REFUSALS.md regenerated (unchanged: the refusal stays where pages cannot be read).

Test: tests::copied_device::copied_buffer_is_made_over_shared_memory_whose_pointer_the_device_refuses
(Linux): where the device refuses shared memory's pointer, the buffer is a copy, announced and
counted as the device's refusal, with every copy's coherence; elsewhere an import.

(cherry picked from commit 0e07fff15b79cf0fdcf4f09a2836c7075db266a3)
2026-11-08 15:58:08 -08:00
Anees Iqbal ddb5440aad An exported buffer's announced external write lets go of its shadows' standings
A texture over an exportable Private buffer whose rows no image holds (a decoder's pitch) reads it
through a shadow, and a shadow over a tracked Private buffer the runtime made stands across
command buffers (shadow_standing.rs): a later command buffer's first copy in moves nothing while
no batch wrote the buffer or the image. Another API's writes through an import of the buffer's
memory are no batch's, and Buffer::external_write_done only noted the acquire, so once such a
texture had copied in, every later external write was missed: each of reims' NVDEC pool
surfaces on the 5080 kept showing its first picture.

external_write_done now counts a write of the buffer's key against every standing recorded on
it (Standings::written_apart, LetGo::TruthWritten), so the next command buffer's first copy in of
each shadow over the bytes moves what the other API wrote. Standings stay otherwise: the
contract already says the device reads another API's writes only once the caller announces them
("What the other API writes there is the device's to read once the caller says so", "Call it
once after each of the other API's writes"), so a write made without the call keeps no new claim
on a standing, and an exported buffer's shadows keep standing between announced writes (one
copy in per write, not one per command buffer). The runtime README, HOWTO and the module docs say
what the call does for a texture's shadow.

tests::exported_memory::a_shadow_over_an_exported_buffer_reads_each_announced_write: a second
VkDevice fills the buffer through an import of its opaque descriptor (released to
VK_QUEUE_FAMILY_EXTERNAL), three values in turn, each followed by external_write_done and two
reads of a padded-row texture through a kernel: the first must read the write and copy in, the
second must read it again with the image standing.

Verification: to follow (clippy x3, the lane and the standing tests on lavapipe and the 780M, a
negative control without the let-go).

(cherry picked from commit 542237e45fe706a39d5cd9e39f861f792c4c2996)
2026-11-08 15:24:26 -08:00
Anees Iqbal 0cadcbae8c Copies over RAM the device refuses always stage through the CPU; its chunks are not faulted in
On a device that refuses pointers to shared memory (RADV) and a RAM of shared
memory with no dma-buf source, a gather was staged through the CPU while the
device's thread had not yet tried the chunk. Once the thread's import was
refused (`tried`), the same gather went to CopyTake::Waits, imported the chunk
itself and was refused as Unsupported(HostMemory). So a copy Metal takes
succeeded or failed depending on when it came. The first-fill bench's steady
fills failed so on a Radeon 780M. A gather after a staged scatter into the
chunk was refused the same way: the scatter set `scattered`, so written_over
kept the gather off the CPU's path. And the thread faulted each 64 MiB chunk
in before an import the device refuses whatever the pages hold.

Now the plan records the refusal (Plan::shared_refused: no source, a range of
shared memory, and the device answers imports_shared_host_pointers false,
asked once at the use). Each chunk of shared memory under it is
ChunkSlot::refused, known from the use on. copy_take answers ThroughCpu for a
refused chunk whether or not the thread ran or tried it. written_over ignores
a copy's write into a refused chunk, which only a staged scatter's CPU drain
makes, in a host step before any later copy's. import_ahead faults no refused
chunk in (it still tries the import, which is refused at once). Chunks it does
fault in are counted: WorkCounts::host_ram_chunks_faulted_ahead.

Tests:
- copies_over_shared_ram_move_their_bytes_after_the_thread_reached_its_chunk:
  gather, scatter, gather over a shared memfd RAM after the thread reached its
  chunk. On a refusing device all three stage and move the right bytes.
- the_ahead_thread_faults_in_only_chunks_the_device_may_import: 0 chunks
  faulted in where the device refuses, and at least the chunks imported ahead
  where it imports (Linux).

(cherry picked from commit 590a07faf1468b162333f479a0f857aa71a353a3)
2026-11-08 14:48:32 -08:00
Anees Iqbal 4b277a28d1 A RAM's use, dropped, waits for its device thread: no page is read after it
The device's thread for a guest RAM (import_ahead, listed_chunks) upgraded the
RAM and faulted a chunk in by reading its pages (read_volatile, since
259be5d3c5) with no hold the use's end waited for. A consumer that dropped
the use and its RAM and then unmapped the pages, as a VMM's teardown does,
had the thread read an unmapped page: SIGSEGV in a consumer's test on an RTX
5080, and in our contended bench on a Radeon 780M (12 of 12 runs before the
bench's keep-alive fix).

Now HostRamUse keeps the thread's JoinHandle. Its drop sets the use's end
(Wake::ended), wakes the thread and joins it. fault_in checks the flag before
each 2 MiB step, and both threads check it at each look and between the
fault-in and the import. So the drop waits at most one step of reads or one
import under way, and once it returns the runtime reads, faults in and imports
no page of the RAM. An import a buffer or a pending command buffer holds still
keeps its pages until the keep-alive goes, as before. The fault_in SAFETY
comment now names what keeps the pages mapped.

Test: a_use_s_drop_waits_out_the_thread_so_its_pages_may_be_unmapped_at_once
makes 32 rounds over a fresh 64 MiB memfd mapped shared, with a keep-alive
that does not unmap. Each round uses the RAM, drops the use 0 to 4.8 ms
later, drops the RAM and unmaps at once. It checks that each round's
keep-alive went before the unmap and that every chunk was freed.

(cherry picked from commit 0c18e1898fc5a9ce50eb5bd7508dd171c01e3093)
2026-11-08 14:09:07 -08:00
Anees Iqbal 80b581bee2 Dma-buf export: README, HOWTO, the API table and REFUSALS.md
The runtime README lists exported_as, export_memory_dma_buf and
external_write_done beside the opaque-fd export; HOWTO gains a section on
memory another API writes (a decoder's DRM_PRIME_2 frame), the old
section 7 now 8. The API signatures table is re-blessed for MemoryExport,
BufferDescriptor::exported_as, with_exported_as, the two Buffer calls,
Problem::ExportedNoCopy and RuntimeGap::DmaBufExport, and REFUSALS.md is
regenerated with the new gap's reach (none: a runtime extension).

(cherry picked from commit 3988f9ec5921e8962708ce7735937c44836361a1)
2026-11-08 13:02:12 -08:00
Anees Iqbal 259be5d3c5 host RAM: fault in a VMM's shared memory by reads, not under the memory map lock
What: the import-ahead thread's fault_in now reads each page of a chunk where
every mapping over it is shared memory of base pages (a memfd, as QEMU maps a
guest's RAM), as PROCMAP_QUERY answers (vma_flags SHARED, vma_page_size the
host's page). A read fault on such a mapping allocates the page and maps it
writable, changing no byte, and since Linux 6.7 runs under the mapping's own
lock, so it holds no mmap_lock. Private memory, hugetlbfs (whose fault past
its pool is SIGBUS) and kernels without PROCMAP_QUERY (before 6.11) keep
MADV_POPULATE_WRITE in 2 MiB steps. host_memory.rs's PROCMAP_QUERY call is
factored into mapping_at, shared by queried_permitted and the new
shared_base_pages.

Why: in a consumer's guest boot on the RTX 5080 laptop, seven slow pipeline
compiles had no thread in an NVIDIA ioctl; their threads sat in an mmap_lock
convoy (vCPUs in get_user_pages, mprotect from heap growth, mmap/munmap in D),
and the one kernel-stack dump that caught the reader found m2v-host-ram in
MADV_POPULATE_WRITE. MADV_POPULATE holds mmap_lock read for each 2 MiB step,
which under reclaim and compaction takes milliseconds, and a waiting writer
queues every later reader behind it.

How verified so far: a C probe on um870 (Linux 7.3.1, 4 GiB memfd under
MADV_HUGEPAGE, a thread calling mprotect every 0.2 ms, two mapping, touching
and unmapping 4 MiB every 0.5 ms): populate in 2 MiB steps took 202-541 ms
with the longest mprotect 4.8-10.1 ms (four runs); per-page reads took
239-247 ms with the longest mprotect 0.40-0.52 ms (two runs), and the write
pass after them faulted no page en masse. New unit tests: the choice of way
(shared memfd by reads, private and a span over both by the advice), and that
a fault-in by reads leaves every page resident, writable (a write pass faults
nothing) and every byte unchanged. cargo fmt only; clippy, the tests and the
5080 before/after run follow as potluck jobs.

(cherry picked from commit e571995af620272b12bb3083a5c59fbf8b844e39)
2026-11-08 12:39:37 -08:00
Anees Iqbal 1c14b4b44a Staged gathers take their staging at their host step, not on the calling thread
A gather staged through the CPU (31e642ecc2) took its region of the
command buffer's arena on the encoding thread. A region over 32 KiB is a
chunk of its own: fresh pages imported by pointer on NVIDIA, about 2.3 ms
plus 0.25 ms/MiB, and more where the import thread allocates at the same
time. On the RTX 5080 the contended fill bench's first call took
52.8 ms, of which checks, pieces and the staging decision were 0.3 ms.

The gather is now a Deferred::GatherStage whose batch's host step does
all of its work: it takes the region, fills it by the CPU from the
pages, and records the vkCmdCopyBuffer into the buffer at the copy's
place. Like the staged scatter's GPU copy, it is recorded at its step
(records_at_its_step). Its uses are noted at the call. It still waits
for the work before it where the GPU may write the pages
(Deferred::steps_after_the_gpu_now, read by step_waits).

StagedFill becomes StagedGather. The command buffer's staged list,
staged_unfilled, fill_staged and State::next_encoder go: segments
carry it all now.

A rebind's encoding again replaces a staged gather's segment with a copy
through the imports: Segment::records_again and splice_replay take it
(recorded_by_an_encoding_again). So an encoder with a staged gather
keeps its log, as before.

Tests (host_ram_copy_device, device tests):
- Every staged copy test asserts that the encoding took no staging of
  the arena (Uploads::bytes below the copy's bytes).
- a_rebind_before_the_first_submission_encodes_a_staged_gather_s_encoder_again:
  a staged gather and a fill of a no-copy buffer over a page outside the
  RAM, in one encoder behind an event wait. The buffer is rebound after
  the commit. The command buffer completes with no error, the encoder
  encoded again once, the fill lands in the new page, and the gather's
  bytes are in its buffer.

Not yet verified; the gem10 checks follow this commit.

(cherry picked from commit 0f60b71653f9f7dfe9eaba18976c21eb75dd696d)
2026-11-08 11:44:50 -08:00
Anees Iqbal 0d65ab5579 Staged scatters: a first scatter into guest RAM makes no import or memory on the calling thread
A copy_to_host_ram over a chunk not yet imported used to import on the
encoding thread. With 16 ranges or fewer it imported those ranges alone
(each import about 2.3 ms on NVIDIA, its pages pinned). With more, it
imported the whole chunk or waited for its import. A clip switch's
block release (a device cache scattered to fresh guest pages) paid this
on the guest's command thread.

Such a scatter is now staged through the CPU, on devices whose thread
imports ahead (plans other than Plan::listed), as gathers are since
31e642ecc2. It leaves its work to two host steps, as two new Deferred
kinds:
- ScatterStage: the host step of the copy's batch waits for no GPU
  work (Deferred::records_at_its_step, which Segment::needs_step and
  known_summary take). It takes a region of the command buffer's arena
  and records one vkCmdCopyBuffer of the bytes the runs cover into it,
  at the copy's place in the encoder. The region's memory is made on
  neither the encoding nor the committing thread (commit_and_submit).
- ScatterDrain: gpu_written, so the rest goes in a part and batch of
  its own. Its host step waits until every VkQueue completed what was
  submitted before it, then copies each run's bytes from the region
  into the pages in run order (a host byte named twice keeps the
  later's), before that batch is submitted. So the pages hold the bytes
  once the command buffer completed, and every later command sees them.
The buffer's read is noted where the GPU copy lies. The chunk keys'
writes are noted at the start of the drain's part, so hazard tracking
orders later readers of those host bytes after the CPU's write, and
the RAM's log hears of them as of a copy through the imports. Each
chunk is taken and asked of the import thread, as a staged gather's is.

An encoder that holds a staged scatter keeps no replay log
(Unlogged::Segments). A rebind before first submission of a buffer
over host pages that the same encoder named fails that submission
with EncodedUseRebound. The HOWTO says so.

Counted:
- WorkCounts::host_ram_scatters_staged
- WorkCounts::host_ram_staged_drain_nanos
Upload::copy_out reads a region back.
host_ram_block_release_bench prints both.

Tests (host_ram_copy_device, device tests):
- a_first_scatter_over_chunks_the_thread_imports_is_in_its_pages_once_it_completes:
  40 single pages over two chunks not imported, one page named twice,
  from a Private buffer the GPU wrote just before in the same encoder.
  At encode: staged 1, no run import, no chunk imported by a copy, no
  import wait. At completion: the pages hold the bytes (the later's for
  the page named twice), the page beside them is untouched, and a
  buffer over one page reads them in a later encoder and in another
  queue's command buffer committed after.
- a_first_scatter_of_few_ranges_imports_nothing_on_the_encoding_thread:
  four pages over two chunks, which the old path imported as ranges
  alone. At encode: no run import made. The thread then imports exactly
  the two chunks, and the next scatter goes through their imports.
- The window test's scatter past the window is now staged: no copy
  import, the thread imports its chunk.

Not yet verified; the gem10 checks follow this commit.

(cherry picked from commit 93965ee58ed9b238084696fa80b910745d6dc281)
2026-11-08 11:12:40 -08:00
Anees Iqbal 48cfac5cb3 HostRam lists kept: the docs say the lists outlive their copies, with same-host numbers
HOWTO, the runtime README and FAST-PATHS still said a copy's lists were
freed with its command buffer and that every copy pays its lists'
imports. They now say each list is kept past its copy for the copies of
the same pages after it (at most 64 MiB and 16 lists, released once no
copy took one for 2 s), and they give the numbers.

The numbers come from tests/host_ram_listed_bench.rs on the Radeon 780M
of one host (um790, RADV, kernel 7.3.1). The kept tip was run with a
timing probe that never lands, then again with the bound sabotaged to
(0, 0), which keeps nothing, back to back. Medians are commit to
completion, then encode:
- A 5 MiB device cache filled again: 0.37 to 0.43 ms and 0.2 to 0.4 ms,
  against 3.0 to 3.2 ms and 0.7 to 1.0 ms with no list kept. Over an
  imported chunk it takes 0.37 to 0.40 ms and 0.12 to 0.14 ms.
- A surface-shaped tile's download after its fill: 0.53 to 0.60 ms,
  against 4.0 to 4.2 ms.
- A scattered tile's download: 0.46 to 0.50 ms, against 0.98 to 1.04 ms.
- A copy that imports pays the lookup through the kept lists: 48 to
  63 us for a surface tile, 250 to 290 us for 1,800 scattered runs
  against 16 lists.
- The scroll's 24 visible tiles pass the 64 MiB bound (about nine
  tiles), so a third to a half of their repeated fills took a kept list.
- Residency is the same with and without kept lists: 4028 of 8192 MiB,
  and 8300 of 16384 MiB.

(cherry picked from commit ee030ba7ed497aeb4bf0c92653cc33078e987379)
2026-11-08 09:42:35 -08:00
Anees Iqbal 7d4d9346df HostRam gathers over a chunk the device's thread imports go through the CPU, never importing on the encoding thread
copy_take answered Now for a gather over a chunk not imported yet whenever
its ranges, joined where under 2 MiB apart, were at most 16 and none was
the whole chunk. The copy then imported those ranges alone on the encoding
thread. With runs scattered over a chunk, the joined ranges cover nearly
all of it. On the RTX 5080 Laptop GPU a 24 MiB cache of 2,477 runs over
five chunks, its runs joined where under 1 MiB apart, pinned 317 MiB in
61 ms (irisperf's first-fill bench), where the CPU copied the same runs
in 2.8 ms. The bench's first call took 105 to 107 ms with import waits of
0, so the staged path (RT 1893) never ran: it covered only gathers that
would otherwise wait. The consumer's mid-playback fills of new 4K
surfaces took 3.4 to 327 ms with one clip and 1.4 to 2.1 s with three.

Now, on a plan that is not listed and with the device's thread running,
a gather over such a chunk is ThroughCpu however few its ranges. It is
staged through the command buffer's arena, filled by the CPU at its
batch's host step, and the chunk is asked of the thread. A gather the
CPU path cannot take (its bytes possibly written by another use, no
staging memory) still takes the imports' path. So do scatters and
listed plans, as before.

Docs: copy_take, the copy module's first-touch bullet, the staging
check, and HOWTO's copy section.

Test: host_ram_copy_device::a_first_gather_of_few_ranges_imports_nothing_on_the_encoding_thread.
It gathers three pages within 2 MiB in one chunk and one in another,
which before this change was an import of the ranges alone. It asserts
no run import is live once the gather is encoded, the gather is staged,
it waits for no import, and it reads the pages. The negative control is
the old match order; it should fail on any device without
AliasedImportBlitsUnordered. Not run yet.

(cherry picked from commit 3dbab04a5849524c694c74aaea52b776cbef6dd2)
2026-11-08 09:36:45 -08:00