@luma.gl/engine 10.0.0-alpha.7 → 10.0.0-alpha.9

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 (191) hide show
  1. package/dist/arrow/index.cjs +5 -0
  2. package/dist/arrow/index.cjs.map +3 -3
  3. package/dist/arrow/index.d.ts +1 -0
  4. package/dist/arrow/index.d.ts.map +1 -1
  5. package/dist/arrow/index.js +1 -0
  6. package/dist/arrow/index.js.map +1 -1
  7. package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.cjs +162 -0
  8. package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.d.ts +34 -0
  9. package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.d.ts.map +1 -0
  10. package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.js +159 -0
  11. package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.js.map +1 -0
  12. package/dist/arrow/renderers/text/renderers/arrow-text-renderer.d.ts +1 -1
  13. package/dist/arrow/renderers/text/renderers/arrow-text-renderer.d.ts.map +1 -1
  14. package/dist/arrow/renderers/text/renderers/arrow-text-renderer.js.map +1 -1
  15. package/dist/arrow/renderers/text/renderers/arrow-text-shaders.cjs +10 -1
  16. package/dist/arrow/renderers/text/renderers/arrow-text-shaders.d.ts.map +1 -1
  17. package/dist/arrow/renderers/text/renderers/arrow-text-shaders.js +10 -3
  18. package/dist/arrow/renderers/text/renderers/arrow-text-shaders.js.map +1 -1
  19. package/dist/compute/computation.cjs +3 -0
  20. package/dist/compute/computation.d.ts.map +1 -1
  21. package/dist/compute/computation.js +3 -0
  22. package/dist/compute/computation.js.map +1 -1
  23. package/dist/dist.dev.js +706 -501
  24. package/dist/dist.min.js +63 -63
  25. package/dist/geometry/gpu-vector-geometry-adapter.cjs +14 -0
  26. package/dist/geometry/gpu-vector-geometry-adapter.d.ts +7 -0
  27. package/dist/geometry/gpu-vector-geometry-adapter.d.ts.map +1 -1
  28. package/dist/geometry/gpu-vector-geometry-adapter.js +17 -0
  29. package/dist/geometry/gpu-vector-geometry-adapter.js.map +1 -1
  30. package/dist/geometry/gpu-vector-geometry.cjs +3 -0
  31. package/dist/geometry/gpu-vector-geometry.d.ts +2 -0
  32. package/dist/geometry/gpu-vector-geometry.d.ts.map +1 -1
  33. package/dist/geometry/gpu-vector-geometry.js +2 -0
  34. package/dist/geometry/gpu-vector-geometry.js.map +1 -1
  35. package/dist/gltf/gltf/gltf-extension-support.cjs +25 -5
  36. package/dist/gltf/gltf/gltf-extension-support.d.ts.map +1 -1
  37. package/dist/gltf/gltf/gltf-extension-support.js +27 -5
  38. package/dist/gltf/gltf/gltf-extension-support.js.map +1 -1
  39. package/dist/gltf/index.cjs.map +1 -1
  40. package/dist/gltf/index.d.ts +1 -1
  41. package/dist/gltf/index.d.ts.map +1 -1
  42. package/dist/gltf/parsers/parse-gltf.cjs +19 -13
  43. package/dist/gltf/parsers/parse-gltf.d.ts +2 -0
  44. package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
  45. package/dist/gltf/parsers/parse-gltf.js +18 -13
  46. package/dist/gltf/parsers/parse-gltf.js.map +1 -1
  47. package/dist/gltf/parsers/post-process-gltf.cjs +1 -0
  48. package/dist/gltf/parsers/post-process-gltf.d.ts.map +1 -1
  49. package/dist/gltf/parsers/post-process-gltf.js +1 -0
  50. package/dist/gltf/parsers/post-process-gltf.js.map +1 -1
  51. package/dist/gltf/types/gltf-postprocessed-schema.d.ts +2 -0
  52. package/dist/gltf/types/gltf-postprocessed-schema.d.ts.map +1 -1
  53. package/dist/gltf/types/gltf-types.d.ts +19 -0
  54. package/dist/gltf/types/gltf-types.d.ts.map +1 -1
  55. package/dist/graph/models/index.cjs.map +3 -3
  56. package/dist/graph/physics/index.cjs +3 -0
  57. package/dist/graph/physics/index.cjs.map +3 -3
  58. package/dist/graph/physics/index.d.ts +2 -0
  59. package/dist/graph/physics/index.d.ts.map +1 -1
  60. package/dist/graph/physics/index.js +1 -0
  61. package/dist/graph/physics/index.js.map +1 -1
  62. package/dist/graph/physics/physics-controller-geometry.cjs +203 -0
  63. package/dist/graph/physics/physics-controller-geometry.d.ts +6 -0
  64. package/dist/graph/physics/physics-controller-geometry.d.ts.map +1 -0
  65. package/dist/graph/physics/physics-controller-geometry.js +205 -0
  66. package/dist/graph/physics/physics-controller-geometry.js.map +1 -0
  67. package/dist/graph/physics/physics-controller.cjs +277 -0
  68. package/dist/graph/physics/physics-controller.d.ts +90 -0
  69. package/dist/graph/physics/physics-controller.d.ts.map +1 -0
  70. package/dist/graph/physics/physics-controller.js +266 -0
  71. package/dist/graph/physics/physics-controller.js.map +1 -0
  72. package/dist/graph/physics/scenegraph-instance.cjs +11 -2
  73. package/dist/graph/physics/scenegraph-instance.d.ts +3 -1
  74. package/dist/graph/physics/scenegraph-instance.d.ts.map +1 -1
  75. package/dist/graph/physics/scenegraph-instance.js +11 -0
  76. package/dist/graph/physics/scenegraph-instance.js.map +1 -1
  77. package/dist/graph/physics/scenegraph-motion.cjs +3 -3
  78. package/dist/graph/physics/scenegraph-motion.d.ts +5 -1
  79. package/dist/graph/physics/scenegraph-motion.d.ts.map +1 -1
  80. package/dist/graph/physics/scenegraph-motion.js +3 -3
  81. package/dist/graph/physics/scenegraph-motion.js.map +1 -1
  82. package/dist/graph/physics/scenegraph-publication.cjs +13 -3
  83. package/dist/graph/physics/scenegraph-publication.d.ts +4 -2
  84. package/dist/graph/physics/scenegraph-publication.d.ts.map +1 -1
  85. package/dist/graph/physics/scenegraph-publication.js +14 -3
  86. package/dist/graph/physics/scenegraph-publication.js.map +1 -1
  87. package/dist/graph/physics/scenegraph-session.cjs +11 -1
  88. package/dist/graph/physics/scenegraph-session.d.ts +11 -2
  89. package/dist/graph/physics/scenegraph-session.d.ts.map +1 -1
  90. package/dist/graph/physics/scenegraph-session.js +13 -1
  91. package/dist/graph/physics/scenegraph-session.js.map +1 -1
  92. package/dist/graph/tables/index.cjs.map +3 -3
  93. package/dist/index.cjs +6 -0
  94. package/dist/index.cjs.map +3 -3
  95. package/dist/index.d.ts +3 -0
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +2 -0
  98. package/dist/index.js.map +1 -1
  99. package/dist/model/batch-uniform-buffer.cjs +70 -0
  100. package/dist/model/batch-uniform-buffer.d.ts +21 -0
  101. package/dist/model/batch-uniform-buffer.d.ts.map +1 -0
  102. package/dist/model/batch-uniform-buffer.js +48 -0
  103. package/dist/model/batch-uniform-buffer.js.map +1 -0
  104. package/dist/model/gpu-vector-bindings.cjs +67 -19
  105. package/dist/model/gpu-vector-bindings.d.ts +1 -1
  106. package/dist/model/gpu-vector-bindings.d.ts.map +1 -1
  107. package/dist/model/gpu-vector-bindings.js +77 -18
  108. package/dist/model/gpu-vector-bindings.js.map +1 -1
  109. package/dist/model/gpu-vector-draw-batches.cjs +8 -5
  110. package/dist/model/gpu-vector-draw-batches.d.ts +1 -1
  111. package/dist/model/gpu-vector-draw-batches.d.ts.map +1 -1
  112. package/dist/model/gpu-vector-draw-batches.js +9 -5
  113. package/dist/model/gpu-vector-draw-batches.js.map +1 -1
  114. package/dist/model/gpu-vector-model-batches.d.ts +5 -0
  115. package/dist/model/gpu-vector-model-batches.d.ts.map +1 -1
  116. package/dist/model/gpu-vector-model-batches.js.map +1 -1
  117. package/dist/model/gpu-vector-model.cjs +63 -17
  118. package/dist/model/gpu-vector-model.d.ts +16 -3
  119. package/dist/model/gpu-vector-model.d.ts.map +1 -1
  120. package/dist/model/gpu-vector-model.js +72 -16
  121. package/dist/model/gpu-vector-model.js.map +1 -1
  122. package/dist/model/model.cjs +8 -0
  123. package/dist/model/model.d.ts +4 -1
  124. package/dist/model/model.d.ts.map +1 -1
  125. package/dist/model/model.js +8 -0
  126. package/dist/model/model.js.map +1 -1
  127. package/dist/scenegraph/geometry-node.cjs +47 -0
  128. package/dist/scenegraph/geometry-node.d.ts +13 -0
  129. package/dist/scenegraph/geometry-node.d.ts.map +1 -0
  130. package/dist/scenegraph/geometry-node.js +26 -0
  131. package/dist/scenegraph/geometry-node.js.map +1 -0
  132. package/dist/scenegraph/group-node.cjs +42 -0
  133. package/dist/scenegraph/group-node.d.ts +8 -0
  134. package/dist/scenegraph/group-node.d.ts.map +1 -1
  135. package/dist/scenegraph/group-node.js +47 -1
  136. package/dist/scenegraph/group-node.js.map +1 -1
  137. package/dist/scenegraph/transform-source.cjs +15 -0
  138. package/dist/scenegraph/transform-source.d.ts +24 -0
  139. package/dist/scenegraph/transform-source.d.ts.map +1 -0
  140. package/dist/scenegraph/transform-source.js +5 -0
  141. package/dist/scenegraph/transform-source.js.map +1 -0
  142. package/dist/splats/gpu-splat-graph-renderer.d.ts +1 -1
  143. package/dist/splats/gpu-splat-graph-renderer.d.ts.map +1 -1
  144. package/dist/splats/index.cjs.map +1 -1
  145. package/dist/splats/splat-data.cjs +34 -23
  146. package/dist/splats/splat-data.d.ts.map +1 -1
  147. package/dist/splats/splat-data.js +34 -22
  148. package/dist/splats/splat-data.js.map +1 -1
  149. package/dist/splats/splat-renderer.cjs +6 -1
  150. package/dist/splats/splat-renderer.d.ts +3 -0
  151. package/dist/splats/splat-renderer.d.ts.map +1 -1
  152. package/dist/splats/splat-renderer.js +6 -1
  153. package/dist/splats/splat-renderer.js.map +1 -1
  154. package/dist/splats/splat-sort.d.ts +1 -1
  155. package/dist/splats/splat-sort.d.ts.map +1 -1
  156. package/package.json +8 -8
  157. package/src/arrow/index.ts +6 -0
  158. package/src/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.ts +220 -0
  159. package/src/arrow/renderers/text/renderers/arrow-text-renderer.ts +1 -0
  160. package/src/arrow/renderers/text/renderers/arrow-text-shaders.ts +12 -5
  161. package/src/compute/computation.ts +3 -0
  162. package/src/geometry/gpu-vector-geometry-adapter.ts +19 -1
  163. package/src/geometry/gpu-vector-geometry.ts +3 -0
  164. package/src/gltf/gltf/gltf-extension-support.ts +27 -5
  165. package/src/gltf/index.ts +1 -0
  166. package/src/gltf/parsers/parse-gltf.ts +21 -14
  167. package/src/gltf/parsers/post-process-gltf.ts +1 -0
  168. package/src/gltf/types/gltf-postprocessed-schema.ts +2 -0
  169. package/src/gltf/types/gltf-types.ts +20 -0
  170. package/src/graph/physics/index.ts +10 -0
  171. package/src/graph/physics/physics-controller-geometry.ts +264 -0
  172. package/src/graph/physics/physics-controller.ts +348 -0
  173. package/src/graph/physics/scenegraph-instance.ts +12 -1
  174. package/src/graph/physics/scenegraph-motion.ts +14 -3
  175. package/src/graph/physics/scenegraph-publication.ts +24 -4
  176. package/src/graph/physics/scenegraph-session.ts +35 -3
  177. package/src/index.ts +8 -0
  178. package/src/model/batch-uniform-buffer.ts +51 -0
  179. package/src/model/gpu-vector-bindings.ts +88 -22
  180. package/src/model/gpu-vector-draw-batches.ts +17 -12
  181. package/src/model/gpu-vector-model-batches.ts +5 -0
  182. package/src/model/gpu-vector-model.ts +101 -18
  183. package/src/model/model.ts +11 -1
  184. package/src/scenegraph/geometry-node.ts +31 -0
  185. package/src/scenegraph/group-node.ts +54 -1
  186. package/src/scenegraph/transform-source.ts +30 -0
  187. package/src/splats/README.md +46 -0
  188. package/src/splats/gpu-splat-graph-renderer.ts +1 -1
  189. package/src/splats/splat-data.ts +53 -45
  190. package/src/splats/splat-renderer.ts +9 -1
  191. package/src/splats/splat-sort.ts +1 -1
@@ -3,7 +3,12 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Matrix4} from '@math.gl/core';
6
- import {GroupNode, decomposePhysicsTransform, type ScenegraphNode} from '../../index';
6
+ import {
7
+ GroupNode,
8
+ decomposePhysicsTransform,
9
+ type ScenegraphNode,
10
+ type ScenegraphBounds
11
+ } from '../../index';
7
12
  import type {GPURigidBodyWorld} from '@luma.gl/graph/gpu-physics';
8
13
  import type {GPURigidBodyBounds} from '@luma.gl/graph/gpu-physics';
9
14
 
@@ -17,11 +22,16 @@ export type ScenegraphPhysicsRenderBinding = {
17
22
  /** Authoring transforms feed GPU publication metadata; simulated poses never come back. */
18
23
  export class ScenegraphPhysicsPublication {
19
24
  readonly bindings = new Map<ScenegraphNode, ScenegraphPhysicsRenderBinding>();
25
+ readonly transformBindings = new Map<
26
+ ScenegraphNode,
27
+ import('../../scenegraph/transform-source').ScenegraphTransformBinding
28
+ >();
20
29
  private boundsKey = '';
21
30
  constructor(
22
31
  readonly world: GPURigidBodyWorld,
23
32
  readonly roots: readonly ScenegraphNode[],
24
- readonly bodies: ReadonlyMap<ScenegraphNode, number>
33
+ readonly bodies: ReadonlyMap<ScenegraphNode, number>,
34
+ readonly localBounds?: ReadonlyMap<ScenegraphNode, ScenegraphBounds>
25
35
  ) {
26
36
  if (!world.poseMatrices || !world.poseBounds)
27
37
  throw new Error('Scene publication requires pose and bounds buffers');
@@ -69,7 +79,10 @@ export class ScenegraphPhysicsPublication {
69
79
  throw new Error('Invalid publication body');
70
80
  bindings.set(node, {body, localMatrix, visible: displayed});
71
81
  // Group bounds include descendants, which may belong to independent child bodies.
72
- const localBounds = node instanceof GroupNode ? null : node.getBounds();
82
+ const localBounds =
83
+ node instanceof GroupNode
84
+ ? null
85
+ : (node.getBounds() ?? this.localBounds?.get(node) ?? null);
73
86
  if (
74
87
  localBounds &&
75
88
  (localBounds.length !== 2 ||
@@ -111,6 +124,13 @@ export class ScenegraphPhysicsPublication {
111
124
  this.boundsKey = key;
112
125
  }
113
126
  this.bindings.clear();
114
- for (const [node, binding] of bindings) this.bindings.set(node, binding);
127
+ this.transformBindings.clear();
128
+ for (const [node, binding] of bindings) {
129
+ this.bindings.set(node, binding);
130
+ this.transformBindings.set(node, {
131
+ matrixIndex: binding.body,
132
+ localMatrix: binding.localMatrix
133
+ });
134
+ }
115
135
  }
116
136
  }
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import type {Device} from '@luma.gl/core';
6
- import {GroupNode, type ScenegraphNode} from '../../index';
5
+ import {assert, type Device, type CommandEncoder} from '@luma.gl/core';
6
+ import {GroupNode, type ScenegraphNode, type ScenegraphBounds} from '../../index';
7
7
  import {
8
8
  ScenegraphPhysicsInstance,
9
9
  type ScenegraphPhysicsDefinition,
@@ -22,6 +22,8 @@ export type ScenegraphPhysicsScene = {
22
22
  roots: readonly ScenegraphNode[];
23
23
  definition: ScenegraphPhysicsDefinition;
24
24
  colliders?: readonly ScenegraphPhysicsColliderTarget[];
25
+ /** Prepared local visual bounds for geometry nodes that do not expose getBounds(). */
26
+ localBounds?: ReadonlyMap<ScenegraphNode, ScenegraphBounds>;
25
27
  properties?: (world: GPURigidBodyWorld) => ScenegraphPhysicsProperties;
26
28
  behaviors?: ScenegraphPhysicsBehaviorProps;
27
29
  };
@@ -102,7 +104,12 @@ export class ScenegraphPhysicsSession {
102
104
  scene.definition.bodies,
103
105
  scene.colliders
104
106
  ),
105
- publication: new ScenegraphPhysicsPublication(world, scene.roots, scene.definition.bodies),
107
+ publication: new ScenegraphPhysicsPublication(
108
+ world,
109
+ scene.roots,
110
+ scene.definition.bodies,
111
+ scene.localBounds
112
+ ),
106
113
  properties: scene.properties?.(world) ?? new ScenegraphPhysicsProperties(world, new Map()),
107
114
  behaviors: scene.behaviors
108
115
  ? new ScenegraphPhysicsBehaviors(world, scene.behaviors)
@@ -127,6 +134,31 @@ export class ScenegraphPhysicsSession {
127
134
  }
128
135
  }
129
136
 
137
+ /** Encode a fixed-step batch after sampling animation; the caller owns submission. */
138
+ encode(
139
+ encoder: CommandEncoder,
140
+ {
141
+ steps = 1,
142
+ animatedNodes = new Set<ScenegraphNode>(),
143
+ excludedNodes,
144
+ targetNodes
145
+ }: {
146
+ steps?: number;
147
+ animatedNodes?: ReadonlySet<ScenegraphNode>;
148
+ excludedNodes?: ReadonlySet<ScenegraphNode>;
149
+ targetNodes?: ReadonlySet<ScenegraphNode>;
150
+ } = {}
151
+ ): void {
152
+ // Synchronous frame encoding must not overlap readback, reset, rebuild or destruction.
153
+ assert(!this.pending && !this.closing);
154
+ // Validate the batch before mutating animation ownership or targets.
155
+ assert(Number.isSafeInteger(steps) && steps > 0);
156
+ this.motion.setAnimatedNodes(animatedNodes, {excludedNodes, targetNodes});
157
+ this.motion.update();
158
+ this.publication.update();
159
+ this.instance.encode(encoder, steps);
160
+ }
161
+
130
162
  /** Sample/blend first; declare active transform tracks, including paused tracks, explicitly. */
131
163
  async step(
132
164
  animatedNodes: ReadonlySet<ScenegraphNode> = new Set(),
package/src/index.ts CHANGED
@@ -85,6 +85,12 @@ export type {
85
85
  GroupNodeProps
86
86
  } from './scenegraph/group-node';
87
87
  export {GroupNode} from './scenegraph/group-node';
88
+ export {GeometryNode, type GeometryNodeProps} from './scenegraph/geometry-node';
89
+ export type {
90
+ ScenegraphTransformSource,
91
+ ScenegraphTransformFrame,
92
+ ScenegraphTransformBinding
93
+ } from './scenegraph/transform-source';
88
94
  export type {ModelNodeProps} from './scenegraph/model-node';
89
95
  export {ModelNode} from './scenegraph/model-node';
90
96
 
@@ -348,3 +354,5 @@ export {makeAdapterAnimationBinding} from './animation/property-animation-bindin
348
354
  export {deformPositions} from './animation/deform-positions';
349
355
 
350
356
  export {createAreaLightLTCTextures} from './lighting/ltc-textures';
357
+
358
+ export {makeGPUVectorGeometry} from './geometry/gpu-vector-geometry-adapter';
@@ -0,0 +1,51 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Buffer, assert, type Device} from '@luma.gl/core';
6
+
7
+ /** Engine-owned aligned uniform slots, reused between submitted batch draws. */
8
+ export class BatchUniformBuffer {
9
+ private buffer?: Buffer;
10
+ private byteOffset = 0;
11
+
12
+ constructor(private readonly device: Device) {}
13
+
14
+ /** Reserves the entire call before drawing, so growth cannot invalidate an earlier batch. */
15
+ prepare(byteLength: number): void {
16
+ if (!this.buffer || this.buffer.byteLength < byteLength) {
17
+ const capacity = Math.max(1024, (this.buffer?.byteLength ?? 0) * 2, byteLength);
18
+ const buffer = this.device.createBuffer({
19
+ id: 'batch-uniforms',
20
+ byteLength: capacity,
21
+ usage: Buffer.UNIFORM | Buffer.COPY_DST
22
+ });
23
+ this.buffer?.destroy();
24
+ this.buffer = buffer;
25
+ }
26
+ this.byteOffset = 0;
27
+ }
28
+
29
+ /** Returns the aligned slot size required for a uniform block. */
30
+ getAlignedByteLength(byteLength: number): number {
31
+ const alignment = this.device.limits.minUniformBufferOffsetAlignment || 1;
32
+ return Math.ceil(byteLength / alignment) * alignment;
33
+ }
34
+
35
+ /** Writes one slot without overwriting earlier batches in this call. */
36
+ write(data: Uint8Array): {buffer: Buffer; offset: number; size: number} {
37
+ // prepare() must reserve enough space for all blocks in all batches before drawing.
38
+ assert(this.buffer && this.byteOffset + data.byteLength <= this.buffer.byteLength);
39
+ const binding = {buffer: this.buffer, offset: this.byteOffset, size: data.byteLength};
40
+ this.buffer.write(data, binding.offset);
41
+ this.byteOffset += this.getAlignedByteLength(data.byteLength);
42
+ return binding;
43
+ }
44
+
45
+ /** Releases the model-owned allocation. */
46
+ destroy(): void {
47
+ this.buffer?.destroy();
48
+ this.buffer = undefined;
49
+ this.byteOffset = 0;
50
+ }
51
+ }
@@ -51,9 +51,17 @@ export class GPUVectorBindings {
51
51
  setInputs(
52
52
  columns: GPUVectorModelAttributes,
53
53
  explicitLayouts: BufferLayout[] | undefined,
54
- stepMode: 'vertex' | 'instance'
54
+ stepMode: 'vertex' | 'instance',
55
+ enforceMatchingVectorLengths = true
55
56
  ): void {
56
- validateGPUVectorBatchStructure(columns);
57
+ if (enforceMatchingVectorLengths) {
58
+ validateGPUVectorBatchStructure(columns);
59
+ } else {
60
+ // Independent attributes currently require contiguous storage.
61
+ for (const column of Object.values(columns)) {
62
+ if (column && !isConstant(column)) assert(column.data.length === 1);
63
+ }
64
+ }
57
65
  this.claimedNames.clear();
58
66
  this.inputs = columns;
59
67
  this.sourceLayouts = explicitLayouts;
@@ -66,32 +74,28 @@ export class GPUVectorBindings {
66
74
  Object.entries(columns).flatMap<BufferLayout>(([name, column]) =>
67
75
  column && !isConstant(column) && column.bufferLayout ? [{...column.bufferLayout, name}] : []
68
76
  );
69
- const layouts: BufferLayout[] = [
70
- ...providedLayouts,
71
- ...Object.entries(columns).flatMap<BufferLayout>(([name, column]) => {
72
- if (
73
- !column ||
74
- providedLayouts.some(
75
- layout =>
76
- layout.name === name ||
77
- layout.attributes?.some(attribute => attribute.attribute === name)
78
- )
77
+ const inferredLayouts = Object.entries(columns).flatMap<BufferLayout>(([name, column]) => {
78
+ if (
79
+ !column ||
80
+ providedLayouts.some(
81
+ layout =>
82
+ layout.name === name ||
83
+ layout.attributes?.some(attribute => attribute.attribute === name)
79
84
  )
80
- return [];
81
- assert(column.format);
82
- const format = column.format as VertexFormat;
83
- const byteStride = isConstant(column) ? 0 : column.byteStride;
84
- return [
85
- {name, stepMode, byteStride, attributes: [{attribute: name, format, byteOffset: 0}]}
86
- ];
87
- })
88
- ];
85
+ )
86
+ return [];
87
+ assert(column.format);
88
+ const format = column.format as VertexFormat;
89
+ const byteStride = isConstant(column) ? 0 : column.byteStride;
90
+ return [{name, stepMode, byteStride, attributes: [{attribute: name, format, byteOffset: 0}]}];
91
+ });
92
+ const layouts = [...providedLayouts, ...consolidateInferredLayouts(columns, inferredLayouts)];
89
93
  for (const [name, column] of Object.entries(columns)) {
90
94
  if (!column) continue;
91
95
  // Inputs must describe a typed vector or a typed constant, never raw buffers or arrays.
92
96
  if (!isConstant(column) && !Array.isArray(column.data))
93
97
  throw new TypeError(`Expected a GPU vector or constant for ${name}`);
94
- if (!isConstant(column)) {
98
+ if (!isConstant(column) && enforceMatchingVectorLengths) {
95
99
  const layout = layouts.find(
96
100
  layout =>
97
101
  layout.name === name ||
@@ -274,3 +278,65 @@ function getShaderConstant(column: GPUVectorModelConstant): TypedArray {
274
278
  return information.signed ? new Int32Array(values) : new Uint32Array(values);
275
279
  return new Float32Array(values);
276
280
  }
281
+
282
+ /** Consolidates inferred views without changing stored bytes or caller-owned layouts. */
283
+ function consolidateInferredLayouts(
284
+ columns: GPUVectorModelAttributes,
285
+ layouts: BufferLayout[]
286
+ ): BufferLayout[] {
287
+ const result: BufferLayout[] = [];
288
+ let constantLayout: BufferLayout | undefined;
289
+ let constantByteLength = 0;
290
+ // Start with the lowest offset so shared views have nonnegative attribute offsets.
291
+ const sortedLayouts = [...layouts].sort((left, right) => {
292
+ const leftColumn = columns[left.name];
293
+ const rightColumn = columns[right.name];
294
+ return (
295
+ (leftColumn && !isConstant(leftColumn) ? (leftColumn.data[0]?.byteOffset ?? 0) : 0) -
296
+ (rightColumn && !isConstant(rightColumn) ? (rightColumn.data[0]?.byteOffset ?? 0) : 0)
297
+ );
298
+ });
299
+ for (const layout of sortedLayouts) {
300
+ const column = columns[layout.name]!;
301
+ const attribute = layout.attributes![0];
302
+ if (isConstant(column)) {
303
+ if (!constantLayout) {
304
+ constantLayout = {...layout, attributes: []};
305
+ result.push(constantLayout);
306
+ }
307
+ const alignment = Math.min(4, column.byteLength);
308
+ constantByteLength = Math.ceil(constantByteLength / alignment) * alignment;
309
+ constantLayout.attributes!.push({...attribute, byteOffset: constantByteLength});
310
+ constantByteLength += column.byteLength;
311
+ continue;
312
+ }
313
+ const sharedLayout = result.find(candidate => {
314
+ const primary = columns[candidate.name];
315
+ if (!primary || isConstant(primary) || !primary.data.length || !column.data.length)
316
+ return false;
317
+ const offset = column.data[0].byteOffset - primary.data[0].byteOffset;
318
+ return (
319
+ candidate.stepMode === layout.stepMode &&
320
+ candidate.byteStride === layout.byteStride &&
321
+ offset >= 0 &&
322
+ offset + column.rowByteLength <= column.byteStride &&
323
+ column.data.every((chunk, index) => {
324
+ const primaryChunk = primary.data[index];
325
+ return (
326
+ chunk.buffer === primaryChunk.buffer &&
327
+ chunk.byteStride === primaryChunk.byteStride &&
328
+ chunk.byteOffset - primaryChunk.byteOffset === offset
329
+ );
330
+ })
331
+ );
332
+ });
333
+ if (sharedLayout) {
334
+ const primary = columns[sharedLayout.name] as GPUVectorModelInput;
335
+ sharedLayout.attributes!.push({
336
+ ...attribute,
337
+ byteOffset: column.data[0].byteOffset - primary.data[0].byteOffset
338
+ });
339
+ } else result.push({...layout, attributes: [...layout.attributes!]});
340
+ }
341
+ return result;
342
+ }
@@ -19,12 +19,16 @@ export function drawGPUVectorGroups(
19
19
  geometry: GPUVectorBindings,
20
20
  attributes: GPUVectorBindings,
21
21
  syncBindings: () => void,
22
- draw: () => boolean
22
+ draw: () => boolean,
23
+ inferDrawCount?: 'instance' | 'vertex' | 'no'
23
24
  ): boolean {
24
25
  const geometryInputs = geometry.inputs;
25
26
  const attributeInputs = attributes.inputs;
26
27
  const geometryLayouts = geometry.sourceLayouts;
27
28
  const attributeLayouts = attributes.sourceLayouts;
29
+ // Keep the full group's inference stable when selecting individual chunks.
30
+ const geometryBatchLayouts = geometry.layouts;
31
+ const attributeBatchLayouts = attributes.layouts;
28
32
  const attributeStepMode = attributes.stepMode;
29
33
  const geometryBatchCount = geometry.batchCount;
30
34
  const attributeBatchCount = attributes.batchCount;
@@ -52,10 +56,10 @@ export function drawGPUVectorGroups(
52
56
  const attributeBatchIndex = independentInstances
53
57
  ? batchIndex % attributeBatchCount
54
58
  : Math.min(batchIndex, attributeBatchCount - 1);
55
- geometry.setInputs(geometryBatches[geometryBatchIndex], geometryLayouts, 'vertex');
59
+ geometry.setInputs(geometryBatches[geometryBatchIndex], geometryBatchLayouts, 'vertex');
56
60
  attributes.setInputs(
57
61
  attributeBatches[attributeBatchIndex],
58
- attributeLayouts,
62
+ attributeBatchLayouts,
59
63
  attributeStepMode
60
64
  );
61
65
  syncBindings();
@@ -65,16 +69,17 @@ export function drawGPUVectorGroups(
65
69
  : attributes.vertexCount !== undefined
66
70
  ? attributeOffsets[attributeBatchIndex]
67
71
  : 0;
68
- model.setVertexCount(
69
- Math.max(
70
- 0,
71
- Math.min(
72
- geometry.rowCount ?? attributes.vertexCount ?? vertexCount,
73
- vertexCount - vertexOffset
72
+ if (inferDrawCount === 'vertex')
73
+ model.setVertexCount(
74
+ Math.max(
75
+ 0,
76
+ Math.min(
77
+ geometry.rowCount ?? attributes.vertexCount ?? vertexCount,
78
+ vertexCount - vertexOffset
79
+ )
74
80
  )
75
- )
76
- );
77
- if (attributes.instanceCount !== undefined)
81
+ );
82
+ if (inferDrawCount === 'instance' && attributes.instanceCount !== undefined)
78
83
  model.setInstanceCount(
79
84
  Math.max(
80
85
  0,
@@ -50,6 +50,11 @@ export type GPUVectorModelDrawBatchesOptions<
50
50
  Inputs extends GPUVectorModelInputs = GPUVectorModelInputs
51
51
  > = {
52
52
  vectors: Inputs;
53
+ /**
54
+ * Runs synchronously before each chunk draw. Managed uniforms use distinct aligned slots
55
+ * within this call; submit before reusing slots with different values in another call.
56
+ * External buffers remain caller-managed. Row offsets are cumulative.
57
+ */
53
58
  onBatch?: (batch: GPUVectorModelBatch<NonNullable<Inputs[keyof Inputs]>['data'][number]>) => void;
54
59
  };
55
60
 
@@ -42,6 +42,7 @@ import {mergeShaderPluginModules, resolveShaderPlugins, ShaderAssembler} from '@
42
42
  import {GLSLShaderAssembler} from '@luma.gl/shaders/glsl';
43
43
  import {WGSLShaderAssembler} from '@luma.gl/shaders/wgsl';
44
44
 
45
+ import {BatchUniformBuffer} from './batch-uniform-buffer';
45
46
  import {getDebugTableForShaderLayout} from '../debug/debug-shader-layout';
46
47
  import {debugFramebuffer} from '../debug/debug-framebuffer';
47
48
  import {deepEqual} from '../utils/deep-equal';
@@ -114,8 +115,13 @@ export type GPUVectorModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindi
114
115
  geometry?: GPUVectorGeometry | null;
115
116
  /** Supplemental vertex or instance vectors and constants. */
116
117
  attributeVectors?: GPUVectorModelAttributes;
117
- /** Draw count updated from each vector batch. Defaults to `instance`. */
118
- gpuVectorCount?: GPUVectorModelCount;
118
+ /**
119
+ * Count inferred from vector rows or each explicit batch. `no` preserves both counts.
120
+ * @default 'no'
121
+ */
122
+ inferDrawCount?: 'instance' | 'vertex' | 'no';
123
+ /** Require aligned lengths and chunks. False requires inferDrawCount: 'no' and single chunks. */
124
+ enforceMatchingVectorLengths?: boolean;
119
125
  source?: string;
120
126
  /** Input language compiled by the application-registered shader assembler transpiler. */
121
127
  sourceLanguage?: string;
@@ -227,7 +233,8 @@ export class GPUVectorModel {
227
233
 
228
234
  static defaultProps: Required<GPUVectorModelProps> = {
229
235
  ...RenderPipeline.defaultProps,
230
- gpuVectorCount: 'instance',
236
+ inferDrawCount: 'no',
237
+ enforceMatchingVectorLengths: true,
231
238
  geometry: null,
232
239
  attributeVectors: undefined!,
233
240
  source: undefined!,
@@ -339,6 +346,7 @@ export class GPUVectorModel {
339
346
 
340
347
  _attributeInfos: Record<string, AttributeInfo> = {};
341
348
  protected props: Required<GPUVectorModelProps>;
349
+ private batchUniformBuffer?: BatchUniformBuffer;
342
350
  private geometryVectorBindings!: GPUVectorBindings;
343
351
  private attributeVectorBindings!: GPUVectorBindings;
344
352
  private explicitBufferLayout: BufferLayout[] = [];
@@ -476,6 +484,7 @@ export class GPUVectorModel {
476
484
  ...this.props,
477
485
  modules,
478
486
  defines,
487
+ pluginHooks: resolvedPlugins.hooks,
479
488
  pluginInjections: resolvedPlugins.injections,
480
489
  pluginVertexInputs: resolvedPlugins.vertexInputs,
481
490
  pluginInterStageVariables: resolvedPlugins.interStageVariables
@@ -513,6 +522,7 @@ export class GPUVectorModel {
513
522
  ...this.props,
514
523
  modules,
515
524
  defines,
525
+ pluginHooks: resolvedPlugins.hooks,
516
526
  pluginInjections: resolvedPlugins.injections,
517
527
  pluginVertexInputs: resolvedPlugins.vertexInputs,
518
528
  pluginInterStageVariables: resolvedPlugins.interStageVariables
@@ -610,6 +620,7 @@ export class GPUVectorModel {
610
620
  this.geometryVectorBindings.destroy();
611
621
  this.attributeVectorBindings.destroy();
612
622
  this._uniformStore?.destroy();
623
+ this.batchUniformBuffer?.destroy();
613
624
  this._destroyed = true;
614
625
  }
615
626
  }
@@ -795,13 +806,22 @@ export class GPUVectorModel {
795
806
  bufferLayouts ??=
796
807
  this.getExplicitVectorLayouts(vectors) ??
797
808
  this.getExplicitVectorLayouts(vectors, this.geometryVectorBindings.sourceLayouts);
798
- validateGPUVectorBatchStructure(vectors);
799
- if (!this.isInstanced || this.attributeVectorBindings.vertexCount !== undefined)
809
+ this.validateVectorLengthPolicy();
810
+ if (this.props.enforceMatchingVectorLengths) validateGPUVectorBatchStructure(vectors);
811
+ if (
812
+ this.props.enforceMatchingVectorLengths &&
813
+ (!this.isInstanced || this.attributeVectorBindings.vertexCount !== undefined)
814
+ )
800
815
  validateGPUVectorBatchStructure([
801
816
  ...Object.values(vectors),
802
817
  ...Object.values(this.attributeVectorBindings.inputs)
803
818
  ]);
804
- this.geometryVectorBindings.setInputs(vectors, bufferLayouts, 'vertex');
819
+ this.geometryVectorBindings.setInputs(
820
+ vectors,
821
+ bufferLayouts,
822
+ 'vertex',
823
+ this.props.enforceMatchingVectorLengths
824
+ );
805
825
  this.claimVectorLayouts(this.geometryVectorBindings);
806
826
  this.syncVectorBindings();
807
827
  const rowCount = this.geometryVectorBindings.rowCount;
@@ -810,7 +830,8 @@ export class GPUVectorModel {
810
830
  this.attributeVectorBindings.vertexCount === undefined ||
811
831
  rowCount === this.attributeVectorBindings.vertexCount
812
832
  );
813
- this.setVertexCount(rowCount ?? this.attributeVectorBindings.vertexCount ?? 0);
833
+ if (this.props.inferDrawCount === 'vertex')
834
+ this.setVertexCount(rowCount ?? this.attributeVectorBindings.vertexCount ?? 0);
814
835
  }
815
836
 
816
837
  /** Replaces supplemental vectors; instanced models default these inputs to instance step mode. */
@@ -838,7 +859,8 @@ export class GPUVectorModel {
838
859
  layout.attributes?.some(attribute => attribute.attribute === name)
839
860
  )?.stepMode ?? vector.bufferLayout?.stepMode) === 'vertex'
840
861
  );
841
- if (usesVertexRows)
862
+ this.validateVectorLengthPolicy();
863
+ if (usesVertexRows && this.props.enforceMatchingVectorLengths)
842
864
  validateGPUVectorBatchStructure([
843
865
  ...Object.values(this.geometryVectorBindings.inputs),
844
866
  ...Object.values(vectors)
@@ -846,14 +868,18 @@ export class GPUVectorModel {
846
868
  this.attributeVectorBindings.setInputs(
847
869
  vectors,
848
870
  bufferLayouts,
849
- this.isInstanced ? 'instance' : 'vertex'
871
+ this.isInstanced ? 'instance' : 'vertex',
872
+ this.props.enforceMatchingVectorLengths
850
873
  );
851
874
  this.claimVectorLayouts(this.attributeVectorBindings);
852
875
  this.syncVectorBindings();
853
- if (this.attributeVectorBindings.instanceCount !== undefined)
876
+ if (
877
+ this.props.inferDrawCount === 'instance' &&
878
+ this.attributeVectorBindings.instanceCount !== undefined
879
+ )
854
880
  this.setInstanceCount(this.attributeVectorBindings.instanceCount);
855
881
  const vertexCount = this.attributeVectorBindings.vertexCount;
856
- if (vertexCount !== undefined) {
882
+ if (vertexCount !== undefined && this.props.inferDrawCount === 'vertex') {
857
883
  const geometryRowCount = this.geometryVectorBindings.rowCount;
858
884
  // Supplemental vertex columns describe the same rows as the geometry columns.
859
885
  assert(geometryRowCount === undefined || geometryRowCount === vertexCount);
@@ -994,7 +1020,8 @@ export class GPUVectorModel {
994
1020
  this.geometryVectorBindings,
995
1021
  this.attributeVectorBindings,
996
1022
  () => this.syncVectorBindings(),
997
- () => GPUVectorModel.prototype.draw.call(this, renderPass)
1023
+ () => GPUVectorModel.prototype.draw.call(this, renderPass),
1024
+ this.props.inferDrawCount
998
1025
  );
999
1026
  if (success) {
1000
1027
  this._lastDrawTimestamp = this.device.timestamp;
@@ -1007,7 +1034,13 @@ export class GPUVectorModel {
1007
1034
  }
1008
1035
  }
1009
1036
 
1010
- /** Draws each aligned physical chunk without retaining or taking ownership of input vectors. */
1037
+ /**
1038
+ * Draws each aligned physical chunk without taking ownership of input vectors.
1039
+ * Each batch uses a separate aligned slot for managed shader-input uniforms set by
1040
+ * `onBatch`. Slots are reused on each call: submit previous draws before changing their
1041
+ * values or growing the allocation. Explicit buffers remain caller-managed. Vector
1042
+ * lengths and physical chunk boundaries must match.
1043
+ */
1011
1044
  drawBatches<Inputs extends GPUVectorModelInputs = GPUVectorModelInputs>(
1012
1045
  renderPass: RenderPass,
1013
1046
  {vectors, onBatch}: GPUVectorModelDrawBatchesOptions<Inputs>
@@ -1026,6 +1059,20 @@ export class GPUVectorModel {
1026
1059
  const previousIsInstanced = this.isInstanced;
1027
1060
  const previousVertexCountSet = this._vertexCountSet;
1028
1061
  const drawingVectorBatches = this.drawingVectorBatches;
1062
+ const batchUniformStore =
1063
+ this.device.type === 'webgpu' && batches.length
1064
+ ? new UniformStore(this.device, this.shaderInputs.modules)
1065
+ : undefined;
1066
+ if (batchUniformStore && this._uniformStore.uniformBuffers.size) {
1067
+ this.batchUniformBuffer ??= new BatchUniformBuffer(this.device);
1068
+ let batchByteLength = 0;
1069
+ for (const moduleName of this._uniformStore.uniformBuffers.keys()) {
1070
+ batchByteLength += this.batchUniformBuffer.getAlignedByteLength(
1071
+ batchUniformStore.getUniformBufferData(moduleName).byteLength
1072
+ );
1073
+ }
1074
+ this.batchUniformBuffer.prepare(batchByteLength * batches.length);
1075
+ }
1029
1076
  this.drawingVectorBatches = true;
1030
1077
  let drawSuccess = true;
1031
1078
  try {
@@ -1033,9 +1080,29 @@ export class GPUVectorModel {
1033
1080
  this.setGPUData(batch.data);
1034
1081
  this.setBatchDrawCount(batch.rowCount);
1035
1082
  onBatch?.(batch);
1036
- drawSuccess = GPUVectorModel.prototype.draw.call(this, renderPass) && drawSuccess;
1083
+ const managedBindings: Record<string, ModelBinding> = {};
1084
+ try {
1085
+ if (batchUniformStore) {
1086
+ batchUniformStore.setUniforms(this.shaderInputs.getUniformValues());
1087
+ for (const [moduleName, buffer] of this._uniformStore.uniformBuffers) {
1088
+ const bindingName = `${moduleName}Uniforms`;
1089
+ // Explicit bindings are caller-owned and must not be replaced.
1090
+ if (this.bindings[bindingName] !== buffer) continue;
1091
+ managedBindings[bindingName] = buffer;
1092
+ this.setBindings({
1093
+ [bindingName]: this.batchUniformBuffer!.write(
1094
+ batchUniformStore.getUniformBufferData(moduleName)
1095
+ )
1096
+ });
1097
+ }
1098
+ }
1099
+ drawSuccess = GPUVectorModel.prototype.draw.call(this, renderPass) && drawSuccess;
1100
+ } finally {
1101
+ this.setBindings(managedBindings);
1102
+ }
1037
1103
  }
1038
1104
  } finally {
1105
+ batchUniformStore?.destroy();
1039
1106
  this.setAttributes(previousAttributes, {byteOffsets: previousAttributeByteOffsets});
1040
1107
  for (const name of Object.keys(this.bindings)) {
1041
1108
  if (!(name in previousBindings)) delete this.bindings[name];
@@ -1067,9 +1134,16 @@ export class GPUVectorModel {
1067
1134
  );
1068
1135
  }
1069
1136
 
1137
+ private validateVectorLengthPolicy(): void {
1138
+ // Independent lengths cannot determine a common draw count.
1139
+ assert(this.props.enforceMatchingVectorLengths !== false || this.props.inferDrawCount === 'no');
1140
+ }
1141
+
1070
1142
  private setBatchDrawCount(
1071
1143
  rowCount: number,
1072
- count: GPUVectorModelCount = this.props.gpuVectorCount
1144
+ count: GPUVectorModelCount = this.props.inferDrawCount === 'no'
1145
+ ? 'none'
1146
+ : this.props.inferDrawCount
1073
1147
  ): void {
1074
1148
  if (count === 'instance') {
1075
1149
  this.setInstanceCount(rowCount);
@@ -1103,13 +1177,22 @@ export class GPUVectorModel {
1103
1177
  this.getExplicitVectorLayouts(geometry.inputs) ?? geometry.sourceLayouts;
1104
1178
  const attributeLayouts =
1105
1179
  this.getExplicitVectorLayouts(attributes.inputs) ?? attributes.sourceLayouts;
1106
- geometry.setInputs(geometry.inputs, geometryLayouts, 'vertex');
1180
+ geometry.setInputs(
1181
+ geometry.inputs,
1182
+ geometryLayouts,
1183
+ 'vertex',
1184
+ this.props.enforceMatchingVectorLengths
1185
+ );
1107
1186
  attributes.setInputs(
1108
1187
  attributes.inputs,
1109
1188
  attributeLayouts,
1110
- this.isInstanced ? 'instance' : 'vertex'
1189
+ this.isInstanced ? 'instance' : 'vertex',
1190
+ this.props.enforceMatchingVectorLengths
1111
1191
  );
1112
- if (!this.isInstanced || attributes.vertexCount !== undefined)
1192
+ if (
1193
+ this.props.enforceMatchingVectorLengths &&
1194
+ (!this.isInstanced || attributes.vertexCount !== undefined)
1195
+ )
1113
1196
  validateGPUVectorBatchStructure([
1114
1197
  ...Object.values(geometry.inputs),
1115
1198
  ...Object.values(attributes.inputs)