tests::pipeline_wait_order asserted the order before the previous change: a copy on queue B of a pass's target waited for the pass, held for its draw's making. A held batch now gives way (scheduler/order.rs, Held batches give way), so the copy completes while the pass waits, reading what was there before it (not the drawn texel), no look counts it as behind an earlier commit, and once made the pass runs after it: a later copy reads the drawn texel. Failed as before on lavapipe at f6a3a5d641 (m3-max-21913, plain and sync), the one failure of 218 lane tests.
Jobs m3-max-21812 and m3-max-21830 (M3 Max, macOS 27.0.1), m3-max-21850 (Radeon Pro 5300M) and m3-max-21851 (UHD 630, both macOS 26.7.1, the x86_64 build). The table is the runs where queue B's later commit ran after queue A's long write and read its words. Comment only.
What: the scheduler's order across queues (scheduler/order.rs) no longer keeps the place of a
batch held unsubmitted for a host step that has not taken its gate: its pipelines being made, or a
step that reads nothing the GPU writes (`place_of`: `Place::GivesWay`). A later commit of another
queue that conflicts with it on a resource goes first, and the held batch is submitted after it,
so the tracker orders the two that way (submission order). The batches after it on its line give
way with it. What still holds a head back behind such a batch is a fence the two share
(`tracker::fenced`: one updates a fence the other waits for or updates, or a batch whose uses are
not known yet against one that names a fence), so no batch is moved after a fence update it waits
for. Unchanged: same-queue order, event and binary-semaphore waits (a batch waiting for the
program still keeps no place), batches held for their submission checks or for a host step whose
gate was taken (they keep their place: a later write going first would land after the step read),
and the order among submitted batches.
Why: on an Intel Iris Xe a guest process's cold compute pipeline took about 3 s to make; its
command buffer kept its place, and the other processes' heads that conflicted with it (the window
server's frames among them, over a surface they shared) waited behind it: the guest's display
froze for 3.1 s. Metal's order across queues is the order the GPU takes the command buffers, not
commit order: probes/cross_queue_surface_order.m's same-buffer control (one tracked buffer,
written by queue A's long compute, then read or written by queue B's later commit) ran B before A
once in three on a Radeon Pro 5300M and on a UHD 630 (macOS 26.7.1; m3-max-21850, m3-max-21851),
and in commit order on an M3 Max (macOS 27.0.1). Where real Macs differ, the cheapest form inside
them is taken; no switch, as matching the x86 Macs trades no accuracy. (The previous commit's
message miscounted the no-copy buffer case: unordered in 10 of 12 runs, 6 of 6 on the M3, 3 of 3
on the 5300M, 1 of 3 on the 630.)
Docs: order.rs's contract (**Tracked order across queues is the order the batches go**, **Held
batches give way**, **No deadlock**), the scheduler's tracking and gate docs,
WorkCounts::heads_held_for_earlier_commits, pending_dispatch.rs, docs/API.md's and the runtime
README's pipeline-wait passages.
Tests: tests::scheduler a_later_commit_goes_before_a_batch_held_for_its_making and
a_batch_held_for_its_making_holds_back_a_commit_sharing_a_fence (the order's model; its existing
a_later_commit_that_conflicts_waits_behind_a_batch_held_for_its_step is the kept-place control);
tests::hold_sites a_head_that_shares_a_buffer_with_a_batch_held_for_its_making_goes_first (was
..._waits_behind_it: the fill completes while the dispatch is held, and the dispatch's words land
over it), a_head_that_waits_for_a_fence_a_batch_held_for_its_making_updates_waits_behind_it (the
fence control), and the host-alias leg, which passes again.
Reverts a5634d48db and 3926d2d8c9, which left the uses the host aliases add out of the
scheduler's order across queues on the strength of host_aliases.rs's line that Metal orders two
textures over one IOSurface across queues only as the program orders them. The conformance probe
probes/cross_queue_surface_order.m measured that case (queue A's long compute write committed
before queue B's blit read of the same bytes, no event between them, three runs each):
- two tracked textures over one IOSurface: B ran after A and read its writes in every run on an
M3 Max (macOS 27.0.1, m3-max-21812, m3-max-21830), a Radeon Pro 5300M and a UHD 630 (macOS
26.7.1, m3-max-21850, m3-max-21851); untracked, the same but one run on the 5300M;
- a texture of another surface (control): ran alongside A on the M3 and the 5300M;
- two no-copy buffers over one allocation: B ran alongside A, reading stale or mixed words, on
all three (8 of 9 runs; the 630 ran it one after the other twice);
- one tracked buffer (control): ordered on the M3; the 5300M and the 630 each took B first once.
So the alias keys' order across queues is the surfaces' order, which Metal keeps; dropping it was
wrong for the consumer's surfaces, whose textures lie over per-texture no-copy buffers.
host_aliases.rs now states those measurements, the plain no-copy buffers' among them, in place of
the M4 line. The freeze the revert reopens (a held batch's making holding other queues' heads
over a shared surface) is answered by the next commit, which lets a batch held for its making give
way across queues, as the x86 Macs' GPUs may take a later commit first.
Until that commit, tests::hold_sites::a_head_over_the_same_host_bytes_through_another_buffer_goes_while_a_batch_is_held
fails as before a5634d48db (m3-max-21752).
Separates an order through the shared IOSurface from a texture blit that would wait for the compute anyway (surface-apart), and an order from hazard tracking from one from the surface itself (surface-two-untracked). Not run yet.
Two textures over one IOSurface and two no-copy buffers over one allocation, queue A's long compute write committed before queue B's short blit read of the same bytes, with one resource on both sides as the control. The basis of the scheduler's order across queues leaving host-alias uses out (host_aliases.rs). Not run yet; its results follow in a later commit.
heads_held_for_earlier_commits and pending_dispatch.rs's module docs said a batch of another queue waits where the two share a resource; since the previous commit a conflict is on a resource both name, not on two resources over the same host bytes (host_aliases.rs). The counter's doc also names the pipelines' making among the runtime's own holds. Docs only; verified by reading.
What: a use the device's host aliases add (host_aliases.rs: a no-copy buffer over the bytes of
another, the consumer's textures of one IOSurface over their plane buffers) is now marked
(`Use::aliased`). The scheduler's order across queues (`Footprint::conflicts`, behind
`Order::is_behind`) leaves marked uses out, so a batch the runtime holds for a reason of its own
(its pipelines' making, a host step, its checks) holds back no later commit of another queue that
meets it only over shared host bytes. A use joined with one its command named stays named (join
and merge keep `aliased` only where both are; `covers` lets no aliased use hold a named one), so
two batches that name one resource still run in commit order, as Metal's tracking orders them.
The tracker's barriers, inside a queue and on the GPU once both are submitted, take aliased uses
as before.
Why: on an Intel Iris Xe, one guest process's compute pipeline took about 3 s to make cold. Its
command buffer kept its place in commit order (held for its making), and five other queues' heads
in each scheduling pass, the window server's frame among them, conflicted with its footprint only
through the alias keys over IOSurface pages they shared (heads_held_for_earlier_commits +5 per
pass, footprints_built +2, the scheduler otherwise idle). The frame's present waits for its
writers' completion, the guest's display pipe allows two unanswered presents, and the guest froze
for 3.1 s. Metal orders two textures over one IOSurface across queues only as the program orders
them (host_aliases.rs's measurement: an M4, macOS 27.0.1, plain and under API validation), so a
later commit of another queue through another resource over those pages does not wait for an
earlier one there; holding it was ours alone.
docs/HOWTO.md's paragraph on copied and same-surface buffers says the same; the order.rs,
scheduler gate and host_aliases.rs docs name the exception.
Tests: tests::hold_sites::a_head_over_the_same_host_bytes_through_another_buffer_goes_while_a_batch_is_held
(the previous commit) failed before this change on lavapipe (m3-max-21752: TimedOut, the fill
waited behind the held dispatch) and is expected to pass after; tests::tracker gains
a_use_the_host_aliases_added_orders_no_batch_across_queues (aliased-only overlaps unordered both
ways, a named key on both sides ordered, a named use joined with an added one of the same range
named); tests::host_aliases expects the added uses marked.
Two no-copy buffers over the same host bytes are two resources, which Metal orders across
queues only as the program orders them (host_aliases.rs's M4 measurement). The scheduler's
cross-queue commit-order hold (Order::is_behind) counted the use host aliases add for the
second buffer as a use of the first, so a fill through the second buffer on another queue
waited for the first queue's dispatch, held by its pipeline's making. On an Iris Xe guest a
cold 3 s compute making so held a compositor's frames behind another process's command buffer
over a shared surface's pages, and the guest froze for 3.1 s.
This commit adds the test alone (hold_sites.rs, Exact pipeline waits, the pool's test hold):
it fails until the order counts only conflicts on a resource both batches name.
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.
The commits before this one give arena and typed thread pointers a null value. Until now they had none, so a phi or select with a null incoming, and a compare of a pointer that may be null, were refused (Lowering(Access): "its copy would need the constant materialized"; LocalStrategy::NullCompare). That is the shape of a helper returning a pointer into a thread array at a run-time index or null, which callers null-check: one of the two refusals keeping a guest's path-tracing kernels from being made.
- memory::plan keeps the private arena's first word (NULL_WORD = 4) when a root set holds an alloca and null; null is offset 0, and no object has it.
- Null-only phi incomings are accepted; a maybe-null pointer compares by offset. Signed compares with null, and threadgroup or typed objects' null, stay refused.
- A null dereference reads at an out-of-arena offset, so containment reads 0 or drops the write (undefined in Metal). Under ContainmentPolicy::UnsafeOff it is an unchecked access; that policy's doc lists it.
- The owned fixture nullable_private (with its Metal probe) and engine_pointer_cells' two compares now run on every profile and check Metal's answers. Its golden rows come at the next bless.
Verified:
- The M3 oracle's words for 8 threads x 8 words (m3-max-21796); runtime_lane::nullable_private passes on lavapipe (m3-max-21869); tests::engine_nullable_private passes on every committed profile, L3 and the CPU interpreter.
- clippy and rustdoc -D warnings are clean, and the metal2vulkan suite passes 3488 tests but the golden tables, whose only change is the new fixture's row (m3-max-21897, 21947).
- macOS 27's 590 MPS functions: 0 rows differ (m3-max-21838).
- The guest's surface-shading kernel moves past the refused phi (block 217) to the next refusal, a pointer store into an undisciplined closure array (block 300), which the next change addresses.
The private arena keeps its first word for null when a pointer into it may be null, so the two
tests that pinned the old refusal (an object at offset 0 would compare equal to null) now run the
kernels on the CPU interpreter on every profile: odd threads read the array's address back and
compare equal to it, even ones read null and compare equal to null.
- `memory::plan` tests: a select of an alloca's address and null puts the alloca in the private
arena past its kept first word (`null_word`, the alloca at 8, the arena 16 bytes); an arena no
pointer of which may be null keeps no word (the typed-alloca test's layout is unchanged).
- `tests::engine_nullable_private`: the owned fixture `nullable_private` compiles and passes L3 on
every committed profile, comparing its pointer's offset with null's
(`access.private.pointer_compare`), and on the CPU interpreter writes what the M3 Max writes
(`probes/nullable_private.m`, run on macOS 27.0.1, m3-max-21796).
- `runtime_lane::nullable_private`: the same words on the device the cfg selects, under the
validation layer.
Docs: `lower::access::local`'s module doc gives the null private pointer (offset 0 of the kept
word, its phi and compare) and narrows its list of what stays refused to the threadgroup and typed
pointers that may be null; `ContainmentPolicy::UnsafeOff` names a null thread pointer's
dereference (undefined in Metal) among the accesses it leaves unchecked.
Our own MSL, compiled by this Mac's toolchain (`scripts/regen-air-fixtures`): `closure_alloc`
hands out the next element of a thread's array at an index only the run knows, or null once the
array's room is used up, and two `noinline` callees null-check it. The AIR carries the shapes the
null private-arena pointer covers: `phi ptr [ %elem, ... ], [ null, ... ]` passed to `weigh` and
to `is_null`, each comparing its argument with null.
`probes/nullable_private.m` runs the same source on Metal and prints each thread's eight words,
for the runtime lane's comparison.
Blender Cycles' closure_alloc hands out a thread pointer into ShaderData's closure array at a
run-time index, or null once the array is full; its callers null-check it. The result is a `phi`
of the element's address and null (66 of them in the surface-shading kernel), and the private
arena had no null value: `lower::access::local::lowered_pointer` refused a phi with a constant
incoming pointer, and the compare of a pointer that may be null with null was refused
(Lowering(Access)).
The memory plan now keeps the private arena's first word (`ArenaLayout::null_word`,
`NULL_WORD` = 4 bytes) when some root set holds an alloca and the null root, so no object lies
at offset 0 and a null private pointer is offset 0, the value zero bytes already hold in a
pointer cell. Such an alloca is merged, so never typed: its pointers are private-arena offsets.
Then:
- a null (or undefined) thread pointer constant is offset 0 (`local_ptr`), so a `select` or
`getelementptr` may take it;
- a phi whose only constant incoming values are null takes them, its copy storing 0
(`pointer::phi_incoming`);
- a compare of a pointer that may be null compares offsets: null at 0 is below every object,
as Metal's null is, so unsigned and equality compares answer as Metal's; a signed compare with
null stays refused.
A dereference of null reads or writes the kept word (or, displaced, an object's bytes): undefined
in Metal, contained in the arena under containment, and unchecked under `UnsafeOff`.
The owned fixture `nullable_private` follows in the next commits.
Kernels whose accesses the analysis now proves apart (an access's span under the unsigned tests
of the branches that dominate it, an or of a constant the other operand's zero low bits cover,
anchors that differ by a multiple of a power of two plus a bounded part) lose lockstep barriers,
and with the simdgroup ones their cross-lane class and pinned subgroups.
What: a tile store whose anchor is a GEP over a GEP from a uniform base, the inner index a
thread's column (`t & 31`) and the outer one its block (`(t & -32) << 3` words), had no spread:
gep_spread takes one varying index over a uniform base only. So every pair of its rows (stores
128 bytes apart off one anchor) was a conflict, and in a block only a simdgroup barrier may
stand in, the barriers made the kernel cross-lane and, on a device with tangled 32-lane
subgroups (the Iris profile), pinned its subgroup to 32 lanes.
The anchor's spread may now be a lattice (Spread::Lattice): walking its GEPs down to a uniform
base, each non-uniform index adds stride * index, with the low zero bits both have
(low_zeros, at most the index width) and, where the index's range is known and not negative
as a signed index, the bytes it spans. For the largest power of two g whose terms with fewer
zero bits all have spans, summing to l below g / 2, two threads' anchors differ by a multiple
of g plus at most l either way: the terms at or above g are multiples of g, and g divides
2^index_bits, so a wrap at the index width keeps the multiple; a term whose range is unknown
or negative as a signed index only counts toward g. apart() then accepts a pair only where no
multiple of g lies strictly between down - l and up + l. The tile is l = 124, g = 1024: rows
128 * j apart, 1 <= |j| <= 7, never meet; the same row (j = 0) stays a conflict (two threads
may share a column where x is a position).
Tests: engine_simd_lockstep's tile_rows_apart_by_more_than_their_columns_take_no_barrier, on
the Iris and lavapipe profiles: the tile (four rows, two simdgroups' blocks) takes no lockstep
barrier and keeps (LaneArithmetic, Linear), its words 4 (t ^ 1) + 600 at 8, 16 and 32 lanes;
the same tile with rows 64 bytes apart (lane l + 16 of row k stores where lane l stores row
k + 1) keeps three simdgroup barriers, CrossLane(BASIC) and Direct on Iris or Emulated on
lavapipe, its words the later row's. a_guarded_access_apart_by_its_bytes_takes_no_barrier now
asserts (LaneArithmetic, Linear): its simdgroup index alone puts it on the linear tier, which
pins nothing.
The address facts took an `or` as a sum only where the IR states `disjoint`. A vector word
`2t | 1` beside `2t` (two 16-byte words a thread stores, as compiled AIR spells them without the
flag) was then no anchor of the even word's shape, so the two stores of different threads met
for every pair the guard's span left overlapping, and took a lockstep barrier.
`low_zeros` reads the low bits a value has zero from the IR (a constant's, a shift's or scaling's
by a constant, a mask's, a sum's, an extension's), and `disjoint_or` takes an `or` of a constant
not negative whose bits those zeros cover as the `disjoint` sum it is: in `plus_const` (whose
flags then state it), the summands, `range` and `inj_int`.
Test: `a_guarded_access_apart_by_its_bytes_takes_no_barrier`'s kernel stores both words; with the
span alone one lockstep simdgroup barrier stayed there.
The lockstep facts gave a guarded access no byte span: `range` read only the IR's own bounds, so
a store under `if (t < 4)` into the first 128 bytes of threadgroup memory spanned every offset a
thread index allows, and met every later store of its barrier interval. Each such pair took a
lockstep barrier, a simdgroup one where the place is uniform only per simdgroup, which raised
the kernel's simd class and, on a device with maximal reconvergence and pinnable 32-lane
subgroups, pinned its subgroup size to 32.
An access's span is now computed under its guards: every `x <u y` that `below` already records
for the branch edges dominating its block bounds `x` by `y`'s largest value less one, and every
exact step from `x` (extensions, shifts, masks, sums) carries the bound into the GEP index. The
value at the access is the one the edge tested, as for `below`. `range` also bounds `x | k` by
`max(x, k)` and `x + k`, which a vector word `2t | 1` needs.
Test: `a_guarded_access_apart_by_its_bytes_takes_no_barrier`, an owned kernel of that shape
(guarded vector words below byte 128, tile words from byte 128 through other address shapes),
on the Iris and lavapipe profiles: no lockstep barrier, no simd tier, and the interpreter's words
at 8, 16 and 32 lanes in both orders.
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.
The commit before this one splits WorkCounts::draws_rebind_stopped_arguments_other, which held 60.6% of Valley's draws at
pin 53 (reims's walkprof3-xtx), into 16 fields: draws_rebind_stopped_arguments_{unkept, restated, stale, unread,
unlisted, slots, images, reshaped, unsettled, checks, narrowed, worked, vertex_buffers, shadows, barrier, detached}.
_other keeps only the stops where every step reports an error. Behaviour is unchanged; api_signatures has the 16 rows.
Verified: cargo fmt; api_signatures --check passes; lint at the branch tip follows (m3-max-21906). The counters are for
a guest run that names the step stopping Valley's draws.
draws_rebind_stopped_arguments_other held every stop past the route, the plan's
tables, the fetch window and the reach. Sixteen new counters split it by the
rebind's step: the kept draw keeps nothing to rebind (unkept), a restated render
state, a carried draw's stale slot, a changed table read otherwise (unread) or no
longer listing its changes (unlisted), more changed slots than a rebind takes
(slots), images, a reshape, an unsettled bind state, every step's checks,
narrowed slots, set-0 writes or uses not worked out (worked), vertex buffers,
shadows, a barrier and a detached buffer. other keeps what is left: an error
every step reports. bring_in answers its stop; rebind sets the stop at each
return. Behaviour is unchanged.
The counters live in one array (draws_rebind_stopped_arguments_by), with the
public fields read from it; api_signatures gains the sixteen rows.
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.
The commits before this one carry a command buffer's kept draws to the next command buffer of the same queue, so its first draws no longer take every step.
- At commit, settle_end_committing hands the carry to the queue place (QueueShared.carried, one carry). An earlier carry nobody took is let go and counted in kept_draws_carry_dropped_commit.
- A render encoder whose command buffer holds no carry of its own takes the queue's, under the same fit checks. The taken draws are Kept::across. Their first rebound draw retains, into its own command buffer, what every step retains beyond the argument tables: the pipeline state, the variant's objects, the VkPipeline and the call's index buffer.
- The carry names guest objects only by key and raw handle (ResourceKey is never reused; pipeline states are held weakly). Draws with a failing DepthStencilState don't carry. Strong holds are the runtime's own objects only, one carry per queue place. So a carry keeps nothing the program released alive.
- New counter kept_draws_carried_across, with its api_signatures row.
- The debug cross-check of every second draw keeps counting across the commit. When it takes every step for a rebound draw, it now compares against the rebind's own reads through copies, which also covers a carried draw that samples a texture its new pass renders.
Measured in one exclusive job (m3-max-21803, gem10): the compositor's shape, before RV 2127 / at RV 2128 / this change, a draw:
- 780M (RADV), two rounds: thread CPU 24.17-23.77 / 22.38-20.84 / 19.78-20.45 us; cycles 68.1-71.2k / 60.8-62.6k / 55.8-58.7k.
- lavapipe: instructions 51,401 / 51,181 / 50,513; cycles 64.1k / 53.7k / 48.6k.
- Draws taking every step, a command buffer: 8 / 3 / 0.05 (the run's first command buffer).
Verified on lavapipe in debug:
- a_carry_its_queue_holds_keeps_nothing_released_alive: an index buffer over host pages released after the commit that left a carry is freed before the next command buffer's pass opens; a re-made pipeline state finds no kept draw and takes every step; pixels equal the same command buffers run each on a queue of its own. Negative control (m3-max-21792): leaking the index buffer in KeptIndex::of fails the test at "the released index buffer freed".
- carried_draws' Apart::CommandBuffers frames give the same counts and pixels as passes in one command buffer.
- The runtime suite passes 2361/2361 (m3-max-21845); the kept, carried, render and host-step lanes 133/133.
- clippy (every feature, --cfg m2v_gpu) and rustdoc -D warnings are clean (m3-max-21857); api_signatures --check passes.
The check of every second rebound draw compared the kept draw's reads through copies
(Kept::through_copies) with every step's; a carried draw's pass may render a texture its kept
draw's pass did not, so its rebind works them out again (record_rebound keeps them). The check
now takes the rebind's, so it checks that every step works out the same. Seen across a commit:
image_standing's chain test carried a draw that sampled a texture into another target into a
pass of that texture (field through_copies, named by a split of the assertion).
The kept draw's VkPipeline goes back into the comparison: a draw of a key's general form is
never kept, so a kept draw's pipeline is the one every step finds.
The check of a draw again compares the kept draw with every step's; a kept draw recorded through
its key's general form (a residual form while its own was made) records through that form
again, where every step finds the key's own made by then. Kept::made holds what the kept
recording names, so the check takes it as the kept draw's, as it takes the command buffer of a
carried one. Seen across a commit: image_standing's chain of passes in command buffers of their
own failed the check (a draw again kept another draw).
The fourth command buffer's pipeline state, made again after the first was released, is warmed
by runs on queues of their own; their counts (a carry let go between at each run's read back,
and their draws' every steps) are the device's, so the frame leaves that span out
(Frame::left_out).
A render encoder's kept draws carried at its command buffer's commit were let go there
(kept_draws_carry_dropped_commit), so each command buffer's first draws of each state took
every step: two of the eight every-step draws a compositor command buffer takes.
The commit now hands the carry to its queue's place (QueueShared::carried, one a place), and a
render encoder of a later command buffer of the queue that holds no carry of its own takes it,
under the same fit as within a command buffer. Its kept draws are across (Kept::across): their
first draw, rebound, retains into its own command buffer what every step retains beyond its
tables' objects: its pipeline state, its variant's objects, its VkPipeline (Kept::made, held
while kept) and the call's index buffer. The one the queue held, which none took, is let go at
the next commit that carries (kept_draws_carry_dropped_commit), counted;
kept_draws_carried_across counts the encoders that opened from one.
The carry names the program's objects by key and handle alone: the bind state holds values,
the kept draws' index buffers are keys and handles (ResourceKey is never reused), their
pipeline states are held weakly. A kept draw whose depth/stencil state fails every fragment,
whose settings hold that state, no longer carries: it takes every step once restated anyway.
So a carry the queue holds keeps nothing the program released alive; the runtime's objects it
holds (settles' variants, VkPipelines) are bounded by the one carry a place.
The debug check of every second carried draw goes on across the commit, so draws carried
across are checked and rebound in turn.
Tests: carried_draws frames gain Apart::CommandBuffers (carried across one queue) beside
Apart::Queues (a queue a pass, which carries nothing, the every-step reference), with the same
counts and pixels as the passes in one command buffer; and
a_carry_its_queue_holds_keeps_nothing_released_alive: an index buffer over host pages released
after the commit that left the carry is freed (its deallocator run) before the next command
buffer's pass opens, whose draw of another index buffer draws that buffer's triangle, and a
pipeline state released and made again finds no kept draw of its own (draws_none_kept).
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.
RUNTIME_VERSION 2128 gave metal2vulkan-runtime's Texture a second private tuple field, Option<Arc<Retain>>. Both fields
are private, so nothing breaks for a consumer; the table prints the struct's declaration and moves with it. Written with
`python3 scripts/api-signatures/signatures.py --bless`; only that row moves.
The commits before this one fix a leak of released heap textures. Residency::use_heap and sync_heaps took Heap::textures_from, which upgraded every texture in the heap's weak list that had any strong handle. A texture the program had released, but that an in-flight command buffer's residency still held, was joined again to each next command buffer. While frames stayed in flight that relay never broke: the texture, its image and its automatic-heap range went only once the device drained. Metal's useHeap retains the heap only.
Now each texture handle the program holds carries a per-texture Retain token; TextureShared keeps a Weak to it. Heap::textures_from takes a texture only while its token lives and hands it out as a heap use holds it (Texture::for_heap_use), without the token. It upgrades under the list lock and filters after the lock is free, so a last handle never drops under the lock. A texture already joined to an in-flight command buffer stays held there until that buffer completes. Handles the runtime holds other than heap uses (encoder bindings) also hold the token, so a released texture still bound in an in-flight command buffer can be taken by one more useHeap; that hold ends when the buffer completes and cannot relay. The residency module docs, HeapShared.textures and both public use_heap docs say so.
Verified on lavapipe in debug:
- tests::heap_use_released::released_heap_textures_go_while_later_users_of_the_heap_are_in_flight (an automatic Private heap with 1 kept and 128 released textures; frames gated on a shared event) fails before the fix with 0 of 128 gone after 10 s (m3-max-21680) and passes after: 128 of 128 gone in 0.09 s, with the kept texture's texels right in all 4 frames (m3-max-21703).
- The runtime's heap and residency tests pass 129/129 (m3-max-21703), and the validation lanes for heaps, residency, used_resources, resource_ids, rebind_reach and executions pass 271/271 (m3-max-21707).
- fmt, clippy (default, --cfg m2v_gpu, --cfg m2v_cpu_icd) and rustdoc -D warnings are clean (m3-max-21704, 21706).
Not run: the Iris Xe or the consumer's guest.
A heap texture the program released was kept until nothing that used its heap was in flight. Each
use_heap and sync_heaps took the heap's textures from its weak list (Heap::textures_from), which
upgraded every texture with any strong handle. A released texture that an in-flight command
buffer's residency still held was therefore joined to the next command buffer's residency, and
from that one to the next. While frames stayed in flight that relay never broke, so the texture,
its image and its automatic heap's range went only once the device drained.
Metal's useHeap: retains the heap, not its textures. A texture's handles now hold a Retain token
(texture::Retain) that a heap use's handle does not hold. Heap::textures_from takes a texture only
while its token lives, and hands it out as a heap use holds it (Texture::for_heap_use): the object
without the token. A texture already joined to an in-flight command buffer's residency stays held
by that command buffer until it completes. A later use of the heap no longer takes it, so it goes
once the command buffers that used it while the program held it complete. Handles that
Texture::upgrade makes hold the token only while another handle does. Textures that are dropped
while textures_from upgrades them go with the heap's list lock free.
The residency module docs, Heap's list docs and both use_heap docs say so.
Verified: tests::heap_use_released, the lavapipe device test of this shape, failed at f9b3024777
(the test alone, m3-max-21680): 0 of 128 released textures gone while the three later frames
waited. The after run is on this commit.
A device test: an automatic Private heap holds a texture the program keeps and 128 more. A first
frame, gated on a shared event, uses the heap and reads the kept texture through its resource ID.
The program releases the 128, commits three more gated frames that use the heap, and signals the
first frame alone. Once it completed, every released texture must go while the later frames still
wait; then each frame read the kept texture's texels.
Today each later frame's use_heap takes the released textures again from the heap's list, which
finds them alive in the first frame's residency, so they go only once nothing that used the heap is
in flight. The fix follows; this commit is the before.
The engine inventory, golden hashes and air_input printouts were re-blessed on the M3 at development a96e93f4da (job m3-max-21679). The inventory, golden and printout steps each exited 0.
What moved:
- icb_depth_indexed_encode, which 82fd1b6108 edited: its new dio_encode_strided kernel has rows in golden_hashes.tsv and public_fixture_expectations_engine.tsv (its profile verdicts match dio_encode's), and the fixture's source hashes and printout changed. The existing kernels' output hashes are unchanged.
- The tns_mm printouts (edge, flags, float, int): SEMANTICS_VERSION 2054's Tensor variants now print `InitStrided { data: Device, trailing: false }` and `Extent { trailing: false }`. Their golden SPIR-V hashes are unchanged.
No other fixture's row moved.
The merged check at the same sha passed (m3-max-21678).
Under METAL2VULKAN_LANE_VALIDATION=sync on lavapipe the runtime lane failed 31 tests on
the layer's hazard reports. At def64b1999 it failed 34: these 31, plus write_routes and two
frame_costs tests, all since fixed in the runtime (write_routes in 14c0b28928 and 952755253f).
None of the 31 is a missing barrier. Each is one of:
- the layer taking a shader's storage buffer as written over its descriptor's whole range;
- the layer reading no indirect draw's counts;
- a difference the runtime already announces;
- a test program's own race, which Metal leaves unordered too.
Claims (runtime_lane::apart_writes, runtime_lane::stage_races; docs/VALIDATION.md's table):
- NotedWrites notes every write a test places in a buffer: a dispatch's, a draw's, a fill's, a
bounded draw's or a patch draw's, by command buffer. The layer's hazard reports are held
apart, each distinct one once with its count, so a claim reads every report.
- LAYER-APART-WRITES, widened from dispatches to draws and fills: a write after write between
noted writes, each one Vulkan command's, no two of which share a byte.
- LAYER-IDLE-DRAW: the index bounds pass's two vkCmdDrawIndexedIndirect of one bounded draw,
reported as recorded, one such draw noted per command buffer, on a device that announced
indirect-index-bounds-pass. At most one of the two draws.
- LAYER-IDLE-CHUNK: an emulated patch draw's vkCmdDrawIndirect chunk draws, reported as
recorded, the patch draws of each command buffer noted apart, on a device that announced
emulated-tessellation-draws. The tests keep each patch draw below 2^30 triangles and the scan
writes vertexCount 0 past them, so at most one chunk of a draw draws.
- LAYER-STAGE-RACE: a later draw's vertex stage against an earlier draw's fragment stage of one
pass, on a buffer the test names, reported as recorded, of the kind whose notice the device
announced (in-place-vertex-reads, fragments-before-geometry).
- Each form has unit tests of the shapes that pass and of those that must fail.
Tests:
- draw_bases, index_fetches, index_pools: bounded draws noted (idle draw).
- int_attributes, normalized_vertex_fetch, memoryless_uses, render_executions,
render_gpu_executions, predication: their writes noted apart.
- argument_buffers moves to NotedWrites.
- patches, patch_indices, render_executions' indexed patch commands: patch draws noted (idle
chunk on the emulation, apart draws on a device with tessellationShader).
answer_as_plain_metal gives each draw that runs a marks buffer of its own: Metal orders no
draw's vertex writes after another's in a pass.
- pass_start_reads: the stage-race claim.
- helper_select: a texture memory barrier between its draws, whose storage image the layer
takes whole.
Verified on lavapipe (CPU ICD), the same sync command at base and tip (whole runtime lane,
--success-output immediate, claim lines printed):
- base 13e0a9b60b, m3-max-21616: 2019 run, 32 failed. That is the 31 above, plus depth_executions,
a regression from RV 2124 fixed on its own branch.
- tip, m3-max-21631: 2032 run, 1 failed (depth_executions). 31 tests passed with claim lines.
- clippy (every feature, --cfg m2v_gpu, --cfg m2v_cpu_icd) and rustdoc clean, m3-max-21617.
Fixes runtime_lane::depth_executions::a_frame_s_executions_wait_for_the_culling_alone. It has
failed since 5766d29051 (SEMANTICS_VERSION 2051, RUNTIME_VERSION 2124), with steps 0, gates
narrowed 0 and correct depths.
Cause: the test lost its premise; no behaviour regressed.
- Its state fetches one float3 stage_in attribute from a fixed 12-byte layout.
- Before RV 2124, plan_replay refused every vertex fetch under replay bindings. So each execution
took the host step, and the test counted those steps' narrowed gates.
- RV 2124 lets a replay pull fixed-function layouts (draw_replay_vertex_layouts). These executions
now run on the GPU alone, with no host step and no gate.
Fix:
- The fixture icb_depth_indexed_encode gains dio_encode_strided. It is dio_encode with the
positions bound at a stride of 12 bytes of its own (set_vertex_buffer(positions, 12, 0)), for a
state whose layout takes its stride per bind. Its companions are regenerated with
scripts/regen-air-fixtures.
- Workload::with_strides(device, per_bind) makes that state (layout stride None), the buffer with
supportDynamicAttributeStride, and the strided kernel.
- A layout whose stride is set per bind keeps the host step (DrawReplayRule::VertexAttributes: a
command's stride lives in its record alone). So the narrow-gate frame takes two host steps
again, and each gate leaves out the unrelated fill and, for the second step, the first pass's
batch: (2, 2).
- Visibility results were tried first and rejected. They keep the host step too, but they unbind
the steps' reads (DeferredPass::bound is None for an execution that counts), so no gate
narrows: (2, 0).
- The fixed-stride shape stays as a_frame_s_executions_at_a_fixed_stride_run_on_the_gpu, which
checks for no host step and no gate, (0, 0), with correct depths.
- The frame's body moved into frame(device, per_bind). It checks the statuses, the refusal and
the depths, and returns (steps, narrowed).
The new kernel adds rows to the translator's fixture tables (public_fixture_expectations_engine.tsv,
golden_hashes.tsv, tests/air_input/icb_depth_indexed_encode.txt). They are left for the bless on
development.
Verified on lavapipe in debug, m3-max-21648, one run each without and with
METAL2VULKAN_LANE_VALIDATION=sync:
- the strided frame printed steps 2, gates narrowed 2;
- the fixed-stride frame printed steps 0, gates narrowed 0;
- the depths were correct in both, and all three depth_executions tests passed each time;
- clippy of metal2vulkan-validation (every feature; plain, --cfg m2v_gpu, --cfg m2v_cpu_icd) is
clean.
SEMANTICS_VERSION 2054 (cd3e2a9274) added the AIR 2.9 forms of the private tensor intrinsics as a `trailing` field on
two metal2vulkan-air variants, and the committed signature table was not re-written with it; the merged check at
cd3e2a9274 failed api_signatures (m3-max-21650).
What changes for a consumer of metal2vulkan-air: `Tensor::Extent` is now a struct variant, `Extent { trailing: bool }`,
and `Tensor::InitStrided` gains `trailing: bool`. A match on `Tensor::Extent` as a unit variant, or constructing either
variant without the field, no longer compiles.
Written with `python3 scripts/api-signatures/signatures.py --bless`; only those two rows move.
The commits before this one add the forms of two tensor intrinsics that Apple's compiler emits at macOS 27 (AIR 2.9, air64_v29):
- air.init_strided_private_tensor.i32.{global,local} is now void (ptr, i16, ptr data, ptr, ptr, i8, ptr same-space, i32, i8), three operands more than AIR 2.8's;
- air.get_extent_private_tensor.i32 is now i32 (ptr, i16, i16, i16), one i16 more.
Tensor::InitStrided and Tensor::Extent each gain `trailing`, the AIR 2.9 form, through the existing `alternative` mechanism.
canon's tensor form models the AIR 2.9 calls only when the new operands carry the values every call read so far passes: null, 0 and -1 for init, and 0 for extent. That covers every MPS row read and our own tns_mm sources compiled as MSL 4.1 for macOS 27 (m3-max-21620). Any other value stays a call and is refused as an unmodeled tensor operation, since what those slots carry otherwise is not established. New tests cover classification of both forms and of near-misses, and canon accepting only those values.
Verified:
- At 43eb38517e: metal2vulkan-air passes 558/558, clippy and rustdoc -D warnings are clean (m3-max-21641), and engine_matmul2d passes 14/14 (m3-max-21645).
- Of macOS 27's 590 MPS functions in release on RDNA3 (m3-max-21638), all 55 DeclaredSignatureMismatch rows move past decode:
- 3 translate and pass spirv-val;
- 12 reach the existing honest refusal of a matmul2d run of the single-thread or v2 form;
- 40 reach GenericPointer(Memory).
160 rows translate (157 before). The slowest row takes 0.34 s and the largest peak is 198 MB.
Not run: execution of an AIR 2.9 tensor kernel on a device.
With the strided initialization's AIR 2.9 form read, three MPS census rows still stopped at
decode on `air.get_extent_private_tensor.i32`: macOS 27's compiler declares it `i32 (ptr, i16,
i16, i16)`, and all 972 calls in one such row pass 0 there. `Tensor::Extent` gains `trailing`,
the AIR 2.9 form, through the same `alternative`; canon's tensor form models the AIR 2.9 extent
only with 0 there and leaves any other a call (refused as an unmodeled tensor operation). The
module docs say what AIR 2.9 adds to the tensor operations and which values are modeled.
Tests: both declarations classify (two other operand lists are mismatches); canon's form reads
the added operand at 0 only.
Apple's compiler at deployment target macOS 27 (AIR 2.9, `xcrun metal` 32023.922) declares
`air.init_strided_private_tensor.i32.{global,local}` as `void (ptr, i16, ptr data, ptr, ptr, i8,
ptr, i32, i8)`, the added pointer in the data's space. The table knew only AIR 2.8's six operands,
so every module that initializes a strided tensor from macOS 27's compiler was refused as
DeclaredSignatureMismatch at decode (55 rows of the MPS census).
`Tensor::InitStrided` gains `trailing`, the AIR 2.9 form, which the name's `alternative` gives,
as a barrier's and an indirect buffer setter's do. Every call seen (our own tns_mm fixtures
compiled as MSL 4.1 for macOS 27, and the MPS rows) passes null, 0 and -1 there; canon's tensor
form models the AIR 2.9 call only with those values, and leaves any other a call, which is
refused as an unmodeled tensor operation, since what those operands carry otherwise is not
established. The object's initialization is the AIR 2.8 form's.
Tests: the two AIR 2.9 declarations classify as the trailing form (and three other operand lists
as mismatches); canon's form reads the added operands at Metal's header values only.
The probe on the Radeon 780M (m3-max-21640, Mesa 26.2.6): a dma-buf
DRM_FORMAT_MOD_LINEAR plane at rows 256 bytes apart is made at offsets 0
and 256 and refused at offset 32
(VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT), and an image's
memory offset must be a multiple of its own alignment
(VUID-vkBindImageMemory-None-10735), so the gap row names the offset as
well as the pitch.
Verified: the cited device run.
dma_buf_rows_the_device_lays_no_plane_at adds BGRA8Unorm 64x8 planes at
rows 256 bytes apart at offsets 256 and 32, beside the one at offset 0:
whether RADV refuses a dma-buf DRM_FORMAT_MOD_LINEAR plane for its offset
where its pitch is one it lays rows at. rows_the_device_lays_no_linear_
image_at prints what the device reports of reading RGBA16Float through a
uniform texel buffer (buffer features, minTexelBufferOffsetAlignment,
maxTexelBufferElements, VkPhysicalDeviceTexelBufferAlignmentProperties):
the documented facts a texel-buffer read of rows at a pitch no image
takes would rest on.
Verified: cargo fmt; device runs follow.
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.
The commits before this one carry kept draws that read their own pass's attachment through a copy (a compositor's backdrop draws) to the next encoder, where before each took every step.
- A carried rebind works out its own shadow uses, gathers them into its new instance, and keeps them with its through_copies.
- Kept::carries still refuses a narrowed slot, and a narrowed mismatch counts as CarryStop::Attached.
- This also fixes a latent bug: a carried draw whose shadow uses equalled its kept draw's gathered nothing into its new instance.
- New WorkCounts fields: draws_none_kept, kept_draws_uncarried_attached and kept_draws_carry_dropped_commit (CarryDropped::Commit). The api_signatures rows are added.
Measured on lavapipe (gem10, the compositor's shape, m3-max-21621), base / counters / carry, a draw:
- instructions 51,335 / 51,312 / 50,972 (-0.7%);
- cycles 64,048 / 65,421 / 51,272 (-20%);
- cache misses 2,442 / 2,471 / 1,545;
- thread CPU 16.19 / 16.66 / 13.11 us (base's range 15.9-16.7 and the carry's 12.7-14.3 do not overlap).
A command buffer: draws_none_kept 8 -> 3, draws_rebound_carried 8 -> 13, kept_draws_uncarried_attached 6 -> 0; the copies are unchanged (shadow_copies 6, attachment_reads_through_copies 6).
Verified:
- carried_draws::a_carried_backdrop_reads_its_own_pass_s_copy passes. With only the carried draw's gather left out, it fails on pixels: the bottom half reads the clear colour from a stale copy (negative control m3-max-21635).
- Lavapipe debug device tests pass 38/38 and the lane set passes 133/133 (m3-max-21622): carried_draws, kept_shadowed_draws, draw_again, attached_read faces and levels, kept_*, render executions, host steps.
- clippy with every feature and under --cfg m2v_gpu, and rustdoc, are clean for the runtime crate (m3-max-21623).
A window compositor's backdrop draw reads its own pass's color attachment through the texture's
copy (texture/attached_reads.rs), and each pass holds one: the only draw of its state in its
encoder. Kept::carries refused such a kept draw, so each pass's backdrop found no kept draw of its
state and took every step: 6 of the compositor shape's 35 draws a command buffer.
Such a kept draw now carries (Kept::carries refuses only a slot narrowed to levels apart from the
attached ones). The carried draw's rebind no longer stops at an attached read. Its kept draw's
shadow uses were gathered into the ended encoder's instance, not into this one, so a carried draw
works out its own (draw_shadows, as every step), gathers them into its instance with its uses
(Rebinding::gathers), whose plan then copies them in before it, and keeps them, with its reads
through copies, for the encoder's next draw rebound to compare with. It goes on only where it uses
shadows exactly where its kept draw did, which keeps Kept::again (never set for a draw that uses
shadows) as every step's. A carried draw whose slot is narrowed where its kept draw's was not stops,
counted in draws_carry_stopped_attached; kept_draws_uncarried_attached counts the narrowed alone.
Before this, a carried draw whose shadow uses equalled its kept draw's (the same shadowed texture,
another encoder) gathered none into its new instance; it now gathers them as every step does.
Test: carried_draws::a_carried_backdrop_reads_its_own_pass_s_copy. Passes over one loaded target,
each a backdrop (tob_read at its own pixel) then a solid color. The backdrop carries and must read
its pass's copy, which the pass before changed. Pixels equal to the same passes in command buffers
of their own and to each pass's color; counts: 5 carried draws rebound, draws_none_kept 2 against
7. The carried_draws module's narrowed test keeps its counts, its stop now at the narrowed slot.
A render encoder's direct draw whose encoder kept no draw of its pipeline state takes every
step, and no count said so: the compositor shape's 8 such draws a command buffer (of 35) showed
only as the 27 rebound subtracted from the draws. New counts:
- draws_none_kept: direct draws whose encoder kept no draw of their state to draw again or
rebind (not replayed or rerouted draws);
- kept_draws_uncarried_attached: kept draws an ended encoder let go that would carry into the
next render encoder but read a texture an attachment of their pass renders (through its copy,
or a slot narrowed to levels apart from the attached ones);
- kept_draws_carry_dropped_commit: a carry let go at the commit, which was let go uncounted
(CarryDropped::Commit; `let_go_carried` takes its cause, as every caller now names one).
Kept::carries is split into the attachment reads and the rest, so the encoder's end can tell a
draw that would carry but for them.
The engine inventory, golden hashes and air_input printouts were re-blessed on the M3 at development fa888c88a8 (job m3-max-21619). The inventory, golden and printout steps each exited 0.
The only change is the generic_pointers fixture, which SV 2052 and SV 2053 edited: it has the new kernels generic_slots, generic_fields and generic_array, and its source hashes changed. Its rows in golden_hashes.tsv and public_fixture_expectations_engine.tsv, and its printout, are replaced. The existing kernels' output hashes are unchanged, and no other fixture's row moved.
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.