deno
deno copied to clipboard
WebGPU: Destroying a device after submitting work crashes
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw new Error("WebGPU is not supported on this device");
}
const device = await adapter.requestDevice();
const buffer = new ArrayBuffer(1024);
const gpuBuffer = device.createBuffer({
size: buffer.byteLength,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
});
device.queue.writeBuffer(gpuBuffer, 0, buffer, 0, buffer.byteLength);
device.destroy();
RUST_BACKTRACE=full deno run --unstable-webgpu bug.ts
============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.
Platform: linux x86_64
Version: 1.39.0
Args: ["deno", "run", "--unstable-webgpu", "tests/main.test.ts"]
thread 'main' panicked at /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.18.1/src/gles/device.rs:1296:18:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: 0x5560aaf150af - <unknown>
1: 0x5560a9e7b6bc - <unknown>
2: 0x5560aaee0f0c - <unknown>
3: 0x5560aaf1d51f - <unknown>
4: 0x5560aaf1d103 - <unknown>
5: 0x5560aaf1ce49 - <unknown>
6: 0x5560a9d686b1 - <unknown>
7: 0x5560aaf1de30 - <unknown>
8: 0x5560aaf1db98 - <unknown>
9: 0x5560aaf1db26 - <unknown>
10: 0x5560aaf1db11 - <unknown>
11: 0x5560a9833084 - <unknown>
12: 0x5560a9833252 - <unknown>
13: 0x5560ab156dac - <unknown>
14: 0x5560aaa73469 - <unknown>
15: 0x5560aaa74593 - <unknown>
16: 0x5560a9fc920c - <unknown>
17: 0x5560aba4195d - <unknown>
Not writing the to the buffer or not destroying the device works. Waiting for the work to be finished before destroying doesn't solve the issue.
I'm running this on Arch Linux inside WSL2 on Windows 11, with a NVIDIA GPU.
Another related case:
Save this as bug.test.ts, then run deno test --unstable-webgpu
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
throw new Error("WebGPU is not supported on this device");
}
Deno.test("bug", async () => {
const device = await adapter.requestDevice();
device.destroy();
});
This outputs:
Check file:///home/.../bug.test.ts
running 1 test from ./bug.test.ts
bug ... ok (7ms)
ok | 1 passed | 0 failed (42ms)
Segmentation fault (core dumped)
No stack trace this time, just a SIGSEGV.
Closing as this is fixed.