From 3393db9f6b3cac83fe97cd16527ca6143c0694f1 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 02:17:09 -0300 Subject: [PATCH 1/3] fix(render): an export says only its last pass's cast-shadow notices (#1782) - complete clears the notices before each pass, as it does the still-to-come flag, and keeps what frames before it said. - The tilted wait test holds the work and runs the export on a thread: it checks the export is still waiting before letting the work go. - start_light's doc comment is back above it, not the LIGHT_HOLD static. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/raster.rs | 4 ++-- crates/render/src/lib.rs | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/crates/map/src/raster.rs b/crates/map/src/raster.rs index 356297d94e..2543972f19 100644 --- a/crates/map/src/raster.rs +++ b/crates/map/src/raster.rs @@ -964,8 +964,6 @@ const STOPPED: &str = "its cast shadows were stopped"; /// each owner's latest. const KEPT_LIGHTS: usize = 3; -/// Works out a light grid: natively on a thread of its own (here if the system refuses one), -/// in the browser here. /// Held by [`hold_cast_shadows`]: light work waits for it before it traces. static LIGHT_HOLD: std::sync::RwLock<()> = std::sync::RwLock::new(()); @@ -976,6 +974,8 @@ pub fn hold_cast_shadows() -> std::sync::RwLockWriteGuard<'static, ()> { LIGHT_HOLD.write().unwrap_or_else(|e| e.into_inner()) } +/// Works out a light grid: natively on a thread of its own (here if the system refuses one), +/// in the browser here. fn start_light(r: Arc, key: LightKey, work: Arc) { let run = move || { drop(LIGHT_HOLD.read().unwrap_or_else(|e| e.into_inner())); diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 654d2716fb..d7676d1f21 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -6468,15 +6468,23 @@ fn complete(map: &mut Map, view: &View, record: bool) -> Option { if !NO_SHADOW_WAIT.with(std::cell::Cell::get) { wait_for_cast_shadows(map, view); } - // Whether cast shadows were still to come is the last pass's to say (an earlier one's may - // have been drawn again with them); what frames before it said is kept (see `shadows_said`). - let before = SHADOWS_TO_COME.with(|c| c.replace(false)); + // What it says of cast shadows (still to come, layers drawn without them) is the last pass's + // to say: an earlier one's may have been drawn again with them. What frames before it said + // is kept (see `shadows_said`). + let before = (SHADOWS_TO_COME.with(|c| c.replace(false)), take_shadow_notices()); let r = complete_passes(map, view, record); - SHADOWS_TO_COME.with(|c| c.set(before || c.get())); + SHADOWS_TO_COME.with(|c| c.set(before.0 || c.get())); + let mut notices = before.1; + for e in take_shadow_notices() { + if !notices.contains(&e) { + notices.push(e); + } + } + SHADOW_NOTICES.with(|n| *n.borrow_mut() = notices); r } -/// [`complete`]'s passes, each saying afresh whether cast shadows were still to come. +/// [`complete`]'s passes, each saying afresh what it drew of cast shadows. fn complete_passes(map: &mut Map, view: &View, record: bool) -> Option { // What had come when it drew: what lands meanwhile is news to the wait. let mut drawn_at = rustgis_tiles::cache::generation(); @@ -6500,6 +6508,7 @@ fn complete_passes(map: &mut Map, view: &View, record: bool) -> Option } drawn_at = now; SHADOWS_TO_COME.with(|c| c.set(false)); + take_shadow_notices(); r = render_cpu(map, view, true, record)?; } Some(r) @@ -8681,9 +8690,20 @@ mod tests { rustgis_map::RasterRenderer::ShadedRelief { band: 0, ramp: None, azimuth: 210.0, altitude: 5.0, z_factor: 1.0, shadow: 1.0 }; // Drawn only zoomed out past a scale between the centre's and the far band's. l.max_scale = Some((centre + farthest) / 2.0); - render_complete(&mut m, &view).unwrap(); + // Its work held before it traces: an export that waits for it can't end until it is let + // go; one that doesn't ends at once. + let hold = rustgis_map::raster::hold_cast_shadows(); + let export = std::thread::spawn(move || { + render_complete(&mut m, &view).unwrap(); + m + }); + std::thread::sleep(std::time::Duration::from_millis(500)); + let waited = !export.is_finished(); + drop(hold); + let m = export.join().unwrap(); + assert!(waited, "the export waited for the far band's cast shadows"); let rl = m.layer(id).and_then(|l| l.raster.as_ref()).unwrap(); - assert!(matches!(rl.cast_shadows(false, (0, 0), || {}), rustgis_map::raster::CastShadows::Ready(_)), "waited for"); + assert!(matches!(rl.cast_shadows(false, (0, 0), || {}), rustgis_map::raster::CastShadows::Ready(_)), "and drew them"); } /// An export doesn't wait for, nor start, the cast shadows of a layer it doesn't draw: one From 69e413955e9b62b637b1d2445292cfc40e5798cd Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 02:54:58 -0300 Subject: [PATCH 2/3] test(render): the tilted wait test waits for the export's own signal (#1782) RasterLayer::cast_shadow_waiters (hidden, for tests) counts who waits for a layer's grids, its copies' too. The test polls it with the work held: the export either says it waits, and can't end, or ends without waiting. No timing decides either way; with the wait cut to the centre scale, it fails. Co-Authored-By: Claude Opus 5.5 --- crates/map/src/raster.rs | 8 ++++++++ crates/render/src/lib.rs | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/map/src/raster.rs b/crates/map/src/raster.rs index 2543972f19..68c80590b5 100644 --- a/crates/map/src/raster.rs +++ b/crates/map/src/raster.rs @@ -732,6 +732,14 @@ impl RasterLayer { matches!(self.style.renderer, RasterRenderer::ShadedRelief { shadow, .. } if shadow > 0.0) } + /// How many wait for its cast shadows now (exports), its copies' too: for tests of what an + /// export waits for. + #[doc(hidden)] + pub fn cast_shadow_waiters(&self) -> usize { + let Ok(jobs) = self.cast.0.lock() else { return 0 }; + jobs.iter().map(|j| j.work.waiting.load(std::sync::atomic::Ordering::SeqCst)).sum() + } + /// The light its cast shadows leave on each cell (see [`crate::shadow::light`]), when it is /// drawn as Shaded Relief with shadows. Worked out once per pixels, band, sun, Z factor and /// mask and kept: each owner's latest, and a few of suns left, for going back. diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index d7676d1f21..f9ea1b6d69 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -8691,14 +8691,17 @@ mod tests { // Drawn only zoomed out past a scale between the centre's and the far band's. l.max_scale = Some((centre + farthest) / 2.0); // Its work held before it traces: an export that waits for it can't end until it is let - // go; one that doesn't ends at once. + // go, and says it waits (a copy of the layer shares its grids); one that doesn't ends. + let probe = m.layer(id).and_then(|l| l.raster.clone()).unwrap(); let hold = rustgis_map::raster::hold_cast_shadows(); let export = std::thread::spawn(move || { render_complete(&mut m, &view).unwrap(); m }); - std::thread::sleep(std::time::Duration::from_millis(500)); - let waited = !export.is_finished(); + while probe.cast_shadow_waiters() == 0 && !export.is_finished() { + std::thread::sleep(std::time::Duration::from_millis(1)); + } + let waited = probe.cast_shadow_waiters() > 0; drop(hold); let m = export.join().unwrap(); assert!(waited, "the export waited for the far band's cast shadows"); From 7c841656a46310f447031a813b5f3889141044e9 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 12 Nov 2026 03:05:14 -0300 Subject: [PATCH 3/3] test(render): the tilted wait test fails, not hangs, after 30 s (#1782) Co-Authored-By: Claude Opus 5.5 --- crates/render/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index f9ea1b6d69..7ca0019567 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -8698,7 +8698,9 @@ mod tests { render_complete(&mut m, &view).unwrap(); m }); + let start = std::time::Instant::now(); while probe.cast_shadow_waiters() == 0 && !export.is_finished() { + assert!(start.elapsed() < std::time::Duration::from_secs(30), "the export neither waited for the grid nor ended"); std::thread::sleep(std::time::Duration::from_millis(1)); } let waited = probe.cast_shadow_waiters() > 0;