dma_buf_leak_4_threads ended in SIGABRT on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, round job
m3-max-16620 at 600b535875). One of the two causes: once a test had failed and the process
exited, a device that dropped after the exit guard closed let go of its recorder slot, clearing
the slot's entry points, while a thread of that device's (the queue-switch check making its
objects) was still inside a section and recording through the slot. The slot's missing-command
thunk then panicked inside an extern "system" function, which aborts.
Every other path that lets go of a slot is the device's ordinary drop, which runs after the
device's threads stopped and so with no section of theirs live. Only an exit leaves sections
running past the slot's release: a section that started runs to its end. Slot::drop now enters
the exit guard; once the guard has closed it returns at once and leaves the slot as it is, with
its entry points stored and its index taken, just as the exit leaves the device to the process's
end.
Test: exit_guard::a_slot_let_go_of_while_the_process_exits_keeps_its_commands. A forked child
routes a stand-in device's functions through a slot and registers the hook. An exit handler that
runs after the hook drops the slot and records through it, and the child expects the stand-in to
be reached.
Verified: the test passes on CPU (potluck m3-max-16978) and in the RTX 3090 run (m3-max-16941).
It fails without the guard check (m3-max-17034, whose child aborts in the thunk).
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.
On a driver with one graphics queue, an unshared queue (a compositor's) shares its VkQueue with
the application's queues. DevicePolicy::unshared_isolation (Bounded, the default; Off) now holds
the other queues' batches back so that an unshared batch waits behind at most about one of them:
- a batch is submitted ahead of the unshared queue's only while the work already submitted ahead
is expected to end within the bound (each queue's expected run from its batches seen complete);
- a batch of a queue with no run seen yet holds the others back until it completes;
- an unshared batch seen complete in the same completion turn as another queue's takes no share
of that batch's run;
- an unshared queue's batches never wait in a group, and no group is kept, on a held VkQueue;
- nothing is held back on a lost device, whose submissions fail at once.
FAST-PATHS records the switch, its measured benefit and its cost under host CPU load.
Measured (owned workload: an app keeping 3 command buffers in flight, a compositor every 16 ms;
Off -> Bounded):
- Iris Xe, quiet host (m3-max-16880, 16885): 30 ms command buffers: compositor p50 75 -> 17.5 ms,
p99 90 -> 37-38 ms; app 33.2-33.3 vs 33.3-33.5/s. 5 ms: p50 12.6 -> 4.7 ms, p99 15 -> 7.2 ms;
app 198.3-198.4 vs 196.4-198.0/s.
- 780M, host load 6-19 (m3-max-16900): 30 ms: p50 71-84 -> 18 ms, worst 94-114 -> 35-40 ms.
5 ms: p50 10.5-11.8 -> 4.2-5.1 ms.
- Cost under host CPU load: Iris 5 ms at load ~10, 181.8 vs 189.3/s (16885); 780M 192.4 vs
203.7/s (16900).
- Unit tests that fail without their fixes:
an_unshared_batch_seen_complete_with_another_queue_s_leaves_it_the_whole_run (22.5 ms instead
of 30 without the fix) and a_batch_of_unknown_length_holds_the_next_back_until_it_completes.
- lavapipe device test, both values: Bounded runs the unshared command buffer between the two
long ones (41.8-42.0 ms); Off runs it last (125.1 ms).
- Lint (fmt, clippy three ways, rustdoc) m3-max-16928, 16945; api/fast_paths 41/41 and lavapipe
unshared_hold + queue_share 26/26 (16929, 16937), at 37eae90024 (the same code before rebase).
Under Off the unshared command buffer runs after the third long one, and the print subtracted its
end from the second long one's start: -76.28 ms of 'GPU idle' on lavapipe (m3-max-16929). A print
only; the assertions are unchanged.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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).
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.
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.
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.
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).
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.
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).
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).
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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).
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.