@wasi-gfx/js-webgpu 0.2.0 → 0.4.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 +3 -3
- package/dist/canvas.d.ts +3 -3
- package/dist/canvas.js +36 -23
- package/dist/globals.js +12 -10
- package/dist/webgpu.d.ts +68 -12
- package/dist/webgpu.js +340 -48
- package/package.json +12 -6
- package/types/interfaces/wasi-cli-run.d.ts +2 -2
- package/types/interfaces/wasi-cli-stdout.d.ts +14 -3
- package/types/interfaces/wasi-cli-types.d.ts +15 -0
- package/types/interfaces/wasi-gfx-frame-buffer-frame-buffer.d.ts +13 -0
- package/types/interfaces/wasi-gfx-surface-surface-frame-buffer.d.ts +12 -0
- package/types/interfaces/wasi-gfx-surface-surface-webgpu.d.ts +29 -0
- package/types/interfaces/{wasi-surface-surface.d.ts → wasi-gfx-surface-surface.d.ts} +8 -18
- package/types/interfaces/wasi-webgpu-webgpu.d.ts +809 -810
- package/types/wit.d.ts +9 -10
- package/wit/deps/wasi-cli-0.3.0/package.wit +256 -0
- package/wit/deps/wasi-clocks-0.3.0/package.wit +43 -0
- package/wit/deps/wasi-filesystem-0.3.0/package.wit +149 -0
- package/wit/deps/wasi-gfx-frame-buffer-0.2.0/package.wit +13 -0
- package/wit/deps/{surface/surface.wit → wasi-gfx-surface-0.2.0/package.wit} +69 -44
- package/wit/deps/wasi-random-0.3.0/package.wit +18 -0
- package/wit/deps/wasi-sockets-0.3.0/package.wit +116 -0
- package/wit/deps/{webgpu/webgpu.wit → wasi-webgpu-0.3.0-rc.2/package.wit} +1007 -836
- package/wit/world.wit +8 -7
- package/types/interfaces/wasi-frame-buffer-frame-buffer.d.ts +0 -21
- package/types/interfaces/wasi-graphics-context-graphics-context.d.ts +0 -17
- package/types/interfaces/wasi-io-error.d.ts +0 -18
- package/types/interfaces/wasi-io-poll.d.ts +0 -43
- package/types/interfaces/wasi-io-streams.d.ts +0 -240
- package/wit/deps/cli/command.wit +0 -7
- package/wit/deps/cli/environment.wit +0 -18
- package/wit/deps/cli/exit.wit +0 -4
- package/wit/deps/cli/imports.wit +0 -20
- package/wit/deps/cli/run.wit +0 -4
- package/wit/deps/cli/stdio.wit +0 -17
- package/wit/deps/cli/terminal.wit +0 -49
- package/wit/deps/clocks/monotonic-clock.wit +0 -45
- package/wit/deps/clocks/wall-clock.wit +0 -42
- package/wit/deps/clocks/world.wit +0 -6
- package/wit/deps/filesystem/preopens.wit +0 -8
- package/wit/deps/filesystem/types.wit +0 -634
- package/wit/deps/filesystem/world.wit +0 -6
- package/wit/deps/frame-buffer/frame-buffer.wit +0 -23
- package/wit/deps/graphics-context/graphics-context.wit +0 -18
- package/wit/deps/io/error.wit +0 -34
- package/wit/deps/io/poll.wit +0 -41
- package/wit/deps/io/streams.wit +0 -262
- package/wit/deps/io/world.wit +0 -6
- package/wit/deps/random/insecure-seed.wit +0 -25
- package/wit/deps/random/insecure.wit +0 -22
- package/wit/deps/random/random.wit +0 -26
- package/wit/deps/random/world.wit +0 -7
- package/wit/deps/sockets/instance-network.wit +0 -9
- package/wit/deps/sockets/ip-name-lookup.wit +0 -51
- package/wit/deps/sockets/network.wit +0 -145
- package/wit/deps/sockets/tcp-create-socket.wit +0 -27
- package/wit/deps/sockets/tcp.wit +0 -353
- package/wit/deps/sockets/udp-create-socket.wit +0 -27
- package/wit/deps/sockets/udp.wit +0 -266
- package/wit/deps/sockets/world.wit +0 -11
- package/wit/deps/webgpu/imports.wit +0 -5
- package/wit/deps.lock +0 -51
- package/wit/deps.toml +0 -18
package/dist/webgpu.js
CHANGED
|
@@ -1,5 +1,92 @@
|
|
|
1
|
-
import * as gfx from 'wasi:webgpu/webgpu@0.0.
|
|
2
|
-
import { inner, key, privateConstructorCalled, Todo, Unreachable } from './common';
|
|
1
|
+
import * as gfx from 'wasi:webgpu/webgpu@0.3.0-rc.2';
|
|
2
|
+
import { EventTarget, inner, key, privateConstructorCalled, Todo, Unreachable } from './common';
|
|
3
|
+
// flags converters: the web API uses numeric bitflags, wasi uses flag records.
|
|
4
|
+
function convertBufferUsageWebToWasi(usage) {
|
|
5
|
+
return {
|
|
6
|
+
mapRead: !!(usage & GPUBufferUsage.MAP_READ),
|
|
7
|
+
mapWrite: !!(usage & GPUBufferUsage.MAP_WRITE),
|
|
8
|
+
copySrc: !!(usage & GPUBufferUsage.COPY_SRC),
|
|
9
|
+
copyDst: !!(usage & GPUBufferUsage.COPY_DST),
|
|
10
|
+
index: !!(usage & GPUBufferUsage.INDEX),
|
|
11
|
+
vertex: !!(usage & GPUBufferUsage.VERTEX),
|
|
12
|
+
uniform: !!(usage & GPUBufferUsage.UNIFORM),
|
|
13
|
+
storage: !!(usage & GPUBufferUsage.STORAGE),
|
|
14
|
+
indirect: !!(usage & GPUBufferUsage.INDIRECT),
|
|
15
|
+
queryResolve: !!(usage & GPUBufferUsage.QUERY_RESOLVE),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function convertBufferUsageWasiToWeb(usage) {
|
|
19
|
+
let n = 0;
|
|
20
|
+
if (usage.mapRead)
|
|
21
|
+
n |= GPUBufferUsage.MAP_READ;
|
|
22
|
+
if (usage.mapWrite)
|
|
23
|
+
n |= GPUBufferUsage.MAP_WRITE;
|
|
24
|
+
if (usage.copySrc)
|
|
25
|
+
n |= GPUBufferUsage.COPY_SRC;
|
|
26
|
+
if (usage.copyDst)
|
|
27
|
+
n |= GPUBufferUsage.COPY_DST;
|
|
28
|
+
if (usage.index)
|
|
29
|
+
n |= GPUBufferUsage.INDEX;
|
|
30
|
+
if (usage.vertex)
|
|
31
|
+
n |= GPUBufferUsage.VERTEX;
|
|
32
|
+
if (usage.uniform)
|
|
33
|
+
n |= GPUBufferUsage.UNIFORM;
|
|
34
|
+
if (usage.storage)
|
|
35
|
+
n |= GPUBufferUsage.STORAGE;
|
|
36
|
+
if (usage.indirect)
|
|
37
|
+
n |= GPUBufferUsage.INDIRECT;
|
|
38
|
+
if (usage.queryResolve)
|
|
39
|
+
n |= GPUBufferUsage.QUERY_RESOLVE;
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
export function convertTextureUsageWebToWasi(usage) {
|
|
43
|
+
return {
|
|
44
|
+
copySrc: !!(usage & GPUTextureUsage.COPY_SRC),
|
|
45
|
+
copyDst: !!(usage & GPUTextureUsage.COPY_DST),
|
|
46
|
+
textureBinding: !!(usage & GPUTextureUsage.TEXTURE_BINDING),
|
|
47
|
+
storageBinding: !!(usage & GPUTextureUsage.STORAGE_BINDING),
|
|
48
|
+
renderAttachment: !!(usage & GPUTextureUsage.RENDER_ATTACHMENT),
|
|
49
|
+
transientAttachment: !!(usage & GPUTextureUsage.TRANSIENT_ATTACHMENT),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function convertTextureUsageWasiToWeb(usage) {
|
|
53
|
+
let n = 0;
|
|
54
|
+
if (usage.copySrc)
|
|
55
|
+
n |= GPUTextureUsage.COPY_SRC;
|
|
56
|
+
if (usage.copyDst)
|
|
57
|
+
n |= GPUTextureUsage.COPY_DST;
|
|
58
|
+
if (usage.textureBinding)
|
|
59
|
+
n |= GPUTextureUsage.TEXTURE_BINDING;
|
|
60
|
+
if (usage.storageBinding)
|
|
61
|
+
n |= GPUTextureUsage.STORAGE_BINDING;
|
|
62
|
+
if (usage.renderAttachment)
|
|
63
|
+
n |= GPUTextureUsage.RENDER_ATTACHMENT;
|
|
64
|
+
if (usage.transientAttachment)
|
|
65
|
+
n |= GPUTextureUsage.TRANSIENT_ATTACHMENT;
|
|
66
|
+
return n;
|
|
67
|
+
}
|
|
68
|
+
function convertShaderStageWebToWasi(visibility) {
|
|
69
|
+
return {
|
|
70
|
+
vertex: !!(visibility & GPUShaderStage.VERTEX),
|
|
71
|
+
fragment: !!(visibility & GPUShaderStage.FRAGMENT),
|
|
72
|
+
compute: !!(visibility & GPUShaderStage.COMPUTE),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function convertColorWriteWebToWasi(mask) {
|
|
76
|
+
return {
|
|
77
|
+
red: !!(mask & GPUColorWrite.RED),
|
|
78
|
+
green: !!(mask & GPUColorWrite.GREEN),
|
|
79
|
+
blue: !!(mask & GPUColorWrite.BLUE),
|
|
80
|
+
alpha: !!(mask & GPUColorWrite.ALPHA),
|
|
81
|
+
all: (mask & GPUColorWrite.ALL) === GPUColorWrite.ALL,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function convertMapModeWebToWasi(mode) {
|
|
85
|
+
return {
|
|
86
|
+
read: !!(mode & GPUMapMode.READ),
|
|
87
|
+
write: !!(mode & GPUMapMode.WRITE),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
3
90
|
// converters
|
|
4
91
|
// don't use raw `Number(x)`/`BigInt(x)` because they accept non-numeric values
|
|
5
92
|
function numToBigInt(n) {
|
|
@@ -21,11 +108,13 @@ function bigIntToNumOptional(n) {
|
|
|
21
108
|
function convertFeatureNameWebToWasi(name) {
|
|
22
109
|
if (name === "texture-compression-bc-sliced-3d")
|
|
23
110
|
return "texture-compression-bc-sliced3d";
|
|
24
|
-
if (name === "texture-compression-astc-sliced-3d"
|
|
111
|
+
if (name === "texture-compression-astc-sliced-3d")
|
|
112
|
+
return "texture-compression-astc-sliced3d";
|
|
113
|
+
if (name === "subgroup-size-control" || name === "texture-compression-unaligned" || name === "atomic-vec2u-min-max")
|
|
25
114
|
throw new Todo;
|
|
26
115
|
return name;
|
|
27
116
|
}
|
|
28
|
-
function convertTextureFormatWebToWasi(name) {
|
|
117
|
+
export function convertTextureFormatWebToWasi(name) {
|
|
29
118
|
switch (name) {
|
|
30
119
|
case "astc-4x4-unorm":
|
|
31
120
|
return "astc4x4-unorm";
|
|
@@ -153,16 +242,7 @@ function convertVertexFormatWebToWasi(name) {
|
|
|
153
242
|
switch (name) {
|
|
154
243
|
case "unorm10-10-10-2":
|
|
155
244
|
return "unorm1010102";
|
|
156
|
-
case "
|
|
157
|
-
case "sint8":
|
|
158
|
-
case "unorm8":
|
|
159
|
-
case "snorm8":
|
|
160
|
-
case "uint16":
|
|
161
|
-
case "sint16":
|
|
162
|
-
case "unorm16":
|
|
163
|
-
case "snorm16":
|
|
164
|
-
case "float16":
|
|
165
|
-
case "unorm8x4-bgra":
|
|
245
|
+
case "snorm10-10-10-2":
|
|
166
246
|
throw new Todo;
|
|
167
247
|
default:
|
|
168
248
|
return name;
|
|
@@ -226,6 +306,15 @@ function convertTextureViewDimensionWasiToWeb(name) {
|
|
|
226
306
|
return name;
|
|
227
307
|
}
|
|
228
308
|
}
|
|
309
|
+
function convertConstantsWebToWasi(constants) {
|
|
310
|
+
if (constants === undefined)
|
|
311
|
+
return undefined;
|
|
312
|
+
const record = new gfx.RecordGpuPipelineConstantValue();
|
|
313
|
+
for (const [key, value] of Object.entries(constants)) {
|
|
314
|
+
record.add(key, value);
|
|
315
|
+
}
|
|
316
|
+
return record;
|
|
317
|
+
}
|
|
229
318
|
function convertGpuLayoutWebToWasi(layout) {
|
|
230
319
|
if (layout instanceof GPUPipelineLayout) {
|
|
231
320
|
return {
|
|
@@ -309,23 +398,25 @@ function convertGpuBindingResourceWebToWasi(resource) {
|
|
|
309
398
|
};
|
|
310
399
|
}
|
|
311
400
|
else if (resource instanceof GPUTextureView) {
|
|
312
|
-
|
|
401
|
+
return {
|
|
402
|
+
tag: 'gpu-texture-view',
|
|
403
|
+
val: resource[inner],
|
|
404
|
+
};
|
|
313
405
|
}
|
|
314
|
-
else if (resource.buffer) {
|
|
315
|
-
let bufferBinding = resource;
|
|
406
|
+
else if ('buffer' in resource && resource.buffer instanceof GPUBuffer) {
|
|
316
407
|
let offsetBitInt;
|
|
317
|
-
if (typeof
|
|
318
|
-
offsetBitInt = numToBigInt(
|
|
408
|
+
if (typeof resource.offset === "number")
|
|
409
|
+
offsetBitInt = numToBigInt(resource.offset);
|
|
319
410
|
let sizeBitInt;
|
|
320
|
-
if (typeof
|
|
321
|
-
sizeBitInt = numToBigInt(
|
|
411
|
+
if (typeof resource.size === "number")
|
|
412
|
+
sizeBitInt = numToBigInt(resource.size);
|
|
322
413
|
return {
|
|
323
414
|
tag: 'gpu-buffer-binding',
|
|
324
415
|
val: {
|
|
325
416
|
...resource,
|
|
326
417
|
size: sizeBitInt,
|
|
327
418
|
offset: offsetBitInt,
|
|
328
|
-
buffer:
|
|
419
|
+
buffer: resource.buffer[inner],
|
|
329
420
|
}
|
|
330
421
|
};
|
|
331
422
|
}
|
|
@@ -333,6 +424,21 @@ function convertGpuBindingResourceWebToWasi(resource) {
|
|
|
333
424
|
throw new Unreachable;
|
|
334
425
|
}
|
|
335
426
|
}
|
|
427
|
+
function convertGpuErrorWasiToWeb(err) {
|
|
428
|
+
const message = err.message();
|
|
429
|
+
const kind = err.kind();
|
|
430
|
+
switch (kind.tag) {
|
|
431
|
+
case "validation-error":
|
|
432
|
+
return new GPUValidationError(message);
|
|
433
|
+
case "out-of-memory-error":
|
|
434
|
+
return new GPUOutOfMemoryError(message);
|
|
435
|
+
case "internal-error":
|
|
436
|
+
return new GPUInternalError(message);
|
|
437
|
+
default:
|
|
438
|
+
kind;
|
|
439
|
+
throw new Unreachable();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
336
442
|
function convertBufferToUint8Array(buffer) {
|
|
337
443
|
if (buffer instanceof Uint8Array) {
|
|
338
444
|
return buffer;
|
|
@@ -384,6 +490,7 @@ export class GPU {
|
|
|
384
490
|
}
|
|
385
491
|
export class GPUAdapter {
|
|
386
492
|
[inner];
|
|
493
|
+
#info;
|
|
387
494
|
constructor(k, i) {
|
|
388
495
|
privateConstructorCalled(k);
|
|
389
496
|
this[inner] = i;
|
|
@@ -399,7 +506,7 @@ export class GPUAdapter {
|
|
|
399
506
|
requiredLimits.add(key, numToBigIntOptional(value));
|
|
400
507
|
}
|
|
401
508
|
}
|
|
402
|
-
return new GPUDevice(key, this[inner].requestDevice({
|
|
509
|
+
return new GPUDevice(key, await this[inner].requestDevice({
|
|
403
510
|
...descriptor,
|
|
404
511
|
requiredFeatures,
|
|
405
512
|
requiredLimits,
|
|
@@ -412,7 +519,12 @@ export class GPUAdapter {
|
|
|
412
519
|
return "GPUAdapter";
|
|
413
520
|
}
|
|
414
521
|
get info() {
|
|
415
|
-
|
|
522
|
+
// From the spec:
|
|
523
|
+
// > The same object is returned each time. To create that object for the first time:
|
|
524
|
+
// https://www.w3.org/TR/webgpu/#dom-gpuadapter-info
|
|
525
|
+
if (!this.#info)
|
|
526
|
+
this.#info = new GPUAdapterInfo(key, this[inner].info());
|
|
527
|
+
return this.#info;
|
|
416
528
|
}
|
|
417
529
|
get features() {
|
|
418
530
|
return new GPUSupportedFeatures(key, this[inner].features());
|
|
@@ -420,9 +532,6 @@ export class GPUAdapter {
|
|
|
420
532
|
get limits() {
|
|
421
533
|
return new GPUSupportedLimits(key, this[inner].limits());
|
|
422
534
|
}
|
|
423
|
-
get isFallbackAdapter() {
|
|
424
|
-
return this[inner].isFallbackAdapter();
|
|
425
|
-
}
|
|
426
535
|
}
|
|
427
536
|
export class GPUSupportedFeatures {
|
|
428
537
|
[inner];
|
|
@@ -482,6 +591,9 @@ export class GPUSupportedLimits {
|
|
|
482
591
|
get maxBindGroupsPlusVertexBuffers() {
|
|
483
592
|
return this[inner].maxBindGroupsPlusVertexBuffers();
|
|
484
593
|
}
|
|
594
|
+
get maxImmediateSize() {
|
|
595
|
+
return this[inner].maxImmediateSize();
|
|
596
|
+
}
|
|
485
597
|
get maxBindingsPerBindGroup() {
|
|
486
598
|
return this[inner].maxBindingsPerBindGroup();
|
|
487
599
|
}
|
|
@@ -579,9 +691,74 @@ export class GPUAdapterInfo {
|
|
|
579
691
|
get description() {
|
|
580
692
|
return this[inner].description();
|
|
581
693
|
}
|
|
694
|
+
get isFallbackAdapter() {
|
|
695
|
+
return this[inner].isFallbackAdapter();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
export class GPUDeviceLostInfo {
|
|
699
|
+
[inner];
|
|
700
|
+
constructor(k, i) {
|
|
701
|
+
privateConstructorCalled(k);
|
|
702
|
+
this[inner] = i;
|
|
703
|
+
}
|
|
704
|
+
get __brand() {
|
|
705
|
+
return "GPUDeviceLostInfo";
|
|
706
|
+
}
|
|
707
|
+
get reason() {
|
|
708
|
+
return this[inner].reason();
|
|
709
|
+
}
|
|
710
|
+
get message() {
|
|
711
|
+
return this[inner].message();
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
export class GPUError {
|
|
715
|
+
#message;
|
|
716
|
+
constructor(k, message) {
|
|
717
|
+
privateConstructorCalled(k);
|
|
718
|
+
this.#message = message;
|
|
719
|
+
}
|
|
720
|
+
get message() {
|
|
721
|
+
return this.#message;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
export class GPUValidationError extends GPUError {
|
|
725
|
+
constructor(message) {
|
|
726
|
+
super(key, message);
|
|
727
|
+
}
|
|
728
|
+
get __brand() {
|
|
729
|
+
return "GPUValidationError";
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
export class GPUOutOfMemoryError extends GPUError {
|
|
733
|
+
constructor(message) {
|
|
734
|
+
super(key, message);
|
|
735
|
+
}
|
|
736
|
+
get __brand() {
|
|
737
|
+
return "GPUOutOfMemoryError";
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
export class GPUInternalError extends GPUError {
|
|
741
|
+
constructor(message) {
|
|
742
|
+
super(key, message);
|
|
743
|
+
}
|
|
744
|
+
get __brand() {
|
|
745
|
+
return "GPUInternalError";
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
export class GPUPipelineError extends DOMException {
|
|
749
|
+
reason;
|
|
750
|
+
constructor(message = "", options) {
|
|
751
|
+
super(message, "GPUPipelineError");
|
|
752
|
+
this.reason = options.reason;
|
|
753
|
+
}
|
|
754
|
+
get __brand() {
|
|
755
|
+
return "GPUPipelineError";
|
|
756
|
+
}
|
|
582
757
|
}
|
|
583
758
|
export class GPUDevice extends EventTarget {
|
|
584
759
|
[inner];
|
|
760
|
+
#adapterInfo;
|
|
761
|
+
#lost;
|
|
585
762
|
constructor(k, i) {
|
|
586
763
|
privateConstructorCalled(k);
|
|
587
764
|
super();
|
|
@@ -597,7 +774,10 @@ export class GPUDevice extends EventTarget {
|
|
|
597
774
|
this[inner].setLabel(value);
|
|
598
775
|
}
|
|
599
776
|
get lost() {
|
|
600
|
-
|
|
777
|
+
if (!this.#lost)
|
|
778
|
+
this.#lost = Promise.resolve(this[inner].lost())
|
|
779
|
+
.then(info => new GPUDeviceLostInfo(key, info));
|
|
780
|
+
return this.#lost;
|
|
601
781
|
}
|
|
602
782
|
get features() {
|
|
603
783
|
return new GPUSupportedFeatures(key, this[inner].features());
|
|
@@ -609,7 +789,12 @@ export class GPUDevice extends EventTarget {
|
|
|
609
789
|
return new GPUQueue(key, this[inner].queue());
|
|
610
790
|
}
|
|
611
791
|
get adapterInfo() {
|
|
612
|
-
|
|
792
|
+
// From the spec:
|
|
793
|
+
// > The same object is returned each time. To create that object for the first time:
|
|
794
|
+
// https://www.w3.org/TR/webgpu/#dom-gpudevice-adapterinfo
|
|
795
|
+
if (!this.#adapterInfo)
|
|
796
|
+
this.#adapterInfo = new GPUAdapterInfo(key, this[inner].adapterInfo());
|
|
797
|
+
return this.#adapterInfo;
|
|
613
798
|
}
|
|
614
799
|
destroy() {
|
|
615
800
|
this[inner].destroy();
|
|
@@ -618,6 +803,7 @@ export class GPUDevice extends EventTarget {
|
|
|
618
803
|
return new GPUBuffer(key, this[inner].createBuffer({
|
|
619
804
|
...descriptor,
|
|
620
805
|
size: numToBigInt(descriptor.size),
|
|
806
|
+
usage: convertBufferUsageWebToWasi(descriptor.usage),
|
|
621
807
|
}));
|
|
622
808
|
}
|
|
623
809
|
createTexture(descriptor) {
|
|
@@ -627,12 +813,17 @@ export class GPUDevice extends EventTarget {
|
|
|
627
813
|
let viewFormats;
|
|
628
814
|
if (descriptor.viewFormats)
|
|
629
815
|
viewFormats = Array.from(descriptor.viewFormats).map(f => convertTextureFormatWebToWasi(f));
|
|
816
|
+
let textureBindingViewDimension;
|
|
817
|
+
if (descriptor.textureBindingViewDimension)
|
|
818
|
+
textureBindingViewDimension = convertTextureViewDimensionWebToWasi(descriptor.textureBindingViewDimension);
|
|
630
819
|
return new GPUTexture(key, this[inner].createTexture({
|
|
631
820
|
...descriptor,
|
|
632
821
|
size: convertExtent3DWebToWasi(descriptor.size),
|
|
633
822
|
format: convertTextureFormatWebToWasi(descriptor.format),
|
|
823
|
+
usage: convertTextureUsageWebToWasi(descriptor.usage),
|
|
634
824
|
dimension,
|
|
635
825
|
viewFormats,
|
|
826
|
+
textureBindingViewDimension,
|
|
636
827
|
}));
|
|
637
828
|
}
|
|
638
829
|
createSampler(descriptor) {
|
|
@@ -672,6 +863,7 @@ export class GPUDevice extends EventTarget {
|
|
|
672
863
|
}
|
|
673
864
|
return {
|
|
674
865
|
...entry,
|
|
866
|
+
visibility: convertShaderStageWebToWasi(entry.visibility),
|
|
675
867
|
buffer,
|
|
676
868
|
texture,
|
|
677
869
|
storageTexture,
|
|
@@ -682,7 +874,17 @@ export class GPUDevice extends EventTarget {
|
|
|
682
874
|
createPipelineLayout(descriptor) {
|
|
683
875
|
return new GPUPipelineLayout(key, this[inner].createPipelineLayout({
|
|
684
876
|
...descriptor,
|
|
685
|
-
bindGroupLayouts: Array.from(descriptor.bindGroupLayouts).map(
|
|
877
|
+
bindGroupLayouts: Array.from(descriptor.bindGroupLayouts).map(bindGroup => {
|
|
878
|
+
if (bindGroup instanceof GPUBindGroupLayout) {
|
|
879
|
+
return bindGroup[inner];
|
|
880
|
+
}
|
|
881
|
+
else if (bindGroup === null || bindGroup === undefined) {
|
|
882
|
+
return undefined;
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
throw new Unreachable;
|
|
886
|
+
}
|
|
887
|
+
}),
|
|
686
888
|
}));
|
|
687
889
|
}
|
|
688
890
|
createBindGroup(descriptor) {
|
|
@@ -700,7 +902,7 @@ export class GPUDevice extends EventTarget {
|
|
|
700
902
|
createShaderModule(descriptor) {
|
|
701
903
|
let compilationHints;
|
|
702
904
|
if (descriptor.compilationHints) {
|
|
703
|
-
compilationHints = descriptor.compilationHints.map(hint => {
|
|
905
|
+
compilationHints = Array.from(descriptor.compilationHints).map(hint => {
|
|
704
906
|
let layout;
|
|
705
907
|
if (hint.layout) {
|
|
706
908
|
layout = convertGpuLayoutWebToWasi(hint.layout);
|
|
@@ -720,7 +922,7 @@ export class GPUDevice extends EventTarget {
|
|
|
720
922
|
let compute = {
|
|
721
923
|
module: descriptor.compute.module[inner],
|
|
722
924
|
entryPoint: descriptor.compute.entryPoint,
|
|
723
|
-
constants:
|
|
925
|
+
constants: convertConstantsWebToWasi(descriptor.compute.constants),
|
|
724
926
|
};
|
|
725
927
|
return new GPUComputePipeline(key, this[inner].createComputePipeline({
|
|
726
928
|
...descriptor,
|
|
@@ -752,7 +954,7 @@ export class GPUDevice extends EventTarget {
|
|
|
752
954
|
}
|
|
753
955
|
const vertex = {
|
|
754
956
|
...descriptor.vertex,
|
|
755
|
-
constants:
|
|
957
|
+
constants: convertConstantsWebToWasi(descriptor.vertex.constants),
|
|
756
958
|
module: descriptor.vertex.module[inner],
|
|
757
959
|
buffers,
|
|
758
960
|
};
|
|
@@ -767,13 +969,17 @@ export class GPUDevice extends EventTarget {
|
|
|
767
969
|
if (descriptor.fragment) {
|
|
768
970
|
fragment = {
|
|
769
971
|
...descriptor.fragment,
|
|
770
|
-
constants:
|
|
972
|
+
constants: convertConstantsWebToWasi(descriptor.fragment.constants),
|
|
771
973
|
module: descriptor.fragment.module[inner],
|
|
772
974
|
targets: Array.from(descriptor.fragment.targets).map(target => {
|
|
773
975
|
if (target) {
|
|
976
|
+
let writeMask;
|
|
977
|
+
if (target.writeMask !== undefined)
|
|
978
|
+
writeMask = convertColorWriteWebToWasi(target.writeMask);
|
|
774
979
|
return {
|
|
775
980
|
...target,
|
|
776
981
|
format: convertTextureFormatWebToWasi(target.format),
|
|
982
|
+
writeMask,
|
|
777
983
|
};
|
|
778
984
|
}
|
|
779
985
|
else {
|
|
@@ -790,11 +996,19 @@ export class GPUDevice extends EventTarget {
|
|
|
790
996
|
layout: convertGpuLayoutWebToWasi(descriptor.layout),
|
|
791
997
|
}));
|
|
792
998
|
}
|
|
793
|
-
async createComputePipelineAsync(
|
|
794
|
-
|
|
999
|
+
async createComputePipelineAsync(descriptor) {
|
|
1000
|
+
// TODO: make this really async
|
|
1001
|
+
await Promise.resolve();
|
|
1002
|
+
const result = this.createComputePipeline(descriptor);
|
|
1003
|
+
await Promise.resolve();
|
|
1004
|
+
return result;
|
|
795
1005
|
}
|
|
796
1006
|
async createRenderPipelineAsync(descriptor) {
|
|
797
|
-
|
|
1007
|
+
// TODO: make this really async
|
|
1008
|
+
await Promise.resolve();
|
|
1009
|
+
const result = this.createRenderPipeline(descriptor);
|
|
1010
|
+
await Promise.resolve();
|
|
1011
|
+
return result;
|
|
798
1012
|
}
|
|
799
1013
|
createCommandEncoder(descriptor = {}) {
|
|
800
1014
|
return new GPUCommandEncoder(key, this[inner].createCommandEncoder(descriptor));
|
|
@@ -823,7 +1037,13 @@ export class GPUDevice extends EventTarget {
|
|
|
823
1037
|
this[inner].pushErrorScope(filter);
|
|
824
1038
|
}
|
|
825
1039
|
async popErrorScope() {
|
|
826
|
-
|
|
1040
|
+
const err = await this[inner].popErrorScope();
|
|
1041
|
+
if (err) {
|
|
1042
|
+
return convertGpuErrorWasiToWeb(err);
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
827
1047
|
}
|
|
828
1048
|
importExternalTexture(descriptor) {
|
|
829
1049
|
throw new Todo;
|
|
@@ -836,6 +1056,9 @@ export class GPURenderBundleEncoder {
|
|
|
836
1056
|
privateConstructorCalled(k);
|
|
837
1057
|
this[inner] = i;
|
|
838
1058
|
}
|
|
1059
|
+
setImmediates(rangeOffset, data, dataOffset, dataSize) {
|
|
1060
|
+
this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
|
|
1061
|
+
}
|
|
839
1062
|
get __brand() {
|
|
840
1063
|
return "GPURenderBundleEncoder";
|
|
841
1064
|
}
|
|
@@ -867,7 +1090,10 @@ export class GPURenderBundleEncoder {
|
|
|
867
1090
|
this[inner].setIndexBuffer(buffer[inner], indexFormat, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
868
1091
|
}
|
|
869
1092
|
setVertexBuffer(slot, buffer, offset, size) {
|
|
870
|
-
|
|
1093
|
+
let gfxBuffer;
|
|
1094
|
+
if (buffer)
|
|
1095
|
+
gfxBuffer = buffer[inner];
|
|
1096
|
+
this[inner].setVertexBuffer(slot, gfxBuffer, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
871
1097
|
}
|
|
872
1098
|
draw(vertexCount, instanceCount, firstVertex, firstInstance) {
|
|
873
1099
|
this[inner].draw(vertexCount, instanceCount, firstVertex, firstInstance);
|
|
@@ -913,8 +1139,49 @@ export class GPUShaderModule {
|
|
|
913
1139
|
set label(value) {
|
|
914
1140
|
this[inner].setLabel(value);
|
|
915
1141
|
}
|
|
916
|
-
getCompilationInfo() {
|
|
917
|
-
|
|
1142
|
+
async getCompilationInfo() {
|
|
1143
|
+
return new GPUCompilationInfo(key, await this[inner].getCompilationInfo());
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
export class GPUCompilationInfo {
|
|
1147
|
+
[inner];
|
|
1148
|
+
constructor(k, i) {
|
|
1149
|
+
privateConstructorCalled(k);
|
|
1150
|
+
this[inner] = i;
|
|
1151
|
+
}
|
|
1152
|
+
get __brand() {
|
|
1153
|
+
return 'GPUCompilationInfo';
|
|
1154
|
+
}
|
|
1155
|
+
get messages() {
|
|
1156
|
+
return this[inner].messages().map(m => new GPUCompilationMessage(key, m));
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
export class GPUCompilationMessage {
|
|
1160
|
+
[inner];
|
|
1161
|
+
constructor(k, i) {
|
|
1162
|
+
privateConstructorCalled(k);
|
|
1163
|
+
this[inner] = i;
|
|
1164
|
+
}
|
|
1165
|
+
get __brand() {
|
|
1166
|
+
return 'GPUCompilationMessage';
|
|
1167
|
+
}
|
|
1168
|
+
get message() {
|
|
1169
|
+
return this[inner].message();
|
|
1170
|
+
}
|
|
1171
|
+
get type() {
|
|
1172
|
+
return this[inner].type();
|
|
1173
|
+
}
|
|
1174
|
+
get lineNum() {
|
|
1175
|
+
return bigIntToNum(this[inner].lineNum());
|
|
1176
|
+
}
|
|
1177
|
+
get linePos() {
|
|
1178
|
+
return bigIntToNum(this[inner].linePos());
|
|
1179
|
+
}
|
|
1180
|
+
get offset() {
|
|
1181
|
+
return bigIntToNum(this[inner].offset());
|
|
1182
|
+
}
|
|
1183
|
+
get length() {
|
|
1184
|
+
return bigIntToNum(this[inner].length());
|
|
918
1185
|
}
|
|
919
1186
|
}
|
|
920
1187
|
export class GPUComputePipeline {
|
|
@@ -993,13 +1260,13 @@ export class GPUBuffer {
|
|
|
993
1260
|
return bigIntToNum(this[inner].size());
|
|
994
1261
|
}
|
|
995
1262
|
get usage() {
|
|
996
|
-
return this[inner].usage();
|
|
1263
|
+
return convertBufferUsageWasiToWeb(this[inner].usage());
|
|
997
1264
|
}
|
|
998
1265
|
get mapState() {
|
|
999
1266
|
return this[inner].mapState();
|
|
1000
1267
|
}
|
|
1001
1268
|
async mapAsync(mode, offset, size) {
|
|
1002
|
-
this[inner].mapAsync(mode, numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1269
|
+
await this[inner].mapAsync(convertMapModeWebToWasi(mode), numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
1003
1270
|
}
|
|
1004
1271
|
getMappedRange(offset, size) {
|
|
1005
1272
|
this._mappedRangeBuffer = this[inner].getMappedRangeGetWithCopy(numToBigIntOptional(offset), numToBigIntOptional(size));
|
|
@@ -1039,8 +1306,8 @@ export class GPUQueue {
|
|
|
1039
1306
|
submit(commandBuffers) {
|
|
1040
1307
|
this[inner].submit(Array.from(commandBuffers).map((cb) => cb[inner]));
|
|
1041
1308
|
}
|
|
1042
|
-
onSubmittedWorkDone() {
|
|
1043
|
-
|
|
1309
|
+
async onSubmittedWorkDone() {
|
|
1310
|
+
await this[inner].onSubmittedWorkDone();
|
|
1044
1311
|
}
|
|
1045
1312
|
writeBuffer(buffer, bufferOffset, data, dataOffset, size) {
|
|
1046
1313
|
this[inner].writeBufferWithCopy(buffer[inner], numToBigInt(bufferOffset), convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(size));
|
|
@@ -1165,7 +1432,7 @@ export class GPUTexture {
|
|
|
1165
1432
|
return convertTextureFormatWasiToWeb(this[inner].format());
|
|
1166
1433
|
}
|
|
1167
1434
|
get usage() {
|
|
1168
|
-
return this[inner].usage();
|
|
1435
|
+
return convertTextureUsageWasiToWeb(this[inner].usage());
|
|
1169
1436
|
}
|
|
1170
1437
|
createView(descriptor) {
|
|
1171
1438
|
let gfxDescriptor;
|
|
@@ -1176,10 +1443,14 @@ export class GPUTexture {
|
|
|
1176
1443
|
let dimension;
|
|
1177
1444
|
if (descriptor.dimension)
|
|
1178
1445
|
dimension = convertTextureViewDimensionWebToWasi(descriptor.dimension);
|
|
1446
|
+
let usage;
|
|
1447
|
+
if (descriptor.usage !== undefined)
|
|
1448
|
+
usage = convertTextureUsageWebToWasi(descriptor.usage);
|
|
1179
1449
|
gfxDescriptor = {
|
|
1180
1450
|
...descriptor,
|
|
1181
1451
|
dimension,
|
|
1182
1452
|
format,
|
|
1453
|
+
usage,
|
|
1183
1454
|
};
|
|
1184
1455
|
}
|
|
1185
1456
|
return new GPUTextureView(key, this[inner].createView(gfxDescriptor));
|
|
@@ -1240,8 +1511,22 @@ export class GPUCommandEncoder {
|
|
|
1240
1511
|
timestampWrites,
|
|
1241
1512
|
}));
|
|
1242
1513
|
}
|
|
1243
|
-
copyBufferToBuffer(source,
|
|
1244
|
-
|
|
1514
|
+
copyBufferToBuffer(source, arg2, arg3, destinationOffset, size) {
|
|
1515
|
+
if (arg2 instanceof GPUBuffer && (typeof arg3 === "number" || arg3 === undefined)) {
|
|
1516
|
+
// (source, destination, size?)
|
|
1517
|
+
const destination = arg2;
|
|
1518
|
+
const size = arg3;
|
|
1519
|
+
this[inner].copyBufferToBuffer(source[inner], undefined, destination[inner], undefined, numToBigIntOptional(size));
|
|
1520
|
+
}
|
|
1521
|
+
else if (typeof arg2 === "number" && arg3 instanceof GPUBuffer) {
|
|
1522
|
+
// (source, sourceOffset, destination, destinationOffset, size?)
|
|
1523
|
+
const sourceOffset = arg2;
|
|
1524
|
+
const destination = arg3;
|
|
1525
|
+
this[inner].copyBufferToBuffer(source[inner], numToBigInt(sourceOffset), destination[inner], numToBigIntOptional(destinationOffset), numToBigIntOptional(size));
|
|
1526
|
+
}
|
|
1527
|
+
else {
|
|
1528
|
+
throw new Unreachable;
|
|
1529
|
+
}
|
|
1245
1530
|
}
|
|
1246
1531
|
copyBufferToTexture(source, destination, copySize) {
|
|
1247
1532
|
let destinationOrigin;
|
|
@@ -1366,6 +1651,9 @@ export class GPUComputePassEncoder {
|
|
|
1366
1651
|
throw new Todo;
|
|
1367
1652
|
}
|
|
1368
1653
|
}
|
|
1654
|
+
setImmediates(rangeOffset, data, dataOffset, dataSize) {
|
|
1655
|
+
this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
|
|
1656
|
+
}
|
|
1369
1657
|
}
|
|
1370
1658
|
export class GPURenderPassEncoder {
|
|
1371
1659
|
[inner];
|
|
@@ -1418,6 +1706,9 @@ export class GPURenderPassEncoder {
|
|
|
1418
1706
|
setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
|
|
1419
1707
|
throw new Todo;
|
|
1420
1708
|
}
|
|
1709
|
+
setImmediates(rangeOffset, data, dataOffset, dataSize) {
|
|
1710
|
+
this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
|
|
1711
|
+
}
|
|
1421
1712
|
setPipeline(pipeline) {
|
|
1422
1713
|
this[inner].setPipeline(pipeline[inner]);
|
|
1423
1714
|
}
|
|
@@ -1510,6 +1801,7 @@ export const GPUTextureUsage = {
|
|
|
1510
1801
|
TEXTURE_BINDING: 0x04,
|
|
1511
1802
|
STORAGE_BINDING: 0x08,
|
|
1512
1803
|
RENDER_ATTACHMENT: 0x10,
|
|
1804
|
+
TRANSIENT_ATTACHMENT: 0x20,
|
|
1513
1805
|
};
|
|
1514
1806
|
export const GPUShaderStage = {
|
|
1515
1807
|
VERTEX: 0x1,
|