Commit Graph
1021 Commits
Author SHA1 Message Date
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 78835b832a Docs: REFUSALS and the API table for the function's logic operation; the probe's findings
docs/REFUSALS.md regenerated: PrivateRenderState's reach names the three features of the
operation's refusal on a device that orders fetch in neither form. The signature table gains
LoweringInputs::logic_operation and RuntimeInput::LogicOperation. The probe's header states
what it measured on the M3 Max.
2026-11-11 14:18:19 -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 294a947dee Docs: an exit handler's work answers Exiting for a making not begun, without a claim about that work's end
The accepted difference said the work that needed such a making fails; what
that work's command buffer then answers was not run. It now says what was run:
the making answers that the process is exiting.

Verified: docs only.
2026-11-11 14:01:46 -08:00
Anees Iqbal 1421ecb9f5 Exit guard: a run of the hook after a making ends the makings and leaves the guard open
An exit handler a program registers once its device is made (the consumer's exit
gate) commits work at exit and waits for it, as Metal's exit runs it. The runtime
registers its hook again after every pipeline making, for the destructors the
driver's compiler registered in it (the 5080's SIGSEGV in libnvidia-glvkspirv.so,
lavapipe's LLVM destructors), so with any making after the handler the hook ran
first, closed the guard, and the handler's wait answered Exiting: the exits
lane's handler_work_exit failed 3 of 3 on the 3090 (m3-max-17079).

Each registration now carries what it follows (exit_guard::After: the argument
of on_exit on glibc, of __cxa_atexit elsewhere), and its run ends what the
destructors registered just before it may break:
- after a making (pipelines_made, the 2 ms registrar): the run ends the makings
  (Guard::end_makings) and waits for those in progress in sections, at most
  MAKING_BOUND, as the close did; no making begins after, on any thread
  (driver_making answers None, and the makings' callers WaitWouldDeadlock of
  DeadlockCause::Exiting). The guard stays open, so the program's handlers
  registered before that making run with the runtime's threads.
- after a device, an instance or a section's first call: the full close, as
  before.
- beside a live CPU device (lavapipe, SwiftShader), whose queues compile as they
  run their work, a making's run is a device's (the close): measured before, a
  queue's compile beside the exit's destructors ended 5 of 300 lavapipe exits.
  handler_work_exit expects that there (hook_ran=1, Exiting), and docs/API.md
  records it as an accepted difference, with the making a handler begins.

Tests (runtime, exit_guard): a_making_s_run_of_the_hook_leaves_the_program_s_
handler_the_guard_open, the_device_s_run_of_the_hook_closes_the_guard_after_a_
making_s_run, a_making_s_run_of_the_hook_closes_the_guard_beside_a_cpu_device,
the_makings_end_once_those_in_progress_ended_and_none_starts_after,
a_making_s_run_ends_the_makings_alone_in_its_own_process; the makings' earlier
tests keep their meaning (a_pipeline_making_that_returned_registers_the_hook_
again now sees the makings ended and the guard open). The exits lane's
handler_work_exit is the contract test.

Verified: cargo fmt only locally; build, lint and runs are potluck jobs.
2026-11-11 14:01:45 -08:00
Anees Iqbal a6224415d1 Docs: the memory log names a placement that takes a kept dedicated block
METAL2VULKAN_LOG_MEMORY's registry entry and docs/API.md now name the line
the log writes where a placement takes a kept empty dedicated block, which
allocates nothing (memory.rs's place_kept_dedicated).
2026-11-11 13:20:44 -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 0515036720 Docs: rewrap the detached contents paragraphs (API.md, the runtime README)
Text unchanged; lines held to the files' width.
2026-11-11 11:22:54 -08:00
Anees Iqbal 07a21899ed Runtime: contents of a detached no-copy buffer answers the caller's pointer of the pages it lay in last
Metal's contents answers the last pointer across a detach (the caller's pointer of the last
replace), and the consumer's host library expects contents unchanged across detach and
replace; the runtime answered None. Buffer::contents now answers that pointer while a no-copy
buffer, a two-copy Managed buffer (either host copy route) or a no-copy heap's buffer is
detached. The runtime itself reads and writes nothing through it: every internal caller takes
the new crate-private mapped_contents, which keeps the old answer (None while detached), and
buffer::Detached keeps the old mapping's address only to answer contents.

Tests: tests::detached_contents (Shared and Managed no-copy buffers, and a no-copy heap's
buffer) maps the pages with no access while detached and runs a blit and a synchronize of the
buffer; managed_copy_device's detach legs and the validation detach lane assert the pointer.
Docs: Buffer::contents, detach.rs, docs/API.md, the runtime README.
2026-11-11 11:22:54 -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
Anees Iqbal 9b5f3d224a Bless the API signatures (HostBacking::DeviceCopy, the managed counts); regenerate REFUSALS.md 2026-11-11 11:22:53 -08:00
Anees Iqbal ad904b20cd FAST-PATHS: a texture over a two-copy Managed no-copy buffer is over its GPU copy 2026-11-11 11:22:53 -08:00
Anees Iqbal f0cdff884d Runtime: a two-copy buffer's rebind makes a new host copy; a texture leg; the docs
A rebind of a Managed no-copy buffer with a device copy makes a new host copy
of the new pages as the making does (an import made as HostCopy, never a
copied.rs copy, or the pages alone), in place of the old, which goes once
nothing holds it, and copies the pages in whole: a rebind whose import the
gate refuses no longer stacks a copied host buffer under the device copy.

Tests: a texture over a two-copy buffer follows its device copy (its GPU
reads after the making, did_modify_range and replace_region, and its
synchronize_resource).

Docs: the runtime's guide (the memory model, host memory without a copy,
host_backing, the recovery), docs/API.md (the two-copy paragraph beside the
Managed device-copy textures, which now reach only buffers that lie in their
pages, and device-memory-overflow), HOWTO (copied host buffers: a two-copy
buffer is never one; did_modify_range is the contract).
2026-11-11 11:22:53 -08:00
Anees Iqbal d3ab77f844 Runtime: take resource option bit 20 as Metal takes it
Bit 20 (0x100000) is an option no Metal header names, of unstated meaning,
which programs pass with their buffers' options (0x100010 for a Managed
no-copy buffer). ResourceOptions::from_raw refused it as undefined, so such
a buffer could not be made at all.

Measured with probes/resource_option_bit20.m on an M3 Max (macOS 27.0.1)
and a Radeon Pro 5300M (macOS 26.7.1), plain and under API validation:
buffers of a length, of bytes and over the caller's pages are made with it,
of every storage mode, and report their options without it; so do a heap
and a heap's buffer (API validation stops the heap's buffer); a texture
descriptor with it ends Metal's process.

So from_raw takes it (ResourceOptions::BIT_20), every buffer and heap maker
drops it (own_memory_options, no_copy_options, take_options, a heap's
new_buffer), and texture_options refuses it as it refuses bit 24 there.
Nothing reads it. docs/API.md states both halves; api_signatures blessed.

Tests: values::bit_20_is_taken_and_dropped_apart, and the device test
option_bit_20 (buffers, no-copy, heaps and their buffers report without
it; a texture descriptor with it is Invalid). Not yet run.
2026-11-11 11:22:45 -08:00
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 56c25f8b7a Runtime: a host step's recording keeps the takes of the one it replaces; a dropped command buffer gives its takes back
A tiled texture's copy taken at use was lost in two places where nothing ran it:

- Work the commit recorded and a host step records again (an execution of indirect commands the
  CPU wrote since the commit): the step's cores decided by the mark, which the commit's recording
  had cleared, so the recording that runs took no copy and the texture read stale levels. Now the
  step hands the replaced recording's takes to the cores it records into (State::step_takes, read
  by EncoderCore::segment_raw, under the step's turn): ShadowSync::over follows each decision
  that recording made, keeping its take and number, and decides a use it never met by the mark.
  As the step's recording replaces the commit's, a take of the commit's it never met is given
  back (Takes::give_back_unheld). TakeBy::Mark carries the replaced decisions; a core with none
  decides as before.
- A command buffer dropped without a commit kept its encoders' takes. Its drop now gives back
  every take of its ended encoders and of its segments' recordings while its status is still
  NotEnqueued.

Unit test tests::shadow::a_recording_in_place_of_another_keeps_its_takes covers the follow, the
by-mark decision of an unmet use, the give-back of an unmet take and of none kept, and a kept
no-take after did_modify_data. The device legs are in the previous commit. docs/API.md's tiled
texture paragraph says both.
2026-11-11 10:02:16 -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 f3f6696eb9 An unstored DontCare load in a pass that draws clears, as Metal's draws read it
Metal (an M3 Max, macOS 27.0.1, lane dont_care_unstored): an attachment a pass loads `DontCare`
and does not store reads zero (a color) or the pass's clear value (a stencil) wherever the pass's
draws read it, never its earlier texels. The runtime left such an attachment `DONT_CARE`
(clear_reach::dont_care_loads skipped every attachment the pass does not store): the first
instance's DONT_CARE load read 0 for the stencil (MoltenVK names no clear value there), later
instances of a split pass LOAD what the first left, so the tiles it did not reach read the
earlier texels, and a color the only instance leaves out (fetched through the pixel interlock)
read its earlier texels everywhere.

Now such an attachment (not memoryless, not separate depth and stencil textures) takes `Clear`
in a pass whose draws reach a tile: zero for a color (dont_care_clear), the attachment's clear
value for depth and stencil, by the first instance's load operation over the render area, and a
color that instance leaves out is cleared before the pass by the existing path for cleared
storage colors (cleared_ahead, or the reach pass over the render area). It is not tile-bounded
and not announced: no fragment reads a tile no draw touches, so the answer is Metal's wherever it
is read. `dont-care-load-tiles`' text, rustdoc and catalogue entry are scoped to stored
attachments; clear_reach.rs records Metal's measured answer and the rule.
2026-11-11 09:59:04 -08:00
Anees Iqbal 2fc317f6e3 Translator: OpenCL-mode image arguments reflect as the textures bound, of no data type
What: AIR names an OpenCL C image's component `unknown` (`texture1d<unknown, read>`), which the
reflection's type grammar did not parse, so a pipeline of OpenCL mode with an image argument had
no reflection (Unsupported, Feature::Reflection, naming the type). Now:
- reflection/types.rs: a texture whose component AIR names `unknown` reflects data type
  DataType::None;
- canon::opencl::entry, the entry as a pipeline of OpenCL mode binds it: a 1D image's texture is
  the 2D one Metal's OpenCL binds (`texture1d<..>` -> `texture2d<..>`, `texture1d_array<..>` ->
  `texture2d_array<..>`, bound_texture), as canon::opencl_1d already reads it, so its binding
  reflects TextureType::Type2D / Type2DArray.
Only the reflection reads an argument's type name; lowering and binding are unchanged.

Why: Metal states exactly that. The probe opencl_image_reflection on the M3 Max (macOS 27.0.1,
job m3-max-16390) reflects every image of an OpenCL-mode pipeline as MTLDataTypeNone, whether
read as float, int, uint or half, written, only queried or unused; image1d_t as 2D and
image1d_array_t as 2DArray (as the clmode-images probe found on the M3 Max and a Radeon Pro
5300M). The data type is not the element type a kernel reads: Metal answers None for every one.

Tests: engine_opencl_mode::an_opencl_mode_pipeline_reflects_its_images_as_the_textures_bound_of_no_data_type
reflects an owned fixture (image1d_t arguments read as float, int, uint and half, an
image1d_array_t, a write-only image1d_t, a buffer) and holds each texture binding to the M3 Max's
answer (type, None, access, not depth, length 1) and the buffers to theirs; before this commit
its reflection is refused. reflection::tests::the_type_grammar_names_textures parses the
`unknown` component.

Docs: canon::opencl's module docs and docs/API.md's OpenCL-mode images.

SEMANTICS_VERSION 2033: a reflection the translator refused it now answers.
2026-11-11 09:54:16 -08:00
Anees Iqbal 49175d0a24 Runtime: a copy made after a failed import of no-copy pages names the failure in its notice
What: the copied-host-pages announcement of a no-copy buffer, heap or rebind made a copy because
the import the device and the gate admitted failed (WorkCounts::copied_host_buffers_degraded)
said only "their import failed". It now names the failure (FailedImport::cause in
buffer_descriptor.rs): for pages the runtime kept from a driver whose failed import of
unpinnable pages breaks it (RuntimeDriverDefect::UnpinnablePagesBreakHostMemory, NVIDIA's), that
the kernel cannot pin some of them (a dma-buf's mapping, VM_PFNMAP, or one it could not ask
about), and whether a source of their dma-bufs was asked (none given or the device imports no
dma-buf; or the caller's source made none, or the device refused them); for an out-of-memory or
other Vulkan failure, whose import failed (the pointer's, or the caller's dma-bufs' after the
pointer's refusal) and the error. The copy path carries the failure and whether the source was
asked (CopiedFor::Failed(FailedImport), the rebind's Err(Some(FailedImport))); copied_pages
borrows the error. Nothing else changes: the counts, the copies and every refusal are as before.

Why: on the RTX 5080 the consumer's no-copy buffer over a view mapped through two udmabufs was
copied (copied_host_buffers_degraded 1) with no notice line saying why, and finding the cause took
a round trip.

Docs: the CopiedHostPages declaration and docs/API.md's catalogue entry say the reason names the
cause.

Tests: tests::host_memory::a_copy_after_a_failed_import_names_the_failure (no device) holds the
four causes' words. tests::host_ram_device::pages_refused_before_the_driver_with_no_source_are_copied
now announces each copied-host-pages (DeviceOptions::announce_each) and, on a driver with the
defect, asserts each of the buffer's, heap's and rebind's three reasons names the unpinnable
pages, the defect and that no source was asked, printing each (HOST-RAM-COPIED). Before this
commit each reason was "their import failed", which names none of them.
2026-11-11 09:54:03 -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 a0de370951 Runtime: the pipeline creation log names each compute VkPipeline and its precision notes
METAL2VULKAN_LOG_PIPELINES logged render VkPipelines only, so a consumer reading the log for a
compute state's notes (an OpenCL-mode kernel's native-nan-encoding) found nothing. A compute
variant now keeps its kernel stage while the log is on (VariantObjects::logged, None while it is
off), and each compute VkPipeline it makes logs one line through the device's sink (id name
metal2vulkan-pipeline-creation, Info): the kernel's entry, its SPIR-V (hash and words), each
specialization constant (id, meaning, value), the precision notes the stage holds under that
specialization, and the creation's wall time. No numbering, diff or split: a compute state's
pipelines differ by their specialization alone, which each line prints whole. Nothing is kept
or measured while the log is off.

Docs: creation_log's module docs, env_vars' METAL2VULKAN_LOG_PIPELINES, docs/API.md.
2026-11-11 09:37:09 -08:00
Anees Iqbal e8418615f1 Translator: a storage slot its function only queries binds a swizzled texture unswizzled
A guest's OpenCL kernel that only queries a write-only image Apple's OpenCL binds as a swizzled
view (CL_BGRA over an RGBA8Unorm view, and on an M3 Max every CL_UNORM_INT8 order but RGBA and
RGBx) failed: the plan joins a storage slot to the swizzled-storage variant only where its
function reads or writes texels, so a query-only slot kept the texture's swizzle on its storage
view, which Vulkan cannot swizzle, and the runtime refused the binding
(NotImplemented(TextureSwizzle)). The guest then read zeros.

A query reads no texel, and what it answers (the view's size, levels and layers; an OpenCL
image's order and data type, which the third hidden buffer holds) no swizzle reaches. Measured
on an M3 Max, macOS 27.0.1 (probe opencl_swizzled_images, job m3-max-16336): plain Metal's
get_width/get_height of a swizzled view at an access::write slot answer the view's size, and
OpenCL mode's width, height, order and data-type queries answer the size and the hidden words,
on every swizzle measured. So the plan now binds such a slot's storage view with no swizzle
(ImageViewDesc::shader_swizzle, under no variant): exact.

The same probe confirms the rest of the contract the crate already builds, in plain Metal and
OpenCL mode alike: reads (read(), read_write, sample, read_imagef with and without a sampler)
answer the swizzled texel, and writes (access::write, read_write, write_imagef) store it with
the swizzle undone. The channel order table and the swizzle never both apply: the table answers
queries only, the swizzle moves texels only.

Docs: ImageViewDesc::shader_swizzle, the runtime's binding_view and view_plan, docs/API.md's
OpenCL-mode images. REFUSALS.md regenerated, unchanged.

SEMANTICS_VERSION 2033.
2026-11-11 09:37:09 -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 eddd9112aa Runtime: an encoder encoded again takes a tiled texture's copy where its first encoding took it
A tiled texture of more than one level over a buffer is a copy of the bytes
taken at use: the first use encoded after its making, a did_modify_data or
a level-0 replace_region clears the texture's mark and records the copy in
and the later levels. A rebind of a no-copy buffer (or heap) the encoder
also named, before its command buffer's first submission, encodes the
encoder again and puts that recording in place of the first, which is never
submitted. The encoding again found the mark already cleared, recorded no
copy, and the texture's levels kept zeros or an older copy for good; a
did_modify_data made after the commit was cleared by the encoding again
instead of the next use.

The decision now belongs to the encoding. ShadowSync notes, in order, what
each first use of a copy taken at use decided (shadow::Takes); the ended
encoder's record keeps that with its log, and the core an encoding again
records into (EncoderCore::replaying, fed by reencode.rs through
State::replaying_takes) takes each copy where the use in its place took it,
never touching the mark. Its forget gives nothing back to the mark either.

Other per-encoding state checked for the same shape: the shadow carry (an
encoding again starts with none and copies the truth in, which earlier
encoders copied back to as they ended; drops-writes shadows are never
carried), gated copy-ins and standings (decided at batch submission, which
sees the recording put in place), heap tiled and multisample sample moves
(planned per recording, no mark), and segments recorded again on the GPU
alone or at a host step (their shadow copies were planned by the encoder,
not decided again). None consumes a mark at encoding.

Verified at the parent (66b00df138), lavapipe, jobs m3-max-16324/16333:
all four tiled_texture_reencode tests fail (levels read zero through the
encoding again; the next use after a did_modify_data took nothing). The
new CPU unit test in tests/shadow.rs covers the decisions directly. Runs
of this commit follow in the report.
2026-11-11 09:11:38 -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 c5bd14c18c HOWTO: an import's last holder can be a texture's image; the measured unmap failure is ANV's
Two claims of "Unmapping host memory" cut to their evidence: with neither a deallocator nor a
keep-alive, a texture released while a command buffer submitted before may read it holds the import
until that command buffer completed (HostMemory::new's contract says so); and the failed
submission with the device lost after an unmap is ANV's (host_residency.rs's measurement), not
measured on RADV.

Verified: docs only.
2026-11-11 09:03:24 -08:00
Anees Iqbal b1a1c67f68 Host memory: state when a program may unmap a no-copy object's pages, and test the order
A Radeon 780M under Linux 7.3.3 oopsed in amdgpu's mmu notifier (amdgpu_hmm_invalidate_gfx,
LIST_POISON2 in a bo_va's status list) while a consumer's thread unmapped a view whose pointer import
was still alive; the consumer dropped the import after the unmap. VK_EXT_external_memory_host
(VkImportMemoryHostPointerInfoEXT): "the application must ensure that the imported memory range
remains valid and accessible for the lifetime of the imported memory object". vkFreeMemory: a
bound buffer or image may hold the payload until it is destroyed. So the objects go first and the
pages after.

The runtime already keeps that order, and this commit changes no behaviour. A no-copy object's
keep-alive is dropped, and with none its deallocator runs, only after its import's vkFreeMemory
returned, on whichever thread freed it. That covers the releasing thread, a queue's thread at the
completion of the last command buffer that held it, a handler thread where a keep-alive alone
waits, and the import made again after the residency thread released it while idle. Imports never
go to the free thread. The one exception is a buffer lying in another live buffer's import, whose
own contract keeps the pages mapped.

The order was spread across private module docs. It now has one statement where consumers read:
- docs/HOWTO.md, "Unmapping host memory": the spec's rule, each object's signal, the threads that
  free imports or submit over them, and what an unmap made first did;
- the runtime README's host-memory bullet;
- the rustdoc of HostMemory::new (the spec's rule, and when a command buffer lets go: after its
  completed handlers, before wait_until_completed returns), Deallocator, KeepAlive and
  Device::host_range_remapped. That call's "they may be unmapped" read as a licence to unmap under
  a live buffer; it now says the call does not mend that.

New device test tests/unmap_order.rs (Linux, m2v_cpu_icd or m2v_gpu):
- 48 rounds. Each round covers a released buffer, a buffer released while a committed copy of it
  waits for an event, and (where pointer imports follow their address) a buffer whose import was
  released while idle and made again by a blit. Each case runs with a keep-alive and with a
  deallocator.
- Another thread submits copies between the device's own buffers throughout.
- Each signal reads WorkCounts::host_imports_live, which must already be back at its baseline,
  then unmaps the pages.
- It asserts that the held cases signalled on a runtime thread and not before the event, that the
  idle releases and imports again counted 96 each, and that every command buffer completed with no
  device loss or recovery.
2026-11-11 09:03:24 -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 21a01a4d7b Device creation: a device the driver refuses for want of resources takes its least queue plan once, else Error::DeviceRefused
What: create_on makes the device through made_within_resources. Where vkCreateDevice answers
VK_ERROR_INITIALIZATION_FAILED or VK_ERROR_OUT_OF_DEVICE_MEMORY for the queue plan's VkQueues and
the least plan (LEAST_QUEUE_LIMITS: a round robin of one VkQueue, none reserved for presenting;
the reserved, extra and staging queues kept, as DeviceOptions::queue_limits of one and none
places them) takes fewer, it asks once more with the least plan's. A device made so announces the
new Performance degradation least-queue-plan (Degradation::LeastQueuePlan, naming both plans'
VkQueues and the driver's answer), sends none of the queue limits' informational messages (the
limits are the runtime's, not the caller's), and its presenting queue's shared-present-queue
notice says why it reserved none. A second refusal, or one where the least plan takes no fewer
(RADV's and lavapipe's one graphics queue), is the new typed Error::DeviceRefused(DeviceRefused
{ device, attempts }), naming each attempt's VkQueues and answer; before, it was Error::Vulkan(-3)
or Error::OutOfMemory(Device). Any other failure is the driver's as before. A recovery's new
VkDevice is made the same way.

Why: on an RTX 2080 (NVIDIA 620.70.06) devices of the plan's 17 VkQueues were refused from the
eighth live one, in one process and across processes alike (tests::many_devices at 655ed906fb:
seven made, p8 to p16 refused with VK_ERROR_INITIALIZATION_FAILED while BAR1 had 38 MiB free),
where a consumer measured the GPU's channel heap holding about 160 to 180 channels, raw 16-queue
devices refused from the 11th and 1-queue devices made 24 of 24.

Public surface (api_signatures.tsv blessed): Error::DeviceRefused and DeviceRefused are new, and
Degradation::LeastQueuePlan. A consumer that matched Error::Vulkan or Error::OutOfMemory from
Device::system_default* for a refused device now gets Error::DeviceRefused.

Tests: tests::queue_limits::a_device_refused_for_want_of_resources_is_asked_for_once_with_its_least_plan
(no device: NVIDIA's family shape with a reserved and an extra queue, 18 VkQueues then 4; made at
once, made with the least plan after either refusal, refused naming both attempts, any other
failure the driver's, and one attempt where the least plan takes no fewer). tests::least_queue_plan
(device tests, refuse_next_devices stands in for the driver's refusal on the creating thread):
refused once, a device whose plan takes more than one VkQueue is made with 1 + 0 and announces
least-queue-plan once, its presenting queue's shared-present-queue naming it; refused twice, it is
Error::DeviceRefused with an attempt per plan. Verified on lavapipe (ms01, job m3-max-16047): both
pass on the refused branch (llvmpipe's plan is one VkQueue: "ERROR_INITIALIZATION_FAILED with 1
VkQueue(s)"); the made branch runs on NVIDIA next. scripts/refusal-surface --check passes
(REFUSALS.md does not list top-level Error variants).

Docs: docs/API.md's catalogue entry for least-queue-plan; the runtime README's device opening
(the fallback) and error table (DeviceRefused). RUNTIME_VERSION is the orchestrator's to bump at
landing.
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 e8ce0d2186 Translator: OpenCL mode clamps an integer conversion with .sat
In a compute pipeline of OpenCL mode both measured oracles clamp an
integer converted to an integer with .sat to the destination's range
(probe jobs m3-max-15651 on a Radeon Pro 5300M and m3-max-15652 on a UHD
Graphics 630, macOS 26.7.1, OpenCL C of our own, one work-item per
operand): int and uint to char, uchar, short, ushort, int and uint; long
and ulong to int and uint; ulong to long, long to ulong, int to ulong;
char to uint, uchar to int; and convert_uchar_sat_rte(int). The
translator wrapped (convert_uchar_sat(300) was 44 where both answer
255). Outside OpenCL mode it still wraps, as the 5300M and the 630
answer there (docs/API.md).

ConvertKind::Int carries the destination's signedness where `.sat` is
honored (arith::honored); the conversion first clamps the held source to
the destination's range (math::saturation_bounds: a bound the source's
own range keeps is skipped), by the source's signedness, on native
integers and on the wide pairs, then converts as before.

Tests: every source of 8..64 bits (signed and unsigned) into every
destination of 8..64 bits (signed and unsigned) around each width's
bounds, native (convert_suffix.rs) and wide (wide.rs), on the
interpreter against exact references; the measured int-to-int forms join
tests::engine_convert_rounding's table (OpenCL mode answers both
oracles' words, outside it the wrapped plain answer).
2026-11-11 07:16:27 -08:00
Anees Iqbal 9e6a8b8a96 Translator: OpenCL mode honors air.convert's directed roundings
In a compute pipeline of OpenCL mode (LowerInputs::open_cl_mode, set
from ComputePipelineDescriptor::open_cl_mode_enabled) Metal honors the
rounding Apple's OpenCL compiler spells after a conversion's types.
Measured over OpenCL C of our own, one work-item per operand, probe jobs
m3-max-15651 (Radeon Pro 5300M) and m3-max-15652 (UHD Graphics 630),
macOS 26.7.1: both round an integer of 8 to 64 bits to float by rtz,
rtp and rtn, and a float to an integer of 8 to 64 bits by rte, rtp and
rtn (then saturate), exactly; neither creates an OpenCL-mode pipeline
for a conversion with a half side. Outside OpenCL mode the Macs answer
most of these as the plain conversion (docs/API.md), so honoring there
would leave every Mac's answer: the translator keeps the plain
conversion outside OpenCL mode.

The device has no directed conversion, so each is built exactly:
- float to integer: RoundEven, Ceil or Floor before the existing
  clamp-and-truncate (the NaN test still reads the operand);
- integer to f32 by rtz/rtp/rtn: the device's conversion (correctly
  rounded in a direction of its own), converted back exactly and
  compared with the integer (2^k told by a float compare), then moved
  one unit in the last place in the bits where it lies on the wrong side.
Both on native integers and on the wide pairs (no shaderInt64).
`arith::honored` decides per form; a half side, rte to float and rtz to
an integer stay the plain conversion.

SEMANTICS_VERSION 2030: an OpenCL-mode module holding such a conversion
changes. The function compile key already appends open_cl_mode; its
coverage test now asserts it.

Tests:
- arith/tests/convert_suffix.rs and wide.rs: every directed rounding of
  i16/i32/i64 (and wide i40/i64) to f32, signed and unsigned, and every
  integral rounding of f32 to 8..64-bit integers (both NaN tests), on
  the interpreter against exact references, around 2^24, 2^25, 2^31,
  2^32, 2^63, 2^64 and ties; the brief's oracle words; selection per
  mode (only_a_pipeline_of_opencl_mode_honors_a_suffix).
- tests::engine_convert_rounding: each measured form, compiled in
  OpenCL mode on lavapipe and moltenvk-m3 without shaderInt64, passes L3
  and answers the 5300M's and the 630's words on the interpreter, and
  the same kernel outside OpenCL mode answers the plain conversion.
2026-11-11 07:16:27 -08:00
Anees Iqbal 24b460971e shadowed-texture: state a tiled texture's copy in its cost
The notice's cost said every shadowed texture is copied in before each use and back after each
write. A tiled texture of more than one level is copied in only at its first use and the first
after each did_modify_data, and never back, so its notice stated a cost it does not pay. The cost
string and docs/API.md's catalogue entry now name that form.

Verified: tests::degradation_catalogue (the catalogue states the announced cost) runs in the
lavapipe job of this tip.
2026-11-11 07:11:38 -08:00