kvark / blade

Sharp and simple graphics library
MIT License
487 stars 31 forks source link

Panics in submit when running under X11 #139

Open ConradIrwin opened 1 month ago

ConradIrwin commented 1 month ago

After the zed launch, we're seeing a number of crashes in ::submit:

It seems like these are exclusive (or at least very much more common) on Zed's X11 implementation vs the Wayland one, so I wonder if we've messed something up on our side.

I haven't seen this locally, but it happens across a wide range of linux distributions in the wild.

Do you have an idea for what I should look for to try and debug this?

ConradIrwin commented 1 month ago

See for example https://github.com/zed-industries/zed/issues/14225.

I wonder if it's specific to the combination of KDE + X11. Will try that tomorrow

kvark commented 1 month ago

That linked Zed issue sounds a lot like the Intel + Nvidia systems issue we've been looking at for a while, e.g. #88 It's a platform issue, and we have a workaround that basically make us not use the Intel GPU in this case. Users can confirm if it's a platform issue by running vkcube --gpu_number X to force Intel and seeing it failing as well.

We need to figure out the scope of affected systems and extend the workaround. Right now it's based on PRIME config - https://github.com/kvark/blade/blob/9e47628b59a18d1ca085ea9555c2d592864de642/blade-graphics/src/vulkan/init.rs#L113-L116

kvark commented 1 month ago

I wrote a general fix for this in #144. It's unfortunately verbose, but it should be 100% correct unlike the current heuristics.

I'd really like a strong signal from people having Intel+Nvidia configuration before merging. This includes both those affected and not. Here is what we'd need:

  1. check out Blade #144
  2. run RUST_LOG=blade_graphics=info cargo run --example bunnymark and share the output
  3. of course vulkaninfo output if they haven't provided it elsewhere

@lemtea8 would you be able to try this out? cc @flukejones for ideas

lemtea8 commented 1 month ago

@kvark Sadly the pr is still not working for my machine. What I got from RUST_LOG=blade_graphics=info cargo run --example bunnymark:

➜  blade git:(90c6da2) RUST_LOG=blade_graphics=info RUST_BACKTRACE=1 cargo run --example bunnymark
warning: `/home/user/Download/blade/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/examples/bunnymark`
[2024-07-18T06:15:11Z WARN  blade_graphics::hal::init] Requested layer is not found: "VK_LAYER_KHRONOS_validation"
[2024-07-18T06:15:11Z WARN  blade_graphics::hal::init] Requested layer is not found: "VK_LAYER_MESA_overlay"
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::init] Enabling Vulkan Portability
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::init] Enabling color space support
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::init] Testing presentation capability on Linux/Intel
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::init] Adapter "Intel(R) UHD Graphics 630 (CFL GT2)"
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::init] No ray tracing extensions are supported
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::init] Using surface present mode MAILBOX
[2024-07-18T06:15:11Z WARN  blade_graphics::hal::init] Unable to forbid exclusive full screen
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::resource] Creating texture 0x560a7f9ccb80 of size 1x1x1 and format Rgba8Unorm, name 'texutre', handle 0
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::resource] Creating buffer 0x560a7f882c70 of size 4, name 'staging', handle 1
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::resource] Creating buffer 0x560a7f9cca20 of size 32, name 'vertex', handle 2
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::descriptor] Creating a descriptor pool for at most 16 sets
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::descriptor] Creating a descriptor pool for at most 16 sets
[2024-07-18T06:15:11Z INFO  blade_graphics::hal::resource] Destroying buffer 0x560a7f882c70, handle 1
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/event_processor.rs:1319:18:
Failed to focus input context: XError { description: "BadMatch (invalid parameter attributes)", error_code: 8, request_code: 149, minor_code: 4 }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/result.rs:1654:5
   3: core::result::Result<T,E>::expect
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/result.rs:1034:23
   4: winit::platform_impl::platform::x11::event_processor::EventProcessor<T>::xinput2_focused
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/event_processor.rs:1317:13
   5: winit::platform_impl::platform::x11::event_processor::EventProcessor<T>::process_xevent
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/event_processor.rs:239:25
   6: winit::platform_impl::platform::x11::event_processor::EventProcessor<T>::process_event
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/event_processor.rs:80:9
   7: winit::platform_impl::platform::x11::EventLoop<T>::drain_events
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:626:13
   8: winit::platform_impl::platform::x11::EventLoop<T>::single_iteration
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:557:9
   9: winit::platform_impl::platform::x11::EventLoop<T>::pump_events
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:441:13
  10: winit::platform_impl::platform::x11::EventLoop<T>::run_on_demand
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/mod.rs:408:19
  11: winit::platform_impl::platform::EventLoop<T>::run_on_demand
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/mod.rs:829:56
  12: winit::platform_impl::platform::EventLoop<T>::run
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/mod.rs:822:9
  13: winit::event_loop::EventLoop<T>::run
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/event_loop.rs:249:9
  14: bunnymark::main
             at ./examples/bunnymark/main.rs:368:5
  15: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

\ And the full output of vulkaninfo, if needed: vulkaninfo.txt

kvark commented 1 month ago

Thank you for testing, @lemtea8 ! The call stack of this failure is purely inside winit and doesn't have any of the Vulkan code, so it's possible you are seeing something else here.

lemtea8 commented 1 month ago

It's interesting that I can run the examples in winit with the same version (0.29.15), but somehow blade fails...

image

kvark commented 1 month ago

Bunnymark example is trying to init a transparent window, maybe that's the main difference. But it's irrelevant to the original issue at hand.