Implement the device_set_device_lost_callback method for ContextWebGpu (#5438)

* impl device_set_device_lost_callback for ContextWebGpu

* merge changelog

---------

Co-authored-by: lixiangyu.ava <lixiangyu.ava@bytedance.com>
This commit is contained in:
李祥煜 2024-03-26 23:12:50 +08:00 committed by GitHub
parent a9ccbc7dea
commit b34219ca21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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::<GpuDeviceLostInfo>().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(