Repository navigation
perf(render): keep a GPU scene's pictures between scenes of the same view (#1057) - #2633
Conversation
…view (opengeos#1057) A GPU scene for the screen now starts from the frame kept of the last scene of the same view under its first changed layer, as a CPU frame does (frame_cache): the checkpoint holds the scene's commands so far, shared with the scene that made them (the pictures drawn on the CPU and the layers' meshes), and the picture it was drawing then. A picture drawn again with the same pixels is that same picture, and the GPU map keeps the texture of a picture it has uploaded by its address while a scene draws it, so the pictures under a restyled layer are neither drawn nor uploaded again. On a map with no blended layer, the first two see-through layers of a scene are pictures of their own, which the GPU places at the layer's opacity (a uniform of the image pipeline). A transparency change alone places the layer kept alone again at its new opacity: nothing is drawn or uploaded. The CPU fallback for scenes of many pictures counts them as before, as though those layers were composited. The kept pictures stay within frame_cache's budget, now counting the pictures and tiles a GPU checkpoint's commands hold, and the meshes they hold within the kept meshes' budget again. vector_layers_bench takes BENCH_RASTER (a raster under the layers), a transparency sequence, and BENCH_ONLY=restyle.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
|
||
| /// Its commands, shared again for a scene starting from it. | ||
| pub(crate) fn cmds(&self) -> Vec<DrawCmd> { | ||
| self.cmds.iter().filter_map(DrawCmd::share).collect() |
There was a problem hiding this comment.
Low confidence, robustness: filter_map(DrawCmd::share) drops any command whose share() returns None without a notice. Today that can't happen, because GpuPart::of refuses checkpoints holding an Extrusion. But if a later change lets one through, a restored scene silently loses a mesh or picture, and that breaks the "never silent" rule.
Suggested direction: make cmds() return Option<Vec<DrawCmd>> (collect with .collect::<Option<_>>()), and have the caller fall back to drawing from nothing when it is None. That turns a silent visual loss into a plain cache miss.
There was a problem hiding this comment.
Not reachable today: GpuPart::of refuses a checkpoint holding anything share() can't share, so every command it keeps comes back. Returning Option and missing the cache instead is left for the release quality pass.
Code reviewI read the full diff (1,510 lines), the PR metadata, and Bugs
Security
Performance
Quality
AGENTS.md
Inline comments posted
Change sizeCompared: the whole PR against main (merge base 1e94919 to PR head 1bcd9b4).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
Summary
The last part of #1057 step 2 on the GPU backend. Layers a GPU scene draws as pictures on the CPU (rasters read into memory, see-through or blended layers, layers too dense to mesh) are kept between scenes of the same view, and a transparency change doesn't draw its layer again.
Kept pictures.
frame_cachenow serves GPU scenes too. A checkpoint holds the scene's commands up to the layer (GpuPart, sharing their data byArc) and the CPU picture it was drawing then. A scene started from it draws only from that layer up, the same scene, command for command and pixel for pixel, as one drawn whole (tested). A picture drawn again with the same pixels is swapped for the kept one, so its texture is reused.mapgpukeeps picture textures by address, weakly on both sides, as it keeps mesh buffers (#2628).Opacity on the GPU. On a map with no blended layer or tile layer, the first two see-through layers of a scene are pictures of their own, placed by the GPU at the layer's opacity (a uniform of the image pipeline): opacity still applies to the finished layer picture. A transparency change alone (
Change::Transparency) places the kept layer again at its new opacity: nothing is drawn or uploaded. A blended layer reads the picture under it, so on such a map see-through layers are composited on the CPU as before, and a transparency change still composites the kept layer rather than drawing it. The CPU fallback for scenes of many pictures counts as before, as though those layers were composited (Runs), so the same scenes stay on the GPU.What still draws again. As on the CPU, the layers above the first changed one are drawn again, and the first step of a transparency drag keeps the layer alone for the next steps. Keeping every picture run by itself would mean keying each run's incoming state too (marker sprites, shapeburst budget, labels, tiles): a separate cache, not this one. Pans and zooms are left to #635 and #2541.
Memory
The kept pictures stay within
frame_cache's budget, unchanged at 2 × 3840 × 2160 pixels (66 MB, plus the marker sprites): a GPU checkpoint now also counts the pictures and raster tiles its commands hold (each shared one once), though it shares them with the scene on screen. That is up to eight pictures of a 1920 × 1080 view in all. The meshes the kept commands hold count again against the kept meshes' budget (128 MiB, 32 MiB in the browser); past it, the older view goes, then this one. A picture is of the view, so none of this grows with a layer's rows. On the GPU, the textures are those of the scenes on screen: none beside them; a see-through layer drawn alone adds one view-sized texture, at most two a scene.cargo xtask memorydoesn't move: its workflows export, and exports keep nothing.Benchmark
vector_layers_benchgainsBENCH_RASTER(a raster read into memory, under the layers), a transparency sequence andBENCH_ONLY=restyle.BENCH_BACKEND=gpu, Shelby County, TN: the USGS 1 arc-second elevation model under buildings, census blocks, block groups and the county outline (338,786 features), 1920 × 1080 points, median of the 7 frames after the first. Before is main (#2628)."Every layer changed" renames every layer in each frame, so none looks as it did: it keeps nothing either way and moves only with the noise of the run. This times the CPU's part of a GPU scene, not the upload, which the kept textures save as well.
Testing
cargo test -p rustgis-render: all pass. Newframe_cachetests draw each GPU scene twice, as it comes and from nothing, and require the same commands: a restyle above a raster takes the raster's picture from the last scene (sameArc); a transparency drag places the same layer picture at each new opacity; a restyle draws it again; a blended layer, or a see-through layer under one, is composited into the picture under it; CPU and GPU frames of the same view keep apart.runs_count_the_pictures_of_a_scene_without_layers_alonechecks the fallback count; the existing fallback test still sends five alternating pictures to the CPU. Thelayer_meshestests clear the kept pictures, to test meshes alone.cargo test -p rustgis-ui-egui --lib mapgpu: all pass on a headless adapter, the CPU/GPU parity of a see-through layer among them. The upload test checks a picture shared with the last scene draws from the same texture, at another opacity too, and a new one is uploaded.cargo clippy -p rustgis-render -p rustgis-ui-egui --all-targets -D warnings;cargo check -p rustgis-render -p rustgis-ui-egui --target wasm32-unknown-unknownwith warnings as errors;cargo fmt --check. The full gate on CI.Reach: the map view on the GPU backend, on the desktop and in the browser; the phone's map is the same view. The command line, Python and exports draw on the CPU, which this doesn't change. Nothing saved, undoable or visible changes beyond speed.
UI evidence
No visible UI change.
Related issue
Part of #1057 (step 2, GPU renderer). With this, each item of step 2 has landed; what still draws again is said above.
Summary by CodeRabbit