From 7e79e9a95cab55e92d8afcd592cf81ab232936e2 Mon Sep 17 00:00:00 2001 From: Eero Lehtinen Date: Sat, 23 Mar 2024 03:38:55 +0200 Subject: [PATCH 1/5] Fix crashing on outdated error with Nvidia 550 --- crates/bevy_render/src/view/window/mod.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index ddb0f77f98aef..ba36ef5a48759 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -304,19 +304,31 @@ pub fn prepare_windows( }) }; + #[cfg(target_os = "linux")] + let is_nvidia = || { + render_instance + .enumerate_adapters(wgpu::Backends::VULKAN) + .iter() + .any(|adapter| adapter.get_info().name.starts_with("NVIDIA")) + }; + let not_already_configured = window_surfaces.configured_windows.insert(window.entity); let surface = &surface_data.surface; if not_already_configured || window.size_changed || window.present_mode_changed { - let frame = surface - .get_current_texture() - .expect("Error configuring surface"); - window.set_swapchain_texture(frame); + match surface.get_current_texture() { + Ok(frame) => window.set_swapchain_texture(frame), + #[cfg(target_os = "linux")] + Err(wgpu::SurfaceError::Outdated) if is_nvidia() => {} + Err(err) => panic!("Error configuring surface: {err}"), + }; } else { match surface.get_current_texture() { Ok(frame) => { window.set_swapchain_texture(frame); } + #[cfg(target_os = "linux")] + Err(wgpu::SurfaceError::Outdated) if is_nvidia() => {} Err(wgpu::SurfaceError::Outdated) => { render_device.configure_surface(surface, &surface_data.configuration); let frame = surface From d2dbf53db3bdc486355bf7ccf1d11b0f867077a9 Mon Sep 17 00:00:00 2001 From: Eero Lehtinen Date: Sun, 24 Mar 2024 02:16:32 +0200 Subject: [PATCH 2/5] Add logging for the ignored error --- crates/bevy_render/src/view/window/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index ba36ef5a48759..33213ce27a9d0 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -319,7 +319,12 @@ pub fn prepare_windows( match surface.get_current_texture() { Ok(frame) => window.set_swapchain_texture(frame), #[cfg(target_os = "linux")] - Err(wgpu::SurfaceError::Outdated) if is_nvidia() => {} + Err(wgpu::SurfaceError::Outdated) if is_nvidia() => { + bevy_utils::tracing::debug!( + "Couldn't get swap chain texture. This often happens with \ + the Nvidia 550 driver. It can be safely ignored." + ); + } Err(err) => panic!("Error configuring surface: {err}"), }; } else { @@ -328,7 +333,12 @@ pub fn prepare_windows( window.set_swapchain_texture(frame); } #[cfg(target_os = "linux")] - Err(wgpu::SurfaceError::Outdated) if is_nvidia() => {} + Err(wgpu::SurfaceError::Outdated) if is_nvidia() => { + bevy_utils::tracing::debug!( + "Couldn't get swap chain texture. This often happens with \ + the Nvidia 550 driver. It can be safely ignored." + ); + } Err(wgpu::SurfaceError::Outdated) => { render_device.configure_surface(surface, &surface_data.configuration); let frame = surface From 8a0eada463b809165f6b8c6d6ff861ee4ce50d72 Mon Sep 17 00:00:00 2001 From: Eero Lehtinen Date: Sun, 24 Mar 2024 02:56:49 +0200 Subject: [PATCH 3/5] Warn once instead of debug --- crates/bevy_render/src/view/window/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index 33213ce27a9d0..116c173ad2c0c 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -8,6 +8,8 @@ use crate::{ }; use bevy_app::{App, Plugin}; use bevy_ecs::{entity::EntityHashMap, prelude::*}; +#[cfg(target_os = "linux")] +use bevy_utils::warn_once; use bevy_utils::{default, tracing::debug, HashSet}; use bevy_window::{ CompositeAlphaMode, PresentMode, PrimaryWindow, RawHandleWrapper, Window, WindowClosed, @@ -320,7 +322,7 @@ pub fn prepare_windows( Ok(frame) => window.set_swapchain_texture(frame), #[cfg(target_os = "linux")] Err(wgpu::SurfaceError::Outdated) if is_nvidia() => { - bevy_utils::tracing::debug!( + warn_once!( "Couldn't get swap chain texture. This often happens with \ the Nvidia 550 driver. It can be safely ignored." ); @@ -334,7 +336,7 @@ pub fn prepare_windows( } #[cfg(target_os = "linux")] Err(wgpu::SurfaceError::Outdated) if is_nvidia() => { - bevy_utils::tracing::debug!( + warn_once!( "Couldn't get swap chain texture. This often happens with \ the Nvidia 550 driver. It can be safely ignored." ); From 8c940acad9ded9484144b673faa8722a7ada3456 Mon Sep 17 00:00:00 2001 From: Eero Lehtinen Date: Sat, 30 Mar 2024 23:20:03 +0200 Subject: [PATCH 4/5] Use vendor id to check for nvidia --- crates/bevy_render/src/view/window/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index 116c173ad2c0c..39b70cf24045c 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -218,6 +218,9 @@ impl WindowSurfaces { } } +#[cfg(target_os = "linux")] +const NVIDIA_VENDOR_ID: u32 = 0x10DE; + /// (re)configures window surfaces, and obtains a swapchain texture for rendering. /// /// NOTE: `get_current_texture` in `prepare_windows` can take a long time if the GPU workload is @@ -311,7 +314,7 @@ pub fn prepare_windows( render_instance .enumerate_adapters(wgpu::Backends::VULKAN) .iter() - .any(|adapter| adapter.get_info().name.starts_with("NVIDIA")) + .any(|adapter| adapter.get_info().vendor & 0xFFFF == NVIDIA_VENDOR_ID) }; let not_already_configured = window_surfaces.configured_windows.insert(window.entity); From 93ea1535b5c48cbc96cd191e9bfb511cc6c5b301 Mon Sep 17 00:00:00 2001 From: James Liu Date: Sat, 30 Mar 2024 16:02:19 -0700 Subject: [PATCH 5/5] Generalize warning text. --- crates/bevy_render/src/view/window/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index 39b70cf24045c..d184f08e12d8c 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -327,7 +327,7 @@ pub fn prepare_windows( Err(wgpu::SurfaceError::Outdated) if is_nvidia() => { warn_once!( "Couldn't get swap chain texture. This often happens with \ - the Nvidia 550 driver. It can be safely ignored." + the NVIDIA drivers on Linux. It can be safely ignored." ); } Err(err) => panic!("Error configuring surface: {err}"),