code wiki / (root) / nx_arousal_mesh_gate.nx

nx_arousal_mesh_gate.nx source

↩ module page · 145 lines · 8162 B

1// nx_arousal_mesh_gate.nx -- liar-killed GATE for arousal on a polygon mesh. 2// 3// TWO INDEPENDENT LAYERS, deliberately: 4// vr/vg = mean VERTEX colour -> proves the physiology was COMPUTED 5// fr/fg = mean RENDERED pixel -> proves it was actually DRAWN 6// These are different claims. The rasterizer discards per-vertex colour entirely at smooth<2 and 7// shades from the flat per-triangle colour instead -- silently, with no error. Under that bug the 8// vertex means stay perfectly correct while every frame renders identical. Only the framebuffer 9// teeth convict it, which is the same shape as an event marker not proving the event. 10// 11// Tooth total is DERIVED; G_MIN_TEETH is a floor so a deleted tooth trips RED. 12// usage: nx_arousal_mesh_gate [elf] exit 0 on all-pass. 13// license_tier: ORIGINAL expect_exit: 0 14import "nx_syscalls.nx" 15 16const G_OUTCAP: i64 = 16384 17const G_MIN_TEETH: i64 = 16 18 19func g_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 20func g_putn(v: i64) -> i64 { 21 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 22 var m: i64 = v 23 let d: *u8 = sys_mmap(24); var k: i64 = 0 24 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 25 let o: *u8 = sys_mmap(24); var w: i64 = 0 26 while w < k { o[w] = d[k-1-w]; w = w + 1 } 27 sys_write(1, o, k) 28 sys_munmap(d, 24); sys_munmap(o, 24) 29 return 0 30} 31func g_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 32func g_bool(name: *u8, got: i64, want: i64, passp: *i64) -> i64 { 33 passp[1] = passp[1] + 1 34 g_puts("T " as *u8); g_puts(name); g_puts(" got=" as *u8); g_putn(got) 35 if got == want { g_puts(" PASS\n" as *u8); passp[0] = passp[0] + 1 } else { g_puts(" FAIL\n" as *u8) } 36 return 0 37} 38func g_has(hay: *u8, hn: i64, needle: *u8) -> i64 { 39 let nl: i64 = g_slen(needle) 40 if nl == 0 { return 0 } 41 var i: i64 = 0 42 while i + nl <= hn { var k: i64 = 0; var ok: i64 = 1; while k < nl { if hay[i+k] != needle[k] { ok = 0; k = nl } k = k + 1 } if ok == 1 { return 1 } i = i + 1 } 43 return 0 44} 45func g_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8, out: *u8, cap: i64) -> i64 { 46 let pb: *i64 = sys_mmap(16) as *i64 47 sys_pipe2(pb, 0) 48 let rfd: i64 = pb[0] & 0xFFFFFFFF 49 let wfd: i64 = (pb[0] >> 32) & 0xFFFFFFFF 50 let pid: i64 = sys_fork() 51 if pid == 0 { 52 sys_dup3(wfd, 1, 0) 53 sys_close(rfd); sys_close(wfd) 54 let av: *i64 = sys_mmap(80) as *i64 55 av[0] = elf as i64 56 var ac: i64 = 1 57 if a1 as i64 != 0 { av[ac] = a1 as i64; ac = ac + 1 } 58 if a2 as i64 != 0 { av[ac] = a2 as i64; ac = ac + 1 } 59 if a3 as i64 != 0 { av[ac] = a3 as i64; ac = ac + 1 } 60 if a4 as i64 != 0 { av[ac] = a4 as i64; ac = ac + 1 } 61 if a5 as i64 != 0 { av[ac] = a5 as i64; ac = ac + 1 } 62 av[ac] = 0 63 sys_execve(elf, av, 0 as *i64) 64 sys_exit(127) 65 } 66 sys_close(wfd) 67 var tot: i64 = 0 68 var n: i64 = sys_read(rfd, out, cap - 1) 69 while n > 0 { tot = tot + n; if tot >= cap - 1 { n = 0 } else { n = sys_read(rfd, (out as i64 + tot) as *u8, cap - 1 - tot) } } 70 sys_close(rfd) 71 let st: *i64 = sys_mmap(16) as *i64 72 sys_wait4(pid, st, 0) 73 out[tot] = 0 as u8 74 return tot 75} 76 77// A DEFAULT THAT WORKS OFF THE AUTHOR'S MACHINE (2026-07-30). The default was the laptop build-output 78// path "_build/<name>.sov.elf"; on the NAS the cwd is nishihost, execve failed, the gate read EMPTY 79// output, and every tooth reported got=0 -- a RED indistinguishable from a real regression but actually 80// meaning SUBJECT NOT FOUND. Prefer the PROMOTED path when it exists, else fall back to the dev path, so 81// one file is correct on both machines. (8 such defaults exist across 6 gates in this lane.) 82func g_exists(pth: *u8) -> i64 { 83 let fd: i64 = sys_openat_rd(pth) 84 if fd < 0 { return 0 } 85 sys_close(fd) 86 return 1 87} 88func g_pick(promoted: *u8, devpath: *u8) -> *u8 { 89 if g_exists(promoted) == 1 { return promoted } 90 return devpath 91} 92func main(argc: i64, argv: *i64) -> i64 { 93 var elf: *u8 = g_pick("nx_arousal_mesh.elf" as *u8, "_build/nx_arousal_mesh.sov.elf" as *u8) 94 if argc >= 2 { elf = argv[1] as *u8 } 95 let pass: *i64 = sys_mmap(16) as *i64 96 pass[0] = 0 97 pass[1] = 0 98 let out: *u8 = sys_mmap(G_OUTCAP) 99 var n: i64 = 0 100 101 // ---- polygonization is stable ------------------------------------------------------------- 102 n = g_run(elf, "_scratch/mg_a.png" as *u8, "1" as *u8, "900" as *u8, "200" as *u8, 0 as *u8, out, G_OUTCAP) 103 g_bool("polygonizes-34196-tris" as *u8, g_has(out, n, "tris=34196" as *u8), 1, pass) 104 g_bool("polygonizes-17094-verts" as *u8, g_has(out, n, "verts=17094" as *u8), 1, pass) 105 106 // ---- LAYER 1: physiology COMPUTED onto vertices -------------------------------------------- 107 g_bool("vertex-baseline-pale-236-207" as *u8, g_has(out, n, "vr0=236 vg0=207" as *u8), 1, pass) 108 g_bool("vertex-flushed-218-118" as *u8, g_has(out, n, "vr2=218 vg2=118" as *u8), 1, pass) 109 // NEG: a constant-colour path would emit the baseline green at the flushed frame too 110 g_bool("NEG-vertex-colour-is-not-constant" as *u8, g_has(out, n, "vg2=207" as *u8), 0, pass) 111 112 // ---- LAYER 2: physiology actually RENDERED (framebuffer readback) -------------------------- 113 g_bool("rendered-baseline-179-159" as *u8, g_has(out, n, "fr0=179 fg0=159" as *u8), 1, pass) 114 g_bool("rendered-flushed-167-94" as *u8, g_has(out, n, "fr2=167 fg2=94" as *u8), 1, pass) 115 // ★THE TOOTH THAT CATCHES smooth<2: under that bug every frame renders the SAME flat colour, 116 // so the flushed frame would report the baseline green. Vertex teeth stay green; this one does not. 117 g_bool("NEG-render-did-not-discard-vertex-colour" as *u8, g_has(out, n, "fg2=159" as *u8), 0, pass) 118 // SORET ON THE RENDER: R barely moves (179->167) while G collapses (159->94) 119 g_bool("soret-red-holds-on-render" as *u8, g_has(out, n, "fr2=167" as *u8), 1, pass) 120 121 // ---- tessellation: geometry follows cell size, colour does NOT ----------------------------- 122 n = g_run(elf, "_scratch/mg_b.png" as *u8, "1" as *u8, "900" as *u8, "200" as *u8, "40" as *u8, out, G_OUTCAP) 123 g_bool("coarser-cell-14366-tris" as *u8, g_has(out, n, "tris=14366" as *u8), 1, pass) 124 g_bool("NEG-cell-size-actually-changes-mesh" as *u8, g_has(out, n, "tris=34196" as *u8), 0, pass) 125 // colour depends on perfusion and POSITION, not on tessellation density 126 g_bool("colour-is-tessellation-independent" as *u8, g_has(out, n, "vr0=236 vg0=207" as *u8), 1, pass) 127 128 // ---- refusals ------------------------------------------------------------------------------ 129 n = g_run(elf, "_scratch/mg_c.png" as *u8, "1" as *u8, "0" as *u8, "200" as *u8, 0 as *u8, out, G_OUTCAP) 130 g_bool("refuses-nonpositive-drive" as *u8, g_has(out, n, "REFUSED reason=nonpositive_drive" as *u8), 1, pass) 131 n = g_run(elf, "_scratch/mg_c.png" as *u8, "1" as *u8, "5000" as *u8, "200" as *u8, 0 as *u8, out, G_OUTCAP) 132 g_bool("refuses-drive-over-permil" as *u8, g_has(out, n, "REFUSED reason=drive_over_permil" as *u8), 1, pass) 133 n = g_run(elf, "_scratch/mg_c.png" as *u8, "1" as *u8, "900" as *u8, "5000" as *u8, 0 as *u8, out, G_OUTCAP) 134 g_bool("refuses-melanin-out-of-range" as *u8, g_has(out, n, "REFUSED reason=melanin_out_of_range" as *u8), 1, pass) 135 n = g_run(elf, "_scratch/mg_c.png" as *u8, "1" as *u8, "900" as *u8, "200" as *u8, "4" as *u8, out, G_OUTCAP) 136 g_bool("refuses-cell-too-fine" as *u8, g_has(out, n, "REFUSED reason=cell_too_fine" as *u8), 1, pass) 137 n = g_run(elf, "_scratch/mg_c.png" as *u8, "1" as *u8, "900" as *u8, "200" as *u8, "500" as *u8, out, G_OUTCAP) 138 g_bool("refuses-cell-too-coarse" as *u8, g_has(out, n, "REFUSED reason=cell_too_coarse" as *u8), 1, pass) 139 140 g_puts("AROUSAL-MESH-GATE pass=" as *u8); g_putn(pass[0]); g_puts("/" as *u8); g_putn(pass[1]); g_puts(" verdict=" as *u8) 141 if pass[1] < G_MIN_TEETH { g_puts("RED reason=teeth_deleted\n" as *u8); return 1 } 142 if pass[0] == pass[1] { g_puts("GREEN\n" as *u8); return 0 } 143 g_puts("RED\n" as *u8) 144 return 1 145}