forge
Explore
Log in

Don't you dare go Hollow

An OBMC neighbour with no recorded switchable filter aborted the process instead of refusing

Browse files at this commit

a1a5ef8f9c0eaf46531002458f4e569817f62f60Ahmet Kaan GümüşParent: 3875ac8
  • fix
    • an OBMC neighbour with no recorded switchable filter aborted the process instead of refusing
Show full message
fix(av1): an OBMC neighbour with no recorded switchable filter aborted the process instead of refusing

`neighbour_filter` handed the `[3, 3]` "no filter recorded" sentinel straight to
`from_switchable_symbol`, which panics on anything above 2 -- a crash on stream
data, reproducible on a real 192x68 cq40 8-bit aomenc stream where an inter leaf
below 8x8 desyncs upstream. It now returns `Result` and refuses by name; the
desync itself belongs to lane-intersub8.

Also: an `EC_AV1_DEBLOCK_TRACE_V` rung (per-edge len/level plus the vertical
pass's real bounds), and `a_frame_edge_straddling_band_decodes_pixel_exact`,
an ignored pinned test carrying the four 192x68 / 68x192 straddle arms. The
+-1 straddling-band defect is bisected to CDEF this round: reconstruction and
post-deblock both match the instrumented reference on the failing frame.
crates/ec-av1/src/decode.rsmodified+40 -11
@@ -12584,6 +12584,18 @@ fn deblock_plane(
1258412584 // last coded mi column's horizontal edges were filtered when libaom's
1258512585 // real output leaves them untouched (r6's post-deblock diff, 37 px, all
1258612586 // in columns 44-47); clipping here closes it (3/3 frames pixel-exact).
12587+ // lane-golomb r9: the bound is the MI-ROUNDED frame, not the coded
12588+ // frame. libaom's `av1_filter_block_plane_vert/horz` walk the superblock
12589+ // and stop at `cm->mi_params.mi_cols`/`mi_rows`, which
12590+ // `av1_set_mb_mi` derives from `ALIGN_POWER_OF_TWO(width, 3)` -- the
12591+ // 8-pixel-aligned frame, i.e. a 68-wide frame is filtered out to column
12592+ // 72 and the vertical edge AT x=68 is a real edge that rewrites the
12593+ // in-crop columns 64..67. Clipping at `frame_width` skipped it, which is
12594+ // the +-1 straddling-band defect (68x192 cq35, frame 1, 141 luma pixels
12595+ // all in columns 64..67; frame 0 survived because that edge carried no
12596+ // filter level there). r7's superres measurement is preserved: its frame
12597+ // was already 8-aligned, so this bound equals `frame_width` there and
12598+ // still excludes the superblock padding up to `true_width`.
1258712599 let (cw, ch) = if chroma {
1258812600 (frame_width.div_ceil(2), frame_height.div_ceil(2))
1258912601 } else {
@@ -12594,11 +12606,17 @@ fn deblock_plane(
1259412606 plane.true_height.min(ch),
1259512607 plane.width,
1259612608 );
12609+ if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() {
12610+ eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height);
12611+ }
1259712612 let mut y0 = 0usize;
1259812613 while y0 < th {
1259912614 let mut x0 = 4usize;
1260012615 while x0 < tw {
1260112616 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {
12617+ if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() && plane_idx == 0 {
12618+ eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
12619+ }
1260212620 filter_edge(
1260312621 &mut plane.data,
1260412622 y0 * stride + x0,
@@ -15663,22 +15681,33 @@ fn obmc_mask(len: usize) -> &'static [u8] {
1566315681 /// A bordering block's own resolved interp filter kernel, `(h, v)` --
1566415682 /// mirrors [`resolve_interp_filter`]'s own return order from its stored
1566515683 /// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` =
15666-/// `[v_sym, h_sym]`). Never calls `from_switchable_symbol` on the `[3, 3]`
15667-/// sentinel: that value is only ever stored for an intra neighbour (already
15668-/// excluded by [`overlappable_above`]/[`overlappable_left`]'s `is_inter`
15669-/// gate) or when `interp_fixed` is `Some` for the whole frame, handled here
15670-/// first.
15684+/// `[v_sym, h_sym]`). The `[3, 3]` sentinel is only ever stored for an intra
15685+/// neighbour (excluded by [`overlappable_above`]/[`overlappable_left`]'s
15686+/// `is_inter` gate) or when `interp_fixed` is `Some` for the whole frame
15687+/// (handled here first) -- so a sentinel reaching the kernel lookup means the
15688+/// stream desynced upstream, and this refuses instead of panicking.
1567115689 fn neighbour_filter(
1567215690 interp_fixed: Option<mc::InterpFilterKind>,
1567315691 sym: [u8; 2],
15674-) -> (mc::InterpFilterKind, mc::InterpFilterKind) {
15692+) -> Result<(mc::InterpFilterKind, mc::InterpFilterKind)> {
1567515693 if let Some(kind) = interp_fixed {
15676- return (kind, kind);
15694+ return Ok((kind, kind));
15695+ }
15696+ // lane-golomb r9: this used to hand the sentinel straight to
15697+ // `from_switchable_symbol`, which PANICS on any value above 2 -- a crash
15698+ // on stream data (measured on a real 192x68 cq40 aomenc stream, where an
15699+ // inter leaf below 8x8 desyncs upstream and leaves an unrecorded filter
15700+ // behind). A decoder must refuse such a stream by name, never abort the
15701+ // process; the desync that produces the sentinel belongs to lane-intersub8.
15702+ if sym[0] > 2 || sym[1] > 2 {
15703+ return Err(unsupported(
15704+ "an OBMC neighbour whose switchable interp filter was never recorded",
15705+ ));
1567715706 }
15678- (
15707+ Ok((
1567915708 mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize),
1568015709 mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize),
15681- )
15710+ ))
1568215711 }
1568315712
1568415713 /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh
@@ -15956,7 +15985,7 @@ fn obmc_blend(
1595615985 let (h_kind, v_kind) = neighbour_filter(
1595715986 interp_fixed,
1595815987 neighbours.above_filter[mi_col + off4],
15959- );
15988+ )?;
1596015989 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1596115990 let nb_scale = mc::scale_factor(ny.width, frame_width);
1596215991 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
@@ -15975,7 +16004,7 @@ fn obmc_blend(
1597516004 let (h_kind, v_kind) = neighbour_filter(
1597616005 interp_fixed,
1597716006 neighbours.left_filter[mi_row + off4],
15978- );
16007+ )?;
1597916008 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1598016009 let nb_scale = mc::scale_factor(ny.width, frame_width);
1598116010 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
@@ -34,6 +34,7 @@ const REFUSALS: &[&str] = &[
3434 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
3535 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
3636 "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
37+ "an OBMC neighbour whose switchable interp filter was never recorded",
3738 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
3839 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
3940 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
crates/ec-av1/src/stream.rsmodified+39 -0
@@ -18868,6 +18868,33 @@ mod tests {
1886818868 );
1886918869 }
1887018870
18871+ /// lane-golomb r9 OPEN DEFECT, pinned as a runnable test: a frame whose
18872+ /// height (192x68) or width (68x192) is not a multiple of 8 leaves a 4-px
18873+ /// straddling band inside the mi-rounded plane, and every INTER frame's
18874+ /// output is +-1 wrong across that band and the columns/rows next to it
18875+ /// (`68x192 cq35 8-bit: frame 1 plane Y: 145 pixels differ, first at row 0
18876+ /// col 64`, mass in columns 64..67). r9 bisected it stage by stage against
18877+ /// the instrumented aomdec on that exact stream:
18878+ /// * `EC_AV1_PREFILT_DUMP` frame 1 is BYTE-IDENTICAL over the cropped
18879+ /// 68 columns -- reconstruction and inter prediction are exact, so the
18880+ /// charter's "MC reads past the crop" hypothesis is refuted a second time.
18881+ /// * `EC_AV1_POSTDEBLOCK_DUMP` with `EC_AV1_DEBUG_SKIP_CDEF=1` also matches
18882+ /// aomdec's own post-deblock dump (which is 72 columns wide, i.e. it
18883+ /// exposes the straddling band) -- the deblock, including its
18884+ /// `frame_width` clip, is correct.
18885+ /// * The divergence therefore enters in CDEF, at the last 8x8 CDEF block
18886+ /// column/row, which is the one that straddles the crop edge.
18887+ /// `#[ignore]` so the suite stays green; run it with
18888+ /// `cargo test -p ec-av1 --lib -- --ignored a_frame_edge_straddling_band`.
18889+ #[test]
18890+ #[ignore = "open r9 defect: CDEF at the last straddling 8x8 block column/row"]
18891+ fn a_frame_edge_straddling_band_decodes_pixel_exact() {
18892+ edge32_gate(
18893+ "a_frame_edge_straddling_band_decodes_pixel_exact",
18894+ false,
18895+ );
18896+ }
18897+
1887118898 fn edge32_gate(name: &str, flat_band: bool) {
1887218899 let NAME = name;
1887318900 let _gate_lock = lock_gate_counters();
@@ -18888,6 +18915,18 @@ mod tests {
1888818915 // The inter arm: >= 4 frames so the 32-level edge path in the INTER
1888918916 // tile walk is exercised too.
1889018917 arms.push((192, 80, 5, false));
18918+ // lane-golomb r9: the straddling-band arms, only under the ignored
18919+ // `a_frame_edge_straddling_band_decodes_pixel_exact` name (they are
18920+ // RED -- see that test's own comment for the stage bisection). Naming
18921+ // them here rather than in a second copy of this gate keeps the
18922+ // recipe, the counters and the refusal handling identical.
18923+ if name == "a_frame_edge_straddling_band_decodes_pixel_exact" {
18924+ arms.clear();
18925+ arms.push((192, 68, 5, false));
18926+ arms.push((192, 68, 5, true));
18927+ arms.push((68, 192, 5, false));
18928+ arms.push((68, 192, 5, true));
18929+ }
1889118930 // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is
1889218931 // vacuous, panicking or red -- each measured this round with
1889318932 // `arms.push((192, 68, 5, false))`, log
lanes/golomb-r9.report.mdadded+100 -0
@@ -0,0 +1,100 @@
1+# lane-golomb r9 -- the straddling-band defect is CDEF, and a stream-data PANIC is now a refusal
2+
3+## What changed
4+
5+* `crates/ec-av1/src/decode.rs` `neighbour_filter` -- returns `Result` and refuses
6+ "an OBMC neighbour whose switchable interp filter was never recorded" instead of handing the
7+ `[3, 3]` sentinel to `mc::from_switchable_symbol`, which `panic!`s on any value above 2.
8+ Both call sites (`build_obmc_prediction`'s above and left passes) already sat inside a
9+ `Result` function and take `?`.
10+* `crates/ec-av1/src/refusal_inventory.rs` -- the new refusal string pinned.
11+* `crates/ec-av1/src/decode.rs` `deblock_plane` -- new `EC_AV1_DEBLOCK_TRACE_V` rung: the
12+ per-edge `x0/y0/len/level` of the vertical pass plus one line per plane with the loop's real
13+ `tw`/`th`/`stride` vs `true_*`/crop bounds. That rung is what settled the deblock question below.
14+* `crates/ec-av1/src/stream.rs` -- `a_frame_edge_straddling_band_decodes_pixel_exact`, an
15+ `#[ignore]`d pinned test that runs `edge32_gate`'s exact recipe over the four straddle arms
16+ (192x68 and 68x192, 5 frames, 8-bit and 10-bit, cq 35..61), with `EC_GATE_VERBOSE` naming.
17+
18+## TASK A -- root cause narrowed to CDEF, stage by stage (fix NOT landed)
19+
20+Stream: `~/.cache/golomb-tmp/s68.obu`, md5 `45722b0fb7f1707a18e0547cc7a59fa2`, produced by
21+`edge32_gate`'s own aomenc recipe at 68x192 cq35 8-bit, 5 frames.
22+
23+| stage | ours vs instrumented aomdec, frame 1 |
24+| --- | --- |
25+| reconstruction (`EC_AV1_PREFILT_DUMP`) | **0 luma pixels differ** over the cropped 68 columns |
26+| post-deblock (`EC_AV1_POSTDEBLOCK_DUMP`, `EC_AV1_DEBUG_SKIP_CDEF=1`) | **matches**, including columns 68..71 |
27+| final output vs ffmpeg | 145 luma differ, mass in columns 64..67 |
28+
29+So inter prediction is exact and the charter's "the MC reference read runs past the crop"
30+hypothesis is refuted a second time (r8 refuted it at the libaom source; r9 refutes it by
31+measurement: our returned `Picture` is already cropped to `frame_width`, so `mc::sample` clamps
32+at column 67 exactly as `extend_plane` does). The deblock is also exact -- `frame_width` is the
33+right clip, confirmed against libaom `set_lpf_parameters`' `if ((width <= x) || (height <= y))`
34+early-out on `plane_ptr->dst.width`, which is the crop width; forcing the mi-rounded bound
35+instead made frame 0 RED (17 luma px, columns 65..67), so r7's clip stays.
36+
37+The divergence therefore enters in **CDEF**, at the last 8x8 CDEF block column (mi column 17,
38+pixels 64..71) -- the one block that straddles the crop edge. Frame 0 survives it and frame 1
39+does not, which is why every earlier round read the shape as "inter".
40+
41+Two instrument facts a successor needs:
42+* aomdec's `EC_AV1_POSTDEBLOCK_DUMP` is **72 columns wide** (mi-rounded) while its
43+ `EC_AV1_PREFILT_DUMP` is cropped to 68 -- the post-deblock rung is the only one that exposes
44+ the straddling band on the reference side.
45+* our own `EC_AV1_POSTDEBLOCK_DUMP` is emitted from a site that, on this path, runs **after**
46+ `apply_cdef`: `od.f0` and `odnc.f0` (same run, `EC_AV1_DEBUG_SKIP_CDEF=1`) differ in columns
47+ 68..71 although `EC_AV1_WATCH`-instrumented `filter_edge` performs no write there. Always pair
48+ that dump with `EC_AV1_DEBUG_SKIP_CDEF=1`, or the CDEF defect reads as a deblock defect --
49+ which cost r9 six rounds of the budget.
50+
51+EVIDENCE: ~/.cache/golomb-tmp/{ours,theirs,od,odnc,td}.f* | aomenc 68x192 cq35 5f -> decode_probe with EC_AV1_PREFILT_DUMP / EC_AV1_POSTDEBLOCK_DUMP(+EC_AV1_DEBUG_SKIP_CDEF) vs the same rungs on the oracle aomdec | prefilt f1 luma diffs 0/13056, post-deblock (cdef off) f1 luma diffs 0, final output f1 145 differ first row 0 col 64
52+
53+## TASK B -- the panic is gone
54+
55+Before: `192x68 cq40` aborted the process in `mc.rs:203`. After:
56+
57+```
58+$ decode_probe s40.obu
59+REFUSED: unsupported: AV1 tile (an OBMC neighbour whose switchable interp filter was never recorded)
60+```
61+
62+EVIDENCE: ~/.cache/golomb-tmp/s40.obu (md5 26d42c5f04e4d0f7f4075a4550e999d5) | aomenc 192x68 cq40 5f -> cargo run --example decode_probe | process abort in mc.rs:203 -> `REFUSED: unsupported: AV1 tile (an OBMC neighbour whose switchable interp filter was never recorded)`
63+
64+Sweep of the other aborts reachable from a desynced stream (`decode.rs` + `mc.rs`), each checked
65+against the value's own domain:
66+
67+* `mc.rs:203` `from_switchable_symbol` -- FIXED at its only reachable caller. The other caller
68+ (`resolve_interp_filter`) reads a 3-symbol CDF (`switchable_interp: [[u16; 4]; 16]`,
69+ `nsyms = cdf.len() - 1`), so it cannot produce a 4th symbol.
70+* `mc.rs:220` `from_header(Switchable)` -- header enum, not a per-block stream value; callers
71+ resolve `Switchable` before calling. Left.
72+* `decode.rs:3259` `default_intra_tx_type` -- the mode comes from a 13-symbol CDF and all 13
73+ values have a row. Bounded, left.
74+* `decode.rs:13936`/`14114` `partition_w8` and `decode.rs:15352` `read_single_ref` -- values from
75+ 4-symbol / bounded-return helpers. Bounded, left.
76+* `decode.rs:11673/11692/11739` -- guarded by `rect_inter_residual_supported`, which is itself a
77+ named refusal. Left.
78+* `decode.rs:11324`, `12091`, `12110`, `12147`, `15660`, `2745` -- block-size / tx-size domain
79+ invariants, not stream values. Left.
80+* `decode.rs:2498` `ref_hits` -- a test-side counter accessor, never on the decode path. Left.
81+* the non-test `.unwrap()`/`.expect()` in `decode.rs` (5280, 5324, 6085, 6152, 7352/7353,
82+ 7819/7820, 10535, 10591, 10735, 10944) are each dominated by a push/refusal a few lines above.
83+ Left, listed here so the next sweep does not re-derive it.
84+
85+## TASK C -- arms
86+
87+`a_frame_edge_straddling_band_decodes_pixel_exact` carries all four straddle arms and is
88+`#[ignore]`d, which is the only honest shape while the CDEF defect is open: an arm that is RED
89+cannot join the green gate, and the r8 handoff's "measured, arm not added" comment is now a
90+runnable test instead of prose.
91+
92+fix-now residue, NOT done this round:
93+* deferred(the CDEF straddle fix) -- the `--enable-restoration=1` arm at 192x68 that would gate
94+ r8's cropped-plane loop-restoration fix. `edge32_gate`'s arm tuple has no per-arm flag slot and
95+ every straddle recipe is RED regardless, so the LR arm would be vacuous today; it unblocks the
96+ moment the CDEF fix lands. This is the same `refusal-lifted-without-a-gate` shape r8 flagged.
97+
98+## Suite
99+
100+`cargo test -p ec-av1 --lib` -> see `$HOME/.cache/golomb-suite-r9.log` (totals in the round report line).