bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.95k stars 3.55k forks source link

Parent device is lost #13472

Open theunrealtarik opened 5 months ago

theunrealtarik commented 5 months ago

Bevy version

bevy = "0.13.2"

Relevant system information

AdapterInfo { name: "AMD Radeon RX 5600 XT", vendor: 4098, device: 29471, device_type: DiscreteGpu, driver: "AMD proprietary driver", driver_info: "24.5.1 (AMD proprietary shader compiler)", backend: Vulkan }

What you did

All what I've tried to do is set my app's primary window mode to fullscreen as follows:

impl Plugin for GameSetupPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(Update, toggle_fullscreen)
            .add_plugins(DefaultPlugins.set(WindowPlugin {
                primary_window: Some(Window {
                    name: Some(String::from("cooktory")),
                    title: String::from("Cooktory"),
                    resolution: WindowResolution::new(600.0, 400.0),
                    present_mode: PresentMode::AutoVsync,
                    prevent_default_event_handling: false,
                    ..Default::default()
                }),
                ..Default::default()
            }));
    }
}

fn toggle_fullscreen(mut window: Query<&mut Window>, input: Res<ButtonInput<KeyCode>>) {
    let mut window = window.single_mut();

    if input.just_pressed(KeyCode::F11) {
        match window.mode {
            WindowMode::Fullscreen => window.mode = WindowMode::Windowed,
            _ => window.mode = WindowMode::Fullscreen,
        }
    }
}

What went wrong

I was simply expecting to have a fullscreen window but everytime I hit F11 to do so the app crashes entirely spitting the following error:

thread 'Compute Task Pool (3)' panicked at C:\Users\tarik\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\backend\wgpu_core.rs:724:18:
Error in Surface::configure: Validation Error

Caused by:
    Parent device is lost

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::view::window::create_surfaces`!
thread 'Compute Task Pool (3)' panicked at C:\Users\tarik\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_render-0.13.2\src\pipelined_rendering.rs:49:67:
called `Result::unwrap()` on an `Err` value: RecvError
error: process didn't exit successfully: `target\debug\cooktory.exe` (exit code: 101)

Additional information

I've tried to run the compiled debug binary on my laptop (hardware information are listed down below) and everything worked flawlessly.

2024-05-22T02:08:00.755257Z  INFO bevy_winit::system: Creating new window "Cooktory" (0v1)
2024-05-22T02:08:00.972624Z  INFO bevy_render::renderer: AdapterInfo { name: "Intel(R) UHD Graphics", vendor: 32902, device: 39745, device_type: IntegratedGpu, driver: "Intel Corporation", driver_info: "Intel driver", backend: Vulkan }
2024-05-22T02:08:01.726417Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Pro", kernel: "22631", cpu: "Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz", core_count: "4", memory: "7.6 GiB" }

I thought the issue is AMD related but I found an open issue from the official Bevy's repository #3225 and an other one from the gfx-rs/wgpu #2519, the graphics API Bevy renderer uses as far as I know, which both users seamingly have a Nvidia GPU.

mnmaita commented 5 months ago

I just tested this with wgpu v0.20 on a Windows laptop and I had the same exact issue FWIW. Here's my current device info:

device_type: IntegratedGpu
driver: "AMD proprietary driver"
driver_info: "23.11.1 (AMD proprietary shader compiler)"
backend: Vulkan

I'll test later in a different machine (with an NVIDIA card) but what I figured out is that if you do the following:

impl Plugin for GameSetupPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins(DefaultPlugins.set(WindowPlugin {
                primary_window: Some(Window {
                    name: Some(String::from("cooktory")),
                    title: String::from("Cooktory"),
                    resolution: WindowResolution::new(600.0, 400.0),
                    present_mode: PresentMode::AutoVsync,
                    prevent_default_event_handling: false,
                    // Both Fullscreen and SizedFullscreen crash at startup:
                    mode: WindowMode::Fullscreen,
                    ..Default::default()
                }),
                ..Default::default()
            }));
    }
}

The app still crashes... Notice there was no need to toggle anything for the app to panic.

Seems like configure_surface() in bevy_render's src/renderer/render_device.rs is failing and, as far as I could see, this function panics if:

Assuming there's no way a wrong texture format is chosen, and that the Window does have a size, can we narrow this down to the first bullet point?

Elabajaba commented 4 months ago

The issue here is that newer AMD drivers (and newer Nvidia drivers, idk about Intel) are giving us a dxgi flip mode swapchain on Windows, which doesn't support exclusive fullscreen.

Use borderless (there's no additional latency with dxgi flip mode swapchains in borderless fullscreen compared to the old exclusive fullscreen, and they have less latency than the legacy swapchain in windowed mode).