@luma.gl/engine 9.3.0-alpha.6 → 9.3.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.
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +3 -0
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/compute/computation.d.ts +3 -7
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +14 -12
- package/dist/compute/computation.js.map +1 -1
- package/dist/dist.dev.js +1751 -831
- package/dist/dist.min.js +296 -148
- package/dist/dynamic-texture/dynamic-texture.d.ts +9 -2
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +54 -5
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-data.d.ts +4 -1
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +19 -2
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +8 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +1711 -847
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +73 -0
- package/dist/material/material-factory.d.ts.map +1 -0
- package/dist/material/material-factory.js +111 -0
- package/dist/material/material-factory.js.map +1 -0
- package/dist/material/material.d.ts +84 -0
- package/dist/material/material.d.ts.map +1 -0
- package/dist/material/material.js +176 -0
- package/dist/material/material.js.map +1 -0
- package/dist/model/model.d.ts +14 -6
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +69 -25
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -2
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/directional-light-model.d.ts +7 -0
- package/dist/models/directional-light-model.d.ts.map +1 -0
- package/dist/models/directional-light-model.js +23 -0
- package/dist/models/directional-light-model.js.map +1 -0
- package/dist/models/light-model-utils.d.ts +69 -0
- package/dist/models/light-model-utils.d.ts.map +1 -0
- package/dist/models/light-model-utils.js +395 -0
- package/dist/models/light-model-utils.js.map +1 -0
- package/dist/models/point-light-model.d.ts +7 -0
- package/dist/models/point-light-model.d.ts.map +1 -0
- package/dist/models/point-light-model.js +22 -0
- package/dist/models/point-light-model.js.map +1 -0
- package/dist/models/spot-light-model.d.ts +7 -0
- package/dist/models/spot-light-model.d.ts.map +1 -0
- package/dist/models/spot-light-model.js +23 -0
- package/dist/models/spot-light-model.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +5 -9
- package/dist/modules/picking/color-picking.d.ts.map +1 -1
- package/dist/modules/picking/color-picking.js +122 -115
- package/dist/modules/picking/color-picking.js.map +1 -1
- package/dist/modules/picking/index-picking.d.ts +2 -2
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +36 -10
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
- package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/legacy-color-picking.js +7 -0
- package/dist/modules/picking/legacy-color-picking.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +29 -3
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +188 -41
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +12 -11
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +26 -13
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +25 -0
- package/dist/modules/picking/picking.d.ts.map +1 -0
- package/dist/modules/picking/picking.js +18 -0
- package/dist/modules/picking/picking.js.map +1 -0
- package/dist/shader-inputs.d.ts +9 -7
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +84 -4
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +7 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -0
- package/dist/utils/shader-module-utils.js +46 -0
- package/dist/utils/shader-module-utils.js.map +1 -0
- package/package.json +4 -4
- package/src/animation-loop/animation-loop.ts +3 -0
- package/src/compute/computation.ts +31 -17
- package/src/dynamic-texture/dynamic-texture.ts +79 -7
- package/src/dynamic-texture/texture-data.ts +25 -4
- package/src/geometry/gpu-geometry.ts +8 -3
- package/src/index.ts +29 -4
- package/src/material/material-factory.ts +157 -0
- package/src/material/material.ts +254 -0
- package/src/model/model.ts +108 -40
- package/src/model/split-uniforms-and-bindings.ts +8 -6
- package/src/models/directional-light-model.ts +32 -0
- package/src/models/light-model-utils.ts +587 -0
- package/src/models/point-light-model.ts +31 -0
- package/src/models/spot-light-model.ts +32 -0
- package/src/modules/picking/color-picking.ts +123 -122
- package/src/modules/picking/index-picking.ts +36 -10
- package/src/modules/picking/legacy-color-picking.ts +8 -0
- package/src/modules/picking/picking-manager.ts +252 -50
- package/src/modules/picking/picking-uniforms.ts +38 -23
- package/src/modules/picking/picking.ts +22 -0
- package/src/shader-inputs.ts +165 -15
- package/src/utils/shader-module-utils.ts +65 -0
- package/dist/factories/pipeline-factory.d.ts +0 -39
- package/dist/factories/pipeline-factory.d.ts.map +0 -1
- package/dist/factories/pipeline-factory.js +0 -216
- package/dist/factories/pipeline-factory.js.map +0 -1
- package/dist/factories/shader-factory.d.ts +0 -19
- package/dist/factories/shader-factory.d.ts.map +0 -1
- package/dist/factories/shader-factory.js +0 -83
- package/dist/factories/shader-factory.js.map +0 -1
- package/dist/types.d.ts +0 -7
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/src/factories/pipeline-factory.ts +0 -266
- package/src/factories/shader-factory.ts +0 -101
- package/src/types.ts +0 -11
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { Shader, log } from '@luma.gl/core';
|
|
5
|
-
/** Manages a cached pool of Shaders for reuse. */
|
|
6
|
-
export class ShaderFactory {
|
|
7
|
-
static defaultProps = { ...Shader.defaultProps };
|
|
8
|
-
/** Returns the default ShaderFactory for the given {@link Device}, creating one if necessary. */
|
|
9
|
-
static getDefaultShaderFactory(device) {
|
|
10
|
-
const moduleData = device.getModuleData('@luma.gl/engine');
|
|
11
|
-
moduleData.defaultShaderFactory ||= new ShaderFactory(device);
|
|
12
|
-
return moduleData.defaultShaderFactory;
|
|
13
|
-
}
|
|
14
|
-
device;
|
|
15
|
-
_cache = {};
|
|
16
|
-
get [Symbol.toStringTag]() {
|
|
17
|
-
return 'ShaderFactory';
|
|
18
|
-
}
|
|
19
|
-
toString() {
|
|
20
|
-
return `${this[Symbol.toStringTag]}(${this.device.id})`;
|
|
21
|
-
}
|
|
22
|
-
/** @internal */
|
|
23
|
-
constructor(device) {
|
|
24
|
-
this.device = device;
|
|
25
|
-
}
|
|
26
|
-
/** Requests a {@link Shader} from the cache, creating a new Shader only if necessary. */
|
|
27
|
-
createShader(props) {
|
|
28
|
-
if (!this.device.props._cacheShaders) {
|
|
29
|
-
return this.device.createShader(props);
|
|
30
|
-
}
|
|
31
|
-
const key = this._hashShader(props);
|
|
32
|
-
let cacheEntry = this._cache[key];
|
|
33
|
-
if (!cacheEntry) {
|
|
34
|
-
const resource = this.device.createShader({
|
|
35
|
-
...props,
|
|
36
|
-
id: props.id ? `${props.id}-cached` : undefined
|
|
37
|
-
});
|
|
38
|
-
this._cache[key] = cacheEntry = { resource, useCount: 1 };
|
|
39
|
-
if (this.device.props.debugFactories) {
|
|
40
|
-
log.log(3, `${this}: Created new shader ${resource.id}`)();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
cacheEntry.useCount++;
|
|
45
|
-
if (this.device.props.debugFactories) {
|
|
46
|
-
log.log(3, `${this}: Reusing shader ${cacheEntry.resource.id} count=${cacheEntry.useCount}`)();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return cacheEntry.resource;
|
|
50
|
-
}
|
|
51
|
-
/** Releases a previously-requested {@link Shader}, destroying it if no users remain. */
|
|
52
|
-
release(shader) {
|
|
53
|
-
if (!this.device.props._cacheShaders) {
|
|
54
|
-
shader.destroy();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const key = this._hashShader(shader);
|
|
58
|
-
const cacheEntry = this._cache[key];
|
|
59
|
-
if (cacheEntry) {
|
|
60
|
-
cacheEntry.useCount--;
|
|
61
|
-
if (cacheEntry.useCount === 0) {
|
|
62
|
-
if (this.device.props._destroyShaders) {
|
|
63
|
-
delete this._cache[key];
|
|
64
|
-
cacheEntry.resource.destroy();
|
|
65
|
-
if (this.device.props.debugFactories) {
|
|
66
|
-
log.log(3, `${this}: Releasing shader ${shader.id}, destroyed`)();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else if (cacheEntry.useCount < 0) {
|
|
71
|
-
throw new Error(`ShaderFactory: Shader ${shader.id} released too many times`);
|
|
72
|
-
}
|
|
73
|
-
else if (this.device.props.debugFactories) {
|
|
74
|
-
log.log(3, `${this}: Releasing shader ${shader.id} count=${cacheEntry.useCount}`)();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// PRIVATE
|
|
79
|
-
_hashShader(value) {
|
|
80
|
-
return `${value.stage}:${value.source}`;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=shader-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shader-factory.js","sourceRoot":"","sources":["../../src/factories/shader-factory.ts"],"names":[],"mappings":"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"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { PipelineFactory } from "./factories/pipeline-factory.js";
|
|
2
|
-
import type { ShaderFactory } from "./factories/shader-factory.js";
|
|
3
|
-
export type EngineModuleState = {
|
|
4
|
-
defaultPipelineFactory?: PipelineFactory;
|
|
5
|
-
defaultShaderFactory?: ShaderFactory;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC,wCAAqC;AAClE,OAAO,KAAK,EAAC,aAAa,EAAC,sCAAmC;AAE9D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,sBAAsB,CAAC,EAAE,eAAe,CAAC;IACzC,oBAAoB,CAAC,EAAE,aAAa,CAAC;CACtC,CAAC"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC"}
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {RenderPipelineProps, ComputePipelineProps, SharedRenderPipeline} from '@luma.gl/core';
|
|
6
|
-
import {Device, RenderPipeline, ComputePipeline, Resource, log} from '@luma.gl/core';
|
|
7
|
-
import type {EngineModuleState} from '../types';
|
|
8
|
-
import {uid} from '../utils/uid';
|
|
9
|
-
|
|
10
|
-
export type PipelineFactoryProps = RenderPipelineProps;
|
|
11
|
-
|
|
12
|
-
type CacheItem<ResourceT extends Resource<any>> = {resource: ResourceT; useCount: number};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Efficiently creates / caches pipelines
|
|
16
|
-
*/
|
|
17
|
-
export class PipelineFactory {
|
|
18
|
-
static defaultProps: Required<PipelineFactoryProps> = {...RenderPipeline.defaultProps};
|
|
19
|
-
|
|
20
|
-
/** Get the singleton default pipeline factory for the specified device */
|
|
21
|
-
static getDefaultPipelineFactory(device: Device): PipelineFactory {
|
|
22
|
-
const moduleData = device.getModuleData<EngineModuleState>('@luma.gl/engine');
|
|
23
|
-
moduleData.defaultPipelineFactory ||= new PipelineFactory(device);
|
|
24
|
-
return moduleData.defaultPipelineFactory;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
readonly device: Device;
|
|
28
|
-
|
|
29
|
-
private _hashCounter: number = 0;
|
|
30
|
-
private readonly _hashes: Record<string, number> = {};
|
|
31
|
-
private readonly _renderPipelineCache: Record<string, CacheItem<RenderPipeline>> = {};
|
|
32
|
-
private readonly _computePipelineCache: Record<string, CacheItem<ComputePipeline>> = {};
|
|
33
|
-
private readonly _sharedRenderPipelineCache: Record<string, CacheItem<SharedRenderPipeline>> = {};
|
|
34
|
-
|
|
35
|
-
get [Symbol.toStringTag](): string {
|
|
36
|
-
return 'PipelineFactory';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
toString(): string {
|
|
40
|
-
return `PipelineFactory(${this.device.id})`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
constructor(device: Device) {
|
|
44
|
-
this.device = device;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Return a RenderPipeline matching supplied props. Reuses an equivalent pipeline if already created. */
|
|
48
|
-
createRenderPipeline(props: RenderPipelineProps): RenderPipeline {
|
|
49
|
-
if (!this.device.props._cachePipelines) {
|
|
50
|
-
return this.device.createRenderPipeline(props);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const allProps: Required<RenderPipelineProps> = {...RenderPipeline.defaultProps, ...props};
|
|
54
|
-
|
|
55
|
-
const cache = this._renderPipelineCache;
|
|
56
|
-
const hash = this._hashRenderPipeline(allProps);
|
|
57
|
-
|
|
58
|
-
let pipeline: RenderPipeline = cache[hash]?.resource;
|
|
59
|
-
if (!pipeline) {
|
|
60
|
-
const sharedRenderPipeline =
|
|
61
|
-
this.device.type === 'webgl' && this.device.props._sharePipelines
|
|
62
|
-
? this.createSharedRenderPipeline(allProps)
|
|
63
|
-
: undefined;
|
|
64
|
-
pipeline = this.device.createRenderPipeline({
|
|
65
|
-
...allProps,
|
|
66
|
-
id: allProps.id ? `${allProps.id}-cached` : uid('unnamed-cached'),
|
|
67
|
-
_sharedRenderPipeline: sharedRenderPipeline
|
|
68
|
-
});
|
|
69
|
-
pipeline.hash = hash;
|
|
70
|
-
cache[hash] = {resource: pipeline, useCount: 1};
|
|
71
|
-
if (this.device.props.debugFactories) {
|
|
72
|
-
log.log(3, `${this}: ${pipeline} created, count=${cache[hash].useCount}`)();
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
cache[hash].useCount++;
|
|
76
|
-
if (this.device.props.debugFactories) {
|
|
77
|
-
log.log(
|
|
78
|
-
3,
|
|
79
|
-
`${this}: ${cache[hash].resource} reused, count=${cache[hash].useCount}, (id=${props.id})`
|
|
80
|
-
)();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return pipeline;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Return a ComputePipeline matching supplied props. Reuses an equivalent pipeline if already created. */
|
|
88
|
-
createComputePipeline(props: ComputePipelineProps): ComputePipeline {
|
|
89
|
-
if (!this.device.props._cachePipelines) {
|
|
90
|
-
return this.device.createComputePipeline(props);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const allProps: Required<ComputePipelineProps> = {...ComputePipeline.defaultProps, ...props};
|
|
94
|
-
|
|
95
|
-
const cache = this._computePipelineCache;
|
|
96
|
-
const hash = this._hashComputePipeline(allProps);
|
|
97
|
-
|
|
98
|
-
let pipeline: ComputePipeline = cache[hash]?.resource;
|
|
99
|
-
if (!pipeline) {
|
|
100
|
-
pipeline = this.device.createComputePipeline({
|
|
101
|
-
...allProps,
|
|
102
|
-
id: allProps.id ? `${allProps.id}-cached` : undefined
|
|
103
|
-
});
|
|
104
|
-
pipeline.hash = hash;
|
|
105
|
-
cache[hash] = {resource: pipeline, useCount: 1};
|
|
106
|
-
if (this.device.props.debugFactories) {
|
|
107
|
-
log.log(3, `${this}: ${pipeline} created, count=${cache[hash].useCount}`)();
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
cache[hash].useCount++;
|
|
111
|
-
if (this.device.props.debugFactories) {
|
|
112
|
-
log.log(
|
|
113
|
-
3,
|
|
114
|
-
`${this}: ${cache[hash].resource} reused, count=${cache[hash].useCount}, (id=${props.id})`
|
|
115
|
-
)();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return pipeline;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
release(pipeline: RenderPipeline | ComputePipeline): void {
|
|
123
|
-
if (!this.device.props._cachePipelines) {
|
|
124
|
-
pipeline.destroy();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const cache = this._getCache(pipeline);
|
|
129
|
-
const hash = pipeline.hash;
|
|
130
|
-
|
|
131
|
-
cache[hash].useCount--;
|
|
132
|
-
if (cache[hash].useCount === 0) {
|
|
133
|
-
this._destroyPipeline(pipeline);
|
|
134
|
-
if (this.device.props.debugFactories) {
|
|
135
|
-
log.log(3, `${this}: ${pipeline} released and destroyed`)();
|
|
136
|
-
}
|
|
137
|
-
} else if (cache[hash].useCount < 0) {
|
|
138
|
-
log.error(`${this}: ${pipeline} released, useCount < 0, resetting`)();
|
|
139
|
-
cache[hash].useCount = 0;
|
|
140
|
-
} else if (this.device.props.debugFactories) {
|
|
141
|
-
log.log(3, `${this}: ${pipeline} released, count=${cache[hash].useCount}`)();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
createSharedRenderPipeline(props: RenderPipelineProps): SharedRenderPipeline {
|
|
146
|
-
const sharedPipelineHash = this._hashSharedRenderPipeline(props);
|
|
147
|
-
let sharedCacheItem = this._sharedRenderPipelineCache[sharedPipelineHash];
|
|
148
|
-
if (!sharedCacheItem) {
|
|
149
|
-
const sharedRenderPipeline = this.device._createSharedRenderPipelineWebGL(props);
|
|
150
|
-
sharedCacheItem = {resource: sharedRenderPipeline, useCount: 0};
|
|
151
|
-
this._sharedRenderPipelineCache[sharedPipelineHash] = sharedCacheItem;
|
|
152
|
-
}
|
|
153
|
-
sharedCacheItem.useCount++;
|
|
154
|
-
return sharedCacheItem.resource;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
releaseSharedRenderPipeline(pipeline: RenderPipeline): void {
|
|
158
|
-
if (!pipeline.sharedRenderPipeline) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const sharedPipelineHash = this._hashSharedRenderPipeline(pipeline.sharedRenderPipeline.props);
|
|
163
|
-
const sharedCacheItem = this._sharedRenderPipelineCache[sharedPipelineHash];
|
|
164
|
-
if (!sharedCacheItem) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
sharedCacheItem.useCount--;
|
|
169
|
-
if (sharedCacheItem.useCount === 0) {
|
|
170
|
-
sharedCacheItem.resource.destroy();
|
|
171
|
-
delete this._sharedRenderPipelineCache[sharedPipelineHash];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// PRIVATE
|
|
176
|
-
|
|
177
|
-
/** Destroy a cached pipeline, removing it from the cache if configured to do so. */
|
|
178
|
-
private _destroyPipeline(pipeline: RenderPipeline | ComputePipeline): boolean {
|
|
179
|
-
const cache = this._getCache(pipeline);
|
|
180
|
-
|
|
181
|
-
if (!this.device.props._destroyPipelines) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
delete cache[pipeline.hash];
|
|
186
|
-
pipeline.destroy();
|
|
187
|
-
if (pipeline instanceof RenderPipeline) {
|
|
188
|
-
this.releaseSharedRenderPipeline(pipeline);
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Get the appropriate cache for the type of pipeline */
|
|
194
|
-
private _getCache(
|
|
195
|
-
pipeline: RenderPipeline | ComputePipeline
|
|
196
|
-
): Record<string, CacheItem<RenderPipeline>> | Record<string, CacheItem<ComputePipeline>> {
|
|
197
|
-
let cache:
|
|
198
|
-
| Record<string, CacheItem<RenderPipeline>>
|
|
199
|
-
| Record<string, CacheItem<ComputePipeline>>
|
|
200
|
-
| undefined;
|
|
201
|
-
if (pipeline instanceof ComputePipeline) {
|
|
202
|
-
cache = this._computePipelineCache;
|
|
203
|
-
}
|
|
204
|
-
if (pipeline instanceof RenderPipeline) {
|
|
205
|
-
cache = this._renderPipelineCache;
|
|
206
|
-
}
|
|
207
|
-
if (!cache) {
|
|
208
|
-
throw new Error(`${this}`);
|
|
209
|
-
}
|
|
210
|
-
if (!cache[pipeline.hash]) {
|
|
211
|
-
throw new Error(`${this}: ${pipeline} matched incorrect entry`);
|
|
212
|
-
}
|
|
213
|
-
return cache;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** Calculate a hash based on all the inputs for a compute pipeline */
|
|
217
|
-
private _hashComputePipeline(props: ComputePipelineProps): string {
|
|
218
|
-
const {type} = this.device;
|
|
219
|
-
const shaderHash = this._getHash(props.shader.source);
|
|
220
|
-
return `${type}/C/${shaderHash}`;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** Calculate a hash based on all the inputs for a render pipeline */
|
|
224
|
-
private _hashRenderPipeline(props: RenderPipelineProps): string {
|
|
225
|
-
const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
|
|
226
|
-
const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
|
|
227
|
-
const varyingHash = this._getWebGLVaryingHash(props);
|
|
228
|
-
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
229
|
-
|
|
230
|
-
const {type} = this.device;
|
|
231
|
-
switch (type) {
|
|
232
|
-
case 'webgl':
|
|
233
|
-
// WebGL wrappers preserve default topology and parameter semantics for direct
|
|
234
|
-
// callers, even though the underlying linked program may be shared separately.
|
|
235
|
-
const webglParameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
236
|
-
return `${type}/R/${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${webglParameterHash}BL${bufferLayoutHash}`;
|
|
237
|
-
|
|
238
|
-
case 'webgpu':
|
|
239
|
-
default:
|
|
240
|
-
// On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
|
|
241
|
-
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
242
|
-
// TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
|
|
243
|
-
// create a deepHash() to deduplicate?
|
|
244
|
-
return `${type}/R/${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}`;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
private _hashSharedRenderPipeline(props: RenderPipelineProps): string {
|
|
249
|
-
const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
|
|
250
|
-
const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
|
|
251
|
-
const varyingHash = this._getWebGLVaryingHash(props);
|
|
252
|
-
return `webgl/S/${vsHash}/${fsHash}V${varyingHash}`;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
private _getHash(key: string): number {
|
|
256
|
-
if (this._hashes[key] === undefined) {
|
|
257
|
-
this._hashes[key] = this._hashCounter++;
|
|
258
|
-
}
|
|
259
|
-
return this._hashes[key];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private _getWebGLVaryingHash(props: RenderPipelineProps): number {
|
|
263
|
-
const {varyings = [], bufferMode = null} = props;
|
|
264
|
-
return this._getHash(JSON.stringify({varyings, bufferMode}));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {Device, Shader, ShaderProps, log} from '@luma.gl/core';
|
|
6
|
-
import type {EngineModuleState} from '../types';
|
|
7
|
-
|
|
8
|
-
type CacheItem = {resource: Shader; useCount: number};
|
|
9
|
-
|
|
10
|
-
/** Manages a cached pool of Shaders for reuse. */
|
|
11
|
-
export class ShaderFactory {
|
|
12
|
-
static readonly defaultProps: Required<ShaderProps> = {...Shader.defaultProps};
|
|
13
|
-
|
|
14
|
-
/** Returns the default ShaderFactory for the given {@link Device}, creating one if necessary. */
|
|
15
|
-
static getDefaultShaderFactory(device: Device): ShaderFactory {
|
|
16
|
-
const moduleData = device.getModuleData<EngineModuleState>('@luma.gl/engine');
|
|
17
|
-
moduleData.defaultShaderFactory ||= new ShaderFactory(device);
|
|
18
|
-
return moduleData.defaultShaderFactory;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public readonly device: Device;
|
|
22
|
-
|
|
23
|
-
private readonly _cache: Record<string, CacheItem> = {};
|
|
24
|
-
|
|
25
|
-
get [Symbol.toStringTag](): string {
|
|
26
|
-
return 'ShaderFactory';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
toString(): string {
|
|
30
|
-
return `${this[Symbol.toStringTag]}(${this.device.id})`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** @internal */
|
|
34
|
-
constructor(device: Device) {
|
|
35
|
-
this.device = device;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Requests a {@link Shader} from the cache, creating a new Shader only if necessary. */
|
|
39
|
-
createShader(props: ShaderProps): Shader {
|
|
40
|
-
if (!this.device.props._cacheShaders) {
|
|
41
|
-
return this.device.createShader(props);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const key = this._hashShader(props);
|
|
45
|
-
|
|
46
|
-
let cacheEntry = this._cache[key];
|
|
47
|
-
if (!cacheEntry) {
|
|
48
|
-
const resource = this.device.createShader({
|
|
49
|
-
...props,
|
|
50
|
-
id: props.id ? `${props.id}-cached` : undefined
|
|
51
|
-
});
|
|
52
|
-
this._cache[key] = cacheEntry = {resource, useCount: 1};
|
|
53
|
-
if (this.device.props.debugFactories) {
|
|
54
|
-
log.log(3, `${this}: Created new shader ${resource.id}`)();
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
cacheEntry.useCount++;
|
|
58
|
-
if (this.device.props.debugFactories) {
|
|
59
|
-
log.log(
|
|
60
|
-
3,
|
|
61
|
-
`${this}: Reusing shader ${cacheEntry.resource.id} count=${cacheEntry.useCount}`
|
|
62
|
-
)();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return cacheEntry.resource;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Releases a previously-requested {@link Shader}, destroying it if no users remain. */
|
|
70
|
-
release(shader: Shader): void {
|
|
71
|
-
if (!this.device.props._cacheShaders) {
|
|
72
|
-
shader.destroy();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const key = this._hashShader(shader);
|
|
77
|
-
const cacheEntry = this._cache[key];
|
|
78
|
-
if (cacheEntry) {
|
|
79
|
-
cacheEntry.useCount--;
|
|
80
|
-
if (cacheEntry.useCount === 0) {
|
|
81
|
-
if (this.device.props._destroyShaders) {
|
|
82
|
-
delete this._cache[key];
|
|
83
|
-
cacheEntry.resource.destroy();
|
|
84
|
-
if (this.device.props.debugFactories) {
|
|
85
|
-
log.log(3, `${this}: Releasing shader ${shader.id}, destroyed`)();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} else if (cacheEntry.useCount < 0) {
|
|
89
|
-
throw new Error(`ShaderFactory: Shader ${shader.id} released too many times`);
|
|
90
|
-
} else if (this.device.props.debugFactories) {
|
|
91
|
-
log.log(3, `${this}: Releasing shader ${shader.id} count=${cacheEntry.useCount}`)();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// PRIVATE
|
|
97
|
-
|
|
98
|
-
protected _hashShader(value: Shader | ShaderProps): string {
|
|
99
|
-
return `${value.stage}:${value.source}`;
|
|
100
|
-
}
|
|
101
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {PipelineFactory} from './factories/pipeline-factory';
|
|
6
|
-
import type {ShaderFactory} from './factories/shader-factory';
|
|
7
|
-
|
|
8
|
-
export type EngineModuleState = {
|
|
9
|
-
defaultPipelineFactory?: PipelineFactory;
|
|
10
|
-
defaultShaderFactory?: ShaderFactory;
|
|
11
|
-
};
|