@luma.gl/webgpu 9.0.0-alpha.9 → 9.0.0-beta.1
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.map +1 -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 +0 -1
- package/dist/adapter/helpers/convert-texture-format.js.map +1 -1
- package/dist/adapter/helpers/generate-mipmaps.d.ts +1 -1
- package/dist/adapter/helpers/generate-mipmaps.js +20 -15
- package/dist/adapter/helpers/generate-mipmaps.js.map +1 -1
- 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 +11 -18
- package/dist/adapter/helpers/get-bind-group.js.map +1 -1
- 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 +36 -40
- package/dist/adapter/helpers/get-vertex-buffer-layout.js.map +1 -1
- 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 +14 -20
- package/dist/adapter/helpers/webgpu-parameters.js.map +1 -1
- 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 +19 -29
- package/dist/adapter/resources/webgpu-buffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -14
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +13 -27
- package/dist/adapter/resources/webgpu-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.d.ts +5 -5
- package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pass.js +13 -27
- package/dist/adapter/resources/webgpu-compute-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +4 -4
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +8 -13
- package/dist/adapter/resources/webgpu-compute-pipeline.js.map +1 -1
- 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 +6 -14
- package/dist/adapter/resources/webgpu-external-texture.js.map +1 -1
- 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 +4 -105
- package/dist/adapter/resources/webgpu-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgpu-query.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +12 -7
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +53 -36
- package/dist/adapter/resources/webgpu-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +15 -22
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +45 -115
- package/dist/adapter/resources/webgpu-render-pipeline.js.map +1 -1
- 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 +8 -14
- package/dist/adapter/resources/webgpu-sampler.js.map +1 -1
- package/dist/adapter/resources/webgpu-shader.d.ts +9 -9
- package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-shader.js +15 -29
- package/dist/adapter/resources/webgpu-shader.js.map +1 -1
- package/dist/adapter/resources/webgpu-texture.d.ts +18 -8
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +38 -33
- package/dist/adapter/resources/webgpu-texture.js.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +26 -0
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -0
- package/dist/adapter/resources/webgpu-vertex-array.js +45 -0
- package/dist/adapter/resources/webgpu-vertex-array.js.map +1 -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 +26 -47
- package/dist/adapter/webgpu-canvas-context.js.map +1 -1
- package/dist/adapter/webgpu-device.d.ts +34 -17
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +94 -103
- package/dist/adapter/webgpu-device.js.map +1 -1
- package/dist/adapter/webgpu-types.js.map +1 -1
- package/dist/dist.dev.js +3130 -0
- package/dist/glsl/glsllang.js +0 -1
- package/dist/glsl/glsllang.js.map +1 -1
- package/dist/index.cjs +1551 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist.min.js +30 -0
- package/package.json +18 -9
- package/src/adapter/helpers/accessor-to-format.ts +1 -2
- package/src/adapter/helpers/convert-texture-format.ts +1 -1
- package/src/adapter/helpers/generate-mipmaps.ts +2 -2
- package/src/adapter/helpers/get-bind-group.ts +23 -13
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +61 -35
- package/src/adapter/helpers/webgpu-parameters.ts +20 -14
- package/src/adapter/resources/webgpu-buffer.ts +63 -8
- package/src/adapter/resources/webgpu-command-encoder.ts +68 -48
- package/src/adapter/resources/webgpu-compute-pass.ts +13 -12
- package/src/adapter/resources/webgpu-compute-pipeline.ts +8 -7
- package/src/adapter/resources/webgpu-external-texture.ts +5 -5
- package/src/adapter/resources/webgpu-framebuffer.ts +8 -109
- package/src/adapter/resources/webgpu-query.ts +3 -3
- package/src/adapter/resources/webgpu-render-pass.ts +68 -15
- package/src/adapter/resources/webgpu-render-pipeline.ts +106 -87
- package/src/adapter/resources/webgpu-sampler.ts +6 -6
- package/src/adapter/resources/webgpu-shader.ts +22 -16
- package/src/adapter/resources/webgpu-texture.ts +54 -25
- package/src/adapter/resources/webgpu-vertex-array.ts +83 -0
- package/src/adapter/webgpu-canvas-context.ts +51 -26
- package/src/adapter/webgpu-device.ts +144 -48
- package/src/index.ts +7 -9
- 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/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/bundle.ts +0 -4
- package/src/init.ts +0 -4
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import WebGPUSampler from './webgpu-sampler';
|
|
1
|
+
import { Texture } from '@luma.gl/core';
|
|
2
|
+
import { getWebGPUTextureFormat } from "../helpers/convert-texture-format.js";
|
|
3
|
+
import { WebGPUSampler } from "./webgpu-sampler.js";
|
|
5
4
|
const BASE_DIMENSIONS = {
|
|
6
5
|
'1d': '1d',
|
|
7
6
|
'2d': '2d',
|
|
@@ -10,45 +9,48 @@ const BASE_DIMENSIONS = {
|
|
|
10
9
|
'cube-array': '2d',
|
|
11
10
|
'3d': '3d'
|
|
12
11
|
};
|
|
13
|
-
export
|
|
12
|
+
export class WebGPUTexture extends Texture {
|
|
14
13
|
constructor(device, props) {
|
|
15
14
|
super(device, props);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "sampler", null);
|
|
24
|
-
|
|
25
|
-
if (typeof this.props.format === 'number') {
|
|
26
|
-
throw new Error('number format');
|
|
27
|
-
}
|
|
28
|
-
|
|
15
|
+
this.device = void 0;
|
|
16
|
+
this.handle = void 0;
|
|
17
|
+
this.view = void 0;
|
|
18
|
+
this.sampler = void 0;
|
|
19
|
+
this.height = 1;
|
|
20
|
+
this.width = 1;
|
|
29
21
|
this.device = device;
|
|
22
|
+
if (props.data instanceof Promise) {
|
|
23
|
+
props.data.then(resolvedImageData => {
|
|
24
|
+
this.props = {
|
|
25
|
+
...props,
|
|
26
|
+
data: resolvedImageData
|
|
27
|
+
};
|
|
28
|
+
this.initialize(this.props);
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.initialize(props);
|
|
33
|
+
}
|
|
34
|
+
initialize(props) {
|
|
35
|
+
var _this$handle;
|
|
30
36
|
this.handle = this.props.handle || this.createHandle();
|
|
31
|
-
|
|
37
|
+
(_this$handle = this.handle).label || (_this$handle.label = this.id);
|
|
32
38
|
if (this.props.data) {
|
|
33
39
|
this.setData({
|
|
34
40
|
data: this.props.data
|
|
35
41
|
});
|
|
36
42
|
}
|
|
37
|
-
|
|
43
|
+
this.width = this.handle.width;
|
|
44
|
+
this.height = this.handle.height;
|
|
38
45
|
this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
|
|
39
|
-
this.view = this.
|
|
46
|
+
this.view = this.createView();
|
|
40
47
|
}
|
|
41
|
-
|
|
42
48
|
createHandle() {
|
|
43
49
|
var _this$props$data, _this$props$data2;
|
|
44
|
-
|
|
45
|
-
if (typeof this.props.format === 'number') {
|
|
46
|
-
throw new Error('number format');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
50
|
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
51
|
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
52
|
return this.device.handle.createTexture({
|
|
53
|
+
label: this.id,
|
|
52
54
|
size: {
|
|
53
55
|
width,
|
|
54
56
|
height,
|
|
@@ -61,22 +63,18 @@ export default class WebGPUTexture extends Texture {
|
|
|
61
63
|
sampleCount: this.props.samples
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
|
-
|
|
65
66
|
destroy() {
|
|
66
67
|
this.handle.destroy();
|
|
67
68
|
}
|
|
68
|
-
|
|
69
69
|
setSampler(sampler) {
|
|
70
70
|
this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
|
|
71
71
|
return this;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
73
|
setData(options) {
|
|
75
74
|
return this.setImage({
|
|
76
75
|
source: options.data
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
|
-
|
|
80
78
|
setImage(options) {
|
|
81
79
|
const {
|
|
82
80
|
source,
|
|
@@ -104,8 +102,15 @@ export default class WebGPUTexture extends Texture {
|
|
|
104
102
|
colorSpace,
|
|
105
103
|
premultipliedAlpha
|
|
106
104
|
}, [width, height, depth]);
|
|
107
|
-
return
|
|
105
|
+
return {
|
|
106
|
+
width,
|
|
107
|
+
height
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
createView() {
|
|
111
|
+
return this.handle.createView({
|
|
112
|
+
label: this.id
|
|
113
|
+
});
|
|
108
114
|
}
|
|
109
|
-
|
|
110
115
|
}
|
|
111
116
|
//# sourceMappingURL=webgpu-texture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapter/resources/webgpu-texture.ts"],"names":["Texture","getWebGPUTextureFormat","WebGPUSampler","BASE_DIMENSIONS","WebGPUTexture","constructor","device","props","format","Error","handle","createHandle","data","setData","sampler","view","createView","width","height","createTexture","size","depthOrArrayLayers","depth","dimension","usage","mipLevelCount","mipLevels","sampleCount","samples","destroy","setSampler","options","setImage","source","sourceX","sourceY","mipLevel","x","y","z","aspect","colorSpace","premultipliedAlpha","queue","copyExternalImageToTexture","origin","texture"],"mappings":";AACA,SAAQA,OAAR,QAAmE,cAAnE;AACA,SAAQC,sBAAR,QAAqC,mCAArC;AAEA,OAAOC,aAAP,MAA0B,kBAA1B;AAEA,MAAMC,eAAmD,GAAG;AAC1D,QAAM,IADoD;AAE1D,QAAM,IAFoD;AAG1D,cAAY,IAH8C;AAI1D,UAAQ,IAJkD;AAK1D,gBAAc,IAL4C;AAM1D,QAAM;AANoD,CAA5D;AASA,eAAe,MAAMC,aAAN,SAA4BJ,OAA5B,CAAoC;AAajDK,EAAAA,WAAW,CAACC,MAAD,EAAuBC,KAAvB,EAA4C;AACrD,UAAMD,MAAN,EAAcC,KAAd;;AADqD;;AAAA;;AAAA;;AAAA,qCAT9B,IAS8B;;AAGrD,QAAI,OAAO,KAAKA,KAAL,CAAWC,MAAlB,KAA6B,QAAjC,EAA2C;AACzC,YAAM,IAAIC,KAAJ,CAAU,eAAV,CAAN;AACD;;AAED,SAAKH,MAAL,GAAcA,MAAd;AACA,SAAKI,MAAL,GAAc,KAAKH,KAAL,CAAWG,MAAX,IAAqB,KAAKC,YAAL,EAAnC;;AAEA,QAAI,KAAKJ,KAAL,CAAWK,IAAf,EAAqB;AACnB,WAAKC,OAAL,CAAa;AAACD,QAAAA,IAAI,EAAE,KAAKL,KAAL,CAAWK;AAAlB,OAAb;AACD;;AAID,SAAKE,OAAL,GAAeP,KAAK,CAACO,OAAN,YAAyBZ,aAAzB,GAAyCK,KAAK,CAACO,OAA/C,GAAyD,IAAIZ,aAAJ,CAAkB,KAAKI,MAAvB,EAA+BC,KAAK,CAACO,OAArC,CAAxE;AAIA,SAAKC,IAAL,GAAY,KAAKL,MAAL,CAAYM,UAAZ,CAAuB,EAAvB,CAAZ;AASD;;AAESL,EAAAA,YAAY,GAAe;AAAA;;A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L,CAAc;AAACC,MAAAA,MAAM,EAAEF,OAAO,CAACnB;AAAjB,KAAd,CAAP;AACD;;AAGDoB,EAAAA,QAAQ,CAACD,OAAD,EAcC;AACP,UAAM;AACJE,MAAAA,MADI;AAEJhB,MAAAA,KAAK,GAAGc,OAAO,CAACE,MAAR,CAAehB,KAFnB;AAGJC,MAAAA,MAAM,GAAGa,OAAO,CAACE,MAAR,CAAef,MAHpB;AAIJI,MAAAA,KAAK,GAAG,CAJJ;AAKJY,MAAAA,OAAO,GAAG,CALN;AAMJC,MAAAA,OAAO,GAAG,CANN;AAOJC,MAAAA,QAAQ,GAAG,CAPP;AAQJC,MAAAA,CAAC,GAAG,CARA;AASJC,MAAAA,CAAC,GAAG,CATA;AAUJC,MAAAA,CAAC,GAAG,CAVA;AAWJC,MAAAA,MAAM,GAAG,KAXL;AAYJC,MAAAA,UAAU,GAAG,MAZT;AAaJC,MAAAA,kBAAkB,GAAG;AAbjB,QAcFX,OAdJ;AAkBA,SAAKzB,MAAL,CAAYI,MAAZ,CAAmBiC,KAAnB,CAAyBC,0BAAzB,CAEE;AACEX,MAAAA,MADF;AAEEY,MAAAA,MAAM,EAAE,CAACX,OAAD,EAAUC,OAAV;AAFV,KAFF,EAOE;AACEW,MAAAA,OAAO,EAAE,KAAKpC,MADhB;AAEEmC,MAAAA,MAAM,EAAE,CAACR,CAAD,EAAIC,CAAJ,EAAOC,CAAP,CAFV;AAGEH,MAAAA,QAHF;AAIEI,MAAAA,MAJF;AAKEC,MAAAA,UALF;AAMEC,MAAAA;AANF,KAPF,EAgBE,CACEzB,KADF,EAEEC,MAFF,EAGEI,KAHF,CAhBF;AAsBA,WAAO,IAAP;AACD;;AAjJgD","sourcesContent":["// luma.gl, MIT license\nimport {Texture, TextureProps, Sampler, SamplerProps, assert} from '@luma.gl/api';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport type WebGPUDevice from '../webgpu-device';\nimport WebGPUSampler from './webgpu-sampler';\n\nconst BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {\n '1d': '1d',\n '2d': '2d',\n '2d-array': '2d',\n 'cube': '2d',\n 'cube-array': '2d',\n '3d': '3d'\n};\n\nexport default class WebGPUTexture extends Texture {\n readonly device: WebGPUDevice;\n readonly handle: GPUTexture;\n readonly view: GPUTextureView;\n sampler: WebGPUSampler = null;\n\n // static async createFromImageURL(src, usage = 0) {\n // const img = document.createElement('img');\n // img.src = src;\n // await img.decode();\n // return WebGPUTexture(img, usage);\n // }\n\n constructor(device: WebGPUDevice, props: TextureProps) {\n super(device, props);\n\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n this.device = device;\n this.handle = this.props.handle || this.createHandle();\n\n if (this.props.data) {\n this.setData({data: this.props.data} );\n }\n\n // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture\n // this.setSampler(props.sampler);\n this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);\n\n // TODO - To support texture arrays we need to create custom views...\n // But we are not ready to expose TextureViews to the public API.\n this.view = this.handle.createView({\n // format: this.props.format,\n // dimension: this.props.dimension,\n // aspect = \"all\";\n // baseMipLevel: 0;\n // mipLevelCount;\n // baseArrayLayer = 0;\n // arrayLayerCount;\n });\n }\n\n protected createHandle(): GPUTexture {\n if (typeof this.props.format === 'number') {\n throw new Error('number format');\n }\n\n // Deduce size from data - TODO this is a hack\n // @ts-expect-error\n const width = this.props.width || this.props.data?.width || 1;\n // @ts-expect-error\n const height = this.props.height || this.props.data?.height || 1;\n\n return this.device.handle.createTexture({\n size: {\n width,\n height,\n depthOrArrayLayers: this.props.depth\n },\n dimension: BASE_DIMENSIONS[this.props.dimension],\n format: getWebGPUTextureFormat(this.props.format),\n usage: this.props.usage,\n mipLevelCount: this.props.mipLevels,\n sampleCount: this.props.samples\n });\n }\n\n destroy(): void {\n this.handle.destroy();\n }\n\n /**\n * Set default sampler\n * Accept a sampler instance or set of props;\n */\n setSampler(sampler: Sampler | SamplerProps): this {\n this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);\n return this;\n }\n\n setData(options: {\n data: any;\n }) {\n return this.setImage({source: options.data});\n }\n\n /** Set image */\n setImage(options: {\n source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;\n width?: number;\n height?: number;\n depth?: number;\n sourceX?: number;\n sourceY?: number;\n mipLevel?: number;\n x?: number;\n y?: number;\n z?: number;\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n colorSpace?: 'srgb';\n premultipliedAlpha?: boolean;\n }): this {\n const {\n source,\n width = options.source.width,\n height = options.source.height,\n depth = 1,\n sourceX = 0,\n sourceY = 0,\n mipLevel = 0,\n x = 0,\n y = 0,\n z = 0,\n aspect = 'all',\n colorSpace = 'srgb',\n premultipliedAlpha = false\n } = options;\n\n // TODO - max out width\n\n this.device.handle.queue.copyExternalImageToTexture(\n // source: GPUImageCopyExternalImage\n {\n source,\n origin: [sourceX, sourceY]\n },\n // destination: GPUImageCopyTextureTagged\n {\n texture: this.handle,\n origin: [x, y, z],\n mipLevel,\n aspect,\n colorSpace,\n premultipliedAlpha\n },\n // copySize: GPUExtent3D\n [\n width,\n height,\n depth\n ]\n );\n return this;\n }\n\n /*\n async readPixels() {\n const readbackBuffer = device.createBuffer({\n usage: Buffer.COPY_DST | Buffer.MAP_READ,\n size: 4 * textureWidth * textureHeight,\n });\n\n // Copy data from the texture to the buffer.\n const encoder = device.createCommandEncoder();\n encoder.copyTextureToBuffer(\n { texture },\n { buffer, rowPitch: textureWidth * 4 },\n [textureWidth, textureHeight],\n );\n device.submit([encoder.finish()]);\n\n // Get the data on the CPU.\n await buffer.mapAsync(GPUMapMode.READ);\n saveScreenshot(buffer.getMappedRange());\n buffer.unmap();\n }\n\n setImageData(imageData, usage): this {\n let data = null;\n\n const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;\n if (bytesPerRow == img.width * 4) {\n data = imageData.data;\n } else {\n data = new Uint8Array(bytesPerRow * img.height);\n let imagePixelIndex = 0;\n for (let y = 0; y < img.height; ++y) {\n for (let x = 0; x < img.width; ++x) {\n const i = x * 4 + y * bytesPerRow;\n data[i] = imageData.data[imagePixelIndex];\n data[i + 1] = imageData.data[imagePixelIndex + 1];\n data[i + 2] = imageData.data[imagePixelIndex + 2];\n data[i + 3] = imageData.data[imagePixelIndex + 3];\n imagePixelIndex += 4;\n }\n }\n }\n return this;\n }\n\n setData(data): this {\n const textureDataBuffer = this.device.handle.createBuffer({\n size: data.byteLength,\n usage: Buffer.COPY_DST | Buffer.COPY_SRC,\n mappedAtCreation: true\n });\n new Uint8Array(textureDataBuffer.getMappedRange()).set(data);\n textureDataBuffer.unmap();\n\n this.setBuffer(textureDataBuffer);\n\n textureDataBuffer.destroy();\n return this;\n }\n\n setBuffer(textureDataBuffer, {bytesPerRow}): this {\n const commandEncoder = this.device.handle.createCommandEncoder();\n commandEncoder.copyBufferToTexture(\n {\n buffer: textureDataBuffer,\n bytesPerRow\n },\n {\n texture: this.handle\n },\n {\n width,\n height,\n depth\n }\n );\n\n this.device.handle.defaultQueue.submit([commandEncoder.finish()]);\n return this;\n }\n */\n}\n"],"file":"webgpu-texture.js"}
|
|
1
|
+
{"version":3,"file":"webgpu-texture.js","names":["Texture","getWebGPUTextureFormat","WebGPUSampler","BASE_DIMENSIONS","WebGPUTexture","constructor","device","props","handle","view","sampler","height","width","data","Promise","then","resolvedImageData","initialize","_this$handle","createHandle","label","id","setData","createView","_this$props$data","_this$props$data2","createTexture","size","depthOrArrayLayers","depth","dimension","format","usage","mipLevelCount","mipLevels","sampleCount","samples","destroy","setSampler","options","setImage","source","sourceX","sourceY","mipLevel","x","y","z","aspect","colorSpace","premultipliedAlpha","queue","copyExternalImageToTexture","origin","texture"],"sources":["../../../src/adapter/resources/webgpu-texture.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {Texture, TextureProps, Sampler, SamplerProps} from '@luma.gl/core';\nimport {getWebGPUTextureFormat} from '../helpers/convert-texture-format';\nimport type {WebGPUDevice} from '../webgpu-device';\nimport {WebGPUSampler} from './webgpu-sampler';\n\nconst BASE_DIMENSIONS: Record<string, '1d' | '2d' | '3d'> = {\n '1d': '1d',\n '2d': '2d',\n '2d-array': '2d',\n 'cube': '2d',\n 'cube-array': '2d',\n '3d': '3d'\n};\n\nexport class WebGPUTexture extends Texture {\n readonly device: WebGPUDevice;\n readonly handle: GPUTexture;\n readonly view: GPUTextureView;\n sampler: WebGPUSampler;\n\n override height: number = 1;\n override width: number = 1;\n\n // static async createFromImageURL(src, usage = 0) {\n // const img = document.createElement('img');\n // img.src = src;\n // await img.decode();\n // return WebGPUTexture(img, usage);\n // }\n\n constructor(device: WebGPUDevice, props: TextureProps) {\n super(device, props);\n\n this.device = device;\n\n if (props.data instanceof Promise) {\n props.data.then(resolvedImageData => {\n // @ts-expect-error\n this.props = {...props, data: resolvedImageData};\n this.initialize(this.props);\n });\n return;\n }\n\n this.initialize(props);\n }\n\n protected initialize(props: TextureProps): void {\n // @ts-expect-error\n this.handle = this.props.handle || this.createHandle();\n this.handle.label ||= this.id;\n\n if (this.props.data) {\n this.setData({data: this.props.data});\n }\n\n this.width = this.handle.width;\n this.height = this.handle.height;\n // Why not just read all properties directly from the texture\n // this.depthOrArrayLayers = this.handle.depthOrArrayLayers;\n // this.mipLevelCount = this.handle.mipLevelCount;\n // this.sampleCount = this.handle.sampleCount;\n // this.dimension = this.handle.dimension;\n // this.format = this.handle.format;\n // this.usage = this.handle.usage;\n\n // Create a default sampler. This mimics the WebGL1 API where sampler props are stored on the texture\n // this.setSampler(props.sampler);\n this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);\n\n // TODO - To support texture arrays we need to create custom views...\n // But we are not ready to expose TextureViews to the public API.\n // @ts-expect-error\n this.view = this.createView();\n // format: this.props.format,\n // dimension: this.props.dimension,\n // aspect = \"all\";\n // baseMipLevel: 0;\n // mipLevelCount;\n // baseArrayLayer = 0;\n // arrayLayerCount;\n }\n\n protected createHandle(): GPUTexture {\n // Deduce size from data - TODO this is a hack\n // @ts-expect-error\n const width = this.props.width || this.props.data?.width || 1;\n // @ts-expect-error\n const height = this.props.height || this.props.data?.height || 1;\n\n return this.device.handle.createTexture({\n label: this.id,\n size: {\n width,\n height,\n depthOrArrayLayers: this.props.depth\n },\n dimension: BASE_DIMENSIONS[this.props.dimension],\n format: getWebGPUTextureFormat(this.props.format),\n usage: this.props.usage,\n mipLevelCount: this.props.mipLevels,\n sampleCount: this.props.samples\n });\n }\n\n override destroy(): void {\n this.handle.destroy();\n }\n\n /**\n * Set default sampler\n * Accept a sampler instance or set of props;\n */\n setSampler(sampler: Sampler | SamplerProps): this {\n this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);\n return this;\n }\n\n setData(options: {\n data: any;\n }) {\n return this.setImage({source: options.data});\n }\n\n /** Set image */\n setImage(options: {\n source: ImageBitmap | HTMLCanvasElement | OffscreenCanvas;\n width?: number;\n height?: number;\n depth?: number;\n sourceX?: number;\n sourceY?: number;\n mipLevel?: number;\n x?: number;\n y?: number;\n z?: number;\n aspect?: 'all' | 'stencil-only' | 'depth-only';\n colorSpace?: 'srgb';\n premultipliedAlpha?: boolean;\n }): {width: number, height: number} {\n const {\n source,\n width = options.source.width,\n height = options.source.height,\n depth = 1,\n sourceX = 0,\n sourceY = 0,\n mipLevel = 0,\n x = 0,\n y = 0,\n z = 0,\n aspect = 'all',\n colorSpace = 'srgb',\n premultipliedAlpha = false\n } = options;\n\n // TODO - max out width\n\n this.device.handle.queue.copyExternalImageToTexture(\n // source: GPUImageCopyExternalImage\n {\n source,\n origin: [sourceX, sourceY]\n },\n // destination: GPUImageCopyTextureTagged\n {\n texture: this.handle,\n origin: [x, y, z],\n mipLevel,\n aspect,\n colorSpace,\n premultipliedAlpha\n },\n // copySize: GPUExtent3D\n [\n width,\n height,\n depth\n ]\n );\n return {width, height};\n }\n\n // WebGPU specific \n \n /** TODO - intention is to expose TextureViews in the public API */\n createView(): GPUTextureView {\n return this.handle.createView({label: this.id});\n }\n \n /*\n async readPixels() {\n const readbackBuffer = device.createBuffer({\n usage: Buffer.COPY_DST | Buffer.MAP_READ,\n size: 4 * textureWidth * textureHeight,\n });\n\n // Copy data from the texture to the buffer.\n const encoder = device.createCommandEncoder();\n encoder.copyTextureToBuffer(\n { texture },\n { buffer, rowPitch: textureWidth * 4 },\n [textureWidth, textureHeight],\n );\n device.submit([encoder.finish()]);\n\n // Get the data on the CPU.\n await buffer.mapAsync(GPUMapMode.READ);\n saveScreenshot(buffer.getMappedRange());\n buffer.unmap();\n }\n\n setImageData(imageData, usage): this {\n let data = null;\n\n const bytesPerRow = Math.ceil((img.width * 4) / 256) * 256;\n if (bytesPerRow == img.width * 4) {\n data = imageData.data;\n } else {\n data = new Uint8Array(bytesPerRow * img.height);\n let imagePixelIndex = 0;\n for (let y = 0; y < img.height; ++y) {\n for (let x = 0; x < img.width; ++x) {\n const i = x * 4 + y * bytesPerRow;\n data[i] = imageData.data[imagePixelIndex];\n data[i + 1] = imageData.data[imagePixelIndex + 1];\n data[i + 2] = imageData.data[imagePixelIndex + 2];\n data[i + 3] = imageData.data[imagePixelIndex + 3];\n imagePixelIndex += 4;\n }\n }\n }\n return this;\n }\n\n setData(data): this {\n const textureDataBuffer = this.device.handle.createBuffer({\n size: data.byteLength,\n usage: Buffer.COPY_DST | Buffer.COPY_SRC,\n mappedAtCreation: true\n });\n new Uint8Array(textureDataBuffer.getMappedRange()).set(data);\n textureDataBuffer.unmap();\n\n this.setBuffer(textureDataBuffer);\n\n textureDataBuffer.destroy();\n return this;\n }\n\n setBuffer(textureDataBuffer, {bytesPerRow}): this {\n const commandEncoder = this.device.handle.createCommandEncoder();\n commandEncoder.copyBufferToTexture(\n {\n buffer: textureDataBuffer,\n bytesPerRow\n },\n {\n texture: this.handle\n },\n {\n width,\n height,\n depth\n }\n );\n\n this.device.handle.defaultQueue.submit([commandEncoder.finish()]);\n return this;\n }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C,UAAU;MACVC;IACF,CAAC,EAED,CACEtC,KAAK,EACLD,MAAM,EACNkB,KAAK,CAET,CAAC;IACD,OAAO;MAACjB,KAAK;MAAED;IAAM,CAAC;EACxB;EAKAY,UAAUA,CAAA,EAAmB;IAC3B,OAAO,IAAI,CAACf,MAAM,CAACe,UAAU,CAAC;MAACH,KAAK,EAAE,IAAI,CAACC;IAAE,CAAC,CAAC;EACjD;AAmFF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Device, Buffer, VertexArrayProps, RenderPass, TypedArray } from '@luma.gl/core';
|
|
2
|
+
import { VertexArray } from '@luma.gl/core';
|
|
3
|
+
import { WebGPUDevice } from '../webgpu-device';
|
|
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
|
+
/** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
|
|
11
|
+
static isConstantAttributeZeroSupported(device: Device): boolean;
|
|
12
|
+
constructor(device: WebGPUDevice, props?: VertexArrayProps);
|
|
13
|
+
destroy(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Set an elements buffer, for indexed rendering.
|
|
16
|
+
* Must be a Buffer bound to buffer with usage bit Buffer.INDEX set.
|
|
17
|
+
*/
|
|
18
|
+
setIndexBuffer(buffer: Buffer | null): void;
|
|
19
|
+
/** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
|
|
20
|
+
setBuffer(location: number, buffer: Buffer): void;
|
|
21
|
+
/** Set a location in vertex attributes array to a constant value, disables the location */
|
|
22
|
+
setConstant(location: number, value: TypedArray): void;
|
|
23
|
+
bindBeforeRender(renderPass: RenderPass, firstIndex?: number, indexCount?: number): void;
|
|
24
|
+
unbindAfterRender(renderPass: RenderPass): void;
|
|
25
|
+
}
|
|
26
|
+
//# 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":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAC,WAAW,EAAM,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;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;IAEvB,6EAA6E;IAC7E,MAAM,CAAC,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;gBAKpD,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,gGAAgG;IAChG,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IASjD,2FAA2F;IAClF,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAItD,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAkBxF,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;CAKzD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
let _Symbol$toStringTag;
|
|
2
|
+
import { VertexArray, log } from '@luma.gl/core';
|
|
3
|
+
import { getBrowser } from '@probe.gl/env';
|
|
4
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
5
|
+
export class WebGPUVertexArray extends VertexArray {
|
|
6
|
+
get [_Symbol$toStringTag]() {
|
|
7
|
+
return 'WebGPUVertexArray';
|
|
8
|
+
}
|
|
9
|
+
static isConstantAttributeZeroSupported(device) {
|
|
10
|
+
return device.info.type === 'webgl2' || getBrowser() === 'Chrome';
|
|
11
|
+
}
|
|
12
|
+
constructor(device, props) {
|
|
13
|
+
super(device, props);
|
|
14
|
+
this.device = void 0;
|
|
15
|
+
this.handle = void 0;
|
|
16
|
+
this.device = device;
|
|
17
|
+
}
|
|
18
|
+
destroy() {}
|
|
19
|
+
setIndexBuffer(buffer) {
|
|
20
|
+
this.indexBuffer = buffer;
|
|
21
|
+
}
|
|
22
|
+
setBuffer(location, buffer) {
|
|
23
|
+
this.attributes[location] = buffer;
|
|
24
|
+
}
|
|
25
|
+
setConstant(location, value) {
|
|
26
|
+
log.warn(`${this.id} constant attributes not supported on WebGPU`);
|
|
27
|
+
}
|
|
28
|
+
bindBeforeRender(renderPass, firstIndex, indexCount) {
|
|
29
|
+
const webgpuRenderPass = renderPass;
|
|
30
|
+
const webgpuIndexBuffer = this.indexBuffer;
|
|
31
|
+
if (webgpuIndexBuffer !== null && webgpuIndexBuffer !== void 0 && webgpuIndexBuffer.handle) {
|
|
32
|
+
log.warn('setting index buffer', webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.indexType)();
|
|
33
|
+
webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer === null || webgpuIndexBuffer === void 0 ? void 0 : webgpuIndexBuffer.indexType);
|
|
34
|
+
}
|
|
35
|
+
for (let location = 0; location < this.maxVertexAttributes; location++) {
|
|
36
|
+
const webgpuBuffer = this.attributes[location];
|
|
37
|
+
if (webgpuBuffer !== null && webgpuBuffer !== void 0 && webgpuBuffer.handle) {
|
|
38
|
+
log.warn('setting vertex buffer', location, webgpuBuffer === null || webgpuBuffer === void 0 ? void 0 : webgpuBuffer.handle)();
|
|
39
|
+
webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer === null || webgpuBuffer === void 0 ? void 0 : webgpuBuffer.handle);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
unbindAfterRender(renderPass) {}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=webgpu-vertex-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgpu-vertex-array.js","names":["VertexArray","log","getBrowser","_Symbol$toStringTag","Symbol","toStringTag","WebGPUVertexArray","isConstantAttributeZeroSupported","device","info","type","constructor","props","handle","destroy","setIndexBuffer","buffer","indexBuffer","setBuffer","location","attributes","setConstant","value","warn","id","bindBeforeRender","renderPass","firstIndex","indexCount","webgpuRenderPass","webgpuIndexBuffer","indexType","maxVertexAttributes","webgpuBuffer","setVertexBuffer","unbindAfterRender"],"sources":["../../../src/adapter/resources/webgpu-vertex-array.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {Device, Buffer, VertexArrayProps, RenderPass, TypedArray} from '@luma.gl/core';\nimport {VertexArray, log} from '@luma.gl/core';\nimport {getBrowser} from '@probe.gl/env';\n\nimport {WebGPUDevice} from '../webgpu-device';\nimport {WebGPUBuffer} from '../resources/webgpu-buffer';\n\nimport {WebGPURenderPass} from './webgpu-render-pass';\n\n/** VertexArrayObject wrapper */\nexport class WebGPUVertexArray extends VertexArray {\n override get [Symbol.toStringTag](): string {\n return 'WebGPUVertexArray';\n }\n\n readonly device: WebGPUDevice;\n /** Vertex Array is a helper class under WebGPU */\n readonly handle: never;\n\n /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */\n static isConstantAttributeZeroSupported(device: Device): boolean {\n return device.info.type === 'webgl2' || getBrowser() === 'Chrome';\n }\n\n // Create a VertexArray\n constructor(device: WebGPUDevice, props?: VertexArrayProps) {\n super(device, props);\n this.device = device;\n }\n\n override destroy(): void {}\n\n /**\n * Set an elements buffer, for indexed rendering.\n * Must be a Buffer bound to buffer with usage bit Buffer.INDEX set. \n */\n setIndexBuffer(buffer: Buffer | null): void {\n // assert(!elementBuffer || elementBuffer.glTarget === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);\n this.indexBuffer = buffer;\n }\n\n /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */\n setBuffer(location: number, buffer: Buffer): void {\n // Sanity check target\n // if (buffer.glUsage === GL.ELEMENT_ARRAY_BUFFER) {\n // throw new Error('Use setIndexBuffer');\n // }\n\n this.attributes[location] = buffer;\n }\n\n /** Set a location in vertex attributes array to a constant value, disables the location */\n override setConstant(location: number, value: TypedArray): void {\n log.warn(`${this.id} constant attributes not supported on WebGPU`)\n }\n\n override bindBeforeRender(renderPass: RenderPass, firstIndex?: number, indexCount?: number): void {\n const webgpuRenderPass = renderPass as WebGPURenderPass;\n const webgpuIndexBuffer = this.indexBuffer as WebGPUBuffer;\n if (webgpuIndexBuffer?.handle) {\n // Note we can't unset an index buffer\n log.warn('setting index buffer', webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType)();\n webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer?.handle, webgpuIndexBuffer?.indexType);\n }\n for (let location = 0; location < this.maxVertexAttributes; location++) {\n const webgpuBuffer = this.attributes[location] as WebGPUBuffer;\n if (webgpuBuffer?.handle) {\n log.warn('setting vertex buffer', location, webgpuBuffer?.handle)();\n webgpuRenderPass.handle.setVertexBuffer(location, webgpuBuffer?.handle);\n }\n }\n // TODO - emit warnings/errors/throw if constants have been set on this vertex array\n }\n\n override unbindAfterRender(renderPass: RenderPass): void {\n // On WebGPU we don't need to unbind. \n // In fact we can't easily do it. setIndexBuffer/setVertexBuffer don't accept null.\n // Unbinding presumably happens automatically when the render pass is ended.\n }\n}\n"],"mappings":";AAIA,SAAQA,WAAW,EAAEC,GAAG,QAAO,eAAe;AAC9C,SAAQC,UAAU,QAAO,eAAe;AAACC,mBAAA,GASzBC,MAAM,CAACC,WAAW;AADlC,OAAO,MAAMC,iBAAiB,SAASN,WAAW,CAAC;EACjD,KAAAG,mBAAA,IAA4C;IAC1C,OAAO,mBAAmB;EAC5B;EAOA,OAAOI,gCAAgCA,CAACC,MAAc,EAAW;IAC/D,OAAOA,MAAM,CAACC,IAAI,CAACC,IAAI,KAAK,QAAQ,IAAIR,UAAU,CAAC,CAAC,KAAK,QAAQ;EACnE;EAGAS,WAAWA,CAACH,MAAoB,EAAEI,KAAwB,EAAE;IAC1D,KAAK,CAACJ,MAAM,EAAEI,KAAK,CAAC;IAAC,KAXdJ,MAAM;IAAA,KAENK,MAAM;IAUb,IAAI,CAACL,MAAM,GAAGA,MAAM;EACtB;EAESM,OAAOA,CAAA,EAAS,CAAC;EAM1BC,cAAcA,CAACC,MAAqB,EAAQ;IAE1C,IAAI,CAACC,WAAW,GAAGD,MAAM;EAC3B;EAGAE,SAASA,CAACC,QAAgB,EAAEH,MAAc,EAAQ;IAMhD,IAAI,CAACI,UAAU,CAACD,QAAQ,CAAC,GAAGH,MAAM;EACpC;EAGSK,WAAWA,CAACF,QAAgB,EAAEG,KAAiB,EAAQ;IAC9DrB,GAAG,CAACsB,IAAI,CAAE,GAAE,IAAI,CAACC,EAAG,8CAA6C,CAAC;EACpE;EAESC,gBAAgBA,CAACC,UAAsB,EAAEC,UAAmB,EAAEC,UAAmB,EAAQ;IAChG,MAAMC,gBAAgB,GAAGH,UAA8B;IACvD,MAAMI,iBAAiB,GAAG,IAAI,CAACb,WAA2B;IAC1D,IAAIa,iBAAiB,aAAjBA,iBAAiB,eAAjBA,iBAAiB,CAAEjB,MAAM,EAAE;MAE7BZ,GAAG,CAACsB,IAAI,CAAC,sBAAsB,EAAEO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEjB,MAAM,EAAEiB,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEC,SAAS,CAAC,CAAC,CAAC;MAC3FF,gBAAgB,CAAChB,MAAM,CAACE,cAAc,CAACe,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEjB,MAAM,EAAEiB,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEC,SAAS,CAAC;IACjG;IACA,KAAK,IAAIZ,QAAQ,GAAG,CAAC,EAAEA,QAAQ,GAAG,IAAI,CAACa,mBAAmB,EAAEb,QAAQ,EAAE,EAAE;MACtE,MAAMc,YAAY,GAAG,IAAI,CAACb,UAAU,CAACD,QAAQ,CAAiB;MAC9D,IAAIc,YAAY,aAAZA,YAAY,eAAZA,YAAY,CAAEpB,MAAM,EAAE;QACxBZ,GAAG,CAACsB,IAAI,CAAC,uBAAuB,EAAEJ,QAAQ,EAAEc,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEpB,MAAM,CAAC,CAAC,CAAC;QACnEgB,gBAAgB,CAAChB,MAAM,CAACqB,eAAe,CAACf,QAAQ,EAAEc,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEpB,MAAM,CAAC;MACzE;IACF;EAEF;EAESsB,iBAAiBA,CAACT,UAAsB,EAAQ,CAIzD;AACF"}
|
|
@@ -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 './webgpu-device';
|
|
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';
|
|
5
|
+
import { WebGPUFramebuffer } from './resources/webgpu-framebuffer';
|
|
6
|
+
import { WebGPUTexture } from './resources/webgpu-texture';
|
|
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":";AACA,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,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;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,CAA4C;IAC1E,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;IAOlC,8FAA8F;IAC9F,6BAA6B;CAY9B"}
|
|
@@ -1,95 +1,74 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export default class WebGPUCanvasContext extends CanvasContext {
|
|
1
|
+
import { CanvasContext, log } from '@luma.gl/core';
|
|
2
|
+
import { getWebGPUTextureFormat } from "./helpers/convert-texture-format.js";
|
|
3
|
+
import { WebGPUFramebuffer } from "./resources/webgpu-framebuffer.js";
|
|
4
|
+
export class WebGPUCanvasContext extends CanvasContext {
|
|
6
5
|
constructor(device, adapter, props) {
|
|
7
6
|
super(props);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
_defineProperty(this, "format", void 0);
|
|
14
|
-
|
|
15
|
-
_defineProperty(this, "width", -1);
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "height", -1);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "depthStencilFormat", 'depth24plus');
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "sampleCount", 1);
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "depthStencilAttachment", null);
|
|
24
|
-
|
|
7
|
+
this.device = void 0;
|
|
8
|
+
this.gpuCanvasContext = void 0;
|
|
9
|
+
this.format = navigator.gpu.getPreferredCanvasFormat();
|
|
10
|
+
this.depthStencilFormat = 'depth24plus';
|
|
11
|
+
this.depthStencilAttachment = null;
|
|
25
12
|
this.device = device;
|
|
13
|
+
this.width = -1;
|
|
14
|
+
this.height = -1;
|
|
15
|
+
this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
|
|
26
16
|
this.gpuCanvasContext = this.canvas.getContext('webgpu');
|
|
27
|
-
this.format =
|
|
17
|
+
this.format = 'bgra8unorm';
|
|
28
18
|
}
|
|
29
|
-
|
|
30
19
|
destroy() {
|
|
31
20
|
this.gpuCanvasContext.unconfigure();
|
|
32
21
|
}
|
|
33
|
-
|
|
34
22
|
getCurrentFramebuffer() {
|
|
35
23
|
this.update();
|
|
36
|
-
const currentColorAttachment = this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
format: this.format,
|
|
40
|
-
width: this.width,
|
|
41
|
-
height: this.height
|
|
42
|
-
});
|
|
43
|
-
|
|
24
|
+
const currentColorAttachment = this.getCurrentTexture();
|
|
25
|
+
this.width = currentColorAttachment.width;
|
|
26
|
+
this.height = currentColorAttachment.height;
|
|
44
27
|
this._createDepthStencilAttachment();
|
|
45
|
-
|
|
46
|
-
return new WEBGPUFramebuffer(this.device, {
|
|
28
|
+
return new WebGPUFramebuffer(this.device, {
|
|
47
29
|
colorAttachments: [currentColorAttachment],
|
|
48
30
|
depthStencilAttachment: this.depthStencilAttachment
|
|
49
31
|
});
|
|
50
32
|
}
|
|
51
|
-
|
|
52
33
|
update() {
|
|
53
34
|
const [width, height] = this.getPixelSize();
|
|
54
35
|
const sizeChanged = width !== this.width || height !== this.height;
|
|
55
|
-
|
|
56
36
|
if (sizeChanged) {
|
|
57
37
|
this.width = width;
|
|
58
38
|
this.height = height;
|
|
59
|
-
|
|
60
39
|
if (this.depthStencilAttachment) {
|
|
61
40
|
this.depthStencilAttachment.destroy();
|
|
62
41
|
this.depthStencilAttachment = null;
|
|
63
42
|
}
|
|
64
|
-
|
|
65
43
|
this.gpuCanvasContext.configure({
|
|
66
44
|
device: this.device.handle,
|
|
67
45
|
format: getWebGPUTextureFormat(this.format),
|
|
68
|
-
size: [this.width, this.height],
|
|
69
46
|
colorSpace: this.props.colorSpace,
|
|
70
|
-
|
|
47
|
+
alphaMode: this.props.alphaMode
|
|
71
48
|
});
|
|
72
|
-
log.log(1,
|
|
49
|
+
log.log(1, `Resized to ${this.width}x${this.height}px`)();
|
|
73
50
|
}
|
|
74
51
|
}
|
|
75
|
-
|
|
76
52
|
resize(options) {
|
|
77
53
|
this.update();
|
|
78
54
|
}
|
|
79
|
-
|
|
55
|
+
getCurrentTexture() {
|
|
56
|
+
return this.device._createTexture({
|
|
57
|
+
id: `${this.id}#color-texture`,
|
|
58
|
+
handle: this.gpuCanvasContext.getCurrentTexture()
|
|
59
|
+
});
|
|
60
|
+
}
|
|
80
61
|
_createDepthStencilAttachment() {
|
|
81
62
|
if (!this.depthStencilAttachment) {
|
|
82
63
|
this.depthStencilAttachment = this.device.createTexture({
|
|
83
|
-
id:
|
|
64
|
+
id: `${this.id}#depth-stencil-texture`,
|
|
84
65
|
format: this.depthStencilFormat,
|
|
85
66
|
width: this.width,
|
|
86
67
|
height: this.height,
|
|
87
68
|
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
88
69
|
});
|
|
89
70
|
}
|
|
90
|
-
|
|
91
71
|
return this.depthStencilAttachment;
|
|
92
72
|
}
|
|
93
|
-
|
|
94
73
|
}
|
|
95
74
|
//# sourceMappingURL=webgpu-canvas-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"webgpu-canvas-context.js","names":["CanvasContext","log","getWebGPUTextureFormat","WebGPUFramebuffer","WebGPUCanvasContext","constructor","device","adapter","props","gpuCanvasContext","format","navigator","gpu","getPreferredCanvasFormat","depthStencilFormat","depthStencilAttachment","width","height","_setAutoCreatedCanvasId","id","canvas","getContext","destroy","unconfigure","getCurrentFramebuffer","update","currentColorAttachment","getCurrentTexture","_createDepthStencilAttachment","colorAttachments","getPixelSize","sizeChanged","configure","handle","colorSpace","alphaMode","resize","options","_createTexture","createTexture","usage","GPUTextureUsage","RENDER_ATTACHMENT"],"sources":["../../src/adapter/webgpu-canvas-context.ts"],"sourcesContent":["// / <reference types=\"@webgpu/types\" />\nimport type {Texture, TextureFormat, CanvasContextProps} from '@luma.gl/core';\nimport {CanvasContext, log} from '@luma.gl/core';\nimport {getWebGPUTextureFormat} from './helpers/convert-texture-format';\nimport {WebGPUDevice} from './webgpu-device';\nimport {WebGPUFramebuffer} from './resources/webgpu-framebuffer';\nimport {WebGPUTexture} from './resources/webgpu-texture';\n\n/** \n * Holds a WebGPU Canvas Context\n * The primary job of the CanvasContext is to generate textures for rendering into the current canvas\n * It also manages canvas sizing calculations and resizing.\n */\nexport class WebGPUCanvasContext extends CanvasContext {\n readonly device: WebGPUDevice;\n readonly gpuCanvasContext: GPUCanvasContext;\n /** Format of returned textures: \"bgra8unorm\", \"rgba8unorm\", \"rgba16float\". */\n readonly format: TextureFormat = navigator.gpu.getPreferredCanvasFormat();\n /** Default stencil format for depth textures */\n depthStencilFormat: TextureFormat = 'depth24plus';\n\n private depthStencilAttachment: Texture | null = null;\n\n constructor(device: WebGPUDevice, adapter: GPUAdapter, props: CanvasContextProps) {\n super(props);\n this.device = device;\n // TODO - hack to trigger resize?\n this.width = -1;\n this.height = -1;\n\n this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);\n // @ts-ignore TODO - we don't handle OffscreenRenderingContext.\n this.gpuCanvasContext = this.canvas.getContext('webgpu');\n // TODO this has been replaced\n // this.format = this.gpuCanvasContext.getPreferredFormat(adapter);\n this.format = 'bgra8unorm';\n }\n\n /** Destroy any textures produced while configured and remove the context configuration. */\n destroy(): void {\n this.gpuCanvasContext.unconfigure();\n }\n\n /** Update framebuffer with properly resized \"swap chain\" texture views */\n getCurrentFramebuffer(): WebGPUFramebuffer {\n // Ensure the canvas context size is updated\n this.update();\n\n // Wrap the current canvas context texture in a luma.gl texture\n // const currentColorAttachment = this.device.createTexture({\n // id: 'default-render-target',\n // handle: this.gpuCanvasContext.getCurrentTexture(),\n // format: this.format,\n // width: this.width,\n // height: this.height\n // });\n\n // Wrap the current canvas context texture in a luma.gl texture \n const currentColorAttachment = this.getCurrentTexture();\n this.width = currentColorAttachment.width;\n this.height = currentColorAttachment.height;\n\n // Resize the depth stencil attachment\n this._createDepthStencilAttachment();\n\n return new WebGPUFramebuffer(this.device, {\n colorAttachments: [currentColorAttachment],\n depthStencilAttachment: this.depthStencilAttachment\n });\n }\n\n /** Resizes and updates render targets if necessary */\n update() {\n const [width, height] = this.getPixelSize();\n\n const sizeChanged = width !== this.width || height !== this.height;\n\n if (sizeChanged) {\n this.width = width;\n this.height = height;\n\n if (this.depthStencilAttachment) {\n this.depthStencilAttachment.destroy();\n this.depthStencilAttachment = null;\n }\n\n // Reconfigure the canvas size.\n // https://www.w3.org/TR/webgpu/#canvas-configuration\n this.gpuCanvasContext.configure({\n device: this.device.handle,\n format: getWebGPUTextureFormat(this.format),\n // Can be used to define e.g. -srgb views\n // viewFormats: [...]\n colorSpace: this.props.colorSpace,\n alphaMode: this.props.alphaMode\n });\n\n log.log(1, `Resized to ${this.width}x${this.height}px`)();\n }\n }\n\n resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {\n this.update();\n }\n\n /** Wrap the current canvas context texture in a luma.gl texture */\n getCurrentTexture(): WebGPUTexture {\n return this.device._createTexture({\n id: `${this.id}#color-texture`,\n handle: this.gpuCanvasContext.getCurrentTexture()\n });\n }\n\n /** We build render targets on demand (i.e. not when size changes but when about to render) */\n _createDepthStencilAttachment() {\n if (!this.depthStencilAttachment) {\n this.depthStencilAttachment = this.device.createTexture({\n id: `${this.id}#depth-stencil-texture`,\n format: this.depthStencilFormat,\n width: this.width,\n height: this.height,\n usage: GPUTextureUsage.RENDER_ATTACHMENT\n });\n }\n return this.depthStencilAttachment;\n }\n}\n"],"mappings":"AAEA,SAAQA,aAAa,EAAEC,GAAG,QAAO,eAAe;AAAC,SACzCC,sBAAsB;AAAA,SAEtBC,iBAAiB;AAQzB,OAAO,MAAMC,mBAAmB,SAASJ,aAAa,CAAC;EAUrDK,WAAWA,CAACC,MAAoB,EAAEC,OAAmB,EAAEC,KAAyB,EAAE;IAChF,KAAK,CAACA,KAAK,CAAC;IAAC,KAVNF,MAAM;IAAA,KACNG,gBAAgB;IAAA,KAEhBC,MAAM,GAAkB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zB,CAAC,CAAC;IACJ;IACA,OAAO,IAAI,CAAC3B,sBAAsB;EACpC;AACF"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
/// <reference types="
|
|
2
|
-
import type { DeviceProps, DeviceInfo, DeviceLimits, DeviceFeature, CanvasContextProps, BufferProps, SamplerProps, ShaderProps, TextureProps, TextureFormat, ExternalTextureProps, FramebufferProps, RenderPipelineProps, ComputePipelineProps, RenderPassProps, ComputePassProps } from '@luma.gl/
|
|
3
|
-
import { Device } from '@luma.gl/
|
|
4
|
-
import WebGPUBuffer from './resources/webgpu-buffer';
|
|
5
|
-
import WebGPUTexture from './resources/webgpu-texture';
|
|
6
|
-
import WebGPUExternalTexture from './resources/webgpu-external-texture';
|
|
7
|
-
import WebGPUSampler from './resources/webgpu-sampler';
|
|
8
|
-
import WebGPUShader from './resources/webgpu-shader';
|
|
9
|
-
import WebGPURenderPipeline from './resources/webgpu-render-pipeline';
|
|
10
|
-
import WebGPUFramebuffer from './resources/webgpu-framebuffer';
|
|
11
|
-
import WebGPUComputePipeline from './resources/webgpu-compute-pipeline';
|
|
12
|
-
import WebGPURenderPass from './resources/webgpu-render-pass';
|
|
13
|
-
import WebGPUComputePass from './resources/webgpu-compute-pass';
|
|
14
|
-
import
|
|
1
|
+
/// <reference types="dist" />
|
|
2
|
+
import type { DeviceProps, DeviceInfo, DeviceLimits, DeviceFeature, CanvasContextProps, BufferProps, SamplerProps, ShaderProps, Texture, TextureProps, TextureFormat, ExternalTextureProps, FramebufferProps, RenderPipelineProps, ComputePipelineProps, RenderPassProps, ComputePassProps, VertexArrayProps, TransformFeedback, TransformFeedbackProps } from '@luma.gl/core';
|
|
3
|
+
import { Device } from '@luma.gl/core';
|
|
4
|
+
import { WebGPUBuffer } from './resources/webgpu-buffer';
|
|
5
|
+
import { WebGPUTexture } from './resources/webgpu-texture';
|
|
6
|
+
import { WebGPUExternalTexture } from './resources/webgpu-external-texture';
|
|
7
|
+
import { WebGPUSampler } from './resources/webgpu-sampler';
|
|
8
|
+
import { WebGPUShader } from './resources/webgpu-shader';
|
|
9
|
+
import { WebGPURenderPipeline } from './resources/webgpu-render-pipeline';
|
|
10
|
+
import { WebGPUFramebuffer } from './resources/webgpu-framebuffer';
|
|
11
|
+
import { WebGPUComputePipeline } from './resources/webgpu-compute-pipeline';
|
|
12
|
+
import { WebGPURenderPass } from './resources/webgpu-render-pass';
|
|
13
|
+
import { WebGPUComputePass } from './resources/webgpu-compute-pass';
|
|
14
|
+
import { WebGPUVertexArray } from './resources/webgpu-vertex-array';
|
|
15
|
+
import { WebGPUCanvasContext } from './webgpu-canvas-context';
|
|
15
16
|
/** WebGPU Device implementation */
|
|
16
|
-
export
|
|
17
|
+
export declare class WebGPUDevice extends Device {
|
|
17
18
|
readonly handle: GPUDevice;
|
|
18
19
|
readonly adapter: GPUAdapter;
|
|
19
20
|
readonly lost: Promise<{
|
|
@@ -29,7 +30,7 @@ export default class WebGPUDevice extends Device {
|
|
|
29
30
|
/** Check if WebGPU is available */
|
|
30
31
|
static isSupported(): boolean;
|
|
31
32
|
static create(props: DeviceProps): Promise<WebGPUDevice>;
|
|
32
|
-
constructor(device: GPUDevice, adapter: GPUAdapter, props: DeviceProps);
|
|
33
|
+
constructor(device: GPUDevice, adapter: GPUAdapter, adapterInfo: GPUAdapterInfo, props: DeviceProps);
|
|
33
34
|
destroy(): void;
|
|
34
35
|
get info(): DeviceInfo;
|
|
35
36
|
features: Set<DeviceFeature>;
|
|
@@ -40,7 +41,7 @@ export default class WebGPUDevice extends Device {
|
|
|
40
41
|
/** @todo implement proper check? */
|
|
41
42
|
isTextureFormatRenderable(format: TextureFormat): boolean;
|
|
42
43
|
get isLost(): boolean;
|
|
43
|
-
|
|
44
|
+
createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WebGPUBuffer;
|
|
44
45
|
_createTexture(props: TextureProps): WebGPUTexture;
|
|
45
46
|
createExternalTexture(props: ExternalTextureProps): WebGPUExternalTexture;
|
|
46
47
|
createShader(props: ShaderProps): WebGPUShader;
|
|
@@ -48,20 +49,36 @@ export default class WebGPUDevice extends Device {
|
|
|
48
49
|
createRenderPipeline(props: RenderPipelineProps): WebGPURenderPipeline;
|
|
49
50
|
createFramebuffer(props: FramebufferProps): WebGPUFramebuffer;
|
|
50
51
|
createComputePipeline(props: ComputePipelineProps): WebGPUComputePipeline;
|
|
52
|
+
createVertexArray(props: VertexArrayProps): WebGPUVertexArray;
|
|
51
53
|
/**
|
|
52
54
|
* Allows a render pass to begin against a canvas context
|
|
53
55
|
* @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
|
|
54
56
|
*/
|
|
55
57
|
beginRenderPass(props: RenderPassProps): WebGPURenderPass;
|
|
56
58
|
beginComputePass(props: ComputePassProps): WebGPUComputePass;
|
|
59
|
+
createTransformFeedback(props: TransformFeedbackProps): TransformFeedback;
|
|
57
60
|
createCanvasContext(props: CanvasContextProps): WebGPUCanvasContext;
|
|
58
61
|
/**
|
|
59
62
|
* Gets default renderpass encoder.
|
|
60
63
|
* Creates a new encoder against default canvasContext if not already created
|
|
61
64
|
* @note Called internally by Model.
|
|
65
|
+
* @deprecated Create explicit pass with device.beginRenderPass
|
|
62
66
|
*/
|
|
63
67
|
getDefaultRenderPass(): WebGPURenderPass;
|
|
64
68
|
submit(): void;
|
|
65
69
|
_getFeatures(): Set<DeviceFeature>;
|
|
70
|
+
copyExternalImageToTexture(options: {
|
|
71
|
+
texture: Texture;
|
|
72
|
+
mipLevel?: number;
|
|
73
|
+
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
74
|
+
colorSpace?: 'display-p3' | 'srgb';
|
|
75
|
+
premultipliedAlpha?: boolean;
|
|
76
|
+
source: ImageBitmap | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas;
|
|
77
|
+
sourceX?: number;
|
|
78
|
+
sourceY?: number;
|
|
79
|
+
width?: number;
|
|
80
|
+
height?: number;
|
|
81
|
+
depth?: number;
|
|
82
|
+
}): void;
|
|
66
83
|
}
|
|
67
84
|
//# sourceMappingURL=webgpu-device.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgpu-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-device.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"webgpu-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgpu-device.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,OAAO,EACP,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAEhB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,MAAM,EAA0B,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,qBAAqB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAC,qBAAqB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAElE,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAElE,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;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