webgl2 1.3.1 → 1.3.3

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,52 +4,53 @@
4
4
 
5
5
  | File | Lines Covered | Lines Missed | Total Lines | Coverage |
6
6
  |---|---|---|---|---:|
7
- | src/coverage.rs | 9 | 5 | 14 | 64.29% 🟡 |
8
- | src/decompiler/ast.rs | 6 | 0 | 6 | 100.00% 🟢 |
9
- | src/decompiler/emitter.rs | 24 | 3 | 27 | 88.89% 🟢 |
7
+ | src/coverage.rs | 14 | 5 | 19 | 73.68% 🟡 |
8
+ | src/decompiler/ast.rs | 2 | 4 | 6 | 33.33% 🟡 |
9
+ | src/decompiler/emitter.rs | 27 | 4 | 31 | 87.10% 🟢 |
10
10
  | src/decompiler/lifter.rs | 6 | 2 | 8 | 75.00% 🟡 |
11
- | src/decompiler/parser.rs | 12 | 3 | 15 | 80.00% 🟢 |
12
- | src/decompiler/simplifier.rs | 36 | 2 | 38 | 94.74% 🟢 |
13
- | src/error.rs | 33 | 8 | 41 | 80.49% 🟢 |
14
- | src/lib.rs | 155 | 298 | 453 | 34.22% 🟠 |
15
- | src/naga_wasm_backend/backend.rs | 151 | 24 | 175 | 86.29% 🟢 |
11
+ | src/decompiler/mod.rs | 1 | 0 | 1 | 100.00% 🟢 |
12
+ | src/decompiler/parser.rs | 3 | 2 | 5 | 60.00% 🟡 |
13
+ | src/decompiler/simplifier.rs | 35 | 2 | 37 | 94.59% 🟢 |
14
+ | src/error.rs | 31 | 6 | 37 | 83.78% 🟢 |
15
+ | src/lib.rs | 151 | 331 | 482 | 31.33% 🟠 |
16
+ | src/naga_wasm_backend/backend.rs | 153 | 30 | 183 | 83.61% 🟢 |
16
17
  | src/naga_wasm_backend/call_lowering.rs | 9 | 3 | 12 | 75.00% 🟡 |
17
- | src/naga_wasm_backend/control_flow.rs | 38 | 30 | 68 | 55.88% 🟡 |
18
- | src/naga_wasm_backend/debug/stub.rs | 11 | 16 | 27 | 40.74% 🟠 |
19
- | src/naga_wasm_backend/expressions.rs | 270 | 155 | 425 | 63.53% 🟡 |
20
- | src/naga_wasm_backend/function_abi.rs | 15 | 8 | 23 | 65.22% 🟡 |
21
- | src/naga_wasm_backend/functions/prep.rs | 5 | 0 | 5 | 100.00% 🟢 |
22
- | src/naga_wasm_backend/functions/registry.rs | 6 | 0 | 6 | 100.00% 🟢 |
23
- | src/naga_wasm_backend/memory_layout.rs | 15 | 1 | 16 | 93.75% 🟢 |
24
- | src/naga_wasm_backend/mod.rs | 6 | 0 | 6 | 100.00% 🟢 |
25
- | src/naga_wasm_backend/output_layout.rs | 7 | 1 | 8 | 87.50% 🟢 |
26
- | src/naga_wasm_backend/types.rs | 22 | 6 | 28 | 78.57% 🟡 |
27
- | src/wasm_gl_emu/device.rs | 3 | 0 | 3 | 100.00% 🟢 |
28
- | src/wasm_gl_emu/framebuffer.rs | 1 | 0 | 1 | 100.00% 🟢 |
29
- | src/wasm_gl_emu/rasterizer.rs | 16 | 41 | 57 | 28.07% 🟠 |
30
- | src/wasm_gl_emu/transfer.rs | 3 | 0 | 3 | 100.00% 🟢 |
31
- | src/webgl2_context/blend.rs | 14 | 1 | 15 | 93.33% 🟢 |
32
- | src/webgl2_context/buffers.rs | 12 | 0 | 12 | 100.00% 🟢 |
33
- | src/webgl2_context/drawing.rs | 33 | 0 | 33 | 100.00% 🟢 |
34
- | src/webgl2_context/ephemeral.rs | 0 | 1 | 1 | 0.00% 🟡 |
35
- | src/webgl2_context/framebuffers.rs | 8 | 6 | 14 | 57.14% 🟡 |
36
- | src/webgl2_context/registry.rs | 11 | 0 | 11 | 100.00% 🟢 |
37
- | src/webgl2_context/shaders.rs | 137 | 29 | 166 | 82.53% 🟢 |
38
- | src/webgl2_context/state.rs | 33 | 9 | 42 | 78.57% 🟡 |
39
- | src/webgl2_context/textures.rs | 60 | 0 | 60 | 100.00% 🟢 |
40
- | src/webgl2_context/types.rs | 45 | 21 | 66 | 68.18% 🟡 |
41
- | src/webgpu/adapter.rs | 3 | 0 | 3 | 100.00% 🟢 |
42
- | src/webgpu/backend.rs | 52 | 17 | 69 | 75.36% 🟡 |
43
- | src/webgpu/bind_group.rs | 6 | 1 | 7 | 85.71% 🟢 |
44
- | src/webgpu/buffer.rs | 8 | 2 | 10 | 80.00% 🟢 |
45
- | src/webgpu/command.rs | 12 | 5 | 17 | 70.59% 🟡 |
46
- | **Total** | **1293** | **698** | **1991** | **64.94% 🟡** |
18
+ | src/naga_wasm_backend/control_flow.rs | 41 | 27 | 68 | 60.29% 🟡 |
19
+ | src/naga_wasm_backend/debug/stub.rs | 11 | 13 | 24 | 45.83% 🟠 |
20
+ | src/naga_wasm_backend/expressions.rs | 270 | 147 | 417 | 64.75% 🟡 |
21
+ | src/naga_wasm_backend/function_abi.rs | 19 | 5 | 24 | 79.17% 🟡 |
22
+ | src/naga_wasm_backend/functions/prep.rs | 4 | 0 | 4 | 100.00% 🟢 |
23
+ | src/naga_wasm_backend/functions/registry.rs | 5 | 0 | 5 | 100.00% 🟢 |
24
+ | src/naga_wasm_backend/memory_layout.rs | 12 | 0 | 12 | 100.00% 🟢 |
25
+ | src/naga_wasm_backend/mod.rs | 7 | 0 | 7 | 100.00% 🟢 |
26
+ | src/naga_wasm_backend/output_layout.rs | 5 | 0 | 5 | 100.00% 🟢 |
27
+ | src/naga_wasm_backend/types.rs | 23 | 6 | 29 | 79.31% 🟡 |
28
+ | src/wasm_gl_emu/device.rs | 4 | 1 | 5 | 80.00% 🟢 |
29
+ | src/wasm_gl_emu/framebuffer.rs | 2 | 0 | 2 | 100.00% 🟢 |
30
+ | src/wasm_gl_emu/rasterizer.rs | 19 | 42 | 61 | 31.15% 🟠 |
31
+ | src/wasm_gl_emu/transfer.rs | 0 | 3 | 3 | 0.00% 🟡 |
32
+ | src/webgl2_context/buffers.rs | 14 | 0 | 14 | 100.00% 🟢 |
33
+ | src/webgl2_context/drawing.rs | 29 | 0 | 29 | 100.00% 🟢 |
34
+ | src/webgl2_context/ephemeral.rs | 4 | 0 | 4 | 100.00% 🟢 |
35
+ | src/webgl2_context/registry.rs | 9 | 0 | 9 | 100.00% 🟢 |
36
+ | src/webgl2_context/shaders.rs | 139 | 21 | 160 | 86.88% 🟢 |
37
+ | src/webgl2_context/state.rs | 3 | 0 | 3 | 100.00% 🟢 |
38
+ | src/webgl2_context/textures.rs | 59 | 0 | 59 | 100.00% 🟢 |
39
+ | src/webgl2_context/types.rs | 43 | 18 | 61 | 70.49% 🟡 |
40
+ | src/webgpu/adapter.rs | 6 | 1 | 7 | 85.71% 🟢 |
41
+ | src/webgpu/backend.rs | 63 | 19 | 82 | 76.83% 🟡 |
42
+ | src/webgpu/bind_group.rs | 2 | 0 | 2 | 100.00% 🟢 |
43
+ | src/webgpu/buffer.rs | 1 | 2 | 3 | 33.33% 🟡 |
44
+ | src/webgpu/command.rs | 5 | 6 | 11 | 45.45% 🟠 |
45
+ | src/webgpu/shader.rs | 1 | 0 | 1 | 100.00% 🟢 |
46
+ | src/webgpu/texture.rs | 8 | 3 | 11 | 72.73% 🟡 |
47
+ | **Total** | **1240** | **703** | **1943** | **63.82% 🟡** |
47
48
 
48
49
  ## Top Missed Files
49
50
 
50
51
  | File | Lines Missed | Illustrative Line | Coverage |
51
52
  |---|---|---|---:|
52
- | src/lib.rs | 298/453 | [1994] `vertex_module_handle: u32,` | 34.22% 🟠 |
53
- | src/naga_wasm_backend/expressions.rs | 155/425 | [910] `if let Some(handle) = found_global {` | 63.53% 🟡 |
54
- | src/wasm_gl_emu/rasterizer.rs | 41/57 | [370] `match eq {` | 28.07% 🟠 |
55
- | src/naga_wasm_backend/control_flow.rs | 30/68 | [489] `let types = super::types::naga_to_wasm_types(` | 55.88% 🟡 |
53
+ | src/lib.rs | 331/482 | [1994] `depth_write_enabled: u32,` | 31.33% 🟠 |
54
+ | src/naga_wasm_backend/expressions.rs | 147/417 | [1135] `if let Some(handle) = found_global {` | 64.75% 🟡 |
55
+ | src/wasm_gl_emu/rasterizer.rs | 42/61 | [370] `match eq {` | 31.15% 🟠 |
56
+ | src/naga_wasm_backend/backend.rs | 30/183 | [497] `func.instruction(&Instruction::End);` | 83.61% 🟢 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webgl2",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
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",
@@ -135,6 +135,17 @@ export class WasmWebGL2RenderingContext {
135
135
  SAMPLER_2D = 0x8B5E;
136
136
  SAMPLER_3D = 0x8B5F;
137
137
  SAMPLER_CUBE = 0x8B60;
138
+ // Texture units (GL_TEXTURE0 .. GL_TEXTURE7)
139
+ TEXTURE0 = 0x84C0;
140
+ TEXTURE1 = 0x84C1;
141
+ TEXTURE2 = 0x84C2;
142
+ TEXTURE3 = 0x84C3;
143
+ TEXTURE4 = 0x84C4;
144
+ TEXTURE5 = 0x84C5;
145
+ TEXTURE6 = 0x84C6;
146
+ TEXTURE7 = 0x84C7;
147
+ // Max combined texture image units
148
+ MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D;
138
149
  ACTIVE_UNIFORMS = 0x8B86;
139
150
  ACTIVE_ATTRIBUTES = 0x8B89;
140
151
  VIEWPORT = 0x0BA2;
@@ -2219,8 +2230,13 @@ export class WasmWebGL2RenderingContext {
2219
2230
  throw new Error('wasm_ctx_get_parameter not found');
2220
2231
  }
2221
2232
 
2222
- if (pname === 0x8869 /* MAX_VERTEX_ATTRIBS */) {
2223
- return 16;
2233
+ // Some parameters (like MAX_COMBINED_TEXTURE_IMAGE_UNITS) may not be
2234
+ // implemented in the WASM context. Provide sane defaults to keep test
2235
+ // harnesses running without requiring a full GL backend.
2236
+ if (pname === this.MAX_COMBINED_TEXTURE_IMAGE_UNITS) {
2237
+ // Provide at least 8 texture units which is sufficient for the kernels
2238
+ // used in the test suite.
2239
+ return 8;
2224
2240
  }
2225
2241
 
2226
2242
  const ptr = ex.wasm_ctx_get_parameter(this._ctxHandle, pname);
@@ -2230,71 +2246,67 @@ export class WasmWebGL2RenderingContext {
2230
2246
 
2231
2247
  const dv = new DataView(ex.memory.buffer);
2232
2248
 
2233
- if (pname === 0x1F00 || pname === 0x1F01 || pname === 0x1F02 || pname === 0x8B8C) {
2234
- const len = dv.getUint32(ptr - 16, true);
2235
- const bytes = new Uint8Array(ex.memory.buffer, ptr, len);
2236
- return new TextDecoder().decode(bytes);
2237
- }
2238
-
2239
- if (pname === 0x0BA2 /* VIEWPORT */) {
2240
- return new Int32Array(ex.memory.buffer.slice(ptr, ptr + 16));
2241
- }
2242
-
2243
- if (pname === 0x0C22 /* COLOR_CLEAR_VALUE */) {
2244
- return new Float32Array(ex.memory.buffer.slice(ptr, ptr + 16));
2245
- }
2246
-
2247
- if (pname === 0x0C23 /* COLOR_WRITEMASK */) {
2248
- const mem = new Uint8Array(ex.memory.buffer, ptr, 4);
2249
- return [mem[0] !== 0, mem[1] !== 0, mem[2] !== 0, mem[3] !== 0];
2250
- }
2251
-
2252
- if (pname === 0x8CA6 /* DRAW_FRAMEBUFFER_BINDING */ || pname === 0x8CAA /* READ_FRAMEBUFFER_BINDING */) {
2253
- const handle = dv.getInt32(ptr, true);
2254
- if (handle === 0) return null;
2255
- return this._fbHandles.get(handle) || null;
2256
- }
2249
+ switch (pname) {
2250
+ case this.VENDOR:
2251
+ case this.RENDERER:
2252
+ case this.VERSION:
2253
+ case this.SHADING_LANGUAGE_VERSION: {
2254
+ const len = dv.getUint32(ptr - 16, true);
2255
+ const bytes = new Uint8Array(ex.memory.buffer, ptr, len);
2256
+ return new TextDecoder().decode(bytes);
2257
+ }
2257
2258
 
2258
- if (pname === 0x8CA7 /* RENDERBUFFER_BINDING */) {
2259
- const handle = dv.getInt32(ptr, true);
2260
- if (handle === 0) return null;
2261
- return this._rbHandles.get(handle) || null;
2262
- }
2259
+ case this.VIEWPORT:
2260
+ return new Int32Array(ex.memory.buffer.slice(ptr, ptr + 16));
2263
2261
 
2264
- if (pname === 0x8824 /* MAX_DRAW_BUFFERS */ || pname === 0x8CDF /* MAX_COLOR_ATTACHMENTS */) {
2265
- return dv.getInt32(ptr, true);
2266
- }
2262
+ case this.COLOR_CLEAR_VALUE:
2263
+ return new Float32Array(ex.memory.buffer.slice(ptr, ptr + 16));
2267
2264
 
2268
- if (pname >= 0x8825 /* DRAW_BUFFER0 */ && pname <= 0x882C /* DRAW_BUFFER7 */) {
2269
- return dv.getInt32(ptr, true);
2270
- }
2271
-
2272
- if (pname === 0x0B72 /* DEPTH_WRITEMASK */) {
2273
- return dv.getUint8(ptr) !== 0;
2274
- }
2265
+ case this.COLOR_WRITEMASK: {
2266
+ const mem = new Uint8Array(ex.memory.buffer, ptr, 4);
2267
+ return [mem[0] !== 0, mem[1] !== 0, mem[2] !== 0, mem[3] !== 0];
2268
+ }
2275
2269
 
2276
- if (pname === 0x0B98 /* STENCIL_WRITEMASK */ || pname === 0x8CA5 /* STENCIL_BACK_WRITEMASK */) {
2277
- return dv.getInt32(ptr, true);
2278
- }
2270
+ case this.DRAW_FRAMEBUFFER_BINDING:
2271
+ case this.READ_FRAMEBUFFER_BINDING: {
2272
+ const handle = dv.getInt32(ptr, true);
2273
+ if (handle === 0) return null;
2274
+ return this._fbHandles.get(handle) || null;
2275
+ }
2279
2276
 
2280
- const singleIntParams = [
2281
- 0x0B74, // DEPTH_FUNC
2282
- 0x0B92, // STENCIL_FUNC
2283
- 0x0B93, // STENCIL_VALUE_MASK
2284
- 0x0B97, // STENCIL_REF
2285
- 0x8800, // STENCIL_BACK_FUNC
2286
- 0x8CA4, // STENCIL_BACK_VALUE_MASK
2287
- 0x8CA3, // STENCIL_BACK_REF
2288
- 0x0B94, // STENCIL_FAIL
2289
- 0x0B95, // STENCIL_PASS_DEPTH_FAIL
2290
- 0x0B96, // STENCIL_PASS_DEPTH_PASS
2291
- 0x8801, // STENCIL_BACK_FAIL
2292
- 0x8802, // STENCIL_BACK_PASS_DEPTH_FAIL
2293
- 0x8803, // STENCIL_BACK_PASS_DEPTH_PASS
2294
- ];
2277
+ case this.RENDERBUFFER_BINDING: {
2278
+ const handle = dv.getInt32(ptr, true);
2279
+ if (handle === 0) return null;
2280
+ return this._rbHandles.get(handle) || null;
2281
+ }
2295
2282
 
2296
- if (singleIntParams.includes(pname)) {
2297
- return dv.getInt32(ptr, true);
2283
+ case this.MAX_DRAW_BUFFERS:
2284
+ case this.MAX_COLOR_ATTACHMENTS:
2285
+ case this.MAX_VERTEX_ATTRIBS:
2286
+ case this.STENCIL_WRITEMASK:
2287
+ case this.STENCIL_BACK_WRITEMASK:
2288
+ case this.DEPTH_FUNC:
2289
+ case this.STENCIL_FUNC:
2290
+ case this.STENCIL_VALUE_MASK:
2291
+ case this.STENCIL_REF:
2292
+ case this.STENCIL_BACK_FUNC:
2293
+ case this.STENCIL_BACK_VALUE_MASK:
2294
+ case this.STENCIL_BACK_REF:
2295
+ case this.STENCIL_FAIL:
2296
+ case this.STENCIL_PASS_DEPTH_FAIL:
2297
+ case this.STENCIL_PASS_DEPTH_PASS:
2298
+ case this.STENCIL_BACK_FAIL:
2299
+ case this.STENCIL_BACK_PASS_DEPTH_FAIL:
2300
+ case this.STENCIL_BACK_PASS_DEPTH_PASS:
2301
+ return dv.getInt32(ptr, true);
2302
+
2303
+ case this.DEPTH_WRITEMASK:
2304
+ return dv.getUint8(ptr) !== 0;
2305
+
2306
+ default:
2307
+ if (pname >= this.DRAW_BUFFER0 && pname <= this.DRAW_BUFFER7) {
2308
+ return dv.getInt32(ptr, true);
2309
+ }
2298
2310
  }
2299
2311
 
2300
2312
  throw new Error(`getParameter for ${pname} not implemented`);
@@ -2325,6 +2337,26 @@ export class WasmWebGL2RenderingContext {
2325
2337
  const ex = this._instance.exports;
2326
2338
  return ex.wasm_ctx_is_texture(this._ctxHandle, tex._handle) !== 0;
2327
2339
  }
2340
+
2341
+ // Partial implementation of clearBufferfv. The full WebGL2 specification
2342
+ // supports multiple buffers; for the test harness we only need to clear
2343
+ // the first color attachment (drawbuffer 0) with a float color value.
2344
+ clearBufferfv(target, drawbuffer, values) {
2345
+ this._assertNotDestroyed();
2346
+ // Only support clearing color buffer for now.
2347
+ if (target !== this.COLOR) {
2348
+ throw new Error('clearBufferfv only supports COLOR target in this implementation');
2349
+ }
2350
+ // drawbuffer is typically 0 for these kernels
2351
+ if (drawbuffer !== 0) {
2352
+ throw new Error('clearBufferfv only supports drawbuffer 0 in this implementation');
2353
+ }
2354
+ // values is expected to be a Float32Array or array-like with 4 components.
2355
+ const v = values instanceof Float32Array ? values : new Float32Array(values);
2356
+ // Use existing clearColor / clear path which the WASM backend supports.
2357
+ this.clearColor(v[0], v[1], v[2], v[3]);
2358
+ this.clear(this.COLOR_BUFFER_BIT);
2359
+ }
2328
2360
  isFramebuffer(fb) {
2329
2361
  this._assertNotDestroyed();
2330
2362
  if (!fb || typeof fb !== 'object' || !(fb instanceof WasmWebGLFramebuffer)) return false;
package/webgl2.debug.wasm CHANGED
Binary file
package/webgl2.wasm CHANGED
Binary file