Commit Graph
118 Commits
Author SHA1 Message Date
Anees Iqbal 1f7b2a67cf No-copy memory with no dma-buf source is a copy on a device without VK_EXT_external_memory_host
On a device that imports no host pointer but imports dma-bufs (Honeykrisp
on Asahi lists no VK_EXT_external_memory_host), a no-copy buffer or heap
over memory with no source of dma-bufs was refused, naming the extension.
Metal makes such a buffer, and in place is impossible there, so it now
takes the copy a refused pointer with no source takes on RADV
(CopiedFor::DeviceRefused): announced as copied-host-pages, counted in
copied_host_buffers_device_refused, with every copy's coherence.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The remedy, decided from documented queries alone:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Not yet verified; the gem10 checks follow this commit.

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

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

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

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

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

Not yet verified; the gem10 checks follow this commit.

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

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

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

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

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

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

(cherry picked from commit 3dbab04a5849524c694c74aaea52b776cbef6dd2)
2026-11-08 09:36:45 -08:00
Anees Iqbal da896c5a1f Textures over a device-allocated copy: the caller's pages' verdicts, the pooled check only for the pitched image
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)
2026-11-08 08:51:02 -08:00
Anees Iqbal 1cf4730839 Textures over a copied host buffer: an image over the copy where the check passed, not a shadow
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)
2026-11-08 08:51:02 -08:00
Anees Iqbal 384ce01a32 HostRam lists: HOWTO, runtime README and FAST-PATHS with the 780M's numbers
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)
2026-11-08 08:18:42 -08:00
Anees Iqbal bdeed7eaa6 HOWTO, signatures: copies over a chunk not imported, staged gathers and their counts
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)
2026-11-08 07:54:42 -08:00
Anees Iqbal 748465a50e Host RAM copies of runs each at a byte of the buffer: one call for a laid-out surface
BlitCommandEncoder::copy_runs_from_host_ram(ram, runs, destination) and
copy_runs_to_host_ram(source, ram, runs) take (buffer byte, host run)
pairs, so a device cache that keeps a surface's layout (row r at
base + r * pitch, the padding between rows the guest's and untouched)
copies every row in one call instead of a call a row (the Iris measured
2054 calls at 3.9 ms GPU and 8.1 ms CPU against 0.83 ms and 1.5 ms for one
call of the same runs, m3-max-8523).

The call now holds runs at their buffer bytes (Run); copy_from_host_ram
and copy_to_host_ram lay theirs one after another from their offset
(one_after_another), so their behaviour and refusals are as before. Runs
join where they touch in the RAM and in the buffer (merged). pieces()
places each piece at its buffer byte; the record path takes the span
from the lowest run's first byte to the highest's last for the bindings,
windows and hazard tracking, and the kernel's entries already carry their
buffer word, so only the table's filling changes. Runs that all end on a
word and lie at words of the buffer's memory take the dispatches; others,
and copies that write a destination byte twice (a scatter's host bytes, a
gather's buffer bytes), take regions, in rounds where a byte is named
twice so the later run's bytes stay. For the runs calls, a run past the
buffer is RangeOutOfBounds (the first such run's), and a run at a buffer
byte off a word takes regions instead of being refused.

Tests: a laid-out surface (rows at a pitch over scattered pages, two side
by side, one in each chunk) both ways in one call with sentinels in the
buffer's padding and the whole RAM compared, 4-byte rows by a dispatch per
chunk, 2-byte rows and rows at a buffer byte off a word by regions; a
gather naming one buffer byte twice keeps the later run's bytes; the
runs calls' refusals; unit tests for merging pairs, in_words off a buffer
word and pieces at their buffer bytes. The bench's laid-out one-call form
now uses copy_runs_to_host_ram from the laid-out cache.

Docs: both calls' API docs, the module docs, Problem::HostRam, HOWTO
section 6 and the runtime README; signatures re-blessed (REFUSALS.md
regenerated, unchanged).

(cherry picked from commit 8292ae5075d07cbcd6eada94cf8dc99060792722)
2026-11-08 07:12:13 -08:00
Anees Iqbal 1c33448daa dma-buf lane: a view of single pages takes the route its device answers; ANV's dma-buf limits documented
What: the reversed-view test now asserts each measured driver's route for a no-copy Shared
buffer over 64 and list_limit + 1 single pages of a memfd in reverse, mapped from the file and
through udmabufs (VM_PFNMAP), placed outside the guest's range, with a dma-buf source:
- RADV: through dma-bufs, one chunk, or two in a sparse buffer;
- ANV: by pointer from the file; through udmabufs, one dma-buf where one udmabuf holds the view,
  else refused (Unsupported, HostMemory) after one request for a single dma-buf of the whole
  view;
- lavapipe: by pointer.
No route is a copy. It prints the mappings the view and the import took.

with_dma_buf's docs and HOWTO now say what ANV does. It imports a dma-buf for a plain buffer but
reports none for a sparse one, so its source is asked for one chunk of the whole length, which one
udmabuf must hold. It refuses the pointer of a mapping of dma-bufs.

Why: a consumer's probe found ANV refusing a view of list_limit + 1 pages mapped through
udmabufs. The runtime's route there was not a copy, nor a skipped source:
- the pointer import of the udmabuf mapping was refused: vkGetMemoryHostPointerPropertiesEXT
  answered memoryTypeBits 0x7f, then vkAllocateMemory with VkImportMemoryHostPointerInfoEXT
  returned VK_ERROR_INVALID_EXTERNAL_HANDLE on memory types 2 and 1;
- the source was then asked;
- vkGetPhysicalDeviceExternalBufferProperties for DMA_BUF reports import for flags 0 but not for
  SPARSE_BINDING, so the request's granule was the whole 4,198,400 bytes, and one udmabuf of 1,025
  items is past list_limit 1024.
No buffer of Vulkan binds more than one imported memory without sparse binding, so the runtime has
no documented path for such a view on ANV.

Verified: diagnostics on a scratch branch (never merged), on the Iris Xe (ms01, job m3-max-8433,
Linux 7.3.1, i915), the 780M (job m3-max-8454) and lavapipe (gem10, job m3-max-8477). The runs of
this test follow.

(cherry picked from commit 32ba8392a0aa8d16b4fceb9b6ed052e5d618b1a0)
2026-11-08 06:36:45 -08:00
Anees Iqbal b30da69b50 Host RAM copies of runs of words take the pages copy's dispatches, not regions
The pages copy's table entries become three words: the run's first word in
the scattered binding, its first word in the consecutive one (from the
shape's first_word) and its words, at most a page's 1024. Each invocation
copies its strided words below the run's count. Whole pages are entries of
1024 words, one a page as before, so their tables' entries, dispatches and
windows are unchanged.

In the runtime, a copy whose runs all end on a word (they already start on
one, and the buffer's bytes too) takes the dispatches: plan() cuts each
piece into runs of at most a page from its start and where a window of the
buffer ends. Only runs that end off a word (rows of 1- or 2-byte texels),
or a scatter whose runs write a byte twice (share_a_byte, so the later
run's bytes stay as with regions), keep vkCmdCopyBuffer regions.

The Iris measured regions at about 1.6 us of GPU and 1 us of CPU each
(m3-max-8389: 8853 regions of a 31.5 MB surface, 14.0 ms GPU, against 0.99
ms for the page kernel over the same pages).

Tests: the kernel's interpreter test of word runs (a word, 128, 129, a run
across a page, a page less a word) with no word around them changed; the
plan's cuts at a page and at a window's end; a device test of rows of 2044
bytes at a 2048 pitch from 16 bytes into a page, a run ending a word before
a page's end, three pages and more from inside a page, one across the
chunks' end and a word, with sentinels over every touched page, a dispatch
per chunk and no region both ways, and a twice-named scatter of word runs
by regions, the later run kept. The regions refusal case now ends off a
word. The bench measures rows of 4-byte texels (dispatches), of 2-byte
texels (regions) and 2046 bytes at a 2048 pitch.

Docs: the kernel's module and entry docs, the copy module, both calls' API
docs, HOWTO and the runtime README; signatures re-blessed (entry() takes
the run's words and returns 12 bytes; ENTRY_WORDS).

(cherry picked from commit 562fc5fc526cce2b31db280c4bbffb29314f8ac4)
2026-11-08 06:20:15 -08:00
Anees Iqbal 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)
2026-11-08 06:06:13 -08:00
Anees Iqbal fe5f08a4b1 Host RAM copies take runs at word starts and any end, copied by regions
reims's laid-out device cache downloads hand copy_to_host_ram each texel
row's bytes (encode_out): runs that start on the device's linear texture
alignment, always a 4-byte word, and end at any byte, short of the row's
padding, which the guest's CPU owns. merged() refused every such run
(Problem::HostRam) and the consumer fell back to a view of the surface's
pages: on ANV one mapping per 4 KiB page, 278 of 294 device caches in
boot 8267.

Now a run starts on a 4-byte word and ends at any byte past it. Copies
whose runs are all whole 4 KiB pages keep the pages copy's one dispatch
per chunk, unchanged. Any other copy records each run's bytes in a chunk
as a region of vkCmdCopyBuffer between the import that holds them (whole
pages, imported as before) and the buffer: byte offsets and sizes, so no
other byte of the runs' pages is read or written. The regions of one
import are one command, at most 1024 each (MOST_REGIONS). A scatter whose
runs name a byte twice takes a round of commands per overlap, so no byte
is written by two regions of one command (VUID-vkCmdCopyBuffer-pRegions-12482),
the later run's bytes left; a buffer over host pages the runs overlap is
refused (VUID-vkCmdCopyBuffer-pRegions-00117). Counted in the new
WorkCounts::host_ram_copy_regions.

Tests: copy.rs's unit tests (word starts, any ends, rows that touch merge,
whole_pages, rounds); host_ram_copy_device's
runs_inside_pages_move_their_bytes_alone_and_leave_the_rest_of_their_pages
(2046-byte rows at a 2048 pitch from 16 bytes into a page, a run ending 2
bytes before a page's end, one across the first chunk's end, one of 3
bytes; pattern sentinels around them; gather into Shared and Private,
scatter back; 10 regions, no dispatch; twice-named bytes; the overlapping
buffer refused); the whole-page test now also asserts no regions; the
refusal test's cases off a word. host_ram_copy_bench gains the laid-out
download: a call a row, one call, and the view with a blit a row.

Docs: copy.rs module and both calls' API docs, Problem::HostRam,
docs/HOWTO.md, the runtime README; docs/REFUSALS.md regenerated and the
API signatures re-blessed (the new WorkCounts field).

(cherry picked from commit 1ba8aba84076208a1eccaf65dd4993058ed53431)
2026-11-08 05:44:56 -08:00
Anees Iqbal 016c09572a Pooled moves: docs and API signatures
TexturePlacement::Pending: over the device's own memory, a texture made while the pooled check
is pending now moves to its image at Metal's pitch the same way (it no longer stays a shadow for
good). Texture::vk_image, docs/FAST-PATHS.md (row 41), docs/API.md (the shadow reasons over the
device's own memory) and docs/HOWTO.md (the padding-unobserved paragraph) say so, naming
WorkCounts::pooled_textures_moved_in_place and pooled_texture_shadows_freed_after_move.

API signatures: the two new WorkCounts fields (scripts/api-signatures/signatures.py --bless, two
lines added).

(cherry picked from commit 4c1beda492dcc4af16923df09724b7fbf0e7387a)
2026-11-08 05:22:32 -08:00
Anees Iqbal 535f50063f Pooled bound over tracked Private buffers alone: CPU-visible caches lie in place at any size
The owner's 2026-11-07 ruling: over CPU-visible memory the GPU works in
place wherever the device's check passed, however much slower; a shadow
there is a correctness fallback, never a speed choice. The 48 KiB pooled
bound (LinearCost) chooses between two speeds where both forms give the
same answer, which holds only over bytes only the runtime's commands
write. So it now applies to tracked textures over Private buffers alone
(Texels::only_commands_write), for every access; over a Shared or Managed
buffer, and for an untracked texture, a texture that samples, renders or
is written takes the DRM_FORMAT_MOD_LINEAR image at its pitch at any size
wherever its check passed. This widens the previous commit's sample-only
exception. reims's histogram (boot 8203) shows no rendered cache past
48 KiB, so the render and write side changes nothing measured today.

The bound's doc comment, LinearCost's (internal and public) and
docs/API.md and docs/HOWTO.md now say so.

Test: a_texture_past_the_pooled_bound_is_a_shadow_of_its_linear_cost_over_private_memory_alone
replaces the rendered bound test and the previous commit's sampled one:
164x82 at 704-byte rows, past the bound, rendering and sample-only, over a
tracked Private buffer Shadow(LinearCost) and no pitched image where the
device makes such images, over a Shared buffer never LinearCost and the
pitched image where the pooled check of its access passed.

(cherry picked from commit cd89debcd731885e8045dc998252a08edc3dc60f)
2026-11-08 05:20:54 -08:00
Anees Iqbal f8caa83975 Pooled bound: a texture that only samples bytes the CPU writes lies in place at any size
The 48 KiB bound weighs a DRM_FORMAT_MOD_LINEAR image at Metal's pitch
against a shadow that renders into its own optimal image, or samples it
copied in once. A texture that only samples a Shared or Managed buffer's
bytes (or an untracked texture that only samples) has no such shadow: its
shadow is copied in whole at every command buffer that samples it, as the
CPU may have written the bytes. The guest's large device caches are
WebKit's tiles, about 5 MiB each, CPU-painted and only sampled; past the
bound each was a shadow re-copied in every command buffer.

Measured on the Iris Xe (ANV, Mesa 26.2.6; job m3-max-8243,
runtime_lane::pooled_draw_costs::pooled_sample_costs), a frame that
samples four such textures whole after the CPU wrote a texel of each,
GPU microseconds as shadows at the padded pitch against linear images at
the tight one: over Shared buffers 1308x512 (2.7 MB) 327.8/215.9,
1324x940 (5.0 MB) 802.2/380.1, 3648x2038 (30 MB) 5789.3/2601.6; over
Private buffers, whose shadows stand copied in once, 237.7/216.2,
404.4/409.4, 2028.1/2433.2. So the bound keeps covering textures that
render or are written, and those that only sample bytes only the
runtime's commands write (Texels::only_commands_write, the predicate a
shadow's standing uses).

Test: a_sampled_texture_past_the_pooled_bound_lies_in_place_over_bytes_the_cpu_writes
(164x82 at 704-byte rows, past the bound, sampled: over a Shared buffer a
pitched image where the pooled reads check passed and never
Shadow(LinearCost); over a Private buffer Shadow(LinearCost) where the
device makes such images).

(cherry picked from commit d99c9c507b00e7b1537257a7a2fddd18d9563e2f)
2026-11-08 05:20:54 -08:00
Anees Iqbal 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)
2026-11-08 03:29:51 -08:00
Anees Iqbal 6717cac4ea Pooled class: a bound in bytes past which a texture over pooled memory stays a shadow (TextureShadowReason::LinearCost)
Measured on the Iris Xe (probe 7933): a small cache's shadow costs a fixed 3.5-4.3 us a
command buffer that writes it, which a linear image at Metal's pitch saves, while caches of
1.4 MB and more render and sample 8-18% slower as linear images than as shadows with their
copies. Over Private memory both forms give the same answer (no CPU reads the bytes, the check
judges the first move), so this chooses between two speeds and takes no FAST-PATHS row or
switch. in_place::POOLED_PITCHED_BYTES bounds a texture's rows to their pitch, the same on every
device; past it the cause is ShadowCause::LinearCost, which the placement query answers as the
new public TextureShadowReason::LinearCost { bytes } through the shared route. docs/API.md (the
padding-unobserved reason) and HOWTO say why.

The bound's value here (256 KiB) is provisional: the size sweep on the Iris and the 780M places
it at the measured crossover in a following commit.

Verified: cargo fmt; api signatures re-blessed (one variant added); REFUSALS.md regenerates
unchanged; builds follow.

(cherry picked from commit 366e098c15c7227006ba7633ecda574da224690e)
2026-11-08 03:29:51 -08:00
Anees Iqbal 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)
2026-11-08 03:29:51 -08:00
Anees Iqbal 6575c031f5 In place: 1- and 2-byte texels a shader writes, checked apart by the device's check
In every guest session reims measured (Iris Xe and Radeon 780M, macOS 26.7.2 guests),
host_texture_shadows_store_width was 114, from 23 distinct R8Unorm, A8Unorm and R16 textures a
shader writes (32x32 at 256-byte rows among them). They were shadows because the in-place
check's write kernel stored only 4-, 8- and 16-byte texels (STORED_TEXEL_BYTES,
ShadowCause::StoreWidth), so no check covered a driver's writes of narrower ones.

What changes:
- in_place.rs (from selfread's parked 0c587bcad5): Access gains NarrowWrites and
  NarrowBufferWrites, with 36 verdicts instead of 24. Access::written picks the writes check of
  a texel width and padding. STORED_TEXEL_BYTES holds 1, 2, 4, 8 and 16; NARROW_TEXEL_BYTES
  holds 1 and 2. in_place asks the written check in place of Writes. The report names
  "narrow writes" and "narrow buffer writes". CHECK_VERSION goes to 9 (development's dma-buf
  import fix took 8).
- in_place_check.rs: NARROW_STORE_SHAPES, rounds of their own for the narrow accesses, through
  the copy-in kernel's R8_UINT and R16_UINT views (a801dac7d7). The shapes are packed R8 256x16
  and R16 128x16 at 256; R8 61x37 and R16 45x29 at 256, whose rows end inside a word and whose
  heights are odd; the 16- and 64-byte tight pitches; and an R8 1024x1024. The source buffer
  holds a word per texel, the texel's bytes low and zeros above, since CopyIn takes 4*words()
  bytes a texel. A narrow round's change fails only the narrow verdicts, never a 4/8/16-byte
  texture's. A device whose kernel or image is not made (no shaderStorageImageExtendedFormats)
  leaves them unchecked.
- in_place::storable: one helper for a render target's storage usage, used by route.rs and
  storage_form.rs. It asks Access::written(texel, Padding::Kept) instead of Writes, so a narrow
  render target never takes the 4-byte verdict. writes_reach (the storage usage an image that
  does not render takes beyond its usage) and fresh_pages_take ask the written check of the
  texels' width; InPlaceWatch carries the width.
- InPlaceAccess::Writes covers the narrow accesses. Docs (in_place, the check, API.md, HOWTO,
  FAST-PATHS row, runtime README, WorkCounts, HostPageTexturePolicy, TextureShadowReason) say
  1, 2, 4, 8 and 16 bytes, with narrow writes checked apart. The lane's VERDICTS goes to 36.

Tests:
- The decision test runs every width, 3 bytes for StoreWidth among them, against narrow answers
  that differ from their wide twins'. It also checks storable.
- Shape tests cover the narrow set: tight pitches, row ends at 16/64/128/256, free padding.
- New: each_check_of_storage_writes_stores_its_texels_width. A narrow tally case.
- New device test narrow_writes_device: the guest's 32x32 R8Unorm and A8Unorm (and RG8Unorm and
  R16Unorm) at 256-byte rows over a no-copy buffer. Each takes its narrow verdict's path, its
  placement query agrees, a kernel's writes reach the bytes, and the padding and the bytes past
  the last row are kept.
- in_place_storage adds an R8Unorm render target.

Verified: not yet built; the build, clippy, unit and device runs follow as jobs.
(cherry picked from commit dbb985df199b1c46bb783aafbd50efd40bcab187)
2026-11-08 01:47:31 -08:00
Anees Iqbal 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)
2026-11-08 01:11:45 -08:00
Anees Iqbal 95a5f1ad37 Point HOWTO's integrators at the texture placement query
docs/HOWTO.md's passage on textures over host pages told a program to start
the in-place check early with Device::settle_in_place_checks; it now also says
that a zero timeout later answers whether the verdicts are known, and that a
program routing each surface to its pages or to a copy of its own asks
Buffer::texture_placement (or texture_placement_with_iosurface_plane), whose
answer is the making's own decision. Docs only.

(cherry picked from commit 17bbae52a0330a75a5d1cd522407f2888dc7bcff)
2026-11-07 23:40:30 -08:00
Anees Iqbal b6c025c12b Free a moved shadow's image once the command buffer that took the move completed
A texture over host pages made before its in-place verdict is a shadow, and moves in place at a
commit once its class's verdicts pass (`texture/storage_form.rs`). The shadow's image then stayed
with the texture until it went, so a long-lived surface kept an unused texel-sized image and its
merges' scratch buffers for the session.

The switch's last part now writes the shadow's image (a tracked transfer write of every level and
layer), so hazard tracking orders the committing command buffer after every use of the shadow
committed before it, on any queue, and that command buffer holds a ShadowAfterMove. Once it
completed, where the texture moved in and only the texture's storage and this hold the shadow's
image, the image's VkImage, views and memory go (`Image::let_go_unused`, the release a drop runs,
at most once), and its merges' kept scratch buffers. Nothing names the shadow by then: every later
command presents the image in place. A view of the texture made before the move, a shadow made
over the shadow's image (which holds it as its truth, `shadow::ImageTruth`), and an untracked
texture keep it until those and the texture go. The in-place counts are unchanged.

New WorkCounts field: host_texture_shadows_freed_after_move. FAST-PATHS (the in-place row) and
HOWTO say when the shadow goes.

Verified:
- runtime_lane::in_place_textures::a_texture_made_before_its_verdict_moves_in_place_once_it_passes
  now requires as many shadows freed as moved (polled up to its wait): "moved 1, in place 1,
  shadows freed 1" on lavapipe (gem10 m3-max-7070, at this base; msi m3-max-7019 at fa17b6ada4)
  and on the M3 Max (m3-max-7027 at fa17b6ada4; the patch is the same at this base).
- Touched runtime tests (in_place, storage_form, shadow, fetch, self_read, usage and view
  shadows, heap_set_copies): 73/73 on lavapipe (m3-max-7070); 71/71 on the M3 (m3-max-7027);
  the in-place lane 7/7 on both.
- Negative control a68e9f2e91 (ShadowAfterMove does nothing) on lavapipe (m3-max-6973): the lane
  test fails, "after the move: 0 shadow images freed, where 1 moved".
- clippy -D warnings for the runtime and validation crates, plain, --cfg m2v_cpu_icd and
  --cfg m2v_gpu (msi m3-max-7019); signatures blessed; refusal surface unchanged.

(cherry picked from commit ea33a4ce5c909723a5c425a7e1dd8ce0fc4a8d5f)
2026-11-07 21:41:11 -08:00
Anees Iqbal 2b7ebd8c38 ANV: blits through two imports of the same host pages are unordered by a barrier in one command buffer
On ms01's Iris Xe (Raptor Lake-P, Mesa 26.2.6) two host_ram_device tests failed (5425): a write
through a buffer bound in a run's import and a read through one bound in the chunk's import of
the same pages, in one blit encoder. A probe of each way (5482, scratch branch
steelbrain/amdperf-iris-probe, two runs) showed the shape MoltenVK's AliasedImportBlitsUnordered
names: in one command buffer, in one encoder or two, a fill through one import, a global memory
barrier and a copy through the other read none of the fill (0 of 4096 bytes) in either
direction, where two command buffers of one queue, a wait first, and two queues each read all of
it, and every way through one import read all of it. Vulkan counts imports of the same pages as
aliases of one memory, which a global barrier orders, so this is the driver's.

ANV now has the defect in the Affected table, so an object over a chunk not yet imported binds in
the chunk's import (waiting for it), never in an import of its own run, as on MoltenVK. The table
test lists it for ANV; host_ram.rs, the host_ram_device tests' docs and HOWTO name ANV beside
MoltenVK.

Verified: cargo fmt only here; the Iris rerun of the 42 tests is a potluck job.
(cherry picked from commit 589815be2cd36191673b6aae36e2f50a2afcd1cd)
2026-11-07 16:59:34 -08:00
Anees Iqbal 78e58c370f Guest RAM: listed chunks stop at 512 MiB, not 256
On a device whose held imports add to the cost of every submission (RADV), a guest RAM's chunks
now run up to 512 MiB. reims's 16 GiB guest on the Radeon 780M (their job 5584, two boots of each
setting) had less of QEMU's RAM resident with 512 MiB chunks than with 256 MiB ones: 0.45 GiB more
than without the source at its desktop against 0.94 GiB, and 0.15 against 0.25 GiB at the end of
its run, with at most 11 to 12 chunks live against 15 to 18. The probe's per-submission cost falls
too: an 8 GiB RAM's submission median was 32 to 33 us in 32 chunks of 256 MiB and 24 us in 16 of
512 MiB (job 5411).

LONGEST_LISTED_CHUNK, the module and use_host_ram docs, HOWTO, the FAST-PATHS row and the
chunk-length probe (now up to 512 MiB) say 512 MiB.

(cherry picked from commit 003382bdc921fa8e7901fa00c7896f29439d7907)
2026-11-07 16:40:58 -08:00
Anees Iqbal f9bc470d7c Move a shadow made before its pages' in-place verdict in place once it passes
A texture over host pages made before its class's in-place verdicts were
known is a shadow (CheckPending): an unknown, not a lack. Under the owner's
11-07 ruling a shadow is only for accesses that cannot be done in place, so
such a shadow must not stay one for life because it was made early.

Each such shadow now waits for its class's verdicts (StorageForms::moves).
The check's thread, at each verdict, decides from facts stored with the
wait (class, usage, texel bytes) and takes no handle of a program's
texture. Where the verdicts take an image in place, the texture waits for
the storage-form switch. At the commit of the device's only uncommitted
command buffer, the switch makes the image in place exactly as the
texture's making makes it: the declared plan, with feedback loop and
storage usage where the device makes them so, and noted for a rebind and
its first move. Where every encoder ran, the texture presents it from then
on (TextureShared::moved; every storage read goes through
Texture::storage). It is counted in host_textures_in_place and in the new
WorkCounts::host_textures_moved_in_place, and its slots are written again.

No texel is copied: between encoders the shadow holds nothing the buffer
lacks, and the image in place is the buffer's bytes, whose uses hazard
tracking orders after earlier copies back and merges. A view made before
the move keeps the shadow. A shadow with a usage or render shadow, over
detached or copied bytes, or whose image the device refuses stays a
shadow. The shadow's image is kept with the texture until it goes.

Test: runtime_lane::in_place_textures::a_texture_made_before_its_verdict_moves_in_place_once_it_passes
(under the validation layer). Docs: storage_form.rs and in_place.rs module
docs, FAST-PATHS in-place row, HOWTO, API.md.

(cherry picked from commit 605d0444de1ad1a9b93e02649db7e1b2fda18e93)
2026-11-07 15:14:38 -08:00
Anees Iqbal 6aff9aaa3c Stop a listed guest RAM's chunks at 256 MiB: a chunk's import pins every page of it
Where each listed import costs every submission (RADV with a source of dma-bufs), a guest RAM
was imported in chunks as long as the source's dma-bufs and the device's limits took: about
2.5 GiB on a consumer's 16 GiB guest on the Radeon 780M. A chunk's import pins every page of the
chunk, and udmabuf allocates the pages of the memfd the guest never touched, which stay
allocated once the chunk is freed. So each chunk an object lies in made all its bytes resident:
the consumer measured QEMU's Pss_Shmem at 7.86 GiB without the source and 12.31 GiB with it.

listed_chunk_bytes now stops at LONGEST_LISTED_CHUNK, 256 MiB, on every device and kernel. It
is a structural bound, not tied to udmabuf's size_limit_mb, which stays an upper bound through
HostRam::with_largest_dma_buf. The trade is speed against memory, with no accuracy change and
so no switch. Each live chunk costs every submission about half a microsecond (an 8 GiB RAM on
the 780M: 128 chunks of 64 MiB took a submission's median from 14 us to 60-88 us; 3 chunks of
2730 MiB, to 16 us). At 256 MiB, a 16 GiB RAM lists at most 64 chunks.

The kept-chunk rule (releases_idle_chunks) is unchanged, so the first-gather win of kept chunks
stays. The docs (the host_ram module, Device::use_host_ram, HOWTO section 6, and the FAST-PATHS
"Idle dma-buf imports are released" entry, edited in place) say where the chunks stop and why.
The lane probe submit_per_ram_chunk_length now measures only the lengths the plan can make (64,
128 and 256 MiB). Its run before the cap measured 64 MiB to 1 GiB.

Verified: the unit test listed_chunks_are_as_long_as_every_limit_takes_in_whole_64_mib fails
without the cap (a 2.5 GiB source gave 2560 MiB chunks) and passes with it (job ids in the tip).

(cherry picked from commit 9a158941e94173b4e0dc53b89f3b15c9b59f60c2)
2026-11-07 15:03:11 -08:00