EmbarkStudios / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧

Home Page:https://shader.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

example-runner-wgpu: surface configuration failed: native window is in use

kevinboulain opened this issue · comments

I'm barely getting started but since the documentation recommends to file issues, here is one.

Example & Steps To Reproduce

  • cargo run --bin wgpu_runner (I guess it should be renamed to example-runner-wgpu to match the documentation):

    backtrace

    [2023-04-27T11:12:38Z ERROR wgpu_core::device] surface configuration failed: Native window is in use
    thread 'main' panicked at 'Error in Surface::configure: Validation Error
    
    Caused by:
        Invalid surface
    ', .../.cargo/git/checkouts/wgpu-53e70f8674b08dd4/a502282/wgpu/src/backend/direct.rs:734:18
    stack backtrace:
       0: rust_begin_unwind
                 at /rustc/44cfafe2fafe816395d3acc434663a45d5178c41/library/std/src/panicking.rs:579:5
       1: core::panicking::panic_fmt
                 at /rustc/44cfafe2fafe816395d3acc434663a45d5178c41/library/core/src/panicking.rs:64:14
       2: wgpu::backend::direct::Context::handle_error_fatal
                 at .../.cargo/git/checkouts/wgpu-53e70f8674b08dd4/a502282/wgpu/src/backend/direct.rs:308:9
       3: <wgpu::backend::direct::Context as wgpu::context::Context>::surface_configure
                 at .../.cargo/git/checkouts/wgpu-53e70f8674b08dd4/a502282/wgpu/src/backend/direct.rs:734:13
       4: <T as wgpu::context::DynContext>::surface_configure
                 at .../.cargo/git/checkouts/wgpu-53e70f8674b08dd4/a502282/wgpu/src/context.rs:2053:9
       5: wgpu::Surface::configure
                 at .../.cargo/git/checkouts/wgpu-53e70f8674b08dd4/a502282/wgpu/src/lib.rs:4144:9
       6: example_runner_wgpu::graphics::run::{{closure}}::{{closure}}
                 at ./examples/runners/wgpu/src/graphics.rs:108:13
       7: example_runner_wgpu::graphics::run::{{closure}}::{{closure}}
                 at ./examples/runners/wgpu/src/graphics.rs:160:42
       8: winit::platform_impl::platform::sticky_exit_callback
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.28.3/src/platform_impl/linux/mod.rs:884:9
       9: winit::platform_impl::platform::x11::EventLoop<T>::run_return::single_iteration
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.28.3/src/platform_impl/linux/x11/mod.rs:334:17
      10: winit::platform_impl::platform::x11::EventLoop<T>::run_return
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.28.3/src/platform_impl/linux/x11/mod.rs:443:31
      11: winit::platform_impl::platform::x11::EventLoop<T>::run
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.28.3/src/platform_impl/linux/x11/mod.rs:498:25
      12: winit::platform_impl::platform::EventLoop<T>::run
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.28.3/src/platform_impl/linux/mod.rs:792:56
      13: winit::event_loop::EventLoop<T>::run
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.28.3/src/event_loop.rs:305:9
      14: example_runner_wgpu::graphics::run::{{closure}}
                 at ./examples/runners/wgpu/src/graphics.rs:145:5
      15: futures_executor::local_pool::block_on::{{closure}}
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.19/src/local_pool.rs:315:23
      16: futures_executor::local_pool::run_executor::{{closure}}
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.19/src/local_pool.rs:90:37
      17: std::thread::local::LocalKey<T>::try_with
                 at /rustc/44cfafe2fafe816395d3acc434663a45d5178c41/library/std/src/thread/local.rs:446:16
      18: std::thread::local::LocalKey<T>::with
                 at /rustc/44cfafe2fafe816395d3acc434663a45d5178c41/library/std/src/thread/local.rs:422:9
      19: futures_executor::local_pool::run_executor
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.19/src/local_pool.rs:86:5
      20: futures_executor::local_pool::block_on
                 at .../.cargo/registry/src/github.com-1ecc6299db9ec823/futures-executor-0.3.19/src/local_pool.rs:315:5
      21: example_runner_wgpu::graphics::start
                 at ./examples/runners/wgpu/src/graphics.rs:433:13
      22: example_runner_wgpu::main
                 at ./examples/runners/wgpu/src/lib.rs:171:5
      23: wgpu_runner::main
                 at ./examples/runners/wgpu/src/bin/wgpu_runner.rs:9:5
      24: core::ops::function::FnOnce::call_once
                 at /rustc/44cfafe2fafe816395d3acc434663a45d5178c41/library/core/src/ops/function.rs:250:5
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    

  • here as a workaround:

    diff --git i/examples/runners/wgpu/src/graphics.rs w/examples/runners/wgpu/src/graphics.rs
    index 9a5bd43263..ca0ceef4cb 100644
    --- i/examples/runners/wgpu/src/graphics.rs
    +++ w/examples/runners/wgpu/src/graphics.rs
    @@ -154,16 +154,6 @@ async fn run(
                 Event::MainEventsCleared => {
                     window.request_redraw();
                 }
    -            Event::Resumed => {
    -                let new_surface = unsafe { instance.create_surface(&window) }
    -                    .expect("Failed to create surface from window (after resume)");
    -                surface_with_config = Ok(auto_configure_surface(
    -                    &adapter,
    -                    &device,
    -                    new_surface,
    -                    window.inner_size(),
    -                ));
    -            }
                 Event::Suspended => {
                     if let Ok((_, surface_config)) = &surface_with_config {
                         surface_with_config = Err(SurfaceCreationPending {

System Info

  • Rust: rustc 1.69.0-nightly (44cfafe2f 2023-03-03)
  • OS: NixOS 23.05.20230422.6c43a34
  • GPU: RUST_LOG=wgpu_hal=debug tells me it's using the discrete GPU here: NVIDIA GeForce RTX 3080 Ti Laptop GPU with driver /nix/store/...-nvidia-x11-530.41.03-6.1.25/lib/libGLX_nvidia.so.0

That should run under Xwayland (setup is similar to your default.nix, without the Wayland stuff that crashes for other reasons).

I'm not too familiar with this stuff, but it looks like the example in the wgpu repo calls surface.resume() when start_condition() is met:

https://github.com/gfx-rs/wgpu/blob/0dc9dd6becdfd69ab241169171c37428fefaa1da/examples/src/framework.rs#L395

It looks like start_condition() is only met on android:

https://github.com/gfx-rs/wgpu/blob/0dc9dd6becdfd69ab241169171c37428fefaa1da/examples/src/framework.rs#L394

otherwise it doesn't do anything on resume, so your patch may be right? Well, after adding the android change.

Changing this would match what the wgpu folks said ("you are trying to use the same window more than once by different surfaces").

Again, not sure, but at least those links might be a clue.