Skip to content

Draw circle tiles on the GPU - #44

Merged
wf9a5m75 merged 5 commits into
developfrom
feat/gpu-shape-tiles
Nov 13, 2026
Merged

wf9a5m75 merged 5 commits into
developfrom
feat/gpu-shape-tiles

Conversation

@wf9a5m75

Copy link
Copy Markdown
Contributor

Summary

Circle tiles are drawn with OpenGL ES 3.0 off screen instead of on a Canvas. Polygon and polyline tiles stay on the Canvas by default (see Measurements). Without GLES 3, or when ShapeTileRenderer.useGpu is false, everything is drawn on the Canvas as before.

This is the Android counterpart of MapConductor/ios-sdk-core#41.

GlShapeScene

What a tile draws, as plain float arrays. It does not touch GL, so it can be built and checked on the JVM.

  • Circles: one instance each. The fill and the outline are computed from the distance to the centre.
  • Polygons: a nonzero fill by stencil-then-cover. The outline is segment quads plus vertex discs, written to the stencil and covered once.
  • Polylines: each line gets its own depth, nearer for each later line, drawn with GL_LESS. A line's own overlapping triangles paint once, later lines pass over earlier ones, and the whole tile is a single draw call. GLES has no stencil export, so this replaces the stencil numbers iOS uses.

GlShapeRasterizer

  • A pool of four EGL contexts, each with its own programs and targets. Tiles are drawn in parallel on the tile server's threads.
  • 4x MSAA with a resolve blit, then glReadPixels. The pixels go straight to the Rust PNG encoder (TilePngEncoder.encode(buffer, premultiplied = true)).
  • The contexts and shaders are made in the background when the first GPU-capable ShapeTileRenderer is created.

Circles from the geometry file

CircleTilePainter.recordAll reads a nationwide set's records straight from CircleTileFileStorage (forEachRecord) instead of decoding a TileCircle per circle, which took about 3.5 µs each.

  • Each block is copied out under the file lock and read outside it, so tiles on other threads do not wait.
  • The callback takes primitives, so nothing is boxed per circle.
  • A circle bent by the projection (drawn as its 128-gon) switches the tile to the batched scene.

Switches

  • ShapeTileRenderer.useGpu = false: everything on the Canvas.
  • ShapeTileRenderer.gpuPolygonsAndLines = true: polygons and polylines on the GPU too. It is off by default.

Measurements

Example app on MapLibre, the tiles of the first view, GPU vs Canvas. Times are median / max / total.

Pixel 5a

page GPU Canvas
US Antenna Horizons (723,800 circles) 914 / 2,840 / 8,145 ms 1,315 / 6,103 / 15,133 ms
Boston Roads (polylines) 180 / 1,190 / 2,871 ms 160 / 1,232 / 2,601 ms
Boston parcels (polygons) 101 / 1,877 / 4,403 ms 101 / 1,196 / 2,569 ms
Boston buildings (polygons) 134 / 2,223 / 4,752 ms 84 / 606 / 1,798 ms

Lenovo TB520FU

page GPU Canvas
US Antenna Horizons 233 / 1,277 / 3,721 ms 329 / 3,400 / 8,442 ms
Boston Roads 28 / 413 / 1,099 ms 20 / 393 / 922 ms
Boston parcels 21 / 642 / 1,622 ms 19 / 377 / 1,071 ms
Boston buildings 21 / 720 / 1,614 ms 18 / 276 / 851 ms

Circles are about 2x faster, with the slowest tile 2.1 to 2.7x faster. Polylines are about even. Polygons are slower on the GPU, because neighbouring parcels' boxes overlap, so a big tile splits into thousands of small batches. That is why polygons and polylines stay on the Canvas for now.

Tests

New ShapeTileGpuDeviceTest (8 tests) draws the same tile on the GPU and on the Canvas and compares the pixels. It turns gpuPolygonsAndLines on, so all three paths are covered. The cases are:

  • holes;
  • translucent polygons stacking in order;
  • a translucent line crossing itself, painted once;
  • 600 lines on Retina tiles;
  • city circles;
  • zoomed-out circle dots;
  • circles drawn as their 128-gon;
  • 30,000 file-backed circles at three zooms.

The existing shape tile device tests (CircleTileRendererDeviceTest, CircleTileFileDeviceTest, PolygonTileRendererDeviceTest, PolylineTileRendererDeviceTest) now run circles on the GPU path.

All 45 device tests pass on a Lenovo TB520FU, and the unit tests pass.

On a Pixel 5a and a Lenovo TB520FU, Skia drew polygon and polyline tiles as fast or faster than the GPU path, while circle tiles were twice as fast on the GPU. ShapeTileRenderer.gpuPolygonsAndLines turns their GPU path on; the comparison tests do.
@wf9a5m75
wf9a5m75 merged commit cbcc1c5 into develop Nov 13, 2026
2 checks passed
@wf9a5m75
wf9a5m75 deleted the feat/gpu-shape-tiles branch November 13, 2026 04:34
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