@luma.gl/engine 9.3.0-alpha.4 → 9.3.0-alpha.8
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 +8 -4
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +73 -43
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +7 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +23 -6
- package/dist/animation-loop/request-animation-frame.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 +2310 -1638
- package/dist/dist.min.js +307 -360
- package/dist/dynamic-texture/dynamic-texture.d.ts +12 -5
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +222 -55
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-data.d.ts +8 -1
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +27 -2
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/geometries/cone-geometry.d.ts +3 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +2 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.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 +2897 -2272
- 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 +17 -7
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +80 -34
- 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/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +10 -8
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/clip-space.js +7 -7
- 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 -16
- 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/passes/get-fragment-shader.js +11 -30
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +0 -2
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +4 -31
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/scenegraph/group-node.d.ts +5 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +12 -0
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.d.ts +2 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +23 -15
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- 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 +78 -46
- package/src/animation-loop/make-animation-loop.ts +13 -5
- package/src/animation-loop/request-animation-frame.ts +32 -6
- package/src/compute/computation.ts +31 -17
- package/src/dynamic-texture/dynamic-texture.ts +301 -68
- package/src/dynamic-texture/texture-data.ts +39 -4
- package/src/geometries/cone-geometry.ts +6 -1
- package/src/geometries/cylinder-geometry.ts +5 -1
- 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 +122 -50
- package/src/model/split-uniforms-and-bindings.ts +8 -6
- package/src/models/billboard-texture-model.ts +10 -8
- package/src/models/clip-space.ts +7 -7
- 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 -16
- 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/passes/get-fragment-shader.ts +11 -30
- package/src/passes/shader-pass-renderer.ts +4 -33
- package/src/scenegraph/group-node.ts +16 -0
- package/src/scenegraph/model-node.ts +2 -2
- package/src/scenegraph/scenegraph-node.ts +27 -16
- package/src/shader-inputs.ts +165 -15
- package/src/utils/shader-module-utils.ts +65 -0
- package/dist/dynamic-texture/mipmaps.d.ts +0 -6
- package/dist/dynamic-texture/mipmaps.d.ts.map +0 -1
- package/dist/dynamic-texture/mipmaps.js +0 -441
- package/dist/dynamic-texture/mipmaps.js.map +0 -1
- package/dist/factories/pipeline-factory.d.ts +0 -37
- package/dist/factories/pipeline-factory.d.ts.map +0 -1
- package/dist/factories/pipeline-factory.js +0 -181
- package/dist/factories/pipeline-factory.js.map +0 -1
- package/dist/factories/shader-factory.d.ts +0 -22
- package/dist/factories/shader-factory.d.ts.map +0 -1
- package/dist/factories/shader-factory.js +0 -89
- 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/dynamic-texture/mipmaps.ts +0 -517
- package/src/factories/pipeline-factory.ts +0 -225
- package/src/factories/shader-factory.ts +0 -105
- package/src/types.ts +0 -11
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { Buffer, textureFormatDecoder } from '@luma.gl/core';
|
|
5
|
-
import { Model } from "../model/model.js";
|
|
6
|
-
import { Computation } from "../compute/computation.js";
|
|
7
|
-
const RENDER_DIMENSIONS = [
|
|
8
|
-
'2d',
|
|
9
|
-
'2d-array',
|
|
10
|
-
'cube',
|
|
11
|
-
'cube-array'
|
|
12
|
-
];
|
|
13
|
-
const WORKGROUP_SIZE = {
|
|
14
|
-
x: 4,
|
|
15
|
-
y: 4,
|
|
16
|
-
z: 4
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Generates mip levels from level 0 to the last mip for an existing texture.
|
|
20
|
-
*/
|
|
21
|
-
export function generateMipmap(device, texture) {
|
|
22
|
-
if (texture.mipLevels <= 1) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (device.type !== 'webgpu') {
|
|
26
|
-
throw new Error(`Cannot generate mipmaps on device type "${device.type}". Use generateMipmapsWebGL for WebGL devices.`);
|
|
27
|
-
}
|
|
28
|
-
if (texture.dimension === '3d') {
|
|
29
|
-
generateMipmaps3D(device, texture);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (RENDER_DIMENSIONS.includes(texture.dimension)) {
|
|
33
|
-
generateMipmapsRender(device, texture);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
throw new Error(`Cannot generate mipmaps for texture dimension "${texture.dimension}" with WebGPU.`);
|
|
37
|
-
}
|
|
38
|
-
function generateMipmapsRender(device, texture) {
|
|
39
|
-
validateFormatCapabilities(device, texture, ['render', 'filter'], 'render');
|
|
40
|
-
const colorAttachmentFormat = getColorAttachmentFormat(texture.format, 'render', texture.dimension);
|
|
41
|
-
const viewDimension = texture.dimension;
|
|
42
|
-
const shader = getRenderMipmapWGSL(viewDimension);
|
|
43
|
-
const sampler = device.createSampler({ minFilter: 'linear', magFilter: 'linear' });
|
|
44
|
-
const uniformValues = new Uint32Array(1);
|
|
45
|
-
const uniformsBuffer = device.createBuffer({
|
|
46
|
-
byteLength: 16,
|
|
47
|
-
usage: Buffer.UNIFORM | Buffer.COPY_DST
|
|
48
|
-
});
|
|
49
|
-
const model = new Model(device, {
|
|
50
|
-
source: shader,
|
|
51
|
-
colorAttachmentFormats: [colorAttachmentFormat],
|
|
52
|
-
topology: 'triangle-list',
|
|
53
|
-
vertexCount: 3,
|
|
54
|
-
shaderLayout: {
|
|
55
|
-
attributes: [],
|
|
56
|
-
bindings: [
|
|
57
|
-
{ type: 'sampler', name: 'sourceSampler', group: 0, location: 0 },
|
|
58
|
-
{
|
|
59
|
-
type: 'texture',
|
|
60
|
-
name: 'sourceTexture',
|
|
61
|
-
group: 0,
|
|
62
|
-
location: 1,
|
|
63
|
-
viewDimension,
|
|
64
|
-
sampleType: 'float'
|
|
65
|
-
},
|
|
66
|
-
{ type: 'uniform', name: 'uniforms', group: 0, location: 2 }
|
|
67
|
-
]
|
|
68
|
-
},
|
|
69
|
-
bindings: {
|
|
70
|
-
sourceSampler: sampler,
|
|
71
|
-
sourceTexture: texture,
|
|
72
|
-
uniforms: uniformsBuffer
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
let sourceWidth = texture.width;
|
|
76
|
-
let sourceHeight = texture.height;
|
|
77
|
-
const layerCount = texture.dimension === '2d' ? 1 : texture.depth;
|
|
78
|
-
try {
|
|
79
|
-
for (let baseMipLevel = 1; baseMipLevel < texture.mipLevels; ++baseMipLevel) {
|
|
80
|
-
validateFormatCapabilities(device, texture, ['render', 'filter'], 'render');
|
|
81
|
-
const sourceMipLevel = baseMipLevel - 1;
|
|
82
|
-
const destinationWidth = Math.max(1, sourceWidth >> 1);
|
|
83
|
-
const destinationHeight = Math.max(1, sourceHeight >> 1);
|
|
84
|
-
const sourceView = texture.createView({
|
|
85
|
-
dimension: viewDimension,
|
|
86
|
-
baseMipLevel: sourceMipLevel,
|
|
87
|
-
mipLevelCount: 1,
|
|
88
|
-
baseArrayLayer: 0,
|
|
89
|
-
arrayLayerCount: texture.depth
|
|
90
|
-
});
|
|
91
|
-
model.setBindings({ sourceTexture: sourceView });
|
|
92
|
-
for (let baseArrayLayer = 0; baseArrayLayer < layerCount; ++baseArrayLayer) {
|
|
93
|
-
uniformValues[0] = baseArrayLayer;
|
|
94
|
-
uniformsBuffer.write(uniformValues);
|
|
95
|
-
const destinationView = texture.createView({
|
|
96
|
-
dimension: '2d',
|
|
97
|
-
baseMipLevel,
|
|
98
|
-
mipLevelCount: 1,
|
|
99
|
-
baseArrayLayer,
|
|
100
|
-
arrayLayerCount: 1
|
|
101
|
-
});
|
|
102
|
-
const framebuffer = device.createFramebuffer({
|
|
103
|
-
colorAttachments: [destinationView]
|
|
104
|
-
});
|
|
105
|
-
const renderPass = device.beginRenderPass({
|
|
106
|
-
id: `mipmap-generation:${texture.format}:${baseMipLevel}:${baseArrayLayer}`,
|
|
107
|
-
framebuffer
|
|
108
|
-
});
|
|
109
|
-
renderPass.setParameters({
|
|
110
|
-
viewport: [0, 0, destinationWidth, destinationHeight, 0, 1],
|
|
111
|
-
scissorRect: [0, 0, destinationWidth, destinationHeight]
|
|
112
|
-
});
|
|
113
|
-
model.draw(renderPass);
|
|
114
|
-
renderPass.end();
|
|
115
|
-
device.submit();
|
|
116
|
-
destinationView.destroy();
|
|
117
|
-
framebuffer.destroy();
|
|
118
|
-
}
|
|
119
|
-
sourceView.destroy();
|
|
120
|
-
sourceWidth = destinationWidth;
|
|
121
|
-
sourceHeight = destinationHeight;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
finally {
|
|
125
|
-
model.destroy();
|
|
126
|
-
sampler.destroy();
|
|
127
|
-
uniformsBuffer.destroy();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function getColorAttachmentFormat(format, path, dimension) {
|
|
131
|
-
if (textureFormatDecoder.isColor(format)) {
|
|
132
|
-
return format;
|
|
133
|
-
}
|
|
134
|
-
throw new Error(`Cannot run ${path} mipmap generation for ${dimension} texture with format "${format}". ` +
|
|
135
|
-
`Only color textures can be used for this operation. ` +
|
|
136
|
-
`Required capabilities: color. ` +
|
|
137
|
-
`Actual capabilities: color=false.`);
|
|
138
|
-
}
|
|
139
|
-
function generateMipmaps3D(device, texture) {
|
|
140
|
-
validateFormatCapabilities(device, texture, ['filter', 'store'], 'compute');
|
|
141
|
-
const format = getColorAttachmentFormat(texture.format, 'compute', texture.dimension);
|
|
142
|
-
const shaderSource = get3DComputeMipmapWGSL(format);
|
|
143
|
-
const uniformsBuffer = device.createBuffer({
|
|
144
|
-
byteLength: 32,
|
|
145
|
-
usage: Buffer.UNIFORM | Buffer.COPY_DST
|
|
146
|
-
});
|
|
147
|
-
const uniformValues = new Uint32Array(8);
|
|
148
|
-
let sourceWidth = texture.width;
|
|
149
|
-
let sourceHeight = texture.height;
|
|
150
|
-
let sourceDepth = texture.depth;
|
|
151
|
-
try {
|
|
152
|
-
for (let destinationMipLevel = 1; destinationMipLevel < texture.mipLevels; ++destinationMipLevel) {
|
|
153
|
-
validateFormatCapabilities(device, texture, ['filter', 'store'], 'compute');
|
|
154
|
-
const destinationWidth = Math.max(1, sourceWidth >> 1);
|
|
155
|
-
const destinationHeight = Math.max(1, sourceHeight >> 1);
|
|
156
|
-
const destinationDepth = Math.max(1, sourceDepth >> 1);
|
|
157
|
-
uniformValues[0] = sourceWidth;
|
|
158
|
-
uniformValues[1] = sourceHeight;
|
|
159
|
-
uniformValues[2] = sourceDepth;
|
|
160
|
-
uniformValues[3] = destinationWidth;
|
|
161
|
-
uniformValues[4] = destinationHeight;
|
|
162
|
-
uniformValues[5] = destinationDepth;
|
|
163
|
-
uniformValues[6] = 0;
|
|
164
|
-
uniformsBuffer.write(uniformValues);
|
|
165
|
-
const sourceView = texture.createView({
|
|
166
|
-
dimension: '3d',
|
|
167
|
-
baseMipLevel: destinationMipLevel - 1,
|
|
168
|
-
mipLevelCount: 1,
|
|
169
|
-
baseArrayLayer: 0,
|
|
170
|
-
arrayLayerCount: 1
|
|
171
|
-
});
|
|
172
|
-
const destinationView = texture.createView({
|
|
173
|
-
dimension: '3d',
|
|
174
|
-
baseMipLevel: destinationMipLevel,
|
|
175
|
-
mipLevelCount: 1,
|
|
176
|
-
baseArrayLayer: 0,
|
|
177
|
-
arrayLayerCount: 1
|
|
178
|
-
});
|
|
179
|
-
const computation = new Computation(device, {
|
|
180
|
-
source: shaderSource,
|
|
181
|
-
shaderLayout: {
|
|
182
|
-
bindings: [
|
|
183
|
-
{
|
|
184
|
-
type: 'texture',
|
|
185
|
-
name: 'sourceTexture',
|
|
186
|
-
group: 0,
|
|
187
|
-
location: 0,
|
|
188
|
-
viewDimension: '3d',
|
|
189
|
-
sampleType: 'float'
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
type: 'storage',
|
|
193
|
-
name: 'destinationTexture',
|
|
194
|
-
group: 0,
|
|
195
|
-
location: 1,
|
|
196
|
-
format,
|
|
197
|
-
viewDimension: '3d',
|
|
198
|
-
access: 'write-only'
|
|
199
|
-
},
|
|
200
|
-
{ type: 'uniform', name: 'uniforms', group: 0, location: 2 }
|
|
201
|
-
]
|
|
202
|
-
},
|
|
203
|
-
bindings: {
|
|
204
|
-
sourceTexture: sourceView,
|
|
205
|
-
destinationTexture: destinationView,
|
|
206
|
-
uniforms: uniformsBuffer
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
const workgroupsX = Math.ceil(destinationWidth / WORKGROUP_SIZE.x);
|
|
210
|
-
const workgroupsY = Math.ceil(destinationHeight / WORKGROUP_SIZE.y);
|
|
211
|
-
const workgroupsZ = Math.ceil(destinationDepth / WORKGROUP_SIZE.z);
|
|
212
|
-
const computePass = device.beginComputePass({});
|
|
213
|
-
computation.dispatch(computePass, workgroupsX, workgroupsY, workgroupsZ);
|
|
214
|
-
computePass.end();
|
|
215
|
-
device.submit();
|
|
216
|
-
computation.destroy();
|
|
217
|
-
sourceView.destroy();
|
|
218
|
-
destinationView.destroy();
|
|
219
|
-
sourceWidth = destinationWidth;
|
|
220
|
-
sourceHeight = destinationHeight;
|
|
221
|
-
sourceDepth = destinationDepth;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
finally {
|
|
225
|
-
uniformsBuffer.destroy();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function validateFormatCapabilities(device, texture, requiredCapabilities, path) {
|
|
229
|
-
const { format, dimension } = texture;
|
|
230
|
-
const capabilities = device.getTextureFormatCapabilities(format);
|
|
231
|
-
const missingCapabilities = requiredCapabilities.filter(capability => !capabilities[capability]);
|
|
232
|
-
if (missingCapabilities.length > 0) {
|
|
233
|
-
const required = requiredCapabilities.join(' + ');
|
|
234
|
-
const actual = requiredCapabilities
|
|
235
|
-
.map(capability => `${capability}=${capabilities[capability]}`)
|
|
236
|
-
.join(', ');
|
|
237
|
-
throw new Error(`Cannot run ${path} mipmap generation for ${dimension} texture with format "${format}". ` +
|
|
238
|
-
`Required capabilities: ${required}. ` +
|
|
239
|
-
`Actual capabilities: ${actual}.`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function getSourceTextureType(dimension) {
|
|
243
|
-
switch (dimension) {
|
|
244
|
-
case '2d':
|
|
245
|
-
return 'texture_2d<f32>';
|
|
246
|
-
case '2d-array':
|
|
247
|
-
return 'texture_2d_array<f32>';
|
|
248
|
-
case 'cube':
|
|
249
|
-
return 'texture_cube<f32>';
|
|
250
|
-
case 'cube-array':
|
|
251
|
-
return 'texture_cube_array<f32>';
|
|
252
|
-
default:
|
|
253
|
-
throw new Error(`Unsupported render dimension "${dimension}" for mipmap generation.`);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
function getRenderMipmapWGSL(dimension) {
|
|
257
|
-
const sourceSnippet = getRenderMipmapSampleSnippet(dimension);
|
|
258
|
-
return `
|
|
259
|
-
struct MipmapUniforms {
|
|
260
|
-
sourceLayer: u32,
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
fn _touchUniform(uniforms: MipmapUniforms) {
|
|
264
|
-
let unusedSourceLayer = uniforms.sourceLayer;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const faceMat = array(
|
|
268
|
-
mat3x3f(
|
|
269
|
-
0.0, 0.0, -2.0,
|
|
270
|
-
0.0, -2.0, 0.0,
|
|
271
|
-
1.0, 1.0, 1.0
|
|
272
|
-
), // pos-x
|
|
273
|
-
mat3x3f(
|
|
274
|
-
0.0, 0.0, 2.0,
|
|
275
|
-
0.0, -2.0, 0.0,
|
|
276
|
-
-1.0, 1.0, -1.0
|
|
277
|
-
), // neg-x
|
|
278
|
-
mat3x3f(
|
|
279
|
-
2.0, 0.0, 0.0,
|
|
280
|
-
0.0, 0.0, 2.0,
|
|
281
|
-
-1.0, 1.0, -1.0
|
|
282
|
-
), // pos-y
|
|
283
|
-
mat3x3f(
|
|
284
|
-
2.0, 0.0, 0.0,
|
|
285
|
-
0.0, 0.0, -2.0,
|
|
286
|
-
-1.0, -1.0, 1.0
|
|
287
|
-
), // neg-y
|
|
288
|
-
mat3x3f(
|
|
289
|
-
2.0, 0.0, 0.0,
|
|
290
|
-
0.0, -2.0, 0.0,
|
|
291
|
-
-1.0, 1.0, 1.0
|
|
292
|
-
), // pos-z
|
|
293
|
-
mat3x3f(
|
|
294
|
-
-2.0, 0.0, 0.0,
|
|
295
|
-
0.0, -2.0, 0.0,
|
|
296
|
-
1.0, 1.0, -1.0
|
|
297
|
-
) // neg-z
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
struct FragmentInputs {
|
|
301
|
-
@builtin(position) position: vec4f,
|
|
302
|
-
@location(0) texcoord: vec2f
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
struct VertexOutput {
|
|
306
|
-
@builtin(position) position: vec4f,
|
|
307
|
-
@location(0) texcoord: vec2f
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
@group(0) @binding(0) var sourceSampler: sampler;
|
|
311
|
-
@group(0) @binding(1) var sourceTexture: ${getSourceTextureType(dimension)};
|
|
312
|
-
@group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
|
|
313
|
-
|
|
314
|
-
@vertex
|
|
315
|
-
fn vertexMain(
|
|
316
|
-
@builtin(vertex_index) vertexIndex: u32
|
|
317
|
-
) -> VertexOutput {
|
|
318
|
-
const positions = array(
|
|
319
|
-
vec2f(-1.0, -1.0),
|
|
320
|
-
vec2f(-1.0, 3.0),
|
|
321
|
-
vec2f( 3.0, -1.0)
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
let xy = positions[vertexIndex];
|
|
325
|
-
return VertexOutput(
|
|
326
|
-
vec4f(xy, 0.0, 1.0),
|
|
327
|
-
xy * vec2f(0.5, -0.5) + vec2f(0.5)
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
@fragment
|
|
332
|
-
fn fragmentMain(fsInput: VertexOutput) -> @location(0) vec4f {
|
|
333
|
-
_touchUniform(uniforms);
|
|
334
|
-
return ${sourceSnippet};
|
|
335
|
-
}
|
|
336
|
-
`;
|
|
337
|
-
}
|
|
338
|
-
function getRenderMipmapSampleSnippet(dimension) {
|
|
339
|
-
const layer = 'uniforms.sourceLayer';
|
|
340
|
-
switch (dimension) {
|
|
341
|
-
case '2d':
|
|
342
|
-
return 'textureSampleLevel(sourceTexture, sourceSampler, fsInput.texcoord, 0.0)';
|
|
343
|
-
case '2d-array':
|
|
344
|
-
return ('textureSampleLevel(sourceTexture, sourceSampler, fsInput.texcoord, ' +
|
|
345
|
-
`i32(${layer}), 0.0)`);
|
|
346
|
-
case 'cube':
|
|
347
|
-
return ('textureSampleLevel(sourceTexture, sourceSampler, ' +
|
|
348
|
-
`faceMat[i32(${layer})] * vec3f(fract(fsInput.texcoord), 1.0), 0.0)`);
|
|
349
|
-
case 'cube-array':
|
|
350
|
-
return ('textureSampleLevel(sourceTexture, sourceSampler, ' +
|
|
351
|
-
`faceMat[i32(${layer} % 6u)] * vec3f(fract(fsInput.texcoord), 1.0), ` +
|
|
352
|
-
`i32(${layer} / 6u), 0.0)`);
|
|
353
|
-
default:
|
|
354
|
-
throw new Error(`Unsupported render dimension "${dimension}" for mipmap generation.`);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
function get3DComputeMipmapWGSL(format) {
|
|
358
|
-
return `
|
|
359
|
-
struct MipmapUniforms {
|
|
360
|
-
sourceWidth: u32,
|
|
361
|
-
sourceHeight: u32,
|
|
362
|
-
sourceDepth: u32,
|
|
363
|
-
destinationWidth: u32,
|
|
364
|
-
destinationHeight: u32,
|
|
365
|
-
destinationDepth: u32,
|
|
366
|
-
padding: u32,
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
@group(0) @binding(0) var sourceTexture: texture_3d<f32>;
|
|
370
|
-
@group(0) @binding(1) var destinationTexture: texture_storage_3d<${format}, write>;
|
|
371
|
-
@group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
|
|
372
|
-
|
|
373
|
-
@compute @workgroup_size(${WORKGROUP_SIZE.x}, ${WORKGROUP_SIZE.y}, ${WORKGROUP_SIZE.z})
|
|
374
|
-
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
|
|
375
|
-
if (
|
|
376
|
-
id.x >= uniforms.destinationWidth ||
|
|
377
|
-
id.y >= uniforms.destinationHeight ||
|
|
378
|
-
id.z >= uniforms.destinationDepth
|
|
379
|
-
) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
let sourceBase = id * 2u;
|
|
384
|
-
let sourceX0 = min(sourceBase.x, uniforms.sourceWidth - 1u);
|
|
385
|
-
let sourceY0 = min(sourceBase.y, uniforms.sourceHeight - 1u);
|
|
386
|
-
let sourceZ0 = min(sourceBase.z, uniforms.sourceDepth - 1u);
|
|
387
|
-
|
|
388
|
-
let sourceX1 = min(sourceBase.x + 1u, uniforms.sourceWidth - 1u);
|
|
389
|
-
let sourceY1 = min(sourceBase.y + 1u, uniforms.sourceHeight - 1u);
|
|
390
|
-
let sourceZ1 = min(sourceBase.z + 1u, uniforms.sourceDepth - 1u);
|
|
391
|
-
|
|
392
|
-
var sum = textureLoad(
|
|
393
|
-
sourceTexture,
|
|
394
|
-
vec3<i32>(i32(sourceX0), i32(sourceY0), i32(sourceZ0)),
|
|
395
|
-
0
|
|
396
|
-
);
|
|
397
|
-
sum += textureLoad(
|
|
398
|
-
sourceTexture,
|
|
399
|
-
vec3<i32>(i32(sourceX1), i32(sourceY0), i32(sourceZ0)),
|
|
400
|
-
0
|
|
401
|
-
);
|
|
402
|
-
sum += textureLoad(
|
|
403
|
-
sourceTexture,
|
|
404
|
-
vec3<i32>(i32(sourceX0), i32(sourceY1), i32(sourceZ0)),
|
|
405
|
-
0
|
|
406
|
-
);
|
|
407
|
-
sum += textureLoad(
|
|
408
|
-
sourceTexture,
|
|
409
|
-
vec3<i32>(i32(sourceX1), i32(sourceY1), i32(sourceZ0)),
|
|
410
|
-
0
|
|
411
|
-
);
|
|
412
|
-
sum += textureLoad(
|
|
413
|
-
sourceTexture,
|
|
414
|
-
vec3<i32>(i32(sourceX0), i32(sourceY0), i32(sourceZ1)),
|
|
415
|
-
0
|
|
416
|
-
);
|
|
417
|
-
sum += textureLoad(
|
|
418
|
-
sourceTexture,
|
|
419
|
-
vec3<i32>(i32(sourceX1), i32(sourceY0), i32(sourceZ1)),
|
|
420
|
-
0
|
|
421
|
-
);
|
|
422
|
-
sum += textureLoad(
|
|
423
|
-
sourceTexture,
|
|
424
|
-
vec3<i32>(i32(sourceX0), i32(sourceY1), i32(sourceZ1)),
|
|
425
|
-
0
|
|
426
|
-
);
|
|
427
|
-
sum += textureLoad(
|
|
428
|
-
sourceTexture,
|
|
429
|
-
vec3<i32>(i32(sourceX1), i32(sourceY1), i32(sourceZ1)),
|
|
430
|
-
0
|
|
431
|
-
);
|
|
432
|
-
|
|
433
|
-
textureStore(
|
|
434
|
-
destinationTexture,
|
|
435
|
-
vec3<i32>(i32(id.x), i32(id.y), i32(id.z)),
|
|
436
|
-
vec4<f32>(sum.xyz / 8.0, sum.w / 8.0)
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
`;
|
|
440
|
-
}
|
|
441
|
-
//# sourceMappingURL=mipmaps.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mipmaps.js","sourceRoot":"","sources":["../../src/dynamic-texture/mipmaps.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAMpC,OAAO,EAAC,MAAM,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,KAAK,EAAC,0BAAuB;AACrC,OAAO,EAAC,WAAW,EAAC,kCAA+B;AAMnD,MAAM,iBAAiB,GAA8C;IACnE,IAAI;IACJ,UAAU;IACV,MAAM;IACN,YAAY;CACb,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;CACI,CAAC;AAEX;;GAEG;AACH,MA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iDAAiD;gBACrE,OAAO,KAAK,cAAc,CAC3B,CAAC;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,0BAA0B,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,MAA0B;IACxD,OAAO;;;;;;;;;;;;mEAY0D,MAAM;;;2BAG9C,cAAc,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEpF,CAAC;AACF,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
*/
|
|
7
|
-
export declare class PipelineFactory {
|
|
8
|
-
static defaultProps: Required<PipelineFactoryProps>;
|
|
9
|
-
/** Get the singleton default pipeline factory for the specified device */
|
|
10
|
-
static getDefaultPipelineFactory(device: Device): PipelineFactory;
|
|
11
|
-
readonly device: Device;
|
|
12
|
-
readonly cachingEnabled: boolean;
|
|
13
|
-
readonly destroyPolicy: 'unused' | 'never';
|
|
14
|
-
readonly debug: boolean;
|
|
15
|
-
private _hashCounter;
|
|
16
|
-
private readonly _hashes;
|
|
17
|
-
private readonly _renderPipelineCache;
|
|
18
|
-
private readonly _computePipelineCache;
|
|
19
|
-
get [Symbol.toStringTag](): string;
|
|
20
|
-
toString(): string;
|
|
21
|
-
constructor(device: Device);
|
|
22
|
-
/** Return a RenderPipeline matching supplied props. Reuses an equivalent pipeline if already created. */
|
|
23
|
-
createRenderPipeline(props: RenderPipelineProps): RenderPipeline;
|
|
24
|
-
/** Return a ComputePipeline matching supplied props. Reuses an equivalent pipeline if already created. */
|
|
25
|
-
createComputePipeline(props: ComputePipelineProps): ComputePipeline;
|
|
26
|
-
release(pipeline: RenderPipeline | ComputePipeline): void;
|
|
27
|
-
/** Destroy a cached pipeline, removing it from the cache (depending on destroy policy) */
|
|
28
|
-
private _destroyPipeline;
|
|
29
|
-
/** Get the appropriate cache for the type of pipeline */
|
|
30
|
-
private _getCache;
|
|
31
|
-
/** Calculate a hash based on all the inputs for a compute pipeline */
|
|
32
|
-
private _hashComputePipeline;
|
|
33
|
-
/** Calculate a hash based on all the inputs for a render pipeline */
|
|
34
|
-
private _hashRenderPipeline;
|
|
35
|
-
private _getHash;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=pipeline-factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-factory.d.ts","sourceRoot":"","sources":["../../src/factories/pipeline-factory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAM,MAAM,eAAe,CAAC;AAI3E,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAKvD;;GAEG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAoC;IAEvF,0EAA0E;IAC1E,MAAM,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe;IAMjE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA+C;IACpF,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAgD;IAEtF,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED,QAAQ,IAAI,MAAM;gBAIN,MAAM,EAAE,MAAM;IAO1B,yGAAyG;IACzG,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,cAAc;IAkChE,0GAA0G;IAC1G,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe;IAkCnE,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI;IAyBzD,0FAA0F;IAC1F,OAAO,CAAC,gBAAgB;IAaxB,yDAAyD;IACzD,OAAO,CAAC,SAAS;IAsBjB,sEAAsE;IACtE,OAAO,CAAC,oBAAoB;IAM5B,qEAAqE;IACrE,OAAO,CAAC,mBAAmB;IA0B3B,OAAO,CAAC,QAAQ;CAMjB"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { RenderPipeline, ComputePipeline, log } from '@luma.gl/core';
|
|
5
|
-
import { uid } from "../utils/uid.js";
|
|
6
|
-
/**
|
|
7
|
-
* Efficiently creates / caches pipelines
|
|
8
|
-
*/
|
|
9
|
-
export class PipelineFactory {
|
|
10
|
-
static defaultProps = { ...RenderPipeline.defaultProps };
|
|
11
|
-
/** Get the singleton default pipeline factory for the specified device */
|
|
12
|
-
static getDefaultPipelineFactory(device) {
|
|
13
|
-
const moduleData = device.getModuleData('@luma.gl/engine');
|
|
14
|
-
moduleData.defaultPipelineFactory ||= new PipelineFactory(device);
|
|
15
|
-
return moduleData.defaultPipelineFactory;
|
|
16
|
-
}
|
|
17
|
-
device;
|
|
18
|
-
cachingEnabled;
|
|
19
|
-
destroyPolicy;
|
|
20
|
-
debug;
|
|
21
|
-
_hashCounter = 0;
|
|
22
|
-
_hashes = {};
|
|
23
|
-
_renderPipelineCache = {};
|
|
24
|
-
_computePipelineCache = {};
|
|
25
|
-
get [Symbol.toStringTag]() {
|
|
26
|
-
return 'PipelineFactory';
|
|
27
|
-
}
|
|
28
|
-
toString() {
|
|
29
|
-
return `PipelineFactory(${this.device.id})`;
|
|
30
|
-
}
|
|
31
|
-
constructor(device) {
|
|
32
|
-
this.device = device;
|
|
33
|
-
this.cachingEnabled = device.props._cachePipelines;
|
|
34
|
-
this.destroyPolicy = device.props._cacheDestroyPolicy;
|
|
35
|
-
this.debug = device.props.debugFactories;
|
|
36
|
-
}
|
|
37
|
-
/** Return a RenderPipeline matching supplied props. Reuses an equivalent pipeline if already created. */
|
|
38
|
-
createRenderPipeline(props) {
|
|
39
|
-
if (!this.cachingEnabled) {
|
|
40
|
-
return this.device.createRenderPipeline(props);
|
|
41
|
-
}
|
|
42
|
-
const allProps = { ...RenderPipeline.defaultProps, ...props };
|
|
43
|
-
const cache = this._renderPipelineCache;
|
|
44
|
-
const hash = this._hashRenderPipeline(allProps);
|
|
45
|
-
let pipeline = cache[hash]?.pipeline;
|
|
46
|
-
if (!pipeline) {
|
|
47
|
-
pipeline = this.device.createRenderPipeline({
|
|
48
|
-
...allProps,
|
|
49
|
-
id: allProps.id ? `${allProps.id}-cached` : uid('unnamed-cached')
|
|
50
|
-
});
|
|
51
|
-
pipeline.hash = hash;
|
|
52
|
-
cache[hash] = { pipeline, useCount: 1 };
|
|
53
|
-
if (this.debug) {
|
|
54
|
-
log.log(3, `${this}: ${pipeline} created, count=${cache[hash].useCount}`)();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
cache[hash].useCount++;
|
|
59
|
-
if (this.debug) {
|
|
60
|
-
log.log(3, `${this}: ${cache[hash].pipeline} reused, count=${cache[hash].useCount}, (id=${props.id})`)();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return pipeline;
|
|
64
|
-
}
|
|
65
|
-
/** Return a ComputePipeline matching supplied props. Reuses an equivalent pipeline if already created. */
|
|
66
|
-
createComputePipeline(props) {
|
|
67
|
-
if (!this.cachingEnabled) {
|
|
68
|
-
return this.device.createComputePipeline(props);
|
|
69
|
-
}
|
|
70
|
-
const allProps = { ...ComputePipeline.defaultProps, ...props };
|
|
71
|
-
const cache = this._computePipelineCache;
|
|
72
|
-
const hash = this._hashComputePipeline(allProps);
|
|
73
|
-
let pipeline = cache[hash]?.pipeline;
|
|
74
|
-
if (!pipeline) {
|
|
75
|
-
pipeline = this.device.createComputePipeline({
|
|
76
|
-
...allProps,
|
|
77
|
-
id: allProps.id ? `${allProps.id}-cached` : undefined
|
|
78
|
-
});
|
|
79
|
-
pipeline.hash = hash;
|
|
80
|
-
cache[hash] = { pipeline, useCount: 1 };
|
|
81
|
-
if (this.debug) {
|
|
82
|
-
log.log(3, `${this}: ${pipeline} created, count=${cache[hash].useCount}`)();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
cache[hash].useCount++;
|
|
87
|
-
if (this.debug) {
|
|
88
|
-
log.log(3, `${this}: ${cache[hash].pipeline} reused, count=${cache[hash].useCount}, (id=${props.id})`)();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return pipeline;
|
|
92
|
-
}
|
|
93
|
-
release(pipeline) {
|
|
94
|
-
if (!this.cachingEnabled) {
|
|
95
|
-
pipeline.destroy();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const cache = this._getCache(pipeline);
|
|
99
|
-
const hash = pipeline.hash;
|
|
100
|
-
cache[hash].useCount--;
|
|
101
|
-
if (cache[hash].useCount === 0) {
|
|
102
|
-
this._destroyPipeline(pipeline);
|
|
103
|
-
if (this.debug) {
|
|
104
|
-
log.log(3, `${this}: ${pipeline} released and destroyed`)();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (cache[hash].useCount < 0) {
|
|
108
|
-
log.error(`${this}: ${pipeline} released, useCount < 0, resetting`)();
|
|
109
|
-
cache[hash].useCount = 0;
|
|
110
|
-
}
|
|
111
|
-
else if (this.debug) {
|
|
112
|
-
log.log(3, `${this}: ${pipeline} released, count=${cache[hash].useCount}`)();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// PRIVATE
|
|
116
|
-
/** Destroy a cached pipeline, removing it from the cache (depending on destroy policy) */
|
|
117
|
-
_destroyPipeline(pipeline) {
|
|
118
|
-
const cache = this._getCache(pipeline);
|
|
119
|
-
switch (this.destroyPolicy) {
|
|
120
|
-
case 'never':
|
|
121
|
-
return false;
|
|
122
|
-
case 'unused':
|
|
123
|
-
delete cache[pipeline.hash];
|
|
124
|
-
pipeline.destroy();
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** Get the appropriate cache for the type of pipeline */
|
|
129
|
-
_getCache(pipeline) {
|
|
130
|
-
let cache;
|
|
131
|
-
if (pipeline instanceof ComputePipeline) {
|
|
132
|
-
cache = this._computePipelineCache;
|
|
133
|
-
}
|
|
134
|
-
if (pipeline instanceof RenderPipeline) {
|
|
135
|
-
cache = this._renderPipelineCache;
|
|
136
|
-
}
|
|
137
|
-
if (!cache) {
|
|
138
|
-
throw new Error(`${this}`);
|
|
139
|
-
}
|
|
140
|
-
if (!cache[pipeline.hash]) {
|
|
141
|
-
throw new Error(`${this}: ${pipeline} matched incorrect entry`);
|
|
142
|
-
}
|
|
143
|
-
return cache;
|
|
144
|
-
}
|
|
145
|
-
/** Calculate a hash based on all the inputs for a compute pipeline */
|
|
146
|
-
_hashComputePipeline(props) {
|
|
147
|
-
const { type } = this.device;
|
|
148
|
-
const shaderHash = this._getHash(props.shader.source);
|
|
149
|
-
return `${type}/C/${shaderHash}`;
|
|
150
|
-
}
|
|
151
|
-
/** Calculate a hash based on all the inputs for a render pipeline */
|
|
152
|
-
_hashRenderPipeline(props) {
|
|
153
|
-
const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
|
|
154
|
-
const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
|
|
155
|
-
// WebGL specific
|
|
156
|
-
// const {varyings = [], bufferMode = {}} = props;
|
|
157
|
-
// const varyingHashes = varyings.map((v) => this._getHash(v));
|
|
158
|
-
const varyingHash = '-'; // `${varyingHashes.join('/')}B${bufferMode}`
|
|
159
|
-
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
160
|
-
const { type } = this.device;
|
|
161
|
-
switch (type) {
|
|
162
|
-
case 'webgl':
|
|
163
|
-
// WebGL is more dynamic
|
|
164
|
-
return `${type}/R/${vsHash}/${fsHash}V${varyingHash}BL${bufferLayoutHash}`;
|
|
165
|
-
case 'webgpu':
|
|
166
|
-
default:
|
|
167
|
-
// On WebGPU we need to rebuild the pipeline if topology, parameters or bufferLayout change
|
|
168
|
-
const parameterHash = this._getHash(JSON.stringify(props.parameters));
|
|
169
|
-
// TODO - Can json.stringify() generate different strings for equivalent objects if order of params is different?
|
|
170
|
-
// create a deepHash() to deduplicate?
|
|
171
|
-
return `${type}/R/${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}`;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
_getHash(key) {
|
|
175
|
-
if (this._hashes[key] === undefined) {
|
|
176
|
-
this._hashes[key] = this._hashCounter++;
|
|
177
|
-
}
|
|
178
|
-
return this._hashes[key];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
//# sourceMappingURL=pipeline-factory.js.map
|