Skip to content

feat: Use devicePixelRatio for level of detail computation in tile traversal - #513

Merged
kylebarron merged 6 commits into
mainfrom
kyle/mpu-lod
May 7, 2026
Merged

kylebarron merged 6 commits into
mainfrom
kyle/mpu-lod

Conversation

@kylebarron

@kylebarron kylebarron commented May 7, 2026 •

Copy link
Copy Markdown
Member

Closes #64

Summary

  • Tile LOD now matches source pixels to device pixels rather than CSS pixels, honoring Deck.useDevicePixels.
    • This is cleaner than making a new prop just for the raster layers. If you want a custom LOD change, you can change it in useDevicePixels that you pass to Deck
  • Refactors the LOD comparison from tileMetersPerPixel <= metersPerScreenPixel to a dimensionless devicePixelsPerSourcePixel <= 1. The pixel ratio is threaded through getTileIndices → RasterTileNode.update() and read lazily from the layer's drawing buffer (drawingBufferWidth / cssWidth) so window-drag-between-displays takes effect on the next traversal.
  • Adds dev-docs/lod-and-pixel-matching.md documenting the LOD criterion, why per-tile LOD already varies by latitude, and three named gaps that remain (camera distance/tilt, source-side latitude variation Should metersPerUnit / scaleDenominator be scaled by the center latitude of each tile for degree-based CRSes? #89, and a sketch of a unified viewport.project-based criterion).
  • Adds dev-docs/README.md clarifying the four-folder layout (top-level living docs, specs/, ideas/, plans/).

Behavior change: on a 2× display, ~4× more tiles fetched per view (one finer overview level over the same area). Correct under the device-pixel framing — the display can resolve that detail.

kylebarron and others added 3 commits May 7, 2026 11:40
`dev-docs/README.md` clarifies the four-folder layout (top-level living
docs, specs/, ideas/, plans/) and when to write what.

`dev-docs/lod-and-pixel-matching.md` documents how tile LOD selection
ties source raster pixels to screen pixels via ground meters, names
the four threads that contribute to or are missing from the criterion
(devicePixelRatio, camera distance/tilt, lat-varying source mpp, the
unifying viewport-project alternative), and explains why per-tile LOD
already varies by latitude today.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds an optional `pixelRatio` parameter to `getTileIndices` and
`RasterTileNode.update()`, replaces the LOD comparison with the
dimensionless `devicePixelsPerSourcePixel <= 1` form. Default
pixelRatio=1 preserves existing CSS-pixel behavior; the layer wire-up
in the next commit changes the user-visible default.

Background: dev-docs/lod-and-pixel-matching.md § (A).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Threads the layer's effective device-pixel ratio (drawing-buffer /
CSS size, computed manually since `cssToDeviceRatio()` is deprecated
and `devicePixelRatio`/`getDevicePixelRatio()` ignore Deck's
`useDevicePixels`) into `RasterTileset2D` as `getPixelRatio`. The LOD
criterion now matches source pixels to *device* pixels rather than
CSS pixels. Closes #64.

Behavior change: on a 2× display the layer fetches ~4× more tiles per
view (one finer overview level over the same area). This is correct
under the device-pixel framing — the display can resolve that detail.

See dev-docs/lod-and-pixel-matching.md § (A).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron kylebarron changed the title Use devicePixelRatio for tile LOD selection (#64) feat: Use devicePixelRatio for tile LOD selection (#64) May 7, 2026
@github-actions github-actions Bot added the feat label May 7, 2026
The implementation reads `drawingBufferWidth / cssWidth`, not luma's
deprecated `cssToDeviceRatio()` and not the system DPR. Document this
explicitly: list the cases where the drawing-buffer ratio diverges
from `window.devicePixelRatio` (useDevicePixels: false, numeric
override, explicit setDrawingBufferSize, maxDrawingBufferSize cap),
and note that deck.gl's convention (which our variable names follow)
uses "device pixel" colloquially to mean "rendered framebuffer
pixel."

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron kylebarron changed the title feat: Use devicePixelRatio for tile LOD selection (#64) feat: Use devicePixelRatio for level of detail computation in tile traversal May 7, 2026
kylebarron and others added 2 commits May 7, 2026 15:07
The `RasterTileset2DOptions.getPixelRatio` JSDoc described the layer
as wiring this to the deprecated `cssToDeviceRatio()`. The actual
implementation reads `drawingBufferWidth / cssWidth` per call, for the
reasons documented in dev-docs/lod-and-pixel-matching.md § (A) (the
luma deprecation conflated drawing-buffer ratio with system DPR).
Update the docstring to match.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron
kylebarron merged commit 4f3e5d0 into main May 7, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/mpu-lod branch May 7, 2026 19:17
kylebarron added a commit that referenced this pull request May 11, 2026
…525)

* docs(specs): add traversal bounding-volume cache design

Memoizes per-tile bounding volumes (proj4 reprojection + OBB construction)
across getTileIndices calls on the RasterTileset2D, eliminating the
per-animation-frame recomputation that #513's device-pixel LOD change
exposed (#523).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* feat(raster-tileset): add BoundingVolumeCache (LRU, soft-capped)

Standalone cache for tile bounding volumes keyed by "z/x/y", with
LRU recency and a swept soft cap. Not wired into the traversal yet.

Refs #523.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* feat(raster-tileset): thread BoundingVolumeCache through the traversal

getBoundingVolume consults an optional BoundingVolumeCache (passed via the
RasterTileNode ctor / createRootTiles / getTileIndices opts) before doing
the proj4 reprojections + OBB fit. Omitting the cache preserves the
previous per-node-only behavior. getTileIndices sweeps the cache once at
the top of each traversal.

Refs #523.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* feat(raster-tileset): RasterTileset2D memoizes tile bounding volumes

Each RasterTileset2D now owns a BoundingVolumeCache and passes it into
getTileIndices, so animation-frame traversals reuse the proj4
reprojections + OBB fit instead of recomputing them every frame. New
RasterTileset2DOptions.maxBoundingVolumeCacheSize tunes the cap.

Fixes the per-frame getTileIndices regression in #523.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(raster-tileset): make BoundingVolumeCache non-optional in traversal

Per PR review:
- The cache is a property of the traversal, not of a node — thread it
  through `update()`'s params (which already propagate down the
  recursion) instead of the `RasterTileNode` constructor / `children`
  getter / `createRootTiles`.
- It always exists: `getTileIndices` uses a caller-supplied cache or a
  throwaway one. That lets `getBoundingVolume` drop its if/else and the
  now-redundant per-node `_boundingVolume` field (which never actually
  hit — `update` calls `getBoundingVolume` once per node).
- Write `DEFAULT_MAX_ENTRIES` as `65_536`.

Refs #523.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(raster-tileset): split getBoundingVolume / computeBoundingVolume

Per PR review: getBoundingVolume is now just the cache wrapper (lookup ->
hit? return : compute, store, return); the case dispatch (Globe assert,
future mercator fast paths, generic Case 4) moves into a lower-level
private computeBoundingVolume.

Refs #523.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@kylebarron kylebarron self-assigned this May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support pixel density adjustment

1 participant