Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/render/src/approximations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! What frames drew otherwise than their layers ask (Never silent): a dashed line drawn solid,
//! a fill left off a block diagram's walls, ground with no height taken as 0 under a block.
//! a fill left off a block diagram's walls, ground with no height taken as 0 under a block, and,
//! in an export's drawing, a layer drawn from less than it needs (the map view says its own).
//!
//! The drawing code has no session to tell, and a frame comes many times a second, so a frame
//! keeps what it approximated on the thread drawing it, one notice per layer and kind (its key),
Expand Down
28 changes: 28 additions & 0 deletions crates/render/src/frame_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,34 @@ mod tests {
assert_eq!(opacities(&scene), vec![100], "the raster, the squares and the points in one picture");
}

/// Drawing again gives no more of a tile layer whose server has none of its tiles in view, so a
/// frame with one is kept: restyling a layer over it draws that layer, and the layer is still said.
#[test]
fn a_frame_with_a_tile_layer_without_a_tile_in_view_is_kept() {
let (mut map, view, _, above) = map();
crate::tiles::tests::serve();
map.tiles.push(rustgis_map::TileLayer::new("Gone", rustgis_map::TileKind::Raster, "https://tiles.test/gone/kept/{z}/{x}/{y}.png"));
crate::render_complete(&mut map, &view).expect("drawn");
// Another test's tiles landing meanwhile rightly draw the frame whole: a drag they fell
// in is done again.
let mut started = None;
for drag in 0..50u8 {
let before = rustgis_tiles::cache::generation();
for step in 0..4u8 {
if let Some(l) = map.layer_mut(above) {
l.renderer = Renderer::Single(rustgis_map::Symbol { fill: Rgba::rgb(drag, 200, 30 + step), ..l.symbol(0) });
}
started = draw(&mut map, &view);
}
if rustgis_tiles::cache::generation() == before {
break;
}
}
assert_eq!(started, Some(1), "a drag draws from the picture under the layer");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop stops at the first drag that lands no tile, so started is whatever the last draw returned. Under a parallel test run, another test's tiles can land during every drag. Then all 50 drags run, and the final draw may not be the one that draws from the picture, so assert_eq!(started, Some(1)) can fail on timing alone. Waiting for the other fetches to finish before the drags (rustgis_tiles::cache::wait), or asserting on the draw that follows the last quiet drag, would tie the check to this frame only. I haven't run it, so the confidence is medium-low.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 79e9e6f: each drag first waits for the fetches under way, other tests' included.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wait this added is out again in 538f680: under one process it waits on fetches other tests hold open on purpose. The retry on a moved generation stays, and CI runs each test in a process of its own.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-raising the earlier flakiness point on this assertion, because the code under it changed. The wait that answered it (79e9e6f) was removed in 538f680, so the loop again ends only on a drag that lands no tile. If other tests' tiles land during every drag (up to 50 drags of 4 draws), the last draw may be one that draws the frame whole, and started is then None here, with nothing in the test to prevent it. A wait on this fixture's own fetches, or asserting on the draw right after the last quiet drag, would tie the check to this frame. Confidence: medium-low; I have not run it.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass. CI runs each test in a process of its own, where no other test's tiles can land; under cargo test the drag is repeated until a quiet one, up to 50 times.

let r = render(&mut map, &view).expect("drawn");
assert!(r.tile_errors.iter().any(|e| e.starts_with("Gone: none of the tiles in view")), "{:?}", r.tile_errors);
}

#[test]
fn a_layer_with_no_look_draws_in_every_frame() {
let (mut map, view, below, _) = map();
Expand Down
9 changes: 6 additions & 3 deletions crates/render/src/gpu_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ pub struct GpuScene {
pub tiles_pending: bool,
/// Streamed layers are still reading the view: drawing again later shows them.
pub data_pending: bool,
/// Tile layers that couldn't be drawn, and why.
/// Layers that couldn't be drawn in full, or whose server has none of their tiles in view, and why.
pub tile_errors: Vec<String>,
/// Those of `tile_errors` that say a layer's server has none of its tiles in view: a view drawn
/// in parts says one only when every part does.
pub absent: Vec<String>,
/// Raster layers read in place drawn from less than the view needs (a coarser level, tiles
/// they couldn't read), by id, their errors among `tile_errors`: an export refuses them.
pub partial: Vec<u32>,
/// they couldn't read), by id, each with its error (also in `tile_errors`): an export refuses them.
pub partial: Vec<(u32, String)>,
/// Raster layers read in place whose tiles are still on their way, by id: drawn again as
/// they land; an export that can't wait refuses them.
pub pending_in_place: Vec<u32>,
Expand Down
48 changes: 47 additions & 1 deletion crates/render/src/layout/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2938,9 +2938,12 @@ fn a_page_says_why_a_frame_drew_no_cast_shadows() {
r.overview = Some((1000, 10));
rl.data = Some(std::sync::Arc::new(r));
let (_, said) = crate::shadows_said(|| colorbar_page(&map, Orientation::Horizontal, false, ""));
// And that its picture is less than the page needs: its file can't be read here.
let undrawn = "a layer couldn't be drawn in full, so parts of it may be empty or coarse: dem: dem.tif: ";
let said = said.notices;
assert_eq!(said.len(), 1, "{said:?}");
assert_eq!(said.len(), 2, "{said:?}");
assert!(said[0].starts_with("dem: ") && said[0].contains("read in place"), "{said:?}");
assert!(said[1].starts_with(undrawn), "{said:?}");
// What the map view's frame said is not a page's: a clean page drawn after it says nothing.
let camera = rustgis_map::Camera { center: rustgis_geom::lonlat_to_merc(Coord::new(0.5, 0.5)), res: 2000.0, bearing: 0.0, pitch: 0.0 };
crate::render(&mut map, &crate::View { width: 64.0, height: 64.0, pixels_per_point: 1.0, camera, sky: false });
Expand All @@ -2949,6 +2952,48 @@ fn a_page_says_why_a_frame_drew_no_cast_shadows() {
assert!(said.notices.is_empty(), "{said:?}");
}

/// An export refused for a raster read in place says that raster's own reason, not that of a layer
/// whose name goes on from its name with a colon.
#[test]
fn a_refused_export_says_the_refused_layers_own_reason() {
crate::tiles::tests::serve();
let mut map = ramp_map(rustgis_map::raster::RasterRenderer::Rgb { red: 0, green: 0, blue: 0 }, rustgis_map::raster::Stretch::MinMax);
let rl = map.layers.iter_mut().find_map(|l| l.raster.as_mut()).unwrap();
rl.in_place = true;
let mut r = (**rl.data.as_ref().unwrap()).clone();
r.overview = Some((1000, 10));
rl.data = Some(std::sync::Arc::new(r));
// Fails, and is drawn (and so said) before the raster.
let failing = "https://tiles.test/unknown-refused/{z}/{x}/{y}.png";
map.tiles = vec![rustgis_map::TileLayer::new("dem: tiles", rustgis_map::TileKind::Raster, failing)];
let camera = rustgis_map::Camera { center: rustgis_geom::lonlat_to_merc(Coord::new(0.5, 0.995)), res: 100.0, bearing: 0.0, pitch: 0.0 };
let view = crate::View { width: 64.0, height: 64.0, pixels_per_point: 1.0, camera, sky: false };
let drawn = crate::render_complete(&mut map, &view).unwrap();
assert!(drawn.tile_errors.first().is_some_and(|e| e.starts_with("dem: tiles: ")), "{:?}", drawn.tile_errors);
// Nor that of one named as its error begins.
map.tiles.insert(0, rustgis_map::TileLayer::new("dem: dem.tif", rustgis_map::TileKind::Raster, failing));
let refused = crate::render_png(&mut map, &view).unwrap_err();
assert_eq!(refused, "dem: dem.tif: only http:// and https:// addresses are fetched, so the image isn't written");
}

/// A map PDF says a raster read in place that is drawn from less than it needs: unlike a PNG or a
/// GeoTIFF, it doesn't refuse one.
#[test]
fn a_map_pdf_says_a_raster_read_in_place_drawn_from_less() {
let mut map = ramp_map(rustgis_map::raster::RasterRenderer::Rgb { red: 0, green: 0, blue: 0 }, rustgis_map::raster::Stretch::MinMax);
let rl = map.layers.iter_mut().find_map(|l| l.raster.as_mut()).unwrap();
rl.in_place = true;
let mut r = (**rl.data.as_ref().unwrap()).clone();
r.overview = Some((1000, 10));
rl.data = Some(std::sync::Arc::new(r));
let camera = rustgis_map::Camera { center: rustgis_geom::lonlat_to_merc(Coord::new(0.5, 0.995)), res: 100.0, bearing: 0.0, pitch: 0.0 };
let view = crate::View { width: 64.0, height: 64.0, pixels_per_point: 1.0, camera, sky: false };
let (pdf, said) = crate::shadows_said(|| crate::render_drawing(&mut map, &view));
assert!(pdf.is_ok());
let undrawn = "a layer couldn't be drawn in full, so parts of it may be empty or coarse: dem: dem.tif: ";
assert_eq!(said.notices.iter().filter(|n| n.starts_with(undrawn)).count(), 1, "{:?}", said.notices);
}

/// A page with maps showing copies of one relief (each layer the first of its map, so with the
/// same id), each under its own sun, drawn again until it has no shadows to come, as the
/// Layout view draws it while they land. Panics if it never settles.
Expand Down Expand Up @@ -5655,6 +5700,7 @@ fn a_frames_attribution_keeps_clear_of_its_grid_labels() {
tiles_pending: false,
data_pending: false,
tile_errors: Vec::new(),
absent: Vec::new(),
partial: Vec::new(),
pending_in_place: Vec::new(),
recorded: None,
Expand Down
93 changes: 60 additions & 33 deletions crates/render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ mod text;
pub use text::CALLOUT_WIDTH;
mod frame_cache;
mod layer_meshes;
mod tile_errors;
pub mod tile_mesh;
mod tiles;
pub mod vector;
pub use tile_errors::{tile_error_kind, tile_error_notices};
pub use tiles::{Live, live as live_tiles};

pub use rustgis_tiles;
Expand Down Expand Up @@ -558,11 +560,14 @@ pub struct Rendered {
pub tiles_pending: bool,
/// Streamed layers are still reading the view: drawing again later shows them.
pub data_pending: bool,
/// Tile layers that couldn't be drawn, and why.
/// Layers that couldn't be drawn in full, or whose server has none of their tiles in view, and why.
pub tile_errors: Vec<String>,
/// Those of `tile_errors` that say a layer's server has none of its tiles in view: a view drawn
/// in parts says one only when every part does.
pub absent: Vec<String>,
/// Raster layers read in place drawn from less than the view needs (a coarser level, tiles
/// they couldn't read), by id, their errors among `tile_errors`: an export refuses them.
pub partial: Vec<u32>,
/// they couldn't read), by id, each with its error (also in `tile_errors`): an export refuses them.
pub partial: Vec<(u32, String)>,
/// Raster layers read in place whose tiles are still on their way, by id: drawn again as
/// they land; an export that can't wait refuses them.
pub pending_in_place: Vec<u32>,
Expand Down Expand Up @@ -2903,7 +2908,8 @@ fn render_tilted(
let mut kept: Vec<(View, (f64, f64), Pixmap)> = Vec::new();
let last = bands_of.len().saturating_sub(1);
let (mut attribution, mut tiles_pending, mut tile_errors) = (Vec::<String>::new(), false, Vec::<String>::new());
let (mut partial, mut pending_in_place) = (Vec::<u32>::new(), Vec::<u32>::new());
let (mut partial, mut pending_in_place) = (Vec::<(u32, String)>::new(), Vec::<u32>::new());
let mut absences = tile_errors::Bands::default();
for (i, b) in bands_of.into_iter().enumerate() {
// A stopped frame (see `cancel`) draws no further band, nor its drape or warp.
if cancel::requested() {
Expand Down Expand Up @@ -2932,21 +2938,23 @@ fn render_tilted(
return None;
}
// Preserve the upstream best-effort band path for ordinary providers.
absences.unknown();
continue;
};
for a in r.attribution {
if !attribution.contains(&a) {
attribution.push(a);
}
}
for e in r.tile_errors {
absences.band(&r.absent);
for e in r.tile_errors.into_iter().filter(|e| !r.absent.contains(e)) {
if !tile_errors.contains(&e) {
tile_errors.push(e);
}
}
for id in r.partial {
if !partial.contains(&id) {
partial.push(id);
for (id, why) in r.partial {
if !partial.iter().any(|(had, _)| *had == id) {
partial.push((id, why));
}
}
for id in r.pending_in_place {
Expand Down Expand Up @@ -2989,6 +2997,8 @@ fn render_tilted(
}
}
let unplaced = if map.label_display.show_unplaced { placed.unplaced } else { Vec::new() };
let absent = absences.finish();
tile_errors.extend(absent.iter().cloned());
Some(Rendered {
pixmap: pm.into_pixmap(),
labels: placed.labels,
Expand All @@ -2997,6 +3007,7 @@ fn render_tilted(
tiles_pending,
data_pending,
tile_errors,
absent,
partial,
pending_in_place,
recorded: None,
Expand Down Expand Up @@ -3453,7 +3464,10 @@ fn gpu_turned(
let mut candidates = Vec::new();
let (mut cmds, mut clips) = (Vec::new(), Vec::new());
let (mut attribution, mut tiles_pending, mut tile_errors, mut clear) = (Vec::<String>::new(), false, Vec::<String>::new(), [0.0; 4]);
let (mut partial, mut pending_in_place) = (Vec::<u32>::new(), Vec::<u32>::new());
let (mut partial, mut pending_in_place) = (Vec::<(u32, String)>::new(), Vec::<u32>::new());
// No band says a layer has no tile in view: a map with tile layers isn't drawn here
// (`gpu_may_turn`).
let absent = Vec::new();
let mut plain = true;
let last = bands.len().saturating_sub(1);
for (i, b) in bands.iter().enumerate() {
Expand Down Expand Up @@ -3505,9 +3519,9 @@ fn gpu_turned(
tile_errors.push(e);
}
}
for id in scene.partial {
if !partial.contains(&id) {
partial.push(id);
for (id, why) in scene.partial {
if !partial.iter().any(|(had, _)| *had == id) {
partial.push((id, why));
}
}
for id in scene.pending_in_place {
Expand Down Expand Up @@ -3562,6 +3576,7 @@ fn gpu_turned(
tiles_pending,
data_pending,
tile_errors,
absent,
partial,
pending_in_place,
tilt,
Expand Down Expand Up @@ -5326,10 +5341,10 @@ fn render_frame(
Err(e) => {
let e = format!("{}: {e}", layer.name);
if !tile_out.errors.contains(&e) {
tile_out.errors.push(e);
tile_out.errors.push(e.clone());
}
if !tile_out.partial.contains(&layer.id) {
tile_out.partial.push(layer.id);
if !tile_out.partial.iter().any(|(id, _)| *id == layer.id) {
tile_out.partial.push((layer.id, e));
}
}
},
Expand Down Expand Up @@ -7144,7 +7159,8 @@ fn render_frame(
}
let attribution = tile_out.attribution;
let tiles_pending = tile_out.pending;
let tile_errors = tile_out.errors;
let absent = tile_out.absent;
let tile_errors: Vec<String> = tile_out.errors.into_iter().chain(absent.iter().cloned()).collect();
let partial = tile_out.partial;
let pending_in_place = tile_out.pending_in_place;
match backend {
Expand All @@ -7161,6 +7177,7 @@ fn render_frame(
tiles_pending,
data_pending,
tile_errors,
absent,
partial,
pending_in_place,
recorded,
Expand Down Expand Up @@ -7190,6 +7207,7 @@ fn render_frame(
tiles_pending,
data_pending,
tile_errors,
absent,
partial,
pending_in_place,
tilt: None,
Expand Down Expand Up @@ -8800,7 +8818,7 @@ fn take_said() -> ShadowsSaid {
let mut notices = take_shadow_notices();
let mut keys = notices.clone();
for (kind, e) in approximations::take_keyed(&[]) {
let key = format!("approximated\0{kind}");
let key = notice_key(&kind);
if !keys.contains(&key) {
keys.push(key);
notices.push(e);
Expand All @@ -8809,6 +8827,15 @@ fn take_said() -> ShadowsSaid {
ShadowsSaid { notices, keys, to_come: SHADOWS_TO_COME.with(|c| c.replace(false)) }
}

/// Starts the kind of what an export or page says of a layer drawn from less than it needs; what
/// follows is the key the map view says that layer's error under ([`tile_error_notices`]).
const UNDRAWN: &str = "\0undrawn\0";

/// The key a notice of `kind` is said once under, by the map view and the pages alike.
pub fn notice_key(kind: &str) -> String {
kind.strip_prefix(UNDRAWN).map_or_else(|| format!("approximated\0{kind}"), str::to_string)
}

/// What frames drawn on this thread approximated since the last call, and what map view frames
/// drawn on worker threads handed over to `relays` ([`ApproximationRelay::hand_over`]), each kind
/// once, as (kind, notice): what the map view says after each frame it shows, each kind once a
Expand Down Expand Up @@ -8908,8 +8935,21 @@ fn complete(map: &mut Map, view: &View, record: bool, failed_source: &mut Option
let before = (SHADOWS_TO_COME.with(|c| c.replace(false)), take_shadow_notices());
let r = complete_passes(map, view, record, failed_source, env);
SHADOWS_TO_COME.with(|c| c.set(before.0 || c.get()));
let drawn = take_shadow_notices();
// A layer drawn from less than it needs (a tile layer whose tiles failed, a raster read in
// place drawn from a coarser level) leaves its part empty or coarse, which in a finished
// picture passes for the map: whoever this draws for says it (see `shadows_said`), each layer
// and kind once. Cast shadows left out are said as such.
for e in r.iter().flat_map(|r| &r.tile_errors).filter(|e| !drawn.contains(e)) {
for (key, notice) in tile_error_notices(map, e) {
approximations::note(
format!("{UNDRAWN}{key}"),
format!("a layer couldn't be drawn in full, so parts of it may be empty or coarse: {notice}"),
);
}
}
let mut notices = before.1;
for e in take_shadow_notices() {
for e in drawn {
if !notices.contains(&e) {
notices.push(e);
}
Expand Down Expand Up @@ -9065,7 +9105,7 @@ pub fn render_placed(map: &mut Map, view: &View) -> Result<Placed, String> {
let approximated = approximations::take();
approximations::restore(approximated_before);
let r = r?;
let tile_errors: Vec<&String> = r.tile_errors.iter().filter(|e| !shadows.contains(e)).collect();
// Tile layers that couldn't be drawn are among what it approximated (see `complete`).
let mut gaps = shadows;
gaps.extend(approximated);
if to_come {
Expand All @@ -9083,14 +9123,6 @@ pub fn render_placed(map: &mut Map, view: &View) -> Result<Placed, String> {
.to_string(),
);
}
if let Some(first) = tile_errors.first() {
let n = tile_errors.len();
gaps.push(if n == 1 {
format!("a tile layer couldn't be drawn, so its part is empty: {first}")
} else {
format!("{n} tile layers couldn't be drawn, so their parts are empty; the first: {first}")
});
}
revisions.finish(map, None, Some(Placed { pixmap: r.pixmap, credits: r.attribution, gaps }), "could not draw the map")
}

Expand All @@ -9108,12 +9140,7 @@ fn render_exported(map: &mut Map, view: &View) -> Result<Rendered, String> {
if let Some(l) = r.pending_in_place.first().and_then(|id| map.layers.iter().find(|l| l.id == *id)) {
return Err(format!("{}: its tiles are still on their way: export again once the map has drawn it", l.name));
}
if let Some(l) = r.partial.first().and_then(|id| map.layers.iter().find(|l| l.id == *id)) {
// Its own error, named by the layer, says why; else the general one.
let why = r.tile_errors.iter().find(|e| e.starts_with(&format!("{}: ", l.name))).cloned();
let why = why.unwrap_or_else(|| {
format!("{}: drawn from less than the view needs (a coarser level, or tiles that couldn't be read)", l.name)
});
if let Some((_, why)) = r.partial.first() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map PDF's overflow fallback still refuses a raster read in place that is drawn from less than it needs. map_pdf_inner (crates/engine/src/cmd/share.rs:370-372) draws the picture through render_png, which goes through render_exported, and that returns Err(... so the image isn't written) when partial is non-empty. So a map PDF that the vector path writes with the new notice fails when it overflows into a picture. Nothing is lost silently, since the export fails with a message, but it contradicts the PR's statement that a map PDF now says such a layer and doesn't refuse it. The new test a_map_pdf_says_a_raster_read_in_place_drawn_from_less only covers the vector path (its map is small), so the overflow path has no coverage.

Either let the overflow picture draw the layer and say it through complete, or state the refusal in docs/user-guide/sharing.md. Confidence: medium-high from reading the call path; I did not run it.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guide and the description say so since 538f680: a map PDF too large for vectors is drawn as a picture and refuses such a raster, as it does on main.

return Err(format!("{why}, so the image isn't written"));
}
Ok(r)
Expand Down
Loading
Loading