@luma.gl/graph 10.0.0-alpha.5 → 10.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +38 -0
- package/README.md +7 -1
- package/dist/arrow/dggs/dggs-gpu-polygons.cjs +667 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.d.ts +75 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.d.ts.map +1 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.js +651 -0
- package/dist/arrow/dggs/dggs-gpu-polygons.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.cjs +411 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts +31 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js +395 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.cjs +304 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts +32 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js +293 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.cjs +232 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.d.ts +54 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.d.ts.map +1 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js +222 -0
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +314 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +42 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +318 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +204 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +30 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +195 -0
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.cjs +257 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.d.ts +45 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.js +257 -0
- package/dist/arrow/gpu/arrow-gpu-table-adapters.js.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +230 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +71 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +215 -0
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -0
- package/dist/arrow/gpu/arrow-input-schema.cjs +36 -0
- package/dist/arrow/gpu/arrow-input-schema.d.ts +41 -0
- package/dist/arrow/gpu/arrow-input-schema.d.ts.map +1 -0
- package/dist/arrow/gpu/arrow-input-schema.js +17 -0
- package/dist/arrow/gpu/arrow-input-schema.js.map +1 -0
- package/dist/arrow/index.cjs +90 -0
- package/dist/arrow/index.cjs.map +6 -0
- package/dist/arrow/index.d.ts +9 -0
- package/dist/arrow/index.d.ts.map +1 -0
- package/dist/arrow/index.js +12 -0
- package/dist/arrow/index.js.map +1 -0
- package/dist/arrow/internal.cjs +30 -0
- package/dist/arrow/internal.cjs.map +6 -0
- package/dist/arrow/internal.d.ts +19 -0
- package/dist/arrow/internal.d.ts.map +1 -0
- package/dist/arrow/internal.js +7 -0
- package/dist/arrow/internal.js.map +1 -0
- package/dist/dist.dev.js +283 -12
- package/dist/dist.min.js +29 -29
- package/dist/geospatial/geospatial-utils.cjs +12 -11
- package/dist/geospatial/geospatial-utils.d.ts +1 -1
- package/dist/geospatial/geospatial-utils.d.ts.map +1 -1
- package/dist/geospatial/geospatial-utils.js +3 -2
- package/dist/geospatial/geospatial-utils.js.map +1 -1
- package/dist/geospatial/index.cjs.map +2 -2
- package/dist/gpu-a5/index.cjs.map +1 -1
- package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
- package/dist/gpu-dggs/gpu-dggs-cell-projection.cjs +2 -2
- package/dist/gpu-dggs/gpu-dggs-cell-projection.js +1 -1
- package/dist/gpu-dggs/gpu-dggs-cell-projection.js.map +1 -1
- package/dist/gpu-dggs/index.cjs.map +1 -1
- package/dist/gpu-h3/index.cjs.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-project/projection-program.cjs +2 -2
- package/dist/gpu-project/projection-program.d.ts +1 -1
- package/dist/gpu-project/projection-program.d.ts.map +1 -1
- package/dist/gpu-project/projection-program.js +1 -1
- package/dist/gpu-project/projection-program.js.map +1 -1
- package/dist/gpu-sql/lu-sql.d.ts +1 -1
- package/dist/gpu-sql/lu-sql.js +1 -1
- package/dist/gpu-tables/engine/gpu-table-shader-bindings.d.ts +1 -1
- package/dist/gpu-tables/engine/gpu-table-shader-bindings.d.ts.map +1 -1
- package/dist/gpu-vector-search/index.cjs.map +1 -1
- package/dist/utils/assemble-compute-kernel.cjs +2 -2
- package/dist/utils/assemble-compute-kernel.d.ts +2 -1
- package/dist/utils/assemble-compute-kernel.d.ts.map +1 -1
- package/dist/utils/assemble-compute-kernel.js +2 -2
- package/dist/utils/assemble-compute-kernel.js.map +1 -1
- package/package.json +19 -7
- package/src/arrow/dggs/dggs-gpu-polygons.ts +820 -0
- package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +519 -0
- package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +415 -0
- package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +369 -0
- package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +474 -0
- package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +294 -0
- package/src/arrow/gpu/arrow-gpu-table-adapters.ts +378 -0
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +324 -0
- package/src/arrow/gpu/arrow-input-schema.ts +98 -0
- package/src/arrow/index.ts +79 -0
- package/src/arrow/internal.ts +23 -0
- package/src/geospatial/geospatial-utils.ts +3 -7
- package/src/gpu-dggs/gpu-dggs-cell-projection.ts +1 -1
- package/src/gpu-project/projection-program.ts +1 -1
- package/src/gpu-sql/lu-sql.ts +1 -1
- package/src/gpu-tables/engine/gpu-table-shader-bindings.ts +1 -1
- package/src/utils/assemble-compute-kernel.ts +3 -7
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var dggs_gpu_polygons_exports = {};
|
|
19
|
+
__export(dggs_gpu_polygons_exports, {
|
|
20
|
+
convertDggsCellIdsToGPUKeys: () => convertDggsCellIdsToGPUKeys,
|
|
21
|
+
convertDggsCellKeysToGPUPaths: () => convertDggsCellKeysToGPUPaths,
|
|
22
|
+
getDggsUint64Words: () => getDggsUint64Words,
|
|
23
|
+
packDggsA5CellKey: () => packDggsA5CellKey,
|
|
24
|
+
packDggsGeohashKey: () => packDggsGeohashKey,
|
|
25
|
+
packDggsH3CellKey: () => packDggsH3CellKey,
|
|
26
|
+
packDggsQuadkeyKey: () => packDggsQuadkeyKey,
|
|
27
|
+
packDggsS2CellKey: () => packDggsS2CellKey
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(dggs_gpu_polygons_exports);
|
|
30
|
+
var import_core = require("@luma.gl/core");
|
|
31
|
+
var import_arrow = require("@luma.gl/gpgpu/_internal/arrow");
|
|
32
|
+
var import_dynamic = require("@luma.gl/core/dynamic");
|
|
33
|
+
var import_shaders = require("@luma.gl/shaders");
|
|
34
|
+
var import_gpu_data = require("@luma.gl/gpgpu/gpu-data");
|
|
35
|
+
var import_apache_arrow = require("apache-arrow");
|
|
36
|
+
var import_arrow2 = require("@luma.gl/gpgpu/arrow");
|
|
37
|
+
var import_arrow3 = require("@luma.gl/gpgpu/_internal/arrow");
|
|
38
|
+
const DGGS_DEFAULT_CELL_POLYGON_POINT_COUNT = 5;
|
|
39
|
+
const DGGS_A5_CELL_POLYGON_POINT_COUNT = 6;
|
|
40
|
+
const DGGS_H3_CELL_POLYGON_POINT_COUNT = 7;
|
|
41
|
+
const GEOHASH_MAXIMUM_LENGTH = 12;
|
|
42
|
+
const GEOHASH_LENGTH_BIT_OFFSET = 60n;
|
|
43
|
+
const QUADKEY_MAXIMUM_LENGTH = 29;
|
|
44
|
+
const QUADKEY_LENGTH_BIT_OFFSET = 58n;
|
|
45
|
+
const A5_HEX_MAXIMUM_LENGTH = 16;
|
|
46
|
+
const H3_HEX_MAXIMUM_LENGTH = 16;
|
|
47
|
+
const UINT64_WORD_MASK = 0xffffffffn;
|
|
48
|
+
const GEOHASH_BASE32_CODES = "0123456789bcdefghjkmnpqrstuvwxyz";
|
|
49
|
+
const GEOHASH_BASE32_CODE_MAP = new Map(Array.from(GEOHASH_BASE32_CODES, (character, index) => [character, index]));
|
|
50
|
+
function packDggsGeohashKey(geohash) {
|
|
51
|
+
const normalizedGeohash = geohash.toLowerCase();
|
|
52
|
+
if (normalizedGeohash.length < 1 || normalizedGeohash.length > GEOHASH_MAXIMUM_LENGTH) {
|
|
53
|
+
throw new Error(`Geohash keys must contain 1-${GEOHASH_MAXIMUM_LENGTH} characters`);
|
|
54
|
+
}
|
|
55
|
+
let encodedValue = 0n;
|
|
56
|
+
for (const character of normalizedGeohash) {
|
|
57
|
+
const characterCode = GEOHASH_BASE32_CODE_MAP.get(character);
|
|
58
|
+
if (characterCode === void 0) {
|
|
59
|
+
throw new Error(`Invalid geohash character "${character}"`);
|
|
60
|
+
}
|
|
61
|
+
encodedValue = encodedValue << 5n | BigInt(characterCode);
|
|
62
|
+
}
|
|
63
|
+
return BigInt(normalizedGeohash.length) << GEOHASH_LENGTH_BIT_OFFSET | encodedValue;
|
|
64
|
+
}
|
|
65
|
+
function packDggsQuadkeyKey(quadkey) {
|
|
66
|
+
if (quadkey.length < 1 || quadkey.length > QUADKEY_MAXIMUM_LENGTH) {
|
|
67
|
+
throw new Error(`Quadkey keys must contain 1-${QUADKEY_MAXIMUM_LENGTH} digits`);
|
|
68
|
+
}
|
|
69
|
+
let encodedValue = 0n;
|
|
70
|
+
for (const digitCharacter of quadkey) {
|
|
71
|
+
const digit = digitCharacter.charCodeAt(0) - 48;
|
|
72
|
+
if (digit < 0 || digit > 3) {
|
|
73
|
+
throw new Error(`Invalid quadkey digit "${digitCharacter}"`);
|
|
74
|
+
}
|
|
75
|
+
encodedValue = encodedValue << 2n | BigInt(digit);
|
|
76
|
+
}
|
|
77
|
+
return BigInt(quadkey.length) << QUADKEY_LENGTH_BIT_OFFSET | encodedValue;
|
|
78
|
+
}
|
|
79
|
+
function packDggsS2CellKey(face, childPositions) {
|
|
80
|
+
if (!Number.isInteger(face) || face < 0 || face > 5) {
|
|
81
|
+
throw new Error("S2 face must be an integer in [0, 5]");
|
|
82
|
+
}
|
|
83
|
+
if (childPositions.length > 30) {
|
|
84
|
+
throw new Error("S2 child position arrays cannot exceed 30 levels");
|
|
85
|
+
}
|
|
86
|
+
let positionBits = 0n;
|
|
87
|
+
for (const childPosition of childPositions) {
|
|
88
|
+
if (!Number.isInteger(childPosition) || childPosition < 0 || childPosition > 3) {
|
|
89
|
+
throw new Error("S2 child positions must be integers in [0, 3]");
|
|
90
|
+
}
|
|
91
|
+
positionBits = positionBits << 2n | BigInt(childPosition);
|
|
92
|
+
}
|
|
93
|
+
const level = BigInt(childPositions.length);
|
|
94
|
+
const sentinelBitOffset = 2n * (30n - level);
|
|
95
|
+
return BigInt(face) << 61n | positionBits << sentinelBitOffset + 1n | 1n << sentinelBitOffset;
|
|
96
|
+
}
|
|
97
|
+
function packDggsA5CellKey(cellId) {
|
|
98
|
+
return packDggsHexCellKey(cellId, "A5", A5_HEX_MAXIMUM_LENGTH);
|
|
99
|
+
}
|
|
100
|
+
function packDggsH3CellKey(cellId) {
|
|
101
|
+
return packDggsHexCellKey(cellId, "H3", H3_HEX_MAXIMUM_LENGTH);
|
|
102
|
+
}
|
|
103
|
+
function packDggsHexCellKey(cellId, encodingName, maximumHexLength) {
|
|
104
|
+
if (typeof cellId === "bigint") {
|
|
105
|
+
return BigInt.asUintN(64, cellId);
|
|
106
|
+
}
|
|
107
|
+
const normalizedCellId = cellId.trim().replace(/^0x/i, "");
|
|
108
|
+
if (normalizedCellId.length < 1 || normalizedCellId.length > maximumHexLength) {
|
|
109
|
+
throw new Error(`${encodingName} cell ids must contain 1-${maximumHexLength} hexadecimal digits`);
|
|
110
|
+
}
|
|
111
|
+
if (!/^[0-9a-fA-F]+$/.test(normalizedCellId)) {
|
|
112
|
+
throw new Error(`Invalid ${encodingName} cell id "${cellId}"`);
|
|
113
|
+
}
|
|
114
|
+
return BigInt.asUintN(64, BigInt(`0x${normalizedCellId}`));
|
|
115
|
+
}
|
|
116
|
+
function convertDggsCellKeysToGPUPaths(device, keys, options) {
|
|
117
|
+
if (device.type !== "webgpu") {
|
|
118
|
+
throw new Error("convertDggsCellKeysToGPUPaths requires a WebGPU device");
|
|
119
|
+
}
|
|
120
|
+
const resourceIdentifier = options.id || `dggs-${options.encoding}-cell-polygons`;
|
|
121
|
+
const cellPolygonPointCount = getDggsCellPolygonPointCount(options.encoding);
|
|
122
|
+
const coordinateFormat = options.coordinateFormat || "float32";
|
|
123
|
+
const pathValueComponentCount = getDggsCellPathCoordinateComponentCount(coordinateFormat);
|
|
124
|
+
const pathFormat = `vertex-list<float32x${pathValueComponentCount}>`;
|
|
125
|
+
const pathType = makeDggsCellPathCoordinateType(pathValueComponentCount);
|
|
126
|
+
const ownsKeyVector = !(keys instanceof import_gpu_data.GPUVector);
|
|
127
|
+
const keyVector = ownsKeyVector ? (0, import_arrow2.makeGPUVectorFromArrow)(device, keys, {
|
|
128
|
+
id: `${resourceIdentifier}-keys`,
|
|
129
|
+
name: `${options.encoding}Keys`,
|
|
130
|
+
format: "uint32x2"
|
|
131
|
+
}) : keys;
|
|
132
|
+
assertDggsCellKeyVector(keyVector, "convertDggsCellKeysToGPUPaths");
|
|
133
|
+
const pathDataChunks = [];
|
|
134
|
+
let pathByteLength = 0;
|
|
135
|
+
let transientByteLength = ownsKeyVector ? getUint64KeyVectorByteLength(keyVector) : 0;
|
|
136
|
+
for (const [chunkIndex, keyData] of keyVector.data.entries()) {
|
|
137
|
+
const valueOffsets = makeFixedCellPathValueOffsets(keyData.length, cellPolygonPointCount);
|
|
138
|
+
const generatedPathByteLength = keyData.length * cellPolygonPointCount * pathValueComponentCount * Float32Array.BYTES_PER_ELEMENT;
|
|
139
|
+
const pathValuesBuffer = new import_dynamic.DynamicBuffer(device, {
|
|
140
|
+
id: `${resourceIdentifier}-path-values-${chunkIndex}`,
|
|
141
|
+
usage: import_core.Buffer.VERTEX | import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC,
|
|
142
|
+
byteLength: Math.max(generatedPathByteLength, Float32Array.BYTES_PER_ELEMENT)
|
|
143
|
+
});
|
|
144
|
+
const extractionConfigBuffer = device.createBuffer({
|
|
145
|
+
id: `${resourceIdentifier}-config-${chunkIndex}`,
|
|
146
|
+
usage: import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC,
|
|
147
|
+
data: new Uint32Array([keyData.length])
|
|
148
|
+
});
|
|
149
|
+
dispatchDggsCellPathExtractionCompute(device, {
|
|
150
|
+
resourceIdentifier: `${resourceIdentifier}-${chunkIndex}`,
|
|
151
|
+
encoding: options.encoding,
|
|
152
|
+
coordinateFormat,
|
|
153
|
+
keys: getGPUDataBinding(keyData, keyData.length * keyData.byteStride),
|
|
154
|
+
extractionConfig: extractionConfigBuffer,
|
|
155
|
+
pathValues: pathValuesBuffer,
|
|
156
|
+
cellCount: keyData.length
|
|
157
|
+
});
|
|
158
|
+
extractionConfigBuffer.destroy();
|
|
159
|
+
transientByteLength += Uint32Array.BYTES_PER_ELEMENT;
|
|
160
|
+
pathByteLength += generatedPathByteLength;
|
|
161
|
+
pathDataChunks.push(new import_gpu_data.GPUData({
|
|
162
|
+
buffer: pathValuesBuffer,
|
|
163
|
+
dataType: pathType,
|
|
164
|
+
format: pathFormat,
|
|
165
|
+
length: keyData.length,
|
|
166
|
+
valueOffsets,
|
|
167
|
+
valueLength: keyData.length * cellPolygonPointCount,
|
|
168
|
+
valueByteLength: generatedPathByteLength,
|
|
169
|
+
stride: pathValueComponentCount,
|
|
170
|
+
byteStride: pathValueComponentCount * Float32Array.BYTES_PER_ELEMENT,
|
|
171
|
+
rowByteLength: pathValueComponentCount * Float32Array.BYTES_PER_ELEMENT,
|
|
172
|
+
ownsBuffer: true,
|
|
173
|
+
readbackMetadata: {
|
|
174
|
+
kind: "variable-length-attribute",
|
|
175
|
+
valueOffsets,
|
|
176
|
+
nullCount: 0,
|
|
177
|
+
valueByteLength: generatedPathByteLength
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
if (ownsKeyVector) {
|
|
182
|
+
keyVector.destroy();
|
|
183
|
+
}
|
|
184
|
+
const paths = new import_gpu_data.GPUVector({
|
|
185
|
+
type: "data",
|
|
186
|
+
name: "paths",
|
|
187
|
+
dataType: pathType,
|
|
188
|
+
format: pathFormat,
|
|
189
|
+
data: pathDataChunks,
|
|
190
|
+
stride: pathValueComponentCount,
|
|
191
|
+
byteStride: pathValueComponentCount * Float32Array.BYTES_PER_ELEMENT,
|
|
192
|
+
rowByteLength: pathValueComponentCount * Float32Array.BYTES_PER_ELEMENT,
|
|
193
|
+
ownsData: true
|
|
194
|
+
});
|
|
195
|
+
let destroyed = false;
|
|
196
|
+
return {
|
|
197
|
+
paths,
|
|
198
|
+
pointCount: cellPolygonPointCount,
|
|
199
|
+
pathByteLength,
|
|
200
|
+
transientByteLength,
|
|
201
|
+
destroy: () => {
|
|
202
|
+
if (destroyed) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
destroyed = true;
|
|
206
|
+
paths.destroy();
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function convertDggsCellIdsToGPUKeys(device, strings, options) {
|
|
211
|
+
if (device.type !== "webgpu") {
|
|
212
|
+
throw new Error("convertDggsCellIdsToGPUKeys requires a WebGPU device");
|
|
213
|
+
}
|
|
214
|
+
if (!import_apache_arrow.DataType.isUtf8(strings.type)) {
|
|
215
|
+
throw new Error("convertDggsCellIdsToGPUKeys requires a Vector<Utf8>");
|
|
216
|
+
}
|
|
217
|
+
const resourceIdentifier = options.id || `dggs-${options.encoding}-cell-keys`;
|
|
218
|
+
const keyType = new import_apache_arrow.Uint64();
|
|
219
|
+
const keyDataChunks = [];
|
|
220
|
+
let keyByteLength = 0;
|
|
221
|
+
let transientByteLength = 0;
|
|
222
|
+
for (const [chunkIndex, stringData] of strings.data.entries()) {
|
|
223
|
+
const stringBytes = (0, import_arrow3.getArrowUtf8DataBufferSource)(stringData);
|
|
224
|
+
const stringOffsets = getNormalizedUtf8Offsets(stringData);
|
|
225
|
+
const packedStringBytes = packUtf8BytesAsUint32Words(stringBytes);
|
|
226
|
+
const stringBytesBuffer = device.createBuffer({
|
|
227
|
+
id: `${resourceIdentifier}-string-bytes-${chunkIndex}`,
|
|
228
|
+
usage: import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC,
|
|
229
|
+
data: packedStringBytes
|
|
230
|
+
});
|
|
231
|
+
const stringOffsetsBuffer = device.createBuffer({
|
|
232
|
+
id: `${resourceIdentifier}-string-offsets-${chunkIndex}`,
|
|
233
|
+
usage: import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC,
|
|
234
|
+
data: new Uint32Array(stringOffsets.buffer, stringOffsets.byteOffset, stringOffsets.length)
|
|
235
|
+
});
|
|
236
|
+
const stringConfigBuffer = device.createBuffer({
|
|
237
|
+
id: `${resourceIdentifier}-string-config-${chunkIndex}`,
|
|
238
|
+
usage: import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC,
|
|
239
|
+
data: new Uint32Array([stringData.length])
|
|
240
|
+
});
|
|
241
|
+
const keyBufferByteLength = stringData.length * BigUint64Array.BYTES_PER_ELEMENT;
|
|
242
|
+
const keyBuffer = new import_dynamic.DynamicBuffer(device, {
|
|
243
|
+
id: `${resourceIdentifier}-keys-${chunkIndex}`,
|
|
244
|
+
usage: import_core.Buffer.VERTEX | import_core.Buffer.STORAGE | import_core.Buffer.COPY_DST | import_core.Buffer.COPY_SRC,
|
|
245
|
+
byteLength: Math.max(keyBufferByteLength, BigUint64Array.BYTES_PER_ELEMENT)
|
|
246
|
+
});
|
|
247
|
+
dispatchDggsCellKeyParsingCompute(device, {
|
|
248
|
+
resourceIdentifier: `${resourceIdentifier}-${chunkIndex}`,
|
|
249
|
+
encoding: options.encoding,
|
|
250
|
+
stringBytes: stringBytesBuffer,
|
|
251
|
+
stringOffsets: stringOffsetsBuffer,
|
|
252
|
+
stringConfig: stringConfigBuffer,
|
|
253
|
+
keys: keyBuffer,
|
|
254
|
+
stringCount: stringData.length
|
|
255
|
+
});
|
|
256
|
+
stringBytesBuffer.destroy();
|
|
257
|
+
stringOffsetsBuffer.destroy();
|
|
258
|
+
stringConfigBuffer.destroy();
|
|
259
|
+
keyByteLength += keyBufferByteLength;
|
|
260
|
+
transientByteLength += packedStringBytes.byteLength + stringOffsets.byteLength + Uint32Array.BYTES_PER_ELEMENT;
|
|
261
|
+
keyDataChunks.push(new import_gpu_data.GPUData({
|
|
262
|
+
buffer: keyBuffer,
|
|
263
|
+
dataType: keyType,
|
|
264
|
+
format: "uint32x2",
|
|
265
|
+
length: stringData.length,
|
|
266
|
+
stride: 1,
|
|
267
|
+
byteStride: BigUint64Array.BYTES_PER_ELEMENT,
|
|
268
|
+
rowByteLength: BigUint64Array.BYTES_PER_ELEMENT,
|
|
269
|
+
ownsBuffer: true
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
const keys = new import_gpu_data.GPUVector({
|
|
273
|
+
type: "data",
|
|
274
|
+
name: `${options.encoding}Keys`,
|
|
275
|
+
dataType: keyType,
|
|
276
|
+
format: "uint32x2",
|
|
277
|
+
data: keyDataChunks,
|
|
278
|
+
stride: 1,
|
|
279
|
+
byteStride: BigUint64Array.BYTES_PER_ELEMENT,
|
|
280
|
+
rowByteLength: BigUint64Array.BYTES_PER_ELEMENT,
|
|
281
|
+
ownsData: true
|
|
282
|
+
});
|
|
283
|
+
let destroyed = false;
|
|
284
|
+
return {
|
|
285
|
+
keys,
|
|
286
|
+
keyByteLength,
|
|
287
|
+
transientByteLength,
|
|
288
|
+
destroy: () => {
|
|
289
|
+
if (destroyed) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
destroyed = true;
|
|
293
|
+
keys.destroy();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function dispatchDggsCellPathExtractionCompute(device, props) {
|
|
298
|
+
const kernelBindings = {
|
|
299
|
+
dggsCellKeys: props.keys,
|
|
300
|
+
dggsCellExtractionConfig: props.extractionConfig,
|
|
301
|
+
dggsCellPathValues: props.pathValues
|
|
302
|
+
};
|
|
303
|
+
const kernel = (0, import_arrow.createArrowComputeKernel)(device, {
|
|
304
|
+
id: `${props.resourceIdentifier}-extract`,
|
|
305
|
+
source: getDggsCellPathExtractionSource(props.encoding, props.coordinateFormat),
|
|
306
|
+
modules: [import_shaders.dggs],
|
|
307
|
+
shaderLayout: {
|
|
308
|
+
bindings: [
|
|
309
|
+
{ name: "dggsCellKeys", type: "read-only-storage", group: 0, location: 0 },
|
|
310
|
+
{ name: "dggsCellExtractionConfig", type: "read-only-storage", group: 0, location: 1 },
|
|
311
|
+
{ name: "dggsCellPathValues", type: "storage", group: 0, location: 2 }
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
if (props.cellCount > 0) {
|
|
316
|
+
const computePass = device.beginComputePass({});
|
|
317
|
+
kernel.dispatch(computePass, { x: Math.ceil(props.cellCount / 64), bindings: kernelBindings });
|
|
318
|
+
computePass.end();
|
|
319
|
+
device.submit();
|
|
320
|
+
}
|
|
321
|
+
kernel.destroy();
|
|
322
|
+
}
|
|
323
|
+
function dispatchDggsCellKeyParsingCompute(device, props) {
|
|
324
|
+
const kernelBindings = {
|
|
325
|
+
dggsStringBytes: props.stringBytes,
|
|
326
|
+
dggsStringOffsets: props.stringOffsets,
|
|
327
|
+
dggsStringParsingConfig: props.stringConfig,
|
|
328
|
+
dggsParsedKeys: props.keys
|
|
329
|
+
};
|
|
330
|
+
const kernel = (0, import_arrow.createArrowComputeKernel)(device, {
|
|
331
|
+
id: `${props.resourceIdentifier}-parse`,
|
|
332
|
+
source: getDggsCellKeyParsingSource(props.encoding),
|
|
333
|
+
modules: [import_shaders.dggs],
|
|
334
|
+
shaderLayout: {
|
|
335
|
+
bindings: [
|
|
336
|
+
{ name: "dggsStringBytes", type: "read-only-storage", group: 0, location: 0 },
|
|
337
|
+
{ name: "dggsStringOffsets", type: "read-only-storage", group: 0, location: 1 },
|
|
338
|
+
{ name: "dggsStringParsingConfig", type: "read-only-storage", group: 0, location: 2 },
|
|
339
|
+
{ name: "dggsParsedKeys", type: "storage", group: 0, location: 3 }
|
|
340
|
+
]
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
if (props.stringCount > 0) {
|
|
344
|
+
const computePass = device.beginComputePass({});
|
|
345
|
+
kernel.dispatch(computePass, { x: Math.ceil(props.stringCount / 64), bindings: kernelBindings });
|
|
346
|
+
computePass.end();
|
|
347
|
+
device.submit();
|
|
348
|
+
}
|
|
349
|
+
kernel.destroy();
|
|
350
|
+
}
|
|
351
|
+
function getDggsCellPathExtractionSource(encoding, coordinateFormat) {
|
|
352
|
+
const boundaryFunction = getDggsBoundaryFunction(encoding, coordinateFormat);
|
|
353
|
+
const cellPolygonPointCount = getDggsCellPolygonPointCount(encoding);
|
|
354
|
+
const pathValueType = coordinateFormat === "fp64-split" ? "vec4f" : "vec2f";
|
|
355
|
+
return (
|
|
356
|
+
/* wgsl */
|
|
357
|
+
`@group(0) @binding(0) var<storage, read> dggsCellKeys : array<vec2u>;
|
|
358
|
+
@group(0) @binding(1) var<storage, read> dggsCellExtractionConfig : array<u32>;
|
|
359
|
+
@group(0) @binding(2) var<storage, read_write> dggsCellPathValues : array<${pathValueType}>;
|
|
360
|
+
|
|
361
|
+
@compute @workgroup_size(64)
|
|
362
|
+
fn main(@builtin(global_invocation_id) globalInvocationId : vec3u) {
|
|
363
|
+
let cellIndex = globalInvocationId.x;
|
|
364
|
+
if (cellIndex >= dggsCellExtractionConfig[0]) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
let cellKey = dggs_u64_from_little_endian_words(dggsCellKeys[cellIndex]);
|
|
369
|
+
let pathStart = cellIndex * ${cellPolygonPointCount}u;
|
|
370
|
+
var pointIndex = 0u;
|
|
371
|
+
loop {
|
|
372
|
+
if (pointIndex >= ${cellPolygonPointCount}u) {
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
dggsCellPathValues[pathStart + pointIndex] = ${boundaryFunction}(cellKey, pointIndex);
|
|
376
|
+
pointIndex += 1u;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
function getDggsBoundaryFunction(encoding, coordinateFormat) {
|
|
383
|
+
const suffix = coordinateFormat === "fp64-split" ? "_fp64_split" : "";
|
|
384
|
+
switch (encoding) {
|
|
385
|
+
case "geohash":
|
|
386
|
+
return `dggs_geohash_get_boundary_point${suffix}`;
|
|
387
|
+
case "quadkey":
|
|
388
|
+
return `dggs_quadkey_get_boundary_point${suffix}`;
|
|
389
|
+
case "s2":
|
|
390
|
+
return `dggs_s2_get_boundary_point${suffix}`;
|
|
391
|
+
case "a5":
|
|
392
|
+
return `dggs_a5_get_boundary_point${suffix}`;
|
|
393
|
+
case "h3":
|
|
394
|
+
return `dggs_h3_get_boundary_point${suffix}`;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function getDggsCellKeyParsingSource(encoding) {
|
|
398
|
+
const parsingFunction = getDggsStringParsingFunction(encoding);
|
|
399
|
+
return (
|
|
400
|
+
/* wgsl */
|
|
401
|
+
`@group(0) @binding(0) var<storage, read> dggsStringBytes : array<u32>;
|
|
402
|
+
@group(0) @binding(1) var<storage, read> dggsStringOffsets : array<u32>;
|
|
403
|
+
@group(0) @binding(2) var<storage, read> dggsStringParsingConfig : array<u32>;
|
|
404
|
+
@group(0) @binding(3) var<storage, read_write> dggsParsedKeys : array<vec2u>;
|
|
405
|
+
|
|
406
|
+
fn dggs_read_string_byte(byteIndex: u32) -> u32 {
|
|
407
|
+
let word = dggsStringBytes[byteIndex / 4u];
|
|
408
|
+
return (word >> ((byteIndex % 4u) * 8u)) & 0xffu;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
fn dggs_get_lowercase_ascii(byte: u32) -> u32 {
|
|
412
|
+
if (byte >= 65u && byte <= 90u) {
|
|
413
|
+
return byte + 32u;
|
|
414
|
+
}
|
|
415
|
+
return byte;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
fn dggs_get_geohash_character_code(byte: u32) -> u32 {
|
|
419
|
+
let lowercaseByte = dggs_get_lowercase_ascii(byte);
|
|
420
|
+
if (lowercaseByte >= 48u && lowercaseByte <= 57u) {
|
|
421
|
+
return lowercaseByte - 48u;
|
|
422
|
+
}
|
|
423
|
+
if (lowercaseByte >= 98u && lowercaseByte <= 104u) {
|
|
424
|
+
return lowercaseByte - 88u;
|
|
425
|
+
}
|
|
426
|
+
if (lowercaseByte >= 106u && lowercaseByte <= 107u) {
|
|
427
|
+
return lowercaseByte - 89u;
|
|
428
|
+
}
|
|
429
|
+
if (lowercaseByte >= 109u && lowercaseByte <= 110u) {
|
|
430
|
+
return lowercaseByte - 90u;
|
|
431
|
+
}
|
|
432
|
+
if (lowercaseByte >= 112u && lowercaseByte <= 122u) {
|
|
433
|
+
return lowercaseByte - 91u;
|
|
434
|
+
}
|
|
435
|
+
return 0u;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
fn dggs_get_hex_character_code(byte: u32) -> u32 {
|
|
439
|
+
let lowercaseByte = dggs_get_lowercase_ascii(byte);
|
|
440
|
+
if (lowercaseByte >= 48u && lowercaseByte <= 57u) {
|
|
441
|
+
return lowercaseByte - 48u;
|
|
442
|
+
}
|
|
443
|
+
if (lowercaseByte >= 97u && lowercaseByte <= 102u) {
|
|
444
|
+
return lowercaseByte - 87u;
|
|
445
|
+
}
|
|
446
|
+
return 0u;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
fn dggs_get_hex_character_code_or_invalid(byte: u32) -> u32 {
|
|
450
|
+
let lowercaseByte = dggs_get_lowercase_ascii(byte);
|
|
451
|
+
if (lowercaseByte >= 48u && lowercaseByte <= 57u) {
|
|
452
|
+
return lowercaseByte - 48u;
|
|
453
|
+
}
|
|
454
|
+
if (lowercaseByte >= 97u && lowercaseByte <= 102u) {
|
|
455
|
+
return lowercaseByte - 87u;
|
|
456
|
+
}
|
|
457
|
+
return 16u;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
fn dggs_parse_geohash_string(startOffset: u32, endOffset: u32) -> vec2u {
|
|
461
|
+
let stringLength = min(endOffset - startOffset, ${GEOHASH_MAXIMUM_LENGTH}u);
|
|
462
|
+
var key = vec2u(0u);
|
|
463
|
+
var characterIndex = 0u;
|
|
464
|
+
loop {
|
|
465
|
+
if (characterIndex >= stringLength) {
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
let characterCode = dggs_get_geohash_character_code(
|
|
469
|
+
dggs_read_string_byte(startOffset + characterIndex)
|
|
470
|
+
);
|
|
471
|
+
key = dggs_u64_shift_left(key, 5u) | vec2u(0u, characterCode);
|
|
472
|
+
characterIndex += 1u;
|
|
473
|
+
}
|
|
474
|
+
return dggs_u64_set_bits(key, ${GEOHASH_LENGTH_BIT_OFFSET}u, 4u, stringLength);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
fn dggs_parse_quadkey_string(startOffset: u32, endOffset: u32) -> vec2u {
|
|
478
|
+
let stringLength = min(endOffset - startOffset, ${QUADKEY_MAXIMUM_LENGTH}u);
|
|
479
|
+
var key = vec2u(0u);
|
|
480
|
+
var characterIndex = 0u;
|
|
481
|
+
loop {
|
|
482
|
+
if (characterIndex >= stringLength) {
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
let byte = dggs_read_string_byte(startOffset + characterIndex);
|
|
486
|
+
var digit = 0u;
|
|
487
|
+
if (byte >= 48u && byte <= 51u) {
|
|
488
|
+
digit = byte - 48u;
|
|
489
|
+
}
|
|
490
|
+
key = dggs_u64_shift_left(key, 2u) | vec2u(0u, digit);
|
|
491
|
+
characterIndex += 1u;
|
|
492
|
+
}
|
|
493
|
+
return dggs_u64_set_bits(key, ${QUADKEY_LENGTH_BIT_OFFSET}u, 6u, stringLength);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
fn dggs_parse_s2_token_string(startOffset: u32, endOffset: u32) -> vec2u {
|
|
497
|
+
let stringLength = endOffset - startOffset;
|
|
498
|
+
if (stringLength == 1u) {
|
|
499
|
+
let byte = dggs_get_lowercase_ascii(dggs_read_string_byte(startOffset));
|
|
500
|
+
if (byte == 120u) {
|
|
501
|
+
return vec2u(0u);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
var key = vec2u(0u);
|
|
506
|
+
var characterIndex = 0u;
|
|
507
|
+
loop {
|
|
508
|
+
if (characterIndex >= 16u) {
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
var digit = 0u;
|
|
512
|
+
if (characterIndex < stringLength) {
|
|
513
|
+
digit = dggs_get_hex_character_code(dggs_read_string_byte(startOffset + characterIndex));
|
|
514
|
+
}
|
|
515
|
+
key = dggs_u64_shift_left(key, 4u) | vec2u(0u, digit);
|
|
516
|
+
characterIndex += 1u;
|
|
517
|
+
}
|
|
518
|
+
return key;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
fn dggs_parse_a5_hex_string(startOffset: u32, endOffset: u32) -> vec2u {
|
|
522
|
+
var firstOffset = startOffset;
|
|
523
|
+
if (endOffset - firstOffset >= 2u) {
|
|
524
|
+
let firstByte = dggs_read_string_byte(firstOffset);
|
|
525
|
+
let secondByte = dggs_get_lowercase_ascii(dggs_read_string_byte(firstOffset + 1u));
|
|
526
|
+
if (firstByte == 48u && secondByte == 120u) {
|
|
527
|
+
firstOffset += 2u;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
let stringLength = endOffset - firstOffset;
|
|
532
|
+
if (stringLength == 0u || stringLength > ${A5_HEX_MAXIMUM_LENGTH}u) {
|
|
533
|
+
return vec2u(0u);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
var key = vec2u(0u);
|
|
537
|
+
var characterIndex = 0u;
|
|
538
|
+
loop {
|
|
539
|
+
if (characterIndex >= stringLength) {
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
let digit = dggs_get_hex_character_code_or_invalid(
|
|
543
|
+
dggs_read_string_byte(firstOffset + characterIndex)
|
|
544
|
+
);
|
|
545
|
+
if (digit >= 16u) {
|
|
546
|
+
return vec2u(0u);
|
|
547
|
+
}
|
|
548
|
+
key = dggs_u64_shift_left(key, 4u) | vec2u(0u, digit);
|
|
549
|
+
characterIndex += 1u;
|
|
550
|
+
}
|
|
551
|
+
return key;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
fn dggs_parse_h3_hex_string(startOffset: u32, endOffset: u32) -> vec2u {
|
|
555
|
+
return dggs_parse_a5_hex_string(startOffset, endOffset);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
@compute @workgroup_size(64)
|
|
559
|
+
fn main(@builtin(global_invocation_id) globalInvocationId : vec3u) {
|
|
560
|
+
let stringIndex = globalInvocationId.x;
|
|
561
|
+
if (stringIndex >= dggsStringParsingConfig[0]) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
let startOffset = dggsStringOffsets[stringIndex];
|
|
566
|
+
let endOffset = dggsStringOffsets[stringIndex + 1u];
|
|
567
|
+
let key = ${parsingFunction}(startOffset, endOffset);
|
|
568
|
+
dggsParsedKeys[stringIndex] = dggs_u64_to_little_endian_words(key);
|
|
569
|
+
}
|
|
570
|
+
`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
function getDggsStringParsingFunction(encoding) {
|
|
574
|
+
switch (encoding) {
|
|
575
|
+
case "geohash":
|
|
576
|
+
return "dggs_parse_geohash_string";
|
|
577
|
+
case "quadkey":
|
|
578
|
+
return "dggs_parse_quadkey_string";
|
|
579
|
+
case "s2":
|
|
580
|
+
return "dggs_parse_s2_token_string";
|
|
581
|
+
case "a5":
|
|
582
|
+
return "dggs_parse_a5_hex_string";
|
|
583
|
+
case "h3":
|
|
584
|
+
return "dggs_parse_h3_hex_string";
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function makeDggsCellPathCoordinateType(componentCount) {
|
|
588
|
+
const coordinateType = new import_apache_arrow.FixedSizeList(componentCount, new import_apache_arrow.Field("values", new import_apache_arrow.Float32(), false));
|
|
589
|
+
return new import_apache_arrow.List(new import_apache_arrow.Field("coordinates", coordinateType, false));
|
|
590
|
+
}
|
|
591
|
+
function getDggsCellPathCoordinateComponentCount(coordinateFormat) {
|
|
592
|
+
return coordinateFormat === "fp64-split" ? 4 : 2;
|
|
593
|
+
}
|
|
594
|
+
function makeFixedCellPathValueOffsets(cellCount, pointCount) {
|
|
595
|
+
const valueOffsets = new Int32Array(cellCount + 1);
|
|
596
|
+
for (let cellIndex = 0; cellIndex <= cellCount; cellIndex++) {
|
|
597
|
+
valueOffsets[cellIndex] = cellIndex * pointCount;
|
|
598
|
+
}
|
|
599
|
+
return valueOffsets;
|
|
600
|
+
}
|
|
601
|
+
function getDggsCellPolygonPointCount(encoding) {
|
|
602
|
+
switch (encoding) {
|
|
603
|
+
case "a5":
|
|
604
|
+
return DGGS_A5_CELL_POLYGON_POINT_COUNT;
|
|
605
|
+
case "h3":
|
|
606
|
+
return DGGS_H3_CELL_POLYGON_POINT_COUNT;
|
|
607
|
+
default:
|
|
608
|
+
return DGGS_DEFAULT_CELL_POLYGON_POINT_COUNT;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function assertDggsCellKeyVector(keys, callerName) {
|
|
612
|
+
const keyType = keys.dataType;
|
|
613
|
+
if (!import_apache_arrow.DataType.isInt(keyType) || keyType.bitWidth !== 64 || keyType.isSigned !== false) {
|
|
614
|
+
throw new Error(`${callerName} requires Uint64 keys`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function getUint64KeyVectorByteLength(keys) {
|
|
618
|
+
return keys.data.reduce((byteLength, data) => byteLength + data.length * data.byteStride, 0);
|
|
619
|
+
}
|
|
620
|
+
function getDggsUint64Words(value) {
|
|
621
|
+
const normalizedValue = BigInt.asUintN(64, value);
|
|
622
|
+
return [
|
|
623
|
+
Number(normalizedValue & UINT64_WORD_MASK),
|
|
624
|
+
Number(normalizedValue >> 32n & UINT64_WORD_MASK)
|
|
625
|
+
];
|
|
626
|
+
}
|
|
627
|
+
function getGPUDataBinding(data, size) {
|
|
628
|
+
return {
|
|
629
|
+
buffer: getGPUDataBuffer(data),
|
|
630
|
+
offset: data.byteOffset,
|
|
631
|
+
...size && size > 0 ? { size } : {}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function getGPUDataBuffer(data) {
|
|
635
|
+
return data.buffer instanceof import_dynamic.DynamicBuffer ? data.buffer.buffer : data.buffer;
|
|
636
|
+
}
|
|
637
|
+
function getNormalizedUtf8Offsets(data) {
|
|
638
|
+
const sourceOffsets = data.valueOffsets;
|
|
639
|
+
const normalizedOffsets = new Uint32Array(data.length + 1);
|
|
640
|
+
if (!sourceOffsets) {
|
|
641
|
+
return normalizedOffsets;
|
|
642
|
+
}
|
|
643
|
+
const firstOffset = sourceOffsets[0] ?? 0;
|
|
644
|
+
for (let offsetIndex = 0; offsetIndex <= data.length; offsetIndex++) {
|
|
645
|
+
normalizedOffsets[offsetIndex] = Math.max(0, (sourceOffsets[offsetIndex] ?? firstOffset) - firstOffset);
|
|
646
|
+
}
|
|
647
|
+
return normalizedOffsets;
|
|
648
|
+
}
|
|
649
|
+
function packUtf8BytesAsUint32Words(bytes) {
|
|
650
|
+
const packedWords = new Uint32Array(Math.max(1, Math.ceil(bytes.length / 4)));
|
|
651
|
+
for (let byteIndex = 0; byteIndex < bytes.length; byteIndex++) {
|
|
652
|
+
const wordIndex = byteIndex >> 2;
|
|
653
|
+
packedWords[wordIndex] = (packedWords[wordIndex] ?? 0) | (bytes[byteIndex] ?? 0) << (byteIndex & 3) * 8;
|
|
654
|
+
}
|
|
655
|
+
return packedWords;
|
|
656
|
+
}
|
|
657
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
658
|
+
0 && (module.exports = {
|
|
659
|
+
convertDggsCellIdsToGPUKeys,
|
|
660
|
+
convertDggsCellKeysToGPUPaths,
|
|
661
|
+
getDggsUint64Words,
|
|
662
|
+
packDggsA5CellKey,
|
|
663
|
+
packDggsGeohashKey,
|
|
664
|
+
packDggsH3CellKey,
|
|
665
|
+
packDggsQuadkeyKey,
|
|
666
|
+
packDggsS2CellKey
|
|
667
|
+
});
|