denoland / deno

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

Logging out webgpu adapater causes an assertion error #26760

Open okikio opened 1 week ago

okikio commented 1 week ago

Version: Deno 2.0.5

On Windows, Linux, and Mac OS trying to log out the WebGPU adapter causes an assertion error which is unexpected and was rather difficult to debug, interestingly enough logging out the actual adapter device works as expected it prints out an object.

I'm not sure if the assertion error is expected behaviour or not but I've not found any documentation that specifies this behaviour, so I'm thinking it's a bug.

Note: when running the script on Windows it doesn't always print the assertion error, sometimes it just causes the script to crash with no errors, making it basically impossible to debug.

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter?.requestDevice();

console.log({
  adapter,
})

Assertion Error:

❯ deno run --unstable-webgpu -A main.ts
[Internal Formatting Error] AssertionError: Assertion failed
    at assert (ext:deno_console/01_console.js:199:11)
    at getKeys (ext:deno_console/01_console.js:1294:7)
    at formatRaw (ext:deno_console/01_console.js:761:14)
    at formatValue (ext:deno_console/01_console.js:545:10)
    at inspect (ext:deno_console/01_console.js:3469:10)
    at GPUAdapter.[Deno.privateCustomInspect] (ext:deno_webgpu/01_webgpu.js:542:12)
    at formatValue (ext:deno_console/01_console.js:487:48)
    at formatProperty (ext:deno_console/01_console.js:1647:11)
    at formatRaw (ext:deno_console/01_console.js:957:9)
    at formatValue (ext:deno_console/01_console.js:545:10)
petamoriken commented 1 week ago

Probably related to #25874

petamoriken commented 1 week ago

Currently, first access to the adapter.info getter property after getting the device throws an exception.

It is a strange code, but I think it may be possible to execute the following code as a workaround:

const adapter = await navigator.gpu.requestAdapter();

// first access to adapter.info *before* getting the device
adapter?.info;

const device = await adapter?.requestDevice();

console.log({
  adapter,
})
okikio commented 1 week ago

Interesting @petamoriken you're right so this is probs a bug in Deno

petamoriken commented 1 week ago

I try to fix this issue.

petamoriken commented 1 week ago

Note for me: https://groups.google.com/a/chromium.org/g/blink-dev/c/q4tpIeEydRI