forge
Explore
Log in

Don't you dare go Hollow

Lane-sb128b -- the clamped-drl writer defect, and 128 roots refuted on film B

Browse files at this commit

fcfba048c4bf6d9b89f3f63c2cdc308d36b46e96Ahmet Kaan GümüşParent: d93d5b5
  • docs
    • lane-sb128b -- the clamped-drl writer defect, and 128 roots refuted on film B
Show full message
docs(av1): lane-sb128b -- the clamped-drl writer defect, and 128 roots refuted on film B
crates/ec-av1/src/tile.rsmodified+1 -0
@@ -5959,6 +5959,7 @@ fn note_drl_clamp(target: usize, signalled: usize, entries: usize) {
5959 }5959 }
5960 5960
5961 /// Takes and clears [`DRL_CLAMP_HITS`], for a gate's own before/after delta.5961 /// Takes and clears [`DRL_CLAMP_HITS`], for a gate's own before/after delta.
5962+#[cfg(test)]
5962 pub(crate) fn take_drl_clamp_hits() -> usize {5963 pub(crate) fn take_drl_clamp_hits() -> usize {
5963 DRL_CLAMP_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)5964 DRL_CLAMP_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)
5964 }5965 }
lanes/sb128b.report.mdadded+123 -0
@@ -0,0 +1,123 @@
1+# lane-sb128b — the film B 128-superblock refusal, and what 128 roots cost
2+
3+Two results, independent:
4+
5+1. **A writer defect, fixed** (`daebefdc`): the inter writer priced a `NEWMV`
6+ residual against a predictor the decoder never derives whenever the SEARCH
7+ chose a DRL index the WRITE-TIME mv stack could not carry. Silent MV drift,
8+ surfacing frames later as a drl desync — on film B as the encoder's own
9+ trial decode refusing a reference slot. Not a 128-superblock bug: 128 roots
10+ only make the search/write stack drift common enough to hit.
11+2. **The 128-root lever is REFUTED on film B** (cen3's L1, ≈0.24 dB expected):
12+ every arm loses, and the loss survives the forced loop-restoration unit.
13+
14+## 1. The refusal, and the first divergent symbol
15+
16+Reproduced at `6b95562d` in 8 s:
17+
18+ EC_ENC_SS=00:40:00 EC_AV1_SB128=1 \
19+ cargo run --release -p ec-av1 --example enc_probe -- <film B> gate 0 12 150
20+ -> Unsupported { "Leaf frame at order 3 (last slot 0, self 0, altref 4,
21+ last2 None, ...): a reference frame selected with no picture at this
22+ frame's own ref_frame_idx slot for it }
23+
24+`EC_AV1_REFPROBE=1` put the refusal inside OUR decode of OUR stream
25+(`filter_search::pick_filters` -> `decode_inter_frame_tiles_lr` ->
26+`decode_inter_block`), i.e. a writer/reader desync, not a DPB bug (class
27+*refusal names a correlate*).
28+
29+**Instrument** (new, kept): `EC_AV1_SYMTRACE=<dir>` writes one line per coded
30+symbol (`index value nsyms cdf[0]`) per coder into `<dir>/w-*.txt` /
31+`<dir>/r-*.txt`, so the writer's file and the reader's file diff positionally;
32+`EC_AV1_SYMTRACE_AT=<i>` or `<from>:<to>` prints a backtrace at those indices
33+on both sides, which names the syntax element. `find_mv_stack` and the two
34+inter-mode sites annotate the same files (`# MVDBG ...`, `# MODE ...`).
35+
36+**First divergent symbol**: index **5393** of the order-3 leaf's tile.
37+
38+| | site | symbol |
39+|---|---|---|
40+| writer | `tile::write_motion_mode` (tile.rs:767) | 3-symbol `motion_mode`, value 0 |
41+| reader | `decode_inter_block` (decode.rs:28171) | 2-symbol `drl_mode`, value 0 |
42+
43+The reader read one `drl_mode` bit the writer never wrote, at mi=(32,176),
44+because its stack held 3 entries where the writer's held 2.
45+
46+**Root cause, one block earlier and silent**: at mi=(16,112) (a 64x64 block,
47+both sides' stacks IDENTICAL — `[((16,0),740), ((16,-24),736)]`):
48+
49+ W MODE mi=(16,112) mode=NewMv idx=2 mv=(16,-16) info_mv=(16,-16)
50+ R MODE mi=(16,112) dbg=16 mv=(16,-40)
51+
52+The search chose `ref_mv_idx = 2`; `write_drl_idx` can only SIGNAL index 1
53+against a two-entry stack, so the decoder derived its predictor from
54+`entries[1] = (16,-24)` while the writer priced the residual against
55+`stack.entries.get(2)` -> the `pred_mv` fallback. The two MVs differ by
56+exactly the two predictors' difference, the mi grid then differed for the rest
57+of the frame, and 60 blocks later the two stacks disagreed on size and the drl
58+symbol count desynced.
59+
60+**Fix** (`crates/ec-av1/src/tile.rs`): `write_drl_idx` returns the index it
61+actually signals, and every caller takes its base MV from THAT index — both
62+single-reference arms (`NewMv`, `NearMv`) and both compound DRL arms
63+(`NearNearMv`, `NEW_NEWMV`), where the walk variable was already the signalled
64+index but the predictor was read at the requested one. Same-shape sweep: the
65+four writer sites above are the whole class; every `entries.get(idx)` in
66+`decode.rs` derives `idx` from the symbols it just read, so the reader side
67+cannot drift. `encode.rs:8722` (the RD pricer's own base) still prices a
68+clamped candidate at the predictor the writer will NOT use — a mis-pricing,
69+not a desync; left open below.
70+
71+**Witness** (`encode::tests::a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`,
72+`#[ignore]` because it forces the process-global superblock size):
73+
74+ cargo test -p ec-av1 --release --lib -- --ignored \
75+ a_128_superblock_clip_whose_drl_index --nocapture
76+
77+lavfi `mandelbrot=size=1280x768`, 12 frames, `force_sb128(true)`: the writer
78+clamps **7** drl indices whose predictor moves (the counter is the gate on the
79+fixture — class *gate blind to feature*), and every frame decodes sample-exact
80+against the encoder's own reconstruction. RED before the fix (frame luma
81+differs), GREEN after. `EC_AV1_SB128=0` clamps 0 on every clip probed, and
82+film B's default-path stream is byte-identical (27634 B at q=150) — the fix
83+does not move the shipped encoder.
84+
85+## 2. The 2x2 attribution — 128 roots are refuted on film B
86+
87+`bd_rate_screen_native`, `EC_AV1_NATIVE_FILM4K=1`, 12 frames, film B row,
88+BD-rate vs libaom cpu-used 6 / rav1e speed 6 (lower is better):
89+
90+| arm | vs libaom | vs rav1e | q=150 bytes |
91+|---|---|---|---|
92+| SB64, LR on (control, reproduced) | **+24.9%** | **−1.9%** | 27634 |
93+| SB64, LR off (`EC_AV1_LR=0`) | +25.4% | −1.6% | 27673 |
94+| SB128, LR on | +37.5% | +7.3% | 27753 |
95+| SB128, LR off | +33.6% | +5.8% | 27823 |
96+
97+Read it in one line: **the 128 root costs 8.2 points against libaom with the
98+loop-restoration unit held out of the comparison** (25.4 -> 33.6), and the
99+forced ≥128 LR unit adds a further 3.9 (33.6 -> 37.5). The keep rule fails on
100+both columns in every arm, so nothing ships: `EC_AV1_SB128` stays off, and
101+film A / screen / long-GOP were not run (the charter gates them on 128
102+winning).
103+
104+**Why the census's 0.24 dB never appears**: `tile::write_sb128_root` writes
105+`PARTITION_SPLIT` at every 128 root by construction — this encoder cannot code
106+a 128x128, 128x64 or 64x128 BLOCK at all. `EC_AV1_SB128=1` therefore buys zero
107+block-count saving and pays the root's partition symbols, the forced LR unit,
108+and (the new number here) whatever the 128 visit order costs: the quadrants
109+are coded TL/TR/BL/BR inside a 128 root instead of raster 64s, which moves
110+every neighbour context and strips `has_top_right` off the BR quadrant. The
111+lever cannot be measured honestly until a 128-root partition SEARCH exists;
112+cen3's L1 should be re-chartered as "search 128x128 blocks", not "set the
113+sequence bit".
114+
115+## Open
116+
117+- `open`: the RD pricer (`encode.rs:8722`) prices a `ref_mv_idx` the writer
118+ will clamp at the WRONG predictor, so those candidates' costs are wrong on
119+ both superblock sizes. Fires rarely (7 blocks per 12-frame 1280x768 clip
120+ under SB128; 0 under SB64 on every clip probed).
121+- `open`: the search-time and write-time mv stacks differ at all — that is the
122+ upstream cause of the clamp. Making the search build its stack from the
123+ writer's grid would remove the clamp instead of making it safe.