@luma.gl/engine 9.4.0-alpha.4 → 9.4.0-beta.2

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 (255) hide show
  1. package/LICENSE +5 -1
  2. package/dist/animation/animation-clip.d.ts +18 -0
  3. package/dist/animation/animation-clip.d.ts.map +1 -0
  4. package/dist/animation/animation-clip.js +15 -0
  5. package/dist/animation/animation-clip.js.map +1 -0
  6. package/dist/animation/animation-interpolation.d.ts +18 -0
  7. package/dist/animation/animation-interpolation.d.ts.map +1 -0
  8. package/dist/animation/animation-interpolation.js +101 -0
  9. package/dist/animation/animation-interpolation.js.map +1 -0
  10. package/dist/animation/animation-mixer.d.ts +88 -0
  11. package/dist/animation/animation-mixer.d.ts.map +1 -0
  12. package/dist/animation/animation-mixer.js +287 -0
  13. package/dist/animation/animation-mixer.js.map +1 -0
  14. package/dist/animation/animation-track.d.ts +42 -0
  15. package/dist/animation/animation-track.d.ts.map +1 -0
  16. package/dist/animation/animation-track.js +34 -0
  17. package/dist/animation/animation-track.js.map +1 -0
  18. package/dist/animation/animator.js +1 -1
  19. package/dist/animation/animator.js.map +1 -1
  20. package/dist/animation/key-frames.js +1 -1
  21. package/dist/animation/key-frames.js.map +1 -1
  22. package/dist/animation/morph-targets.d.ts +15 -0
  23. package/dist/animation/morph-targets.d.ts.map +1 -0
  24. package/dist/animation/morph-targets.js +151 -0
  25. package/dist/animation/morph-targets.js.map +1 -0
  26. package/dist/animation/skin.d.ts +18 -0
  27. package/dist/animation/skin.d.ts.map +1 -0
  28. package/dist/animation/skin.js +30 -0
  29. package/dist/animation/skin.js.map +1 -0
  30. package/dist/animation/timeline.js +1 -1
  31. package/dist/animation/timeline.js.map +1 -1
  32. package/dist/animation-loop/animation-loop-template.js +1 -1
  33. package/dist/animation-loop/animation-loop-template.js.map +1 -1
  34. package/dist/animation-loop/animation-loop.d.ts +5 -4
  35. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  36. package/dist/animation-loop/animation-loop.js +3 -3
  37. package/dist/animation-loop/animation-loop.js.map +1 -1
  38. package/dist/animation-loop/animation-props.d.ts +1 -1
  39. package/dist/animation-loop/animation-props.js +1 -1
  40. package/dist/animation-loop/animation-props.js.map +1 -1
  41. package/dist/animation-loop/make-animation-loop.d.ts +1 -1
  42. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  43. package/dist/animation-loop/make-animation-loop.js +6 -3
  44. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  45. package/dist/animation-loop/request-animation-frame.js +1 -1
  46. package/dist/animation-loop/request-animation-frame.js.map +1 -1
  47. package/dist/application-utils/load-file.js +1 -1
  48. package/dist/application-utils/load-file.js.map +1 -1
  49. package/dist/application-utils/random.js +1 -1
  50. package/dist/application-utils/random.js.map +1 -1
  51. package/dist/compute/buffer-transform.d.ts +1 -1
  52. package/dist/compute/buffer-transform.d.ts.map +1 -1
  53. package/dist/compute/buffer-transform.js +1 -1
  54. package/dist/compute/buffer-transform.js.map +1 -1
  55. package/dist/compute/computation.d.ts +1 -1
  56. package/dist/compute/computation.d.ts.map +1 -1
  57. package/dist/compute/computation.js +11 -6
  58. package/dist/compute/computation.js.map +1 -1
  59. package/dist/compute/swap.js +1 -1
  60. package/dist/compute/swap.js.map +1 -1
  61. package/dist/compute/texture-transform.js +1 -1
  62. package/dist/compute/texture-transform.js.map +1 -1
  63. package/dist/controls/orbit-controls.d.ts +61 -0
  64. package/dist/controls/orbit-controls.d.ts.map +1 -0
  65. package/dist/controls/orbit-controls.js +179 -0
  66. package/dist/controls/orbit-controls.js.map +1 -0
  67. package/dist/debug/copy-texture-to-image.js +1 -1
  68. package/dist/debug/copy-texture-to-image.js.map +1 -1
  69. package/dist/debug/debug-framebuffer.js +1 -1
  70. package/dist/debug/debug-framebuffer.js.map +1 -1
  71. package/dist/debug/debug-shader-layout.js +1 -1
  72. package/dist/debug/debug-shader-layout.js.map +1 -1
  73. package/dist/debug/pixel-data-utils.js +1 -1
  74. package/dist/debug/pixel-data-utils.js.map +1 -1
  75. package/dist/dist.dev.js +7588 -6260
  76. package/dist/dist.min.js +31 -31
  77. package/dist/dynamic-buffer/dynamic-buffer.js +1 -1
  78. package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -1
  79. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  80. package/dist/dynamic-texture/dynamic-texture.js +3 -2
  81. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  82. package/dist/dynamic-texture/texture-binding-source.js +1 -1
  83. package/dist/dynamic-texture/texture-binding-source.js.map +1 -1
  84. package/dist/dynamic-texture/texture-data.js +1 -1
  85. package/dist/dynamic-texture/texture-data.js.map +1 -1
  86. package/dist/dynamic-texture/video-texture.js +1 -1
  87. package/dist/dynamic-texture/video-texture.js.map +1 -1
  88. package/dist/geometries/cone-geometry.js +1 -1
  89. package/dist/geometries/cone-geometry.js.map +1 -1
  90. package/dist/geometries/cube-geometry.js +1 -1
  91. package/dist/geometries/cube-geometry.js.map +1 -1
  92. package/dist/geometries/cylinder-geometry.js +1 -1
  93. package/dist/geometries/cylinder-geometry.js.map +1 -1
  94. package/dist/geometries/ico-sphere-geometry.js +1 -1
  95. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  96. package/dist/geometry/geometry-table.js +1 -1
  97. package/dist/geometry/geometry-table.js.map +1 -1
  98. package/dist/geometry/geometry-utils.js +1 -1
  99. package/dist/geometry/geometry-utils.js.map +1 -1
  100. package/dist/geometry/geometry.js +1 -1
  101. package/dist/geometry/geometry.js.map +1 -1
  102. package/dist/geometry/gpu-geometry.js +1 -1
  103. package/dist/geometry/gpu-geometry.js.map +1 -1
  104. package/dist/geometry/mesh-simplification.d.ts +29 -0
  105. package/dist/geometry/mesh-simplification.d.ts.map +1 -0
  106. package/dist/geometry/mesh-simplification.js +402 -0
  107. package/dist/geometry/mesh-simplification.js.map +1 -0
  108. package/dist/index.cjs +9858 -1420
  109. package/dist/index.cjs.map +3 -4
  110. package/dist/index.d.ts +16 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +9 -1
  113. package/dist/index.js.map +1 -1
  114. package/dist/material/material-factory.js +1 -1
  115. package/dist/material/material-factory.js.map +1 -1
  116. package/dist/material/material.js +1 -1
  117. package/dist/material/material.js.map +1 -1
  118. package/dist/model/model.d.ts +1 -1
  119. package/dist/model/model.d.ts.map +1 -1
  120. package/dist/model/model.js +35 -10
  121. package/dist/model/model.js.map +1 -1
  122. package/dist/model/split-uniforms-and-bindings.js +1 -1
  123. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  124. package/dist/models/billboard-texture-model.js +1 -1
  125. package/dist/models/billboard-texture-model.js.map +1 -1
  126. package/dist/models/billboard-texture-module.js +1 -1
  127. package/dist/models/billboard-texture-module.js.map +1 -1
  128. package/dist/models/clip-space.js +1 -1
  129. package/dist/models/clip-space.js.map +1 -1
  130. package/dist/models/directional-light-model.js +1 -1
  131. package/dist/models/directional-light-model.js.map +1 -1
  132. package/dist/models/light-model-utils.js +1 -1
  133. package/dist/models/light-model-utils.js.map +1 -1
  134. package/dist/models/point-light-model.js +1 -1
  135. package/dist/models/point-light-model.js.map +1 -1
  136. package/dist/models/spot-light-model.js +1 -1
  137. package/dist/models/spot-light-model.js.map +1 -1
  138. package/dist/modules/picking/color-picking.js +1 -1
  139. package/dist/modules/picking/color-picking.js.map +1 -1
  140. package/dist/modules/picking/index-color-picking.js +1 -1
  141. package/dist/modules/picking/index-color-picking.js.map +1 -1
  142. package/dist/modules/picking/index-picking.js +1 -1
  143. package/dist/modules/picking/index-picking.js.map +1 -1
  144. package/dist/modules/picking/legacy-color-picking.js +1 -1
  145. package/dist/modules/picking/legacy-color-picking.js.map +1 -1
  146. package/dist/modules/picking/legacy-picking-manager.js +1 -1
  147. package/dist/modules/picking/legacy-picking-manager.js.map +1 -1
  148. package/dist/modules/picking/picking-manager.js +1 -1
  149. package/dist/modules/picking/picking-manager.js.map +1 -1
  150. package/dist/modules/picking/picking-uniforms.js +1 -1
  151. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  152. package/dist/modules/picking/picking.js +1 -1
  153. package/dist/modules/picking/picking.js.map +1 -1
  154. package/dist/passes/get-fragment-shader.js +1 -1
  155. package/dist/passes/get-fragment-shader.js.map +1 -1
  156. package/dist/passes/shader-pass-renderer.d.ts +19 -1
  157. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  158. package/dist/passes/shader-pass-renderer.js +180 -11
  159. package/dist/passes/shader-pass-renderer.js.map +1 -1
  160. package/dist/passes/texture-transform-module.js +1 -1
  161. package/dist/passes/texture-transform-module.js.map +1 -1
  162. package/dist/scenegraph/group-node.d.ts.map +1 -1
  163. package/dist/scenegraph/group-node.js +7 -1
  164. package/dist/scenegraph/group-node.js.map +1 -1
  165. package/dist/scenegraph/model-node.js +1 -1
  166. package/dist/scenegraph/model-node.js.map +1 -1
  167. package/dist/scenegraph/scenegraph-bounds.js +1 -1
  168. package/dist/scenegraph/scenegraph-bounds.js.map +1 -1
  169. package/dist/scenegraph/scenegraph-node.js +4 -4
  170. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  171. package/dist/shader-inputs.js +1 -1
  172. package/dist/shader-inputs.js.map +1 -1
  173. package/dist/utils/buffer-layout-helper.js +1 -1
  174. package/dist/utils/buffer-layout-helper.js.map +1 -1
  175. package/dist/utils/buffer-layout-order.js +1 -1
  176. package/dist/utils/buffer-layout-order.js.map +1 -1
  177. package/dist/utils/deep-equal.js +1 -1
  178. package/dist/utils/deep-equal.js.map +1 -1
  179. package/dist/utils/shader-module-utils.js +1 -1
  180. package/dist/utils/shader-module-utils.js.map +1 -1
  181. package/dist/utils/uid.js +1 -1
  182. package/dist/utils/uid.js.map +1 -1
  183. package/package.json +2 -2
  184. package/src/animation/animation-clip.ts +28 -0
  185. package/src/animation/animation-interpolation.ts +175 -0
  186. package/src/animation/animation-mixer.ts +370 -0
  187. package/src/animation/animation-track.ts +70 -0
  188. package/src/animation/animator.ts +1 -1
  189. package/src/animation/key-frames.ts +1 -1
  190. package/src/animation/morph-targets.ts +191 -0
  191. package/src/animation/skin.ts +50 -0
  192. package/src/animation/timeline.ts +1 -1
  193. package/src/animation-loop/animation-loop-template.ts +1 -1
  194. package/src/animation-loop/animation-loop.ts +8 -7
  195. package/src/animation-loop/animation-props.ts +2 -2
  196. package/src/animation-loop/make-animation-loop.ts +8 -5
  197. package/src/animation-loop/request-animation-frame.ts +1 -1
  198. package/src/application-utils/load-file.ts +1 -1
  199. package/src/application-utils/random.ts +1 -1
  200. package/src/compute/buffer-transform.ts +2 -2
  201. package/src/compute/computation.ts +22 -8
  202. package/src/compute/swap.ts +1 -1
  203. package/src/compute/texture-transform.ts +1 -1
  204. package/src/controls/orbit-controls.ts +248 -0
  205. package/src/debug/copy-texture-to-image.ts +1 -1
  206. package/src/debug/debug-framebuffer.ts +1 -1
  207. package/src/debug/debug-shader-layout.ts +1 -1
  208. package/src/debug/pixel-data-utils.ts +1 -1
  209. package/src/dynamic-buffer/dynamic-buffer.ts +1 -1
  210. package/src/dynamic-texture/dynamic-texture.ts +3 -2
  211. package/src/dynamic-texture/texture-binding-source.ts +1 -1
  212. package/src/dynamic-texture/texture-data.ts +1 -1
  213. package/src/dynamic-texture/video-texture.ts +1 -1
  214. package/src/geometries/cone-geometry.ts +1 -1
  215. package/src/geometries/cube-geometry.ts +1 -1
  216. package/src/geometries/cylinder-geometry.ts +1 -1
  217. package/src/geometries/ico-sphere-geometry.ts +1 -1
  218. package/src/geometry/geometry-table.ts +1 -1
  219. package/src/geometry/geometry-utils.ts +1 -1
  220. package/src/geometry/geometry.ts +1 -1
  221. package/src/geometry/gpu-geometry.ts +1 -1
  222. package/src/geometry/mesh-simplification.ts +554 -0
  223. package/src/index.ts +31 -1
  224. package/src/material/material-factory.ts +1 -1
  225. package/src/material/material.ts +1 -1
  226. package/src/model/model.ts +67 -12
  227. package/src/model/split-uniforms-and-bindings.ts +1 -1
  228. package/src/models/billboard-texture-model.ts +1 -1
  229. package/src/models/billboard-texture-module.ts +1 -1
  230. package/src/models/clip-space.ts +1 -1
  231. package/src/models/directional-light-model.ts +1 -1
  232. package/src/models/light-model-utils.ts +1 -1
  233. package/src/models/point-light-model.ts +1 -1
  234. package/src/models/spot-light-model.ts +1 -1
  235. package/src/modules/picking/color-picking.ts +1 -1
  236. package/src/modules/picking/index-color-picking.ts +1 -1
  237. package/src/modules/picking/index-picking.ts +1 -1
  238. package/src/modules/picking/legacy-color-picking.ts +1 -1
  239. package/src/modules/picking/legacy-picking-manager.ts +1 -1
  240. package/src/modules/picking/picking-manager.ts +1 -1
  241. package/src/modules/picking/picking-uniforms.ts +1 -1
  242. package/src/modules/picking/picking.ts +1 -1
  243. package/src/passes/get-fragment-shader.ts +1 -1
  244. package/src/passes/shader-pass-renderer.ts +246 -14
  245. package/src/passes/texture-transform-module.ts +1 -1
  246. package/src/scenegraph/group-node.ts +8 -1
  247. package/src/scenegraph/model-node.ts +1 -1
  248. package/src/scenegraph/scenegraph-bounds.ts +1 -1
  249. package/src/scenegraph/scenegraph-node.ts +4 -4
  250. package/src/shader-inputs.ts +1 -1
  251. package/src/utils/buffer-layout-helper.ts +1 -1
  252. package/src/utils/buffer-layout-order.ts +1 -1
  253. package/src/utils/deep-equal.ts +1 -1
  254. package/src/utils/shader-module-utils.ts +1 -1
  255. package/src/utils/uid.ts +1 -1
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  // A lot of imports, but then Model is where it all comes together...
6
6
  import {type TypedArray} from '@math.gl/types';
@@ -32,6 +32,7 @@ import {
32
32
  PipelineFactory,
33
33
  ShaderFactory,
34
34
  UniformStore,
35
+ assert,
35
36
  log,
36
37
  dataTypeDecoder,
37
38
  getAttributeInfosFromLayouts,
@@ -42,7 +43,9 @@ import type {
42
43
  ShaderBindingDebugRow,
43
44
  ShaderModule,
44
45
  ShaderPlugin,
45
- PlatformInfo
46
+ PlatformInfo,
47
+ GLSLShaderAssembler,
48
+ WGSLShaderAssembler
46
49
  } from '@luma.gl/shadertools';
47
50
  import {
48
51
  mergeShaderPluginModules,
@@ -156,7 +159,7 @@ export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
156
159
  pipelineFactory?: PipelineFactory;
157
160
  /** Factory used to create a {@link Shader}. Defaults to {@link Device} default factory. */
158
161
  shaderFactory?: ShaderFactory;
159
- /** Shader assembler. Defaults to the ShaderAssembler.getShaderAssembler() */
162
+ /** Shader assembler. Defaults to the shared assembler for the device's shader language. */
160
163
  shaderAssembler?: ShaderAssembler;
161
164
  };
162
165
 
@@ -207,7 +210,7 @@ export class Model {
207
210
  pipelineFactory: undefined!,
208
211
  shaderFactory: undefined!,
209
212
  transformFeedback: undefined!,
210
- shaderAssembler: ShaderAssembler.getDefaultShaderAssembler(),
213
+ shaderAssembler: ShaderAssembler.getDefaultShaderAssembler('glsl'),
211
214
 
212
215
  debugShaders: undefined!,
213
216
  disableWarnings: undefined!
@@ -316,7 +319,16 @@ export class Model {
316
319
  }
317
320
 
318
321
  constructor(device: Device, props: ModelProps) {
319
- this.props = {...Model.defaultProps, ...props};
322
+ const defaultShaderAssembler = Model.defaultProps.shaderAssembler;
323
+ this.props = {
324
+ ...Model.defaultProps,
325
+ ...props,
326
+ shaderAssembler:
327
+ props.shaderAssembler ??
328
+ (isShaderAssemblerForLanguage(defaultShaderAssembler, device.info.shadingLanguage)
329
+ ? defaultShaderAssembler
330
+ : ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
331
+ };
320
332
  props = this.props;
321
333
  this.id = props.id || uid('model');
322
334
  this.device = device;
@@ -358,7 +370,15 @@ export class Model {
358
370
  // TODO - this is wrong, compile a single shader
359
371
  if (isWebGPU && this.props.source) {
360
372
  // WGSL
361
- const {source, getUniforms, bindingTable} = this.props.shaderAssembler.assembleWGSLShader({
373
+ const shaderAssembler = this.props.shaderAssembler;
374
+ // WGSL sources require an assembler with WGSL-specific hooks and binding state.
375
+ assert(isShaderAssemblerForLanguage(shaderAssembler, 'wgsl'));
376
+ const {
377
+ source,
378
+ getUniforms,
379
+ bindingTable,
380
+ shaderLayout: assembledShaderLayout
381
+ } = shaderAssembler.assembleWGSLShader({
362
382
  platformInfo,
363
383
  ...this.props,
364
384
  modules,
@@ -371,12 +391,14 @@ export class Model {
371
391
  // @ts-expect-error
372
392
  this._getModuleUniforms = getUniforms;
373
393
  this._bindingTable = bindingTable;
374
- // Extract shader layout after modules have been added to WGSL source, to include any bindings added by modules
375
- const reflectedShaderLayout = (
376
- device as Device & {getShaderLayout?: (source: string) => any}
377
- ).getShaderLayout?.(this.source);
394
+ // Infer the layout after modules have been added so their bindings are included.
395
+ const scannedOrReflectedShaderLayout =
396
+ assembledShaderLayout ??
397
+ (device as Device & {getShaderLayout?: (source: string) => any}).getShaderLayout?.(
398
+ this.source
399
+ );
378
400
  const inferredShaderLayout = normalizeShaderPluginAttributeNames(
379
- reflectedShaderLayout,
401
+ scannedOrReflectedShaderLayout,
380
402
  resolvedPlugins.vertexInputs
381
403
  );
382
404
  const shaderLayout = mergeInferredShaderLayout(
@@ -388,7 +410,10 @@ export class Model {
388
410
  mergeShaderModuleBindingsIntoLayout(shaderLayout || null, modules) || null;
389
411
  } else {
390
412
  // GLSL
391
- const {vs, fs, getUniforms} = this.props.shaderAssembler.assembleGLSLShaderPair({
413
+ const shaderAssembler = this.props.shaderAssembler;
414
+ // GLSL shader pairs require an assembler with GLSL-specific hooks.
415
+ assert(isShaderAssemblerForLanguage(shaderAssembler, 'glsl'));
416
+ const {vs, fs, getUniforms} = shaderAssembler.assembleGLSLShaderPair({
392
417
  platformInfo,
393
418
  ...this.props,
394
419
  modules,
@@ -1298,6 +1323,36 @@ export class Model {
1298
1323
 
1299
1324
  // HELPERS
1300
1325
 
1326
+ function isShaderAssemblerForLanguage(
1327
+ shaderAssembler: ShaderAssembler,
1328
+ shaderLanguage: 'glsl'
1329
+ ): shaderAssembler is GLSLShaderAssembler;
1330
+ function isShaderAssemblerForLanguage(
1331
+ shaderAssembler: ShaderAssembler,
1332
+ shaderLanguage: 'wgsl'
1333
+ ): shaderAssembler is WGSLShaderAssembler;
1334
+ function isShaderAssemblerForLanguage(
1335
+ shaderAssembler: ShaderAssembler,
1336
+ shaderLanguage: 'glsl' | 'wgsl'
1337
+ ): shaderAssembler is GLSLShaderAssembler | WGSLShaderAssembler;
1338
+ function isShaderAssemblerForLanguage(
1339
+ shaderAssembler: ShaderAssembler,
1340
+ shaderLanguage: 'glsl' | 'wgsl'
1341
+ ): boolean {
1342
+ if (
1343
+ shaderAssembler.shaderLanguage !== undefined &&
1344
+ shaderAssembler.shaderLanguage !== shaderLanguage
1345
+ ) {
1346
+ return false;
1347
+ }
1348
+
1349
+ return shaderLanguage === 'glsl'
1350
+ ? 'assembleGLSLShaderPair' in shaderAssembler &&
1351
+ typeof shaderAssembler.assembleGLSLShaderPair === 'function'
1352
+ : 'assembleWGSLShader' in shaderAssembler &&
1353
+ typeof shaderAssembler.assembleWGSLShader === 'function';
1354
+ }
1355
+
1301
1356
  function normalizeShaderPluginAttributeNames(
1302
1357
  shaderLayout: ShaderLayout | null | undefined,
1303
1358
  vertexInputs: Record<string, AttributeShaderType>
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Binding, CompositeShaderType, UniformValue} from '@luma.gl/core';
6
6
  import type {ShaderModuleUniformValue} from '@luma.gl/shadertools';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device, type CommandEncoder, Texture} from '@luma.gl/core';
6
6
  import type {ShaderModule} from '@luma.gl/shadertools';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {ShaderModule} from '@luma.gl/shadertools';
6
6
 
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  // ClipSpace
6
6
  import {Device} from '@luma.gl/core';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device} from '@luma.gl/core';
6
6
  import {ConeGeometry} from '../geometries/cone-geometry';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Buffer, Device, type RenderPass, type RenderPipelineParameters} from '@luma.gl/core';
6
6
  import {Matrix4, type NumericArray} from '@math.gl/core';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device} from '@luma.gl/core';
6
6
  import {SphereGeometry} from '../geometries/sphere-geometry';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device} from '@luma.gl/core';
6
6
  import {ConeGeometry} from '../geometries/cone-geometry';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ShaderModule} from '@luma.gl/shadertools';
6
6
 
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ShaderModule} from '@luma.gl/shadertools';
6
6
 
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ShaderModule} from '@luma.gl/shadertools';
6
6
 
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {picking as shadertoolsPicking} from '@luma.gl/shadertools';
6
6
 
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device, Framebuffer} from '@luma.gl/core';
6
6
  import {picking} from '@luma.gl/shadertools';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Buffer, Device, Framebuffer, Texture} from '@luma.gl/core';
6
6
  import {ShaderInputs} from '../../shader-inputs';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {NumberArray4} from '@math.gl/types';
6
6
  import type {ShaderModule} from '@luma.gl/shadertools';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ShaderModule} from '@luma.gl/shadertools';
6
6
  import type {Device} from '@luma.gl/core';
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {ShaderPass} from '@luma.gl/shadertools';
6
6
 
@@ -1,11 +1,12 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import type {Binding, CommandEncoder, TextureFormatColor} from '@luma.gl/core';
6
- import {Device, Framebuffer, RenderPass, Texture} from '@luma.gl/core';
5
+ import type {Binding, BindingDeclaration, CommandEncoder, TextureFormatColor} from '@luma.gl/core';
6
+ import {Buffer, Device, Framebuffer, RenderPass, Texture} from '@luma.gl/core';
7
7
  import type {
8
8
  ShaderPass,
9
+ ShaderPassComputeOptimization,
9
10
  ShaderPassInputSource,
10
11
  ShaderPassPipeline,
11
12
  ShaderPassRenderTarget
@@ -16,6 +17,7 @@ import {DynamicTexture} from '../dynamic-texture/dynamic-texture';
16
17
  import type {TextureBindingSource} from '../dynamic-texture/texture-binding-source';
17
18
  import {ClipSpace} from '../models/clip-space';
18
19
  import {SwapFramebuffers} from '../compute/swap';
20
+ import {Computation} from '../compute/computation';
19
21
  import {BackgroundTextureModel} from '../models/billboard-texture-model';
20
22
 
21
23
  import {getFragmentShaderForRenderPass} from './get-fragment-shader';
@@ -237,6 +239,12 @@ export class ShaderPassRenderer {
237
239
  try {
238
240
  for (const passRenderer of this.passRenderers) {
239
241
  passRenderer.initializeHistoryTargets(originalTexture, this.textureModel, commandEncoder);
242
+ passRenderer.runComputeOptimization({
243
+ commandEncoder,
244
+ originalTexture,
245
+ previousTexture,
246
+ runtimeUniforms: options.uniforms || {}
247
+ });
240
248
  for (const execution of passRenderer.subPassExecutions) {
241
249
  const outputName = execution.output || 'previous';
242
250
  const outputFramebuffer: Framebuffer =
@@ -305,6 +313,7 @@ class PassRenderer {
305
313
  passDefinition: ShaderPassLike;
306
314
  renderTargets: Record<string, ManagedRenderTarget>;
307
315
  subPassExecutions: EffectiveSubPass[];
316
+ computeRenderer?: PipelineComputeRenderer;
308
317
 
309
318
  constructor(
310
319
  device: Device,
@@ -319,7 +328,20 @@ class PassRenderer {
319
328
  if (isShaderPassPipeline(passDefinition)) {
320
329
  validateRenderTargetNames(passDefinition.name, passDefinition.renderTargets || {});
321
330
  this.renderTargets = createManagedRenderTargets(device, passDefinition.renderTargets || {});
322
- this.subPassExecutions = passDefinition.steps.flatMap(step =>
331
+ if (supportsComputeOptimization(device, passDefinition)) {
332
+ this.computeRenderer = new PipelineComputeRenderer(
333
+ device,
334
+ passDefinition.compute!,
335
+ this.renderTargets,
336
+ shaderInputs
337
+ );
338
+ }
339
+ const executableSteps = this.computeRenderer
340
+ ? passDefinition.steps.filter(
341
+ step => !passDefinition.compute!.replacedPasses.includes(step.shaderPass.name)
342
+ )
343
+ : passDefinition.steps;
344
+ this.subPassExecutions = executableSteps.flatMap(step =>
323
345
  this.createStepExecutions(passDefinition, step, flipY)
324
346
  );
325
347
  return;
@@ -334,6 +356,7 @@ class PassRenderer {
334
356
  }
335
357
 
336
358
  destroy() {
359
+ this.computeRenderer?.destroy();
337
360
  for (const execution of this.subPassExecutions) {
338
361
  execution.subPassRenderer.destroy();
339
362
  }
@@ -344,6 +367,26 @@ class PassRenderer {
344
367
  resizeManagedRenderTargets(this.device, this.renderTargets, size);
345
368
  }
346
369
 
370
+ runComputeOptimization(options: {
371
+ commandEncoder: CommandEncoder;
372
+ originalTexture: Texture;
373
+ previousTexture: Texture;
374
+ runtimeUniforms: Record<string, Record<string, unknown>>;
375
+ }): void {
376
+ if (!this.computeRenderer) {
377
+ return;
378
+ }
379
+ const sourceTexture = this.resolveInputTexture(
380
+ this.computeRenderer.optimization.input,
381
+ options.originalTexture,
382
+ options.previousTexture
383
+ );
384
+ this.computeRenderer.encode(options.commandEncoder, sourceTexture, options.runtimeUniforms);
385
+ for (const targetName of Object.values(this.computeRenderer.optimization.outputs)) {
386
+ this.markTargetWritten(targetName);
387
+ }
388
+ }
389
+
347
390
  resetHistory(): void {
348
391
  for (const renderTarget of Object.values(this.renderTargets)) {
349
392
  renderTarget.historyInitialized = false;
@@ -458,7 +501,7 @@ class PassRenderer {
458
501
  `${execution.ownerName}: subpass cannot read and write render target "${outputName}" in the same draw`
459
502
  );
460
503
  }
461
- if (bindingName === 'sourceTexture' && texture === outputTexture) {
504
+ if (texture === outputTexture) {
462
505
  throw new Error(
463
506
  `${execution.ownerName}: subpass cannot sample from the render target it is writing to`
464
507
  );
@@ -548,6 +591,109 @@ class PassRenderer {
548
591
  }
549
592
  }
550
593
 
594
+ /** Executes one optional WebGPU compute replacement before the remaining fragment passes. */
595
+ class PipelineComputeRenderer {
596
+ readonly optimization: ShaderPassComputeOptimization;
597
+
598
+ private readonly renderTargets: Record<string, ManagedRenderTarget>;
599
+ private readonly shaderInputs: ShaderInputs;
600
+ private readonly computation: Computation;
601
+ private readonly parameterBuffer: Buffer;
602
+
603
+ constructor(
604
+ device: Device,
605
+ optimization: ShaderPassComputeOptimization,
606
+ renderTargets: Record<string, ManagedRenderTarget>,
607
+ shaderInputs: ShaderInputs
608
+ ) {
609
+ this.optimization = optimization;
610
+ this.renderTargets = renderTargets;
611
+ this.shaderInputs = shaderInputs;
612
+ this.parameterBuffer = device.createBuffer({
613
+ id: `${optimization.name}-parameters`,
614
+ byteLength: Math.max(Math.ceil(optimization.uniformNames.length / 4) * 16, 16),
615
+ usage: Buffer.UNIFORM | Buffer.COPY_DST
616
+ });
617
+ const outputBindings: BindingDeclaration[] = Object.entries(optimization.outputs).map(
618
+ ([bindingName, targetName], outputIndex) => ({
619
+ name: bindingName,
620
+ type: 'storage',
621
+ group: 0,
622
+ location: outputIndex + 2,
623
+ access: 'write-only',
624
+ format: renderTargets[targetName].texture.format
625
+ })
626
+ );
627
+ try {
628
+ this.computation = new Computation(device, {
629
+ id: optimization.name,
630
+ source: optimization.source,
631
+ shaderLayout: {
632
+ bindings: [
633
+ {name: optimization.uniformBinding, type: 'uniform', group: 0, location: 0},
634
+ {
635
+ name: 'sourceTexture',
636
+ type: 'texture',
637
+ group: 0,
638
+ location: 1,
639
+ sampleType: 'unfilterable-float'
640
+ },
641
+ ...outputBindings
642
+ ]
643
+ }
644
+ });
645
+ } catch (error) {
646
+ this.parameterBuffer.destroy();
647
+ throw error;
648
+ }
649
+ }
650
+
651
+ encode(
652
+ commandEncoder: CommandEncoder,
653
+ sourceTexture: Texture,
654
+ runtimeUniforms: Record<string, Record<string, unknown>>
655
+ ): void {
656
+ const effectiveUniforms = {
657
+ ...(this.shaderInputs.getUniformValues()[this.optimization.uniformModule] || {}),
658
+ ...this.optimization.uniforms,
659
+ ...(runtimeUniforms[this.optimization.uniformModule] || {})
660
+ };
661
+ const uniformValues = new Float32Array(
662
+ Math.max(Math.ceil(this.optimization.uniformNames.length / 4) * 4, 4)
663
+ );
664
+ for (const [uniformIndex, uniformName] of this.optimization.uniformNames.entries()) {
665
+ const value = effectiveUniforms[uniformName];
666
+ uniformValues[uniformIndex] = typeof value === 'number' ? value : 0;
667
+ }
668
+ this.parameterBuffer.write(uniformValues);
669
+
670
+ const outputEntries = Object.entries(this.optimization.outputs);
671
+ const bindings: Record<string, Binding> = {
672
+ [this.optimization.uniformBinding]: this.parameterBuffer,
673
+ sourceTexture: sourceTexture.view
674
+ };
675
+ for (const [bindingName, targetName] of outputEntries) {
676
+ bindings[bindingName] = this.renderTargets[targetName].texture.view;
677
+ }
678
+ this.computation.setBindings(bindings);
679
+ this.computation.predraw(commandEncoder);
680
+ const dispatchTarget = this.renderTargets[outputEntries[0][1]].texture;
681
+ const computePass = commandEncoder.beginComputePass({id: this.optimization.name});
682
+ this.computation.dispatch(
683
+ computePass,
684
+ Math.ceil(dispatchTarget.width / this.optimization.workgroupSize[0]),
685
+ Math.ceil(dispatchTarget.height / this.optimization.workgroupSize[1]),
686
+ 1
687
+ );
688
+ computePass.end();
689
+ }
690
+
691
+ destroy(): void {
692
+ this.computation.destroy();
693
+ this.parameterBuffer.destroy();
694
+ }
695
+ }
696
+
551
697
  /** Renders a single subpass of a `ShaderPass`. */
552
698
  class SubPassRenderer {
553
699
  model: ClipSpace;
@@ -618,6 +764,34 @@ function isShaderPassPipeline(shaderPass: ShaderPassLike): shaderPass is ShaderP
618
764
  return 'steps' in shaderPass;
619
765
  }
620
766
 
767
+ function supportsComputeOptimization(device: Device, pipeline: ShaderPassPipeline): boolean {
768
+ const optimization = pipeline.compute;
769
+ if (!optimization || device.type !== 'webgpu') {
770
+ return false;
771
+ }
772
+
773
+ const outputNames = Object.values(optimization.outputs);
774
+ if (
775
+ outputNames.length === 0 ||
776
+ outputNames.length > device.limits.maxStorageTexturesPerShaderStage ||
777
+ optimization.workgroupSize[0] > device.limits.maxComputeWorkgroupSizeX ||
778
+ optimization.workgroupSize[1] > device.limits.maxComputeWorkgroupSizeY ||
779
+ optimization.workgroupSize[0] * optimization.workgroupSize[1] >
780
+ device.limits.maxComputeInvocationsPerWorkgroup
781
+ ) {
782
+ return false;
783
+ }
784
+
785
+ return outputNames.every(targetName => {
786
+ const target = pipeline.renderTargets?.[targetName];
787
+ if (!target?.storage) {
788
+ return false;
789
+ }
790
+ const format = target.format || device.preferredColorFormat;
791
+ return device.getTextureFormatCapabilities(format).store;
792
+ });
793
+ }
794
+
621
795
  function validateShaderPassDoesNotOwnRenderTargets(
622
796
  shaderPass: ShaderPass,
623
797
  ownerName: string
@@ -706,17 +880,66 @@ function createManagedRenderTargets(
706
880
  renderTargets: Record<string, ShaderPassRenderTarget>
707
881
  ): Record<string, ManagedRenderTarget> {
708
882
  const size = device.getCanvasContext().getDrawingBufferSize();
709
- return Object.entries(renderTargets).reduce(
710
- (managedRenderTargets, [name, spec]) => ({
711
- ...managedRenderTargets,
712
- [name]: createManagedRenderTarget(device, name, spec, size)
713
- }),
714
- {} as Record<string, ManagedRenderTarget>
883
+ const managedRenderTargets: Record<string, ManagedRenderTarget> = {};
884
+
885
+ for (const [name, spec] of Object.entries(renderTargets)) {
886
+ if (spec.aliasFor) {
887
+ const aliasedTarget = managedRenderTargets[spec.aliasFor];
888
+ if (!aliasedTarget) {
889
+ throw new Error(`${name}: target alias references an unknown earlier target`);
890
+ }
891
+ const targetSize = getRenderTargetSize(size, spec.scale);
892
+ const targetFormat = spec.format || device.preferredColorFormat;
893
+ if (
894
+ spec.lifetime === 'history' ||
895
+ aliasedTarget.spec.lifetime === 'history' ||
896
+ !hasMatchingRenderTargetScale(spec, aliasedTarget.spec) ||
897
+ aliasedTarget.texture.width !== targetSize[0] ||
898
+ aliasedTarget.texture.height !== targetSize[1] ||
899
+ aliasedTarget.texture.format !== targetFormat ||
900
+ (spec.storage && !aliasedTarget.spec.storage) ||
901
+ !hasMatchingRenderTargetSampler(spec, aliasedTarget.spec)
902
+ ) {
903
+ throw new Error(
904
+ `${name}: target alias must match a transient target's size, format, and sampler`
905
+ );
906
+ }
907
+ managedRenderTargets[name] = aliasedTarget;
908
+ continue;
909
+ }
910
+
911
+ managedRenderTargets[name] = createManagedRenderTarget(device, name, spec, size);
912
+ }
913
+
914
+ return managedRenderTargets;
915
+ }
916
+
917
+ function hasMatchingRenderTargetScale(
918
+ firstTarget: ShaderPassRenderTarget,
919
+ secondTarget: ShaderPassRenderTarget
920
+ ): boolean {
921
+ const firstScale = firstTarget.scale || [1, 1];
922
+ const secondScale = secondTarget.scale || [1, 1];
923
+ return firstScale[0] === secondScale[0] && firstScale[1] === secondScale[1];
924
+ }
925
+
926
+ function hasMatchingRenderTargetSampler(
927
+ firstTarget: ShaderPassRenderTarget,
928
+ secondTarget: ShaderPassRenderTarget
929
+ ): boolean {
930
+ const firstSampler = firstTarget.sampler || {};
931
+ const secondSampler = secondTarget.sampler || {};
932
+ const firstEntries = Object.entries(firstSampler);
933
+ return (
934
+ firstEntries.length === Object.keys(secondSampler).length &&
935
+ firstEntries.every(
936
+ ([name, value]) => secondSampler[name as keyof typeof secondSampler] === value
937
+ )
715
938
  );
716
939
  }
717
940
 
718
941
  function destroyManagedRenderTargets(renderTargets: Record<string, ManagedRenderTarget>): void {
719
- for (const renderTarget of Object.values(renderTargets)) {
942
+ for (const renderTarget of new Set(Object.values(renderTargets))) {
720
943
  renderTarget.framebuffer.destroy();
721
944
  renderTarget.texture.destroy();
722
945
  renderTarget.historyFramebuffer?.destroy();
@@ -729,7 +952,7 @@ function resizeManagedRenderTargets(
729
952
  renderTargets: Record<string, ManagedRenderTarget>,
730
953
  size: [width: number, height: number]
731
954
  ): void {
732
- for (const renderTarget of Object.values(renderTargets)) {
955
+ for (const renderTarget of new Set(Object.values(renderTargets))) {
733
956
  const targetSize = getRenderTargetSize(size, renderTarget.spec.scale);
734
957
  if (
735
958
  renderTarget.texture.width === targetSize[0] &&
@@ -796,7 +1019,16 @@ function createTargetResources(
796
1019
  width: targetSize[0],
797
1020
  height: targetSize[1],
798
1021
  format: spec.format || device.preferredColorFormat,
799
- usage: Texture.SAMPLE | Texture.RENDER | Texture.COPY_SRC | Texture.COPY_DST,
1022
+ usage:
1023
+ Texture.SAMPLE |
1024
+ Texture.RENDER |
1025
+ Texture.COPY_SRC |
1026
+ Texture.COPY_DST |
1027
+ (spec.storage &&
1028
+ device.type === 'webgpu' &&
1029
+ device.getTextureFormatCapabilities(spec.format || device.preferredColorFormat).store
1030
+ ? Texture.STORAGE
1031
+ : 0),
800
1032
  ...(spec.sampler ? {sampler: spec.sampler} : {})
801
1033
  });
802
1034
  const framebuffer = device.createFramebuffer({
@@ -1,6 +1,6 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ShaderModule} from '@luma.gl/shadertools';
6
6