4b37878cdaa103cb8b0fe882474cd5961baafafe
90
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2d98657ca8 |
A Managed buffer's pages that a guest RAM's chunk imports hold are copied in by the GPU from them
What: a Managed no-copy buffer on a device without unified memory can have
a host copy that is its pages alone, because its own import would map pages
a live import holds or the device refused it. Where a guest RAM's chunk
imports hold all of those pages, it now keeps the pieces of those imports
(host_ram.rs RamOnDevice::pieces_of, ChunkPiece). The caller's resolver is
still asked once: its answer is kept for the pieces.
- Its copies in (as it is made, at a rebind, and each range
did_modify_range names under AtSubmission) are GPU copies from those
imports' VkBuffers, one per piece. They are held as a host copy
(Keeps::HostCopy): nothing is staged, no bound applies, no submission is
made. AtCommit still stages a named range on the CPU at the commit.
- New public WorkCounts, so a pass can tell the paths apart:
- managed_bytes_staged_in, the bytes the CPU staged for copies in;
- managed_bytes_copied_in_from_ram;
- managed_pages_alone_refused, managed_pages_alone_over_imports and
managed_pages_alone_unwritable, why a host copy is its pages alone;
- managed_pages_in_ram_chunks.
- Tests: tests/host_ram_managed.rs, a buffer across a chunk's end with
both chunks imported, under both policies. It checks the counts (pages
alone over imports, held by the chunks, nothing imported, gate unasked),
the bytes the GPU reads as the buffer is made and after a named CPU
write across the end, and which path copied them.
- Docs: managed_copy.rs, managed.rs, buffer.rs, HostMemory::with_runs,
docs/API.md, and FAST-PATHS row 51. Signatures blessed.
Why: such pages were staged by the CPU at every commit that took a named
range. That is a CPU copy and staging memory, on the commit's thread, for
bytes the device already maps through the chunk imports. Zero copy first.
Verified: not run at this commit. The 2080 equality tests and the bench
(before at the bench commit, after here) and lint follow on the rebased
branch.
|
||
|
|
70fcece3f5 |
A making's copy in goes as a plain fill: no command buffer can have read its bytes
What: buffer.rs's Replaces says what a copy from a buffer's host copy into its own bytes replaces. - Unread: the buffer's making (a two-copy no-copy buffer's first copy in, managed_copy.rs; Device::new_buffer_with_descriptor's upload), or its device copy's making on a recovery's new VkDevice. It registers as a plain fill (FirstMoves::register_bytes), as before |
||
|
|
5039015420 |
An import several no-copy buffers over the same bytes lie in stays releasable
A no-copy buffer made over exactly the bytes a live one covers lies in that
buffer's import (host_aliases.rs, "One memory, one import"). Until now its
making read the import apart (ReadApart::SecondBuffer), which keeps a
releasable import imported for good. Such a buffer reads the import the way
the first one does, through the import: its blits take the import's objects,
imported again where released, and any other read of it exposes the import
just as a read of the first buffer would. So the import now stays releasable
while every read of each buffer in it was a blit's, or there was none. A
buffer that is never read, made only to keep the bytes imported, keeps the
import no more than a buffer read only by blits does.
Why: on the RX 7900 XTX (RADV), a guest's 3D benchmark kept 1,000 to 1,330
dma-buf imports live. RADV lists every one of them in every kernel submission,
at 0.43 to 0.44 us each (docs/FAST-PATHS.md, known gaps). Of those imports,
1,262 were held for good, and every held one had a second buffer lying in it.
The consumer keeps a holder for each view of guest pages: a no-copy buffer
over the whole view that nothing reads, with the block's buffer lying in its
import. The frames named about 0.6 imports per command buffer, while the
scheduler thread spent 0.63 to 0.90 s of each second in vkQueueSubmit, at
0.835 ms per call. Our own blocks on that device are plain VRAM, which RADV
makes local and lists in no submission.
What still keeps such an import imported for good:
- a no-copy heap's own bytes lying in it: the heap's placed buffers'
addresses are the heap's, handed out without any read of the import noted;
- a rebound buffer lying in it, as a rebind's own import is kept;
- a buffer bound inside its memory with a VkBuffer of its own;
- a buffer made to share its buffer's range (BufferDescriptor::range_of),
which is handed that buffer's address.
Counters: the gauge host_imports_read_apart_second_buffer is split into
host_imports_read_apart_inside, _shared_range, _heap and _rebound. The new
host_imports_joined_releasable counts the buffers that came to lie in a
releasable import beside another and left it releasable; a walk shows the
path ran when it is non-zero. host_residency.rs ("Several buffers in one
import"), host_aliases.rs, the WorkCounts docs, docs/HOWTO.md and the API
signature table say so.
Test: tests::host_residency::an_import_two_buffers_lie_in_is_released_while_idle_and_read_right_again.
It makes a never-read holder and a second buffer over the same 4 pages of a
udmabuf-backed memfd. Joining keeps the import releasable (nothing held for
good, no read apart) and imports nothing new. Read by a blit, the import is
released. The file's writes made while it is released are read by the next
blit through the second buffer, imported again from the kept descriptors. It
is released again. Then a kernel binds the second buffer, makes the holder
resident (useResource:, as Metal reaches a no-copy buffer through an address
only once a command buffer used it) and loads the holder's Metal address from
set_bytes; the binding imports the import again for good. The words the kernel
reads through the address, and the words it writes through it, are checked
against the pages. The source is called once, and the import leaves the gauges
once its buffers go.
host_import_counts now expects a second buffer over the same bytes to read
nothing apart.
Verified (the runtime's debug test binary, --cfg m2v_gpu, not a release build):
- m3-max-23710 (msi-laptop): cargo clippy --workspace --all-targets
--all-features -D warnings, the runtime's clippy under --cfg m2v_gpu, and
the runtime's rustdoc with -D warnings: clean.
- m3-max-23713 (msi-laptop): the API signature tests, 16 passed; the
runtime's suite, 1502 passed, 6 skipped; on lavapipe (--cfg m2v_cpu_icd)
the host_import_counts, host_residency, pointer_residency and host_aliases
tests, 39 passed.
- m3-max-23761 (Radeon 780M, RADV PHOENIX): the host_residency and
host_import_counts device tests, 15 passed, the new test among them ("1
chunks of two buffers released twice, imported again twice"). The negative
control, the same binary with a joining buffer reading the import apart as
before, fails the new test at "the second buffer kept the import for good"
(held for good 1, expected 0).
The lint and suite jobs ran one commit before the test's last change (the
holder made resident before the kernel reads through its address), a
test-only change that the 780M run's binary carries.
|
||
|
|
a52c30aff2 |
A recovery carries no-copy heaps and the textures placed in heaps
What: a heap over the caller's memory (new_heap_with_bytes_no_copy) is
carried as a no-copy buffer is: its own buffer made again over the same
pages (Buffer::carry_no_copy, now for a heap's own buffer too, kept among
no program resources; its pages keep what they were made of, a heap's own
included), its identity kept, the buffers placed in it carried at their
offsets (Buffer::carry_placed), their bytes as they are. The textures
placed in a carried heap, Private or no-copy, are made again there after
the heaps (Remake::Heap, Device::heap_texture_again): as the runtime's own
texture over the same range of the heap's bytes, through the making that
placed them (a texture buffer's buffer carried with carry_placed), sharing
the range's makeAliasable flag (HeapPlace::aliasable is an Arc), the range
handed to the newest image (HeapPlace::again, hand_range_to), so it is
given back once. A Private heap's texture reads as a new one, a no-copy
heap's reads the pages. The heap keeps its textures numbered as they were
(no forget_held); one the recovery leaves is forgotten (Numbered::forget,
Heap::forget_texture). A texture over a carried heap buffer is made again
over it, as over any carried buffer. Heap::carry answers what its bytes'
carry did with their contents and None where it was carried already, so
the notice counts no-copy heaps apart (", and N no-copy heaps with the M
buffers placed in them, over the same pages") and textures placed in
no-copy heaps apart ("N textures placed in the no-copy heaps carried"),
a Private heap's textures by storage mode. Docs: heap.rs, texture/carry.rs,
device/carry.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs,
API.md), the runtime README, and FAST-PATHS's known gap on lost texture
contents, which now names a Private heap's textures.
Why: reims's forced recoveries (3090 m3-max-23482, XTX m3-max-23547) left
44 no-copy heaps and 929 heaps' textures refused: 3424 refused texture
binds in one compositor's command buffers, 82 placements in those heaps
refused, the desktop mostly black after. Metal keeps a heap and what is
placed in it. The owner's call: a Private heap's textures are carried with
their contents lost, as new_texture's are.
Verified: a check of the runtime's lib and tests under plain and
m2v_cpu_icd was clean (m3-max-23688, on a probe commit of this change);
the lane that follows runs the tests.
|
||
|
|
2b8b56617d |
An object a recovery carries answers the caller's own device handle
What: the public device() of every object whose borrow reached a handle a recovery lets go of answers an owned Device, a clone of the generation handle it read: Buffer, Texture, Heap, IndirectCommandBuffer, Event, Fence, SamplerState, Library, Function, DepthStencilState, AddressPool, DynamicLibrary, BinaryArchive and SharedTextureHandle (whose device is its texture's). The runtime's own reads keep a borrow through a crate-private generation() on the types they read it of (Buffer, Texture, Heap, IndirectCommandBuffer, SamplerState, Function, BinaryArchive): 301 call sites, so no hot path pays a clone. Each changed item's doc says the handle is the caller's and keeps its generation, VkDevice included, while held, past a recovery that carries the object on; MadeOn's doc states that no borrow of it reaches the program. The validation lane's four callers that passed the borrow on take a reference of the handle. Signature table re-blessed (14 rows). Why: these accessors answered a borrow into device/carry.rs's MadeOn (a Buffer's or Event's parts, or a LineDevice's GenerationLink), whose let_go drops that Device at the lost generation's rest while the object lives. Safe code that held the borrow across a recovery and that rest read a dropped Device. Metal's device property answers a retained device. The other objects' device() (queues, command buffers, argument encoders, rate maps, pipeline states and their function tables) answer a borrow of a handle the object owns for its life, which no recovery lets go of. Verified: the lane that follows runs tests::device_recovery_handles before (it fails: one live VkDevice while the borrow is held) and after the fix; a workspace check of the accessor change was clean under the plain cfg and found the four validation callers under m2v_gpu and m2v_cpu_icd (job m3-max-23584 on a probe commit). |
||
|
|
a14dca977f |
did_modify_range: a batch takes no upload of bytes a later commit took
The 3090 run of the race fix (a392521bff) still read the wrong bytes, on one queue as on two: 48 rounds of a Managed buffer, each writing its byte, naming the range and committing a copy of it, read the last round of the buffer's bytes in rounds 1 and 2 of each four (3 read 7, 5 read 7; never the 0xee each round writes after its commit). Each commit staged its own bytes, but the scheduler submitted the earlier rounds after the CPU loop had committed the later ones, and an earlier round's batch took every upload of the buffer waiting, its own and the later commits', copying them in order before its blit. Each commit now takes a stamp under Modified's lock (take_at_commit returns it; the command buffer keeps it in State::commit). An upload taken at a commit carries its stamp (FirstFill::upload, register_upload's commit), and a batch takes an upload only where its command buffer's stamp is at least the upload's (FillTake::Owned and FillTake::Reached carry the batch's). An upload no commit took (a buffer's making, a rebind, a completion's undo) carries 0 and goes with any batch that reaches it, as before. Internal submissions take every upload, as before. Verified: first_move's unit test an_upload_goes_with_no_batch_committed_before_its_bytes_were_taken (an upload of commits 2, 3, 4: a batch of commit 1 takes none, of 2 the first, of 4 the other two, on devices with and without a fill queue); the 3090 before/after of ranges_named_ follows on this commit. |
||
|
|
36316325da |
An IOSurface plane over a buffer that declares padding unobserved takes the declaration
What: Texels::padding_owned is true for an IOSurface plane's rows where the buffer declares the bytes between a texture's rows unobserved (BufferDescriptor::padding_unobserved), as for a buffer's rows: such a plane whose rows, each to its pitch, share no line with bytes past them has Padding::Unobserved, so a render asks the check of renders over unobserved padding (Access::UnobservedRenders) and a shader's writes the check that lets the padding change. Without the declaration a plane's padding stays Kept. The docs of Padding, Padding::of, padding_owned, Texels::padding, in_place.rs's module docs and BufferDescriptor::padding_unobserved say so. Why: Metal keeps an IOSurface plane's padding under every command, but bytes the buffer's maker declares nothing reads cannot tell keeping from changing. A guest's WebGL page on the Iris Xe made 431 surface tiles over padding-unobserved Private buffers shadows (each 'an image whose texels share a line of memory with bytes beside them'), as the plane's padding asked the check of renders that keeps every byte, which the Iris fails for rows ending inside a 64-byte line. Verified: the parent commit's test, lavapipe before and after; clippy three ways and rustdoc (job ids in the report). |
||
|
|
4ae4f9b5d4 |
An object's device stays a generation handle across a recovery
What: a fence, a depth/stencil state, a library and its functions and an address pool hold their device as a LineDevice (device/carry.rs): a root handle, which their own checks match by the line as before, and a chain of generation handles, kept by the generation's carry registry. device() answers the generation handle of the generation the object was made on, else of the one a recovery carried it to last, as a carried buffer's or texture's device does. The recovery links the next generation's handle after the lost one and lets the lost one go at the lost generation's rest (MadeOn, a LostParts entry), so the object still holds nothing of the lost generation once it rests; a handle a caller took keeps meaning its generation and keeps it alive while held. A library's functions share the library's chain. The internal checks (encoders' fence and depth/stencil checks, sparse fences, dynamic libraries, function handles, pipeline additions, compute creation from a function, a pool slot's placement) use the new root_device() accessors. Docs: the four modules, carry.rs, MadeBeforeRecovery, the runtime README. REFUSALS.md regenerated: unchanged. Why: RV 2155-2159 made those device() accessors answer a root handle, an API break: a root's raw() answers whichever VkDevice serves and lets go of the one it answered before, so a consumer that takes `new_fence().device()` as the serving generation's handle destroyed objects made on the lost VkDevice through the new one's handles (SIGSEGV in vkDestroyCommandPool on ANV). Verified: see the lane run reported with this sha (the test commit before it fails, this one passes). |
||
|
|
bf9e921058 |
Guest RAM: on ANV an object over a listed chunk keeps its own path
7536aa8c75 had an object over a listed chunk not imported import the chunk where the device's barriers do not order two imports of the same pages (ANV), or where the object had no source of dma-bufs. With a consumer's run resolvers on every object, that pins every 512 MiB chunk any object lies in, the residency regime RV 2144 left. Back to RV 2144's object path on every listed plan: the object takes its own path (its import of dma-bufs alone where the aliases are ordered, 345302afc2). On ANV its own import still holds the chunk back from the copies over it; the CPU path that takes those copies follows separately. The beside test now runs where the device orders the aliases only, and the listed idle test's first object takes its own import on every driver, as before. |
||
|
|
f7941289d2 |
Guest RAM: an object a listed RAM routes outside its chunks imports its dma-bufs alone
The object's own path on a listed plan whose device orders two imports of the same pages (7536aa8c75) took its pointer first wherever the device takes it, as every own import does (lavapipe takes a shared mapping's pointer; RADV refuses it, so its imports there were dma-bufs already). An import of the pointer at the RAM's own addresses holds the chunk back (one page, one import), so the copies over the chunk could still not import it. Now pages a guest RAM routes that no chunk binds in, where the RAM's chunks may be imported beside them (Routed::own_dma_bufs: listed plan, ordered aliases), are imported as the caller's dma-bufs alone, never by the pointer and the gate not asked, as pages beside live dma-buf imports are since RV 2134; a failed import of them is a copy. At the buffer's making and at a rebind. Found by the new test on lavapipe (m3-max-22946): the object's own import was ImportedByPointer where the test expects ImportedAsDmaBuf. |
||
|
|
9c35a3407d |
Guest RAM: a listed chunk is imported beside objects' own dma-bufs; on ANV objects import it
Since RV 2144 an object over a chunk not imported on a listed plan takes its own path,
outside the RAM's routing. At the RAM's own addresses its import is noted in the
aliases registry, which held the chunk back (RamOnDevice::held_back): the chunk could
not be imported while the object lived, and a copy by runs over it that no CPU stage
takes (a gather over bytes an object lies over) failed with "a guest RAM chunk a live
import of an object's own holds pages of" (a consumer's IOSurface block on the Iris Xe,
Mesa 26.7.2; on the 780M the hold-backs went from 4 to 45 in a walk once every object
got a run resolver, the copies falling to run lists).
Two cases, by whether the device's barriers order blits through two imports of the
same pages:
- They do (RADV, lavapipe): held_back now answers Held::{Free, BesideDmaBufs, Back}.
Where every live import holding the chunk's pages is of dma-bufs and the plan is
listed, the chunk is imported beside them as one dma-buf of the RAM's source, never
by its pointer (import_chunk's new beside flag drops the pointer fallback): two
aliases of external memory, ordered by the host bytes they lie over, the rule
Device::imports_beside applies to objects' own dma-bufs since RV 2134. Counted as
ObjectChurn::dma_buf_imports_beside_live, not host_ram_chunks_held_back. Imports of
a pointer, and claims in flight, still hold the chunk back.
- They do not (ANV, AliasedImportBlitsUnordered): the chunk's import beside an
object's would be unordered, so an object there takes the chunk's import (made or
waited for), as it did before RV 2144 and as on plans that import ahead. So does an
object with no source of dma-bufs of its own pages, whose own import would be of its
pointer. for_object takes the object's `sourced` (HostWindow::source) through
bind_in_chunk.
Docs: host_ram.rs (module, Held, held_back, for_object, copy_take, import_chunk,
use_host_ram), WorkCounts::host_ram_chunks_held_back and chunk_bound_buffers_made,
ObjectChurn's two import counters, HOWTO.md.
|
||
|
|
27cd4bccc0 |
Guest RAM: on a listed plan an object over a chunk not imported takes its own path and asks for no chunk
On a device whose plan is listed (each held import costing every submission and the RAM's chunks its dma-bufs: RADV, ANV where the import tax holds), an object over a chunk whose import was not made was bound in an import of its own run and asked the device's thread for the chunk, which faulted in and imported the whole chunk: udmabuf allocates every page of it and keeps them after the import is freed, so attaching runs to every no-copy object would make the guest RAM under every object resident chunk by chunk (12.3 GiB of a 16 GiB guest on the 780M before the listed plan). Now such an object is bound in the chunk only where its import is made, and otherwise takes its own path, as over memory no RAM holds: no run import, no ask. Chunks are imported for the copies over them, and the objects over them after that lie in them. Plans that import ahead (NVIDIA, host-pointer chunks) are unchanged. Removed with the object path: RunAgain, Routed::run_again, Placement::over_ram_run, the residency's AgainFrom::RamRun with Device::ram_run_in_chunk and ram_run_alone_again, and WorkCounts::run_bound_buffers_made (an object is never bound in a run import now; copies keep their ranges alone and run_imports_live). Docs: host_ram.rs, host_residency.rs, copy.rs, HostMemory::with_runs, driver_defects.rs, WorkCounts, HOWTO.md; the API signatures table re-blessed. Tests: the listed tests now import their chunks by copies; the first object over a chunk not imported, with a source of its own pages as a consumer's come, takes its own import, no chunk imported and none asked of the RAM's source, and the objects over a chunk a copy imported lie in it. The other host RAM tests lose their run-bound terms (0 on every plan they run). |
||
|
|
47ca9278c8 |
Pages beside live dma-buf imports import their own dma-bufs, not a copy
A no-copy buffer or heap (made or rebound) whose pages a live import of another holds some of was always a copy of them (CopiedBecause::OverImport), for VK_EXT_external_memory_host's undefined second import of a host pointer (its issue 6). On RADV every no-copy object's pages are udmabuf dma-bufs, which that clause does not cover, so since the one-import rule landed a consumer's 780M walk made 2715 such copies (copied_over_live_imports, 292 MB copied in). Now, where every live import that holds some of the pages is of dma-bufs, the pages come with a source of dma-bufs the device imports, and the device's barriers order blits through two imports of the same pages (no RuntimeDriverDefect::AliasedImportBlitsUnordered, which ANV and MoltenVK have), the object imports its own dma-bufs from the source, never its pointer (Device::imports_beside). Two dma-bufs of the same pages are two aliases of external memory (Vulkan 1.4, 12.11 Memory Aliasing: consistent for buffers, uses separated by a memory dependency); the tracker orders every use by the host bytes it touches across keys with global memory barriers, as for a guest RAM's run imported beside its chunk. A pointer import on either side keeps the copy. A failed import there falls back to the copy, announced with the failure. HostAliases::within now names the live imports that meet the pages (Within::Meets(Vec)). Counted: ObjectChurn::dma_buf_imports_beside_live (imports_inside_live stays the count of pages imported twice where that is undefined). Tests: tests::dma_buf_beside (device, Linux): a buffer over part of a live import's pages and a buffer rebound onto pages two live imports hold some of, as made and without pointer imports: beside dma-bufs where the first import is of dma-bufs, else a copy; the GPU reads the CPU's bytes, CPU writes between encode and commit reach the command, GPU writes reach the pages and the other buffer, and in imports a fill through one and a copy through the other in one encoder are ordered either way. The host_aliases unit test checks Meets names the import met. The validation lane's dma-buf joined-import test takes the third outcome. Checks: to run. |
||
|
|
41b54edde6 |
Rebind: the noted import joins no key; a rebind onto a rebound buffer's bytes lies in its import
b5bfbaf377 noted a rebound buffer's own import with join, which gives the buffer the memory's
key: host_aliases.rs keeps the memory a rebound buffer takes unjoined ("Not joined"). It is now
noted with hold, as a heap's own import is, joining no key, and so is the live import a rebind's
new pages lie in (shared by bytes another buffer's note holds), so that the note stays while any
buffer lies in it.
With the import noted, a rebind onto bytes a rebound buffer's import holds lies in that import
(one page, one import) where it imported them a second time before.
host_import_counts::a_rebind_s_import_is_unlisted_until_a_command_buffer_uses_it_and_covered_
over_bytes_lain_over (m3-max-18968: [2, 1, 2] expected, the second rebind making no import)
asserted that second import; it is renamed ..._and_shared_over_bytes_it_holds and asserts one
import, none covered, unlisted until the first command buffer. host_aliases.rs's docs say the
bytes rebound onto are looked up and shared as those made over.
|
||
|
|
711b74238b |
Rebind: an import of the new pages of the buffer's own is noted, as a making notes one
rebind_host_pages placed the new pages in the alias registry (aliases.place) but never noted their import, so held_back could not see it: a guest RAM chunk holding some of a rebound buffer's own imported pages was imported over them, the same pages imported twice (a_rebind_s_own_import_holds_its_chunk_back_while_it_lives). After the rebind leaves the memory it was made over, an import of the new pages of its own (not a copy, not bound in a chunk or inside another import, not a read-only view) is noted as a making notes one: join for a buffer, hold for a heap's own buffer. The rebind's claim of guest RAM pages (Device::claim_ram_pages) now lasts until that note, so no chunk's import slips in between the import and the note. |
||
|
|
88af28874e |
Host RAM: an object's own import claims its RAM pages until noted; chunks mark in flight under the claims
The straddle copy (f083e9c806) and the held-back chunk (c55501db1b) each read only finished state: an object's check read made chunk imports alone (chunks_hold_any), and a chunk's check read noted object imports alone (the alias registry). So an object made while a chunk's import was in flight, or a chunk imported while an object's own import was between its checks and its note, imported the same pages twice. Both tests of 1d77522508 showed it on lavapipe, 3 runs of 3 each (m3-max-18881): imports_inside_live 1. Each RAM the device uses now keeps the claims of objects' own imports in flight. An object's making and a rebind claim their window's RAM pages (Device::claim_ram_pages) where no chunk binds them, and hold the claim through their import until it is noted: where a chunk's import, made or in flight, holds some of the pages, nothing is claimed and the object is a copy (CopiedBecause::OverRamChunk, as for a made one). A chunk's import is marked in flight only under the RAM's claims (RamOnDevice::chunk takes them before the chunk's lock, as a claim does, and looks at the chunk again), and is held back where a claim meets its pages (held_back), as where a noted import does. Whichever starts first, the other never imports the same page. Docs: host_ram.rs's one-import bullet; the OverRamChunk cause, copied_over_live_imports and docs/API.md's copied-host-pages entry say made or in flight. |
||
|
|
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. |
||
|
|
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. |
||
|
|
4f3bc2e7a3 |
One page, one import: compile fixes (a Pages placement accessor, raw handle bits in Debug, an unshadowed test heap)
The first build of ed11f23e9a failed: bind_in_import read Pages' private memory field, InImport's Debug printed handle flags ash gives no Debug for, and a test's heap binding shadowed its heap helper. Found by potluck job m3-max-18250 (lavapipe build on ms01). |
||
|
|
cfd7bc829e |
One page, one import: a buffer over a live import's pages lies inside it, else a copy
VK_EXT_external_memory_host leaves a host allocation imported twice into one device undefined (issue 6: "Some platforms do not allow locking the same physical pages for device access multiple times, so attempting to do it may result in undefined behavior"). The runtime imported the same pages twice in several ways: a heap's own import was never noted in HostAliases, so a no-copy buffer over exactly a heap's bytes, or over part of them, imported them again (the consumer's guest heaps over 2 MiB page-block views, and the block's view as a buffer); a buffer over part of a live buffer's bytes imported its own (counted, object_churn.imports_inside_live: 34 in one 3090 walk); and a heap over a live buffer's bytes imported its own. Now: - a heap's own import is noted (HostAliases::hold), joining no key; - a buffer or heap over exactly a live import's bytes lies in that import (a heap keeps its heap identity); - a buffer whose window a live import holds all of is bound inside that import's memory at its offset, with a VkBuffer of its own and no import (Device::bind_in_import, Placement::in_import, which holds the import; the import is exposed, so never released while idle); counted object_churn.buffers_bound_in_import; - a buffer or heap whose window a live import holds some of and not all, and a heap a live import holds more than, is a copy (CopiedBecause::OverImport, copied_over_live_imports, announced copied-host-pages); - rebinds take the same rule; - imports_inside_live now counts only imports made where a live one held some of the pages all the same (two buffers made at once). Tests: host_aliases unit test a_page_a_live_import_holds_is_never_imported_again; device tests one_import (heap first, buffer first). Not yet run: this commit is for the build. |
||
|
|
569ac877dc |
copied-host-pages is announced once per cause, not once per kind
A consumer acts on a refused import, a failed one and a move apart, and rule 2 says each degradation is announced; the kind-level once let a gate's refusal silence a later failed import on the same device. Device::degrade_copied_pages keys copied-host-pages by its CopiedBecause cause (and a buffer lying in another's live copy as a reason of its own) with a bit per reason in the device's Announced record. Device::degrade keeps its rule for every other kind; both share degrade_where (lowering refusal, replay, announce_each, placement), so only this kind's record changes. Test: copies_of_two_causes_on_one_device_are_each_announced, a refused copy then a failed one (fail_next_host_imports) both heard with their reasons, a second refused copy not. docs/API.md states the rule and the entry. |
||
|
|
07a21899ed |
Runtime: contents of a detached no-copy buffer answers the caller's pointer of the pages it lay in last
Metal's contents answers the last pointer across a detach (the caller's pointer of the last replace), and the consumer's host library expects contents unchanged across detach and replace; the runtime answered None. Buffer::contents now answers that pointer while a no-copy buffer, a two-copy Managed buffer (either host copy route) or a no-copy heap's buffer is detached. The runtime itself reads and writes nothing through it: every internal caller takes the new crate-private mapped_contents, which keeps the old answer (None while detached), and buffer::Detached keeps the old mapping's address only to answer contents. Tests: tests::detached_contents (Shared and Managed no-copy buffers, and a no-copy heap's buffer) maps the pages with no access while detached and runs a blit and a synchronize of the buffer; managed_copy_device's detach legs and the validation detach lane assert the pointer. Docs: Buffer::contents, detach.rs, docs/API.md, the runtime README. |
||
|
|
61073ee41c | Runtime docs: a two-copy Managed no-copy buffer's making, rebind and detach | ||
|
|
8d7dfc4623 |
Runtime: a Managed no-copy buffer is two copies on a device without unified memory
On a Mac with a discrete GPU a Managed resource has two copies, the CPU's and the GPU's own, synced at didModifyRange: and a blit's synchronizeResource:, and a Managed buffer over the caller's pages is no exception: a kernel read one 256 MiB such buffer and wrote another at 102.5 GB/s on a Radeon Pro 5300M. The runtime left it in the caller's pages, read across the bus (5.8 GB/s on an RTX 5080 Laptop), as a Shared one. Now (managed_copy.rs) such a buffer is a buffer of device-local memory of the runtime's own, as a Managed buffer the runtime makes there, whose host copy is the caller's pages: an import of them made as a no-copy buffer's (by pointer, dma-bufs, a guest RAM's chunk), outside the Metal address space, or, where the device imports none, the pages alone (never a copied.rs copy as well). contents is the caller's pointer; the deallocator and keep-alive go as a no-copy buffer's. - Copies in (the making, did_modify_range, a rebind) go through the device's next submission's first work, after the commands before it on its queue: from the import's VkBuffer, or through write-combined staging of 32 MiB at most, freed when the submission completed. - synchronize_resource copies out as a blit's write of the import, or into host-cached staging copied to the pages at the command buffer's completion (CommandBuffer::at_completion, run in completion.rs before anything sees it complete). - Read-only pages: nothing is copied out, and the pages are copied in again at the completion of each command buffer that used the buffer. - Rebind and detach act on the host copy (the import's own, or the pages'), a rebind copying the new pages in whole; a recovery makes the host copy again and copies the pages in. - No device-local room: the buffer lies in its pages, announced as device-memory-overflow, never refused. - Counted: WorkCounts::managed_device_copies*, managed_bytes_copied_in/out, managed_staging_bytes, managed_writes_undone. HostBacking::DeviceCopy. Not yet built: the commits after this one fix what the build finds. |
||
|
|
d3ab77f844 |
Runtime: take resource option bit 20 as Metal takes it
Bit 20 (0x100000) is an option no Metal header names, of unstated meaning, which programs pass with their buffers' options (0x100010 for a Managed no-copy buffer). ResourceOptions::from_raw refused it as undefined, so such a buffer could not be made at all. Measured with probes/resource_option_bit20.m on an M3 Max (macOS 27.0.1) and a Radeon Pro 5300M (macOS 26.7.1), plain and under API validation: buffers of a length, of bytes and over the caller's pages are made with it, of every storage mode, and report their options without it; so do a heap and a heap's buffer (API validation stops the heap's buffer); a texture descriptor with it ends Metal's process. So from_raw takes it (ResourceOptions::BIT_20), every buffer and heap maker drops it (own_memory_options, no_copy_options, take_options, a heap's new_buffer), and texture_options refuses it as it refuses bit 24 there. Nothing reads it. docs/API.md states both halves; api_signatures blessed. Tests: values::bit_20_is_taken_and_dropped_apart, and the device test option_bit_20 (buffers, no-copy, heaps and their buffers report without it; a texture descriptor with it is Invalid). Not yet run. |
||
|
|
8a25f74631 |
Runtime: the copy notice's reason is typed as a str where the failure's words join the fixed causes
degrade_copied's reason took a String's borrow in one arm of a nested match whose other arms are string literals; the binding is now typed &str and the arm borrows the String as one, so every arm coerces to the same type. No behaviour change. |
||
|
|
49175d0a24 |
Runtime: a copy made after a failed import of no-copy pages names the failure in its notice
What: the copied-host-pages announcement of a no-copy buffer, heap or rebind made a copy because the import the device and the gate admitted failed (WorkCounts::copied_host_buffers_degraded) said only "their import failed". It now names the failure (FailedImport::cause in buffer_descriptor.rs): for pages the runtime kept from a driver whose failed import of unpinnable pages breaks it (RuntimeDriverDefect::UnpinnablePagesBreakHostMemory, NVIDIA's), that the kernel cannot pin some of them (a dma-buf's mapping, VM_PFNMAP, or one it could not ask about), and whether a source of their dma-bufs was asked (none given or the device imports no dma-buf; or the caller's source made none, or the device refused them); for an out-of-memory or other Vulkan failure, whose import failed (the pointer's, or the caller's dma-bufs' after the pointer's refusal) and the error. The copy path carries the failure and whether the source was asked (CopiedFor::Failed(FailedImport), the rebind's Err(Some(FailedImport))); copied_pages borrows the error. Nothing else changes: the counts, the copies and every refusal are as before. Why: on the RTX 5080 the consumer's no-copy buffer over a view mapped through two udmabufs was copied (copied_host_buffers_degraded 1) with no notice line saying why, and finding the cause took a round trip. Docs: the CopiedHostPages declaration and docs/API.md's catalogue entry say the reason names the cause. Tests: tests::host_memory::a_copy_after_a_failed_import_names_the_failure (no device) holds the four causes' words. tests::host_ram_device::pages_refused_before_the_driver_with_no_source_are_copied now announces each copied-host-pages (DeviceOptions::announce_each) and, on a driver with the defect, asserts each of the buffer's, heap's and rebind's three reasons names the unpinnable pages, the defect and that no source was asked, printing each (HOST-RAM-COPIED). Before this commit each reason was "their import failed", which names none of them. |
||
|
|
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).
|
||
|
|
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. |
||
|
|
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). |
||
|
|
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). |
||
|
|
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. |
||
|
|
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. |
||
|
|
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
(
|
||
|
|
086e684cb8 |
A buffer that lies in another's import keeps what it was made of on its own pages
Each buffer over a live import has pages of its own (`HostCell` over `HostPages`), so the shared-import path has to give its pages the parts too. After a5222925b2 it gave them nothing, and the recovery left such a buffer on the lost generation as a detached no-copy buffer: the probe run (m3-max-11758) reported "2 buffers with their contents" for the pointer import, its alias and the gate-refused copy. The parts are kept at the path's existing look at the pages, so the making still looks once. Verification: to run on lavapipe with the recovery tests. (cherry picked from commit e22110a9a63f2f61f0a2a1ba90fb0d6ea7cf7f15) |
||
|
|
56382cbd95 |
A buffer's pages keep what they were made of from the making's one look at them
buffer_over_host_parts looked at where the new buffer lies a second time to give its pages what they were made of (`HostPages::made_of`), so making a no-copy buffer looked twice (`tests::no_copy_lies` read 2 against 1). What it was made of is now given to the pages with their log, runs and copy name from the one look (`keep_in`, `kept`), and the wrapper folds into the function it wrapped. A buffer that lies in another's import leaves its pages the first buffer's parts, over the same bytes. The guest-RAM carry test compared the device's bound-buffer counts, which are kept across its generations, against 1 after the recovery: it now compares the recovery's own, from before it. Verification: to run on lavapipe (the recovery tests and the runtime's whole suite). (cherry picked from commit 0f89fe34b5e7f0116fe35b4593ab2fb344c4bb74) |
||
|
|
15923d88c0 |
Docs: a recovery carries no-copy buffers and uses of guest RAM
The DeviceRecovered cost text (and docs/API.md's catalogue entry, which states it), the runtime README's recovery section, new_buffer_with_bytes_no_copy, and the contracts of the import gate, the run resolver and the dma-buf source now say the following. A recovery carries a device's uses of guest RAM and its no-copy buffers. Each buffer is made again over the same pages. The caller's callbacks are asked again on the thread that recovers, before the new device serves, so they must make no call on the device. The deallocator runs at the buffer's release once no VkDevice's import of its pages is left (the keep-alive's contract says the same). Detached no-copy buffers and a no-copy heap's buffers stay refused. HostRamUse's doc says the use goes on. (cherry picked from commit 58ba0931b857a9dcf9a6124138c81fc31a259552) |
||
|
|
446f9ebc8d |
Recovery carries no-copy buffers, made again over the same pages
A recovery now makes a no-copy buffer again on the new generation, over the caller's pages it lies in, from the memory they were given as (HostPages::made_of). It goes through the same making as before: an import of the pointer or of the source's dma-bufs, a run of a guest RAM the new device uses (carried just before), a copy, or a read-only view. The caller's gate and resolver are asked again there. The made buffer keeps the buffer's ObjectId, identity, label and purgeable state, its Metal address (a share of its range) and its range token. Its contents pointer and bytes are as they were. Release order: the deallocator and keep-alive move to a HeldBack (Release::carry_on). It now counts the imports of the pages still mapped (the lost generation's, then each later one's) rather than a single flag. The pages made on the new generation carry a release that tells the HeldBack the buffer's release came and that their own import went (Release::carried, HeldBack::released). So the deallocator runs at the buffer's release, or at its next rebind, once no generation's import maps the pages, or at once where a keep-alive keeps them mapped. A detach of the carried buffer holds back the same wait, as a detach holds back a deallocator. At the lost generation's rest, the buffer's parts there go (LostHost). It leaves that generation's live buffers and its registries of no-copy buffers. Its cell's pages go (Lying::Gone, which nothing reads from then on). The cell and the buffer let go of their handles of the generation (HostCell::device is now a MadeOn). A call under way that holds the parts defers this, as for any carried buffer, and a handed-out VkBuffer keeps them until the buffer goes. Left the lost generation's: a detached no-copy buffer, one whose last detach's deallocator still waits for its next rebind, a no-copy heap's buffers, and any buffer whose making on the new device fails. Verification: none yet. Tests follow. (cherry picked from commit 3a7ea4834d47fac623ef36a325a265b6d4a11e5b) |
||
|
|
e35a85e725 |
No-copy buffers keep what their pages were made of, and a making names who it makes
No change in behaviour; the plumbing a no-copy buffer's carry rests on. - HostParts is clonable. A no-copy buffer's pages (not a heap's own) keep the parts of the caller's memory they were made of (HostPages::made_of), at making and at each rebind: what a recovery makes the buffer again of on the next generation. - buffer_over_host_memory resolves its release and hands over to buffer_over_host_parts, which a carry calls with the parts kept. - Naming says who a making makes: a new buffer, or a buffer a recovery carries, whose ObjectId, identity and attributes it keeps. It goes through BufferParts, buffer_in_import, copied_buffer and buffer_lying. Every other making names a new buffer. Verification: none yet. Builds and tests come with the carry that uses it. (cherry picked from commit 0417e783cc14a6bed17a54fac07df00075a48862) |
||
|
|
5e020e43bd |
fd blocks: buffers that declare their padding unobserved stay in plain blocks
A texture over a buffer whose rows lie apart is in place only where the buffer declares its padding unobserved, and there, over a plain block, it may take a DRM_FORMAT_MOD_LINEAR image at Metal's pitch, which RADV makes for exportable memory only as a dedicated allocation. The placement test at b48d8fae41 counted 15276 such textures lost over exportable blocks for padding-unobserved buffers and 0 for padding-kept ones. So the split: - BufferDescriptor's padding_unobserved reaches the placement (Made, buffer_of_length, NewBufferOf::Unobserved): such a buffer lies in a plain block (Holds::Buffers) wherever; every other buffer of the runtime's buffer path lies where the device's own buffers do. - The recycler's BufferMaking keys on the block kind, so a parked buffer in an exportable block is never handed to a padding-unobserved one. - fd_blocks_cover's second guard asks what a padding-kept texture can take: rows one after another at a multiple of 16 bytes where the device's own linear image lies otherwise, at every width of linear_alignment::WIDTHS, every backed format and usage; any DRM_FORMAT_MOD_LINEAR image of its own memory made there refuses the blocks. The linear layout comparison runs at every width too. - WorkCounts::plain_buffer_blocks_made counts plain blocks of buffers, beside fd_buffer_blocks_made, so a lane can read the share of block makes on each side; the bench prints it. - The placement test tries rows rounded to 16 too, makes the program's buffer through new_buffer_with_descriptor for each padding, asserts where it lies, and asserts 0 lost for both kinds. The nv12 test checks a padding-unobserved picture lies in a plain block while a parked exportable one of its making exists. - Docs: memory.rs, in_place_check.rs, the FAST-PATHS in-place row, the descriptor field and the runtime README. Verified: cargo fmt only; builds and device tests are dispatched next. (cherry picked from commit 6e5c80ac3caaa2ad26c0456ecfc0801bca4ccd42) |
||
|
|
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 |
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) |
||
|
|
65df8cd48a |
Dma-buf export: its test, a second device writing through the import; compile fixes
tests::dma_buf_export: a Private and a Shared frame laying byte 0x20 on a multiple of 256, padding unobserved, exported as a dma-buf; a second VkDevice imports it, writes both planes and releases them to the foreign queue family; external_write_done notes the acquire (deferred for the Private frame, made at once for the Shared one); the planes' textures alias the buffer wherever a plain frame's do and read the second device's bytes. The refusals: a device without the export only where it lacks an extension or the export, NoCopy contents, and buffers not made exportable as a dma-buf. Fixes: MemoryExport is named through buffer_descriptor, and new_buffer_with_bytes passes a Made. (cherry picked from commit f8a90f1199de45b725be40ce7c82146787694ff7) |
||
|
|
976aa0a0ff |
Buffers whose memory is exported as a dma-buf, with the acquire of an external write
A buffer descriptor's exported_as (MemoryExport::OpaqueFd or DmaBuf) makes a buffer of the runtime's own memory exportable as that handle type, with the descriptor's aligned_byte and padding_unobserved. Buffer::export_memory_dma_buf answers a new dma-buf with the allocation's size and the buffer's first byte's offset in it (the aligned byte's lead included), as export_memory_fd does for an opaque descriptor. Dma-buf-exportable buffers share blocks of their own kind (Holds::DmaBufs), or take a dedicated allocation where the device needs or prefers one; pooled exportable buffers now sit at a multiple of 256 bytes as every other buffer of the runtime's memory. Buffer::external_write_done notes the acquire Vulkan needs before the device reads what another API wrote: from VK_QUEUE_FAMILY_FOREIGN_EXT for a dma-buf, VK_QUEUE_FAMILY_EXTERNAL for an opaque descriptor, of the whole VkBuffer, recorded by the device's next submission in the barrier that leads its first work (FirstFill::acquired). A host-visible buffer's acquire is settled at once. The device enables VK_EXT_queue_family_foreign beside the dma-buf route's extensions where listed; a device without them, or whose external buffer properties do not export a dma-buf, refuses the making as NotImplemented(RuntimeGap::DmaBufExport). NoCopy contents with exported_as are Invalid (ExportedNoCopy). The branch carries the narrowed hand-out settle (cherry-picked) so that the export's settle is the narrow one. Verification: none yet; build and tests follow. (cherry picked from commit ad32644d7b2bd0e85ebaec16664b2a6d480f91c6) |
||
|
|
3587dde9da |
BufferDescriptor::aligned_byte: pass the placement and the aligned byte as one pair
zero_buffer handed buffer_of_length the placement and the byte apart, where it takes them as one (Place, Option<u64>) pair (E0061; um870 m3-max-8425, gem10 m3-max-8426). Verified: cargo fmt; the builds follow. (cherry picked from commit ed3f0801da87a9031bc6e98885c2d3c22e6a4293) |
||
|
|
6ba9ac779f |
BufferDescriptor::aligned_byte: lay a buffer's byte on a multiple of 256 bytes of its memory
A consumer that lands decoded frames in a buffer of the runtime's own memory makes plane textures at CoreVideo's offsets: the first plane 32 bytes into the surface, the second 32 bytes past a multiple of 256 after the first's rows. A linear image aliasing the buffer binds at the buffer's memory offset plus the texture's, which must meet the device's linear-image alignment (256 on RADV, 128 on NVIDIA, 64 on lavapipe), and the runtime starts each buffer on a multiple of 256, so those planes are shadows there (the 780M probe, um870 m3-max-8351: Shared and Private buffers, in place at 0 and 256, shadows at 32, 64 and 128). BufferDescriptor::aligned_byte (with_aligned_byte), a runtime extension for the runtime's own memory, names the byte to lay on a multiple of 256 (LINEAR_IMAGE_ALIGNMENT). placed_new_buffer then makes the VkBuffer that byte's shortfall longer, binds it where its placement starts, and starts the buffer's bytes that many bytes into both (BufferParts offset and base, the mechanism host imports use), so the byte lands on the multiple and textures there alias the memory. Such a buffer is never parked nor taken from the parked, and lies in no fresh pages. Its length and gpuAddress (the runtime's address space's) are unchanged; a Shared one's contents start the byte's remainder short of a multiple of 256, which the field's docs name against Metal's page-aligned contents. Refused with NoCopy contents (Problem::AlignedByteNoCopy). tests::aligned_byte: over Shared and Private buffers laying byte 0x20, the 8-bit and 10-bit frames' planes (R8/RG8 at rows 3840, R16/RG16 at rows 7680; the second plane at 0x20 + 0x7E9000 or 0xFD2000), sampled, written and rendered into, alias wherever the same texture at offset 0 of a plain buffer does, and are shadows at 0x20 of a plain buffer wherever the device's linear alignment is past 32; a blit of each sampled plane reads the bytes at its offset; length, gpuAddress and contents as above; the refusal over NoCopy. Docs: the field, HOWTO, API.md's shadowed-texture entry, the runtime README; api_signatures blessed and REFUSALS.md regenerated. New public items: BufferDescriptor::aligned_byte, BufferDescriptor::with_aligned_byte, Problem::AlignedByteNoCopy. Verified: cargo fmt; the 780M, lavapipe and Iris runs follow. (cherry picked from commit bef28766eee658ef30dfcc5d0492a1493171b34d) |
||
|
|
7e5821d9d1 |
In place: renders over padding a buffer declares unobserved take a verdict that lets that padding change (Access::UnobservedRenders)
What: a new check access, UnobservedRenders, that the renders rounds answer beside Renders, as the
storage-write rounds answer BufferWrites beside Writes. Where a shape's rows' padding is free
(Shape::padding), a renders round that changed no byte but of that padding (after a row's last
texel, before its pitch, the last row's included) fails Renders for its row ends and keeps
UnobservedRenders. A byte past the last row's pitch, or a texel, fails both. A new Padding variant,
Unobserved (Free padding over a buffer that declares padding_unobserved, Texels::padding), makes
in_place() ask UnobservedRenders in the stead of Renders (Access::rendered); the wider render-target
plan of an image in place asks the same. The check's SHAPES gain 172x67 BGRA8 at a 704-byte pitch,
whose last row's pitch ends 64 bytes past a multiple of 128 and 256, so a device that writes back
more than a line around a row's last texels changes a byte past the image and fails both.
VERDICTS 48 -> 56 (7 accesses), the record 56 bytes; CHECK_VERSION stays 11 (unlanded).
Why: on the Iris Xe (job 7965 at c4eeeba7e8), the pooled class's Renders verdict failed for rows
ending mid-line (the clear and store, and draws, write back the 64-byte line holding a row's last
texels whole), so none of the 93 device caches went in place (93 shadows, frame 4145 us declared
and undeclared alike), and the item's case (a padding-unobserved texture at a 64-aligned pitch, rows
ending mid-line, rendered) stayed a shadow (CheckFailed{Renders, InLines}). The declaration already
lets a render pass's load and store write those bytes; no byte past the last row's pitch may change,
and Padding::of guarantees the last row's pitch ends on a line.
Also: a padding-unobserved buffer in fresh pages takes the same rule; BufferDescriptor's doc says so.
Tests: unit cases for the compare (the line write-back of each row's padding is Padded; a 128-byte
write-back past the last row's pitch, a byte past it or a texel is Changed), Padding::declared, the
tally (Renders answers two), the decision test over Unobserved padding, the shadow-cause words; the
device test asks the UnobservedRenders verdict and asserts the texels' padding is Unobserved. Device
evidence follows on the Iris.
(cherry picked from commit 990d744ec71269663e292c7f2f3e4148d166bacb)
|
||
|
|
703eca0dba |
Pooled class: tests and docs
The padding-unobserved device test settles the check and holds the answer to the making's (NotHostPages exactly where the texture aliases, else the shadow's cause); a new device test renders textures of the guests' cache shapes (64-aligned pitches, rows ending inside a 64-byte line) over declared buffers and checks that a pitched image appears only where the pooled class passed for reads and renders, that the CPU's texels read back through the texture, that a clear reaches the buffer's rows, and that the bytes after the last row keep the CPU's. The validation lane reads 48 verdicts. Docs: in_place.rs and in_place_check.rs module docs, FAST-PATHS row 41, API.md (placement answers, the shadow reasons), HOWTO's padding-unobserved paragraph, the runtime README, BufferDescriptor::padding_unobserved, TexturePlacement's NotHostPages and Pending (a pooled texture made before its verdicts stays a shadow). Verified: cargo fmt only; builds and the device runs follow. (cherry picked from commit ae31d0fd3841b136c692897cbdf425633e9344c3) |
||
|
|
b136c2531a |
Buffers: a declaration that the bytes between a texture's rows are unobserved
A consumer's cache buffer of the runtime's own memory (the 780M guest's 3662x2038 desktop
surface, more guest-page pieces than udmabuf takes) holds textures whose rows lie 14848 bytes
apart, 14648 bytes of texels each. linear_plan::holding shadows every such texture, since an image
at that pitch holds the bytes between rows and Vulkan lets its layout moves and a render pass's
load and store write them; the consumer's download copies each row's texels alone, so it never
reads those bytes, and the shadow's copies cost it about 1 G texels/s in a Finder drag.
BufferDescriptor::padding_unobserved (with_padding_unobserved) is the maker's declaration that
nothing reads the bytes between a texture's rows over the buffer (each row's bytes after its
texels to its pitch, the last row's included) nor between its slices. A runtime extension with
no Metal counterpart, only for the runtime's own memory: refused, Invalid
(PaddingUnobservedNoCopy), with NoCopy contents. The buffer keeps it (Buffer::padding_unobserved).
- The route (texture/route.rs) decides it for a buffer of the device's own memory:
Route::Device { holds } carries linear_plan::holding's answer, which with the declaration
holds rows and slices that lie apart (rows that share bytes stay refused). The making and the
placement query share it: the query answers NotHostPages where an image may hold the texels,
and the new TextureShadowReason::BytesBetweenRows where it may not (it answered NotHostPages
for both before).
- aliases takes the declaration: the image's subresources may then hold the padding
(linear_plan::within_padding: each subresource ends at its slice's last row's pitch or before,
slices at Metal's stride), never a byte past the last row's pitch, nor memory past the
buffer's. A byte of the image's memory past every subresource is reached by no operation on
it, the reading texels_alone already rests on, so no new check class is needed.
- WorkCounts::unobserved_padding_aliases counts the aliasing images that hold such bytes.
- A buffer the runtime lays in fresh pages (a long one where pointer imports cost submissions
nothing) keeps the in-place check's route: the declaration lets nothing more there (documented).
Docs: the field and builder, NotHostPages and BytesBetweenRows, HOWTO's paragraph on textures
over the runtime's own memory, API.md's shadow reasons and placement answers, the runtime
README; REFUSALS.md and api_signatures.tsv regenerated.
Tests: linear_plan's unit tests of the declared holding and aliasing (padding to the last row's
pitch held, past it or past the buffer refused, slices at Metal's stride alone, shared rows
refused); the route's placement test of both Route::Device answers; a device test
(tests/padding_unobserved.rs): a 101x48 BGRA8Unorm texture at 416, 448 and 512 bytes a row over
an undeclared buffer answers Shadow(BytesBetweenRows) and is a shadow, over a declared one answers
NotHostPages and is an aliasing image wherever the device lays one at the pitch (counted), at
least one pitch aliasing, its texels read back by a blit; and the declaration refused over the
caller's memory. The in-place lane's unobserved_padding_costs times a frame reading the
consumer's surface shape over a declared and an undeclared buffer.
Verified: pending (lavapipe and MoltenVK device tests, the 780M lane run next).
(cherry picked from commit 430523ce0e4dbd8433eb2b514f837d44ce1c5a9a)
|
||
|
|
b4fd8c9210 |
In-place check: import the dma-buf class's pages only as their dma-buf
What: HostMemory::dma_buf_only (crate-internal) has a no-copy import skip the pointer and take the source's dma-bufs (buffer_descriptor.rs's host_window: by_pointer false). The check's dma-buf pages, an allocation of the device's own exported as a dma-buf and mapped, take it. CHECK_VERSION 8, so a record holding the old unchecked dma-buf verdicts is not read. Why: a texture over host pages imported as dma-bufs asks the dma-buf class's verdicts. The check made that class's pages as a no-copy buffer with a source of their dma-buf and kept the class only where the buffer lay over the dma-buf; a no-copy import asks the pointer first, so a driver that takes the pointer of its own mapped allocation (ANV on the Iris Xe) put the buffer over the pointer and left the class unchecked, recorded. The guest's buffers on the Iris are dma-buf class (a guest RAM imports its chunks as dma-bufs first where held pointer imports tax every submission, host_ram.rs), so each of its textures over them asked the unchecked verdict and was a shadow: reims counted 756 and 786 such shadows (host_texture_shadows_unchecked) in a guest session of each mode on the Iris, the second-largest cause there. Test: tests::in_place_check::the_in_place_check_imports_its_dma_buf_pages_as_dma_bufs (Linux device tests): the dma-buf-only import lies over the dma-buf where the pointer-first import of the same kind of pages is printed for contrast; the check's dma-buf reads are never unchecked; a 234x18 BGRA8Unorm texture at 1024-byte rows over such pages (the guest's shape) is in place exactly where the class's reads verdict for its row ends passed. It prints the verdicts. Verified: pending (the Iris run follows). (cherry picked from commit 3709d06189144f0981ed7a93c6fa51332357bfd3) |