code wiki / _hdl_build / nx_craft_style_gate.nx

nx_craft_style_gate.nx source

↩ module page · 255 lines · 13497 B

1// nx_craft_style_gate.nx -- THE REFEREE FOR "ART STYLE IS DATA" IN THE SERVED ENGINE (2026-09-01). 2// SUBJECT: the P_STYLE spec word (idx 49) in nx_wasm_craft.nx and its wshade2 dispatch. 3// WHAT IT PROVES, and the ORDER MATTERS: (1) the fixture REACHED the condition -- a real world was 4// generated, a non-blank frame rendered, and the style the engine reports back is the style that 5// was asked for -- BEFORE (2) any outcome about the frames is asserted. Asserting an outcome 6// without first asserting the fixture reached the condition is how four fixtures in one day passed 7// on cases the organ never examined. 8// WHY THIS IS NOT A DUPLICATE RULER: _hdl_build/nx_world_style_gate.nx proves the SAME doctrine 9// over nx_voxel_world -- a 320x240 library renderer with SEVEN importers, EVERY ONE OF THEM A GATE. 10// Its subject is a renderer nothing ships. The subject HERE is the engine that renders 11// nishifamily.com/world/*. The doctrine is the incumbent one; only the subject is new, and the 12// three style ids are deliberately identical so the two cannot drift into two vocabularies for one 13// idea. 14// ANTI-VACUITY IS THE POINT: "the frames differ" is passed by ANY implementation that perturbs 15// pixels, a broken one included. Two teeth here refuse that -- TOON must REDUCE tonal variety 16// (that IS banding) and FLAT must REDUCE local high-frequency detail (that IS untexturing). A 17// random perturbation raises both and dies on either. 18// license_tier: ORIGINAL No hw writes (Rule 26). 19import "nx_syscalls.nx" 20import "nx_gate_verdict.nx" 21import "nx_wasm_craft.nx" 22 23const CS_ARENA_SLACK: i64 = 4096 24const CS_SEED: i64 = 20260728 25const CS_IDENT_SHORE: i64 = 2 // the shore identity -- the operator review stage 26const CS_TICKS: i64 = 2 // enough to settle the first frame. This gate judges the 27 // SHADER, not the simulation, so more ticks buy nothing and 28 // cost rays. 29const CS_Q: i64 = 4 // ray pixel size. NOT a quality choice and NOT tuned: every 30 // tooth below is a COMPARISON between frames taken at the 31 // SAME q, so q cancels out of every claim and its only effect 32 // is run time. wc_q clamps to 1..Q_MAX regardless. 33const CS_HIST_BITS: i64 = 4 // colour bucket = top 4 bits per channel -> 4096 buckets. 34 // Fixed 32 KB whatever the frame size, which is what lets ONE 35 // instrument read every style with no per-style constant. 36const CS_HIST_N: i64 = 4096 37const CS_HIST_GS: i64 = 16 38const CS_HIST_RS: i64 = 256 39const CS_RGB24: i64 = 16777215 // the colour bits of a framebuffer word. The high bits carry 40 // the depth plane (FB_DEPTH_SHIFT), so a comparison that did 41 // not mask would be judging depth, not the look. 42const CS_BAD_STYLE: i64 = 7 // an id the engine does not own -- the neg-control input 43const CS_LUMA_R: i64 = 77 // Rec.601 luma in 1/256 units: 0.299/0.587/0.114 times 256 44const CS_LUMA_G: i64 = 150 45const CS_LUMA_B: i64 = 29 46const CS_LUMA_SH: i64 = 8 47const CS_PERMIL: i64 = 1000 48const CS_FNV_BASIS: i64 = 1469598103 49const CS_FNV_MUL: i64 = 31 50const CS_FNV_MOD: i64 = 1000000007 51const CS_TICK_MS: i64 = 16 52 53func cs_luma(px: i64) -> i64 { 54 let r: i64 = px & 255 55 let g: i64 = (px >> 8) & 255 56 let b: i64 = (px >> 16) & 255 57 return (r*CS_LUMA_R + g*CS_LUMA_G + b*CS_LUMA_B) >> CS_LUMA_SH 58} 59// Frame digest over the WRITTEN extent only. wc_rw/wc_rh are the engine own owners of that extent: 60// a consumer that assumes W*H reads unwritten memory and calls it a measurement. 61func cs_hash(fb: *i64, n: i64) -> i64 { 62 var h: i64 = CS_FNV_BASIS 63 var i: i64 = 0 64 while i < n { h = (h*CS_FNV_MUL + (fb[i] & CS_RGB24)) % CS_FNV_MOD; i = i + 1 } 65 return h 66} 67func cs_copy(dst: *i64, fb: *i64, n: i64) -> i64 { 68 var i: i64 = 0 69 while i < n { dst[i] = fb[i]; i = i + 1 } 70 return 0 71} 72func cs_same(a: *i64, b: *i64, n: i64) -> i64 { 73 var i: i64 = 0 74 while i < n { if (a[i] & CS_RGB24) != (b[i] & CS_RGB24) { return 0 } i = i + 1 } 75 return 1 76} 77// TONAL VARIETY: how many distinct coarse colours the frame uses. Banding COLLAPSES this; a random 78// perturbation INFLATES it. That asymmetry is why this is the anti-vacuity tooth, not "differs". 79func cs_distinct(fb: *i64, n: i64, hist: *i64) -> i64 { 80 var i: i64 = 0 81 while i < CS_HIST_N { hist[i] = 0; i = i + 1 } 82 i = 0 83 while i < n { 84 let px: i64 = fb[i] 85 let r: i64 = (px & 255) >> CS_HIST_BITS 86 let g: i64 = ((px >> 8) & 255) >> CS_HIST_BITS 87 let b: i64 = ((px >> 16) & 255) >> CS_HIST_BITS 88 hist[r*CS_HIST_RS + g*CS_HIST_GS + b] = 1 89 i = i + 1 90 } 91 var c: i64 = 0 92 i = 0 93 while i < CS_HIST_N { if hist[i] == 1 { c = c + 1 } i = i + 1 } 94 return c 95} 96// LOCAL HIGH-FREQUENCY ENERGY: mean absolute horizontal luma step, times 1000 so the comparison is 97// integer and scale-free. The procedural texel noise lives exactly here, which is why removing it 98// MUST lower this number, and why "the frame changed" cannot substitute for it. 99func cs_detail(fb: *i64, w: i64, h: i64) -> i64 { 100 var acc: i64 = 0 101 var cnt: i64 = 0 102 var y: i64 = 0 103 while y < h { 104 var x: i64 = 1 105 while x < w { 106 let a: i64 = cs_luma(fb[y*w + x]) 107 let b: i64 = cs_luma(fb[y*w + x - 1]) 108 var d: i64 = a - b 109 if d < 0 { d = 0 - d } 110 acc = acc + d 111 cnt = cnt + 1 112 x = x + 1 113 } 114 y = y + 1 115 } 116 if cnt == 0 { return 0 - 1 } 117 return acc*CS_PERMIL/cnt 118} 119func cs_nonsky(fb: *i64, n: i64, sky: i64) -> i64 { 120 var c: i64 = 0 121 var i: i64 = 0 122 while i < n { if (fb[i] & CS_RGB24) != (sky & CS_RGB24) { c = c + 1 } i = i + 1 } 123 return c 124} 125// ONE RENDER, at a PINNED q, so every frame this gate compares was taken under identical sampling. 126// render_impl reads wc_q on EVERY call, so the pin is re-applied per render: an adaptive retune 127// would otherwise silently change the subject between two captures the gate believes comparable. 128func cs_render(base: i64) -> i64 { 129 // BIND THE POINTER, THEN INDEX. Writing an indexed assignment straight onto a CALL result is a 130 // PARSE ERROR in this dialect and nx_cc said so on the first build, naming the line and the 131 // reason. Recorded rather than silently fixed because the same shape appeared four times here 132 // and once in the engine style writer -- and because the first repair attempt failed on its own 133 // comment, which quoted the offending form and so re-armed the very pattern it was explaining. 134 let sq9: *i64 = wst(base) 135 sq9[S_Q] = CS_Q 136 render_impl(base) 137 return 0 138} 139 140func main() -> i64 { 141 let ctr: *i64 = gv_ctr() 142 gv_head("nx_craft_style_gate -- ART STYLE IS DATA in the SERVED engine (P_STYLE idx 49)" as *u8) 143 144 let base: i64 = sys_mmap(CRAFT_TOTAL + CS_ARENA_SLACK) as i64 145 init_impl_v(base, CS_IDENT_SHORE, CS_SEED) 146 var t: i64 = 0 147 while t < CS_TICKS { tick_impl(base, CS_TICK_MS); t = t + 1 } 148 149 let sq0: *i64 = wst(base) 150 sq0[S_Q] = CS_Q 151 let rw: i64 = wc_rw(base) 152 let rh: i64 = wc_rh(base) 153 let n: i64 = rw*rh 154 let fb: *i64 = wfb(base) 155 let hist: *i64 = sys_mmap(CS_HIST_N*8) as *i64 156 let fr_real: *i64 = sys_mmap(n*8 + CS_ARENA_SLACK) as *i64 157 let fr_toon: *i64 = sys_mmap(n*8 + CS_ARENA_SLACK) as *i64 158 let fr_flat: *i64 = sys_mmap(n*8 + CS_ARENA_SLACK) as *i64 159 let fr_bad: *i64 = sys_mmap(n*8 + CS_ARENA_SLACK) as *i64 160 161 // ---- FIXTURE FIRST. Nothing below is evidence about the shader unless these hold. ---- 162 let style0: i64 = wc_style_i(base) 163 cs_render(base) 164 cs_copy(fr_real, fb, n) 165 let sky: i64 = wsky(base, rh/2) 166 let ns_real: i64 = cs_nonsky(fr_real, n, sky) 167 let d_real: i64 = cs_distinct(fr_real, n, hist) 168 let x_real: i64 = cs_detail(fr_real, rw, rh) 169 170 var f1: i64 = 0 171 if n > 0 { if rw > 0 { if rh > 0 { f1 = 1 } } } 172 gv_check("T1 fixture-reached-extent-nonzero (wc_rw by wc_rh is a real frame, so no tooth below judges the empty set)" as *u8, f1, ctr) 173 var f2: i64 = 0 174 if ns_real > 0 { f2 = 1 } 175 gv_check("T2 fixture-reached-world-rendered (the REAL frame contains non-sky pixels -- a blank frame would pass every difference tooth below and prove nothing)" as *u8, f2, ctr) 176 var f3: i64 = 0 177 if style0 == WC_STYLE_REAL { f3 = 1 } 178 gv_check("T3 default-is-REAL-by-construction (the wc_spec zeroing loop already writes 0 to idx 49, so every world published before this renders unchanged with no preserved branch)" as *u8, f3, ctr) 179 180 // ---- TOON ---- 181 let set_t: i64 = wc_set_style_i(base, WC_STYLE_TOON) 182 let got_t: i64 = wc_style_i(base) 183 var f4: i64 = 0 184 if set_t == WC_STYLE_TOON { if got_t == WC_STYLE_TOON { f4 = 1 } } 185 gv_check("T4 fixture-reached-TOON (the writer returned the id it was given AND the reader hands the same id back -- the frame teeth below are about TOON only if this holds)" as *u8, f4, ctr) 186 cs_render(base) 187 cs_copy(fr_toon, fb, n) 188 let d_toon: i64 = cs_distinct(fr_toon, n, hist) 189 let x_toon: i64 = cs_detail(fr_toon, rw, rh) 190 var f5: i64 = 0 191 if cs_same(fr_real, fr_toon, n) == 0 { f5 = 1 } 192 gv_check("T5 TOON-changes-the-frame" as *u8, f5, ctr) 193 var f6: i64 = 0 194 if d_toon < d_real { f6 = 1 } 195 gv_check("T6 anti-vacuity-TOON-REDUCES-tonal-variety (banding COLLAPSES the distinct-colour count while any random perturbation INFLATES it, so this is the tooth a wrong implementation cannot pass)" as *u8, f6, ctr) 196 197 // ---- FLAT ---- 198 let set_f: i64 = wc_set_style_i(base, WC_STYLE_FLAT) 199 let got_f: i64 = wc_style_i(base) 200 var f7: i64 = 0 201 if set_f == WC_STYLE_FLAT { if got_f == WC_STYLE_FLAT { f7 = 1 } } 202 gv_check("T7 fixture-reached-FLAT (writer returned the id and the reader hands it back)" as *u8, f7, ctr) 203 cs_render(base) 204 cs_copy(fr_flat, fb, n) 205 let x_flat: i64 = cs_detail(fr_flat, rw, rh) 206 var f8: i64 = 0 207 if cs_same(fr_real, fr_flat, n) == 0 { f8 = 1 } 208 gv_check("T8 FLAT-changes-the-frame" as *u8, f8, ctr) 209 var f9: i64 = 0 210 if x_flat < x_real { f9 = 1 } 211 gv_check("T9 anti-vacuity-FLAT-REDUCES-local-detail (removing the procedural texel MUST lower the mean horizontal luma step; a frame that merely differs does not)" as *u8, f9, ctr) 212 var f10: i64 = 0 213 if cs_same(fr_toon, fr_flat, n) == 0 { f10 = 1 } 214 gv_check("T10 THREE-distinct-looks-not-two (TOON and FLAT differ from EACH OTHER, so the style word SELECTS AMONG styles rather than toggling one)" as *u8, f10, ctr) 215 216 // ---- NEGATIVE CONTROLS ---- 217 let refuse_hi: i64 = wc_set_style_i(base, CS_BAD_STYLE) 218 let refuse_lo: i64 = wc_set_style_i(base, 0 - 1) 219 let still: i64 = wc_style_i(base) 220 var f11: i64 = 0 221 if refuse_hi == (0 - 1) { if refuse_lo == (0 - 1) { if still == WC_STYLE_FLAT { f11 = 1 } } } 222 gv_check("neg-control-writer-REFUSES-unowned-id-and-leaves-state (set_style 7 and set_style -1 both return -1 and the style in force is unchanged -- clamping down to REAL would make asking for style 7 and asking for the shipped look the same observation)" as *u8, f11, ctr) 223 224 let spb: *i64 = wsp(base) 225 spb[P_STYLE] = CS_BAD_STYLE 226 cs_render(base) 227 cs_copy(fr_bad, fb, n) 228 var f12: i64 = 0 229 if cs_same(fr_real, fr_bad, n) == 1 { f12 = 1 } 230 gv_check("neg-control-unowned-id-in-the-plane-renders-REAL (a value poked PAST the door, as a recipe row or a hostile page can, falls through both style tests and reproduces the REAL frame EXACTLY -- the fail-safe direction, asserted not assumed)" as *u8, f12, ctr) 231 232 // ---- THE NO-OP CLAIM, MEASURED RATHER THAN ASSERTED ---- 233 let spr: *i64 = wsp(base) 234 spr[P_STYLE] = WC_STYLE_REAL 235 cs_render(base) 236 var f13: i64 = 0 237 if cs_same(fr_real, fb, n) == 1 { f13 = 1 } 238 gv_check("T13 style-0-round-trip-is-byte-identical (after visiting TOON, FLAT and a garbage id, returning to 0 reproduces the ORIGINAL frame exactly -- this IS the claim that every published world is unchanged, measured here rather than asserted in a comment)" as *u8, f13, ctr) 239 240 gv_puts("\n MEASURED extent=" as *u8); gv_num(rw); gv_puts("x" as *u8); gv_num(rh) 241 gv_puts(" nonsky_real=" as *u8); gv_num(ns_real) 242 gv_puts("\n MEASURED distinct_colours real=" as *u8); gv_num(d_real) 243 gv_puts(" toon=" as *u8); gv_num(d_toon) 244 gv_puts("\n MEASURED horiz_luma_step_x1000 real=" as *u8); gv_num(x_real) 245 gv_puts(" toon=" as *u8); gv_num(x_toon) 246 gv_puts(" flat=" as *u8); gv_num(x_flat) 247 gv_puts("\n MEASURED frame_hash real=" as *u8); gv_num(cs_hash(fr_real, n)) 248 gv_puts(" toon=" as *u8); gv_num(cs_hash(fr_toon, n)) 249 gv_puts(" flat=" as *u8); gv_num(cs_hash(fr_flat, n)) 250 gv_puts("\n SCOPE this gate judges the SHADING axis only. vox_off to O_VOX is still the only\n world door: a toon or flat world is a voxel world that stopped looking photoreal,\n NOT a world that stopped being cubes. REPRESENTATION is a separate contract.\n" as *u8) 251 252 let rc: i64 = gv_verdict("CRAFT-STYLE" as *u8, ctr, "P_STYLE selects three distinct looks in the served engine; style 0 is byte-identical; both the writer and the reader fail safe" as *u8) 253 sys_exit(rc) 254 return rc 255}