cache present modes, add check for present modes in set_render_mode and move present mode localization to hud

This commit is contained in:
Isse 2024-01-27 22:57:29 +01:00 committed by Marcel Märtens
parent cfd0ffd7f6
commit 89d70cc932
3 changed files with 30 additions and 24 deletions

View File

@ -7,7 +7,7 @@ use crate::{
},
render::{
AaMode, BloomConfig, BloomFactor, BloomMode, CloudMode, FluidMode, LightingMode,
ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode,
PresentMode, ReflectionMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode,
},
session::settings_change::Graphics as GraphicsChange,
settings::{Fps, GraphicsSettings},
@ -662,7 +662,14 @@ impl<'a> Widget for Video<'a> {
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()))
.map(|mode| {
self.localized_strings.get_msg(match mode {
PresentMode::Fifo => "hud-settings-present_mode-vsync_capped",
PresentMode::FifoRelaxed => "hud-settings-present_mode-vsync_adaptive",
PresentMode::Mailbox => "hud-settings-present_mode-vsync_uncapped",
PresentMode::Immediate => "hud-settings-present_mode-vsync_off",
})
})
.collect::<Vec<_>>();
// Get which present mode is currently active

View File

@ -298,17 +298,6 @@ pub enum PresentMode {
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<PresentMode> for wgpu::PresentMode {
fn from(mode: PresentMode) -> Self {
match mode {

View File

@ -135,7 +135,6 @@ enum State {
pub struct Renderer {
device: Arc<wgpu::Device>,
queue: wgpu::Queue,
adapter: wgpu::Adapter,
surface: wgpu::Surface,
surface_config: wgpu::SurfaceConfiguration,
@ -185,6 +184,8 @@ pub struct Renderer {
/// The texture format used for the intermediate rendering passes
intermediate_format: wgpu::TextureFormat,
present_modes: Vec<PresentMode>,
}
impl Renderer {
@ -562,10 +563,16 @@ impl Renderer {
#[cfg(feature = "egui-ui")]
let egui_renderpass = egui_wgpu_backend::RenderPass::new(&device, format, 1);
let present_modes = surface
.get_capabilities(&adapter)
.present_modes
.into_iter()
.filter_map(|present_mode| PresentMode::try_from(present_mode).ok())
.collect();
Ok(Self {
device,
queue,
adapter,
surface,
surface_config,
@ -606,6 +613,7 @@ impl Renderer {
graphics_backend,
intermediate_format,
present_modes,
})
}
@ -642,7 +650,16 @@ impl Renderer {
self.other_modes = other_modes;
// Update present mode in swap chain descriptor
self.surface_config.present_mode = self.other_modes.present_mode.into();
self.surface_config.present_mode =
if self.present_modes.contains(&self.other_modes.present_mode) {
self.other_modes.present_mode
} else {
*self
.present_modes
.first()
.expect("There should never be no supported present modes")
}
.into();
// Only enable profiling if the wgpu features are enabled
self.other_modes.profiler_enabled &= self.profiler_features_enabled;
@ -687,14 +704,7 @@ impl Renderer {
pub fn pipeline_modes(&self) -> &PipelineModes { &self.pipeline_modes }
/// Get the supported present modes.
pub fn present_modes(&self) -> Vec<PresentMode> {
self.surface
.get_capabilities(&self.adapter)
.present_modes
.into_iter()
.filter_map(|present_mode| PresentMode::try_from(present_mode).ok())
.collect()
}
pub fn present_modes(&self) -> &[PresentMode] { &self.present_modes }
/// Get the current profiling times
/// Nested timings immediately follow their parent