@simulatte/webgpu-doe 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 ADDED
@@ -0,0 +1,117 @@
1
+ # @simulatte/webgpu-doe
2
+
3
+ Native WebGPU runtime for Node.js via the Doe drop-in library.
4
+
5
+ Doe (`libdoe_webgpu`) is a Zig-built WebGPU routing layer that provides the
6
+ standard `wgpu*` C ABI. This package wraps it as a Node.js N-API addon, giving
7
+ JavaScript code a WebGPU compute surface without depending on browser runtimes.
8
+
9
+ ## Status
10
+
11
+ **v0.1.0 — bring your own libs.** This release ships the N-API binding source
12
+ and JS wrapper. You must build `libdoe_webgpu` yourself and point the package
13
+ to it. Prebuilt binaries are planned for a future release.
14
+
15
+ ## Requirements
16
+
17
+ - Node.js >= 18
18
+ - A C compiler (node-gyp builds the N-API addon on `npm install`)
19
+ - `libdoe_webgpu` shared library (`.dylib` / `.so` / `.dll`)
20
+ - Dawn sidecar library (`libwebgpu_dawn`) — loaded by `libdoe_webgpu` at runtime
21
+
22
+ ## Building libdoe_webgpu
23
+
24
+ From the [fawn](https://github.com/clocksmith/fawn) repository:
25
+
26
+ ```sh
27
+ cd fawn/zig
28
+ zig build dropin
29
+ # produces zig-out/lib/libdoe_webgpu.{dylib,so}
30
+ ```
31
+
32
+ The Dawn sidecar must also be built or obtained separately. See
33
+ `fawn/bench/vendor/dawn/` for build instructions.
34
+
35
+ ## Install
36
+
37
+ ```sh
38
+ npm install @simulatte/webgpu-doe
39
+ ```
40
+
41
+ node-gyp compiles the N-API addon automatically. If the build fails, ensure you
42
+ have a working C toolchain (`xcode-select --install` on macOS, `build-essential`
43
+ on Debian/Ubuntu).
44
+
45
+ ## Configuration
46
+
47
+ The package searches for `libdoe_webgpu` in these locations (first match wins):
48
+
49
+ 1. `DOE_WEBGPU_LIB` environment variable (full path to the shared library)
50
+ 2. `<package>/prebuilds/<platform>-<arch>/libdoe_webgpu.{ext}` (future prebuilds)
51
+ 3. `<workspace>/zig/zig-out/lib/libdoe_webgpu.{ext}` (monorepo dev layout)
52
+ 4. `<cwd>/zig/zig-out/lib/libdoe_webgpu.{ext}`
53
+
54
+ Dawn's sidecar library must be discoverable at runtime. On macOS/Linux, set
55
+ `DYLD_LIBRARY_PATH` or `LD_LIBRARY_PATH` to include the directory containing
56
+ `libwebgpu_dawn.dylib` / `libwebgpu_dawn.so`.
57
+
58
+ ```sh
59
+ export DOE_WEBGPU_LIB=/path/to/libdoe_webgpu.dylib
60
+ export DYLD_LIBRARY_PATH=/path/to/dawn/out/Release
61
+ node your-app.js
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ### Direct API
67
+
68
+ ```js
69
+ import { create, globals } from '@simulatte/webgpu-doe';
70
+
71
+ const gpu = create();
72
+ const adapter = await gpu.requestAdapter();
73
+ const device = await adapter.requestDevice();
74
+
75
+ const buffer = device.createBuffer({
76
+ size: 64,
77
+ usage: globals.GPUBufferUsage.STORAGE | globals.GPUBufferUsage.COPY_SRC,
78
+ });
79
+ ```
80
+
81
+ ### Setup globals (navigator.gpu)
82
+
83
+ ```js
84
+ import { setupGlobals } from '@simulatte/webgpu-doe';
85
+
86
+ setupGlobals(globalThis);
87
+
88
+ const adapter = await navigator.gpu.requestAdapter();
89
+ const device = await adapter.requestDevice();
90
+ ```
91
+
92
+ ### Convenience helpers
93
+
94
+ ```js
95
+ import { requestAdapter, requestDevice } from '@simulatte/webgpu-doe';
96
+
97
+ const adapter = await requestAdapter();
98
+ const device = await requestDevice();
99
+ ```
100
+
101
+ ## Supported surface
102
+
103
+ v0.1.0 covers the headless compute surface:
104
+
105
+ - Instance creation, adapter/device request
106
+ - Buffer create, map, unmap, destroy
107
+ - Shader module creation (WGSL)
108
+ - Compute pipeline, bind group layout, bind group, pipeline layout
109
+ - Command encoder, compute pass (setPipeline, setBindGroup, dispatch, end)
110
+ - Buffer-to-buffer copy
111
+ - Queue submit, queue writeBuffer
112
+
113
+ Render passes, textures, and canvas presentation are not yet supported.
114
+
115
+ ## License
116
+
117
+ ISC
package/binding.gyp ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "doe_napi",
5
+ "sources": ["native/doe_napi.c"],
6
+ "include_dirs": [],
7
+ "conditions": [
8
+ ["OS=='mac'", {
9
+ "xcode_settings": {
10
+ "OTHER_CFLAGS": ["-std=c11"],
11
+ "MACOSX_DEPLOYMENT_TARGET": "13.0"
12
+ }
13
+ }],
14
+ ["OS=='linux'", {
15
+ "cflags": ["-std=c11"]
16
+ }]
17
+ ]
18
+ }
19
+ ]
20
+ }