Commit Graph
508 Commits
Author SHA1 Message Date
Anees Iqbal ee9e1140b1 API.md: a texture's size never makes a texture over the runtime's own memory a shadow
The clause the bound's removal left read as a trailing participle; it now states the rule.
2026-11-12 01:50:58 -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 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 7c5a452dac Submission checks: a submission that never completes stalls them at 10 s, and the teardown returns
The submission checks' thread waited for each of its fences in 100 ms slices with no end. On the
RTX 3090, with six processes making their devices at once, the kernel logged a pushbuffer error
(Xid 69, Xid 32) and one process's checks waited on their fence for good, its device's teardown
behind them (SubmitChecks::stop waits for the thread). An accuracy-free self-check must not end
a program's work (AGENTS.md rule 2).

Now a wait past STALL (10 s) takes the device as lost for the checks: nothing is submitted again,
what had not answered is Unchecked for the device's life, nothing is recorded, and the sink hears
metal2vulkan-submit-check-stalled. The stalled submission's fence and command pool stay pending,
so the thread leaves them to the teardown, which waits up to STALL more and releases them once the
fence signalled; where it still has not, the teardown leaves the device and its instance to the
process's end (as the exit path does) instead of a vkDeviceWaitIdle that would never return. A
step held whole lets go of the loader word without waiting for the relay mark of a stalled use.
The checks' report now gives their longest wait.

Test: a_submission_that_never_completes_stalls_the_checks_and_the_teardown_returns injects a
submission whose first info waits on a timeline semaphore nothing signals, with a 2 s bound; the
checks settle at the bound, the sink hears it once, nothing is recorded, and the device's drop
returns after the bound with its VkDevice still live; then the test signals the semaphore.

Not yet verified: build, lint, the test runs (to come in the following jobs).
2026-11-11 22:43:20 -08:00
Anees Iqbal 3b986605e3 The host-deallocator-delayed kind announces the wait for a buffer bound inside the import
RUNTIME_VERSION 2083 made a buffer bound inside its pages' import hold the import, so a no-copy
buffer's deallocator given no keep-alive waits for that buffer to go, and docs/API.md's catalogue
entry said so in its cost. The kind's announced cost (Degradation::HostDeallocatorDelayed's) did
not, and tests::degradation_catalogue::a_runtime_kind_s_entry_states_the_cost_it_announces failed
on every device that runs it (pin 44: Iris, m3-max-19132, and the 780M).

The announced cost now carries the same clause, worded 'every buffer bound inside their import
goes' in both, and the kind's own docs list the case beside the others it waits for.

Verified: the degradation_catalogue tests on lavapipe (see the landing report).
2026-11-11 22:28:41 -08:00
Anees Iqbal 3aa410e2ab A device refused for want of resources takes its least plan whatever the code: too many objects and host memory too
vkCreateDevice's answer where the device-specific resources a logical
device needs run out is VK_ERROR_TOO_MANY_OBJECTS (the Vulkan spec,
vkCreateDevice), and a driver short of host memory for the plan's
VkQueues may make a device of fewer: both now take the least plan, as
VK_ERROR_INITIALIZATION_FAILED (NVIDIA's channels) and
VK_ERROR_OUT_OF_DEVICE_MEMORY did. A device refused with both plans
is refused naming each attempt, as before.

Asked for by a device test on an RTX 2080 under parallel test load
(job m3-max-18589) that got OutOfMemory(Host) from
Device::system_default_with, where the least plan's three queues would
have fit: the 2080 held 10 devices of the plan's 18 VkQueues at once,
and 68 of the least plan's 3 (job m3-max-18774).

The pure test of made_within_resources takes each of the four codes.
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 b649078d10 Docs: a buffer bound inside a no-copy buffer's import holds its keep-alive, or its deallocator
The release order RV 2073 brought, in the docs a consumer reads. A no-copy buffer made over part
of a live one's bytes, or over the same bytes as memory of another class, is bound inside the
live one's import (one live import of a page: VK_EXT_external_memory_host leaves a host allocation
imported twice into one device undefined) and holds it, so the live one's keep-alive is dropped
only once both are released and the import is freed. With a keep-alive its deallocator still runs
at its release, as Metal's; given none, the deallocator waits for the free, announced as
host-deallocator-delayed.

- API.md: the host-deallocator-delayed entry names the cause and its cost; section 10 (Heaps and
  memory) records the keep-alive's later drop as an accepted difference, with
  WorkCounts::host_releases_held_inside.
- HOWTO, "Unmapping host memory": the order for a buffer over part of another's bytes.
- The runtime README's no-copy paragraph and KeepAlive's doc name it.
2026-11-11 21:51:08 -08:00
Anees Iqbal 88af28874e Host RAM: an object's own import claims its RAM pages until noted; chunks mark in flight under the claims
The straddle copy (f083e9c806) and the held-back chunk (c55501db1b) each read only finished
state: an object's check read made chunk imports alone (chunks_hold_any), and a chunk's check
read noted object imports alone (the alias registry). So an object made while a chunk's import
was in flight, or a chunk imported while an object's own import was between its checks and its
note, imported the same pages twice. Both tests of 1d77522508 showed it on lavapipe, 3 runs of
3 each (m3-max-18881): imports_inside_live 1.

Each RAM the device uses now keeps the claims of objects' own imports in flight. An object's
making and a rebind claim their window's RAM pages (Device::claim_ram_pages) where no chunk binds
them, and hold the claim through their import until it is noted: where a chunk's import, made or
in flight, holds some of the pages, nothing is claimed and the object is a copy
(CopiedBecause::OverRamChunk, as for a made one). A chunk's import is marked in flight only under
the RAM's claims (RamOnDevice::chunk takes them before the chunk's lock, as a claim does, and
looks at the chunk again), and is held back where a claim meets its pages (held_back), as where a
noted import does. Whichever starts first, the other never imports the same page.

Docs: host_ram.rs's one-import bullet; the OverRamChunk cause, copied_over_live_imports and
docs/API.md's copied-host-pages entry say made or in flight.
2026-11-11 21:49:22 -08:00
Anees Iqbal 53501197a8 Host RAM: an object across two imported chunks is a copy, never a second import
A no-copy object whose pages cross the end of a guest RAM's chunk, the chunks on both sides
imported, is bound in neither: route_runs answers Runs, and the object took the gate's path
and imported its own pages, the same host addresses as the two live chunk imports
(VK_EXT_external_memory_host leaves that undefined; imports_inside_live counted it). The
consumer's walks hit it at boot on the 2080 and the 3090: a 2 MiB heap from 0x3f22000 into a
64 MiB chunk, 0xde000 bytes in the first chunk and 0x122000 in the next.

Such an object, and one over a live chunk's pages that no resolver routed, is now a copy of its
pages (CopiedBecause::OverRamChunk, counted in copied_over_live_imports, announced as
copied-host-pages, the gate not asked), at its making and at a heap's rebind. Chosen over:
- aligning chunk imports to objects: the chunks are imported ahead, before the objects over
  them exist, and objects lie anywhere;
- one import over both chunks: each chunk's import already binds objects when the straddling
  one comes, and swapping it would move every bound object;
- a sparse binding of both chunks' memory: heaps place resources at any offset, and not every
  device binds sparse buffers.
A copy costs one copy of the object's pages per commit, the rare edge object alone (one per
chunk end an object crosses).

Test: a_heap_across_two_imported_chunks_is_a_copy_and_imports_nothing (the consumer's shape:
both chunks imported by a buffer each, then a 2 MiB heap from 0xde000 before the first chunk's
end): one copy, no pointer import, imports_inside_live 0, the gate not asked; a buffer placed
across the chunks' end reads the RAM's bytes and a fill through it reaches them.
2026-11-11 21:20:02 -08:00
Anees Iqbal 8cb5400e78 Pooled bound: a texture over bytes another texture was made over takes the image at its pitch
A guest's window server makes dozens of textures over each of its large Private surfaces (other
formats of the same bytes, and a new texture each frame), and past the pooled bound each was a
shadow of its linear cost of its own (216 on a Radeon 780M at a login, 1022 in 13 s on an Iris Xe).
storage_over_buffer decided each texture alone: pooled_pitched_image answered LinearCost for any
tracked texture over a Private buffer past 48 KiB, so every texture over the same bytes made a
full image of its own, copied every texel in at its first use, copied in again after a write
through any other (which lets go of its standing) and copied back whole after a kernel's write.
The shadow log names the buffer's object, not the texture's, so one object's two lines 22 ms apart
are two textures over the same surface, a frame apart.

The bound weighed one texture over the bytes. A buffer now notes the runs of bytes textures were
made over (texture_spans.rs, at most 8 runs, joined where they meet), whether those textures
still live: a texture over bytes another texture was made over takes the DRM_FORMAT_MOD_LINEAR
image at Metal's pitch at any size, as over CPU-visible memory, and the first texture's shadow of
its linear cost moves to that image once another texture is made over its bytes, through the
existing pooled move (wait_to_move_in_place: at the next quiet commit, with no copy). Both forms
give Metal's answer; the textures alias the bytes as Metal's do. The bound has no FAST-PATHS row:
it chooses between two exact speeds (6717cac4ea). API.md, HOWTO and the LinearCost docs say so.

Verified: cargo fmt; builds and device runs follow as potluck jobs.
2026-11-11 20:59:46 -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 0e53ff56d5 Docs: the fill queue, where a batch's fills run, and what waits for it
device/staging.rs documents the fill queue: why (a copy through the graphics family runs on the
engine the kernels run on; the 3090 and 5080 numbers so far), why not the staging queue, what it
waits for, what waits for it (with the spec's semaphore and sharing text), what it holds, and what
stays where it was. first_move.rs and managed_copy.rs say where a batch's fills go. Queue counts:
the plan takes 18 queues on NVIDIA now, so the measured 17- and 2-queue devices are named by their
queues, and the least plan keeps the fill queue as it keeps the staging queue.
2026-11-11 19:08:57 -08:00
Anees Iqbal b3a9bda684 Docs: copied-host-pages names pages a live import holds some of; listed runs alone described where they stay
API.md's copied-host-pages entry gains the over-a-live-import cause
(copied_over_live_imports, announced once per device as the others are).
HOWTO's listed-plan paragraph described its runs alone "as above", text
the previous commit removed: it now says what a listed RAM's run import is
(a dma-buf), what it costs, how it orders, and that MoltenVK and ANV import
the chunk instead.
2026-11-11 19:01:50 -08:00
Anees Iqbal e97d5da60c Docs: HelperBranchDropsSimdgroupStores also covers a call in no branch that SPIRV-Cross writes in one
The catalogue entry and the variant's rustdoc name the new case: a ?: arm, the right side of a && or ||, or a selection's arm, where the call's value is read once (spirv::helper_branches).
2026-11-11 18:13:09 -08:00
Anees Iqbal 5175cca5b4 Pipeline creation log: a compute line names its kernel's descriptor, and the dump writes compute modules
A compute pipeline's line in METAL2VULKAN_LOG_PIPELINES named the kernel's function, its SPIR-V
hash and length, its specialization constants and notes, but not what the kernel was made from:
a cold boot's slow compute creations could not be made again off the device, because the
function's Metal constant values were nowhere in the log, and METAL2VULKAN_DUMP_PIPELINES wrote
render modules only.

The compute line now ends with `; descriptor: ` and the same naming a render state's first line
gives each function (its name, the SHA-256 of its bitcode, the constant values by index and by
name with their types and bytes), from one helper both share (`render::logged_function`). With
the dump directory set, the line's module is written there as `<hash>.spv` (`dump_modules`, the
render dump's writer, now over any modules), and a failed write is named in the line as a render
line names it. Nothing is kept or measured while the variables are unset: the descriptor's text
is made only where the log is on (`compute_kernel`).

The creation log's module doc also names the record words the split prints since the record
naming change (`record's cache shared`, `found in cache`, `compiled`).

Test: `opencl_data::the_pipeline_creation_log_names_a_compute_pipeline_and_its_notes` now runs
its child with the dump directory set, and asserts the line's descriptor (the kernel's name,
`air`, `constants {`), no dump failure, and a SPIR-V module (its magic) at the hash the line
names. It and the creation_log unit tests, and lint, run on this commit as jobs after it is made
(the report names them); a failure is fixed forward.
2026-11-11 17:57:53 -08:00
Anees Iqbal 5a1e043784 A driver cache record names its pass without the attachments' formats
A render making's record of the driver's data, and the libraries of its
pre-rasterization and fragment shader parts, were named by the pass
shape whole, formats included. A program that makes one state against
passes that differ only in a colour attachment's format (RGBA8Unorm,
RGBA16Float, BGRA8Unorm) so got one VkPipelineCache per format, and the
driver compiled the same fragment module once in each: on the Iris Xe
(ANV, Mesa 26.2.6) 3.3 to 3.7 s per compile for one large module, three
times over at a cold start.

No stage's conversion reads an attachment's format through the pass: a
format the translation reads is in the stage's own words and constants,
which name the part's record too. So a part's record now names the pass
by PassShape::without_formats (which attachments it has, its samples,
fetch inputs, unread inputs, storage attachments, view mask and
locations), and the depth bias is left out of it as before. The library
names the runtime keys its own library objects by keep the formats (the
libraries are made against VkRenderPasses, which must be compatible);
only the driver cache record is shared. A driver that does key a stage
by format keys that entry apart in the one cache: a compile, never a
wrong pipeline.

The record-naming version (shader_cache/driver.rs VERSION) goes to 3.
METAL2VULKAN_LOG_PIPELINES now says, per library, whether its record
was loaded, missed or its cache shared with an earlier making, and
whether the driver found it in that cache or compiled it (from
VK_EXT_pipeline_creation_feedback).

Measured before the change (a harness making the module's fragment
library against three passes on the Iris Xe, MESA_SHADER_CACHE_DISABLE):
a cache per format, 3.5 s, 3.7 s, 3.3 s; one shared cache, 3.5 s then
0.0 ms and 0.0 ms, the second and third APPLICATION_PIPELINE_CACHE_HIT.

Tests: record_pass_formats (a pass's record name drops formats, keeps
presence, samples, fetch inputs and view mask);
driver_pipeline_compile::creations_over_colour_formats_take_the_first_s_records
(two makings over BGRA8Unorm and RGBA16Float share the first's record,
caches_shared grows by the makings, one fragment library compiled,
while a constant that changes the module keeps its own record);
creation_log's text test.
2026-11-11 17:03:23 -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 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 d2f862c193 Copied host buffers: a split comparison's threads take their runs with the runs' lock let go
The pull loop's while-let held the lock of the runs' iterator through each run's work,
so the threads took their runs one after another. The lock is now let go before the
work, as a let statement drops its temporaries.
2026-11-11 15:32:23 -08:00
Anees Iqbal 8ddde3eec8 Docs: where a copied buffer's base lies, as copied_base_type decides it (a heap of 1 GiB or more) 2026-11-11 15:32:21 -08:00
Anees Iqbal 755656ccd8 Docs: a copied host buffer's base is made at its first writer, tagged per 1 KiB, its bytes in VRAM where a resizable BAR has room
HOWTO's copied-buffer section and API.md's copied-host-pages notice say what a copied
buffer holds beyond its copy and which WorkCounts count it.
2026-11-11 15:32:18 -08:00
Anees Iqbal cb8f4a0988 A compute state's required size past its kernel's own maximum is refused
A compute creation whose descriptor requires a threadgroup size of more threads than its
kernel's own [[max_total_threads_per_threadgroup(n)]] is now refused,
RequiredThreadsProblem::OverKernelMax, as Metal's first compile of the kernel refuses it. The
runtime made such a state and answered the kernel's maximum.

Measured on the M3 Max under macOS 27.0.1, compute_pipeline_limits.m with a salt
(m3-max-17580), each case a first compile and the same again in its salt:
required-128-attribute-64 is refused both times, code 3, "requested required threads per
threadgroup 128,1,1 but 'count64' expects max threads per threadgroup 64";
required-32-attribute-64 is made answering 32. After a compile of the kernel with no size,
Metal makes the 128 state and answers 64. The runtime answers as the first compile, every time,
as it already does for the other history-dependent answers (docs/API.md, accepted differences).

How: the check runs after the compile (additions::check_kernel_maximum, called from
of_kernel), not in the translator's compile: the required size is no part of the compiled
pipeline's key, so a pipeline of the kernel found in the memo, an archive or the disk cache
would skip a check there. It reads the kernel's maximum through a new public accessor,
CompiledFunction::max_total_threads_attribute. A tile function's own maximum beside a
required size is unmeasured and not checked.

Also: the probe header records the salted answers and the descriptor-validation stops of
m3-max-17549; docs/API.md's accepted difference and the additions.rs module docs name the
refusal; docs/REFUSALS.md regenerated; api_signatures.tsv blessed (two additions: the variant
and the accessor).

Test: runtime_lane::compute_threadgroups::
a_required_size_past_the_kernels_own_maximum_is_refused_every_time refuses 128x1x1 and 16x8x1
beside 64 before and after a state of the kernel is made (the second finds the pipeline
compiled), makes 32x1x1 (32) and 8x8x1 (64), and makes 128x1x1 for the kernel without a
maximum.

Verified: nothing yet; the lavapipe run of the test and the lint follow.
2026-11-11 15:17:08 -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 569ac877dc copied-host-pages is announced once per cause, not once per kind
A consumer acts on a refused import, a failed one and a move apart, and rule 2
says each degradation is announced; the kind-level once let a gate's refusal
silence a later failed import on the same device. Device::degrade_copied_pages
keys copied-host-pages by its CopiedBecause cause (and a buffer lying in
another's live copy as a reason of its own) with a bit per reason in the
device's Announced record. Device::degrade keeps its rule for every other
kind; both share degrade_where (lowering refusal, replay, announce_each,
placement), so only this kind's record changes.

Test: copies_of_two_causes_on_one_device_are_each_announced, a refused copy
then a failed one (fail_next_host_imports) both heard with their reasons, a
second refused copy not. docs/API.md states the rule and the entry.
2026-11-11 15:00:04 -08:00
Anees Iqbal aba4034dca Runtime: a program's exit handler reaches no destroyed thread-local
exit destroys the exiting thread's thread-locals before it runs the exit handlers (macOS, the
GNU C library), and LocalKey::with on a destroyed one panics, which in a handler aborts the
process. The exits lane case an_exit_handler_s_common_calls_answer_as_on_any_thread aborted
there on both: "cannot access a Thread Local Storage value during or after destruction" in
calls_at_exit on the M3, and on lavapipe at warm::pass::warming from PipelineMemo::compute,
in the handler's new_compute_pipeline_state.

Every runtime thread-local whose type needs dropping that a program's call reaches is now read
with try_with, with what the thread does once it can keep nothing:
- the making budget's turn (pipeline/budget.rs): program_turn takes none there, holds_turn is
  false, and a turn's give-back and lend read the note with try_with;
- the driver facts' expectation (driver_facts.rs): expecting runs the call alone, its messages
  relayed;
- the creation log's split (pipeline/creation_log.rs): none noted;
- the warm pass (warm/pass.rs): none;
- a relayed compile's held sink messages (device/compiles.rs): the call alone, its messages
  delivered as raised;
- a lowering's refusal (render/deferral.rs): lowering::refusing is false there, so a notice of
  a kind the device refuses while lowering is announced, as anywhere else;
- the debug-build checks of kept resident uses (binding.rs) and of slot rebinds (the
  translator's bind/graphics.rs): skipped.

dirty_pages, shards, resource_ids and contexts already read theirs with try_with; the rest hold
Copy values with no destructor. docs/API.md's accepted differences under "Process exit" say what
an exit handler's calls keep no state for.
2026-11-11 14:55:15 -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 397c0f5d99 A late pass sends an unshared queue's command buffer before held work it lets go
Under UnsharedIsolationPolicy::Bounded, another queue's batch on an unshared
queue's VkQueue is held until its room comes, keeping its place in the order.
A pass that came only after the room came (the scheduler's thread, or a
waiting thread's pass, run late by a loaded host) found that batch and the
unshared queue's command buffer ready together and sent them in commit order:
the whole held batch, about 30 ms in the pin 39 round's 5080 runtime leg, went
ahead of the unshared one, which the hold exists to keep from waiting.

Order::next now takes `first`: the heads it puts first are asked before the
others, each still behind any earlier batch it conflicts with that keeps its
place (is_behind), so tracked order across queues stays commit order. Both
passes (the thread's and a committing or waiting thread's) put first an
unshared queue's head on a VkQueue that holds other queues' work back for it
(CommandBufferShared::goes_ahead_of_held_work); under Off, and for every other
queue, the order is unchanged.

Tests: a_late_pass_sends_an_unshared_queue_s_command_buffer_before_work_let_go_with_it
(the device test from the commit before, which fails without this), and
a_head_put_first_goes_before_the_ready_heads_committed_before_it (Order alone).
2026-11-11 14:31:06 -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 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 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 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 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 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