GPUDeviceLostInfo
注意:此功能在 Web Workers 中可用。
GPUDeviceLostInfo 接口是 WebGPU API 的一部分,当 GPUDevice.lost Promise 解析时返回的对象。它提供了设备丢失的原因信息。
有关“丢失”状态的更多信息,请参阅 GPUDevice.lost 页面。
实例属性
示例
js
async function init() {
if (!navigator.gpu) {
throw Error("WebGPU not supported.");
}
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw Error("Couldn't request WebGPU adapter.");
}
// Create a GPUDevice
let device = await adapter.requestDevice(descriptor);
// Use lost to handle lost devices
device.lost.then((info) => {
console.error(`WebGPU device was lost: ${info.message}`);
device = null;
if (info.reason !== "destroyed") {
init();
}
});
// …
}
规范
| 规范 |
|---|
| WebGPU # gpudevicelostinfo |
浏览器兼容性
加载中…