From 22dc43b96e5ae3ce989f8828631e5bc60a8be676 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 2 Sep 2022 16:52:20 +0200 Subject: [PATCH 1/3] Use any available present mode that does vsync Previously, any choice of `wgpu::PresentMode` had fallback options. This is no longer the case in wgpu's most recent version, which can lead to hardware-dependent failures. With this change, we're choosing one of the new auto modes, which has fallback options, restoring something close to the previous behavior. --- crates/fj-viewer/src/graphics/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index 64ad13b1d..9e7e36771 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -176,7 +176,7 @@ impl Renderer { format: color_format, width, height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }; surface.configure(&device, &surface_config); From c2c41c54a9503a16715ba5101e134796c5bb7e67 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 2 Sep 2022 16:55:42 +0200 Subject: [PATCH 2/3] Change order of attributes and doc comments This brings the style used here in line with all the other code in the Fornjot codebase. --- crates/fj-viewer/src/graphics/renderer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index 9e7e36771..e695af3a0 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -669,24 +669,24 @@ impl Renderer { /// Error describing the set of render surface initialization errors #[derive(Error, Debug)] pub enum InitError { - #[error("I/O error: {0}")] /// General IO error + #[error("I/O error: {0}")] Io(#[from] io::Error), - #[error("Error request adapter")] /// Graphics accelerator acquisition error + #[error("Error request adapter")] RequestAdapter, - #[error("Error requesting device: {0}")] /// Device request errors /// /// See: [wgpu::RequestDeviceError](https://docs.rs/wgpu/latest/wgpu/struct.RequestDeviceError.html) + #[error("Error requesting device: {0}")] RequestDevice(#[from] wgpu::RequestDeviceError), - #[error("Error loading font: {0}")] /// Error loading font /// /// See: [ab_glyph::InvalidFont](https://docs.rs/ab_glyph/latest/ab_glyph/struct.InvalidFont.html) + #[error("Error loading font: {0}")] InvalidFont(#[from] InvalidFont), } @@ -695,14 +695,14 @@ pub enum InitError { /// Describes errors related to non initialization graphics errors. #[derive(Error, Debug)] pub enum DrawError { - #[error("Error acquiring output surface: {0}")] /// Surface drawing error. /// /// See - [wgpu::SurfaceError](https://docs.rs/wgpu/latest/wgpu/enum.SurfaceError.html) + #[error("Error acquiring output surface: {0}")] Surface(#[from] wgpu::SurfaceError), - #[error("Error drawing text: {0}")] /// Text rasterisation error. + #[error("Error drawing text: {0}")] Text(String), } From fb65e9423b3186ff4091ff4b090f944de144a12c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 2 Sep 2022 17:04:44 +0200 Subject: [PATCH 3/3] Ignore timeout errors --- crates/fj-viewer/src/graphics/renderer.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index e695af3a0..092e110a3 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -324,7 +324,20 @@ impl Renderer { bytemuck::cast_slice(&[uniforms]), ); - let surface_texture = self.surface.get_current_texture()?; + let surface_texture = match self.surface.get_current_texture() { + Ok(surface_texture) => surface_texture, + Err(wgpu::SurfaceError::Timeout) => { + // I'm seeing this all the time now (as in, multiple times per + // microsecond), which `PresentMode::AutoVsync`. Not sure what's + // going on, but for now, it works to just ignore it. + // + // Issues for reference: + // - https://github.com/gfx-rs/wgpu/issues/1218 + // - https://github.com/gfx-rs/wgpu/issues/1565 + return Ok(()); + } + result => result?, + }; let color_view = surface_texture .texture .create_view(&wgpu::TextureViewDescriptor::default());