@luma.gl/graph 10.0.0-alpha.13 → 10.0.0-alpha.14
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/dist/arrow/arrow-colors.cjs +99 -18
- package/dist/arrow/arrow-colors.d.ts +27 -10
- package/dist/arrow/arrow-colors.d.ts.map +1 -1
- package/dist/arrow/arrow-colors.js +107 -24
- package/dist/arrow/arrow-colors.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +2 -0
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts +1 -0
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +32 -3
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +6 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +37 -3
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/dist.dev.js +19 -4
- package/dist/dist.min.js +38 -38
- package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-operation.js +1 -1
- package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
- package/dist/gpu-data/color-conversion.cjs +105 -0
- package/dist/gpu-data/color-conversion.d.ts +30 -0
- package/dist/gpu-data/color-conversion.d.ts.map +1 -0
- package/dist/gpu-data/color-conversion.js +109 -0
- package/dist/gpu-data/color-conversion.js.map +1 -0
- package/dist/gpu-data/index.cjs +7 -2
- package/dist/gpu-data/index.cjs.map +3 -3
- package/dist/gpu-data/index.d.ts +2 -0
- package/dist/gpu-data/index.d.ts.map +1 -1
- package/dist/gpu-data/index.js +1 -0
- package/dist/gpu-data/index.js.map +1 -1
- package/dist/gpu-project/graph.cjs.map +3 -3
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/index.d.ts +1 -1
- package/dist/gpu-simple-graph/index.d.ts.map +1 -1
- package/dist/gpu-simple-graph/index.js.map +1 -1
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +2 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +3 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
- package/dist/gpu-simple-graph/operations/convert-colors.cjs +6 -6
- package/dist/gpu-simple-graph/operations/convert-colors.d.ts +5 -1
- package/dist/gpu-simple-graph/operations/convert-colors.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operations/convert-colors.js +12 -7
- package/dist/gpu-simple-graph/operations/convert-colors.js.map +1 -1
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.cjs +16 -33
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.js +22 -35
- package/dist/gpu-simple-graph/operations/cpu/convert-colors.js.map +1 -1
- package/dist/gpu-simple-graph/operations/cpu/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.cjs +31 -13
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js +42 -13
- package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js.map +1 -1
- package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +1 -1
- package/dist/gpu-sql/gpu-sql.js +1 -1
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +1 -1
- package/package.json +8 -7
- package/src/arrow/arrow-colors.ts +194 -33
- package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +3 -1
- package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +46 -4
- package/src/gpu-core/gpu-expression-operation.ts +1 -1
- package/src/gpu-data/color-conversion.ts +158 -0
- package/src/gpu-data/index.ts +3 -0
- package/src/gpu-simple-graph/index.ts +1 -0
- package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +2 -0
- package/src/gpu-simple-graph/operations/convert-colors.ts +22 -7
- package/src/gpu-simple-graph/operations/cpu/convert-colors.ts +31 -48
- package/src/gpu-simple-graph/operations/webgpu/convert-colors.ts +47 -13
- package/src/gpu-sql/gpu-sql.ts +2 -2
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "10.0.0-alpha.
|
|
6
|
+
"version": "10.0.0-alpha.14",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -242,8 +242,8 @@
|
|
|
242
242
|
}
|
|
243
243
|
},
|
|
244
244
|
"peerDependencies": {
|
|
245
|
-
"@luma.gl/core": "~10.0.0-alpha.
|
|
246
|
-
"@luma.gl/shaders": "~10.0.0-alpha.
|
|
245
|
+
"@luma.gl/core": "~10.0.0-alpha.14",
|
|
246
|
+
"@luma.gl/shaders": "~10.0.0-alpha.14",
|
|
247
247
|
"apache-arrow": ">=17.0.0"
|
|
248
248
|
},
|
|
249
249
|
"peerDependenciesMeta": {
|
|
@@ -252,10 +252,11 @@
|
|
|
252
252
|
}
|
|
253
253
|
},
|
|
254
254
|
"dependencies": {
|
|
255
|
-
"@math.gl/arrow": "~5.0.0-beta.
|
|
256
|
-
"@math.gl/core": "~5.0.0-beta.
|
|
257
|
-
"@math.gl/
|
|
255
|
+
"@math.gl/arrow": "~5.0.0-beta.8",
|
|
256
|
+
"@math.gl/core": "~5.0.0-beta.8",
|
|
257
|
+
"@math.gl/expressions": "~5.0.0-beta.8",
|
|
258
|
+
"@math.gl/geospatial": "~5.0.0-beta.8",
|
|
258
259
|
"probe.gl": "^5.0.0"
|
|
259
260
|
},
|
|
260
|
-
"gitHead": "
|
|
261
|
+
"gitHead": "8d01b6b1f5dc0300a3980328f93bfbb0009134c9"
|
|
261
262
|
}
|
|
@@ -9,20 +9,40 @@ import {
|
|
|
9
9
|
} from '../gpu-simple-graph/operations/convert-colors';
|
|
10
10
|
import {GPUDataEvaluator} from '../gpu-simple-graph/operation/gpu-data-evaluator';
|
|
11
11
|
import {GPUVectorEvaluator} from '../gpu-simple-graph/operation/gpu-vector-evaluator';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
CPUData,
|
|
14
|
+
CPUVector,
|
|
15
|
+
resolveColorOutputFormat,
|
|
16
|
+
getGPUVectorFormatInfo,
|
|
17
|
+
GPUData,
|
|
18
|
+
GPUVector,
|
|
19
|
+
type ColorConversionOptions,
|
|
20
|
+
type ColorOutputFormat,
|
|
21
|
+
type GPUVectorBufferProps
|
|
22
|
+
} from '@luma.gl/graph/gpu-data';
|
|
13
23
|
import {DataType, Field, FixedSizeList, Float16, Float32, Uint8, Vector} from 'apache-arrow';
|
|
14
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
makeArrowGPUValidityBitmap,
|
|
26
|
+
makeGPUVectorFromArrow,
|
|
27
|
+
readArrowGPUVectorAsync
|
|
28
|
+
} from './gpu/arrow-gpu-vector-adapters';
|
|
29
|
+
import {getArrowDataBufferSource, getArrowFixedSizeListRowValidity} from './gpu/arrow-gpu-data';
|
|
15
30
|
import type {GPUDataReadbackMetadata} from './gpu/arrow-gpu-data';
|
|
31
|
+
import type {AttributeArrowType} from './arrow-utils/arrow-types';
|
|
32
|
+
import type {Data} from 'apache-arrow';
|
|
33
|
+
import {convertCPUColorData} from '../gpu-data/color-conversion';
|
|
16
34
|
|
|
17
35
|
export type ArrowColorType = FixedSizeList<Uint8> | FixedSizeList<Float16> | FixedSizeList<Float32>;
|
|
18
36
|
type ArrowUint8ColorType = FixedSizeList<Uint8>;
|
|
19
37
|
|
|
20
|
-
type ConvertColorsProps = {
|
|
38
|
+
type ConvertColorsProps = ColorConversionOptions & {
|
|
21
39
|
name?: string;
|
|
22
40
|
inputFormat?: ColorInputFormat;
|
|
23
41
|
};
|
|
24
42
|
|
|
25
|
-
type ConvertArrowColorsProps = {
|
|
43
|
+
type ConvertArrowColorsProps = ColorConversionOptions & {
|
|
44
|
+
/** Convert Arrow payloads before uploading; avoids source upload and readback on CPU backends. */
|
|
45
|
+
preferCPU?: boolean;
|
|
26
46
|
name?: string;
|
|
27
47
|
bufferProps?: GPUVectorBufferProps;
|
|
28
48
|
};
|
|
@@ -32,45 +52,76 @@ const ARROW_UINT8_COLOR_TYPE = new FixedSizeList(
|
|
|
32
52
|
new Field('value', new Uint8(), false)
|
|
33
53
|
) as ArrowUint8ColorType;
|
|
34
54
|
|
|
35
|
-
/** Converts fixed-width GPU RGB/RGBA chunks
|
|
55
|
+
/** Converts fixed-width GPU RGB/RGBA chunks; preserve returns a borrowed wrapper when compatible. */
|
|
56
|
+
export function convertColors(
|
|
57
|
+
device: Device,
|
|
58
|
+
colors: GPUVector,
|
|
59
|
+
props?: ConvertColorsProps & {format?: 'unorm8x4'}
|
|
60
|
+
): Promise<GPUVector<'unorm8x4'>>;
|
|
61
|
+
export function convertColors<T extends ColorOutputFormat>(
|
|
62
|
+
device: Device,
|
|
63
|
+
colors: GPUVector,
|
|
64
|
+
props: ConvertColorsProps & {format: T}
|
|
65
|
+
): Promise<GPUVector<T>>;
|
|
66
|
+
export function convertColors(
|
|
67
|
+
device: Device,
|
|
68
|
+
colors: GPUVector,
|
|
69
|
+
props: ConvertColorsProps
|
|
70
|
+
): Promise<GPUVector<ColorOutputFormat>>;
|
|
36
71
|
export async function convertColors(
|
|
37
72
|
device: Device,
|
|
38
73
|
colors: GPUVector,
|
|
39
74
|
props: ConvertColorsProps = {}
|
|
40
|
-
): Promise<GPUVector<
|
|
75
|
+
): Promise<GPUVector<ColorOutputFormat>> {
|
|
76
|
+
const format = resolveColorOutputFormat(
|
|
77
|
+
props.inputFormat?.startsWith('float16') ? 'float16x4' : colors.format!,
|
|
78
|
+
props
|
|
79
|
+
);
|
|
80
|
+
const outputType = getColorArrowType(format);
|
|
81
|
+
const byteStride = getGPUVectorFormatInfo(format).byteLength;
|
|
82
|
+
if (props.format === 'preserve' && colors.format === format) {
|
|
83
|
+
return new GPUVector<ColorOutputFormat>({
|
|
84
|
+
type: 'data',
|
|
85
|
+
name: props.name ?? colors.name,
|
|
86
|
+
format,
|
|
87
|
+
dataType: outputType,
|
|
88
|
+
data: colors.data as GPUData<ColorOutputFormat>[],
|
|
89
|
+
ownsData: false
|
|
90
|
+
});
|
|
91
|
+
}
|
|
41
92
|
const source = GPUVectorEvaluator.fromGPUVector(colors);
|
|
42
93
|
const converted = source.mapGPUData(data =>
|
|
43
|
-
convertColorData(data, {inputFormat: props.inputFormat})
|
|
94
|
+
convertColorData(data, {inputFormat: props.inputFormat, format})
|
|
44
95
|
);
|
|
45
|
-
const outputBuffers =
|
|
46
|
-
const buffer = device.createBuffer({
|
|
47
|
-
id: `${props.name ?? 'colors'}-${chunkIndex}`,
|
|
48
|
-
usage: Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_DST | Buffer.COPY_SRC,
|
|
49
|
-
byteLength: evaluator.byteLength
|
|
50
|
-
});
|
|
51
|
-
evaluator.setTargetBuffer({buffer});
|
|
52
|
-
return buffer;
|
|
53
|
-
});
|
|
54
|
-
|
|
96
|
+
const outputBuffers: Buffer[] = [];
|
|
55
97
|
try {
|
|
98
|
+
converted.gpuDataEvaluators.forEach((evaluator, chunkIndex) => {
|
|
99
|
+
const buffer = device.createBuffer({
|
|
100
|
+
id: `${props.name ?? 'colors'}-${chunkIndex}`,
|
|
101
|
+
usage: Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_DST | Buffer.COPY_SRC,
|
|
102
|
+
byteLength: Math.max(evaluator.byteLength, 4)
|
|
103
|
+
});
|
|
104
|
+
evaluator.setTargetBuffer({buffer});
|
|
105
|
+
outputBuffers.push(buffer);
|
|
106
|
+
});
|
|
56
107
|
const evaluated = await converted.evaluate(device, {
|
|
57
108
|
name: props.name ?? 'colors',
|
|
58
|
-
format
|
|
109
|
+
format
|
|
59
110
|
});
|
|
60
111
|
const data = evaluated.data.map((chunk, chunkIndex) => {
|
|
61
112
|
const sourceData = colors.data[chunkIndex];
|
|
62
113
|
const readbackMetadata = sourceData
|
|
63
114
|
? getConvertedColorReadbackMetadata(sourceData)
|
|
64
115
|
: undefined;
|
|
65
|
-
return new GPUData<
|
|
116
|
+
return new GPUData<ColorOutputFormat>({
|
|
66
117
|
buffer: outputBuffers[chunkIndex],
|
|
67
|
-
dataType:
|
|
68
|
-
format
|
|
118
|
+
dataType: outputType,
|
|
119
|
+
format,
|
|
69
120
|
length: chunk.length,
|
|
70
121
|
stride: 4,
|
|
71
122
|
byteOffset: chunk.byteOffset,
|
|
72
|
-
byteStride
|
|
73
|
-
rowByteLength:
|
|
123
|
+
byteStride,
|
|
124
|
+
rowByteLength: byteStride,
|
|
74
125
|
ownsBuffer: true,
|
|
75
126
|
nullBitmap: readbackMetadata?.nullBitmap,
|
|
76
127
|
readbackMetadata
|
|
@@ -80,8 +131,8 @@ export async function convertColors(
|
|
|
80
131
|
return new GPUVector({
|
|
81
132
|
type: 'data',
|
|
82
133
|
name: evaluated.name,
|
|
83
|
-
dataType:
|
|
84
|
-
format
|
|
134
|
+
dataType: outputType,
|
|
135
|
+
format,
|
|
85
136
|
data,
|
|
86
137
|
ownsData: true
|
|
87
138
|
});
|
|
@@ -96,7 +147,7 @@ export async function convertColors(
|
|
|
96
147
|
}
|
|
97
148
|
}
|
|
98
149
|
|
|
99
|
-
/** Returns true
|
|
150
|
+
/** Returns true for supported fixed-width RGB/RGBA Arrow or GPU inputs. */
|
|
100
151
|
export function canConvertColors(colors: GPUVector | Vector): boolean {
|
|
101
152
|
try {
|
|
102
153
|
if (colors instanceof GPUVector) {
|
|
@@ -117,14 +168,105 @@ export function canConvertColors(colors: GPUVector | Vector): boolean {
|
|
|
117
168
|
}
|
|
118
169
|
}
|
|
119
170
|
|
|
120
|
-
/**
|
|
171
|
+
/** Converts Arrow RGB/RGBA chunks to selected storage without changing color space or alpha convention. */
|
|
172
|
+
export function convertArrowColors(
|
|
173
|
+
device: Device,
|
|
174
|
+
colors: Vector<ArrowColorType>,
|
|
175
|
+
props?: ConvertArrowColorsProps & {format?: 'unorm8x4'}
|
|
176
|
+
): Promise<GPUVector<'unorm8x4'>>;
|
|
177
|
+
export function convertArrowColors<T extends ColorOutputFormat>(
|
|
178
|
+
device: Device,
|
|
179
|
+
colors: Vector<ArrowColorType>,
|
|
180
|
+
props: ConvertArrowColorsProps & {format: T}
|
|
181
|
+
): Promise<GPUVector<T>>;
|
|
182
|
+
export function convertArrowColors(
|
|
183
|
+
device: Device,
|
|
184
|
+
colors: Vector<ArrowColorType>,
|
|
185
|
+
props: ConvertArrowColorsProps
|
|
186
|
+
): Promise<GPUVector<ColorOutputFormat>>;
|
|
121
187
|
export async function convertArrowColors(
|
|
122
188
|
device: Device,
|
|
123
189
|
colors: Vector<ArrowColorType>,
|
|
124
190
|
props: ConvertArrowColorsProps = {}
|
|
125
|
-
): Promise<GPUVector<
|
|
191
|
+
): Promise<GPUVector<ColorOutputFormat>> {
|
|
126
192
|
validateArrowColorType(colors.type, 'convertArrowColors');
|
|
127
193
|
const inputFormat = getArrowColorInputFormat(colors.type);
|
|
194
|
+
const sourceFormat = getArrowColorGPUFormat(inputFormat);
|
|
195
|
+
const format = resolveColorOutputFormat(
|
|
196
|
+
inputFormat.startsWith('float16') ? 'float16x4' : sourceFormat,
|
|
197
|
+
props
|
|
198
|
+
);
|
|
199
|
+
if (
|
|
200
|
+
props.format === 'preserve' &&
|
|
201
|
+
(sourceFormat === format || (sourceFormat === 'uint8x4' && format === 'unorm8x4'))
|
|
202
|
+
) {
|
|
203
|
+
return makeGPUVectorFromArrow(device, colors, {
|
|
204
|
+
...props.bufferProps,
|
|
205
|
+
name: props.name ?? 'colors',
|
|
206
|
+
format,
|
|
207
|
+
preserveDataChunks: true
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (props.preferCPU || device.type !== 'webgpu') {
|
|
211
|
+
const cpuSource = new CPUVector({
|
|
212
|
+
name: props.name ?? 'colors',
|
|
213
|
+
format: sourceFormat,
|
|
214
|
+
data: colors.data.map(
|
|
215
|
+
chunk =>
|
|
216
|
+
new CPUData({
|
|
217
|
+
buffer: getArrowDataBufferSource(chunk as Data<AttributeArrowType>),
|
|
218
|
+
format: sourceFormat,
|
|
219
|
+
length: chunk.length,
|
|
220
|
+
nullBitmap: makeArrowGPUValidityBitmap(getArrowFixedSizeListRowValidity(chunk))
|
|
221
|
+
})
|
|
222
|
+
)
|
|
223
|
+
});
|
|
224
|
+
const data: GPUData<ColorOutputFormat>[] = [];
|
|
225
|
+
try {
|
|
226
|
+
for (const chunk of cpuSource.data) {
|
|
227
|
+
const converted = convertCPUColorData(chunk, format, inputFormat);
|
|
228
|
+
const bytes = new Uint8Array(
|
|
229
|
+
converted.buffer,
|
|
230
|
+
converted.byteOffset,
|
|
231
|
+
converted.length * converted.byteStride
|
|
232
|
+
);
|
|
233
|
+
const readbackMetadata = getConvertedColorReadbackMetadata({
|
|
234
|
+
nullBitmap: chunk.nullBitmap,
|
|
235
|
+
length: chunk.length
|
|
236
|
+
});
|
|
237
|
+
data.push(
|
|
238
|
+
new GPUData({
|
|
239
|
+
buffer: device.createBuffer({
|
|
240
|
+
...props.bufferProps,
|
|
241
|
+
byteLength: Math.max(bytes.length, 4),
|
|
242
|
+
data: bytes.length ? bytes : new Uint8Array(4),
|
|
243
|
+
usage:
|
|
244
|
+
props.bufferProps?.usage ??
|
|
245
|
+
Buffer.VERTEX | Buffer.STORAGE | Buffer.COPY_DST | Buffer.COPY_SRC
|
|
246
|
+
}),
|
|
247
|
+
format,
|
|
248
|
+
dataType: getColorArrowType(format),
|
|
249
|
+
length: chunk.length,
|
|
250
|
+
ownsBuffer: true,
|
|
251
|
+
nullBitmap: readbackMetadata?.nullBitmap,
|
|
252
|
+
readbackMetadata
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
return new GPUVector({
|
|
257
|
+
type: 'data',
|
|
258
|
+
name: props.name ?? 'colors',
|
|
259
|
+
format,
|
|
260
|
+
dataType: getColorArrowType(format),
|
|
261
|
+
data,
|
|
262
|
+
ownsData: true
|
|
263
|
+
});
|
|
264
|
+
} catch (error) {
|
|
265
|
+
for (const chunk of data) chunk.destroy();
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
128
270
|
const source = makeGPUVectorFromArrow(device, colors, {
|
|
129
271
|
...props.bufferProps,
|
|
130
272
|
name: props.name ? `${props.name}-source` : 'colors-source',
|
|
@@ -135,22 +277,33 @@ export async function convertArrowColors(
|
|
|
135
277
|
try {
|
|
136
278
|
return await convertColors(device, source, {
|
|
137
279
|
name: props.name ?? 'colors',
|
|
138
|
-
inputFormat
|
|
280
|
+
inputFormat,
|
|
281
|
+
format
|
|
139
282
|
});
|
|
140
283
|
} finally {
|
|
141
284
|
source.destroy();
|
|
142
285
|
}
|
|
143
286
|
}
|
|
144
287
|
|
|
145
|
-
/**
|
|
288
|
+
/** Converts color storage and reads it back; floating outputs retain HDR and negative channels. */
|
|
289
|
+
export function convertArrowColorsToArrow(
|
|
290
|
+
device: Device,
|
|
291
|
+
colors: Vector<ArrowColorType>,
|
|
292
|
+
props?: ConvertArrowColorsProps & {format?: 'unorm8x4'}
|
|
293
|
+
): Promise<Vector<ArrowUint8ColorType>>;
|
|
294
|
+
export function convertArrowColorsToArrow(
|
|
295
|
+
device: Device,
|
|
296
|
+
colors: Vector<ArrowColorType>,
|
|
297
|
+
props: ConvertArrowColorsProps
|
|
298
|
+
): Promise<Vector<ArrowColorType>>;
|
|
146
299
|
export async function convertArrowColorsToArrow(
|
|
147
300
|
device: Device,
|
|
148
301
|
colors: Vector<ArrowColorType>,
|
|
149
302
|
props: ConvertArrowColorsProps = {}
|
|
150
|
-
): Promise<Vector<
|
|
303
|
+
): Promise<Vector<ArrowColorType>> {
|
|
151
304
|
const converted = await convertArrowColors(device, colors, props);
|
|
152
305
|
try {
|
|
153
|
-
return await readArrowGPUVectorAsync<
|
|
306
|
+
return await readArrowGPUVectorAsync<ArrowColorType>(converted);
|
|
154
307
|
} finally {
|
|
155
308
|
converted.destroy();
|
|
156
309
|
}
|
|
@@ -213,7 +366,7 @@ function getArrowColorGPUFormat(inputFormat: ColorInputFormat): VertexFormat {
|
|
|
213
366
|
}
|
|
214
367
|
|
|
215
368
|
function getConvertedColorReadbackMetadata(
|
|
216
|
-
source: GPUData
|
|
369
|
+
source: Pick<GPUData, 'nullBitmap' | 'length'>
|
|
217
370
|
): Extract<GPUDataReadbackMetadata, {kind: 'fixed-size-list'}> | undefined {
|
|
218
371
|
const sourceNullBitmap = source.nullBitmap;
|
|
219
372
|
if (!sourceNullBitmap) {
|
|
@@ -231,3 +384,11 @@ function getConvertedColorReadbackMetadata(
|
|
|
231
384
|
? {kind: 'fixed-size-list', nullCount, nullBitmap, childNullCount: 0}
|
|
232
385
|
: undefined;
|
|
233
386
|
}
|
|
387
|
+
|
|
388
|
+
function getColorArrowType(format: ColorOutputFormat): ArrowColorType {
|
|
389
|
+
return format === 'unorm8x4'
|
|
390
|
+
? ARROW_UINT8_COLOR_TYPE
|
|
391
|
+
: format === 'float16x4'
|
|
392
|
+
? new FixedSizeList(4, new Field('value', new Float16(), false))
|
|
393
|
+
: new FixedSizeList(4, new Field('value', new Float32(), false));
|
|
394
|
+
}
|
|
@@ -507,7 +507,9 @@ function getArrowDataValueLength(data: Data): number {
|
|
|
507
507
|
return Math.max(0, lastValueOffset - firstValueOffset);
|
|
508
508
|
}
|
|
509
509
|
|
|
510
|
-
function makeArrowGPUValidityBitmap(
|
|
510
|
+
export function makeArrowGPUValidityBitmap(
|
|
511
|
+
validity: Uint32Array | undefined
|
|
512
|
+
): Uint8Array | undefined {
|
|
511
513
|
if (!validity) {
|
|
512
514
|
return undefined;
|
|
513
515
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type GPUVectorBufferProps,
|
|
14
14
|
type GPUVectorFormat
|
|
15
15
|
} from '@luma.gl/graph/gpu-data';
|
|
16
|
+
import {resolveColorOutputFormat, type ColorOutputFormat} from '../../gpu-data/color-conversion';
|
|
16
17
|
import {castData} from '../../gpu-simple-graph/operations/cast-data';
|
|
17
18
|
import {fround} from '../../gpu-simple-graph/operations/fround';
|
|
18
19
|
import {GPUDataEvaluator} from '../../gpu-simple-graph/operation/gpu-data-evaluator';
|
|
@@ -113,7 +114,11 @@ export type ArrowGPUConversionOptions = {
|
|
|
113
114
|
/** Semantic conversion family. `auto` recognizes temporal and metadata-tagged matrices. */
|
|
114
115
|
semantic?: ArrowGPUConversionSemantic;
|
|
115
116
|
/** One required output memory format. */
|
|
116
|
-
format?: GPUVectorFormat;
|
|
117
|
+
format?: GPUVectorFormat | 'preserve';
|
|
118
|
+
/** Consumer color storage capabilities, checked independently of the requested policy. */
|
|
119
|
+
acceptedFormats?: readonly ColorOutputFormat[];
|
|
120
|
+
/** Explicit fallback when preserved color precision is not accepted. */
|
|
121
|
+
fallbackFormat?: ColorOutputFormat;
|
|
117
122
|
/** Ordered acceptable output formats. The planner selects the first compatible format. */
|
|
118
123
|
formats?: readonly GPUVectorFormat[];
|
|
119
124
|
/** Strategy constraint. */
|
|
@@ -265,9 +270,14 @@ export async function convertArrowToGPUVector(
|
|
|
265
270
|
case 'convert-color': {
|
|
266
271
|
const vector =
|
|
267
272
|
source instanceof GPUVector
|
|
268
|
-
? await convertColors(device, source, {
|
|
273
|
+
? await convertColors(device, source, {
|
|
274
|
+
name,
|
|
275
|
+
format: plan.targetFormat as ColorOutputFormat
|
|
276
|
+
})
|
|
269
277
|
: await convertArrowColors(device, source as Parameters<typeof convertArrowColors>[1], {
|
|
270
278
|
name,
|
|
279
|
+
format: plan.targetFormat as ColorOutputFormat,
|
|
280
|
+
preferCPU: plan.backend === 'cpu',
|
|
271
281
|
bufferProps: options.bufferProps
|
|
272
282
|
});
|
|
273
283
|
return makePreparedArrowGPUVector(vector, plan, true);
|
|
@@ -368,10 +378,33 @@ function resolveTargetFormat(
|
|
|
368
378
|
options: ArrowGPUConversionOptions
|
|
369
379
|
): GPUVectorFormat {
|
|
370
380
|
const canonicalFormat = getCanonicalSemanticFormat(semantic, source, sourceFormat, options.field);
|
|
381
|
+
if (semantic === 'color') {
|
|
382
|
+
const requested =
|
|
383
|
+
options.format ??
|
|
384
|
+
options.formats?.find(format => ['unorm8x4', 'float16x4', 'float32x4'].includes(format)) ??
|
|
385
|
+
'unorm8x4';
|
|
386
|
+
if (!['preserve', 'unorm8x4', 'float16x4', 'float32x4'].includes(requested))
|
|
387
|
+
throw new Error('Unsupported color output format');
|
|
388
|
+
if (options.formats && !options.formats.includes(requested as GPUVectorFormat))
|
|
389
|
+
throw new Error('No compatible color output format');
|
|
390
|
+
return resolveColorOutputFormat(
|
|
391
|
+
source instanceof Vector &&
|
|
392
|
+
DataType.isFixedSizeList(source.type) &&
|
|
393
|
+
source.type.children[0].type instanceof Float16
|
|
394
|
+
? 'float16x4'
|
|
395
|
+
: (sourceFormat ?? canonicalFormat),
|
|
396
|
+
{
|
|
397
|
+
format: requested as ColorOutputFormat | 'preserve',
|
|
398
|
+
acceptedFormats: options.acceptedFormats,
|
|
399
|
+
fallbackFormat: options.fallbackFormat
|
|
400
|
+
}
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
if (options.format === 'preserve') throw new Error('preserve requires color semantics');
|
|
371
404
|
const requestedFormats = options.format ? [options.format] : options.formats;
|
|
372
405
|
if (!requestedFormats?.length) return canonicalFormat;
|
|
373
406
|
|
|
374
|
-
if (semantic === '
|
|
407
|
+
if (semantic === 'matrix' || semantic === 'temporal') {
|
|
375
408
|
if (!requestedFormats.includes(canonicalFormat)) {
|
|
376
409
|
throw new Error(
|
|
377
410
|
`Arrow ${semantic} conversion produces ${canonicalFormat}, not ${requestedFormats.join(', ')}`
|
|
@@ -435,7 +468,8 @@ function resolveConversionStrategy(
|
|
|
435
468
|
if (!sourceFormat || !areGPUFormatsByteCompatible(sourceFormat, targetFormat)) {
|
|
436
469
|
return 'convert-color';
|
|
437
470
|
}
|
|
438
|
-
if (source instanceof GPUVector)
|
|
471
|
+
if (source instanceof GPUVector)
|
|
472
|
+
return sourceFormat === targetFormat ? 'borrow' : 'convert-color';
|
|
439
473
|
return sourceFormat === targetFormat ? 'upload' : 'reinterpret-upload';
|
|
440
474
|
}
|
|
441
475
|
if (semantic === 'matrix') {
|
|
@@ -478,6 +512,8 @@ function resolveConversionBackend(
|
|
|
478
512
|
if (strategy === 'borrow') return 'none';
|
|
479
513
|
if (strategy === 'upload' || strategy === 'reinterpret-upload') return 'upload';
|
|
480
514
|
if (strategy === 'convert-matrix' && source instanceof Vector) return 'cpu';
|
|
515
|
+
if (strategy === 'convert-color' && source instanceof Vector && policy === 'prefer-cpu')
|
|
516
|
+
return 'cpu';
|
|
481
517
|
if (
|
|
482
518
|
strategy === 'convert-numeric' &&
|
|
483
519
|
source instanceof Vector &&
|
|
@@ -1060,6 +1096,12 @@ function getConversionWarnings(
|
|
|
1060
1096
|
backend: ArrowGPUConversionBackend
|
|
1061
1097
|
): string[] {
|
|
1062
1098
|
const warnings: string[] = [];
|
|
1099
|
+
if (strategy === 'convert-color') {
|
|
1100
|
+
if (targetFormat === 'unorm8x4')
|
|
1101
|
+
warnings.push('floating color channels are clamped and quantized to RGBA8');
|
|
1102
|
+
if (targetFormat === 'float16x4')
|
|
1103
|
+
warnings.push('color channels are rounded to binary16; out-of-range values may overflow');
|
|
1104
|
+
}
|
|
1063
1105
|
const sourceType = getSourceArrowType(source);
|
|
1064
1106
|
const leafType = sourceType ? getArrowNumericLeafType(sourceType) : undefined;
|
|
1065
1107
|
if (
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {parse, type Expression} from '@math.gl/
|
|
5
|
+
import {parse, type Expression} from '@math.gl/expressions';
|
|
6
6
|
import {getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
7
7
|
import {gpuGraph, type GPUGraphVectorFormat} from './gpu-graph-value';
|
|
8
8
|
import type {GPUOperationContract} from './gpu-operation-contract';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {assert} from '@luma.gl/core';
|
|
6
|
+
import {fromHalfFloat} from '@luma.gl/shaders';
|
|
7
|
+
import {CPUData} from './cpu-data';
|
|
8
|
+
import {CPUVector} from './cpu-vector';
|
|
9
|
+
import {getGPUVectorFormatInfo, type GPUVectorFormat} from './gpu-vector-format';
|
|
10
|
+
|
|
11
|
+
export type ColorOutputFormat = 'unorm8x4' | 'float16x4' | 'float32x4';
|
|
12
|
+
export type ColorConversionOptions = {
|
|
13
|
+
/** Default RGBA8; preserve keeps source precision while expanding RGB to RGBA. */
|
|
14
|
+
format?: ColorOutputFormat | 'preserve';
|
|
15
|
+
/** Consumer capabilities; never silently select a lossy fallback. */
|
|
16
|
+
acceptedFormats?: readonly ColorOutputFormat[];
|
|
17
|
+
fallbackFormat?: ColorOutputFormat;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Resolve color storage independently from the device and conversion backend. */
|
|
21
|
+
export function resolveColorOutputFormat(
|
|
22
|
+
sourceFormat: GPUVectorFormat,
|
|
23
|
+
options: ColorConversionOptions = {}
|
|
24
|
+
): ColorOutputFormat {
|
|
25
|
+
const info = getGPUVectorFormatInfo(sourceFormat);
|
|
26
|
+
// Only fixed-width byte/IEEE RGB or RGBA rows have color semantics here.
|
|
27
|
+
assert(
|
|
28
|
+
!info.vertexList &&
|
|
29
|
+
!info.valueList &&
|
|
30
|
+
!info.fixedSizeList &&
|
|
31
|
+
(info.components === 3 || info.components === 4) &&
|
|
32
|
+
['uint8', 'float16', 'float32'].includes(info.signedDataType)
|
|
33
|
+
);
|
|
34
|
+
const preserved =
|
|
35
|
+
info.signedDataType === 'float32'
|
|
36
|
+
? 'float32x4'
|
|
37
|
+
: info.signedDataType === 'float16'
|
|
38
|
+
? 'float16x4'
|
|
39
|
+
: 'unorm8x4';
|
|
40
|
+
let format = options.format === 'preserve' ? preserved : (options.format ?? 'unorm8x4');
|
|
41
|
+
if (options.acceptedFormats && !options.acceptedFormats.includes(format)) {
|
|
42
|
+
if (
|
|
43
|
+
options.format === 'preserve' &&
|
|
44
|
+
options.fallbackFormat &&
|
|
45
|
+
options.acceptedFormats.includes(options.fallbackFormat)
|
|
46
|
+
)
|
|
47
|
+
format = options.fallbackFormat;
|
|
48
|
+
else throw new Error('Requested color format is not accepted by the consumer');
|
|
49
|
+
}
|
|
50
|
+
return format;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** CPU storage interpretation, independent of output format negotiation. */
|
|
54
|
+
type CPUColorConversionOptions = ColorConversionOptions & {
|
|
55
|
+
/** Interpret packed Float16 RGB stored using the uint16x3-webgl alias. */
|
|
56
|
+
inputFormat?: 'float16x3';
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Convert CPU color chunks without uploading or combining chunks. Input storage is borrowed. */
|
|
60
|
+
export function convertCPUColors(
|
|
61
|
+
source: CPUVector,
|
|
62
|
+
options?: CPUColorConversionOptions & {format?: 'unorm8x4'}
|
|
63
|
+
): CPUVector<'unorm8x4'>;
|
|
64
|
+
export function convertCPUColors<T extends ColorOutputFormat>(
|
|
65
|
+
source: CPUVector,
|
|
66
|
+
options: CPUColorConversionOptions & {format: T}
|
|
67
|
+
): CPUVector<T>;
|
|
68
|
+
export function convertCPUColors(
|
|
69
|
+
source: CPUVector,
|
|
70
|
+
options: CPUColorConversionOptions
|
|
71
|
+
): CPUVector<ColorOutputFormat>;
|
|
72
|
+
export function convertCPUColors(
|
|
73
|
+
source: CPUVector,
|
|
74
|
+
options: CPUColorConversionOptions = {}
|
|
75
|
+
): CPUVector<ColorOutputFormat> {
|
|
76
|
+
const format = resolveColorOutputFormat(
|
|
77
|
+
options.inputFormat ? 'float16x4' : source.format,
|
|
78
|
+
options
|
|
79
|
+
);
|
|
80
|
+
if (options.format === 'preserve' && source.format === format)
|
|
81
|
+
return new CPUVector({
|
|
82
|
+
name: source.name,
|
|
83
|
+
format,
|
|
84
|
+
data: source.data as readonly CPUData<ColorOutputFormat>[]
|
|
85
|
+
});
|
|
86
|
+
return new CPUVector({
|
|
87
|
+
name: source.name,
|
|
88
|
+
format,
|
|
89
|
+
data: source.data.map(chunk => convertCPUColorData(chunk, format, options.inputFormat))
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @internal Shared CPU backend implementation, including offsets, strides and validity. */
|
|
94
|
+
export function convertCPUColorData(
|
|
95
|
+
source: CPUData,
|
|
96
|
+
format: ColorOutputFormat,
|
|
97
|
+
inputFormat?: string
|
|
98
|
+
): CPUData<ColorOutputFormat> {
|
|
99
|
+
const info = getGPUVectorFormatInfo(source.format);
|
|
100
|
+
const type = inputFormat?.startsWith('float16') ? 'float16' : info.signedDataType;
|
|
101
|
+
const components = inputFormat?.endsWith('x3') ? 3 : info.components;
|
|
102
|
+
// Color rows contain only byte channels or IEEE floats and three or four components.
|
|
103
|
+
assert((components === 3 || components === 4) && ['uint8', 'float16', 'float32'].includes(type));
|
|
104
|
+
const bytes = type === 'uint8' ? 1 : type === 'float16' ? 2 : 4;
|
|
105
|
+
const input = new DataView(source.buffer, source.byteOffset);
|
|
106
|
+
const output =
|
|
107
|
+
format === 'unorm8x4'
|
|
108
|
+
? new Uint8Array(source.length * 4)
|
|
109
|
+
: format === 'float16x4'
|
|
110
|
+
? new Uint16Array(source.length * 4)
|
|
111
|
+
: new Float32Array(source.length * 4);
|
|
112
|
+
const scratch = new DataView(new ArrayBuffer(4));
|
|
113
|
+
for (let rowIndex = 0; rowIndex < source.length; rowIndex++) {
|
|
114
|
+
for (let componentIndex = 0; componentIndex < 4; componentIndex++) {
|
|
115
|
+
const offset = rowIndex * source.byteStride + componentIndex * bytes;
|
|
116
|
+
const value =
|
|
117
|
+
componentIndex >= components
|
|
118
|
+
? 1
|
|
119
|
+
: type === 'uint8'
|
|
120
|
+
? input.getUint8(offset) / 255
|
|
121
|
+
: type === 'float16'
|
|
122
|
+
? fromHalfFloat(input.getUint16(offset, true))
|
|
123
|
+
: input.getFloat32(offset, true);
|
|
124
|
+
output[rowIndex * 4 + componentIndex] =
|
|
125
|
+
format === 'unorm8x4'
|
|
126
|
+
? Math.round(Math.min(Math.max(value, 0), 1) * 255)
|
|
127
|
+
: format === 'float16x4'
|
|
128
|
+
? encodeHalfFloat(value, scratch)
|
|
129
|
+
: value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return new CPUData({
|
|
133
|
+
buffer: output,
|
|
134
|
+
format,
|
|
135
|
+
length: source.length,
|
|
136
|
+
nullBitmap: source.nullBitmap && new Uint8Array(source.nullBitmap)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** IEEE binary16 round-to-nearest-even, matching pack2x16float (no display-range clamp). */
|
|
141
|
+
function encodeHalfFloat(value: number, scratch: DataView): number {
|
|
142
|
+
scratch.setFloat32(0, value, true);
|
|
143
|
+
const bits = scratch.getUint32(0, true);
|
|
144
|
+
const sign = (bits >>> 16) & 0x8000;
|
|
145
|
+
const exponent = (bits >>> 23) & 255;
|
|
146
|
+
const mantissa = bits & 0x7fffff;
|
|
147
|
+
if (exponent === 255) return sign | 0x7c00 | (mantissa ? 0x200 : 0);
|
|
148
|
+
if (exponent > 142) return sign | 0x7c00;
|
|
149
|
+
if (exponent < 102) return sign;
|
|
150
|
+
const shift = exponent < 113 ? 126 - exponent : 13;
|
|
151
|
+
const significand = exponent < 113 ? mantissa | 0x800000 : mantissa;
|
|
152
|
+
const divisor = 2 ** shift;
|
|
153
|
+
const quotient = Math.floor(significand / divisor);
|
|
154
|
+
const remainder = significand % divisor;
|
|
155
|
+
const rounded =
|
|
156
|
+
quotient + (remainder > divisor / 2 || (remainder === divisor / 2 && quotient % 2) ? 1 : 0);
|
|
157
|
+
return sign | ((exponent < 113 ? 0 : (exponent - 112) * 1024) + rounded);
|
|
158
|
+
}
|
package/src/gpu-data/index.ts
CHANGED
|
@@ -73,3 +73,6 @@ export {CPUData, type CPUDataProps} from './cpu-data';
|
|
|
73
73
|
export {CPUVector, type CPUVectorProps} from './cpu-vector';
|
|
74
74
|
|
|
75
75
|
export {makeGPUVectorFromCPUVector, makeCPUVectorFromGPUVector} from './cpu-gpu-vector-transfer';
|
|
76
|
+
|
|
77
|
+
export {convertCPUColors, resolveColorOutputFormat} from './color-conversion';
|
|
78
|
+
export type {ColorOutputFormat, ColorConversionOptions} from './color-conversion';
|
|
@@ -929,6 +929,8 @@ function getVertexFormat(
|
|
|
929
929
|
if (size < 1 || size > 4) {
|
|
930
930
|
throw new Error(`Cannot synthesize a GPUVector vertex format with ${size} components`);
|
|
931
931
|
}
|
|
932
|
+
// Binary16 RGB has no vertex format; retain byte-identical packed storage for compute readers.
|
|
933
|
+
if (type === 'float16' && size === 3 && !normalized) return 'uint16x3-webgl';
|
|
932
934
|
let baseFormat: string = type;
|
|
933
935
|
if (normalized) {
|
|
934
936
|
switch (type) {
|