webgl2 1.1.4 → 1.1.5

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/coverage.md CHANGED
@@ -4,29 +4,30 @@
4
4
 
5
5
  | File | Lines Covered | Lines Missed | Total Lines | Coverage |
6
6
  |---|---|---|---|---|
7
- | src/lib.rs | 78 | 17 | 95 | 82.11% 🟢 |
7
+ | src/lib.rs | 79 | 20 | 99 | 79.80% 🟡 |
8
8
  | src/naga_wasm_backend/backend.rs | 39 | 0 | 39 | 100.00% 🟢 |
9
9
  | src/naga_wasm_backend/control_flow.rs | 15 | 4 | 19 | 78.95% 🟡 |
10
10
  | src/naga_wasm_backend/expressions.rs | 27 | 12 | 39 | 69.23% 🟡 |
11
11
  | src/naga_wasm_backend/types.rs | 6 | 0 | 6 | 100.00% 🟢 |
12
- | src/wasm_gl_emu/rasterizer.rs | 1 | 0 | 1 | 100.00% 🟢 |
13
- | src/webgl2_context/buffers.rs | 16 | 1 | 17 | 94.12% 🟢 |
14
- | src/webgl2_context/drawing.rs | 25 | 5 | 30 | 83.33% 🟢 |
12
+ | src/wasm_gl_emu/rasterizer.rs | 6 | 0 | 6 | 100.00% 🟢 |
13
+ | src/webgl2_context/buffers.rs | 16 | 2 | 18 | 88.89% 🟢 |
14
+ | src/webgl2_context/drawing.rs | 27 | 3 | 30 | 90.00% 🟢 |
15
15
  | src/webgl2_context/framebuffers.rs | 8 | 0 | 8 | 100.00% 🟢 |
16
16
  | src/webgl2_context/registry.rs | 3 | 2 | 5 | 60.00% 🟡 |
17
17
  | src/webgl2_context/renderbuffers.rs | 10 | 0 | 10 | 100.00% 🟢 |
18
18
  | src/webgl2_context/shaders.rs | 61 | 0 | 61 | 100.00% 🟢 |
19
- | src/webgl2_context/state.rs | 11 | 3 | 14 | 78.57% 🟡 |
19
+ | src/webgl2_context/state.rs | 5 | 1 | 6 | 83.33% 🟢 |
20
20
  | src/webgl2_context/textures.rs | 9 | 0 | 9 | 100.00% 🟢 |
21
21
  | src/webgl2_context/types.rs | 11 | 1 | 12 | 91.67% 🟢 |
22
- | src/webgl2_context/vaos.rs | 16 | 0 | 16 | 100.00% 🟢 |
23
- | **Total** | **336** | **45** | **381** | **88.19% 🟢** |
22
+ | src/webgl2_context/vaos.rs | 24 | 0 | 24 | 100.00% 🟢 |
23
+ | src/webgpu/adapter.rs | 0 | 1 | 1 | 0.00% 🟡 |
24
+ | **Total** | **346** | **46** | **392** | **88.27% 🟢** |
24
25
 
25
26
  ## Top Missed Files
26
27
 
27
28
  | File | Lines Missed | Illustrative Line | Coverage |
28
29
  |---|---|---|---|
29
- | src/lib.rs | 17/95 | [56] `pub fn js_log(level: u32, s: &str) {` | 82.11% 🟢 |
30
+ | src/lib.rs | 20/99 | [57] `pub fn js_log(level: u32, s: &str) {` | 79.80% 🟡 |
30
31
  | src/naga_wasm_backend/expressions.rs | 12/39 | [49] `if component_idx == 0 {` | 69.23% 🟡 |
31
- | src/webgl2_context/drawing.rs | 5/30 | [561] `for k in 0..64 {` | 83.33% 🟢 |
32
32
  | src/naga_wasm_backend/control_flow.rs | 4/19 | [80] `for _ in 0..types.len() {` | 78.95% 🟡 |
33
+ | src/webgl2_context/drawing.rs | 3/30 | [434] `if i + 2 >= vertices.len() {` | 90.00% 🟢 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webgl2",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
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",
@@ -12,7 +12,7 @@
12
12
  "build-debug": "npm run build-debug-wasm-only && npm run build-debug-distill",
13
13
  "build": "npm run build-release && npm run build-debug",
14
14
  "prepublishOnly": "npm run build",
15
- "test": "NODE_OPTIONS='--import ./test/all-coverage.js' node --test test/*.test.js"
15
+ "test": "node --import ./test/all-coverage.js --test test/*.test.js"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
@@ -42,6 +42,7 @@ export class WasmWebGL2RenderingContext {
42
42
  VIEWPORT = 0x0BA2;
43
43
  COLOR_CLEAR_VALUE = 0x0C22;
44
44
  BUFFER_SIZE = 0x8764;
45
+ MAX_VERTEX_ATTRIBS = 0x8869;
45
46
  NO_ERROR = 0;
46
47
 
47
48
  RENDERBUFFER = 0x8D41;
@@ -1142,6 +1143,10 @@ export class WasmWebGL2RenderingContext {
1142
1143
  }
1143
1144
  }
1144
1145
 
1146
+ if (pname === 0x8869 /* MAX_VERTEX_ATTRIBS */) {
1147
+ return 16;
1148
+ }
1149
+
1145
1150
  throw new Error(`getParameter for ${pname} not implemented`);
1146
1151
  }
1147
1152
  getError() {
@@ -0,0 +1,301 @@
1
+ /**
2
+ * WebGPU API implementation for WebAssembly
3
+ *
4
+ * This module provides a complete WebGPU API surface that runs entirely in
5
+ * WebAssembly/Rust, enabling deterministic execution, advanced debugging,
6
+ * and software rasterization of WebGPU workloads.
7
+ */
8
+
9
+ export class GPU {
10
+ constructor(wasmModule, wasmMemory) {
11
+ this.wasm = wasmModule;
12
+ this.memory = wasmMemory;
13
+ }
14
+
15
+ /**
16
+ * Request a GPUAdapter
17
+ * @param {Object} options - Adapter request options
18
+ * @returns {Promise<GPUAdapter>}
19
+ */
20
+ async requestAdapter(options = {}) {
21
+ // Create a WebGPU context
22
+ const ctxHandle = this.wasm.wasm_webgpu_create_context();
23
+ if (ctxHandle === 0) {
24
+ return null;
25
+ }
26
+
27
+ return new GPUAdapter(this.wasm, this.memory, ctxHandle);
28
+ }
29
+ }
30
+
31
+ export class GPUAdapter {
32
+ constructor(wasmModule, wasmMemory, ctxHandle) {
33
+ this.wasm = wasmModule;
34
+ this.memory = wasmMemory;
35
+ this.ctxHandle = ctxHandle;
36
+ this.features = new Set();
37
+ this.limits = {};
38
+ }
39
+
40
+ /**
41
+ * Request a GPUDevice
42
+ * @param {Object} descriptor - Device descriptor
43
+ * @returns {Promise<GPUDevice>}
44
+ */
45
+ async requestDevice(descriptor = {}) {
46
+ // TODO: Call wasm function to create device
47
+ // Using placeholder handle until WASM integration is complete
48
+ const deviceHandle = 1; // FIXME: Generate unique handles
49
+ return new GPUDevice(this.wasm, this.memory, this.ctxHandle, deviceHandle);
50
+ }
51
+ }
52
+
53
+ export class GPUDevice {
54
+ constructor(wasmModule, wasmMemory, ctxHandle, deviceHandle) {
55
+ this.wasm = wasmModule;
56
+ this.memory = wasmMemory;
57
+ this.ctxHandle = ctxHandle;
58
+ this.deviceHandle = deviceHandle;
59
+ this.queue = new GPUQueue(wasmModule, wasmMemory, ctxHandle, 1); // Placeholder queue handle
60
+ }
61
+
62
+ /**
63
+ * Create a buffer
64
+ * @param {Object} descriptor - Buffer descriptor
65
+ * @returns {GPUBuffer}
66
+ */
67
+ createBuffer(descriptor) {
68
+ // TODO: Call wasm function to create buffer
69
+ const bufferHandle = 1; // Placeholder
70
+ return new GPUBuffer(this.wasm, this.memory, this.ctxHandle, bufferHandle, descriptor.size);
71
+ }
72
+
73
+ /**
74
+ * Create a shader module
75
+ * @param {Object} descriptor - Shader module descriptor
76
+ * @returns {GPUShaderModule}
77
+ */
78
+ createShaderModule(descriptor) {
79
+ // TODO: Call wasm function to create shader module
80
+ const moduleHandle = 1; // Placeholder
81
+ return new GPUShaderModule(this.wasm, this.memory, this.ctxHandle, moduleHandle);
82
+ }
83
+
84
+ /**
85
+ * Create a render pipeline
86
+ * @param {Object} descriptor - Render pipeline descriptor
87
+ * @returns {GPURenderPipeline}
88
+ */
89
+ createRenderPipeline(descriptor) {
90
+ // TODO: Call wasm function to create render pipeline
91
+ const pipelineHandle = 1; // Placeholder
92
+ return new GPURenderPipeline(this.wasm, this.memory, this.ctxHandle, pipelineHandle);
93
+ }
94
+
95
+ /**
96
+ * Create a command encoder
97
+ * @param {Object} descriptor - Command encoder descriptor
98
+ * @returns {GPUCommandEncoder}
99
+ */
100
+ createCommandEncoder(descriptor = {}) {
101
+ // TODO: Call wasm function to create command encoder
102
+ const encoderHandle = 1; // Placeholder
103
+ return new GPUCommandEncoder(this.wasm, this.memory, this.ctxHandle, encoderHandle);
104
+ }
105
+
106
+ /**
107
+ * Destroy the device
108
+ */
109
+ destroy() {
110
+ // TODO: Clean up device resources
111
+ }
112
+ }
113
+
114
+ export class GPUQueue {
115
+ constructor(wasmModule, wasmMemory, ctxHandle, queueHandle) {
116
+ this.wasm = wasmModule;
117
+ this.memory = wasmMemory;
118
+ this.ctxHandle = ctxHandle;
119
+ this.queueHandle = queueHandle;
120
+ }
121
+
122
+ /**
123
+ * Submit command buffers to the queue
124
+ * @param {Array<GPUCommandBuffer>} commandBuffers
125
+ */
126
+ submit(commandBuffers) {
127
+ // TODO: Call wasm function to submit command buffers
128
+ }
129
+
130
+ /**
131
+ * Write data to a buffer
132
+ * @param {GPUBuffer} buffer
133
+ * @param {number} bufferOffset
134
+ * @param {ArrayBuffer|TypedArray} data
135
+ * @param {number} dataOffset
136
+ * @param {number} size
137
+ */
138
+ writeBuffer(buffer, bufferOffset, data, dataOffset = 0, size) {
139
+ // TODO: Call wasm function to write buffer
140
+ }
141
+ }
142
+
143
+ export class GPUBuffer {
144
+ constructor(wasmModule, wasmMemory, ctxHandle, bufferHandle, size) {
145
+ this.wasm = wasmModule;
146
+ this.memory = wasmMemory;
147
+ this.ctxHandle = ctxHandle;
148
+ this.bufferHandle = bufferHandle;
149
+ this.size = size;
150
+ }
151
+
152
+ /**
153
+ * Map buffer for reading/writing
154
+ * @param {number} mode - Map mode
155
+ * @param {number} offset
156
+ * @param {number} size
157
+ * @returns {Promise<void>}
158
+ */
159
+ async mapAsync(mode, offset = 0, size) {
160
+ // TODO: Implement buffer mapping
161
+ return Promise.resolve();
162
+ }
163
+
164
+ /**
165
+ * Get mapped range
166
+ * @param {number} offset
167
+ * @param {number} size
168
+ * @returns {ArrayBuffer}
169
+ */
170
+ getMappedRange(offset = 0, size) {
171
+ // TODO: Return mapped range
172
+ return new ArrayBuffer(size || this.size);
173
+ }
174
+
175
+ /**
176
+ * Unmap the buffer
177
+ */
178
+ unmap() {
179
+ // TODO: Implement unmapping
180
+ }
181
+
182
+ /**
183
+ * Destroy the buffer
184
+ */
185
+ destroy() {
186
+ // TODO: Call wasm function to destroy buffer
187
+ }
188
+ }
189
+
190
+ export class GPUShaderModule {
191
+ constructor(wasmModule, wasmMemory, ctxHandle, moduleHandle) {
192
+ this.wasm = wasmModule;
193
+ this.memory = wasmMemory;
194
+ this.ctxHandle = ctxHandle;
195
+ this.moduleHandle = moduleHandle;
196
+ }
197
+ }
198
+
199
+ export class GPURenderPipeline {
200
+ constructor(wasmModule, wasmMemory, ctxHandle, pipelineHandle) {
201
+ this.wasm = wasmModule;
202
+ this.memory = wasmMemory;
203
+ this.ctxHandle = ctxHandle;
204
+ this.pipelineHandle = pipelineHandle;
205
+ }
206
+ }
207
+
208
+ export class GPUCommandEncoder {
209
+ constructor(wasmModule, wasmMemory, ctxHandle, encoderHandle) {
210
+ this.wasm = wasmModule;
211
+ this.memory = wasmMemory;
212
+ this.ctxHandle = ctxHandle;
213
+ this.encoderHandle = encoderHandle;
214
+ }
215
+
216
+ /**
217
+ * Begin a render pass
218
+ * @param {Object} descriptor - Render pass descriptor
219
+ * @returns {GPURenderPassEncoder}
220
+ */
221
+ beginRenderPass(descriptor) {
222
+ // TODO: Call wasm function to begin render pass
223
+ const passHandle = 1; // Placeholder
224
+ return new GPURenderPassEncoder(this.wasm, this.memory, this.ctxHandle, passHandle);
225
+ }
226
+
227
+ /**
228
+ * Finish encoding and create a command buffer
229
+ * @returns {GPUCommandBuffer}
230
+ */
231
+ finish() {
232
+ // TODO: Call wasm function to finish encoding
233
+ const commandBufferHandle = 1; // Placeholder
234
+ return new GPUCommandBuffer(this.wasm, this.memory, this.ctxHandle, commandBufferHandle);
235
+ }
236
+ }
237
+
238
+ export class GPURenderPassEncoder {
239
+ constructor(wasmModule, wasmMemory, ctxHandle, passHandle) {
240
+ this.wasm = wasmModule;
241
+ this.memory = wasmMemory;
242
+ this.ctxHandle = ctxHandle;
243
+ this.passHandle = passHandle;
244
+ }
245
+
246
+ /**
247
+ * Set the render pipeline
248
+ * @param {GPURenderPipeline} pipeline
249
+ */
250
+ setPipeline(pipeline) {
251
+ // TODO: Call wasm function to set pipeline
252
+ }
253
+
254
+ /**
255
+ * Set vertex buffer
256
+ * @param {number} slot
257
+ * @param {GPUBuffer} buffer
258
+ * @param {number} offset
259
+ * @param {number} size
260
+ */
261
+ setVertexBuffer(slot, buffer, offset = 0, size) {
262
+ // TODO: Call wasm function to set vertex buffer
263
+ }
264
+
265
+ /**
266
+ * Draw vertices
267
+ * @param {number} vertexCount
268
+ * @param {number} instanceCount
269
+ * @param {number} firstVertex
270
+ * @param {number} firstInstance
271
+ */
272
+ draw(vertexCount, instanceCount = 1, firstVertex = 0, firstInstance = 0) {
273
+ // TODO: Call wasm function to draw
274
+ }
275
+
276
+ /**
277
+ * End the render pass
278
+ */
279
+ end() {
280
+ // TODO: Call wasm function to end render pass
281
+ }
282
+ }
283
+
284
+ export class GPUCommandBuffer {
285
+ constructor(wasmModule, wasmMemory, ctxHandle, commandBufferHandle) {
286
+ this.wasm = wasmModule;
287
+ this.memory = wasmMemory;
288
+ this.ctxHandle = ctxHandle;
289
+ this.commandBufferHandle = commandBufferHandle;
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Create a navigator.gpu object
295
+ * @param {Object} wasmModule - WebAssembly module
296
+ * @param {WebAssembly.Memory} wasmMemory - WebAssembly memory
297
+ * @returns {GPU}
298
+ */
299
+ export function createWebGPU(wasmModule, wasmMemory) {
300
+ return new GPU(wasmModule, wasmMemory);
301
+ }
package/webgl2.debug.wasm CHANGED
Binary file
package/webgl2.wasm CHANGED
Binary file