@luma.gl/webgpu 9.0.0-alpha.14 → 9.0.0-alpha.16
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/adapter/helpers/accessor-to-format.js +100 -1
- package/dist/adapter/helpers/convert-texture-format.js +5 -6
- package/dist/adapter/helpers/generate-mipmaps.js +88 -92
- package/dist/adapter/helpers/get-bind-group.js +54 -48
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +97 -84
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +181 -129
- package/dist/adapter/resources/webgpu-buffer.js +57 -73
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +47 -63
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +51 -55
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +22 -24
- package/dist/adapter/resources/webgpu-external-texture.js +26 -27
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +89 -103
- package/dist/adapter/resources/webgpu-query.js +42 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +64 -89
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +158 -154
- package/dist/adapter/resources/webgpu-sampler.d.ts +1 -1
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +16 -22
- package/dist/adapter/resources/webgpu-shader.d.ts +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +47 -58
- package/dist/adapter/resources/webgpu-texture.d.ts +0 -1
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +100 -103
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +77 -90
- package/dist/adapter/webgpu-device.js +215 -242
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/bundle.js +1 -2
- package/dist/dist.js +8051 -0
- package/dist/dist.min.js +1 -0
- package/dist/es5/adapter/helpers/accessor-to-format.js +2 -0
- package/dist/es5/adapter/helpers/accessor-to-format.js.map +1 -0
- package/dist/es5/adapter/helpers/convert-texture-format.js +13 -0
- package/dist/es5/adapter/helpers/convert-texture-format.js.map +1 -0
- package/dist/es5/adapter/helpers/generate-mipmaps.js +103 -0
- package/dist/es5/adapter/helpers/generate-mipmaps.js.map +1 -0
- package/dist/es5/adapter/helpers/get-bind-group.js +66 -0
- package/dist/es5/adapter/helpers/get-bind-group.js.map +1 -0
- package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js +149 -0
- package/dist/es5/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
- package/dist/es5/adapter/helpers/webgpu-parameters.js +150 -0
- package/dist/es5/adapter/helpers/webgpu-parameters.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-buffer.js +131 -0
- package/dist/es5/adapter/resources/webgpu-buffer.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-command-encoder.js +90 -0
- package/dist/es5/adapter/resources/webgpu-command-encoder.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-compute-pass.js +85 -0
- package/dist/es5/adapter/resources/webgpu-compute-pass.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-compute-pipeline.js +48 -0
- package/dist/es5/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-external-texture.js +50 -0
- package/dist/es5/adapter/resources/webgpu-external-texture.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-framebuffer.js +126 -0
- package/dist/es5/adapter/resources/webgpu-framebuffer.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-query.js +2 -0
- package/dist/es5/adapter/resources/webgpu-query.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-render-pass.js +124 -0
- package/dist/es5/adapter/resources/webgpu-render-pass.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-render-pipeline.js +185 -0
- package/dist/es5/adapter/resources/webgpu-render-pipeline.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-sampler.js +45 -0
- package/dist/es5/adapter/resources/webgpu-sampler.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-shader.js +125 -0
- package/dist/es5/adapter/resources/webgpu-shader.js.map +1 -0
- package/dist/es5/adapter/resources/webgpu-texture.js +138 -0
- package/dist/es5/adapter/resources/webgpu-texture.js.map +1 -0
- package/dist/es5/adapter/webgpu-canvas-context.js +111 -0
- package/dist/es5/adapter/webgpu-canvas-context.js.map +1 -0
- package/dist/es5/adapter/webgpu-device.js +317 -0
- package/dist/es5/adapter/webgpu-device.js.map +1 -0
- package/dist/es5/adapter/webgpu-types.js +2 -0
- package/dist/es5/adapter/webgpu-types.js.map +1 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/glsl/glsllang.js +47 -0
- package/dist/es5/glsl/glsllang.js.map +1 -0
- package/dist/es5/index.js +44 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/init.js +7 -0
- package/dist/es5/init.js.map +1 -0
- package/dist/esm/adapter/helpers/accessor-to-format.js +2 -0
- package/dist/esm/adapter/helpers/accessor-to-format.js.map +1 -0
- package/dist/esm/adapter/helpers/convert-texture-format.js +7 -0
- package/dist/esm/adapter/helpers/convert-texture-format.js.map +1 -0
- package/dist/esm/adapter/helpers/generate-mipmaps.js +88 -0
- package/dist/esm/adapter/helpers/generate-mipmaps.js.map +1 -0
- package/dist/esm/adapter/helpers/get-bind-group.js +51 -0
- package/dist/esm/adapter/helpers/get-bind-group.js.map +1 -0
- package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js +83 -0
- package/dist/esm/adapter/helpers/get-vertex-buffer-layout.js.map +1 -0
- package/dist/esm/adapter/helpers/webgpu-parameters.js +137 -0
- package/dist/esm/adapter/helpers/webgpu-parameters.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-buffer.js +70 -0
- package/dist/esm/adapter/resources/webgpu-buffer.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-command-encoder.js +49 -0
- package/dist/esm/adapter/resources/webgpu-command-encoder.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-compute-pass.js +44 -0
- package/dist/esm/adapter/resources/webgpu-compute-pass.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-compute-pipeline.js +23 -0
- package/dist/esm/adapter/resources/webgpu-compute-pipeline.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-external-texture.js +23 -0
- package/dist/esm/adapter/resources/webgpu-external-texture.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-framebuffer.js +93 -0
- package/dist/esm/adapter/resources/webgpu-framebuffer.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-query.js +2 -0
- package/dist/esm/adapter/resources/webgpu-query.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-render-pass.js +79 -0
- package/dist/esm/adapter/resources/webgpu-render-pass.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-render-pipeline.js +130 -0
- package/dist/esm/adapter/resources/webgpu-render-pipeline.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-sampler.js +20 -0
- package/dist/esm/adapter/resources/webgpu-sampler.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-shader.js +50 -0
- package/dist/esm/adapter/resources/webgpu-shader.js.map +1 -0
- package/dist/esm/adapter/resources/webgpu-texture.js +95 -0
- package/dist/esm/adapter/resources/webgpu-texture.js.map +1 -0
- package/dist/esm/adapter/webgpu-canvas-context.js +74 -0
- package/dist/esm/adapter/webgpu-canvas-context.js.map +1 -0
- package/dist/esm/adapter/webgpu-device.js +196 -0
- package/dist/esm/adapter/webgpu-device.js.map +1 -0
- package/dist/esm/adapter/webgpu-types.js +2 -0
- package/dist/esm/adapter/webgpu-types.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/glsl/glsllang.js +9 -0
- package/dist/esm/glsl/glsllang.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/init.js +4 -0
- package/dist/esm/init.js.map +1 -0
- package/dist/glsl/glsllang.js +9 -7
- package/dist/index.js +8 -6
- package/dist/init.js +1 -2
- package/package.json +8 -8
- package/src/adapter/helpers/webgpu-parameters.ts +7 -2
- package/src/adapter/resources/webgpu-command-encoder.ts +2 -1
- package/src/adapter/resources/webgpu-compute-pass.ts +4 -4
- package/src/adapter/resources/webgpu-compute-pipeline.ts +2 -1
- package/src/adapter/resources/webgpu-framebuffer.ts +3 -2
- package/src/adapter/resources/webgpu-render-pass.ts +2 -2
- package/src/adapter/resources/webgpu-render-pipeline.ts +2 -1
- package/src/adapter/resources/webgpu-shader.ts +1 -1
- package/src/adapter/webgpu-canvas-context.ts +3 -2
- package/src/adapter/webgpu-device.ts +2 -2
- package/dist/adapter/helpers/accessor-to-format.js.map +0 -1
- package/dist/adapter/helpers/convert-texture-format.js.map +0 -1
- package/dist/adapter/helpers/generate-mipmaps.js.map +0 -1
- package/dist/adapter/helpers/get-bind-group.js.map +0 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +0 -1
- package/dist/adapter/helpers/webgpu-parameters.js.map +0 -1
- package/dist/adapter/resources/webgpu-buffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-command-encoder.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-external-texture.js.map +0 -1
- package/dist/adapter/resources/webgpu-framebuffer.js.map +0 -1
- package/dist/adapter/resources/webgpu-query.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pass.js.map +0 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +0 -1
- package/dist/adapter/resources/webgpu-sampler.js.map +0 -1
- package/dist/adapter/resources/webgpu-shader.js.map +0 -1
- package/dist/adapter/resources/webgpu-texture.js.map +0 -1
- package/dist/adapter/webgpu-canvas-context.js.map +0 -1
- package/dist/adapter/webgpu-device.js.map +0 -1
- package/dist/adapter/webgpu-types.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init.js.map +0 -1
|
@@ -1,111 +1,108 @@
|
|
|
1
|
-
|
|
1
|
+
// luma.gl, MIT license
|
|
2
2
|
import { Texture } from '@luma.gl/api';
|
|
3
|
-
import { getWebGPUTextureFormat } from '../helpers/convert-texture-format';
|
|
4
|
-
import WebGPUSampler from './webgpu-sampler';
|
|
3
|
+
import { getWebGPUTextureFormat } from '../helpers/convert-texture-format.js';
|
|
4
|
+
import WebGPUSampler from './webgpu-sampler.js';
|
|
5
5
|
const BASE_DIMENSIONS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
'1d': '1d',
|
|
7
|
+
'2d': '2d',
|
|
8
|
+
'2d-array': '2d',
|
|
9
|
+
'cube': '2d',
|
|
10
|
+
'cube-array': '2d',
|
|
11
|
+
'3d': '3d'
|
|
12
12
|
};
|
|
13
13
|
export default class WebGPUTexture extends Texture {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
// static async createFromImageURL(src, usage = 0) {
|
|
15
|
+
// const img = document.createElement('img');
|
|
16
|
+
// img.src = src;
|
|
17
|
+
// await img.decode();
|
|
18
|
+
// return WebGPUTexture(img, usage);
|
|
19
|
+
// }
|
|
20
|
+
constructor(device, props) {
|
|
21
|
+
super(device, props);
|
|
22
|
+
if (typeof this.props.format === 'number') {
|
|
23
|
+
throw new Error('number format');
|
|
24
|
+
}
|
|
25
|
+
this.device = device;
|
|
26
|
+
this.handle = this.props.handle || this.createHandle();
|
|
27
|
+
if (this.props.data) {
|
|
28
|
+
this.setData({ data: this.props.data });
|
|
29
|
+
}
|
|
30
|
+
// Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
|
|
31
|
+
// this.setSampler(props.sampler);
|
|
32
|
+
this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
|
|
33
|
+
// TODO - To support texture arrays we need to create custom views...
|
|
34
|
+
// But we are not ready to expose TextureViews to the public API.
|
|
35
|
+
this.view = this.handle.createView({
|
|
36
|
+
// format: this.props.format,
|
|
37
|
+
// dimension: this.props.dimension,
|
|
38
|
+
// aspect = "all";
|
|
39
|
+
// baseMipLevel: 0;
|
|
40
|
+
// mipLevelCount;
|
|
41
|
+
// baseArrayLayer = 0;
|
|
42
|
+
// arrayLayerCount;
|
|
43
|
+
});
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
createHandle() {
|
|
46
|
+
if (typeof this.props.format === 'number') {
|
|
47
|
+
throw new Error('number format');
|
|
48
|
+
}
|
|
49
|
+
// Deduce size from data - TODO this is a hack
|
|
50
|
+
// @ts-expect-error
|
|
51
|
+
const width = this.props.width || this.props.data?.width || 1;
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
const height = this.props.height || this.props.data?.height || 1;
|
|
54
|
+
return this.device.handle.createTexture({
|
|
55
|
+
size: {
|
|
56
|
+
width,
|
|
57
|
+
height,
|
|
58
|
+
depthOrArrayLayers: this.props.depth
|
|
59
|
+
},
|
|
60
|
+
dimension: BASE_DIMENSIONS[this.props.dimension],
|
|
61
|
+
format: getWebGPUTextureFormat(this.props.format),
|
|
62
|
+
usage: this.props.usage,
|
|
63
|
+
mipLevelCount: this.props.mipLevels,
|
|
64
|
+
sampleCount: this.props.samples
|
|
65
|
+
});
|
|
36
66
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
destroy() {
|
|
68
|
+
this.handle.destroy();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set default sampler
|
|
72
|
+
* Accept a sampler instance or set of props;
|
|
73
|
+
*/
|
|
74
|
+
setSampler(sampler) {
|
|
75
|
+
this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
setData(options) {
|
|
79
|
+
return this.setImage({ source: options.data });
|
|
80
|
+
}
|
|
81
|
+
/** Set image */
|
|
82
|
+
setImage(options) {
|
|
83
|
+
const { source, width = options.source.width, height = options.source.height, depth = 1, sourceX = 0, sourceY = 0, mipLevel = 0, x = 0, y = 0, z = 0, aspect = 'all', colorSpace = 'srgb', premultipliedAlpha = false } = options;
|
|
84
|
+
// TODO - max out width
|
|
85
|
+
this.device.handle.queue.copyExternalImageToTexture(
|
|
86
|
+
// source: GPUImageCopyExternalImage
|
|
87
|
+
{
|
|
88
|
+
source,
|
|
89
|
+
origin: [sourceX, sourceY]
|
|
90
|
+
},
|
|
91
|
+
// destination: GPUImageCopyTextureTagged
|
|
92
|
+
{
|
|
93
|
+
texture: this.handle,
|
|
94
|
+
origin: [x, y, z],
|
|
95
|
+
mipLevel,
|
|
96
|
+
aspect,
|
|
97
|
+
colorSpace,
|
|
98
|
+
premultipliedAlpha
|
|
99
|
+
},
|
|
100
|
+
// copySize: GPUExtent3D
|
|
101
|
+
[
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
depth
|
|
105
|
+
]);
|
|
106
|
+
return this;
|
|
47
107
|
}
|
|
48
|
-
|
|
49
|
-
const width = this.props.width || ((_this$props$data = this.props.data) === null || _this$props$data === void 0 ? void 0 : _this$props$data.width) || 1;
|
|
50
|
-
const height = this.props.height || ((_this$props$data2 = this.props.data) === null || _this$props$data2 === void 0 ? void 0 : _this$props$data2.height) || 1;
|
|
51
|
-
return this.device.handle.createTexture({
|
|
52
|
-
size: {
|
|
53
|
-
width,
|
|
54
|
-
height,
|
|
55
|
-
depthOrArrayLayers: this.props.depth
|
|
56
|
-
},
|
|
57
|
-
dimension: BASE_DIMENSIONS[this.props.dimension],
|
|
58
|
-
format: getWebGPUTextureFormat(this.props.format),
|
|
59
|
-
usage: this.props.usage,
|
|
60
|
-
mipLevelCount: this.props.mipLevels,
|
|
61
|
-
sampleCount: this.props.samples
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
destroy() {
|
|
66
|
-
this.handle.destroy();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
setSampler(sampler) {
|
|
70
|
-
this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
setData(options) {
|
|
75
|
-
return this.setImage({
|
|
76
|
-
source: options.data
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
setImage(options) {
|
|
81
|
-
const {
|
|
82
|
-
source,
|
|
83
|
-
width = options.source.width,
|
|
84
|
-
height = options.source.height,
|
|
85
|
-
depth = 1,
|
|
86
|
-
sourceX = 0,
|
|
87
|
-
sourceY = 0,
|
|
88
|
-
mipLevel = 0,
|
|
89
|
-
x = 0,
|
|
90
|
-
y = 0,
|
|
91
|
-
z = 0,
|
|
92
|
-
aspect = 'all',
|
|
93
|
-
colorSpace = 'srgb',
|
|
94
|
-
premultipliedAlpha = false
|
|
95
|
-
} = options;
|
|
96
|
-
this.device.handle.queue.copyExternalImageToTexture({
|
|
97
|
-
source,
|
|
98
|
-
origin: [sourceX, sourceY]
|
|
99
|
-
}, {
|
|
100
|
-
texture: this.handle,
|
|
101
|
-
origin: [x, y, z],
|
|
102
|
-
mipLevel,
|
|
103
|
-
aspect,
|
|
104
|
-
colorSpace,
|
|
105
|
-
premultipliedAlpha
|
|
106
|
-
}, [width, height, depth]);
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
108
|
}
|
|
111
|
-
//# sourceMappingURL=webgpu-texture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAM,MAAM,cAAc,CAAC;AAEhD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,aAAa;IAC5D,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,kBAAkB,EAAE,aAAa,CAAiB;IAClD,WAAW,EAAE,MAAM,CAAK;IAExB,OAAO,CAAC,sBAAsB,CAAwB;gBAE1C,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;
|
|
1
|
+
{"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAM,MAAM,cAAc,CAAC;AAEhD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,aAAa;IAC5D,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,kBAAkB,EAAE,aAAa,CAAiB;IAClD,WAAW,EAAE,MAAM,CAAK;IAExB,OAAO,CAAC,sBAAsB,CAAwB;gBAE1C,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;IAahF,OAAO,IAAI,IAAI;IAIf,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IAsB1C,sDAAsD;IACtD,MAAM;IA6BN,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAI7F,8FAA8F;IAC9F,6BAA6B;CAY9B"}
|
|
@@ -1,96 +1,83 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import { CanvasContext, log } from '@luma.gl/api';
|
|
3
|
-
import { getWebGPUTextureFormat } from './helpers/convert-texture-format';
|
|
4
|
-
import WEBGPUFramebuffer from './resources/webgpu-framebuffer';
|
|
2
|
+
import { getWebGPUTextureFormat } from './helpers/convert-texture-format.js';
|
|
3
|
+
import WEBGPUFramebuffer from './resources/webgpu-framebuffer.js';
|
|
4
|
+
/**
|
|
5
|
+
* Holds a WebGPU Canvas Context which handles resizing etc
|
|
6
|
+
*/
|
|
5
7
|
export default class WebGPUCanvasContext extends CanvasContext {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
_defineProperty(this, "gpuCanvasContext", void 0);
|
|
12
|
-
|
|
13
|
-
_defineProperty(this, "format", void 0);
|
|
14
|
-
|
|
15
|
-
_defineProperty(this, "depthStencilFormat", 'depth24plus');
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "sampleCount", 1);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "depthStencilAttachment", null);
|
|
20
|
-
|
|
21
|
-
this.device = device;
|
|
22
|
-
this.width = -1;
|
|
23
|
-
this.height = -1;
|
|
24
|
-
|
|
25
|
-
this._setAutoCreatedCanvasId("".concat(this.device.id, "-canvas"));
|
|
26
|
-
|
|
27
|
-
this.gpuCanvasContext = this.canvas.getContext('webgpu');
|
|
28
|
-
this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
destroy() {
|
|
32
|
-
this.gpuCanvasContext.unconfigure();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getCurrentFramebuffer() {
|
|
36
|
-
this.update();
|
|
37
|
-
const currentColorAttachment = this.device.createTexture({
|
|
38
|
-
id: 'default-render-target',
|
|
39
|
-
handle: this.gpuCanvasContext.getCurrentTexture(),
|
|
40
|
-
format: this.format,
|
|
41
|
-
width: this.width,
|
|
42
|
-
height: this.height
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
this._createDepthStencilAttachment();
|
|
46
|
-
|
|
47
|
-
return new WEBGPUFramebuffer(this.device, {
|
|
48
|
-
colorAttachments: [currentColorAttachment],
|
|
49
|
-
depthStencilAttachment: this.depthStencilAttachment
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
update() {
|
|
54
|
-
const [width, height] = this.getPixelSize();
|
|
55
|
-
const sizeChanged = width !== this.width || height !== this.height;
|
|
56
|
-
|
|
57
|
-
if (sizeChanged) {
|
|
58
|
-
this.width = width;
|
|
59
|
-
this.height = height;
|
|
60
|
-
|
|
61
|
-
if (this.depthStencilAttachment) {
|
|
62
|
-
this.depthStencilAttachment.destroy();
|
|
8
|
+
constructor(device, adapter, props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.depthStencilFormat = 'depth24plus';
|
|
11
|
+
this.sampleCount = 1;
|
|
63
12
|
this.depthStencilAttachment = null;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
log.log(1, "Resized to ".concat(this.width, "x").concat(this.height, "px"))();
|
|
13
|
+
this.device = device;
|
|
14
|
+
// TODO - hack to trigger resize?
|
|
15
|
+
this.width = -1;
|
|
16
|
+
this.height = -1;
|
|
17
|
+
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
18
|
+
this.gpuCanvasContext = this.canvas.getContext('webgpu');
|
|
19
|
+
// @ts-expect-error TODO this has been replaced
|
|
20
|
+
this.format = this.gpuCanvasContext.getPreferredFormat(adapter);
|
|
74
21
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
22
|
+
destroy() {
|
|
23
|
+
this.gpuCanvasContext.unconfigure();
|
|
24
|
+
}
|
|
25
|
+
/** Update framebuffer with properly resized "swap chain" texture views */
|
|
26
|
+
getCurrentFramebuffer() {
|
|
27
|
+
// Ensure the canvas context size is updated
|
|
28
|
+
this.update();
|
|
29
|
+
// Wrap the current canvas context texture in a luma.gl texture
|
|
30
|
+
const currentColorAttachment = this.device.createTexture({
|
|
31
|
+
id: 'default-render-target',
|
|
32
|
+
handle: this.gpuCanvasContext.getCurrentTexture(),
|
|
33
|
+
format: this.format,
|
|
34
|
+
width: this.width,
|
|
35
|
+
height: this.height
|
|
36
|
+
});
|
|
37
|
+
// Resize the depth stencil attachment
|
|
38
|
+
this._createDepthStencilAttachment();
|
|
39
|
+
return new WEBGPUFramebuffer(this.device, {
|
|
40
|
+
colorAttachments: [currentColorAttachment],
|
|
41
|
+
depthStencilAttachment: this.depthStencilAttachment
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Resizes and updates render targets if necessary */
|
|
45
|
+
update() {
|
|
46
|
+
const [width, height] = this.getPixelSize();
|
|
47
|
+
const sizeChanged = width !== this.width || height !== this.height;
|
|
48
|
+
if (sizeChanged) {
|
|
49
|
+
this.width = width;
|
|
50
|
+
this.height = height;
|
|
51
|
+
if (this.depthStencilAttachment) {
|
|
52
|
+
this.depthStencilAttachment.destroy();
|
|
53
|
+
this.depthStencilAttachment = null;
|
|
54
|
+
}
|
|
55
|
+
// Reconfigure the canvas size.
|
|
56
|
+
// https://www.w3.org/TR/webgpu/#canvas-configuration
|
|
57
|
+
this.gpuCanvasContext.configure({
|
|
58
|
+
device: this.device.handle,
|
|
59
|
+
format: getWebGPUTextureFormat(this.format),
|
|
60
|
+
// size: [this.width, this.height],
|
|
61
|
+
colorSpace: this.props.colorSpace,
|
|
62
|
+
alphaMode: this.props.alphaMode
|
|
63
|
+
});
|
|
64
|
+
log.log(1, `Resized to ${this.width}x${this.height}px`)();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
resize(options) {
|
|
68
|
+
this.update();
|
|
69
|
+
}
|
|
70
|
+
/** We build render targets on demand (i.e. not when size changes but when about to render) */
|
|
71
|
+
_createDepthStencilAttachment() {
|
|
72
|
+
if (!this.depthStencilAttachment) {
|
|
73
|
+
this.depthStencilAttachment = this.device.createTexture({
|
|
74
|
+
id: 'depth-stencil-target',
|
|
75
|
+
format: this.depthStencilFormat,
|
|
76
|
+
width: this.width,
|
|
77
|
+
height: this.height,
|
|
78
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return this.depthStencilAttachment;
|
|
90
82
|
}
|
|
91
|
-
|
|
92
|
-
return this.depthStencilAttachment;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
83
|
}
|
|
96
|
-
//# sourceMappingURL=webgpu-canvas-context.js.map
|