diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 4280efd4a..e7fdbb497 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -1847,30 +1847,12 @@ impl Renderer { }) .create_view(&Default::default()) } - /// VSync on: tear-free presentation (Mailbox, else Fifo); off: Immediate when available. - /// VSync, unless Horizon's present-mode setting names a supported mode. + /// VSync on presents with Fifo, capped to the display's refresh rate in a + /// window and in fullscreen alike; Horizon's present-mode setting applies + /// only with VSync off (`window::chosen_present_mode`). pub fn set_present_mode(&mut self, vsync: bool, mode: crate::graphics::PresentMode) { use crate::graphics::PresentMode as P; - let wanted = match mode { - P::Auto => None, - P::Fifo => Some(wgpu::PresentMode::Fifo), - P::Mailbox => Some(wgpu::PresentMode::Mailbox), - P::Immediate => Some(wgpu::PresentMode::Immediate), - }; - match wanted.filter(|m| self.present_modes.contains(m)) { - Some(m) => { - if self.config.present_mode != m - && let Some(surface) = &self.surface - { - self.config.present_mode = m; - surface.configure(&self.device, &self.config); - } - } - None => self.set_vsync(vsync), - } - } - pub fn set_vsync(&mut self, vsync: bool) { - use crate::window::{PresentMode, vsync_present_mode}; + use crate::window::{PresentMode, chosen_present_mode}; let supported: Vec = self .present_modes .iter() @@ -1881,8 +1863,13 @@ impl Renderer { _ => None, }) .collect(); - // GpuSurface.PresentMode.getSupportedVsyncMode. - let mode = match vsync_present_mode(&supported, vsync) { + let setting = match mode { + P::Auto => None, + P::Fifo => Some(PresentMode::Fifo), + P::Mailbox => Some(PresentMode::Mailbox), + P::Immediate => Some(PresentMode::Immediate), + }; + let mode = match chosen_present_mode(&supported, vsync, setting) { Some(PresentMode::Mailbox) => wgpu::PresentMode::Mailbox, Some(PresentMode::Immediate) => wgpu::PresentMode::Immediate, _ => wgpu::PresentMode::Fifo, diff --git a/crates/horizon-client/src/graphics.rs b/crates/horizon-client/src/graphics.rs index f10c6b3b3..e8fb2bff1 100644 --- a/crates/horizon-client/src/graphics.rs +++ b/crates/horizon-client/src/graphics.rs @@ -53,7 +53,9 @@ impl Preset { /// How the swapchain presents frames. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum PresentMode { - /// Follow vanilla's VSync option (Mailbox or Fifo on, Immediate off). + /// Vanilla's choice: Fifo with VSync on, else the first of Immediate, + /// Mailbox and Fifo the surface supports. The other modes apply only + /// with VSync off: VSync on always presents with Fifo. #[default] Auto, Fifo, diff --git a/crates/horizon-client/src/graphics_ui.rs b/crates/horizon-client/src/graphics_ui.rs index 745cd5d80..4d7619037 100644 --- a/crates/horizon-client/src/graphics_ui.rs +++ b/crates/horizon-client/src/graphics_ui.rs @@ -211,7 +211,7 @@ pub fn rows(level: Level) -> Vec { h( H::PresentMode, None, - "How frames reach the screen. Auto follows VSync.", + "How frames reach the screen while VSync is off.", ), h( H::Pacing, diff --git a/crates/horizon-client/src/window.rs b/crates/horizon-client/src/window.rs index 7c77d85c6..33ff52111 100644 --- a/crates/horizon-client/src/window.rs +++ b/crates/horizon-client/src/window.rs @@ -128,6 +128,20 @@ pub fn vsync_present_mode(supported: &[PresentMode], vsync: bool) -> Option, +) -> Option { + setting + .filter(|m| !vsync && supported.contains(m)) + .or_else(|| vsync_present_mode(supported, vsync)) +} + /// `FramerateLimiter.limitDisplayFPS` with an injectable clock so the sleep /// and spin decisions are testable. #[derive(Clone, Debug)] @@ -415,4 +429,23 @@ mod tests { Some(PresentMode::Fifo) ); } + #[test] + fn vsync_on_waits_for_the_display_whatever_the_present_mode() { + use PresentMode::*; + let all = [Mailbox, Fifo, Immediate]; + for setting in [None, Some(Fifo), Some(Mailbox), Some(Immediate)] { + assert_eq!(chosen_present_mode(&all, true, setting), Some(Fifo)); + } + assert_eq!(chosen_present_mode(&all, false, None), Some(Immediate)); + assert_eq!( + chosen_present_mode(&all, false, Some(Mailbox)), + Some(Mailbox) + ); + assert_eq!(chosen_present_mode(&all, false, Some(Fifo)), Some(Fifo)); + // Metal has no Mailbox: vanilla's choice instead. + assert_eq!( + chosen_present_mode(&[Fifo, Immediate], false, Some(Mailbox)), + Some(Immediate) + ); + } } diff --git a/docs/graphics.md b/docs/graphics.md index a55313bea..7fa69577e 100644 --- a/docs/graphics.md +++ b/docs/graphics.md @@ -25,7 +25,7 @@ Every row has a one-line description and its cost in frame time (none, low, medi | Performance | battery mode, worker threads, upload budget per frame | `horizon-graphics.txt` | | Overlay | performance overlay: FPS, frame/CPU/GPU times, frame-time graph | `horizon-graphics.txt` | -`options.txt` keeps exactly vanilla's keys and values, so the options harness still compares it with vanilla; Horizon's settings live in `horizon-graphics.txt` beside it. Their defaults render as vanilla does: cave culling on, no upload budgets, sky, fog and weather on, 100% resolution, no FXAA, the present mode following VSync. Frame pacing defaults to Efficient: the limiter sleeps through the last half millisecond where vanilla spins, which changes timing, not pixels. +`options.txt` keeps exactly vanilla's keys and values, so the options harness still compares it with vanilla; Horizon's settings live in `horizon-graphics.txt` beside it. Their defaults render as vanilla does: cave culling on, no upload budgets, sky, fog and weather on, 100% resolution, no FXAA, the present mode following VSync. VSync on always waits for the display (Fifo), in a window and in fullscreen, as in vanilla; the present mode setting chooses how frames are shown only while VSync is off. Frame pacing defaults to Efficient: the limiter sleeps through the last half millisecond where vanilla spins, which changes timing, not pixels. **Battery mode** (Performance, off by default) is for laptops and handhelds: at most 60 frames per second in a world, 30 in menus without a world or while another window has focus, and half the automatic worker threads (chunks load slower). It changes only when frames are drawn: what they show and the game's 20 ticks per second stay as they are.