@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/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wasi-gfx/js-webgpu",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "WebGPU JavaScript API on top of wasi-gfx",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/",
|
|
8
|
+
"wit/",
|
|
9
|
+
"types/"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "cd src && tsc",
|
|
14
|
+
"check": "cd src && tsc --noEmit && cd ../examples && tsc --noEmit",
|
|
15
|
+
"generate-types": "rm -rf types && jco types wit --out-dir=types",
|
|
16
|
+
"test": "npm run test:generate-spec-list && npm run test:rollup && npm run test:jco && echo 'Test wasm built but not run temp/tests.wasm'",
|
|
17
|
+
"test:generate-spec-list": "node tests/generate-spec-list.js",
|
|
18
|
+
"test:rollup": "rollup --config './tests/rollup.config.js'",
|
|
19
|
+
"test:jco": "jco componentize ./temp/tests.js --wit ./wit -n imports -o out/tests.wasm --disable 'http'",
|
|
20
|
+
"example": "npm run example:rollup && npm run example:jco",
|
|
21
|
+
"example:rollup": "rollup --config './examples/rollup.config.js' --configExample=$npm_config_example",
|
|
22
|
+
"example:jco": "mkdir -p out && jco componentize temp/$npm_config_example.js --wit ./wit -n imports -o out/$npm_config_example.wasm --disable 'http' --debug-starlingmonkey-build"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@bytecodealliance/jco": "^1.11.2",
|
|
26
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
|
27
|
+
"@types/dom-mediacapture-transform": "^0.1.10",
|
|
28
|
+
"@types/node": "22.15.7",
|
|
29
|
+
"@types/w3c-image-capture": "^1.0.10",
|
|
30
|
+
"@webgpu/types": "^0.1.52",
|
|
31
|
+
"rollup": "^4.12.0",
|
|
32
|
+
"tslib": "^2.8.1",
|
|
33
|
+
"typescript": "^5.7.2"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @module Interface wasi:frame-buffer/frame-buffer@0.0.1 **/
|
|
2
|
+
export type Context = import('./wasi-graphics-context-graphics-context.js').Context;
|
|
3
|
+
export type AbstractBuffer = import('./wasi-graphics-context-graphics-context.js').AbstractBuffer;
|
|
4
|
+
|
|
5
|
+
export class Buffer {
|
|
6
|
+
/**
|
|
7
|
+
* This type does not have a public constructor.
|
|
8
|
+
*/
|
|
9
|
+
private constructor();
|
|
10
|
+
static fromGraphicsBuffer(buffer: AbstractBuffer): Buffer;
|
|
11
|
+
/**
|
|
12
|
+
* TODO: This should be replcated with something that doesn't require a copy.
|
|
13
|
+
*/
|
|
14
|
+
get(): Uint8Array;
|
|
15
|
+
set(val: Uint8Array): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class Device {
|
|
19
|
+
constructor()
|
|
20
|
+
connectGraphicsContext(context: Context): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @module Interface wasi:graphics-context/graphics-context@0.0.1 **/
|
|
2
|
+
|
|
3
|
+
export class AbstractBuffer {
|
|
4
|
+
/**
|
|
5
|
+
* This type does not have a public constructor.
|
|
6
|
+
*/
|
|
7
|
+
private constructor();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class Context {
|
|
11
|
+
constructor()
|
|
12
|
+
getCurrentBuffer(): AbstractBuffer;
|
|
13
|
+
/**
|
|
14
|
+
* TODO: might want to remove this.
|
|
15
|
+
*/
|
|
16
|
+
present(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @module Interface wasi:io/error@0.2.0 **/
|
|
2
|
+
|
|
3
|
+
export class Error {
|
|
4
|
+
/**
|
|
5
|
+
* This type does not have a public constructor.
|
|
6
|
+
*/
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Returns a string that is suitable to assist humans in debugging
|
|
10
|
+
* this error.
|
|
11
|
+
*
|
|
12
|
+
* WARNING: The returned string should not be consumed mechanically!
|
|
13
|
+
* It may change across platforms, hosts, or other implementation
|
|
14
|
+
* details. Parsing this string is a major platform-compatibility
|
|
15
|
+
* hazard.
|
|
16
|
+
*/
|
|
17
|
+
toDebugString(): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** @module Interface wasi:io/poll@0.2.0 **/
|
|
2
|
+
/**
|
|
3
|
+
* Poll for completion on a set of pollables.
|
|
4
|
+
*
|
|
5
|
+
* This function takes a list of pollables, which identify I/O sources of
|
|
6
|
+
* interest, and waits until one or more of the events is ready for I/O.
|
|
7
|
+
*
|
|
8
|
+
* The result `list<u32>` contains one or more indices of handles in the
|
|
9
|
+
* argument list that is ready for I/O.
|
|
10
|
+
*
|
|
11
|
+
* If the list contains more elements than can be indexed with a `u32`
|
|
12
|
+
* value, this function traps.
|
|
13
|
+
*
|
|
14
|
+
* A timeout can be implemented by adding a pollable from the
|
|
15
|
+
* wasi-clocks API to the list.
|
|
16
|
+
*
|
|
17
|
+
* This function does not return a `result`; polling in itself does not
|
|
18
|
+
* do any I/O so it doesn't fail. If any of the I/O sources identified by
|
|
19
|
+
* the pollables has an error, it is indicated by marking the source as
|
|
20
|
+
* being reaedy for I/O.
|
|
21
|
+
*/
|
|
22
|
+
export function poll(in_: Array<Pollable>): Uint32Array;
|
|
23
|
+
|
|
24
|
+
export class Pollable {
|
|
25
|
+
/**
|
|
26
|
+
* This type does not have a public constructor.
|
|
27
|
+
*/
|
|
28
|
+
private constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Return the readiness of a pollable. This function never blocks.
|
|
31
|
+
*
|
|
32
|
+
* Returns `true` when the pollable is ready, and `false` otherwise.
|
|
33
|
+
*/
|
|
34
|
+
ready(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* `block` returns immediately if the pollable is ready, and otherwise
|
|
37
|
+
* blocks until ready.
|
|
38
|
+
*
|
|
39
|
+
* This function is equivalent to calling `poll.poll` on a list
|
|
40
|
+
* containing only this pollable.
|
|
41
|
+
*/
|
|
42
|
+
block(): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/** @module Interface wasi:io/streams@0.2.0 **/
|
|
2
|
+
export type Error = import('./wasi-io-error.js').Error;
|
|
3
|
+
export type Pollable = import('./wasi-io-poll.js').Pollable;
|
|
4
|
+
/**
|
|
5
|
+
* An error for input-stream and output-stream operations.
|
|
6
|
+
*/
|
|
7
|
+
export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
|
|
8
|
+
/**
|
|
9
|
+
* The last operation (a write or flush) failed before completion.
|
|
10
|
+
*
|
|
11
|
+
* More information is available in the `error` payload.
|
|
12
|
+
*/
|
|
13
|
+
export interface StreamErrorLastOperationFailed {
|
|
14
|
+
tag: 'last-operation-failed',
|
|
15
|
+
val: Error,
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The stream is closed: no more input will be accepted by the
|
|
19
|
+
* stream. A closed output-stream will return this error on all
|
|
20
|
+
* future operations.
|
|
21
|
+
*/
|
|
22
|
+
export interface StreamErrorClosed {
|
|
23
|
+
tag: 'closed',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class InputStream {
|
|
27
|
+
/**
|
|
28
|
+
* This type does not have a public constructor.
|
|
29
|
+
*/
|
|
30
|
+
private constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Perform a non-blocking read from the stream.
|
|
33
|
+
*
|
|
34
|
+
* When the source of a `read` is binary data, the bytes from the source
|
|
35
|
+
* are returned verbatim. When the source of a `read` is known to the
|
|
36
|
+
* implementation to be text, bytes containing the UTF-8 encoding of the
|
|
37
|
+
* text are returned.
|
|
38
|
+
*
|
|
39
|
+
* This function returns a list of bytes containing the read data,
|
|
40
|
+
* when successful. The returned list will contain up to `len` bytes;
|
|
41
|
+
* it may return fewer than requested, but not more. The list is
|
|
42
|
+
* empty when no bytes are available for reading at this time. The
|
|
43
|
+
* pollable given by `subscribe` will be ready when more bytes are
|
|
44
|
+
* available.
|
|
45
|
+
*
|
|
46
|
+
* This function fails with a `stream-error` when the operation
|
|
47
|
+
* encounters an error, giving `last-operation-failed`, or when the
|
|
48
|
+
* stream is closed, giving `closed`.
|
|
49
|
+
*
|
|
50
|
+
* When the caller gives a `len` of 0, it represents a request to
|
|
51
|
+
* read 0 bytes. If the stream is still open, this call should
|
|
52
|
+
* succeed and return an empty list, or otherwise fail with `closed`.
|
|
53
|
+
*
|
|
54
|
+
* The `len` parameter is a `u64`, which could represent a list of u8 which
|
|
55
|
+
* is not possible to allocate in wasm32, or not desirable to allocate as
|
|
56
|
+
* as a return value by the callee. The callee may return a list of bytes
|
|
57
|
+
* less than `len` in size while more bytes are available for reading.
|
|
58
|
+
*/
|
|
59
|
+
read(len: bigint): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Read bytes from a stream, after blocking until at least one byte can
|
|
62
|
+
* be read. Except for blocking, behavior is identical to `read`.
|
|
63
|
+
*/
|
|
64
|
+
blockingRead(len: bigint): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Skip bytes from a stream. Returns number of bytes skipped.
|
|
67
|
+
*
|
|
68
|
+
* Behaves identical to `read`, except instead of returning a list
|
|
69
|
+
* of bytes, returns the number of bytes consumed from the stream.
|
|
70
|
+
*/
|
|
71
|
+
skip(len: bigint): bigint;
|
|
72
|
+
/**
|
|
73
|
+
* Skip bytes from a stream, after blocking until at least one byte
|
|
74
|
+
* can be skipped. Except for blocking behavior, identical to `skip`.
|
|
75
|
+
*/
|
|
76
|
+
blockingSkip(len: bigint): bigint;
|
|
77
|
+
/**
|
|
78
|
+
* Create a `pollable` which will resolve once either the specified stream
|
|
79
|
+
* has bytes available to read or the other end of the stream has been
|
|
80
|
+
* closed.
|
|
81
|
+
* The created `pollable` is a child resource of the `input-stream`.
|
|
82
|
+
* Implementations may trap if the `input-stream` is dropped before
|
|
83
|
+
* all derived `pollable`s created with this function are dropped.
|
|
84
|
+
*/
|
|
85
|
+
subscribe(): Pollable;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class OutputStream {
|
|
89
|
+
/**
|
|
90
|
+
* This type does not have a public constructor.
|
|
91
|
+
*/
|
|
92
|
+
private constructor();
|
|
93
|
+
/**
|
|
94
|
+
* Check readiness for writing. This function never blocks.
|
|
95
|
+
*
|
|
96
|
+
* Returns the number of bytes permitted for the next call to `write`,
|
|
97
|
+
* or an error. Calling `write` with more bytes than this function has
|
|
98
|
+
* permitted will trap.
|
|
99
|
+
*
|
|
100
|
+
* When this function returns 0 bytes, the `subscribe` pollable will
|
|
101
|
+
* become ready when this function will report at least 1 byte, or an
|
|
102
|
+
* error.
|
|
103
|
+
*/
|
|
104
|
+
checkWrite(): bigint;
|
|
105
|
+
/**
|
|
106
|
+
* Perform a write. This function never blocks.
|
|
107
|
+
*
|
|
108
|
+
* When the destination of a `write` is binary data, the bytes from
|
|
109
|
+
* `contents` are written verbatim. When the destination of a `write` is
|
|
110
|
+
* known to the implementation to be text, the bytes of `contents` are
|
|
111
|
+
* transcoded from UTF-8 into the encoding of the destination and then
|
|
112
|
+
* written.
|
|
113
|
+
*
|
|
114
|
+
* Precondition: check-write gave permit of Ok(n) and contents has a
|
|
115
|
+
* length of less than or equal to n. Otherwise, this function will trap.
|
|
116
|
+
*
|
|
117
|
+
* returns Err(closed) without writing if the stream has closed since
|
|
118
|
+
* the last call to check-write provided a permit.
|
|
119
|
+
*/
|
|
120
|
+
write(contents: Uint8Array): void;
|
|
121
|
+
/**
|
|
122
|
+
* Perform a write of up to 4096 bytes, and then flush the stream. Block
|
|
123
|
+
* until all of these operations are complete, or an error occurs.
|
|
124
|
+
*
|
|
125
|
+
* This is a convenience wrapper around the use of `check-write`,
|
|
126
|
+
* `subscribe`, `write`, and `flush`, and is implemented with the
|
|
127
|
+
* following pseudo-code:
|
|
128
|
+
*
|
|
129
|
+
* ```text
|
|
130
|
+
* let pollable = this.subscribe();
|
|
131
|
+
* while !contents.is_empty() {
|
|
132
|
+
* // Wait for the stream to become writable
|
|
133
|
+
* pollable.block();
|
|
134
|
+
* let Ok(n) = this.check-write(); // eliding error handling
|
|
135
|
+
* let len = min(n, contents.len());
|
|
136
|
+
* let (chunk, rest) = contents.split_at(len);
|
|
137
|
+
* this.write(chunk ); // eliding error handling
|
|
138
|
+
* contents = rest;
|
|
139
|
+
* }
|
|
140
|
+
* this.flush();
|
|
141
|
+
* // Wait for completion of `flush`
|
|
142
|
+
* pollable.block();
|
|
143
|
+
* // Check for any errors that arose during `flush`
|
|
144
|
+
* let _ = this.check-write(); // eliding error handling
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
blockingWriteAndFlush(contents: Uint8Array): void;
|
|
148
|
+
/**
|
|
149
|
+
* Request to flush buffered output. This function never blocks.
|
|
150
|
+
*
|
|
151
|
+
* This tells the output-stream that the caller intends any buffered
|
|
152
|
+
* output to be flushed. the output which is expected to be flushed
|
|
153
|
+
* is all that has been passed to `write` prior to this call.
|
|
154
|
+
*
|
|
155
|
+
* Upon calling this function, the `output-stream` will not accept any
|
|
156
|
+
* writes (`check-write` will return `ok(0)`) until the flush has
|
|
157
|
+
* completed. The `subscribe` pollable will become ready when the
|
|
158
|
+
* flush has completed and the stream can accept more writes.
|
|
159
|
+
*/
|
|
160
|
+
flush(): void;
|
|
161
|
+
/**
|
|
162
|
+
* Request to flush buffered output, and block until flush completes
|
|
163
|
+
* and stream is ready for writing again.
|
|
164
|
+
*/
|
|
165
|
+
blockingFlush(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Create a `pollable` which will resolve once the output-stream
|
|
168
|
+
* is ready for more writing, or an error has occured. When this
|
|
169
|
+
* pollable is ready, `check-write` will return `ok(n)` with n>0, or an
|
|
170
|
+
* error.
|
|
171
|
+
*
|
|
172
|
+
* If the stream is closed, this pollable is always ready immediately.
|
|
173
|
+
*
|
|
174
|
+
* The created `pollable` is a child resource of the `output-stream`.
|
|
175
|
+
* Implementations may trap if the `output-stream` is dropped before
|
|
176
|
+
* all derived `pollable`s created with this function are dropped.
|
|
177
|
+
*/
|
|
178
|
+
subscribe(): Pollable;
|
|
179
|
+
/**
|
|
180
|
+
* Write zeroes to a stream.
|
|
181
|
+
*
|
|
182
|
+
* This should be used precisely like `write` with the exact same
|
|
183
|
+
* preconditions (must use check-write first), but instead of
|
|
184
|
+
* passing a list of bytes, you simply pass the number of zero-bytes
|
|
185
|
+
* that should be written.
|
|
186
|
+
*/
|
|
187
|
+
writeZeroes(len: bigint): void;
|
|
188
|
+
/**
|
|
189
|
+
* Perform a write of up to 4096 zeroes, and then flush the stream.
|
|
190
|
+
* Block until all of these operations are complete, or an error
|
|
191
|
+
* occurs.
|
|
192
|
+
*
|
|
193
|
+
* This is a convenience wrapper around the use of `check-write`,
|
|
194
|
+
* `subscribe`, `write-zeroes`, and `flush`, and is implemented with
|
|
195
|
+
* the following pseudo-code:
|
|
196
|
+
*
|
|
197
|
+
* ```text
|
|
198
|
+
* let pollable = this.subscribe();
|
|
199
|
+
* while num_zeroes != 0 {
|
|
200
|
+
* // Wait for the stream to become writable
|
|
201
|
+
* pollable.block();
|
|
202
|
+
* let Ok(n) = this.check-write(); // eliding error handling
|
|
203
|
+
* let len = min(n, num_zeroes);
|
|
204
|
+
* this.write-zeroes(len); // eliding error handling
|
|
205
|
+
* num_zeroes -= len;
|
|
206
|
+
* }
|
|
207
|
+
* this.flush();
|
|
208
|
+
* // Wait for completion of `flush`
|
|
209
|
+
* pollable.block();
|
|
210
|
+
* // Check for any errors that arose during `flush`
|
|
211
|
+
* let _ = this.check-write(); // eliding error handling
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
blockingWriteZeroesAndFlush(len: bigint): void;
|
|
215
|
+
/**
|
|
216
|
+
* Read from one stream and write to another.
|
|
217
|
+
*
|
|
218
|
+
* The behavior of splice is equivelant to:
|
|
219
|
+
* 1. calling `check-write` on the `output-stream`
|
|
220
|
+
* 2. calling `read` on the `input-stream` with the smaller of the
|
|
221
|
+
* `check-write` permitted length and the `len` provided to `splice`
|
|
222
|
+
* 3. calling `write` on the `output-stream` with that read data.
|
|
223
|
+
*
|
|
224
|
+
* Any error reported by the call to `check-write`, `read`, or
|
|
225
|
+
* `write` ends the splice and reports that error.
|
|
226
|
+
*
|
|
227
|
+
* This function returns the number of bytes transferred; it may be less
|
|
228
|
+
* than `len`.
|
|
229
|
+
*/
|
|
230
|
+
splice(src: InputStream, len: bigint): bigint;
|
|
231
|
+
/**
|
|
232
|
+
* Read from one stream and write to another, with blocking.
|
|
233
|
+
*
|
|
234
|
+
* This is similar to `splice`, except that it blocks until the
|
|
235
|
+
* `output-stream` is ready for writing, and the `input-stream`
|
|
236
|
+
* is ready for reading, before performing the `splice`.
|
|
237
|
+
*/
|
|
238
|
+
blockingSplice(src: InputStream, len: bigint): bigint;
|
|
239
|
+
}
|
|
240
|
+
|