code wiki / _hdl_build / nx_meshview_wasm_gate.nx
nx_meshview_wasm_gate.nx source
↩ module page · 255 lines · 20309 B
1// nx_meshview_wasm_gate.nx -- R3 WASM proof: compiles nx_meshview_wasm.nx to .wasm via the SOVEREIGN chain
2// (nx_compile_wat -> nx_wat_compiler, NO Emscripten), runs it in our own nx_wasm_vm, and checks the rendered
3// framebuffer (read straight from the VM's linear memory) is z-correct + non-vacuous + deterministic -- i.e.
4// our general-mesh renderer renders IN THE BROWSER LANE, sovereign, no WebGL/NVIDIA. expect_exit: 0
5import "nx_syscalls.nx"
6import "nx_g_puts_lib.nx"
7import "nx_wasm_vm.nx"
8
9const CWAT_ELF: *u8 = "/tmp/nx_compile_wat.sov.elf"
10const WATC_ELF: *u8 = "/tmp/nx_wat_compiler.sov.elf"
11const SRC_NX: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/runtime/nx_meshview_wasm.nx"
12const OUT_WAT: *u8 = "/tmp/mv.wat"
13const OUT_WASM: *u8 = "/tmp/mv.wasm"
14
15const O_FB: i64 = 0
16const MV_N: i64 = 4096
17const CTR: i64 = 2080 // (32*64+32) screen-centre pixel index
18const BG: i64 = 4280295456 // background r32 g32 b32 a255
19
20func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45 as u8;sys_write(1,b,1);x=0-x} if x==0{b[0]=48 as u8;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 }
21func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
22func run_elf(elf: *u8, a1: *u8, a2: *u8) -> i64 {
23 let pid: i64 = sys_fork()
24 if pid == 0 {
25 let argv: *i64 = sys_mmap(64) as *i64
26 argv[0] = elf as i64
27 var ai: i64 = 1
28 if (a1 as i64) != 0 { argv[ai] = a1 as i64; ai = ai + 1 }
29 if (a2 as i64) != 0 { argv[ai] = a2 as i64; ai = ai + 1 }
30 argv[ai] = 0
31 let envp: *i64 = sys_mmap(16) as *i64
32 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64
33 envp[1] = 0
34 sys_execve(elf, argv, envp)
35 sys_exit(127)
36 }
37 let st: *i64 = sys_mmap(16) as *i64
38 sys_wait4(pid, st, 0)
39 return (st[0] >> 8) & 0xff
40}
41func cover(fbp: *i64) -> i64 { var k: i64=0; var i: i64=0; while i<MV_N { if fbp[i]!=BG {k=k+1} i=i+1 } return k }
42
43func main() -> i64 {
44 g_puts("nx_meshview_wasm_gate (sovereign .nx->wasm -> nx_wasm_vm: our mesh renderer in the browser lane)\n" as *u8)
45 let rc1: i64 = run_elf(CWAT_ELF, SRC_NX, OUT_WAT)
46 g_puts(" [build] nx_compile_wat rc="); g_pn(rc1); g_puts("\n" as *u8)
47 let rc2: i64 = run_elf(WATC_ELF, OUT_WAT, OUT_WASM)
48 g_puts(" [build] nx_wat_compiler rc="); g_pn(rc2); g_puts("\n" as *u8)
49
50 let box: *i64 = sys_mmap(16) as *i64
51 let wasm: *u8 = sys_read_file(OUT_WASM, box)
52 if (wasm as i64) == 0 { g_puts(" FAIL cannot read mv.wasm\nverdict=RED\n" as *u8); sys_exit(1); return 1 }
53 g_puts(" [measure] wasm bytes="); g_pn(box[0]); g_puts("\n" as *u8)
54 let mod: *WasmMod = wm_new(wasm, box[0])
55 if wm_parse(mod) != 0 { g_puts(" FAIL wasm parse\nverdict=RED\n" as *u8); sys_exit(1); return 1 }
56 mod.mem = sys_mmap(131072) as *u8
57 g_puts(" [measure] funcs="); g_pn(mod.n_funcs); g_puts(" exports="); g_pn(mod.n_exports); g_puts("\n" as *u8)
58
59 let fbp: *i64 = (mod.mem as i64 + O_FB) as *i64
60 let drawn: i64 = wm_run(mod, "mv_render" as *u8, 0, 0, 0, 0, 0, 1) // mv_render(angle=0)
61 let center: i64 = fbp[CTR]
62 let cr: i64 = center % 256
63 let cb: i64 = (center / 65536) % 256
64 let cov: i64 = cover(fbp)
65 g_puts(" drawn_tris="); g_pn(drawn); g_puts(" center_R="); g_pn(cr); g_puts(" center_B="); g_pn(cb); g_puts(" coverage="); g_pn(cov); g_puts("\n" as *u8)
66 let d2: i64 = wm_run(mod, "mv_render" as *u8, 0, 0, 0, 0, 0, 1)
67 let center2: i64 = fbp[CTR]
68 let cov2: i64 = cover(fbp)
69
70 var pass: i64=0; var t: i64=0
71 var t1: i64=0; if wm_find_export(mod, "mv_render" as *u8) >= 0 { t1=1 }
72 pass=pass+ck("T1: nx_meshview_wasm compiled to wasm + mv_render exported (sovereign chain, no Emscripten)" as *u8, t1); t=t+1
73 var t2: i64=0; if drawn==2 { t2=1 }
74 pass=pass+ck("T2: both triangles transformed+projected+drawn in the wasm VM (drawn==2)" as *u8, t2); t=t+1
75 var t3: i64=0; if cr==255 { if cb==0 { t3=1 } }
76 pass=pass+ck("T3 (z-correct in wasm): nearer RED wins overlap centre (R==255, B==0) -- matches native" as *u8, t3); t=t+1
77 var t4: i64=0; if cov>100 { t4=1 }
78 pass=pass+ck("T4 (non-vacuous): rendered coverage > 100 px in the wasm framebuffer" as *u8, t4); t=t+1
79 var t5: i64=0; if center2==center { if cov2==cov { t5=1 } }
80 pass=pass+ck("T5 (deterministic): identical wasm framebuffer across two mv_render calls" as *u8, t5); t=t+1
81
82 // ---- CAP-PBR: render the LIT CUBE in the wasm VM + measure shading variation ----
83 let cd: i64 = wm_run(mod, "mv_render_cube" as *u8, 35, 0, 0, 0, 0, 1)
84 var cubecov: i64=0; var rmin: i64=999; var rmax: i64=0; var ii: i64=0
85 while ii < MV_N { let px: i64=fbp[ii]; if px!=BG { cubecov=cubecov+1; let rr: i64=px%256; if rr<rmin {rmin=rr} if rr>rmax {rmax=rr} } ii=ii+1 }
86 let rrange: i64 = rmax - rmin
87 let cd2: i64 = wm_run(mod, "mv_render_cube" as *u8, 35, 0, 0, 0, 0, 1)
88 var cubecov2: i64=0; var jj: i64=0
89 while jj < MV_N { if fbp[jj]!=BG { cubecov2=cubecov2+1 } jj=jj+1 }
90 g_puts(" cube_drawn="); g_pn(cd); g_puts(" cube_cov="); g_pn(cubecov); g_puts(" R_min="); g_pn(rmin); g_puts(" R_max="); g_pn(rmax); g_puts(" R_range="); g_pn(rrange); g_puts("\n" as *u8)
91
92 var t6: i64=0; if cd>0 { if cubecov>100 { t6=1 } }
93 pass=pass+ck("T6: lit cube renders in the wasm VM (drawn>0, coverage>100)" as *u8, t6); t=t+1
94 var t7: i64=0; if cubecov2==cubecov { t7=1 }
95 pass=pass+ck("T7 (deterministic): identical cube coverage across two renders" as *u8, t7); t=t+1
96 var t8: i64=0; if rrange>30 { t8=1 }
97 pass=pass+ck("T8 (MEASURED shading): cube R-channel varies (lit faces brighter than shadowed) = Lambert live in render" as *u8, t8); t=t+1
98 var t9: i64=0; if cd<12 { if cd>=2 { if cubecov>400 { t9=1 } } }
99 pass=pass+ck("T9 (MEASURED cull): back-face culling drew <12 of 12 tris, coverage>400 (same image, ~half the raster work)" as *u8, t9); t=t+1
100
101 // ---- CAP-SKELETAL-ANIM visual: skinned cube bends -> the rendered IMAGE changes (pixel-diff straight vs bent) ----
102 let sd0: i64 = wm_run(mod, "mv_render_skincube" as *u8, 0, 0, 0, 0, 0, 1)
103 let snap: *i64 = sys_mmap(MV_N*8) as *i64
104 var sc0: i64=0; var q0: i64=0
105 while q0 < MV_N { snap[q0]=fbp[q0]; if fbp[q0]!=BG { sc0=sc0+1 } q0=q0+1 }
106 let sd1: i64 = wm_run(mod, "mv_render_skincube" as *u8, 30, 0, 0, 0, 0, 1) // frame 30 = max bend (50deg)
107 var diff: i64=0; var q1: i64=0
108 while q1 < MV_N { if fbp[q1]!=snap[q1] { diff=diff+1 } q1=q1+1 }
109 g_puts(" skincube_drawn="); g_pn(sd0); g_puts(" cov0="); g_pn(sc0); g_puts(" pixels_changed_straight_vs_bent="); g_pn(diff); g_puts("\n" as *u8)
110 var t10: i64=0; if sd0>0 { if sc0>100 { t10=1 } }
111 pass=pass+ck("T10: skinned cube renders in the wasm VM (drawn>0, coverage>100)" as *u8, t10); t=t+1
112 var t11: i64=0; if diff>50 { t11=1 }
113 pass=pass+ck("T11 (MEASURED deform): bending the joint changes >50 rendered pixels (straight vs bent) = skinning live in the render" as *u8, t11); t=t+1
114
115 // ---- CAP-SKELETAL-ANIM rung-2: the bending cube LIT from its SKINNED normals (lighting tracks deformation) ----
116 let ld0: i64 = wm_run(mod, "mv_render_skincube_lit" as *u8, 0, 0, 0, 0, 0, 1)
117 let lsnap: *i64 = sys_mmap(MV_N*8) as *i64
118 var lcov: i64=0; var lsum: i64=0; var r0: i64=0
119 while r0 < MV_N { let px: i64=fbp[r0]; lsnap[r0]=px; if px!=BG { lcov=lcov+1; lsum=lsum + (px%256) + ((px/256)%256) + ((px/65536)%256) } r0=r0+1 }
120 let fd0: i64 = wm_run(mod, "mv_render_skincube" as *u8, 0, 0, 0, 0, 0, 1) // flat at the SAME pose -> same geometry, only shading differs
121 var fsum: i64=0; var ldiff: i64=0; var r1: i64=0
122 while r1 < MV_N { let px: i64=fbp[r1]; if px!=BG { fsum=fsum + (px%256) + ((px/256)%256) + ((px/65536)%256) } if px!=lsnap[r1] { ldiff=ldiff+1 } r1=r1+1 }
123 let ld1: i64 = wm_run(mod, "mv_render_skincube_lit" as *u8, 0, 0, 0, 0, 0, 1)
124 var lcov2: i64=0; var r2: i64=0
125 while r2 < MV_N { if fbp[r2]!=BG { lcov2=lcov2+1 } r2=r2+1 }
126 g_puts(" litcube_drawn="); g_pn(ld0); g_puts(" lit_cov="); g_pn(lcov); g_puts(" lit_bright="); g_pn(lsum); g_puts(" flat_bright="); g_pn(fsum); g_puts(" lit_vs_flat_px="); g_pn(ldiff); g_puts("\n" as *u8)
127 var t12: i64=0; if ld0>0 { if lcov>100 { if lcov2==lcov { t12=1 } } }
128 pass=pass+ck("T12: lit skinned cube renders in the wasm VM (drawn>0, coverage>100, deterministic)" as *u8, t12); t=t+1
129 var t13: i64=0; if ldiff>50 { if lsum<fsum { t13=1 } }
130 pass=pass+ck("T13 (MEASURED lighting): lit skincube differs from flat at the SAME pose (>50 px) AND is DARKER overall (Lambert+ambient attenuates) = skinned-normal lighting LIVE in the render" as *u8, t13); t=t+1
131
132 // ---- CAP-PBR rung-2: the lit cube + Blinn-Phong SPECULAR -> glossy; specular ADDS a highlight over diffuse ----
133 let pd0: i64 = wm_run(mod, "mv_render_skincube_spec" as *u8, 0, 0, 0, 0, 0, 1)
134 var pcov: i64=0; var spbrighter: i64=0; var pmax: i64=0; var u0: i64=0
135 while u0 < MV_N { let px: i64=fbp[u0]; if px!=BG { pcov=pcov+1; let pbri: i64=(px%256)+((px/256)%256)+((px/65536)%256); let lbri: i64=(lsnap[u0]%256)+((lsnap[u0]/256)%256)+((lsnap[u0]/65536)%256); if pbri>lbri { spbrighter=spbrighter+1 } if pbri>pmax { pmax=pbri } } u0=u0+1 }
136 let pd1: i64 = wm_run(mod, "mv_render_skincube_spec" as *u8, 0, 0, 0, 0, 0, 1)
137 var pcov2: i64=0; var u1: i64=0
138 while u1 < MV_N { if fbp[u1]!=BG { pcov2=pcov2+1 } u1=u1+1 }
139 g_puts(" speccube_drawn="); g_pn(pd0); g_puts(" spec_cov="); g_pn(pcov); g_puts(" px_brighter_than_lit="); g_pn(spbrighter); g_puts(" max_bright="); g_pn(pmax); g_puts("\n" as *u8)
140 var t14: i64=0; if pd0>0 { if pcov>100 { if pcov2==pcov { t14=1 } } }
141 pass=pass+ck("T14: glossy (lit+specular) skinned cube renders in the wasm VM (drawn>0, coverage>100, deterministic)" as *u8, t14); t=t+1
142 var t15: i64=0; if spbrighter>30 { t15=1 }
143 pass=pass+ck("T15 (MEASURED specular): >30 px are BRIGHTER than the diffuse-only cube at the same pose (the Blinn-Phong highlight is live)" as *u8, t15); t=t+1
144
145 // ---- CAP-PBR rung-3: smooth Gouraud sphere vs flat-shaded sphere (gradient continuum vs few facet levels) ----
146 let hist: *i64 = sys_mmap(64*8) as *i64
147 let qd0: i64 = wm_run(mod, "mv_render_sphere" as *u8, 60, 0, 0, 0, 0, 1)
148 var hz0: i64=0; while hz0<64 { hist[hz0]=0; hz0=hz0+1 }
149 var scov: i64=0; var sj: i64=0
150 while sj < MV_N { let px: i64=fbp[sj]; if px!=BG { scov=scov+1; let bri: i64=(px%256)+((px/256)%256)+((px/65536)%256); var bin: i64=bri/12; if bin>63 { bin=63 } hist[bin]=hist[bin]+1 } sj=sj+1 }
151 var smooth_bins: i64=0; var sb: i64=0; while sb<64 { if hist[sb]>0 { smooth_bins=smooth_bins+1 } sb=sb+1 }
152 let qd1: i64 = wm_run(mod, "mv_render_sphere_flat" as *u8, 60, 0, 0, 0, 0, 1)
153 var hz1: i64=0; while hz1<64 { hist[hz1]=0; hz1=hz1+1 }
154 var fcov: i64=0; var fj: i64=0
155 while fj < MV_N { let px: i64=fbp[fj]; if px!=BG { fcov=fcov+1; let bri: i64=(px%256)+((px/256)%256)+((px/65536)%256); var bin: i64=bri/12; if bin>63 { bin=63 } hist[bin]=hist[bin]+1 } fj=fj+1 }
156 var flat_bins: i64=0; var fb2: i64=0; while fb2<64 { if hist[fb2]>0 { flat_bins=flat_bins+1 } fb2=fb2+1 }
157 g_puts(" sphere_drawn="); g_pn(qd0); g_puts(" smooth_cov="); g_pn(scov); g_puts(" smooth_bins="); g_pn(smooth_bins); g_puts(" flat_bins="); g_pn(flat_bins); g_puts("\n" as *u8)
158 var t16: i64=0; if qd0>0 { if scov>200 { t16=1 } }
159 pass=pass+ck("T16: smooth Gouraud sphere renders in the wasm VM (drawn>0, coverage>200)" as *u8, t16); t=t+1
160 var t17: i64=0; if smooth_bins>flat_bins { if smooth_bins>20 { t17=1 } }
161 pass=pass+ck("T17 (MEASURED smooth): the Gouraud sphere has MANY more distinct brightness levels than the flat-shaded same sphere = per-vertex interpolation = no facets" as *u8, t17); t=t+1
162
163 // ---- CAP-PBR rung-4: true PHONG (per-pixel normal) vs Gouraud (per-vertex colour) at the SAME pose ----
164 let gd: i64 = wm_run(mod, "mv_render_sphere" as *u8, 45, 0, 0, 0, 0, 1)
165 let gsnap: *i64 = sys_mmap(MV_N*8) as *i64
166 var gmax: i64=0; var gq: i64=0
167 while gq < MV_N { let px: i64=fbp[gq]; gsnap[gq]=px; if px!=BG { let bri: i64=(px%256)+((px/256)%256)+((px/65536)%256); if bri>gmax { gmax=bri } } gq=gq+1 }
168 let phd: i64 = wm_run(mod, "mv_render_sphere_phong" as *u8, 45, 0, 0, 0, 0, 1)
169 var pmax: i64=0; var pcov: i64=0; var pdiff: i64=0; var pq: i64=0
170 while pq < MV_N { let px: i64=fbp[pq]; if px!=BG { pcov=pcov+1; let bri: i64=(px%256)+((px/256)%256)+((px/65536)%256); if bri>pmax { pmax=bri } } if px!=gsnap[pq] { pdiff=pdiff+1 } pq=pq+1 }
171 let phd2: i64 = wm_run(mod, "mv_render_sphere_phong" as *u8, 45, 0, 0, 0, 0, 1)
172 var pcov2: i64=0; var pr: i64=0
173 while pr < MV_N { if fbp[pr]!=BG { pcov2=pcov2+1 } pr=pr+1 }
174 g_puts(" phong_drawn="); g_pn(phd); g_puts(" phong_cov="); g_pn(pcov); g_puts(" phong_max="); g_pn(pmax); g_puts(" gouraud_max="); g_pn(gmax); g_puts(" phong_vs_gouraud_px="); g_pn(pdiff); g_puts("\n" as *u8)
175 var t18: i64=0; if phd>0 { if pcov>200 { if pcov2==pcov { t18=1 } } }
176 pass=pass+ck("T18: Phong sphere renders in the wasm VM (drawn>0, coverage>200, deterministic)" as *u8, t18); t=t+1
177 var t19: i64=0; if pdiff>50 { if pmax>=gmax { t19=1 } }
178 pass=pass+ck("T19 (MEASURED phong): per-pixel Phong differs from Gouraud (>50 px) AND its specular peak >= Gouraud's (computed at the true peak, not interpolated down between vertices)" as *u8, t19); t=t+1
179
180 // ---- CAP-PBR rung-5: bump-mapped sphere (per-pixel procedural normal perturbation) vs smooth Phong, same pose ----
181 let php: i64 = wm_run(mod, "mv_render_sphere_phong" as *u8, 45, 0, 0, 0, 0, 1)
182 let psnap: *i64 = sys_mmap(MV_N*8) as *i64
183 var nq: i64=0; while nq < MV_N { psnap[nq]=fbp[nq]; nq=nq+1 }
184 let nmd: i64 = wm_run(mod, "mv_render_sphere_nmap" as *u8, 45, 0, 0, 0, 0, 1)
185 var ncov: i64=0; var ndiff: i64=0; var nq2: i64=0
186 while nq2 < MV_N { let px: i64=fbp[nq2]; if px!=BG { ncov=ncov+1 } if px!=psnap[nq2] { ndiff=ndiff+1 } nq2=nq2+1 }
187 let nmd2: i64 = wm_run(mod, "mv_render_sphere_nmap" as *u8, 45, 0, 0, 0, 0, 1)
188 var ncov2: i64=0; var nq3: i64=0
189 while nq3 < MV_N { if fbp[nq3]!=BG { ncov2=ncov2+1 } nq3=nq3+1 }
190 g_puts(" nmap_drawn="); g_pn(nmd); g_puts(" nmap_cov="); g_pn(ncov); g_puts(" nmap_vs_phong_px="); g_pn(ndiff); g_puts("\n" as *u8)
191 var t20: i64=0; if nmd>0 { if ncov>200 { if ncov2==ncov { t20=1 } } }
192 pass=pass+ck("T20: bump-mapped sphere renders in the wasm VM (drawn>0, coverage>200, deterministic)" as *u8, t20); t=t+1
193 var t21: i64=0; if ndiff>100 { t21=1 }
194 pass=pass+ck("T21 (MEASURED bump): per-pixel normal perturbation reshapes the surface lighting on >100 px vs smooth Phong = procedural surface detail with NO extra geometry" as *u8, t21); t=t+1
195
196 // ---- R4: the GENERIC mesh renderer -- a TORUS (genus-1, different topology) via mv_render_mesh; the sphere
197 // T16/T17 PASSING ABOVE already prove the generic renderer reproduces the sphere exactly. ----
198 let trd: i64 = wm_run(mod, "mv_render_torus" as *u8, 30, 0, 0, 0, 0, 1)
199 var trcov: i64=0; var trj: i64=0
200 while trj < MV_N { if fbp[trj]!=BG { trcov=trcov+1 } trj=trj+1 }
201 let trd2: i64 = wm_run(mod, "mv_render_torus" as *u8, 30, 0, 0, 0, 0, 1)
202 var trcov2: i64=0; var trj2: i64=0
203 while trj2 < MV_N { if fbp[trj2]!=BG { trcov2=trcov2+1 } trj2=trj2+1 }
204 g_puts(" torus_drawn="); g_pn(trd); g_puts(" torus_cov="); g_pn(trcov); g_puts("\n" as *u8)
205 var t22: i64=0; if trd>0 { if trcov>40 { if trcov2==trcov { t22=1 } } }
206 pass=pass+ck("T22 (R4 generic renderer): a TORUS renders via mv_render_mesh (drawn>0, coverage>40, deterministic) -- the SAME renderer the sphere routes through = an arbitrary loaded mesh renders" as *u8, t22); t=t+1
207
208 // ---- R4 rung-2: the EXTERNAL-LOAD path -- write an octahedron into the generic mesh buffers (exactly as the
209 // page's JS does at mv_meshv_off/n_off/i_off) then mv_render_loaded. Proves the in-browser STL-load path headless. ----
210 let lv: *i64 = (mod.mem as i64 + 83616) as *i64 // O_MVV
211 let ln: *i64 = (mod.mem as i64 + 89760) as *i64 // O_MVN
212 let li: *i64 = (mod.mem as i64 + 106144) as *i64 // O_MVI
213 lv[0]=8192; lv[1]=0; lv[2]=0; lv[3]=0-8192; lv[4]=0; lv[5]=0; lv[6]=0; lv[7]=8192; lv[8]=0; lv[9]=0; lv[10]=0-8192; lv[11]=0; lv[12]=0; lv[13]=0; lv[14]=8192; lv[15]=0; lv[16]=0; lv[17]=0-8192
214 ln[0]=16384; ln[1]=0; ln[2]=0; ln[3]=0-16384; ln[4]=0; ln[5]=0; ln[6]=0; ln[7]=16384; ln[8]=0; ln[9]=0; ln[10]=0-16384; ln[11]=0; ln[12]=0; ln[13]=0; ln[14]=16384; ln[15]=0; ln[16]=0; ln[17]=0-16384
215 li[0]=0; li[1]=2; li[2]=4; li[3]=0; li[4]=4; li[5]=3; li[6]=0; li[7]=3; li[8]=5; li[9]=0; li[10]=5; li[11]=2; li[12]=1; li[13]=4; li[14]=2; li[15]=1; li[16]=3; li[17]=4; li[18]=1; li[19]=5; li[20]=3; li[21]=1; li[22]=2; li[23]=5
216 let lod: i64 = wm_run(mod, "mv_render_loaded" as *u8, 0, 6, 8, 0, 0, 3)
217 var locov: i64=0; var loq: i64=0
218 while loq < MV_N { if fbp[loq]!=BG { locov=locov+1 } loq=loq+1 }
219 let lod2: i64 = wm_run(mod, "mv_render_loaded" as *u8, 0, 6, 8, 0, 0, 3)
220 var locov2: i64=0; var loq2: i64=0
221 while loq2 < MV_N { if fbp[loq2]!=BG { locov2=locov2+1 } loq2=loq2+1 }
222 g_puts(" loaded_drawn="); g_pn(lod); g_puts(" loaded_cov="); g_pn(locov); g_puts("\n" as *u8)
223 var t23: i64=0; if lod>0 { if locov>40 { if locov2==locov { t23=1 } } }
224 pass=pass+ck("T23 (R4 external load): an octahedron WRITTEN into the generic buffers (as the page's JS does) renders via mv_render_loaded -- the in-browser STL-load path, proven headless + deterministic" as *u8, t23); t=t+1
225
226 // ---- Track-E rung-1: interactive ORBIT VIEWPORT -- camera yaw spins the object on screen; dist zooms ----
227 // (the octahedron is still in the generic buffers from T23). dist 65536 = 4.0 Q14 (near), 131072 = 8.0 (far).
228 let cam0: i64 = wm_run(mod, "mv_render_loaded_cam" as *u8, 0, 65536, 6, 8, 0, 4)
229 let csnap: *i64 = sys_mmap(MV_N*8) as *i64
230 var ccov: i64=0; var cq: i64=0
231 while cq < MV_N { csnap[cq]=fbp[cq]; if fbp[cq]!=BG { ccov=ccov+1 } cq=cq+1 }
232 let cam90: i64 = wm_run(mod, "mv_render_loaded_cam" as *u8, 45, 65536, 6, 8, 0, 4) // 45deg (NOT a 90deg symmetry of the octahedron)
233 var cdiff: i64=0; var c2: i64=0
234 while c2 < MV_N { if fbp[c2]!=csnap[c2] { cdiff=cdiff+1 } c2=c2+1 }
235 let camz: i64 = wm_run(mod, "mv_render_loaded_cam" as *u8, 0, 131072, 6, 8, 0, 4)
236 var zcov: i64=0; var zq: i64=0
237 while zq < MV_N { if fbp[zq]!=BG { zcov=zcov+1 } zq=zq+1 }
238 let cam0b: i64 = wm_run(mod, "mv_render_loaded_cam" as *u8, 0, 65536, 6, 8, 0, 4)
239 var ccov2: i64=0; var c3: i64=0
240 while c3 < MV_N { if fbp[c3]!=BG { ccov2=ccov2+1 } c3=c3+1 }
241 g_puts(" cam_cov="); g_pn(ccov); g_puts(" yaw0_vs_yaw45_px="); g_pn(cdiff); g_puts(" zoomout_cov="); g_pn(zcov); g_puts("\n" as *u8)
242 var t24: i64=0; if cam0>0 { if ccov>40 { if ccov2==ccov { t24=1 } } }
243 pass=pass+ck("T24 (orbit viewport): the loaded mesh renders through the camera-orbit path (drawn>0, coverage>40, deterministic)" as *u8, t24); t=t+1
244 var t25: i64=0; if cdiff>30 { if zcov<ccov { t25=1 } }
245 pass=pass+ck("T25 (MEASURED viewport): yaw SPINS the object on screen (yaw0 != yaw45 by >30 px) AND dist ZOOMS (far view covers fewer px) = a real orbit+zoom camera" as *u8, t25); t=t+1
246
247 var okall: i64=0; if pass==t { okall=1 }
248 g_puts("---- nx_meshview_wasm_gate: passed "); g_pn(pass); g_puts(" / "); g_pn(t); g_puts(" ----\n" as *u8)
249 if okall==1 {
250 let logf: i64=sys_openat_append("knowledge/status/meshview_wasm_gate.log" as *u8, 420)
251 if logf>=0 { let msg: *u8="MESHVIEW-WASM GREEN: general-mesh renderer compiled .nx->wasm (sovereign chain) + z-correct in nx_wasm_vm -- browser lane, no WebGL/NVIDIA/Emscripten\n" as *u8; var ml: i64=0; while msg[ml]!=(0 as u8){ml=ml+1} let z: i64=sys_write(logf,msg,ml); sys_close(logf) }
252 g_puts("verdict=GREEN (our arbitrary-mesh renderer runs in the browser lane via OUR wasm, z-correct -- the emit-not-3rd-party payoff)\n" as *u8); sys_exit(0); return 0
253 }
254 g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1
255}