perf(render): tessellate a GPU scene's layers on several threads

Open
#2,541 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start by reading the GPU branch in crates/render/src/lib.rs, then inspect mesh::collect_layer in crates/render/src/mesh.rs and the threaded mesh building in tile_mesh.rs. Check AGENTS.md for the threading guidance and use the vector_layers_bench command in the issue to establish the GPU baseline. Done means the one-thread and multi-thread scenes match, the vertex-room fallback matches, and the GPU benchmark sequences improve.

Written by the indexing model from the issue text.

Description

enhancement

With the GPU backend on (the status bar's CPU/GPU switch, or RUSTGIS_GPU), each full redraw tessellates every layer's geometry into meshes on one thread. Zoomed out, that makes a GPU redraw slower than drawing the frame on the CPU.

Measured

vector_layers_bench (#2525, with BENCH_BACKEND=gpu, #2539) on swisstopo's swiss-map-vector25, one map sheet (66 layers, 335,000 features, 3.0 million vertices). This is the CPU side of a GPU frame (the scene render_backend(.., Backend::Gpu) builds), not the device's upload and draw. Median frame, one build, CPU backend drawing in bands on 16 threads:

Sequence CPU 1× GPU 1× CPU 2× GPU 2×
whole sheet 336 ms 322 ms 828 ms 613 ms
zoom 166 ms 250 ms 293 ms 278 ms
pan 10 m 120 ms 211 ms 293 ms 283 ms
pan 3 m 54 ms 38 ms 158 ms 49 ms

The GPU wins zoomed in and at 2×: its cost doesn't grow with the pixels. Zoomed out at 1× it is up to 75% slower. A zoomed-out scene holds 3.2–4.9 million vertices (about 130–195 MB at 40 bytes a vertex).

While the map moves, the app moves the last scene's meshes without building anything (the camera fast path). These numbers are the redraw when it stops, or when the view leaves the meshes' reach.

Where

render_frame's GPU branch (crates/render/src/lib.rs, mesh::collect_layer for each layer) and crates/render/src/mesh.rs. Each layer's tessellation is independent of the others. Vector tiles already build their meshes on several threads (tile_mesh.rs).

Proposal

Tessellate the layers, or a big layer's features in chunks, on rustgis_data::threads::max() threads (AGENTS.md "Use the threads"):

  • the same scene as one thread, command for command, in layer order;
  • the layer's vertex room (MAX_LAYER_VERTICES) decided as one thread decides it;
  • one thread below a size threshold and in the browser;
  • scratch within memory::thread_scratch;
  • a thread the system refuses costs speed only.

The CPU parts of the scene (layers drawn as pictures) stay where they are in the order.

Keeping a layer's meshes between redraws is #1057's step 2.4, and goes with it.

Tests

  • A scene built on 1 and several threads is the same.
  • A layer over its vertex room falls back as on one thread.
  • The benchmark's GPU sequences before and after.

Related

  • The benchmark's GPU option is merged (#2539): BENCH_BACKEND=gpu cargo run --release -p rustgis-render --example vector_layers_bench -- map.gpkg.
  • #2540's second step decides before tessellating whether a layer is worth a mesh (features in view and their size on screen) instead of after MAX_LAYER_VERTICES is reached. That takes the biggest zoomed-out layers out of tessellation altogether, so it comes before this and changes what is left to split; measure again after it.
  • Keeping a layer's meshes between redraws is #1057's step 2.4 (measurements posted there).
Dominant language
Rust
Stars
1.9k
Forks
268
Avg merge
11h 1m
Merged PRs (30d)
942

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opengeos/RustGIS

All issues in opengeos/RustGIS

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.