From b7a56e895a1d2df42bff93d142d4ef0deb0a65fe Mon Sep 17 00:00:00 2001 From: Isse Date: Thu, 18 Jan 2024 00:57:01 +0100 Subject: [PATCH] Only show available present modes in graphic settings --- assets/voxygen/i18n/en/hud/settings.ftl | 1 + voxygen/src/hud/settings_window/video.rs | 18 ++++++---------- voxygen/src/render/mod.rs | 27 ++++++++++++++++++++++++ voxygen/src/render/renderer.rs | 27 +++++++++++++++++++++--- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/assets/voxygen/i18n/en/hud/settings.ftl b/assets/voxygen/i18n/en/hud/settings.ftl index b61b457e7d..c5a4866dbf 100644 --- a/assets/voxygen/i18n/en/hud/settings.ftl +++ b/assets/voxygen/i18n/en/hud/settings.ftl @@ -72,6 +72,7 @@ hud-settings-maximum_fps = Maximum FPS hud-settings-background_fps = Background FPS hud-settings-present_mode = Present Mode hud-settings-present_mode-vsync_capped = Vsync capped +hud-settings-present_mode-vsync_adaptive = Adaptive vsync hud-settings-present_mode-vsync_uncapped = Vsync uncapped hud-settings-present_mode-vsync_off = Vsync off hud-settings-fov = Field of View (deg) diff --git a/voxygen/src/hud/settings_window/video.rs b/voxygen/src/hud/settings_window/video.rs index ae6dda8127..577b98051a 100644 --- a/voxygen/src/hud/settings_window/video.rs +++ b/voxygen/src/hud/settings_window/video.rs @@ -7,7 +7,7 @@ use crate::{ }, render::{ AaMode, BloomConfig, BloomFactor, BloomMode, CloudMode, FluidMode, LightingMode, - PresentMode, ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode, + ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode, }, session::settings_change::Graphics as GraphicsChange, settings::{Fps, GraphicsSettings}, @@ -659,17 +659,11 @@ impl<'a> Widget for Video<'a> { .color(TEXT_COLOR) .set(state.ids.present_mode_text, ui); - let mode_list = [ - PresentMode::Fifo, - PresentMode::Mailbox, - PresentMode::Immediate, - ]; - let mode_label_list = [ - "hud-settings-present_mode-vsync_capped", - "hud-settings-present_mode-vsync_uncapped", - "hud-settings-present_mode-vsync_off", - ] - .map(|k| self.localized_strings.get_msg(k)); + let mode_list = self.global_state.window.renderer().present_modes(); + let mode_label_list = mode_list + .iter() + .map(|mode| self.localized_strings.get_msg(mode.localize())) + .collect::>(); // Get which present mode is currently active let selected = mode_list diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 8386bff56f..222b7f1dd8 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -292,21 +292,48 @@ impl Default for UpscaleMode { pub enum PresentMode { Mailbox, Immediate, + FifoRelaxed, #[default] #[serde(other)] Fifo, // has to be last for `#[serde(other)]` } +impl PresentMode { + pub fn localize(&self) -> &'static str { + match self { + Self::Fifo => "hud-settings-present_mode-vsync_capped", + Self::FifoRelaxed => "hud-settings-present_mode-vsync_adaptive", + Self::Mailbox => "hud-settings-present_mode-vsync_uncapped", + Self::Immediate => "hud-settings-present_mode-vsync_off", + } + } +} + impl From for wgpu::PresentMode { fn from(mode: PresentMode) -> Self { match mode { PresentMode::Fifo => wgpu::PresentMode::Fifo, + PresentMode::FifoRelaxed => wgpu::PresentMode::FifoRelaxed, PresentMode::Mailbox => wgpu::PresentMode::Mailbox, PresentMode::Immediate => wgpu::PresentMode::Immediate, } } } +impl TryFrom for PresentMode { + type Error = (); + + fn try_from(mode: wgpu::PresentMode) -> Result { + match mode { + wgpu::PresentMode::Fifo => Ok(PresentMode::Fifo), + wgpu::PresentMode::FifoRelaxed => Ok(PresentMode::FifoRelaxed), + wgpu::PresentMode::Mailbox => Ok(PresentMode::Mailbox), + wgpu::PresentMode::Immediate => Ok(PresentMode::Immediate), + _ => Err(()), + } + } +} + /// Bloom factor /// Controls fraction of output image luminosity that is blurred bloom #[derive(Default, PartialEq, Clone, Copy, Debug, Serialize, Deserialize)] diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index ff15ff398a..05f0f0c13c 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -28,8 +28,8 @@ use super::{ terrain, ui, GlobalsBindGroup, GlobalsLayouts, ShadowTexturesBindGroup, }, texture::Texture, - AddressMode, FilterMode, OtherModes, PipelineModes, RenderError, RenderMode, ShadowMapMode, - ShadowMode, Vertex, + AddressMode, FilterMode, OtherModes, PipelineModes, PresentMode, RenderError, RenderMode, + ShadowMapMode, ShadowMode, Vertex, }; use common::assets::{self, AssetExt, AssetHandle, ReloadWatcher}; use common_base::span; @@ -135,6 +135,7 @@ enum State { pub struct Renderer { device: Arc, queue: wgpu::Queue, + adapter: wgpu::Adapter, surface: wgpu::Surface, surface_config: wgpu::SurfaceConfiguration, @@ -350,12 +351,21 @@ impl Renderer { let format = surface_capabilities.formats[0]; info!("Using {:?} as the surface format", format); + let present_mode = other_modes.present_mode.into(); let surface_config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format, width: dims.width, height: dims.height, - present_mode: other_modes.present_mode.into(), + present_mode: if surface_capabilities.present_modes.contains(&present_mode) { + present_mode + } else { + *surface_capabilities + .present_modes + .iter() + .find(|mode| PresentMode::try_from(**mode).is_ok()) + .expect("There should never be no supported present modes") + }, alpha_mode: wgpu::CompositeAlphaMode::Opaque, view_formats: Vec::new(), }; @@ -555,6 +565,7 @@ impl Renderer { Ok(Self { device, queue, + adapter, surface, surface_config, @@ -675,6 +686,16 @@ impl Renderer { /// Get the pipelines mode. pub fn pipeline_modes(&self) -> &PipelineModes { &self.pipeline_modes } + /// Get the supported present modes. + pub fn present_modes(&self) -> Vec { + self.surface + .get_capabilities(&self.adapter) + .present_modes + .into_iter() + .filter_map(|present_mode| PresentMode::try_from(present_mode).ok()) + .collect() + } + /// Get the current profiling times /// Nested timings immediately follow their parent /// Returns Vec<(how nested this timing is, label, length in seconds)>