@luma.gl/engine 9.2.6 → 9.3.0-alpha.4
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 +3 -1
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +10 -4
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +3 -2
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/swap.d.ts +2 -0
- package/dist/compute/swap.d.ts.map +1 -1
- package/dist/compute/swap.js +10 -5
- package/dist/compute/swap.js.map +1 -1
- package/dist/dist.dev.js +1251 -574
- package/dist/dist.min.js +216 -48
- package/dist/dynamic-texture/dynamic-texture.d.ts +95 -0
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -0
- package/dist/dynamic-texture/dynamic-texture.js +389 -0
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -0
- package/dist/dynamic-texture/mipmaps.d.ts +6 -0
- package/dist/dynamic-texture/mipmaps.d.ts.map +1 -0
- package/dist/dynamic-texture/mipmaps.js +441 -0
- package/dist/dynamic-texture/mipmaps.js.map +1 -0
- package/dist/dynamic-texture/texture-data.d.ts +137 -0
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -0
- package/dist/dynamic-texture/texture-data.js +183 -0
- package/dist/dynamic-texture/texture-data.js.map +1 -0
- package/dist/factories/pipeline-factory.d.ts.map +1 -1
- package/dist/factories/pipeline-factory.js +3 -3
- package/dist/factories/pipeline-factory.js.map +1 -1
- package/dist/factories/shader-factory.d.ts.map +1 -1
- package/dist/factories/shader-factory.js +3 -2
- package/dist/factories/shader-factory.js.map +1 -1
- package/dist/index.cjs +1243 -583
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts +31 -10
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +34 -14
- package/dist/model/model.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts +8 -5
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +70 -18
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/passes/get-fragment-shader.js +15 -11
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +5 -5
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +13 -12
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/buffer-layout-order.d.ts.map +1 -1
- package/dist/utils/buffer-layout-order.js +12 -2
- package/dist/utils/buffer-layout-order.js.map +1 -1
- package/package.json +6 -6
- package/src/animation-loop/animation-loop.ts +11 -4
- package/src/compute/computation.ts +3 -2
- package/src/compute/swap.ts +13 -7
- package/src/dynamic-texture/dynamic-texture.ts +499 -0
- package/src/dynamic-texture/mipmaps.ts +517 -0
- package/src/dynamic-texture/texture-data.ts +301 -0
- package/src/factories/pipeline-factory.ts +4 -3
- package/src/factories/shader-factory.ts +4 -2
- package/src/index.ts +9 -4
- package/src/model/model.ts +37 -18
- package/src/models/billboard-texture-model.ts +81 -22
- package/src/passes/get-fragment-shader.ts +15 -11
- package/src/passes/shader-pass-renderer.ts +22 -16
- package/src/types.ts +11 -0
- package/src/utils/buffer-layout-order.ts +18 -2
- package/dist/async-texture/async-texture.d.ts +0 -166
- package/dist/async-texture/async-texture.d.ts.map +0 -1
- package/dist/async-texture/async-texture.js +0 -386
- package/dist/async-texture/async-texture.js.map +0 -1
- package/src/async-texture/async-texture.ts +0 -551
- /package/src/{async-texture/texture-setters.ts.disabled → dynamic-texture/texture-data.ts.disabled} +0 -0
|
@@ -0,0 +1,441 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,OAAgB;IAC7D,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO;IACT,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,2CAA2C,MAAM,CAAC,IAAI,gDAAgD,CACvG,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;QAC/B,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,OAAO;IACT,CAAC;IAED,IAAI,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAuC,CAAC,EAAE,CAAC;QAChF,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvC,O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,KAAK,CAAC,iCAAiC,SAAS,0BAA0B,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAqC;IAChE,MAAM,aAAa,GAAG,4BAA4B,CAAC,SAAS,CAAC,CAAC;IAE9D,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAqDkC,oBAAoB,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;WAuB/D,aAAa;;CAEvB,CAAC;AACF,CAAC;AAED,SAAS,4BAA4B,CAAC,SAAqC;IACzE,MAAM,KAAK,GAAG,sBAAsB,CAAC;IAErC,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,IAAI;YACP,OAAO,yEAAyE,CAAC;QACnF,KAAK,UAAU;YACb,OAAO,CACL,qEAAqE;gBACrE,OAAO,KAAK,SAAS,CACtB,CAAC;QACJ,KAAK,MAAM;YACT,OAAO,CACL,mDAAmD;gBACnD,eAAe,KAAK,gDAAgD,CACrE,CAAC;QACJ,KAAK,YAAY;YACf,OAAO,CACL,mDAAmD;gBACnD,eAAe,KAAK,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"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { TypedArray, TextureFormat, ExternalImage } from '@luma.gl/core';
|
|
2
|
+
export type TextureImageSource = ExternalImage;
|
|
3
|
+
/**
|
|
4
|
+
* One mip level
|
|
5
|
+
* Basic data structure is similar to `ImageData`
|
|
6
|
+
* additional optional fields can describe compressed texture data.
|
|
7
|
+
*/
|
|
8
|
+
export type TextureImageData = {
|
|
9
|
+
/** WebGPU style format string. Defaults to 'rgba8unorm' */
|
|
10
|
+
format?: TextureFormat;
|
|
11
|
+
/** Typed Array with the bytes of the image. @note beware row byte alignment requirements */
|
|
12
|
+
data: TypedArray;
|
|
13
|
+
/** Width of the image, in pixels, @note beware row byte alignment requirements */
|
|
14
|
+
width: number;
|
|
15
|
+
/** Height of the image, in rows */
|
|
16
|
+
height: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A single mip-level can be initialized by data or an ImageBitmap etc
|
|
20
|
+
* @note in the WebGPU spec a mip-level is called a subresource
|
|
21
|
+
*/
|
|
22
|
+
export type TextureMipLevelData = TextureImageData | TextureImageSource;
|
|
23
|
+
/**
|
|
24
|
+
* Texture data for one image "slice" (which can consist of multiple miplevels)
|
|
25
|
+
* Thus data for one slice be a single mip level or an array of miplevels
|
|
26
|
+
* @note in the WebGPU spec each cross-section image in a 3D texture is called a "slice",
|
|
27
|
+
* in a array texture each image in the array is called an array "layer"
|
|
28
|
+
* luma.gl calls one image in a GPU texture a "slice" regardless of context.
|
|
29
|
+
*/
|
|
30
|
+
export type TextureSliceData = TextureMipLevelData | TextureMipLevelData[];
|
|
31
|
+
/** Names of cube texture faces */
|
|
32
|
+
export type TextureCubeFace = '+X' | '-X' | '+Y' | '-Y' | '+Z' | '-Z';
|
|
33
|
+
/** Array of cube texture faces. @note: index in array is the face index */
|
|
34
|
+
export declare const TEXTURE_CUBE_FACES: readonly ["+X", "-X", "+Y", "-Y", "+Z", "-Z"];
|
|
35
|
+
/** Map of cube texture face names to face indexes */
|
|
36
|
+
export declare const TEXTURE_CUBE_FACE_MAP: {
|
|
37
|
+
readonly '+X': 0;
|
|
38
|
+
readonly '-X': 1;
|
|
39
|
+
readonly '+Y': 2;
|
|
40
|
+
readonly '-Y': 3;
|
|
41
|
+
readonly '+Z': 4;
|
|
42
|
+
readonly '-Z': 5;
|
|
43
|
+
};
|
|
44
|
+
/** @todo - Define what data type is supported for 1D textures. TextureImageData with height = 1 */
|
|
45
|
+
export type Texture1DData = TextureSliceData;
|
|
46
|
+
/** Texture data can be one or more mip levels */
|
|
47
|
+
export type Texture2DData = TextureSliceData;
|
|
48
|
+
/** 6 face textures */
|
|
49
|
+
export type TextureCubeData = Record<TextureCubeFace, TextureSliceData>;
|
|
50
|
+
/** Array of textures */
|
|
51
|
+
export type Texture3DData = TextureSliceData[];
|
|
52
|
+
/** Array of textures */
|
|
53
|
+
export type TextureArrayData = TextureSliceData[];
|
|
54
|
+
/** Array of 6 face textures */
|
|
55
|
+
export type TextureCubeArrayData = Record<TextureCubeFace, TextureSliceData>[];
|
|
56
|
+
type TextureData = Texture1DData | Texture3DData | TextureArrayData | TextureCubeArrayData | TextureCubeData;
|
|
57
|
+
/** Sync data props */
|
|
58
|
+
export type TextureDataProps = {
|
|
59
|
+
dimension: '1d';
|
|
60
|
+
data: Texture1DData | null;
|
|
61
|
+
} | {
|
|
62
|
+
dimension?: '2d';
|
|
63
|
+
data: Texture2DData | null;
|
|
64
|
+
} | {
|
|
65
|
+
dimension: '3d';
|
|
66
|
+
data: Texture3DData | null;
|
|
67
|
+
} | {
|
|
68
|
+
dimension: '2d-array';
|
|
69
|
+
data: TextureArrayData | null;
|
|
70
|
+
} | {
|
|
71
|
+
dimension: 'cube';
|
|
72
|
+
data: TextureCubeData | null;
|
|
73
|
+
} | {
|
|
74
|
+
dimension: 'cube-array';
|
|
75
|
+
data: TextureCubeArrayData | null;
|
|
76
|
+
};
|
|
77
|
+
/** Async data props */
|
|
78
|
+
export type TextureDataAsyncProps = {
|
|
79
|
+
dimension: '1d';
|
|
80
|
+
data?: Promise<Texture1DData> | Texture1DData | null;
|
|
81
|
+
} | {
|
|
82
|
+
dimension?: '2d';
|
|
83
|
+
data?: Promise<Texture2DData> | Texture2DData | null;
|
|
84
|
+
} | {
|
|
85
|
+
dimension: '3d';
|
|
86
|
+
data?: Promise<Texture3DData> | Texture3DData | null;
|
|
87
|
+
} | {
|
|
88
|
+
dimension: '2d-array';
|
|
89
|
+
data?: Promise<TextureArrayData> | TextureArrayData | null;
|
|
90
|
+
} | {
|
|
91
|
+
dimension: 'cube';
|
|
92
|
+
data?: Promise<TextureCubeData> | TextureCubeData | null;
|
|
93
|
+
} | {
|
|
94
|
+
dimension: 'cube-array';
|
|
95
|
+
data?: Promise<TextureCubeArrayData> | TextureCubeArrayData | null;
|
|
96
|
+
};
|
|
97
|
+
/** Describes data for one sub resource (one mip level of one slice (depth or array layer)) */
|
|
98
|
+
export type TextureSubresource = {
|
|
99
|
+
/** slice (depth or array layer)) */
|
|
100
|
+
z: number;
|
|
101
|
+
/** mip level (0 - max mip levels) */
|
|
102
|
+
mipLevel: number;
|
|
103
|
+
} & ({
|
|
104
|
+
type: 'external-image';
|
|
105
|
+
image: ExternalImage;
|
|
106
|
+
/** @deprecated is this an appropriate place for this flag? */
|
|
107
|
+
flipY?: boolean;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'texture-data';
|
|
110
|
+
data: TextureImageData;
|
|
111
|
+
});
|
|
112
|
+
/** Check if texture data is a typed array */
|
|
113
|
+
export declare function isTextureSliceData(data: TextureData): data is TextureImageData;
|
|
114
|
+
export declare function getFirstMipLevel(layer: TextureSliceData | null): TextureMipLevelData | null;
|
|
115
|
+
export declare function getTextureSizeFromData(props: TextureDataProps): {
|
|
116
|
+
width: number;
|
|
117
|
+
height: number;
|
|
118
|
+
} | null;
|
|
119
|
+
/** Resolve size for a single mip-level datum */
|
|
120
|
+
/** Convert cube face label to depth index */
|
|
121
|
+
export declare function getCubeFaceIndex(face: TextureCubeFace): number;
|
|
122
|
+
/** Convert cube face label to texture slice index. Index can be used with `setTexture2DData()`. */
|
|
123
|
+
export declare function getCubeArrayFaceIndex(cubeIndex: number, face: TextureCubeFace): number;
|
|
124
|
+
/** Experimental: Set multiple mip levels (1D) */
|
|
125
|
+
export declare function getTexture1DSubresources(data: Texture1DData): TextureSubresource[];
|
|
126
|
+
/** Experimental: Set multiple mip levels (2D), optionally at `z` (depth/array index) */
|
|
127
|
+
export declare function getTexture2DSubresources(slice: number, lodData: Texture2DData): TextureSubresource[];
|
|
128
|
+
/** 3D: multiple depth slices, each may carry multiple mip levels */
|
|
129
|
+
export declare function getTexture3DSubresources(data: Texture3DData): TextureSubresource[];
|
|
130
|
+
/** 2D array: multiple layers, each may carry multiple mip levels */
|
|
131
|
+
export declare function getTextureArraySubresources(data: TextureArrayData): TextureSubresource[];
|
|
132
|
+
/** Cube: 6 faces, each may carry multiple mip levels */
|
|
133
|
+
export declare function getTextureCubeSubresources(data: TextureCubeData): TextureSubresource[];
|
|
134
|
+
/** Cube array: multiple cubes (faces×layers), each face may carry multiple mips */
|
|
135
|
+
export declare function getTextureCubeArraySubresources(data: TextureCubeArrayData): TextureSubresource[];
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=texture-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-data.d.ts","sourceRoot":"","sources":["../../src/dynamic-texture/texture-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAG5E,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,4FAA4F;IAC5F,IAAI,EAAE,UAAU,CAAC;IACjB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAExE;;;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