A texture over host pages whose buffer ends inside its last row's pitch is a shadow
(Refused(Placement)): a linear image's last row takes the whole pitch, so the image's memory
requirements reach past the buffer's bytes, over an import of the caller's pages and over a copied
host buffer's copy alike, whose placement is the buffer's length. Metal reads such a texture in
place, so it is a runtime cost above the driver's: docs/FAST-PATHS.md's known gaps now say so, and
InPlaceRefusal::Placement's doc names the case.
Seen on the Iris Xe (ANV) and the 780M and RX 550 (RADV) by a probe at the guest's shape, which
stays on a branch of its own.
Verified: cargo fmt; scripts/api-signatures --check (signatures unchanged; a doc change).
(cherry picked from commit 9493894b26cee3b1a525d9a0916a83f3fc6a594f)
d119fdeca7 made a two-plane YCbCr texture's conversion (its staging buffer, sets and refresh, and
with them the conversion's kernels) at the texture's first conversion instead of at its making, so
the test, which counted them at the making, read 0 kernels and failed on every device.
The test now counts each step apart: the making builds no kernel and takes no scratch; the first
conversion (a read() of the texture, which reads the converted image) builds the kernels and takes
the texture's scratch; the next conversion builds and takes none; a second texture over the same
surface builds none at its first conversion and takes scratch of its own. ycbcr_in_place_loop's
read is split into reader (the pipeline state, made outside the counts) and read_with (a grid of
texels), which the test shares.
Verified: cargo fmt; the device test runs as a potluck job after this commit.
(cherry picked from commit 0008710e8ece5cadf96ce3761419a0cb009e2edb)
Its product fingerprint follows development's versions at 0164fee7da. Blessed on the
M3 (s37-pl.sh censusbless --bless, dv-m3).
(cherry picked from commit bd9d9b89f85f1b30660bd0451a473fdc119725af)
Translation changed at f84816ddec (SEMANTICS_VERSION 1993). Blessed on the M3
(s37-pl.sh bless, dv-golden).
(cherry picked from commit 0164fee7da0c9e51459b2c8465c8b7df73c8d1e0)
A no-copy buffer's or texture's dma-buf import (dma_buf.rs import_chunks, and textures over
dma-buf pages) called vkAllocateMemory with the device's memory lock held, so every other making,
placement or free on any thread waited for the driver's import: 62 to 273 ms on the Radeon 780M in
reims's boots (8588, 8866). It now chooses the type under the lock, imports without it and records
the import under it, as pointer imports already did (radvruns, 66f69a827a..93437d2586). Runtime
sources re-pinned.
Verified: the doc checks in the landing tree. The change's own evidence: 780M gem10 8861
makings_beside_a_dma_buf_import_in_the_driver_wait_for_none_of_it (a placement 0.170 ms, a pointer
import 0.248 ms beside a held import; the negative control waits past 5 s), 91/91 in the dma-buf,
residency, in-place, export, host RAM and YCbCr suites; clippy x3 and rustdoc (8829).
The 780M run of the timed test at 97594efec3 (job 8861) showed the same
placements with the lock held across the import and with it released:
median 0.003 ms, slowest 0.87 ms against 0.79 ms. Its placements were
4 KiB buffers dropped at once, so each later one was a parked buffer of
the same making (recycle.rs). That path takes no memory lock, so the run
never measured the wait the fix removes.
The placing thread now times each wait for lock(&shared.memory) itself.
It also keeps the buffers it places, at most 4096, so none is taken from
the parked and each placement takes the lock. Printed: the import times,
the lock waits (median, slowest, count past 1 ms) and the placements'
(median, slowest, count past 10 ms). The job's negative control, with the
lock held across the import, gives the before figure.
(cherry picked from commit aba88f26431d9232c842aee11b65fb3f59afd2c2)
The test's stand-in for a slow driver import held every dma-buf import of the
device while set, the device's own checks' among them, which could hold one
and leave the making's waiting a minute. It now holds only the import made on
the making's thread (named for the test).
(cherry picked from commit 97594efec3564e2db6b99636651a3e0bae8816b3)
A no-copy buffer's import of its dma-bufs (dma_buf.rs, Device::import_chunks)
and a texture's over dma-buf pages each called Memory::import_dma_buf through
lock(&shared.memory), so the device's memory mutex was held across the
driver's vkAllocateMemory with VkImportMemoryFdInfoKHR. A consumer measured
no-copy buffers over dma-bufs on the Radeon 780M taking 120 to 273 ms to make
while their mapping took 0.14 to 1.8 ms, with two other threads' makings stuck
beside them; every placement, import and free of the device takes that lock.
memory::import_dma_buf is now a function of the memory's mutex, as
import_host is: the types and the device-address flag are chosen under the
lock, the driver's import runs with it released, and the import is logged
under it once made. Pool blocks, imports of pointers and of the runtime's own
pages, and the exported pages already allocated with it released; no other
vkAllocateMemory runs under it.
Tests (tests/host_residency.rs): with the memory's test stand-in for a driver
slow to import (Memory::import_hold, cfg(test) only, called where the
driver's import runs), a placement and an import of a pointer made while a
no-copy buffer's dma-buf import is held must each be done within 5 s, and the
held import then makes its buffer, which reads the file's bytes; and a timed
test prints how long placements wait beside three real 256 MiB dma-buf
imports.
(cherry picked from commit 66f69a827a9de23c7b65443e2974906728fa58ce)
A texture made over a host buffer the runtime copied (the copy's memory its own) was refused as
Refused(Placement) and made a shadow of the copy: two trips a use, the Iris's 491
refused-placement shadows in reims's census. It is now a linear image bound in the copy's memory
at the texels' offset where the in-place check passed: the host-allocation image under the Fresh
verdicts for a copy in fresh pages; for a copy in device memory the driver's linear image
(PREINITIALIZED), or a DRM_FORMAT_MOD_LINEAR image at Metal's pitch, under the caller's pages'
verdicts (the pooled check only for the pitched image). A rebind re-makes the image over the new
memory (perdraw, 1cf4730839 + da896c5a1f). New count copied_textures_in_place. Runtime sources
re-pinned.
Verified: the doc checks in the landing tree. The change's own evidence: lavapipe (gem10 8867:
clippy x3, rustdoc, 57/57 focused, 40/40 lanes, suite 1900/1901 with the one failure present at
its base), 780M 8878 46/46, RX 550 8881 46/46, Iris 8825 46/46, negative control 8840 failing.
On RADV (the RX 550, job 8832) every texture over a copied host buffer whose copy lies in memory
the device allocates stayed a shadow: the route asked the runtime's pooled class's verdicts, which
the check leaves unchecked there, though the image over such a copy is mostly the driver's own
linear image, which starts PREINITIALIZED and so keeps the copy's bytes at its first move. The
pooled class judges only the DRM_FORMAT_MOD_LINEAR image made UNDEFINED at Metal's pitch where the
driver lays its rows otherwise.
So the route asks the caller's pages' class (Pointer) for texels as they lie in the copy and as they
lie in the pages (a rebind may import them), and fresh pages' where the copy lies in them;
copy_unplaced refuses the pitched image for its pitch where the pooled check did not pass for its
accesses. The wider plans of a texture over a copy (the usages its descriptor lacks) take the
caller's pages' verdicts too, as the route does. Texels::over_caller_pages answers only over a
copied buffer.
The device test now asserts an image over the copy where both checks passed and none where the
pages' did not.
Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit 7911bb167b88661f3d4b8b6a4431145ff22a143c)
Every texture made over a copied host buffer (a no-copy buffer whose import the caller's gate
refused, or that failed) was a shadow, refused as `Refused(Placement)` ("a copy of the caller's
pages in memory of the device's own"), whatever its usage: each command buffer copied the copy's
texels into the shadow's image, and merged writes back, on top of the copy's own copy-in and merge.
A consumer whose views of guest memory pass the host's mapping budget gets copies of its large
window surfaces (reims's Iris census: 112 gate copies, 1.9 GB), and every texture over them is
such a double copy: the boots' 491 refused-placement shadows.
The GPU uses the copy in the pages' stead, so a texture's image can lie there, as a rebind onto a
copy already makes one (`in_place_over_copy`):
- route.rs: a copied buffer's class is its copy's memory's (Fresh in fresh pages the runtime
imported, else Pooled); the in-place decision asks that class's verdicts and the caller's pages'
(Pointer: a rebind may import them), each for texels that lie in lines as they lie there
(`Texels::line_start` reads the copy's offset in its memory; `over_caller_pages` the pages').
- in_place_image.rs: `unplaced` over a copy makes the image in the copy's memory: in fresh pages
the host-allocation one, as over the pages; in memory the device allocates `own_unbound`, the
driver's linear image (PREINITIALIZED) where it lays the rows at the pitch, else the
DRM_FORMAT_MOD_LINEAR one of no external memory (`unbound_in` serves both, and
`in_place_unbound`). The image is watched for rebinds and its first move holds the pages, for any
no-copy buffer's pages (the class no longer decides it). A rebind onto a device-allocated copy
takes the DRM_FORMAT_MOD_LINEAR image too where the pooled class passed for its accesses
(`class_takes`, from `fresh_pages_take`).
- The image's identity is the buffer's, so its uses name the copy: commits copy the CPU's writes
in, completions merge the GPU's back, as for the buffer.
- Counted: `WorkCounts::copied_textures_in_place` (also in `host_textures_in_place`); a shadow's
notice names the copy.
Tests (copied_device.rs): a sampled and a rendered texture over a gate-refused copy take an image
over the copy exactly where the verdicts of the copy's memory and the pages pass (before this,
every one was a shadow, so on a device whose check passes the test fails), read the caller's
texels and a CPU write before a commit, and their blit and clear reach the texels' bytes in the
pages alone; such a texture follows rebinds to another copy and back to an import.
Docs: copied.rs, in_place.rs, in_place_image.rs, route.rs, HOWTO (copied host buffers),
FAST-PATHS (the in-place row), TexturePlacement::InPlace; api_signatures blessed.
(cherry picked from commit e6573e3f1b942d11bda3063f5477745018cf9239)
A block that goes (its queue went, or it sat unleased for QUIET) becomes the device's spare of its
kind where the device has none, and a queue's first lease takes the spare before it makes one
(cbnotice, dcc2bc0cb4 + 79e85cc69f). A device makes no more blocks of a kind than the most queues
that held one at once; it keeps at most one block per kind beyond them (254.7 MiB of device memory
on the RTX 5080, 1 GiB of wired host memory on the M3 Max). FAST-PATHS's known gap narrows to
makings past that peak. Runtime sources re-pinned.
Verified: the doc checks in the landing tree (signatures --check exit 0, refusal surface,
conformance coverage). The change's own evidence: gem10 m3-max-8873 (gpu_pools 6/6, negative
control 4/6 failing, lavapipe index_pools 4/4 x6, clippy x3, rustdoc); M3 m3-max-8894 (index_pools
4/4 x3, the handler test told 36/36 rounds).
The two closures of one chain both borrowed the queue blocks mutably
(E0524). Collect the queues' blocks first, then keep or release each.
Verified: cargo fmt only, here; the build follows as potluck jobs.
(cherry picked from commit 79e85cc69f5b2ec9f98ae682d0a4a775f0d4fff0)
A queue's pool block that went (its queue went, or no lease held it for
QUIET) was released, and the next queue to need a block of that kind
made one again: on the RTX 5080 a 254.7 MiB vkAllocateMemory of 4.9 to
189.5 ms beside other GPU work, during which the driver holds every
vkQueueSubmit of the process (docs/FAST-PATHS.md, known gaps).
Now the block becomes the device's spare of its kind where the device
holds none (else it is released, as before), a made-meanwhile block too,
and a queue holding no block takes the spare at its first lease before
it makes one. A device so makes no more blocks of a kind than the most
queues that held one at once, and none as queues come and go or rest.
The cost is one block of each kind beyond the queues' own until a queue
takes it or the device goes: 254.7 MiB of device memory on the RTX 5080
Laptop GPU, 1 GiB of host memory kept wired on the M3 Max. The spare is
safe to hand on: no lease holds a block that goes, so no command uses
it, and nothing reads a pool's bytes before its own command buffer wrote
them.
QueueBlocks::drain pops the slots instead of taking the map.
Tests: the pool CPU tests cover the spare from both releases, the
made-meanwhile block, the teardown and queue churn (eight queues one
after another make one block); the device tests see a later queue and a
rested one take the spare without a making, and the handler test makes
each round's block after a holder queue took the spare.
Verified: cargo fmt only, here; the runtime and validation suites, clippy
and the device runs follow as potluck jobs.
(cherry picked from commit dcc2bc0cb49f391b7d14c135d7aae97f1a93795b)
The probe commits cherry-picked with it are removed again in 795d860397, so the runtime's code is
as before; only gpu_pools.rs's module doc differs. Verified: the pin recomputed in the landing tree.
On the RTX 5080 the test passed 20 of 20 beside another lane while
telling almost nothing: in 240 rounds only 8 told, and its negative
control (the completion path waiting on a lock the making holds) failed
0 of 3. The round committed its command buffer and began the making at
once, so the scheduler's vkQueueSubmit mostly came after the making's
vkAllocateMemory began and the driver held it to the making's end; the
command buffer then completed after the making, where a handler that
waits for the making and one that does not look the same.
Each round now waits for the command buffer to be scheduled (its
submission returned, the completion watch begun) before the making
begins, so the allocation holds none of it, and its draw takes about
3 ms of GPU time (instances doubled from one until a measured command
buffer took that long, at most 1 << 24), so it completes early in the
making. A round tells only where the completion fell in the making's
first half (no longer where it came before the making began).
Verified: cargo fmt only, here; the build, clippy, the 5080 runs beside
load with the negative control, and lavapipe follow as potluck jobs.
(cherry picked from commit 319a3632e44804f381002fa2ea88f24cfbbcdca6)
runtime_lane::index_pools::a_completed_handler_waits_for_no_pool_block_made_meanwhile
failed on the RTX 5080 (round 5ce05e1908, lane ln07): the handler ran 37.2 ms
after its command buffer completed, during a 50.5 ms making of the other
queue's index pool block.
What it waited on is the driver, not the completion path. A probe on the
5080 (NVIDIA 615.71.09; 40 rounds of the lane's draw, with and without the
validation layer, completion trace, b5080 entry poolwait-probe1) found:
- the making is nearly all vkAllocateMemory of the 254.7 MiB block, 3.1 to
35.7 ms beside another process's GPU work;
- in 25 rounds the scheduler thread's vkQueueSubmit of the first command
buffer was called during that allocation and returned 0.01 to 0.25 ms after
it, twice after the GPU had ended the batch (23.9 ms into a 29.4 ms making;
0.3 ms into a 3.7 ms one: the failure's shape). The runtime watches a batch
from its submission's return on, so it completed as the making ended;
- in the other 15 the submission returned before the allocation began, and
the handler ran during the allocation in all 15;
- in all 40, the handler ran 0.07 to 1.44 ms after the later of the GPU end
and the submission's return;
- raw, another thread's vkWaitSemaphores (no wait), vkGetSemaphoreCounterValue
and vkGetFenceStatus took at most 0.03 ms during allocations of that size
(1.9 to 213.6 ms): host waits are not held, submissions are.
So the claim is now exact: the lag counts from the later of the GPU end and
the kernel end time (the last vkQueueSubmit's return), and a round tells only
where both fall in the making's first half. One round told about one time in
four on the 5080, so the test runs 12, each with a queue of its own, and
prints each. The driver's hold of the submission is a known gap
(docs/FAST-PATHS.md), and gpu_pools.rs says what a making costs there.
(cherry picked from commit 438b4ec928dc1d44d2003a20537fea77a768d731)
The probe (23e11f529f and the two commits before it) answered its question on
the RTX 5080: the next commit states the finding where its test and docs live.
Its runs: b5080 entries poolwait-probe1 (5080), m3-max-8354 (lavapipe),
m3-max-8388 (RX 7900 XTX).
(cherry picked from commit 795d860397d36cd3ffc50da78ff65e124d38f284)
A test-only probe (ignored, run by name) and test-only trace marks on the
pool block's making, the completion turn and the handler thread, to find
what the 5080's index_pools failure waited on. Not for landing as is.
(cherry picked from commit 1299b5a3ea5c01cf70e78a5f1e6fd47d759c988a)
HostRam::with_dma_buf_of_runs (radvruns, 0f36724d0f..384ce01a32): on Plan::listed (RADV), a copy
over chunks not imported takes one UDMABUF_CREATE_LIST dma-buf per list of up to list_limit runs
across every chunk it touches, freed once its command buffer completes. Without the source, copies
take their chunks as before. New work count host_ram_run_list_import_nanos. Runtime sources
re-pinned.
Verified: the doc checks in the landing tree (signatures --check exit 0, refusal surface,
conformance coverage). The change's own evidence: 780M (gem10, m3-max-8822) host_ram_dma_buf 7/7 and
60/60 host RAM device tests; lavapipe 67/67, clippy x3 and rustdoc (m3-max-8786).
HOWTO section 6 gains HostRam::with_dma_buf_of_runs: what the source answers,
where copies take lists, what they differ from (a chunk's import pins every
page of it, for good, and later copies import nothing; lists pin the copy's
pages while it runs, and every copy pays its imports), and the Radeon 780M's
numbers from tests/host_ram_listed_bench.rs at 4f30c38a77 (before the rebase
onto development; the list path is unchanged by it): 4028 MiB of an 8 GiB
guest's file held where whole chunks would make 8192 MiB resident, 8300 of
16384 for 16 GiB; a surface-shaped tile 4.1 to 4.5 ms from the commit to the
completion, a scattered one 0.9 to 1.25 ms, against 0.39 to 0.48 ms over an
imported chunk. The copy paragraph says where lists replace the staged and
alone paths. The runtime README names the call; FAST-PATHS's row on idle
dma-buf imports gains the trade (memory for per-copy time, the consumer's
choice, no accuracy).
(cherry picked from commit c6f08a396cc2e4713dedfae06ad0648019e9e22d)
A list of a copy's runs is the copy's own import of its pages, made on the
encoding thread as a range's alone is, so its time goes in a counter of its
own, WorkCounts::host_ram_run_list_import_nanos (the source's dma-buf and the
device's import, made or failed), not in host_ram_chunk_import_nanos (a
chunk's imports) nor in host_ram_copy_import_wait_nanos (a copy's waits for a
chunk's import). The waits of the chunks no list takes still reach that
counter, through CopyImports. The tile test fails where lists are imported
in no time counted, and prints the time.
Also drops copy.rs's Duration import, which the rebase left unused.
(cherry picked from commit 84f83a5672b392c6c5182a30b0c089dd6fd966e1)
The 780M bench at c4077928ac showed a tile of 1,800 guest pages spread over an 8 GiB RAM taking 16
lists a copy and over a 16 GiB RAM 32: one per 512 MiB chunk it touched, each its own udmabuf
and import (call 1.0 to 2.5 ms, commit to completion 1.5 to 5.2 ms). A list's runs need not share a
chunk: udmabuf's list names a file and offset per run.
RamOnDevice::copy_imports now gathers a copy's imports for every chunk it touches: where lists are
taken (Plan::listed, a source of run lists, ordered blits through aliases, room in the allocation
limit) each imported chunk's own import, then RamOnDevice::run_lists over the runs of every other
chunk, by address across them (page runs cut at chunk ends), split at the source's count of runs
and a chunk's bytes; a list serves each chunk it holds pages of (CopyImports::of_chunk). Chunks
with a run that is the whole chunk, and every chunk where lists are not taken, take
RamOnDevice::for_copy, which is development's again (no list branch). The residency test's RAM
is two 64 MiB chunks where listed, so its 90 clusters across both are one list, which the
per-chunk lists made two.
Verified: cargo fmt only; the 780M runs follow.
(cherry picked from commit 66146a596638850ce0649317928306fb4892686a)
clippy's single_range_in_vec_init refused a one-element array of a Range in the lists test.
Verified: cargo fmt only; clippy follows.
(cherry picked from commit 5e1fe73b374193ba3a412fec13151e0a8661586d)
HostRam::with_dma_buf_of_runs(source, most_runs) gives a RAM a DmaBufRunsSource: one dma-buf of
a list of runs of its pages, their pages one after another (udmabuf's UDMABUF_CREATE_LIST on
Linux, at most list_limit runs a list). Only copies by runs call it, and only where the plan is
Plan::listed (each held import costs every submission and the RAM's chunks are the device's
dma-bufs of its source: RADV) and the device's barriers order blits through two imports of the
same pages. There RamOnDevice::for_copy, for a chunk not imported, takes RamOnDevice::run_lists:
the copy's ranges of the chunk by address, widened to whole host pages and joined where those
share or touch a page (copy::page_runs), split into lists of at most most_runs runs and one
dma-buf's bytes (copy::run_lists), each imported as one dma-buf of the source
(Device::ram_runs_as_dma_buf, Imported::Runs), held by the command buffer until it completed and
freed then. The chunk is neither imported nor asked for, so copies pin their own pages while they
run and never a chunk's untouched pages, which udmabuf allocates for good. Without the source, a
source that fails or answers a dma-buf of another length, the margin of the allocation limit, a
run that is the whole chunk or passes one dma-buf, the copy takes the chunk as before.
A list's VkBuffer holds each run from where the runs before it end: RamChunk keeps the runs and
their offsets (RamChunk::offset_of, RamChunk::bytes), and the copy maps each piece through it;
regions take their host bytes from the pieces, not the import's span. alone_ranges takes one
chunk's sorted ranges (chunk_ranges with no cap) and joins them as before, so every other plan
(ANV, NVIDIA, lavapipe, MoltenVK, RADV without the source) copies as before.
Counted: WorkCounts::host_ram_run_list_imports (new), live in run_imports_live. Tests: copy.rs
units for page_runs and run_lists; host_ram_dma_buf's tile tests over a RAM with a udmabuf list
source (lists of at most 1,024 runs, no chunk, nothing asked, no untouched page resident) and,
without it, the chunk; elsewhere the list source never asked. The bench takes the list source and
prints first and repeated copies, sorted runs and lists per copy, over surface-shaped and
scattered tiles. api_signatures blessed (three added: DmaBufRunsSource, with_dma_buf_of_runs,
the counter; nothing removed); docs/REFUSALS.md regenerated (a DmaBuf site).
Verified: cargo fmt and the signature and refusal scripts only; the 780M runs follow.
(cherry picked from commit f2e5c143dd314835fd58cd6f8430c5c7c620e52a)
Reverts be6e2759e9 and fb3c488788. Importing each of a tile's ranges alone as a dma-buf of its
own kept residency bounded (8 GiB guest: 4028 MiB stays 4028; 16 GiB: 8300 stays 8300) but cost
35 to 45 us an import on the Radeon 780M, 13 to 19 ms for a tile of 1,800 scattered pages, every
copy, where over an imported chunk a copy takes 0.15 ms to encode and 0.5 ms to complete. That
is a speed regression for any caller copying today. The bounded path comes back as an opt-in
source of one dma-buf for a list of runs (UDMABUF_CREATE_LIST), in the next commit.
Verified: cargo fmt only; host_ram.rs and host_ram/copy.rs equal development's (2e381ae1f0).
(cherry picked from commit 5df2d2c71df35ea9be08fd377dced78680a68447)
udmabuf makes no dma-buf of a memfd not sealed against shrinking, so the bench's first copy
was refused (Unsupported, HostMemory: the source failed and RADV refused the shared pointer).
QEMU's memory-backend-memfd seals its file so; the bench's RAM is sealed as the dma-buf tests'
is. Also times the 5 MiB cache's copies over a RAM of one 512 MiB chunk an object imported:
what a copy costs with no import of its own.
Verified: cargo fmt; the 780M run follows.
(cherry picked from commit d89c82e6e85c3488b268015b8842728af99801fd)
tests::host_ram_device::the_ahead_thread_leaves_the_allocation_limit_to_the_objects failed on
the Radeon 780M (homelab-um790-xtx-1, RADV, Mesa 26.2.6) in a run of 41 host RAM tests in
parallel, at its check that the device's live allocations stand at the limit less its margin
once the thread stopped (host_ram_device.rs:575), and passed alone five times and with
host_ram_device's 20 tests. The test picks the allocation limit from the live allocations it
reads first; the device's submission checks (submit_check.rs) hold imports of their own while
they run (TAX_IMPORTS), off the test's thread, and a test that read the live count while they
held them saw the count drop once they let go. ahead_device now waits for the checks to answer,
as host_residency's device does, so no test of the file reads counts or a limit the checks move.
Verified: cargo fmt; the 780M runs follow.
(cherry picked from commit 6ccb33ed88c3650b6014666a7e386c2b3312550c)
copy_from_host_ram: where a chunk is not imported, the pages are imported alone; on a device
whose held imports add to every submission's cost (RADV with a source) always so, joined only
across pages in memory, the chunk not imported for it; elsewhere for at most 16 ranges. What is
refused: pages the device cannot import alone nor as their chunk, with RADV's case named (a RAM
of shared memory with no source). use_host_ram: a copy over a listed RAM's chunk asks for
nothing; a RAM of shared memory with no source refuses copies too. with_dma_buf: the source may
be asked once for each of a copy's ranges. host_ram.rs module docs: the copies bullet.
Verified: cargo fmt only.
(cherry picked from commit 477925f329a4dabff7716f2847d7c248f42d9e40)
Where each listed import costs every submission (RADV with the RAM's source of dma-bufs,
Plan::listed), a copy by runs over a chunk not imported no longer takes the chunk for its pages:
- RamOnDevice::for_copy imports its ranges alone however many they are (no copy::MOST_ALONE
cap there), joins two ranges less than 2 MiB apart only where every page between them is in
memory already (host_ram::resident, mincore), and asks the device's thread for nothing
(run_alone's new ask flag), so the copy pins its runs' pages and pages the guest's file holds
already. A chunk's import pinned every page of a chunk of up to 512 MiB, and udmabuf
allocated each page the guest never wrote, for good.
- The chunk's import stays where the chunk is made already, the device's barriers do not order
blits through two imports of the same pages (AliasedImportBlitsUnordered), the allocations
are within the margin the device's thread leaves, a range is the whole chunk, or a range's
import fails.
- Every other plan (ANV, NVIDIA, lavapipe, MoltenVK, and RADV without a source) is unchanged:
copy::alone_ranges takes the join test as a closure, which answers yes there, over the same
sorted ranges (chunk_ranges with no cap, then the 2 MiB joins as before).
Verified: cargo fmt only; the 780M runs follow.
(cherry picked from commit 9093fc6093d8880b51b920c3b2029449a769048d)
On RADV with the RAM's source of dma-bufs (a listed plan: chunks of up to 512 MiB, each one
dma-buf), a copy by runs over a chunk not imported either imports the whole chunk (past
copy::MOST_ALONE ranges) or imports its ranges alone and asks the device's thread for the
chunk, which imports it. Either way the chunk's import pins every page of it, and udmabuf
allocates each page of the guest's file the guest never wrote, which stays allocated. reims
measured 12.3 GiB of a 16 GiB guest resident with the RAM handed to the 780M, against 7.9 to
8.0 GiB with views alone, and so hands RADV no RAM (and makes no copy by runs there).
These tests state what a copy should do there instead, and fail on the code as it is:
- host_ram_dma_buf's tile test (1,800 pages, near and spread across both chunks; from
steelbrain/ramcopy's f6ce20514c and f5a5fd6cff, reworked): over chunks not imported, each
copy imports its ranges alone as dma-bufs and no chunk, and asks for none (checked past a
tick of the device's thread); over chunks imported by objects, no import; byte for byte both
ways.
- copies_over_a_listed_ram_make_no_untouched_page_of_it_resident: a RAM of which the guest
wrote the tile's pages alone; the copies leave the file's pages in memory (mincore over the
RAM's mapping) as they were, each range imported alone, none joined across pages not in
memory.
- The listed test's copy over a released chunk: its run alone and no ask; the next object over
the chunk lies in its run's import and asks for the chunk.
- tests/host_ram_listed_bench.rs (ignored): an 8 GiB and a 16 GiB guest RAM, half written in
2 MiB extents, a scroll of 240 tiles of 1,800 pages copied both ways: the file's pages in
memory against what whole-chunk imports would hold, and each copy's CPU, wall, GPU and
completion times; a 5 MiB cache's fill and download.
Verified: cargo fmt only. The 780M runs come with the fix.
(cherry picked from commit e63fb417f16a6811d6f1292d5d7455e5b2024579)
The first shape's pages are nine apart and join into one range, which a copy imports alone. A
consumer's tile spreads wider: the second shape is 36 groups of 50 pages, 3.5 MiB apart across
both chunks, past copy::MOST_ALONE. Each shape copies over a RAM of its own, so its first round
finds no chunk imported.
Verified so far: cargo fmt only.
(cherry picked from commit 780c820736ae6bd69f8711aaeacf7fdb48f3ee3c)
A consumer's cache copies a tile of about 1,800 scattered guest pages with copy_from_host_ram and
copy_to_host_ram over a RAM of shared memfd pages with a dma-buf source. This test copies such
a tile both ways, first with its chunk not imported and then with it imported. It checks every
page, and that the page beside each run is untouched. It prints each copy's answer, times and
imports (HOST-RAM-TILE).
Verified so far: cargo fmt only.
(cherry picked from commit 0f36724d0fc69c4801c02a7276aae034c44b4bbf)
What: an_exit_mid_making_is_clean accepts a making_exit without its mark where the
runtime's at-once notice ended it. Why: the hook ends the process at once where the
runtime's work outlasts its bound (AT_ONCE), and then no handler registered before
the hook runs; exits_cleanly counts such an exit to the notice. How verified: with the
tip's runs.
(cherry picked from commit 53c69417c40700c5614ceafa8cbc1ca5089b786b)
What: the making_exit child registers after_the_later_devices right after its
device, as instance_after_handler_exit does. exits_cleanly then counts the exit
up to that mark, and the handlers registered as the device was made (the
driver's and the layer's) are printed, not bounded. an_exit_mid_making_is_clean
asserts that the mark was printed.
Why: on the RTX 5080 beside the runtime suite (-j 6), making_exit failed
EXIT_LIMIT in 44 of 122 exits (entry exitflake) and in 48 of 123 (entry
exitprobe, with probes). The probe timed each part. The hook closed 1 to 2 ms
after the child's last line. The making ended, and the handlers registered after
the device (the hook's later registrations, the compiler's destructors) were
done, 8 to 41 ms after it. The handlers registered as the device was made, the
NVIDIA driver's and the validation layer's, then took 1.5 to 5.9 s. That is the
driver's own exit, slowed by the other GPU work, as exits_cleanly's mark already
treats it for instance_after_handler_exit. In passing exits the whole exit took
205 to 1443 ms.
How verified: the tip's evidence (5080 making_exit loops beside the runtime
suite, the exits module on lavapipe).
(cherry picked from commit 49fb927001081866dd076931707d88232ec7b24f)
On plans that are not listed (every device but RADV's), a copy out of host RAM over a chunk the
device's thread has yet to import no longer waits for that import. Its bytes are filled into the
command buffer's arena in the batch's host step and copied with one vkCmdCopyBuffer, behind the
GPU gate wherever another placement or a recorded scatter covers them (irisperf, 8a22e487b4 to
294c10215f). The ahead thread then imports the chunks such gathers asked for. New work counts:
host_ram_copies_staged, host_ram_staged_fills_gated, host_ram_staged_fill_nanos. Runtime sources
re-pinned.
Verified: the doc checks in the landing tree (signatures --check exit 0, refusal surface,
conformance coverage). The change's own evidence: lavapipe 78/78 host_ram + host_aliases, the
negative controls 186b38bb12 and 7250eecde2 failing; the M3 and the 5080 before/after runs are
checks on development.
A staging the device has no memory for (the arena's unset region refused)
no longer fails the copy: the copy takes the chunks' imports as before.
The region is asked for before record_staged, which takes it.
(cherry picked from commit 7044fd2ea59da6cb0452e4029214130cecf0f981)
docs/HOWTO.md's host RAM copy paragraph said a copy over a chunk not
imported waits for its import; it now says what each takes: ranges
alone (at most 16, not on MoltenVK or ANV), a staged gather through the
CPU on devices whose thread imports ahead, and the wait otherwise, with
the counts that show each.
api_signatures.tsv blessed for the six new WorkCounts fields
(signatures.py --bless: six records added, none moved).
(cherry picked from commit 9332df0676eea0a5336ee95ffc25deb2b5d0b05f)
Clippy's drain_collect: the fills leave the state as the arena does, and
are dropped outside its lock with it.
Also the tests: a unit test of HostAliases::others_over, and device
tests of a first gather staged through the CPU (no wait, the CPU's
writes after encoding gathered, the asked chunks and only those
imported next, the next gather through the imports), of a staged gather
gated behind a GPU write over its pages, and of one behind a shared
event reading the CPU's writes before the signal.
(cherry picked from commit c2290563334f25f1ada2dec376ea1d276172dba1)
On a device whose plan is not listed (NVIDIA, ANV, lavapipe, MoltenVK), a
gather over a chunk not imported yet whose ranges cannot go alone (more
than MOST_ALONE, a whole-chunk range, or AliasedImportBlitsUnordered)
took the chunk's import on its encoding thread: about 60 ms a 64 MiB chunk
on the RTX 5080, 216-297 ms for a login's first fill of a 24 MiB cache.
Such a gather, where the device's thread will import the chunk, is now
staged: an unset region of the command buffer's arena as long as the
copy's bytes, filled by the CPU from the pages in the host step of the
copy's batch (the scheduler's existing host-step hold), and one
vkCmdCopyBuffer of the covered bytes into the buffer. No import is made
or waited for, and no page is pinned for it. The copy's uses stay the
chunks' keys' reads and the buffer's write, so hazard tracking orders it
as before.
Exactness:
- The step runs once the batch is otherwise ready: its event waits met,
every batch before it in order submitted, so CPU writes before the
commit or before an awaited signal are in the pages.
- Where a key other than the chunks' own read-only copy keys lies over
the bytes (HostAliases::others_over: a buffer or heap over host pages,
placed until its last command buffer let it go), or a scatter into
those chunks was recorded (ChunkSlot::scattered), the step waits for
the gate: every VkQueue done with what was submitted before it.
- Such a use at encode time (which covers earlier work of the same
command buffer, not submitted before the step) keeps the imports' path.
So does an encoder encoded again.
The device's thread now imports chunks a staged gather asked for before
its window's next (next_ahead takes next_asked first), so a cache over
scattered chunks is imported whole by the next fill.
New WorkCounts: host_ram_copies_staged, host_ram_staged_fills_gated,
host_ram_staged_fill_nanos.
Unverified at this commit: build and tests follow.
(cherry picked from commit 8a22e487b457be90b237a460251ca2397038a600)
Measures a login's first fill of a device cache by copy_from_host_ram:
thousands of 1-4 page runs over five chunks of a fresh 1 GiB memfd, only
the cache's pages written. It reports the first fill and the steady
fills (call, GPU, commit to completion, and the counts' movement), and
what each way to serve a first fill costs alone: imports of the runs by
no-copy buffers, joined at gaps of 0, 64 KiB and 1 MiB; the five chunks
imported whole, one after another and on a thread each; and the runs
gathered by the CPU into a Shared buffer that the GPU copies into the
cache.
Ignored, m2v_gpu only. It is the evidence for removing the first-touch
wait on devices with no listed plan.
(cherry picked from commit 837f4a87f1400ef4919f104bb1b416ddc471d056)
checked_frames_merge_once read the device's counts around each frame as the other tests of the
module did before 8d4c3f3db1: the device's in-place check of textures over host pages renders
passes over linear images of its own on its own thread, which the forced rule renders apart and
the device counts with the test's (an RTX 5080 under load counted 727 passes through copies for
706). The test now waits for the check to end before it makes anything (merge_scratch::settled)
and opens each frame's window through merge_scratch::counts_alone, as the module's other tests do.
Verified: see the tip's evidence (lavapipe on gem10, clippy with --cfg m2v_gpu).
(cherry picked from commit e62a71d0958bbf0e08d8811ca719f215c5974a2d)
The consumer's many_passes frame, as a runtime test: a clear, then 706 passes over a target over
a Private buffer (rows of 2048 bytes), each loading and storing it beside a cleared depth
attachment, each after a 1x1 encoder of no attachment whose state rasterizes nothing (WebKit's
index check). Run in eight shapes, the linear rule forced: a Depth32Float_Stencil8 attachment
whose stencil each pass loads, or Depth32Float; the check encoders or none; each pass's
rectangle and color in the command buffer's upload arena (setVertexBytes, setFragmentBytes) or
in a no-copy buffer over host pages at an offset of its own (a consumer's upload chunk in its
guest RAM). Each shape must render every pass apart, merge the passes after the clear once as
one run, every later pass taking the merge over, and leave the texels a private texture holds
after the same frame. Each prints its counts and its GPU time against the private texture's.
The run's break the consumer measured (11-05: 707 passes apart, 706 merges, 705 scratches
reused) was the once rule that 4368a35894 removed: a pass naming a buffer over host pages joined
no run. The runtime's own upload arena never counted: its chunks are the runtime's Shared
buffers (Owner::Runtime, Lie::Fixed), never registered in Rebinds, so Rebinds::host_range
answers None for them.
The probe at 49e75ea4a3 (64 passes a shape) on lavapipe, gem10, job m3-max-8640: every shape
65 passes through copies, 1 merge recorded and 63 taken over, the texels a private texture's.
merge_scratch.rs: blending_beside, the blending state beside any depth and stencil format.
(cherry picked from commit f22edb6823e2a85c89ad6d51120e543fdf1531e4)
A WebGPU frame split at every indexed draw, as the consumer's many_passes test renders it: a
clear, then passes each loading and storing a target over a Private buffer beside a depth
attachment, each after a 1x1 encoder of no attachment whose state rasterizes nothing. The
consumer measured one merge a pass there on an RTX 5080 (707 passes apart, 706 merges), where
one merge a run is the rule. The test runs the frame in each of eight shapes (a
Depth32Float_Stencil8 attachment whose stencil each pass loads, or Depth32Float; the check
encoders or none; the passes' data from a no-copy buffer over host pages, or their own bytes
through setVertexBytes and setFragmentBytes) with the linear rule forced, prints each shape's
merges and compares the texels with a private texture's.
Verified: not yet run (a probe, to find which shape breaks the run).
(cherry picked from commit 6688871a54bd97cbd978675fb419a4be082afba7)
The work counts gain host_ram_chunk_import_nanos, host_ram_copy_import_waits and
host_ram_copy_import_wait_nanos (e8397f1a66), so a run records more. Signatures
re-blessed and the runtime sources re-pinned.
Verified: the doc checks (signatures --check, refusal surface, conformance coverage)
in the landing tree; the change's own evidence is in its commit.
A copy over a chunk not imported yet, whose ranges cannot go alone (more
than MOST_ALONE of them, the device's thread not running, ANV's or
MoltenVK's defect), takes the chunk's import on its encoding thread: it
makes the import there or waits for the one under way. reims-vgpu saw a
login's first fill of a 24 MiB cache take 216-297 ms on the RTX 5080 and
could only infer the cause.
New WorkCounts fields:
- host_ram_chunk_import_nanos: the time every chunk import took, whoever
made it (the device's thread, an object, a copy), failed ones included.
- host_ram_copy_import_waits: copies whose encoding waited for a chunk's
import, counted once a copy.
- host_ram_copy_import_wait_nanos: the time those encodings waited.
RamOnDevice::for_copy answers the time its thread spent in the chunk's
import with the imports; record_host_ram_copy sums it over the copy's
chunks.
Verified: a_gather_and_a_scatter_move_every_runs_bytes_in_order asserts
one wait and nonzero import time for the first copy (the thread held, so
the copy imports both chunks), and no wait and no import time for the
next copy over the imported chunks.
(cherry picked from commit e8397f1a669e062f2a3134f332b0afabf0d16a72)
What: each test of the two modules waits for the device's in-place check of
textures over host pages to end before it makes anything (merge_scratch::settled,
where the policy runs one), and opens each window of the device's counts through
merge_scratch::counts_alone, which asserts that no verdict is pending: the check
no longer runs.
Why: an RTX 5080 under load failed
linear_runs::passes_reading_host_pages_form_one_run with 727 passes through
copies for the test's 706. The counts are the device's. The check renders passes
over linear images of its own on its own thread, and the device counts them with
the test's. The rule the test forces (linear_rule_forced) renders those passes
apart too. That run's output holds the clear-copies notice for an R8Unorm linear
attachment, and the test makes no R8Unorm texture. Once every verdict is known,
the check runs no more, so a window opened after it holds the test's work alone,
exactly. The device memory bounds in merge_scratch read the same windows. A
target over host pages made after the verdicts takes its place for good, where
one made before them is a shadow that may move in place at a later commit.
How verified: see the tip's evidence (5080 beside a lane x20, lavapipe, MoltenVK,
and a probe without the settle showing the check running as the window opens).
(cherry picked from commit 17384c19019c8d305f66fa38b63a8f3fd2ffbd25)
irisperf-pairs (8292ae5075, 02b7831f79): BlitCommandEncoder::copy_runs_from_host_ram and
copy_runs_to_host_ram take (buffer byte, host run) pairs, so a laid-out surface copies in one call;
copy_from_host_ram and copy_to_host_ram lay their runs one after another as before, behaviour and
refusals unchanged, so RUNTIME_VERSION stays.
Verified (irisperf): Iris ms01 8653 host RAM copy tests 18/18, negative control fails the
laid-out test; gem10 8633 runtime clippy plain and m2v_gpu, signature/refusal/api_surface 19/19,
lavapipe host_ram 57/57. Iris, a 31.5 MB laid-out BGRA surface downloaded in one call: 1.02 ms GPU
and 1.79 ms CPU against 4.29 ms and 8.78 ms one call per row.