Skip to main content

@luma.gl/graph/gpu-dggs

Discrete global grid indexes are compact, stable identifiers. Rendering and spatial analysis need coordinates. The experimental @luma.gl/graph/gpu-dggs module connects those two representations without pulling a large cell column back to JavaScript.

InputShared GPU primitiveOutput
Packed uint32x2 cell IDsvalidation → topology decode → spherical projectionfloat32x2 longitude/latitude or float32x3 unit vectors

The same operation projects centers for H3 and A5. Set the family from your source data or application configuration.

Live benchmark​

This benchmark runs locally on the reader's WebGPU adapter. It validates every result before and after timing and reports portable completion-fence latency separately from compute-only timestamp queries when the adapter exposes them.

Live DGGS cell-center projection

Decode a repeated, globally distributed set of valid H3 or A5 indexes with the public command-graph primitive. Correctness checks, upload, compilation, and readback stay outside measured submissions.

Ready to decode 16,384 H3 indexes into normalized vectors.

Mobile quality · smallest workload

Benchmark input is already resident when timing begins. Upload, shader compilation, and validation readback are deliberately excluded. That makes the result representative of a projection pass inside a larger GPU pipeline, not a claim about end-to-end file ingestion.

Project cell centers​

Use gpuDGGSCellProjection for both H3 and A5. Choose the grid with family and choose longitude/latitude degrees or unit vectors with projection.

import {gpuDGGSCellProjection} from '@luma.gl/graph/gpu-dggs';

graph.addInput('cells', {type: 'vector', format: 'uint32x2'});
graph.add(gpuDGGSCellProjection, {
family: 'h3',
cells: 'cells',
output: 'centers',
validity: 'validCenters'
});

The named outputs inherit the row count and chunk boundaries of cells. Pass centers and validCenters to gpuProjectCoordinates to transform geographic centers while keeping invalid rows masked.

In a caller-owned command graph, pass a concrete view. Supply destination views or let the graph allocate them.

import type {GPUDGGSCellProjectionResult} from '@luma.gl/graph/gpu-dggs';

commandGraph.add(gpuDGGSCellProjection, {
id: 'centers',
family: 'a5',
cells,
validity: true,
projection: 'unit-vector'
});
const centers = commandGraph.getContribution<GPUDGGSCellProjectionResult<'float32x3'>>('centers');

centers.output can feed a vertex input or compute pass. The command graph owns allocated output buffers. It borrows any destination passed as output or validity.

GPU data contract​

cells supplies packed uint32x2 rows. The default wordOrder: 'little-endian' expects the low 32-bit word first and matches a native BigUint64Array on the browser platforms WebGPU targets. Set wordOrder: 'high-low' for canonical high-word-first storage.

PropertyFormatMeaning
cellsuint32x2One split 64-bit cell index per row
output, projection: 'lnglat'float32x2Longitude then latitude, in degrees
output, projection: 'unit-vector'float32x3Normalized Earth-centered Cartesian vector
validityoptional uint321 for a valid cell, 0 for an invalid index

Invalid rows write zero coordinates. All views must have the same row count, belong to the target graph, use packed layouts, and occupy separate buffers. Three-dimensional bounded dispatch removes the device's one-dimensional workgroup-count limit for very large arrays.

tip

Choose unit vectors for GPU-resident geometry.

Unit vectors compose directly with globe rendering, dot-product distance filters, hemisphere tests, and normal generation. They also avoid the inverse trigonometry required to materialize longitude and latitude. Choose geographic output when downstream code genuinely needs degrees.

Reusable pipeline patterns​

The primitive is source-aligned: output row i always describes cell row i. That makes it easy to compose with existing graph operations.

GoalSuggested graph
Render cell centersDGGS projection → model vertex input
Cull invalid dataprojection with validity → GPUCompaction
Aggregate spatial metricsunit vectors → expression/filter → reduction
Publish coordinates to the CPUprojection → explicit readback ring
Switch grids at runtimepass family to gpuDGGSCellProjection

The fixed H3 icosahedron basis is currently a 960-byte module-scope WGSL constant. A storage-buffer table would add a binding and upload without reducing the working set. The shared family-neutral class deliberately leaves that implementation choice behind the API boundary, so a profiled adapter-specific table path could be added later without changing application graphs.

Resident cell boundaries​

Use graph.add(gpuDGGSCellBoundary, props) to generate a closed ring from each packed key. The definition supports H3, A5, S2, quadkey, and geohash.

import {gpuDGGSCellBoundary, type GPUDGGSCellBoundaryResult} from '@luma.gl/graph/gpu-dggs';

const cells = graph.createDataView(inputHandle, {format: 'uint32x2', length: cellCount});
graph.add(gpuDGGSCellBoundary, {id: 'rings', family: 'a5', cells, counts: true});
const {vertices, counts} = graph.getContribution<GPUDGGSCellBoundaryResult<'float32x2'>>('rings');

Pass vertices directly to graph.add(gpuProjectCoordinates, {id, input: vertices, program}) to project them in the same command graph. Keep the DGGS counts to identify valid rings and their closing vertices.

Add one contribution per physical source chunk. Supply vertices and counts views to borrow caller-owned output buffers. Use counts: true to allocate a transient count buffer, or omit it when the consumer can use the padded slot directly. Input keys and each output use separate storage buffers. The caller compiles, encodes, and submits the graph. Vertex row i * getDGGSCellBoundaryCapacity(family) starts the path for input row i. Coordinates are longitude/latitude in degrees. Choose float32x4 for the [longitude, latitude, 0, 0] layout used by split-position consumers.

The optional count includes the closing point. A count of zero identifies an invalid or unsupported key, whose slot is zero-filled. Valid short paths repeat their first vertex through the end of the slot. Consumers can read the counts on the GPU or use the fixed layout directly when they can handle degenerate edges. The Arrow adapter wraps these same fixed slots in its existing list representation for all five families.

FamilySlot capacityCount and coverage
H311Closed hexagons and pentagons, including vertices at icosahedral face crossings. Regular hexagons have count seven. Class III pentagons can use all eleven slots.
A56Four for triangles and six for pentagons. Longitude follows the cell center across the antimeridian.
S25Four spherical corners plus closure. Edge tessellation and seam clipping belong to downstream consumers.
Quadkey5Four tile bounds corners plus closure. The high six bits store the digit count (1–29), and the remaining bits hold right-aligned base-4 digits.
Geohash5Four box bounds corners plus closure. The high four bits store the character count (1–12), and the remaining bits hold right-aligned base-32 digits.

The generic contributor accepts all five families. For packed quadkeys and geohashes, unused payload bits must be zero. S2 uses the native 64-bit CellId. H3 slots increased from seven to eleven. Allocate with getDGGSCellBoundaryCapacity('h3') and use the per-row count for the true path length. The Arrow adapter uses eleven positions per H3 row and pads shorter rings with their first vertex. Icosahedron face crossings are part of the H3 ring. Antimeridian splitting for a specific map viewport remains a consumer operation.

Project boundaries in a GPUGraph​

Use the same operation for H3 and A5. The graph creates one vertex chunk and one count chunk per cell chunk. A downstream projection consumes the named vertex vector directly.

import {GPUGraph} from '@luma.gl/graph/gpu-graph';
import {gpuDGGSCellBoundary} from '@luma.gl/graph/gpu-dggs';
import {gpuProjectCoordinates} from '@luma.gl/graph/gpu-project';

const graph = new GPUGraph();
graph.addInput('cells', {type: 'vector', format: 'uint32x2'});
graph
.add(gpuDGGSCellBoundary, {
family: 'h3', // Use 'a5' for A5 cell IDs.
cells: 'cells',
vertices: 'longitudeLatitude',
counts: 'counts'
})
.add(gpuProjectCoordinates, {
program: projection, // A compiled projection accepting float32x2 longitude/latitude.
input: 'longitudeLatitude',
output: 'projected'
});

const compiledGraph = graph.compile(device, {
outputs: {projected: {type: 'vector', format: 'float32x2'}, counts: {type: 'vector', format: 'uint32'}}
});
const {projected, counts} = await compiledGraph.run({inputs: {cells}});

Within each projected chunk, cell row i begins at i * getDGGSCellBoundaryCapacity(family). The matching count gives the length of its closed ring. Skip rows with count zero and ignore vertices past each ring's count. Fixed slots let the graph allocate storage from the bound chunk lengths before the GPU writes the actual counts.

The Global Grids example uses this sequence for both packed Uint64 and UTF-8 inputs. It records boundary generation and projection on the render encoder, then draws directly from the projected vertex and count buffers. Each line instance can recover its source cell within the chunk by dividing the instance index by the number of segment slots per cell. The shader skips zero counts and padded segments, so invalid cells do not shift later rows.

Compact H3 boundaries​

Use GPUH3CellBoundaryOffsets and GPUH3CompactCellBoundary for packed H3 rings with no per-cell vertex padding. The first operation uses a count pass and an exclusive GPU scan to fill cells.length + 1 offsets in vertex units. The second writes each closed ring into the range between adjacent offsets. Invalid keys have empty ranges. The final offset is the total number of vertices. Pass the same cell snapshot and word order to both operations.

import {GPUH3CellBoundaryOffsets, GPUH3CompactCellBoundary} from '@luma.gl/graph/gpu-h3';

new GPUH3CellBoundaryOffsets({cells, offsets}).addToGraph(graph);
new GPUH3CompactCellBoundary({cells, offsets, vertices}).addToGraph(graph);

For a fully resident graph, provide output storage with enough capacity for the total vertex count and use the terminal offset as its logical length. For exact allocation, run the offset operation first and allocate from the terminal offset before registering the write operation. Both stages borrow caller-owned buffers. The padded operation remains available for fixed-stride consumers.

The asynchronous Arrow adapter convertH3CellKeysToCompactGPUPaths reads back only the offsets to construct list metadata and allocate exact-sized coordinate buffers per input chunk. Coordinate generation stays on the GPU. Use convertDggsCellKeysToGPUPaths for the existing synchronous padded output.

Benchmark API​

The live page uses an isolated optional entry point, keeping measurement code out of application bundles:

import {runGPUDGGSCellProjectionBenchmark} from '@luma.gl/graph/gpu-dggs/benchmarks';

const report = await runGPUDGGSCellProjectionBenchmark(device, {
family: 'h3',
cells: packedCellWords,
referenceValues: precomputedUnitVectorCenters,
projection: 'unit-vector'
});

The runner accepts low-word/high-word Uint32Array input plus row-matched CPU or precomputed reference centers. It rejects invalid cells, compares every output component with that oracle, range-checks geographic centers, verifies vector normalization, and returns distributions rather than a single best-case sample. Use referenceTolerance to override the default 0.03° geographic or 0.002 unit-vector component tolerance.