diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index b991c224b..099e47e97 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -9644,12 +9644,17 @@ impl Game<'_> { } Ok(()) } + /// LOD Distance as far terrain uses it (`Graphics::lod_distance_on`). + fn lod_distance(&self) -> u32 { + match &self.renderer { + Some(renderer) => self.settings.horizon.lod_distance_on(&renderer.info), + None => self.settings.horizon.lod_distance.min(1024), + } + } /// Only enabled LOD worlds extend the renderer's range, never simulation. fn terrain_distance(&self) -> i32 { if self.lod.is_some() { - self.streaming - .radius - .max(self.settings.horizon.lod_distance.min(1024) as i32) + self.streaming.radius.max(self.lod_distance() as i32) } else { self.streaming.radius } @@ -9822,6 +9827,8 @@ impl Game<'_> { } } if let (Some(lod), Some(player)) = (&mut self.lod, &self.player) { + let lod_distance = self.settings.horizon.lod_distance_on(&renderer.info); + lod.set_near_loading(self.streaming.busy()); // The covered columns change only with the complete ones and // the render area: rebuilt then, not every frame. let at = ( @@ -9845,7 +9852,7 @@ impl Game<'_> { [player.position.x, player.position.y, player.position.z], self.yaw, self.streaming.radius, - self.settings.horizon.lod_distance, + lod_distance, covered, ) }); diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 212ec0505..06ebf31d6 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -752,6 +752,7 @@ impl Game<'_> { physical_keys.sort(); let lod = json!({ "distance": self.settings.horizon.lod_distance, + "effective_distance": self.lod_distance(), "terrain_distance": self.terrain_distance(), "source": if self.lod.is_none() { "none" } else if self.integrated.is_some() { "integrated" } else { "local" }, "source_attempted": self.lod_source_attempted, diff --git a/crates/horizon-client/src/graphics.rs b/crates/horizon-client/src/graphics.rs index 467afc8c2..e118a55ce 100644 --- a/crates/horizon-client/src/graphics.rs +++ b/crates/horizon-client/src/graphics.rs @@ -114,6 +114,26 @@ pub enum Overlay { Graph, } +/// The farthest LOD Distance, in chunks, on integrated GPUs other than +/// Apple's: they share the CPU's memory bandwidth, and past it far terrain +/// costs them more frame time than it is worth. +pub const INTEGRATED_LOD_DISTANCE: u32 = 128; +/// Whether `INTEGRATED_LOD_DISTANCE` applies to this adapter. Apple's GPUs +/// are integrated too, with memory and bandwidth enough for every distance. +pub fn lod_capped(info: &wgpu::AdapterInfo) -> bool { + info.device_type == wgpu::DeviceType::IntegratedGpu && !info.name.starts_with("Apple") +} +impl Graphics { + /// `lod_distance` as far terrain uses it on this adapter. + pub fn lod_distance_on(&self, info: &wgpu::AdapterInfo) -> u32 { + let distance = self.lod_distance.min(1024); + if lod_capped(info) { + distance.min(INTEGRATED_LOD_DISTANCE) + } else { + distance + } + } +} #[derive(Clone, Debug, PartialEq)] pub struct Graphics { pub preset: Preset, @@ -370,6 +390,46 @@ mod tests { ); } + #[test] + fn integrated_gpus_other_than_apple_cap_the_lod_distance() { + let adapter = |name: &str, device_type| wgpu::AdapterInfo { + name: name.into(), + vendor: 0, + device: 0, + device_type, + device_pci_bus_id: String::new(), + driver: String::new(), + driver_info: String::new(), + backend: wgpu::Backend::Vulkan, + subgroup_min_size: 0, + subgroup_max_size: 0, + transient_saves_memory: None, + limit_bucket: None, + }; + let hd620 = adapter( + "Intel(R) HD Graphics 620 (KBL GT2)", + wgpu::DeviceType::IntegratedGpu, + ); + let m4 = adapter("Apple M4 Pro", wgpu::DeviceType::IntegratedGpu); + let discrete = adapter("NVIDIA GeForce RTX 4070", wgpu::DeviceType::DiscreteGpu); + for (distance, capped) in [(0, 0), (64, 64), (128, 128), (256, 128), (1024, 128)] { + let g = Graphics { + lod_distance: distance, + ..Graphics::default() + }; + assert_eq!(g.lod_distance_on(&hd620), capped); + assert_eq!(g.lod_distance_on(&m4), distance); + assert_eq!(g.lod_distance_on(&discrete), distance); + } + assert!( + crate::graphics_ui::rows(crate::graphics_ui::Level::Simple) + .iter() + .any(|row| matches!(row, crate::graphics_ui::Row::Setting(s) + if s.text.contains(&format!("{INTEGRATED_LOD_DISTANCE} chunks")))), + "the LOD Distance description names the cap" + ); + } + #[test] fn lod_distance_is_opt_in_and_bounded() { assert_eq!(Graphics::default().lod_distance, 0); diff --git a/crates/horizon-client/src/graphics_ui.rs b/crates/horizon-client/src/graphics_ui.rs index 1da7c0f4f..0678f955c 100644 --- a/crates/horizon-client/src/graphics_ui.rs +++ b/crates/horizon-client/src/graphics_ui.rs @@ -82,7 +82,7 @@ pub fn rows(level: Level) -> Vec { let lod = h( H::LodDistance, Medium, - "Coarse distant surface in local worlds; no extra simulation.", + "Coarse distant terrain in local worlds. Integrated GPUs stop at 128 chunks.", ); let fov = v( Opt::Fov, diff --git a/crates/horizon-client/src/lod.rs b/crates/horizon-client/src/lod.rs index 463b814f9..0e1ed89ca 100644 --- a/crates/horizon-client/src/lod.rs +++ b/crates/horizon-client/src/lod.rs @@ -22,6 +22,10 @@ use std::{ const CELLS: usize = 16; const MAX_SAVED: usize = 1024; const SAMPLE_JOBS: usize = 4; +/// While the near terrain loads on a machine with four threads or fewer, far +/// terrain starts one sample job at most this often and no detail: it would +/// otherwise take the cores the near chunks and the frame need. +const HELD_SAMPLE_STEP: std::time::Duration = std::time::Duration::from_millis(500); /// The coarsest tile level: `Plan` roots cover at most 1024 chunks around. const MAX_LEVEL: u8 = 10; /// Top solid face and optional fluid face, in absolute block coordinates. @@ -507,6 +511,12 @@ pub struct Lod { detail_masks: FxHashMap, detail_request_pending: bool, detail_request_at: std::time::Instant, + /// Four threads or fewer: far work waits for the near terrain (`hold`). + small: bool, + /// The near terrain is loading (`set_near_loading`). + near_loading: bool, + /// When `request_samples` last started a job while held. + held_sample_at: std::time::Instant, /// `state_kinds`, from the first observed chunk's facts. kinds: Option>, /// Each tile's samples, shared with mesh jobs in flight. @@ -691,6 +701,9 @@ impl Lod { detail_masks: FxHashMap::default(), detail_request_pending: false, detail_request_at: std::time::Instant::now(), + small: thread::available_parallelism().map_or(1, |n| n.get()) <= 4, + near_loading: false, + held_sample_at: std::time::Instant::now(), kinds: None, ready: FxHashMap::default(), active: FxHashSet::default(), @@ -875,8 +888,17 @@ impl Lod { } self.invalidate_chunk(key.0, key.1); } + /// Whether the near terrain is still loading: on small machines far + /// terrain then holds back (`HELD_SAMPLE_STEP`). + pub fn set_near_loading(&mut self, loading: bool) { + self.near_loading = loading; + } + fn held(&self) -> bool { + self.small && self.near_loading + } fn request_detail(&mut self, camera: [i32; 2]) { - if self.detail_request_pending + if self.held() + || self.detail_request_pending || self.detail_request_at.elapsed() < std::time::Duration::from_millis(250) { return; @@ -1148,10 +1170,19 @@ impl Lod { elevation: i32, ) { // Every sample slot busy: no tile can be requested this frame. - let free = SAMPLE_JOBS.saturating_sub(self.pending.len()); + let free = if self.held() { + usize::from( + self.pending.is_empty() && self.held_sample_at.elapsed() >= HELD_SAMPLE_STEP, + ) + } else { + SAMPLE_JOBS.saturating_sub(self.pending.len()) + }; if free == 0 { return; } + if self.held() { + self.held_sample_at = std::time::Instant::now(); + } // Load desired nearby leaves directly, alongside broad fallback coverage. // Waiting for every ancestor/sibling made full detail take minutes to appear. let mut wanted = Vec::new(); diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 933219a21..3d791729c 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -766,6 +766,15 @@ impl Streaming { pub fn pending(&self) -> usize { self.shared.queue.lock().unwrap().len() } + /// Whether any chunk is queued or on its way from generation to a mesh. + pub fn busy(&self) -> bool { + !(self.generating.is_empty() + && self.decorating == 0 + && self.finishing.is_empty() + && self.lighting.is_empty() + && self.meshing.is_empty() + && self.pending() == 0) + } /// How much work each stage holds: queued jobs, then what is in flight or /// waiting at each step from generation to meshing. pub fn stages(&self) -> [(&'static str, usize); 7] {