gfx-rs/wgpu

WebGL2 examples require WebGPU support on Chrome v124

lierdakil opened this issue · 1 comments

Description

I've tried to test some examples in https://wgpu.rs/examples/. Since I'm on Linux, WebGPU is disabled by default. What is surprising, is that WebGL2 examples do not work either unless I jump through the hoops of enabling WebGPU.

AFAICT, this happens because Chrome does expose navigator.gpu even if WebGPU is disabled, however it will return null for requestAdapter.

Now, I'm not sure why WebGL2 backend even tries to access navigator.gpu, but apparently it does, and crashes when it gets null as the result of requestAdapter.

Everything works when WebGPU is forcibly on, but the point of WebGL2 is it should work when WebGPU doesn't.

Repro steps

Try to open any example, e.g. https://wgpu.rs/examples/?backend=webgl2&example=hello_triangle, using WebGL2 backend on Google Chrome / Chromium v124 on Linux with WebGPU disabled.

Expected vs observed behavior

Expected: example works

Observed:

webgl2.js:743 WebGPU is experimental on this platform. See https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#implementation-status
webgl2.js:743 Failed to create WebGPU Context Provider
imports.wbg.__wbg_requestAdapter_83566b2b75a979fe @ webgl2.js:743Understand this warning
webgl2.js:366 panicked at examples/src/hello_triangle/mod.rs:24:10:
Failed to find an appropriate adapter

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (https://wgpu.rs/examples/webgl2.js:372:21)
    at console_error_panic_hook::Error::new::h3275e6bb6f361546 (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[33021]:0xedd18c)
    at console_error_panic_hook::hook_impl::h6a82be8592fd12fb (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[8849]:0xaba1c0)
    at console_error_panic_hook::hook::hea01129fe3d37a14 (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[40007]:0xf4a161)
    at core::ops::function::Fn::call::hfb5d5d3335fa4383 (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[35244]:0xf040ac)
    at std::panicking::rust_panic_with_hook::h1e6ac5d404b8e31b (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[16086]:0xcc1c2d)
    at std::panicking::begin_panic_handler::{{closure}}::h24b0f4622f2766a5 (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[19919]:0xd75534)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h19f35d272c126e7c (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[47553]:0xf9692a)
    at rust_begin_unwind (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[36109]:0xf120e7)
    at core::panicking::panic_fmt::h87755523850ece9e (https://wgpu.rs/examples/webgl2_bg.wasm:wasm-function[39746]:0xf46b6c)


imports.wbg.__wbg_error_f851667af71bcfc6 @ webgl2.js:366Understand this error
webgl2_bg.wasm:0xf96a8e Uncaught RuntimeError: unreachable
    at __rust_start_panic (webgl2_bg.wasm:0xf96a8e)
    at rust_panic (webgl2_bg.wasm:0xf9512e)
    at std::panicking::rust_panic_with_hook::h1e6ac5d404b8e31b (webgl2_bg.wasm:0xcc1c5d)
    at std::panicking::begin_panic_handler::{{closure}}::h24b0f4622f2766a5 (webgl2_bg.wasm:0xd75534)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h19f35d272c126e7c (webgl2_bg.wasm:0xf9692a)
    at rust_begin_unwind (webgl2_bg.wasm:0xf120e7)
    at core::panicking::panic_fmt::h87755523850ece9e (webgl2_bg.wasm:0xf46b6c)
    at core::option::expect_failed::h65a8ce8e046de7db (webgl2_bg.wasm:0xe9aa70)
    at core::option::Option<T>::expect::hfc6e062804c34257 (webgl2_bg.wasm:0xcd005c)
    at wgpu_examples::hello_triangle::run::{{closure}}::hc5e377421f122e1c (webgl2_bg.wasm:0x29471a)Understand this error

Extra materials

None.

Platform

Google Chrome Version 124.0.6367.118 (Official Build) (64-bit)

Wumpf commented

ah I painfully recognize this. I implemented a workaround for this in egui, it was quite involved. Maybe an opportunity to make this easier to handle in wgpu (somehow, don't know how yet)

Now, I'm not sure why WebGL2 backend even tries to access navigator.gpu, but apparently it does, and crashes when it gets null as the result of requestAdapter.

I believe (haven't checked!) the problem is more that we compile with the WebGPU backend enabled and the instance creation will try to pick WebGPU. Since navigator.gpu exists it incorrectly concludes that this is the way to go.

If so, the obvious first fix there is to not specify the webgpu backend when creating the wgpu::Instance for a demo where we obviously want to use webgl