GPUDeviceLostInfo
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The **GPUDeviceLostInfo** interface of the {{domxref("WebGPU API", "WebGPU API", "", "nocode")}} represents the object returned when the {{domxref("GPUDevice.lost")}} {{jsxref("Promise")}} resolves. This provides information as to why a device has been lost.
See the {{domxref("GPUDevice.lost")}} page for more information about "lost" state.
{{InheritanceDiagram}}
Instance properties
- {{domxref("GPUDeviceLostInfo.message", "message")}} {{ReadOnlyInline}}
- : A string providing a human-readable message that explains why the device was lost.
- {{domxref("GPUDeviceLostInfo.reason", "reason")}} {{ReadOnlyInline}}
- : An enumerated value that defines the reason the device was lost in a machine-readable way.
Examples
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();
}
});
// …
}Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- The WebGPU API