@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.
Files changed (75) hide show
  1. package/dist/arrow/arrow-colors.cjs +99 -18
  2. package/dist/arrow/arrow-colors.d.ts +27 -10
  3. package/dist/arrow/arrow-colors.d.ts.map +1 -1
  4. package/dist/arrow/arrow-colors.js +107 -24
  5. package/dist/arrow/arrow-colors.js.map +1 -1
  6. package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +2 -0
  7. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts +1 -0
  8. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
  9. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +1 -1
  10. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
  11. package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +32 -3
  12. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +6 -1
  13. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
  14. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +37 -3
  15. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
  16. package/dist/arrow/index.cjs.map +3 -3
  17. package/dist/dist.dev.js +19 -4
  18. package/dist/dist.min.js +38 -38
  19. package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
  20. package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
  21. package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
  22. package/dist/gpu-core/gpu-expression-operation.js +1 -1
  23. package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
  24. package/dist/gpu-data/color-conversion.cjs +105 -0
  25. package/dist/gpu-data/color-conversion.d.ts +30 -0
  26. package/dist/gpu-data/color-conversion.d.ts.map +1 -0
  27. package/dist/gpu-data/color-conversion.js +109 -0
  28. package/dist/gpu-data/color-conversion.js.map +1 -0
  29. package/dist/gpu-data/index.cjs +7 -2
  30. package/dist/gpu-data/index.cjs.map +3 -3
  31. package/dist/gpu-data/index.d.ts +2 -0
  32. package/dist/gpu-data/index.d.ts.map +1 -1
  33. package/dist/gpu-data/index.js +1 -0
  34. package/dist/gpu-data/index.js.map +1 -1
  35. package/dist/gpu-project/graph.cjs.map +3 -3
  36. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  37. package/dist/gpu-simple-graph/index.d.ts +1 -1
  38. package/dist/gpu-simple-graph/index.d.ts.map +1 -1
  39. package/dist/gpu-simple-graph/index.js.map +1 -1
  40. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +2 -0
  41. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +3 -0
  42. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
  43. package/dist/gpu-simple-graph/operations/convert-colors.cjs +6 -6
  44. package/dist/gpu-simple-graph/operations/convert-colors.d.ts +5 -1
  45. package/dist/gpu-simple-graph/operations/convert-colors.d.ts.map +1 -1
  46. package/dist/gpu-simple-graph/operations/convert-colors.js +12 -7
  47. package/dist/gpu-simple-graph/operations/convert-colors.js.map +1 -1
  48. package/dist/gpu-simple-graph/operations/cpu/convert-colors.cjs +16 -33
  49. package/dist/gpu-simple-graph/operations/cpu/convert-colors.d.ts.map +1 -1
  50. package/dist/gpu-simple-graph/operations/cpu/convert-colors.js +22 -35
  51. package/dist/gpu-simple-graph/operations/cpu/convert-colors.js.map +1 -1
  52. package/dist/gpu-simple-graph/operations/cpu/index.cjs.map +3 -3
  53. package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +3 -3
  54. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.cjs +31 -13
  55. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.d.ts.map +1 -1
  56. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js +42 -13
  57. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js.map +1 -1
  58. package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
  59. package/dist/gpu-sql/gpu-sql.cjs +1 -1
  60. package/dist/gpu-sql/gpu-sql.js +1 -1
  61. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  62. package/dist/gpu-sql/index.cjs.map +1 -1
  63. package/package.json +8 -7
  64. package/src/arrow/arrow-colors.ts +194 -33
  65. package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +3 -1
  66. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +46 -4
  67. package/src/gpu-core/gpu-expression-operation.ts +1 -1
  68. package/src/gpu-data/color-conversion.ts +158 -0
  69. package/src/gpu-data/index.ts +3 -0
  70. package/src/gpu-simple-graph/index.ts +1 -0
  71. package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +2 -0
  72. package/src/gpu-simple-graph/operations/convert-colors.ts +22 -7
  73. package/src/gpu-simple-graph/operations/cpu/convert-colors.ts +31 -48
  74. package/src/gpu-simple-graph/operations/webgpu/convert-colors.ts +47 -13
  75. package/src/gpu-sql/gpu-sql.ts +2 -2
@@ -8,6 +8,7 @@ import {
8
8
  type GPUDataEvaluatorInput
9
9
  } from '../operation/gpu-data-evaluator';
10
10
  import {Operation} from '../operation/operation';
11
+ import type {ColorOutputFormat} from '../../gpu-data/color-conversion';
11
12
 
12
13
  export type ColorInputFormat =
13
14
  | 'uint8x3'
@@ -17,13 +18,17 @@ export type ColorInputFormat =
17
18
  | 'float32x3'
18
19
  | 'float32x4';
19
20
 
21
+ export type {ColorOutputFormat} from '../../gpu-data/color-conversion';
22
+
20
23
  export type ConvertColorsProps = {
24
+ format?: ColorOutputFormat;
21
25
  inputFormat?: ColorInputFormat;
22
26
  };
23
27
 
24
28
  export type ConvertColorsInputs = {
25
29
  source: GPUDataEvaluator;
26
30
  inputFormat: ColorInputFormat;
31
+ outputFormat: ColorOutputFormat;
27
32
  };
28
33
 
29
34
  class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
@@ -31,15 +36,24 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
31
36
 
32
37
  output: GPUDataEvaluator;
33
38
 
34
- constructor(source: GPUDataEvaluator, inputFormat: ColorInputFormat) {
35
- super({source, inputFormat});
39
+ constructor(
40
+ source: GPUDataEvaluator,
41
+ inputFormat: ColorInputFormat,
42
+ outputFormat: ColorOutputFormat
43
+ ) {
44
+ super({source, inputFormat, outputFormat});
36
45
 
37
46
  this.output = new GPUDataEvaluator({
38
47
  id: `convertColors(${source})`,
39
- type: 'uint8',
48
+ type:
49
+ outputFormat === 'unorm8x4'
50
+ ? 'uint8'
51
+ : outputFormat === 'float16x4'
52
+ ? 'float16'
53
+ : 'float32',
40
54
  size: 4,
41
- normalized: true,
42
- format: 'unorm8x4',
55
+ normalized: outputFormat === 'unorm8x4',
56
+ format: outputFormat,
43
57
  length: source.length,
44
58
  source: this
45
59
  });
@@ -50,14 +64,15 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
50
64
  }
51
65
  }
52
66
 
53
- /** Converts one fixed-width GPU data range to normalized Uint8 RGBA values. */
67
+ /** Converts one fixed-width color range to RGBA8, binary16 or binary32 RGBA storage. */
54
68
  export function convertColorData(
55
69
  source: GPUDataEvaluatorInput,
56
70
  props: ConvertColorsProps = {}
57
71
  ): GPUDataEvaluator {
58
72
  const sourceEvaluator = getGPUDataEvaluator(source);
59
73
  const inputFormat = props.inputFormat ?? getColorInputFormat(sourceEvaluator);
60
- return new ConvertColorsOperation(sourceEvaluator, inputFormat).output;
74
+ return new ConvertColorsOperation(sourceEvaluator, inputFormat, props.format ?? 'unorm8x4')
75
+ .output;
61
76
  }
62
77
 
63
78
  function getColorInputFormat(source: GPUDataEvaluator): ColorInputFormat {
@@ -2,55 +2,38 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import {fromHalfFloat} from '@luma.gl/shaders';
6
- import type {TypedArray} from '@math.gl/core';
5
+ import {CPUData} from '../../../gpu-data/cpu-data';
6
+ import {convertCPUColorData} from '../../../gpu-data/color-conversion';
7
7
  import type {OperationHandler} from '../../operation/operation';
8
8
  import type {ConvertColorsInputs} from '../convert-colors';
9
9
 
10
- export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
11
- inputs,
12
- output,
13
- target
14
- }) => {
15
- const {source, inputFormat} = inputs;
16
- const sourceValue = await source.ensureCPUValue();
17
- const result = new output.ValueType(output.length * output.size);
18
- const inputSize = inputFormat.endsWith('x3') ? 3 : 4;
19
-
20
- for (let rowIndex = 0; rowIndex < output.length; rowIndex++) {
21
- const inputOffset =
22
- source.offset / source.ValueType.BYTES_PER_ELEMENT +
23
- rowIndex * (source.stride / source.ValueType.BYTES_PER_ELEMENT);
24
- const outputOffset = rowIndex * 4;
25
-
26
- result[outputOffset] = convertColorChannel(sourceValue, inputOffset, inputFormat);
27
- result[outputOffset + 1] = convertColorChannel(sourceValue, inputOffset + 1, inputFormat);
28
- result[outputOffset + 2] = convertColorChannel(sourceValue, inputOffset + 2, inputFormat);
29
- result[outputOffset + 3] =
30
- inputSize === 4 ? convertColorChannel(sourceValue, inputOffset + 3, inputFormat) : 255;
31
- }
32
-
33
- target.write(result);
34
- return {success: true, value: result};
10
+ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({inputs, target}) => {
11
+ const {source, inputFormat, outputFormat} = inputs;
12
+ const values = await source.ensureCPUValue();
13
+ const format =
14
+ source.format ??
15
+ (inputFormat === 'uint8x3'
16
+ ? 'uint8x3-webgl'
17
+ : inputFormat === 'float16x3'
18
+ ? 'uint16x3-webgl'
19
+ : inputFormat);
20
+ const converted = convertCPUColorData(
21
+ new CPUData({
22
+ buffer: values,
23
+ format,
24
+ length: source.length,
25
+ byteOffset: source.offset,
26
+ byteStride: source.stride
27
+ }),
28
+ outputFormat,
29
+ inputFormat
30
+ );
31
+ const bytes = new Uint8Array(
32
+ converted.buffer,
33
+ converted.byteOffset,
34
+ converted.length * converted.byteStride
35
+ );
36
+ target.write(bytes);
37
+ // Let the evaluator decode the target in its own Float16Array/Uint16Array representation.
38
+ return {success: true};
35
39
  };
36
-
37
- function convertColorChannel(values: TypedArray, index: number, inputFormat: string): number {
38
- if (inputFormat.startsWith('uint8')) {
39
- return values[index];
40
- }
41
-
42
- const value = inputFormat.startsWith('float16') ? getFloat16Value(values, index) : values[index];
43
- return Math.round(Math.min(Math.max(value, 0), 1) * 255);
44
- }
45
-
46
- function getFloat16Value(values: TypedArray, index: number): number {
47
- const Float16ArrayConstructor = getNativeFloat16ArrayConstructor();
48
- if (Float16ArrayConstructor && values.constructor === Float16ArrayConstructor) {
49
- return values[index];
50
- }
51
- return fromHalfFloat(values[index]);
52
- }
53
-
54
- function getNativeFloat16ArrayConstructor(): unknown {
55
- return (globalThis as typeof globalThis & {Float16Array?: unknown}).Float16Array;
56
- }
@@ -13,11 +13,19 @@ const COMPUTATION_RUNS = 'Computation Runs';
13
13
  export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
14
14
  inputs,
15
15
  output,
16
- target
16
+ target,
17
+ scope
17
18
  }) => {
18
19
  const {source, inputFormat} = inputs;
20
+ if (output.length === 0) return {success: true};
19
21
  const kernel = new Kernel(target.device, {
20
- source: getConvertColorsWGSL(inputFormat, source.offset, source.stride, output.length),
22
+ source: getConvertColorsWGSL(
23
+ inputFormat,
24
+ source.offset,
25
+ source.stride,
26
+ output.length,
27
+ inputs.outputFormat
28
+ ),
21
29
  shaderLayout: {
22
30
  bindings: [
23
31
  {name: 'source', type: 'storage' as const, group: 0, location: 0},
@@ -31,23 +39,38 @@ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
31
39
  result: target
32
40
  };
33
41
 
34
- const computePass = target.device.beginComputePass({});
35
- target.device.statsManager.getStats(GPGPU_OPERATION_STATS).get(COMPUTATION_RUNS).incrementCount();
36
- kernel.dispatch(computePass, {
37
- bindings: kernelBindings,
38
- x: Math.ceil(output.length / WORKGROUP_SIZE)
39
- });
40
- computePass.end();
41
- target.device.submit();
42
- kernel.destroy();
42
+ if (scope) scope.retain(() => kernel.destroy());
43
+ try {
44
+ const computePass = scope
45
+ ? scope.commandEncoder.beginComputePass({})
46
+ : target.device.beginComputePass({});
47
+ try {
48
+ target.device.statsManager
49
+ .getStats(GPGPU_OPERATION_STATS)
50
+ .get(COMPUTATION_RUNS)
51
+ .incrementCount();
52
+ kernel.dispatch(computePass, {
53
+ bindings: kernelBindings,
54
+ x: Math.ceil(output.length / WORKGROUP_SIZE)
55
+ });
56
+ } finally {
57
+ computePass.end();
58
+ }
59
+ if (!scope) target.device.submit();
60
+ } finally {
61
+ if (!scope) kernel.destroy();
62
+ }
63
+
43
64
  return {success: true};
44
65
  };
66
+ convertColors.supportsEvaluationScope = true;
45
67
 
46
68
  function getConvertColorsWGSL(
47
69
  inputFormat: ConvertColorsInputs['inputFormat'],
48
70
  byteOffset: number,
49
71
  byteStride: number,
50
- length: number
72
+ length: number,
73
+ outputFormat: ConvertColorsInputs['outputFormat']
51
74
  ): string {
52
75
  return /* wgsl */ `\
53
76
  @group(0) @binding(0) var<storage, read> source: array<u32>;
@@ -90,7 +113,18 @@ ${getReadColorWGSL(inputFormat)}
90
113
  return;
91
114
  }
92
115
 
93
- result[rowIndex] = pack4x8unorm(readColor(rowIndex));
116
+ let color = readColor(rowIndex);
117
+ ${
118
+ outputFormat === 'unorm8x4'
119
+ ? ' result[rowIndex] = pack4x8unorm(color);'
120
+ : outputFormat === 'float16x4'
121
+ ? ` result[rowIndex * 2u] = pack2x16float(color.xy);
122
+ result[rowIndex * 2u + 1u] = pack2x16float(color.zw);`
123
+ : ` result[rowIndex * 4u] = bitcast<u32>(color.x);
124
+ result[rowIndex * 4u + 1u] = bitcast<u32>(color.y);
125
+ result[rowIndex * 4u + 2u] = bitcast<u32>(color.z);
126
+ result[rowIndex * 4u + 3u] = bitcast<u32>(color.w);`
127
+ }
94
128
  }
95
129
  `;
96
130
  }
@@ -3,8 +3,8 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  // SPDX-FileComment: Independently implemented for WebGPU; inspired by relational SQL semantics.
5
5
 
6
- import type {Expression} from '@math.gl/core/expressions';
7
- import {parseSQLExpression} from '@math.gl/core/sql';
6
+ import {parseSQLExpression} from '@math.gl/expressions/sql';
7
+ import type {Expression} from '@math.gl/expressions';
8
8
  import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
9
9
  import {GPUDataFrame} from '../gpu-dataframe/gpu-data-frame';
10
10
  import {GPUDataFrameQuery} from '../gpu-dataframe/gpu-data-frame-query';