nx_vcodec_stage_bench_recovery_20260912.nx
buildroot/runtime/nx_vcodec_stage_bench_recovery_20260912.nx
about
nx_vcodec_stage_bench.nx -- WHERE DOES THE ENCODE TIME GO. Stage attribution of the LIVE rct8 RTC encoder, per
macroblock, on the REAL head-to-head test card (the akiyo index-strip card nx_video_h2h judged 2026-09-02).
WHY IT EXISTS: the same-instrument head-to-head measured ours at 9.9-18.2 of 30 fps against Jitsi's 29, and the
probes' own arming dump showed the cause is encode COST (93 ms single-thread, 48 ms banded at 640x480), not the
ladder (30/45/60 rungs exist) and not wasm (native 74 us per MB == browser 77 us per MB). Nothing in the estate
attributed that cost to a stage (nx_capsearch 2026-09-02: no encoder stage profiler), so every fix would have been
a guess. This organ MEASURES: (A) the whole production frame encode, (B) the integer motion search kernel called
once per MB exactly as the block coder calls it, (C) the quarter-pel refine kernel on the CODED MBs (and on all
MBs, the ceiling), and derives REST = A - B - C (transform, quant, RDOQ, entropy, recon, deblock). Kernel costs
are the cost of ONE call per MB, which is an UPPER BOUND on their share if the encoder early-outs before them.
Historical baseline: emode 2593 = range coder + sig-map + gentle deblock + RD-skip.
Build 865 additionally enables quiet-quadrant skip (emode 18977); both arms remain in this benchmark.
The live skip threshold is qp*30; qp*188 is the separate RD-benchmark control. Two qp points bracket
the ladder. Prints one line per stage per qp; last line is the verdict for gv_last_line readers.
Card: 352x288, first 120 frames of the h2h card (banked in _ops/video_h2h/testcard120.y4m). license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_video_codec_wasm.nxnx_quality_metric.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 20 | const SB_W: i64 = 352 |
| 21 | const SB_H: i64 = 288 |
| 22 | const SB_NF: i64 = 120 |
| 23 | const SB_T: i64 = 16 |
| 24 | const SB_QP_A: i64 = 24 |
| 25 | const SB_QP_B: i64 = 32 |
| 26 | const SB_THRESH_LIVE: i64 = 30 // the LIVE worker's skip threshold: app.v2.js passes B(m.qp * 30) to vv_enc_rct8 |
| 27 | const SB_THRESH_RDBENCH: i64 = 188 // the rd bench's value (qp*188 = the measured real-translation band) -- the OTHER convention |
| 28 | const SB_NOISE_MAX: i64 = 2 // sensor / colour-conversion noise emulation: +-0, +-1, +-2 LSB per luma pixel |
| 29 | const SB_LCG_A: i64 = 1103515245 |
| 30 | const SB_LCG_C: i64 = 12345 |
| 31 | const SB_LCG_MASK: i64 = 2147483647 |
| 32 | const SB_EMODE_RTC: i64 = 2593 // 1 | 32 | 512 | 2048 -- rc + sig + deblock + rdskip (vv_seed_rctx, RTC room) |
| 33 | const SB_WIRE_CAP: i64 = 4194304 |
| 34 | const SB_RCBUF: i64 = 2097152 |
| 35 | const SB_T8C_BYTES: i64 = 5120 |
| 36 | const SB_MAXFRAMES: i64 = 1024 |
| 37 | const SB_NS_PER_US: i64 = 1000 |
| 44 | const SB_EMODE_NORDSKIP: i64 = 545 // 2593 - 2048: the RD-skip band trial OFF (rc + sig + deblock) |
| 45 | const SB_EMODE_NOSIG: i64 = 513 // 545 - 32: sig-map coefficient coder OFF (rc + deblock) |
| 46 | const SB_EMODE_RCONLY: i64 = 1 // range coder only: no sig-map, no deblock, no RD-skip |
| 47 | const SB_EMODE_QQ: i64 = 18977 // 2593 | 16384: the live RTC mode plus the quiet-quadrant early skip (VC_EMODE_QQSKIP) |
| 48 | const SB_EMODE_QQ_HEX: i64 = 51745 // 18977 | 32768: plus the hexagon motion search (VC_EMODE_HEXME) |
| 53 | const SB_RC_P_HALF: i64 = 2048 |
| 121 | const SB_BD_NF: i64 = 48 // the sweep clock: 48 frames at 30 fps -> kbps_milli = total_bytes*5 (nx_bd_calc contract) |
| 122 | const SB_BD_KBPS_MUL: i64 = 5 |
| 123 | const SB_BD_NQ: i64 = 5 |
functions
| 39 | func sw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 40 | func sn(v: i64) -> i64 |
| 49 | func seedctx(rctx: *i64, est: *i64, probs: *i64, rcbuf: *u8, t8c: *i64, emode: i64) -> i64 |
| 52 | func cpb(d: *u8, s: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { d[i] = s[i]; i = i + 1 } return 0 } |
| 55 | func sb_fill_res(blk: *i64, cur: *u8, prev: *u8, W: i64, sx: i64, sy: i64) -> i64 called by 1: sb_run |
| 63 | func sb_noisy(dst: *u8, src: *u8, sz: i64, n_luma: i64, amp: i64, seed: i64) -> i64 |
| 81 | func sb_wnfd(fd: i64, v: i64, sep: i64) -> i64 |
| 93 | func sb_psnr_cdb_sse(s: i64, n: i64) -> i64 |
| 100 | func sb_sse(a: *u8, b: *u8, n: i64) -> i64 called by 1: sb_bd |
| 105 | func sb_parse_y4m(raw: *u8, total: i64, fp: *i64, maxf: i64) -> i64 called by 1: main |
| 127 | func sb_bd(fp: *i64, nf: i64, emode: i64, bufs: *i64, ptsfd: i64) -> i64 |
| 166 | func sb_run(fp: *i64, nf: i64, qp: i64, tmult: i64, amp: i64, emode: i64, bufs: *i64) -> i64 |
| 293 | func sb_atoi(a: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while a[i] != (0 as u8) { v = v * 10 + ((a[i] as i64 & 0xff) - 48); i = i + 1 } return v } called by 1: main |
| 294 | func sb_is_bd(a: *u8) -> i64 { if a[0] != (98 as u8) { return 0 } if a[1] != (100 as u8) { return 0 } if a[2] != (0 as u8) { return 0 } return 1 } |
| 295 | func main(argc: i64, argv: *i64) -> i64 |