@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.10

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 (187) hide show
  1. package/LICENSE +3 -1
  2. package/dist/animation/key-frames.d.ts +1 -1
  3. package/dist/animation/key-frames.d.ts.map +1 -1
  4. package/dist/animation/key-frames.js +51 -72
  5. package/dist/animation/timeline.d.ts +8 -8
  6. package/dist/animation/timeline.d.ts.map +1 -1
  7. package/dist/animation/timeline.js +95 -131
  8. package/dist/animation-loop/animation-loop-template.d.ts +23 -0
  9. package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
  10. package/dist/animation-loop/animation-loop-template.js +21 -0
  11. package/dist/{lib → animation-loop}/animation-loop.d.ts +31 -23
  12. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  13. package/dist/animation-loop/animation-loop.js +442 -0
  14. package/dist/{lib → animation-loop}/animation-props.d.ts +4 -5
  15. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  16. package/dist/animation-loop/animation-props.js +1 -0
  17. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  18. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  19. package/dist/animation-loop/make-animation-loop.js +32 -0
  20. package/dist/computation.d.ts +95 -0
  21. package/dist/computation.d.ts.map +1 -0
  22. package/dist/computation.js +248 -0
  23. package/dist/debug/copy-texture-to-image.d.ts +26 -0
  24. package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
  25. package/dist/debug/copy-texture-to-image.js +43 -0
  26. package/dist/debug/debug-framebuffer.d.ts +11 -0
  27. package/dist/debug/debug-framebuffer.d.ts.map +1 -0
  28. package/dist/debug/debug-framebuffer.js +46 -0
  29. package/dist/debug/debug-shader-layout.d.ts +9 -0
  30. package/dist/debug/debug-shader-layout.d.ts.map +1 -0
  31. package/dist/debug/debug-shader-layout.js +27 -0
  32. package/dist/debug/pixel-data-utils.d.ts +24 -0
  33. package/dist/debug/pixel-data-utils.d.ts.map +1 -0
  34. package/dist/debug/pixel-data-utils.js +39 -0
  35. package/dist/dist.dev.js +9592 -0
  36. package/dist/dist.min.js +102 -0
  37. package/dist/geometries/cone-geometry.d.ts +2 -2
  38. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  39. package/dist/geometries/cone-geometry.js +13 -18
  40. package/dist/geometries/cube-geometry.d.ts +2 -2
  41. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  42. package/dist/geometries/cube-geometry.js +192 -57
  43. package/dist/geometries/cylinder-geometry.d.ts +2 -2
  44. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  45. package/dist/geometries/cylinder-geometry.js +11 -15
  46. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  47. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  48. package/dist/geometries/ico-sphere-geometry.js +143 -171
  49. package/dist/geometries/plane-geometry.d.ts +2 -2
  50. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  51. package/dist/geometries/plane-geometry.js +95 -122
  52. package/dist/geometries/sphere-geometry.d.ts +2 -2
  53. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  54. package/dist/geometries/sphere-geometry.js +78 -101
  55. package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
  56. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  57. package/dist/geometries/truncated-cone-geometry.js +100 -134
  58. package/dist/geometry/geometry-table.d.ts +2 -2
  59. package/dist/geometry/geometry-table.d.ts.map +1 -1
  60. package/dist/geometry/geometry-table.js +3 -1
  61. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  62. package/dist/geometry/geometry-utils.js +35 -41
  63. package/dist/geometry/geometry.d.ts +43 -43
  64. package/dist/geometry/geometry.d.ts.map +1 -1
  65. package/dist/geometry/geometry.js +82 -139
  66. package/dist/geometry/gpu-geometry.d.ts +37 -0
  67. package/dist/geometry/gpu-geometry.d.ts.map +1 -0
  68. package/dist/geometry/gpu-geometry.js +90 -0
  69. package/dist/geometry/gpu-table.d.ts +1 -0
  70. package/dist/geometry/gpu-table.d.ts.map +1 -0
  71. package/dist/geometry/gpu-table.js +42 -0
  72. package/dist/index.cjs +3444 -0
  73. package/dist/index.cjs.map +7 -0
  74. package/dist/index.d.ts +43 -24
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +29 -15
  77. package/dist/lib/clip-space.d.ts +8 -0
  78. package/dist/lib/clip-space.d.ts.map +1 -1
  79. package/dist/lib/clip-space.js +43 -2
  80. package/dist/lib/pipeline-factory.d.ts +17 -51
  81. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  82. package/dist/lib/pipeline-factory.js +84 -209
  83. package/dist/lib/shader-factory.d.ts +17 -0
  84. package/dist/lib/shader-factory.d.ts.map +1 -0
  85. package/dist/lib/shader-factory.js +46 -0
  86. package/dist/model/model.d.ts +219 -0
  87. package/dist/model/model.d.ts.map +1 -0
  88. package/dist/model/model.js +659 -0
  89. package/dist/scenegraph/group-node.d.ts +21 -0
  90. package/dist/scenegraph/group-node.d.ts.map +1 -0
  91. package/dist/scenegraph/group-node.js +84 -0
  92. package/dist/scenegraph/model-node.d.ts +18 -0
  93. package/dist/scenegraph/model-node.d.ts.map +1 -0
  94. package/dist/scenegraph/model-node.js +35 -0
  95. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  96. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  97. package/dist/scenegraph/scenegraph-node.js +153 -0
  98. package/dist/shader-inputs.d.ts +63 -0
  99. package/dist/shader-inputs.d.ts.map +1 -0
  100. package/dist/shader-inputs.js +107 -0
  101. package/dist/transform/buffer-transform.d.ts +35 -0
  102. package/dist/transform/buffer-transform.d.ts.map +1 -0
  103. package/dist/transform/buffer-transform.js +70 -0
  104. package/dist/transform/texture-transform.d.ts +57 -0
  105. package/dist/transform/texture-transform.d.ts.map +1 -0
  106. package/dist/transform/texture-transform.js +117 -0
  107. package/dist.min.js +25 -0
  108. package/package.json +24 -14
  109. package/src/animation/timeline.ts +35 -34
  110. package/src/animation-loop/animation-loop-template.ts +25 -0
  111. package/src/{lib → animation-loop}/animation-loop.ts +114 -93
  112. package/src/{lib → animation-loop}/animation-props.ts +2 -2
  113. package/src/animation-loop/make-animation-loop.ts +53 -0
  114. package/src/computation.ts +346 -0
  115. package/src/debug/copy-texture-to-image.ts +70 -0
  116. package/src/debug/debug-framebuffer.ts +70 -0
  117. package/src/debug/debug-shader-layout.ts +38 -0
  118. package/src/debug/pixel-data-utils.ts +54 -0
  119. package/src/geometries/cone-geometry.ts +1 -1
  120. package/src/geometries/cube-geometry.ts +62 -56
  121. package/src/geometries/cylinder-geometry.ts +2 -2
  122. package/src/geometries/ico-sphere-geometry.ts +6 -5
  123. package/src/geometries/plane-geometry.ts +5 -4
  124. package/src/geometries/sphere-geometry.ts +4 -3
  125. package/src/geometries/truncated-cone-geometry.ts +6 -14
  126. package/src/geometry/geometry-table.ts +10 -7
  127. package/src/geometry/geometry-utils.ts +19 -3
  128. package/src/geometry/geometry.ts +68 -110
  129. package/src/geometry/gpu-geometry.ts +132 -0
  130. package/src/geometry/gpu-table.ts +41 -0
  131. package/src/index.ts +37 -10
  132. package/src/lib/clip-space.ts +32 -34
  133. package/src/lib/pipeline-factory.ts +83 -193
  134. package/src/lib/shader-factory.ts +57 -0
  135. package/src/model/model.ts +835 -0
  136. package/src/scenegraph/group-node.ts +107 -0
  137. package/src/scenegraph/model-node.ts +50 -0
  138. package/src/scenegraph/scenegraph-node.ts +204 -0
  139. package/src/shader-inputs.ts +157 -0
  140. package/src/transform/buffer-transform.ts +102 -0
  141. package/src/transform/texture-transform.ts +168 -0
  142. package/dist/animation/key-frames.js.map +0 -1
  143. package/dist/animation/timeline.js.map +0 -1
  144. package/dist/bundle.d.ts +0 -2
  145. package/dist/bundle.d.ts.map +0 -1
  146. package/dist/bundle.js +0 -5
  147. package/dist/bundle.js.map +0 -1
  148. package/dist/geometries/cone-geometry.js.map +0 -1
  149. package/dist/geometries/cube-geometry.js.map +0 -1
  150. package/dist/geometries/cylinder-geometry.js.map +0 -1
  151. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  152. package/dist/geometries/plane-geometry.js.map +0 -1
  153. package/dist/geometries/sphere-geometry.js.map +0 -1
  154. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  155. package/dist/geometry/geometry-table.js.map +0 -1
  156. package/dist/geometry/geometry-utils.js.map +0 -1
  157. package/dist/geometry/geometry.js.map +0 -1
  158. package/dist/geometry/primitive-utils.d.ts +0 -1
  159. package/dist/geometry/primitive-utils.d.ts.map +0 -1
  160. package/dist/geometry/primitive-utils.js +0 -2
  161. package/dist/geometry/primitive-utils.js.map +0 -1
  162. package/dist/index.js.map +0 -1
  163. package/dist/lib/animation-loop.d.ts.map +0 -1
  164. package/dist/lib/animation-loop.js +0 -480
  165. package/dist/lib/animation-loop.js.map +0 -1
  166. package/dist/lib/animation-props.d.ts.map +0 -1
  167. package/dist/lib/animation-props.js +0 -2
  168. package/dist/lib/animation-props.js.map +0 -1
  169. package/dist/lib/clip-space.js.map +0 -1
  170. package/dist/lib/model-utils.d.ts +0 -5
  171. package/dist/lib/model-utils.d.ts.map +0 -1
  172. package/dist/lib/model-utils.js +0 -45
  173. package/dist/lib/model-utils.js.map +0 -1
  174. package/dist/lib/model.d.ts +0 -41
  175. package/dist/lib/model.d.ts.map +0 -1
  176. package/dist/lib/model.js +0 -182
  177. package/dist/lib/model.js.map +0 -1
  178. package/dist/lib/pipeline-factory.js.map +0 -1
  179. package/dist/lib/render-loop.d.ts +0 -14
  180. package/dist/lib/render-loop.d.ts.map +0 -1
  181. package/dist/lib/render-loop.js +0 -49
  182. package/dist/lib/render-loop.js.map +0 -1
  183. package/src/bundle.ts +0 -4
  184. package/src/geometry/primitive-utils.ts +0 -30
  185. package/src/lib/model-utils.ts +0 -124
  186. package/src/lib/model.ts +0 -183
  187. package/src/lib/render-loop.ts +0 -58
package/dist/index.js CHANGED
@@ -1,15 +1,29 @@
1
- export { AnimationLoop } from './lib/animation-loop';
2
- export { RenderLoop } from './lib/render-loop';
3
- export { default as Model } from './lib/model';
4
- export { PipelineFactory } from './lib/pipeline-factory';
5
- export { Timeline } from './animation/timeline';
6
- export { KeyFrames } from './animation/key-frames';
7
- export { default as Geometry } from './geometry/geometry';
8
- export { ConeGeometry } from './geometries/cone-geometry';
9
- export { CubeGeometry } from './geometries/cube-geometry';
10
- export { CylinderGeometry } from './geometries/cylinder-geometry';
11
- export { IcoSphereGeometry } from './geometries/ico-sphere-geometry';
12
- export { PlaneGeometry } from './geometries/plane-geometry';
13
- export { SphereGeometry } from './geometries/sphere-geometry';
14
- export { TruncatedConeGeometry } from './geometries/truncated-cone-geometry';
15
- //# sourceMappingURL=index.js.map
1
+ // luma.gl Engine API
2
+ // Animation
3
+ export { Timeline } from "./animation/timeline.js";
4
+ export { KeyFrames } from "./animation/key-frames.js";
5
+ export { AnimationLoopTemplate } from "./animation-loop/animation-loop-template.js";
6
+ export { AnimationLoop } from "./animation-loop/animation-loop.js";
7
+ export { makeAnimationLoop } from "./animation-loop/make-animation-loop.js";
8
+ export { Model } from "./model/model.js";
9
+ export { BufferTransform } from "./transform/buffer-transform.js";
10
+ export { TextureTransform } from "./transform/texture-transform.js";
11
+ export { PipelineFactory } from "./lib/pipeline-factory.js";
12
+ export { ShaderFactory } from "./lib/shader-factory.js";
13
+ // Utils
14
+ export { ClipSpace } from "./lib/clip-space.js";
15
+ // Scenegraph Core nodes
16
+ export { ScenegraphNode } from "./scenegraph/scenegraph-node.js";
17
+ export { GroupNode } from "./scenegraph/group-node.js";
18
+ export { ModelNode } from "./scenegraph/model-node.js";
19
+ export { Geometry } from "./geometry/geometry.js";
20
+ export { GPUGeometry } from "./geometry/gpu-geometry.js";
21
+ export { ConeGeometry } from "./geometries/cone-geometry.js";
22
+ export { CubeGeometry } from "./geometries/cube-geometry.js";
23
+ export { CylinderGeometry } from "./geometries/cylinder-geometry.js";
24
+ export { IcoSphereGeometry } from "./geometries/ico-sphere-geometry.js";
25
+ export { PlaneGeometry } from "./geometries/plane-geometry.js";
26
+ export { SphereGeometry } from "./geometries/sphere-geometry.js";
27
+ export { TruncatedConeGeometry } from "./geometries/truncated-cone-geometry.js";
28
+ export { ShaderInputs as _ShaderInputs } from "./shader-inputs.js";
29
+ export { Computation } from "./computation.js";
@@ -1 +1,9 @@
1
+ import { Device } from '@luma.gl/core';
2
+ import { Model, ModelProps } from "../model/model.js";
3
+ /**
4
+ * A flat geometry that covers the "visible area" that the GPU renders.
5
+ */
6
+ export declare class ClipSpace extends Model {
7
+ constructor(device: Device, opts: Omit<ModelProps, 'vs' | 'vertexCount' | 'geometry'>);
8
+ }
1
9
  //# sourceMappingURL=clip-space.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clip-space.d.ts","sourceRoot":"","sources":["../../src/lib/clip-space.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"clip-space.d.ts","sourceRoot":"","sources":["../../src/lib/clip-space.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAO,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAC,KAAK,EAAE,UAAU,EAAC,0BAAuB;AAwBjD;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,aAAa,GAAG,UAAU,CAAC;CAkBtF"}
@@ -1,2 +1,43 @@
1
-
2
- //# sourceMappingURL=clip-space.js.map
1
+ // ClipSpace
2
+ import { glsl } from '@luma.gl/core';
3
+ import { Model } from "../model/model.js";
4
+ import { Geometry } from "../geometry/geometry.js";
5
+ const CLIPSPACE_VERTEX_SHADER = `\
6
+ #version 300 es
7
+ in vec2 aClipSpacePosition;
8
+ in vec2 aTexCoord;
9
+ in vec2 aCoordinate;
10
+ out vec2 position;
11
+ out vec2 coordinate;
12
+ out vec2 uv;
13
+ void main(void) {
14
+ gl_Position = vec4(aClipSpacePosition, 0., 1.);
15
+ position = aClipSpacePosition;
16
+ coordinate = aCoordinate;
17
+ uv = aTexCoord;
18
+ }
19
+ `;
20
+ /* eslint-disable indent, no-multi-spaces */
21
+ const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
22
+ /**
23
+ * A flat geometry that covers the "visible area" that the GPU renders.
24
+ */
25
+ export class ClipSpace extends Model {
26
+ constructor(device, opts) {
27
+ const TEX_COORDS = POSITIONS.map(coord => (coord === -1 ? 0 : coord));
28
+ super(device, {
29
+ ...opts,
30
+ vs: CLIPSPACE_VERTEX_SHADER,
31
+ vertexCount: 4,
32
+ geometry: new Geometry({
33
+ topology: 'triangle-strip',
34
+ vertexCount: 4,
35
+ attributes: {
36
+ aClipSpacePosition: { size: 2, value: new Float32Array(POSITIONS) },
37
+ aTexCoord: { size: 2, value: new Float32Array(TEX_COORDS) },
38
+ aCoordinate: { size: 2, value: new Float32Array(TEX_COORDS) }
39
+ }
40
+ })
41
+ });
42
+ }
43
+ }
@@ -1,60 +1,26 @@
1
- import type { RenderPipelineParameters, PrimitiveTopology, ShaderLayout } from '@luma.gl/api';
2
- import { Device, RenderPipeline } from '@luma.gl/api/';
3
- import type { ShaderModule } from '@luma.gl/shadertools';
4
- export declare type GetRenderPipelineOptions = {
5
- vs: string;
6
- fs: string | null;
7
- topology: PrimitiveTopology;
8
- layout?: ShaderLayout | null;
9
- parameters?: RenderPipelineParameters;
10
- modules?: ShaderModule[];
11
- defines?: Record<string, string | number | boolean>;
12
- inject?: Record<string, string>;
13
- transpileToGLSL100?: boolean;
14
- varyings?: string[];
15
- bufferMode?: number;
16
- };
17
- export declare type GetComputePipelineOptions = {
18
- cs: string;
19
- parameters?: RenderPipelineParameters;
20
- modules?: ShaderModule[];
21
- defines?: Record<string, string>;
22
- inject?: Record<string, string>;
23
- transpileToGLSL100?: boolean;
24
- varyings?: string[];
25
- bufferMode?: number;
26
- };
27
- declare type GetUniformsFunc = (props?: Record<string, any>) => Record<string, any>;
28
- /** Efficiently create shared pipelines with varying parameters */
1
+ import type { RenderPipelineProps, ComputePipelineProps } from '@luma.gl/core';
2
+ import { Device, RenderPipeline, ComputePipeline } from '@luma.gl/core';
3
+ export type PipelineFactoryProps = RenderPipelineProps;
4
+ /**
5
+ * Efficiently creates / caches pipelines
6
+ */
29
7
  export declare class PipelineFactory {
8
+ static defaultProps: Required<PipelineFactoryProps>;
30
9
  readonly device: Device;
31
- stateHash: number;
32
10
  private _hashCounter;
33
11
  private readonly _hashes;
34
- private readonly _useCounts;
35
- private readonly _pipelineCache;
36
- private readonly _getUniforms;
37
- private readonly _hookFunctions;
38
- private _defaultModules;
12
+ private readonly _renderPipelineCache;
13
+ private readonly _computePipelineCache;
14
+ /** Get the singleton default pipeline factory for the specified device */
39
15
  static getDefaultPipelineFactory(device: Device): PipelineFactory;
40
16
  constructor(device: Device);
41
- addDefaultModule(module: ShaderModule): void;
42
- removeDefaultModule(module: ShaderModule): void;
43
- addShaderHook(hook: any, opts?: any): void;
44
- createRenderPipeline(options: GetRenderPipelineOptions): {
45
- pipeline: RenderPipeline;
46
- getUniforms: GetUniformsFunc;
47
- };
48
- release(pipeline: RenderPipeline): void;
49
- getUniforms(pipeline: RenderPipeline): GetUniformsFunc;
50
- _createRenderPipeline(props: GetRenderPipelineOptions): {
51
- pipeline: RenderPipeline;
52
- getUniforms: GetUniformsFunc;
53
- };
17
+ /** Return a RenderPipeline matching props. Reuses a similar pipeline if already created. */
18
+ createRenderPipeline(props: RenderPipelineProps): RenderPipeline;
19
+ createComputePipeline(props: ComputePipelineProps): ComputePipeline;
20
+ release(pipeline: RenderPipeline | ComputePipeline): void;
21
+ private _hashComputePipeline;
54
22
  /** Calculate a hash based on all the inputs for a render pipeline */
55
- _hashRenderPipeline(props: GetRenderPipelineOptions): string;
56
- _getHash(key: string): number;
57
- _getModuleList(appModules?: ShaderModule[]): ShaderModule[];
23
+ private _hashRenderPipeline;
24
+ private _getHash;
58
25
  }
59
- export {};
60
26
  //# s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C5D,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ7B,cAAc,CAAC,UAAU,GAAE,YAAY,EAAO,GAAG,YAAY,EAAE;CAyBhE"}
1
+ {"version":3,"file":"pipeline-factory.d.ts","sourceRoot":"","sources":["../../src/lib/pipeline-factory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAEtE,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEvD;;GAEG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAoC;IAEvF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAG9B;IACP,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAG/B;IAEP,0EAA0E;IAC1E,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe;gBAMrD,MAAM,EAAE,MAAM;IAI1B,4FAA4F;IAC5F,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,cAAc;IAkBhE,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe;IAkBnE,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI;IAYzD,OAAO,CAAC,oBAAoB;IAK5B,qEAAqE;IACrE,OAAO,CAAC,mBAAmB;IAuB3B,OAAO,CAAC,QAAQ;CAMjB"}
@@ -1,219 +1,94 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { assembleShaders } from '@luma.gl/shadertools';
3
- const DEFAULT_RENDER_PIPELINE_OPTIONS = {
4
- vs: '',
5
- fs: '',
6
- modules: [],
7
- defines: {},
8
- inject: {},
9
- transpileToGLSL100: false,
10
- layout: null,
11
- varyings: [],
12
- bufferMode: 0x8c8d,
13
- topology: 'triangle-list',
14
- parameters: {}
15
- };
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { RenderPipeline, ComputePipeline } from '@luma.gl/core';
5
+ /**
6
+ * Efficiently creates / caches pipelines
7
+ */
16
8
  export class PipelineFactory {
17
- static getDefaultPipelineFactory(device) {
18
- device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);
19
- return device.defaultPipelineFactory;
20
- }
21
-
22
- constructor(device) {
23
- _defineProperty(this, "device", void 0);
24
-
25
- _defineProperty(this, "stateHash", 0);
26
-
27
- _defineProperty(this, "_hashCounter", 0);
28
-
29
- _defineProperty(this, "_hashes", {});
30
-
31
- _defineProperty(this, "_useCounts", {});
32
-
33
- _defineProperty(this, "_pipelineCache", {});
34
-
35
- _defineProperty(this, "_getUniforms", {});
36
-
37
- _defineProperty(this, "_hookFunctions", []);
38
-
39
- _defineProperty(this, "_defaultModules", []);
40
-
41
- this.device = device;
42
- }
43
-
44
- addDefaultModule(module) {
45
- if (!this._defaultModules.find(m => m.name === (typeof module === 'string' ? module : module.name))) {
46
- this._defaultModules.push(module);
9
+ static defaultProps = { ...RenderPipeline.defaultProps };
10
+ device;
11
+ _hashCounter = 0;
12
+ _hashes = {};
13
+ _renderPipelineCache = {};
14
+ _computePipelineCache = {};
15
+ /** Get the singleton default pipeline factory for the specified device */
16
+ static getDefaultPipelineFactory(device) {
17
+ device._lumaData.defaultPipelineFactory =
18
+ device._lumaData.defaultPipelineFactory || new PipelineFactory(device);
19
+ return device._lumaData.defaultPipelineFactory;
47
20
  }
48
-
49
- this.stateHash++;
50
- }
51
-
52
- removeDefaultModule(module) {
53
- const moduleName = typeof module === 'string' ? module : module.name;
54
- this._defaultModules = this._defaultModules.filter(m => m.name !== moduleName);
55
- this.stateHash++;
56
- }
57
-
58
- addShaderHook(hook, opts) {
59
- if (opts) {
60
- hook = Object.assign(opts, {
61
- hook
62
- });
21
+ constructor(device) {
22
+ this.device = device;
63
23
  }
64
-
65
- this._hookFunctions.push(hook);
66
-
67
- this.stateHash++;
68
- }
69
-
70
- createRenderPipeline(options) {
71
- const props = { ...DEFAULT_RENDER_PIPELINE_OPTIONS,
72
- ...options
73
- };
74
-
75
- const modules = this._getModuleList(props.modules);
76
-
77
- const hash = this._hashRenderPipeline({ ...props,
78
- modules
79
- });
80
-
81
- if (!this._pipelineCache[hash]) {
82
- const {
83
- pipeline,
84
- getUniforms
85
- } = this._createRenderPipeline({ ...props,
86
- modules
87
- });
88
-
89
- pipeline.hash = hash;
90
- this._pipelineCache[hash] = pipeline;
91
-
92
- this._getUniforms[hash] = getUniforms || (x => ({}));
93
-
94
- this._useCounts[hash] = 0;
24
+ /** Return a RenderPipeline matching props. Reuses a similar pipeline if already created. */
25
+ createRenderPipeline(props) {
26
+ const allProps = { ...RenderPipeline.defaultProps, ...props };
27
+ const hash = this._hashRenderPipeline(allProps);
28
+ if (!this._renderPipelineCache[hash]) {
29
+ const pipeline = this.device.createRenderPipeline({
30
+ ...allProps,
31
+ id: allProps.id ? `${allProps.id}-cached` : undefined
32
+ });
33
+ pipeline.hash = hash;
34
+ this._renderPipelineCache[hash] = { pipeline, useCount: 0 };
35
+ }
36
+ this._renderPipelineCache[hash].useCount++;
37
+ return this._renderPipelineCache[hash].pipeline;
95
38
  }
96
-
97
- this._useCounts[hash]++;
98
- return {
99
- pipeline: this._pipelineCache[hash],
100
- getUniforms: this._getUniforms[hash]
101
- };
102
- }
103
-
104
- release(pipeline) {
105
- const hash = pipeline.hash;
106
- this._useCounts[hash]--;
107
-
108
- if (this._useCounts[hash] === 0) {
109
- this._pipelineCache[hash].destroy();
110
-
111
- delete this._pipelineCache[hash];
112
- delete this._getUniforms[hash];
113
- delete this._useCounts[hash];
39
+ createComputePipeline(props) {
40
+ const allProps = { ...ComputePipeline.defaultProps, ...props };
41
+ const hash = this._hashComputePipeline(allProps);
42
+ if (!this._computePipelineCache[hash]) {
43
+ const pipeline = this.device.createComputePipeline({
44
+ ...allProps,
45
+ id: allProps.id ? `${allProps.id}-cached` : undefined
46
+ });
47
+ pipeline.hash = hash;
48
+ this._computePipelineCache[hash] = { pipeline, useCount: 0 };
49
+ }
50
+ this._computePipelineCache[hash].useCount++;
51
+ return this._computePipelineCache[hash].pipeline;
114
52
  }
115
- }
116
-
117
- getUniforms(pipeline) {
118
- return this._getUniforms[pipeline.hash] || null;
119
- }
120
-
121
- _createRenderPipeline(props) {
122
- const platformInfo = {
123
- gpu: this.device.info.gpu,
124
- features: this.device.features
125
- };
126
-
127
- if (!props.fs) {
128
- throw new Error('fs');
53
+ release(pipeline) {
54
+ const hash = pipeline.hash;
55
+ const cache = pipeline instanceof ComputePipeline ? this._computePipelineCache : this._renderPipelineCache;
56
+ cache[hash].useCount--;
57
+ if (cache[hash].useCount === 0) {
58
+ cache[hash].pipeline.destroy();
59
+ delete cache[hash];
60
+ }
129
61
  }
130
-
131
- const assembled = assembleShaders(platformInfo, { ...props,
132
- fs: props.fs,
133
- hookFunctions: this._hookFunctions
134
- });
135
- const pipeline = this.device.createRenderPipeline({ ...props,
136
- vs: this.device.createShader({
137
- stage: 'vertex',
138
- source: assembled.vs
139
- }),
140
- fs: assembled.fs ? this.device.createShader({
141
- stage: 'fragment',
142
- source: assembled.fs
143
- }) : null
144
- });
145
- return {
146
- pipeline,
147
- getUniforms: assembled.getUniforms
148
- };
149
- }
150
-
151
- _hashRenderPipeline(props) {
152
- const {
153
- modules = [],
154
- varyings = [],
155
- defines = [],
156
- inject = [],
157
- parameters = []
158
- } = props;
159
-
160
- const vsHash = this._getHash(props.vs);
161
-
162
- const fsHash = props.fs ? this._getHash(props.fs) : 0;
163
- const moduleHashes = modules.map(m => this._getHash(typeof m === 'string' ? m : m.name)).sort();
164
- const varyingHashes = varyings.map(v => this._getHash(v));
165
- const defineKeys = Object.keys(defines).sort();
166
- const injectKeys = Object.keys(inject).sort();
167
- const defineHashes = [];
168
- const injectHashes = [];
169
-
170
- for (const key of defineKeys) {
171
- defineHashes.push(this._getHash(key));
172
- defineHashes.push(this._getHash(defines[key]));
62
+ // PRIVATE
63
+ _hashComputePipeline(props) {
64
+ const shaderHash = this._getHash(props.shader.source);
65
+ return `${shaderHash}`;
173
66
  }
174
-
175
- for (const key of injectKeys) {
176
- injectHashes.push(this._getHash(key));
177
- injectHashes.push(this._getHash(inject[key]));
67
+ /** Calculate a hash based on all the inputs for a render pipeline */
68
+ _hashRenderPipeline(props) {
69
+ const vsHash = this._getHash(props.vs.source);
70
+ const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
71
+ // WebGL specific
72
+ // const {varyings = [], bufferMode = {}} = props;
73
+ // const varyingHashes = varyings.map((v) => this._getHash(v));
74
+ const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`
75
+ const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
76
+ switch (this.device.type) {
77
+ // case 'webgl':
78
+ // WebGL is more dynamic
79
+ // return `${vsHash}/${fsHash}V${varyingHash}BL${bufferLayoutHash}`;
80
+ default:
81
+ // On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
82
+ const parameterHash = this._getHash(JSON.stringify(props.parameters));
83
+ // TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
84
+ // create a deepHash() to deduplicate?
85
+ return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}`;
86
+ }
178
87
  }
179
-
180
- const parameterHash = JSON.stringify(parameters);
181
- return "".concat(vsHash, "/").concat(fsHash, "D").concat(defineHashes.join('/'), "M").concat(moduleHashes.join('/'), "I").concat(injectHashes.join('/'), "V").concat(varyingHashes.join('/'), "H").concat(this.stateHash, "B").concat(props.bufferMode).concat(props.transpileToGLSL100 ? 'T' : '', "P").concat(parameterHash);
182
- }
183
-
184
- _getHash(key) {
185
- if (this._hashes[key] === undefined) {
186
- this._hashes[key] = this._hashCounter++;
88
+ _getHash(key) {
89
+ if (this._hashes[key] === undefined) {
90
+ this._hashes[key] = this._hashCounter++;
91
+ }
92
+ return this._hashes[key];
187
93
  }
188
-
189
- return this._hashes[key];
190
- }
191
-
192
- _getModuleList(appModules = []) {
193
- const modules = new Array(this._defaultModules.length + appModules.length);
194
- const seen = {};
195
- let count = 0;
196
-
197
- for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
198
- const module = this._defaultModules[i];
199
- const name = module.name;
200
- modules[count++] = module;
201
- seen[name] = true;
202
- }
203
-
204
- for (let i = 0, len = appModules.length; i < len; ++i) {
205
- const module = appModules[i];
206
- const name = module.name;
207
-
208
- if (!seen[name]) {
209
- modules[count++] = module;
210
- seen[name] = true;
211
- }
212
- }
213
-
214
- modules.length = count;
215
- return modules;
216
- }
217
-
218
94
  }
219
- //# sourceMappingURL=pipeline-factory.js.map
@@ -0,0 +1,17 @@
1
+ import { Device, Shader, ShaderProps } from '@luma.gl/core';
2
+ /** Manages a cached pool of Shaders for reuse. */
3
+ export declare class ShaderFactory {
4
+ static readonly defaultProps: Required<ShaderProps>;
5
+ readonly device: Device;
6
+ private readonly _cache;
7
+ /** Returns the default ShaderFactory for the given {@link Device}, creating one if necessary. */
8
+ static getDefaultShaderFactory(device: Device): ShaderFactory;
9
+ /** @internal */
10
+ constructor(device: Device);
11
+ /** Requests a {@link Shader} from the cache, creating a new Shader only if necessary. */
12
+ createShader(props: ShaderProps): Shader;
13
+ /** Releases a previously-requested {@link Shader}, destroying it if no users remain. */
14
+ release(shader: Shader): void;
15
+ private _hashShader;
16
+ }
17
+ //# sourceMappingURL=shader-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader-factory.d.ts","sourceRoot":"","sources":["../../src/lib/shader-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1D,kDAAkD;AAClD,qBAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,CAA4B;IAE/E,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0D;IAEjF,iGAAiG;IACjG,MAAM,CAAC,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa;IAK7D,gBAAgB;gBACJ,MAAM,EAAE,MAAM;IAI1B,yFAAyF;IACzF,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM;IAgBxC,wFAAwF;IACxF,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAc7B,OAAO,CAAC,WAAW;CAGpB"}
@@ -0,0 +1,46 @@
1
+ import { Shader } from '@luma.gl/core';
2
+ /** Manages a cached pool of Shaders for reuse. */
3
+ export class ShaderFactory {
4
+ static defaultProps = { ...Shader.defaultProps };
5
+ device;
6
+ _cache = {};
7
+ /** Returns the default ShaderFactory for the given {@link Device}, creating one if necessary. */
8
+ static getDefaultShaderFactory(device) {
9
+ device._lumaData.defaultShaderFactory ||= new ShaderFactory(device);
10
+ return device._lumaData.defaultShaderFactory;
11
+ }
12
+ /** @internal */
13
+ constructor(device) {
14
+ this.device = device;
15
+ }
16
+ /** Requests a {@link Shader} from the cache, creating a new Shader only if necessary. */
17
+ createShader(props) {
18
+ const key = this._hashShader(props);
19
+ let cacheEntry = this._cache[key];
20
+ if (!cacheEntry) {
21
+ const shader = this.device.createShader({
22
+ ...props,
23
+ id: props.id ? `${props.id}-cached` : undefined
24
+ });
25
+ this._cache[key] = cacheEntry = { shader, useCount: 0 };
26
+ }
27
+ cacheEntry.useCount++;
28
+ return cacheEntry.shader;
29
+ }
30
+ /** Releases a previously-requested {@link Shader}, destroying it if no users remain. */
31
+ release(shader) {
32
+ const key = this._hashShader(shader);
33
+ const cacheEntry = this._cache[key];
34
+ if (cacheEntry) {
35
+ cacheEntry.useCount--;
36
+ if (cacheEntry.useCount === 0) {
37
+ delete this._cache[key];
38
+ cacheEntry.shader.destroy();
39
+ }
40
+ }
41
+ }
42
+ // PRIVATE
43
+ _hashShader(value) {
44
+ return `${value.stage}:${value.source}`;
45
+ }
46
+ }