webgl2 1.2.8 → 1.3.1
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 +43 -41
- package/index.js +38 -27
- package/package.json +1 -1
- package/src/webgl2_context.js +146 -295
- package/webgl2.debug.wasm +0 -0
- package/webgl2.wasm +0 -0
package/coverage.md
CHANGED
|
@@ -4,50 +4,52 @@
|
|
|
4
4
|
|
|
5
5
|
| File | Lines Covered | Lines Missed | Total Lines | Coverage |
|
|
6
6
|
|---|---|---|---|---:|
|
|
7
|
-
| src/coverage.rs |
|
|
8
|
-
| src/decompiler/ast.rs |
|
|
9
|
-
| src/decompiler/emitter.rs |
|
|
10
|
-
| src/decompiler/lifter.rs | 6 |
|
|
11
|
-
| src/decompiler/
|
|
12
|
-
| src/decompiler/
|
|
13
|
-
| src/
|
|
14
|
-
| src/
|
|
15
|
-
| src/
|
|
16
|
-
| src/
|
|
17
|
-
| src/naga_wasm_backend/
|
|
18
|
-
| src/naga_wasm_backend/
|
|
19
|
-
| src/naga_wasm_backend/
|
|
20
|
-
| src/naga_wasm_backend/
|
|
21
|
-
| src/naga_wasm_backend/
|
|
22
|
-
| src/naga_wasm_backend/
|
|
23
|
-
| src/naga_wasm_backend/
|
|
24
|
-
| src/naga_wasm_backend/
|
|
25
|
-
| src/naga_wasm_backend/
|
|
26
|
-
| src/naga_wasm_backend/
|
|
27
|
-
| src/
|
|
28
|
-
| src/wasm_gl_emu/
|
|
29
|
-
| src/wasm_gl_emu/
|
|
30
|
-
| src/wasm_gl_emu/
|
|
31
|
-
| src/
|
|
32
|
-
| src/webgl2_context/
|
|
33
|
-
| src/webgl2_context/
|
|
34
|
-
| src/webgl2_context/
|
|
35
|
-
| src/webgl2_context/
|
|
36
|
-
| src/webgl2_context/
|
|
37
|
-
| src/webgl2_context/
|
|
38
|
-
| src/webgl2_context/
|
|
39
|
-
| src/webgl2_context/
|
|
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% 🟢 |
|
|
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% 🟢 |
|
|
16
|
+
| 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% 🟡 |
|
|
40
41
|
| src/webgpu/adapter.rs | 3 | 0 | 3 | 100.00% 🟢 |
|
|
41
|
-
| src/webgpu/backend.rs |
|
|
42
|
-
| src/webgpu/
|
|
43
|
-
| src/webgpu/
|
|
44
|
-
|
|
|
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% 🟡** |
|
|
45
47
|
|
|
46
48
|
## Top Missed Files
|
|
47
49
|
|
|
48
50
|
| File | Lines Missed | Illustrative Line | Coverage |
|
|
49
51
|
|---|---|---|---:|
|
|
50
|
-
| src/lib.rs |
|
|
51
|
-
| src/naga_wasm_backend/expressions.rs |
|
|
52
|
-
| src/
|
|
53
|
-
| src/naga_wasm_backend/control_flow.rs |
|
|
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% 🟡 |
|
package/index.js
CHANGED
|
@@ -269,26 +269,30 @@ async function initWASM({ debug } = {}) {
|
|
|
269
269
|
ACTIVE_FRAME_SP: turboGlobals.ACTIVE_FRAME_SP,
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
-
|
|
273
|
-
env.
|
|
274
|
-
env.
|
|
275
|
-
env.
|
|
276
|
-
env.
|
|
277
|
-
env.
|
|
278
|
-
env.
|
|
279
|
-
env.
|
|
280
|
-
env.
|
|
281
|
-
env.
|
|
282
|
-
env.
|
|
283
|
-
env.
|
|
284
|
-
env.
|
|
285
|
-
env.
|
|
286
|
-
env.
|
|
287
|
-
env.
|
|
288
|
-
env.
|
|
289
|
-
env.
|
|
290
|
-
env.
|
|
291
|
-
|
|
272
|
+
env.gl_sin = instance.exports.gl_sin;
|
|
273
|
+
env.gl_cos = instance.exports.gl_cos;
|
|
274
|
+
env.gl_tan = instance.exports.gl_tan;
|
|
275
|
+
env.gl_asin = instance.exports.gl_asin;
|
|
276
|
+
env.gl_acos = instance.exports.gl_acos;
|
|
277
|
+
env.gl_atan = instance.exports.gl_atan;
|
|
278
|
+
env.gl_atan2 = instance.exports.gl_atan2;
|
|
279
|
+
env.gl_exp = instance.exports.gl_exp;
|
|
280
|
+
env.gl_exp2 = instance.exports.gl_exp2;
|
|
281
|
+
env.gl_log = instance.exports.gl_log;
|
|
282
|
+
env.gl_log2 = instance.exports.gl_log2;
|
|
283
|
+
env.gl_pow = instance.exports.gl_pow;
|
|
284
|
+
env.gl_ldexp = instance.exports.gl_ldexp;
|
|
285
|
+
env.gl_sinh = instance.exports.gl_sinh;
|
|
286
|
+
env.gl_cosh = instance.exports.gl_cosh;
|
|
287
|
+
env.gl_tanh = instance.exports.gl_tanh;
|
|
288
|
+
env.gl_asinh = instance.exports.gl_asinh;
|
|
289
|
+
env.gl_acosh = instance.exports.gl_acosh;
|
|
290
|
+
env.gl_atanh = instance.exports.gl_atanh;
|
|
291
|
+
|
|
292
|
+
// Link diagnostic and math helpers from the main module
|
|
293
|
+
env.gl_debug4 = instance.exports.gl_debug4;
|
|
294
|
+
env.gl_inverse_mat2 = instance.exports.gl_inverse_mat2;
|
|
295
|
+
env.gl_inverse_mat3 = instance.exports.gl_inverse_mat3;
|
|
292
296
|
|
|
293
297
|
const shaderInstance = new WebAssembly.Instance(shaderModule, { env });
|
|
294
298
|
if (shaderInstance.exports.main) {
|
|
@@ -362,16 +366,23 @@ async function initWASM({ debug } = {}) {
|
|
|
362
366
|
*/
|
|
363
367
|
function _readErrorMessage(instance) {
|
|
364
368
|
const ex = instance.exports;
|
|
365
|
-
if (!ex || typeof ex.
|
|
369
|
+
if (!ex || typeof ex.wasm_last_error !== 'function') {
|
|
370
|
+
if (typeof ex.wasm_last_error_ptr === 'function') {
|
|
371
|
+
const ptr = ex.wasm_last_error_ptr();
|
|
372
|
+
const len = ex.wasm_last_error_len();
|
|
373
|
+
if (ptr === 0 || len === 0) return '';
|
|
374
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
375
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
376
|
+
return new TextDecoder('utf-8').decode(bytes);
|
|
377
|
+
}
|
|
366
378
|
return '(no error message available)';
|
|
367
379
|
}
|
|
368
|
-
const ptr = ex.
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
380
|
+
const ptr = ex.wasm_last_error();
|
|
381
|
+
if (ptr === 0) return '';
|
|
382
|
+
const dv = new DataView(ex.memory.buffer);
|
|
383
|
+
const len = dv.getUint32(ptr - 16, true);
|
|
373
384
|
const mem = new Uint8Array(ex.memory.buffer);
|
|
374
|
-
const bytes = mem.
|
|
385
|
+
const bytes = mem.slice(ptr, ptr + len);
|
|
375
386
|
return new TextDecoder('utf-8').decode(bytes);
|
|
376
387
|
}
|
|
377
388
|
|
package/package.json
CHANGED
package/src/webgl2_context.js
CHANGED
|
@@ -709,48 +709,31 @@ export class WasmWebGL2RenderingContext {
|
|
|
709
709
|
throw new Error('wasm_ctx_read_pixels not found');
|
|
710
710
|
}
|
|
711
711
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const len = width * height * bpp;
|
|
726
|
-
if (!out || out.byteLength < len) {
|
|
727
|
-
throw new Error(`output buffer too small (need ${len} bytes, have ${out ? out.byteLength : 0})`);
|
|
712
|
+
const ptr = ex.wasm_ctx_read_pixels(
|
|
713
|
+
this._ctxHandle,
|
|
714
|
+
x | 0,
|
|
715
|
+
y | 0,
|
|
716
|
+
width >>> 0,
|
|
717
|
+
height >>> 0,
|
|
718
|
+
format >>> 0,
|
|
719
|
+
type_ >>> 0
|
|
720
|
+
);
|
|
721
|
+
|
|
722
|
+
if (ptr === 0) {
|
|
723
|
+
const msg = readErrorMessage(this._instance);
|
|
724
|
+
throw new Error(`readPixels failed: ${msg}`);
|
|
728
725
|
}
|
|
729
726
|
|
|
730
|
-
const
|
|
731
|
-
|
|
727
|
+
const dv = new DataView(ex.memory.buffer);
|
|
728
|
+
const len = dv.getUint32(ptr - 16, true);
|
|
732
729
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
this._ctxHandle,
|
|
736
|
-
x | 0,
|
|
737
|
-
y | 0,
|
|
738
|
-
width >>> 0,
|
|
739
|
-
height >>> 0,
|
|
740
|
-
format >>> 0,
|
|
741
|
-
type_ >>> 0,
|
|
742
|
-
ptr >>> 0,
|
|
743
|
-
len >>> 0
|
|
744
|
-
);
|
|
745
|
-
_checkErr(code, this._instance);
|
|
746
|
-
|
|
747
|
-
const mem = new Uint8Array(ex.memory.buffer);
|
|
748
|
-
const src = mem.subarray(ptr, ptr + len);
|
|
749
|
-
const out_bytes = new Uint8Array(out.buffer, out.byteOffset, len);
|
|
750
|
-
out_bytes.set(src);
|
|
751
|
-
} finally {
|
|
752
|
-
ex.wasm_free(ptr);
|
|
730
|
+
if (!out || out.byteLength < len) {
|
|
731
|
+
throw new Error(`output buffer too small (need ${len} bytes, have ${out ? out.byteLength : 0})`);
|
|
753
732
|
}
|
|
733
|
+
|
|
734
|
+
const src = new Uint8Array(ex.memory.buffer, ptr, len);
|
|
735
|
+
const out_bytes = new Uint8Array(out.buffer, out.byteOffset, len);
|
|
736
|
+
out_bytes.set(src);
|
|
754
737
|
}
|
|
755
738
|
|
|
756
739
|
// --- Stubs for unimplemented WebGL2 methods (forwarding API surface) ---
|
|
@@ -856,43 +839,18 @@ export class WasmWebGL2RenderingContext {
|
|
|
856
839
|
}
|
|
857
840
|
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
858
841
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
const typePtr = ex.wasm_alloc(4);
|
|
862
|
-
const nameMaxLen = 256;
|
|
863
|
-
const namePtr = ex.wasm_alloc(nameMaxLen);
|
|
864
|
-
|
|
865
|
-
try {
|
|
866
|
-
const nameLen = ex.wasm_ctx_get_active_uniform(
|
|
867
|
-
this._ctxHandle,
|
|
868
|
-
programHandle,
|
|
869
|
-
index >>> 0,
|
|
870
|
-
sizePtr,
|
|
871
|
-
typePtr,
|
|
872
|
-
namePtr,
|
|
873
|
-
nameMaxLen
|
|
874
|
-
);
|
|
875
|
-
|
|
876
|
-
if (nameLen === 0) {
|
|
877
|
-
return null;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
const mem32SizeIdx = sizePtr >>> 2;
|
|
881
|
-
const mem32TypeIdx = typePtr >>> 2;
|
|
882
|
-
|
|
883
|
-
const size = new Int32Array(ex.memory.buffer)[mem32SizeIdx];
|
|
884
|
-
const type_ = new Uint32Array(ex.memory.buffer)[mem32TypeIdx];
|
|
885
|
-
|
|
886
|
-
const nameBytes = new Uint8Array(ex.memory.buffer, namePtr, nameLen);
|
|
887
|
-
const name = new TextDecoder().decode(nameBytes);
|
|
842
|
+
const ptr = ex.wasm_ctx_get_active_uniform(this._ctxHandle, programHandle, index >>> 0);
|
|
843
|
+
if (ptr === 0) return null;
|
|
888
844
|
|
|
889
|
-
|
|
845
|
+
const dv = new DataView(ex.memory.buffer);
|
|
846
|
+
const totalLen = dv.getUint32(ptr - 16, true);
|
|
847
|
+
const size = dv.getInt32(ptr, true);
|
|
848
|
+
const type_ = dv.getUint32(ptr + 4, true);
|
|
849
|
+
const nameLen = totalLen - 8;
|
|
850
|
+
const nameBytes = new Uint8Array(ex.memory.buffer, ptr + 8, nameLen);
|
|
851
|
+
const name = new TextDecoder('utf-8').decode(nameBytes);
|
|
890
852
|
|
|
891
|
-
|
|
892
|
-
ex.wasm_free(sizePtr);
|
|
893
|
-
ex.wasm_free(typePtr);
|
|
894
|
-
ex.wasm_free(namePtr);
|
|
895
|
-
}
|
|
853
|
+
return { name, size, type: type_ };
|
|
896
854
|
}
|
|
897
855
|
|
|
898
856
|
getActiveAttrib(program, index) {
|
|
@@ -903,43 +861,18 @@ export class WasmWebGL2RenderingContext {
|
|
|
903
861
|
}
|
|
904
862
|
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
905
863
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const typePtr = ex.wasm_alloc(4);
|
|
909
|
-
const nameMaxLen = 256;
|
|
910
|
-
const namePtr = ex.wasm_alloc(nameMaxLen);
|
|
911
|
-
|
|
912
|
-
try {
|
|
913
|
-
const nameLen = ex.wasm_ctx_get_active_attrib(
|
|
914
|
-
this._ctxHandle,
|
|
915
|
-
programHandle,
|
|
916
|
-
index >>> 0,
|
|
917
|
-
sizePtr,
|
|
918
|
-
typePtr,
|
|
919
|
-
namePtr,
|
|
920
|
-
nameMaxLen
|
|
921
|
-
);
|
|
922
|
-
|
|
923
|
-
if (nameLen === 0) {
|
|
924
|
-
return null;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
const mem32SizeIdx = sizePtr >>> 2;
|
|
928
|
-
const mem32TypeIdx = typePtr >>> 2;
|
|
929
|
-
|
|
930
|
-
const size = new Int32Array(ex.memory.buffer)[mem32SizeIdx];
|
|
931
|
-
const type_ = new Uint32Array(ex.memory.buffer)[mem32TypeIdx];
|
|
932
|
-
|
|
933
|
-
const nameBytes = new Uint8Array(ex.memory.buffer, namePtr, nameLen);
|
|
934
|
-
const name = new TextDecoder().decode(nameBytes);
|
|
864
|
+
const ptr = ex.wasm_ctx_get_active_attrib(this._ctxHandle, programHandle, index >>> 0);
|
|
865
|
+
if (ptr === 0) return null;
|
|
935
866
|
|
|
936
|
-
|
|
867
|
+
const dv = new DataView(ex.memory.buffer);
|
|
868
|
+
const totalLen = dv.getUint32(ptr - 16, true);
|
|
869
|
+
const size = dv.getInt32(ptr, true);
|
|
870
|
+
const type_ = dv.getUint32(ptr + 4, true);
|
|
871
|
+
const nameLen = totalLen - 8;
|
|
872
|
+
const nameBytes = new Uint8Array(ex.memory.buffer, ptr + 8, nameLen);
|
|
873
|
+
const name = new TextDecoder('utf-8').decode(nameBytes);
|
|
937
874
|
|
|
938
|
-
|
|
939
|
-
ex.wasm_free(sizePtr);
|
|
940
|
-
ex.wasm_free(typePtr);
|
|
941
|
-
ex.wasm_free(namePtr);
|
|
942
|
-
}
|
|
875
|
+
return { name, size, type: type_ };
|
|
943
876
|
}
|
|
944
877
|
|
|
945
878
|
linkProgram(program) {
|
|
@@ -1036,7 +969,10 @@ export class WasmWebGL2RenderingContext {
|
|
|
1036
969
|
const mathFuncs = [
|
|
1037
970
|
'gl_sin', 'gl_cos', 'gl_tan', 'gl_asin', 'gl_acos', 'gl_atan', 'gl_atan2',
|
|
1038
971
|
'gl_exp', 'gl_exp2', 'gl_log', 'gl_log2', 'gl_pow',
|
|
1039
|
-
'gl_sinh', 'gl_cosh', 'gl_tanh', 'gl_asinh', 'gl_acosh', 'gl_atanh'
|
|
972
|
+
'gl_sinh', 'gl_cosh', 'gl_tanh', 'gl_asinh', 'gl_acosh', 'gl_atanh',
|
|
973
|
+
'gl_inverse_mat2', 'gl_inverse_mat3',
|
|
974
|
+
'gl_debug4'
|
|
975
|
+
|
|
1040
976
|
];
|
|
1041
977
|
for (const name of mathFuncs) {
|
|
1042
978
|
if (this._instance.exports[name]) {
|
|
@@ -1056,7 +992,19 @@ export class WasmWebGL2RenderingContext {
|
|
|
1056
992
|
}
|
|
1057
993
|
|
|
1058
994
|
let fsModule;
|
|
995
|
+
// Dump WASM to disk when debug_shaders is enabled to aid diagnostics
|
|
996
|
+
if (this._debugShaders) {
|
|
997
|
+
try {
|
|
998
|
+
require('fs').writeFileSync('test_debug/failing_fragment.wasm', Buffer.from(fsWasm));
|
|
999
|
+
} catch (e) {
|
|
1000
|
+
// Best-effort; ignore write failures in constrained environments
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (this._debug) {
|
|
1004
|
+
console.log("Compiling FS Module...");
|
|
1005
|
+
}
|
|
1059
1006
|
fsModule = new WebAssembly.Module(fsWasm);
|
|
1007
|
+
|
|
1060
1008
|
const fsInstanceRef = { current: null };
|
|
1061
1009
|
const fsDebugEnv = createDebugEnv(this.FRAGMENT_SHADER, fsInstanceRef);
|
|
1062
1010
|
|
|
@@ -1078,6 +1026,10 @@ export class WasmWebGL2RenderingContext {
|
|
|
1078
1026
|
}
|
|
1079
1027
|
}
|
|
1080
1028
|
|
|
1029
|
+
if (!fsEnv.gl_debug4) fsEnv.gl_debug4 = (a, b, c, d) => {};
|
|
1030
|
+
if (!fsEnv.gl_inverse_mat2) fsEnv.gl_inverse_mat2 = (in_ptr, out_ptr) => {};
|
|
1031
|
+
if (!fsEnv.gl_inverse_mat3) fsEnv.gl_inverse_mat3 = (in_ptr, out_ptr) => {};
|
|
1032
|
+
|
|
1081
1033
|
program._fsInstance = new WebAssembly.Instance(fsModule, {
|
|
1082
1034
|
env: fsEnv
|
|
1083
1035
|
});
|
|
@@ -1197,18 +1149,14 @@ export class WasmWebGL2RenderingContext {
|
|
|
1197
1149
|
}
|
|
1198
1150
|
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
1199
1151
|
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
if (ptr === 0) throw new Error('Failed to allocate memory for getShaderInfoLog');
|
|
1152
|
+
const ptr = ex.wasm_ctx_get_shader_info_log(this._ctxHandle, shaderHandle);
|
|
1153
|
+
if (ptr === 0) return "";
|
|
1203
1154
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
} finally {
|
|
1210
|
-
ex.wasm_free(ptr);
|
|
1211
|
-
}
|
|
1155
|
+
const dv = new DataView(ex.memory.buffer);
|
|
1156
|
+
const len = dv.getUint32(ptr - 16, true);
|
|
1157
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1158
|
+
const bytes = mem.slice(ptr, ptr + len);
|
|
1159
|
+
return new TextDecoder().decode(bytes);
|
|
1212
1160
|
}
|
|
1213
1161
|
|
|
1214
1162
|
getProgramInfoLog(program) {
|
|
@@ -1219,18 +1167,14 @@ export class WasmWebGL2RenderingContext {
|
|
|
1219
1167
|
}
|
|
1220
1168
|
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1221
1169
|
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1224
|
-
if (ptr === 0) throw new Error('Failed to allocate memory for getProgramInfoLog');
|
|
1170
|
+
const ptr = ex.wasm_ctx_get_program_info_log(this._ctxHandle, programHandle);
|
|
1171
|
+
if (ptr === 0) return "";
|
|
1225
1172
|
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
} finally {
|
|
1232
|
-
ex.wasm_free(ptr);
|
|
1233
|
-
}
|
|
1173
|
+
const dv = new DataView(ex.memory.buffer);
|
|
1174
|
+
const len = dv.getUint32(ptr - 16, true);
|
|
1175
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1176
|
+
const bytes = mem.slice(ptr, ptr + len);
|
|
1177
|
+
return new TextDecoder().decode(bytes);
|
|
1234
1178
|
}
|
|
1235
1179
|
|
|
1236
1180
|
getProgramWasm(program, shaderType) {
|
|
@@ -1899,45 +1843,18 @@ export class WasmWebGL2RenderingContext {
|
|
|
1899
1843
|
}
|
|
1900
1844
|
const programHandle = program && typeof program === "object" && typeof program._handle === "number" ? program._handle : (program >>> 0);
|
|
1901
1845
|
|
|
1902
|
-
const
|
|
1903
|
-
|
|
1904
|
-
const nameCapacity = 256;
|
|
1905
|
-
const namePtr = ex.wasm_alloc(nameCapacity);
|
|
1906
|
-
|
|
1907
|
-
if (sizePtr === 0 || typePtr === 0 || namePtr === 0) {
|
|
1908
|
-
if (sizePtr) ex.wasm_free(sizePtr);
|
|
1909
|
-
if (typePtr) ex.wasm_free(typePtr);
|
|
1910
|
-
if (namePtr) ex.wasm_free(namePtr);
|
|
1911
|
-
throw new Error("Failed to allocate memory for getTransformFeedbackVarying");
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
try {
|
|
1915
|
-
const code = ex.wasm_ctx_get_transform_feedback_varying(
|
|
1916
|
-
this._ctxHandle,
|
|
1917
|
-
programHandle,
|
|
1918
|
-
index >>> 0,
|
|
1919
|
-
sizePtr,
|
|
1920
|
-
typePtr,
|
|
1921
|
-
namePtr,
|
|
1922
|
-
nameCapacity
|
|
1923
|
-
);
|
|
1924
|
-
_checkErr(code, this._instance);
|
|
1925
|
-
|
|
1926
|
-
const mem = new DataView(ex.memory.buffer);
|
|
1927
|
-
const size = mem.getInt32(sizePtr, true);
|
|
1928
|
-
const type = mem.getUint32(typePtr, true);
|
|
1846
|
+
const ptr = ex.wasm_ctx_get_transform_feedback_varying(this._ctxHandle, programHandle, index >>> 0);
|
|
1847
|
+
if (ptr === 0) return null;
|
|
1929
1848
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1849
|
+
const dv = new DataView(ex.memory.buffer);
|
|
1850
|
+
const totalLen = dv.getUint32(ptr - 16, true);
|
|
1851
|
+
const size = dv.getInt32(ptr, true);
|
|
1852
|
+
const type = dv.getUint32(ptr + 4, true);
|
|
1853
|
+
const nameLen = totalLen - 8;
|
|
1854
|
+
const nameBytes = new Uint8Array(ex.memory.buffer, ptr + 8, nameLen);
|
|
1855
|
+
const name = new TextDecoder('utf-8').decode(nameBytes);
|
|
1934
1856
|
|
|
1935
|
-
|
|
1936
|
-
} finally {
|
|
1937
|
-
ex.wasm_free(sizePtr);
|
|
1938
|
-
ex.wasm_free(typePtr);
|
|
1939
|
-
ex.wasm_free(namePtr);
|
|
1940
|
-
}
|
|
1857
|
+
return { name, size, type };
|
|
1941
1858
|
}
|
|
1942
1859
|
|
|
1943
1860
|
createQuery() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
@@ -2298,116 +2215,66 @@ export class WasmWebGL2RenderingContext {
|
|
|
2298
2215
|
getParameter(pname) {
|
|
2299
2216
|
this._assertNotDestroyed();
|
|
2300
2217
|
const ex = this._instance.exports;
|
|
2301
|
-
if (!ex || typeof ex.
|
|
2302
|
-
throw new Error('
|
|
2218
|
+
if (!ex || typeof ex.wasm_ctx_get_parameter !== 'function') {
|
|
2219
|
+
throw new Error('wasm_ctx_get_parameter not found');
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
if (pname === 0x8869 /* MAX_VERTEX_ATTRIBS */) {
|
|
2223
|
+
return 16;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
const ptr = ex.wasm_ctx_get_parameter(this._ctxHandle, pname);
|
|
2227
|
+
if (ptr === 0) {
|
|
2228
|
+
return null;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
const dv = new DataView(ex.memory.buffer);
|
|
2232
|
+
|
|
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);
|
|
2303
2237
|
}
|
|
2304
2238
|
|
|
2305
2239
|
if (pname === 0x0BA2 /* VIEWPORT */) {
|
|
2306
|
-
|
|
2307
|
-
try {
|
|
2308
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 16);
|
|
2309
|
-
_checkErr(code, this._instance);
|
|
2310
|
-
const mem = new Int32Array(ex.memory.buffer, ptr, 4);
|
|
2311
|
-
return new Int32Array(mem);
|
|
2312
|
-
} finally {
|
|
2313
|
-
ex.wasm_free(ptr, 16);
|
|
2314
|
-
}
|
|
2240
|
+
return new Int32Array(ex.memory.buffer.slice(ptr, ptr + 16));
|
|
2315
2241
|
}
|
|
2316
2242
|
|
|
2317
2243
|
if (pname === 0x0C22 /* COLOR_CLEAR_VALUE */) {
|
|
2318
|
-
|
|
2319
|
-
try {
|
|
2320
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 16);
|
|
2321
|
-
_checkErr(code, this._instance);
|
|
2322
|
-
const mem = new Float32Array(ex.memory.buffer, ptr, 4);
|
|
2323
|
-
return new Float32Array(mem);
|
|
2324
|
-
} finally {
|
|
2325
|
-
ex.wasm_free(ptr, 16);
|
|
2326
|
-
}
|
|
2244
|
+
return new Float32Array(ex.memory.buffer.slice(ptr, ptr + 16));
|
|
2327
2245
|
}
|
|
2328
2246
|
|
|
2329
2247
|
if (pname === 0x0C23 /* COLOR_WRITEMASK */) {
|
|
2330
|
-
const
|
|
2331
|
-
|
|
2332
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2333
|
-
_checkErr(code, this._instance);
|
|
2334
|
-
const mem = new Uint8Array(ex.memory.buffer, ptr, 4);
|
|
2335
|
-
return [mem[0] !== 0, mem[1] !== 0, mem[2] !== 0, mem[3] !== 0];
|
|
2336
|
-
} finally {
|
|
2337
|
-
ex.wasm_free(ptr, 4);
|
|
2338
|
-
}
|
|
2248
|
+
const mem = new Uint8Array(ex.memory.buffer, ptr, 4);
|
|
2249
|
+
return [mem[0] !== 0, mem[1] !== 0, mem[2] !== 0, mem[3] !== 0];
|
|
2339
2250
|
}
|
|
2340
2251
|
|
|
2341
2252
|
if (pname === 0x8CA6 /* DRAW_FRAMEBUFFER_BINDING */ || pname === 0x8CAA /* READ_FRAMEBUFFER_BINDING */) {
|
|
2342
|
-
const
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
_checkErr(code, this._instance);
|
|
2346
|
-
const handle = new Int32Array(ex.memory.buffer, ptr, 1)[0];
|
|
2347
|
-
if (handle === 0) return null;
|
|
2348
|
-
return this._fbHandles.get(handle) || null;
|
|
2349
|
-
} finally {
|
|
2350
|
-
ex.wasm_free(ptr, 4);
|
|
2351
|
-
}
|
|
2253
|
+
const handle = dv.getInt32(ptr, true);
|
|
2254
|
+
if (handle === 0) return null;
|
|
2255
|
+
return this._fbHandles.get(handle) || null;
|
|
2352
2256
|
}
|
|
2353
2257
|
|
|
2354
2258
|
if (pname === 0x8CA7 /* RENDERBUFFER_BINDING */) {
|
|
2355
|
-
const
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
_checkErr(code, this._instance);
|
|
2359
|
-
const handle = new Int32Array(ex.memory.buffer, ptr, 1)[0];
|
|
2360
|
-
if (handle === 0) return null;
|
|
2361
|
-
return this._rbHandles.get(handle) || null;
|
|
2362
|
-
} finally {
|
|
2363
|
-
ex.wasm_free(ptr, 4);
|
|
2364
|
-
}
|
|
2259
|
+
const handle = dv.getInt32(ptr, true);
|
|
2260
|
+
if (handle === 0) return null;
|
|
2261
|
+
return this._rbHandles.get(handle) || null;
|
|
2365
2262
|
}
|
|
2366
2263
|
|
|
2367
2264
|
if (pname === 0x8824 /* MAX_DRAW_BUFFERS */ || pname === 0x8CDF /* MAX_COLOR_ATTACHMENTS */) {
|
|
2368
|
-
|
|
2369
|
-
try {
|
|
2370
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2371
|
-
_checkErr(code, this._instance);
|
|
2372
|
-
return new Int32Array(ex.memory.buffer, ptr, 1)[0];
|
|
2373
|
-
} finally {
|
|
2374
|
-
ex.wasm_free(ptr, 4);
|
|
2375
|
-
}
|
|
2265
|
+
return dv.getInt32(ptr, true);
|
|
2376
2266
|
}
|
|
2377
2267
|
|
|
2378
2268
|
if (pname >= 0x8825 /* DRAW_BUFFER0 */ && pname <= 0x882C /* DRAW_BUFFER7 */) {
|
|
2379
|
-
|
|
2380
|
-
try {
|
|
2381
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2382
|
-
_checkErr(code, this._instance);
|
|
2383
|
-
return new Int32Array(ex.memory.buffer, ptr, 1)[0];
|
|
2384
|
-
} finally {
|
|
2385
|
-
ex.wasm_free(ptr, 4);
|
|
2386
|
-
}
|
|
2269
|
+
return dv.getInt32(ptr, true);
|
|
2387
2270
|
}
|
|
2388
2271
|
|
|
2389
2272
|
if (pname === 0x0B72 /* DEPTH_WRITEMASK */) {
|
|
2390
|
-
|
|
2391
|
-
try {
|
|
2392
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2393
|
-
_checkErr(code, this._instance);
|
|
2394
|
-
const mem = new Uint8Array(ex.memory.buffer, ptr, 1);
|
|
2395
|
-
return mem[0] !== 0;
|
|
2396
|
-
} finally {
|
|
2397
|
-
ex.wasm_free(ptr, 4);
|
|
2398
|
-
}
|
|
2273
|
+
return dv.getUint8(ptr) !== 0;
|
|
2399
2274
|
}
|
|
2400
2275
|
|
|
2401
2276
|
if (pname === 0x0B98 /* STENCIL_WRITEMASK */ || pname === 0x8CA5 /* STENCIL_BACK_WRITEMASK */) {
|
|
2402
|
-
|
|
2403
|
-
try {
|
|
2404
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2405
|
-
_checkErr(code, this._instance);
|
|
2406
|
-
const mem = new Int32Array(ex.memory.buffer, ptr, 1);
|
|
2407
|
-
return mem[0];
|
|
2408
|
-
} finally {
|
|
2409
|
-
ex.wasm_free(ptr, 4);
|
|
2410
|
-
}
|
|
2277
|
+
return dv.getInt32(ptr, true);
|
|
2411
2278
|
}
|
|
2412
2279
|
|
|
2413
2280
|
const singleIntParams = [
|
|
@@ -2427,19 +2294,7 @@ export class WasmWebGL2RenderingContext {
|
|
|
2427
2294
|
];
|
|
2428
2295
|
|
|
2429
2296
|
if (singleIntParams.includes(pname)) {
|
|
2430
|
-
|
|
2431
|
-
try {
|
|
2432
|
-
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2433
|
-
_checkErr(code, this._instance);
|
|
2434
|
-
const mem = new Int32Array(ex.memory.buffer, ptr, 1);
|
|
2435
|
-
return mem[0];
|
|
2436
|
-
} finally {
|
|
2437
|
-
ex.wasm_free(ptr, 4);
|
|
2438
|
-
}
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
if (pname === 0x8869 /* MAX_VERTEX_ATTRIBS */) {
|
|
2442
|
-
return 16;
|
|
2297
|
+
return dv.getInt32(ptr, true);
|
|
2443
2298
|
}
|
|
2444
2299
|
|
|
2445
2300
|
throw new Error(`getParameter for ${pname} not implemented`);
|
|
@@ -2721,16 +2576,24 @@ export class WasmWebGL2RenderingContext {
|
|
|
2721
2576
|
*/
|
|
2722
2577
|
export function readErrorMessage(instance) {
|
|
2723
2578
|
const ex = instance.exports;
|
|
2724
|
-
if (!ex || typeof ex.
|
|
2579
|
+
if (!ex || typeof ex.wasm_last_error !== 'function') {
|
|
2580
|
+
// Fallback to old ptr/len if exists, otherwise return unknown
|
|
2581
|
+
if (typeof ex.wasm_last_error_ptr === 'function') {
|
|
2582
|
+
const ptr = ex.wasm_last_error_ptr();
|
|
2583
|
+
const len = ex.wasm_last_error_len();
|
|
2584
|
+
if (ptr === 0 || len === 0) return '';
|
|
2585
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
2586
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
2587
|
+
return new TextDecoder('utf-8').decode(bytes);
|
|
2588
|
+
}
|
|
2725
2589
|
return '(no error message available)';
|
|
2726
2590
|
}
|
|
2727
|
-
const ptr = ex.
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}
|
|
2591
|
+
const ptr = ex.wasm_last_error();
|
|
2592
|
+
if (ptr === 0) return '';
|
|
2593
|
+
const dv = new DataView(ex.memory.buffer);
|
|
2594
|
+
const len = dv.getUint32(ptr - 16, true);
|
|
2732
2595
|
const mem = new Uint8Array(ex.memory.buffer);
|
|
2733
|
-
const bytes = mem.
|
|
2596
|
+
const bytes = mem.slice(ptr, ptr + len);
|
|
2734
2597
|
return new TextDecoder('utf-8').decode(bytes);
|
|
2735
2598
|
}
|
|
2736
2599
|
|
|
@@ -2878,24 +2741,18 @@ export function getShaderGlsl(ctxHandle, programHandle, shaderType) {
|
|
|
2878
2741
|
mem.set(wasmBytes, wasmBytesPtr);
|
|
2879
2742
|
|
|
2880
2743
|
// Call the decompiler
|
|
2881
|
-
const
|
|
2744
|
+
const glslPtr = ex.wasm_decompile_to_glsl(wasmBytesPtr, wasmBytesLen);
|
|
2882
2745
|
|
|
2883
|
-
if (
|
|
2746
|
+
if (glslPtr === 0) {
|
|
2884
2747
|
return null;
|
|
2885
2748
|
}
|
|
2886
2749
|
|
|
2887
|
-
|
|
2888
|
-
const
|
|
2889
|
-
const glslLen = ex.wasm_get_decompiled_glsl_len();
|
|
2890
|
-
|
|
2891
|
-
if (glslPtr === 0 || glslLen === 0) {
|
|
2892
|
-
return null;
|
|
2893
|
-
}
|
|
2750
|
+
const dv = new DataView(ex.memory.buffer);
|
|
2751
|
+
const glslLen = dv.getUint32(glslPtr - 16, true);
|
|
2894
2752
|
|
|
2895
2753
|
// Read the GLSL string
|
|
2896
|
-
const glslBytes = new Uint8Array(ex.memory.buffer).
|
|
2897
|
-
|
|
2898
|
-
return decoder.decode(glslBytes);
|
|
2754
|
+
const glslBytes = new Uint8Array(ex.memory.buffer).slice(glslPtr, glslPtr + glslLen);
|
|
2755
|
+
return new TextDecoder('utf-8').decode(glslBytes);
|
|
2899
2756
|
} finally {
|
|
2900
2757
|
// Free the allocated memory
|
|
2901
2758
|
ex.wasm_free(wasmBytesPtr);
|
|
@@ -2934,24 +2791,18 @@ export function decompileWasmToGlsl(gl, wasmBytes) {
|
|
|
2934
2791
|
mem.set(wasmBytes, wasmBytesPtr);
|
|
2935
2792
|
|
|
2936
2793
|
// Call the decompiler
|
|
2937
|
-
const
|
|
2794
|
+
const glslPtr = ex.wasm_decompile_to_glsl(wasmBytesPtr, wasmBytesLen);
|
|
2938
2795
|
|
|
2939
|
-
if (
|
|
2796
|
+
if (glslPtr === 0) {
|
|
2940
2797
|
return null;
|
|
2941
2798
|
}
|
|
2942
2799
|
|
|
2943
|
-
|
|
2944
|
-
const
|
|
2945
|
-
const glslLen = ex.wasm_get_decompiled_glsl_len();
|
|
2946
|
-
|
|
2947
|
-
if (glslPtr === 0 || glslLen === 0) {
|
|
2948
|
-
return null;
|
|
2949
|
-
}
|
|
2800
|
+
const dv = new DataView(ex.memory.buffer);
|
|
2801
|
+
const glslLen = dv.getUint32(glslPtr - 16, true);
|
|
2950
2802
|
|
|
2951
2803
|
// Read the GLSL string
|
|
2952
|
-
const glslBytes = new Uint8Array(ex.memory.buffer).
|
|
2953
|
-
|
|
2954
|
-
return decoder.decode(glslBytes);
|
|
2804
|
+
const glslBytes = new Uint8Array(ex.memory.buffer).slice(glslPtr, glslPtr + glslLen);
|
|
2805
|
+
return new TextDecoder('utf-8').decode(glslBytes);
|
|
2955
2806
|
} finally {
|
|
2956
2807
|
// Free the allocated memory
|
|
2957
2808
|
ex.wasm_free(wasmBytesPtr);
|
package/webgl2.debug.wasm
CHANGED
|
Binary file
|
package/webgl2.wasm
CHANGED
|
Binary file
|