Commit Graph
396 Commits
Author SHA1 Message Date
Anees Iqbal 4289823b20 Runtime: work recorded again keeps its tiled takes; a batch that fails at its submission gives them back
A tiled texture's copy taken at use is taken by the first use encoded after
its mark; a recording that never runs must hand its take on or give it back.
Three paths lost it:

- A rebind that encodes an encoder again re-recorded the encoder's segments
  (a render pass recorded on the GPU alone, its shadowed textures' copies
  in the segment) into cores that asked the mark, which the first
  recording had cleared: the pass read a copy nothing made. The same held
  for work on the GPU alone a rebind records again without encoding its
  encoder again.
- A host step whose recording failed, and a vkQueueSubmit that failed,
  failed the command buffer outside fail_part: the takes of the batch and
  the later ones were never given back, so the next use read stale levels.

How:
- shadow.rs: one way to decide. ShadowSync::again (take nothing unmet,
  note nothing) is gone; every recording in place of others is
  ShadowSync::over a shared Replaced pool: a use that meets a decision of
  the replaced recordings keeps its take, any other asks the mark. The
  cores recorded during one turn share the pool, so each decision is met
  once, in order.
- State::replaced_takes (was step_takes and replaying_takes) holds the
  pool while a host step, a rebind's encoding again (the first encoding's
  takes and its segments' recordings' takes, State::takes_of) or a
  rebind's recording again on the GPU alone records. segment_raw hands it
  to every core. A spliced encoding again or segment gives back the takes
  of the first recordings it did not meet (Takes::give_back_unheld); a
  refused one gives back its own takes the first did not hold. The
  encoder's record keeps the encoding again's takes.
- State::place joins a placed segment's takes into its encoder's record,
  and CommandBufferShared::never_runs_from (State::give_back_from) gives
  back the takes of every part from the failed batch on, called beside
  each of the scheduler's three failed() calls.
- docs/FAST-PATHS.md, known gaps: a predicated loop's run again records
  its work apart as a new recording that asks the mark, so a
  did_modify_data during the loop is taken mid-loop and the next use
  after it takes nothing. Keeping the first run's takes (over) would copy
  in again at every run, so it stays a recorded gap.
- docs/API.md and the shadow.rs and reencode.rs module docs say the
  above.

Verified: see the next report (lavapipe before/after, the 780M, lint).
2026-11-11 11:10:10 -08:00
Anees Iqbal 60dfe0eb4b FAST-PATHS: the Shared bus cost drops its OpenCL claim, which the consumer's measurement withdrew
The consumer re-measured (their job m3-max-16759): Apple's OpenCL on Metal makes one Managed
no-copy buffer per cl_mem and synchronizes it as Metal requires; its Shared buffers are
staging. So no OpenCL buffer must stay Shared on a discrete GPU; the Shared bus cost stands
as measured.
2026-11-11 11:09:11 -08:00
Anees Iqbal e05da5d264 FAST-PATHS: the measured cost of VertexReachPolicy::Exact on lavapipe
runtime_lane::far_vertex_fetches::far_reach_costs on lavapipe (Mesa 26.2.4, LLVM 23.1.1, msi;
jobs m3-max-16602 and m3-max-16705): under Exact one pipeline more (the pulled variant, made at
the first uint-indexed draw), and a pass of one draw of 65,536 uint-indexed points 2.3 to 2.8
times as long (medians 0.94 against 2.41 ms beside two builds; 3.5 to 4.8 against 9.7 to 12.0 ms
at a load average of 59 on 24 threads). Not free, so the switch stays opt-in.

The defect's doc names the second lavapipe release measured and the 780M's Mesa.
2026-11-11 10:54:48 -08:00
Anees Iqbal 834b663634 Runtime: pull a far vertex layout on a driver whose fixed-function fetch wraps at 4 GiB
lavapipe's fixed-function vertex input takes an element's displacement modulo 2^32: the
conformance case vertex-fetch-past-4gib-small-buffer reads the wrapped words in 24 elements
where Metal reads zero. Vulkan places the attribute at the whole displacement (28.4 Vertex Input
Address Calculation) and robustBufferAccess2 makes a read past the bound range zero, so the
wrap is the driver's defect: a new RuntimeDriverDefect::VertexFetchWrapsPast4GiB, listed for
MESA_LLVMPIPE alone.

On a listed driver the render lowering names the fixed-function layouts a draw may fetch past
2^32 bytes of their bind offset in a new BindState/BindShape field, far_vertex_buffers, and the
binder pulls them (the existing pulled-vertex-buffer variant, whose fetch reads past 2^32 as
zero). The reach is the existing furthest_element: a draw's last vertex, 65535 plus the base
vertex for ushort indices, the base instance plus the last instance over the rate. Those are
pulled by default. A per-vertex layout of a uint-indexed draw, and an indirect draw's, has its
reach stated by GPU memory; pulling it costs a variant for every such draw, so it is behind a
new runtime-only DevicePolicy switch, vertex_reach (VertexReachPolicy::Bounded by default,
Exact in exact_answers()). Under Bounded such a draw keeps fixed function and is announced
vertex-fetch-may-wrap (Precision). The draw-again paths (rebound, restated) compare the pulled
set; the host-step precompile names none; the GPU replay derives it from its indirect draw.
WorkCounts::far_vertex_fetch_pulled_draws counts the pulled draws.

The conformance case's known-gaps row is removed: replay runs under Exact. FAST-PATHS gets the
switch's row (its lavapipe cost is measured next, in a later commit). New tests: the binder
pulls a named layout; far_layouts under both policies; runtime_lane::far_vertex_fetches
measures the defect on every device under both values, and far_reach_costs (ignored) measures
the exact form's cost.

SEMANTICS_VERSION is unchanged: an empty far_vertex_buffers, every existing shape's, plans as
before, so no output changes under an unchanged key.

Verified so far: api_signatures blessed (signatures.py), refusal_surface --check, the
conformance and Metal coverage checks; builds and tests follow as potluck jobs.
2026-11-11 10:54:47 -08:00
Anees Iqbal 9a67d986e6 Separate depth and stencil textures: an unstored DontCare aspect follows UnstoredDontCarePolicy in the scratch image
A pass whose depth and stencil attachments are two textures renders through a scratch image of
the combined format (depth_stencil_scratch.rs), and clear_reach::dont_care_loads skipped it: an
aspect loaded DontCare and not stored took the scratch's DONT_CARE load under every policy, with
no notice. So under exact_answers() its draws read what the new scratch image held (on MoltenVK
a stencil of 0 and a depth of 1.0, Metal's defaults for a load that names no clear value), where
Metal's read the pass's clear value: measured on the M3 Max under macOS 27.0.1 by the lane's
passes through Metal itself (job m3-max-16522), each aspect apart, whether the other aspect is so
loaded or loaded and stored.

Now such an aspect takes the answer of any attachment so loaded, each aspect apart: in a pass
whose draws reach a tile, the scratch's Clear to the aspect's clear value under
UnstoredDontCarePolicy::Cleared and on a driver with DriverFact::UnstoredClearNoSlower (the
scratch image is a combined depth/stencil attachment, the shape the fact measured), else its
DONT_CARE, announced dont-care-unstored-load naming the aspect. Nothing is copied into the
aspect before the pass (only Load aspects are), so no earlier bytes reach it. An aspect the pass
stores keeps the scratch's DONT_CARE load as before.

Docs: clear_reach.rs records Metal's answer for separate textures and the rule; the scratch
module, the notice's rustdoc and catalogue entry, UnstoredDontCarePolicy's rustdoc, API.md's
section and the FAST-PATHS row name separate textures; the known gap is removed.
2026-11-11 10:35:17 -08:00
Anees Iqbal 56c3037d68 FAST-PATHS: a Shared buffer over host pages runs at the bus's speed on a discrete GPU, OpenCL on Metal's included
Measured by the consumer on the RTX 5080 Laptop GPU and a Radeon Pro 5300M (their jobs
16447, 16453, 16455, 16554): Shared no-copy 5.3 GB/s against Private 328 GB/s on the 5080;
6.1 against 96.1 on the 5300M. Apple's OpenCL on Metal synchronizes its Managed buffers on
its map path only, so a second copy would go stale; its buffers stay Shared on a discrete
GPU, a cost recorded here.
2026-11-11 10:15:27 -08:00
Anees Iqbal 02a20709a5 FAST-PATHS and the fact's measurements: NVIDIA's RTX 5080 Laptop GPU clears 3.2 us slower, so no row
The same probe through the 5080 batch loop (b1111-091522-t, job m3-max-16381, exclusive): 74.4 and
74.6 us a pass with CLEAR against 71.2 and 71.4 with DONT_CARE, the rounds' spreads apart (73.6 to
75.1 against 70.2 to 72.6). NVIDIA keeps DONT_CARE under the default, announced; the RTX 3090 is
unmeasured (um870 stayed behind exclusive boots) and takes the same.
2026-11-11 09:59:04 -08:00
Anees Iqbal 35c68796d3 Unstored DontCare loads: a DevicePolicy switch, cleared by default where the driver clears no slower
The fix before this cleared every attachment a pass loads `DontCare` and does not store, Metal's
answer (lane dont_care_unstored). Measured, that clear is no cost on some drivers and a cost on
others, so by rule 1 it is now a speed-for-accuracy choice with both forms kept:

- DevicePolicy::unstored_dont_care_loads: UnstoredDontCarePolicy::Driver (the default) clears
  such an attachment on a driver with DriverFact::UnstoredClearNoSlower and leaves it DONT_CARE
  elsewhere, announced `dont-care-unstored-load` (a new precision notice); ::Cleared, which
  exact_answers() selects, clears it everywhere. The runtime's choice alone: no profile carries it.
- DriverFact::UnstoredClearNoSlower, a cost fact, one row per GPU measured no slower with CLEAR
  than DONT_CARE (a probe of eight 3648x2038 passes a frame, an RG16Float colour and a
  Depth32Float_Stencil8 loaded by the form and stored DontCare, GPU time per pass, medians of 15
  frames in two rounds): RADV, Mesa 26.2.6, on the Radeon 780M (861 and 865 us against 1147 and
  988, job m3-max-16320) and MoltenVK 1.4.2 on the M3 Max (218 and 218 against 224 and 217,
  within one form's spread, m3-max-16341). Measured slower, so no row: lavapipe (10480 and 10744
  against 7280 and 7259, m3-max-16321) and ANV, Mesa 26.2.6, on the Iris Xe (1936 and 1936
  against 1907 and 1151, m3-max-16343).
- The lane dont_care_unstored expects Metal's answer under exact_answers() and on a driver with
  the fact, lavapipe's earlier texels under the default there, and the notice exactly where the
  load is left to the driver.
- dont-care-store's text names the new answer after such a pass: where the pass loads the
  attachment DontCare and clears it, a tile no draw touches holds zero or the clear value.
- docs/FAST-PATHS.md: the switch's row with the per-driver numbers, and a known gap: separate
  depth and stencil textures (the scratch path) still load DONT_CARE under every policy.

NVIDIA is not measured yet; its row follows with the measurement.
2026-11-11 09:59:04 -08:00
Anees Iqbal 9d024acefe Runtime: a tiled texture's take whose encoder runs nothing is given back
A tiled texture of more than one level over a buffer takes its copy of the
bytes at the first use encoded after its making or a did_modify_data,
which clears its mark. Where that encoder runs nothing because its command
buffer failed before it ran (committed as failed, an encoder a failure
names, a protection fault, a submission that fails EncodedUseRebound or
DetachedBacking, a hang's discard or recovery, a predication record that
drops it), the copy was never taken but the mark stayed cleared, so every
later use read zeros or an older copy until the next did_modify_data.

The take is now given back where the runtime knows its recording will not
run: State::fail_part, the one point every such failure releases a part
through. The mark is an AtomicU64 whose low bit is the mark and whose
upper bits count the takes; LevelsCopy::take returns the take's number,
and give_back(number) sets the mark again only where that take is still
the latest and nothing set the mark since (a later take holds its own
copy; a did_modify_data since already asks for one), so giving back twice,
or after a later take, changes nothing. shadow::Takes now holds each take's
number and a weak hold of the texture's copies; every ended encoder's
record keeps its takes (not only one whose log is kept), and a recorded
segment carries its own core's takes, both given back by fail_part.
ShadowSync::forget gives its takes back by number too.

An encoder split into parts at a host step gives back every take of its
own where any of its parts runs nothing, so a take that ran in an earlier
part is taken again at the next use when only a later batch fails; that
gap is in docs/FAST-PATHS.md's known gaps. docs/API.md and shadow.rs state
the rule.

Tests: tests::shadow gains a unit test of the give-back's rules (latest
take, a later take, a mark set since, twice, forget). The device tests of
the previous commit fail without this change; the runs of both commits are
in the report.
2026-11-11 09:41:44 -08:00
Anees Iqbal 63bbaa086d Submission checks: remove the follows check; release idle pointer imports where a held one costs
The device's submission checks ran a "follows" check at every Linux device's creation: they
imported two pages of their own by pointer, submitted a copy, mapped new anonymous pages over
the first page (mmap MAP_FIXED) while that import lived, copied again, and only then freed the
import. That remap under a live host-pointer import is outside VK_EXT_external_memory_host's
contract ("Whether device memory objects imported from a host pointer hold a reference to their
payload is undefined ... the application must ensure that the imported memory range remains
valid and accessible for the lifetime of the imported memory object"), so the verdict rested on
undocumented driver behaviour, and it ran on every device's making.

Its one reader was the idle release of a no-copy buffer's pointer import (host_residency.rs,
Again::pointer). Under HostMemory::new's contract the pages at the pointer stay the same while
the buffer lives, so an import again at the same pointer reads what the kept one read on every
driver: "follows" mattered only for remaps that break the contract. The release is now gated on
what it is for, the per-submission cost of a held import, which the existing import tax check
measures (32 imports of 16 MiB in all held through timed submissions):
- RADV and ANV on i915 pay it: idle pointer imports are released, as before.
- NVIDIA's driver (RTX 5080 Laptop GPU, 615.71.09: 2.1-2.2 us a submission with and without
  held imports) and MoltenVK pay none: pointer imports stay imported, as before on NVIDIA, now
  because a release would save nothing and cost the next blit an import.
- lavapipe, which the follows check answered yes on, is released only where its tax check
  answers Holds.
Buffers made before the check answered keep their imports, as before.

Changes:
- submit_check.rs: the follows check is gone (its remap, its bound buffer, its copy command
  buffer, Check::Follows). A record holds two verdicts; CHECK_VERSION 6 -> 7, so earlier records
  are never read and every driver measures again. The checks' pool no longer resets command
  buffers (only the copy was re-recorded).
- Public API, breaking: Device::pointer_imports_follow_their_address is removed. A hidden lane
  accessor, Device::releases_idle_pointer_imports, says whether the device releases idle pointer
  imports. api_signatures.tsv re-blessed for both. reims-vgpu's no_copy_remap_linux.rs test
  called the removed method (main is telling reims).
- Docs: HOWTO section 6, the FAST-PATHS known gap about remaps (now: what a no-copy buffer reads
  after a remap under it is unspecified; a released import's next blit imports the new pages; the
  RADV file-page loss stays), the RADV per-page cost gap's gate, Device::host_range_remapped,
  host_memory.rs, host_residency.rs, KeptBecause and WorkCounts docs, the validation lane.
- Tests: the pointer residency and unmap-order tests hold the device to the release
  (SubmitChecks::force on the import tax), so the release path runs on every Linux device
  whatever load does to the check; a new test checks the natural gate
  (an_idle_pointer_import_is_released_where_held_imports_cost_submissions), and a new device test
  checks a device's checks make and bind no buffer and free every import by their answer
  (a_device_s_checks_map_no_pages_over_a_live_import: on Linux it fails with the follows check,
  which made and bound two buffers).

RUNTIME_VERSION is not bumped here (bumped and re-pinned at landing).
2026-11-11 09:32:34 -08:00
Anees Iqbal daf963ab80 Docs: on NVIDIA, a device kept to the exit can fault in the driver's own exit handler
What: FAST-PATHS's known gap of NVIDIA exits now names the cause and the measured rates, and
HOWTO (section 8), the runtime README (at the process's exit) and API.md's accepted differences
tell consumers to drop the runtime's devices before the process exits on that driver.
exit_guard.rs and tests/exit_guard.rs, comments only, say that the 5080's fault in
libnvidia-glvkspirv.so also comes with no making in progress.

Why: reims-vgpu's test an_adopted_device_starts_its_in_place_check (device kept in a static,
check waited for to its end, then the test process exits) died with SIGSEGV after "ok" on the
RTX 3090. Reproduced with the runtime alone (a scratch example: device made on a named thread with
an empty shader cache of its own, in-place check started and waited for, device kept, main
returns). Every core shows the same thing: a worker thread of NVIDIA's driver, started from the
thread that made the device and so carrying its name, faulting at libnvidia-glvkspirv.so+0x363a8
(`mov 0x18,%rax; ud2`, a null dereference trap) while the main thread runs libEGL_nvidia.so's exit
handler inside exit(). No runtime thread was in a section or in the driver. reims's two cores
on that node (pids 106291, 170154) faulted on a thread named after the test thread, which libtest
joins before printing "ok", so a thread the driver started.

How verified (RTX 3090, NVIDIA 620.70.06, 8 processes at once, 80 exits each):
- exit right after the check ended, device kept: 6/80 SIGSEGV (potluck m3-max-16257)
- exit 3 s after the check ended: 0/80 (m3-max-16279)
- device dropped before the exit: 0/80 (m3-max-16280)
- no check, exit right after creation / 6 s after: 0/80 each (m3-max-16278, m3-max-16277)
- lavapipe (Mesa 26.2.6), exit right after the check: 0/20 (m3-max-16283)
Vulkan has no call that waits for the driver's worker, and a dropped device leaves none, so
the remedy is the consumer's drop, documented; no runtime behaviour changes.
2026-11-11 09:04:14 -08:00
Anees Iqbal 788f459391 Runtime: count command buffers that wait behind another command queue's work on their VkQueue
On a GPU with one graphics queue (RADV, ANV, lavapipe) every command queue, the unshared ones
included, submits to the same VkQueue in order, so a compositor's command buffer waits behind an
application's long one. Deciding whether to build compositor isolation needs to know how often
that happens in real use, so the runtime now counts it, always on:

- WorkCounts::command_buffers_behind_other_queues: command buffers whose first batch took its
  value on a VkQueue while the latest batch of another command queue's before it there was not
  seen complete;
- ..._over_16ms and ..._over_33ms: those whose wait, from the first batch's submission (or hold
  in a group) to the host's observation of that other batch's completion, ran over 16 or 33 ms
  (an upper bound: the host sees a completion after the GPU's end);
- wait_behind_other_queues_longest_nanos: the longest such wait;
- the same four with an unshared_ prefix for queues made with new_command_queue_unshared.

How (queue_wait.rs): each VkQueue keeps its last batch's value and command queue, the value of its
latest batch of another queue than that one, and the waits being timed, in the order of the value
each waits for, which never falls. The submission side runs under the scheduler's lock where a
batch takes its value (command_buffer/submit.rs); the completion side where the host publishes a
new timeline value (QueueSlot::completed). O(1) per batch and per completion; no command queue of
the device is scanned. The runtime's own submissions (staging, checks, a step's run again) are
not seen.

Test: queue_share_device::a_command_buffer_behind_another_queue_s_long_one_counts_its_wait (two
queues on one VkQueue, a ~30 ms command buffer then a short one: one wait from another queue,
bounded below by the long one's GPU work left and above by the host's time around it; none from
the same queue; the unshared tallies from an unshared queue). The API signatures table is
re-blessed; docs: WorkCounts, the runtime README's unshared queue entry, FAST-PATHS known gap.
2026-11-11 08:53:40 -08:00
Anees Iqbal 395e5c3305 Runtime: a tiled texture's take makes every format's later levels, and its first level is the bytes to the CPU
A tiled texture of more than one level (Buffer::new_tiled_texture) is a copy of the buffer's
bytes taken at use. Two leftovers from that change against what two x86 Macs answer:

1. Its take made the later levels only by the device's blit chain. A format generate_mipmaps
   makes by the compute filter (an extended-range one, an 8-bit sRGB one held as its UNORM twin,
   one without blits or linear filtering) or by the integer picks kept zeros past its first level,
   where Metal makes every level. Now the making keeps generate_mipmaps' own plan of the format
   (shadow::LaterLevels: the blit chain, the compute filter or the picks, announced as that call
   announces them; Kept for a format it leaves or refuses, or a scratch past the device's
   limits). The encoder makes a take's filter or picks run as it plans the copy
   (EncoderCore::later_runs, beside sample_moves: the scratch, the kernels and sets), held by the
   command buffer, and the copy in records it after its copy into the first level, behind a
   barrier, as it records the blit chain: transfers of the image and dispatches over the scratch
   alone, outside any render pass, before the first command that uses the texture. A filter take
   counts in WorkCounts::mipmaps_filtered. mipmap_filter.rs and mipmap_pick.rs split their
   recording into FilterRun and PickRun, which generate_mipmaps and the take share; what
   generate_mipmaps records is unchanged. A run that cannot be made (no room for the scratch)
   fails the command buffer, as a heap texture's sample moves do.

2. Its CPU calls reached every level in the image. On the Macs, getBytes and replaceRegion of
   level 0 address the buffer's bytes, and a replaceRegion there makes the next use take the copy
   again, as didModifyData does. Now level 0 reads and writes the bytes (Texture::level_in_image),
   a write there marks the copy stale, and while the bytes are detached level 0 is refused
   (NotImplemented(DetachedTexelAccess)) as a one-level texture's is. Levels 1 and up stay in the
   image (the GPU reads a replace_region there until the next take), where the Macs' GPU never
   sees such a write: an accepted difference in docs/API.md and the rustdoc. Blits are unchanged.

Tests (tests/tiled_texture_device.rs), each failing before its fix: RGBA8Uint's later levels are
plain Metal's picks exactly after a blit first use, and after a pass into level 1 as the first use
(level 1 cleared over the picks, the rest picked); BGR10XR's later levels are within the compute
filter's bound of the level above, the take counted once in mipmaps_filtered; level 0's get_bytes
reads the bytes before the first use, after a GPU write into level 0 (which the GPU reads) and
after a CPU write of them (which no level sees); a level-0 replace_region writes the bytes (the
rows' padding kept) and the next use takes the copy again, every level made from it. The detached
test now holds level 0 refused while detached and reads the new pages' bytes after a rebind.

Docs: new_tiled_texture's, replace_region's, get_bytes's and did_modify_data's rustdoc,
DetachedTexelAccess, WorkCounts::mipmaps_filtered, shadow.rs's Copies taken at use, the filter and
pick modules, docs/API.md (the tiled texture and an accepted difference), docs/RUNTIME-PORTING.md,
docs/FAST-PATHS.md's known gap narrowed to formats generate_mipmaps leaves or refuses, and
docs/REFUSALS.md regenerated (the MipmapGeneration sites moved). RUNTIME_VERSION and the
runtime-sources pin are left to the landing.

Checked here: cargo fmt. Clippy in three configurations, rustdoc and the device tests run as
cluster jobs on this commit.
2026-11-11 08:37:22 -08:00
Anees Iqbal f36c987934 FAST-PATHS: the RADV plain-making hold's kernel path, what smaller allocations do, and why no block can carry optimal images
The known gap "On RADV, a command buffer submitted while the runtime makes a block of plain
memory waits for that making" now states:
- The kernel path: amdgpu_gem_create_ioctl reserves the VM root for a VM_ALWAYS_VALID object and
  makes it on that reservation; ttm_bo_init_reserved fills its pages before the root is released
  (ttm_bo_validate, ttm_tt_populate, ttm_pool_alloc), a 2 MiB run asked at order 9 with
  __GFP_RETRY_MAYFAIL; every submission and every object made, opened or imported waits on it.
- Smaller allocations move the hold into direct reclaim under the same reservation (runs above a
  page asked with no reclaim), with the measured numbers, and an image of 2 MiB or more takes
  order-9 runs whatever the blocks; many small local objects cost a submission nothing.
- Dedicated, exportable and host-pointer memory cannot carry optimal images: RADV makes a dedicated
  allocation a local object too, requires a dedicated allocation of every external image not in
  linear tiling, and a host pointer's import may not be dedicated (VUID-vkBindImageMemory-memory-02728,
  -02989, -image-01445, VUID-VkMemoryAllocateInfo-pNext-02806); every non-local object is listed in
  each submission (radv_amdgpu_bo.c, unconditionally), and pointer imports cost 24.1 us per 64 MiB.

Why: the scroll investigation closed sub-2 MiB granularity, non-local blocks and host-pointer blocks
as routes around the hold; the ledger now says so where a reader looks.

Verified: tests::reclaim_submit_bench on gem10's Radeon 780M (RADV PHOENIX, Mesa 26.2.6, Linux
7.3.3), release, exclusive, TTM pools drained before each arm (potluck m3-max-16143, arms on
steelbrain/scrollblocks-q3); Mesa statements read from the mesa-26.2.6 tag (radv_device_memory.c,
radv_device.c, radv_formats.c, winsys/amdgpu/radv_amdgpu_bo.c and _cs.c); VUIDs from the Vulkan
1.4.366 specification; the kernel path from linux-stable v7.3.3. Docs only; cargo fmt.
2026-11-11 08:34:57 -08:00
Anees Iqbal 08fcc2375b Docs: the small-heap blocks' and the least queue plan's measured numbers on an RTX 2080 and an RTX 3090
What: the runtime README, the degrade-notice catalogue, FAST-PATHS' memory-blocks bullet and the
rustdoc of pooled_block_bytes, made_within_resources, DeviceRefused and LeastQueuePlan now state
what the after runs measured, and no longer name the BAR as what the driver lacked when it refused
a device: in these runs it was not (BAR1 stayed under 30 of 256 MiB), and the kernel logged a
channel instance-block allocation failure.

Evidence (potluck, NVIDIA 620.70.06, at cad545d601, --cfg m2v_gpu --cfg m2v_gpu_hazards):
- RTX 2080, 256 MiB BAR1 (m3-max-16089, um790):
  - one process, devices kept live: BAR1 5 -> 8, 10, 13, 15, 18, 20, 23 MiB for devices 1-7
    (before, at 239d729627: 5 -> 72, 138, 205, then +2-3 each); pools at open Buffers@1,
    Buffers@4, Images@1 of 64 MiB, none of the BAR type (before: Buffers@5 64 MiB too). The 8th
    device refused with 17 VkQueues and then with the least plan's 2 (DeviceRefused, two attempts).
    Kernel: kchannelAllocMem_GM107 "Instance block allocation ... failed", "Could not create
    Channel", NV_ERR_NO_MEMORY.
  - 16 processes 3 s apart, one device each: p1-p7 made with 16+1 VkQueues (BAR1 5 -> 26),
    p8 and p9 made with the least plan (vk_queues=1, BAR1 -> 28, 29), p10-p16 refused with both
    plans at BAR1 29 of 256 MiB. Before (m3-max-16046): 7 made, p8-p16 refused at BAR1 218.
  - touched device tests 11/11 (small_heap, least_queue_plan both branches' made path,
    queue_limits, the block-size rule); LEAST-QUEUE-PLAN: took 1 + 0 of the plan's 14 + 2.
- RTX 3090 control (m3-max-16085, gem10): one process BAR1 3 -> 6, 8, 11, 13, 16, 18, 21 for
  devices 1-7 (before: 3 -> 70, 136, 203), the 8th refused with both plans; touched tests 11/11.
2026-11-11 08:31:42 -08:00
Anees Iqbal 6e5dc3b087 memory: a small heap's pooled blocks are at most a sixteenth of it, and none is made before a placement needs it
What: a pooled block's size is per memory type now, from its heap (memory::pooled_block_bytes):
64 MiB in every heap of 1 GiB or more, as before, and in a smaller heap the largest power of two
within a sixteenth of it, at least 1 MiB (8 MiB in a 246 MiB heap), never past the largest
allocation. A pool of such a small heap (Memory::small) gets no room kept at creation calls
(keep_room), no block made ahead (memory/ready.rs: makes_ahead and keep_ahead skip it), and the
placement that finds no room makes its block itself. A placement past half of its memory type's
block takes a block of its own. Large heaps behave as before: no first encoding makes a 64 MiB
block it did not make before.

Why: without unified memory the WriteCombined class ranks DEVICE_LOCAL|HOST_VISIBLE first, which
on an NVIDIA GPU without Resizable BAR is the 246 MiB heap of its 256 MiB BAR. keep_room kept room
for half a 64 MiB block in that pool at each device's first command queue, whatever the program
placed there. Measured with tests::many_devices at 655ed906fb (NVIDIA 620.70.06): BAR1 used grew
67 MiB a device for the first three devices (RTX 2080: 5, 72, 138, 205 MiB; RTX 3090 in 16
processes: 3, 70, 137, 204 MiB), and the heap then held no fourth block (later devices' pools
show no block of type 5), 3 MiB a device after that. A consumer saw the kernel refuse later
devices' BAR mappings on the 2080 (vkCreateDevice: VK_ERROR_INITIALIZATION_FAILED).

Tests: tests::memory::a_pooled_block_is_at_most_a_sixteenth_of_a_small_heap (the rule and its
bound over heap sizes; fails at the base, which has no rule); tests::small_heap (every heap made
small by a stand-in: a device's first command queue makes no block and starts no making, and a
write-combined buffer makes its pool's first block, of the heap's block size). Verified on
lavapipe (ms01, cpu_icd, job m3-max-16047): both pass, with the touched modules' 32 tests, and
clippy -D warnings under m2v_cpu_icd is clean. Device evidence before and after on the 2080 and
the 3090 follows with the next commits.

docs/FAST-PATHS.md: the memory blocks' row states the small-heap rule and its cost (about eight
times as many blocks for the same placements there, none made ahead of its need).
2026-11-11 08:31:42 -08:00
Anees Iqbal cecd273a23 FAST-PATHS: the one-graphics-queue gap names the drivers measured to have one, not MoltenVK
MoltenVK's four families of one queue each are not one queue; the round robin
spreads command queues over them.
2026-11-11 08:05:07 -08:00
Anees Iqbal d6901247d8 Known gap: on a one-graphics-queue device a compositor's command buffers wait behind another queue's long one
RADV, ANV and lavapipe expose one graphics VkQueue, so new_command_queue_unshared
shares it with every other queue there. Measured on ms01's Iris Xe (ANV, Mesa
26.2.6, i915) with owned shaders (scratch branch steelbrain/irisfs-preempt): a
16x16 clear on a second VkDevice waited the whole 440 ms of a command buffer of
four 110 ms draws, at equal priority and at MEDIUM against LOW (HIGH refused,
VK_ERROR_NOT_PERMITTED_KHR), with or without 8 bands per draw; with the same
work as 32 submissions it waited p50 13.9 ms, max 14.0 ms. Recorded in
FAST-PATHS's known gaps and scoped in the runtime README.
2026-11-11 08:04:06 -08:00
Anees Iqbal c880d49235 FAST-PATHS: the Asahi kernel keeps a freed dma-buf import past the process's exit
The asahi DRM driver gives an imported GEM object no close callback, so a freed
import stays mapped until a later VM_BIND maps over its range; a VM's teardown
defers the unlinks of what is still mapped and never runs the deferred cleanup,
so those vm_bos (each holding the gpuvm and the GEM object) stay forever. Traced
on the Asahi host with scripts/dma-buf-leak/kernel-holds-gpuvm.bt (52 objects
alive at exit, each a zombie vm_bo never destroyed; every deferred cleanup ran
from an ioctl, none after the teardown's 102 deferred unlinks) and read in the
public kernel source. No documented Vulkan call avoids it; recorded as a known
gap.
2026-11-11 07:59:16 -08:00
Anees Iqbal 8f4a534b01 Runtime: a tiled texture of more than one level is a copy of its bytes taken at use
A mipmapped tiled texture over a buffer (Buffer::new_tiled_texture, more than one level)
read zeros past its first level: its first level was a shadow of the bytes kept in step at
command boundaries and the later levels were never written, so a minified sample of such a
texture drew black. Two x86 Macs (an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under
macOS 26.7.1, measured by the consumer on both SPI forms, Shared and Managed descriptors,
RGBA8Unorm and BGRA8Unorm) take a copy of the bytes at the texture's first GPU use, every
level generated from the first; again at the first use after didModifyData; between those no
CPU write reaches a level, and a GPU write to a level never reaches the bytes or the other
levels.

The texture stays one image of every level (Storage::Shadow), its shadow now a copy taken at
use (ShadowCopies::levels, a LevelsCopy): a stale flag set at the making and by the new
Texture::did_modify_data (Metal's private -[MTLTexture didModifyData]) is taken by the first
command of an encoder that uses any of its levels (its shadow range is every level now), which
records before it the copy of every texel of the first level and the device's blit chain over
the later levels (mipmap_plan's plan, record_blit), as generate_mipmaps makes them, announced
device-filtered-mipmaps. Every other use copies nothing in; nothing is copied back, kept or
merged; a change of the truth never makes it stale; a take whose encoding is left out is given
back. get_bytes and replace_region reach every level in the image; a detach no longer loads
the first level (keep_first_level, keep_first_levels, Writes and TexturesOver::keeping go), as
the image is its own copy. A format the device's blits do not filter has its first level copied
and its later levels left as they are: a FAST-PATHS known gap. The one-level form is unchanged.

Tests (tests/tiled_texture_device.rs, rewritten for the contract): the first use takes bytes
written after the making into every level (a uniform grey, the compositor's shapes and the
probe's 256x256 of 9 levels in both formats); every later level is the 2x2 box of the one
above (a gradient); a first kernel sample at LOD 1 reads the made level (zeros before); a CPU
write after the first use reaches no level and copies nothing; did_modify_data takes the copy
at the next use, not the call (the probe's steps); a blit into level 0 reaches neither the
bytes nor the later levels; a pass into level 1 takes the copy first; detached and rebound
bytes leave every level as taken until did_modify_data.

Docs: new_tiled_texture's and did_modify_data's rustdoc, shadow.rs's Copies taken at use,
docs/API.md, docs/RUNTIME-PORTING.md, docs/FAST-PATHS.md known gaps; the API signature table
blessed (+ Texture::did_modify_data). RUNTIME_VERSION and the runtime-sources pin are left to
the landing.

Checked here: cargo fmt. The device tests, clippy in three configurations and rustdoc run as
cluster jobs on this commit.
2026-11-11 07:11:37 -08:00
Anees Iqbal f345282a06 FAST-PATHS: the NVIDIA dma-buf gap names the 64 MiB chunk the RTX 5080 Laptop imports dedicated to nothing
Measured in b5080 entry hkhostmem-3-hk3-dedicated-064011 (615.71.09):
without_pointer_imports_a_ram_s_chunks_are_its_dma_bufs lists the RAM, imports
its 64 MiB chunk as one dma-buf dedicated to nothing, and its first page
dedicated to its buffer (dma_buf_buffer_imports_dedicated 1). Docs only.
2026-11-11 06:56:33 -08:00
Anees Iqbal a41f025ebd Runtime: a dma-buf import that backs one buffer alone is retried dedicated to it
NVIDIA's 615.71.09 (RTX 5080 Laptop) refuses an import of a small udmabuf
dedicated to nothing (ERROR_OUT_OF_DEVICE_MEMORY: one 4 KiB page refused,
64 KiB taken, measured by a probe) and takes the same page dedicated to its
buffer. Two device tests failed there: a guest RAM's use asked the driver
with its first page, the refusal was remembered for the device's life, and
every chunk was then copied; a no-copy buffer's 16 KiB window was copied.

- memory.rs: import_dma_buf takes what the memory backs (DmaBufFor): an
  image (dedicated to it), shared memory (dedicated to nothing), or one
  buffer alone for its life, tried dedicated to nothing in every type and,
  where the driver refuses each, dedicated to the buffer in every type.
  That is Vulkan's documented form for one buffer's memory; no driver name
  or size rule decides it.
- dma_buf.rs: chunks_buffer/import_chunks pass the buffer where the caller
  binds nothing else in the import and the buffer is not sparse: a no-copy
  buffer's own import (never a heap's), its residency re-import, a copy's
  list of a RAM's runs, and the page a RAM's use asks the driver with. A
  RAM's chunk or run is never dedicated: its objects' buffers bind in it.
- A RAM's dma-buf refusal is remembered only where it lasts
  (not_importable: the driver refuses the dma-buf itself, or no type takes
  it); memory that ran out is that import's alone.
- WorkCounts::dma_buf_buffer_imports_dedicated counts the dedicated retries.
- Tests: two stand-in driven device tests (a no-copy page refused
  undedicated takes a dedicated import; a RAM's page is asked dedicated and
  the RAM listed while chunk refusals for want of memory are not
  remembered); the three remembered-refusal tests use the lasting
  ERROR_INVALID_EXTERNAL_HANDLE; the two NVIDIA-failing tests print the
  dedicated count.
- Docs: FAST-PATHS's NVIDIA dma-buf gap, HOWTO, the counters' docs.

Verification: in the following jobs (3090, 5080, PHOENIX, clippy x3).
2026-11-11 06:56:33 -08:00
Anees Iqbal 22749e28d6 FAST-PATHS: the RADV plain-making hold's cause, size and why no allocation avoids it
What: the known gap "On RADV, a command buffer submitted while the runtime makes a block of
plain memory waits for that making" now states the hold's cause and size, and why the runtime
has no allocation route around it.
- Cause: the kernel fills a plain block's pages in runs of up to 4 MiB, and a 2 MiB run (the
  order amdgpu names beneficial) may reclaim and compact until it succeeds or fails, under the
  reservation every submission of the process takes (Linux 7.3.3 ttm_pool.c, amdgpu_gem.c's
  VM_ALWAYS_VALID create path).
- Size: beside a consumer's guest scroll on a Radeon 780M short of free memory, one making held
  the submissions 228 ms, 222 ms of it one compaction for one 2 MiB run; so no block size of
  2 MiB or more bounds the hold below one run's.
- No route: RADV (Mesa 26.2.6) makes every memory neither exported nor imported a local buffer
  object (radv_device_memory.c PREFER_LOCAL_BO -> VM_ALWAYS_VALID), and asks a dedicated
  allocation of every image made for an external handle type in other than linear tiling
  (radv_device.c), so blocks of optimal images or of the DRM_FORMAT_MOD_LINEAR images over
  padding-unobserved buffers can be neither exportable nor imported pages; a dedicated
  exportable allocation per image puts each in RADV's global BO list, which every submission
  names (about 1 us each); and Vulkan reports neither the carve-out's size nor its room.

Why: the consumer's 780M scroll traces (host ftrace + perf compaction events) put every long
submission wait on a block making's order-9 compaction under the VM root reservation; the
ledger said the making holds submissions but not how long, nor why no other allocation helps.

Verified: the 228/222 ms figures parsed from the traces' compaction events per making thread;
the kernel and Mesa statements read from linux-stable v7.3.3 and the mesa-26.2.6 tag; the
carve-out sizes read from sysfs on two 780M hosts (2 GiB full, 4 GiB). Docs only; cargo fmt.
2026-11-11 05:59:14 -08:00
Anees Iqbal 0e4d2c225c Conformance: read_through and two footprint cases name the shared-memory notice the XTX announces
The round's replay on the RX 7900 XTX (RADV NAVI31, at 6898863f3f) read 15 cases divergent at the
notices site alone (case/notices, and for three of them case/notices/set and case/notices/counts),
unlisted: the runtime announced `shared-in-system-memory`, which none of them declared.

The placement is the runtime's rule, not a shortage of room: without unified memory a `Shared`
buffer prefers a host-cached memory type, then a device-local one (memory.rs `candidates`), because
the host reads uncached memory, resizable BAR included, slowly, and a discrete Mac's GPU reads a
shared resource across the bus the same way. So the notice is the venue's memory model and never a
wrong answer, and the suite's declaration for it is `replay::shared_memory_notice`, which every
other case that reads back through a `Shared` buffer carries. It loosens the notices site alone.

- read_through: all 13 cases bind their positions and output in `Shared` buffers; each declares it.
- format_footprints: one-plane-ycbcr and padded-wide-channels set `shared_texture_buffers`. The
  runtime now makes their formats' `Shared` texture buffers, as Metal does (the recordings hold
  `makes-texture` Ok for them, and the XTX run matches), which was not so when the 5080's replay
  measured only the plain stragglers announcing it.
- docs/FAST-PATHS.md: the replay paragraph no longer says a card without unified memory makes the
  comparison unreadable; it says how the cases declare the notice.

Verified by the XTX replay of this tip (job ids in the report).
2026-11-11 04:10:13 -08:00
Anees Iqbal 22a96f62d4 Docs: framebuffer fetch between draws, its note, REFUSALS and the API signatures
docs/API.md's framebuffer-fetch paragraph says what a device with neither
ordered form does, and the degrade-notice catalogue gains
unordered-fetch-within-draw. docs/FAST-PATHS.md's device-gap table gains its
row. docs/REFUSALS.md regenerated (FramebufferFetch loses the
unsupported_features and family-row sites). api_signatures.tsv blessed: the
PrecisionNote and Degradation variants and WorkCounts::fetch_draw_barriers.

Verified: refusal_surface.py (0 without reach mark or basis), signatures.py
--bless (3 added).
2026-11-11 04:01:35 -08:00
Anees Iqbal e831b50ad6 FAST-PATHS: drop the 64 MiB image blocks' scroll claim the confirming block overturned
653060d6ee's row said 64 MiB image blocks matched the build before the 68 MiB
ones in a macOS guest's page scroll on a Hawk Point 780M, from reims's first
block (4 + 4 boots). Its mirrored second block (m3-max-14080) overturns that:
pooled over 8 + 8 boots, pin 36 with 64 MiB image blocks has 14 rAF gaps of
100 ms or more against pin 30's 8, with twice the ready thread's direct
compaction for the same block count. The row now says what the size choice is
and costs, and no scroll figure; the scroll regression is open and worked
apart. Docs only.
2026-11-11 01:43:37 -08:00
Anees Iqbal 399e8d6d17 Runtime: a host-transfer image takes its class's own memory types, never overflow ones
What: Memory::host_image_types (now the pure memory::host_image_types, with
class_types beside it) returns the types of the image's class among those allowed,
in both of its branches, instead of every allowed type. A `Shared` or `Managed`
texture's image with host-transfer usage so never overflows into system memory: where
none of its class's types has room, its placement fails and host_placed_image makes the
image without the usage, which lies in device-local memory where that image has room
(and overflows only where none has, as any image does). The unused Memory delegates
host_cached_placement and host_incoherent go. Texture::placed_type and
Memory::type_and_heap are test-only accessors for the new device test.

Why: the RTX 3090 lanes (validation runtime_lane, round at 7d7085f9d0, gem10 and
um870) announced device-memory-overflow for `Shared` Depth32Float textures in six
tests. Those 3090s run without resizable BAR (NVIDIA 620.70.06, vulkaninfo on gem10:
heap 2, DEVICE_LOCAL, 246 MiB; nvidia-smi BAR1 total 256 MiB), and NVIDIA places a
host-transfer image in that BAR heap alone (type 5, its one device-local type for it),
beside system types 3 and 4. With 16 lane tests at once, each device's 68 MiB block of
such images fills the shared 246 MiB heap; the next process's depth texture then
overflowed into types 3/4 while heap 0 (24 GiB, type 1, which the image without the
usage takes) had room. Color textures there copy on the staging queue and take no
host-transfer usage, which is why only depth textures overflowed.

Tests: tests::memory::host_transfer_images_take_no_type_their_class_overflows_into
(pure; on the 3090's memory types the image takes type 5 alone, where the old answer
3..5 overflowed into [3, 4]); tests::host_image_room (device: on a GPU whose
host-transfer heap is at most 1 GiB, fills it with 16 MiB Shared Depth32Float
textures, none may overflow, all lie device-local, CPU copies round-trip). Docs:
host_copy.rs module docs, the FAST-PATHS device-gap row for the copies' submissions.
Builds, clippy and the 3090 runs go to potluck after this commit.
2026-11-11 01:33:24 -08:00
Anees Iqbal 653060d6ee Memory: a pool of images' blocks are 64 MiB, as every pool's
930e3aa49e made a pooled block of images a sixteenth larger than every other
pool's (68 MiB, IMAGE_BLOCK_SLACK), so that four images of a quarter block
fit in one past the driver's metadata. On the consumer's 780M scroll gate
those blocks were pin 36's regression against pin 30. Pin 36 with images'
blocks at BLOCK_BYTES (probe e674b9c87d) matched pin 30 over 4 + 4 boots in
ABBA BAAB order (um870 Hawk Point 780M, x86 macOS 12.7.6 guest, page scroll,
job m3-max-13952): rAF gaps of 100 ms or more 8 against 8, of 50 ms or more
22 against 24, presents 29.0/s against 29.3/s; its ready thread made 72 blocks
of 64 MiB a boot and none of 68 MiB.

Every pooled block is now Memory::block_bytes: IMAGE_BLOCK_SLACK,
Memory::image_block_bytes, BlockMaker::image_block_bytes and the two
pooled_bytes lookups that existed only to tell images apart go; their callers
read block_bytes.

tests::blocks_ahead: the packing test now holds that a pool of images' blocks
are BLOCK_BYTES (fails at 68 MiB) and that textures pack as many to a block
as the driver's own placed bytes and alignment fit (three 2048x2048 RGBA8 on
RADV and ANV, four on lavapipe), instead of four to a block.

docs/FAST-PATHS.md: the NVIDIA, blocks-ahead and RADV plain-blocks rows say
64 MiB for images too, with the scroll A/B above.

Owed on development: RUNTIME_VERSION and the pin (block sizes change what a
run allocates), and the cost records of the two cases whose
device_memory_allocated read 71303168 (shared-creator-extended-range-samples,
shared-creator-padded-format-storage) at the next whole-set re-bless.
2026-11-11 01:16:55 -08:00
Anees Iqbal 6ead79e1bb Runtime: make plain blocks by their own allocation alone, no exportable fill first
What: remove "Blocks filled exportable first". The device computes no fill types;
Memory::fill_plain_blocks and its state, Fills, the FILL_* constants, the fill branch of
BlockMaker::make_as and BlockMaker::fill_first, Block::filled and Fill go, with the
public counters WorkCounts::plain_block_fills_saved, plain_block_fills_missed and
plain_block_fills_skipped (api_signatures.tsv re-blessed), tests::block_fills, the Fills
unit test, the fill parts of memory/making_parts.rs and the reclaim bench's unfilled arms
and fill printouts. DriverFact::PlainAllocationsHoldSubmissions stays as a measured fact;
its docs say the runtime makes such blocks by their own allocation on every driver.
docs/FAST-PATHS.md drops the fill's row; the plain-makings-hold-submissions known gap says
the runtime does not fill first and why.

Why: on the Radeon 780M most fills miss under memory pressure (saved/missed per scroll
1/7, 7/20, 2/7, 2/8), so the kernel compacts order-9 pages for both the fill and the
block. The consumer's scroll gate traces: all 11 rAF gaps of 100 ms or more overlap one
ready-thread direct-compaction episode of 46-164 ms inside one block making; on pin 35, 6
of 9 gaps sit in a fill making (68M+68M makes, 134-162 ms of compaction), most of it
between the fill's free and the block's create. Their no-fill A/B (fill_plain_blocks(0)):
0 gaps of 100 ms or more, against pin 30's 6 and pin 33's 11.

Verified here: scripts/api-signatures/signatures.py --check passes after --bless (only the
three counters left the table); refusal_surface.py regenerated docs/REFUSALS.md unchanged;
cargo fmt --all. Builds, clippy, rustdoc and the runtime's memory tests run on potluck
after this commit.

(cherry picked from commit c11bf907bced149e81301c6319d3fab1d615061c)
2026-11-10 05:49:16 -08:00
Anees Iqbal 84db1b3675 FAST-PATHS: the ANV binding-table pool gap with the passes inline and the barriers bounded
The known gap now counts command buffers begun (barrier command buffers took blocks too), names
the passes that still take a secondary, the 2,048 planned barrier command buffers a batch begins
at most, and what ms01's Iris Xe (Mesa 26.2.6) measured: 10,000 passes beside a cleared depth in
one command buffer run in 12,049 command buffers (tests::many_passes); passes inline encode to
16,173; passes with a secondary fail at the end of the 8,087th; with the targets' first clears in
the submission 14,000 passes ran and 14,300 crashed in the driver, recorded as the open part.

Verified: the numbers are the probe runs' (jobs m3-max-13726, -13731, -13643).
(cherry picked from commit 67f1d8710d78adf21768002c82a86e739721e271)
2026-11-10 05:25:14 -08:00
Anees Iqbal f0b1976e58 Queue sharing: a command buffer whose VkQueue waits on the GPU for another's work counts that wait in its long mark
The Adaptive long mark read a command buffer's own GPU timestamps alone. A batch that waits on the
GPU for another VkQueue's work (an MTLEvent's signal pending there, the tracker's wait for another
VkQueue's writes, new resources' first work there) writes its start timestamp only once that wait
is met, so a queue of short command buffers, each waiting for another queue's 30 ms one, never went
long: it kept sharing its VkQueue, and every command buffer the queues sharing it committed behind
each wait waited for the other queue's whole long command buffer.

Now submit_batch notes, at the first batch whose VkQueue it hands such a wait (an event wait whose
signal is pending on another VkQueue or is the caller's, EventTimeline::waits_across; a tracker or
first-work wait on another VkQueue), the host time its submission was called (Times::waited_across).
place_gpu_times marks the queue long also where more than LONG_HEAD ran from then to the command
buffer's GPU end, placed in the host's time. A command buffer with no such wait is timed as before,
by its own timestamps, so the host-view false marks the module docs describe stay out.

The device test a_compositor_beside_a_queue_waiting_on_the_gpu_for_long_work_keeps_its_latency now
also asserts that the waiting queue goes long (WorkCounts::queues_gone_long >= 2). The QueueSharing
notice's cost, docs/API.md's catalogue entry and the FAST-PATHS row name the wait.

Verified: cargo fmt; unit test a_wait_crosses_queues_where_its_signal_is_pending_on_another; the
build, clippy and the 5080 device run are dispatched.

(cherry picked from commit 6391625634472fb158b6477dfad36340956ae2dd)
2026-11-10 05:16:05 -08:00
Anees Iqbal 24025b3866 Argument-buffer textures read through a sampler: border texels from the handle-table entry
What: a Metal 4.1 read(sampler, ...) of a texture held in an argument buffer now hands back
Metal's border texel of the resident texture, its pixel format's through its swizzle, for every
sampler: a constexpr one of any border colour, a runtime [[sampler(n)]] and an argument buffer's
sampler (the colour from the sampler's word).
- The binder writes each texture's border texels (metal::sampler::border_texels of its format
  and swizzle, the layout of a slot's BorderTexels specialization) in its handle-table entry's
  flags, bits 3 to 14 (memory::handles::FLAG_BORDER_TEXELS); handle_entry_flags carries them, so
  a consumer's own table of every ID gets them too.
- A module with such a read searches the table in a new indexed form (Lookup::Indexed): the
  handle is the element with the found entry's index in its top 16 bits (HANDLE_ENTRY). The read
  loads the entry's border texels by it (handles::border_texels); every use that reads another of
  the entry's flags (texel class, red-blue order, out-of-bounds alpha) loads them from the entry
  into the flagged handle's layout (handles::flagged_handle), through one typed value
  (texture::emit::HeapFlags) so no reader sees the entry index in those bits.
- through::finish selects the border texel for slots and heap elements alike; a heap member read
  by its raw texels (an extended-range form) takes its border and its zero past the level or
  layer from its own image's addressing inside the raw arm, not the float array's neutral's.
- The old heap path, which selected the out-of-bounds texel (transparent black, unswizzled) and
  refused every other border colour and runtime sampler NotImplemented(ArgumentBufferTextures),
  is gone, with ReadSampler::transparent and the forced alpha flag of such reads.

Why: the M3 runs all three (conformance cases read-through-heap-border, read-through-heap-sampler,
and read-through-rgba8-swizzled's rt_heap_zero, where (G, R, 1, 0) reads (0, 0, 1, 0) past the
edge and we read (0, 0, 0, 0)). A 32-bit heap handle had no room for 12 border bits beside the
element, class, red-blue and alpha fields; the entry does (bits 3 to 14 were unused).

SEMANTICS_VERSION 2017 (translation output changes). ARTIFACT_FORMAT_VERSION unchanged: no
encoded type changed. RUNTIME (for the orchestrator's bump): the runtime's handle tables
(heap_sets.rs, through bind::handle_entry_flags) now carry the border-texel bits.

Ledger: the three rows of these gaps go; llvmpipe's rt_heap_zero row of the swizzled case keeps
only llvmpipe's 8-bit unorm conversion. FAST-PATHS known gap removed; REFUSALS.md,
CONFORMANCE-COVERAGE.md regenerated (METAL-COVERAGE.md unchanged).

Verified: not yet built (next: Linux build, clippy and the touched tests).
(cherry picked from commit bc000fa475e572131248b908541dbe29f1f5996c)
2026-11-10 04:45:05 -08:00
Anees Iqbal 2c31428f3c Measure a texture's first CPU copies after a runtime suspend; the known gap is the device's resume
The XTX's first get_bytes after the GPU idled into runtime suspend took 4.7 to
5.2 s. A run decides whose that is: any first submission after the suspend
pays it, so it is the kernel's resume of the device, not our staging queue.

tests::cpu_copy_times gains an ignored measurement, run by name: per size
(1920 x 1080 in a pooled block, 4096 x 4096 in a block of its own) it makes a
Shared BGRA8Unorm texture, copies it awake once, then for three sequences,
each twice, waits for the PCI function's power/runtime_status to read
suspended and times each step: replace_region then get_bytes; get_bytes then
replace_region; a fill command buffer on the program's queue (commit timed
apart from its wait) then both copies. It prints the status after each step
and the staging submissions made.

Evidence, RX 7900 XTX on gem10 (Mesa 26.2.6, autosuspend delay 5000 ms),
job m3-max-13545, two runs, 24 suspends:
- the program queue's command buffer: commit 0.12 to 0.52 ms, its wait 4.83
  to 4.86 s;
- the staging queue: replace_region returned in its awake time (0.48 to 12.74
  ms at 1080p, 5.02 to 5.58 ms at 4096^2) with the device still suspended,
  and the get_bytes after it, the first staging submission, took 4.73 to
  4.79 s; get_bytes first took 4.76 to 4.88 s;
- after the command buffer woke the device, get_bytes took 3.2 to 4.0 ms
  (1080p) and 18.7 to 20.8 ms (4096^2).
The kernel's log of the run's last resume: SMU resumed at :09, "Wait for DMUB
auto-load failed" at :10, 16 "DMCUB error" lines to :13, "Cannot find any crtc
or sizes", then the rings: the card has no display attached.

Paying it ahead off the caller's path: a commit already hands its batches to
the scheduler thread and returns in under a millisecond, so only a wait or a
synchronous read waits. A wake started when a replace_region queues its copy
would win only the time between that call and the next submission (none in
the measured sequences) against a 4.8 s resume, and the program's queue and
the staging queue pay alike, so no queue choice avoids it. A keep-alive is
out. No runtime change.

docs/FAST-PATHS.md's known gap is rewritten with these numbers; its 86 ms
and 73 ms first replace_region of the host path no longer apply on the XTX,
whose Shared textures copy on the staging queue (replace_region now
returns in its awake time after a suspend).

(cherry picked from commit 112b405a9167666407ae15cd08b7bdf76d09d038)
2026-11-10 03:33:55 -08:00
Anees Iqbal af1dd85b66 Blend-source notes state their bound and the device compiler's regrouping; padded rows on the 5080 and the Iris Xe
ExtendedRangeBlendSource and ExtendedRangeFloatBlendSource (their docs, the API
catalogue entries and the FAST-PATHS device-gap row) now say what the suite
measured: the device's compiler may contract and regroup the in-shader blend
(MoltenVK on the M3 Max and NVIDIA's driver on the RTX 5080 compute
S·F + D·(1 - F) as D + F·(S - D)); a stored channel lands within two codes of
Metal's on a linear format and within six near zero on an sRGB twin; and where
the compiler regroups a padded format's blend, an infinite second source stores
an end code where Metal's sum is NaN, stored as 0. The FAST-PATHS row names the
padded formats, which it lacked, and no longer says 'not measured'.

known-gaps.tsv: the 168 extended-range rows (xr-blend, xr-gamut, xr-gradient,
xr-masked) whose Open item was the blend notes' documentation are closed (Open:
nothing, the recorded bound covering the difference); every one is within the
bound (survey of the rows' largest differences). The padded-blend rows are
regenerated for five venues: the M3 Max, RADV PHOENIX and llvmpipe as before,
and the RTX 5080 (b5080 entry xrblend2-padded-replay-5080) and the Iris Xe
(job m3-max-13386), 17 each. The 5080's second-source cases differ by the whole
code range as the M3's do, and its counts are exactly a model of
D + a·(S - D) over an unnarrowed float destination (971 on R10Unorm_X6, 1850 on
RG10Unorm_X12); the Iris's are exactly the sum as written over the half
destination (844, 1607), as RADV's; llvmpipe's the sum as written over a float
destination (962, 1831). No venue's largest difference exceeds the M3's, the
780M's or llvmpipe's.

engine_padded_blends: a fetch of a padded attachment makes the whole pipeline
on every committed profile that orders fetch (storage form or input
attachment) and names the device gap elsewhere; a bfloat fetch stays
NotImplemented(Format), the negative control. Not yet run.

(cherry picked from commit c923b6d49c36c8354f375f6dababfd5f81f1ffbc)
(cherry picked from commit e3a2b226d7f5938811d1d251172088baf05c15cb)
(cherry picked from commit 85a2473cc6ea6a2c9165e2614d1e87ca77c1627e)
2026-11-10 02:59:18 -08:00
Anees Iqbal 962aa365dd FAST-PATHS: the fill decision's evidence on um870 and gem10
The fill row gains the decision's measurements: the images arm of
tests::reclaim_submit_bench, two runs each of the base (every block filled),
the decision (cf5561bb5d) and the arm with no fill, interleaved, the TTM
page pools emptied through the shrinker's debugfs before each arm and before
its pressed phase.

um870 (RADV, Mesa 26.2.6, Linux 7.3.1-1-cachyos), pressed, base / decision /
no fill: turnarounds of 8 ms or more 19 and 4 / 5 and 11 / 11 and 17, of
17 ms or more 1 and 1 / 1 and 2 / 8 and 9; the ready thread's makings 419
and 461 / 379 and 343 / 494 and 292 ms, in compaction 269 and 299 / 215 and
203 / 374 and 179 ms; block-sized buffer objects 2.0 / 2.0 and 1.5 / 1.0 a
making. Quiet: the decision filled every block (1 miss alone in 26) with no
turnaround of 8 ms or more; no fill had 12 a run. gem10 (quiet in both
phases): the decision made no block plain, no turnaround of 8 ms or more.

Also: the misses' free times (17 of 18 quiet misses freed in 0.06 to
0.20 ms, the pages left to the kernel's deferred delete; 44 of 47 pressed
ones in 2.7 ms or more), the fill's CPU shares (91 to 99% and 85 to 100%),
the page-table buffer objects a fill's mapping adds, and the block_fills
misses as now measured (0 or 1 of 5).

(cherry picked from commit 58bff1328f25ca7f96f4c82bab23d46ff5a40b1b)
2026-11-10 02:11:07 -08:00
Anees Iqbal 15c596f09a Memory: a device stops its fills once 3 of its last 4 missed
On gem10's 780M, quiet (12 GiB of free memory left beside the bench), a
tip of 2 of the last 4 stopped once: two fills in a row whose frees
returned in 0.14 and 0.17 ms, the pages left to the kernel's deferred
delete, each block then filling its own (8.0 and 10.9 ms); the 2 plain
makings that followed held the submissions 10.0 ms. Of the misses the
benches' quiet phases saw on um870 and gem10, 14 of 15 had such a fast
free; of those under um870's pressed phase, 30 of 33 freed in 2.7 ms or
more, in runs of up to 6.

Replayed over the always-filling base's phases, stopping at 3 of the last 4
fills 6 to 8 of 12 under um870's pressure (2 of 4: 5 to 7) and none on a
quiet host.

Verified so far: the CPU test is rewritten for the threshold; its run and
the device evidence follow.

(cherry picked from commit cf5561bb5d95b659debfeeedc3454188cda701b3)
2026-11-10 02:11:07 -08:00
Anees Iqbal 09e4afdba6 Memory: a device stops its fills once 2 of its last 4 missed, not after a lone miss
On um870's 780M (pools emptied before each arm and again before its
pressed phase), a quiet phase's fills missed alone: 1 of 13 and 1 of 5 in
the always-filling base, each the fill's free returning in 0.06 to 0.15 ms
where a free that hands its pages to the kernel's pool takes 2.7 to 3.5 ms,
so that the block's allocation ran before the pages were back. Backing off
after each such miss (837c461b2b) made the next 2 makings plain on the
quiet host, each holding the submissions 9.0 to 9.6 ms: 3 turnarounds of
8 ms or more in a quiet phase where the base had none.

Now a device keeps the outcomes of its last 4 fills (FILL_RECENT) and
stops filling once 2 of them missed (FILL_STOP_MISSES); the backoff after
that is as before (2, doubling with each missed probe up to 32), and a
probe that saves clears the record. Misses under pressure come together
(the same base, pressed: 8 of 12 and 3 of 12, runs of up to 5).

Verified so far: the rule's CPU test is rewritten for it
(tests::memory::fills_stop_once_two_of_the_last_four_miss_and_a_saved_probe_brings_them_back);
its run and the device evidence follow.

(cherry picked from commit bc3338dee50f9627b799cf68c747bef1b36a4672)
2026-11-10 02:11:07 -08:00
Anees Iqbal 261af18a27 Memory: after a fill misses, a device makes its next plain blocks plain, probing with backoff
The fill rule of 6da2c8c1dc kept a device filling while each fill spared
its block's allocation half its time, so on a host short of free memory it
kept making a second block-sized allocation for each block, the kernel
compacting and reclaiming for both: the consumer's scroll on um870's 780M
(pin 33) waited longer on host compaction than pin 30 did, with no fill.

Now a fill that missed (its block's own allocation took 1 ms or more,
FILL_SAVED_BELOW, as WorkCounts::plain_block_fills_missed counts) leaves the
next 2 makings plain, then fills one, a probe; each further miss in a row
doubles the plain makings between probes, up to 32; a probe that saves
brings filling back for every making (Fills, FILL_BACKOFF_FIRST,
FILL_BACKOFF_MOST). The module docs, the skipped count's docs and the
ledger row say the rule.

Verified so far: tests::memory::fills_back_off_after_a_miss_and_a_saved_probe_brings_them_back
is the rule's CPU test (not yet run: the build is next). Device evidence
follows in a later commit.

(cherry picked from commit 837c461b2b1aa716622237afc48870307282dbf8)
2026-11-10 02:11:07 -08:00
Anees Iqbal 34310d93f7 Reads through a sampler: a texture buffer's border by its t axis, the ledger rows
The read_through conformance family's per-axis states, recorded on the M3 Max,
show a texture buffer's index past its end addressed as the first texel of a
row past its one row: the border texel where t's mode is a border mode, else
texel 0, whatever s and r are; a runtime sampler whose s mode is
clamp_to_edge clamps it first (s-border reads texel 0, st-border the border,
tr-border clamps). The read took s's mode, which read the border for s-border,
sr-border, s-zero and three mixed states. The border now follows t, and never
applies where the sampler clamps.

The retaken buffer recording; known-gaps rows for the argument-buffer
texture's swizzled transparent border (divergent) and its opaque-border and
runtime-sampler reads (refused), with the swizzle gap in FAST-PATHS.md's known
gaps; the module docs say both.

Verified: the replay on the M3 through MoltenVK (job m3-max-13263) named the
six buffer divergences this fixes; the fix's replay is next.

(cherry picked from commit 22c6817d4074c1b18bbc7c6d166370fe9990c1a5)
2026-11-10 01:30:11 -08:00
Anees Iqbal dbad32bb7b Docs: visibility venues, Metal's subnormal sample coordinates, a shared event's queue rule
Three corrections, each checked against the tree:

- runtime/src/visibility.rs said Metal's visibility-result behaviour was
  measured on an M4, which is not one of our venues. The conformance
  suite's visibility cases record Metal's answers on an Apple M3 Max with
  macOS 27.0.1 (recordings/visibility-*.json); the doc now names that venue.
  The 5300M and UHD 630 answers it cites beside it are unchanged.

- docs/FAST-PATHS.md's DeviceSampling row (and docs/API.md's device-sampling
  entry) said Metal reads any subnormal coordinate as the zero of its sign
  before addressing. That holds for a normalized coordinate (measured on the
  M3 Max on R32Float, PrecisionNote::DeviceSampling's documentation); a
  negative subnormal pixel coordinate addresses texel -1, as the M3 Max's
  recording of pixel-samplers-subnormal-border answers (the border at
  -2^-149, -2^-140 and -2^-127, known-gaps.tsv). Both now say so, and the 27
  known-gaps.tsv rows that quoted the old reading quote the new one.

- SharedEvent::reserve_vk_signal's Safety text lacked the same-VkQueue rule
  that Event::reserve_vk_signal states. A shared event's command-buffer waits
  are held on the host (event_timeline.rs: a settable timeline never hands
  a wait to Vulkan), but a command buffer that signals the event after the
  reservation waits on its VkQueue for the reserved index before its own
  signal (EventTimeline::signal's `after`, the order wait in
  command_buffer/submit.rs), so the caller's signalling submission must not
  go behind it on one VkQueue, and a texture copy on the first VkQueue behind
  it waits for the signal too. The rule is now stated, scoped to those
  signalling command buffers.

Verified: rustdoc and the runtime's degradation_catalogue test over the
edited text; no behaviour changes.

(cherry picked from commit 12bac3fafd3d3e66dc0b88d01231dd30e2694ffb)
2026-11-09 23:49:33 -08:00
Anees Iqbal 05a31354c1 Spares: hold at most 4,096 command buffers, the pools out of them counted
A command buffer keeps what its recording took of the driver's device-wide pools until it is
begun again, reset or freed, and the spare command pools kept each pool's peak over its recent
uses with no bound across pools. On ANV below Xe-HP each command buffer that records a binding
table takes a 64 KiB block of the device's 1 GiB binding-table pool, so a device holds at most
16,384 of them, and the next recording fails with VK_ERROR_OUT_OF_DEVICE_MEMORY with no driver
message. tests::linear_runs::checked_frames_merge_once failed so on ms01's Iris Xe (6 of 79 runs
beside the runtime suite, job m3-max-13027): its frames of 707 and 1,413 render passes, each a
command buffer whose pool kept its peak, left the spares holding 9,716 to 9,771 command buffers
in every failed run (2,786 to 7,747 in sampled passing runs) before the frame that failed. A
probe on the same Iris Xe (job m3-max-13053, twice): one command buffer of render passes, each
a primary and a secondary beside a cleared depth target, failed at the end of its 8,087th pass
with the spares holding 424, 2 x 8,086 + 212 = 16,384.

A give-back now counts the spares, the pool given back, and what each pool out of the spares
held as it went out (taken by a command buffer, out for frees, or beginning a primary ahead:
CommandPools::out, kept under the spares' lock). Past HELD (4,096) the oldest spares that hold
any shed all their command buffers on the free thread as an idle spare does and go back as the
oldest; where that is not enough, the pool given back frees its last made past the bound, a
secondary kept, never the primary begun ahead (past_held, CommandPool::past). On ANV the frees
do not trim, as before, so kept barriers stay valid. HELD leaves three quarters of the binding-
table pool to the command buffers committed and in recording.

Tests: tests::spares::the_spares_and_a_pool_given_back_hold_at_most_held_command_buffers (the
policy, no device) and tests::spares::device::
command_buffers_alive_at_once_leave_the_spares_holding_at_most_held (three command buffers of
2,112 blit encoders alive at once, each in a pool of its own). docs/FAST-PATHS.md records the
remaining ceiling: one command buffer of about 8,000 such passes still fails on ANV below Xe-HP.

Verification follows in the next commits' messages and the report: build and clippy, the
spares tests on lavapipe, the M3 and the Iris Xe with a negative control, and a loaded Iris run.

(cherry picked from commit 8ab6915d698cdaf29e2aa8bfd50c77cd8922d507)
2026-11-09 23:18:09 -08:00
Anees Iqbal c120cdf105 Docs: the fill misses often, not mostly, in a process that submits nothing
tests::block_fills on the Radeon 780M (RADV PHOENIX, Mesa 26.2.6) missed 4 of its 5 fills in job
12841 and 2 of 5 in job 12891 (at the rebased tree of this branch); the fill row said "mostly"
from the first run alone. Documentation only.

(cherry picked from commit caa2b45263277b2696184602298e329291c8b5dd)
2026-11-09 20:49:31 -08:00
Anees Iqbal ee0b8af622 Docs: the fill row's fragmented phases at 68 MiB blocks of images, 0 to 4 and 0 to 2
The row said a fragmented phase had 1 to 4 turnarounds of 8 ms or more and 1 or 2 missed fills;
job 12852's second run of the bursts arm had neither (0 and 0), so the ranges are 0 to 4 and 0 to
2. Documentation only.

(cherry picked from commit e20985fc7ff241c40edcd55b3c21506b715bb899)
2026-11-09 20:49:31 -08:00
Anees Iqbal 6f4f45f1a8 Docs: the fill with 68 MiB blocks of images, measured; its misses where nothing is submitted
The fill row's numbers were of 64 MiB blocks of images. With the 68 MiB ones made now, on the
Radeon 780M (RADV PHOENIX, Mesa 26.2.6), the kernel's page pools drained before each run, the
reclaim bench's arms (jobs 12852, two runs, and 12860, one run with the fill-window print): a
quiet phase 0 or 1 turnarounds of 8 ms or more, no fill missed, the makings' vkAllocateMemory
1.2 to 2.0 ms in all; a fragmented phase 1 to 4 (the slowest 33.1 ms, behind a missed block
whose allocation took 29.4 ms), 1 or 2 of its 12 or 13 fills missed. Of the 957 submissions
begun while a fill ran (12860), 1 turned around in 8 ms or more (14.0 ms, fragmented); in 12852
a 24.0 ms one began within a 32 ms fill on the fragmented host. The row also says that in a
process that submits nothing the fill mostly misses (tests::block_fills on the 780M, job 12841:
of 5 fills, 1 saved and 4 missed), the cause not measured, and the fill's cost for a 68 MiB
block (about 16 ms on the quiet host, at most 17.3 ms).

(cherry picked from commit 30108c53759b9f76e25c0994e7db3cd4f7de7731)
2026-11-09 20:49:30 -08:00
Anees Iqbal 314263e447 Docs: the 2048x2048 packing measured, the slack's reason; the fill's other devices by the test
Verified at the tree of "Memory: pooled blocks stay 64 MiB, 68 MiB for images" (job 12840 on
ms01, the Iris Xe; job 12841 on gem10, the 780M) and at that of "Memory: a block's making time is
the tests' alone" (job 12851 on ms01, the Iris Xe and lavapipe):
- tests::blocks_ahead::a_block_of_images_holds_four_textures_of_a_quarter_block_each passes on
  the Radeon 780M (RADV PHOENIX, Mesa 26.2.6; 12841), on the Iris Xe (ANV; 12840 and 12851) and
  on lavapipe (12851): eight RGBA8Unorm textures of 2048x2048 lie in 2 blocks of 68 MiB. Each
  took 16842752 bytes at an alignment of 65536 on the 780M and the Iris Xe, 16777216 at 64 on
  lavapipe. With the slack taken out (a negative control, image blocks of 64 MiB), the test fails
  on the 780M (12841) and the Iris Xe (12840): the eight lie in 3 blocks. So the sixteenth stays,
  for images.
- tests::block_fills passes on all three: the 780M fills every block of images first (types
  0x15864: of 3 blocks of images, 5 plain blocks filled first, 1 made under 1 ms and 4 not, in a
  process that submits nothing; 12841); the Iris Xe and lavapipe fill none (types 0x0, 0 fills;
  12851).
- The memory, blocks_ahead, zeroed_start, clip_bursts, exported and freed memory,
  device_recovery and host_copy tests pass on the 780M (51 of 51; 12841) and the Iris Xe (51 of
  51; 12840); blocks_ahead and block_fills on the Iris Xe (8 of 8; 12851), and blocks_ahead,
  block_fills and memory on lavapipe under --cfg m2v_cpu_icd (27 of 27; 12851).
- clippy with no cfg, with --cfg m2v_gpu and with --cfg m2v_cpu_icd, the runtime's Rustdoc, the
  API signatures and the driver-fact tests (9 of 9): clean (12851). The conformance crate's suite:
  1029 of 1029 (12840).

(cherry picked from commit 458aa4a23c3359cc6b44f01812d53a88260f29ba)
2026-11-09 20:49:30 -08:00
Anees Iqbal 930e3aa49e Memory: pooled blocks stay 64 MiB, 68 MiB for images; the making-rate rule goes
The rule that made a device's later pooled blocks of plain memory smaller once a making took
longer than 8 ms (MAKING_BOUND, MIN_PLAIN_BLOCK_BYTES, Memory::plain_block_made) is removed,
with what existed only for it: placements larger than a pool's small blocks taking blocks of
their own power of two (pooled_block_bytes, Pool::large, took_large), the block's worth of small
blocks kept ahead (ahead_sizes' count), the call's upper bound on the blocks it takes
(ready::Need's most; a call now takes a block of its least bytes or more), and nearness by the
largest block a pool holds (Pool::ahead_room). Every pool's blocks are one size: 64 MiB, or the
device's largest allocation, and a pool of images' 68 MiB, a sixteenth besides
(IMAGE_BLOCK_SLACK, formerly PLAIN_BLOCK_SLACK, now on images alone): a driver's image takes more
than its texels, so that four images of a quarter of a block fit in one.

The hold that rule shortened is taken away by the exportable fill of the commit before, where
the driver holds submissions in plain makings, with the blocks kept at 64 MiB: the 17 MiB blocks
made 45 to 55 makings a phase on the 780M against 13 to 15, holding 138 to 230 ms against 125 to
201 ms, and put every texture past 17 MiB in a block of its own (docs/FAST-PATHS.md).

Tests: tests::plain_blocks goes; blocks_ahead's small-blocks tests go (the reserve of four small
blocks, the large placements' block, the mixed-sizes run made smaller partway); its packing test
now packs four RGBA8Unorm textures of 2048x2048 (a quarter of 64 MiB) to a block of images;
the first-block test runs on 64 MiB blocks. A new device test, tests::block_fills, holds that a
device with DriverFact::PlainAllocationsHoldSubmissions fills every block of images it makes
exportable first, counted, and that a device without it fills none. The reclaim bench's
small-blocks arms go. The conformance cost gate gates device_memory_allocated again (the
BLOCK_SIZE reason goes): block sizes no longer follow how long earlier makings took.

docs/FAST-PATHS.md: the RADV plain-blocks row is rewritten (blocks stay 64 MiB, the hold
measured), a row for the fill is added (its kernel dependency, its counters, the 780M A/B and
its cost), and the NVIDIA memory-block row says one block is kept ahead.

Verified: not yet compiled; the clippy, Rustdoc and device runs follow.

(cherry picked from commit 2cc9b21cb99b3fa7ac3b4199ae2aca88a99e014e)
2026-11-09 20:49:29 -08:00
Anees Iqbal f066aaf587 Blocks made ahead: a pool near its next block by three quarters of the largest block it holds
tests::blocks_ahead::mixed_sizes_find_their_blocks_made_ahead failed in
two of five runs of the memory tests on the Radeon 780M (gem10, jobs
12627 and 12669): "creation calls waited for a block of images at
textures [11]". In both, a slow making of the host's (the tests beside
it) made the device's blocks of plain memory smaller early in the run,
while its pool of images still filled its first block of 64 MiB, made
before. A pool that has not grown keeps its next block made ahead once
it is near it (Pool::near_next), which was measured by three quarters of
its blocks' size now: 12.75 MiB of a 17 MiB block (12 MiB of 16 MiB
before the blocks' sixteenth). The 64 MiB block had 12.4 MiB left, so
the pool kept none ahead, and texture 11 (2560 x 1440, 15,790,080 bytes
on RADV) found no room and waited for its block. Told of a slow making
before its fourth texture (a scratch of the test, job 12687) the 780M
waited at texture 11 in two runs of two; before its seventh or eleventh,
by which the pool had grown or was near its next block, in none.

A pool is now near its next block below three quarters of the largest of
its blocks' size and the pooled blocks it holds (Pool::ahead_room), so a
pool still filling a block made before its blocks were made smaller
keeps its next block ahead as it did for that block; the sweep of blocks
made ahead and unused reads the same measure. A pool whose blocks are
all of one size is unchanged.

New test: mixed_sizes_after_blocks_made_smaller_find_their_blocks_made_
ahead, the mixed run told of a slow making before its fourth texture.
memory/ready.rs and docs/FAST-PATHS.md's blocks-made-ahead row say the
measure.

Verified on the 780M (job 12692): the new test without this change
waited at texture 11 in three runs of three; with it, the memory tests
(66) pass in three runs of three, the new test with no wait (7 blocks of
images made ahead), and in one of them the existing mixed test's own
blocks made smaller at texture 15 by a slow making of the host's, with
no wait. The memory tests pass on the RX 550, lavapipe (job 12693) and
the Iris Xe (job 12694); clippy plain and under m2v_gpu and
m2v_cpu_icd, and the runtime's Rustdoc, clean.

(cherry picked from commit c3fd622421584dfcc0b34ca133dbae22f53203e6)
2026-11-09 17:52:06 -08:00
Anees Iqbal 6346da2609 Small blocks: a sixteenth besides the power of two, so four quarter-block images fit
A pooled block of plain memory made smaller after a slow making
(Memory::plain_block_made) was a power of two, 16 MiB at the least. A
driver's image takes more than its texels: a Private RGBA8Unorm texture
of 1024 x 1024, sampled and rendered to, is placed in 4,210,688 bytes on
a Radeon 780M (RADV PHOENIX) and an Iris Xe (ANV, RPL-P) and 4,210,712 on
an RX 550 (RADV POLARIS12), each at an alignment of 64 KiB, so the second
starts at 4 MiB and 64 KiB and a 16 MiB block holds three, not four
(lavapipe: 4,194,304 bytes at 64, four).

The blocks are now made of that power of two and a sixteenth of it
besides (PLAIN_BLOCK_SLACK): 17 MiB at the least, holding four images of
a quarter of the power of two with up to 256 KiB of metadata and
alignment each, two of a half with up to 512 KiB, one of the whole with
up to 1 MiB. plain_block_made picks the largest power of two whose block
with its sixteenth the slow making's rate makes within MAKING_BOUND, so
the 8 ms bound holds for the block as made (64 MiB in 16 ms: 16 MiB, not
32, as 34 MiB would pass it). A placement larger than such a block takes
the least power of two so made that holds it (a 20 MiB texture: 34 MiB).
Blocks of plain memory not made smaller keep their 64 MiB, and the
blocks of exportable buffers theirs. The reserve a pool keeps ahead is
as many of its blocks as come to a 64 MiB block or more (four of 17 MiB,
68 MiB), at least what it kept before.

Verified, tests::blocks_ahead::small_blocks_hold_four_textures_of_a_
quarter_block_each (16 such textures, one at a time, on a device told of
a slow making): before, 6 pooled blocks of 16 MiB held them on the 780M
and the RX 550 (failing, jobs 12602 and 12590); after, 4 blocks of 17 MiB
hold them on the 780M, the RX 550, the Iris Xe and lavapipe (a fifth
made ahead). The memory tests (blocks_ahead, plain_blocks, zeroed_start,
memory, clip_bursts, host_copy) pass on the RX 550, lavapipe and the
Iris Xe, and on the 780M but for mixed_sizes_find_their_blocks_made_
ahead in two runs of five: a wait older than the sixteenth, which the
branch's last commit fixes. Clippy plain and under both cfgs, and the
runtime's Rustdoc, clean.

tests::reclaim_submit_bench on the 780M (gem10, Mesa 26.2.6), the
small-blocks arms, pooled blocks made a phase before -> after (two runs
each, release):
- images, 1024 x 1024 one a frame: quiet 64 (1024 MiB) -> 48 (816 MiB),
  pressed 67 (1072 MiB) -> 51 (867 MiB);
- images of mixed sizes: quiet 36 (576 MiB) -> 30 (510 MiB), pressed 39
  (624 MiB) -> 33 (561 MiB);
- images in bursts: quiet 64 (1024 MiB) -> 48 (816 MiB), pressed 64-67
  (1024-1072 MiB) -> 51 (867 MiB); calls that waited for a block made
  ahead 23 -> 15 quiet, 20-23 -> 15 pressed.
The three blocks made ahead and freed unused in each pressed phase stay
(48 MiB -> 51 MiB).

docs/FAST-PATHS.md's known gap (blocks made smaller, down to 17 MiB) and
its blocks-made-ahead row change with it.

(cherry picked from commit 532d06c2359fb2756f5514ba2821f959cf48293b)
2026-11-09 17:52:06 -08:00
Anees Iqbal 40831926fd Blocks made ahead: the reserve counted in bytes with the pool's room, made again at large placements
The trigger of a pool's blocks made ahead skipped the pool while it had room for a whole block
(`ready_if_growing`'s `has_room(bytes)`). A call that takes a block from the reserve leaves the
pool a whole block of room and none made ahead, so nothing was made again until a later creation
call found the pool short of a whole block; by then the placements had taken the room, and the
next call that needed a block waited for a making it started itself. On an RX 550 (64 MiB
blocks, textures of 4, 14.1 and 31.6 MiB one at a time, every making ended between two) the call
after each 31.6 MiB texture waited so, at textures 8, 16 and 24 of 32 (job 12539,
`tests::blocks_ahead::mixed_sizes_find_their_blocks_made_ahead`, with made-ahead empty from
texture 6 on). On a Radeon 780M the bench's mixed arm waited for 8 and 6 of its blocks with
none hurried (job 12513).

- The reserve counts its own blocks in bytes together with the pool's room (`Memory::lacking`,
  the longest free range, `Pool::room`): none lacks while those made ahead and the room come to
  their worth (a block's worth, as before), and once they come to less, as many as bring those
  made ahead back to it. The trigger no longer skips a pool with room for a whole block: a pool
  that grew or is near its next block keeps what it lacks. The large block's rule is unchanged.
- A placement of a quarter of a block or more in a pool whose blocks are made ahead runs that
  trigger there and then (`ready_after_placing`, in `place`), not at the next creation call,
  which may need the block at once: a quarter of a block is the lead `ahead_room` gives the next
  block's making before the half block `keep_room` keeps, so such a placement can use it up in
  one step. (A threshold of half a block would miss the 31.6 MiB texture, just under half of
  64 MiB, and pooled placements are at most half a block.) Room is cached
  (`Pool::room`), so the check derives it where the next creation call would have.
- A call whose waited making ended without its block waits once more, on a making that counts
  it from its start (`take_ready`), before it makes the block itself. A thread ends so without a
  failure: a reserve making no call waited for as it began makes no block within the device's
  allocation margin (`Allocations::room_ahead`), and its ending drops the sizes queued behind
  it, the waiting call's among them. This is the hole the M3 cost records' selection-only image
  and buffer blocks made in place point to (not measured here).

Measured on a Radeon 780M (RADV PHOENIX, gem10, exclusive; job 12560, two runs each, the
reclaim bench's images arms; RT 1991 is development with the ready threads' rename):
- Mixed sizes, 64 MiB blocks: blocks waited for, quiet and pressed, RT 1991 8 and 6 in both runs
  (none hurried), with this change 0 and 0 in both. Slowest creation call in the pressed phase
  8.5 and 5.8 ms at RT 1991, 3.6 and 1.9 ms with it (RT 1987: 5.2 and 1.5 ms, with 8 and 6
  blocks of images made in place, none since). Blocks made, 13 and 14 a phase, unchanged.
- Bursts of 16 textures, 16 MiB blocks: waited for, quiet 24 and 25 at RT 1991, 20 and 21 with
  it; pressed 27 and 27, then 23 and 23; hurried 11 to 12 at both (RT 1987: 60 a phase).
- Images one a frame and mixed sizes on 16 MiB blocks, and the 64 MiB images and bursts arms:
  no wait at either, none in place, the same blocks made.
On an RX 550 the mixed-sizes test waited at textures 8, 16 and 24 without this change and at
none with it (job 12556); lavapipe, whose slow makings made its blocks 16 MiB, waits only at
texture 7, the first texture larger than its blocks.

The mixed-sizes test allows the one wait it should: where a device's slow makings made its
blocks of images smaller (lavapipe, 16 MiB), the first texture larger than them waits for a
block of its own size, which nothing foretold.

Work counts expected to move: blocks_ahead_waited_for down (the mixed and burst arms' waits on
makings started late become blocks made ahead and found ready); image/buffer_blocks_made_ahead
about the same in total, with makings started earlier; blocks_ahead_hurried down where those
makings would have been cut short; image/buffer_blocks_made_in_place down to 0 in the M3
selection where the room_ahead ending was the cause (expected, unmeasured). The bytes kept ahead
are bounded as before: a block's worth a pool, plus the large block.

(cherry picked from commit 384c96121f7fa1ff8dec80ccfbf98f401ab77a74)
2026-11-09 16:55:06 -08:00
Anees Iqbal f79bf9a144 Blocks made ahead: calls for a pool's own blocks leave its large block alone, and a taken block is waited for again
1. The large block kept ahead was not kept for the large placements. While a pool's placements
   past its 16 MiB blocks are recent, it keeps one 32 MiB block ahead (074d8e762e). But
   add_ready and the waits took the smallest made block of the needed size or more. So a burst of
   textures that ran through the pool's own 16 MiB blocks before their refill took the 32 MiB
   block too, and the next large placement waited for a new one. Shown at d562bd4148 by the new
   burst phase of tests::blocks_ahead (24 textures of 4 MiB back to back with a queue use held
   open): the burst took the 32 MiB block, nothing made ahead was left (lavapipe and the RX 550),
   and the pool ended with 5 and 6 blocks of 32 MiB against 4 large textures.

   Fix (memory.rs, memory/ready.rs): a call takes a block within a range (ready::Need). Below the
   pool's recent large size it takes no block of that size or more. The waits and the "will a
   block come" check use the same range. The pool's own blocks are kept at a full block's worth
   again (4 of 16 MiB), and the large block is kept besides them. Before, the large block was
   inside the 64 MiB but could already come on top of four small ones. So a pool of 16 MiB blocks
   with placements past 16 MiB in the last 10 s keeps up to 64 + 32 MiB ahead; every other pool
   keeps 64 MiB, as before 1984. ready.rs and FAST-PATHS' kept-blocks row say so.

2. A call that waited for a block made for it could still make one itself, if another call took
   that block first: take_ready then returned false and keep_room made the block in place. Now
   Waiter::wait says whether a fitting block was made, and take_ready waits again when one was
   but another call took it. Found by reading the path for the 5080's first-growth red at RT 1987.
   A call now makes a pool's block itself only where no making serves it: a host-copies placement
   while that pool's thread reads pages, a making that failed or a thread that did not start, or a
   placement before the device's first creation call.

3. The test placements_past_a_pool_s_small_blocks_find_a_block_of_their_size_made_ahead checked
   the device's count of waits, which also counts other pools' blocks. On the RX 550 (job 12498)
   it went red with the filtered suite running: 7 waits, 1 after the first 20 MiB texture. Alone,
   d562bd4148 passed 3 of 3 with the memory log on (job 12514): 5 waits, 0 after. It now reads the
   image pool's made blocks before each later 20 MiB texture, and it adds the burst phase.

Work counts expected to move against 074d8e762e: none in the cost cases. Their pools' blocks are
64 MiB and they place nothing past half a block, so the range is unbounded there and the reserve
is the same. Only a device whose blocks shrank and that places past them keeps the large block
ahead through a burst: fewer blocks_ahead_waited_for, and pooled_memory_blocks_made rises by the
small blocks the burst waits for instead of taking the large one.

(cherry picked from commit b38f14b41a45a152453358a9f6dd5459bf74f3cd)
2026-11-09 15:45:26 -08:00