Commit Graph
822 Commits
Author SHA1 Message Date
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 098eec639b API.md: when a texture over exported memory is a shadow
The shadowed-texture list in section 10 gains the exported-memory causes the handle-type fix introduced: the check of that exported memory not passed (pending ones move in place), the image format query refusing the handle type but in a dedicated allocation, and a buffer's dedicated allocation.

(cherry picked from commit cd993135eca08d877b7b55a3c0570df86df7510f)
2026-11-08 17:00:48 -08:00
Anees Iqbal 99453e91d8 Images bound over exported memory name its handle type; a check class per export handle
A texture over an exportable buffer (exported_memory.rs) was a PREINITIALIZED linear
image, or a DRM_FORMAT_MOD_LINEAR one, with no VkExternalMemoryImageCreateInfo, bound in
memory allocated with VkExportMemoryAllocateInfo: VUID-vkBindImageMemory-memory-02728
("it must include at least one of the handles set in
VkExternalMemoryImageCreateInfo::handleTypes"). RADV and NVIDIA tolerate it; the layer
does not.

What changed:
- memory.rs: Memory::bound_memory reads a placement's own record (the block's export,
  import, own pages or read-only view, a guest RAM chunk's handle, a dma-buf import) and
  answers the handle type an image bound there names: none for memory of no export, the
  export's handle for a shared exported block, HOST_ALLOCATION or DMA_BUF for imports, and
  no image for a buffer's dedicated allocation (VUID-vkBindImageMemory-memory-10926) or the
  caller's memory. Buffer::bound_memory answers it for a buffer (a heap buffer's, its heap's).
- texture.rs alias_unbound decides the image from that record, not the route: over exported
  memory the device's linear image made for the handle type (external_linear_image, the
  former host_linear_image generalized), else the DRM_FORMAT_MOD_LINEAR one made for it
  (ModifierMemory::Exported). Either is made UNDEFINED (VUID-VkImageCreateInfo-pNext-01443),
  so its first move may discard the bytes, which only the device's check may vouch for.
- in_place.rs: two check classes, PagesClass::ExportedFd and ExportedDmaBuf. Their buffer
  is an exportable Shared buffer of that handle type in a shared block; their textures take
  the product's image. A texture over exported memory takes its image where the policy and
  those verdicts pass for its accesses; before them it is a CheckPending shadow that moves
  in place at the next quiet commit, as over the pooled memory (storage_form.rs now moves
  any class over the runtime's own memory). No LinearCost bound there: another API writes
  those bytes.
- The image format query (VkPhysicalDeviceExternalImageFormatInfo) must answer the handle
  type exportable (importable for imports) without DEDICATED_ONLY, for the linear and the
  DRM_FORMAT_MOD_LINEAR image alike; else the texture is a shadow, its notice naming the
  query's refusal. A dedicated allocation keeps the shadow, its notice naming 10926.
- ycbcr_planes.rs: the two-plane image is PREINITIALIZED with no handle type, so it takes
  only memory whose record says no export or import (KeptTexels::Memory elsewhere).
- in_place::CHECK_VERSION 12 -> 13: the record holds two more classes, so every driver's
  check runs once more.

Checked and unchanged: heap.rs's images (heaps are never exported; over host pages they are
HOST_ALLOCATION images, over a copy in device memory a shadow or an Own linear image), the
in-place images over host pages and copies (HOST_ALLOCATION over imports, Own over device
copies), and the runtime's own images in Holds::Images/Buffers blocks.

The placement rule (in_place.rs, "The runtime's exported memory"): per texture (per plane),
the texels' offset in the memory (the buffer's first byte, or its aligned_byte, at a
multiple of 256 there, plus the texture's offset) must be a multiple of
VkMemoryRequirements::alignment from vkGetImageMemoryRequirements for the image made for the
handle type of the texture's format, extent and usage; vkGetImageSubresourceLayout of its
first subresource must answer offset 0 and Metal's rowPitch; its size must stay inside the
buffer. The linear image first, then the DRM_FORMAT_MOD_LINEAR one with its own alignment.

Test: tests/exported_textures.rs, an NV12 picture's R8 3840x2160 and RG8 1920x1080 planes at
32 and 8294432 of an exportable buffer laid with aligned_byte(32), opaque fd and dma-buf,
Private and Shared, under the validation layer: a shadow first, both moved in place after
settle_in_place_checks, readback equal, in place at once after, no layer message.
dma_buf_export settles the checks before its plane textures. Not yet run: this commit is
for the build and the device runs.

(cherry picked from commit 40872fbb4748cbd228c06c27dc0cd63ca2d0a5ec)
2026-11-08 17:00:47 -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 ee3f269fa3 Heap depth textures: the copy in clamps a 32-bit float depth into [0, 1] where the device takes no other
A heap's 32-bit float depth texture whose shadow copies the heap's bytes
into its image went through vkCmdCopyBufferToImage with whatever float the
bytes held. On a device without VK_EXT_depth_range_unrestricted that is
invalid usage for a value outside [0, 1]
(VUID-vkCmdCopyBufferToImage-pRegions-07931); ANV stored it clamped, and
the runtime only announced it (restricted-depth-upload).

The tiled texel kernel (metal2vulkan::bind) now clamps a level's elements
on the way into the tight buffer where the level says so:
- TiledLevelMove::clamps_depth, set with TiledLevelMove::clamping_depth;
- the shape's level record grows to 14 words;
- the clamp compares the word's bits, so no denormal is flushed: a
  negative value becomes 0.0, one above 1.0 (and +inf) becomes 1.0, a NaN
  of either sign becomes 1.0 (as nan_clear.rs clears a NaN depth), and
  -0.0 and every value inside [0, 1] keep their bits;
- the move back is unchanged.
HeapTiledCopies::new takes the image's format and marks the 4-byte depth
planes' levels of a D32_SFLOAT or D32_SFLOAT_S8_UINT image where
ImageFacts::depth_clamps holds: exactly where restricted-depth-upload is
announced. MoltenVK, whose driver is measured to keep such values
(DriverFact::DepthImageKeepsValuesOutsideUnitRange), keeps its copies as
they were. The clamp is the device's own answer, so the notice stays and
its text now says the copy in clamps.

Tests:
- bind::tiled_texels::tests::clamped_depths_move_into_the_image_inside_0_1,
  run through the CPU interpreter;
- lane heap_textures::a_heap_depth_texture_s_copy_in_takes_no_depth_outside_0_1,
  which turns on the layer's GPU-assisted buffer-copy check
  (gpuav_buffer_copies), asserts no VUID-07931 message, and checks a blit
  reads the clamped values where the device clamps, else the bytes as
  they are.

Docs:
- the restricted-depth-upload declaration, docs/API.md's catalogue and its
  docs/FAST-PATHS.md device-gap row say the copy in clamps;
- docs/FAST-PATHS.md's known gaps gain one entry: a heap texture Metal
  keeps uncompressed lies in its driver's layout where its image fits
  Metal's answer (heap-texture-untiled-layout);
- api_signatures.tsv is blessed for the two new public items.

Verification in the tip report.

(cherry picked from commit de683c02ce08d337e8281dd752c2519f863bbe39)
2026-11-08 15:41:19 -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 8b664a27a2 Shadow log names every shadow a texture makes; never-stood copies in split by what kept the end from standing
The walk's unskipped copies in are all of a 3648x2038 surface that never
stood, and the shadow log, which named only a texture over a buffer's bytes,
never named it. Two instruments to find out which shadow it is and why no
command buffer's end leaves it standing:

- METAL2VULKAN_LOG_SHADOWS now names each shadow a device makes of a
  texture: a usage shadow (a binding beyond its usage, an attached read, a
  YCbCr texture's writes), with what the texture's own image is (an aliasing
  image over the bytes with or without the feedback loop usage, a shadow, or
  an image of its own); a rotated texture's image of its stored frame and its
  twin; a two-plane extended-range texture's image; a depth or stencil
  texture's tiled twin over a surface plane; and a YCbCr texture's converted
  image and render shadow. A line's truth is the buffer's bytes or the
  texture's own image.
- WorkCounts::shadow_texels_never_stood_{unmet, not_current, dropped,
  partial, end} split shadow_texels_unskipped_never_stood by what last kept a
  command buffer's end from leaving the image standing
  (shadow_standing::Missed): no end met it, an encoder ended with its image
  not holding the truth, what the command buffer carried let it go, the end
  held it in part or stale, or the end records no standing. Each shadow that
  may stand keeps the last one; off the counts it changes nothing.

Verified: cargo fmt only so far; the checks run as a potluck job.
shadow_standing_device now asserts the five sum to never_stood and that a
first read's never-stood texels are all unmet.

(cherry picked from commit 1dd2a2ee2b9c39a2ba7aaeea3e3ad7906fd035f9)
2026-11-08 13:46:25 -08:00
Anees Iqbal dae9923446 Heap refit docs: which textures an image in place serves, and what the shadows of Metal's tiles cost
HeapTextureHostTransfer and HeapTextureLinear (and docs/API.md's catalogue)
say the refit takes an image of host-transfer usage only for a texture Metal
compresses or whose layout is not modelled, and of one Metal keeps
uncompressed only a linear image whose every element lies where Metal's tiles
place it. docs/FAST-PATHS.md's costs record the shadow of Metal's tiles kept
for every other such texture, with the 1x1 shadow's GPU time measured on the
Iris Xe at RUNTIME_VERSION 1909 (35.9 us against 8.1 us a frame); the
compositor's 3x3 to 10x10 shapes are not measured apart.

(cherry picked from commit dc30f3c6c8768ab3780bad861bba9db1ad9f4b84)
2026-11-08 13:32:36 -08:00
Anees Iqbal ec94c62dce heap depth textures: a merge's keep holds the heap's bytes, not the image's
A 2-slice Depth32Float 64x64 x2 multisample texture in a Shared placement heap
on ANV (Iris Xe, RPL-P, Mesa 26.2.6) lost the samples a blit wrote into one
slice: 16384 of 16384 were off Metal's tiles after the merge back, while a
read straight from the image matched. The heap's bytes held 0xee before the
blit. The copy in hands the image 0xeeeeeeee, a float outside [0, 1], which
Vulkan leaves undefined in a depth image without
VK_EXT_depth_range_unrestricted, and ANV stores 0.0. The merge's keep was
moved out of the image (only drivers announced drawn-depth-copy kept the
heap's bytes), so it held 0.0, and the merge kept the heap's 0xee in every
byte of a written sample that equals 0.0's: a probe found 9155 0xee bytes
left in the slice, the 9134 zero bytes of the samples plus 21 sample bytes
that are 0xee, and no sample whole.

Now a heap's tiled texture with a depth aspect, of any sample count, keeps
the heap's bytes: the staging buffer its copy in filled where the keep
follows it (WorkCounts::shadow_keeps_from_staging), else the heap's bytes
themselves, and plans no moves out of the image for the keep. Every byte a
command wrote is merged whatever the copy in changed; a value the copy in
changed in a texel no command wrote is written back as stored, as a copy back
writes it.

That clamp is the device's: a heap's 32-bit float depth texture whose shadow
copies the heap's bytes into its image now announces restricted-depth-upload
as it is made, on a device without VK_EXT_depth_range_unrestricted whose
driver is not measured to keep such a value (ANV; not MoltenVK, NVIDIA or
lavapipe with the extension). Its declaration, docs/API.md's catalogue and a
device-gap row in docs/FAST-PATHS.md say so.

The measured drawn-depth-copy flag a multisample texture held for its keep
is gone with its one reader; the announcement at making stays.

heap_multisample_textures_keep_their_samples_in_metal_s_tiles now also
checks, for each counted 32-bit float depth texture, restricted-depth-upload
as it is made where the device clamps, and that a blit into one slice or
aspect keeps from staging. Verification in the tip report.

(cherry picked from commit 688e1dcc00ff67979833fdcbaf2f5484057e18a6)
2026-11-08 13:16:59 -08:00
Anees Iqbal e106dbf2c7 FAST-PATHS: the 780M's later clips at one budget for its heaps made no allocation and took 122 and 119 ms
m3-max-9499 at 9bc836c2e9 on um790's Radeon 780M alone (RADV PHOENIX,
MESA_VK_DEVICE_SELECT 1002:15bf!): tests::clip_bursts' later clips made
0 and 0 allocations (16 in the first) in 121.5 and 119.2 ms, against 4
each and 237/245 ms with the placements in the system heap and a budget
per heap, and 132/126 ms with them device-local. The bullet said the
unified budget keeps every block; it now carries the measurement.

(cherry picked from commit f2e2063f1ff7050d7eeefd6ecdc26ace0c4bc29c)
2026-11-08 13:02:13 -08:00
Anees Iqbal 6be762136b Memory: with unified memory the heaps keep one budget of empty blocks
With the UMA placement, a Radeon 780M's Private placements take its
5.53 GiB system heap, whose eighth (707 MiB) kept all but 3 of a video
clip's 16 blocks: each later clip made 4 again (tests::clip_bursts,
m3-max-9454: [4, 4]) and took 237/245 ms to make against 132/126 ms with
the placements device-local (m3-max-9448). With unified memory every heap
is the same memory: the budget is now an eighth of all the heaps, at most
KEPT_EMPTY_BYTES, and the empty blocks of every heap count against it, so
the 780M keeps 2 GiB as one budget where it kept 707 MiB and 1414 MiB
apart (2.1 GiB in all). Devices without unified memory keep a budget per
heap as before.

Tests: tests::memory::unified_memory_keeps_one_budget_for_its_heaps (the
780M's heaps, a discrete card's, one heap). FAST-PATHS: the kept-memory
row's 780M figures, and the UMA row's clip-burst cost.

Verified: not yet run; lavapipe and the 780M follow as potluck jobs.
(cherry picked from commit 9bc836c2e9cac4b43b86380e4c53ee3a02133214)
2026-11-08 13:02:13 -08:00
Anees Iqbal 40a634d351 FAST-PATHS: unified memory's Private placements in the system heap first, and what they cost
The 780M runs before and after the placement (m3-max-9103 at the base,
m3-max-9157 at the change, um790, RADV PHOENIX): copies of 256 MiB at
23.9/28.8 GB/s device-local against 28.5/29.0 GB/s in the system heap's
type; a 259-tile scroll beside 1 GiB of another allocation's local memory
at median frames 1.31/1.29 ms before and 1.87/1.30 ms after (frames 300
and 600), alone 2.87/4.87 ms before and 1.33/1.31 ms after; no
amdgpu_bo_move eviction traced in either. Recorded under the costs of
matching Metal: no cost measured, no switch, not announced.

(cherry picked from commit 3d1f49072ca66c9976835da4df54773f50a7f283)
2026-11-08 13:02:13 -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 7fbbac9536 Heap textures: an image that fits Metal's answer lies in place before a shadow
A single-sample colour heap texture whose image of the route the device
first took (ANV's compressed optimal image under the default
HeapCompressionPolicy, say) takes more bytes or a coarser alignment of the
heap than Metal's answer was a shadow of the heap's bytes in Metal's tiles,
copied in before each command buffer's first use and back after each
writing encoder. The owner's rule keeps a shadow as a correctness fallback
only: where the device makes an image that fits the answer in the heap's
memory, the texture now lies there in place, its optimal image of
host-transfer usage first, else its linear image
(Device::fitting_heap_image), announced heap-texture-host-transfer or
heap-texture-linear with the making's facts and what the first image took.

Unverified: built and measured on ms01's Iris Xe in the commits that follow.
(cherry picked from commit c1a996cd53f74d0afa130dd867ab42499c2b758f)
2026-11-08 12:19:41 -08:00
Anees Iqbal 6ef13920d0 Shadow causes for a walk: why a private truth's first copy in moved, and a log of each shadow made
The 780M's glass composites copy large Private IOSurface planes in each command buffer: walk 9286
counted 41.07 M texels first copied in per composite, 37.70 M of them over images an earlier
command buffer left standing, yet only 3 copies in a composite were decided against a standing
(2 skipped) of 84 shadow copies. No count said where the rest were decided, nor why each shadow
over those planes takes no image over the bytes.

- WorkCounts::shadow_texels_unskipped_*: every encoder's first copy in of a Private (or
  Memoryless) buffer's bytes, an IOSurface plane's among them, that moved its texels, by where it
  was decided (shadow_standing::Unskipped): unstanding (its shadow never stands: untracked, a
  heap's, the caller's memory, its VkBuffer handed out, writes dropped), between_instances (a held
  render pass's copies between its instances, inline_splits, which no submission decides),
  after_encoder_writes, recorded_whole (predicated laying, no new VkCommandBuffer),
  command_buffer (at submission: its command buffer reaches unnamed memory or an earlier encoder
  wrote the truth or image), let_go (at submission: the standing let go). With
  shadow_texels_skipped_by_standing they sum to shadow_texels_first_copied_in_private_buffers +
  _private_surfaces. And, but for unstanding, by what the standing held then (shadow_standing::
  LetGo, Standings::let_go): stood, never_stood, unnamed_since, truth_written, image_written; for
  those decided as the encoder records them, by the batches submitted so far.
- METAL2VULKAN_LOG_SHADOWS (default-off diagnostic, shadow_log.rs): one line per shadow a device
  makes of a texture over a buffer's bytes: the call (new_texture_with_iosurface_plane for a
  plane's), format, size, levels, usage, the buffer's storage mode, length and object ID, the
  texels' offset and row pitch, and the reason its shadowed-texture notice gives (announced once
  a device). Two textures over the same bytes name the same object ID and offset.
- Standings::stands is folded into let_go; submit.rs's gate answers where it was decided.
- Tests: shadow_standing_device checks both sums in every leg, and the first read's copy in is
  let_go/never_stood, the read after another queue's fill let_go/truth_written, a read after its
  own command buffer's fill command_buffer, a read once the VkBuffer was handed out unstanding.
- Docs: shadow_standing.rs, WorkCounts, docs/API.md (the log), env_vars REGISTRY; the artifact
  test's note on the variables the runtime reads. api_signatures blessed.

No behaviour changes: counts and a default-off log only. RUNTIME_VERSION not bumped (main's).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit a82491daf4a24ad57845c6e0f62bd53946dc22f8)
2026-11-08 12:18:18 -08:00
Anees Iqbal 8e1383b1b6 In-place check: an unchecked verdict whose cause lasts is kept; one that may pass is checked again
The previous commit kept every unchecked verdict out of the record, so a driver that truly
lacks what a class needs (an extension, a feature, an import, a format or an image of the
shape, such as lavapipe's DmaBuf and Pooled rows-in-lines, which RuntimeDriverDefect::
ExplicitPlaneRowsPastHeight refuses) would be checked again by every device. Such a cause is
fixed for the driver's identity, as stable as a passed or failed verdict, so it is kept; only an
unchecked verdict from a cause that can change between runs is kept unmeasured and checked
again.

- in_place_check::Unmade: the reason the check made no pages, pass or image, and whether its
  cause lasts. ClassPages::make, ExportedPages::make and Round::NotMade carry it.
  Lasting: no host import (VK_EXT_external_memory_host), no dma-buf images, export only as a
  dedicated allocation, no host-visible coherent type, no DRM_FORMAT_MOD_LINEAR images, and a
  placement answer the image's making decides before it binds (Refused Rows, Image, Pitch,
  Placement, DmaBuf; another route of the shape), and an error that is the device's gap or
  Metal's refusal (Error::Unsupported, Error::Invalid).
  May pass: pages, memory or mappings not made, an export failing, a no-copy buffer copied or
  imported otherwise on a device that imports host memory, an answer in place that only the
  bind refused (the dma-buf's import), detached or sourceless pages, the writer thread not
  started, a first move, pass or kernel's stores failing, the kernel's buffers refused, any
  other error (out of memory, a lost device, a Vulkan failure, the runtime's own gap).
- check_class answers, by row ends, whether an unchecked verdict met a cause that may pass;
  run writes those verdicts pending in the record and the rest as given. encode writes the
  verdicts as given; decode reads every verdict byte (unchecked among them).
- Notes say which cause it was, "(a cause that lasts, kept)" or "(a cause that may pass,
  checked again)": the first of each kind per class and access.
- CHECK_VERSION stays 12 (the bump the previous commit made, not landed): a record of 11 may
  hold unchecked verdicts whose cause may pass, which no device takes now.
- Tests: an_unchecked_verdict_is_checked_again_where_its_cause_may_pass_and_kept_where_it_lasts
  (device test, replacing the previous one: the pointer class's failed import is noted as a
  cause that may pass and checked again by the next device; every measured verdict is recalled,
  each unchecked one recalled unchecked or checked again; on a driver with
  ExplicitPlaneRowsPastHeight the DmaBuf reads of rows inside lines are recalled unchecked).
  The record round trip holds passed, failed, unchecked and pending verdicts. The in-place
  textures lane's record test takes measured <= recalled <= VERDICTS.
  narrow_writes_device and freed_memory read only the report's verdict lines, not the notes
  after them (20 narrow lines counted where 16 were due on lavapipe, job 9303).
- Docs: in_place.rs, in_place_check.rs, WorkCounts::in_place_checks_recalled,
  settle_in_place_checks, docs/API.md, docs/FAST-PATHS.md (the in-place row).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit b420f97f56237fc0bf153691e9ac7e5a8e923386)
2026-11-08 12:15:38 -08:00
Anees Iqbal aa188702ad In-place check: an unchecked verdict is no measurement, kept unmeasured and checked again
On the Iris Xe (ANV) reims' arm-s boots made 890 shadows over guest RAM imported as dma-bufs,
every one "the device's check made no image over host pages imported as dma-bufs" (Unchecked),
small ShaderRead textures at offset 0 on whole pages among them, where a fresh check of the
same driver passes the class's reads (aafecf768a, job 7667). The record kept every verdict the
check gave, Unchecked among them, and every later device of that driver and check version
recalled it and checked nothing: a refusal of the class's pages (or of its rounds' images) in
one process, a transient one or one of that device's setup, answered for every boot after.
And the check kept no reason for it: the class's pages and rounds that made no image returned
unchecked with no note.

- in_place::encode writes an unchecked verdict as unmeasured (a pending verdict's byte);
  decode reads that back pending and refuses an unchecked byte (never written).
  recall_in_place_checks recalls the measured verdicts (passed or failed, counted as recalled)
  and settles only where none is pending: the first texture that asks a pending one starts the
  check, which runs only the classes and accesses still pending, and its record replaces the
  old one.
- CHECK_VERSION 12: a record of 11 may hold unchecked verdicts as answers, which no device now
  takes; reims' stale records are dropped by it.
- Reasons, noted in the check's report after the verdicts: ClassPages::make answers why it made
  no pages (each step of ExportedPages::make for the dma-buf class: no host import, no dma-buf
  images, an export only as a dedicated allocation, no host-visible coherent type, the
  allocation, map or export failing; a no-copy buffer refused, copied, or imported otherwise),
  and a round that made no image says why (its making's error, the placement's answer for a
  texture not in place, its first move or pass failing), the first per class and access.
- Tests: a_class_whose_pages_the_check_could_not_make_is_checked_again_by_the_next_device
  (device test: the pointer class's first import fails, so its reads are Unchecked and noted; the
  next device of the cache recalls every measured verdict, finds those reads pending, checks
  them again; the device after recalls them). Before this change the second device recalled the
  reads as Unchecked. The record round trip reads unchecked back pending; the in-place textures
  lane's record test recalls the measured verdicts and checks the rest again.
- Docs: in_place.rs, in_place_check.rs, WorkCounts::in_place_checks_recalled,
  settle_in_place_checks, docs/API.md, docs/FAST-PATHS.md (the in-place row).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit 29f3114ca990382776e795f35ea9b81f8345399a)
2026-11-08 12:15:38 -08:00
Anees Iqbal a3fb1283e6 FAST-PATHS: the first clip's allocations stay open, with their cause and why no block is made ahead
(cherry picked from commit 4d2833ae3d662006101e3be98bfba4c7da58603e)
2026-11-08 11:49:37 -08:00
Anees Iqbal 186d327fe7 Memory: kept blocks past their quiet period go within a second at the next creation call; FAST-PATHS records the kept memory
A kept empty block was looked at only when a release came in its own pool, so a
pool whose resources stopped coming and going kept its blocks, up to its heap's
budget, until its next release. The device's creation calls (keep_room) now
also free every pool's kept blocks past KEPT_EMPTY_FOR, at most once every
KEPT_SWEEP_EVERY (1 s): the memory is held at most about 11 s past a working
set's dip wherever the program still makes resources.

docs/FAST-PATHS.md, known gaps: the NVIDIA memory block row, with the bound
(an eighth of a heap, at most 2 GiB, 10 s), what it holds per device, why it
has no switch (no answer of Metal's changes), and the RTX 5080 measurement of
tests::clip_bursts (poolwait-burst, NVIDIA 615.71.09, two runs each): clips 2
and 3 took 41 and 40 allocations and 89 to 102 ms with 2 to 5 commits held
1 ms or more (longest 8.8 to 9.4 ms) before, none and 64 to 71 ms with no
commit held (longest 0.39 to 0.67 ms) after; a first clip 44 allocations
before, 16 after.

Not yet built: the sweep builds and runs next on lavapipe.

(cherry picked from commit b31e221ee4cfba1861320e8c674a01ea83614013)
2026-11-08 11:49: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 6f702cb76a docs/API.md: an exit mid-making, the difference left
What: the accepted differences' "Process exit" names what the exit hook's registrar leaves: a
making on the program's own thread, which the exit does not wait for, and destructors the
driver's compiler registered in the last 2 ms before the exit (or past the registrar's 16384
registrations), which can run beside the compile, where Metal compiles in another process.

Why: the registrar (RUNTIME_VERSION 1899) closed the rest of exit_guard's hole for makings on the
runtime's threads; what is still open is a consumer-visible difference, and one such exit (a
consumer's making thread left running) ended its process with SIGSEGV inside NVIDIA's SPIR-V
compiler on the RTX 5080.

How verified: docs only; the figures are exit_guard's MAKING_INTERVAL and MAKING_REGISTRATIONS.

(cherry picked from commit 5f1846a295017a2244fde27cdd2ed3db97bdb9cb)
2026-11-08 09:58:54 -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 ecddb49936 FAST-PATHS: the NVIDIA pool block gap with its sizes, its frees and making ahead
The RTX 5080's measurement of its own (an exclusive window, 12 blocks a
size): vkAllocateMemory of a pool block's memory takes about 0.16 ms a
MiB, idle or beside another process's GPU work (medians 5.5, 11.0, 20.4
and 40.6 ms for 32, 64, 128 and 254.7 MiB), vkFreeMemory about 0.035 ms
a MiB, and every vkQueueSubmit another thread calls during either
returns once it does. Frames every 16.7 ms met a 254.7 MiB making 28.6
to 48.6 ms late on their own thread (23 of 23 over 1 ms), and up to 67.5
ms with the making on another thread, spread over the frame or right
after a submission (11 of 23 either way). So no block is made ahead on
a thread of the device's own: it would not keep frames from the hold.
A smaller block would shorten it in proportion, at the cost of each
command buffer's pool capacity, which is the orchestrator's call.

Verified: docs only; the numbers are entry
poolwait-poolwait-sizes-063031-063031 (7eb0aab5e5's allocation_holds).

(cherry picked from commit f3e209f7ea255d79ef6b524bd1dcd176e9792589)
2026-11-08 09:33:19 -08:00
Anees Iqbal 0d66b9de2b with_vk_queue: the closure gets the VkDevice its VkQueue belongs to
`CommandQueue::with_vk_queue` now calls `f(&ash::Device, vk::Queue, u32)`. The
device is the serving generation's, read under the queue's lock with the
VkQueue. After a recovery the queue lends the new VkDevice's VkQueue. Until
now a caller could get the device only from `Device::raw` handles it had
cached, and after a recovery those name the lost VkDevice. The consumer's
copier did exactly that: it submitted command buffers from a pool made on the
lost device to the new device's queue, and the process died inside RADV
(a segfault at null+0x50 in libvulkan_radeon.so, right after our "VkDevice
was lost and made again" log). No call let it see the change atomically.

Every call site in the runtime, its examples and the validation lanes takes
the new argument. The runtime README's interop and "A lost device" sections,
`Device::raw`'s docs and docs/API.md's device-recovered entry say what the
closure gets. api_signatures.tsv is re-blessed (one signature changed).

Test: device_recovery::a_lent_queue_names_the_vk_device_it_belongs_to_across_a_recovery.
It reads the lent queue's device before and after recover_for_test. The two
differ, and the second equals what Device::raw answers after the recovery.
The test also asserts the old route is wrong: the raw handle cached before the
recovery differs from the lent queue's device after it. That cached handle was
the only source of the device under the old signature.

(cherry picked from commit b4bf228df9db98a451c997f350c6014b027f7e31)
2026-11-08 09:16:24 -08:00
Anees Iqbal 97ba27de2d Regenerate docs/REFUSALS.md for the version-1 symbol table's refusal site
The module-level symbol table reader (bitcode/module.rs, Names::read)
refuses a summary-index entry (VST_COMBINED_ENTRY) as
Unsupported(BitcodeRecord), a new construction site of that variant.
Generated with python3 scripts/refusal-surface/refusal_surface.py.

(cherry picked from commit b500dc8717a4dd60f84eb775fa0a70446db44cd6)
2026-11-08 09:09:42 -08:00
Anees Iqbal bfcd71e5d6 Record the short last row's shadow among the known gaps
A texture over host pages whose buffer ends inside its last row's pitch is a shadow
(Refused(Placement)): a linear image's last row takes the whole pitch, so the image's memory
requirements reach past the buffer's bytes, over an import of the caller's pages and over a copied
host buffer's copy alike, whose placement is the buffer's length. Metal reads such a texture in
place, so it is a runtime cost above the driver's: docs/FAST-PATHS.md's known gaps now say so, and
InPlaceRefusal::Placement's doc names the case.

Seen on the Iris Xe (ANV) and the 780M and RX 550 (RADV) by a probe at the guest's shape, which
stays on a branch of its own.

Verified: cargo fmt; scripts/api-signatures --check (signatures unchanged; a doc change).
(cherry picked from commit 9493894b26cee3b1a525d9a0916a83f3fc6a594f)
2026-11-08 09:08:35 -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 15c72b1690 GPU pools: a block a queue lets go is the device's spare for the next queue
A queue's pool block that went (its queue went, or no lease held it for
QUIET) was released, and the next queue to need a block of that kind
made one again: on the RTX 5080 a 254.7 MiB vkAllocateMemory of 4.9 to
189.5 ms beside other GPU work, during which the driver holds every
vkQueueSubmit of the process (docs/FAST-PATHS.md, known gaps).

Now the block becomes the device's spare of its kind where the device
holds none (else it is released, as before), a made-meanwhile block too,
and a queue holding no block takes the spare at its first lease before
it makes one. A device so makes no more blocks of a kind than the most
queues that held one at once, and none as queues come and go or rest.
The cost is one block of each kind beyond the queues' own until a queue
takes it or the device goes: 254.7 MiB of device memory on the RTX 5080
Laptop GPU, 1 GiB of host memory kept wired on the M3 Max. The spare is
safe to hand on: no lease holds a block that goes, so no command uses
it, and nothing reads a pool's bytes before its own command buffer wrote
them.

QueueBlocks::drain pops the slots instead of taking the map.

Tests: the pool CPU tests cover the spare from both releases, the
made-meanwhile block, the teardown and queue churn (eight queues one
after another make one block); the device tests see a later queue and a
rested one take the spare without a making, and the handler test makes
each round's block after a holder queue took the spare.

Verified: cargo fmt only, here; the runtime and validation suites, clippy
and the device runs follow as potluck jobs.

(cherry picked from commit dcc2bc0cb49f391b7d14c135d7aae97f1a93795b)
2026-11-08 08:48:27 -08:00
Anees Iqbal 9024d9ee5f index_pools: count a completed handler's lag from its submission's return too
runtime_lane::index_pools::a_completed_handler_waits_for_no_pool_block_made_meanwhile
failed on the RTX 5080 (round 5ce05e1908, lane ln07): the handler ran 37.2 ms
after its command buffer completed, during a 50.5 ms making of the other
queue's index pool block.

What it waited on is the driver, not the completion path. A probe on the
5080 (NVIDIA 615.71.09; 40 rounds of the lane's draw, with and without the
validation layer, completion trace, b5080 entry poolwait-probe1) found:
- the making is nearly all vkAllocateMemory of the 254.7 MiB block, 3.1 to
  35.7 ms beside another process's GPU work;
- in 25 rounds the scheduler thread's vkQueueSubmit of the first command
  buffer was called during that allocation and returned 0.01 to 0.25 ms after
  it, twice after the GPU had ended the batch (23.9 ms into a 29.4 ms making;
  0.3 ms into a 3.7 ms one: the failure's shape). The runtime watches a batch
  from its submission's return on, so it completed as the making ended;
- in the other 15 the submission returned before the allocation began, and
  the handler ran during the allocation in all 15;
- in all 40, the handler ran 0.07 to 1.44 ms after the later of the GPU end
  and the submission's return;
- raw, another thread's vkWaitSemaphores (no wait), vkGetSemaphoreCounterValue
  and vkGetFenceStatus took at most 0.03 ms during allocations of that size
  (1.9 to 213.6 ms): host waits are not held, submissions are.

So the claim is now exact: the lag counts from the later of the GPU end and
the kernel end time (the last vkQueueSubmit's return), and a round tells only
where both fall in the making's first half. One round told about one time in
four on the 5080, so the test runs 12, each with a queue of its own, and
prints each. The driver's hold of the submission is a known gap
(docs/FAST-PATHS.md), and gpu_pools.rs says what a making costs there.

(cherry picked from commit 438b4ec928dc1d44d2003a20537fea77a768d731)
2026-11-08 08:23:36 -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 27eea49ec5 HostRam: a copy over a listed chunk not imported takes lists of its own pages, of an opt-in source
HostRam::with_dma_buf_of_runs(source, most_runs) gives a RAM a DmaBufRunsSource: one dma-buf of
a list of runs of its pages, their pages one after another (udmabuf's UDMABUF_CREATE_LIST on
Linux, at most list_limit runs a list). Only copies by runs call it, and only where the plan is
Plan::listed (each held import costs every submission and the RAM's chunks are the device's
dma-bufs of its source: RADV) and the device's barriers order blits through two imports of the
same pages. There RamOnDevice::for_copy, for a chunk not imported, takes RamOnDevice::run_lists:
the copy's ranges of the chunk by address, widened to whole host pages and joined where those
share or touch a page (copy::page_runs), split into lists of at most most_runs runs and one
dma-buf's bytes (copy::run_lists), each imported as one dma-buf of the source
(Device::ram_runs_as_dma_buf, Imported::Runs), held by the command buffer until it completed and
freed then. The chunk is neither imported nor asked for, so copies pin their own pages while they
run and never a chunk's untouched pages, which udmabuf allocates for good. Without the source, a
source that fails or answers a dma-buf of another length, the margin of the allocation limit, a
run that is the whole chunk or passes one dma-buf, the copy takes the chunk as before.

A list's VkBuffer holds each run from where the runs before it end: RamChunk keeps the runs and
their offsets (RamChunk::offset_of, RamChunk::bytes), and the copy maps each piece through it;
regions take their host bytes from the pieces, not the import's span. alone_ranges takes one
chunk's sorted ranges (chunk_ranges with no cap) and joins them as before, so every other plan
(ANV, NVIDIA, lavapipe, MoltenVK, RADV without the source) copies as before.

Counted: WorkCounts::host_ram_run_list_imports (new), live in run_imports_live. Tests: copy.rs
units for page_runs and run_lists; host_ram_dma_buf's tile tests over a RAM with a udmabuf list
source (lists of at most 1,024 runs, no chunk, nothing asked, no untouched page resident) and,
without it, the chunk; elsewhere the list source never asked. The bench takes the list source and
prints first and repeated copies, sorted runs and lists per copy, over surface-shaped and
scattered tiles. api_signatures blessed (three added: DmaBufRunsSource, with_dma_buf_of_runs,
the counter; nothing removed); docs/REFUSALS.md regenerated (a DmaBuf site).

Verified: cargo fmt and the signature and refusal scripts only; the 780M runs follow.
(cherry picked from commit f2e5c143dd314835fd58cd6f8430c5c7c620e52a)
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 ded385b661 YCbCr textures: announce the device's conversion at the first conversion; the lanes read in-place samples as Metal's
On the Radeon 780M, which converts the 4:2:0 formats itself and reads their planes in place, the
ycbcr lanes failed 9 of 48 at this branch (um870 m3-max-8383) and 17 of 48 at development's tip
(gem10 m3-max-8421), the same 9 among them. Two causes:

- A texture whose conversion is the device's announced ycbcr-filter-not-exact as it was made,
  though a texture whose planes every function reads in place never converts and so never reads
  the device's conversion (a_ycbcr_texture_sampled_and_gathered_by_one_function_reads_its_planes_in_place,
  a_ycbcr_sample_through_an_unmeasured_filter_is_announced). Converts::new now announces it at
  the texture's first conversion. WorkCounts::ycbcr_device_conversions still counts the texture
  as it is made, so a lane can tell before a read that the texture's image holds the device's
  conversion. The lanes' notice predicates now take a conversion that ran,
  WorkCounts::ycbcr_device_samples (device_samples), in place of the textures made.
- The lanes held the samples of a texture whose planes are read in place to its image's texels,
  the device's conversion on such a device, where a function reading the planes converts the codes
  itself: Metal's conversion and filter under the lane's exact_answers (YCbCrInPlacePolicy::Exact),
  as ycbcr.rs states. Texels::sampled takes Metal's steps of the codes (modelled) for a texture read
  in place and the image's texels elsewhere, in a_linear_sample_of_a_ycbcr_texture_is_metals,
  a_linear_sample_is_metals_through_each_sampler_and_result and its fragment twin,
  a_ycbcr_slot_takes_the_devices_filter_in_the_pipeline_its_creation_made and
  ycbcr_textures_read_the_texels_metal_converts; a_draw_samples_the_planes_as_written_before_it
  holds a draw read in place to Metal's conversion of the uniform codes.

four_two_two_and_four_four_four_codes_read_what_metal_reads also held a code twin over a surface
whose chroma plane it does not fit in to Metal's codes where the device reconstructs them itself:
it now takes the device's codes there, as the test's other surfaces do.

Docs: the ycbcr.rs and ycbcr_device.rs module docs, Degradation::YCbCrFilterNotExact and its
docs/API.md catalogue entry say the notice comes at the first conversion.

Verified: cargo fmt; the 780M runs on um870 and gem10 follow.
(cherry picked from commit c498f9383a3f4a2ef3f267a135ea5494aa8fb5e4)
2026-11-08 06:29:49 -08:00
Anees Iqbal 5640e17560 Document the model's linear sample of planes read in place
FAST-PATHS.md gets the ledger row for ycbcr_in_place_reads (Model default,
Exact switch, the 780M's exact-form cost measured at development's tip),
the device-gaps row and the in-place section name the choice; API.md's
policy list and the half/float filter and ycbcr-filter-not-exact catalogue
entries name the model; PrecisionNote::HalfSampleFilter/FloatSampleFilter
and Degradation::YCbCrFilterNotExact docs say the model records and
announces them.

(cherry picked from commit 5f83699d296386c3b0b357f2baa63cfefc086096)
2026-11-08 06:29:47 -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 48caeeb155 DegradeNotice::command_buffer: the command buffer whose work announced a notice
A consumer that makes some notices fatal (reims-vgpu's ReleasedCommandState,
PrivateResourceOption, HostDeallocatorDelayed) could not tell which command
buffer a notice was about: a ReleasedCommandState announced at a host step on
the scheduler's steps thread ended its whole VM. Now every notice carries the
ID of the command buffer whose work the runtime was doing on the announcing
thread, so the consumer can fail that one command buffer.

What changed:
- CommandBuffer::object_id: an ObjectId, minted at the command buffer's
  making from the process-wide count buffers, textures and heaps use.
- DegradeNotice::command_buffer: Option<ObjectId>, read at the notice's making
  from a thread-local scope (degradation::NoticesFor), as `call` reads the
  call being lowered. The scope is set where the runtime holds the command
  buffer and does its work: the compute and blit encoders' logged funnels and
  their other recording calls and ends, the render lowering's at-call funnel,
  its unit calls, its batches' lowering (on the lowering thread or a drain)
  and its end, the resource state encoder's calls, encoder openings, the
  commit (at the call or queued behind a render end), a batch's submission and
  the storage-form settle that rides on it, host steps, a rebind's encoding
  again, and GPU-time reads. Nested scopes name the innermost.
- None, explicitly, for a recovery of the device (device-recovered), for
  grouped-completion (several command buffers' batches), and inside the
  program's code the runtime calls (exit_guard::program, indirect command
  checks, executed-commands handlers).
- A bind's memoized notices, announced again at each later bind under
  announce_each, are named as that bind's: its command buffer and the call
  being lowered (the call was the first bind's before; same mechanism).
- ObjectId docs, docs/API.md section 9, docs/RUNTIME-PORTING.md; API
  signatures re-blessed (two records: the field and the method).

Tests (runtime crate, device tests):
- notice_command_buffers: an ICB execution recorded at a host step announces
  released-command-state on the steps thread naming the executing command
  buffer; its commit's host-replayed-indirect-commands, on the program's
  thread, names it too; private-resource-option of an ICB made between the
  encoder's calls names none.
- deferred_calls: the call-naming test also checks the command buffer under
  both lowering policies; a new test waits for the lowering thread to announce
  unsized-points after end_encoding and checks the thread, call and command
  buffer, and that a device notice between the encoder's calls names none.
- vertex_conversion_notices: a memoized bind notice (device-nan-encoding)
  announced at a second command buffer's draw names that command buffer and
  its own call index, with bound_notices_made proving the memo was reused.

(cherry picked from commit b4c2ba83ea726229f129a405ce6f432b0bdb0127)
2026-11-08 04:45:15 -08:00
Anees Iqbal df2d326289 A device's teardown leaves the device to the process's end at its next step once the exit began
runtime_lane::exits::exits_right_after_learning_of_completion_are_clean failed on the RTX 5080
in lane 10 of development's round at 9bd38c7994: handler_learns_exit's exit took 2.08 s, against
the lane's EXIT_LIMIT of 1.5 s. In that case the program drops its device while a command buffer
is in flight, then exits once the command buffer's completed handler has run. The device's last
reference goes on the handler thread, so its teardown (DeviceShared::drop, one section of the
exit guard) runs while the program's exit begins, and the exit's hook waits for that section.

Each step of that teardown was timed in a scratch build (b5080 entry holds-exit-2, beside another
process's lane on the GPU). vkDestroyDevice, through the validation layer into NVIDIA's driver,
took 0.3 to 2.6 s; every other step took under 0.25 s in all. 86 of the 120 exits ran past the
hook's 2 s bound and ended at once. In each stack taken 1.2 s after the child's last line, the
teardown's thread was in vkDestroyDevice. The same tail showed with 47174c4775 (the queue-switch
check's round hold) reverted: entry holds-exit-1, 30 exits a tree, the two trees' exits in the
same two modes (about 25 ms, and 150 to 250 ms with a tail to 0.6 and 0.95 s).

The teardown now reads the guard at three points: before its wait for idle, before its pipeline
caches and memory go, and before vkDestroyDevice. Once the exit has closed the guard, the device,
its objects and its memory are left to the process's end, as where the exit began before the
teardown, so the exit waits for no more than the teardown's step in progress. A teardown that no
exit races is unchanged. exit_guard's module docs ("Once closed", BOUND), the teardown's comments
and docs/API.md's process-exit difference say so.

Verified, RTX 5080 Laptop GPU, b5080 entry holds-exit-3 (a shared batch). Runtime_lane::
framebuffer_fetch looped beside on the GPU. handler_learns_exit's child ran as the lane runs it,
alternating two builds 60 times each: development dc064aec27 with the step timings, and the same
with this change. Each exit was measured as the lane measures it, less the exiting thread's wait
for a CPU:

                              before (dc064aec27)   this change
    teardown on the handler   43 of 60              41 of 60
    left at wait-for-idle     -                     41 of 41
    hook's wait (handler)     0.17 to 1.03 s        1 to 7.5 ms
    exit, median              478 ms                206 ms
    exit, 90th percentile     932 ms                411 ms
    exit, longest             1130 ms               590 ms
    exits of 500 ms or more   29                    1
    exits of 1 s or more      2                     0

- With this change, an exit whose teardown ran on the handler still takes 0.17 to 0.59 s past the
  hook. That time is in the exit handlers registered before the hook's last registration (the
  driver's and the layer's), with the device left to them. Before, that remainder was 24 to
  138 ms.
- exit_guard's unit tests passed 46 of 46 (homelab-gem10-1, m3-max-8041).
Not run before this commit: the exits lane whole (development's round runs it), and the change
beside the heavier GPU load of holds-exit-2 (queued: holds-exit-4).

(cherry picked from commit 4ee7b0934a7e2db25b2262cf9c03d84313336be3)
2026-11-08 03:41:48 -08:00