WebGPU Device Lost Event – Interoperability with Browser Upgrade
0 reputation · 25 Oct 2022, 05:16 UTC
0 reputation · 25 Oct 2022, 05:16 UTC
The goal is to safely recover from a WebGPU device loss that may occur during a browser upgrade, ensuring no pending command buffers are silently discarded.
In practice, applications submit command buffers in a rendering loop, then await the next frame. If the device is lost mid‑frame, the timing of the device.lost event relative to those queued commands can vary between browsers.
The WebGPU spec currently permits either synchronous or asynchronous loss notifications, and recent releases have shown different emission points—some fire immediately after the crash, others after the next poll or frame.
Given this nondeterminism, developers must guard against both scenarios, but the precise boundary remains unclear.
Specific questions:
device.lost event fire before or after any command buffers queued in the current frame?33275 reputation · 25 Oct 2022, 08:32 UTC
1. Does the device.lost event fire before or after any command buffers queued in the current frame?
According to the WebGPU specification, the timing of device.lost is implementation‑specific: it may be delivered synchronously (immediately when the loss is detected) or asynchronously (queued as a task). Therefore the spec does **not** guarantee whether the event occurs before or after command buffers submitted in the same frame.
2. If it fires asynchronously, at what point in the rendering pipeline is it guaranteed to be observed?
Observed behavior in current Chrome (≥124) and Firefox (≥128) is that the lost event is fired as a microtask **after** the current render frame has finished. At that point any queue.submit calls made earlier in that frame have been recorded (and may have begun execution), but work that was still in‑flight on the GPU may not yet be complete. No earlier guarantee exists across browsers.
3. Are there any version‑specific guarantees that browsers will provide a consistent loss timing in future releases?
No. The timing is explicitly left to the implementation and may change in future releases. Developers must treat device.lost as potentially arriving before or after any given frame’s command buffers.
device.lost event on the GPUDevice.device.lost.promise to ensure the loss notification has been fully processed.device.queue.onSubmittedWorkDone() to flush any previously submitted work that might still be executing on the GPU.device.destroy() if needed) and request a new adapter and device via navigator.gpu.requestAdapter() and adapter.requestDevice().By waiting for the lost promise (and optionally the queue’s completion promise) you guarantee that no in‑flight work is silently discarded, regardless of whether the loss notification arrived before or after the current frame’s submissions. The subsequent recreation of the device with a fresh queue provides a clean state for resubmission.
If you need to distinguish whether the loss happened before or after a particular frame’s work (e.g., to decide whether to resubmit or skip a frame), you would need a timestamp or frame‑counter that is recorded both before submitting work and when handling the lost event. Without that detail, the safe‑recovery approach above remains the recommended course.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.