webgl2 1.0.7 β 1.0.8
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 +10 -140
- package/index.js +16 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,16 +8,10 @@ A **Rust + WASM** based toolkit for debugging GLSL shaders and generating ergono
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
# Build the project
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# Compile a GLSL shader to WASM with debug info
|
|
14
|
-
cargo run --bin webgl2 -- compile tests/fixtures/simple.vert --debug
|
|
15
|
-
|
|
16
|
-
# Validate a shader
|
|
17
|
-
cargo run --bin webgl2 -- validate tests/fixtures/simple.frag
|
|
11
|
+
npm run build
|
|
18
12
|
|
|
19
|
-
#
|
|
20
|
-
|
|
13
|
+
# Run node tests
|
|
14
|
+
npm run tests
|
|
21
15
|
```
|
|
22
16
|
|
|
23
17
|
### Build via npm
|
|
@@ -29,122 +23,22 @@ This repository is both a Rust workspace and an npm package. Run the npm build h
|
|
|
29
23
|
npm run build
|
|
30
24
|
```
|
|
31
25
|
|
|
32
|
-
Notes:
|
|
33
|
-
- The script runs `cargo build --target wasm32-unknown-unknown --release` and copies any `.wasm` files from `target/wasm32-unknown-unknown/release/` into `runners/wasm/`.
|
|
34
|
-
- 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.
|
|
35
|
-
|
|
36
26
|
## π Project Overview and Goals
|
|
37
27
|
|
|
38
|
-
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
|
|
28
|
+
The project aims to create a **Composite WebGL2 Development Platform** built with **Rust and WASM**. The primary objective is to significantly improve the WebGL2 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 hairy API, lack of debugging, incomprehensible errors and opaque GPU execution.
|
|
39
29
|
|
|
40
30
|
| Key Goals | Target Block | Value Proposition |
|
|
41
31
|
| :--- | :--- | :--- |
|
|
42
32
|
| **GPU Debugging** | Block 1 (Emulator) | Enable **step-through debugging**, breakpoints, and variable inspection for GLSL code. |
|
|
43
33
|
| **Unit Testing** | Block 1 (Emulator) | Provide a stable, deterministic environment for **automated testing** of graphics logic. |
|
|
44
|
-
| **API Ergonomics** | Block 2 (Codegen) | **Automate boilerplate code** for resource binding, attribute setup, and uniform linking. |
|
|
45
34
|
| **Tech Stack** | Both | Utilize **Rust for safety and WASM for high-performance cross-platform execution** in the browser. |
|
|
46
35
|
|
|
47
36
|
-----
|
|
48
37
|
|
|
49
|
-
## π οΈ Functional Block 1: WebGL2 Software Rendering Pipeline (The Debugger)
|
|
50
|
-
|
|
51
|
-
This block provides the **deterministic, inspectable execution environment** for GLSL logic.
|
|
52
|
-
|
|
53
|
-
### 1\. **Core Component: Rust-based WebGL2 Emulator (`wasm-gl-emu`)**
|
|
54
|
-
|
|
55
|
-
* **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.
|
|
56
|
-
* **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).
|
|
57
|
-
* **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.
|
|
58
|
-
|
|
59
|
-
### 2\. **GLSL Translation and Debugging Integration (`glsl-to-wasm`)**
|
|
60
|
-
|
|
61
|
-
* **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).
|
|
62
|
-
* **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.
|
|
63
|
-
* **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.
|
|
64
|
-
* **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.
|
|
65
|
-
|
|
66
|
-
### 3\. **Debugging and Testing Harness**
|
|
67
|
-
|
|
68
|
-
* **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.
|
|
69
|
-
* **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).
|
|
70
|
-
|
|
71
|
-
-----
|
|
72
|
-
|
|
73
|
-
## βοΈ Functional Block 2: Introspection and Codegen Tool (The Ergonomics Layer)
|
|
74
|
-
|
|
75
|
-
This block automates the error-prone, repetitive JavaScript/TypeScript code required for WebGL2 resource setup.
|
|
76
|
-
|
|
77
|
-
### 1\. **GLSL Introspection Engine (`glsl-parser-rs`)**
|
|
78
|
-
|
|
79
|
-
* **Parsing:** Use a dedicated Rust parser to analyze the GLSL source files (both Vertex and Fragment shaders).
|
|
80
|
-
* **Annotation Extraction:** The parser must identify and extract **discardable annotations** embedded in the GLSL source.
|
|
81
|
-
* *Example Annotation:*
|
|
82
|
-
```glsl
|
|
83
|
-
//! @buffer_layout MeshData
|
|
84
|
-
layout(location = 0) in vec3 a_position;
|
|
85
|
-
// JSDoc-like for resource description
|
|
86
|
-
/** @uniform_group Camera @semantic ProjectionMatrix */
|
|
87
|
-
uniform mat4 u_projection;
|
|
88
|
-
```
|
|
89
|
-
* **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).
|
|
90
|
-
|
|
91
|
-
### 2\. **Code Generation Module (`js-harness-codegen`)**
|
|
92
|
-
|
|
93
|
-
* **Harness Template:** Define a set of customizable templates (e.g., Handlebars, Tera) for generating the target **JavaScript/TypeScript harness code**.
|
|
94
|
-
* **Code Generation:** Using the resource map data from the parser, the module will generate files that:
|
|
95
|
-
* Define **JavaScript/TypeScript classes** for each shader program.
|
|
96
|
-
* Provide methods for **binding resource objects** (e.g., `program.setUniforms(cameraData)`).
|
|
97
|
-
* Implement all the necessary `gl.bindBuffer()`, `gl.getUniformLocation()`, `gl.vertexAttribPointer()`, and `gl.uniformX()` calls.
|
|
98
|
-
* *Goal:* Reduce the developer's WebGL setup code to simple, type-safe resource assignments.
|
|
99
|
-
|
|
100
|
-
### 3\. **Tool Integration**
|
|
101
|
-
|
|
102
|
-
* 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).
|
|
103
|
-
|
|
104
|
-
-----
|
|
105
|
-
|
|
106
|
-
## β³ Project Phases and Deliverables
|
|
107
|
-
|
|
108
|
-
| Phase | Duration | Focus | Key Deliverables |
|
|
109
|
-
| :--- | :--- | :--- | :--- |
|
|
110
|
-
| **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). |
|
|
111
|
-
| **Phase 2** | 4 Months | Core Emulator Implementation | Basic WebGL2 State Machine and Triangle Rasterizer (Block 1). Source Map integration (GLSL \<-\> WASM \<-\> DevTools) (Block 1). |
|
|
112
|
-
| **Phase 3** | 3 Months | Feature Completion & Polishing | Full WebGL2 feature set support in emulator (textures, complex blending, stencil). Robustness testing and documentation. |
|
|
113
|
-
| **Phase 4** | 2 Months | Integration & Release | Unit testing framework integration. Final documentation and developer tutorials. Full platform release. |
|
|
114
|
-
|
|
115
|
-
-----
|
|
116
|
-
|
|
117
|
-
## οΏ½ Project Structure
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
webgl2/
|
|
121
|
-
βββ crates/
|
|
122
|
-
β βββ naga-wasm-backend/ # Naga IR β WASM compiler with DWARF
|
|
123
|
-
β βββ wasm-gl-emu/ # Software rasterizer & WASM runtime
|
|
124
|
-
β βββ glsl-introspection/ # GLSL parser + annotation extraction
|
|
125
|
-
β βββ js-codegen/ # TypeScript harness generator
|
|
126
|
-
β βββ webgl2-cli/ # Command-line interface
|
|
127
|
-
βββ tests/fixtures/ # Test shaders
|
|
128
|
-
βββ docs/ # Detailed documentation
|
|
129
|
-
β βββ 1-plan.md # Original project plan
|
|
130
|
-
β βββ 1.1-ir-wasm.md # Naga IR β WASM architecture
|
|
131
|
-
βββ external/ # Reference implementations (naga, wgpu, servo)
|
|
132
|
-
```
|
|
133
|
-
|
|
134
38
|
## ποΈ Architecture
|
|
135
39
|
|
|
136
40
|
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.
|
|
137
41
|
|
|
138
|
-
### Key Components
|
|
139
|
-
|
|
140
|
-
1. **naga-wasm-backend**: Translates Naga IR to WebAssembly with DWARF debug information
|
|
141
|
-
2. **wasm-gl-emu**: Executes WASM shaders in a software rasterizer for debugging
|
|
142
|
-
3. **glsl-introspection**: Parses GLSL and extracts resource metadata
|
|
143
|
-
4. **js-codegen**: Generates ergonomic TypeScript bindings
|
|
144
|
-
5. **webgl2-cli**: Unified command-line tool
|
|
145
|
-
|
|
146
|
-
See [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) for detailed architecture documentation.
|
|
147
|
-
|
|
148
42
|
## π§ Development Status
|
|
149
43
|
|
|
150
44
|
**Current Phase: Phase 0 - Foundation Setup** β
|
|
@@ -161,45 +55,21 @@ See [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) for detailed architecture docum
|
|
|
161
55
|
|
|
162
56
|
- [`docs/1-plan.md`](docs/1-plan.md) - Original project proposal and plan
|
|
163
57
|
- [`docs/1.1-ir-wasm.md`](docs/1.1-ir-wasm.md) - Naga IR β WASM architecture (recommended reading)
|
|
164
|
-
- [`external/use.md`](external/use.md) - Guide to leveraging external repositories
|
|
165
|
-
|
|
166
|
-
## β³ Project Phases
|
|
167
|
-
|
|
168
|
-
| Phase | Duration | Focus | Status |
|
|
169
|
-
| :--- | :--- | :--- | :--- |
|
|
170
|
-
| **Phase 0** | 2 Weeks | Foundation & DWARF Validation | **In Progress** |
|
|
171
|
-
| **Phase 1** | 8 Weeks | Core Backend (scalars, vectors, control flow) | Not Started |
|
|
172
|
-
| **Phase 2** | 6 Weeks | Advanced Features (uniforms, textures, matrices) | Not Started |
|
|
173
|
-
| **Phase 3** | 4 Weeks | Software Rasterizer Integration | Not Started |
|
|
174
|
-
| **Phase 4** | 8 Weeks | Codegen Tool & Polish | Not Started |
|
|
175
58
|
|
|
176
59
|
## π§ͺ Testing
|
|
177
60
|
|
|
178
61
|
```bash
|
|
179
|
-
# Run
|
|
62
|
+
# Run Rust tests
|
|
180
63
|
cargo test
|
|
181
64
|
|
|
182
|
-
#
|
|
65
|
+
# Run JS tests
|
|
66
|
+
npm test
|
|
67
|
+
|
|
68
|
+
# Test with a simple shader (prototype, experimental)
|
|
183
69
|
cargo run --bin webgl2 -- compile tests/fixtures/simple.vert --debug -o output.wasm
|
|
184
70
|
cargo run --bin webgl2 -- run output.wasm
|
|
185
71
|
```
|
|
186
72
|
|
|
187
|
-
## π€ Contributing
|
|
188
|
-
|
|
189
|
-
This project is in early development. Contributions are welcome once Phase 0 is complete and the architecture is validated.
|
|
190
|
-
|
|
191
73
|
## π License
|
|
192
74
|
|
|
193
|
-
MIT
|
|
194
|
-
|
|
195
|
-
-----
|
|
196
|
-
|
|
197
|
-
## οΏ½π° Resource Requirements
|
|
198
|
-
|
|
199
|
-
The project will require specialized expertise in:
|
|
200
|
-
|
|
201
|
-
* **Rust and WASM Development**
|
|
202
|
-
* **Computer Graphics / GPU Pipeline Implementation** (for the emulator)
|
|
203
|
-
* **Compiler Design / Language Tooling** (for GLSL parsing and source map generation)
|
|
204
|
-
|
|
205
|
-
Would you like to discuss the **specific toolchain recommendations** for the GLSL-to-WASM compilation process?
|
|
75
|
+
MIT
|
package/index.js
CHANGED
|
@@ -108,7 +108,22 @@ async function initWASM() {
|
|
|
108
108
|
const wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
109
109
|
|
|
110
110
|
// Instantiate WASM (no imports needed, memory is exported)
|
|
111
|
-
|
|
111
|
+
let instance;
|
|
112
|
+
const importObject = {
|
|
113
|
+
env: {
|
|
114
|
+
print: (ptr, len) => {
|
|
115
|
+
const mem = new Uint8Array(instance.exports.memory.buffer);
|
|
116
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
117
|
+
console.log(new TextDecoder('utf-8').decode(bytes));
|
|
118
|
+
},
|
|
119
|
+
wasm_execute_shader: (type, attrPtr, uniformPtr, varyingPtr, privatePtr) => {
|
|
120
|
+
if (WasmWebGL2RenderingContext.activeContext) {
|
|
121
|
+
WasmWebGL2RenderingContext.activeContext._executeShader(type, attrPtr, uniformPtr, varyingPtr, privatePtr);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
instance = await WebAssembly.instantiate(wasmModule, importObject);
|
|
112
127
|
|
|
113
128
|
// Verify required exports
|
|
114
129
|
const ex = instance.exports;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webgl2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "WebGL2 tools to derisk large GPU projects on the web beyond toys and demos.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"keywords": [],
|
|
25
25
|
"author": "",
|
|
26
|
-
"license": "
|
|
26
|
+
"license": "MIT",
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/mavity/mavity/issues"
|
|
29
29
|
},
|