denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97k stars 5.36k forks source link

WebGPU: Deno hangs when destroying a device that has created a buffer #24798

Open matthew-wong1 opened 2 months ago

matthew-wong1 commented 2 months ago

I compiled Deno from source using the latest commit (fe884c557a76fd288f7457aa433052f65be70c81 as of writing).

I found that the following program causes Deno to hang on Linux (Ubuntu 22.04) and not finish execution (or at least not finish execution within 30 mins on my machine):

async function main() {
    const adapter = await navigator.gpu.requestAdapter();
    const device = await adapter.requestDevice();
    const buffer = device.createBuffer({
        mappedAtCreation: true,
        size: 12,
        usage: GPUBufferUsage.COPY_SRC
    });
    device.destroy();
}
main().catch(console.error);

On macOS, there is some different behavior. The following is output to the console:

No active command buffers for fence value 1
Failed to wait for buffer Id(0,1,mtl): Parent device is lost

It seems to be because mappedAtCreation is true. When mappedAtCreation is false, the program finishes executing on both macOS and Linux successfully.

lucacasonato commented 2 months ago

Can reproduce, looks like an upstream wgpu bug. cc @crowlKats