diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index ac0a542a..0e85784a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -28177,6 +28177,11 @@ fn decode_inter_block( }; (mv, false) }; + if crate::msac::symtrace::dir().is_some() { + crate::msac::symtrace::note(&format!( + " MODE mi=({mi_row},{mi_col}) dbg={dbg_mode} mv={mv:?}" + )); + } if crate::envflags::env_flag!("EC_TRACE_MODE") { for (i, e) in stack.entries.iter().enumerate() { eprintln!( diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index a1918ace..88baa2db 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -13471,7 +13471,7 @@ mod tests { eprintln!("SKIP probe_intrabc_key_frame: no OBS recording"); return; }; - let (width, height) = (640usize, 384usize); + let (width, height) = (1280usize, 768usize); let picture = clip_frame(clip, "0", width, height); eprintln!("| base_q_idx | intrabc | bytes | PSNR | blocks | searches/found/won |"); for q in [5u8, 20, 35, 45] { @@ -15130,6 +15130,77 @@ mod tests { /// symbol (`EC_TRACE_MODE_STEP`) on the very stream that broke. This is /// the instrument the inter `TxMode::Select` hunt lacked; on failure it /// names the first differing frame, plane and position. + /// lane-sb128b: the writer used to price a `NEWMV` residual against + /// `stack.pred_mv` whenever the SEARCH chose a `ref_mv_idx` the + /// write-time stack could not carry, while the drl symbols signalled the + /// clamped index -- so the decoder derived a DIFFERENT motion vector with + /// the entropy stream still in sync, and the drift only surfaced frames + /// later as a drl desync (on film B, as the encoder's own trial decode + /// refusing a reference slot). + /// + /// The clamp needs a stack that shrinks between search and write, which + /// is what a 128x128 superblock's visit order does; the counter is the + /// point (class `gate-blind-to-feature`): a green round trip on a clip + /// that never clamps proves nothing. + /// + /// `#[ignore]`: [`force_sb128`] moves a process-global. + /// + /// cargo test -p ec-av1 --release --lib -- --ignored \ + /// a_128_superblock_clip_whose_drl_index_the_write_time_stack --nocapture + #[test] + #[ignore = "sets the process-global superblock size: run it alone"] + fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() { + let _knobs = crate::speed::knob_write(); + if !have_ffmpeg() { + eprintln!("SKIP: no ffmpeg"); + return; + } + force_sb128(true); + let dir = std::env::temp_dir().join(format!("ec-av1-sb128b-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let clip = dir.join("mandelbrot-1280x768.y4m"); + let ok = Command::new("ffmpeg") + .args(["-v", "error", "-y", "-f", "lavfi", "-i", "mandelbrot=size=1280x768:rate=24"]) + .args(["-frames:v", "12", "-pix_fmt", "yuv420p"]) + .arg(&clip) + .status() + .expect("ffmpeg failed to run") + .success(); + assert!(ok, "ffmpeg could not write the synthetic clip"); + let path = clip.to_str().unwrap(); + let (width, height) = (1280usize, 768usize); + let pictures = crate::probe::source(path, "0", "null", width, height, 12); + + let _ = crate::tile::take_drl_clamp_hits(); + let encoded = encode_sequence(&pictures, 150, 0.5).unwrap(); + let clamps = crate::tile::take_drl_clamp_hits(); + assert!( + clamps > 0, + "this clip never asked for a drl index the write-time stack could not carry, \ + so it cannot witness the defect" + ); + eprintln!("clamped drl indices: {clamps}"); + + let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder"); + assert_eq!(decoded.len(), encoded.frames.len(), "frame count"); + for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() { + let recon = &frame.reconstruction; + for (plane, got, want) in [ + ("luma", &dec.y, &recon.y), + ("U", &dec.u, &recon.u), + ("V", &dec.v, &recon.v), + ] { + let differ = got.iter().zip(want).filter(|(a, b)| a != b).count(); + assert_eq!( + differ, 0, + "frame {i}: {plane} -- {differ} of {} samples differ from the encoder's \ + own reconstruction", + got.len() + ); + } + } + } + #[test] fn every_frame_of_a_sequence_decodes_through_our_own_decoder() { let _knobs = crate::speed::knob_read(); diff --git a/crates/ec-av1/src/msac.rs b/crates/ec-av1/src/msac.rs index ab975d5b..636c7956 100644 --- a/crates/ec-av1/src/msac.rs +++ b/crates/ec-av1/src/msac.rs @@ -144,6 +144,9 @@ impl SymbolEncoder { /// shorter than a two-symbol alphabet's three entries. pub fn symbol_fixed(&mut self, symbol: usize, cdf: &[u16]) { assert!(cdf.len() >= 3, "a CDF covers at least two symbols"); + if !self.pricing && symtrace::dir().is_some() { + symtrace::push(symbol, cdf.len() - 1, cdf[0]); + } let nsyms = cdf.len() - 1; assert!(symbol < nsyms, "symbol {symbol} is outside the alphabet"); @@ -201,6 +204,7 @@ impl SymbolEncoder { /// payload end on a byte boundary with no terminator. pub fn finish(mut self) -> Vec { assert!(!self.pricing, "a pricer holds no bytes to flush"); + symtrace::flush('w'); // Round the interval's low end up to a value with 14 low zero bits, // then set bit 14: the result is inside the interval (the interval is // at least 2^15 wide before normalisation) and its tail bits are all @@ -303,6 +307,12 @@ pub struct SymbolDecoder<'a> { max_bits: i32, } +impl Drop for SymbolDecoder<'_> { + fn drop(&mut self) { + symtrace::flush('r'); + } +} + impl<'a> SymbolDecoder<'a> { /// `init_symbol` (spec 8.2.2). #[must_use] @@ -397,6 +407,16 @@ impl<'a> SymbolDecoder<'a> { /// [`SymbolEncoder::symbol_fixed`]. #[inline] pub fn symbol_fixed(&mut self, cdf: &[u16]) -> usize { + if symtrace::dir().is_some() { + let s = self.symbol_fixed_raw(cdf); + symtrace::push(s, cdf.len() - 1, cdf[0]); + return s; + } + self.symbol_fixed_raw(cdf) + } + + #[inline] + fn symbol_fixed_raw(&mut self, cdf: &[u16]) -> usize { let nsyms = cdf.len() - 1; // Two-symbol alphabets are most of the stream (every flag, every bit of // a literal), and their walk has exactly one boundary: computing it @@ -493,7 +513,11 @@ impl<'a> SymbolDecoder<'a> { // `EQUIPROBABLE`'s single boundary: `f >> EC_PROB_SHIFT` is 256, so // the range multiply is a shift. let cur = ((self.range >> 8) << 7) + EC_MIN_PROB; - v = (v << 1) | self.bool_cur(cur) as u32; + let bit = self.bool_cur(cur); + if symtrace::dir().is_some() { + symtrace::push(bit, 2, EQUIPROBABLE[0]); + } + v = (v << 1) | bit as u32; } v } @@ -790,3 +814,78 @@ pub(crate) mod tests { } } } + +/// Symbol-by-symbol writer/reader trace (`EC_AV1_SYMTRACE=`), the +/// instrument a desync between OUR writer and OUR reader is bisected with: +/// every non-pricing [`SymbolEncoder`] and every [`SymbolDecoder`] dumps one +/// line per symbol (`index value nsyms cdf0`) into `/w-.txt` / +/// `/r-.txt`, and the first line where the two differ names the +/// divergent symbol. `EC_AV1_SYMTRACE_AT=` additionally prints a +/// backtrace at that index on both sides, which names the syntax element. +/// Off (the variable unset) this is one relaxed load per symbol. +pub(crate) mod symtrace { + use std::cell::RefCell; + use std::sync::OnceLock; + + static DIR: OnceLock> = OnceLock::new(); + static AT: OnceLock> = OnceLock::new(); + static SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + + thread_local! { + static BUF: RefCell<(String, usize)> = const { RefCell::new((String::new(), 0)) }; + } + + pub(crate) fn dir() -> Option<&'static str> { + DIR.get_or_init(|| crate::envflags::var("EC_AV1_SYMTRACE").ok().filter(|v| !v.is_empty())) + .as_deref() + } + + /// `EC_AV1_SYMTRACE_AT=` or `=:` (inclusive). + fn at() -> Option<(usize, usize)> { + *AT.get_or_init(|| { + let v = crate::envflags::var("EC_AV1_SYMTRACE_AT").ok()?; + let (a, b) = v.split_once(':').unwrap_or((v.as_str(), v.as_str())); + Some((a.parse().ok()?, b.parse().ok()?)) + }) + } + + /// A caller's own annotation, interleaved with this coder's symbol lines + /// (`# ...`) so the writer/reader diff shows the state around a desync. + pub(crate) fn note(line: &str) { + if dir().is_none() { + return; + } + BUF.with(|b| { + let (buf, _) = &mut *b.borrow_mut(); + buf.push_str("# "); + buf.push_str(line); + buf.push('\n'); + }); + } + + pub(crate) fn push(value: usize, nsyms: usize, cdf0: u16) { + BUF.with(|b| { + let (buf, n) = &mut *b.borrow_mut(); + if at().is_some_and(|(a, b)| (a..=b).contains(n)) { + eprintln!("SYMTRACE at {n}: {}", std::backtrace::Backtrace::force_capture()); + } + buf.push_str(&format!("{n} {value} {nsyms} {cdf0}\n")); + *n += 1; + }); + } + + /// Flushes this coder's lines as `/-.txt` and starts the + /// next coder's trace. + pub(crate) fn flush(side: char) { + let Some(dir) = dir() else { return }; + BUF.with(|b| { + let (buf, n) = &mut *b.borrow_mut(); + if !buf.is_empty() { + let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + let _ = std::fs::write(format!("{dir}/{side}-{seq:05}.txt"), buf.as_bytes()); + } + buf.clear(); + *n = 0; + }); + } +} diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index f6ac1631..342c7935 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -1742,6 +1742,24 @@ pub fn find_mv_stack_with_sign_bias( .checked_sub(1) .is_some_and(|c| grid.skip_at(mi_row, c)); + // lane-sb128b: the writer/reader stack diff instrument (`EC_AV1_MVDBG=1`) + // -- one line per built stack, in build order, so the two sides' logs + // diff to the first block whose candidate list differs. + if crate::msac::symtrace::dir().is_some() { + crate::msac::symtrace::note(&format!( + "MVDBG mi=({mi_row},{mi_col}) b=({bw4}x{bh4}) ref={ref_frame} n={} mv={:?}", + candidates.len(), + candidates.iter().map(|e| (e.mv, e.weight)).collect::>(), + )); + let row = mi_row.checked_sub(1).map(|r| { + (mi_col..mi_col + bw4).map(|c| grid.get(r, c).map(|m| (m.ref_frame, m.mv))).collect::>() + }); + let col = mi_col.checked_sub(1).map(|c| { + (mi_row..mi_row + bh4).map(|r| grid.get(r, c).map(|m| (m.ref_frame, m.mv))).collect::>() + }); + crate::msac::symtrace::note(&format!(" above={row:?}")); + crate::msac::symtrace::note(&format!(" left={col:?}")); + } MvStack { entries: candidates, nearest_mv, diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index db28f7ca..22685639 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -1042,10 +1042,13 @@ fn write_compound_block( } walk += 1; } - stack - .entries - .get(idx) - .map_or(stack.near_mv, |e| (e.mv0, e.mv1)) + let near = |i: usize| { + stack.entries.get(i).map_or(stack.near_mv, |e| (e.mv0, e.mv1)) + }; + if walk != idx && near(walk) != near(idx) { + note_drl_clamp(idx, walk, stack.entries.len()); + } + near(walk) } InterMode::NearestNewMv | InterMode::NewNearestMv => { // Neither mode codes a DRL index (the decoder leaves `ref_mv_idx` @@ -1074,10 +1077,13 @@ fn write_compound_block( } walk += 1; } - let base = stack - .entries - .get(idx) - .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1)); + let nearest = |i: usize| { + stack.entries.get(i).map_or(stack.nearest_mv, |e| (e.mv0, e.mv1)) + }; + if walk != idx && nearest(walk) != nearest(idx) { + note_drl_clamp(idx, walk, stack.entries.len()); + } + let base = nearest(walk); write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base.0)?; write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv1, base.1)?; (info.mv, info.mv1) @@ -5937,6 +5943,27 @@ pub(crate) fn take_ref_hits() -> [usize; 7] { } /// Bumps the two histograms for one coded inter block. +/// How many blocks this process wrote whose search-chosen `ref_mv_idx` the +/// write-time stack could not carry, so the writer signalled a SMALLER index +/// (lane-sb128b). Every one of these used to price its residual against a +/// predictor the decoder never derives. +static DRL_CLAMP_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + +/// Counts one clamped DRL index whose predictor differs from the one the +/// search asked for -- the harmful case, and the only one a witness can see. +fn note_drl_clamp(target: usize, signalled: usize, entries: usize) { + DRL_CLAMP_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + if crate::envflags::env_flag!("EC_AV1_TRACE") { + eprintln!("DRL_CLAMP target={target} signalled={signalled} entries={entries}"); + } +} + +/// Takes and clears [`DRL_CLAMP_HITS`], for a gate's own before/after delta. +#[cfg(test)] +pub(crate) fn take_drl_clamp_hits() -> usize { + DRL_CLAMP_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) +} + fn note_inter_mode(mode: usize, drl: usize) { INTER_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed); DRL_HITS[drl.min(3)].fetch_add(1, std::sync::atomic::Ordering::Relaxed); @@ -5959,23 +5986,31 @@ pub(crate) fn take_drl_hits() -> [usize; 4] { /// `drl_mode` bit per stack entry past `start`, `1` to advance and `0` to /// stop, at most two bits. `drl_ctx[idx]` is the context between /// `entries[idx]` and `entries[idx + 1]`, exactly the pair the bit chooses -/// between. +/// between. Returns the index the symbols actually SIGNAL, which is `target` +/// clamped by the stack (`min(target, start + 2, entries.len() - 1)`): the +/// decoder derives its predictor from THAT index, so every caller must take +/// its own base MV from the returned value and not from `target` (lane-sb128b: +/// a search-chosen `ref_mv_idx` of 2 against a two-entry write-time stack +/// signalled index 1 and priced the residual against `pred_mv`, and the +/// decoder's MV silently drifted a whole frame before the drl symbols +/// desynced). fn write_drl_idx( enc: &mut SymbolEncoder, cdfs: &mut Cdfs, stack: &crate::mvstack::MvStack, start: usize, target: usize, -) { +) -> usize { let mut idx = start; while idx < start + 2 && stack.entries.len() > idx + 1 { let advance = idx < target; enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[idx]]); if !advance { - return; + return idx; } idx += 1; } + idx } /// Writer-side counterpart of the decoder's single-reference @@ -6008,8 +6043,12 @@ fn write_inter_mode( match info.mode { InterMode::NewMv => { enc.symbol(0, &mut cdfs.new_mv[stack.new_mv_ctx]); - write_drl_idx(enc, cdfs, stack, 0, idx); - let base = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); + let signalled = write_drl_idx(enc, cdfs, stack, 0, idx); + let base = stack.entries.get(signalled).map_or(stack.pred_mv, |e| e.mv); + if signalled != idx && base != stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv) { + note_drl_clamp(idx, signalled, stack.entries.len()); + } + let idx = signalled; write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base)?; note_inter_mode(3, idx); Ok((info.mv, true)) @@ -6033,8 +6072,12 @@ fn write_inter_mode( enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24). let idx = idx.max(1); - write_drl_idx(enc, cdfs, stack, 1, idx); - let mv = stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv); + let signalled = write_drl_idx(enc, cdfs, stack, 1, idx); + let mv = stack.entries.get(signalled).map_or(stack.near_mv, |e| e.mv); + if signalled != idx && mv != stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) { + note_drl_clamp(idx, signalled, stack.entries.len()); + } + let idx = signalled; note_inter_mode(1, idx); Ok((mv, false)) } @@ -6327,6 +6370,12 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( mi_rows as usize, ); let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; + if crate::msac::symtrace::dir().is_some() { + crate::msac::symtrace::note(&format!( + " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}", + info.mode, info.ref_mv_idx, info.mv + )); + } (mv, (0, 0), is_new_mv) }; for dr in 0..SB_MI as usize { @@ -6722,6 +6771,12 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( ); let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; + if crate::msac::symtrace::dir().is_some() { + crate::msac::symtrace::note(&format!( + " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}", + info.mode, info.ref_mv_idx, info.mv + )); + } grid.set( mi_row, mi_col, diff --git a/lanes/sb128b.report.md b/lanes/sb128b.report.md new file mode 100644 index 00000000..2cff51f1 --- /dev/null +++ b/lanes/sb128b.report.md @@ -0,0 +1,123 @@ +# lane-sb128b — the film B 128-superblock refusal, and what 128 roots cost + +Two results, independent: + +1. **A writer defect, fixed** (`daebefdc`): the inter writer priced a `NEWMV` + residual against a predictor the decoder never derives whenever the SEARCH + chose a DRL index the WRITE-TIME mv stack could not carry. Silent MV drift, + surfacing frames later as a drl desync — on film B as the encoder's own + trial decode refusing a reference slot. Not a 128-superblock bug: 128 roots + only make the search/write stack drift common enough to hit. +2. **The 128-root lever is REFUTED on film B** (cen3's L1, ≈0.24 dB expected): + every arm loses, and the loss survives the forced loop-restoration unit. + +## 1. The refusal, and the first divergent symbol + +Reproduced at `6b95562d` in 8 s: + + EC_ENC_SS=00:40:00 EC_AV1_SB128=1 \ + cargo run --release -p ec-av1 --example enc_probe -- gate 0 12 150 + -> Unsupported { "Leaf frame at order 3 (last slot 0, self 0, altref 4, + last2 None, ...): a reference frame selected with no picture at this + frame's own ref_frame_idx slot for it } + +`EC_AV1_REFPROBE=1` put the refusal inside OUR decode of OUR stream +(`filter_search::pick_filters` -> `decode_inter_frame_tiles_lr` -> +`decode_inter_block`), i.e. a writer/reader desync, not a DPB bug (class +*refusal names a correlate*). + +**Instrument** (new, kept): `EC_AV1_SYMTRACE=` writes one line per coded +symbol (`index value nsyms cdf[0]`) per coder into `/w-*.txt` / +`/r-*.txt`, so the writer's file and the reader's file diff positionally; +`EC_AV1_SYMTRACE_AT=` or `:` prints a backtrace at those indices +on both sides, which names the syntax element. `find_mv_stack` and the two +inter-mode sites annotate the same files (`# MVDBG ...`, `# MODE ...`). + +**First divergent symbol**: index **5393** of the order-3 leaf's tile. + +| | site | symbol | +|---|---|---| +| writer | `tile::write_motion_mode` (tile.rs:767) | 3-symbol `motion_mode`, value 0 | +| reader | `decode_inter_block` (decode.rs:28171) | 2-symbol `drl_mode`, value 0 | + +The reader read one `drl_mode` bit the writer never wrote, at mi=(32,176), +because its stack held 3 entries where the writer's held 2. + +**Root cause, one block earlier and silent**: at mi=(16,112) (a 64x64 block, +both sides' stacks IDENTICAL — `[((16,0),740), ((16,-24),736)]`): + + W MODE mi=(16,112) mode=NewMv idx=2 mv=(16,-16) info_mv=(16,-16) + R MODE mi=(16,112) dbg=16 mv=(16,-40) + +The search chose `ref_mv_idx = 2`; `write_drl_idx` can only SIGNAL index 1 +against a two-entry stack, so the decoder derived its predictor from +`entries[1] = (16,-24)` while the writer priced the residual against +`stack.entries.get(2)` -> the `pred_mv` fallback. The two MVs differ by +exactly the two predictors' difference, the mi grid then differed for the rest +of the frame, and 60 blocks later the two stacks disagreed on size and the drl +symbol count desynced. + +**Fix** (`crates/ec-av1/src/tile.rs`): `write_drl_idx` returns the index it +actually signals, and every caller takes its base MV from THAT index — both +single-reference arms (`NewMv`, `NearMv`) and both compound DRL arms +(`NearNearMv`, `NEW_NEWMV`), where the walk variable was already the signalled +index but the predictor was read at the requested one. Same-shape sweep: the +four writer sites above are the whole class; every `entries.get(idx)` in +`decode.rs` derives `idx` from the symbols it just read, so the reader side +cannot drift. `encode.rs:8722` (the RD pricer's own base) still prices a +clamped candidate at the predictor the writer will NOT use — a mis-pricing, +not a desync; left open below. + +**Witness** (`encode::tests::a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`, +`#[ignore]` because it forces the process-global superblock size): + + cargo test -p ec-av1 --release --lib -- --ignored \ + a_128_superblock_clip_whose_drl_index --nocapture + +lavfi `mandelbrot=size=1280x768`, 12 frames, `force_sb128(true)`: the writer +clamps **7** drl indices whose predictor moves (the counter is the gate on the +fixture — class *gate blind to feature*), and every frame decodes sample-exact +against the encoder's own reconstruction. RED before the fix (frame luma +differs), GREEN after. `EC_AV1_SB128=0` clamps 0 on every clip probed, and +film B's default-path stream is byte-identical (27634 B at q=150) — the fix +does not move the shipped encoder. + +## 2. The 2x2 attribution — 128 roots are refuted on film B + +`bd_rate_screen_native`, `EC_AV1_NATIVE_FILM4K=1`, 12 frames, film B row, +BD-rate vs libaom cpu-used 6 / rav1e speed 6 (lower is better): + +| arm | vs libaom | vs rav1e | q=150 bytes | +|---|---|---|---| +| SB64, LR on (control, reproduced) | **+24.9%** | **−1.9%** | 27634 | +| SB64, LR off (`EC_AV1_LR=0`) | +25.4% | −1.6% | 27673 | +| SB128, LR on | +37.5% | +7.3% | 27753 | +| SB128, LR off | +33.6% | +5.8% | 27823 | + +Read it in one line: **the 128 root costs 8.2 points against libaom with the +loop-restoration unit held out of the comparison** (25.4 -> 33.6), and the +forced ≥128 LR unit adds a further 3.9 (33.6 -> 37.5). The keep rule fails on +both columns in every arm, so nothing ships: `EC_AV1_SB128` stays off, and +film A / screen / long-GOP were not run (the charter gates them on 128 +winning). + +**Why the census's 0.24 dB never appears**: `tile::write_sb128_root` writes +`PARTITION_SPLIT` at every 128 root by construction — this encoder cannot code +a 128x128, 128x64 or 64x128 BLOCK at all. `EC_AV1_SB128=1` therefore buys zero +block-count saving and pays the root's partition symbols, the forced LR unit, +and (the new number here) whatever the 128 visit order costs: the quadrants +are coded TL/TR/BL/BR inside a 128 root instead of raster 64s, which moves +every neighbour context and strips `has_top_right` off the BR quadrant. The +lever cannot be measured honestly until a 128-root partition SEARCH exists; +cen3's L1 should be re-chartered as "search 128x128 blocks", not "set the +sequence bit". + +## Open + +- `open`: the RD pricer (`encode.rs:8722`) prices a `ref_mv_idx` the writer + will clamp at the WRONG predictor, so those candidates' costs are wrong on + both superblock sizes. Fires rarely (7 blocks per 12-frame 1280x768 clip + under SB128; 0 under SB64 on every clip probed). +- `open`: the search-time and write-time mv stacks differ at all — that is the + upstream cause of the clamp. Making the search build its stack from the + writer's grid would remove the clamp instead of making it safe.