code wiki / (root) / nx_tissuebudget.nx

nx_tissuebudget.nx source

↩ module page · 164 lines · 8608 B

1// nx_tissuebudget.nx -- WHAT THE TISSUE TICK ACTUALLY COSTS, AGAINST THE BUDGET THAT WAS ALREADY BANKED. 2// 3// WHY THIS EXISTS. knowledge/gamefeel_oracle.conf has carried frame_budget_ms_90hz 11..12 and js_block_ms 4// 0..2 since the realism-oracles sweep, both cited to vendor VR performance guidance -- and NOTHING HAS EVER 5// MEASURED OURS AGAINST EITHER. The board says it plainly: a real-time claim with no measured frame cost is 6// a wish. This organ is the measurement, and it REFUSES rather than reporting a number nobody acts on. 7// 8// THE SUBJECT IS THE RUNTIME SPRING, NOT THE XPBD CAGE. sb_tick_mob_gene is what runs every frame for every 9// girl in the browser; nx_softtissue's tet solver runs OFFLINE to identify the plant and never ships in the 10// frame loop. Measuring the cage here would price a cost the visitor never pays, which is the measured-a- 11// different-subject defect. The work unit is therefore ONE CAST TICK: TB_MOBS mobs x SB_PTS spring points. 12// 13// THIS NUMBER IS A FLOOR AND IS LABELLED ONE. It is native x86 on the estate host. The shipped path is 14// WebAssembly in a visitor's browser, which is slower, on hardware that is very likely weaker. A floor is 15// still decisive in one direction: if the FLOOR already misses the budget the browser cannot make it, and 16// that is a refusal you can act on. It can never prove the browser fits, and this file does not claim it. 17// 18// THE SAMPLE SIZE IS DERIVED FROM THE CLOCK, NOT CHOSEN. sys_clock_now_us resolves to 1 us, so a total 19// elapsed of T us carries ~1/T relative error on the per-tick figure. To resolve one part in 20// TB_RESOLVE_PERMIL the run must last at least TB_RESOLVE_PERMIL microseconds, so the loop DOUBLES its tick 21// count until it does. Below that it ABSTAINS instead of dividing a 0 into a per-tick cost of 0 -- the same 22// instrument-resolution trap nx_replyreserve refuses on the reply phase, where "0 ms" meant "under 1 ms". 23// license_tier: ORIGINAL No hw writes (Rule 26). 24import "nx_syscalls.nx" 25import "nx_softbind.nx" 26import "nx_frame_budget.nx" 27import "nx_oracleband_lib.nx" 28import "nx_gate_verdict.nx" 29 30const TB_CONF: *u8 = "knowledge/gamefeel_oracle.conf\x00" 31const TB_MOBS: i64 = 16 // the shipped cast: nx_wasm_craft MOB_CAP 32const TB_FPS_VR: i64 = 90 // the rate frame_budget_ms_90hz is cited at 33const TB_RESOLVE_PERMIL: i64 = 1000 // resolve the per-tick figure to one part in this many 34const TB_TICKS0: i64 = 1024 // first attempt; DOUBLED until the run resolves 35const TB_TICKS_CAP: i64 = 4194304 // refuse to spin forever: announced, never silent 36const TB_WARM: i64 = 256 // seat + settle before timing, so page-in is not in the sample 37const TB_MS_US: i64 = 1000 38const TB_GENE0: i64 = 305419896 // one fixed genome; the cost is per-point and genome-independent, 39 // and a fixed one keeps the measurement reproducible run to run 40 41// One cast tick: every mob's hair, chest and skirt advanced once. This is the unit the budget is spent in. 42func tb_one_tick(st: *i64, t: i64) -> i64 { 43 var k: i64 = 0 44 while k < TB_MOBS { 45 sb_tick_mob_gene(st, k, t % 64, 12 + (t % 3), t % 32, TB_GENE0 + k) 46 k = k + 1 47 } 48 return 0 49} 50 51// Returns elapsed microseconds for `ticks` cast ticks. Warm-up is OUTSIDE the timed region. 52func tb_run(ticks: i64) -> i64 { 53 let st: *i64 = sb_alloc(TB_MOBS) 54 var k: i64 = 0 55 while k < TB_MOBS { sb_seat_mob(st, k, 0, 12, 0); k = k + 1 } 56 var w: i64 = 0 57 while w < TB_WARM { tb_one_tick(st, w); w = w + 1 } 58 let t0: i64 = sys_clock_now_us() 59 var i: i64 = 0 60 while i < ticks { tb_one_tick(st, i); i = i + 1 } 61 let t1: i64 = sys_clock_now_us() 62 return t1 - t0 63} 64 65// Measure until the run is long enough to resolve, doubling. out[0]=ticks out[1]=elapsed_us. 66// Returns 1 = resolved, 0 = hit the cap without resolving (ABSTAIN, never a fabricated 0). 67func tb_measure(out: *i64) -> i64 { 68 var ticks: i64 = TB_TICKS0 69 while ticks <= TB_TICKS_CAP { 70 let el: i64 = tb_run(ticks) 71 out[0] = ticks 72 out[1] = el 73 if el >= TB_RESOLVE_PERMIL { return 1 } 74 ticks = ticks * 2 75 } 76 return 0 77} 78 79// per-cast-tick cost in NANOseconds -- microseconds would truncate a sub-microsecond tick to 0, which is the 80// instrument artifact this organ exists to avoid reporting. 81func tb_ns_per_tick(elapsed_us: i64, ticks: i64) -> i64 { return elapsed_us*1000/ticks } 82 83func main() -> i64 { 84 let ctr: *i64 = gv_ctr() 85 gv_head("nx_tissuebudget -- the per-frame tissue cost against the BANKED 90 Hz budget" as *u8) 86 87 let nrows: i64 = ob_load(TB_CONF as *u8) 88 var tableok: i64 = 0 89 if nrows > 0 { tableok = 1 } 90 gv_check("oracle table readable (the budget is CITED data, never a number in this file)" as *u8, tableok, ctr) 91 if tableok == 0 { 92 let rcx0: i64 = gv_verdict("TISSUE-BUDGET" as *u8, ctr, "no oracle table" as *u8) 93 sys_exit(rcx0) 94 return rcx0 95 } 96 97 let out: *i64 = sys_mmap(4*8) as *i64 98 let resolved: i64 = tb_measure(out) 99 gv_puts(" ticks=" as *u8); gv_num(out[0]) 100 gv_puts(" elapsed_us=" as *u8); gv_num(out[1]) 101 gv_puts(" resolve_floor_us=" as *u8); gv_num(TB_RESOLVE_PERMIL); gv_puts("\n" as *u8) 102 gv_check("measurement RESOLVED (ran long enough that 1 us of clock error is under one part in a thousand)" as *u8, resolved, ctr) 103 if resolved == 0 { 104 gv_puts(" ABSTAINING: the run never reached the resolve floor inside the announced tick cap.\n" as *u8) 105 let rcx1: i64 = gv_verdict("TISSUE-BUDGET" as *u8, ctr, "unresolved -- no number is published" as *u8) 106 sys_exit(rcx1) 107 return rcx1 108 } 109 110 let ns: i64 = tb_ns_per_tick(out[1], out[0]) 111 let us_frame: i64 = ns/1000 112 gv_puts(" cast=" as *u8); gv_num(TB_MOBS) 113 gv_puts(" mobs per-cast-tick=" as *u8); gv_num(ns) 114 gv_puts(" ns (=" as *u8); gv_num(us_frame) 115 gv_puts(" us per frame, a NATIVE FLOOR -- the browser is slower)\n" as *u8) 116 117 // The VR frame budget, derived from the rate rather than typed: 1e6/90 us. 118 let vr_us: i64 = fb_budget_us(TB_FPS_VR) 119 gv_puts(" fb_budget_us(" as *u8); gv_num(TB_FPS_VR) 120 gv_puts(")=" as *u8); gv_num(vr_us) 121 gv_puts(" us headroom=" as *u8); gv_num(fb_headroom_us(us_frame, vr_us)); gv_puts(" us\n" as *u8) 122 gv_check("tissue tick fits the DERIVED 90 Hz frame budget (1e6/fps, not a typed constant)" as *u8, 123 fb_fits(us_frame, vr_us), ctr) 124 125 // js_block_ms is the binding bar for app logic: the conf's own source is "any app logic over 2ms 126 // should be optimized". The tissue tick IS app logic, so this is the row that governs it. 127 let rjs: i64 = ob_find("js_block_ms" as *u8) 128 var jsok: i64 = 0 129 if rjs >= 0 { 130 let hi_us: i64 = ob_hi(rjs)*TB_MS_US 131 gv_puts(" js_block_ms cited [" as *u8); gv_num(ob_lo(rjs)) 132 gv_puts(".." as *u8); gv_num(ob_hi(rjs)) 133 gv_puts("] ms => " as *u8); gv_num(hi_us); gv_puts(" us ceiling\n" as *u8) 134 jsok = fb_fits(us_frame, hi_us) 135 } 136 gv_check("tissue tick fits the CITED js_block_ms ceiling (app-logic bar, the binding one)" as *u8, jsok, ctr) 137 138 // The frame row is cited in MILLISECONDS; cross-check the derived budget against it rather than 139 // trusting that 1e6/90 and the banked row agree. If they ever disagree, one of them is wrong. 140 var frok: i64 = 0 141 let rfr: i64 = ob_find("frame_budget_ms_90hz" as *u8) 142 if rfr >= 0 { 143 let lo_us: i64 = ob_lo(rfr)*TB_MS_US 144 let hi2_us: i64 = ob_hi(rfr)*TB_MS_US 145 gv_puts(" frame_budget_ms_90hz cited [" as *u8); gv_num(ob_lo(rfr)) 146 gv_puts(".." as *u8); gv_num(ob_hi(rfr)) 147 gv_puts("] ms vs derived " as *u8); gv_num(vr_us); gv_puts(" us\n" as *u8) 148 if vr_us >= lo_us { if vr_us <= hi2_us { frok = 1 } } 149 } 150 gv_check("the DERIVED 1e6/90 budget agrees with the CITED frame_budget_ms_90hz row" as *u8, frok, ctr) 151 152 // NEG-CONTROL: a cost deliberately above the ceiling must be REFUSED. Without it every green above is 153 // consistent with fb_fits returning 1 for anything at all. 154 let rjs2: i64 = ob_find("js_block_ms" as *u8) 155 var negfired: i64 = 0 156 if rjs2 >= 0 { 157 let ceil_us: i64 = ob_hi(rjs2)*TB_MS_US 158 if fb_fits(ceil_us + 1, ceil_us) == 0 { negfired = 1 } 159 } 160 gv_check("neg-control-a-cost-one-microsecond-over-the-cited-ceiling-is-REFUSED" as *u8, negfired, ctr) 161 162 return gv_verdict("TISSUE-BUDGET" as *u8, ctr, 163 "per-frame tissue cost measured against cited VR bars; the figure is a NATIVE FLOOR, never a browser number" as *u8) 164}