wgpuDeviceGetLostFuture implemented in the WebGPU C API
Component: WebGPU | d5b102b
Source/WebGPU/WebGPU/CAPI/CAPIFutures.h
Source/WebGPU/WebGPU/CAPI/CAPIDevice.mm
The WebGPU C API (webgpu.h) uses futures instead of callbacks. wgpuInstanceWaitAny() drains instance events and reports completed futures, and an EventManager tracks them under a lock. WebGPU::Device exposes a single device-lost callback slot, and replacing it completes the old callback. For Web Process proxy devices, loss arrives as the async ResolveDeviceLostPromise IPC reply. If the GPU Process exits, that reply is cancelled with a Destroyed reason.
EventManager now keeps a per-device lost future in a Vector of weak device refs. The first wgpuDeviceGetLostFuture call takes the device's callback slot to complete the future, and later calls return the same future. ResolveDeviceLostPromise is marked ReplyCanDispatchOutOfOrder so wgpuInstanceWaitAny() can dispatch it, and the entry point is wired into ANGLE's Dawn proc table.
Significance
ANGLE's WebGPU backend can now detect device loss and report it as a context reset, including for Web Process devices handed over via retainCAPIHandle(). This comes with new exported C API surface, thread-signalled completion, and an out-of-order IPC reply path.
Audit directions
Start with lifetime. m_deviceLostFutures holds ThreadSafeWeakPtr<Device> while the device's callback references the EventManager. Check the lock/weak-ref interplay in deviceLostFuture(), didLoseDevice() and isDeviceLostFuture() when the callback fires during or after device destruction, and whether the Vector is ever pruned. The callback can run on the IPC dispatch thread, the destroying thread or the waiter thread, so check lock ordering against m_lock and the condition-variable signalling in timed waitAny(). The single slot means a client installing its own callback completes the future as a false loss, and the Destroyed reply is indistinguishable from a replaced callback; map the state transitions that allows. ReplyCanDispatchOutOfOrder lets the reply run inside wgpuInstanceWaitAny(), so check reentrancy and replies that arrive mid-dispatch or after device release.