ORIXAtlas
Prototype of the ORIX Atlas Engine, the future proprietary Metal map renderer of ORIX Maps. It is not a complete
engine and is not linked into the application. It draws the fills and lines of real vector tiles (no text, no icons,
no 3D, no interaction) into an offscreen texture, from pieces that are each unit-tested. The specification, the status
of every subsystem and the gap list against MapLibre are in docs/ATLAS_ENGINE.md.
Depends on ORIXGeoCore, ORIXTileStore (PMTiles reader, vector tile decoder, LRU cache) and ORIXMapStyle (themes).
System frameworks: Metal, CoreGraphics, simd. No third-party code.
Public API
| Type | Role |
|---|---|
AtlasCamera |
Centre, fractional zoom (512-point tiles), bearing, pitch: the semantics of MapCamera. normalized, projection(viewport:). |
AtlasProjection |
A camera bound to a viewport: viewProjection (doubles), point(for:), coordinate(at:), worldPoint(at:), groundQuad, visibleBounds, tileMatrix(for:wrap:), tileUnitsPerPoint(tileZoom:). |
TileCover |
tileZoom(forZoom:minZoom:maxZoom:), tiles(for:tileZoom:limit:) → [CoveredTile] (tile + world copy), centre-out, capped. |
TileFallback, TileClip, TileDrawItem |
Replacement of tiles that are not ready by ready children and clipped ancestors. |
Triangulator |
Ear clipping with holes on exact integer arithmetic; Diagnostics for invalid input. |
LineTessellator, LineMesh, LineVertex, LineJoin, LineCap |
Polylines → triangles; width-independent geometry (position + extrusion). |
AtlasLayer, AtlasStyle, AtlasStyleTable |
Layer model mirrored from StyleBuilder; per-frame table of colour / opacity / width from a MapTheme and a zoom. |
TileMeshBuilder, TileMesh, AtlasVertex |
Decoded VectorTile → one vertex buffer + one index buffer + ordered draw segments. |
AtlasRenderer (actor) |
render(camera:size:scale:) -> CGImage, renderBitmap(...) -> AtlasBitmap, setTheme, lastFrame, cachedMeshBytes, corruptTileCount, purge(). |
let store = TileStore(archive: try PMTilesArchive(url: montrealURL))
let renderer = try await AtlasRenderer(store: store, theme: BuiltInThemes.day)
let image = try await renderer.render(camera: AtlasCamera(center: downtown, zoom: 14, bearing: 30, pitch: 45),
size: CGSize(width: 393, height: 852), scale: 3)Design choices worth knowing
- Per-draw style, not per-vertex colour. A vertex carries a 16-bit layer index; colour, opacity, visibility and line
width are read by the vertex shader from a 128-row table rebuilt each frame from the theme and the fractional zoom.
A mesh therefore depends neither on the theme nor on the zoom: switching theme or zooming rebuilds nothing (tested:
eight themes rendered from the same cached meshes,
tilesBuilt == 0).TileMeshBuilder.buildconsequently takes noMapTheme, which deviates from the letter of the brief. - Line width in the shader. Line vertices are
position + extrusion × halfWidth; the half width in tile units ispoints × tileUnitsPerPoint / 2, so a width in points stays exact at every fractional zoom and over the change of tile zoom (tested to the pixel on a synthetic tile, zoom 12 to 17.2, flat and pitched at the view centre). - One vertex format (12 bytes), one pipeline. Fills are lines with a zero extrusion. A tile is one vertex buffer, one index buffer, and at most 7 indexed draws (fills, then casing and base pass for tunnels, roads, bridges).
- Clipping with
clip_distance. Each draw is clipped to the square of the tile it stands for (or to the part of an ancestor), in the vertex stage, without stencil and withoutdiscard. Neighbours never overlap, so translucent layers are never blended twice at tile borders. - Antialiasing: 4× MSAA on the offscreen target, resolved into a shared-storage BGRA8 texture. Lines thinner than one pixel are drawn one pixel wide with proportionally reduced alpha. No analytic (distance-based) edge antialiasing: at 1× scale line edges show the five coverage levels of 4× MSAA.
- Colours are blended in sRGB-encoded space (
bgra8Unorm, no linearization), as MapLibre does, so opaque pixels have exactly the theme's bytes.
Shader
Sources/ORIXAtlas/Shaders/Atlas.metal is shipped as a text resource (.copy) and compiled at run time with
MTLDevice.makeLibrary(source:). Reason: swift build / swift test do not run the Metal compiler on .metal
sources (only Xcode's build system produces default.metallib), and the prototype must be verified from the command
line. Measured cost: 4.8 ms for the first renderer of a process, 0.2–0.3 ms afterwards (the system shader cache may
already have been warm; a truly cold cache was not measured). A product build should precompile a .metallib.
Tests
cd Packages/ORIXAtlas
swift test # 72 tests run, 4 benchmark tests skipped
ORIX_ATLAS_BENCH=1 swift test -c release --filter BenchmarksResult on 2026-11-25 (Apple M5 Max, macOS 27.0, Swift 6.4.2): 76 tests in 10 suites, 72 passed, 4 skipped
(benchmarks, opt-in), 0 failed, 7.8 s in debug. Tests that need data/build/montreal.pmtiles are disabled by
.enabled(if: TestData.hasMontreal) (9 of the 72, plus the 4 benchmarks); tests needing Metal by .enabled(if: AtlasRenderer.isMetalAvailable).
The skip path with the Montréal file absent is by construction and was not exercised (the file was present).
What the tests establish:
- Camera: centre ↔ view centre,
coordinate(at:)/point(for:)round trip under 1e-5 point for zoom 6.5–20, bearing 0–359, pitch 0–60; bearing and pitch directions; world wrap; nil beyond the poles; float tile matrix within 0.05 point of the double projection for a z15 tile at zoom 20, pitch 55. - Tile cover: zoom 0, world copies, antimeridian, pole clamp, every visible ground point covered (flat, rotated, pitched), centre-out order, cap; fallback to clipped ancestors and ready children.
- Triangulation: exact area and no triangle outside on hand-made and 400 random simple polygons (with holes); degenerate, self-touching, self-intersecting, extreme-coordinate and 1 500 random garbage inputs never trap and stay in range; a 20 000-point random ring finishes (7.5 s in debug). On real Montréal data: 128 170 polygons of the buildings, landuse, water and earth layers of 146 tiles, 128 170 triangulated with exactly the polygon's area, no diagnostic.
- Lines: quad, miter, miter limit → bevel, round joins and caps, closed rings, degenerate input, area and distance properties.
- Mesh: layer order, segments, vertex layout (12 bytes), extent normalization, coordinate clamping, 600 byte-flipped copies of a real tile never trap.
- Renderer (pixels): water, land and motorway colours at known Montréal coordinates at zoom 10, 12, 13.5 and 15;
the same places found at
point(for:)in rotated and pitched frames (GPU matrix = CPU conversions); land / water of the world map, antimeridian, three world copies at zoom 0; no seam on uniform land across a tile border (flat, rotated, pitched); line and casing width to the pixel; hairline coverage; clipping of buffer geometry; corrupt tile counted once and replaced by its parent; cache hit renders an identical frame; 2 MB cache budget holds.
PNG files are written to Artifacts/ (git-ignored) by the renderer tests: montreal-z10-day, -z12-day, -z14-day,
-z16-day, -z17.5-overzoom-day, -z15.5-bearing30-pitch60-day, -z12.5-bearing300-pitch45-day, montreal-z12.3-
{day,midnight,terrain,minimal,transit,topographic,explorer,highcontrast}, montreal-archive-toronto-z11-fallback,
world-z1.6-day, world-z1.6-bare, world-antimeridian-z3.2, world-z0-copies (20 files).
Measurements
Mac numbers only: Apple M5 Max (18 cores, 48 GB), macOS 27.0, release build, 2026-11-25. Nothing was measured on an iPhone, where CPU, GPU, memory bandwidth and thermal limits are different; do not extrapolate.
Command: ORIX_ATLAS_BENCH=1 swift test -c release --filter Benchmarks (one run; timings vary by a few percent
between runs). Tile set: the tiles of zoom 12–15 covering 45.47–45.56° N, 73.66–73.50° W (downtown Montréal, Mount
Royal, the river), at most 64 per zoom evenly spaced: 146 tiles (TestData.benchmarkTiles()).
Mesh build per tile (single thread, best of 3 per tile)
| Zoom | Tiles | Decode p50 / p95 (ms) | Mesh build p50 / p95 (ms) | Vertices p50 / max | Indices p50 / max | Buffer bytes p50 / max |
|---|---|---|---|---|---|---|
| 12 | 6 | 0.65 / 0.75 | 1.74 / 2.54 | 45 823 / 62 590 | 116 751 / 162 984 | 1 016 880 / 1 403 016 |
| 13 | 20 | 0.42 / 0.64 | 1.33 / 2.25 | 42 737 / 78 782 | 107 556 / 203 679 | 943 068 / 1 760 100 |
| 14 | 56 | 0.45 / 0.64 | 1.60 / 3.37 | 44 592 / 80 289 | 118 737 / 225 024 | 1 006 512 / 1 863 564 |
| 15 | 64 | 0.95 / 2.00 | 0.78 / 1.38 | 22 811 / 44 491 | 58 233 / 117 699 | 507 000 / 1 004 688 |
| all | 146 | 0.51 / 1.79 | 1.11 / 2.74 |
"Decode" is VectorTile(data:) on already inflated bytes (ORIXTileStore); "mesh build" is TileMeshBuilder.build
(triangulation + line tessellation + buffer assembly, building outlines included).
Triangulation alone (best of 5)
| Rings | Polygons | Ring points | Largest polygon | Triangles | Time | Throughput |
|---|---|---|---|---|---|---|
| buildings | 104 180 | 1 225 486 | 272 points | 910 351 | 71.7 ms | 12.7 M triangles/s |
| landuse | 22 975 | 288 527 | 911 points | 219 836 | 19.5 ms | 11.3 M triangles/s |
These rings are small (the tile builder already cuts and simplifies them); the largest in the set has 911 points, so the numbers say nothing about the behaviour on rings of tens of thousands of points.
Offscreen frame, 1179 × 2556 px (393 × 852 pt at 3×), 4× MSAA, ORIX Day
Cold = new archive mapping, empty decoded-tile cache, empty mesh cache, first frame (tile read + inflate + decode + mesh build on the task pool + upload + texture allocation + draw + read-back; shader compilation excluded, see above). Warm = 60 further frames of the same camera from cached meshes.
| Camera | Tiles | Draw calls | Triangles | Cold (ms) | of which tiles (ms) | Warm p50 / p95 (ms) | Encode p50 | GPU p50 | Read-back p50 | Mesh cache |
|---|---|---|---|---|---|---|---|---|---|---|
| z10 | 6 | 18 | 209 471 | 22.1 | 8.1 | 4.30 / 5.53 | 0.07 | 0.60 | 3.03 | 4.28 MB |
| z12 | 6 | 40 | 290 401 | 27.1 | 11.6 | 4.90 / 6.37 | 0.06 | 0.61 | 3.60 | 5.53 MB |
| z12.9 | 4 | 28 | 226 526 | 15.8 | 5.2 | 3.59 / 3.86 | 0.03 | 0.47 | 2.55 | 4.27 MB |
| z14 | 6 | 42 | 318 316 | 18.4 | 6.7 | 4.12 / 4.30 | 0.03 | 0.58 | 2.98 | 6.66 MB |
| z16 (z15 tiles) | 2 | 14 | 55 960 | 13.1 | 3.6 | 3.01 / 3.15 | 0.02 | 0.47 | 2.00 | 1.12 MB |
| z15.5, bearing 30, pitch 60 | 9 | 59 | 202 375 | 16.7 | 6.1 | 3.60 / 3.86 | 0.04 | 0.53 | 2.51 | 4.29 MB |
The warm frame is dominated by the read-back (allocating and copying 12 MB), which an on-screen frame does not pay: CPU encoding is under 0.1 ms and the GPU time reported by Metal about 0.5–0.6 ms on this Mac. Triangle counts include the casing pass and layers hidden at that zoom (submitted, collapsed in the vertex shader).
Memory of cached meshes
Cached mesh = vertex buffer (12 bytes per vertex) + index buffer (4 bytes per index); nothing else is retained per tile.
The 146 benchmark tiles together: 5 041 394 vertices, 13 226 406 indices, 113.4 MB, 0.78 MB per tile on average
(0.5 MB at zoom 15, about 1 MB at zoom 12–14). One phone frame holds 1.1–6.7 MB (table above). Default cache budget:
256 MB (AtlasRenderer.Configuration.meshCacheBytes), LRU. The decoded-tile cache of TileStore (48 MB by default)
is separate and estimated by that module, not measured here.
Worked around locally (missing in other modules)
ORIXMapStyleexposes the layer model only as a MapLibre style document: the layer order, thekindfilters and the width ramps ofStyleBuilder.Builderare internal, soAtlasStyleduplicates them (road stops, land use groups, opacity ramps). They can drift; a renderer-neutral layer description inORIXMapStylewould remove this.ORIXTileStore:VectorTile,LayerandFeaturehave no public memberwise initializer and there is no PMTiles writer, so the tests carry a small MVT encoder and a PMTiles v3 writer (Tests/…/Support.swift).LRUCacherequiresSendablevalues, henceGPUTileMesh: @unchecked Sendable(immutable after creation).LRUCache.insertscans all entries to find the victim (fine at the prototype's sizes).ORIXMapRendereris not a dependency (it links MapLibre), soAtlasCameramirrorsMapCamerainstead of using it; the adapter belongs in the futureMapBackendimplementation.
Known limits
Everything listed "not started" or "partial" in the specification. In particular: no labels, icons, dashes, building extrusion, terrain, overlays, picking, on-screen view or gestures; single archive (no base + region composition); tiles of one zoom per frame (no level of detail under pitch); tiles are loaded before the frame is drawn (the offscreen path waits, so the fallback logic is only exercised for absent and corrupt tiles); vertex positions are 16-bit, a coordinate beyond ±32 767 tile units is clamped and counted.