diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 7bfb8d18..cf74ea5e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -12584,6 +12584,18 @@ fn deblock_plane( // last coded mi column's horizontal edges were filtered when libaom's // real output leaves them untouched (r6's post-deblock diff, 37 px, all // in columns 44-47); clipping here closes it (3/3 frames pixel-exact). + // lane-golomb r9: the bound is the MI-ROUNDED frame, not the coded + // frame. libaom's `av1_filter_block_plane_vert/horz` walk the superblock + // and stop at `cm->mi_params.mi_cols`/`mi_rows`, which + // `av1_set_mb_mi` derives from `ALIGN_POWER_OF_TWO(width, 3)` -- the + // 8-pixel-aligned frame, i.e. a 68-wide frame is filtered out to column + // 72 and the vertical edge AT x=68 is a real edge that rewrites the + // in-crop columns 64..67. Clipping at `frame_width` skipped it, which is + // the +-1 straddling-band defect (68x192 cq35, frame 1, 141 luma pixels + // all in columns 64..67; frame 0 survived because that edge carried no + // filter level there). r7's superres measurement is preserved: its frame + // was already 8-aligned, so this bound equals `frame_width` there and + // still excludes the superblock padding up to `true_width`. let (cw, ch) = if chroma { (frame_width.div_ceil(2), frame_height.div_ceil(2)) } else { @@ -12594,11 +12606,17 @@ fn deblock_plane( plane.true_height.min(ch), plane.width, ); + if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() { + eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height); + } let mut y0 = 0usize; while y0 < th { let mut x0 = 4usize; while x0 < tw { if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) { + if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() && plane_idx == 0 { + eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}"); + } filter_edge( &mut plane.data, y0 * stride + x0, @@ -15663,22 +15681,33 @@ fn obmc_mask(len: usize) -> &'static [u8] { /// A bordering block's own resolved interp filter kernel, `(h, v)` -- /// mirrors [`resolve_interp_filter`]'s own return order from its stored /// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` = -/// `[v_sym, h_sym]`). Never calls `from_switchable_symbol` on the `[3, 3]` -/// sentinel: that value is only ever stored for an intra neighbour (already -/// excluded by [`overlappable_above`]/[`overlappable_left`]'s `is_inter` -/// gate) or when `interp_fixed` is `Some` for the whole frame, handled here -/// first. +/// `[v_sym, h_sym]`). The `[3, 3]` sentinel is only ever stored for an intra +/// neighbour (excluded by [`overlappable_above`]/[`overlappable_left`]'s +/// `is_inter` gate) or when `interp_fixed` is `Some` for the whole frame +/// (handled here first) -- so a sentinel reaching the kernel lookup means the +/// stream desynced upstream, and this refuses instead of panicking. fn neighbour_filter( interp_fixed: Option, sym: [u8; 2], -) -> (mc::InterpFilterKind, mc::InterpFilterKind) { +) -> Result<(mc::InterpFilterKind, mc::InterpFilterKind)> { if let Some(kind) = interp_fixed { - return (kind, kind); + return Ok((kind, kind)); + } + // lane-golomb r9: this used to hand the sentinel straight to + // `from_switchable_symbol`, which PANICS on any value above 2 -- a crash + // on stream data (measured on a real 192x68 cq40 aomenc stream, where an + // inter leaf below 8x8 desyncs upstream and leaves an unrecorded filter + // behind). A decoder must refuse such a stream by name, never abort the + // process; the desync that produces the sentinel belongs to lane-intersub8. + if sym[0] > 2 || sym[1] > 2 { + return Err(unsupported( + "an OBMC neighbour whose switchable interp filter was never recorded", + )); } - ( + Ok(( mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize), mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize), - ) + )) } /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh @@ -15956,7 +15985,7 @@ fn obmc_blend( let (h_kind, v_kind) = neighbour_filter( interp_fixed, neighbours.above_filter[mi_col + off4], - ); + )?; let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; let nb_scale = mc::scale_factor(ny.width, frame_width); let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); @@ -15975,7 +16004,7 @@ fn obmc_blend( let (h_kind, v_kind) = neighbour_filter( interp_fixed, neighbours.left_filter[mi_row + off4], - ); + )?; let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; let nb_scale = mc::scale_factor(ny.width, frame_width); let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4); diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 4ab1f2c6..c92b7210 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -34,6 +34,7 @@ const REFUSALS: &[&str] = &[ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", + "an OBMC neighbour whose switchable interp filter was never recorded", "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index dced19d4..fe156c02 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -18868,6 +18868,33 @@ mod tests { ); } + /// lane-golomb r9 OPEN DEFECT, pinned as a runnable test: a frame whose + /// height (192x68) or width (68x192) is not a multiple of 8 leaves a 4-px + /// straddling band inside the mi-rounded plane, and every INTER frame's + /// output is +-1 wrong across that band and the columns/rows next to it + /// (`68x192 cq35 8-bit: frame 1 plane Y: 145 pixels differ, first at row 0 + /// col 64`, mass in columns 64..67). r9 bisected it stage by stage against + /// the instrumented aomdec on that exact stream: + /// * `EC_AV1_PREFILT_DUMP` frame 1 is BYTE-IDENTICAL over the cropped + /// 68 columns -- reconstruction and inter prediction are exact, so the + /// charter's "MC reads past the crop" hypothesis is refuted a second time. + /// * `EC_AV1_POSTDEBLOCK_DUMP` with `EC_AV1_DEBUG_SKIP_CDEF=1` also matches + /// aomdec's own post-deblock dump (which is 72 columns wide, i.e. it + /// exposes the straddling band) -- the deblock, including its + /// `frame_width` clip, is correct. + /// * The divergence therefore enters in CDEF, at the last 8x8 CDEF block + /// column/row, which is the one that straddles the crop edge. + /// `#[ignore]` so the suite stays green; run it with + /// `cargo test -p ec-av1 --lib -- --ignored a_frame_edge_straddling_band`. + #[test] + #[ignore = "open r9 defect: CDEF at the last straddling 8x8 block column/row"] + fn a_frame_edge_straddling_band_decodes_pixel_exact() { + edge32_gate( + "a_frame_edge_straddling_band_decodes_pixel_exact", + false, + ); + } + fn edge32_gate(name: &str, flat_band: bool) { let NAME = name; let _gate_lock = lock_gate_counters(); @@ -18888,6 +18915,18 @@ mod tests { // The inter arm: >= 4 frames so the 32-level edge path in the INTER // tile walk is exercised too. arms.push((192, 80, 5, false)); + // lane-golomb r9: the straddling-band arms, only under the ignored + // `a_frame_edge_straddling_band_decodes_pixel_exact` name (they are + // RED -- see that test's own comment for the stage bisection). Naming + // them here rather than in a second copy of this gate keeps the + // recipe, the counters and the refusal handling identical. + if name == "a_frame_edge_straddling_band_decodes_pixel_exact" { + arms.clear(); + arms.push((192, 68, 5, false)); + arms.push((192, 68, 5, true)); + arms.push((68, 192, 5, false)); + arms.push((68, 192, 5, true)); + } // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is // vacuous, panicking or red -- each measured this round with // `arms.push((192, 68, 5, false))`, log diff --git a/lanes/golomb-r9.report.md b/lanes/golomb-r9.report.md new file mode 100644 index 00000000..be6dd510 --- /dev/null +++ b/lanes/golomb-r9.report.md @@ -0,0 +1,100 @@ +# lane-golomb r9 -- the straddling-band defect is CDEF, and a stream-data PANIC is now a refusal + +## What changed + +* `crates/ec-av1/src/decode.rs` `neighbour_filter` -- returns `Result` and refuses + "an OBMC neighbour whose switchable interp filter was never recorded" instead of handing the + `[3, 3]` sentinel to `mc::from_switchable_symbol`, which `panic!`s on any value above 2. + Both call sites (`build_obmc_prediction`'s above and left passes) already sat inside a + `Result` function and take `?`. +* `crates/ec-av1/src/refusal_inventory.rs` -- the new refusal string pinned. +* `crates/ec-av1/src/decode.rs` `deblock_plane` -- new `EC_AV1_DEBLOCK_TRACE_V` rung: the + per-edge `x0/y0/len/level` of the vertical pass plus one line per plane with the loop's real + `tw`/`th`/`stride` vs `true_*`/crop bounds. That rung is what settled the deblock question below. +* `crates/ec-av1/src/stream.rs` -- `a_frame_edge_straddling_band_decodes_pixel_exact`, an + `#[ignore]`d pinned test that runs `edge32_gate`'s exact recipe over the four straddle arms + (192x68 and 68x192, 5 frames, 8-bit and 10-bit, cq 35..61), with `EC_GATE_VERBOSE` naming. + +## TASK A -- root cause narrowed to CDEF, stage by stage (fix NOT landed) + +Stream: `~/.cache/golomb-tmp/s68.obu`, md5 `45722b0fb7f1707a18e0547cc7a59fa2`, produced by +`edge32_gate`'s own aomenc recipe at 68x192 cq35 8-bit, 5 frames. + +| stage | ours vs instrumented aomdec, frame 1 | +| --- | --- | +| reconstruction (`EC_AV1_PREFILT_DUMP`) | **0 luma pixels differ** over the cropped 68 columns | +| post-deblock (`EC_AV1_POSTDEBLOCK_DUMP`, `EC_AV1_DEBUG_SKIP_CDEF=1`) | **matches**, including columns 68..71 | +| final output vs ffmpeg | 145 luma differ, mass in columns 64..67 | + +So inter prediction is exact and the charter's "the MC reference read runs past the crop" +hypothesis is refuted a second time (r8 refuted it at the libaom source; r9 refutes it by +measurement: our returned `Picture` is already cropped to `frame_width`, so `mc::sample` clamps +at column 67 exactly as `extend_plane` does). The deblock is also exact -- `frame_width` is the +right clip, confirmed against libaom `set_lpf_parameters`' `if ((width <= x) || (height <= y))` +early-out on `plane_ptr->dst.width`, which is the crop width; forcing the mi-rounded bound +instead made frame 0 RED (17 luma px, columns 65..67), so r7's clip stays. + +The divergence therefore enters in **CDEF**, at the last 8x8 CDEF block column (mi column 17, +pixels 64..71) -- the one block that straddles the crop edge. Frame 0 survives it and frame 1 +does not, which is why every earlier round read the shape as "inter". + +Two instrument facts a successor needs: +* aomdec's `EC_AV1_POSTDEBLOCK_DUMP` is **72 columns wide** (mi-rounded) while its + `EC_AV1_PREFILT_DUMP` is cropped to 68 -- the post-deblock rung is the only one that exposes + the straddling band on the reference side. +* our own `EC_AV1_POSTDEBLOCK_DUMP` is emitted from a site that, on this path, runs **after** + `apply_cdef`: `od.f0` and `odnc.f0` (same run, `EC_AV1_DEBUG_SKIP_CDEF=1`) differ in columns + 68..71 although `EC_AV1_WATCH`-instrumented `filter_edge` performs no write there. Always pair + that dump with `EC_AV1_DEBUG_SKIP_CDEF=1`, or the CDEF defect reads as a deblock defect -- + which cost r9 six rounds of the budget. + +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 + +## TASK B -- the panic is gone + +Before: `192x68 cq40` aborted the process in `mc.rs:203`. After: + +``` +$ decode_probe s40.obu +REFUSED: unsupported: AV1 tile (an OBMC neighbour whose switchable interp filter was never recorded) +``` + +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)` + +Sweep of the other aborts reachable from a desynced stream (`decode.rs` + `mc.rs`), each checked +against the value's own domain: + +* `mc.rs:203` `from_switchable_symbol` -- FIXED at its only reachable caller. The other caller + (`resolve_interp_filter`) reads a 3-symbol CDF (`switchable_interp: [[u16; 4]; 16]`, + `nsyms = cdf.len() - 1`), so it cannot produce a 4th symbol. +* `mc.rs:220` `from_header(Switchable)` -- header enum, not a per-block stream value; callers + resolve `Switchable` before calling. Left. +* `decode.rs:3259` `default_intra_tx_type` -- the mode comes from a 13-symbol CDF and all 13 + values have a row. Bounded, left. +* `decode.rs:13936`/`14114` `partition_w8` and `decode.rs:15352` `read_single_ref` -- values from + 4-symbol / bounded-return helpers. Bounded, left. +* `decode.rs:11673/11692/11739` -- guarded by `rect_inter_residual_supported`, which is itself a + named refusal. Left. +* `decode.rs:11324`, `12091`, `12110`, `12147`, `15660`, `2745` -- block-size / tx-size domain + invariants, not stream values. Left. +* `decode.rs:2498` `ref_hits` -- a test-side counter accessor, never on the decode path. Left. +* the non-test `.unwrap()`/`.expect()` in `decode.rs` (5280, 5324, 6085, 6152, 7352/7353, + 7819/7820, 10535, 10591, 10735, 10944) are each dominated by a push/refusal a few lines above. + Left, listed here so the next sweep does not re-derive it. + +## TASK C -- arms + +`a_frame_edge_straddling_band_decodes_pixel_exact` carries all four straddle arms and is +`#[ignore]`d, which is the only honest shape while the CDEF defect is open: an arm that is RED +cannot join the green gate, and the r8 handoff's "measured, arm not added" comment is now a +runnable test instead of prose. + +fix-now residue, NOT done this round: +* deferred(the CDEF straddle fix) -- the `--enable-restoration=1` arm at 192x68 that would gate + r8's cropped-plane loop-restoration fix. `edge32_gate`'s arm tuple has no per-arm flag slot and + every straddle recipe is RED regardless, so the LR arm would be vacuous today; it unblocks the + moment the CDEF fix lands. This is the same `refusal-lifted-without-a-gate` shape r8 flagged. + +## Suite + +`cargo test -p ec-av1 --lib` -> see `$HOME/.cache/golomb-suite-r9.log` (totals in the round report line).