parasyte / pixels

A tiny hardware-accelerated pixel frame buffer. 🦀
https://docs.rs/pixels
MIT License
1.81k stars 123 forks source link

Panic in wgpu when no adapters are available #36

Closed parasyte closed 4 years ago

parasyte commented 5 years ago

Original report: https://github.com/parasyte/pixels/issues/29#issuecomment-549721793

Debug Backtrace ``` Running `target/debug/examples/invaders` [2019-11-05T08:37:36Z ERROR gfx_backend_vulkan] GENERAL [Loader Message (0)] : setupLoaderTermPhysDevs: Failed to detect any valid GPUs in the current config object info: (type: INSTANCE, hndl: 94142666705760) [2019-11-05T08:37:36Z ERROR gfx_backend_vulkan] GENERAL [Loader Message (0)] : setupLoaderTrampPhysDevs: Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count. object info: (type: INSTANCE, hndl: 94142666705760) [2019-11-05T08:37:36Z ERROR gfx_backend_vulkan] GENERAL [Loader Message (0)] : setupLoaderTermPhysDevs: Failed to detect any valid GPUs in the current config object info: (type: INSTANCE, hndl: 94142666705760) [2019-11-05T08:37:36Z ERROR gfx_backend_vulkan] GENERAL [Loader Message (0)] : setupLoaderTrampPhysDevs: Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count. object info: (type: INSTANCE, hndl: 94142666705760) [2019-11-05T08:37:36Z ERROR gfx_backend_vulkan] Could not enumerate physical devices! Initialization of a object has failed thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21 stack backtrace: 0: 0x559f4b21165b - backtrace::backtrace::libunwind::trace::h89fcc71e59e3bc5b at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88 1: 0x559f4b21165b - backtrace::backtrace::trace_unsynchronized::h0bad9be1379e729a at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66 2: 0x559f4b21165b - std::sys_common::backtrace::_print::hd3382a1f33c473da at src/libstd/sys_common/backtrace.rs:47 3: 0x559f4b21165b - std::sys_common::backtrace::print::h0ec6f03cfb8e76a6 at src/libstd/sys_common/backtrace.rs:36 4: 0x559f4b21165b - std::panicking::default_hook::{{closure}}::h96cbf7b454e3f557 at src/libstd/panicking.rs:200 5: 0x559f4b211336 - std::panicking::default_hook::h95a8f00337383d83 at src/libstd/panicking.rs:214 6: 0x559f4b211dcd - std::panicking::rust_panic_with_hook::h92f98b46e22f14ed at src/libstd/panicking.rs:477 7: 0x559f4b211952 - std::panicking::continue_panic_fmt::h25abfbb4e5b7043a at src/libstd/panicking.rs:384 8: 0x559f4b211836 - rust_begin_unwind at src/libstd/panicking.rs:311 9: 0x559f4b22dacd - core::panicking::panic_fmt::h7e9f94035af782b3 at src/libcore/panicking.rs:85 10: 0x559f4b22da0c - core::panicking::panic::hda536e6f3accfb91 at src/libcore/panicking.rs:49 11: 0x559f4ae9aa98 - core::option::Option::unwrap::h6a8982082ab21bf2 at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libcore/macros.rs:12 12: 0x559f4afb2a7d - wgpu_request_adapter at /home/caemor/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.0/src/instance.rs:474 13: 0x559f4adb33de - wgpu::Adapter::request::h5d0f480938252090 at /home/caemor/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.4.0/src/lib.rs:545 14: 0x559f4adabe25 - pixels::PixelsBuilder::build::h59b6760c73bac5f1 at src/lib.rs:413 15: 0x559f4adab2e4 - pixels::Pixels::new::hd357520d8b07f9a8 at src/lib.rs:140 16: 0x559f4a6eae21 - invaders::main::h1045af4f645b64f7 at examples/invaders/main.rs:28 17: 0x559f4a6e8d20 - std::rt::lang_start::{{closure}}::hda704dadbaa610b3 at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64 18: 0x559f4b2117d3 - std::rt::lang_start_internal::{{closure}}::h4e93c1949c7a1955 at src/libstd/rt.rs:49 19: 0x559f4b2117d3 - std::panicking::try::do_call::h9440ccd4dc467eaa at src/libstd/panicking.rs:296 20: 0x559f4b2160aa - __rust_maybe_catch_panic at src/libpanic_unwind/lib.rs:80 21: 0x559f4b2122dd - std::panicking::try::hc046e7ee42ee744f at src/libstd/panicking.rs:275 22: 0x559f4b2122dd - std::panic::catch_unwind::h27dfc457c200aee0 at src/libstd/panic.rs:394 23: 0x559f4b2122dd - std::rt::lang_start_internal::hea1b49a567afe309 at src/libstd/rt.rs:48 24: 0x559f4a6e8cf9 - std::rt::lang_start::h6eaa7268c68ca014 at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64 25: 0x559f4a6ebcfa - main 26: 0x7febf9b9f153 - __libc_start_main 27: 0x559f4a6df1ae - _start 28: 0x0 - ```
caemor commented 5 years ago

same error for the wgpu-rs default example and the gfx-rs with vulkan, but gfx-rs with gl (opengl) works fine. So it seems the problem is that currently the wrong (vulkan) backend is chosen?

I need to go out now, I can add more backtraces later or check if I just need to install these deps from: https://github.com/gfx-rs/gfx/blob/master/info/getting_started.md#vulkan-dependencies

~/g/t/g/examples> cargo run --bin quad --features vulkan
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s                                                                 
     Running `/home/caemor/git/tests/gfx/target/debug/quad`
[2019-11-05T16:52:38Z ERROR gfx_backend_vulkan] 
GENERAL [Loader Message (0)] : setupLoaderTermPhysDevs:  Failed to detect any valid GPUs in the current config
object info: (type: INSTANCE, hndl: 94256011912432)

[2019-11-05T16:52:38Z ERROR gfx_backend_vulkan] 
GENERAL [Loader Message (0)] : setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
object info: (type: INSTANCE, hndl: 94256011912432)

[2019-11-05T16:52:38Z ERROR gfx_backend_vulkan] 
GENERAL [Loader Message (0)] : setupLoaderTermPhysDevs:  Failed to detect any valid GPUs in the current config
object info: (type: INSTANCE, hndl: 94256011912432)

[2019-11-05T16:52:38Z ERROR gfx_backend_vulkan] 
GENERAL [Loader Message (0)] : setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
object info: (type: INSTANCE, hndl: 94256011912432)

[2019-11-05T16:52:38Z ERROR gfx_backend_vulkan] Could not enumerate physical devices! Initialization of a object has failed
thread 'main' panicked at 'assertion failed: index < len', src/liballoc/vec.rs:988:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

~/g/t/g/examples> cargo run --bin quad --features gl
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s                                                                 
     Running `/home/caemor/git/tests/gfx/target/debug/quad`
AdapterInfo { name: "AMD PITCAIRN (DRM 2.50.0, 5.3.7-2-MANJARO, LLVM 9.0.0)", vendor: 0, device: 0, device_type: DiscreteGpu }
Memory types: [MemoryType { properties: CPU_VISIBLE | COHERENT | CPU_CACHED, heap_index: 1 }, MemoryType { properties: CPU_VISIBLE | COHERENT, heap_index: 1 }, MemoryType { properties: CPU_VISIBLE | CPU_CACHED, heap_index: 1 }, MemoryType { properties: DEVICE_LOCAL, heap_index: 0 }, MemoryType { properties: DEVICE_LOCAL, heap_index: 0 }]
formats: Some([Rgba8Srgb, Bgra8Srgb])
SwapchainConfig { present_mode: FIFO, composite_alpha_mode: OPAQUE, format: Rgba8Srgb, extent: Extent2D { width: 1024, height: 768 }, image_count: 2, image_layers: 1, image_usage: COLOR_ATTACHMENT }
resized to LogicalSize { width: 1024.0, height: 768.0 }
SwapchainConfig { present_mode: FIFO, composite_alpha_mode: OPAQUE, format: Rgba8Srgb, extent: Extent2D { width: 1024, height: 768 }, image_count: 2, image_layers: 1, image_usage: COLOR_ATTACHMENT }
^C⏎                                                                                                                           
~/g/t/g/examples> 
~/g/t/wgpu-rs> env RUST_BACKTRACE=full cargo run --example cube
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s                                                                 
     Running `target/debug/examples/cube`
[2019-11-05T16:50:20Z ERROR gfx_backend_vulkan] 
    GENERAL [Loader Message (0)] : setupLoaderTermPhysDevs:  Failed to detect any valid GPUs in the current config
    object info: (type: INSTANCE, hndl: 94167132465104)

[2019-11-05T16:50:20Z ERROR gfx_backend_vulkan] 
    GENERAL [Loader Message (0)] : setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
    object info: (type: INSTANCE, hndl: 94167132465104)

[2019-11-05T16:50:20Z ERROR gfx_backend_vulkan] 
    GENERAL [Loader Message (0)] : setupLoaderTermPhysDevs:  Failed to detect any valid GPUs in the current config
    object info: (type: INSTANCE, hndl: 94167132465104)

[2019-11-05T16:50:20Z ERROR gfx_backend_vulkan] 
    GENERAL [Loader Message (0)] : setupLoaderTrampPhysDevs:  Failed during dispatch call of 'vkEnumeratePhysicalDevices' to lower layers or loader to get count.
    object info: (type: INSTANCE, hndl: 94167132465104)

[2019-11-05T16:50:20Z ERROR gfx_backend_vulkan] Could not enumerate physical devices! Initialization of a object has failed
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0:     0x55a4fd71b9eb - backtrace::backtrace::libunwind::trace::h89fcc71e59e3bc5b
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
   1:     0x55a4fd71b9eb - backtrace::backtrace::trace_unsynchronized::h0bad9be1379e729a
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
   2:     0x55a4fd71b9eb - std::sys_common::backtrace::_print::hd3382a1f33c473da
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x55a4fd71b9eb - std::sys_common::backtrace::print::h0ec6f03cfb8e76a6
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x55a4fd71b9eb - std::panicking::default_hook::{{closure}}::h96cbf7b454e3f557
                               at src/libstd/panicking.rs:200
   5:     0x55a4fd71b6c6 - std::panicking::default_hook::h95a8f00337383d83
                               at src/libstd/panicking.rs:214
   6:     0x55a4fd71c15d - std::panicking::rust_panic_with_hook::h92f98b46e22f14ed
                               at src/libstd/panicking.rs:477
   7:     0x55a4fd71bce2 - std::panicking::continue_panic_fmt::h25abfbb4e5b7043a
                               at src/libstd/panicking.rs:384
   8:     0x55a4fd71bbc6 - rust_begin_unwind
                               at src/libstd/panicking.rs:311
   9:     0x55a4fd73bddd - core::panicking::panic_fmt::h7e9f94035af782b3
                               at src/libcore/panicking.rs:85
  10:     0x55a4fd73bd1c - core::panicking::panic::hda536e6f3accfb91
                               at src/libcore/panicking.rs:49
  11:     0x55a4fd0415e8 - core::option::Option<T>::unwrap::hb2ea246757546eef
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libcore/macros.rs:12
  12:     0x55a4fd15f1cd - wgpu_request_adapter
                               at /home/caemor/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-native-0.4.0/src/instance.rs:474
  13:     0x55a4fcf61ace - wgpu::Adapter::request::h4996314114b36e87
                               at src/lib.rs:545
  14:     0x55a4fccf4da8 - cube::framework::run::he9cacdce564445ff
                               at examples/cube/../framework.rs:97
  15:     0x55a4fcd0a7e5 - cube::main::hd44faa43e89bb2f0
                               at examples/cube/main.rs:357
  16:     0x55a4fccddc20 - std::rt::lang_start::{{closure}}::h3e1988d7e9300019
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64
  17:     0x55a4fd71bb63 - std::rt::lang_start_internal::{{closure}}::h4e93c1949c7a1955
                               at src/libstd/rt.rs:49
  18:     0x55a4fd71bb63 - std::panicking::try::do_call::h9440ccd4dc467eaa
                               at src/libstd/panicking.rs:296
  19:     0x55a4fd7243ba - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  20:     0x55a4fd71c66d - std::panicking::try::hc046e7ee42ee744f
                               at src/libstd/panicking.rs:275
  21:     0x55a4fd71c66d - std::panic::catch_unwind::h27dfc457c200aee0
                               at src/libstd/panic.rs:394
  22:     0x55a4fd71c66d - std::rt::lang_start_internal::hea1b49a567afe309
                               at src/libstd/rt.rs:48
  23:     0x55a4fccddbf9 - std::rt::lang_start::hfc3473c8e4738dc5
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64
  24:     0x55a4fcd0a81a - main
  25:     0x7f4322637153 - __libc_start_main
  26:     0x55a4fccad1ae - _start
  27:                0x0 - <unknown>
parasyte commented 5 years ago

Sure, no worries. This is really helpful info, so far. If the problem does get resolved by installing Vulkan dependencies, that might be a reasonable workaround for now. But I'm considering to option of surfacing this to the wgpu maintainers.

They recently announced that wgpu automatically selects a backend. This might end up being a common case where users are capable of running OpenGL but not Vulkan? And wgpu always prefers Vulkan on supported platforms.

For now I'm going to label this as an upstream bug. When you get a chance, let me know how that testing goes.

kvark commented 5 years ago

We don't support GL at the moment. So if your Linux system can't initialize Vulkan, it's not supported yet. Do you expect a nicer error message/handling?

parasyte commented 5 years ago

Leaving this here as a reminder for myself: If wgpu::Adapter::request() fails, we can try again with wgpu::RequestAdapterOptions { backends: wgpu::BackendBit::SECONDARY, .. } to check for OpenGL and DirectX11.

caemor commented 5 years ago

So I installed all the stuff from the gfx-getting started link and also from https://wiki.archlinux.org/index.php/Vulkan for my graphics card and I now get a slightly different error where it seems that my graphic card is too old. Rest of the error message is still the same :thinking:

Not sure what else I can try :-D

❯ cargo run --bin quad --features vulkan
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `/home/caemor/git/tests/gfx/target/debug/quad`
amdgpu_device_initialize: DRM version is 2.50.0 but this driver is only compatible with 3.x.x.
amdgpu_device_initialize: DRM version is 2.50.0 but this driver is only compatible with 3.x.x.
[2019-11-08T10:42:47Z ERROR gfx_backend_vulkan] 
....

❯ inxi -G
Graphics:  Device-1: Advanced Micro Devices [AMD/ATI] Pitcairn XT [Radeon HD 7870 GHz Edition] driver: radeon v: kernel 
           Display: x11 server: X.org 1.20.5 driver: ati,radeon unloaded: modesetting resolution: <xdpyinfo missing> 
           OpenGL: renderer: AMD PITCAIRN (DRM 2.50.0 5.3.8-3-MANJARO LLVM 9.0.0) v: 4.5 Mesa 19.2.2 
bjorn3 commented 5 years ago

DRM version is 2.50.0 but this driver is only compatible with 3.x.x

Maybe try updating libdrm.so? Maybe that will need a kernel update too.

parasyte commented 5 years ago

This is all very much outside of my zone of familiarity. If your machine cannot do Vulkan, the best I can do on my end is request an adapter that supports OpenGL. We'll just have to see how OpenGL support improves in wgpu.

kvark commented 5 years ago

@caemor try some basic Vulkan demos, like vkcube. If it works, gfx-rs Vulkan backend would also work to some extent. Otherwise, you'll have to wait till wgpu-rs gets GL support.

ngasull commented 4 years ago

Hi :wave: I ran into the same issue on my Ubuntu. Having a crappy Intel GPU, I eventually searched for Intel+Vulkan+Ubuntu issues and ended with a fix:

sudo apt install mesa-vulkan-drivers

Good to know however that our category of end-users won't support current implementation of wgpu out of the box. I'd naively expect 2D stuff especially to work out of the box, without installing dependencies, but it's gonna be the job of OS distributions I guess :slightly_smiling_face:

@joshtriplett as you seemed to have this exact issue. Does this added dependency solve it?

parasyte commented 4 years ago

This should be fixed on master with wgpu = "0.5.0".

AnEnigmaticBug commented 3 years ago

@parasyte I also have a similar issue in a fresh Ubuntu 20.04 install (pixels 0.2.0). Here's the output from my program with RUST_LOG=trace:

[2021-01-01T15:18:13Z TRACE mio::poll] registering with poller
[2021-01-01T15:18:13Z TRACE mio::poll] registering with poller
[2021-01-01T15:18:13Z TRACE mio::poll] registering with poller
[2021-01-01T15:18:13Z TRACE mio::poll] registering with poller
[2021-01-01T15:18:13Z TRACE mio::poll] registering with poller
[2021-01-01T15:18:13Z INFO  winit::platform_impl::platform::x11::window] Guessed window scale factor: 1
[2021-01-01T15:18:13Z DEBUG winit::platform_impl::platform::x11::window] Calculated physical dimensions: 640x480
[2021-01-01T15:18:13Z ERROR gfx_backend_vulkan] Could not enumerate physical devices! Initialization of a object has failed
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: AdapterNotFound', src/main.rs:37:56

The panic happens when I call Pixels::new.

The binary runs on my dev machine (also Ubuntu). But it didn't work on my friend's laptop. So, I executed the binary in VirtualBox for testing and saw this output. I suspect this maybe due to a missing shared library.

I tried sudo apt install libx11-dev as mentioned in #83. But the issue still persists. I have the mesa-vulkan-drivers package installed. Could you please recommend anything?

parasyte commented 3 years ago

@AnEnigmaticBug It looks like you need to install a Vulkan driver for your GPU.

AnEnigmaticBug commented 3 years ago

I searched a bit and got to know that Vulkan doesn't work properly in VirtualBox. The vkcube and vulkaninfo utilities also failed in my VM. So, the issue isn't related to pixels at all. Thanks for your suggestion about looking into Vulkan support itself.