webgl2 1.0.1 β†’ 1.0.4

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 (4) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +203 -0
  3. package/index.js +15 -0
  4. package/package.json +29 -4
package/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2025 WebGL2 Platform Team
2
+ All Rights Reserved.
3
+
4
+ THIS IS A RESTRICTIVE PLACEHOLDER LICENSE (PROPRIETARY).
5
+
6
+ Permission to use, copy, modify, distribute, or publish this software, in whole
7
+ or in part, is NOT granted. All rights are reserved by the copyright holder.
8
+
9
+ This file is intentionally restrictive and intended only as a temporary
10
+ placeholder to allow packaging/testing in private. Replace this file with an
11
+ appropriate open-source license (for example, MIT or Apache-2.0)
12
+ if you intend to grant any rights to others.
13
+
14
+ -- END OF PLACEHOLDER LICENSE --
package/README.md ADDED
@@ -0,0 +1,203 @@
1
+ # WebGL2 Development Platform: VISION
2
+
3
+ A **Rust + WASM** based toolkit for debugging GLSL shaders and generating ergonomic WebGL2 bindings.
4
+
5
+ ## 🎯 Quick Start
6
+
7
+ ```bash
8
+ # Build the project
9
+ cargo build --release
10
+
11
+ # Compile a GLSL shader to WASM with debug info
12
+ cargo run --bin webgl2 -- compile tests/fixtures/simple.vert --debug
13
+
14
+ # Validate a shader
15
+ cargo run --bin webgl2 -- validate tests/fixtures/simple.frag
16
+
17
+ # Generate TypeScript harness
18
+ cargo run --bin webgl2 -- codegen tests/fixtures/simple.vert -o output.ts
19
+ ```
20
+
21
+ ### Build via npm
22
+
23
+ This repository is both a Rust workspace and an npm package. Run the npm build helper to build the Rust workspace for the WASM target and copy produced .wasm files into `runners/wasm/`:
24
+
25
+ ```bash
26
+ # from repository root
27
+ npm run build
28
+ ```
29
+
30
+ Notes:
31
+ - The script runs `cargo build --target wasm32-unknown-unknown --release` and copies any `.wasm` files from `target/wasm32-unknown-unknown/release/` into `runners/wasm/`.
32
+ - If you need `wasm-bindgen` output (JS glue), run `wasm-bindgen` manually on the produced `.wasm` files; adding automated wasm-bindgen support is a follow-up task.
33
+
34
+ ## πŸš€ Project Overview and Goals
35
+
36
+ The project aims to create a **Composite WebGL2 Development Platform** built with **Rust and WASM**. The primary objective is to significantly improve the developer experience by introducing standard software engineering practicesβ€”specifically, **robust debugging and streamlined resource management**β€”into the WebGL/GLSL workflow, which is currently hindered by platform-specific API complexity and opaque GPU execution.
37
+
38
+ | Key Goals | Target Block | Value Proposition |
39
+ | :--- | :--- | :--- |
40
+ | **GPU Debugging** | Block 1 (Emulator) | Enable **step-through debugging**, breakpoints, and variable inspection for GLSL code. |
41
+ | **Unit Testing** | Block 1 (Emulator) | Provide a stable, deterministic environment for **automated testing** of graphics logic. |
42
+ | **API Ergonomics** | Block 2 (Codegen) | **Automate boilerplate code** for resource binding, attribute setup, and uniform linking. |
43
+ | **Tech Stack** | Both | Utilize **Rust for safety and WASM for high-performance cross-platform execution** in the browser. |
44
+
45
+ -----
46
+
47
+ ## πŸ› οΈ Functional Block 1: WebGL2 Software Rendering Pipeline (The Debugger)
48
+
49
+ This block provides the **deterministic, inspectable execution environment** for GLSL logic.
50
+
51
+ ### 1\. **Core Component: Rust-based WebGL2 Emulator (`wasm-gl-emu`)**
52
+
53
+ * **State Machine Emulation:** Implement a full software model of the WebGL2 state (e.g., Framebuffer Objects, Renderbuffers, Texture Units, Vertex Array Objects, current programs, depth/stencil settings). This component will track all API calls and maintain a CPU-accessible copy of all state.
54
+ * **Rasterization Logic:** Implement CPU-based vertex and fragment processing. This logic must precisely follow the WebGL2/OpenGL ES 3.0 specification, including clipping, primitive assembly, and the fragment pipeline (culling, depth test, blending).
55
+ * **Input/Output:** Expose the emulator's state and rendering results via a standard Rust interface that can be compiled to WASM and wrapped for JavaScript access.
56
+
57
+ ### 2\. **GLSL Translation and Debugging Integration (`glsl-to-wasm`)**
58
+
59
+ * **GLSL Frontend:** Use a Rust-based GLSL parser (e.g., based on `naga` or a custom parser) to convert shader source code into an Intermediate Representation (IR).
60
+ * **WASM Backend:** Compile the IR into **WASM module functions**. Each shader stage (Vertex, Fragment) will be converted into a function that executes the shader logic on a single vertex or fragment input.
61
+ * **Source Map Generation:** The crucial step is to generate **high-quality source maps** that link the generated WASM instructions back to the original GLSL source code line and variable names. This enables DevTools/IDE to pause WASM execution and display the corresponding GLSL line and variable values.
62
+ * **JIT Compilation:** For performance during debugging, the WASM modules can be compiled using a fast JIT compiler (potentially leveraging existing browser capabilities or a custom runtime) to execute the many vertex/fragment calls.
63
+
64
+ ### 3\. **Debugging and Testing Harness**
65
+
66
+ * **Test Runner:** Develop a testing harness in Rust/WASM that can execute a defined set of inputs (e.g., vertex attributes, uniform values) against the emulated pipeline and assert on the final pixel output or intermediate variable state.
67
+ * **Step-Through Integration:** The WASM modules, when run by the browser's JavaScript engine, will expose the generated source maps, allowing the developer to naturally set **breakpoints** within the GLSL source file viewed in the browser's DevTools (or a connected IDE).
68
+
69
+ -----
70
+
71
+ ## βš™οΈ Functional Block 2: Introspection and Codegen Tool (The Ergonomics Layer)
72
+
73
+ This block automates the error-prone, repetitive JavaScript/TypeScript code required for WebGL2 resource setup.
74
+
75
+ ### 1\. **GLSL Introspection Engine (`glsl-parser-rs`)**
76
+
77
+ * **Parsing:** Use a dedicated Rust parser to analyze the GLSL source files (both Vertex and Fragment shaders).
78
+ * **Annotation Extraction:** The parser must identify and extract **discardable annotations** embedded in the GLSL source.
79
+ * *Example Annotation:*
80
+ ```glsl
81
+ //! @buffer_layout MeshData
82
+ layout(location = 0) in vec3 a_position;
83
+ // JSDoc-like for resource description
84
+ /** @uniform_group Camera @semantic ProjectionMatrix */
85
+ uniform mat4 u_projection;
86
+ ```
87
+ * **Resource Mapping:** Generate a structured data model (e.g., JSON or Rust structs) that lists all attributes, uniforms, uniform blocks, and their associated types, locations, and extracted metadata (like semantic hints from the annotations).
88
+
89
+ ### 2\. **Code Generation Module (`js-harness-codegen`)**
90
+
91
+ * **Harness Template:** Define a set of customizable templates (e.g., Handlebars, Tera) for generating the target **JavaScript/TypeScript harness code**.
92
+ * **Code Generation:** Using the resource map data from the parser, the module will generate files that:
93
+ * Define **JavaScript/TypeScript classes** for each shader program.
94
+ * Provide methods for **binding resource objects** (e.g., `program.setUniforms(cameraData)`).
95
+ * Implement all the necessary `gl.bindBuffer()`, `gl.getUniformLocation()`, `gl.vertexAttribPointer()`, and `gl.uniformX()` calls.
96
+ * *Goal:* Reduce the developer's WebGL setup code to simple, type-safe resource assignments.
97
+
98
+ ### 3\. **Tool Integration**
99
+
100
+ * Package the Rust component as a **Command-Line Interface (CLI)** tool (or an accompanying library) that runs during the build step, consuming GLSL files and outputting the JavaScript/TypeScript harness code. This integrates smoothly into modern build pipelines (e.g., Webpack, Vite).
101
+
102
+ -----
103
+
104
+ ## ⏳ Project Phases and Deliverables
105
+
106
+ | Phase | Duration | Focus | Key Deliverables |
107
+ | :--- | :--- | :--- | :--- |
108
+ | **Phase 1** | 3 Months | Core Compiler & Codegen | Functional GLSL parser (Block 2). CLI tool for JS harness generation (Block 2). Prototype `glsl-to-wasm` compiler (Block 1). |
109
+ | **Phase 2** | 4 Months | Core Emulator Implementation | Basic WebGL2 State Machine and Triangle Rasterizer (Block 1). Source Map integration (GLSL \<-\> WASM \<-\> DevTools) (Block 1). |
110
+ | **Phase 3** | 3 Months | Feature Completion & Polishing | Full WebGL2 feature set support in emulator (textures, complex blending, stencil). Robustness testing and documentation. |
111
+ | **Phase 4** | 2 Months | Integration & Release | Unit testing framework integration. Final documentation and developer tutorials. Full platform release. |
112
+
113
+ -----
114
+
115
+ ## οΏ½ Project Structure
116
+
117
+ ```
118
+ webgl2/
119
+ β”œβ”€β”€ crates/
120
+ β”‚ β”œβ”€β”€ naga-wasm-backend/ # Naga IR β†’ WASM compiler with DWARF
121
+ β”‚ β”œβ”€β”€ wasm-gl-emu/ # Software rasterizer & WASM runtime
122
+ β”‚ β”œβ”€β”€ glsl-introspection/ # GLSL parser + annotation extraction
123
+ β”‚ β”œβ”€β”€ js-codegen/ # TypeScript harness generator
124
+ β”‚ └── webgl2-cli/ # Command-line interface
125
+ β”œβ”€β”€ tests/fixtures/ # Test shaders
126
+ β”œβ”€β”€ docs/ # Detailed documentation
127
+ β”‚ β”œβ”€β”€ 1-plan.md # Original project plan
128
+ β”‚ └── 1.1-ir-wasm.md # Naga IR β†’ WASM architecture
129
+ └── external/ # Reference implementations (naga, wgpu, servo)
130
+ ```
131
+
132
+ ## πŸ—οΈ Architecture
133
+
134
+ This project uses **Naga** (from the wgpu/WebGPU ecosystem) as the shader IR, rather than building a custom IR from scratch. This significantly reduces complexity while providing a proven, well-maintained foundation.
135
+
136
+ ### Key Components
137
+
138
+ 1. **naga-wasm-backend**: Translates Naga IR to WebAssembly with DWARF debug information
139
+ 2. **wasm-gl-emu**: Executes WASM shaders in a software rasterizer for debugging
140
+ 3. **glsl-introspection**: Parses GLSL and extracts resource metadata
141
+ 4. **js-codegen**: Generates ergonomic TypeScript bindings
142
+ 5. **webgl2-cli**: Unified command-line tool
143
+
144
+ See [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) for detailed architecture documentation.
145
+
146
+ ## πŸ”§ Development Status
147
+
148
+ **Current Phase: Phase 0 - Foundation Setup** βœ…
149
+
150
+ - [x] Workspace structure created
151
+ - [x] Core crate skeletons implemented
152
+ - [x] Basic WASM backend (emits empty functions)
153
+ - [x] Runtime structure (wasmtime integration)
154
+ - [x] CLI tool with compile/validate/codegen/run commands
155
+ - [ ] DWARF debug information generation (in progress)
156
+ - [ ] Browser DevTools integration validation
157
+
158
+ ## πŸ“š Documentation
159
+
160
+ - [`docs/1-plan.md`](docs/1-plan.md) - Original project proposal and plan
161
+ - [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) - Naga IR β†’ WASM architecture (recommended reading)
162
+ - [`external/use.md`](external/use.md) - Guide to leveraging external repositories
163
+
164
+ ## ⏳ Project Phases
165
+
166
+ | Phase | Duration | Focus | Status |
167
+ | :--- | :--- | :--- | :--- |
168
+ | **Phase 0** | 2 Weeks | Foundation & DWARF Validation | **In Progress** |
169
+ | **Phase 1** | 8 Weeks | Core Backend (scalars, vectors, control flow) | Not Started |
170
+ | **Phase 2** | 6 Weeks | Advanced Features (uniforms, textures, matrices) | Not Started |
171
+ | **Phase 3** | 4 Weeks | Software Rasterizer Integration | Not Started |
172
+ | **Phase 4** | 8 Weeks | Codegen Tool & Polish | Not Started |
173
+
174
+ ## πŸ§ͺ Testing
175
+
176
+ ```bash
177
+ # Run all tests
178
+ cargo test
179
+
180
+ # Test with a simple shader
181
+ cargo run --bin webgl2 -- compile tests/fixtures/simple.vert --debug -o output.wasm
182
+ cargo run --bin webgl2 -- run output.wasm
183
+ ```
184
+
185
+ ## 🀝 Contributing
186
+
187
+ This project is in early development. Contributions are welcome once Phase 0 is complete and the architecture is validated.
188
+
189
+ ## πŸ“„ License
190
+
191
+ MIT OR Apache-2.0
192
+
193
+ -----
194
+
195
+ ## οΏ½πŸ’° Resource Requirements
196
+
197
+ The project will require specialized expertise in:
198
+
199
+ * **Rust and WASM Development**
200
+ * **Computer Graphics / GPU Pipeline Implementation** (for the emulator)
201
+ * **Compiler Design / Language Tooling** (for GLSL parsing and source map generation)
202
+
203
+ Would you like to discuss the **specific toolchain recommendations** for the GLSL-to-WASM compilation process?
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ // index.js (compat shim)
2
+ // Re-export the new implementation in `index2.js` so existing consumers who
3
+ // import `index.js` keep working. The legacy implementation was removed and
4
+ // moved to `index2.js` which contains the canonical, tested API.
5
+
6
+ const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
7
+
8
+ if (isNode) {
9
+ // In Node.js environments re-export everything from index2.js
10
+ module.exports = require('./index2.js');
11
+ } else {
12
+ // In browsers assume `index2.js` is loaded alongside this file and has
13
+ // populated `window.webGL2`. Nothing else to do here.
14
+ // (Keeping a no-op shim avoids duplicating the implementation.)
15
+ }
package/package.json CHANGED
@@ -1,12 +1,37 @@
1
1
  {
2
2
  "name": "webgl2",
3
- "version": "1.0.1",
4
- "description": "",
3
+ "version": "1.0.4",
4
+ "description": "WebGL2 tools to derisk large GPU projects on the web beyond toys and demos.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "start": "node ./index.js",
8
+ "build:wasm": "node ./scripts/build-wasm.js",
9
+ "build": "node -e \"(async()=>{const p=require('path');const dir=process.env.INIT_CWD||process.cwd();require(p.join(dir,'scripts','build-wasm.js'));})()\"",
10
+ "prepublishOnly": "npm run build",
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "test:smoke": "npm run build:wasm && node ./test/smoke.js"
13
+ },
14
+ "wasmBuild": {
15
+ "outDir": "wasm",
16
+ "target": "wasm32-unknown-unknown",
17
+ "profile": "release"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/mavity/mavity"
8
22
  },
9
23
  "keywords": [],
10
24
  "author": "",
11
- "license": "ISC"
25
+ "license": "TBD",
26
+ "bugs": {
27
+ "url": "https://github.com/mavity/mavity/issues"
28
+ },
29
+ "homepage": "https://github.com/mavity/mavity#readme"
30
+ ,
31
+ "files": [
32
+ "index.js",
33
+ "wasm",
34
+ "README.md",
35
+ "LICENSE"
36
+ ]
12
37
  }