@luma.gl/webgpu 9.0.0-alpha.9 → 9.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -1
- package/dist/adapter/helpers/accessor-to-format.js +102 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts +2 -2
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +8 -6
- package/dist/adapter/helpers/get-bind-group.d.ts +4 -4
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +61 -52
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +5 -5
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +123 -90
- package/dist/adapter/helpers/webgpu-parameters.d.ts +2 -2
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +184 -130
- package/dist/adapter/resources/webgpu-buffer.d.ts +14 -5
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +117 -70
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +13 -14
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +83 -65
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +19 -13
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +78 -57
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +16 -6
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +48 -26
- package/dist/adapter/resources/webgpu-external-texture.d.ts +5 -5
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +38 -29
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +4 -21
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +15 -109
- package/dist/adapter/resources/webgpu-query-set.d.ts +17 -0
- package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-query-set.js +27 -0
- package/dist/adapter/resources/webgpu-render-pass.d.ts +14 -7
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +136 -91
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +63 -23
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +151 -148
- package/dist/adapter/resources/webgpu-sampler.d.ts +5 -5
- package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-sampler.js +23 -23
- package/dist/adapter/resources/webgpu-shader.d.ts +9 -12
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +47 -60
- package/dist/adapter/resources/webgpu-texture-view.d.ts +20 -0
- package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-texture-view.js +35 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +20 -10
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +133 -105
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +27 -0
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-vertex-array.js +66 -0
- package/dist/adapter/webgpu-canvas-context.d.ts +17 -12
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +105 -92
- package/dist/adapter/webgpu-device.d.ts +45 -30
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +266 -241
- package/dist/dist.dev.js +1664 -0
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +1432 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -8
- package/dist.min.js +9 -0
- package/package.json +22 -11
- package/src/adapter/helpers/accessor-to-format.ts +6 -3
- package/src/adapter/helpers/convert-texture-format.ts +5 -2
- package/src/adapter/helpers/get-bind-group.ts +30 -14
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +73 -39
- package/src/adapter/helpers/webgpu-parameters.ts +99 -29
- package/src/adapter/resources/webgpu-buffer.ts +85 -17
- package/src/adapter/resources/webgpu-command-encoder.ts +93 -58
- package/src/adapter/resources/webgpu-compute-pass.ts +56 -32
- package/src/adapter/resources/webgpu-compute-pipeline.ts +51 -18
- package/src/adapter/resources/webgpu-external-texture.ts +19 -11
- package/src/adapter/resources/webgpu-framebuffer.ts +11 -108
- package/src/adapter/resources/webgpu-query-set.ts +37 -0
- package/src/adapter/resources/webgpu-render-pass.ts +95 -19
- package/src/adapter/resources/webgpu-render-pipeline.ts +139 -159
- package/src/adapter/resources/webgpu-sampler.ts +10 -7
- package/src/adapter/resources/webgpu-shader.ts +30 -35
- package/src/adapter/resources/webgpu-texture-view.ts +46 -0
- package/src/adapter/resources/webgpu-texture.ts +75 -41
- package/src/adapter/resources/webgpu-vertex-array.ts +91 -0
- package/src/adapter/webgpu-canvas-context.ts +60 -29
- package/src/adapter/webgpu-device.ts +219 -120
- package/src/index.ts +8 -9
- 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.d.ts +0 -10
- package/dist/adapter/helpers/generate-mipmaps.d.ts.map +0 -1
- package/dist/adapter/helpers/generate-mipmaps.js +0 -95
- 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.d.ts +0 -1
- package/dist/adapter/resources/webgpu-query.d.ts.map +0 -1
- package/dist/adapter/resources/webgpu-query.js +0 -2
- 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.d.ts +0 -1
- package/dist/adapter/webgpu-types.d.ts.map +0 -1
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/adapter/webgpu-types.js.map +0 -1
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/glsl/glsllang.d.ts +0 -3
- package/dist/glsl/glsllang.d.ts.map +0 -1
- package/dist/glsl/glsllang.js +0 -10
- package/dist/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init.d.ts +0 -2
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -4
- package/dist/init.js.map +0 -1
- package/src/adapter/helpers/generate-mipmaps.ts +0 -107
- package/src/adapter/resources/webgpu-query.ts +0 -43
- package/src/adapter/webgpu-types.ts +0 -0
- package/src/bundle.ts +0 -4
- package/src/glsl/glsllang.ts +0 -14
- package/src/init.ts +0 -4
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
/// <reference types="
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
export
|
|
1
|
+
/// <reference types="dist" />
|
|
2
|
+
import { Texture, TextureProps, TextureViewProps, Sampler, SamplerProps } from '@luma.gl/core';
|
|
3
|
+
import type { WebGPUDevice } from "../webgpu-device.js";
|
|
4
|
+
import { WebGPUSampler } from "./webgpu-sampler.js";
|
|
5
|
+
import { WebGPUTextureView } from "./webgpu-texture-view.js";
|
|
6
|
+
export declare class WebGPUTexture extends Texture {
|
|
7
7
|
readonly device: WebGPUDevice;
|
|
8
8
|
readonly handle: GPUTexture;
|
|
9
|
-
|
|
9
|
+
height: number;
|
|
10
|
+
width: number;
|
|
10
11
|
sampler: WebGPUSampler;
|
|
12
|
+
view: WebGPUTextureView;
|
|
11
13
|
constructor(device: WebGPUDevice, props: TextureProps);
|
|
12
|
-
protected createHandle(): GPUTexture;
|
|
13
14
|
destroy(): void;
|
|
15
|
+
createView(props: TextureViewProps): WebGPUTextureView;
|
|
16
|
+
protected initialize(props: TextureProps): void;
|
|
17
|
+
protected createHandle(): GPUTexture;
|
|
14
18
|
/**
|
|
15
19
|
* Set default sampler
|
|
16
20
|
* Accept a sampler instance or set of props;
|
|
@@ -18,7 +22,10 @@ export default class WebGPUTexture extends Texture {
|
|
|
18
22
|
setSampler(sampler: Sampler | SamplerProps): this;
|
|
19
23
|
setData(options: {
|
|
20
24
|
data: any;
|
|
21
|
-
}):
|
|
25
|
+
}): {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
22
29
|
/** Set image */
|
|
23
30
|
setImage(options: {
|
|
24
31
|
source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;
|
|
@@ -34,6 +41,9 @@ export default class WebGPUTexture extends Texture {
|
|
|
34
41
|
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
35
42
|
colorSpace?: 'srgb';
|
|
36
43
|
premultipliedAlpha?: boolean;
|
|
37
|
-
}):
|
|
44
|
+
}): {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|
|
38
48
|
}
|
|
39
49
|
//# sourceMappingURL=webgpu-texture.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgpu-texture.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webgpu-texture.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":[],"mappings":";AAIA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAE7F,OAAO,KAAK,EAAC,YAAY,EAAC,4BAAyB;AACnD,OAAO,EAAC,aAAa,EAAC,4BAAyB;AAC/C,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AAWxD,qBAAa,aAAc,SAAQ,OAAO;IACxC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAEnB,MAAM,EAAE,MAAM,CAAK;IACnB,KAAK,EAAE,MAAM,CAAK;IAE3B,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,iBAAiB,CAAC;gBASZ,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY;IAiB5C,OAAO,IAAI,IAAI;IAMxB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB;IAItD,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAwC/C,SAAS,CAAC,YAAY,IAAI,UAAU;IAsBpC;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI;IAMjD,OAAO,CAAC,OAAO,EAAE;QAAC,IAAI,EAAE,GAAG,CAAA;KAAC;;;;IAI5B,gBAAgB;IAChB,QAAQ,CAAC,OAAO,EAAE;QAChB,MAAM,EAAE,WAAW,GAAG,iBAAiB,GAAG,eAAe,CAAC;QAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,MAAM,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,YAAY,CAAC;QAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,GAAG;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC;CA2HpC"}
|
|
@@ -1,111 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Texture } from '@luma.gl/core';
|
|
5
|
+
import { getWebGPUTextureFormat } from "../helpers/convert-texture-format.js";
|
|
6
|
+
import { WebGPUSampler } from "./webgpu-sampler.js";
|
|
7
|
+
import { WebGPUTextureView } from "./webgpu-texture-view.js";
|
|
5
8
|
const BASE_DIMENSIONS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
'1d': '1d',
|
|
10
|
+
'2d': '2d',
|
|
11
|
+
'2d-array': '2d',
|
|
12
|
+
cube: '2d',
|
|
13
|
+
'cube-array': '2d',
|
|
14
|
+
'3d': '3d'
|
|
12
15
|
};
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
export class WebGPUTexture extends Texture {
|
|
17
|
+
device;
|
|
18
|
+
handle;
|
|
19
|
+
height = 1;
|
|
20
|
+
width = 1;
|
|
21
|
+
sampler;
|
|
22
|
+
view;
|
|
23
|
+
// static async createFromImageURL(src, usage = 0) {
|
|
24
|
+
// const img = document.createElement('img');
|
|
25
|
+
// img.src = src;
|
|
26
|
+
// await img.decode();
|
|
27
|
+
// return WebGPUTexture(img, usage);
|
|
28
|
+
// }
|
|
29
|
+
constructor(device, props) {
|
|
30
|
+
super(device, props);
|
|
31
|
+
this.device = device;
|
|
32
|
+
if (props.data instanceof Promise) {
|
|
33
|
+
props.data.then(resolvedImageData => {
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
this.props = { ...props, data: resolvedImageData };
|
|
36
|
+
this.initialize(this.props);
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.initialize(props);
|
|
27
41
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (this.props.data) {
|
|
33
|
-
this.setData({
|
|
34
|
-
data: this.props.data
|
|
35
|
-
});
|
|
42
|
+
destroy() {
|
|
43
|
+
this.handle?.destroy();
|
|
44
|
+
// @ts-expect-error readonly
|
|
45
|
+
this.handle = null;
|
|
36
46
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
createView(props) {
|
|
48
|
+
return new WebGPUTextureView(this.device, { ...props, texture: this });
|
|
49
|
+
}
|
|
50
|
+
initialize(props) {
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
this.handle = this.props.handle || this.createHandle();
|
|
53
|
+
this.handle.label ||= this.id;
|
|
54
|
+
if (this.props.data) {
|
|
55
|
+
this.setData({ data: this.props.data });
|
|
56
|
+
}
|
|
57
|
+
this.width = this.handle.width;
|
|
58
|
+
this.height = this.handle.height;
|
|
59
|
+
// Why not just read all properties directly from the texture
|
|
60
|
+
// this.depthOrArrayLayers = this.handle.depthOrArrayLayers;
|
|
61
|
+
// this.mipLevelCount = this.handle.mipLevelCount;
|
|
62
|
+
// this.sampleCount = this.handle.sampleCount;
|
|
63
|
+
// this.dimension = this.handle.dimension;
|
|
64
|
+
// this.format = this.handle.format;
|
|
65
|
+
// this.usage = this.handle.usage;
|
|
66
|
+
// Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture
|
|
67
|
+
// this.setSampler(props.sampler);
|
|
68
|
+
this.sampler =
|
|
69
|
+
props.sampler instanceof WebGPUSampler
|
|
70
|
+
? props.sampler
|
|
71
|
+
: new WebGPUSampler(this.device, props.sampler);
|
|
72
|
+
// TODO - To support texture arrays we need to create custom views...
|
|
73
|
+
// But we are not ready to expose TextureViews to the public API.
|
|
74
|
+
// @ts-expect-error
|
|
75
|
+
this.view = new WebGPUTextureView(this.device, { ...this.props, texture: this });
|
|
76
|
+
// format: this.props.format,
|
|
77
|
+
// dimension: this.props.dimension,
|
|
78
|
+
// aspect = "all";
|
|
79
|
+
// baseMipLevel: 0;
|
|
80
|
+
// mipLevelCount;
|
|
81
|
+
// baseArrayLayer = 0;
|
|
82
|
+
// arrayLayerCount;
|
|
83
|
+
}
|
|
84
|
+
createHandle() {
|
|
85
|
+
// Deduce size from data - TODO this is a hack
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
const width = this.props.width || this.props.data?.width || 1;
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
const height = this.props.height || this.props.data?.height || 1;
|
|
90
|
+
return this.device.handle.createTexture({
|
|
91
|
+
label: this.id,
|
|
92
|
+
size: {
|
|
93
|
+
width,
|
|
94
|
+
height,
|
|
95
|
+
depthOrArrayLayers: this.props.depth
|
|
96
|
+
},
|
|
97
|
+
dimension: BASE_DIMENSIONS[this.props.dimension],
|
|
98
|
+
format: getWebGPUTextureFormat(this.props.format),
|
|
99
|
+
usage: this.props.usage,
|
|
100
|
+
mipLevelCount: this.props.mipLevels,
|
|
101
|
+
sampleCount: this.props.samples
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Set default sampler
|
|
106
|
+
* Accept a sampler instance or set of props;
|
|
107
|
+
*/
|
|
108
|
+
setSampler(sampler) {
|
|
109
|
+
this.sampler =
|
|
110
|
+
sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
setData(options) {
|
|
114
|
+
return this.setImage({ source: options.data });
|
|
115
|
+
}
|
|
116
|
+
/** Set image */
|
|
117
|
+
setImage(options) {
|
|
118
|
+
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;
|
|
119
|
+
// TODO - max out width
|
|
120
|
+
this.device.handle.queue.copyExternalImageToTexture(
|
|
121
|
+
// source: GPUImageCopyExternalImage
|
|
122
|
+
{
|
|
123
|
+
source,
|
|
124
|
+
origin: [sourceX, sourceY]
|
|
125
|
+
},
|
|
126
|
+
// destination: GPUImageCopyTextureTagged
|
|
127
|
+
{
|
|
128
|
+
texture: this.handle,
|
|
129
|
+
origin: [x, y, z],
|
|
130
|
+
mipLevel,
|
|
131
|
+
aspect,
|
|
132
|
+
colorSpace,
|
|
133
|
+
premultipliedAlpha
|
|
134
|
+
},
|
|
135
|
+
// copySize: GPUExtent3D
|
|
136
|
+
[width, height, depth]);
|
|
137
|
+
return { width, height };
|
|
47
138
|
}
|
|
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
139
|
}
|
|
111
|
-
//# sourceMappingURL=webgpu-texture.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Device, Buffer, VertexArrayProps, RenderPass } from '@luma.gl/core';
|
|
2
|
+
import { VertexArray } from '@luma.gl/core';
|
|
3
|
+
import { WebGPUDevice } from "../webgpu-device.js";
|
|
4
|
+
/** VertexArrayObject wrapper */
|
|
5
|
+
export declare class WebGPUVertexArray extends VertexArray {
|
|
6
|
+
get [Symbol.toStringTag](): string;
|
|
7
|
+
readonly device: WebGPUDevice;
|
|
8
|
+
/** Vertex Array is a helper class under WebGPU */
|
|
9
|
+
readonly handle: never;
|
|
10
|
+
constructor(device: WebGPUDevice, props?: VertexArrayProps);
|
|
11
|
+
destroy(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Set an elements buffer, for indexed rendering.
|
|
14
|
+
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
15
|
+
*/
|
|
16
|
+
setIndexBuffer(buffer: Buffer | null): void;
|
|
17
|
+
/** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
|
|
18
|
+
setBuffer(bufferSlot: number, buffer: Buffer): void;
|
|
19
|
+
bindBeforeRender(renderPass: RenderPass, firstIndex?: number, indexCount?: number): void;
|
|
20
|
+
unbindAfterRender(renderPass: RenderPass): void;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated is this even an issue for WebGPU?
|
|
23
|
+
* Attribute 0 can not be disable on most desktop OpenGL based browsers
|
|
24
|
+
*/
|
|
25
|
+
static isConstantAttributeZeroSupported(device: Device): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=webgpu-vertex-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgpu-vertex-array.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgpu-vertex-array.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAChF,OAAO,EAAC,WAAW,EAAM,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAC,YAAY,EAAC,4BAAyB;AAK9C,gCAAgC;AAChC,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;gBAGX,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,gBAAgB;IAKjD,OAAO,IAAI,IAAI;IAExB;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAK3C,oGAAoG;IACpG,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAS1C,gBAAgB,CACvB,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI;IAqBE,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAQxD;;;OAGG;IACH,MAAM,CAAC,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAGjE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { VertexArray, log } from '@luma.gl/core';
|
|
5
|
+
import { getBrowser } from '@probe.gl/env';
|
|
6
|
+
/** VertexArrayObject wrapper */
|
|
7
|
+
export class WebGPUVertexArray extends VertexArray {
|
|
8
|
+
get [Symbol.toStringTag]() {
|
|
9
|
+
return 'WebGPUVertexArray';
|
|
10
|
+
}
|
|
11
|
+
device;
|
|
12
|
+
/** Vertex Array is a helper class under WebGPU */
|
|
13
|
+
handle;
|
|
14
|
+
// Create a VertexArray
|
|
15
|
+
constructor(device, props) {
|
|
16
|
+
super(device, props);
|
|
17
|
+
this.device = device;
|
|
18
|
+
}
|
|
19
|
+
destroy() { }
|
|
20
|
+
/**
|
|
21
|
+
* Set an elements buffer, for indexed rendering.
|
|
22
|
+
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
23
|
+
*/
|
|
24
|
+
setIndexBuffer(buffer) {
|
|
25
|
+
// assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
|
|
26
|
+
this.indexBuffer = buffer;
|
|
27
|
+
}
|
|
28
|
+
/** Set a bufferSlot in vertex attributes array to a buffer, enables the bufferSlot, sets divisor */
|
|
29
|
+
setBuffer(bufferSlot, buffer) {
|
|
30
|
+
// Sanity check target
|
|
31
|
+
// if (buffer.glUsage === GL.ELEMENT_ARRAY_BUFFER) {
|
|
32
|
+
// throw new Error('Use setIndexBuffer');
|
|
33
|
+
// }
|
|
34
|
+
this.attributes[bufferSlot] = buffer;
|
|
35
|
+
}
|
|
36
|
+
bindBeforeRender(renderPass, firstIndex, indexCount) {
|
|
37
|
+
const webgpuRenderPass = renderPass;
|
|
38
|
+
const webgpuIndexBuffer = this.indexBuffer;
|
|
39
|
+
if (webgpuIndexBuffer?.handle) {
|
|
40
|
+
// Note we can't unset an index buffer
|
|
41
|
+
log.warn('setting index buffer', webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType)();
|
|
42
|
+
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType);
|
|
43
|
+
}
|
|
44
|
+
for (let location = 0; location < this.maxVertexAttributes; location++) {
|
|
45
|
+
const webgpuBuffer = this.attributes[location];
|
|
46
|
+
if (webgpuBuffer?.handle) {
|
|
47
|
+
log.warn(`setting vertex buffer ${location}`, webgpuBuffer?.handle)();
|
|
48
|
+
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer?.handle);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// TODO - emit warnings/errors/throw if constants have been set on this vertex array
|
|
52
|
+
}
|
|
53
|
+
unbindAfterRender(renderPass) {
|
|
54
|
+
// On WebGPU we don't need to unbind.
|
|
55
|
+
// In fact we can't easily do it. setIndexBuffer/setVertexBuffer don't accept null.
|
|
56
|
+
// Unbinding presumably happens automatically when the render pass is ended.
|
|
57
|
+
}
|
|
58
|
+
// DEPRECATED METHODS
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated is this even an issue for WebGPU?
|
|
61
|
+
* Attribute 0 can not be disable on most desktop OpenGL based browsers
|
|
62
|
+
*/
|
|
63
|
+
static isConstantAttributeZeroSupported(device) {
|
|
64
|
+
return getBrowser() === 'Chrome';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
/// <reference types="
|
|
2
|
-
import type { Texture, TextureFormat, CanvasContextProps } from '@luma.gl/
|
|
3
|
-
import { CanvasContext } from '@luma.gl/
|
|
4
|
-
import WebGPUDevice from
|
|
5
|
-
import
|
|
1
|
+
/// <reference types="dist" />
|
|
2
|
+
import type { Texture, TextureFormat, CanvasContextProps } from '@luma.gl/core';
|
|
3
|
+
import { CanvasContext } from '@luma.gl/core';
|
|
4
|
+
import { WebGPUDevice } from "./webgpu-device.js";
|
|
5
|
+
import { WebGPUFramebuffer } from "./resources/webgpu-framebuffer.js";
|
|
6
|
+
import { WebGPUTexture } from "./resources/webgpu-texture.js";
|
|
6
7
|
/**
|
|
7
|
-
* Holds a WebGPU Canvas Context
|
|
8
|
+
* Holds a WebGPU Canvas Context
|
|
9
|
+
* The primary job of the CanvasContext is to generate textures for rendering into the current canvas
|
|
10
|
+
* It also manages canvas sizing calculations and resizing.
|
|
8
11
|
*/
|
|
9
|
-
export
|
|
12
|
+
export declare class WebGPUCanvasContext extends CanvasContext {
|
|
10
13
|
readonly device: WebGPUDevice;
|
|
11
14
|
readonly gpuCanvasContext: GPUCanvasContext;
|
|
15
|
+
/** Format of returned textures: "bgra8unorm", "rgba8unorm", "rgba16float". */
|
|
12
16
|
readonly format: TextureFormat;
|
|
13
|
-
|
|
14
|
-
height: number;
|
|
17
|
+
/** Default stencil format for depth textures */
|
|
15
18
|
depthStencilFormat: TextureFormat;
|
|
16
|
-
sampleCount: number;
|
|
17
19
|
private depthStencilAttachment;
|
|
18
20
|
constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps);
|
|
21
|
+
/** Destroy any textures produced while configured and remove the context configuration. */
|
|
19
22
|
destroy(): void;
|
|
20
23
|
/** Update framebuffer with properly resized "swap chain" texture views */
|
|
21
|
-
getCurrentFramebuffer():
|
|
24
|
+
getCurrentFramebuffer(): WebGPUFramebuffer;
|
|
22
25
|
/** Resizes and updates render targets if necessary */
|
|
23
26
|
update(): void;
|
|
24
27
|
resize(options?: {
|
|
@@ -26,7 +29,9 @@ export default class WebGPUCanvasContext extends CanvasContext {
|
|
|
26
29
|
height?: number;
|
|
27
30
|
useDevicePixels?: boolean | number;
|
|
28
31
|
}): void;
|
|
32
|
+
/** Wrap the current canvas context texture in a luma.gl texture */
|
|
33
|
+
getCurrentTexture(): WebGPUTexture;
|
|
29
34
|
/** We build render targets on demand (i.e. not when size changes but when about to render) */
|
|
30
|
-
_createDepthStencilAttachment(): Texture
|
|
35
|
+
_createDepthStencilAttachment(): Texture<import("@luma.gl/core").TextureProps>;
|
|
31
36
|
}
|
|
32
37
|
//# sourceMappingURL=webgpu-canvas-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"webgpu-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-canvas-context.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,EAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAC,aAAa,EAAM,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,iBAAiB,EAAC,0CAAuC;AACjE,OAAO,EAAC,aAAa,EAAC,sCAAmC;AAEzD;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IACpD,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAC5C,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,aAAa,CAA6D;IAC3F,gDAAgD;IAChD,kBAAkB,EAAE,aAAa,CAAiB;IAElD,OAAO,CAAC,sBAAsB,CAAwB;gBAE1C,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB;IAehF,2FAA2F;IAC3F,OAAO,IAAI,IAAI;IAIf,0EAA0E;IAC1E,qBAAqB,IAAI,iBAAiB;IA2B1C,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,mEAAmE;IACnE,iBAAiB,IAAI,aAAa;IAQlC,8FAA8F;IAC9F,6BAA6B;CAY9B"}
|