Files
metal2vulkan/docs
Anees Iqbal e63ecb9405 RUNTIME 2453: Host pages: a buffer inside a no-copy buffer's own dma-buf import dedicated to nothing is bound in it
What: Device::bind_in_import now binds a no-copy buffer whose pages a live
import of dma-bufs holds all of inside that import, as it does inside an
import of the pointer, where the import is one VkDeviceMemory dedicated to
nothing (a no-copy buffer's own dma-buf of one chunk, a piece of a shared
file's import, a guest RAM chunk's). The new VkBuffer is made for the import's
handle type (VkExternalMemoryBufferCreateInfo DMA_BUF, from bound_memory), its
alignment and memory type checked as before, and the holding import is kept
imported for good (HostImport::pages(ReadApart::Inside), as for a pointer
import). Still refused: an import the driver took only dedicated to its buffer
(DmaBufPages::dedicated_to_buffer, NVIDIA 615's retry) and several chunks bound
to a sparse buffer (no memory); those pages stay a copy, or an import of their
own beside dma-bufs. Before, every dma-buf import but a guest RAM chunk's
refused, so such a buffer was a copy (copied_over_live_imports) whenever it
came with no dma-buf source, or a second import beside it.

The Vulkan rules: VUID-vkBindBufferMemory-memory-02985 (a buffer bound to
imported memory names the import's handle type in
VkExternalMemoryBufferCreateInfo::handleTypes, which host_buffer does from
bound_memory's External(DMA_BUF)); VUID-vkBindBufferMemory-memory-01508 binds
only the dedicated buffer where VkMemoryDedicatedAllocateInfo::buffer was not
VK_NULL_HANDLE, which holds only for the dedicated retry, still refused;
VUID-vkBindBufferMemory-None-10739 (offset a multiple of the alignment) and
-memory-01035 (memory type) as checked before.

Why: on the Iris, with a platform mapping a view of guest pages through one
dma-buf, a guest heap's region takes a 2 MiB no-copy buffer imported through
that dma-buf, and the 256 KiB buffers placed in the heap's pages, handed over by
their pointer alone, became copies of the pages over the live import: 582 copy
ins compared a second, each the copy's whole 64 pages (155 MB/s), 10.7 MB/s
copied in, commit_nanos 43.7 -> 120.5 ms/s. With the views mapped from their
files the same buffers were bound inside the pointer import
(buffers_bound_in_import), with no copy. dma_buf_buffer_imports_dedicated was
0 there: every such import was dedicated to nothing.

Docs: bind_in_import's doc no longer says a buffer's own dma-bufs' memory is
that buffer's alone; dma_buf.rs's module docs, import_from_source's and
chunks_buffer's `sole` contract and DmaBufPages::dedicated_to_buffer say a
buffer over part of the pages binds inside an import dedicated to nothing and
in none dedicated to its buffer; FAST-PATHS's NVIDIA dma-buf gap says the same.

Test: tests/dma_buf_beside.rs's
without_pointer_imports_a_buffer_inside_a_live_dma_buf_import_is_bound_in_it,
on a device made without VK_EXT_external_memory_host: a first no-copy buffer
over 4 pages of a memfd with a dma-buf source, then inside it a second with no
source and a third with one, each bound inside ([0, 0, 0, 0, 1] of copied over
live, beside, inside live, pointer imports, bound inside) where the first's
import is dedicated to nothing (else a copy, and beside or a copy); the GPU
reads the CPU's bytes through each, a CPU write before the commit reaches a
copy through the second, a fill through one and a copy through the other in one
encoder are ordered either way, and after the first's release the second's
fill reaches the file's pages and reads through the third.

Verified: m3-max-36423 at e377c24dce, clippy -D warnings (runtime and translator, all targets and features) 0 and rustdoc -D warnings 0. Lavapipe tests, the negative control, the cfg clippy and PHOENIX run after the merge.
2026-11-16 05:56:00 -08:00
..