Repository navigation
Draw circle, polygon and polyline tiles on the GPU - #41
Merged
Merged
Conversation
A circle tile went through CGContext once per circle, and each circle of a large set was read back from the geometry file as a new Shape (about 6 µs each). On US Antenna Horizons (723,800 circles) a zoomed-out tile took up to 2 s. MetalShapeRasterizer draws every circle of a tile as one instance (fill and outline by distance, 1 px antialiasing, source-over in the given order) and reads the pixels back for the Rust PNG encoder, like MetalMarkerRasterizer. The circles are read as plain values from the geometry file, and colours are converted once per palette entry. A tile with a circle bent by the projection (drawn as the 128-gon) stays on the CPU, as do tiles without Metal or with MAPCONDUCTOR_SHAPE_TILE_CPU=1.
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shape tiles (circles, polygons, polylines) are drawn with Metal instead of CGContext. Without Metal, or with
MAPCONDUCTOR_SHAPE_TILE_CPU=1(for comparison), they are drawn on the CPU as before.Circles:
MetalShapeRasterizerCircleGeometryFile(ShapeTileStorage.circleValues). Before, each circle was rebuilt as aShape, which took about 6 µs. Colours are converted to premultiplied RGBA once per palette entry.Polygons and polylines:
MetalPathRasterizerstrokePath.Both
ShapeTileRendereris made. This takes 0.4 s on an iPad Pro 11, and the first tiles used to wait for it.Measurements
iPad Pro 11 (2018), sample app on MapLibre, built with
-O. Times are per-tile draw time for the tiles of the first view, GPU vs CPU (MAPCONDUCTOR_SHAPE_TILE_CPU=1):On the largest tiles, building the vertices on the CPU (100 to 250 ms) now takes longer than the GPU draw (about 50 ms).
Checks
MetalShapeRasterizerTests(circles) andMetalPathRasterizerTests(polygons and polylines) draw the same tile on the GPU and on the CPU and compare the pixels. They cover:PolygonTileRendererTests.testOutlineIsLeftOutUnderFourPixelsnow counts drawn pixels rather than pixels above 128 blue. A 1 px outline on a pixel boundary is drawn at half strength in two columns: 128/128 on the GPU, 127/129 on the CPU. The old threshold only passed on the CPU by that rounding.