@wasi-gfx/js-webgpu 0.1.0
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/README.md +26 -0
- package/dist/index.js +1665 -0
- package/package.json +35 -0
- package/types/interfaces/wasi-cli-run.d.ts +5 -0
- package/types/interfaces/wasi-cli-stdout.d.ts +3 -0
- package/types/interfaces/wasi-frame-buffer-frame-buffer.d.ts +21 -0
- package/types/interfaces/wasi-graphics-context-graphics-context.d.ts +17 -0
- package/types/interfaces/wasi-io-error.d.ts +18 -0
- package/types/interfaces/wasi-io-poll.d.ts +43 -0
- package/types/interfaces/wasi-io-streams.d.ts +240 -0
- package/types/interfaces/wasi-surface-surface.d.ts +400 -0
- package/types/interfaces/wasi-webgpu-webgpu.d.ts +1636 -0
- package/types/wit.d.ts +10 -0
- package/wit/deps/cli/command.wit +7 -0
- package/wit/deps/cli/environment.wit +18 -0
- package/wit/deps/cli/exit.wit +4 -0
- package/wit/deps/cli/imports.wit +20 -0
- package/wit/deps/cli/run.wit +4 -0
- package/wit/deps/cli/stdio.wit +17 -0
- package/wit/deps/cli/terminal.wit +49 -0
- package/wit/deps/clocks/monotonic-clock.wit +45 -0
- package/wit/deps/clocks/wall-clock.wit +42 -0
- package/wit/deps/clocks/world.wit +6 -0
- package/wit/deps/filesystem/preopens.wit +8 -0
- package/wit/deps/filesystem/types.wit +634 -0
- package/wit/deps/filesystem/world.wit +6 -0
- package/wit/deps/frame-buffer/frame-buffer.wit +23 -0
- package/wit/deps/graphics-context/graphics-context.wit +18 -0
- package/wit/deps/io/error.wit +34 -0
- package/wit/deps/io/poll.wit +41 -0
- package/wit/deps/io/streams.wit +262 -0
- package/wit/deps/io/world.wit +6 -0
- package/wit/deps/random/insecure-seed.wit +25 -0
- package/wit/deps/random/insecure.wit +22 -0
- package/wit/deps/random/random.wit +26 -0
- package/wit/deps/random/world.wit +7 -0
- package/wit/deps/sockets/instance-network.wit +9 -0
- package/wit/deps/sockets/ip-name-lookup.wit +51 -0
- package/wit/deps/sockets/network.wit +145 -0
- package/wit/deps/sockets/tcp-create-socket.wit +27 -0
- package/wit/deps/sockets/tcp.wit +353 -0
- package/wit/deps/sockets/udp-create-socket.wit +27 -0
- package/wit/deps/sockets/udp.wit +266 -0
- package/wit/deps/sockets/world.wit +11 -0
- package/wit/deps/surface/surface.wit +248 -0
- package/wit/deps/webgpu/imports.wit +5 -0
- package/wit/deps/webgpu/webgpu.wit +1085 -0
- package/wit/deps.lock +51 -0
- package/wit/deps.toml +18 -0
- package/wit/world.wit +10 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1665 @@
|
|
|
1
|
+
import * as gfx from 'wasi:webgpu/webgpu@0.0.1';
|
|
2
|
+
import * as wasiSurface from 'wasi:surface/surface@0.0.1';
|
|
3
|
+
import * as wasiGraphicsContext from 'wasi:graphics-context/graphics-context@0.0.1';
|
|
4
|
+
export function createCanvas() {
|
|
5
|
+
return new HTMLCanvasElement(key);
|
|
6
|
+
}
|
|
7
|
+
// https://dom.spec.whatwg.org/#interface-eventtarget
|
|
8
|
+
class EventTarget {
|
|
9
|
+
addEventListener(type, callback, options) {
|
|
10
|
+
throw new Todo;
|
|
11
|
+
}
|
|
12
|
+
dispatchEvent(event) {
|
|
13
|
+
throw new Todo;
|
|
14
|
+
}
|
|
15
|
+
removeEventListener(type, callback, options) {
|
|
16
|
+
throw new Todo;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class Todo extends Error {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("TODO: not yet implemented");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class Unimplemented extends Error {
|
|
25
|
+
constructor() {
|
|
26
|
+
super("Unimplemented.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class Unreachable extends Error {
|
|
30
|
+
constructor() {
|
|
31
|
+
super("Unreachable code reached.");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const inner = Symbol("inner");
|
|
35
|
+
const key = Symbol("key");
|
|
36
|
+
function privateConstructorCalled(k) {
|
|
37
|
+
if (k !== key)
|
|
38
|
+
throw new TypeError("Illegal constructor.");
|
|
39
|
+
}
|
|
40
|
+
// converters
|
|
41
|
+
// don't use raw `Number(x)`/`BigInt(x)` because they accept non-numeric values
|
|
42
|
+
function numToBigInt(n) {
|
|
43
|
+
return BigInt(n);
|
|
44
|
+
}
|
|
45
|
+
function bigIntToNum(n) {
|
|
46
|
+
return Number(n);
|
|
47
|
+
}
|
|
48
|
+
function numToBigIntOptional(n) {
|
|
49
|
+
if (n === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
return numToBigInt(n);
|
|
52
|
+
}
|
|
53
|
+
function bigIntToNumOptional(n) {
|
|
54
|
+
if (n === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
return bigIntToNum(n);
|
|
57
|
+
}
|
|
58
|
+
function convertFeatureNameWebToWasi(name) {
|
|
59
|
+
if (name === "texture-compression-bc-sliced-3d")
|
|
60
|
+
return "texture-compression-bc-sliced3d";
|
|
61
|
+
if (name === "texture-compression-astc-sliced-3d" || name === "float32-blendable")
|
|
62
|
+
throw new Todo;
|
|
63
|
+
return name;
|
|
64
|
+
}
|
|
65
|
+
function convertTextureFormatWebToWasi(name) {
|
|
66
|
+
switch (name) {
|
|
67
|
+
case "astc-4x4-unorm":
|
|
68
|
+
return "astc4x4-unorm";
|
|
69
|
+
case "astc-4x4-unorm-srgb":
|
|
70
|
+
return "astc4x4-unorm-srgb";
|
|
71
|
+
case "astc-5x4-unorm":
|
|
72
|
+
return "astc5x4-unorm";
|
|
73
|
+
case "astc-5x4-unorm-srgb":
|
|
74
|
+
return "astc5x4-unorm-srgb";
|
|
75
|
+
case "astc-5x5-unorm":
|
|
76
|
+
return "astc5x5-unorm";
|
|
77
|
+
case "astc-5x5-unorm-srgb":
|
|
78
|
+
return "astc5x5-unorm-srgb";
|
|
79
|
+
case "astc-6x5-unorm":
|
|
80
|
+
return "astc6x5-unorm";
|
|
81
|
+
case "astc-6x5-unorm-srgb":
|
|
82
|
+
return "astc6x5-unorm-srgb";
|
|
83
|
+
case "astc-6x6-unorm":
|
|
84
|
+
return "astc6x6-unorm";
|
|
85
|
+
case "astc-6x6-unorm-srgb":
|
|
86
|
+
return "astc6x6-unorm-srgb";
|
|
87
|
+
case "astc-8x5-unorm":
|
|
88
|
+
return "astc8x5-unorm";
|
|
89
|
+
case "astc-8x5-unorm-srgb":
|
|
90
|
+
return "astc8x5-unorm-srgb";
|
|
91
|
+
case "astc-8x6-unorm":
|
|
92
|
+
return "astc8x6-unorm";
|
|
93
|
+
case "astc-8x6-unorm-srgb":
|
|
94
|
+
return "astc8x6-unorm-srgb";
|
|
95
|
+
case "astc-8x8-unorm":
|
|
96
|
+
return "astc8x8-unorm";
|
|
97
|
+
case "astc-8x8-unorm-srgb":
|
|
98
|
+
return "astc8x8-unorm-srgb";
|
|
99
|
+
case "astc-10x5-unorm":
|
|
100
|
+
return "astc10x5-unorm";
|
|
101
|
+
case "astc-10x5-unorm-srgb":
|
|
102
|
+
return "astc10x5-unorm-srgb";
|
|
103
|
+
case "astc-10x6-unorm":
|
|
104
|
+
return "astc10x6-unorm";
|
|
105
|
+
case "astc-10x6-unorm-srgb":
|
|
106
|
+
return "astc10x6-unorm-srgb";
|
|
107
|
+
case "astc-10x8-unorm":
|
|
108
|
+
return "astc10x8-unorm";
|
|
109
|
+
case "astc-10x8-unorm-srgb":
|
|
110
|
+
return "astc10x8-unorm-srgb";
|
|
111
|
+
case "astc-10x10-unorm":
|
|
112
|
+
return "astc10x10-unorm";
|
|
113
|
+
case "astc-10x10-unorm-srgb":
|
|
114
|
+
return "astc10x10-unorm-srgb";
|
|
115
|
+
case "astc-12x10-unorm":
|
|
116
|
+
return "astc12x10-unorm";
|
|
117
|
+
case "astc-12x10-unorm-srgb":
|
|
118
|
+
return "astc12x10-unorm-srgb";
|
|
119
|
+
case "astc-12x12-unorm":
|
|
120
|
+
return "astc12x12-unorm";
|
|
121
|
+
case "astc-12x12-unorm-srgb":
|
|
122
|
+
return "astc12x12-unorm-srgb";
|
|
123
|
+
default:
|
|
124
|
+
return name;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function convertTextureFormatWasiToWeb(name) {
|
|
128
|
+
switch (name) {
|
|
129
|
+
case "astc4x4-unorm":
|
|
130
|
+
return "astc-4x4-unorm";
|
|
131
|
+
case "astc4x4-unorm-srgb":
|
|
132
|
+
return "astc-4x4-unorm-srgb";
|
|
133
|
+
case "astc5x4-unorm":
|
|
134
|
+
return "astc-5x4-unorm";
|
|
135
|
+
case "astc5x4-unorm-srgb":
|
|
136
|
+
return "astc-5x4-unorm-srgb";
|
|
137
|
+
case "astc5x5-unorm":
|
|
138
|
+
return "astc-5x5-unorm";
|
|
139
|
+
case "astc5x5-unorm-srgb":
|
|
140
|
+
return "astc-5x5-unorm-srgb";
|
|
141
|
+
case "astc6x5-unorm":
|
|
142
|
+
return "astc-6x5-unorm";
|
|
143
|
+
case "astc6x5-unorm-srgb":
|
|
144
|
+
return "astc-6x5-unorm-srgb";
|
|
145
|
+
case "astc6x6-unorm":
|
|
146
|
+
return "astc-6x6-unorm";
|
|
147
|
+
case "astc6x6-unorm-srgb":
|
|
148
|
+
return "astc-6x6-unorm-srgb";
|
|
149
|
+
case "astc8x5-unorm":
|
|
150
|
+
return "astc-8x5-unorm";
|
|
151
|
+
case "astc8x5-unorm-srgb":
|
|
152
|
+
return "astc-8x5-unorm-srgb";
|
|
153
|
+
case "astc8x6-unorm":
|
|
154
|
+
return "astc-8x6-unorm";
|
|
155
|
+
case "astc8x6-unorm-srgb":
|
|
156
|
+
return "astc-8x6-unorm-srgb";
|
|
157
|
+
case "astc8x8-unorm":
|
|
158
|
+
return "astc-8x8-unorm";
|
|
159
|
+
case "astc8x8-unorm-srgb":
|
|
160
|
+
return "astc-8x8-unorm-srgb";
|
|
161
|
+
case "astc10x5-unorm":
|
|
162
|
+
return "astc-10x5-unorm";
|
|
163
|
+
case "astc10x5-unorm-srgb":
|
|
164
|
+
return "astc-10x5-unorm-srgb";
|
|
165
|
+
case "astc10x6-unorm":
|
|
166
|
+
return "astc-10x6-unorm";
|
|
167
|
+
case "astc10x6-unorm-srgb":
|
|
168
|
+
return "astc-10x6-unorm-srgb";
|
|
169
|
+
case "astc10x8-unorm":
|
|
170
|
+
return "astc-10x8-unorm";
|
|
171
|
+
case "astc10x8-unorm-srgb":
|
|
172
|
+
return "astc-10x8-unorm-srgb";
|
|
173
|
+
case "astc10x10-unorm":
|
|
174
|
+
return "astc-10x10-unorm";
|
|
175
|
+
case "astc10x10-unorm-srgb":
|
|
176
|
+
return "astc-10x10-unorm-srgb";
|
|
177
|
+
case "astc12x10-unorm":
|
|
178
|
+
return "astc-12x10-unorm";
|
|
179
|
+
case "astc12x10-unorm-srgb":
|
|
180
|
+
return "astc-12x10-unorm-srgb";
|
|
181
|
+
case "astc12x12-unorm":
|
|
182
|
+
return "astc-12x12-unorm";
|
|
183
|
+
case "astc12x12-unorm-srgb":
|
|
184
|
+
return "astc-12x12-unorm-srgb";
|
|
185
|
+
default:
|
|
186
|
+
return name;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function convertVertexFormatWebToWasi(name) {
|
|
190
|
+
switch (name) {
|
|
191
|
+
case "unorm10-10-10-2":
|
|
192
|
+
return "unorm1010102";
|
|
193
|
+
case "uint8":
|
|
194
|
+
case "sint8":
|
|
195
|
+
case "unorm8":
|
|
196
|
+
case "snorm8":
|
|
197
|
+
case "uint16":
|
|
198
|
+
case "sint16":
|
|
199
|
+
case "unorm16":
|
|
200
|
+
case "snorm16":
|
|
201
|
+
case "float16":
|
|
202
|
+
case "unorm8x4-bgra":
|
|
203
|
+
throw new Todo;
|
|
204
|
+
default:
|
|
205
|
+
return name;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function convertVertexFormatWasiToWeb(name) {
|
|
209
|
+
switch (name) {
|
|
210
|
+
case "unorm1010102":
|
|
211
|
+
return "unorm10-10-10-2";
|
|
212
|
+
default:
|
|
213
|
+
return name;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function convertTextureDimensionWebToWasi(name) {
|
|
217
|
+
name = name.toLowerCase();
|
|
218
|
+
switch (name) {
|
|
219
|
+
case "1d":
|
|
220
|
+
return "d1";
|
|
221
|
+
case "2d":
|
|
222
|
+
return "d2";
|
|
223
|
+
case "3d":
|
|
224
|
+
return "d3";
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function convertTextureDimensionWasiToWeb(name) {
|
|
228
|
+
switch (name) {
|
|
229
|
+
case "d1":
|
|
230
|
+
return "1d";
|
|
231
|
+
case "d2":
|
|
232
|
+
return "2d";
|
|
233
|
+
case "d3":
|
|
234
|
+
return "3d";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function convertTextureViewDimensionWebToWasi(name) {
|
|
238
|
+
name = name.toLowerCase();
|
|
239
|
+
switch (name) {
|
|
240
|
+
case "1d":
|
|
241
|
+
return "d1";
|
|
242
|
+
case "2d":
|
|
243
|
+
return "d2";
|
|
244
|
+
case "3d":
|
|
245
|
+
return "d3";
|
|
246
|
+
case "2d-array":
|
|
247
|
+
return "d2-array";
|
|
248
|
+
default:
|
|
249
|
+
return name;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function convertTextureViewDimensionWasiToWeb(name) {
|
|
253
|
+
switch (name) {
|
|
254
|
+
case "d1":
|
|
255
|
+
return "1d";
|
|
256
|
+
case "d2":
|
|
257
|
+
return "2d";
|
|
258
|
+
case "d3":
|
|
259
|
+
return "3d";
|
|
260
|
+
case "d2-array":
|
|
261
|
+
return "2d-array";
|
|
262
|
+
default:
|
|
263
|
+
return name;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function convertGpuLayoutWebToWasi(layout) {
|
|
267
|
+
if (layout instanceof GPUPipelineLayout) {
|
|
268
|
+
return {
|
|
269
|
+
tag: 'specific',
|
|
270
|
+
val: layout[inner],
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
else if (layout === 'auto') {
|
|
274
|
+
return {
|
|
275
|
+
tag: 'auto',
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
throw new Unreachable;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function convertGpuLayoutWasiToWeb(layout) {
|
|
283
|
+
throw new Todo;
|
|
284
|
+
}
|
|
285
|
+
function convertColorWebToWasi(color) {
|
|
286
|
+
// https://www.w3.org/TR/webgpu/#colors-and-vectors
|
|
287
|
+
if (Symbol.iterator in color) {
|
|
288
|
+
const iter = color[Symbol.iterator]();
|
|
289
|
+
const r = iter.next().value;
|
|
290
|
+
const g = iter.next().value;
|
|
291
|
+
const b = iter.next().value;
|
|
292
|
+
const a = iter.next().value;
|
|
293
|
+
if (r === undefined || g === undefined || b === undefined || a === undefined || !iter.next().done)
|
|
294
|
+
throw new TypeError("color must have exactly 4 items");
|
|
295
|
+
return {
|
|
296
|
+
r, g, b, a,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return color;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function convertExtent3DWebToWasi(extent) {
|
|
304
|
+
// TODO: add correct link https://www.w3.org/TR/webgpu/#colors-and-vectors
|
|
305
|
+
if (Symbol.iterator in extent) {
|
|
306
|
+
const iter = extent[Symbol.iterator]();
|
|
307
|
+
const width = iter.next().value;
|
|
308
|
+
const height = iter.next().value;
|
|
309
|
+
const depthOrArrayLayers = iter.next().value;
|
|
310
|
+
if (width === undefined || !iter.next().done)
|
|
311
|
+
throw new TypeError("extent must have 1-3 items");
|
|
312
|
+
return {
|
|
313
|
+
width,
|
|
314
|
+
height,
|
|
315
|
+
depthOrArrayLayers,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
return extent;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function convertOrigin3DWebToWasi(origin) {
|
|
323
|
+
// TODO: add correct link https://www.w3.org/TR/webgpu/#colors-and-vectors
|
|
324
|
+
if (Symbol.iterator in origin) {
|
|
325
|
+
const iter = origin[Symbol.iterator]();
|
|
326
|
+
const x = iter.next().value;
|
|
327
|
+
const y = iter.next().value;
|
|
328
|
+
const z = iter.next().value;
|
|
329
|
+
if (x === undefined || y === undefined || z === undefined || !iter.next().done)
|
|
330
|
+
throw new TypeError("origin must have exactly 3 items");
|
|
331
|
+
return {
|
|
332
|
+
x,
|
|
333
|
+
y,
|
|
334
|
+
z,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
return origin;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function convertGpuBindingResourceWebToWasi(resource) {
|
|
342
|
+
if (resource instanceof GPUSampler) {
|
|
343
|
+
return {
|
|
344
|
+
tag: 'gpu-sampler',
|
|
345
|
+
val: resource[inner],
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
else if (resource instanceof GPUTextureView) {
|
|
349
|
+
throw new Todo;
|
|
350
|
+
}
|
|
351
|
+
else if (resource.buffer) {
|
|
352
|
+
let bufferBinding = resource;
|
|
353
|
+
let offsetBitInt;
|
|
354
|
+
if (typeof bufferBinding.offset === "number")
|
|
355
|
+
offsetBitInt = numToBigInt(bufferBinding.offset);
|
|
356
|
+
let sizeBitInt;
|
|
357
|
+
if (typeof bufferBinding.size === "number")
|
|
358
|
+
sizeBitInt = numToBigInt(bufferBinding.size);
|
|
359
|
+
return {
|
|
360
|
+
tag: 'gpu-buffer-binding',
|
|
361
|
+
val: {
|
|
362
|
+
...resource,
|
|
363
|
+
size: sizeBitInt,
|
|
364
|
+
offset: offsetBitInt,
|
|
365
|
+
buffer: bufferBinding.buffer[inner],
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
throw new Unreachable;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function convertBufferToUint8Array(buffer) {
|
|
374
|
+
if (buffer instanceof Uint8Array) {
|
|
375
|
+
return buffer;
|
|
376
|
+
}
|
|
377
|
+
else if (buffer instanceof Int8Array
|
|
378
|
+
|| buffer instanceof Int16Array
|
|
379
|
+
|| buffer instanceof Int32Array
|
|
380
|
+
|| buffer instanceof Uint16Array
|
|
381
|
+
|| buffer instanceof Uint32Array
|
|
382
|
+
|| buffer instanceof Uint8ClampedArray
|
|
383
|
+
|| buffer instanceof BigInt64Array
|
|
384
|
+
|| buffer instanceof BigUint64Array
|
|
385
|
+
// TODO: enable next line if/when Float16Array is supported in StarlingMonkey
|
|
386
|
+
// || buffer instanceof Float16Array
|
|
387
|
+
|| buffer instanceof Float32Array
|
|
388
|
+
|| buffer instanceof Float64Array
|
|
389
|
+
|| buffer instanceof DataView) {
|
|
390
|
+
return new Uint8Array(buffer.buffer);
|
|
391
|
+
}
|
|
392
|
+
else if (buffer instanceof ArrayBuffer || buffer instanceof SharedArrayBuffer) {
|
|
393
|
+
return new Uint8Array(buffer);
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
throw new Unreachable;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
export class HTMLCanvasElement {
|
|
400
|
+
_surface;
|
|
401
|
+
_graphicsContext;
|
|
402
|
+
#framePollable;
|
|
403
|
+
get height() {
|
|
404
|
+
return this._surface.height();
|
|
405
|
+
}
|
|
406
|
+
set height(value) {
|
|
407
|
+
this._surface.requestSetSize(value, undefined);
|
|
408
|
+
}
|
|
409
|
+
get width() {
|
|
410
|
+
return this._surface.width();
|
|
411
|
+
}
|
|
412
|
+
set width(value) {
|
|
413
|
+
this._surface.requestSetSize(undefined, value);
|
|
414
|
+
}
|
|
415
|
+
constructor(k) {
|
|
416
|
+
privateConstructorCalled(k);
|
|
417
|
+
this._surface = new wasiSurface.Surface({});
|
|
418
|
+
this._graphicsContext = new wasiGraphicsContext.Context();
|
|
419
|
+
this._surface.connectGraphicsContext(this._graphicsContext);
|
|
420
|
+
}
|
|
421
|
+
getContext(contextId, options) {
|
|
422
|
+
switch (contextId.toLowerCase()) {
|
|
423
|
+
case "2d":
|
|
424
|
+
throw new Unimplemented;
|
|
425
|
+
case "bitmaprenderer":
|
|
426
|
+
throw new Todo;
|
|
427
|
+
case "webgl":
|
|
428
|
+
throw new Unimplemented;
|
|
429
|
+
case "webgl2":
|
|
430
|
+
throw new Unimplemented;
|
|
431
|
+
case "webgpu":
|
|
432
|
+
return new GPUCanvasContext(key, this);
|
|
433
|
+
default:
|
|
434
|
+
throw new Unreachable;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
transferControlToOffscreen() {
|
|
438
|
+
throw new Todo;
|
|
439
|
+
}
|
|
440
|
+
addEventListener(type, listener, options) {
|
|
441
|
+
throw new Todo;
|
|
442
|
+
}
|
|
443
|
+
removeEventListener(type, listener, options) {
|
|
444
|
+
throw new Todo;
|
|
445
|
+
}
|
|
446
|
+
dispatchEvent(event) {
|
|
447
|
+
throw new Todo;
|
|
448
|
+
}
|
|
449
|
+
onclick = null;
|
|
450
|
+
ondblclick = null;
|
|
451
|
+
oninput = null;
|
|
452
|
+
onkeydown = null;
|
|
453
|
+
onkeyup = null;
|
|
454
|
+
onpointerdown = null;
|
|
455
|
+
onpointermove = null;
|
|
456
|
+
onpointerup = null;
|
|
457
|
+
cancelAnimationFrame(handle) {
|
|
458
|
+
throw new Todo;
|
|
459
|
+
}
|
|
460
|
+
requestAnimationFrame(callback) {
|
|
461
|
+
if (!this.#framePollable)
|
|
462
|
+
this.#framePollable = this._surface.subscribeFrame();
|
|
463
|
+
const pollable = this.#framePollable;
|
|
464
|
+
// giving the event loop a chance to do other work before blocking.
|
|
465
|
+
Promise.resolve().then(() => {
|
|
466
|
+
pollable.block();
|
|
467
|
+
this._surface.getFrame();
|
|
468
|
+
// TODO: this number should be real
|
|
469
|
+
callback(0);
|
|
470
|
+
this._graphicsContext.present();
|
|
471
|
+
});
|
|
472
|
+
// TODO: this number should be real
|
|
473
|
+
return 0;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
export class GPUCanvasContext {
|
|
477
|
+
#canvas;
|
|
478
|
+
constructor(k, canvas) {
|
|
479
|
+
privateConstructorCalled(k);
|
|
480
|
+
this.#canvas = canvas;
|
|
481
|
+
}
|
|
482
|
+
__brand = "GPUCanvasContext";
|
|
483
|
+
get canvas() {
|
|
484
|
+
throw new Todo;
|
|
485
|
+
}
|
|
486
|
+
configure(configuration) {
|
|
487
|
+
let device = configuration.device[inner];
|
|
488
|
+
let context = this.#canvas._graphicsContext;
|
|
489
|
+
device.connectGraphicsContext(context);
|
|
490
|
+
}
|
|
491
|
+
unconfigure() {
|
|
492
|
+
throw new Todo;
|
|
493
|
+
}
|
|
494
|
+
getConfiguration() {
|
|
495
|
+
throw new Todo;
|
|
496
|
+
}
|
|
497
|
+
getCurrentTexture() {
|
|
498
|
+
const buffer = this.#canvas._graphicsContext.getCurrentBuffer();
|
|
499
|
+
let texture = gfx.GpuTexture.fromGraphicsBuffer(buffer);
|
|
500
|
+
return new GPUTexture(key, texture);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
export class GPU {
|
|
504
|
+
[inner];
|
|
505
|
+
constructor(k, i) {
|
|
506
|
+
privateConstructorCalled(k);
|
|
507
|
+
this[inner] = i;
|
|
508
|
+
}
|
|
509
|
+
get __brand() {
|
|
510
|
+
return "GPU";
|
|
511
|
+
}
|
|
512
|
+
get wgslLanguageFeatures() {
|
|
513
|
+
throw new Todo;
|
|
514
|
+
}
|
|
515
|
+
async requestAdapter(descriptor = {}) {
|
|
516
|
+
const adapter = await this[inner].requestAdapter(descriptor);
|
|
517
|
+
if (adapter)
|
|
518
|
+
return new GPUAdapter(key, adapter);
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
getPreferredCanvasFormat() {
|
|
522
|
+
return convertTextureFormatWasiToWeb(this[inner].getPreferredCanvasFormat());
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
export class GPUAdapter {
|
|
526
|
+
[inner];
|
|
527
|
+
constructor(k, i) {
|
|
528
|
+
privateConstructorCalled(k);
|
|
529
|
+
this[inner] = i;
|
|
530
|
+
}
|
|
531
|
+
async requestDevice(descriptor = {}) {
|
|
532
|
+
let requiredFeatures;
|
|
533
|
+
if (descriptor.requiredFeatures)
|
|
534
|
+
requiredFeatures = Array.from(descriptor.requiredFeatures).map(convertFeatureNameWebToWasi);
|
|
535
|
+
let requiredLimits;
|
|
536
|
+
if (descriptor.requiredLimits) {
|
|
537
|
+
requiredLimits = new gfx.RecordOptionGpuSize64();
|
|
538
|
+
for (const [key, value] of Object.entries(descriptor.requiredLimits)) {
|
|
539
|
+
requiredLimits.add(key, numToBigIntOptional(value));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return new GPUDevice(key, this[inner].requestDevice({
|
|
543
|
+
...descriptor,
|
|
544
|
+
requiredFeatures,
|
|
545
|
+
requiredLimits,
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
requestAdapterInfo() {
|
|
549
|
+
throw new Todo();
|
|
550
|
+
}
|
|
551
|
+
get __brand() {
|
|
552
|
+
return "GPUAdapter";
|
|
553
|
+
}
|
|
554
|
+
get info() {
|
|
555
|
+
return new GPUAdapterInfo(key, this[inner].info());
|
|
556
|
+
}
|
|
557
|
+
get features() {
|
|
558
|
+
return new GPUSupportedFeatures(key, this[inner].features());
|
|
559
|
+
}
|
|
560
|
+
get limits() {
|
|
561
|
+
return new GPUSupportedLimits(key, this[inner].limits());
|
|
562
|
+
}
|
|
563
|
+
get isFallbackAdapter() {
|
|
564
|
+
return this[inner].isFallbackAdapter();
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
export class GPUSupportedFeatures {
|
|
568
|
+
[inner];
|
|
569
|
+
constructor(k, i) {
|
|
570
|
+
privateConstructorCalled(k);
|
|
571
|
+
this[inner] = i;
|
|
572
|
+
}
|
|
573
|
+
get __brand() {
|
|
574
|
+
return "GPUSupportedFeatures";
|
|
575
|
+
}
|
|
576
|
+
get size() {
|
|
577
|
+
throw new Todo;
|
|
578
|
+
}
|
|
579
|
+
has(value) {
|
|
580
|
+
return this[inner].has(value);
|
|
581
|
+
}
|
|
582
|
+
forEach(callbackfn, thisArg) {
|
|
583
|
+
throw new Todo;
|
|
584
|
+
}
|
|
585
|
+
entries() {
|
|
586
|
+
throw new Todo;
|
|
587
|
+
}
|
|
588
|
+
keys() {
|
|
589
|
+
throw new Todo;
|
|
590
|
+
}
|
|
591
|
+
values() {
|
|
592
|
+
throw new Todo;
|
|
593
|
+
}
|
|
594
|
+
[Symbol.iterator]() {
|
|
595
|
+
throw new Todo;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
export class GPUSupportedLimits {
|
|
599
|
+
[inner];
|
|
600
|
+
constructor(k, i) {
|
|
601
|
+
privateConstructorCalled(k);
|
|
602
|
+
this[inner] = i;
|
|
603
|
+
}
|
|
604
|
+
get __brand() {
|
|
605
|
+
return "GPUSupportedLimits";
|
|
606
|
+
}
|
|
607
|
+
get maxTextureDimension1D() {
|
|
608
|
+
return this[inner].maxTextureDimension1D();
|
|
609
|
+
}
|
|
610
|
+
get maxTextureDimension2D() {
|
|
611
|
+
return this[inner].maxTextureDimension2D();
|
|
612
|
+
}
|
|
613
|
+
get maxTextureDimension3D() {
|
|
614
|
+
return this[inner].maxTextureDimension3D();
|
|
615
|
+
}
|
|
616
|
+
get maxTextureArrayLayers() {
|
|
617
|
+
return this[inner].maxTextureArrayLayers();
|
|
618
|
+
}
|
|
619
|
+
get maxBindGroups() {
|
|
620
|
+
return this[inner].maxBindGroups();
|
|
621
|
+
}
|
|
622
|
+
get maxBindGroupsPlusVertexBuffers() {
|
|
623
|
+
return this[inner].maxBindGroupsPlusVertexBuffers();
|
|
624
|
+
}
|
|
625
|
+
get maxBindingsPerBindGroup() {
|
|
626
|
+
return this[inner].maxBindingsPerBindGroup();
|
|
627
|
+
}
|
|
628
|
+
get maxDynamicUniformBuffersPerPipelineLayout() {
|
|
629
|
+
return this[inner].maxDynamicUniformBuffersPerPipelineLayout();
|
|
630
|
+
}
|
|
631
|
+
get maxDynamicStorageBuffersPerPipelineLayout() {
|
|
632
|
+
return this[inner].maxDynamicStorageBuffersPerPipelineLayout();
|
|
633
|
+
}
|
|
634
|
+
get maxSampledTexturesPerShaderStage() {
|
|
635
|
+
return this[inner].maxSampledTexturesPerShaderStage();
|
|
636
|
+
}
|
|
637
|
+
get maxSamplersPerShaderStage() {
|
|
638
|
+
return this[inner].maxSamplersPerShaderStage();
|
|
639
|
+
}
|
|
640
|
+
get maxStorageBuffersPerShaderStage() {
|
|
641
|
+
return this[inner].maxStorageBuffersPerShaderStage();
|
|
642
|
+
}
|
|
643
|
+
get maxStorageTexturesPerShaderStage() {
|
|
644
|
+
return this[inner].maxStorageTexturesPerShaderStage();
|
|
645
|
+
}
|
|
646
|
+
get maxUniformBuffersPerShaderStage() {
|
|
647
|
+
return this[inner].maxUniformBuffersPerShaderStage();
|
|
648
|
+
}
|
|
649
|
+
get maxUniformBufferBindingSize() {
|
|
650
|
+
return bigIntToNum(this[inner].maxUniformBufferBindingSize());
|
|
651
|
+
}
|
|
652
|
+
get maxStorageBufferBindingSize() {
|
|
653
|
+
return bigIntToNum(this[inner].maxStorageBufferBindingSize());
|
|
654
|
+
}
|
|
655
|
+
get minUniformBufferOffsetAlignment() {
|
|
656
|
+
return this[inner].minUniformBufferOffsetAlignment();
|
|
657
|
+
}
|
|
658
|
+
get minStorageBufferOffsetAlignment() {
|
|
659
|
+
return this[inner].minStorageBufferOffsetAlignment();
|
|
660
|
+
}
|
|
661
|
+
get maxVertexBuffers() {
|
|
662
|
+
return this[inner].maxVertexBuffers();
|
|
663
|
+
}
|
|
664
|
+
get maxBufferSize() {
|
|
665
|
+
return bigIntToNum(this[inner].maxBufferSize());
|
|
666
|
+
}
|
|
667
|
+
get maxVertexAttributes() {
|
|
668
|
+
return this[inner].maxVertexAttributes();
|
|
669
|
+
}
|
|
670
|
+
get maxVertexBufferArrayStride() {
|
|
671
|
+
return this[inner].maxVertexBufferArrayStride();
|
|
672
|
+
}
|
|
673
|
+
get maxInterStageShaderVariables() {
|
|
674
|
+
return this[inner].maxInterStageShaderVariables();
|
|
675
|
+
}
|
|
676
|
+
get maxColorAttachments() {
|
|
677
|
+
return this[inner].maxColorAttachments();
|
|
678
|
+
}
|
|
679
|
+
get maxColorAttachmentBytesPerSample() {
|
|
680
|
+
return this[inner].maxColorAttachmentBytesPerSample();
|
|
681
|
+
}
|
|
682
|
+
get maxComputeWorkgroupStorageSize() {
|
|
683
|
+
return this[inner].maxComputeWorkgroupStorageSize();
|
|
684
|
+
}
|
|
685
|
+
get maxComputeInvocationsPerWorkgroup() {
|
|
686
|
+
return this[inner].maxComputeInvocationsPerWorkgroup();
|
|
687
|
+
}
|
|
688
|
+
get maxComputeWorkgroupSizeX() {
|
|
689
|
+
return this[inner].maxComputeWorkgroupSizeX();
|
|
690
|
+
}
|
|
691
|
+
get maxComputeWorkgroupSizeY() {
|
|
692
|
+
return this[inner].maxComputeWorkgroupSizeY();
|
|
693
|
+
}
|
|
694
|
+
get maxComputeWorkgroupSizeZ() {
|
|
695
|
+
return this[inner].maxComputeWorkgroupSizeZ();
|
|
696
|
+
}
|
|
697
|
+
get maxComputeWorkgroupsPerDimension() {
|
|
698
|
+
return this[inner].maxComputeWorkgroupsPerDimension();
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
export class GPUAdapterInfo {
|
|
702
|
+
[inner];
|
|
703
|
+
constructor(k, i) {
|
|
704
|
+
privateConstructorCalled(k);
|
|
705
|
+
this[inner] = i;
|
|
706
|
+
}
|
|
707
|
+
get __brand() {
|
|
708
|
+
return "GPUAdapterInfo";
|
|
709
|
+
}
|
|
710
|
+
get vendor() {
|
|
711
|
+
return this[inner].vendor();
|
|
712
|
+
}
|
|
713
|
+
get architecture() {
|
|
714
|
+
return this[inner].architecture();
|
|
715
|
+
}
|
|
716
|
+
get device() {
|
|
717
|
+
return this[inner].device();
|
|
718
|
+
}
|
|
719
|
+
get description() {
|
|
720
|
+
return this[inner].description();
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
export class GPUDevice extends EventTarget {
|
|
724
|
+
[inner];
|
|
725
|
+
constructor(k, i) {
|
|
726
|
+
privateConstructorCalled(k);
|
|
727
|
+
super();
|
|
728
|
+
this[inner] = i;
|
|
729
|
+
}
|
|
730
|
+
get __brand() {
|
|
731
|
+
return "GPUDevice";
|
|
732
|
+
}
|
|
733
|
+
get label() {
|
|
734
|
+
return this[inner].label();
|
|
735
|
+
}
|
|
736
|
+
set label(value) {
|
|
737
|
+
this[inner].setLabel(value);
|
|
738
|
+
}
|
|
739
|
+
get lost() {
|
|
740
|
+
throw new Todo();
|
|
741
|
+
}
|
|
742
|
+
get features() {
|
|
743
|
+
return new GPUSupportedFeatures(key, this[inner].features());
|
|
744
|
+
}
|
|
745
|
+
get limits() {
|
|
746
|
+
return new GPUSupportedLimits(key, this[inner].limits());
|
|
747
|
+
}
|
|
748
|
+
get queue() {
|
|
749
|
+
return new GPUQueue(key, this[inner].queue());
|
|
750
|
+
}
|
|
751
|
+
get adapterInfo() {
|
|
752
|
+
return new GPUAdapterInfo(key, this[inner].adapterInfo());
|
|
753
|
+
}
|
|
754
|
+
destroy() {
|
|
755
|
+
this[inner].destroy();
|
|
756
|
+
}
|
|
757
|
+
createBuffer(descriptor) {
|
|
758
|
+
return new GPUBuffer(key, this[inner].createBuffer({
|
|
759
|
+
...descriptor,
|
|
760
|
+
size: numToBigInt(descriptor.size),
|
|
761
|
+
}));
|
|
762
|
+
}
|
|
763
|
+
createTexture(descriptor) {
|
|
764
|
+
let dimension;
|
|
765
|
+
if (descriptor.dimension)
|
|
766
|
+
dimension = convertTextureDimensionWebToWasi(descriptor.dimension);
|
|
767
|
+
let viewFormats;
|
|
768
|
+
if (descriptor.viewFormats)
|
|
769
|
+
viewFormats = Array.from(descriptor.viewFormats).map(f => convertTextureFormatWebToWasi(f));
|
|
770
|
+
return new GPUTexture(key, this[inner].createTexture({
|
|
771
|
+
...descriptor,
|
|
772
|
+
size: convertExtent3DWebToWasi(descriptor.size),
|
|
773
|
+
format: convertTextureFormatWebToWasi(descriptor.format),
|
|
774
|
+
dimension,
|
|
775
|
+
viewFormats,
|
|
776
|
+
}));
|
|
777
|
+
}
|
|
778
|
+
createSampler(descriptor) {
|
|
779
|
+
return new GPUSampler(key, this[inner].createSampler(descriptor));
|
|
780
|
+
}
|
|
781
|
+
createBindGroupLayout(descriptor) {
|
|
782
|
+
return new GPUBindGroupLayout(key, this[inner].createBindGroupLayout({
|
|
783
|
+
...descriptor,
|
|
784
|
+
entries: Array.from(descriptor.entries).map(entry => {
|
|
785
|
+
let buffer;
|
|
786
|
+
if (entry.buffer) {
|
|
787
|
+
buffer = {
|
|
788
|
+
...entry.buffer,
|
|
789
|
+
minBindingSize: numToBigIntOptional(entry.buffer.minBindingSize),
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
let texture;
|
|
793
|
+
if (entry.texture) {
|
|
794
|
+
let viewDimension;
|
|
795
|
+
if (entry.texture.viewDimension)
|
|
796
|
+
viewDimension = convertTextureViewDimensionWebToWasi(entry.texture.viewDimension);
|
|
797
|
+
texture = {
|
|
798
|
+
...entry.texture,
|
|
799
|
+
viewDimension,
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
let storageTexture;
|
|
803
|
+
if (entry.storageTexture) {
|
|
804
|
+
let viewDimension;
|
|
805
|
+
if (entry.storageTexture.viewDimension)
|
|
806
|
+
viewDimension = convertTextureViewDimensionWebToWasi(entry.storageTexture.viewDimension);
|
|
807
|
+
storageTexture = {
|
|
808
|
+
...entry.storageTexture,
|
|
809
|
+
viewDimension,
|
|
810
|
+
format: convertTextureFormatWebToWasi(entry.storageTexture.format),
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
return {
|
|
814
|
+
...entry,
|
|
815
|
+
buffer,
|
|
816
|
+
texture,
|
|
817
|
+
storageTexture,
|
|
818
|
+
};
|
|
819
|
+
}),
|
|
820
|
+
}));
|
|
821
|
+
}
|
|
822
|
+
createPipelineLayout(descriptor) {
|
|
823
|
+
return new GPUPipelineLayout(key, this[inner].createPipelineLayout({
|
|
824
|
+
...descriptor,
|
|
825
|
+
bindGroupLayouts: Array.from(descriptor.bindGroupLayouts).map(b => b[inner])
|
|
826
|
+
}));
|
|
827
|
+
}
|
|
828
|
+
createBindGroup(descriptor) {
|
|
829
|
+
return new GPUBindGroup(key, this[inner].createBindGroup({
|
|
830
|
+
...descriptor,
|
|
831
|
+
entries: Array.from(descriptor.entries).map(entry => {
|
|
832
|
+
return {
|
|
833
|
+
...entry,
|
|
834
|
+
resource: convertGpuBindingResourceWebToWasi(entry.resource),
|
|
835
|
+
};
|
|
836
|
+
}),
|
|
837
|
+
layout: descriptor.layout[inner],
|
|
838
|
+
}));
|
|
839
|
+
}
|
|
840
|
+
createShaderModule(descriptor) {
|
|
841
|
+
let compilationHints;
|
|
842
|
+
if (descriptor.compilationHints) {
|
|
843
|
+
compilationHints = descriptor.compilationHints.map(hint => {
|
|
844
|
+
let layout;
|
|
845
|
+
if (hint.layout) {
|
|
846
|
+
layout = convertGpuLayoutWebToWasi(hint.layout);
|
|
847
|
+
}
|
|
848
|
+
return {
|
|
849
|
+
...hint,
|
|
850
|
+
layout,
|
|
851
|
+
};
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
return new GPUShaderModule(key, this[inner].createShaderModule({
|
|
855
|
+
...descriptor,
|
|
856
|
+
compilationHints,
|
|
857
|
+
}));
|
|
858
|
+
}
|
|
859
|
+
createComputePipeline(descriptor) {
|
|
860
|
+
let compute = {
|
|
861
|
+
module: descriptor.compute.module[inner],
|
|
862
|
+
entryPoint: descriptor.compute.entryPoint,
|
|
863
|
+
constants: undefined, // TODO:
|
|
864
|
+
};
|
|
865
|
+
return new GPUComputePipeline(key, this[inner].createComputePipeline({
|
|
866
|
+
...descriptor,
|
|
867
|
+
compute,
|
|
868
|
+
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
869
|
+
}));
|
|
870
|
+
}
|
|
871
|
+
createRenderPipeline(descriptor) {
|
|
872
|
+
let buffers = undefined;
|
|
873
|
+
if (descriptor.vertex.buffers) {
|
|
874
|
+
buffers = Array.from(descriptor.vertex.buffers).map(vbl => {
|
|
875
|
+
if (vbl) {
|
|
876
|
+
return {
|
|
877
|
+
...vbl,
|
|
878
|
+
arrayStride: numToBigInt(vbl.arrayStride),
|
|
879
|
+
attributes: Array.from(vbl.attributes).map(attribute => {
|
|
880
|
+
return {
|
|
881
|
+
...attribute,
|
|
882
|
+
offset: numToBigInt(attribute.offset),
|
|
883
|
+
format: convertVertexFormatWebToWasi(attribute.format),
|
|
884
|
+
};
|
|
885
|
+
}),
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
else {
|
|
889
|
+
return undefined;
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
const vertex = {
|
|
894
|
+
...descriptor.vertex,
|
|
895
|
+
constants: undefined, // TODO:
|
|
896
|
+
module: descriptor.vertex.module[inner],
|
|
897
|
+
buffers,
|
|
898
|
+
};
|
|
899
|
+
let depthStencil;
|
|
900
|
+
if (descriptor.depthStencil) {
|
|
901
|
+
depthStencil = {
|
|
902
|
+
...descriptor.depthStencil,
|
|
903
|
+
format: convertTextureFormatWebToWasi(descriptor.depthStencil.format),
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
let fragment;
|
|
907
|
+
if (descriptor.fragment) {
|
|
908
|
+
fragment = {
|
|
909
|
+
...descriptor.fragment,
|
|
910
|
+
constants: undefined, // TODO:
|
|
911
|
+
module: descriptor.fragment.module[inner],
|
|
912
|
+
targets: Array.from(descriptor.fragment.targets).map(target => {
|
|
913
|
+
if (target) {
|
|
914
|
+
return {
|
|
915
|
+
...target,
|
|
916
|
+
format: convertTextureFormatWebToWasi(target.format),
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
else {
|
|
920
|
+
return undefined;
|
|
921
|
+
}
|
|
922
|
+
}),
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
return new GPURenderPipeline(key, this[inner].createRenderPipeline({
|
|
926
|
+
...descriptor,
|
|
927
|
+
vertex,
|
|
928
|
+
depthStencil,
|
|
929
|
+
fragment,
|
|
930
|
+
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
931
|
+
}));
|
|
932
|
+
}
|
|
933
|
+
async createComputePipelineAsync(_descriptor) {
|
|
934
|
+
throw new Todo();
|
|
935
|
+
}
|
|
936
|
+
async createRenderPipelineAsync(descriptor) {
|
|
937
|
+
throw new Todo();
|
|
938
|
+
}
|
|
939
|
+
createCommandEncoder(descriptor = {}) {
|
|
940
|
+
return new GPUCommandEncoder(key, this[inner].createCommandEncoder(descriptor));
|
|
941
|
+
}
|
|
942
|
+
createRenderBundleEncoder(descriptor) {
|
|
943
|
+
let depthStencilFormat;
|
|
944
|
+
if (descriptor.depthStencilFormat)
|
|
945
|
+
depthStencilFormat = convertTextureFormatWebToWasi(descriptor.depthStencilFormat);
|
|
946
|
+
return new GPURenderBundleEncoder(key, this[inner].createRenderBundleEncoder({
|
|
947
|
+
...descriptor,
|
|
948
|
+
colorFormats: Array.from(descriptor.colorFormats).map(colorFormat => {
|
|
949
|
+
if (colorFormat) {
|
|
950
|
+
return convertTextureFormatWebToWasi(colorFormat);
|
|
951
|
+
}
|
|
952
|
+
{
|
|
953
|
+
return undefined;
|
|
954
|
+
}
|
|
955
|
+
}),
|
|
956
|
+
depthStencilFormat,
|
|
957
|
+
}));
|
|
958
|
+
}
|
|
959
|
+
createQuerySet(descriptor) {
|
|
960
|
+
return new GPUQuerySet(key, this[inner].createQuerySet(descriptor));
|
|
961
|
+
}
|
|
962
|
+
pushErrorScope(filter) {
|
|
963
|
+
this[inner].pushErrorScope(filter);
|
|
964
|
+
}
|
|
965
|
+
async popErrorScope() {
|
|
966
|
+
throw new Todo();
|
|
967
|
+
}
|
|
968
|
+
importExternalTexture(descriptor) {
|
|
969
|
+
throw new Todo;
|
|
970
|
+
}
|
|
971
|
+
onuncapturederror = null;
|
|
972
|
+
}
|
|
973
|
+
export class GPURenderBundleEncoder {
|
|
974
|
+
[inner];
|
|
975
|
+
constructor(k, i) {
|
|
976
|
+
privateConstructorCalled(k);
|
|
977
|
+
this[inner] = i;
|
|
978
|
+
}
|
|
979
|
+
get __brand() {
|
|
980
|
+
return "GPURenderBundleEncoder";
|
|
981
|
+
}
|
|
982
|
+
get label() {
|
|
983
|
+
return this[inner].label();
|
|
984
|
+
}
|
|
985
|
+
set label(value) {
|
|
986
|
+
this[inner].setLabel(value);
|
|
987
|
+
}
|
|
988
|
+
finish(descriptor) {
|
|
989
|
+
return new GPURenderBundle(key, this[inner].finish(descriptor));
|
|
990
|
+
}
|
|
991
|
+
pushDebugGroup(groupLabel) {
|
|
992
|
+
this[inner].pushDebugGroup(groupLabel);
|
|
993
|
+
}
|
|
994
|
+
popDebugGroup() {
|
|
995
|
+
this[inner].popDebugGroup();
|
|
996
|
+
}
|
|
997
|
+
insertDebugMarker(markerLabel) {
|
|
998
|
+
this[inner].insertDebugMarker(markerLabel);
|
|
999
|
+
}
|
|
1000
|
+
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1001
|
+
throw new Todo;
|
|
1002
|
+
}
|
|
1003
|
+
setPipeline(pipeline) {
|
|
1004
|
+
this[inner].setPipeline(pipeline[inner]);
|
|
1005
|
+
}
|
|
1006
|
+
setIndexBuffer(buffer, indexFormat, offset, size) {
|
|
1007
|
+
this[inner].setIndexBuffer(buffer[inner], indexFormat, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1008
|
+
}
|
|
1009
|
+
setVertexBuffer(slot, buffer, offset, size) {
|
|
1010
|
+
this[inner].setVertexBuffer(slot, buffer[inner], numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1011
|
+
}
|
|
1012
|
+
draw(vertexCount, instanceCount, firstVertex, firstInstance) {
|
|
1013
|
+
this[inner].draw(vertexCount, instanceCount, firstVertex, firstInstance);
|
|
1014
|
+
}
|
|
1015
|
+
drawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance) {
|
|
1016
|
+
this[inner].drawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance);
|
|
1017
|
+
}
|
|
1018
|
+
drawIndirect(indirectBuffer, indirectOffset) {
|
|
1019
|
+
this[inner].drawIndirect(indirectBuffer[inner], numToBigInt(indirectOffset));
|
|
1020
|
+
}
|
|
1021
|
+
drawIndexedIndirect(indirectBuffer, indirectOffset) {
|
|
1022
|
+
this[inner].drawIndexedIndirect(indirectBuffer[inner], numToBigInt(indirectOffset));
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
export class GPURenderBundle {
|
|
1026
|
+
[inner];
|
|
1027
|
+
constructor(k, i) {
|
|
1028
|
+
privateConstructorCalled(k);
|
|
1029
|
+
this[inner] = i;
|
|
1030
|
+
}
|
|
1031
|
+
get __brand() {
|
|
1032
|
+
return "GPURenderBundle";
|
|
1033
|
+
}
|
|
1034
|
+
get label() {
|
|
1035
|
+
return this[inner].label();
|
|
1036
|
+
}
|
|
1037
|
+
set label(value) {
|
|
1038
|
+
this[inner].setLabel(value);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
export class GPUShaderModule {
|
|
1042
|
+
[inner];
|
|
1043
|
+
constructor(k, i) {
|
|
1044
|
+
privateConstructorCalled(k);
|
|
1045
|
+
this[inner] = i;
|
|
1046
|
+
}
|
|
1047
|
+
get __brand() {
|
|
1048
|
+
return "GPUShaderModule";
|
|
1049
|
+
}
|
|
1050
|
+
get label() {
|
|
1051
|
+
return this[inner].label();
|
|
1052
|
+
}
|
|
1053
|
+
set label(value) {
|
|
1054
|
+
this[inner].setLabel(value);
|
|
1055
|
+
}
|
|
1056
|
+
getCompilationInfo() {
|
|
1057
|
+
throw new Todo();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
export class GPUComputePipeline {
|
|
1061
|
+
[inner];
|
|
1062
|
+
constructor(k, i) {
|
|
1063
|
+
privateConstructorCalled(k);
|
|
1064
|
+
this[inner] = i;
|
|
1065
|
+
}
|
|
1066
|
+
get __brand() {
|
|
1067
|
+
return "GPUComputePipeline";
|
|
1068
|
+
}
|
|
1069
|
+
get label() {
|
|
1070
|
+
return this[inner].label();
|
|
1071
|
+
}
|
|
1072
|
+
set label(value) {
|
|
1073
|
+
this[inner].setLabel(value);
|
|
1074
|
+
}
|
|
1075
|
+
getBindGroupLayout(index) {
|
|
1076
|
+
return new GPUBindGroupLayout(key, this[inner].getBindGroupLayout(index));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
export class GPUPipelineLayout {
|
|
1080
|
+
[inner];
|
|
1081
|
+
constructor(k, i) {
|
|
1082
|
+
privateConstructorCalled(k);
|
|
1083
|
+
this[inner] = i;
|
|
1084
|
+
}
|
|
1085
|
+
get __brand() {
|
|
1086
|
+
return "GPUPipelineLayout";
|
|
1087
|
+
}
|
|
1088
|
+
get label() {
|
|
1089
|
+
return this[inner].label();
|
|
1090
|
+
}
|
|
1091
|
+
set label(value) {
|
|
1092
|
+
this[inner].setLabel(value);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
export class GPURenderPipeline {
|
|
1096
|
+
[inner];
|
|
1097
|
+
constructor(k, i) {
|
|
1098
|
+
privateConstructorCalled(k);
|
|
1099
|
+
this[inner] = i;
|
|
1100
|
+
}
|
|
1101
|
+
get __brand() {
|
|
1102
|
+
return "GPURenderPipeline";
|
|
1103
|
+
}
|
|
1104
|
+
get label() {
|
|
1105
|
+
return this[inner].label();
|
|
1106
|
+
}
|
|
1107
|
+
set label(value) {
|
|
1108
|
+
this[inner].setLabel(value);
|
|
1109
|
+
}
|
|
1110
|
+
getBindGroupLayout(index) {
|
|
1111
|
+
return new GPUBindGroupLayout(key, this[inner].getBindGroupLayout(index));
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
export class GPUBuffer {
|
|
1115
|
+
[inner];
|
|
1116
|
+
_mappedRangeBuffer;
|
|
1117
|
+
_mappedRangeOffset;
|
|
1118
|
+
_mappedRangeSize;
|
|
1119
|
+
constructor(k, i) {
|
|
1120
|
+
privateConstructorCalled(k);
|
|
1121
|
+
this[inner] = i;
|
|
1122
|
+
}
|
|
1123
|
+
get __brand() {
|
|
1124
|
+
return "GPUBuffer";
|
|
1125
|
+
}
|
|
1126
|
+
get label() {
|
|
1127
|
+
return this[inner].label();
|
|
1128
|
+
}
|
|
1129
|
+
set label(value) {
|
|
1130
|
+
this[inner].setLabel(value);
|
|
1131
|
+
}
|
|
1132
|
+
get size() {
|
|
1133
|
+
return bigIntToNum(this[inner].size());
|
|
1134
|
+
}
|
|
1135
|
+
get usage() {
|
|
1136
|
+
return this[inner].usage();
|
|
1137
|
+
}
|
|
1138
|
+
get mapState() {
|
|
1139
|
+
return this[inner].mapState();
|
|
1140
|
+
}
|
|
1141
|
+
async mapAsync(mode, offset, size) {
|
|
1142
|
+
this[inner].mapAsync(mode, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1143
|
+
}
|
|
1144
|
+
getMappedRange(offset, size) {
|
|
1145
|
+
this._mappedRangeBuffer = this[inner].getMappedRangeGetWithCopy(numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1146
|
+
this._mappedRangeOffset = numToBigIntOptional(offset);
|
|
1147
|
+
this._mappedRangeSize = numToBigIntOptional(size);
|
|
1148
|
+
return this._mappedRangeBuffer.buffer;
|
|
1149
|
+
}
|
|
1150
|
+
unmap() {
|
|
1151
|
+
if (!this._mappedRangeBuffer) {
|
|
1152
|
+
throw new Todo();
|
|
1153
|
+
}
|
|
1154
|
+
this[inner].getMappedRangeSetWithCopy(this._mappedRangeBuffer, this._mappedRangeOffset, this._mappedRangeSize);
|
|
1155
|
+
this._mappedRangeBuffer = undefined;
|
|
1156
|
+
this._mappedRangeOffset = undefined;
|
|
1157
|
+
this._mappedRangeSize = undefined;
|
|
1158
|
+
this[inner].unmap();
|
|
1159
|
+
}
|
|
1160
|
+
destroy() {
|
|
1161
|
+
this[inner].destroy();
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
export class GPUQueue {
|
|
1165
|
+
[inner];
|
|
1166
|
+
constructor(k, i) {
|
|
1167
|
+
privateConstructorCalled(k);
|
|
1168
|
+
this[inner] = i;
|
|
1169
|
+
}
|
|
1170
|
+
get __brand() {
|
|
1171
|
+
return "GPUQueue";
|
|
1172
|
+
}
|
|
1173
|
+
get label() {
|
|
1174
|
+
return this[inner].label();
|
|
1175
|
+
}
|
|
1176
|
+
set label(value) {
|
|
1177
|
+
this[inner].setLabel(value);
|
|
1178
|
+
}
|
|
1179
|
+
submit(commandBuffers) {
|
|
1180
|
+
this[inner].submit(Array.from(commandBuffers).map((cb) => cb[inner]));
|
|
1181
|
+
}
|
|
1182
|
+
onSubmittedWorkDone() {
|
|
1183
|
+
throw new Todo();
|
|
1184
|
+
}
|
|
1185
|
+
writeBuffer(buffer, bufferOffset, data, dataOffset, size) {
|
|
1186
|
+
this[inner].writeBufferWithCopy(buffer[inner], numToBigInt(bufferOffset), convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(size));
|
|
1187
|
+
}
|
|
1188
|
+
writeTexture(destination, data, dataLayout, size) {
|
|
1189
|
+
let destinationTexture = destination.texture[inner];
|
|
1190
|
+
let destinationOrigin;
|
|
1191
|
+
if (destination.origin) {
|
|
1192
|
+
destinationOrigin = convertOrigin3DWebToWasi(destination.origin);
|
|
1193
|
+
}
|
|
1194
|
+
this[inner].writeTextureWithCopy({
|
|
1195
|
+
...destination,
|
|
1196
|
+
texture: destinationTexture,
|
|
1197
|
+
origin: destinationOrigin,
|
|
1198
|
+
}, convertBufferToUint8Array(data), {
|
|
1199
|
+
...dataLayout,
|
|
1200
|
+
offset: numToBigIntOptional(dataLayout.offset)
|
|
1201
|
+
}, convertExtent3DWebToWasi(size));
|
|
1202
|
+
}
|
|
1203
|
+
copyExternalImageToTexture(source, destination, copySize) {
|
|
1204
|
+
throw new Todo();
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
export class GPUBindGroupLayout {
|
|
1208
|
+
[inner];
|
|
1209
|
+
constructor(k, i) {
|
|
1210
|
+
privateConstructorCalled(k);
|
|
1211
|
+
this[inner] = i;
|
|
1212
|
+
}
|
|
1213
|
+
get __brand() {
|
|
1214
|
+
return "GPUBindGroupLayout";
|
|
1215
|
+
}
|
|
1216
|
+
get label() {
|
|
1217
|
+
return this[inner].label();
|
|
1218
|
+
}
|
|
1219
|
+
set label(value) {
|
|
1220
|
+
this[inner].setLabel(value);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
export class GPUBindGroup {
|
|
1224
|
+
[inner];
|
|
1225
|
+
constructor(k, i) {
|
|
1226
|
+
privateConstructorCalled(k);
|
|
1227
|
+
this[inner] = i;
|
|
1228
|
+
}
|
|
1229
|
+
get __brand() {
|
|
1230
|
+
return "GPUBindGroup";
|
|
1231
|
+
}
|
|
1232
|
+
get label() {
|
|
1233
|
+
return this[inner].label();
|
|
1234
|
+
}
|
|
1235
|
+
set label(value) {
|
|
1236
|
+
this[inner].setLabel(value);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
export class GPUSampler {
|
|
1240
|
+
[inner];
|
|
1241
|
+
constructor(k, i) {
|
|
1242
|
+
privateConstructorCalled(k);
|
|
1243
|
+
this[inner] = i;
|
|
1244
|
+
}
|
|
1245
|
+
get __brand() {
|
|
1246
|
+
return "GPUSampler";
|
|
1247
|
+
}
|
|
1248
|
+
get label() {
|
|
1249
|
+
return this[inner].label();
|
|
1250
|
+
}
|
|
1251
|
+
set label(value) {
|
|
1252
|
+
this[inner].setLabel(value);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
export class GPUTextureView {
|
|
1256
|
+
[inner];
|
|
1257
|
+
constructor(k, i) {
|
|
1258
|
+
privateConstructorCalled(k);
|
|
1259
|
+
this[inner] = i;
|
|
1260
|
+
}
|
|
1261
|
+
get __brand() {
|
|
1262
|
+
return "GPUTextureView";
|
|
1263
|
+
}
|
|
1264
|
+
get label() {
|
|
1265
|
+
return this[inner].label();
|
|
1266
|
+
}
|
|
1267
|
+
set label(value) {
|
|
1268
|
+
this[inner].setLabel(value);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
export class GPUTexture {
|
|
1272
|
+
[inner];
|
|
1273
|
+
constructor(k, i) {
|
|
1274
|
+
privateConstructorCalled(k);
|
|
1275
|
+
this[inner] = i;
|
|
1276
|
+
}
|
|
1277
|
+
get __brand() {
|
|
1278
|
+
return "GPUTexture";
|
|
1279
|
+
}
|
|
1280
|
+
get label() {
|
|
1281
|
+
return this[inner].label();
|
|
1282
|
+
}
|
|
1283
|
+
set label(value) {
|
|
1284
|
+
this[inner].setLabel(value);
|
|
1285
|
+
}
|
|
1286
|
+
get width() {
|
|
1287
|
+
return this[inner].width();
|
|
1288
|
+
}
|
|
1289
|
+
get height() {
|
|
1290
|
+
return this[inner].height();
|
|
1291
|
+
}
|
|
1292
|
+
get depthOrArrayLayers() {
|
|
1293
|
+
return this[inner].depthOrArrayLayers();
|
|
1294
|
+
}
|
|
1295
|
+
get mipLevelCount() {
|
|
1296
|
+
return this[inner].mipLevelCount();
|
|
1297
|
+
}
|
|
1298
|
+
get sampleCount() {
|
|
1299
|
+
return this[inner].sampleCount();
|
|
1300
|
+
}
|
|
1301
|
+
get dimension() {
|
|
1302
|
+
return convertTextureDimensionWasiToWeb(this[inner].dimension());
|
|
1303
|
+
}
|
|
1304
|
+
get format() {
|
|
1305
|
+
return convertTextureFormatWasiToWeb(this[inner].format());
|
|
1306
|
+
}
|
|
1307
|
+
get usage() {
|
|
1308
|
+
return this[inner].usage();
|
|
1309
|
+
}
|
|
1310
|
+
createView(descriptor) {
|
|
1311
|
+
let gfxDescriptor;
|
|
1312
|
+
if (descriptor) {
|
|
1313
|
+
let format;
|
|
1314
|
+
if (descriptor.format)
|
|
1315
|
+
format = convertTextureFormatWebToWasi(descriptor.format);
|
|
1316
|
+
let dimension;
|
|
1317
|
+
if (descriptor.dimension)
|
|
1318
|
+
dimension = convertTextureViewDimensionWebToWasi(descriptor.dimension);
|
|
1319
|
+
gfxDescriptor = {
|
|
1320
|
+
...descriptor,
|
|
1321
|
+
dimension,
|
|
1322
|
+
format,
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
return new GPUTextureView(key, this[inner].createView(gfxDescriptor));
|
|
1326
|
+
}
|
|
1327
|
+
destroy() {
|
|
1328
|
+
this[inner].destroy();
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
export class GPUCommandEncoder {
|
|
1332
|
+
[inner];
|
|
1333
|
+
constructor(k, i) {
|
|
1334
|
+
privateConstructorCalled(k);
|
|
1335
|
+
this[inner] = i;
|
|
1336
|
+
}
|
|
1337
|
+
get __brand() {
|
|
1338
|
+
return "GPUCommandEncoder";
|
|
1339
|
+
}
|
|
1340
|
+
get label() {
|
|
1341
|
+
return this[inner].label();
|
|
1342
|
+
}
|
|
1343
|
+
set label(value) {
|
|
1344
|
+
this[inner].setLabel(value);
|
|
1345
|
+
}
|
|
1346
|
+
beginRenderPass(descriptor) {
|
|
1347
|
+
let colorAttachments = Array.from(descriptor.colorAttachments).map(colorAttachment => {
|
|
1348
|
+
let resolveTarget;
|
|
1349
|
+
if (colorAttachment?.resolveTarget)
|
|
1350
|
+
resolveTarget = colorAttachment.resolveTarget[inner];
|
|
1351
|
+
let clearValue;
|
|
1352
|
+
if (colorAttachment?.clearValue)
|
|
1353
|
+
clearValue = convertColorWebToWasi(colorAttachment.clearValue);
|
|
1354
|
+
if (colorAttachment) {
|
|
1355
|
+
return {
|
|
1356
|
+
...colorAttachment,
|
|
1357
|
+
view: colorAttachment.view[inner],
|
|
1358
|
+
resolveTarget,
|
|
1359
|
+
clearValue,
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
else {
|
|
1363
|
+
return undefined;
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
return new GPURenderPassEncoder(key, this[inner].beginRenderPass({
|
|
1367
|
+
colorAttachments
|
|
1368
|
+
}));
|
|
1369
|
+
}
|
|
1370
|
+
beginComputePass(descriptor) {
|
|
1371
|
+
let timestampWrites;
|
|
1372
|
+
if (descriptor?.timestampWrites) {
|
|
1373
|
+
timestampWrites = {
|
|
1374
|
+
...timestampWrites,
|
|
1375
|
+
querySet: descriptor.timestampWrites.querySet[inner],
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
return new GPUComputePassEncoder(key, this[inner].beginComputePass({
|
|
1379
|
+
...descriptor,
|
|
1380
|
+
timestampWrites,
|
|
1381
|
+
}));
|
|
1382
|
+
}
|
|
1383
|
+
copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) {
|
|
1384
|
+
this[inner].copyBufferToBuffer(source[inner], numToBigInt(sourceOffset), destination[inner], numToBigInt(destinationOffset), numToBigInt(size));
|
|
1385
|
+
}
|
|
1386
|
+
copyBufferToTexture(source, destination, copySize) {
|
|
1387
|
+
let destinationOrigin;
|
|
1388
|
+
if (destination.origin)
|
|
1389
|
+
destinationOrigin = convertOrigin3DWebToWasi(destination.origin);
|
|
1390
|
+
this[inner].copyBufferToTexture({
|
|
1391
|
+
...source,
|
|
1392
|
+
buffer: source.buffer[inner],
|
|
1393
|
+
offset: numToBigIntOptional(source.offset)
|
|
1394
|
+
}, {
|
|
1395
|
+
...destination,
|
|
1396
|
+
texture: destination.texture[inner],
|
|
1397
|
+
origin: destinationOrigin,
|
|
1398
|
+
}, convertExtent3DWebToWasi(copySize));
|
|
1399
|
+
}
|
|
1400
|
+
copyTextureToBuffer(source, destination, copySize) {
|
|
1401
|
+
let sourceOrigin;
|
|
1402
|
+
if (source.origin)
|
|
1403
|
+
sourceOrigin = convertOrigin3DWebToWasi(source.origin);
|
|
1404
|
+
this[inner].copyTextureToBuffer({
|
|
1405
|
+
...source,
|
|
1406
|
+
texture: source.texture[inner],
|
|
1407
|
+
origin: sourceOrigin
|
|
1408
|
+
}, {
|
|
1409
|
+
...destination,
|
|
1410
|
+
buffer: destination.buffer[inner],
|
|
1411
|
+
offset: numToBigIntOptional(destination.offset),
|
|
1412
|
+
}, convertExtent3DWebToWasi(copySize));
|
|
1413
|
+
}
|
|
1414
|
+
copyTextureToTexture(source, destination, copySize) {
|
|
1415
|
+
let sourceOrigin;
|
|
1416
|
+
if (source.origin)
|
|
1417
|
+
sourceOrigin = convertOrigin3DWebToWasi(source.origin);
|
|
1418
|
+
let destinationOrigin;
|
|
1419
|
+
if (destination.origin)
|
|
1420
|
+
destinationOrigin = convertOrigin3DWebToWasi(destination.origin);
|
|
1421
|
+
this[inner].copyTextureToTexture({
|
|
1422
|
+
...source,
|
|
1423
|
+
texture: source.texture[inner],
|
|
1424
|
+
origin: sourceOrigin
|
|
1425
|
+
}, {
|
|
1426
|
+
...destination,
|
|
1427
|
+
texture: destination.texture[inner],
|
|
1428
|
+
origin: destinationOrigin,
|
|
1429
|
+
}, convertExtent3DWebToWasi(copySize));
|
|
1430
|
+
}
|
|
1431
|
+
clearBuffer(buffer, offset, size) {
|
|
1432
|
+
this[inner].clearBuffer(buffer[inner], numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1433
|
+
}
|
|
1434
|
+
resolveQuerySet(querySet, firstQuery, queryCount, destination, destinationOffset) {
|
|
1435
|
+
this[inner].resolveQuerySet(querySet[inner], firstQuery, queryCount, destination[inner], numToBigInt(destinationOffset));
|
|
1436
|
+
}
|
|
1437
|
+
finish(descriptor) {
|
|
1438
|
+
return new GPUCommandBuffer(key, this[inner].finish(descriptor));
|
|
1439
|
+
}
|
|
1440
|
+
pushDebugGroup(groupLabel) {
|
|
1441
|
+
this[inner].pushDebugGroup(groupLabel);
|
|
1442
|
+
}
|
|
1443
|
+
popDebugGroup() {
|
|
1444
|
+
this[inner].popDebugGroup();
|
|
1445
|
+
}
|
|
1446
|
+
insertDebugMarker(markerLabel) {
|
|
1447
|
+
this[inner].insertDebugMarker(markerLabel);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
export class GPUComputePassEncoder {
|
|
1451
|
+
[inner];
|
|
1452
|
+
constructor(k, i) {
|
|
1453
|
+
privateConstructorCalled(k);
|
|
1454
|
+
this[inner] = i;
|
|
1455
|
+
}
|
|
1456
|
+
get __brand() {
|
|
1457
|
+
return "GPUComputePassEncoder";
|
|
1458
|
+
}
|
|
1459
|
+
get label() {
|
|
1460
|
+
return this[inner].label();
|
|
1461
|
+
}
|
|
1462
|
+
set label(value) {
|
|
1463
|
+
this[inner].setLabel(value);
|
|
1464
|
+
}
|
|
1465
|
+
setPipeline(pipeline) {
|
|
1466
|
+
this[inner].setPipeline(pipeline[inner]);
|
|
1467
|
+
}
|
|
1468
|
+
dispatchWorkgroups(workgroupCountX, workgroupCountY, workgroupCountZ) {
|
|
1469
|
+
this[inner].dispatchWorkgroups(workgroupCountX, workgroupCountY, workgroupCountZ);
|
|
1470
|
+
}
|
|
1471
|
+
dispatchWorkgroupsIndirect(indirectBuffer, indirectOffset) {
|
|
1472
|
+
this[inner].dispatchWorkgroupsIndirect(indirectBuffer[inner], numToBigInt(indirectOffset));
|
|
1473
|
+
}
|
|
1474
|
+
end() {
|
|
1475
|
+
this[inner].end();
|
|
1476
|
+
}
|
|
1477
|
+
pushDebugGroup(groupLabel) {
|
|
1478
|
+
this[inner].pushDebugGroup(groupLabel);
|
|
1479
|
+
}
|
|
1480
|
+
popDebugGroup() {
|
|
1481
|
+
this[inner].popDebugGroup();
|
|
1482
|
+
}
|
|
1483
|
+
insertDebugMarker(markerLabel) {
|
|
1484
|
+
this[inner].insertDebugMarker(markerLabel);
|
|
1485
|
+
}
|
|
1486
|
+
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1487
|
+
let bindGroupGfx;
|
|
1488
|
+
if (bindGroup)
|
|
1489
|
+
bindGroupGfx = bindGroup[inner];
|
|
1490
|
+
if ((dynamicOffsetsData === undefined || dynamicOffsetsData[Symbol.iterator]) && dynamicOffsetsDataStart === undefined && dynamicOffsetsDataLength === undefined) {
|
|
1491
|
+
let dynamicOffsetsDataGfx;
|
|
1492
|
+
if (dynamicOffsetsData) {
|
|
1493
|
+
if (dynamicOffsetsData instanceof Uint32Array) {
|
|
1494
|
+
dynamicOffsetsDataGfx = dynamicOffsetsData;
|
|
1495
|
+
}
|
|
1496
|
+
else {
|
|
1497
|
+
dynamicOffsetsDataGfx = new Uint32Array(dynamicOffsetsData);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
this[inner].setBindGroup(index, bindGroupGfx, dynamicOffsetsDataGfx, dynamicOffsetsDataStart, dynamicOffsetsDataLength);
|
|
1501
|
+
}
|
|
1502
|
+
else if (dynamicOffsetsData instanceof Uint32Array && typeof dynamicOffsetsDataStart === "number" && typeof dynamicOffsetsDataLength === "number") {
|
|
1503
|
+
this[inner].setBindGroup(index, bindGroupGfx, dynamicOffsetsData, numToBigInt(dynamicOffsetsDataStart), dynamicOffsetsDataLength);
|
|
1504
|
+
}
|
|
1505
|
+
else {
|
|
1506
|
+
throw new Todo;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
export class GPURenderPassEncoder {
|
|
1511
|
+
[inner];
|
|
1512
|
+
constructor(k, i) {
|
|
1513
|
+
privateConstructorCalled(k);
|
|
1514
|
+
this[inner] = i;
|
|
1515
|
+
}
|
|
1516
|
+
get __brand() {
|
|
1517
|
+
return "GPURenderPassEncoder";
|
|
1518
|
+
}
|
|
1519
|
+
get label() {
|
|
1520
|
+
return this[inner].label();
|
|
1521
|
+
}
|
|
1522
|
+
set label(value) {
|
|
1523
|
+
this[inner].setLabel(value);
|
|
1524
|
+
}
|
|
1525
|
+
setViewport(x, y, width, height, minDepth, maxDepth) {
|
|
1526
|
+
this[inner].setViewport(x, y, width, height, minDepth, maxDepth);
|
|
1527
|
+
}
|
|
1528
|
+
setScissorRect(x, y, width, height) {
|
|
1529
|
+
this[inner].setScissorRect(x, y, width, height);
|
|
1530
|
+
}
|
|
1531
|
+
setBlendConstant(color) {
|
|
1532
|
+
this[inner].setBlendConstant(convertColorWebToWasi(color));
|
|
1533
|
+
}
|
|
1534
|
+
setStencilReference(reference) {
|
|
1535
|
+
this[inner].setStencilReference(reference);
|
|
1536
|
+
}
|
|
1537
|
+
beginOcclusionQuery(queryIndex) {
|
|
1538
|
+
this[inner].beginOcclusionQuery(queryIndex);
|
|
1539
|
+
}
|
|
1540
|
+
endOcclusionQuery() {
|
|
1541
|
+
this[inner].endOcclusionQuery();
|
|
1542
|
+
}
|
|
1543
|
+
executeBundles(bundles) {
|
|
1544
|
+
this[inner].executeBundles(Array.from(bundles).map(bundle => bundle[inner]));
|
|
1545
|
+
}
|
|
1546
|
+
end() {
|
|
1547
|
+
this[inner].end();
|
|
1548
|
+
}
|
|
1549
|
+
pushDebugGroup(groupLabel) {
|
|
1550
|
+
this[inner].pushDebugGroup(groupLabel);
|
|
1551
|
+
}
|
|
1552
|
+
popDebugGroup() {
|
|
1553
|
+
this[inner].popDebugGroup();
|
|
1554
|
+
}
|
|
1555
|
+
insertDebugMarker(markerLabel) {
|
|
1556
|
+
this[inner].insertDebugMarker(markerLabel);
|
|
1557
|
+
}
|
|
1558
|
+
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1559
|
+
throw new Todo;
|
|
1560
|
+
}
|
|
1561
|
+
setPipeline(pipeline) {
|
|
1562
|
+
this[inner].setPipeline(pipeline[inner]);
|
|
1563
|
+
}
|
|
1564
|
+
setIndexBuffer(buffer, indexFormat, offset, size) {
|
|
1565
|
+
this[inner].setIndexBuffer(buffer[inner], indexFormat, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1566
|
+
}
|
|
1567
|
+
setVertexBuffer(slot, buffer, offset, size) {
|
|
1568
|
+
let gfxBuffer;
|
|
1569
|
+
if (buffer)
|
|
1570
|
+
gfxBuffer = buffer[inner];
|
|
1571
|
+
this[inner].setVertexBuffer(slot, gfxBuffer, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1572
|
+
}
|
|
1573
|
+
draw(vertexCount, instanceCount, firstVertex, firstInstance) {
|
|
1574
|
+
this[inner].draw(vertexCount, instanceCount, firstVertex, firstInstance);
|
|
1575
|
+
}
|
|
1576
|
+
drawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance) {
|
|
1577
|
+
this[inner].drawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance);
|
|
1578
|
+
}
|
|
1579
|
+
drawIndirect(indirectBuffer, indirectOffset) {
|
|
1580
|
+
this[inner].drawIndirect(indirectBuffer[inner], numToBigInt(indirectOffset));
|
|
1581
|
+
}
|
|
1582
|
+
drawIndexedIndirect(indirectBuffer, indirectOffset) {
|
|
1583
|
+
this[inner].drawIndexedIndirect(indirectBuffer[inner], numToBigInt(indirectOffset));
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
export class GPUQuerySet {
|
|
1587
|
+
[inner];
|
|
1588
|
+
constructor(k, i) {
|
|
1589
|
+
privateConstructorCalled(k);
|
|
1590
|
+
this[inner] = i;
|
|
1591
|
+
}
|
|
1592
|
+
destroy() {
|
|
1593
|
+
this[inner].destroy();
|
|
1594
|
+
}
|
|
1595
|
+
get __brand() {
|
|
1596
|
+
return "GPUQuerySet";
|
|
1597
|
+
}
|
|
1598
|
+
get label() {
|
|
1599
|
+
return this[inner].label();
|
|
1600
|
+
}
|
|
1601
|
+
set label(value) {
|
|
1602
|
+
this[inner].setLabel(value);
|
|
1603
|
+
}
|
|
1604
|
+
get type() {
|
|
1605
|
+
return this[inner].type();
|
|
1606
|
+
}
|
|
1607
|
+
get count() {
|
|
1608
|
+
return this[inner].count();
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
export class GPUCommandBuffer {
|
|
1612
|
+
[inner];
|
|
1613
|
+
constructor(k, i) {
|
|
1614
|
+
privateConstructorCalled(k);
|
|
1615
|
+
this[inner] = i;
|
|
1616
|
+
}
|
|
1617
|
+
get __brand() {
|
|
1618
|
+
return "GPUCommandBuffer";
|
|
1619
|
+
}
|
|
1620
|
+
get label() {
|
|
1621
|
+
return this[inner].label();
|
|
1622
|
+
}
|
|
1623
|
+
set label(value) {
|
|
1624
|
+
this[inner].setLabel(value);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
export function getGpu() {
|
|
1628
|
+
return new GPU(key, gfx.getGpu());
|
|
1629
|
+
}
|
|
1630
|
+
// constants
|
|
1631
|
+
export const GPUBufferUsage = {
|
|
1632
|
+
MAP_READ: 0x0001,
|
|
1633
|
+
MAP_WRITE: 0x0002,
|
|
1634
|
+
COPY_SRC: 0x0004,
|
|
1635
|
+
COPY_DST: 0x0008,
|
|
1636
|
+
INDEX: 0x0010,
|
|
1637
|
+
VERTEX: 0x0020,
|
|
1638
|
+
UNIFORM: 0x0040,
|
|
1639
|
+
STORAGE: 0x0080,
|
|
1640
|
+
INDIRECT: 0x0100,
|
|
1641
|
+
QUERY_RESOLVE: 0x0200,
|
|
1642
|
+
};
|
|
1643
|
+
export const GPUMapMode = {
|
|
1644
|
+
READ: 0x0001,
|
|
1645
|
+
WRITE: 0x0002,
|
|
1646
|
+
};
|
|
1647
|
+
export const GPUTextureUsage = {
|
|
1648
|
+
COPY_SRC: 0x01,
|
|
1649
|
+
COPY_DST: 0x02,
|
|
1650
|
+
TEXTURE_BINDING: 0x04,
|
|
1651
|
+
STORAGE_BINDING: 0x08,
|
|
1652
|
+
RENDER_ATTACHMENT: 0x10,
|
|
1653
|
+
};
|
|
1654
|
+
export const GPUShaderStage = {
|
|
1655
|
+
VERTEX: 0x1,
|
|
1656
|
+
FRAGMENT: 0x2,
|
|
1657
|
+
COMPUTE: 0x4,
|
|
1658
|
+
};
|
|
1659
|
+
export const GPUColorWrite = {
|
|
1660
|
+
RED: 0x1,
|
|
1661
|
+
GREEN: 0x2,
|
|
1662
|
+
BLUE: 0x4,
|
|
1663
|
+
ALPHA: 0x8,
|
|
1664
|
+
ALL: 0xF,
|
|
1665
|
+
};
|