Commit Graph
447 Commits
Author SHA1 Message Date
Anees Iqbal 89483d65cb An idle device lets go of its kept empty blocks and parked objects
What: a device keeps an emptied memory block for 10 s (KEPT_EMPTY_FOR) and a
released image or buffer parked for 1 s (recycle.rs), and only let either go
at a later call of the program: a release in the block's pool, a creation
call (sweep_stale, from keep_room), or a recycler's park or take. A device
whose program stopped making resources kept them until its next creation
call, however long that took. The consumer's Iris Xe rerun showed it: after a
guest application quit, 11 empty pooled blocks, 4 empty dedicated ones and
the parked objects sat 33 s with no counter moving; the first creation call
then freed 12 at once, and 7 empty blocks still stayed, the "one pooled block
per pool" kept for good.

How: one idle-sweep thread per device (idle_sweep.rs), started by the first
creation call that may wait (Device::keep_room). A block kept empty, a block
made ahead and an object parked each say when they may go (Due::by). The
thread waits for the earliest of those moments, sweeps (recyclers first, then
Memory::sweep_kept, the creation calls' sweep without its throttle), asks
what comes due next (Recycler::due, Memory::sweep_due) and waits again, with
no timeout when nothing is due. It sweeps at most once a second. It holds the
memory, the two recyclers (now Arc'd), the functions and the counts, never
the device. Its Vulkan calls run in an exit-guard section, and the teardown
stops and joins it before the parked objects and the memory go. Freed blocks
are posted to the free thread, which paces them as before.

The pool's last empty block now stays only in the pools the runtime keeps
room in for its own encodings' and commits' resources (Memory::keeps_room:
the kept list, not a small heap's). That block is the room the next creation
call's keep_room would make again. Every other pool keeps none past the 10 s.
So the lasting spare is bounded at one block per kept pool and counted in
WorkCounts::empty_memory_blocks_live. docs/FAST-PATHS.md's row says so and no
longer claims "held until 10 s after the dip" for blocks that stayed for good.

Verified: tests::idle_sweep (lavapipe, ms01). Private buffers and textures
over several blocks are used by a command buffer that completes, one refused
at commit (abandoned encoder) and one its submission check fails, then all
are released and the device idles. Before this change (b11d8115f1, job
m3-max-20498) it failed after 40 s idle: 32 images and 3 buffers parked,
8 pooled blocks live against 1 at the start, 512 MiB in the heap against
64 MiB. The unit test a_pool_without_room_lets_its_last_kept_block_go covers
stale/stale_at with and without room. The after-run is in the report.
2026-11-12 04:24:52 -08:00
Anees Iqbal cdcd787fb8 A render target's channel-order sibling views are views of its image
A pass rendering into a BGRA8Unorm or BGRA8Unorm_sRGB view of an
RGBA8Unorm texture made without PixelFormatView usage (and the same for
BGRA8Unorm and the sRGB twins) rendered through a shadow image of the
view's format, copied in before the pass and back after it
(shadowed-texture-view, about 50-95 us a command buffer at 64x64): the
texture's image was mutable only for its sRGB twin's formats, so Vulkan
made no view of it in the sibling's format.

Basis, documented on both sides:
- Vulkan: VkImageFormatListCreateInfo (core 1.2), pViewFormats
  "specifying all formats which can be used when creating views of this
  image", with MUTABLE_FORMAT; the formats are of one class.
- Metal: MTLTextureUsage.pixelFormatView, "Don't set this option if your
  texture view only converts between linear space and sRGB. For example,
  if your texture uses the rgba8Unorm pixel format and your texture view
  uses bgra8Unorm_srgb." Plain Metal makes the BGRA8Unorm view too and
  renders through it (its API validation stops it; view_attachments).

Change (image_plan.rs): a color texture of those four formats with
RenderTarget usage lists, besides its sRGB twin's views, the views of
its sibling and the sibling's twin (reordered_views, reordered_formats),
in the single-sample and the multisample plan; a word attachment's view
is left out as for the twin. A texture that renders nothing lists none:
its sibling views already read the image through a swizzle. The view's
other uses then view the image too (takes_views_of).

Compression: expected, not measured. Mesa's sources suggest RADV before
GFX11 keeps no DCC for a list whose formats' channel orders differ, ANV
keeps CCS_E for formats of the same channel bits, RADV GFX11+ keeps DCC
for any list; NVIDIA documents nothing. The A/B lane
view_attachments::reordered_view_render_costs (the parent commit)
measures it per driver.

Tests: image_plan::render_targets_take_their_channel_order_sibling_s_views
(every committed profile: the sibling and its twin taken where the
device renders them directly, none for a texture that only reads, none
for RGBA16Float); runtime_lane::view_attachments::
a_render_target_s_reordered_views_render_in_place (draws through both
views, Metal's bytes, no shadowed-texture-view).
Docs: the ShadowedTextureView notice (degradation.rs, API.md), the
FAST-PATHS view bullet, view_shadow.rs.

Verified: not yet built.
2026-11-12 03:56:51 -08:00
Anees Iqbal 9d184d13ec Heaps over host pages: a texture Metal tiles lies in the device's image over the pages first
In a heap over the caller's host pages (new_heap_with_bytes_no_copy), a single-sample texture
whose bytes Metal lays out in its tiles now takes the image bound to the pages wherever one
serves: its linear image made for host allocations, or over dma-buf pages the driver's
DRM_FORMAT_MOD_LINEAR image, in the driver's rows with no copy, announced
heap-texture-untiled-layout (Untiled::LINEAR). The shadow of Metal's tiles (AliasRoute::Tiled)
is the fallback where no such image serves, and stays the route of a copied heap.

The bytes in guest pages are now the device's layout, not Metal's tiles. Basis: Apple documents
a texture's layout in a heap's bytes as private to Metal, and the consumer confirms that no guest
code of theirs reads or writes a heap texture's bytes in guest pages (replaceRegion and getBytes
go through a staging blit; no buffer aliases a heap texture), so the copies in and out of the
tiles shadow bought nothing it could see (the owner's rule: shadows are a fallback, never a
first option). dma_buf_heap_plan now answers why its image does not serve instead of taking the
shadow itself, so a texture Metal tiles over dma-buf pages falls back to the tiles shadow before
the rows one.

Docs: host_heap_plan, AliasRoute::Tiled, the dma_buf module, the heap-texture-untiled-layout
declaration and catalogue entry, and the FAST-PATHS known-gap entry on heap textures in the
driver's layout.

Verified: cargo fmt only; builds and tests run as potluck jobs after this commit.
2026-11-12 03:56:49 -08:00
Anees Iqbal 236340a171 A heap texture's observed residency is resident; a sparse member under it is refused at plan
A function that observes the residency of a read, sample or gather of a texture it reaches
through an argument buffer (sparse_sample, then sparse_color::resident()) was refused at
pipeline creation: lower::texture::residency answered Lowering(Texture), NotImplemented, for a
heap element's status word. A forward renderer that streams its material textures compiles
exactly that, so its pipeline never made and it drew nothing.

Metal reports a texture that is not sparse resident everywhere, which is the word 0 the module
already builds for a heap element's access (emit::with_word). So residency() now answers a heap
element's observed residency with no residency form, the word 0, and the stage states the new
RuntimeFact::HeapResidency { stage } (PlanTimeCheck). The planner (bind::heap::HeapPlanner::new)
refuses a sparse texture (TextureFacts::sparse) that such a stage's handle tables reach,
Unsupported { ArgumentBufferTextures, NotImplemented }: answering one would need the member's
tile map or sparse image per handle-table entry, which is not built. docs/FAST-PATHS.md records
it as a known gap; a slot's sparse texture stays answered (RuntimeFact::SparseTexture).

SEMANTICS_VERSION 2041 (refusals become modules); ARTIFACT_FORMAT_VERSION 504 (a RuntimeFact
variant). docs/REFUSALS.md and the API surface table regenerated.

Test: tests::engine_heap_residency over the new tail_argument_sparse_samples fixture: both
fragments compile behind its vertex function on every committed profile with what they use
(moltenvk-m3, lavapipe and amd-780m-radv named), state the fact and pass L3; their plan holds
a texture that is not sparse and refuses a sparse one. Before the change the base CLI refused
argument_sparse_fragment with Lowering(Texture), NotImplemented, at block 0 instruction 2, the
sparse sample (job m3-max-20327, gem10).
2026-11-12 03:35:36 -08:00
Anees Iqbal e25e6c5258 FAST-PATHS: the RADV interlock row's measured creation time
Release, on the RX 7900 XTX with Mesa 26.2.6 and MESA_SHADER_CACHE_DISABLE=true:
con_fetch_coverage's first pipeline made whole in 0.9 ms (m3-max-20254, at the fix), and
linked in 1.1 ms at the base (m3-max-20257: pre-rasterization library 0.6-0.7 ms, fragment
shader library 0.4 ms, link 0.0 ms).
2026-11-12 03:07:42 -08:00
Anees Iqbal 9ad6257845 Runtime: on RADV a render pipeline whose fragment stage interlocks is made whole
RADV's fast-linked graphics pipelines leave the ordered pixel interlock unordered within a
draw. A fragment shader library made without the fragment output interface jumps to a separate
color epilog, and ACO waits for the interlocked storage writes before the final export only where
that export is the shader's own (RADV_DEBUG=shaders: a whole pipeline's image_store is followed
by s_waitcnt_vscnt and the done export, a fast-linked one's by s_setpc_b64 into the epilog). The
GPU ends the ordered section at that export, so the next overlapping fragment reads before the
write lands.

The new RuntimeDriverDefect::FastLinkedInterlocksUnordered is RADV's on every GPU (keyed on the
driverID, no clean GPU). On a driver with it, GraphicsContent::links() is false for a variant
whose fragment stage declares an interlock execution mode (interlocked_writes::facts), so the
pipeline is made whole, as a feedback-loop state is.

Evidence so far, all on the RX 7900 XTX, Mesa 26.2.6:
- tests::lone_fetch's layers leg at the base: 35 of 72 targets wrong, and 0 of 72 under
  RADV_DEBUG=nogpl (m3-max-20108).
- A bare-Vulkan probe with 12 instances of one quad in one draw: fast-linked, 46 to 62 of 72
  counters wrong; whole or linked with link-time optimization, none (m3-max-20040, -20134).

lone_fetch's run now prints the device's pipelines made whole and asserts one there. The fixed
tests on the XTX, the creation time, lavapipe and lint follow.
2026-11-12 03:07:42 -08:00
Anees Iqbal d971205216 RUNTIME_VERSION 2101: a slot that reads only levels past the attached ones reads them in place
A draw that samples a texture its own pass renders at one level read the texture's copy unless
every read reached only levels before the lowest attached one. A slot every read of which
reaches only levels past the highest attached one (a pyramid pass that renders level m from
level m + 1, or through a sampler whose minLod lies past m) now binds the texture's own image
through a view of its levels from the first up to the highest it reads (all of them where the
sampler's maxLod reaches past the last), and names in its uses only those from the lowest it may
read (LevelReads::lowest_level, SampledLevels::lowest, through each bound sampler's levels, its
lodBias as the bind takes it included). The levels read hold the copy's texels: nothing the
instance does writes them, checked as the levels-before case checks (reads_levels_in_place,
shares_attachment, the unordered writes, the draw's own writes).

The view holds the attached levels too, unread. Vulkan's rules against reading an attachment are
of accesses (VUID-vkCmdDraw-None-10795; the Render Pass chapter's subresource "simultaneously
being used as an attachment"), and the descriptor's layout must match the subresources the view
holds (VUID-vkCmdDraw-imageLayout-00344): GENERAL, where every attachment rests. So such a slot
keeps its copy in an instance that holds one of the texture's attached colors in the feedback
loop layout, and the instance's general_colors (renamed from storage_colors, which now also
holds the colors such a view spans) sends a later snapshot read of one into another instance.

Counted as WorkCounts::attached_read_slots_past. The reasons a slot keeps its copy now test any
level before the first-level case, which covers only a read that may reach an attached level.

Tests: tests::attached_levels (runtime, the device cfgs) gains reads past the attached level;
runtime_lane::attached_levels (validation, under the layer) reads levels past the attached one in
a pass recorded inline, where the layer sees the attachment. Verified: built and run in the next
job, with a negative control.
2026-11-12 02:46:13 -08:00
Anees Iqbal cf4d8017f2 FAST-PATHS: the heap answer row's measured counts and bytes
heap_texture_images at 4c6ffc7567 (code identical to this tip), under each HeapAnswerPolicy:
of the 22 compositor shapes, on ANV (Iris Xe, m3-max-20000) 14 lie in an image put in place of
their first one and 7 are shadows in Metal's tiles under Metal, none of either under Device, the
answers 3769962 bytes against Metal's 3656426; on the RX 7900 XTX (m3-max-20001) 1 and 8 under
Metal, none under Device, 4155498 bytes. heap_compression_costs on ANV under the default
(m3-max-20014): the 2048x2048 render target still takes the linear image under both compression
values (clear 955.3 and 971.4 us), so the HeapCompression row now says so.

Verified: the jobs named; docs only here.
2026-11-12 01:52:37 -08:00
Anees Iqbal 5b5362124c FAST-PATHS: the heap-shadow cost entry is HeapAnswerPolicy::Metal's
Under the default HeapAnswerPolicy::Device a heap texture Metal keeps uncompressed lies in its
device's image wherever its alignment is within the answer's bounds, so the entry's shadow and its
ANV figures describe the switch, and a texture past the bounds whose 4 KiB image does not fit.

Verified: docs only.
2026-11-12 01:52:37 -08:00
Anees Iqbal d8b584a939 RUNTIME_VERSION 2097: a heap texture answers its device's image where that needs more than Metal's answer
Add DevicePolicy::heap_answers, HeapAnswerPolicy::{Device (the default), Metal (in
exact_answers)}. Under Device, a single-sample heap texture whose image binds into the heap's
memory and needs more bytes or a coarser alignment than Metal's modelled answer answers the
larger of Metal's answer and that image's (heap_extent), and lies in that image: no refit to an
image that fits Metal's answer and no shadow of Metal's tiles. A Shared texture's answer also
holds the linear image a heap over host pages binds for it (host_route_extent), so a heap over
guest pages places it too. The answer's alignment is taken only up to 64 KiB (the largest a Mac
answers: an AMD Radeon Pro 5300M) and up to the larger of 4 KiB and its own size, so padding
before a texture stays at most a page or its own bytes. Where the first route's alignment is
coarser than that (ANV's compressed image of a small texture: 64 KiB for 16 KiB), the image a
4 KiB alignment holds (host-transfer usage, else linear: fitting_heap_image with no tiles) lies
there in its place and the answer is that image's, before any shadow. Metal's measured answers
(4:2:2, one-plane YCbCr, two-plane, X32_Stencil8, BlockWritesOnly), multisample textures and
textures whose image lies in memory of its own keep Metal's answer. Metal keeps today's
behaviour exactly.

Why: Metal's 128-byte model made every non-MoltenVK device refit or shadow its heap textures.
Measured with heap_shadow_costs::heap_texture_images, 0 of a guest compositor's 22 heap shapes
fit Metal's answer on ANV (Iris Xe, every optimal image at 65536), on the RTX 3090 (1024) and on
the RX 7900 XTX (256 to 65536). The shadow costs a frame that clears and blits a 1x1 array 34.7
us against 8.2 us outside a heap (ANV). The ledger gets the row; the HeapCompression row notes
that its compressed figure needs the device's answer.

heap_texture_images now runs under both values, makes each shape in a heap and prints a
HEAP-COUNT line (refits, tiled shadows, answer bytes against Metal's).

Verified: cargo fmt only, here; the build, clippy and tests run as potluck jobs after this commit.
2026-11-12 01:52:36 -08:00
Anees Iqbal 0d144ec0de Pooled memory: no bound on a texture's bytes; ShadowCause::LinearCost is gone
The owner, through reims: zero copy, in place where possible, shadow copies a fallback and never
a first option. A tracked texture over a Private buffer of the runtime's pooled memory whose rows
the device's own linear image lays out otherwise was a shadow past 48 KiB to its pitch
(TextureShadowReason::LinearCost), a speed choice measured on an Iris Xe alone that shadowed 1001
of an RTX 2080 guest boot's 1366 textures. It now takes its DRM_FORMAT_MOD_LINEAR image at Metal's
pitch at any size, wherever the device makes one and its check of the pooled memory passed, as a
texture over a Shared buffer already did; it is a shadow only where the device makes no such
image (its format, usage, pitch or limits), its policy is HostPageTexturePolicy::Shadow, or the
check failed or is pending (a pending one still moves in place once it passes).

Removed with the bound: in_place::POOLED_PITCHED_BYTES, ShadowCause::LinearCost and the public
TextureShadowReason::LinearCost (a breaking change of metal2vulkan-runtime's surface:
api_signatures.tsv loses its variant), texture_spans.rs (the runs of bytes textures were made
over, which only the bound read) and the moves it fed (MoveAfter::Aliases, LoneShadow, the
buffer's note and wait), Texels::only_commands_write (the bound's alone), the bench behind the
bound (runtime_lane::pooled_draw_costs, its crossover additions included) and
aliased_surfaces' cost bench. aliased_surfaces' first check now asserts every texture over one
surface's bytes takes the image at Metal's pitch, the first included, and a read copies nothing;
its one-after-another check, about the first texture's shadow, is gone. storage_over_buffer is
one function again (REFUSALS.md regenerated for the name). API.md, HOWTO.md, FAST-PATHS.md (the
in-place row) say "at any size".

RUNTIME_VERSION is not bumped here: the landing bumps it and re-pins the runtime sources.
2026-11-12 01:50:58 -08:00
Anees Iqbal fbef0a0948 Docs: the copied buffers' 7840HS and pass figures are of comparisons on four threads
The ledger's copied-buffer rows (FAST-PATHS) and copied.rs's Cost bullet quote
the copied_bench and copied_pass_bench figures measured while a comparison ran
on up to four threads; it now runs on up to eight, so they say so, in the past
tense, rather than read as the eight-thread cost. The two FAST-PATHS rows are
rewrapped to 100 columns (one line ran to 130).

No behaviour change; no figure is new.
2026-11-12 01:13:40 -08:00
Anees Iqbal 86d6fd9cb2 FAST-PATHS: the fill queue's narrowed waits, as the RTX 3090 measured them
tests::fill_waits_bench on the RTX 3090 (job m3-max-19457): beside an app making two 4 MiB Private buffers per command buffer, the compositor's frame p50 went from 8.96-9.01 ms (every batch waiting for the fill queue's last submission, 424-429 unused waits in 4 s) to 2.10 ms (0 unused), as with nothing made (2.08-2.12 ms).
2026-11-12 00:52:55 -08:00
Anees Iqbal 781bd94935 Fill queue: a batch takes and waits for the fills of memory its commands may reach alone
On a device with a fill queue (NVIDIA's copy engine), a batch took every fill waiting, whichever
buffers its commands name, and every submission of the device's waited on the GPU for the fill
queue's last submission until the host saw it complete. A fill-queue submission waits for the
batches before its batch on that batch's VkQueue, so a compositor's frame that named only old
buffers waited for an app's new buffer's zeros behind the app's kernels, or made them itself and
waited for its own queue's last batch first.

What, on such a device:
- A batch takes the fills of memory its commands may reach (FillTake::Reached): memory a resource
  its encoders' uses name owns (used_resources::owner_of over Owners and HeapKeys: the buffer, or
  the heap it lies in); every fill where a command of it may reach memory no use names
  (State::reaches_unnamed, State::parts_reach) or where it takes a move of an image in memory
  another resource owns or a staged copy (Taken::every_fill), which come after every fill of that
  memory; and the fills of the device's own buffers, which no use names. The rest stay waiting, in
  their order, for a batch that may reach them or an internal submission, which takes every one.
  A fill's key is noted as it is registered (Filled::key), and its owner as it is taken, so a
  buffer's fills share their turn.
- A batch waits on the GPU for the last fill-queue submission the host may not have seen complete
  whose fills it may reach (Device::fill_queue_wait_for), where its VkQueue did not already.
  Internal submissions still wait for the fill queue's last.
- A command buffer that needs no GPU work goes with no submission where nothing waits but fills of
  the program's memory (FirstMoves::none_waiting_but).
Other devices take every fill, as before.

Tests: first_move::a_batch_takes_the_fills_of_memory_it_reaches (pure); fill_waits (device) holds
fill_queue_waits_unused at 0, where the commit before counts the compositor's waits.

Docs: device/staging.rs and texture/first_move.rs module docs, the runtime README, FAST-PATHS'
fill-queue row.

Verified: cargo fmt. Builds, device runs and numbers follow as potluck jobs.
2026-11-12 00:52:54 -08:00
Anees Iqbal ba69642609 Copied buffers: a comparison splits across up to eight threads, not four
A copy's comparison of 4 MiB or more (a commit's copy in with no base, whose
pages carry no log, and a comparison with a base) ran on up to four threads, the
calling one among them. On the RTX 5080 Laptop GPU's host (a Core Ultra 9
275HX) eight cut the commit of a kernel-read pass over 256 MiB from 11.2 to
8.4 ms (12.3 to 14.1 GB/s), 64 MiB from 2.9 to 2.2 ms, a copy in after the CPU
rewrote every float of 256 MiB from 30.3 to 17.0 ms (6.6 to 9.0 GB/s), and the
merge back of a 256 MiB kernel-write from 65 to 41 ms with the stores of
27c4a1ae46 (copied_bandwidth_bench's copied-t8 rows at 31333d4bf4, b5080
entry nvcopybw-nvcopybw-5080-ab-234252); on the RTX 3090's host (a Ryzen 7
7840HS) the 256 MiB kernel-read commit from 14.0 to 11.9 ms and the 64 MiB
kernel-write merge back from 11.2 to 8.8 ms (m3-max-19454). A host that runs
fewer threads at once runs that many.

SPLIT_THREADS is now 8, so a device's comparisons (one at a time under its
copies' lock) hold at most seven more threads at once. The bandwidth bench's
contrast row is now four threads (copied-t4); copied_256_bench_eight_threads,
which measured what is now the default, is gone. Docs say eight.

Tests: run after this commit (copied tests on a host without AVX-512, lavapipe).
2026-11-12 00:47:30 -08:00
Anees Iqbal 13d05be0a4 Copied buffers: a comparison splits across threads from 4 MiB, not 16
SPLIT_BYTES, the fewest bytes each thread of a split comparison takes, goes
from 8 MiB to 2 MiB. A merge back runs about 1.75 GB/s a thread on the RTX 5080
Laptop GPU's host (copied_bandwidth_bench, b5080 entry nvcopybw-bw-before-222944),
so a 16 MiB copy the GPU rewrote merged back on two threads in 4.2-4.5 ms of a
5.4-6.4 ms pass (2.6-3.1 GB/s); a run of 2 MiB takes about a millisecond a
thread, against tens of microseconds to start one. The thread count stays at
most four.

Docs: HOWTO, API and FAST-PATHS said a comparison of a copy with a base of 16 MiB
or more splits; now 4 MiB or more, with a base or without (the copy in with no
base splits since d33e19bc70).

Tests: the split tests take 4 x SPLIT_BYTES (a_comparison_split_across_threads_...,
a_copy_in_with_no_base_splits_...), now 8 MiB. Not run yet.
2026-11-12 00:47:30 -08:00
Anees Iqbal 84b6b4295b Copied host buffers copy in again as a batch waits out an event its commit came before
A commit copies into each copied host buffer the bytes the CPU changed in
its pages, before any of the command buffer's work is submitted. A batch
that waits for an event runs its commands only once the event reaches
the value, and on Metal those commands read the pages as they stand
then. So a CPU write made after the commit and before the host's signal
(or before a later command buffer's signal) never reached the copy, and
the waiting command buffer read the bytes from before it.

The commit now notes, before its copy in, the batches that wait for an
event value not yet reached (CopiesAgain::unreached, from each event's
timeline). When the scheduler submits such a batch, which it does only
once the wait is met, submit_batch first copies in again
(copy_in_again): the copies the command buffer reaches, as at the
commit, take the CPU's changes since. This runs with no lock of the
command buffer held, since a copy over logged pages waits for the log's
publication. A batch with no wait, or whose every wait was already
reached at the commit, copies nothing more. The new counter is
WorkCounts::copied_copy_ins_after_waits.

The same mechanism serves a reader held by an event across queues: the
signal of a batch submitted while a copy is live is seen only at its
completion turn, after the merge back. The FAST-PATHS gap that listed
event-ordered reads across queues as stale now says the held reader
copies in again; that case is expected from the code and not run.

Docs: copied.rs (Coherence, the two-memories bullet, copy_in),
dirty_pages.rs (stamps), HOWTO (copied host buffers), FAST-PATHS (cost
row and gap), api_signatures.tsv (the new field).

Verified: waited_reads in the jobs named in the report. The copied leg
fails at cae2e24b4d and passes here; the no-wait copied leg makes 0
copies in again.
2026-11-11 22:35:50 -08:00
Anees Iqbal 3cfcbe6304 FAST-PATHS: reflow the one-graphics-queue gap's new count line 2026-11-11 21:51:22 -08:00
Anees Iqbal 37db40177b Command queues take the VkQueue the fewest live queues hold; unshared ones an empty one under every verdict
A new command queue took the round robin's VkQueue by a creation counter (made modulo the
round robin), which never reuses a slot: a guest makes about 340 queues past NVIDIA's 14 in a
250 s walk, so live queues landed together while other VkQueues stood empty. An unshared
queue (a compositor's) got a VkQueue of its own only where the device shares (an Adaptive
verdict of Idles); under PerQueue, on MoltenVK, and on a device that answers GPU times from
the host (reims-vgpu's, Unchecked) it took the round robin's next, so app queues made later
landed on it every 14th make. Guest walks (reims's logs, read in place): unshared command
buffers behind another queue's batch 1062 in one 3090 walk (39 over 16 ms, longest 33.8 ms),
5 in the next on the same build; 511 on a 2080; 2048 on the M3 (437 over 16 ms).

Now, under every policy and verdict, a command queue takes, as it is made, the round robin's
VkQueue the fewest live command queues hold of those no unshared queue holds, the first in
turn from the counter among equals (queue_share.rs fewest_held, Device::take_round_robin):
one pass over the round robin's VkQueues' counts, atomics alone, at creation only; nothing
scans the command queues. Its claim is made before it reads the unshared count, as an
unshared queue's is made before it reads the live count, both sequentially consistent, so the
two never both succeed. An unshared queue takes one no command queue holds where one is free
(the existing unshared_order, now ungated), else the one the fewest hold.

Counts: WorkCounts::command_queues_live_most (the most command queues the program held at
once: what a walk needs to size the plan by) and unshared_queues_sharing_a_vk_queue (an
unshared queue that found no VkQueue free of other queues). queues_sharing_a_vk_queue keeps
its meaning, the queues made past the round robin's VkQueues; unshared queues now count among
them under every verdict, as they did where the device did not share. QueueLimits notes keep
theirs, an unshared queue's included.

Tests: tests::queue_share's pure churn shaped like a walk (354 made over 14 VkQueues, at most
12 live, an unshared one kept): no queue placed beside a live one while one stood empty and
the unshared one never shared, against a positive count by the old rule; device test
over_a_churn_queues_take_the_least_held_vk_queue_and_unshared_ones_an_empty_one under
Adaptive, PerQueue and untimed Adaptive. The helpers that share a VkQueue on purpose (beside,
the lane's queue_where) keep the queues they make until one lands there.

Docs: QueueSharingPolicy, new_command_queue_unshared, new_command_queue_for_presenting,
queue.rs and queue_share.rs module docs, docs/API.md, the runtime README, FAST-PATHS's queue
sharing row and its known gaps.

Not yet built or run: potluck jobs follow.
2026-11-11 21:51:22 -08:00
Anees Iqbal 85041aa633 dma-buf imports try only the system-memory types the host maps last
87b0acd6d5 tried every type the host does not map before every type it maps. On an Iris Xe
(ANV, Mesa 26.2.x, m3-max-18804) that moved Shared, WriteCombined and Managed imports of a
udmabuf and of a device-local dma-buf from type 2 (DEVICE_LOCAL|HOST_VISIBLE|COHERENT|CACHED,
the class's first) to type 0 (DEVICE_LOCAL alone). On a unified-memory GPU the host's flags on
a device-local type may choose how the GPU caches its accesses to the pages, so that move is
not shown to be harmless.

Now only the system-memory types the host maps (HOST_VISIBLE without DEVICE_LOCAL) go last;
device-local types keep their class's order. NVIDIA's udmabuf types (0: no flag, 4: host-visible
coherent cached system memory) still order 0 before 4, so the 3090's result stands. ANV's types
are all device-local, RADV's for a udmabuf all host-mapped system memory, lavapipe's one: the
class's order as before.

Unit test: dma_buf_imports_try_the_system_memory_types_the_host_maps_last (renamed), with an
ANV-like set (all device-local, unified) and a GTT-like set (all host-mapped system memory)
whose orders and forms stand. FAST-PATHS's NVIDIA dma-buf gap says the same.
2026-11-11 21:20:02 -08:00
Anees Iqbal c267e94e74 dma-buf imports try the types the host does not map first
NVIDIA's 620.70.06 lists a udmabuf of host pages as its type 0 (system memory, no property
flag) and its type 4 (host-visible, coherent and cached, the Shared class's first), refuses
every import as type 4 with ERROR_OUT_OF_DEVICE_MEMORY, and imports it as type 0. Measured on
an RTX 3090 (tests::export_after_dma_buf, raw vkAllocateMemory answers on fresh devices): once
it refused an import as type 4, it answers ERROR_OUT_OF_DEVICE_MEMORY to every allocation of
its device-local type 1 exportable as an opaque fd or a dma-buf (with the device-address flag
or without), at 12,441,600 bytes and at 64 MiB, for the device's life; plain and
device-address-only allocations are still made. After a successful import as type 0, every
chain is made. Whether the import was dedicated does not matter. The runtime's first Shared
dma-buf import tried type 4 first, so every later Private exportable buffer overflowed into
system memory (type 0, DeviceMemoryOverflow).

The runtime never maps a dma-buf import (the CPU reaches the pages through the caller's own
mapping), so a type the host does not map serves it as well. dma_buf_candidates now orders the
types the host does not map first, then those it maps, each in the class's order
(dma_buf_class_order, the order before), and dma_buf_attempts tries every form (dedicated to
nothing, then to the buffer) of the first group before any form of the second. On NVIDIA the
import ends as type 0, as before, without the refused attempt. A driver that lists only
host-mapped types for a dma-buf keeps the class's order.

Tests:
- memory::dma_buf_imports_try_the_types_the_host_does_not_map_first (unit): both orders, and the
  attempts' order, for NVIDIA's types and for a set whose listed types are all host-mapped.
- export_after_dma_buf::a_private_exportable_buffer_after_a_dma_buf_import_lies_in_device_local_memory
  (renamed): asserts each export lies in a DEVICE_LOCAL type with the control's flags and no
  overflow counted. It failed on the RTX 3090 before this change (type 0, one overflow each).
- export_after_dma_buf::the_driver_s_answers_after_each_kind_of_dma_buf_import: kept as the
  driver's evidence, printed and not asserted.
- export_after_dma_buf::the_type_each_class_s_dma_buf_import_takes_against_the_class_s_order:
  prints, per class, the type the runtime's import takes and the type the class's order took,
  for a udmabuf and for a dma-buf of the device's own device-local memory; asserts they agree
  where both orders are the same.
docs/FAST-PATHS.md's NVIDIA dma-buf gap records the driver's refusal and the order.
2026-11-11 21:20:02 -08:00
Anees Iqbal d277b155e2 Shadows of a tracked Private image stand across command buffers, stale inside a rectangle
What: a usage or attached-read shadow whose truth is a tracked Private or Memoryless image the
runtime made in memory of its own (not shareable, its VkImage never handed out) now stands
across command buffers, as a shadow of a Private buffer's bytes already did
(Backing::PrivateImage, StandingAcross::over_image). A standing also keeps the rectangle its
image is stale in when the command buffer ended with it current there alone, and the next
command buffer's gated copy in moves only those texels (Standings::standing,
GatedCopyIn::standing_copy). The first render pass instance of a pass now bounds its loaded
colors' writes by its draws' scissors as later instances did, so a draw that samples the
texture its pass renders leaves that texture's shadow stale inside the drawn rectangle alone.

Why: on the 780M a 2618x1024 texture read through such a shadow was copied in whole once per
frame although its texels changed only every 4th frame: 2,680,832 texels a frame, about
200-370 us of GPU time, for a draw beyond the texture's usage and for one that samples it in
the pass that renders it through a 64x64 scissor. An image truth never stood (stands_across
took bytes alone), and a one-instance pass's attachment writes were never bounded, so the
shadow lost the truth whole. The copy an attached read takes before any barrier stays: read in
place through the feedback loop it would race the pass's own writes, which Vulkan forbids
(attached_reads.rs now names it).

New WorkCounts fields: shadow_texels_first_copied_in_private_images,
shadow_texels_unskipped_stale_within.

Tests: unchanged_truth_copies now asserts that a frame that changed nothing moves no texel the
shadow holds (0 beyond usage, the scissor's 4096 for the small attached read); image_standing
checks the stale-rectangle copy's texels and counts, the let-go after another write, and the
mip chain (clear level 0, render level 1 sampling the whole texture, then level 2, then sample
every level) with and without a usage shadow, its passes apart and in one command buffer. Run on
lavapipe and RADV PHOENIX after this commit (job ids in the report to main).
2026-11-11 20:30:20 -08:00
Anees Iqbal b11e59ec86 Records carry a compute state's dispatches, and the warm pass makes their pipelines
A compute state whose descriptor requires no threadgroup size predicts no
VkPipeline at its creation: the local size and the threadgroup memory
lengths are the dispatch's own calls, so its creation's record made none of
its dispatches' pipelines on a later warm pass, and each was a cold driver
compile at the program's first dispatch of its shape (the 12.7.6 kernels'
case in FAST-PATHS).

Now, where the device hands records over, a compute state's direct dispatch
(dispatchThreadgroups: or dispatchThreads:) whose regions' pipelines were not
all made hands the hook one more record: the creation's descriptor, as its
own record holds it, and the dispatch (its threadgroup, a dispatchThreads:
grid reduced to one whole threadgroup and its ragged edge per axis, and the
encoder's threadgroup memory lengths). Each such dispatch once per state, at
most 16 a state (pipeline/dispatch_record.rs). A warm pass that creates such a
record's state then plans the dispatch as a creation's prediction plans its
first one (nothing bound but the default samplers), with the recorded
lengths, settles its variant as a dispatch does, and makes each region's
VkPipeline on the pass's thread, so their driver data lands in the records
under the names the program's dispatch of that shape asks for.
WarmStatistics::dispatch_pipelines_warmed counts them. Indirect dispatches,
dispatches of a threadgroup range and tile dispatches record nothing.

Records are immutable, one per dispatch shape, so a consumer keeps each once
and needs no rule for which supersedes which. The record format moves to 7:
a compute record's bytes now end in its dispatch list (count, then each
dispatch), so a format-6 record reads as none. The codec bounds the list at
16 dispatches and 31 lengths each, both when writing and when reading.

Tests: warm_record round-trips a compute record with a dispatchThreadgroups:
and a ragged dispatchThreads: carrying two threadgroup lengths, and bounds the
list (more than 16 is unwritable; bytes claiming 17, resealed, are no record;
16 read back). The device test
a_warm_pass_makes_the_pipelines_of_the_dispatches_its_records_name records a
state's creation and first dispatch, checks that the same dispatch again and a
grid of the same edge make and record nothing, warms both records on a
device over the same directory (dispatch_pipelines_warmed equals the regions
the recording dispatch made), and checks that the program's first dispatch
there hands each of its makings the driver cache the pass filled
(caches_shared) and translates nothing. A control device warmed with the
creation's record alone makes no dispatch pipeline and shares no cache.
Verification is in the report to main (potluck lint and lavapipe jobs).

Docs: the runtime README, HOWTO and FAST-PATHS ("Made again before the
program asks") describe the dispatch records; api_signatures gains the
WarmStatistics field.
2026-11-11 19:10:38 -08:00
Anees Iqbal 0307da09ba Docs: the fill queue's numbers with the tip's runs on the RTX 3090, RTX 2080 and RX 7900 XTX
At the tip the RTX 3090's 1 MiB frame alone took 0.93 times as long through
the fill queue (18358), against 1.04 in the two runs before (17900, 18199),
and the RTX 2080's 64 MiB one 1.04 times (18309, against 1.00 in 18167): the
trade sentence names both, and the swept size from which the fill queue was
within 1% alone in every run is 256 MiB, not 64 MiB. The tip's runs, whose
two devices both copy at the batch's start under 1 MiB, put them 0.31 to
1.85 times apart there (RTX 2080 18309, RTX 3090 18358, RX 7900 XTX 18310);
64 MiB beside the kernels at the batch's start took up to 49.4 ms, and the
other queue's share moved -11 to +8 points on the RTX 3090 and RTX 2080.

Verified: cargo fmt.
2026-11-11 19:08:58 -08:00
Anees Iqbal 3a349c2419 Docs: the fill queue's numbers from the sweeps, with the bench's spread under 1 MiB
The ledger bullet and staging.rs's fill-queue docs take the ranges of all
the runs: 1 MiB beside another queue's kernels 1.80-1.84 against
3.53-3.60 ms on the RTX 3090 and RTX 2080 (18199, 18167, 18309), 64 MiB
35.9-37.8 against 40.6-48.9 ms, and on the RTX 5080 Laptop GPU 3.31-3.39
against 5.90-5.92 ms (18316, 18108). Under 1 MiB the fill queue's frames
took 0.51-2.03 times the batch's start's, but at the tip, where both of
the bench's devices copy at the batch's start under 1 MiB, the same bench
put them 0.31-1.39 times apart (18309): the sub-1 MiB differences are not
past the bench's spread, which the docs now say instead of a 2.0x loss.

Verified: cargo fmt.
2026-11-11 19:08:58 -08:00
Anees Iqbal 700b0fec07 FAST-PATHS: the fill queue's 1 MiB least trades 0.06 ms alone on the RTX 3090 for the halved frame beside other work
At 1 MiB alone the RTX 3090's frame took 1.04 times as long through the fill
queue (jobs 17900 and 18199), and beside another queue's kernels half as
long; the swept size from which it is within 1% alone on all three NVIDIA
GPUs is 64 MiB. The owner's coordinator kept 1 MiB; the bullet says the trade.

Verified: cargo fmt.
2026-11-11 19:08:58 -08:00
Anees Iqbal 421799152d Fill queue: a batch's fills go there only where they write 1 MiB or more
The fill queue's own submission and the batch's wait for it cost small
copies more than the copy engine saves them. The sweep of
managed_copies_bench (a Managed buffer's copy in each frame, the fill queue
against the batch's start, p50) placed the crossover:

- RTX 2080 (18167): 128 KiB 1.04x alone and 1.11x beside another queue's
  kernels; 256 KiB 2.03x alone (0.94 against 0.46 ms), 1.09x beside;
  512 KiB 1.31x alone; from 1 MiB up 0.98-1.00x alone and 0.51-0.91x
  beside (1 MiB 1.81 against 3.57 ms).
- RTX 3090 (18199): faster or within 4% everywhere; 1 MiB alone 1.04x
  (reproduced, 17900), beside 0.51x (1.80 against 3.53 ms).
- RTX 5080 Laptop GPU (18108, before the sweep): 64 KiB 1.44x alone and
  1.06x beside; from 1 MiB up 0.93-0.99x alone and 0.56-0.96x beside.

So FILL_QUEUE_LEAST is 1 MiB, the smallest swept size from which the fill
queue is no slower beside the kernels on any of the three and at most 1.04
times as long alone: Taken::take_fills takes the batch's fills only where
they write that many bytes in all (copies and zeros), and fewer stay at the
batch's start, as on a device without a fill queue. Decided from bytes, not
from the device.

The fill-queue test gains a last command buffer whose fills (a new Managed
buffer's zeros and its copy in, under half the least each) make no
fill-queue submission and read back exactly. The ledger's costs of
matching Metal gain the fill queue's bullet; the staging, create, bench and
README docs say the least and the measured numbers (the create.rs 82% came
from the raw example and is gone).

Verified: cargo fmt; device runs, lavapipe and lint follow.
2026-11-11 19:08:58 -08:00
Anees Iqbal 269d7066c4 FAST-PATHS: what is built around a cold making's driver time, and the compute kernels' case
The known gap on the cold making of a 200,000-word compositing module ended "Nothing is built
around it", which was not true. It now names what is:

- the driver records across boots (`shader_cache/driver.rs`), named by the driver's identity, so a
  driver update, another device or a removed content directory makes every making cold again, and
  no machine's records serve another's;
- pipeline records and `Device::warm`, which remake a previous process's creations on a thread of
  their own below every other making, and what they do not cover today (a compute state that
  states no required threadgroup size predicts nothing, so its dispatches' pipelines are made at
  their first dispatch);
- `PipelineWaitPolicy::Bounded` at creation and at commit, and dispatches that hand their making
  to the pool;
- the consumer's creation of guest states on a compile thread off the guest's command path.

It adds the compute case: a convolution kernel's 12 variants at a macOS 12.7.6 login, one SIMD8
program each of 6,222 to 8,925 instructions with 70 to 221 spills, and the host-load
sensitivity that made the same login's makings 2 to 13 times slower than alone.

Measured on the Iris Xe (Mesa 26.2.6), the dumped modules made by a scratch harness with
the logged specialization, one module of its own per making, the driver's disk cache off:
- the 23,108-word variant alone 0.27 to 0.34 s (jobs 18284, 18292); 11 at once 0.31 to 0.53 s
  each, 0.50 to 0.53 s for all (18293); device robustness on or off alike (18292);
- the 138,047-word fragment module alone 2.03 to 2.42 s, two at once 2.42 to 2.53 s each, four
  at once 2.69 to 3.33 s each (18284);
- under 20 and 30 busy threads on the 20-CPU host, that fragment making 6.27 and 7.94 s, and 11
  kernel makings at once under 20 busy threads 0.78 to 1.44 s each (18293);
- the program counts from INTEL_DEBUG=cs (18226).
The login's own numbers (4.87 s; 1.5 to 4.2 s, 10 or 11 at once; the guest's 1 to 197 command
buffers a second during the making) are the consumer's cold-login log at the 12.7.6 capture; the
3.1 ms warm making is the consumer's warm boot.

Docs only.
2026-11-11 18:36:17 -08:00
Anees Iqbal a58070d630 Docs: a cold making of the 200,000-word compositing fragment module is the driver's own cost
Records, as a known gap, what is left of the Iris Xe's cold login
creations after the records stopped naming attachment formats: the one
compile of the compositing fragment module (203,016 words, macOS
26.7.2) that every state over another format then finds in its record.

Measured with a scratch harness making the module's fragment shader
library cold, the driver's disk cache off:
- ANV, Iris Xe, Mesa 26.2.6: 3.3 to 3.7 s at load ~16 (m3-max-17871);
  its program is 29,101 SIMD8 instructions, 34 spills, 10,585 non-SSA
  registers.
- RADV, Radeon 780M: 1.3 to 3.0 s (m3-max-17958, -18098).
- RTX 3090, 620.70.06: 4.5 to 7.4 s (m3-max-17957, -18097).

Why no translator change: spirv-opt -O (186,314 words) and -O with
frozen specialization constants (180,402) leave ANV's NIR within 0.2%
(27,347 to 27,393 instructions) and its program within 9 instructions,
and their creations are no faster than the original's within the
run's noise (m3-max-18022, -18034, -18127). Holding half values in 16
bits across moves, phis and selects (a scratch pass on the -O module)
makes it 29,719 instructions with 103 spills. So the words the
translator emits do not drive ANV's time; the shader's own work does
(NIR: 4,163 fmul, 2,868 fadd, 1,689 ffma, 1,835 csel, ~290 samples,
30 loops).

VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT: ANV builds the same
program in the same time and the 3090 the same time; RADV takes 0.9
to 1.0 s (m3-max-18098), at a draw cost not measured. Nothing is
built around it. Doc only.
2026-11-11 17:57:53 -08:00
Anees Iqbal d729b77438 FAST-PATHS: on NVIDIA each vkFreeMemory holds the device's other submissions, measured
The known gap the frees' pacing answers in part: tests::import_free_hold_bench on an RTX 3090
(NVIDIA 620.70.06, quiet host, two runs) put a fill's commit to completion at 0.13-0.14 ms beside
no free, 0.46-0.54 ms beside runs of 512 KiB pointer or dma-buf imports freed one after another
(each free 0.26-0.39 ms), 2.6-2.9 ms beside 64 MiB imports (2.2-2.4 ms each), 1.2-1.6 ms beside
512 KiB plain host-visible allocations (1.1-1.2 ms) and 70-79 ms beside 64 MiB ones (28-30 ms);
paced, 0.10-0.32 ms beside every kind. An RTX 2080 on a loaded host showed pacing lower the median
beside every kind too. What stays open: a program's own release of a no-copy buffer frees its
import there (Metal's contract), unpaced, as does a completed command buffer's handler that frees
the imports its blits held last; one free still holds a submission that meets it.
2026-11-11 17:54:27 -08:00
Anees Iqbal 515367b8f2 FAST-PATHS: the XTX's submission times beside surfaces over dma-bufs
submit_per_surface on the RX 7900 XTX, three runs at the tip: 128 surfaces list
256 dma-bufs (108 to 109 us in the ioctl) while in use and 128 after their idle
window (59 to 70 us). Text only.
2026-11-11 17:14:21 -08:00
Anees Iqbal e2c31d54e4 FAST-PATHS: what RADV lists in each submission, and what a texture in place over a dma-buf keeps
The idle-release bullet says a texture in place over a no-copy buffer leaves
the buffer's import to the release (its blit reads the buffer as any blit), with
the 780M lane's counts (submit_per_surface, three runs: 128 surfaces list 256
dma-bufs while in use, 128 after the idle window). A known-gap entry records the
per-entry cost the raw probe measured on the 780M and the XTX (0.43 to 0.44 us
per dma-buf import per kernel submission), what Vulkan offers that does not
change it (memory priority, no device address, no pageable extension listed),
that separate submission calls list every import again, and that each in-place
texture's own image import stays listed for its life (RADV requires a dedicated
allocation of such an image).
2026-11-11 17:14:21 -08:00
Anees Iqbal 9c766f63d0 Docs: an RTX 3090 saturates logicOp's out-of-range integer outputs too
The logic-operation lane on an RTX 3090 (driver 620.70.06, job
m3-max-17707, at bdb59d55de): every out-of-range integer channel
(RGBA8Uint, RGBA8Sint, R16Uint, RG16Sint under xor and and) stores Metal's
saturated code through Vulkan's logicOp and through the fragment
function's operation, as on lavapipe. The FAST-PATHS known-gap row and
the private_state docs name both measured devices. No note: the spec
leaves the value undefined, and neither device differs from Metal.
2026-11-11 15:44:59 -08:00
Anees Iqbal e393b10cb7 Half + - * on the device's 16-bit arithmetic take the AIR's own contraction
A half fadd, fsub or fmul on the device's 16-bit arithmetic (ArithStrategy::F16:
MoltenVK, measured, and the float-controls profiles) was always kept apart: a
sum or difference decorated NoContraction and a product as Fma(a, b, -0.0)
decorated NoContraction, whatever the AIR's flags allowed. That holds Metal's
exact half bits at the cost of every fusion the flags allow (AGENTS.md rule 1:
the device's native arithmetic). It now decides as float does (contraction()):
an operation whose flags carry both contract and reassoc is undecorated, its
product a plain OpFMul, and the device's compiler groups and fuses it; any
other keeps today's form.

Notes mirror float's: note_rewrites already records FastMathRewrites where a
neighbour can be rewritten. On MoltenVK, Metal's fast compile folds an
undecorated 16-bit operation's conversions away and answers the float result
unrounded (the MetalHalfArithmetic measurement), so there a fast operation
records FastMathRewrites, whose doc (and docs/API.md's catalogue entry and the
FAST-PATHS device-gap row) now says so, and requires no MetalHalfArithmetic,
which the kept form still requires.

On an owned proxy (hnq_half_layer_composite) on the Iris Xe, the step-1
prototype of this form cut the SIMD8 cycle estimate from 58584 to 33092.

Tests: f16_binary's rounded-result and one-instruction tests under both
contractions; half_arithmetic_on_the_device_takes_the_airs_contraction
compiles fast, contract-only and flagless half + - * on every profile that
computes them in 16 bits and checks the instruction, its decoration, the note,
the requirement and the interpreted answers.
2026-11-11 15:37:33 -08:00
Anees Iqbal 256867fc33 Docs: copied host buffers' gem10 cost figures cover the run at the read-back tip too
The 256 MiB bench at the two-pass comparison's tip (gem10, job 17674, load 6-7) took
5.9-6.1 ms each way where nothing changed, 26.1-26.4 ms in and 26.7-27.3 ms back where
every byte changed, and 25.9-27.5 ms (47.4 without masked stores) for the GPU's rewrite of
every float, the snapshot 15.4-15.8, 146-152, 206-215 and 280-289 ms beside it: the ranges
in FAST-PATHS and copied.rs's module docs now cover both runs. And a module-doc line past
100 columns is wrapped.
2026-11-11 15:32:27 -08:00
Anees Iqbal edbd81a4df Docs: a copied host buffer's device base, its host blocks and its reads back on the staging queue
FAST-PATHS' base bullet gives the host's uncached reads of a device base (9-16 us a block
awake, 170-206 us idle on the RTX 5080 Laptop GPU's host), the blocks kept on the host, the
read back of 32 blocks or more on the staging queue with the crossover bench's figures on
the 5080 and the RX 7900 XTX, the GPU's wake from power-down a copy may wait for, and the
first and later merges back of a 256 MiB copy both sides wrote whole. Its cost bullet gives
the quiet gem10 run's figures (job 17408), and its kernel bullet the 5080's pass figures
(job 17417). HOWTO and API.md name copied_base_host_blocks and
copied_base_blocks_read_back.

Earlier commits 4af4a8665b and 7a93903404 carried doc edits with their code (the split's
sentence in API.md and HOWTO, copied.rs's cost bullet).
2026-11-11 15:32:27 -08:00
Anees Iqbal 9a14d3f38a Docs: FAST-PATHS states what a missed tag undoes at a completion, and the merge's byte both sides wrote
The merge back compares each block the GPU changed with the pages' own bytes where
their tag agrees, so a CPU write in such a block that the tag missed (at most 2^-64
a block a comparison) is undone where the GPU did not change its byte. A byte the CPU
writes while the merge runs keeps the CPU's or the GPU's.
2026-11-11 15:32:24 -08:00
Anees Iqbal fbbf6322a1 Runtime tests: the 256 MiB copied bench prints the bytes copied in and merged back, and their rate 2026-11-11 15:32:22 -08:00
Anees Iqbal 1396cad799 NativeLogicOperation: Vulkan's logicOp on a signed normalized format's own codes is recorded
Post-merge evidence m3-max-17539 (msi, lavapipe lane at 0103821834) failed
the_logic_operation_over_a_signed_channel_s_lowest_code: Vulkan's logicOp
over an RGBA8Snorm channel holding 0x80 stored the operation of the raw
code (xor of 0xe0 gives 0x60, equivalence 0x9f) where Metal reads 0x80 as
0x81 and stores 0x61 and 0x9e, through a pipeline that recorded no note.
The Vulkan specification's logical operations take "the color attachment's
R, G, B or A component value", the stored code itself, so this is the
device's native form (rule 1): it stays, and is recorded.

lower::fragment::logic::vulkan_differs replaces widens as the test
note_vulkan_codes applies: a 10-bit unorm format, or any signed normalized
one. Docs: PrecisionNote and Degradation docs, API.md catalogue, the
FAST-PATHS known-gap row (now also citing the spec's "undefined" for
integer outputs past the channel's range, which lavapipe saturates as
Metal does, so no note), private_state and logic module docs, the
conformance replay bullet.

The unwritten-channel half of the item (masked channels, and no-op, which
draws unwritten, keep 0x80 where Metal stores 0x81, in both lavapipe forms)
is the existing snorm-minimum-kept notice: Metal's pass writes each tile
back through its values. The lane now accepts a kept lowest code only
where the device announced snorm-minimum-kept, and the integer test fails
any non-Metal answer that comes through no NativeLogicOperation pipeline.

Tests: the translator unit test
vulkan_s_operation_differs_on_10_bit_and_signed_codes_alone, the engine
test's lavapipe assertions (RGBA8Snorm and R16Snorm xor noted). Evidence
jobs follow on lavapipe (both forms) and the translator suite.
2026-11-11 15:06:23 -08:00
Anees Iqbal 93281ffc68 PrecisionNote::NativeLogicOperation: Vulkan's logicOp on a 10-bit format's own codes is recorded
Metal's private logic operation into RGB10A2Unorm and BGR10A2Unorm widens each channel's codes to
16 bits, operates and narrows back (probe logic_operation, M3 Max). A device with Vulkan's
logicOp draws with Vulkan's operation, the device's native form (rule 1), which works on the
10-bit codes themselves and can store another code (lavapipe's xor: green 938 where Metal's rule
gives 937). docs/FAST-PATHS.md's known-gap row ended "No note records it".

DeviceColorConversion could not carry it: every device that has logicOp (lavapipe, RADV, ANV,
NVIDIA) already records that note for any float write into a unorm attachment, so it would
neither tell this difference apart nor be absent where the fragment function computes Metal's
rule. So a new note, NativeLogicOperation (degrade code native-logic-operation, a native note):
the render pipeline's fragment stage records it exactly where Vulkan's logicOp operates on an
attachment whose codes Metal widens (lower::fragment::logic_widens, structural on the channels'
write rules: the 10-bit unorm formats), that a first output writes (GraphicsState::color_outputs)
with a channel its write mask keeps. The runtime announces it through the stage's notes, as every
note. The fragment function's operation records none.

Docs: FAST-PATHS's known-gap row names the note; API.md's catalogue gains the entry; the
conformance suite's NATIVE_NOTES and the validation comparison's allowance (unbounded) class it;
api_signatures.tsv re-blessed. REFUSALS unchanged (refusal_surface.py --check passes).

Tests: engine_private_render_state's logic test asserts the note on lavapipe's Vulkan xor into
RGB10A2Unorm and BGR10A2Unorm, and its absence for RGBA8Unorm, RGBA8Snorm, R16Unorm and
RGBA16Float, under copy, with an empty write mask, at an attachment no output writes, on MoltenVK
(the function's operation) and on lavapipe without logicOp; logic::tests the widened formats; the
lane runtime_lane::logic_ops asserts the note on each draw it counts as the 10-bit codes' own and
that the device announced native-logic-operation exactly where it has logicOp.

Verified: cargo fmt; scripts/api-signatures --bless; refusal_surface.py --check. Builds and
tests follow as potluck jobs.
2026-11-11 14:34:30 -08:00
Anees Iqbal 72834578f0 Docs: the dma-buf stall's runs with the form and type order on the RTX 5080 Laptop GPU
docs/FAST-PATHS.md's NVIDIA dma-buf stall bullet adds the result of the form and type order with a
kind's first imports one at a time on 615.71.09: 6 of 6 four- and eight-thread probe runs ended on
the RTX 5080 Laptop GPU, in 8 to 9 s each (potluck m3-max-17361, three runs of each probe, at
branch steelbrain/nv5080fails-serialform, which carries this branch's code on the earlier base).
Before it, with the type order alone, both probes stalled in their first run (m3-max-17118); with
every import serialized and the type order alone, 2 of 4 runs failed (m3-max-17296).

The stall stays open for a kind's first imports, which still try a refused form or type.
2026-11-11 14:24:49 -08:00
Anees Iqbal c6371eebfe dma-buf: an import tries first the form and type its kind last imported as
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09) the four- and eight-thread leak probes still
stalled with the type order alone. A failed import there can spin inside vkAllocateMemory while
holding the driver's lock. With every failed import printed (potluck m3-max-17206, a scratch
commit that also tried no host-visible type), 4346 of the probe's 6000 imports failed first: type
0, dedicated to nothing, ERROR_OUT_OF_DEVICE_MEMORY, for udmabufs of scattered pages from 16 KiB
to 63 MiB. Each then succeeded dedicated to its buffer. The type order cannot remove these,
because they are a refusal of the form, not of the type. Locking every import alone did not stop
the stall either: 2 of 4 runs still stalled, every import failing twice before it succeeded
(m3-max-17296).

The order extends from type to form and type. Each kind remembers the form (dedicated to its
buffer or not) and the type its last import succeeded as (Memory::dma_buf_imported_as), and
tries that pair first. Every other pair is still tried after it, in today's order. worked_first is
generic over what it orders. On 615.71.09 a no-copy buffer's imports then go dedicated first and
no longer fail in steady state. On 620.70.06 the pair is (dedicated to nothing, type 0), as
before. The import's third value now says whether the memory is dedicated to its buffer, made so
now or because an earlier import of its kind found that form
(WorkCounts::dma_buf_buffer_imports_dedicated counts the same imports). The dedicated-allocation
info is renamed so that it no longer shadows the attempt's form.

docs/FAST-PATHS.md records 615.71.09's refusal of the form, the order, the first-import lock, and
the stall's runs on 615.71.09.

Test: memory::a_dma_buf_import_tries_the_form_and_type_its_kind_last_imported_as_first covers
the pairs: a buffer's attempts with the dedicated form put first, and with the undedicated form
put first; a shared import, which has no dedicated form; and the type cases as before.

Verified at this change's sources (branch steelbrain/nv5080fails-serialform, which carries the
same code on the earlier base):
- CPU: 31 of 31 tests pass (potluck m3-max-17327).
- RTX 2080: 31 of 31 touched tests pass (m3-max-17331), including host_ram_dma_buf x12 and
  no_pointer_import x2, which cover the dedicated retry. The probes ran in 28.8 s (four threads),
  56.8 s (eight threads) and 16.8 s (one thread).
- RTX 3090: 31 of 31 pass (m3-max-17358). The probes ran in 41.7 s, 69.2 s and 18.0 s.
2026-11-11 14:24:48 -08:00
Anees Iqbal a334ecbef2 FAST-PATHS: the 10-bit gap as the lane measured it on lavapipe
Job m3-max-17323: under lavapipe's logicOp the lane's xor and equivalence draws into
RGB10A2Unorm (blended and not) store exactly the per-channel texel, 4 draws, where Metal's
rule widens the codes to 16 bits.
2026-11-11 14:18:20 -08:00
Anees Iqbal 9873d6cfed Logic operation: RGB10A2Unorm and BGR10A2Unorm on 16-bit codes, as Metal's
The probe (job m3-max-17294 on the M3 Max) confirms Metal's rule for the 10-bit unorm formats at
all 12,800 texels of its formats and masks cases: each stored code widened to 16 bits
(round(d * 65535 / max)), the operation on it and the output's 16-bit code, the result narrowed
back to the channel's code. The fragment function's operation now computes it as a 16-bit
channel's (logic::channels answers 16 for a 10-bit or 2-bit unorm channel), the device's write
narrowing the result, so these formats are no longer refused under the function's operation.

Vulkan's logicOp, which a device that has it draws with, operates on the 10-bit codes
themselves: recorded as a known gap in FAST-PATHS. The lane now checks Metal's rule for
RGB10A2Unorm and counts apart the draws that store exactly the per-channel rule's texel under
Vulkan's operation. Translator tests: RGB10A2Unorm compiles under the function's operation on
MoltenVK and on lavapipe without logicOp; B5G6R5Unorm is refused there.

Not yet built or run.
2026-11-11 14:18:20 -08:00
Anees Iqbal 606ad972c2 Logic operation: lanes without indexing, docs for the function's operation
The per-lane loop zips the format's channels instead of indexing them (clippy's
indexing_slicing in lower). FAST-PATHS's known gap now names what the function's operation
still refuses, and API.md's DeviceColorConversion entry names the operation's conversion.
2026-11-11 14:18:19 -08:00
Anees Iqbal 52bf0c4f13 dma-buf: hand the driver its descriptor at a kept number, and try first the type a kind last imported as
dma_buf_leak_4_threads ended in SIGABRT and dma_buf_leak_8_threads in a GPU recovery
(GpuRecoveryVictim) on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, round job m3-max-16620 at
600b535875). On the RTX 3090 (620.70.06, round job m3-max-16728) dma_buf_leak_8_threads ended on
Rust's I/O safety check, with "owned fd already closed" in import_dma_buf's drop of its clone.

The cause is the driver's handling of a failed import. NVIDIA lists a udmabuf of host pages as
two memory types, 0 and 4 (host-visible, coherent, cached), and refuses every import as type 4
as out of device memory. The runtime ranked type 4 first. strace -f -k under the eight-thread
probe on the RTX 2080 (620.70.06, potluck m3-max-16817) showed that every failed import closed
the descriptor it was handed. Vulkan gives the descriptor to the driver only on success. In 3
of 10 failed imports the driver closed the same number twice within the one call, with two
more opens of /dev/nvidiactl between the closes. The kernel gives a new descriptor the lowest
free number, so between the two closes another thread's new udmabuf took the number, and the
second close closed it. That thread then imported a third thread's dma-buf under the number,
and the process aborted on the I/O safety check.

- handed_descriptor.rs: an import hands the driver a clone at a number kept for imports in
  flight. The range is the 64 numbers below min(soft RLIMIT_NOFILE, 65536). The clone is taken
  with fcntl(F_DUPFD_CLOEXEC, n) and kept only where it landed on n itself, never by dup2, and
  no two imports in flight hold the same number. So a number the driver closes stays free until
  the import returns, and a second close reaches nothing. After a failure, the number is still
  the import's alone, so whether the driver left it open is read without a race and, where it
  did, it is closed. That also ends the leak of one descriptor per failed import on a driver
  that leaves it open. Where the limit is under 256, the process holds the range itself, or
  more than 64 imports are in flight, the clone is an ordinary one: correct, but unprotected,
  and a failed import lets it go rather than close a number that may be another's by then.
- memory.rs: each kind of import (what it backs, and its memory class) remembers the type it
  last imported as, and the next import of that kind tries that type first (worked_first). Every
  other type is still tried after it, in today's order. In steady state this avoids the import
  the driver refuses, along with its closes and the stall below.
- docs/FAST-PATHS.md, known gaps: the type listing and refusal, the closes, the kept numbers and
  their fallback, and the stall. A failed import can spin inside vkAllocateMemory holding the
  driver's lock: 3 of 7 four-thread runs on the RTX 2080 alone, and one on the RTX 3090. It
  stays open for the first imports of each kind, which still try type 4.
- tests/dma_buf_fds.rs (device test): what a driver does with the handed descriptor, for each
  type, size and form. It checks that no number the driver let go of is closed again later. A
  let-go number is taken by F_DUPFD_CLOEXEC and watched only where the clone landed on it.

Tests: handed_descriptor (CPU) drives Handed with stand-in imports. One driver closes the
number twice with another thread's open between the closes. Another leaves the clone open on a
failure. Imports in flight each hold a number of their own. A test covers the range for low,
high and unlimited limits. Two cover the fallback: the clone with no number kept, and a range
the process holds itself. memory::a_dma_buf_import_tries_the_type_its_kind_last_imported_as_first
covers the ordering.

Verified:
- The handed_descriptor tests fail with ordinary clones (potluck m3-max-17034, a scratch commit)
  and pass with the kept numbers on CPU (m3-max-16978) and in the RTX 3090 (m3-max-17024) and
  RTX 2080 (m3-max-17076) runs, NVIDIA 620.70.06. Each of those runs passed 15 of 15 touched
  tests. dma_buf_leak_4_threads ran its five rounds in 39.6 s on the 3090 and 31.2 s on the 2080,
  and dma_buf_leak_8_threads in 64.9 s and 58.2 s. dma_buf_fds on the 2080 took 12 numbers the
  driver let go of: none was taken by another descriptor first, and none was closed again.
- The stall, with the type order: eight four-thread runs in a row ended 8 of 8 on the RTX 2080
  (m3-max-17077) and 8 of 8 on the RTX 3090 (m3-max-17065). Without it, 3 of 7 stalled on the
  2080, and the 3090 stalled in m3-max-16941. The kernel logged 28 and 30 refusals of the
  host-visible import over the eight runs (3 to 4 a run): the first imports of each kind.
- Lint: clippy with all features, with --cfg m2v_gpu and with --cfg m2v_cpu_icd, and Rustdoc,
  all clean (m3-max-17066).
2026-11-11 12:48:58 -08:00
Anees Iqbal a379f41e0b Docs: the unshared hold's measured benefit and cost, and a queue with no run seen
FAST-PATHS's row for unshared_isolation, API.md's bullet, the policy's Bounded doc and
unshared_hold.rs's costs now say that a batch of a queue with no run seen holds the others back
until it completes, and give the owned workload's numbers (queue_share frames --unshared, Off
against Bounded): the Iris Xe (m3-max-16880, -16885) and the Radeon 780M (m3-max-16900), the
compositor's median and worst waits, the application's rate and GPU idle on a quiet host, and the
loss under host CPU load (the hold's 2 ms of slack against Off's queued batches). Bounded stays the
default on every one-graphics-queue driver.
2026-11-11 12:03:50 -08:00
Anees Iqbal 478e0aa494 Docs: the unshared isolation switch, and the one-graphics-queue gap narrowed to what a submitted batch holds
FAST-PATHS: unshared_isolation's two values under the switches whose default is Metal's (not an
accuracy choice: it trades other queues' submission ahead for the unshared queue's wait); the
known gap now says what stays true under Bounded: a submitted batch runs to its end, so a
compositor still waits for the whole of a long one, and neither a second VkDevice nor splitting is
built. API.md section 5's policy list, the runtime README's unshared queue entry and
new_command_queue_unshared's rustdoc say the same.
2026-11-11 12:03:49 -08:00
Anees Iqbal 4148882774 DontCare depth and stencil: separate textures' stored aspects take the single texture's answer; no NaN clear value
Separate depth and stencil textures loaded DontCare and stored. The pass renders them through a
scratch image whose aspect loaded DONT_CARE, and the copy back wrote the scratch's undefined bytes
over the render area. Metal (M3 Max, macOS 27.0.1) leaves the same as in one combined texture,
each aspect apart: its texels in a pass whose draws reach no tile, the clear value in the 32x32
tiles a writing draw touches, its texels elsewhere. Such an aspect now takes the single texture's
answer in the scratch image (`clear_reach::dont_care_loads`): it is copied in, and the tiles the
draws' viewports and scissors reach are cleared on the scratch image after the copy
(`ReachClears` over the render area). The copies are now planned after the reach clears' loads.
An aspect that cannot be copied in (`depth_stencil_scratch::copies_in`: a multisampled one copied
by draws, whose copy in needs a sampled texture and draws its store does not) clears over the
render area and announces dont-care-load-tiles.

A DontCare load's clear depth. Metal clamps one outside [0, 1] and stores a NaN as 0x7fc00000
(32-bit float) or 0 (Depth16Unorm); its API validation stops such a pass. The runtime clamped at
begin, but a NaN reached VkClearDepthStencilValue wherever a DontCare load turned into a clear
(single textures since RUNTIME_VERSION 2045). Now a Depth16Unorm clears to 0, Metal's answer, and
a 32-bit float depth to 1.0, the value Metal's test orders a NaN nearest, announced
signed-depth-test, as nan_clear does where it cannot write the word. A Depth16Unorm cleared so at
a depth the device may round above Metal's truncation announces unorm-depth-rounding, as a Clear
load's does.

Docs: clear_reach, depth_stencil_scratch and nan_clear module docs; the dont-care-load-tiles and
signed-depth-test rustdoc and docs/API.md catalogue entries. docs/FAST-PATHS.md's known gaps
gains one measured in the same probe: a draw that neither tests nor writes the depth and stencil
leaves Metal's texels in the tiles it touches, where the runtime clears them, for one texture and
for separate ones alike.

Run: the previous commit's lane tests on lavapipe and the M3 Max, before and after this commit.
2026-11-11 11:49:18 -08:00
Anees Iqbal bf64da677d FAST-PATHS: the cost of a two-copy Managed no-copy buffer, with its bandwidth; two known gaps
Costs of matching Metal: a Managed no-copy buffer without unified memory holds device-local
memory of its size and copies across the bus (at the making, each rebind, each
did_modify_range's range, each synchronize). managed_bandwidth (release, 256 MiB read and 256
MiB written a command buffer): RX 7900 XTX (RADV) 11.3-11.4 GB/s in the pages before,
864.6-866.8 after; RTX 2080 2.7 before, 395.6-396.0 after; Shared no-copy (control) unchanged
at 11.3-11.4 and 2.7; Private 865.0-867.3 and 395.6-396.0.

Known gaps: read-only pages keep the GPU's writes until the writing command buffer completed
(the undo at completion); a synchronize encoded before a rebind copies to the old pages.
2026-11-11 11:22:54 -08:00