@wasi-gfx/js-webgpu 0.1.0 → 0.3.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.
Files changed (67) hide show
  1. package/README.md +3 -3
  2. package/dist/canvas.d.ts +45 -0
  3. package/dist/canvas.js +125 -0
  4. package/dist/common.d.ts +17 -0
  5. package/dist/common.js +33 -0
  6. package/dist/globals.d.ts +1 -0
  7. package/dist/globals.js +52 -0
  8. package/dist/webgpu.d.ts +380 -0
  9. package/dist/{index.js → webgpu.js} +243 -177
  10. package/package.json +26 -7
  11. package/types/interfaces/wasi-cli-run.d.ts +2 -2
  12. package/types/interfaces/wasi-cli-stdout.d.ts +14 -3
  13. package/types/interfaces/wasi-cli-types.d.ts +15 -0
  14. package/types/interfaces/wasi-gfx-frame-buffer-frame-buffer.d.ts +13 -0
  15. package/types/interfaces/wasi-gfx-surface-surface-frame-buffer.d.ts +12 -0
  16. package/types/interfaces/wasi-gfx-surface-surface-webgpu.d.ts +29 -0
  17. package/types/interfaces/{wasi-surface-surface.d.ts → wasi-gfx-surface-surface.d.ts} +8 -18
  18. package/types/interfaces/wasi-webgpu-webgpu.d.ts +809 -810
  19. package/types/wit.d.ts +9 -10
  20. package/wit/deps/wasi-cli-0.3.0/package.wit +256 -0
  21. package/wit/deps/wasi-clocks-0.3.0/package.wit +43 -0
  22. package/wit/deps/wasi-filesystem-0.3.0/package.wit +149 -0
  23. package/wit/deps/wasi-gfx-frame-buffer-0.2.0/package.wit +13 -0
  24. package/wit/deps/{surface/surface.wit → wasi-gfx-surface-0.2.0/package.wit} +69 -44
  25. package/wit/deps/wasi-random-0.3.0/package.wit +18 -0
  26. package/wit/deps/wasi-sockets-0.3.0/package.wit +116 -0
  27. package/wit/deps/{webgpu/webgpu.wit → wasi-webgpu-0.3.0-rc.2/package.wit} +1007 -836
  28. package/wit/world.wit +8 -7
  29. package/types/interfaces/wasi-frame-buffer-frame-buffer.d.ts +0 -21
  30. package/types/interfaces/wasi-graphics-context-graphics-context.d.ts +0 -17
  31. package/types/interfaces/wasi-io-error.d.ts +0 -18
  32. package/types/interfaces/wasi-io-poll.d.ts +0 -43
  33. package/types/interfaces/wasi-io-streams.d.ts +0 -240
  34. package/wit/deps/cli/command.wit +0 -7
  35. package/wit/deps/cli/environment.wit +0 -18
  36. package/wit/deps/cli/exit.wit +0 -4
  37. package/wit/deps/cli/imports.wit +0 -20
  38. package/wit/deps/cli/run.wit +0 -4
  39. package/wit/deps/cli/stdio.wit +0 -17
  40. package/wit/deps/cli/terminal.wit +0 -49
  41. package/wit/deps/clocks/monotonic-clock.wit +0 -45
  42. package/wit/deps/clocks/wall-clock.wit +0 -42
  43. package/wit/deps/clocks/world.wit +0 -6
  44. package/wit/deps/filesystem/preopens.wit +0 -8
  45. package/wit/deps/filesystem/types.wit +0 -634
  46. package/wit/deps/filesystem/world.wit +0 -6
  47. package/wit/deps/frame-buffer/frame-buffer.wit +0 -23
  48. package/wit/deps/graphics-context/graphics-context.wit +0 -18
  49. package/wit/deps/io/error.wit +0 -34
  50. package/wit/deps/io/poll.wit +0 -41
  51. package/wit/deps/io/streams.wit +0 -262
  52. package/wit/deps/io/world.wit +0 -6
  53. package/wit/deps/random/insecure-seed.wit +0 -25
  54. package/wit/deps/random/insecure.wit +0 -22
  55. package/wit/deps/random/random.wit +0 -26
  56. package/wit/deps/random/world.wit +0 -7
  57. package/wit/deps/sockets/instance-network.wit +0 -9
  58. package/wit/deps/sockets/ip-name-lookup.wit +0 -51
  59. package/wit/deps/sockets/network.wit +0 -145
  60. package/wit/deps/sockets/tcp-create-socket.wit +0 -27
  61. package/wit/deps/sockets/tcp.wit +0 -353
  62. package/wit/deps/sockets/udp-create-socket.wit +0 -27
  63. package/wit/deps/sockets/udp.wit +0 -266
  64. package/wit/deps/sockets/world.wit +0 -11
  65. package/wit/deps/webgpu/imports.wit +0 -5
  66. package/wit/deps.lock +0 -51
  67. package/wit/deps.toml +0 -18
@@ -1,41 +1,91 @@
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);
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
+ };
6
17
  }
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
+ 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;
18
41
  }
19
- class Todo extends Error {
20
- constructor() {
21
- super("TODO: not yet implemented");
22
- }
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
+ };
23
51
  }
24
- class Unimplemented extends Error {
25
- constructor() {
26
- super("Unimplemented.");
27
- }
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;
28
67
  }
29
- class Unreachable extends Error {
30
- constructor() {
31
- super("Unreachable code reached.");
32
- }
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
+ };
33
83
  }
34
- const inner = Symbol("inner");
35
- const key = Symbol("key");
36
- function privateConstructorCalled(k) {
37
- if (k !== key)
38
- throw new TypeError("Illegal constructor.");
84
+ function convertMapModeWebToWasi(mode) {
85
+ return {
86
+ read: !!(mode & GPUMapMode.READ),
87
+ write: !!(mode & GPUMapMode.WRITE),
88
+ };
39
89
  }
40
90
  // converters
41
91
  // don't use raw `Number(x)`/`BigInt(x)` because they accept non-numeric values
@@ -58,11 +108,13 @@ function bigIntToNumOptional(n) {
58
108
  function convertFeatureNameWebToWasi(name) {
59
109
  if (name === "texture-compression-bc-sliced-3d")
60
110
  return "texture-compression-bc-sliced3d";
61
- if (name === "texture-compression-astc-sliced-3d" || name === "float32-blendable")
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")
62
114
  throw new Todo;
63
115
  return name;
64
116
  }
65
- function convertTextureFormatWebToWasi(name) {
117
+ export function convertTextureFormatWebToWasi(name) {
66
118
  switch (name) {
67
119
  case "astc-4x4-unorm":
68
120
  return "astc4x4-unorm";
@@ -190,16 +242,7 @@ function convertVertexFormatWebToWasi(name) {
190
242
  switch (name) {
191
243
  case "unorm10-10-10-2":
192
244
  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":
245
+ case "snorm10-10-10-2":
203
246
  throw new Todo;
204
247
  default:
205
248
  return name;
@@ -346,23 +389,25 @@ function convertGpuBindingResourceWebToWasi(resource) {
346
389
  };
347
390
  }
348
391
  else if (resource instanceof GPUTextureView) {
349
- throw new Todo;
392
+ return {
393
+ tag: 'gpu-texture-view',
394
+ val: resource[inner],
395
+ };
350
396
  }
351
- else if (resource.buffer) {
352
- let bufferBinding = resource;
397
+ else if ('buffer' in resource && resource.buffer instanceof GPUBuffer) {
353
398
  let offsetBitInt;
354
- if (typeof bufferBinding.offset === "number")
355
- offsetBitInt = numToBigInt(bufferBinding.offset);
399
+ if (typeof resource.offset === "number")
400
+ offsetBitInt = numToBigInt(resource.offset);
356
401
  let sizeBitInt;
357
- if (typeof bufferBinding.size === "number")
358
- sizeBitInt = numToBigInt(bufferBinding.size);
402
+ if (typeof resource.size === "number")
403
+ sizeBitInt = numToBigInt(resource.size);
359
404
  return {
360
405
  tag: 'gpu-buffer-binding',
361
406
  val: {
362
407
  ...resource,
363
408
  size: sizeBitInt,
364
409
  offset: offsetBitInt,
365
- buffer: bufferBinding.buffer[inner],
410
+ buffer: resource.buffer[inner],
366
411
  }
367
412
  };
368
413
  }
@@ -396,110 +441,7 @@ function convertBufferToUint8Array(buffer) {
396
441
  throw new Unreachable;
397
442
  }
398
443
  }
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
- }
444
+ // When forwarding a method to gfx.[type].[method], always pass down objects (like `...descriptor`) so that if new fields are added and tsc can catch it.
503
445
  export class GPU {
504
446
  [inner];
505
447
  constructor(k, i) {
@@ -524,6 +466,7 @@ export class GPU {
524
466
  }
525
467
  export class GPUAdapter {
526
468
  [inner];
469
+ #info;
527
470
  constructor(k, i) {
528
471
  privateConstructorCalled(k);
529
472
  this[inner] = i;
@@ -539,7 +482,7 @@ export class GPUAdapter {
539
482
  requiredLimits.add(key, numToBigIntOptional(value));
540
483
  }
541
484
  }
542
- return new GPUDevice(key, this[inner].requestDevice({
485
+ return new GPUDevice(key, await this[inner].requestDevice({
543
486
  ...descriptor,
544
487
  requiredFeatures,
545
488
  requiredLimits,
@@ -552,7 +495,12 @@ export class GPUAdapter {
552
495
  return "GPUAdapter";
553
496
  }
554
497
  get info() {
555
- return new GPUAdapterInfo(key, this[inner].info());
498
+ // From the spec:
499
+ // > The same object is returned each time. To create that object for the first time:
500
+ // https://www.w3.org/TR/webgpu/#dom-gpuadapter-info
501
+ if (!this.#info)
502
+ this.#info = new GPUAdapterInfo(key, this[inner].info());
503
+ return this.#info;
556
504
  }
557
505
  get features() {
558
506
  return new GPUSupportedFeatures(key, this[inner].features());
@@ -560,9 +508,6 @@ export class GPUAdapter {
560
508
  get limits() {
561
509
  return new GPUSupportedLimits(key, this[inner].limits());
562
510
  }
563
- get isFallbackAdapter() {
564
- return this[inner].isFallbackAdapter();
565
- }
566
511
  }
567
512
  export class GPUSupportedFeatures {
568
513
  [inner];
@@ -622,6 +567,9 @@ export class GPUSupportedLimits {
622
567
  get maxBindGroupsPlusVertexBuffers() {
623
568
  return this[inner].maxBindGroupsPlusVertexBuffers();
624
569
  }
570
+ get maxImmediateSize() {
571
+ return this[inner].maxImmediateSize();
572
+ }
625
573
  get maxBindingsPerBindGroup() {
626
574
  return this[inner].maxBindingsPerBindGroup();
627
575
  }
@@ -719,9 +667,13 @@ export class GPUAdapterInfo {
719
667
  get description() {
720
668
  return this[inner].description();
721
669
  }
670
+ get isFallbackAdapter() {
671
+ return this[inner].isFallbackAdapter();
672
+ }
722
673
  }
723
674
  export class GPUDevice extends EventTarget {
724
675
  [inner];
676
+ #adapterInfo;
725
677
  constructor(k, i) {
726
678
  privateConstructorCalled(k);
727
679
  super();
@@ -749,7 +701,12 @@ export class GPUDevice extends EventTarget {
749
701
  return new GPUQueue(key, this[inner].queue());
750
702
  }
751
703
  get adapterInfo() {
752
- return new GPUAdapterInfo(key, this[inner].adapterInfo());
704
+ // From the spec:
705
+ // > The same object is returned each time. To create that object for the first time:
706
+ // https://www.w3.org/TR/webgpu/#dom-gpudevice-adapterinfo
707
+ if (!this.#adapterInfo)
708
+ this.#adapterInfo = new GPUAdapterInfo(key, this[inner].adapterInfo());
709
+ return this.#adapterInfo;
753
710
  }
754
711
  destroy() {
755
712
  this[inner].destroy();
@@ -758,6 +715,7 @@ export class GPUDevice extends EventTarget {
758
715
  return new GPUBuffer(key, this[inner].createBuffer({
759
716
  ...descriptor,
760
717
  size: numToBigInt(descriptor.size),
718
+ usage: convertBufferUsageWebToWasi(descriptor.usage),
761
719
  }));
762
720
  }
763
721
  createTexture(descriptor) {
@@ -767,12 +725,17 @@ export class GPUDevice extends EventTarget {
767
725
  let viewFormats;
768
726
  if (descriptor.viewFormats)
769
727
  viewFormats = Array.from(descriptor.viewFormats).map(f => convertTextureFormatWebToWasi(f));
728
+ let textureBindingViewDimension;
729
+ if (descriptor.textureBindingViewDimension)
730
+ textureBindingViewDimension = convertTextureViewDimensionWebToWasi(descriptor.textureBindingViewDimension);
770
731
  return new GPUTexture(key, this[inner].createTexture({
771
732
  ...descriptor,
772
733
  size: convertExtent3DWebToWasi(descriptor.size),
773
734
  format: convertTextureFormatWebToWasi(descriptor.format),
735
+ usage: convertTextureUsageWebToWasi(descriptor.usage),
774
736
  dimension,
775
737
  viewFormats,
738
+ textureBindingViewDimension,
776
739
  }));
777
740
  }
778
741
  createSampler(descriptor) {
@@ -812,6 +775,7 @@ export class GPUDevice extends EventTarget {
812
775
  }
813
776
  return {
814
777
  ...entry,
778
+ visibility: convertShaderStageWebToWasi(entry.visibility),
815
779
  buffer,
816
780
  texture,
817
781
  storageTexture,
@@ -822,7 +786,17 @@ export class GPUDevice extends EventTarget {
822
786
  createPipelineLayout(descriptor) {
823
787
  return new GPUPipelineLayout(key, this[inner].createPipelineLayout({
824
788
  ...descriptor,
825
- bindGroupLayouts: Array.from(descriptor.bindGroupLayouts).map(b => b[inner])
789
+ bindGroupLayouts: Array.from(descriptor.bindGroupLayouts).map(bindGroup => {
790
+ if (bindGroup instanceof GPUBindGroupLayout) {
791
+ return bindGroup[inner];
792
+ }
793
+ else if (bindGroup === null || bindGroup === undefined) {
794
+ return undefined;
795
+ }
796
+ else {
797
+ throw new Unreachable;
798
+ }
799
+ }),
826
800
  }));
827
801
  }
828
802
  createBindGroup(descriptor) {
@@ -840,7 +814,7 @@ export class GPUDevice extends EventTarget {
840
814
  createShaderModule(descriptor) {
841
815
  let compilationHints;
842
816
  if (descriptor.compilationHints) {
843
- compilationHints = descriptor.compilationHints.map(hint => {
817
+ compilationHints = Array.from(descriptor.compilationHints).map(hint => {
844
818
  let layout;
845
819
  if (hint.layout) {
846
820
  layout = convertGpuLayoutWebToWasi(hint.layout);
@@ -911,9 +885,13 @@ export class GPUDevice extends EventTarget {
911
885
  module: descriptor.fragment.module[inner],
912
886
  targets: Array.from(descriptor.fragment.targets).map(target => {
913
887
  if (target) {
888
+ let writeMask;
889
+ if (target.writeMask !== undefined)
890
+ writeMask = convertColorWriteWebToWasi(target.writeMask);
914
891
  return {
915
892
  ...target,
916
893
  format: convertTextureFormatWebToWasi(target.format),
894
+ writeMask,
917
895
  };
918
896
  }
919
897
  else {
@@ -930,11 +908,19 @@ export class GPUDevice extends EventTarget {
930
908
  layout: convertGpuLayoutWebToWasi(descriptor.layout),
931
909
  }));
932
910
  }
933
- async createComputePipelineAsync(_descriptor) {
934
- throw new Todo();
911
+ async createComputePipelineAsync(descriptor) {
912
+ // TODO: make this really async
913
+ await Promise.resolve();
914
+ const result = this.createComputePipeline(descriptor);
915
+ await Promise.resolve();
916
+ return result;
935
917
  }
936
918
  async createRenderPipelineAsync(descriptor) {
937
- throw new Todo();
919
+ // TODO: make this really async
920
+ await Promise.resolve();
921
+ const result = this.createRenderPipeline(descriptor);
922
+ await Promise.resolve();
923
+ return result;
938
924
  }
939
925
  createCommandEncoder(descriptor = {}) {
940
926
  return new GPUCommandEncoder(key, this[inner].createCommandEncoder(descriptor));
@@ -963,7 +949,15 @@ export class GPUDevice extends EventTarget {
963
949
  this[inner].pushErrorScope(filter);
964
950
  }
965
951
  async popErrorScope() {
966
- throw new Todo();
952
+ const err = await this[inner].popErrorScope();
953
+ if (err) {
954
+ return {
955
+ message: err.message(),
956
+ };
957
+ }
958
+ else {
959
+ return null;
960
+ }
967
961
  }
968
962
  importExternalTexture(descriptor) {
969
963
  throw new Todo;
@@ -976,6 +970,9 @@ export class GPURenderBundleEncoder {
976
970
  privateConstructorCalled(k);
977
971
  this[inner] = i;
978
972
  }
973
+ setImmediates(rangeOffset, data, dataOffset, dataSize) {
974
+ this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
975
+ }
979
976
  get __brand() {
980
977
  return "GPURenderBundleEncoder";
981
978
  }
@@ -1007,7 +1004,10 @@ export class GPURenderBundleEncoder {
1007
1004
  this[inner].setIndexBuffer(buffer[inner], indexFormat, numToBigIntOptional(offset), numToBigIntOptional(size));
1008
1005
  }
1009
1006
  setVertexBuffer(slot, buffer, offset, size) {
1010
- this[inner].setVertexBuffer(slot, buffer[inner], numToBigIntOptional(offset), numToBigIntOptional(size));
1007
+ let gfxBuffer;
1008
+ if (buffer)
1009
+ gfxBuffer = buffer[inner];
1010
+ this[inner].setVertexBuffer(slot, gfxBuffer, numToBigIntOptional(offset), numToBigIntOptional(size));
1011
1011
  }
1012
1012
  draw(vertexCount, instanceCount, firstVertex, firstInstance) {
1013
1013
  this[inner].draw(vertexCount, instanceCount, firstVertex, firstInstance);
@@ -1053,8 +1053,49 @@ export class GPUShaderModule {
1053
1053
  set label(value) {
1054
1054
  this[inner].setLabel(value);
1055
1055
  }
1056
- getCompilationInfo() {
1057
- throw new Todo();
1056
+ async getCompilationInfo() {
1057
+ return new GPUCompilationInfo(key, await this[inner].getCompilationInfo());
1058
+ }
1059
+ }
1060
+ export class GPUCompilationInfo {
1061
+ [inner];
1062
+ constructor(k, i) {
1063
+ privateConstructorCalled(k);
1064
+ this[inner] = i;
1065
+ }
1066
+ get __brand() {
1067
+ return 'GPUCompilationInfo';
1068
+ }
1069
+ get messages() {
1070
+ return this[inner].messages().map(m => new GPUCompilationMessage(key, m));
1071
+ }
1072
+ }
1073
+ export class GPUCompilationMessage {
1074
+ [inner];
1075
+ constructor(k, i) {
1076
+ privateConstructorCalled(k);
1077
+ this[inner] = i;
1078
+ }
1079
+ get __brand() {
1080
+ return 'GPUCompilationMessage';
1081
+ }
1082
+ get message() {
1083
+ return this[inner].message();
1084
+ }
1085
+ get type() {
1086
+ return this[inner].type();
1087
+ }
1088
+ get lineNum() {
1089
+ return bigIntToNum(this[inner].lineNum());
1090
+ }
1091
+ get linePos() {
1092
+ return bigIntToNum(this[inner].linePos());
1093
+ }
1094
+ get offset() {
1095
+ return bigIntToNum(this[inner].offset());
1096
+ }
1097
+ get length() {
1098
+ return bigIntToNum(this[inner].length());
1058
1099
  }
1059
1100
  }
1060
1101
  export class GPUComputePipeline {
@@ -1133,13 +1174,13 @@ export class GPUBuffer {
1133
1174
  return bigIntToNum(this[inner].size());
1134
1175
  }
1135
1176
  get usage() {
1136
- return this[inner].usage();
1177
+ return convertBufferUsageWasiToWeb(this[inner].usage());
1137
1178
  }
1138
1179
  get mapState() {
1139
1180
  return this[inner].mapState();
1140
1181
  }
1141
1182
  async mapAsync(mode, offset, size) {
1142
- this[inner].mapAsync(mode, numToBigIntOptional(offset), numToBigIntOptional(size));
1183
+ await this[inner].mapAsync(convertMapModeWebToWasi(mode), numToBigIntOptional(offset), numToBigIntOptional(size));
1143
1184
  }
1144
1185
  getMappedRange(offset, size) {
1145
1186
  this._mappedRangeBuffer = this[inner].getMappedRangeGetWithCopy(numToBigIntOptional(offset), numToBigIntOptional(size));
@@ -1305,7 +1346,7 @@ export class GPUTexture {
1305
1346
  return convertTextureFormatWasiToWeb(this[inner].format());
1306
1347
  }
1307
1348
  get usage() {
1308
- return this[inner].usage();
1349
+ return convertTextureUsageWasiToWeb(this[inner].usage());
1309
1350
  }
1310
1351
  createView(descriptor) {
1311
1352
  let gfxDescriptor;
@@ -1316,10 +1357,14 @@ export class GPUTexture {
1316
1357
  let dimension;
1317
1358
  if (descriptor.dimension)
1318
1359
  dimension = convertTextureViewDimensionWebToWasi(descriptor.dimension);
1360
+ let usage;
1361
+ if (descriptor.usage !== undefined)
1362
+ usage = convertTextureUsageWebToWasi(descriptor.usage);
1319
1363
  gfxDescriptor = {
1320
1364
  ...descriptor,
1321
1365
  dimension,
1322
1366
  format,
1367
+ usage,
1323
1368
  };
1324
1369
  }
1325
1370
  return new GPUTextureView(key, this[inner].createView(gfxDescriptor));
@@ -1380,8 +1425,22 @@ export class GPUCommandEncoder {
1380
1425
  timestampWrites,
1381
1426
  }));
1382
1427
  }
1383
- copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) {
1384
- this[inner].copyBufferToBuffer(source[inner], numToBigInt(sourceOffset), destination[inner], numToBigInt(destinationOffset), numToBigInt(size));
1428
+ copyBufferToBuffer(source, arg2, arg3, destinationOffset, size) {
1429
+ if (arg2 instanceof GPUBuffer && (typeof arg3 === "number" || arg3 === undefined)) {
1430
+ // (source, destination, size?)
1431
+ const destination = arg2;
1432
+ const size = arg3;
1433
+ this[inner].copyBufferToBuffer(source[inner], undefined, destination[inner], undefined, numToBigIntOptional(size));
1434
+ }
1435
+ else if (typeof arg2 === "number" && arg3 instanceof GPUBuffer) {
1436
+ // (source, sourceOffset, destination, destinationOffset, size?)
1437
+ const sourceOffset = arg2;
1438
+ const destination = arg3;
1439
+ this[inner].copyBufferToBuffer(source[inner], numToBigInt(sourceOffset), destination[inner], numToBigIntOptional(destinationOffset), numToBigIntOptional(size));
1440
+ }
1441
+ else {
1442
+ throw new Unreachable;
1443
+ }
1385
1444
  }
1386
1445
  copyBufferToTexture(source, destination, copySize) {
1387
1446
  let destinationOrigin;
@@ -1506,6 +1565,9 @@ export class GPUComputePassEncoder {
1506
1565
  throw new Todo;
1507
1566
  }
1508
1567
  }
1568
+ setImmediates(rangeOffset, data, dataOffset, dataSize) {
1569
+ this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
1570
+ }
1509
1571
  }
1510
1572
  export class GPURenderPassEncoder {
1511
1573
  [inner];
@@ -1558,6 +1620,9 @@ export class GPURenderPassEncoder {
1558
1620
  setBindGroup(index, bindGroup, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength) {
1559
1621
  throw new Todo;
1560
1622
  }
1623
+ setImmediates(rangeOffset, data, dataOffset, dataSize) {
1624
+ this[inner].setImmediates(rangeOffset, convertBufferToUint8Array(data), numToBigIntOptional(dataOffset), numToBigIntOptional(dataSize));
1625
+ }
1561
1626
  setPipeline(pipeline) {
1562
1627
  this[inner].setPipeline(pipeline[inner]);
1563
1628
  }
@@ -1650,6 +1715,7 @@ export const GPUTextureUsage = {
1650
1715
  TEXTURE_BINDING: 0x04,
1651
1716
  STORAGE_BINDING: 0x08,
1652
1717
  RENDER_ATTACHMENT: 0x10,
1718
+ TRANSIENT_ATTACHMENT: 0x20,
1653
1719
  };
1654
1720
  export const GPUShaderStage = {
1655
1721
  VERTEX: 0x1,