@simulatte/webgpu 0.3.0 → 0.3.2

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 (50) hide show
  1. package/CHANGELOG.md +37 -10
  2. package/LICENSE +191 -0
  3. package/README.md +62 -48
  4. package/api-contract.md +67 -49
  5. package/architecture.md +317 -0
  6. package/assets/package-layers.svg +3 -3
  7. package/docs/doe-api-reference.html +1842 -0
  8. package/doe-api-design.md +237 -0
  9. package/examples/doe-api/README.md +19 -0
  10. package/examples/doe-api/buffers-readback.js +3 -2
  11. package/examples/{doe-routines/compute-once-like-input.js → doe-api/compute-one-shot-like-input.js} +1 -1
  12. package/examples/{doe-routines/compute-once-matmul.js → doe-api/compute-one-shot-matmul.js} +2 -2
  13. package/examples/{doe-routines/compute-once-multiple-inputs.js → doe-api/compute-one-shot-multiple-inputs.js} +1 -1
  14. package/examples/{doe-routines/compute-once.js → doe-api/compute-one-shot.js} +1 -1
  15. package/examples/doe-api/{compile-and-dispatch.js → kernel-create-and-dispatch.js} +4 -6
  16. package/examples/doe-api/{compute-dispatch.js → kernel-run.js} +4 -6
  17. package/headless-webgpu-comparison.md +3 -3
  18. package/jsdoc-style-guide.md +435 -0
  19. package/native/doe_napi.c +1481 -84
  20. package/package.json +18 -6
  21. package/prebuilds/darwin-arm64/doe_napi.node +0 -0
  22. package/prebuilds/darwin-arm64/libwebgpu_doe.dylib +0 -0
  23. package/prebuilds/darwin-arm64/metadata.json +5 -5
  24. package/prebuilds/linux-x64/metadata.json +1 -1
  25. package/scripts/generate-doe-api-docs.js +1607 -0
  26. package/scripts/generate-readme-assets.js +3 -3
  27. package/src/build_metadata.js +7 -4
  28. package/src/bun-ffi.js +1229 -474
  29. package/src/bun.js +5 -1
  30. package/src/compute.d.ts +16 -7
  31. package/src/compute.js +84 -53
  32. package/src/full.d.ts +16 -7
  33. package/src/full.js +12 -10
  34. package/src/index.js +679 -1324
  35. package/src/runtime_cli.js +17 -17
  36. package/src/shared/capabilities.js +144 -0
  37. package/src/shared/compiler-errors.js +78 -0
  38. package/src/shared/encoder-surface.js +295 -0
  39. package/src/shared/full-surface.js +514 -0
  40. package/src/shared/public-surface.js +82 -0
  41. package/src/shared/resource-lifecycle.js +120 -0
  42. package/src/shared/validation.js +495 -0
  43. package/src/webgpu_constants.js +30 -0
  44. package/support-contracts.md +2 -2
  45. package/compat-scope.md +0 -46
  46. package/layering-plan.md +0 -259
  47. package/src/auto_bind_group_layout.js +0 -32
  48. package/src/doe.d.ts +0 -184
  49. package/src/doe.js +0 -641
  50. package/zig-source-inventory.md +0 -468
package/CHANGELOG.md CHANGED
@@ -7,26 +7,53 @@ retrofitted from package version history and package-surface commits so the npm
7
7
  package has a conventional release history alongside the broader Fawn status
8
8
  and process documents.
9
9
 
10
+ ## [0.3.2] - 2026-03-15
11
+
12
+ ### Changed
13
+
14
+ - Switched the package Doe helper namespace to depend on the standalone
15
+ `@simulatte/webgpu-doe` package instead of the previous bundled-only import
16
+ path.
17
+ - Updated the package README to point package users at the new helper-only
18
+ package when they want the Doe API as an independent npm boundary.
19
+
20
+ ## [0.3.1] - 2026-03-11
21
+
22
+ ### Changed
23
+
24
+ - Tightened the published package README wording, section names, and layering
25
+ narrative after the `0.3.0` release.
26
+ - Clarified the terminology split between the `Doe runtime` underneath the
27
+ package and the `Doe API` JS convenience surface exposed by the package,
28
+ including the more opinionated `gpu.compute(...)` helper within it.
29
+ - Fixed the layered README SVG asset so it renders correctly on package
30
+ surfaces.
31
+
10
32
  ## [0.3.0] - 2026-03-11
11
33
 
12
34
  ### Changed
13
35
 
14
36
  - Breaking: redesigned the shared `doe` surface around `await
15
- doe.requestDevice()`, grouped `gpu.buffers.*`, and grouped
16
- `gpu.compute.*` instead of the earlier flat bound-helper methods.
17
- - Added `gpu.buffers.like(...)` for buffer-allocation boilerplate reduction and
18
- `gpu.compute.once(...)` for the first `Doe routines` workflow.
37
+ doe.requestDevice()`, grouped `gpu.buffer.*`, grouped `gpu.kernel.*`, and
38
+ `gpu.compute(...)` instead of the earlier flat bound-helper methods.
39
+ - Added `gpu.compute(...)` as the first more opinionated one-shot helper inside
40
+ the Doe API.
41
+ - `gpu.buffer.create(...)` now accepts an optional `data` field for combined
42
+ allocation and upload (replaces `fromData`). `like(...)` removed; use
43
+ `create({ size: src.size, ... })`. `read(...)` now takes an options bag.
19
44
  - Doe helper token values now use camelCase (`storageRead`,
20
45
  `storageReadWrite`) and Doe workgroups now accept `[x, y]` in addition to
21
46
  `number` and `[x, y, z]`.
22
- - `gpu.compute.once(...)` now rejects raw numeric WebGPU usage flags; use Doe
23
- usage tokens there or drop to `gpu.buffers.*` for explicit raw-flag control.
47
+ - `gpu.compute(...)` now rejects raw numeric WebGPU usage flags; use Doe
48
+ usage tokens there or drop to `gpu.buffer.*` / `gpu.kernel.*` for explicit
49
+ raw control.
24
50
  - Kept the same `doe` shape on `@simulatte/webgpu` and
25
51
  `@simulatte/webgpu/compute`; the package split remains the underlying raw
26
52
  device surface (`full` vs compute-only facade), not separate helper dialects.
27
53
  - Updated the package README, API contract, and JSDoc guide to standardize the
28
- `Direct WebGPU`, `Doe API`, and `Doe routines` model and the boundary between the headless package lane and
29
- `nursery/fawn-browser`.
54
+ `Direct WebGPU` and `Doe API` model, including the more opinionated
55
+ `gpu.compute(...)` helper within the Doe API, and the boundary between
56
+ the headless package lane and `nursery/fawn-browser`.
30
57
 
31
58
  ## [0.2.4] - 2026-03-11
32
59
 
@@ -54,8 +81,8 @@ and process documents.
54
81
  - Added explicit package export surfaces for `@simulatte/webgpu` (default
55
82
  full) and `@simulatte/webgpu/compute`, plus the first `doe` ergonomic
56
83
  namespace for buffer/readback/compute helpers.
57
- - Added `doe.bind(device)` so the ergonomic helper surface supports device-bound
58
- workflows in addition to static helper calls.
84
+ - Added `doe.bind(device)` so the ergonomic helper surface can wrap an existing
85
+ device into the same bound helper object returned by `doe.requestDevice()`.
59
86
 
60
87
  ### Changed
61
88
 
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Fawn Contributors
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md CHANGED
@@ -6,27 +6,35 @@
6
6
  <strong>Run real WebGPU workloads in Node.js and Bun with Doe, the WebGPU runtime from Fawn.</strong>
7
7
  </td>
8
8
  <td valign="middle">
9
- <img src="assets/fawn-icon-main-256.png" alt="Fawn logo" width="88" />
9
+ <img src="assets/fawn-icon-main.svg" alt="Fawn logo" width="88" />
10
10
  </td>
11
11
  </tr>
12
12
  </table>
13
13
 
14
14
  `@simulatte/webgpu` is Fawn's headless WebGPU package for Node.js and Bun: use
15
15
  the raw WebGPU API through `requestDevice()` and `device.*`, or move up to the
16
- Doe API + routines when you want the same runtime with less setup. Browser
17
- DOM/canvas ownership lives in the separate `nursery/fawn-browser` lane.
16
+ Doe API when you want the same runtime with less setup. Browser DOM/canvas
17
+ ownership lives in the separate `nursery/fawn-browser` lane.
18
18
 
19
19
  Terminology in this README is deliberate:
20
20
 
21
21
  - `Doe runtime` means the Zig/native WebGPU runtime underneath the package
22
- - `Doe API` means the explicit JS convenience surface under `doe`, `gpu.buffers.*`,
23
- `gpu.compute.run(...)`, and `gpu.compute.compile(...)`
24
- - `Doe routines` means the narrower, more opinionated JS flows such as
25
- `gpu.compute.once(...)`
22
+ - `Doe API` means the explicit JS convenience surface under `doe`, `gpu.buffer.*`,
23
+ `gpu.kernel.run(...)`, `gpu.kernel.create(...)`, and `gpu.compute(...)`
24
+
25
+ The current implemented helper contract is documented in
26
+ [api-contract.md](./api-contract.md). The proposed naming cleanup for the Doe
27
+ helper surface is documented in [doe-api-design.md](./doe-api-design.md).
28
+ The generated interactive Doe API reference lives at
29
+ [docs/doe-api-reference.html](./docs/doe-api-reference.html).
30
+
31
+ The same helper layer is now also published separately as
32
+ `@simulatte/webgpu-doe` when you want the Doe API as an independent package
33
+ boundary.
26
34
 
27
35
  ## Start here
28
36
 
29
- ### Same workload, two layers
37
+ ### From direct WebGPU to Doe API
30
38
 
31
39
  The same simple compute pass, shown first at the raw WebGPU layer and then at
32
40
  the explicit Doe API layer.
@@ -110,12 +118,10 @@ to manage the resources yourself.
110
118
  import { doe } from "@simulatte/webgpu/compute";
111
119
 
112
120
  const gpu = await doe.requestDevice();
113
- const src = gpu.buffers.fromData(Float32Array.of(1, 2, 3, 4));
114
- const dst = gpu.buffers.like(src, {
115
- usage: "storageReadWrite",
116
- });
121
+ const src = gpu.buffer.create({ data: Float32Array.of(1, 2, 3, 4) });
122
+ const dst = gpu.buffer.create({ size: src.size, usage: "storageReadWrite" });
117
123
 
118
- await gpu.compute.run({
124
+ await gpu.kernel.run({
119
125
  code: `
120
126
  @group(0) @binding(0) var<storage, read> src: array<f32>;
121
127
  @group(0) @binding(1) var<storage, read_write> dst: array<f32>;
@@ -131,18 +137,18 @@ await gpu.compute.run({
131
137
  workgroups: 1,
132
138
  });
133
139
 
134
- console.log(await gpu.buffers.read(dst, Float32Array)); // Float32Array(4) [ 2, 4, 6, 8 ]
140
+ console.log(await gpu.buffer.read({ buffer: dst, type: Float32Array })); // Float32Array(4) [ 2, 4, 6, 8 ]
135
141
  ```
136
142
 
137
- The package identity is simple:
143
+ What this package gives you:
138
144
 
139
145
  - `requestDevice()` gives you real headless WebGPU
140
146
  - `doe` gives you the same runtime with less boilerplate and explicit resource control
141
- - `compute.once(...)` is the more opinionated routines layer when you do not want to manage buffers and readback yourself
147
+ - `gpu.compute(...)` is the more opinionated Doe API helper when you do not want to manage buffers and readback yourself
142
148
 
143
- #### 3. Doe routines: one-shot tensor matmul
149
+ #### 3. Doe API: one-shot tensor matmul
144
150
 
145
- This is where the routines layer starts to separate itself: you pass typed
151
+ This is the more opinionated one-shot end of the Doe API: you pass typed
146
152
  arrays and an output spec, and the package handles upload, output allocation,
147
153
  dispatch, and readback while the shader and tensor shapes stay explicit.
148
154
 
@@ -156,7 +162,7 @@ const lhs = Float32Array.from({ length: M * K }, (_, i) => (i % 17) / 17);
156
162
  const rhs = Float32Array.from({ length: K * N }, (_, i) => (i % 13) / 13);
157
163
  const dims = new Uint32Array([M, K, N, 0]);
158
164
 
159
- const result = await gpu.compute.once({
165
+ const result = await gpu.compute({
160
166
  code: `
161
167
  struct Dims {
162
168
  m: u32,
@@ -185,11 +191,7 @@ const result = await gpu.compute.once({
185
191
  out[row * dims.n + col] = acc;
186
192
  }
187
193
  `,
188
- inputs: [
189
- { data: dims, usage: "uniform", access: "uniform" },
190
- lhs,
191
- rhs,
192
- ],
194
+ inputs: [{ data: dims, usage: "uniform", access: "uniform" }, lhs, rhs],
193
195
  output: {
194
196
  type: Float32Array,
195
197
  size: M * N * Float32Array.BYTES_PER_ELEMENT,
@@ -200,11 +202,11 @@ const result = await gpu.compute.once({
200
202
  console.log(result.subarray(0, 8)); // Float32Array(8) [ ... ]
201
203
  ```
202
204
 
203
- ### Benchmarked package surface
205
+ ### Benchmark snapshot
204
206
 
205
- The package is not just a wrapper API. It is the headless package surface of
206
- the Doe runtime, Fawn's Zig-first WebGPU implementation, and it is exercised as
207
- a measured package surface with explicit package lanes.
207
+ This package is the headless package surface of the Doe runtime, Fawn's
208
+ Zig-first WebGPU implementation, and it is benchmarked through separate
209
+ Node and Bun package lanes.
208
210
 
209
211
  <p align="center">
210
212
  <img src="assets/package-surface-cube-snapshot.svg" alt="Static package-surface benchmark cube snapshot" width="920" />
@@ -221,6 +223,12 @@ separate `nursery/fawn-browser` Chromium/browser integration lane.
221
223
  npm install @simulatte/webgpu
222
224
  ```
223
225
 
226
+ If you want the helper-only extraction explicitly:
227
+
228
+ ```bash
229
+ npm install @simulatte/webgpu @simulatte/webgpu-doe
230
+ ```
231
+
224
232
  The install ships platform-specific prebuilds for macOS arm64 (Metal) and
225
233
  Linux x64 (Vulkan). If no prebuild matches your platform, the installer falls
226
234
  back to building the native addon with `node-gyp` only; it does not build or
@@ -229,18 +237,18 @@ platforms, use a local Fawn workspace build for those runtime libraries.
229
237
 
230
238
  ## Choose a surface
231
239
 
232
- | Import | Surface | Includes |
233
- | --------------------------- | --------------------- | --------------------------------------------------------- |
234
- | `@simulatte/webgpu` | Default full surface | Buffers, compute, textures, samplers, render, Doe API + routines |
235
- | `@simulatte/webgpu/compute` | Compute-first surface | Buffers, compute, copy/upload/readback, Doe API + routines |
236
- | `@simulatte/webgpu/full` | Explicit full surface | Same contract as the default package surface |
240
+ | Import | Surface | Includes |
241
+ | --------------------------- | --------------------- | ---------------------------------------------------------------- |
242
+ | `@simulatte/webgpu` | Default full surface | Buffers, compute, textures, samplers, render, Doe API |
243
+ | `@simulatte/webgpu/compute` | Compute-first surface | Buffers, compute, copy/upload/readback, Doe API |
244
+ | `@simulatte/webgpu/full` | Explicit full surface | Same contract as the default package surface |
237
245
 
238
246
  Use `@simulatte/webgpu/compute` when you want the constrained package contract
239
247
  for AI workloads and other buffer/dispatch-heavy headless execution. The
240
248
  compute surface intentionally omits render and sampler methods from the JS
241
249
  facade.
242
250
 
243
- ## Package basics
251
+ ## Basic entry points
244
252
 
245
253
  ### Inspect the provider
246
254
 
@@ -269,38 +277,44 @@ console.log(typeof device.createComputePipeline); // "function"
269
277
  console.log(typeof device.createRenderPipeline); // "undefined"
270
278
  ```
271
279
 
272
- ## Doe layers
280
+ ## API layers
273
281
 
274
- The package exposes three layers over the same runtime:
282
+ The package gives you two API styles over the same Doe runtime:
275
283
 
276
284
  <p align="center">
277
- <img src="assets/package-layers.svg" alt="Layered package graph showing direct WebGPU, Doe API, and Doe routines over the same package surfaces." width="920" />
285
+ <img src="assets/package-layers.svg" alt="Layered package graph showing direct WebGPU and Doe API over the same package surfaces." width="920" />
278
286
  </p>
279
287
 
280
288
  - `Direct WebGPU`
281
289
  raw `requestDevice()` plus direct `device.*`
282
290
  - `Doe API`
283
- explicit Doe surface for lower-boilerplate buffer and compute flows
284
- - `Doe routines`
285
- more opinionated Doe flows where the JS surface carries more of the operation
291
+ explicit Doe surface for lower-boilerplate buffer, kernel, and one-shot compute flows
286
292
 
287
293
  Examples for each style ship in:
288
294
 
289
295
  - `examples/direct-webgpu/`
290
296
  - `examples/doe-api/`
291
- - `examples/doe-routines/`
297
+
298
+ The Doe example directory is organized by API shape:
299
+
300
+ - `buffers-readback.js` for `gpu.buffer.*`
301
+ - `kernel-run.js` for `gpu.kernel.run(...)`
302
+ - `kernel-create-and-dispatch.js` for `gpu.kernel.create(...)` plus `kernel.dispatch(...)`
303
+ - `compute-one-shot*.js` for the `gpu.compute(...)` helper family
292
304
 
293
305
  `doe` is the package's shared JS convenience surface over the Doe runtime. It is available
294
306
  from both `@simulatte/webgpu` and `@simulatte/webgpu/compute`.
295
307
 
296
308
  - `await doe.requestDevice()` gets a bound helper object in one step; use
297
309
  `doe.bind(device)` when you already have a device.
298
- - `gpu.buffers.*`, `gpu.compute.run(...)`, and `gpu.compute.compile(...)` are
310
+ - `gpu.buffer.*`, `gpu.kernel.run(...)`, and `gpu.kernel.create(...)` are
299
311
  the main `Doe API` surface.
300
- - `gpu.compute.once(...)` is currently the first `Doe routines` path.
312
+ - `gpu.compute(...)` is the single more opinionated one-shot helper inside the same Doe API surface.
313
+ - `doe` itself is just the binding entrypoint; the actual helper methods live
314
+ on the returned `gpu` object.
301
315
 
302
- The Doe API and Doe routines surface is the same on both package surfaces.
303
- The difference is the raw device beneath it:
316
+ The Doe API surface is the same on both package surfaces. The difference is the
317
+ raw device beneath it:
304
318
 
305
319
  - `@simulatte/webgpu/compute` returns a compute-only facade
306
320
  - `@simulatte/webgpu` keeps the full headless device surface
@@ -349,9 +363,9 @@ covers the Node package contract and a packed-tarball export/import check.
349
363
 
350
364
  ## Further reading
351
365
 
366
+ - [Architecture](./architecture.md) — full layer stack from Zig native to package exports
352
367
  - [API contract](./api-contract.md)
368
+ - [Doe API design](./doe-api-design.md)
353
369
  - [Support contracts](./support-contracts.md)
354
- - [Compatibility scope](./compat-scope.md)
355
- - [Layering plan](./layering-plan.md)
370
+ - [Scope and non-goals](./api-contract.md#scope-and-non-goals)
356
371
  - [Headless WebGPU comparison](./headless-webgpu-comparison.md)
357
- - [Zig source inventory](./zig-source-inventory.md)
package/api-contract.md CHANGED
@@ -3,68 +3,57 @@
3
3
  Contract version: `v1`
4
4
 
5
5
  Scope: current headless WebGPU package contract for Node.js and Bun, with a
6
- default `full` surface, an explicit `compute` subpath, and the Doe API / Doe
7
- routines surface used by benchmarking, CI, and artifact-backed comparison
8
- workflows.
6
+ default `full` surface, an explicit `compute` subpath, and the Doe API surface
7
+ used by benchmarking, CI, and artifact-backed comparison workflows.
9
8
 
10
9
  Terminology in this contract is explicit:
11
10
 
12
11
  - `Doe runtime`
13
12
  the Zig/native WebGPU runtime underneath the package
14
13
  - `Doe API`
15
- the explicit JS convenience surface under `doe.bind(...)`, `gpu.buffers.*`,
16
- `gpu.compute.run(...)`, and `gpu.compute.compile(...)`
17
- - `Doe routines`
18
- the narrower, more opinionated JS flows layered on that same runtime;
19
- currently `gpu.compute.once(...)`
14
+ the explicit JS convenience surface under `doe.bind(...)`, `gpu.buffer.*`,
15
+ `gpu.kernel.run(...)`, `gpu.kernel.create(...)`, and `gpu.compute(...)`
20
16
 
21
17
  For the current `compute` vs `full` support split, see
22
- [`./support-contracts.md`](./support-contracts.md).
18
+ [`./support-contracts.md`](./support-contracts.md). For scope and non-goals, see
19
+ the bottom of this document.
23
20
 
24
21
  Exact type and method shapes live in:
25
22
 
26
23
  - [`./src/full.d.ts`](./src/full.d.ts)
27
24
  - [`./src/compute.d.ts`](./src/compute.d.ts)
28
- - [`./src/doe.d.ts`](./src/doe.d.ts)
25
+ - `@simulatte/webgpu-doe` in `src/index.d.ts`
26
+
27
+ Planned naming cleanup for the Doe helper surface is documented separately in:
28
+
29
+ - [`./doe-api-design.md`](./doe-api-design.md)
29
30
 
30
31
  This contract covers package-surface GPU access, provider metadata, and helper
31
32
  entrypoints. It does not promise DOM/canvas ownership or browser-process
32
33
  parity.
33
34
 
35
+ This is the contract for the current implemented API. It intentionally may
36
+ differ from the future helper naming proposed in `doe-api-design.md`.
37
+
34
38
  ## API styles
35
39
 
36
- The current package surface is organized around three API styles:
40
+ The package surface has two API styles: `Direct WebGPU` (raw
41
+ `requestAdapter`, `requestDevice`, `device.*`) and `Doe API` (convenience
42
+ surface under `doe.bind(...)`, `gpu.buffer.*`, `gpu.kernel.*`, and the
43
+ one-shot `gpu.compute(...)` helper).
37
44
 
38
- - `Direct WebGPU`
39
- raw `requestAdapter(...)`, `requestDevice(...)`, and direct `device.*` usage
40
- - `Doe API`
41
- the package's explicit JS convenience surface under `doe.bind(...)`,
42
- `gpu.buffers.*`, `gpu.compute.run(...)`, and `gpu.compute.compile(...)`
43
- - `Doe routines`
44
- the package's more opinionated precomposed flows; currently
45
- `gpu.compute.once(...)`
45
+ For the full layer stack from Zig native to package exports, see
46
+ [`./architecture.md`](./architecture.md).
46
47
 
47
48
  ## Export surfaces
48
49
 
49
- ### `@simulatte/webgpu`
50
-
51
- Default package surface.
52
-
53
- Contract:
54
-
55
- - headless `full` surface
56
- - includes compute plus render/sampler/surface APIs already exposed by the Doe runtime package surface
57
- - also exports the shared `doe` namespace for the Doe API and Doe routines surface
58
-
59
- ### `@simulatte/webgpu/compute`
60
-
61
- Compute-first package surface.
50
+ | Import | Surface |
51
+ |--------|---------|
52
+ | `@simulatte/webgpu` | Default full headless surface + `doe` namespace |
53
+ | `@simulatte/webgpu/compute` | Compute-first facade + `doe` namespace |
62
54
 
63
- Contract:
64
-
65
- - sized for AI workloads and other buffer/dispatch-heavy headless execution
66
- - excludes render/sampler/surface methods from the public JS facade
67
- - also exports the same `doe` namespace for the Doe API and Doe routines surface
55
+ Export paths and transport details are documented in
56
+ [`./architecture.md`](./architecture.md).
68
57
 
69
58
  ## Shared runtime API
70
59
 
@@ -85,6 +74,10 @@ level:
85
74
  - `setupGlobals(...)` installs globals and `navigator.gpu` when missing.
86
75
  - `requestAdapter(...)` and `requestDevice(...)` are the `Direct WebGPU` entry
87
76
  points.
77
+ - `preflightShaderSource(code)` validates WGSL source before pipeline creation
78
+ and returns structured compilation diagnostics.
79
+ - `setNativeTimeoutMs(ms)` sets the native-side timeout for synchronous GPU
80
+ operations (map, flush).
88
81
 
89
82
  On `@simulatte/webgpu/compute`, the returned device is intentionally
90
83
  compute-only:
@@ -105,22 +98,23 @@ Behavior:
105
98
 
106
99
  Behavior:
107
100
 
108
- - provides the `Doe API` and `Doe routines` surface for common headless
109
- compute tasks
101
+ - provides the `Doe API` surface for common headless compute tasks
110
102
  - the exported `doe` namespace is the JS convenience surface, distinct from
111
103
  the underlying Doe runtime
112
104
  - `requestDevice(options?)` resolves the package-local `requestDevice(...)` and returns
113
105
  the bound helper object directly
114
- - supports both static helper calls and `doe.bind(device)` for device-bound workflows
115
- - helper methods are grouped under `buffers.*` and `compute.*`
116
- - `buffers.*`, `compute.run(...)`, and `compute.compile(...)` are the main
106
+ - `doe.bind(device)` wraps an existing raw device into the same bound helper object
107
+ - helper methods are grouped under the bound helper object's `buffer.*`,
108
+ `kernel.*`, and `compute(...)`
109
+ - `buffer.*`, `kernel.run(...)`, and `kernel.create(...)` are the main
117
110
  `Doe API` surface
118
- - `compute.once(...)` is the first `Doe routines` path and stays intentionally
111
+ - `gpu.compute(...)` is the more opinionated one-shot helper inside the same
112
+ `Doe API` surface and stays intentionally
119
113
  narrow: typed-array/headless one-call execution, not a replacement for
120
114
  explicit reusable resource ownership
121
- - infers `compute.run(...).bindings` access from Doe helper-created buffer usage when that
115
+ - infers `kernel.run(...).bindings` access from Doe helper-created buffer usage when that
122
116
  usage maps to one bindable access mode (`uniform`, `storageRead`, `storageReadWrite`)
123
- - `compute.once(...)` accepts Doe usage tokens only; raw numeric WebGPU usage flags stay on
117
+ - `compute(...)` accepts Doe usage tokens only; raw numeric WebGPU usage flags stay on
124
118
  the more explicit `Doe API` surface
125
119
  - fails fast for bare bindings that do not carry Doe helper usage metadata or whose
126
120
  usage is non-bindable/ambiguous; callers must pass `{ buffer, access }` explicitly
@@ -156,8 +150,32 @@ Purpose:
156
150
 
157
151
  - one-command Dawn-vs-Doe compare wrapper from Node tooling.
158
152
 
159
- ## Non-goals in v1
153
+ ## Scope and non-goals
154
+
155
+ This package exists for headless GPU work in Node/Bun: compute, offscreen
156
+ execution, benchmarking, and CI. Compatibility work serves those surfaces first.
157
+
158
+ ### Required now
159
+
160
+ 1. Stable headless Node/Bun provider behavior for real Doe-native execution.
161
+ 2. Stable command/trace orchestration for benchmark and CI pipelines.
162
+ 3. Reliable wrappers for Doe native bench runs and Dawn-vs-Doe compare runs.
163
+ 4. Deterministic artifact paths and non-zero exit-code propagation.
164
+ 5. Minimal convenience entrypoints for Node consumers (`create`, `globals`,
165
+ `requestAdapter`/`requestDevice`, `setupGlobals`).
166
+
167
+ ### Optional later (only when demanded by integrations)
168
+
169
+ 1. Minimal constants compatibility (only constants required by real integrations).
170
+ 2. Provider-module swap support for non-default backends beyond `webgpu`.
171
+
172
+ ### Not planned
173
+
174
+ 1. Full `navigator.gpu` browser-parity behavior in Node.
175
+ 2. Full object lifetime/event parity (`device lost`, full error scopes, full mapping semantics).
176
+ 3. Broad drop-in support for arbitrary npm packages expecting complete `webgpu` behavior.
177
+ 4. Browser presentation parity.
160
178
 
161
- 1. Full browser-parity WebGPU JS object model emulation.
162
- 2. Browser presentation parity.
163
- 3. npm `webgpu` drop-in compatibility guarantee.
179
+ Decision rule: add parity features only after a concrete headless integration is
180
+ blocked by a missing capability and cannot be addressed by the existing package,
181
+ bridge, or CLI contract.