Skip to content

perf(render): keep a GPU scene's pictures between scenes of the same view (#1057) - #2633

Merged
Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/gpu-scene-pictures
Nov 22, 2026
Merged

Mavrick-F merged 1 commit into
opengeos:mainfrom
Mavrick-F:perf/gpu-scene-pictures

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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.

 render_frame (a GPU scene for the screen)
-  frame_cache off: draw every picture, upload every picture
+  start from the frame kept under the first changed layer, as a CPU frame does:
+    the scene's commands so far (pictures and meshes, shared) and the picture it was drawing
 SceneBuffers::from_scene
-  a new texture for every picture
+  the texture already uploaded for a picture it drew before (by address)

Kept pictures. frame_cache now serves GPU scenes too. A checkpoint holds the scene's commands up to the layer (GpuPart, sharing their data by Arc) 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. mapgpu keeps 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 memory doesn't move: its workflows export, and exports keep nothing.

Benchmark

vector_layers_bench gains BENCH_RASTER (a raster read into memory, under the layers), a transparency sequence and BENCH_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).

view top layer's fill top layer's transparency every layer changed
whole county, 1× 532 → 37 ms 453 → 1 ms 657 → 361 ms
10 m a point, 1× 303 → 22 ms 338 → 1 ms 331 → 280 ms
whole county, 2× 1924 → 76 ms 2215 → 110 ms 2332 → 2207 ms
10 m a point, 2× 559 → 33 ms 545 → 39 ms 461 → 553 ms

"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. New frame_cache tests 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 (same Arc); 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_alone checks the fallback count; the existing fallback test still sends five alternating pictures to the CPU. The layer_meshes tests 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-unknown with 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

  • Improvements
    • GPU rendering can reuse cached scene content, helping reduce repeated rendering work when layers change.
    • Eligible see-through layers can be rendered separately with adjustable opacity, while other blend modes continue to be composited.
    • Cached rendering now accounts for memory budgets and falls back to CPU rendering when GPU scene complexity exceeds supported limits.

…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.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

GPU frame caching now retains reusable GPU commands and pictures. The renderer can draw eligible see-through layers as separate images with opacity. The benchmark adds raster input and restyle-only scenarios.

Changes: GPU frame reuse

Layer / File(s) Summary
Shared image commands and GPU textures
crates/render/src/gpu_scene.rs, crates/ui-egui/src/mapgpu.rs, crates/ui-egui/src/mapgpu.wgsl
Image commands now use shared pixmaps and carry opacity. The GPU renderer reuses textures for live pixmaps and applies opacity when drawing images.
GPU checkpoint data and budgets
crates/render/src/frame_cache.rs
Frame cache entries distinguish CPU and GPU frames and whether standalone layer pictures are retained. Checkpoints can hold shared GPU commands and pictures. The cache counts shared picture allocations and enforces a mesh-byte budget.
Standalone layers and cached GPU rendering
crates/render/src/lib.rs, crates/render/src/tiles.rs, crates/render/src/frame_cache.rs, crates/render/src/layer_meshes.rs
The renderer tracks image runs and can emit eligible see-through layers as separate pictures. It restores and captures GPU checkpoints, and falls back to CPU rendering when the run count exceeds four. Tests cover checkpoint reuse, opacity changes, blending, and run counts.
Raster and restyle benchmark scenarios
crates/render/examples/vector_layers_bench.rs
The benchmark can add a raster beneath vector layers and run restyle-only scenarios for fill changes, transparency changes, and changes to all layers.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Renderer as GPU renderer
  participant FrameCache
  participant SceneBuffers
  participant PictureTextures
  participant Shader as Image shader
  Renderer->>FrameCache: Restore cached commands and pictures
  FrameCache->>Renderer: Return checkpoint state
  Renderer->>SceneBuffers: Build draws from image commands
  SceneBuffers->>PictureTextures: Reuse or upload pixmap texture
  SceneBuffers->>Shader: Bind texture and opacity
Loading

Possibly related issues

  • opengeos/RustGIS#2541 — This PR retains GPU scene data between frames, but does not add the issue’s proposed multi-thread tessellation.
  • opengeos/RustGIS#1057 — The PR reuses retained pictures at updated opacity and retains GPU meshes and images, covering part of the issue’s requested behavior.
  • opengeos/RustGIS#1051 — The PR supports changing a layer’s transparency without redrawing its retained picture in the described GPU rendering path.

Possibly related PRs

  • opengeos/RustGIS#2628 — This PR adds a retained-mesh budget for GPU scenes, and the current PR counts checkpoint meshes against a kept-mesh budget.

Suggested reviewers: giswqs, sheecegardezi, pick2510

Merge Risk: Minimal · up to 1bcd9

This change lets GPU map redraws resume from cached pictures and apply layer transparency changes without re-rendering or re-uploading them. The reviewed code shows no concrete defect in the checkpoint reuse, texture caching or budget handling. The CPU rendering paths are unchanged. The change looks ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf(render): keep a GPU scene's pictures between scenes of the same view (#1057)" matches the main change. The changeset adds GPU scene support to frame_cache, keeps CPU-rendered pictures …
Description check Passed The description follows the template sections (Summary, Testing, UI evidence, Related issue). The Summary explains the change, the kept pictures, the opacity handling, the memory budget, and a benchma…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf(render): keep a GPU scene's pictures between scenes of the same view (#1057)" matches the main change. The changeset adds GPU scene support to frame_cache, keeps CPU-rendered pictures and commands as checkpoints, and reuses textures in mapgpu. The title uses a conventional-commit prefix and gives the primary change. It omits the opacity-on-GPU and benchmark parts, which is acceptable for a title.

Full details: Description check

Explanation

The description follows the template sections (Summary, Testing, UI evidence, Related issue). The Summary explains the change, the kept pictures, the opacity handling, the memory budget, and a benchmark. Testing lists the cargo test, clippy, wasm check, and fmt runs. The UI evidence section states 'No visible UI change.' as the template allows. The Related issue section cites #1057 step 2. The Testing section gives commands and test names, which is enough to verify the change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit watched the layers glow,
As shared pictures stayed in tow.
A gentle fade, a raster below,
The cached scenes were set to flow.
“Hop, render, and restyle!” said so.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c83e97ac-bd36-48a5-b43b-0fe74ad0c8ea
Commits

Reviewing files that changed from the base of the PR and between 87dabf1 and 1bcd9b4.

Files selected for processing: 8

  • crates/render/examples/vector_layers_bench.rs
  • crates/render/src/frame_cache.rs
  • crates/render/src/gpu_scene.rs
  • crates/render/src/layer_meshes.rs
  • crates/render/src/lib.rs
  • crates/render/src/tiles.rs
  • crates/ui-egui/src/mapgpu.rs
  • crates/ui-egui/src/mapgpu.wgsl

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


/// 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()

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.

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.

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.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff (1,510 lines), the PR metadata, and AGENTS.md. There are no prior review threads, so nothing was left out as already raised. I traced the new GPU checkpoint and picture-placement logic in render_frame against the existing layer paths, the cache planning, the mapgpu texture cache, and the bench and test helpers. I found no correctness bugs. The new paths are gated so that see-through layers only become pictures when no blend or tile layer reads what is underneath, and the CPU fallback counts stay consistent with the old behaviour.

Bugs

  • None found.

Security

  • None found. The change does no I/O and takes no external input beyond the existing raster read in the bench, which uses the existing fail path.

Performance

  • None raised. Checkpoints on a pan capture at index 0, where the accumulator is usually empty, so they add no full-screen clone there. The new per-keep mesh_bytes and pixels sums are O(commands) and fine.

Quality

  • Duplicate share helpers (confidence high): layer_meshes::share (crates/render/src/layer_meshes.rs:124) still exists and is still used at lines 217 and 238. It now duplicates the new DrawCmd::share (gpu_scene.rs) for Mesh and Points. Consider one helper, or having layer_meshes filter on DrawCmd::share. This is a refactor point, so it can wait for the release quality pass.
  • Nits, also for the quality pass: the frame_cache.rs Kept::pixels doc says "a scene's command shares the layer alone", where it should say "commands share". The GPU_ALONE doc comment has an overlong line.

AGENTS.md

  • The unwrap, expect and panic! calls added in the diff are all inside test code, so the no-crash rule holds.
  • No new command or export is added, so the long_commands lists don't need updating. The PR's reach and memory notes are present.
  • Nothing else in AGENTS.md looks broken. I did not build or run the tests, so the PR's reported results stand unverified here.

Inline comments posted

  • crates/render/src/frame_cache.rs:176 (low confidence, robustness): GpuPart::cmds uses filter_map(DrawCmd::share), which silently drops a command if share() ever returns None. That can't happen today, because GpuPart::of refuses extrusions. Suggested direction: return Option and fall back to a cache miss.

Change size

Compared: the whole PR against main (merge base 1e94919 to PR head 1bcd9b4).

Measure Value
Files changed 8 (0 added, 8 modified, 0 removed, 0 renamed)
Size before 1.06 MB
Size after 1.09 MB
Total size change +30.3 KB
Path Before After Change
crates/render/src/frame_cache.rs 30.5 KB 44.1 KB +13.6 KB
crates/render/src/lib.rs 759.4 KB 769.3 KB +9.8 KB
crates/ui-egui/src/mapgpu.rs 128.4 KB 132.3 KB +4.0 KB
crates/render/src/gpu_scene.rs 12.3 KB 13.9 KB +1.6 KB
crates/render/examples/vector_layers_bench.rs 16.3 KB 17.8 KB +1.5 KB
crates/ui-egui/src/mapgpu.wgsl 12.9 KB 13.1 KB +168 B
crates/render/src/layer_meshes.rs 25.6 KB 25.8 KB +163 B
crates/render/src/tiles.rs 98.3 KB 98.4 KB +147 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2633/
Web app https://preview.rustgis.app/pr-2633/app/
Commit 1bcd9b4

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 preview label (once per commit).

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 22, 2026
Merged via the queue into opengeos:main with commit a14f5b6 Nov 22, 2026
25 checks passed
@Mavrick-F
Mavrick-F deleted the perf/gpu-scene-pictures branch November 22, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant