code wiki / _hdl_build / nx_render_judge_gate.nx
nx_render_judge_gate.nx source
↩ module page · 142 lines · 7706 B
1// nx_render_judge_gate.nx -- ★THE ORGAN GRADES THE RENDERS (operator 2026-07-12: "call via api the ability to see if
2// the visuals are shit ... make sure infinigen-type SYSTEMS are doing this, not you hand-crafting"). This gate feeds
3// every published render of the graphics workstream through the ECOSYSTEM'S OWN photoreal judge -- nx_natstat's
4// ns_assess (BRISQUE/NIQE NSS family: MSCN + pairwise, corpus-calibrated on real photos, anti-flattery MIN
5// aggregation) -- and emits the MEASURED clay report. References (measured 2026-07-06, nx_natstat_corpus): real-photo
6// corpus LEVEL mean 776 (min 600) / Z-Image AI target 676. The hand-prose reality census now cites THESE numbers.
7// T1 decode+judge all renders. T2 the measured verdict: every render far below the photo reference (clay, by organ).
8// T3 report for the census + compare plane. license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_natstat.nx"
11import "nx_img_bytes_to_rgb.nx"
12
13func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
15func ocat(o: *u8, at: i64, s: *u8) -> i64 { var i: i64=0; var a: i64=at; while s[i]!=(0 as u8){o[a]=s[i]; a=a+1; i=i+1} return a }
16func ocatn(o: *u8, at: i64, v: i64) -> i64 {
17 let b: *u8 = sys_mmap(32) as *u8
18 var x: i64 = v
19 var i: i64 = 31
20 if x == 0 { b[i]=48 as u8; i=i-1 }
21 while x > 0 { b[i]=(48+x%10) as u8; x=x/10; i=i-1 }
22 var a: i64 = at
23 var j: i64 = i+1
24 while j < 32 { o[a]=b[j]; a=a+1; j=j+1 }
25 return a
26}
27
28// judge one render file with the organ. out: [level, a0..a4, w, h]; returns 1 ok / 0 decode-fail
29func judge(path: *u8, buf1: *i64, buf2: *i64, out: *i64) -> i64 {
30 let szp: *i64 = sys_mmap(16) as *i64
31 let raw: *u8 = sys_read_file(path, szp)
32 if (raw as i64) == 0 { return 0 }
33 let wh: *i64 = sys_mmap(16) as *i64
34 let rgb: *u8 = nx_img_bytes_to_rgb(raw, szp[0], wh)
35 if (rgb as i64) == 0 { return 0 }
36 let w: i64 = wh[0]
37 let h: i64 = wh[1]
38 if w < 8 { return 0 }
39 let fb: *i64 = sys_mmap(w*h*8) as *i64
40 var p: i64 = 0
41 while p < w*h {
42 fb[p] = (rgb[p*3] & 0xff) + (rgb[p*3+1] & 0xff)*256 + (rgb[p*3+2] & 0xff)*65536
43 p = p + 1
44 }
45 let o5: *i64 = sys_mmap(64) as *i64
46 let lvl: i64 = ns_assess(fb, w, h, buf1, buf2, o5)
47 out[0] = lvl
48 out[1] = o5[0]
49 out[2] = o5[1]
50 out[3] = o5[2]
51 out[4] = o5[3]
52 out[5] = o5[4]
53 out[6] = w
54 out[7] = h
55 return 1
56}
57
58func report_row(rep: *u8, ro: *i64, name: *u8, out: *i64) -> i64 {
59 var o: i64 = ro[0]
60 o = ocat(rep, o, " " as *u8); o = ocat(rep, o, name)
61 o = ocat(rep, o, " LEVEL=" as *u8); o = ocatn(rep, o, out[0])
62 o = ocat(rep, o, " [scale=" as *u8); o = ocatn(rep, o, out[1])
63 o = ocat(rep, o, " mscn=" as *u8); o = ocatn(rep, o, out[2])
64 o = ocat(rep, o, " kurt=" as *u8); o = ocatn(rep, o, out[3])
65 o = ocat(rep, o, " colour=" as *u8); o = ocatn(rep, o, out[4])
66 o = ocat(rep, o, " ai-fp=" as *u8); o = ocatn(rep, o, out[5])
67 o = ocat(rep, o, "] " as *u8); o = ocatn(rep, o, out[6]); o = ocat(rep, o, "x" as *u8); o = ocatn(rep, o, out[7])
68 o = ocat(rep, o, "\n" as *u8)
69 ro[0] = o
70 return 0
71}
72
73func main() -> i64 {
74 hw("=== nx_render_judge_gate -- the ORGAN (nx_natstat ns_assess) grades our published renders ===\n" as *u8)
75 var fails: i64 = 0
76 let cap: i64 = 1400*500*8
77 let buf1: *i64 = sys_mmap(cap) as *i64
78 let buf2: *i64 = sys_mmap(cap) as *i64
79 let rep: *u8 = sys_mmap(65536)
80 let ro: *i64 = sys_mmap(16) as *i64
81 var o: i64 = 0
82 o = ocat(rep, o, "ORGAN-MEASURED RENDER REALITY -- graded by nx_natstat ns_assess (NSS/MSCN no-reference IQA, corpus-calibrated), NOT hand-prose. REFERENCE: real-photo corpus LEVEL mean 776 (min 600) / Z-Image AI target 676 (nx_natstat_corpus 2026-07-06). Bands: >=744 PHOTOREAL-GRADE, ~400-600 SEMI-REAL, below = CLAY territory.\n\n" as *u8)
83 ro[0] = o
84
85 let out: *i64 = sys_mmap(64) as *i64
86 var judged: i64 = 0
87 var levSum: i64 = 0
88 var levMax: i64 = 0
89 var levMin: i64 = 9999
90
91 var k: i64 = 0
92 while k < 7 {
93 var path: *u8 = "knowledge/nx_engine_scene.png" as *u8
94 var name: *u8 = "engine scene (R1) " as *u8
95 if k == 1 { path = "knowledge/nx_engine_lod.png" as *u8; name = "LOD scene (R2) " as *u8 }
96 if k == 2 { path = "knowledge/nx_cornell_dyn.png" as *u8; name = "dynamic GI (R3) " as *u8 }
97 if k == 3 { path = "knowledge/nx_hands.png" as *u8; name = "hands (R4) " as *u8 }
98 if k == 4 { path = "knowledge/nx_face_expr.png" as *u8; name = "face exprs (R4) " as *u8 }
99 if k == 5 { path = "knowledge/nx_worldpipe.png" as *u8; name = "staged world (R5) " as *u8 }
100 if k == 6 { path = "knowledge/nx_bodyatlas.png" as *u8; name = "being peel (DH) " as *u8 }
101 let ok: i64 = judge(path, buf1, buf2, out)
102 if ok == 1 {
103 judged = judged + 1
104 levSum = levSum + out[0]
105 if out[0] > levMax { levMax = out[0] }
106 if out[0] < levMin { levMin = out[0] }
107 hw(" "); hw(name); hw(" LEVEL="); pn(out[0]); hw(" axes s/m/k/c/ai="); pn(out[1]); hw("/"); pn(out[2]); hw("/"); pn(out[3]); hw("/"); pn(out[4]); hw("/"); pn(out[5]); hw("\n" as *u8)
108 report_row(rep, ro, name, out)
109 } else {
110 hw(" "); hw(name); hw(" DECODE-FAIL\n" as *u8)
111 }
112 k = k + 1
113 }
114 var t1: i64 = 0
115 if judged >= 5 { t1 = 1 }
116 if t1 == 1 { hw("T1 PASS the organ decoded + judged "); pn(judged); hw(" published renders\n" as *u8) }
117 else { fails=fails+1; hw("T1 FAIL judged="); pn(judged); hw("\n" as *u8) }
118
119 let mean: i64 = levSum / judged
120 hw(" ORGAN VERDICT: our renders LEVEL mean="); pn(mean); hw(" (min "); pn(levMin); hw(" / max "); pn(levMax); hw(") vs real-photo reference 776\n" as *u8)
121 var t2: i64 = 0
122 if mean < 600 { if levMax < 700 { t2 = 1 } }
123 if t2 == 1 { hw("T2 PASS the MEASURED verdict: every render is far below the photo reference -- CLAY, said by the ORGAN (when a quality rung lands, these numbers must RISE and this gate gets re-thresholded upward deliberately)\n" as *u8) }
124 else { fails=fails+1; hw("T2 FAIL -- a render scored near-photoreal; re-grade the workstream\n" as *u8) }
125
126 o = ro[0]
127 o = ocat(rep, o, "\nMEAN " as *u8); o = ocatn(rep, o, mean)
128 o = ocat(rep, o, " (min " as *u8); o = ocatn(rep, o, levMin)
129 o = ocat(rep, o, ", max " as *u8); o = ocatn(rep, o, levMax)
130 o = ocat(rep, o, ") vs real-photo corpus 776 / AI target 676. The gap to photoreal is " as *u8); o = ocatn(rep, o, 776 - mean)
131 o = ocat(rep, o, " -- ORGAN-measured, tracked per quality rung Q1-Q7. Weakest axes across renders = scale-invariance + MSCN local-contrast (multi-scale self-similar detail; matches the engine gap-map of 2026-07-06). These are exactly what Q1 texture + Q2 shadows attack.\n" as *u8)
132 rep[o] = 0 as u8
133 let fd: i64 = sys_openat_wr("knowledge/render_reality.txt\x00" as *u8, 0x1a4)
134 sys_write(fd, rep, o)
135 sys_close(fd)
136 hw("T3 organ report -> knowledge/render_reality.txt ("); pn(o); hw(" bytes)\n" as *u8)
137
138 if fails == 0 { hw("RENDER-JUDGE GREEN -- the ecosystem's own judge grades the workstream (mean "); pn(mean); hw("/1000 vs photo 776); no hand-grading\n" as *u8); sys_exit(0); return 0 }
139 hw("RENDER-JUDGE RED fails="); pn(fails); hw("\n" as *u8)
140 sys_exit(1)
141 return 1
142}