Commit Graph
3924 Commits
Author SHA1 Message Date
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 688cf76271 Example queue_share: frames makes the compositor's queue before the application starts
Other queues' batches are held back only while an unshared queue exists, so with the compositor's
queue made 50 ms after the application began, the application's first command buffers went
untracked and the compositor's first frames waited behind all three: one 85-87 ms wait in every
run on both the Iris Xe and the Radeon 780M (m3-max-16884, -16885), which set the worst wait the
run reported. A compositor's queue exists before the applications it shows.
2026-11-11 12:03:50 -08:00
Anees Iqbal 70ed4b1424 Runtime: a batch of a queue with no run seen holds the others back until it completes
A queue with no run seen was expected to run the 2 ms budget, so an application that commits
several command buffers at once (the owned workload keeps three in flight) put them all on the
VkQueue before its first was seen complete, and the compositor's first frames waited behind all of
them: on the Radeon 780M (gem10, m3-max-16785, three 30 ms command buffers beside a 16 ms
compositor) the switch on still left p99 48-58 ms and a worst wait of 79-90 ms, about three batches,
where the median was 17-19 ms.

Such a batch is now of unknown length: while one is in flight on a VkQueue held back for an unshared
queue, no other queue's batch goes there until it is seen complete, which gives its queue a run. It
costs one completion's turn per queue. Unit test: a batch of unknown length holds the next back
whatever it has run, and its completion gives its queue the run.
2026-11-11 12:03:50 -08:00
Anees Iqbal 76ba0696c0 Runtime: an unshared batch seen complete with another queue's takes no share of its run
Flight::completed split the host-observed run equally among every batch the completion covered,
the unshared queue's included. A compositor's light batch submitted behind an application's is
usually seen complete in the same completion turn, so the application's batch was credited half
its run and its queue's expected run halved toward it. On the Radeon 780M (gem10, m3-max-16762,
three 30 ms command buffers in flight beside a 16 ms compositor) the hold then let a second
application batch in about halfway through the one ahead, and the compositor's median wait stayed
at one whole batch (32-34 ms, against 74-77 ms with the switch off) where about half of one is
the bound's.

The run is now shared among the other queues' batches only; an unshared batch seen complete alone
updates nothing. The unit test of a shared run now expects 4.5 ms each of a 9 ms run over two other
queues' batches and an unshared one, and a new one checks that an application's 30 ms run seen
complete with a compositor's batch keeps its 30 ms (it fails before this change: 22.5 ms).
2026-11-11 12:03:50 -08:00
Anees Iqbal 07700b3a86 Runtime: an unshared queue's batches never wait in a group, and no group is kept, on a VkQueue held back for it
Measured on the Radeon 780M (job m3-max-16523, queue_share frames, three 30 ms command buffers in
flight beside an unshared compositor's draw every 16 ms): with the hold alone the compositor's
p50 fell from 72-77 ms to 34-35 ms but its max stayed 84-85 ms, 3.1-3.2 batches ahead of its long
waits, and the GPU idled 0.9-1.0% where it idled 0.04%. Two parts of grouped submissions
(CompletionPolicy::Grouped, Mesa's merging drivers) undid the hold:

- a compositor's batch held in a group goes with the next batch the hold lets go, and is seen
  complete at that batch's end, 30 ms late;
- Group::keeps holds a group while two submissions of its VkQueue run (the compositor's queued
  behind the application's is the second), so the application's next batch, which the hold let go
  about 2 ms before the one ahead ends, waited for that one's completion: the GPU idle between.

So, on a VkQueue other queues' work is held back from (Device::holds_back_for_unshared): an
unshared queue's batch never waits in a group (CommandBufferShared::groups, which submit_batch now
asks too), and a group is never kept. The hold bounds the work ahead there by expected GPU time
instead of the count of submissions. Elsewhere grouping is as before.

The queue_share example's frames mode also reports the application's mean GPU time a command
buffer and the kernel submissions a second.
2026-11-11 12:03:50 -08:00
Anees Iqbal a61da20d1d Tests: unshared_isolation keys no profile; the expected run's halving rounds toward the longer
The unit test asked 10 ms where halving 20 ms toward 1 ns answers 10 ms and 1 ns (job
m3-max-16503, the one failure of its 62 tests); the profile test is the one every runtime
choice of DevicePolicy has.
2026-11-11 12:03:50 -08:00
Anees Iqbal 9bad7ed6f7 Runtime: no batch is held back for an unshared queue on a lost device, whose submissions fail at once 2026-11-11 12:03:49 -08:00
Anees Iqbal d7fb932380 Runtime: unshared_hold's expected run updates with try_update, fetch_update's new name 2026-11-11 12:03:49 -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 f9d4c06388 Runtime: hold other queues' work back from a VkQueue an unshared queue shares
On a device whose graphics family has one queue (RADV, ANV, lavapipe), every command queue submits
to it, an unshared one (a compositor's) included, and a VkQueue runs its submissions in order: the
compositor's light command buffer waits for every batch submitted before it. On a Radeon 780M, a
compositor committing a draw every 16 ms beside an application keeping three 30 ms command buffers
in flight waited 76 ms at the median, 112 ms at worst (queue_share example, frames mode, job
m3-max-16449).

New DevicePolicy switch unshared_isolation: UnsharedIsolationPolicy::Bounded (the default) or Off.
Under Bounded, on a VkQueue an unshared queue holds (SlotShare::unshared), another command queue's
batch, otherwise ready, is submitted only while less than 2 ms (unshared_hold::BUDGET) of other
queues' expected GPU work is in flight there; else the scheduler holds it, keeping its place in the
order (HeldFor::UnsharedIsolation, WorkCounts::heads_held_for_unshared_isolation), and waits for the
VkQueue's next completion (a gate in Awaits) or, where the oldest batch's expected run covers it,
for the time the work left falls under the budget (wake_by): so the next batch goes in before the
one ahead ends.

How (unshared_hold.rs): each VkQueue an unshared queue holds keeps a Flight of its batches taken and
not seen complete, under queue_wait.rs's leaf lock, at the batch's value take and the host's
completion; each other queue's batch carries its command queue's expected run, the host's view of
how long its recent batches ran as the VkQueue's oldest (queue_wait.rs's runs), raised at once by a
longer run and halved toward a shorter one. The work left is the expected runs in flight less what
the oldest has run, up to its own expected run. A committing or waiting thread's own pass leaves a
held batch to the scheduler's thread, which it wakes.

Tests: unit tests of the expected run and the flight (tests/unshared_hold.rs), among them a queue
whose batches drop from 30 ms to 1 ms let have two in flight again within five; device test
queue_share_device::an_unshared_queue_s_command_buffer_goes_ahead_of_other_queues_held_work, both
values. The wait-counting test runs under Off. The queue_share example takes --isolation and
reports the application's GPU-busy share and the GPU's idle share. API signatures re-blessed.
2026-11-11 12:03:49 -08:00
Anees Iqbal 349b455385 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 11:54:07 -08:00
Anees Iqbal 16dec3f2d3 RUNTIME_VERSION 2051: DontCare depth and stencil on separate textures, and no NaN clear depth
A stored DontCare aspect of separate depth and stencil textures now takes the single texture's
answer: the aspect is copied into the scratch image and the draws' tiles are cleared there after
the copy. An aspect that can't be copied in (a multisampled aspect copied by draws) is cleared
over the render area and announced as dont-care-load-tiles. A NaN DontCare clear depth clears a
Depth16Unorm to 0 (Metal's answer) and a 32-bit float depth to 1.0, announced as
signed-depth-test. A Depth16Unorm DontCare load that becomes a clear at a midpoint depth announces
unorm-depth-rounding. A new known gap in FAST-PATHS: a draw that neither tests nor writes the
aspect still gets its tiles cleared, where Metal keeps its texels.

Verified (potluck jobs):
- Metal on the M3 Max, macOS 27.0.1: m3-max-16665, 16673 (the probes the answers come from).
- lavapipe before: 16751, 16780 (the lane tests fail); after: 16783, 4/4 pass.
- M3 MoltenVK before: 16755, 3/3 fail; after: 16764, 3/3 pass and 200/200 in the related lanes.
- lavapipe runtime suite 16737, 2133/2133; full runtime_lane 16745, 1974/1975 (the one failure
  was the test bug fixed in the stencil-write commit).
- Lint 16740, 16775, 16782: fmt, clippy all-features, m2v_gpu, m2v_cpu_icd, rustdoc, fast_paths.
- M3 MoltenVK at the tip: 16877, 4/4 and 201/201 in the related lanes; before at 8a13441633: 16879, 0/4.
2026-11-11 11:49:31 -08:00
Anees Iqbal 24a000b2ca Lane dont_care_depth_stencil: a multisampled separate depth loaded DontCare and stored
A 4-sample separate Depth32Float, loaded DontCare and stored and resolved (sample 0), beside a
Stencil8 loaded and stored, under a writing draw over a 4x4 rectangle: the resolved depth holds
the draw's depth in the rectangle, the clear value in the rest of its 32x16 tile, and one answer
everywhere else, the poison (copied in, its tiles cleared) or the clear value (cleared over the
render area where the runtime copies the aspect by draws), with dont-care-load-tiles announced.
The test prints which form ran; a device that refuses the textures or the pass is printed.
2026-11-11 11:49:19 -08:00
Anees Iqbal 9f1a7dba36 Lane dont_care_depth_stencil: no stencil writes in a pass without a stencil
The writing draw's state replaced the stencil in the Depth32Float and Depth16Unorm passes too,
which have no stencil attachment: the runtime refuses such a draw
(NotImplemented(HiddenDepthStencil), m3-max-16748 on the M3 Max). Metal's probe passes of those
formats wrote the depth alone. The state now writes the stencil only where the pass has one.
2026-11-11 11:49:18 -08:00
Anees Iqbal 1b17754e87 Lane dont_care_depth_stencil: drop the unused side field
The textures' side was stored and never read: dead code, which -D warnings stops in the
validation crate's test build (m3-max-16733 at 1852ee71f2).
2026-11-11 11:49:18 -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 93f94fe148 Lane: depth and stencil loaded DontCare, stored separate textures and NaN or out-of-range clear depths
Three device tests of what a render pass's `DontCare`-loaded depth and stencil hold, against
Metal's answers measured on the M3 Max under macOS 27.0.1 (probe jobs m3-max-16665 and
m3-max-16673, the same passes through Metal over the same MSL):

- separate Depth32Float and Stencil8 textures, and one Depth32Float_Stencil8 as the control,
  each aspect or both loaded DontCare and stored, under a writing draw over three small
  rectangles and under a draw call of no vertex: Metal leaves the clear value in the rest of
  the 32x32 tiles the rectangle touches, in each aspect loaded DontCare, and every other texel
  as it was, alike for both arrangements;
- a DontCare load's clear depth of a NaN of either sign, 2.0 and -1.0, over Depth32Float,
  Depth16Unorm, Depth32Float_Stencil8 and separate textures under exact_answers(): Metal
  clamps 2.0 and -1.0, stores 0x7fc00000 (32-bit float) or 0 (Depth16Unorm) for a NaN, and
  tests a NaN above every value; the tests take the runtime's 1.0 for a 32-bit float NaN
  with signed-depth-test, and require the validation layer to report nothing;
- a Depth16Unorm DontCare load cleared under exact_answers() announces unorm-depth-rounding
  at 0.5 and not at 0.

Written before the runtime change that gives these answers; run before and after it (the
next commit says what ran).
2026-11-11 11:49:04 -08:00
Anees Iqbal 06d8a02925 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 11:26:54 -08:00
Anees Iqbal 0940646cb5 RUNTIME_VERSION 2050: a Managed no-copy buffer keeps a copy in VRAM on a GPU without unified memory
On a device without unified memory a Managed no-copy buffer is two copies, Metal's on a Mac
with a discrete GPU: its GPU copy in device-local memory, the caller's pages its CPU copy,
copied in at its making, at did_modify_range and at a rebind, out at synchronize_resource;
contents() keeps the last pointer while detached. Measured on the branch (managed_bandwidth,
a kernel reading one 256 MiB buffer and writing another): RX 7900 XTX 11.4 -> 865.8 GB/s
(Private 865.6, Shared no-copy 11.3 unchanged); RTX 2080 2.7 -> 395.8 (Private 396.0).
Device tests 19/19 and lanes 84/84 on both cards; XTX runtime suite 2145/2147 before the
read-only undo fix, whose two tests then pass; clippy three ways and rustdoc clean.
2026-11-11 11:23:05 -08:00
Anees Iqbal 6bda92bb13 Runtime: a two-copy buffer's undo at completion runs in an exit-guard section
The undo of a command buffer's writes to a two-copy buffer over read-only pages copies the
pages in again on the completion's thread, and that copy reaches the device (staging buffers,
first moves): outside a section the exit guard aborted the process ("the runtime's thread
metal2vulkan-queue-wait-0 reached the device outside an exit-guard section") in both
managed_copy_device::read_only_* legs on the RX 7900 XTX and the RTX 2080 once c8ba58c531 made
the undo run. Once the process is exiting the undo is skipped: no later command buffer reads
the buffer.
2026-11-11 11:22:55 -08:00
Anees Iqbal c416a4dcd0 Validation: the detach lane names HostBacking where its one use is compiled
Table 3's assertion is compiled only under m2v_cpu_icd or m2v_gpu_hazards, so the import was
unused under m2v_gpu alone (a warning in the gpucfg test build at 9e68536e67).
2026-11-11 11:22:54 -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 c814a6dc2d Runtime: a commit gathers the two-copy buffers its commands used, so read-only pages undo the GPU's writes
The commit registered AtCompletion::Undo only for the buffers of Reached, which held the
buffers over host pages and the heaps: a two-copy buffer is runtime-owned memory, so it was
never among them, and a command buffer that wrote one over read-only pages left its writes for
the next command buffer (managed_copy_device::read_only_* failed on the RX 7900 XTX and the
RTX 2080: no undo counted). Owner::of_buffer now marks a two-copy buffer gathered as well;
LiveBuffers::reach still lists only the buffers over host pages, and the host-import count
takes only buffers with host pages, so neither changes.
2026-11-11 11:22:54 -08:00
Anees Iqbal 63a75b4167 Validation: device_copies' log has no wait that cannot say any more (no leg asks it) 2026-11-11 11:22:54 -08:00
Anees Iqbal 0c111a6355 Runtime: a two-copy buffer's pages refused before their write permission was asked drop the GPU's writes where the process cannot write them
The caller's gate is asked before the pages' write permission, so a two-copy
buffer (or rebind) over read-only pages whose import the gate refused took
pages that keep the GPU's writes, and synchronize_resource's copy back at
completion wrote into read-only pages: the process faulted
(managed_copy_device::read_only_pages_no_import_maps_drop_the_gpu_writes on
the RX 7900 XTX). caller_side now asks the system (refuse_unwritable, as an
import does) where the refusal came first, unless the caller vouched
(HostMemory::assume_writable).
2026-11-11 11:22:54 -08:00
Anees Iqbal 653a6166a5 Runtime: first-move copies into bytes an earlier one wrote land after it
A Managed no-copy buffer's copies in wait for the device's next submission,
and its making's, a rebind's and each did_modify_range's read the pages at
different times; the submission recorded them back to back with no barrier,
so two into the same bytes raced: on the RX 7900 XTX a read-only rebind made
right after the making read about 38 KB of the first pages' zeros among the
new pages' bytes (managed_copy_device's read-only legs). Now a copy whose
bytes meet one recorded since the last barrier takes a barrier before it, so
they land in the order they were noted (texture/first_move.rs).

Test: copies in that wait for one submission land in their order (the
making's, then two whole did_modify_ranges), over an import and over pages
no import maps.
2026-11-11 11:22:54 -08:00
Anees Iqbal e493161dc2 Validation: a Managed surface over host pages is two copies without unified memory; a two-copy buffer answers NonVolatile
runtime_lane::device_copies: on a device without unified memory the surface's
Managed no-copy buffer is two copies (managed_copy.rs), so its texture reads
the GPU's copy, which takes the pages at the making and at did_modify_range,
whatever the log says, and the pages take the GPU's writes at a
synchronize_resource: the legs tell the buffer of each CPU write, check that a
write nothing tells is not seen there (and is seen with unified memory), that
a blit's fill reaches the pages only at a synchronize there, and that no
device copy of host pages is made; device_copy_costs tells did_modify_range
too and prints the bytes copied in either way.

copied_surfaces: a Managed buffer over a refused surface's pages is two
copies there, its gate asked and refusing, no copy shared: counts [1, 1, 0,
2], HostBacking::DeviceCopy; the one-command-buffer leg holds only where they
share the copy.

Runtime: set_purgeable_state of a two-copy buffer answers NonVolatile and
keeps its bytes, as a no-copy buffer's (its device copy is the runtime's own
memory, Owner::Runtime, which the check missed).
2026-11-11 11:22:53 -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 d941411cdc Runtime tests: a GPU address compares as its word 2026-11-11 11:22:53 -08:00
Anees Iqbal 61073ee41c Runtime docs: a two-copy Managed no-copy buffer's making, rebind and detach 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 26c7d527b0 Runtime tests: a Managed no-copy buffer's two copies on a device without unified memory
Device tests (managed_copy_device.rs), each over an import of the pages and
over pages no import maps (the caller's gate refuses the import): the copies
in at the making and at did_modify_range, not at an unnamed CPU write; the
copy out at synchronize_resource, not without one; a 256 MiB buffer's device
copy and staging within the bound across cycles, none at rest, and no copy of
the pages; rebind, detach, read-only pages dropping the GPU's writes, a
recovery; a Shared no-copy buffer with no device copy. On unified memory each
leg checks the buffer is one copy.

Not yet built.
2026-11-11 11:22:53 -08:00
Anees Iqbal 8d7dfc4623 Runtime: a Managed no-copy buffer is two copies on a device without unified memory
On a Mac with a discrete GPU a Managed resource has two copies, the CPU's and
the GPU's own, synced at didModifyRange: and a blit's synchronizeResource:,
and a Managed buffer over the caller's pages is no exception: a kernel read
one 256 MiB such buffer and wrote another at 102.5 GB/s on a Radeon Pro
5300M. The runtime left it in the caller's pages, read across the bus
(5.8 GB/s on an RTX 5080 Laptop), as a Shared one.

Now (managed_copy.rs) such a buffer is a buffer of device-local memory of the
runtime's own, as a Managed buffer the runtime makes there, whose host copy
is the caller's pages: an import of them made as a no-copy buffer's (by
pointer, dma-bufs, a guest RAM's chunk), outside the Metal address space, or,
where the device imports none, the pages alone (never a copied.rs copy as
well). contents is the caller's pointer; the deallocator and keep-alive go
as a no-copy buffer's.

- Copies in (the making, did_modify_range, a rebind) go through the device's
  next submission's first work, after the commands before it on its queue:
  from the import's VkBuffer, or through write-combined staging of 32 MiB at
  most, freed when the submission completed.
- synchronize_resource copies out as a blit's write of the import, or into
  host-cached staging copied to the pages at the command buffer's completion
  (CommandBuffer::at_completion, run in completion.rs before anything sees it
  complete).
- Read-only pages: nothing is copied out, and the pages are copied in again at
  the completion of each command buffer that used the buffer.
- Rebind and detach act on the host copy (the import's own, or the pages'),
  a rebind copying the new pages in whole; a recovery makes the host copy
  again and copies the pages in.
- No device-local room: the buffer lies in its pages, announced as
  device-memory-overflow, never refused.
- Counted: WorkCounts::managed_device_copies*, managed_bytes_copied_in/out,
  managed_staging_bytes, managed_writes_undone. HostBacking::DeviceCopy.

Not yet built: the commits after this one fix what the build finds.
2026-11-11 11:22:53 -08:00
Anees Iqbal d56a590767 Example: managed_bandwidth checks the kernel's sum, and reads the output through common::bytes
The check wanted 2 * (i + shift) where the kernel writes input + i, which is
2i + shift; it read the output through its own slice, leaving common::bytes
unused (a dead-code warning).
2026-11-11 11:22:45 -08:00
Anees Iqbal 458c3dda4a Example: managed_bandwidth, a kernel's GB/s through 256 MiB buffers of each kind
Not a consumer's example: a kernel reads one 256 MiB buffer and writes another
of the same kind (scale_and_offset of the owned fixture, 4 bytes read and 4
written a thread), timed by the command buffers' GPU times, for Shared and
Managed no-copy buffers over the example's own pages and the runtime's own
Shared, Managed and Private buffers. Each row checks the kernel's answer
(a Managed output after a blit's synchronize_resource), and the Managed
no-copy row checks that a CPU write told by did_modify_range reaches the next
command buffer. It is the bandwidth evidence for Managed no-copy buffers on a
discrete GPU, with Shared no-copy as the control.
2026-11-11 11:22:45 -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 c1ccb0b48d Probe: what Metal does with resource option bit 20
The options a guest's OpenCL runtime passes for its buffers set bit 20 (0x100000),
which no public MTLResourceOptions value names, and the runtime refuses it today.
The probe prints, for each way of making a resource, whether Metal made it and
what the resource reports of its options.
2026-11-11 11:22:45 -08:00
Anees Iqbal 91528cf602 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 11:10:50 -08:00
Anees Iqbal d5cc880770 RUNTIME_VERSION 2049: a host step or submission that fails gives the tiled takes of its batch and every later one back
A command buffer failed by its host step's recording or by vkQueueSubmit now gives back the
takes of the failed batch and every later part (CommandBufferShared::never_runs_from), as
fail_part does. A predicated loop's rerun stays a known gap. Verified on the branch: before
the fix lavapipe's two new legs take no copy (potluck m3-max-16608); after it lavapipe and
RADV PHOENIX 272/272 (m3-max-16713, 16714); lint m3-max-16715, 16716.
2026-11-11 11:10:11 -08:00
Anees Iqbal 5d2c21b79b Runtime: keep the encoding-again take mode; a rebind's segments decide no takes
The before-runs of the GPU-pass rebind leg passed on the pre-fix code
(lavapipe, m3-max-16674 with the draw before the execution, m3-max-16689
with it after): the draw read the bytes. A render pass recorded in a
segment has its shadowed textures' copies planned by its encoder's own core
as the pass ends (render.rs end_pass, shadows::plan), the take among them,
and the segment only records them. GPU-alone compute executions
(gpu_execute) plan no shadows. The segment cores that plan their own
(indirect dispatches, executions recorded from records) are host steps'
recordings, which a rebind does not record again. So no segment a rebind
records again decides a take, and the encoding again's main core already
keeps them (ShadowSync::again).

So this puts back shadow.rs's two modes, State::replaying_takes and
step_takes, and reencode.rs and encoder.rs as development has them. The
shared pool, the give-backs at a splice and Replayed::takes are gone. Kept:
the failed-submission give-back (State::give_back_from, never_runs_from,
place joining a segment's takes into its encoder's), its docs, the loop
gap in FAST-PATHS, and the GPU-pass leg as a regression test, its doc now
saying where the take is decided.
2026-11-11 11:10:11 -08:00
Anees Iqbal bd987bf8a8 Runtime tests: the GPU-pass rebind leg draws the texture after the execution
Its before-run at 92a2a37461 (job m3-max-16674, lavapipe) passed: the draw came before the
execution, in an instance of its own that the encoder records inline (the pass split before the
execution), so its take was the encoder's, which the encoding again already kept. The draw now
follows the execution, in the instance the commit records in a segment.
2026-11-11 11:10:10 -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 ce043e791d Runtime tests: the GPU-pass rebind leg's buffer holds a draw the blit resets
Its first run (job m3-max-16608, lavapipe) found the pass recorded by a host step, not on the
GPU alone: the GPU form asks that the records may hold draws, and a reset alone holds none. The
host step then held the index buffer's pages, so the rebind was refused (EncodedUses). The CPU
now writes a triangle draw into command 0, which the blit resets on the GPU before the pass.
2026-11-11 11:10:10 -08:00
Anees Iqbal f154f4dfb7 Runtime tests: tiled takes in a pass a rebind records again, and in batches whose step or submit fails
Three device legs that fail on the tip:

- tiled_texture_reencode: a render pass recorded on the GPU alone (it
  executes indirect commands a blit reset) whose indexed draw reads a
  tiled texture and takes its indices from a no-copy buffer. A rebind of
  that buffer encodes the render encoder again; the pass's segment is
  recorded again, and must take the copy the commit's segment took.
- tiled_texture_step: the host-step leg's setup shared, and a leg whose
  host step's recording fails (CommandBuffer::fail_host_step, a test
  injection after the step records): the batch never runs, so the
  commit's take must be given back.
- tiled_texture_failed: a leg whose batch's vkQueueSubmit fails
  (Device::fail_next_submissions, a test injection in submit_logged that
  makes no call): the take must be given back.

Both injections are cfg(test) only. Not run yet: the before-run is the
next step.
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 f696df5065 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 11:08:53 -08:00
Anees Iqbal 8fe1cbef1c RUNTIME_VERSION 2048: far vertex layouts pulled past lavapipe's wrapping fetch; a load-robust merge check
On a driver whose fixed-function vertex fetch wraps at 4 GiB
(RuntimeDriverDefect::VertexFetchWrapsPast4GiB, lavapipe), a layout the draw's own values
reach past 2^32 is pulled; uint-indexed and indirect draws are pulled under
DevicePolicy::vertex_reach = Exact (exact_answers()), announced vertex-fetch-may-wrap
otherwise. The submission-merge check floors each call apart on its own (CHECK_VERSION 8).
Rebased over the unstored-DontCare switch: both DevicePolicy fields kept. Verified on the
branch: lavapipe before 24 elements differ (potluck m3-max-16570), after exact under
exact_answers() (16602); touched tests on lavapipe, the 780M and the M3 (16602, 16642,
16617); full lavapipe lane 5518/5519, the pin alone failing (16647); core 5432/5432 (16666);
lint 16601; ledger tests 34/34 (16712).
2026-11-11 10:55:00 -08:00