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
6 changes: 6 additions & 0 deletions crates/map/src/look.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ impl LayerLook {
pub fn id(&self) -> u32 {
self.layer.id
}

/// Whether the rows it was taken of are still held: once the layer is removed, its map or
/// project closed, or its rows edited, nothing can look as this look again.
pub fn rows_held(&self) -> bool {

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.

rows_held releases less than its doc and the PR text say (Low-Medium, confidence ~0.5). let_go only drops a mesh once the Arc of its rows is gone. A layer that is removed or whose map closes keeps its rows alive while anything else shares them, for example an Undo step that holds the pre-removal dataset. Its mesh then stays in the cache until a later keep for that layer or the 128 MiB budget evicts it, even though the doc says nothing can use it again.

Nothing is wrong with the output, since no live layer can match the look. This is memory retention only, and it is bounded. Either reword the doc to say "the mesh is freed once its rows are", or make removal explicit (for example, let_go also drops entries whose instance_id no longer belongs to a live layer, if the caller can supply that).

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.

Right: a mesh goes once its rows do, so rows an Undo step still shares keep it until it is put out within the cap. Output is unaffected and the retention stays within the cap; the doc wording is left for the release quality pass.

self.rows.strong_count() > 0
}
}

/// Whether two time bindings show the same rows: the same field through the same window (what
Expand Down
73 changes: 56 additions & 17 deletions crates/render/examples/vector_layers_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
//! layer of a GeoPackage, and its heaviest layers alone, at 1× and 2× pixel scale, each frame the
//! exact frame drawn once the map rests.
//!
//! `cargo run --release -p rustgis-render --example vector_layers_bench -- map.gpkg`
//! `cargo run --release -p rustgis-render --example vector_layers_bench -- map.gpkg [more files]`
//!
//! - **whole:** the whole map, four times (the first builds its level of detail);
//! - **zoom:** from the whole map to about a metre a point over its centre, 1.5× a step, and back
//! out (the way out finds the levels of detail built on the way in, those still kept);
//! - **pan 10 m / pan 3 m:** west to east across it at 10 and 3 Web Mercator metres a point, a
//! quarter of the view a step, so every frame brings new features in;
//! - **tilt 10 m:** the same pan at 10 m, tilted 60°.
//! - **tilt 10 m:** the same pan at 10 m, tilted 60°;
//! - **restyle:** the top layer's fill colour changed in each of 8 frames of one view, over the
//! whole map and at 10 m a point (#1057), then the same with every layer renamed in each frame
//! too, so that none looks as it did: what each frame drew before a frame kept what still
//! stands (the picture under the changed layer on the CPU, each layer's mesh on the GPU).
//!
//! `BENCH_BACKEND=gpu` times the GPU scene instead (`Backend::Gpu`): what the CPU does for a GPU
//! frame, tessellating the layers the GPU draws and drawing the rest into pictures, not the
Expand Down Expand Up @@ -68,10 +72,11 @@ fn fail(why: impl std::fmt::Display) -> ! {
}

fn main() {
let Some(path) = std::env::args().nth(1) else {
eprintln!("usage: vector_layers_bench map.gpkg");
let paths: Vec<String> = std::env::args().skip(1).collect();
if paths.is_empty() {
eprintln!("usage: vector_layers_bench map.gpkg [more files]");
return;
};
}
// `BENCH_THREADS=1` draws on one thread (the user's thread setting), to compare.
if let Some(n) = std::env::var("BENCH_THREADS").ok().and_then(|n| n.parse().ok())
&& let Err(e) = rustgis_data::threads::set_max(Some(n))
Expand All @@ -89,17 +94,19 @@ fn main() {
}
println!("{} threads, {} backend", rustgis_data::threads::max(), if backend.is_gpu() { "GPU" } else { "CPU" });
let t = std::time::Instant::now();
let file = std::path::Path::new(&path);
let names = match rustgis_data::source::layers(file) {
Ok(n) => n,
Err(e) => fail(format!("{path}: {e}")),
};
// Every table, or no run: "all layers" would time fewer.
// Every table of every file, or no run: "all layers" would time fewer.
let mut read = Vec::new();
for name in names {
match rustgis_data::source::open_path(file, Some(&name)).and_then(|src| rustgis_data::source::materialize(src.as_ref())) {
Ok((d, _)) => read.push(d),
Err(e) => fail(format!("{name}: {e}")),
for path in &paths {
let file = std::path::Path::new(path);
let names = match rustgis_data::source::layers(file) {
Ok(n) => n,
Err(e) => fail(format!("{path}: {e}")),
};
for name in names {
match rustgis_data::source::open_path(file, Some(&name)).and_then(|src| rustgis_data::source::materialize(src.as_ref())) {
Ok((d, _)) => read.push(d),
Err(e) => fail(format!("{name}: {e}")),
}
}
}
println!("read {} layers in {:.1} s", read.len(), t.elapsed().as_secs_f64());
Expand All @@ -122,15 +129,15 @@ fn main() {
if !(extent.min_x.is_finite() && extent.max_x.is_finite() && extent.min_y.is_finite() && extent.max_y.is_finite())
|| (extent.max_x <= extent.min_x && extent.max_y <= extent.min_y)
{
fail(format!("{path}: no features with an extent to fit the views to"));
fail("no features with an extent to fit the views to");
}

let (lo, hi) = (lonlat_to_merc(Coord::new(extent.min_x, extent.min_y)), lonlat_to_merc(Coord::new(extent.max_x, extent.max_y)));
let centre = Coord::new((lo.x + hi.x) / 2.0, (lo.y + hi.y) / 2.0);
// Web Mercator units a pixel showing all of it across 1920 points (a 2× screen shows the same).
let whole = ((hi.x - lo.x) / 1920.0).max((hi.y - lo.y) / 1080.0);
if !(whole.is_finite() && whole > 0.0) {
fail(format!("{path}: an extent that doesn't project to Web Mercator (not longitude/latitude?)"));
fail("an extent that doesn't project to Web Mercator (not longitude/latitude?)");
}
println!(
"extent {:.3},{:.3} to {:.3},{:.3}; whole map at {whole:.1} Mercator m a point",
Expand Down Expand Up @@ -219,6 +226,26 @@ fn main() {
let max = s.last().copied().unwrap_or(0.0);
format!("{:>3} frames, median {median:6.0} ms, slowest {max:6.0} ms, total {:7.0} ms", s.len(), s.iter().sum::<f64>())
};
// The top layer's fill changed in each frame; with `all`, every layer renamed too.
let restyle = |m: &mut Map, cam: Camera, ppp: f64, all: bool| -> Vec<(f64, Drawn)> {
let Some(top) = ids.last().copied() else { return Vec::new() };
(0..8u8)
.map(|i| {
if let Some(l) = m.layer_mut(top) {
let fill = rustgis_map::Rgba::rgb(40 + i * 20, 120, 200 - i * 20);
l.renderer = rustgis_map::Renderer::Single(rustgis_map::Symbol { fill, ..l.symbol(0) });
}
if all {
for id in &ids {
if let Some(l) = m.layer_mut(*id) {
l.name = format!("{} {i}", l.name.trim_end_matches(|c: char| c.is_ascii_digit() || c == ' '));
}
}
}
run_drawn(m, &[cam], ppp).remove(0)
})
.collect()
};
show(&mut m, None);
// `BENCH_ONLY` that names no pixel scale and sequence stops the run, not runs everything.
if let Ok(only) = std::env::var("BENCH_ONLY") {
Expand Down Expand Up @@ -263,6 +290,18 @@ fn main() {
}
}
}
show(&mut m, None);
for ppp in [1.0f64, 2.0] {
for res in [whole, 10.0] {
for all in [false, true] {
let drawn = restyle(&mut m, camera(centre, res), ppp, all);
// The first frame of a view keeps; the next seven take what still stands.
let times: Vec<f64> = drawn.iter().skip(1).map(|d| d.0).collect();
let what = if all { "every layer changed" } else { "the top layer restyled" };
println!("{ppp}x restyle at {res:.1} m, {what}: {}{}", summary(&times), scenes(&drawn));
}
}
}
// The layers a GPU scene draws on the CPU: each alone, over the whole map and at 3 m, flat;
// after the sequences, so it warms no cache they time.
if backend.is_gpu() {
Expand Down
11 changes: 7 additions & 4 deletions crates/render/src/gpu_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ pub enum DrawCmd {
/// Screen-sized premultiplied RGBA, drawn covering the whole map view. The pixmap is
/// moved in, not copied — flushing the CPU accumulator doesn't pay a full-screen `to_vec`.
Image { pixmap: tiny_skia::Pixmap },
/// Tessellated polygon fills and line/ring strokes of one layer run.
Mesh { origin: [f64; 2], vertices: Vec<MeshVertex>, indices: Vec<u32> },
/// Point markers: instances of a small set of unit-space shape templates.
Points { origin: [f64; 2], instances: Vec<PointInstance> },
/// Tessellated polygon fills and line/ring strokes of one layer run. Shared: a layer that looks
/// as it did keeps its mesh from one scene to the next (`layer_meshes`), and the GPU keeps the
/// buffers of a mesh it has uploaded while the mesh lives.
Mesh { origin: [f64; 2], vertices: Arc<Vec<MeshVertex>>, indices: Arc<Vec<u32>> },
/// Point markers: instances of a small set of unit-space shape templates, shared as
/// [`DrawCmd::Mesh`] is.
Points { origin: [f64; 2], instances: Arc<Vec<PointInstance>> },
/// Extruded features standing up in a tilted view: roofs and walls, lit and drawn with a
/// depth buffer (as MapLibre's fill extrusions), or, with `shadows`, the shadows they cast
/// on the ground, drawn under every feature.
Expand Down
Loading
Loading