Metal's MTLDevice survives a GPU recovery; the runtime's device refused every
call with DeviceLost from the first loss on, and the consumer ends its VM at
the first refusal. Now a device the runtime made is a line of generations
(device/line.rs), each a DeviceShared over its own VkDevice, and the first call
that needs the device after a loss makes a new VkDevice of the same physical
device, options, queue families and extensions.
- Two kinds of handle. The program's device (and its clones) is a root handle:
it holds the line, pins no generation, and every public Device call goes to
the generation that serves (each public method forwards to its *_now body).
Objects hold generation handles, so their Vulkan calls, drops included, reach
their own VkDevice alone. A generation handle's check is one relaxed load of
the line's generation (Device::generation_serves).
- A draw pays nothing for it. A command buffer takes its generation once, as
it is made (CommandBuffer::generation); its encoders' per-draw reaches (work
counts, fresh-unwritten and alias records, sampler-slot changes, attachment
read notices) read it there, not through a device handle's kind. A bind's
device check is one compare of the cells the two handles hold, inlined, its
refusal (Device::foreign) out of line.
- The state machine (Live, Lost, Failed): the claiming call recovers, every
other call waits (a notice past 10 s, waiting on); threads command buffers'
completion depends on never wait. Recovery: the lost generation's command
buffers in flight fail through its completion path, its queues drain under
their locks, create_on makes the next VkDevice, the queues are retired.
- Command-buffer answers, as a real loss is one more hang: the oldest
incomplete batch's command buffer fails GpuHang (exact on one VkQueue; on two
or more the queue whose oldest incomplete batch was submitted first, said so
in the notice), counted against its queue so the second revokes it
(AccessRevoked); the others GpuRecoveryVictim; one committed on the hang's
queue before the recovery runs nothing and completes with no error; one made
before and committed after fails GpuRecoveryVictim. One loss names one hang:
a batch that went to the driver just before the loss and reached the lost
device's completion after the loss took the pending batches fails with it,
as a victim (its own wait need not fail: the test hook's VkDevice runs it),
and no later failure of the lost device names a second hang.
- Command queues survive: a queue is a root handle and a cell of its place on
one generation (VkQueue, slots, pools, hangs), which a recovery retires and
the next command buffer re-makes; label and GPU-error count go on.
- Objects made before a recovery are refused where they meet the new VkDevice
or need their lost one: RuntimeGap::MadeBeforeRecovery, at the 38 lost-device
checks (Device::lost_refusal) and at every foreign-object check of one line
(Device::foreign). DeviceLost stays for a device the consumer made.
- Carried across generations: the address space, resource IDs and the passing
holds a making waits out before it takes one, unique identifiers, counters
and the announced notice kinds.
- A device handle is an enum of the two kinds (24 bytes, was 16): the shadow
merge's copy-back dispatch, which holds handles, is boxed (clippy's
large_enum_variant).
- Device::recover_for_test (public, documented) runs the whole path with no
GPU fault; RuntimeGap::AdoptedDeviceRecovery on an adopted device.
- Degradation::DeviceRecovered (device-recovered), announced at each recovery
with the culprit and its time. WorkCounts::vk_devices_live, vk_devices_made,
device_recoveries: two VkDevices while objects of the lost one live, one
after.
Docs: docs/API.md catalogue entry, the runtime README's device-loss section,
FAST-PATHS known gap (a make whose own submission first meets the loss is
refused DeviceLost), docs/REFUSALS.md regenerated (refusal_surface.py names a
forwarded body's sites by its public method), api_signatures blessed.
Tests: runtime_lane::device_recovery (hang and victims, command buffers on
their way to the driver at a recovery, MadeBeforeRecovery and the VkDevice
bound, revocation at the second hang, a command buffer made before fails as
victim, all under the validation layer; a recovery that finds nothing of the
queue scheduled names no hang, its command buffers victims),
tests::device_recovery (the hold of the hang's queue between a loss and the
recovery), detach_lost and the MoltenVK lost-device lanes updated to the
recovery's answers.
Verified:
- lavapipe: runtime suite and touched validation tests 1850/1850, surface
19/19 (m3-max-5695, gem10, before the rebase onto 7e039f062a); on
7e039f062a, before the one-hang fix, 1853/1853, surface 19/19, clippy clean
(m3-max-6150, ms01). This tree: clippy clean (m3-max-6278, msi).
- RADV RX 7900 XTX: 81/81 touched device tests (m3-max-5709). Iris Xe (ANV):
80/81 (m3-max-5766), the 81st kept_images, which fails so at development
too and the last of these three commits fixes; the recovery tests alone 3
rounds of 3 (m3-max-5852). RTX 5080 Laptop GPU: 80/81 (b5080 entry
devloss-devloss-tip1-nine-163410), the 81st the test's own 20 s bound on
the recovery, which took 39.5 s beside another entry; the test now prints
the recovery beside the device's first making and bounds neither.
- MoltenVK on the M3 Max: the device_recovery tests 8 rounds of 8
(m3-max-6135); with the one-hang fix 12 of 12 (m3-max-6242), where without
it 3 rounds of about 20 failed with a command buffer Completed after the
hang (m3-max-6219, m3-max-6233). The RTX 5080 failed the second-hang test
so in 2 runs of 3 (devloss-devloss-rec-alone-170457).
- Recovery time, alone, under the validation layer: llvmpipe 29.9 ms, RX 7900
XTX 20.4 ms, Iris Xe 15 to 21 ms (its first making 30 to 41 ms), M3 Max
(MoltenVK) 35 to 40 ms (42 to 50 ms), RTX 5080 530 to 559 ms (602 to 635
ms). VK_EXT_device_fault listed: llvmpipe 0, XTX 1, Iris 0, 5080 1.
- Per draw (draw_costs, release, --heap, M3 Max, base 7e039f062a and the tip
alternating, 4 rounds, m3-max-6121): instructions a draw ws +0.03%, many
-0.05%, 10k -0.31%; draw_primitives +10, +8 and -26 of 17,172, 11,245 and
7,736 a call; each set_* call +3 to +4 (of 425 to 860); a command buffer's
creation +170 to +370, an encoder's end +120 to +390.
(cherry picked from commit 3d7758c074fc9895d5d6c9766604c6c4eae9166d)