From fcfba048c4bf6d9b89f3f63c2cdc308d36b46e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 11:13:22 +0300 Subject: [PATCH] docs(av1): lane-sb128b -- the clamped-drl writer defect, and 128 roots refuted on film B --- crates/ec-av1/src/tile.rs | 1 + lanes/sb128b.report.md | 123 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 lanes/sb128b.report.md diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index fcb280ca..b89dbdb3 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -5959,6 +5959,7 @@ fn note_drl_clamp(target: usize, signalled: usize, entries: usize) { } /// 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) } 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.