@wasi-gfx/js-webgpu 0.2.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 (63) hide show
  1. package/README.md +3 -3
  2. package/dist/canvas.d.ts +3 -3
  3. package/dist/canvas.js +36 -23
  4. package/dist/webgpu.d.ts +39 -12
  5. package/dist/webgpu.js +248 -42
  6. package/package.json +12 -6
  7. package/types/interfaces/wasi-cli-run.d.ts +2 -2
  8. package/types/interfaces/wasi-cli-stdout.d.ts +14 -3
  9. package/types/interfaces/wasi-cli-types.d.ts +15 -0
  10. package/types/interfaces/wasi-gfx-frame-buffer-frame-buffer.d.ts +13 -0
  11. package/types/interfaces/wasi-gfx-surface-surface-frame-buffer.d.ts +12 -0
  12. package/types/interfaces/wasi-gfx-surface-surface-webgpu.d.ts +29 -0
  13. package/types/interfaces/{wasi-surface-surface.d.ts → wasi-gfx-surface-surface.d.ts} +8 -18
  14. package/types/interfaces/wasi-webgpu-webgpu.d.ts +809 -810
  15. package/types/wit.d.ts +9 -10
  16. package/wit/deps/wasi-cli-0.3.0/package.wit +256 -0
  17. package/wit/deps/wasi-clocks-0.3.0/package.wit +43 -0
  18. package/wit/deps/wasi-filesystem-0.3.0/package.wit +149 -0
  19. package/wit/deps/wasi-gfx-frame-buffer-0.2.0/package.wit +13 -0
  20. package/wit/deps/{surface/surface.wit → wasi-gfx-surface-0.2.0/package.wit} +69 -44
  21. package/wit/deps/wasi-random-0.3.0/package.wit +18 -0
  22. package/wit/deps/wasi-sockets-0.3.0/package.wit +116 -0
  23. package/wit/deps/{webgpu/webgpu.wit → wasi-webgpu-0.3.0-rc.2/package.wit} +1007 -836
  24. package/wit/world.wit +8 -7
  25. package/types/interfaces/wasi-frame-buffer-frame-buffer.d.ts +0 -21
  26. package/types/interfaces/wasi-graphics-context-graphics-context.d.ts +0 -17
  27. package/types/interfaces/wasi-io-error.d.ts +0 -18
  28. package/types/interfaces/wasi-io-poll.d.ts +0 -43
  29. package/types/interfaces/wasi-io-streams.d.ts +0 -240
  30. package/wit/deps/cli/command.wit +0 -7
  31. package/wit/deps/cli/environment.wit +0 -18
  32. package/wit/deps/cli/exit.wit +0 -4
  33. package/wit/deps/cli/imports.wit +0 -20
  34. package/wit/deps/cli/run.wit +0 -4
  35. package/wit/deps/cli/stdio.wit +0 -17
  36. package/wit/deps/cli/terminal.wit +0 -49
  37. package/wit/deps/clocks/monotonic-clock.wit +0 -45
  38. package/wit/deps/clocks/wall-clock.wit +0 -42
  39. package/wit/deps/clocks/world.wit +0 -6
  40. package/wit/deps/filesystem/preopens.wit +0 -8
  41. package/wit/deps/filesystem/types.wit +0 -634
  42. package/wit/deps/filesystem/world.wit +0 -6
  43. package/wit/deps/frame-buffer/frame-buffer.wit +0 -23
  44. package/wit/deps/graphics-context/graphics-context.wit +0 -18
  45. package/wit/deps/io/error.wit +0 -34
  46. package/wit/deps/io/poll.wit +0 -41
  47. package/wit/deps/io/streams.wit +0 -262
  48. package/wit/deps/io/world.wit +0 -6
  49. package/wit/deps/random/insecure-seed.wit +0 -25
  50. package/wit/deps/random/insecure.wit +0 -22
  51. package/wit/deps/random/random.wit +0 -26
  52. package/wit/deps/random/world.wit +0 -7
  53. package/wit/deps/sockets/instance-network.wit +0 -9
  54. package/wit/deps/sockets/ip-name-lookup.wit +0 -51
  55. package/wit/deps/sockets/network.wit +0 -145
  56. package/wit/deps/sockets/tcp-create-socket.wit +0 -27
  57. package/wit/deps/sockets/tcp.wit +0 -353
  58. package/wit/deps/sockets/udp-create-socket.wit +0 -27
  59. package/wit/deps/sockets/udp.wit +0 -266
  60. package/wit/deps/sockets/world.wit +0 -11
  61. package/wit/deps/webgpu/imports.wit +0 -5
  62. package/wit/deps.lock +0 -51
  63. package/wit/deps.toml +0 -18
package/README.md CHANGED
@@ -19,8 +19,8 @@ npm run example --example=[example]
19
19
  ### Run an example:
20
20
  Use [github.com/wasi-gfx/graphtime](https://github.com/wasi-gfx/graphtime) to run ./out/[example].wasm
21
21
 
22
-
23
- ## Generate types from wit
22
+ ## After Updating wit
23
+ Make sure to run:
24
24
  ```shell
25
- jco types wit --out-dir=types
25
+ npm run wit
26
26
  ```
package/dist/canvas.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import * as wasiSurface from 'wasi:surface/surface@0.0.1';
2
- import * as wasiGraphicsContext from 'wasi:graphics-context/graphics-context@0.0.1';
1
+ import * as wasiSurface from 'wasi-gfx:surface/surface@0.2.0';
2
+ import * as wasiSurfaceWebgpu from 'wasi-gfx:surface/surface-webgpu@0.2.0';
3
3
  import { GPUTexture } from './webgpu';
4
4
  export declare function createCanvas(): HTMLCanvasElement;
5
5
  type LimitedCanvas = Pick<globalThis.HTMLCanvasElement, "height" | "width" | "getContext" | "transferControlToOffscreen" | "addEventListener" | "removeEventListener" | "dispatchEvent" | "onclick" | "ondblclick" | "oninput" | "onkeydown" | "onkeyup" | "onpointerdown" | "onpointermove" | "onpointerup">;
6
6
  export declare class HTMLCanvasElement implements LimitedCanvas, AnimationFrameProvider {
7
7
  #private;
8
8
  _surface: wasiSurface.Surface;
9
- _graphicsContext: wasiGraphicsContext.Context;
9
+ _webgpuContext: wasiSurfaceWebgpu.Context | undefined;
10
10
  get height(): number;
11
11
  set height(value: number);
12
12
  get width(): number;
package/dist/canvas.js CHANGED
@@ -1,15 +1,14 @@
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';
1
+ import * as wasiSurface from 'wasi-gfx:surface/surface@0.2.0';
2
+ import * as wasiSurfaceWebgpu from 'wasi-gfx:surface/surface-webgpu@0.2.0';
4
3
  import { inner, key, privateConstructorCalled, Todo, Unreachable, Unimplemented } from './common';
5
- import { GPUTexture } from './webgpu';
4
+ import { GPUTexture, convertTextureFormatWebToWasi, convertTextureUsageWebToWasi } from './webgpu';
6
5
  export function createCanvas() {
7
6
  return new HTMLCanvasElement(key);
8
7
  }
9
8
  export class HTMLCanvasElement {
10
9
  _surface;
11
- _graphicsContext;
12
- #framePollable;
10
+ _webgpuContext;
11
+ #frames;
13
12
  get height() {
14
13
  return this._surface.height();
15
14
  }
@@ -25,8 +24,6 @@ export class HTMLCanvasElement {
25
24
  constructor(k) {
26
25
  privateConstructorCalled(k);
27
26
  this._surface = new wasiSurface.Surface({});
28
- this._graphicsContext = new wasiGraphicsContext.Context();
29
- this._surface.connectGraphicsContext(this._graphicsContext);
30
27
  }
31
28
  getContext(contextId, options) {
32
29
  switch (contextId.toLowerCase()) {
@@ -68,16 +65,16 @@ export class HTMLCanvasElement {
68
65
  throw new Todo;
69
66
  }
70
67
  requestAnimationFrame(callback) {
71
- if (!this.#framePollable)
72
- this.#framePollable = this._surface.subscribeFrame();
73
- const pollable = this.#framePollable;
74
- // giving the event loop a chance to do other work before blocking.
75
- Promise.resolve().then(() => {
76
- pollable.block();
77
- this._surface.getFrame();
68
+ if (!this.#frames)
69
+ this.#frames = this._surface.onFrame()[Symbol.asyncIterator]();
70
+ const frames = this.#frames;
71
+ frames.next().then(({ done }) => {
72
+ if (done)
73
+ return;
78
74
  // TODO: this number should be real
79
75
  callback(0);
80
- this._graphicsContext.present();
76
+ // present automatically just like the web
77
+ this._webgpuContext?.present();
81
78
  });
82
79
  // TODO: this number should be real
83
80
  return 0;
@@ -94,19 +91,35 @@ export class GPUCanvasContext {
94
91
  throw new Todo;
95
92
  }
96
93
  configure(configuration) {
97
- let device = configuration.device[inner];
98
- let context = this.#canvas._graphicsContext;
99
- device.connectGraphicsContext(context);
94
+ let usage;
95
+ if (configuration.usage !== undefined)
96
+ usage = convertTextureUsageWebToWasi(configuration.usage);
97
+ let viewFormats;
98
+ if (configuration.viewFormats)
99
+ viewFormats = Array.from(configuration.viewFormats).map(convertTextureFormatWebToWasi);
100
+ const context = new wasiSurfaceWebgpu.Context(this.#canvas._surface);
101
+ context.configure({
102
+ ...configuration,
103
+ usage,
104
+ viewFormats,
105
+ device: configuration.device[inner],
106
+ format: convertTextureFormatWebToWasi(configuration.format),
107
+ });
108
+ this.#canvas._webgpuContext = context;
100
109
  }
101
110
  unconfigure() {
102
- throw new Todo;
111
+ this.#canvas._webgpuContext?.unconfigure();
112
+ this.#canvas._webgpuContext = undefined;
103
113
  }
104
114
  getConfiguration() {
105
115
  throw new Todo;
106
116
  }
107
117
  getCurrentTexture() {
108
- const buffer = this.#canvas._graphicsContext.getCurrentBuffer();
109
- let texture = gfx.GpuTexture.fromGraphicsBuffer(buffer);
110
- return new GPUTexture(key, texture);
118
+ if (!this.#canvas._webgpuContext) {
119
+ // https://www.w3.org/TR/webgpu/#dom-gpucanvascontext-getcurrenttexture
120
+ // > 1. If this.[[configuration]] is null, throw an InvalidStateError and return.
121
+ throw new DOMException("GPUCanvasContext.getCurrentTexture: Canvas not configured", "InvalidStateError");
122
+ }
123
+ return new GPUTexture(key, this.#canvas._webgpuContext.getCurrentTexture());
111
124
  }
112
125
  }
package/dist/webgpu.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import * as gfx from 'wasi:webgpu/webgpu@0.0.1';
2
- import { inner } from './common';
1
+ import * as gfx from 'wasi:webgpu/webgpu@0.3.0-rc.2';
2
+ import { EventTarget, inner } from './common';
3
+ export declare function convertTextureUsageWebToWasi(usage: number): gfx.GpuTextureUsage;
4
+ export declare function convertTextureFormatWebToWasi(name: GPUTextureFormat): gfx.GpuTextureFormat;
3
5
  export declare class GPU implements globalThis.GPU {
4
6
  [inner]: gfx.Gpu;
5
7
  constructor(k: symbol, i: gfx.Gpu);
@@ -9,6 +11,7 @@ export declare class GPU implements globalThis.GPU {
9
11
  getPreferredCanvasFormat(): GPUTextureFormat;
10
12
  }
11
13
  export declare class GPUAdapter implements globalThis.GPUAdapter {
14
+ #private;
12
15
  [inner]: gfx.GpuAdapter;
13
16
  constructor(k: symbol, i: gfx.GpuAdapter);
14
17
  requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;
@@ -17,7 +20,6 @@ export declare class GPUAdapter implements globalThis.GPUAdapter {
17
20
  get info(): GPUAdapterInfo;
18
21
  get features(): GPUSupportedFeatures;
19
22
  get limits(): GPUSupportedLimits;
20
- get isFallbackAdapter(): boolean;
21
23
  }
22
24
  export declare class GPUSupportedFeatures implements globalThis.GPUSupportedFeatures {
23
25
  [inner]: gfx.GpuSupportedFeatures;
@@ -41,6 +43,7 @@ export declare class GPUSupportedLimits implements globalThis.GPUSupportedLimits
41
43
  get maxTextureArrayLayers(): number;
42
44
  get maxBindGroups(): number;
43
45
  get maxBindGroupsPlusVertexBuffers(): number;
46
+ get maxImmediateSize(): number;
44
47
  get maxBindingsPerBindGroup(): number;
45
48
  get maxDynamicUniformBuffersPerPipelineLayout(): number;
46
49
  get maxDynamicStorageBuffersPerPipelineLayout(): number;
@@ -75,8 +78,10 @@ export declare class GPUAdapterInfo implements globalThis.GPUAdapterInfo {
75
78
  get architecture(): string;
76
79
  get device(): string;
77
80
  get description(): string;
81
+ get isFallbackAdapter(): boolean;
78
82
  }
79
83
  export declare class GPUDevice extends EventTarget implements globalThis.GPUDevice {
84
+ #private;
80
85
  [inner]: gfx.GpuDevice;
81
86
  constructor(k: symbol, i: gfx.GpuDevice);
82
87
  get __brand(): 'GPUDevice';
@@ -97,7 +102,7 @@ export declare class GPUDevice extends EventTarget implements globalThis.GPUDevi
97
102
  createShaderModule(descriptor: GPUShaderModuleDescriptor): GPUShaderModule;
98
103
  createComputePipeline(descriptor: GPUComputePipelineDescriptor): GPUComputePipeline;
99
104
  createRenderPipeline(descriptor: GPURenderPipelineDescriptor): GPURenderPipeline;
100
- createComputePipelineAsync(_descriptor: GPUComputePipelineDescriptor): Promise<GPUComputePipeline>;
105
+ createComputePipelineAsync(descriptor: GPUComputePipelineDescriptor): Promise<GPUComputePipeline>;
101
106
  createRenderPipelineAsync(descriptor: GPURenderPipelineDescriptor): Promise<GPURenderPipeline>;
102
107
  createCommandEncoder(descriptor?: GPUCommandEncoderDescriptor): GPUCommandEncoder;
103
108
  createRenderBundleEncoder(descriptor: GPURenderBundleEncoderDescriptor): GPURenderBundleEncoder;
@@ -110,6 +115,7 @@ export declare class GPUDevice extends EventTarget implements globalThis.GPUDevi
110
115
  export declare class GPURenderBundleEncoder implements globalThis.GPURenderBundleEncoder {
111
116
  [inner]: gfx.GpuRenderBundleEncoder;
112
117
  constructor(k: symbol, i: gfx.GpuRenderBundleEncoder);
118
+ setImmediates(rangeOffset: GPUSize32, data: GPUAllowSharedBufferSource, dataOffset?: GPUSize64, dataSize?: GPUSize64): undefined;
113
119
  get __brand(): 'GPURenderBundleEncoder';
114
120
  get label(): string;
115
121
  set label(value: string);
@@ -118,13 +124,13 @@ export declare class GPURenderBundleEncoder implements globalThis.GPURenderBundl
118
124
  popDebugGroup(): undefined;
119
125
  insertDebugMarker(markerLabel: string): undefined;
120
126
  setBindGroup(index: unknown, bindGroup: unknown, dynamicOffsetsData?: unknown, dynamicOffsetsDataStart?: unknown, dynamicOffsetsDataLength?: unknown): undefined;
121
- setPipeline(pipeline: globalThis.GPURenderPipeline): undefined;
122
- setIndexBuffer(buffer: globalThis.GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
123
- setVertexBuffer(slot: GPUIndex32, buffer: globalThis.GPUBuffer | null | undefined, offset?: GPUSize64, size?: GPUSize64): undefined;
127
+ setPipeline(pipeline: GPURenderPipeline): undefined;
128
+ setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
129
+ setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer | null | undefined, offset?: GPUSize64, size?: GPUSize64): undefined;
124
130
  draw(vertexCount: GPUSize32, instanceCount?: GPUSize32, firstVertex?: GPUSize32, firstInstance?: GPUSize32): undefined;
125
131
  drawIndexed(indexCount: GPUSize32, instanceCount?: GPUSize32, firstIndex?: GPUSize32, baseVertex?: GPUSignedOffset32, firstInstance?: GPUSize32): undefined;
126
- drawIndirect(indirectBuffer: globalThis.GPUBuffer, indirectOffset: GPUSize64): undefined;
127
- drawIndexedIndirect(indirectBuffer: globalThis.GPUBuffer, indirectOffset: GPUSize64): undefined;
132
+ drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
133
+ drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
128
134
  }
129
135
  export declare class GPURenderBundle implements globalThis.GPURenderBundle {
130
136
  [inner]: gfx.GpuRenderBundle;
@@ -141,6 +147,23 @@ export declare class GPUShaderModule implements globalThis.GPUShaderModule {
141
147
  set label(value: string);
142
148
  getCompilationInfo(): Promise<GPUCompilationInfo>;
143
149
  }
150
+ export declare class GPUCompilationInfo implements globalThis.GPUCompilationInfo {
151
+ [inner]: gfx.GpuCompilationInfo;
152
+ constructor(k: symbol, i: gfx.GpuCompilationInfo);
153
+ get __brand(): 'GPUCompilationInfo';
154
+ get messages(): GPUCompilationMessage[];
155
+ }
156
+ export declare class GPUCompilationMessage implements globalThis.GPUCompilationMessage {
157
+ [inner]: gfx.GpuCompilationMessage;
158
+ constructor(k: symbol, i: gfx.GpuCompilationMessage);
159
+ get __brand(): 'GPUCompilationMessage';
160
+ get message(): string;
161
+ get type(): GPUCompilationMessageType;
162
+ get lineNum(): number;
163
+ get linePos(): number;
164
+ get offset(): number;
165
+ get length(): number;
166
+ }
144
167
  export declare class GPUComputePipeline implements globalThis.GPUComputePipeline {
145
168
  [inner]: gfx.GpuComputePipeline;
146
169
  constructor(k: symbol, i: gfx.GpuComputePipeline);
@@ -235,7 +258,7 @@ export declare class GPUTexture implements globalThis.GPUTexture {
235
258
  get dimension(): GPUTextureDimension;
236
259
  get format(): GPUTextureFormat;
237
260
  get usage(): number;
238
- createView(descriptor?: GPUTextureViewDescriptor): globalThis.GPUTextureView;
261
+ createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView;
239
262
  destroy(): undefined;
240
263
  }
241
264
  export declare class GPUCommandEncoder implements globalThis.GPUCommandEncoder {
@@ -246,12 +269,13 @@ export declare class GPUCommandEncoder implements globalThis.GPUCommandEncoder {
246
269
  set label(value: string);
247
270
  beginRenderPass(descriptor: GPURenderPassDescriptor): GPURenderPassEncoder;
248
271
  beginComputePass(descriptor?: GPUComputePassDescriptor): GPUComputePassEncoder;
249
- copyBufferToBuffer(source: GPUBuffer, sourceOffset: GPUSize64, destination: GPUBuffer, destinationOffset: GPUSize64, size: GPUSize64): undefined;
272
+ copyBufferToBuffer(source: GPUBuffer, destination: GPUBuffer, size?: GPUSize64): undefined;
273
+ copyBufferToBuffer(source: GPUBuffer, sourceOffset: GPUSize64, destination: GPUBuffer, destinationOffset: GPUSize64, size?: GPUSize64): undefined;
250
274
  copyBufferToTexture(source: GPUTexelCopyBufferInfo, destination: GPUTexelCopyTextureInfo, copySize: GPUExtent3D): undefined;
251
275
  copyTextureToBuffer(source: GPUTexelCopyTextureInfo, destination: GPUTexelCopyBufferInfo, copySize: GPUExtent3D): undefined;
252
276
  copyTextureToTexture(source: GPUTexelCopyTextureInfo, destination: GPUTexelCopyTextureInfo, copySize: GPUExtent3D): undefined;
253
277
  clearBuffer(buffer: GPUBuffer, offset?: GPUSize64, size?: GPUSize64): undefined;
254
- resolveQuerySet(querySet: GPUQuerySet, firstQuery: GPUSize32, queryCount: GPUSize32, destination: globalThis.GPUBuffer, destinationOffset: GPUSize64): undefined;
278
+ resolveQuerySet(querySet: GPUQuerySet, firstQuery: GPUSize32, queryCount: GPUSize32, destination: GPUBuffer, destinationOffset: GPUSize64): undefined;
255
279
  finish(descriptor?: GPUCommandBufferDescriptor): GPUCommandBuffer;
256
280
  pushDebugGroup(groupLabel: string): undefined;
257
281
  popDebugGroup(): undefined;
@@ -271,6 +295,7 @@ export declare class GPUComputePassEncoder implements globalThis.GPUComputePassE
271
295
  popDebugGroup(): undefined;
272
296
  insertDebugMarker(markerLabel: string): undefined;
273
297
  setBindGroup(index: GPUIndex32, bindGroup: GPUBindGroup | null, dynamicOffsetsData?: Iterable<GPUBufferDynamicOffset> | Uint32Array, dynamicOffsetsDataStart?: GPUSize64, dynamicOffsetsDataLength?: GPUSize32): undefined;
298
+ setImmediates(rangeOffset: GPUSize32, data: GPUAllowSharedBufferSource, dataOffset?: GPUSize64, dataSize?: GPUSize64): undefined;
274
299
  }
275
300
  export declare class GPURenderPassEncoder implements globalThis.GPURenderPassEncoder {
276
301
  [inner]: gfx.GpuRenderPassEncoder;
@@ -290,6 +315,7 @@ export declare class GPURenderPassEncoder implements globalThis.GPURenderPassEnc
290
315
  popDebugGroup(): undefined;
291
316
  insertDebugMarker(markerLabel: string): undefined;
292
317
  setBindGroup(index: unknown, bindGroup: unknown, dynamicOffsetsData?: unknown, dynamicOffsetsDataStart?: unknown, dynamicOffsetsDataLength?: unknown): undefined;
318
+ setImmediates(rangeOffset: GPUSize32, data: GPUAllowSharedBufferSource, dataOffset?: GPUSize64, dataSize?: GPUSize64): undefined;
293
319
  setPipeline(pipeline: GPURenderPipeline): undefined;
294
320
  setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): undefined;
295
321
  setVertexBuffer(slot: GPUIndex32, buffer: GPUBuffer | null, offset?: GPUSize64, size?: GPUSize64): undefined;
@@ -338,6 +364,7 @@ export declare const GPUTextureUsage: {
338
364
  TEXTURE_BINDING: number;
339
365
  STORAGE_BINDING: number;
340
366
  RENDER_ATTACHMENT: number;
367
+ TRANSIENT_ATTACHMENT: number;
341
368
  };
342
369
  export declare const GPUShaderStage: {
343
370
  VERTEX: number;