diff --git a/CHANGELOG.md b/CHANGELOG.md index 24d61fce9c..b98734c5e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ Bottom level categories: #### WebGPU +- Implement the `device_set_device_lost_callback` method for `ContextWebGpu`. By @suti in [#5438](https://github.com/gfx-rs/wgpu/pull/5438) - Add support for storage texture access modes `ReadOnly` and `ReadWrite`. By @JolifantoBambla in [#5434](https://github.com/gfx-rs/wgpu/pull/5434) ### Bug Fixes diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 52a4d2931e..acd3561461 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -1979,10 +1979,23 @@ impl crate::context::Context for ContextWebGpu { fn device_set_device_lost_callback( &self, _device: &Self::DeviceId, - _device_data: &Self::DeviceData, - _device_lost_callback: crate::context::DeviceLostCallback, + device_data: &Self::DeviceData, + device_lost_callback: crate::context::DeviceLostCallback, ) { - unimplemented!(); + use webgpu_sys::{GpuDeviceLostInfo, GpuDeviceLostReason}; + + let closure = Closure::once(move |info: JsValue| { + let info = info.dyn_into::().unwrap(); + device_lost_callback( + match info.reason() { + GpuDeviceLostReason::Destroyed => crate::DeviceLostReason::Destroyed, + GpuDeviceLostReason::Unknown => crate::DeviceLostReason::Unknown, + _ => crate::DeviceLostReason::Unknown, + }, + info.message(), + ); + }); + let _ = device_data.0.lost().then(&closure); } fn device_poll(