Skip to content

Commit

Permalink
An attempt to handle lost device on WebGPU
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Valigursky committed Oct 14, 2024
1 parent cea6b42 commit ad8f165
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/platform/graphics/webgpu/webgpu-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
this.twgsl = results[0];
this.glslang = results[1];

// create the device
return this.createDevice();
}

async createDevice() {

/** @type {GPURequestAdapterOptions} */
const adapterOptions = {
powerPreference: this.initOptions.powerPreference !== 'default' ? this.initOptions.powerPreference : undefined
Expand Down Expand Up @@ -258,10 +264,17 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
*/
this.wgpu = await this.gpuAdapter.requestDevice(deviceDescr);

this.wgpu.lost?.then((info) => {
this.wgpu.lost?.then(async (info) => {

// reason is 'destroyed' if we intentionally destroy the device
if (info.reason !== 'destroyed') {
Debug.warn(`WebGPU device was lost: ${info.message}, this needs to be handled`);

super.loseContext();

await this.createDevice();

super.restoreContext();
}
});

Expand Down

0 comments on commit ad8f165

Please sign in to comment.