The steps this packet landed as, in order:
- Read a YCbCr texture's 2D-array view as Metal's, and drop packed 4:4:4 writes
- Name bfloat attachments in the unreached-tiles notice
- Let go of each predicated loop run's sets and uploads once the run completed
- Check that a lent descriptor arena takes every set and reuses its reset pools
- Bump the semantics, artifact format and runtime versions for the eighth stack
- Pin the runtime sources of the eighth stack
- Bless the golden hash tables over the eighth stack
Content: the tree of `development` at ee0b90d176, unchanged.
Encoders log their commands into deferred command buffers, and the device's recorder thread replays
them into Vulkan once the command buffer is committed, so the encoding thread no longer calls the
driver for each command. Every recorded command goes through a slot of its device's; the recorder's
queue and the scheduler's inbox are sized for a frame's commits and grow ahead of them on the
recorder's thread; a commit's end allocates nothing; a render pass instance's secondary that nothing
executes is never replayed. The replays' commands are counted by kind, and the recorder's modules
are listed among those that may keep the device's functions.
Folds in:
- Route every command the runtime records through a slot of its device's
- List recorder/mod.rs among the modules that keep the device's functions
- List recorder/thunks.rs among the modules that keep the device's functions
- Record Vulkan commands off the encoding thread: encoders log into deferred command buffers, the
device's recorder thread replays them once committed
- Grow the recorder's queue ahead of the commits, on the recorder's thread
- Give the scheduler's inbox and the recorder's queue room for a frame's commits from their making
- Count the commands the recorder's replays call, by kind
- Give a commit's tail log its fold's room when its encoder ends
- Never replay a render pass instance's secondary that nothing will execute
- Give new replays room to end each deferred command buffer as it is made, so a commit's end
allocates nothing
Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
No-copy buffers and host imports now cost the kernel and the encoding thread less, and their
deallocators run in the call Metal runs them in, including when a detach races a commit.
What changes:
- Idle pointer imports. A no-copy buffer's own pointer import is releasable, as its dma-buf
import was: while only blits read it and no pending command buffer holds it, the residency
thread releases it after its idle window (2 s, doubling at each import again up to 64 s), and the
next blit imports it again at the same pointer. Only where the new measured fact
DriverFact::PointerImportsFollowTheirAddress holds (ANV 26.2.4 on the Iris Xe; lavapipe 26.0.8
to 26.2.4): there a pointer import reads the pages mapped at its address at each submission, so
an import again reads what the kept one would. A refused re-import fails the blit's call, typed.
- Deallocator timing. A released import hands its keep-alive and deallocators to the objects a
command buffer still holds, so they run as that memory is freed (or parked and announced, as a
kept import's). A committed but unsubmitted command buffer holds a blit's import objects weakly,
so a rebind or detach before its first submission runs the deallocator in its call, as Metal
does. A detach racing a commit on another thread runs the deallocator in one of the two calls:
a let-go mark on the pages and the commit's hold count, both sequentially consistent, make each
side see the other, and a commit that sees the mark replays its own command buffer at once. The
live list re-reads a buffer's pages where a detach moved them meanwhile. HostDeallocatorDelayed
is no longer announced for these races.
- Fewer kernel queries. A no-copy buffer asks the kernel about its mappings (PROCMAP_QUERY) only
where it makes its own import; a rebind onto a live buffer's bytes lies in that buffer's import
and asks nothing; /proc/self/maps stays open for the queries (reopened in a forked process).
Three blit paths that read the caller's buffer as a read apart now read it as blits, so their
imports stay releasable.
- Fewer rewrites and lookups. A rebind or detach rewrites only the heap slots of textures over the
bytes it moved; host-page alias lookups visit only the length classes that hold ranges and keep
each range's overlapping ranges; a binding and a descriptor each read where a no-copy buffer lies
once.
- Counters (WorkCounts): host_imports_used and host_imports_read_apart (with its six reasons),
host_imports_kept_for_fds and kept imports by cause (of_heap, rebound, pointer, no_stand_in),
heap_slots_rewritten, host_mappings_queried (Linux; 0 elsewhere), host_range_lookups,
host_remaps_reported, host_remaps_over_imports, host_imports_remapped, host_pointer_imports_made
and _bytes_made, no_copy_lies_read, host_imports_rebound_unlisted, host_rebind_imports_made and
_covered.
- Docs: docs/HOWTO.md on both kinds of release, the RLIMIT_NOFILE soft limit a program raises
itself and the new gauges; a FAST-PATHS known gap that a buffer made before a remap reads the new
pages on drivers whose pointer imports follow their address, where Metal keeps the old ones
(HostMemory::new's contract forbids such a remap); the rustdoc of host_range_remapped.
Why: ANV over i915 lists every VkDeviceMemory in every execbuffer, and a pointer import costs about
0.19 us an execbuffer; the consumer's guest keeps hundreds of no-copy buffers live and uses few in
a frame. Its swap thread spent 1.54 ms of kernel time a frame querying mappings of a buffer that
joined a live import. And a released import's deallocator unmapped pages under a live userptr,
losing the device.
Verified:
- Iris Xe, a guest-shaped lane of 520 pointer imports and 43 command buffers a frame, the idle
ones released: objects per execbuffer 536 -> 51, ioctl 4.24-4.31 -> 0.85-1.09 ms a frame,
scheduler CPU 4.96-5.05 -> 1.33-1.74 ms a frame, frame p50 5.27-5.43 -> 2.70-3.11 ms.
- The fact, probed outside the runtime on the Iris Xe and through tests::pointer_residency on it
and lavapipe: a kept import read the pages a remap put at its address.
- The detach race on the Iris Xe and RTX 5080 under the validation layer: without the fix 3 of 3
runs failed (deallocators late or on another thread); with it 12 of 12 runs, 15,360 races, each
deallocator in the detach or the commit, never late.
- A second no-copy buffer over 2040 scattered mappings: 415-418 us -> 0.3-0.6 us. A rebind with
1024 other live textures: 4766 -> 49 us. Alias lookups: a draw -5.3% instructions on host-page
frames (RX 7900 XTX).
- Device and unit tests: freed_memory, pointer_residency, host_residency, blit_holds,
encoder_holds, host_import_counts, host_aliases (up to 45 passed per run); lanes rebinds,
rebind_reach, detach, detach_textures, host_memory, no_copy_heaps, dma_buf_imports, draw_work
(74 passed on lavapipe, 30 on the Iris Xe for the deallocator fixes). clippy -D warnings (plain,
m2v_gpu, m2v_cpu_icd) and rustdoc.
Three measured cost facts for ANV (Mesa 26.2.4) on the Iris Xe of RPL-P (0xa7a0), each a pure fast
path that keeps every texel and the order of every use: no policy switch, notice or ledger row.
What changes:
- DriverFact::DontCareStoreIsOneOfMetals gains a row for this GPU: an attachment a pass stores
DontCare is Vulkan's DONT_CARE there, as on the UHD 770 and the Radeon 780M.
- New DriverFact::SampledDepthKeepsHiZ. ANV turns off a single-sample depth image's hierarchical
depth and compression in GENERAL (the layout every runtime image rests in) for an image of
transfer-source usage, but keeps its write-through form on for one of sampled usage. Where the
fact holds, a single-sample depth attachment plan the device samples takes SAMPLED too
(image_plan::hiz_candidate), heap textures and the runtime's own depth images included; the heap
size answer comes from the same plan. Memory size and alignment are equal with and without it.
- New DriverFact::MultisampledDepthFasterOutOfGeneral. A multisampled depth image renders very
slowly in GENERAL on this GPU, since the write-through hierarchical depth is single-sample only.
Where the fact holds:
- each render pass instance holds a multisampled depth attachment in
DEPTH_STENCIL_ATTACHMENT_OPTIMAL, moved from GENERAL by a barrier before it and back after
it (the feedback-loop mechanism, generalized to moved images; WorkCounts
depth_attachments_moved);
- the device's own Private multisampled depth texture stays in the attachment layout between
encoders that only render it (texture/held_depth.rs). The scheduler moves it at encoder
boundaries, before any encoder that uses it otherwise, as a tracked write of the whole image so
the hazard tracker orders it against every use on every queue. A pass holds only when nothing
else in its encoder touches the image; a later use breaking a hold fails the encoder's end
with a visible internal error. WorkCounts depth_instances_held and held_depths_released.
- An instance an execution of render commands joins, inline instances and the resolve-after
instance stay in GENERAL. Layout transitions preserve contents unless the old layout is
UNDEFINED (Vulkan, Synchronization, Image Layout Transitions).
- New measurement runtime_lane::depth_costs (ignored by default).
Why: in GENERAL these depth attachments lose the hierarchical depth test, so the depth test
rejects no fragment a block at a time; and moving back to GENERAL after every pass costs a full
hierarchical-depth resolve, about 1.95 ms a pass at 1080p with 4 samples.
Verified, release, on the Iris Xe:
- runtime_lane::dont_care_stores: every texel of its twelve kept cases was the earlier or the
stored one, none other.
- A 1080p heap Depth32Float at 32 layers: 4.72-5.66 -> 0.82-0.87 ms with sampled usage. A 4x
Depth32Float at 32 layers: 12.14 -> 1.44-1.52 ms moved per instance; held between encoders, 1
layer 2.56 -> 0.62 ms and 32 layers 4.35 -> 2.38 ms (GPU clock fixed at 300 MHz). Batches that do
not name the depth showed no CPU difference above noise.
- runtime_lane::msaa_depth_moves 9 of 9 under the validation layer with the counters checked (a
blit between passes, a resolve in its pass, frames, reads after each pass, two queues ordered by
an event, a split pass, an argument-buffer read with useResource, an encoder that also binds its
depth, an indirect-command-buffer execution); the depth, resolve, snapshot, clear-reach,
memoryless and fence-stage lanes passed. On the Radeon 780M and RTX 3090: msaa_depth_moves 9 of
9 with the fact off and every counter 0. Runtime unit filters 134 passed.
- The RTX 3090 measured neutral for both depth facts, and the RX 7900 XTX keeps DontCare as STORE
(not a measured identity), so neither is listed.
- Unaudited: no lane covers a tile dispatch in a held pass.
Compare a draw's graphics key in place, keep a drawing state's routing for the pass colors it last
met, write descriptors from the stack and allocate the set in place, keep a draw's small lists on
the stack, hold what a draw retains by reference in one entry per encoder, find a draw's bind shape
among its state's settles, fill push bytes in place, bound coverage without allocating, gather named
keys only once a draw reaches the resident set, compare viewport compensations as they come, list
argument samplers again only where the device's changed, and keep each pass shape's compatible
render pass on the device (up to 64 shapes). The frame-cost lane bounds a draw at 27 allocations and
a pass open at 14.
Gain: allocations per draw from 67.5 to 24.5 and per pass open from 18 to 13 on RADV, ANV and
lavapipe. Frame CPU on ANV (Iris Xe), clean rounds: 5.66 -> 5.02 ms.
Verified on the original branch: the runtime lanes, 1313 of 1313 on RADV, ANV and lavapipe. This
squashed commit (with the wake fix under it) was not re-tested on its own.
Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.
- A Cargo workspace of five crates under crates/: metal2vulkan (the
translator and the metal2vulkan command), metal2vulkan-runtime (the
Metal API on Vulkan), metal2vulkan-air (the AIR front end),
metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
refusals, runtime porting and validation guides.
Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b