@zushah/wasmgpu 0.7.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,335 @@
1
+ <p align="center">
2
+ <a href="https://zushah.github.io/WasmGPU">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Zushah/WasmGPU/main/assets/logo-darkmode.png">
5
+ <img alt="WasmGPU logo" src="https://raw.githubusercontent.com/Zushah/WasmGPU/main/assets/logo-lightmode.png" width="50%">
6
+ </picture>
7
+ </a>
8
+ </p>
9
+ <p align="center">
10
+ <a href="https://www.github.com/Zushah/WasmGPU/releases/tag/v0.7.0"><img src="https://img.shields.io/badge/release-v0.7.0-005a9c?logo=github&logoColor=white" alt="Latest release"></a>
11
+ <a href="https://raw.githubusercontent.com/Zushah/WasmGPU/v0.7.0/dist/WasmGPU.js"><img src="https://img.shields.io/badge/minified-450.6_kB-654ff0?logo=javascript&logoColor=white" alt="450.6 kilobytes minified bundle size"></a>
12
+ <a href="https://www.npmjs.com/package/@zushah/wasmgpu"><img src="https://img.shields.io/npm/dm/%40zushah/wasmgpu?logo=npm&logoColor=white" alt="npm downloads per month"></a>
13
+ <a href="https://www.jsdelivr.com/package/gh/Zushah/WasmGPU"><img src="https://img.shields.io/jsdelivr/gh/hm/Zushah/WasmGPU?color=654ff0&logo=jsdelivr&logoColor=white" alt="jsDelivr requests per month"></a>
14
+ <a href="https://www.github.com/Zushah/WasmGPU/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/license-MPL--2.0-005a9c?logo=gitbook&logoColor=white" alt="Mozilla Public License 2.0"></a>
15
+ </p><br>
16
+
17
+ ## About
18
+
19
+ - 🔥 WebGPU × WebAssembly rendering and computing engine for scientific workloads in the browser.
20
+ - 🚀 Latest release: [**`v0.7.0`**](https://github.com/Zushah/WasmGPU/releases/tag/v0.7.0).
21
+ - 💡 Website: [https://zushah.github.io/WasmGPU](https://zushah.github.io/WasmGPU)
22
+ - ⚙️ WebGPU engine written in TypeScript, spanning **scene & assets** (meshes, pointclouds, glyphfields, data materials, lights, cameras, glTF 2.0 assets, mipmapped texture sampling, transparency, animations, 4- or 8-influence skinning, and richer built-in geometry including 2D primitives plus cartesian and parametric curves and surfaces for graphing); **rendering architecture** (WebAssembly-driven frustum culling, opaque draw batching with automatic instanced rendering, optional subpixel morphological anti-aliasing, configurable canvas format selection, and GPU ID-pass picking for both single-hit queries and rectangular or lasso region queries with typed results); **interaction, overlays, & diagnostics** (orbit/trackball orthographic/perspective camera navigation with bounds-based scene framing, inspection views, and a composable overlay and annotation toolkit with triads, grids, legends, markers, probes, and measurements); and **compute & interop** (a first-class WebGPU compute subsystem with reusable pipelines and buffers, an extensive kernels library, an ndarray abstraction, asynchronous readback utilities, a unified scale-transform model shared across rendering and computing workflows, and Python-in-the-browser interoperability).
23
+ - 🦀 WebAssembly driver written in Rust, spanning **data layout & transforms** (transforms stored in SoA memory with per-index dirty tracking and partial local or world propagation plus model and normal matrix packing); **animation & asset hot paths** (animation sampling and joint-matrix generation executed in WebAssembly together with glTF accessor deinterleaving, sparse patch application, numeric conversion, and mesh normal generation); **bounds, culling, & visibility** (world-space bounds computation for geometry, pointclouds, and glyphfields together with frustum plane extraction and sphere-frustum culling kernels); **array semantics & zero-copy staging** (ndarray indexing utilities for explicit shape-and-stride byte-offset math plus uniforms and instance data staged as zero-copy views into WebAssembly memory with explicit typed-slice handles for JavaScript interop); and **performance envelope** (hot-path allocations avoided via cached pipelines and bind-group layouts plus a frame arena and user heap arenas, with builds optimized via LLVM and Binaryen and SIMD128 enabled for even higher throughput).
24
+
25
+ ## Architecture Diagram
26
+
27
+ The diagram below reflects currently implemented subsystems and runtime flow in WasmGPU v0.7.0.
28
+
29
+ Solid arrows indicate control flow while dashed arrows indicate data and resource flow.
30
+
31
+ ```mermaid
32
+ flowchart LR
33
+ subgraph API["Public API"]
34
+ APP["User Application"]
35
+ ENG["WasmGPU v0.7.0"]
36
+ FAC["Factory surface: scene, camera, controls, geometry, material, texture, mesh, pointcloud, glyphfield, light, asset import, animation, overlay, annotation"]
37
+ end
38
+
39
+ subgraph RT["WebGPU Engine"]
40
+ LOOP["Frame loop"]
41
+ REND["Renderer"]
42
+ SCALE["Scaling service"]
43
+ OVER["Overlay framework"]
44
+ ANNO["Annotation toolkit"]
45
+ PICK["Picking utility"]
46
+ CAPI["Compute subsystem"]
47
+ CBUF["Buffer resource manager"]
48
+ CPIPE["Pipeline controller"]
49
+ CPLAN["Dispatch workgroup planner"]
50
+ CKERN["Kernels library"]
51
+ CARR["N-dimensional array abstraction for CPU & GPU memory"]
52
+ CREAD["Asynchronous readback ring"]
53
+ CSCR["Scratch buffer pool"]
54
+ end
55
+
56
+ subgraph DATA["Object & Data Model"]
57
+ SCN["Scene"]
58
+ TSTORE["Transform store in SoA memory"]
59
+ MESH["Mesh with geometry, material, & texture"]
60
+ PGG["Pointcloud & glyphfield"]
61
+ CMAP["Colormapping"]
62
+ SKIN["Skin instance data"]
63
+ ASTORE["Annotation store"]
64
+ ALOAD["Loader for glTF 2.0 asset data"]
65
+ ADEC["Accessor decoding & data conversion"]
66
+ AIMP["Importer from asset data to scene resources"]
67
+ end
68
+
69
+ subgraph WASM["WebAssembly Driver"]
70
+ WHEAP["Heap allocation for persistent typed memory"]
71
+ WFAR["Frame arena for transient typed memory"]
72
+ WTR["Transform propagation"]
73
+ WMATH["Matrix, vector, & quaternion mathematics"]
74
+ WND["N-dimensional array indexing & stride-offsetting"]
75
+ WMESH["Mesh normal generation"]
76
+ WGLTF["glTF accessor decoding, sparse patching, & numeric conversion"]
77
+ WANI["Animation sampling & joint matrix generation"]
78
+ WBOUNDS["Bounds for mesh, pointcloud, & glyphfield"]
79
+ WCULL["Frustum culling"]
80
+ end
81
+
82
+ subgraph GPU["Browser Resources"]
83
+ DEV["Graphics device & queue"]
84
+ CACHE["Pipeline cache & bindgroup cache"]
85
+ RES["Graphics buffers, textures, & samplers"]
86
+ RPASS["Render passes for opaque geometry, transparent geometry, post-processing, & user interaction"]
87
+ CPASS["Compute passes for kernels"]
88
+ end
89
+
90
+ classDef darkblue fill:#4E79FF,stroke:#0B2B8F,stroke-width:2px,color:#06153D;
91
+ classDef green fill:#22D37D,stroke:#0A6D3C,stroke-width:2px,color:#04311A;
92
+ classDef lightblue fill:#17C9FF,stroke:#005E80,stroke-width:2px,color:#022433;
93
+ classDef yellow fill:#FFB238,stroke:#9A4D00,stroke-width:2px,color:#5A2C00;
94
+ classDef purple fill:#B18AFF,stroke:#5A2FA6,stroke-width:2px,color:#2E165E;
95
+ classDef pink fill:#FF5EA8,stroke:#9A2E62,stroke-width:2px,color:#4D1532;
96
+
97
+ class APP,ENG,FAC darkblue;
98
+ class LOOP,REND,SCALE,OVER,ANNO,PICK green;
99
+ class CAPI,CBUF,CPIPE,CPLAN,CKERN,CARR,CREAD,CSCR lightblue;
100
+ class SCN,TSTORE,MESH,PGG,CMAP,SKIN,ASTORE,ALOAD,ADEC,AIMP yellow;
101
+ class WHEAP,WFAR,WTR,WMATH,WND,WMESH,WGLTF,WANI,WBOUNDS,WCULL purple;
102
+ class DEV,CACHE,RES,RPASS,CPASS pink;
103
+
104
+ APP --> ENG
105
+ ENG --> FAC
106
+ ENG --> LOOP
107
+ ENG --> OVER
108
+ ENG --> ANNO
109
+ ENG --> PICK
110
+ ENG --> CAPI
111
+
112
+ FAC --> SCN
113
+ FAC --> MESH
114
+ FAC --> PGG
115
+ FAC --> CMAP
116
+ FAC --> SKIN
117
+ FAC --> ALOAD
118
+ MESH --> CMAP
119
+
120
+ ALOAD --> ADEC --> AIMP
121
+ AIMP -.-> SCN
122
+ AIMP -.-> MESH
123
+ AIMP -.-> SKIN
124
+ AIMP -.-> TSTORE
125
+ ADEC -.-> WGLTF
126
+
127
+ LOOP --> REND
128
+ SCN --> REND
129
+ TSTORE --> REND
130
+ MESH --> REND
131
+ PGG --> REND
132
+ CMAP --> REND
133
+ SKIN --> REND
134
+ OVER --> REND
135
+ REND --> PICK
136
+ PICK --> ANNO
137
+ ASTORE --> ANNO
138
+ ANNO --> OVER
139
+
140
+ CAPI --> CBUF
141
+ CAPI --> CPIPE
142
+ CAPI --> CPLAN
143
+ CAPI --> CKERN
144
+ CAPI --> CARR
145
+ CAPI --> CREAD
146
+ CAPI --> CSCR
147
+ CAPI --> SCALE
148
+ SCALE --> MESH
149
+ SCALE --> PGG
150
+ SCALE --> CMAP
151
+ CBUF --> CPASS
152
+ CPIPE --> CPASS
153
+ CPLAN --> CPASS
154
+ CKERN --> CPASS
155
+ CSCR --> CPASS
156
+ CPASS --> DEV
157
+ CREAD --> DEV
158
+
159
+ REND --> RPASS
160
+ REND --> CACHE
161
+ CACHE --> DEV
162
+ RPASS --> DEV
163
+
164
+ ENG -.-> WHEAP
165
+ LOOP -.-> WFAR
166
+ WHEAP -.-> TSTORE
167
+ WHEAP -.-> CARR
168
+ WFAR -.-> REND
169
+ TSTORE -.-> WTR
170
+ WTR -.-> WMATH
171
+ SKIN -.-> WANI
172
+ WANI -.-> WMATH
173
+ MESH -.-> WMESH
174
+ WMESH -.-> MESH
175
+ MESH -.-> WBOUNDS
176
+ PGG -.-> WBOUNDS
177
+ WBOUNDS -.-> WCULL
178
+ REND -.-> WCULL
179
+ WCULL -.-> REND
180
+ WTR -.-> TSTORE
181
+ WANI -.-> RES
182
+ WGLTF -.-> ADEC
183
+ WGLTF -.-> WND
184
+ WND -.-> CARR
185
+ CBUF -.-> MESH
186
+ MESH -.-> RES
187
+ REND -.-> RES
188
+ CBUF -.-> RES
189
+ ```
190
+
191
+ ## Architecture Comparison Tables
192
+
193
+ ### 1. Platform and Toolchain
194
+ | | **WebGL / WebGPU** | **Three.js / Babylon.js** | **WasmGPU** |
195
+ | :--- | :--- | :--- | :--- |
196
+ | **Origin** | 2011 / 2023 | 2010 / 2013 | 2026 |
197
+ | **Implementation Language** | JavaScript & C++ | JavaScript / TypeScript | TypeScript & Rust |
198
+ | **Application Language** | JavaScript & GLSL / WGSL | JavaScript / TypeScript & GLSL / WGSL | JavaScript / TypeScript & WGSL (& Python via Pyodide) |
199
+ | **Buildtime Optimization** | Not available | Transpilation, tree-shaking, minification | Transpilation & LLVM, tree-shaking & Binaryen, minification |
200
+ | **Graphics Engine** | WebGL / WebGPU | WebGL-native & WebGPU-adoptive | WebGPU-native |
201
+ | **Vectorization** | Not available | Scalar | SIMD128 |
202
+ | **API Ergonomics** | Verbose | Streamlined | Streamlined |
203
+
204
+ ### 2. Execution Model and Memory Layout
205
+ | | **WebGL / WebGPU** | **Three.js / Babylon.js** | **WasmGPU** |
206
+ | :--- | :--- | :--- | :--- |
207
+ | **Scene Graph Memory** | Not available | Object-oriented (AoS) | Data-oriented (SoA) |
208
+ | **Math Execution** | JavaScript | JavaScript | WebAssembly |
209
+ | **Transform Updates** | Not available | Recursive traversal | Linear iteration |
210
+ | **Bounds Computation** | Manual | JavaScript | WebAssembly |
211
+ | **View Framing** | Manual | Helper-based fitting | Bounds-based scene/object fitting |
212
+ | **Garbage Collection** | Manual & low/high pressure via JavaScript engine | Automatic & high pressure via JavaScript engine | Automatic & low pressure via WebAssembly driver |
213
+ | **Render Loop** | Run by JavaScript | Run by JavaScript | Run by JavaScript & WebAssembly |
214
+
215
+ ### 3. Rendering Pipeline Infrastructure
216
+ | | **WebGL / WebGPU** | **Three.js / Babylon.js** | **WasmGPU** |
217
+ | :--- | :--- | :--- | :--- |
218
+ | **Uniform Uploads** | Manual packing | Extraction & packing | Zero-copy views & no packing |
219
+ | **Render State Caching** | Manual | State filtering | Pipeline caching |
220
+ | **Instancing** | Manual | Manual | Automatic |
221
+ | **Visibility Culling** | Not available | Frustum culling in JavaScript | Frustum culling in WebAssembly |
222
+ | **Picking** | Manual GPU / CPU picking | Often CPU-centered | GPU ID-pass with typed hits |
223
+ | **Skinning** | Not available | Data textures | Storage buffers |
224
+ | **Anti-aliasing** | Not available | MSAA | SMAA |
225
+ | **Textures** | Manual | Managed objects | Managed objects |
226
+ | **Animation System** | Not available | Executed in JavaScript | Executed in WebAssembly |
227
+ | **Asset Importing** | Not available | glTF 2.0 | glTF 2.0 |
228
+ | **Camera Controls** | Not available | Built-in | Built-in unified orbit & trackball navigation |
229
+
230
+ ### 4. Compute Workloads and Scientific Visualizations
231
+ | | **WebGL / WebGPU** | **Three.js / Babylon.js** | **WasmGPU** |
232
+ | :--- | :--- | :--- | :--- |
233
+ | **GPGPU** | Manual, low-level, high-boilerplate | Integrated, high-abstraction, scene-centric | Automated, kernel-driven, compute-optimized |
234
+ | **Ndarray Abstraction** | Not available | Not available | CPU & GPU ndarrays |
235
+ | **GPU Readback** | Manual | Manual | Async readback ring |
236
+ | **Python Interoperability** | Not available | Not available | With Pyodide |
237
+ | **Scientific Primitives** | Manual | Manual | Point clouds & glyph fields |
238
+ | **Mathematical Geometry** | Manual | Manual | Cartesian & parametric curves & surfaces |
239
+ | **Scaling Statistics** | Manual | Manual | Min/max & percentile analysis |
240
+ | **Colormap Support** | Manual | Manual | Built-ins & custom |
241
+ | **Data-driven Materials** | Manual | Manual | Data material |
242
+ | **Scientific Overlays** | Manual | Manual | Grids, triads, & legends |
243
+ | **Annotation & Measurement** | Manual | Manual | Markers, probes, distance, & angle toolkit |
244
+
245
+ ## Getting Started
246
+
247
+ Examples:
248
+ 1. [`./examples/esm.html`](https://zushah.github.io/WasmGPU/examples/esm.html) to see how to get started with the ESM build.
249
+ 2. [`./examples/iife.html`](https://zushah.github.io/WasmGPU/examples/iife.html) to see how to get started with the IIFE build.
250
+ 3. [`./examples/gltf.html`](https://zushah.github.io/WasmGPU/examples/gltf.html) to see how a glTF model of a chessboard can be loaded and imported.
251
+ 4. [`./examples/controls.html`](https://zushah.github.io/WasmGPU/examples/controls.html) to see how the camera controls and navigation functionalities work.
252
+ 5. [`./examples/picking.html`](https://zushah.github.io/WasmGPU/examples/picking.html) to see how the picking, probing, and selecting utility works.
253
+ 6. [`./examples/scaling.html`](https://zushah.github.io/WasmGPU/examples/scaling.html) to see how the scaling service and colormapping works.
254
+ 7. [`./examples/overlay.html`](https://zushah.github.io/WasmGPU/examples/overlay.html) to see how the overlay framework and annotation toolkit works.
255
+ 8. [`./examples/mandelbulb.html`](https://zushah.github.io/WasmGPU/examples/mandelbulb.html) to see how the compute subsystem can be used to render a Mandelbulb fractal.
256
+ 9. [`./examples/galaxy.html`](https://zushah.github.io/WasmGPU/examples/galaxy.html) to see how a point cloud can be used with Python intero via Pyodide and the compute subsystem to render a realistic galaxy.
257
+ 10. [`./examples/fluid.html`](https://zushah.github.io/WasmGPU/examples/fluid.html) to see how a glyph field and a point cloud can be used with Python interop, the compute subsystem, navigation, selection, and overlay features to render a fluid dynamics demo.
258
+ 11. [`./examples/graphing.html`](https://zushah.github.io/WasmGPU/examples/graphing.html) to see how the mathematical function primitives and data materials can be used with Python interop, navigation, selection, and overlay features to render for a 3D graphing calculator.
259
+ 12. [`./examples/protein.html`](https://zushah.github.io/WasmGPU/examples/protein.html) to see how a point cloud can be used with Python interop, navigation, selection, colormap, and overlay features to render a visualization of a protein structure (hemoglobin) from the Protein Data Bank.
260
+
261
+ Super basic example to render a cube:
262
+ ```js
263
+ // Setup
264
+ import { WasmGPU } from "https://cdn.jsdelivr.net/gh/Zushah/WasmGPU@0.7.0/dist/WasmGPU.min.js";
265
+ const canvas = document.querySelector("canvas");
266
+ const wgpu = await WasmGPU.create(canvas, { antialias: true});
267
+
268
+ // Scene, camera, and controls
269
+ const scene = wgpu.createScene([0.05, 0.05, 0.1]);
270
+ const camera = wgpu.createCamera.perspective({
271
+ fov: 60,
272
+ near: 0.1,
273
+ far: 1000
274
+ });
275
+ camera.transform.setPosition(-2, 2, -2);
276
+ camera.lookAt(0, 0, 0);
277
+ const controls = wgpu.createControls.orbit(camera, canvas);
278
+
279
+ // Light
280
+ scene.addLight(wgpu.createLight.directional({
281
+ direction: [1, -1, -1],
282
+ color: [1, 1, 1],
283
+ intensity: 1.5
284
+ }));
285
+
286
+ // Cube
287
+ const cube = wgpu.createMesh(
288
+ wgpu.geometry.box(1, 1, 1),
289
+ wgpu.material.standard({
290
+ color: [1, 0, 0],
291
+ metallic: 0.7
292
+ })
293
+ );
294
+ scene.add(cube);
295
+
296
+ // Render
297
+ wgpu.run((dt, time) => {
298
+ controls.update(dt);
299
+ wgpu.render(scene, camera);
300
+ });
301
+ ```
302
+
303
+ Using the IIFE bundle instead of the ESM bundle is exactly the same as above, except you must use an HTML `script` tag instead of a JavaScript `import` statement:
304
+ ```html
305
+ <script src="https://cdn.jsdelivr.net/gh/Zushah/WasmGPU@0.7.0/dist/WasmGPU.iife.min.js"></script>
306
+ ```
307
+
308
+ ## Development
309
+
310
+ 1. Install dev dependencies: `npm install`.
311
+ 2. Make sure you develop in `./src/` rather than `./dist/`.
312
+ 3. Build and test: `npm run build` & `npm run test`, or just `npm run dev`.
313
+ 4. Serve locally to check if the `./examples/` work: `npm run start` or use the [live server extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer).
314
+ 5. Restore latest release build since builds are only committed during releases: `npm run restore`.
315
+
316
+ The `./dist/` folder contains:
317
+ - ESM bundle: `WasmGPU.js` & `WasmGPU.min.js`
318
+ - IIFE bundle: `WasmGPU.iife.min.js`
319
+ - WebAssembly bridge: `wasm.js`
320
+ - WebAssembly driver: `wasm.wasm`
321
+
322
+ Note: `wasm.js` and `wasm.wasm` must be located beside the WasmGPU bundles, i.e. in the `./dist/` folder. These files are automatically copied from the `./build/` folder by `./esbuild.config.js`, so this should not be a problem, but it could become one.
323
+
324
+ The `./build/` folder contains:
325
+ - WebAssembly bridge: `wasm.js`
326
+ - WebAssembly type declarations: `wasm.d.ts`
327
+ - WebAssembly driver: `wasm.wasm`
328
+ - WebAssembly text format: `wasm.wat`
329
+
330
+ The WasmGPU logo is built by `npm run logo` which runs `./scripts/rasterize_logo.py` to rasterize the `./assets/logo.svg` file to the `./assets/*.png` files used in the repository and on the website.
331
+
332
+ The WasmGPU [website](https://zushah.github.io/WasmGPU) is built by `npm run website` which runs `./scripts/build_website.py` to compile the files in `./website/src/` to `./website/build/` and then deploys to GitHub Pages via the `./.github/workflows/deploy_website.yaml` action.
333
+
334
+ ## License
335
+ WasmGPU is available under the [Mozilla Public License 2.0 (MPL-2.0)](https://www.github.com/Zushah/WasmGPU/blob/main/LICENSE.md).