@luma.gl/webgpu 9.0.0-beta.4 → 9.0.0-beta.6
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 +102 -1
- package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
- package/dist/adapter/helpers/convert-texture-format.js +8 -5
- package/dist/adapter/helpers/generate-mipmaps.d.ts.map +1 -1
- package/dist/adapter/helpers/generate-mipmaps.js +85 -82
- package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
- package/dist/adapter/helpers/get-bind-group.js +57 -41
- package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-vertex-buffer-layout.js +117 -80
- package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
- package/dist/adapter/helpers/webgpu-parameters.js +185 -125
- package/dist/adapter/resources/webgpu-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-buffer.js +117 -62
- package/dist/adapter/resources/webgpu-command-encoder.d.ts +7 -1
- package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-command-encoder.js +81 -49
- 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 +71 -41
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-compute-pipeline.js +28 -19
- package/dist/adapter/resources/webgpu-external-texture.d.ts +2 -2
- package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-external-texture.js +33 -18
- package/dist/adapter/resources/webgpu-framebuffer.d.ts +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-framebuffer.js +14 -7
- 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 +25 -0
- package/dist/adapter/resources/webgpu-query.js +42 -1
- package/dist/adapter/resources/webgpu-render-pass.d.ts +4 -2
- package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pass.js +133 -105
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts +3 -4
- package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-render-pipeline.js +137 -80
- 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 +18 -15
- 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 +56 -45
- 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 +32 -0
- package/dist/adapter/resources/webgpu-texture.d.ts +5 -4
- package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-texture.js +130 -107
- package/dist/adapter/resources/webgpu-vertex-array.d.ts +7 -6
- package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgpu-vertex-array.js +60 -39
- package/dist/adapter/webgpu-canvas-context.d.ts +3 -3
- package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgpu-canvas-context.js +100 -67
- package/dist/adapter/webgpu-device.d.ts +24 -21
- package/dist/adapter/webgpu-device.d.ts.map +1 -1
- package/dist/adapter/webgpu-device.js +264 -220
- package/dist/adapter/webgpu-types.js +0 -2
- package/dist/dist.dev.js +782 -2222
- package/dist/glsl/glsllang.js +9 -6
- package/dist/index.cjs +279 -388
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist.min.js +1 -22
- package/package.json +9 -7
- package/src/adapter/helpers/accessor-to-format.ts +5 -1
- package/src/adapter/helpers/convert-texture-format.ts +4 -1
- package/src/adapter/helpers/generate-mipmaps.ts +37 -26
- package/src/adapter/helpers/get-bind-group.ts +8 -2
- package/src/adapter/helpers/get-vertex-buffer-layout.ts +12 -4
- package/src/adapter/helpers/webgpu-parameters.ts +79 -15
- package/src/adapter/resources/webgpu-buffer.ts +21 -10
- package/src/adapter/resources/webgpu-command-encoder.ts +24 -9
- package/src/adapter/resources/webgpu-compute-pass.ts +26 -8
- package/src/adapter/resources/webgpu-compute-pipeline.ts +15 -10
- package/src/adapter/resources/webgpu-external-texture.ts +12 -6
- package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
- package/src/adapter/resources/webgpu-query-set.ts +35 -0
- package/src/adapter/resources/webgpu-render-pass.ts +37 -14
- package/src/adapter/resources/webgpu-render-pipeline.ts +30 -41
- package/src/adapter/resources/webgpu-sampler.ts +1 -1
- package/src/adapter/resources/webgpu-shader.ts +5 -4
- package/src/adapter/resources/webgpu-texture-view.ts +43 -0
- package/src/adapter/resources/webgpu-texture.ts +23 -19
- package/src/adapter/resources/webgpu-vertex-array.ts +25 -17
- package/src/adapter/webgpu-canvas-context.ts +8 -3
- package/src/adapter/webgpu-device.ts +100 -88
- package/src/index.ts +2 -1
- 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/resources/webgpu-vertex-array.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/glsl/glsllang.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/adapter/resources/webgpu-query.ts +0 -43
- package/src/adapter/webgpu-types.ts +0 -0
- package/src/glsl/glsllang.ts +0 -14
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Device, DeviceFeatures, CanvasContext, log, uid } from '@luma.gl/core';
|
|
2
5
|
import { WebGPUBuffer } from "./resources/webgpu-buffer.js";
|
|
3
6
|
import { WebGPUTexture } from "./resources/webgpu-texture.js";
|
|
4
7
|
import { WebGPUExternalTexture } from "./resources/webgpu-external-texture.js";
|
|
@@ -8,226 +11,267 @@ import { WebGPURenderPipeline } from "./resources/webgpu-render-pipeline.js";
|
|
|
8
11
|
import { WebGPUComputePipeline } from "./resources/webgpu-compute-pipeline.js";
|
|
9
12
|
import { WebGPURenderPass } from "./resources/webgpu-render-pass.js";
|
|
10
13
|
import { WebGPUComputePass } from "./resources/webgpu-compute-pass.js";
|
|
14
|
+
// import {WebGPUCommandEncoder} from './resources/webgpu-command-encoder';
|
|
11
15
|
import { WebGPUVertexArray } from "./resources/webgpu-vertex-array.js";
|
|
12
16
|
import { WebGPUCanvasContext } from "./webgpu-canvas-context.js";
|
|
17
|
+
import { WebGPUQuerySet } from "./resources/webgpu-query-set.js";
|
|
18
|
+
/** WebGPU Device implementation */
|
|
13
19
|
export class WebGPUDevice extends Device {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
20
|
+
static type = 'webgpu';
|
|
21
|
+
/** The underlying WebGPU device */
|
|
22
|
+
handle;
|
|
23
|
+
/* The underlying WebGPU adapter */
|
|
24
|
+
adapter;
|
|
25
|
+
/* The underlying WebGPU adapter's info */
|
|
26
|
+
adapterInfo;
|
|
27
|
+
features;
|
|
28
|
+
info;
|
|
29
|
+
limits;
|
|
30
|
+
lost;
|
|
31
|
+
canvasContext = null;
|
|
32
|
+
_isLost = false;
|
|
33
|
+
commandEncoder = null;
|
|
34
|
+
renderPass = null;
|
|
35
|
+
/** Check if WebGPU is available */
|
|
36
|
+
static isSupported() {
|
|
37
|
+
return Boolean(typeof navigator !== 'undefined' && navigator.gpu);
|
|
38
|
+
}
|
|
39
|
+
static async create(props) {
|
|
40
|
+
if (!navigator.gpu) {
|
|
41
|
+
throw new Error('WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu');
|
|
42
|
+
}
|
|
43
|
+
log.groupCollapsed(1, 'WebGPUDevice created')();
|
|
44
|
+
const adapter = await navigator.gpu.requestAdapter({
|
|
45
|
+
powerPreference: 'high-performance'
|
|
46
|
+
// forceSoftware: false
|
|
47
|
+
});
|
|
48
|
+
if (!adapter) {
|
|
49
|
+
throw new Error('Failed to request WebGPU adapter');
|
|
50
|
+
}
|
|
51
|
+
const adapterInfo = await adapter.requestAdapterInfo();
|
|
52
|
+
log.probe(2, 'Adapter available', adapterInfo)();
|
|
53
|
+
const requiredFeatures = [];
|
|
54
|
+
const requiredLimits = {};
|
|
55
|
+
if (props.requestMaximalLimits) {
|
|
56
|
+
requiredFeatures.push(...Array.from(adapter.features));
|
|
57
|
+
for (const key in adapter.limits) {
|
|
58
|
+
requiredLimits[key] = adapter.limits[key];
|
|
59
|
+
}
|
|
60
|
+
delete requiredLimits.minSubgroupSize;
|
|
61
|
+
delete requiredLimits.maxSubgroupSize;
|
|
62
|
+
}
|
|
63
|
+
const gpuDevice = await adapter.requestDevice({
|
|
64
|
+
requiredFeatures,
|
|
65
|
+
requiredLimits
|
|
66
|
+
});
|
|
67
|
+
log.probe(1, 'GPUDevice available')();
|
|
68
|
+
if (typeof props.canvas === 'string') {
|
|
69
|
+
await CanvasContext.pageLoaded;
|
|
70
|
+
log.probe(1, 'DOM is loaded')();
|
|
71
|
+
}
|
|
72
|
+
const device = new WebGPUDevice(gpuDevice, adapter, adapterInfo, props);
|
|
73
|
+
log.probe(1, 'Device created. For more info, set chrome://flags/#enable-webgpu-developer-features')();
|
|
74
|
+
log.table(1, device.info)();
|
|
75
|
+
log.groupEnd(1)();
|
|
76
|
+
return device;
|
|
77
|
+
}
|
|
78
|
+
constructor(device, adapter, adapterInfo, props) {
|
|
79
|
+
super({ ...props, id: props.id || uid('webgpu-device') });
|
|
80
|
+
this.handle = device;
|
|
81
|
+
this.adapter = adapter;
|
|
82
|
+
this.adapterInfo = adapterInfo;
|
|
83
|
+
this.info = this._getInfo();
|
|
84
|
+
this.features = this._getFeatures();
|
|
85
|
+
this.limits = this.handle.limits;
|
|
86
|
+
// "Context" loss handling
|
|
87
|
+
this.lost = new Promise(async (resolve) => {
|
|
88
|
+
const lostInfo = await this.handle.lost;
|
|
89
|
+
this._isLost = true;
|
|
90
|
+
resolve({ reason: 'destroyed', message: lostInfo.message });
|
|
91
|
+
});
|
|
92
|
+
// Note: WebGPU devices can be created without a canvas, for compute shader purposes
|
|
93
|
+
// if (props.canvas) {
|
|
94
|
+
this.canvasContext = new WebGPUCanvasContext(this, this.adapter, {
|
|
95
|
+
canvas: props.canvas,
|
|
96
|
+
height: props.height,
|
|
97
|
+
width: props.width,
|
|
98
|
+
container: props.container
|
|
99
|
+
});
|
|
100
|
+
// }
|
|
101
|
+
}
|
|
102
|
+
// TODO
|
|
103
|
+
// Load the glslang module now so that it is available synchronously when compiling shaders
|
|
104
|
+
// const {glsl = true} = props;
|
|
105
|
+
// this.glslang = glsl && await loadGlslangModule();
|
|
106
|
+
destroy() {
|
|
107
|
+
this.handle.destroy();
|
|
108
|
+
}
|
|
109
|
+
isTextureFormatSupported(format) {
|
|
110
|
+
return !format.includes('webgl');
|
|
111
|
+
}
|
|
112
|
+
/** @todo implement proper check? */
|
|
113
|
+
isTextureFormatFilterable(format) {
|
|
114
|
+
return this.isTextureFormatSupported(format);
|
|
115
|
+
}
|
|
116
|
+
/** @todo implement proper check? */
|
|
117
|
+
isTextureFormatRenderable(format) {
|
|
118
|
+
return this.isTextureFormatSupported(format);
|
|
119
|
+
}
|
|
120
|
+
get isLost() {
|
|
121
|
+
return this._isLost;
|
|
122
|
+
}
|
|
123
|
+
createBuffer(props) {
|
|
124
|
+
const newProps = this._getBufferProps(props);
|
|
125
|
+
return new WebGPUBuffer(this, newProps);
|
|
126
|
+
}
|
|
127
|
+
_createTexture(props) {
|
|
128
|
+
return new WebGPUTexture(this, props);
|
|
129
|
+
}
|
|
130
|
+
createExternalTexture(props) {
|
|
131
|
+
return new WebGPUExternalTexture(this, props);
|
|
132
|
+
}
|
|
133
|
+
createShader(props) {
|
|
134
|
+
return new WebGPUShader(this, props);
|
|
135
|
+
}
|
|
136
|
+
createSampler(props) {
|
|
137
|
+
return new WebGPUSampler(this, props);
|
|
138
|
+
}
|
|
139
|
+
createRenderPipeline(props) {
|
|
140
|
+
return new WebGPURenderPipeline(this, props);
|
|
141
|
+
}
|
|
142
|
+
createFramebuffer(props) {
|
|
143
|
+
throw new Error('Not implemented');
|
|
144
|
+
}
|
|
145
|
+
createComputePipeline(props) {
|
|
146
|
+
return new WebGPUComputePipeline(this, props);
|
|
147
|
+
}
|
|
148
|
+
createVertexArray(props) {
|
|
149
|
+
return new WebGPUVertexArray(this, props);
|
|
150
|
+
}
|
|
151
|
+
// WebGPU specifics
|
|
152
|
+
/**
|
|
153
|
+
* Allows a render pass to begin against a canvas context
|
|
154
|
+
* @todo need to support a "Framebuffer" equivalent (aka preconfigured RenderPassDescriptors?).
|
|
155
|
+
*/
|
|
156
|
+
beginRenderPass(props) {
|
|
157
|
+
this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
|
|
158
|
+
return new WebGPURenderPass(this, props);
|
|
159
|
+
}
|
|
160
|
+
beginComputePass(props) {
|
|
161
|
+
this.commandEncoder = this.commandEncoder || this.handle.createCommandEncoder();
|
|
162
|
+
return new WebGPUComputePass(this, props);
|
|
163
|
+
}
|
|
164
|
+
// createCommandEncoder(props: CommandEncoderProps): WebGPUCommandEncoder {
|
|
165
|
+
// return new WebGPUCommandEncoder(this, props);
|
|
166
|
+
// }
|
|
167
|
+
createTransformFeedback(props) {
|
|
168
|
+
throw new Error('Transform feedback not supported in WebGPU');
|
|
169
|
+
}
|
|
170
|
+
createQuerySet(props) {
|
|
171
|
+
return new WebGPUQuerySet(this, props);
|
|
172
|
+
}
|
|
173
|
+
createCanvasContext(props) {
|
|
174
|
+
return new WebGPUCanvasContext(this, this.adapter, props);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Gets default renderpass encoder.
|
|
178
|
+
* Creates a new encoder against default canvasContext if not already created
|
|
179
|
+
* @note Called internally by Model.
|
|
180
|
+
* @deprecated Create explicit pass with device.beginRenderPass
|
|
181
|
+
*/
|
|
182
|
+
getDefaultRenderPass() {
|
|
183
|
+
// this.renderPass =
|
|
184
|
+
// this.renderPass ||
|
|
185
|
+
// this.beginRenderPass({
|
|
186
|
+
// framebuffer: this.canvasContext?.getCurrentFramebuffer()
|
|
187
|
+
// });
|
|
188
|
+
// return this.renderPass;
|
|
189
|
+
throw new Error('a');
|
|
190
|
+
}
|
|
191
|
+
submit() {
|
|
192
|
+
// this.renderPass?.end();
|
|
193
|
+
const commandBuffer = this.commandEncoder?.finish();
|
|
194
|
+
if (commandBuffer) {
|
|
195
|
+
this.handle.queue.submit([commandBuffer]);
|
|
196
|
+
}
|
|
197
|
+
this.commandEncoder = null;
|
|
198
|
+
// this.renderPass = null;
|
|
199
|
+
}
|
|
200
|
+
// PRIVATE METHODS
|
|
201
|
+
_getInfo() {
|
|
202
|
+
const [driver, driverVersion] = (this.adapterInfo.driver || '').split(' Version ');
|
|
203
|
+
// See https://developer.chrome.com/blog/new-in-webgpu-120#adapter_information_updates
|
|
204
|
+
const vendor = this.adapterInfo.vendor || this.adapter.__brand || 'unknown';
|
|
205
|
+
const renderer = driver || '';
|
|
206
|
+
const version = driverVersion || '';
|
|
207
|
+
const gpu = vendor === 'apple' ? 'apple' : 'unknown'; // 'nvidia' | 'amd' | 'intel' | 'apple' | 'unknown',
|
|
208
|
+
const gpuArchitecture = this.adapterInfo.architecture || 'unknown';
|
|
209
|
+
const gpuBackend = this.adapterInfo.backend || 'unknown';
|
|
210
|
+
const gpuType = (this.adapterInfo.type || '').split(' ')[0].toLowerCase() || 'unknown';
|
|
211
|
+
return {
|
|
212
|
+
type: 'webgpu',
|
|
213
|
+
vendor,
|
|
214
|
+
renderer,
|
|
215
|
+
version,
|
|
216
|
+
gpu,
|
|
217
|
+
gpuType,
|
|
218
|
+
gpuBackend,
|
|
219
|
+
gpuArchitecture,
|
|
220
|
+
shadingLanguage: 'wgsl',
|
|
221
|
+
shadingLanguageVersion: 100
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
_getFeatures() {
|
|
225
|
+
// Initialize with actual WebGPU Features (note that unknown features may not be in DeviceFeature type)
|
|
226
|
+
const features = new Set(this.handle.features);
|
|
227
|
+
// Fixups for pre-standard names: https://github.com/webgpu-native/webgpu-headers/issues/133
|
|
228
|
+
// @ts-expect-error Chrome Canary v99
|
|
229
|
+
if (features.has('depth-clamping')) {
|
|
230
|
+
// @ts-expect-error Chrome Canary v99
|
|
231
|
+
features.delete('depth-clamping');
|
|
232
|
+
features.add('depth-clip-control');
|
|
233
|
+
}
|
|
234
|
+
// Some subsets of WebGPU extensions correspond to WebGL extensions
|
|
235
|
+
if (features.has('texture-compression-bc')) {
|
|
236
|
+
features.add('texture-compression-bc5-webgl');
|
|
237
|
+
}
|
|
238
|
+
const WEBGPU_ALWAYS_FEATURES = [
|
|
239
|
+
'timer-query-webgl',
|
|
240
|
+
'compilation-status-async-webgl',
|
|
241
|
+
'float32-renderable-webgl',
|
|
242
|
+
'float16-renderable-webgl',
|
|
243
|
+
'norm16-renderable-webgl',
|
|
244
|
+
'texture-filterable-anisotropic-webgl',
|
|
245
|
+
'shader-noperspective-interpolation-webgl'
|
|
246
|
+
];
|
|
247
|
+
for (const feature of WEBGPU_ALWAYS_FEATURES) {
|
|
248
|
+
features.add(feature);
|
|
249
|
+
}
|
|
250
|
+
return new DeviceFeatures(Array.from(features));
|
|
251
|
+
}
|
|
252
|
+
copyExternalImageToTexture(options) {
|
|
253
|
+
const { source, sourceX = 0, sourceY = 0, texture, mipLevel = 0, aspect = 'all', colorSpace = 'display-p3', premultipliedAlpha = false,
|
|
254
|
+
// destinationX,
|
|
255
|
+
// destinationY,
|
|
256
|
+
// desitnationZ,
|
|
257
|
+
width = texture.width, height = texture.height, depth = 1 } = options;
|
|
258
|
+
const webGpuTexture = texture;
|
|
259
|
+
this.handle?.queue.copyExternalImageToTexture(
|
|
260
|
+
// source: GPUImageCopyExternalImage
|
|
261
|
+
{
|
|
262
|
+
source,
|
|
263
|
+
origin: [sourceX, sourceY]
|
|
264
|
+
},
|
|
265
|
+
// destination: GPUImageCopyTextureTagged
|
|
266
|
+
{
|
|
267
|
+
texture: webGpuTexture.handle,
|
|
268
|
+
origin: [0, 0, 0], // [x, y, z],
|
|
269
|
+
mipLevel,
|
|
270
|
+
aspect,
|
|
271
|
+
colorSpace,
|
|
272
|
+
premultipliedAlpha
|
|
273
|
+
},
|
|
274
|
+
// copySize: GPUExtent3D
|
|
275
|
+
[width, height, depth]);
|
|
276
|
+
}
|
|
231
277
|
}
|
|
232
|
-
WebGPUDevice.type = 'webgpu';
|
|
233
|
-
//# sourceMappingURL=webgpu-device.js.map
|