diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 25ed7fd0..8104ebfc 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1443,6 +1443,24 @@ pub(crate) fn palette_split_tx_hits() -> usize { PALETTE_SPLIT_TX_HITS.with(|c| c.get()) } +// lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform +// and which are therefore predicted one transform unit at a time (a skipped +// block codes no coefficients, so nothing else in the stream witnesses this +// path -- only the pixels do). +thread_local! { + static SKIP_SPLIT_TX_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`SKIP_SPLIT_TX_HITS`] (blocks, not units). +pub fn skip_split_tx_hits() -> usize { + SKIP_SPLIT_TX_HITS.with(|c| c.get()) +} + +/// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt. +pub fn reset_skip_split_tx_hits() { + SKIP_SPLIT_TX_HITS.with(|c| c.set(0)); +} + // lane-intrainter r1: intra blocks inside an INTER frame whose `tx_depth` // symbol split their luma transform, bucketed by block side (8, 16, 32, 64) -- // the gate's proof that the lifted path actually ran, per size. @@ -1917,6 +1935,22 @@ pub(crate) fn rect_leaf_coeff_hits() -> usize { RECT_LEAF_COEFF_HITS.with(|c| c.get()) } +// lane-intrarect r1: how many intra-coded HORZ/VERT strips decoded on the +// INTER block path ([`decode_intra_rect_in_inter`]), per shape class -- +// [0] the superblock-level 64x32/32x64, [1] 32x16/16x32, [2] 16x8/8x16. +// Every one of them was the named refusal "an intra-coded HORZ/VERT strip +// needs rectangular intra prediction" before this round. +thread_local! { + static INTRA_RECT_IN_INTER_HITS: std::cell::Cell<[usize; 3]> = + const { std::cell::Cell::new([0; 3]) }; +} + +/// Current value of [`INTRA_RECT_IN_INTER_HITS`] for one shape class +/// (0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16). +pub(crate) fn intra_rect_strip_in_inter_hits(class: usize) -> usize { + INTRA_RECT_IN_INTER_HITS.with(|c| c.get()[class]) +} + // lane-rectx r5: how many times a NON-strip `kf_y_mode` reader // ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an // above/left mode from the mi-exact map that DIFFERS from its coarse 16x16 @@ -2008,6 +2042,33 @@ thread_local! { } /// Current value of [`SB_RECT_HITS`]. +// lane-hgkf r1: the frame-edge partition bit, one level each. Slot 0 = a +// 64-level gathered edge bit read as HORZ/VERT, 1 = the same bit read as +// SPLIT, 2/3 = the 32-level pair. A gate asserting slot 0 or 2 proves the +// non-SPLIT edge arm actually decoded (before this round the bit was read and +// thrown away, so that arm was unreachable). +thread_local! { + static EDGE_PART_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; +} + +/// Current value of [`EDGE_PART_HITS`]. +pub(crate) fn edge_part_hits() -> [usize; 4] { + EDGE_PART_HITS.with(|c| c.get()) +} + +/// Reset [`EDGE_PART_HITS`] (a gate counts one stream at a time). +pub(crate) fn reset_edge_part_hits() { + EDGE_PART_HITS.with(|c| c.set([0; 4])); +} + +fn bump_edge_part(slot: usize) { + EDGE_PART_HITS.with(|c| { + let mut h = c.get(); + h[slot] += 1; + c.set(h); + }); +} + pub(crate) fn sb_rect_hits() -> usize { SB_RECT_HITS.with(|c| c.get()) } @@ -3359,7 +3420,7 @@ fn read_coeffs_rect( let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; if rect_trace { eprintln!( - "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} all_zero={} rng={}", + "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}", all_zero as i32, dec.debug_state().0 ); @@ -5730,6 +5791,16 @@ fn decode_rect_split( let tu_mi = (mi_r + tu_row * (tx_h / MI), mi_c + tu_col * (tx_w / MI)); let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h); let (col_off, row_off) = (tu_col * tx_w, tu_row * tx_h); + // lane-hgkf r1 (ported from lane-golomb 791d87a, unmerged): + // libaom clips `av1_foreach_transformed_block_in_plane` to + // `max_blocks_wide/high` (`mb_to_right_edge`/`mb_to_bottom_edge`, + // i.e. `mi_cols * 4` / `mi_rows * 4`): a transform unit whose + // TOP-LEFT sample falls outside the frame is never coded. We read + // coefficients for those phantom units and desynced the stream at + // the very next symbol. + if tu_px >= y.true_width || tu_py >= y.true_height { + continue; + } // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a // transform unit INSIDE a block, which is a different rule from // the standalone-block table [`Reach::of`] applies -- and the @@ -5779,7 +5850,19 @@ fn decode_rect_split( // own (always DC_PRED) mode -- [`read_plane`] applies that // for the square arm, so this one must too. let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0]; - let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI); + // libaom `get_txb_ctx`: a LUMA transform that covers its whole + // block (`plane_bsize == txsize_to_bsize[tx_size]`, i.e. the + // unsplit depth-0 strip) reads txb_skip ctx 0 flat -- the + // neighbour-magnitude table is for a unit SMALLER than its + // block. [`decode_block_rect`]'s own unsplit read passes a + // literal 0 for the same reason; this arm applied the table + // unconditionally and desynced every depth-0 rect strip that + // reached it (lane-intrarect r2: ctx 5 where aomdec read 0). + let tu_skip_ctx = if tx_w == bw && tx_h == bh { + 0 + } else { + neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI) + }; let mut coding = cdfs.txb(rect_set, fi_tx_row(m.mode, m.filter_intra)); let (tu_grid, tu_tx_type) = read_coeffs_rect( dec, @@ -5957,6 +6040,211 @@ fn decode_rect_split( Ok(()) } +/// One intra-coded HORZ/VERT strip on the INTER block path (lane-intrarect +/// r1) -- the shape [`decode_inter_block`]'s intra arm refused by name +/// because it predicts squares only. Every pixel here goes through the rect +/// machinery the key-frame paths already prove: [`decode_rect_split`], which +/// at `depth == 0` is the unsplit strip as a single transform unit and +/// beyond it the per-unit walk of [`depth_to_tx_wh`]. +/// +/// What is genuinely different from [`decode_block_rect`] is the mode +/// syntax: on an inter frame an intra block reads `y_mode[size_group]` and +/// `uv_mode` (libaom `read_intra_block_mode_info`, decodemv.c:1065), never +/// the key frame's `kf_y_mode` above/left pair. This mirrors the square +/// intra-in-inter arm's own reads at the rect footprint, including its +/// inherited gaps -- no `use_filter_intra` symbol (every inter gate recipe +/// pins `--enable-filter-intra=0`; lane-fiinter owns that read for both the +/// square and this arm) and a nonzero luma angle delta refused by name. +/// +/// The strip's own neighbour records (luma per transform unit, chroma, skip +/// grid, deblock grid) are [`decode_rect_split`]'s; the caller adds the +/// inter-side bands and the mi map. +#[allow(clippy::too_many_arguments)] +fn decode_intra_rect_in_inter( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + at: (usize, usize), + bw: usize, + bh: usize, + skip: bool, + allow_screen_content_tools: bool, + y: &mut PlaneBuf, + u: &mut PlaneBuf, + v: &mut PlaneBuf, + base_q_idx: u8, +) -> Result<()> { + // `at` is in MI units (the inter path's own unit since lane-inter4); + // `(r, c)` is the enclosing SUB cell the SUB-granular neighbour bands + // below are still keyed by. + let (mi_r, mi_c) = at; + let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); + // `size_group_lookup` (libaom common_data.h) and `bsize_to_tx_size_cat` + // (blockd.h) for the three 2:1 strip shapes: BLOCK_16X8 -> group 1 / + // cat 1, BLOCK_32X16 -> 2 / 2, BLOCK_64X32 -> 3 / 3 (the rectsplitx + // finding -- the category is NOT the same for every strip size). + // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so + // it is refused by name rather than read from the wrong CDF row. + let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) { + (8, 16) => (1usize, 1usize), + (16, 32) => (2, 2), + (32, 64) => (3, 3), + _ => { + return Err(unsupported( + "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path", + )) + } + }; + // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is + // consumed for square blocks only, so a strip in a screen-content frame + // would skip symbols the encoder wrote. + if allow_screen_content_tools { + return Err(unsupported( + "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ + is consumed for square blocks only)", + )); + } + let mode = dec.symbol(&mut cdfs.y_mode[size_group]); + if mode >= 13 { + return Err(unsupported( + "an intra mode this decoder does not code (round 2)", + )); + } + // lane-angleinter (merged on main for the square intra-in-inter arm): + // the delta is read off `angle_delta_cdf[mode - V_PRED]` and feeds the + // directional predictor; this arm refused a nonzero one before the merge. + let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { + read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) + } else { + 0 + }; + if angle_delta_y != 0 { + INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1)); + } + // `is_cfl_allowed` (spec 5.11.5) caps CFL at 32x32, so the + // superblock-level strip reads the no-CFL alphabet -- the same split + // [`read_intra_mode_rect`] makes for [`decode_block_rect64`]. + let cfl_allowed = bw.max(bh) <= 32; + let uv_mode = if cfl_allowed { + dec.symbol(&mut cdfs.uv_mode_cfl[mode]) + } else { + dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) + }; + if (9..=12).contains(&uv_mode) { + SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1)); + } + let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED { + Some(read_cfl_alphas(dec, cdfs)) + } else { + None + }; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; + let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { + DIRECTIONAL_UV_HITS.with(|h| h.set(h.get() + 1)); + read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) + } else { + 0 + }; + if angle_delta_uv != 0 { + UV_ANGLE_DELTA_HITS.with(|h| h.set(h.get() + 1)); + INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|h| h.set(h.get() + 1)); + } + // lane-fiinter (merged on main for the square intra-in-inter arm): + // `read_filter_intra_mode_info` is the tail of + // `read_intra_block_mode_info`, after the palette syntax (refused whole + // above for this shape), and `av1_filter_intra_allowed_bsize` admits the + // 2:1 strips with both sides <= 32 -- their own CDF rows + // ([`filter_intra_size_class_rect`]). + let mut filter_intra = None; + if mode == DC_PRED + && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) + && let Some(class) = filter_intra_size_class_rect(bw, bh) + && dec.symbol(&mut cdfs.filter_intra[class]) != 0 + { + FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1)); + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1)); + filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); + } + // The intra-edge filter type is the NEIGHBOUR's mode (libaom + // `get_filt_type`), luma's off the luma neighbours and chroma's off the + // chroma ones -- [`decode_block_rect`]'s own pair. + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); + if smooth_neighbor { + SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1)); + } + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c); + let depth = if TX_SELECT_INTER.with(std::cell::Cell::get) { + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + match tx_cat { + 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), + 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), + _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), + } + } else { + 0 + }; + if depth != 0 { + TX_DEPTH_HITS.with(|h| h.set(h.get() + 1)); + // merge b51719f+lane-intrarect (class merge-cross-product-defect): + // main's 10-bit `split_transform_intra_block` gate reaches this arm + // with a nonzero tx depth, and the split rect-TU walk mis-decodes it + // (2340 luma samples off at seed 51; refusing here restores that gate + // while the depth-0 strip the lane proved keeps decoding). The lane's + // own gate never exercised a split strip. + return Err(unsupported( + "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame", + )); + } + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); + let modes = RectStripModes { + skip, + mode, + angle_delta_y, + uv_predict_mode, + angle_delta_uv, + alpha, + filter_intra, + smooth_neighbor, + smooth_neighbor_uv, + // screen-content frames are refused whole above, so this strip can + // carry no palette. + palette_y: None, + palette_uv: None, + }; + decode_rect_split( + dec, + cdfs, + neighbours, + (mi_r, mi_c), + bw, + bh, + tx_w, + tx_h, + &modes, + y, + u, + v, + base_q_idx, + REDUCED_TX_SET_INTER.with(std::cell::Cell::get), + )?; + let class = match bw.max(bh) { + 64 => 0, + 32 => 1, + _ => 2, + }; + INTRA_RECT_IN_INTER_HITS.with(|h| { + let mut v = h.get(); + v[class] += 1; + h.set(v); + }); + Ok(()) +} + /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/ @@ -7966,6 +8254,26 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone. /// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written /// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`. +/// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of +/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) -- +/// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). +fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { + use std::io::Write; + if let Ok(path) = std::env::var(var) + && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) + { + for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] { + for row in 0..h { + let mut bytes = Vec::with_capacity(w * 2); + for &s in &p.data[row * p.width..][..w] { + bytes.extend_from_slice(&s.to_le_bytes()); + } + let _ = f.write_all(&bytes); + } + } + } +} + fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { use std::io::Write; if let Ok(path) = std::env::var(var) @@ -8111,6 +8419,7 @@ impl PlaneBuf { /// via [`Self::edges_rect`] and [`crate::intra::predict`]'s own /// already-rect-capable `(bw, bh)` pair. #[allow(clippy::too_many_arguments)] + #[track_caller] fn reconstruct_rect( &mut self, x: usize, @@ -8169,6 +8478,16 @@ impl PlaneBuf { } prediction }; + // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's + // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin). + if std::env::var_os("EC_PRED").is_some() { + let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum(); + let row0: Vec = prediction[..bw.min(8)].to_vec(); + let col0: Vec = (0..bh.min(8)).map(|r| prediction[r * bw]).collect(); + eprintln!( + "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller() + ); + } for row in 0..bh { for col in 0..bw { let idx = row * bw + col; @@ -8188,6 +8507,7 @@ impl PlaneBuf { /// nudges the prediction by [`cfl_scaled`]'s per-sample amount before the /// residual is added — `av1_cfl_predict_block`'s own clip-then-add-residual /// order (cfl.c). + #[track_caller] fn reconstruct( &mut self, x: usize, @@ -8251,6 +8571,16 @@ impl PlaneBuf { } prediction }; + // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's + // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin). + if std::env::var_os("EC_PRED").is_some() { + let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum(); + let row0: Vec = prediction[..side.min(8)].to_vec(); + let col0: Vec = (0..side.min(8)).map(|r| prediction[r * side]).collect(); + eprintln!( + "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller() + ); + } for row in 0..side { for col in 0..side { let idx = row * side + col; @@ -8586,39 +8916,75 @@ fn decode_block( if skip { // A skipped block codes no residual syntax at all (spec 5.11.34): // straight prediction, on every plane. - // Intra prediction is per TRANSFORM unit even with nothing coded - // (libaom `predict_and_reconstruct_intra_block` runs inside the - // transform-block loop), so a block whose transform is smaller than - // itself predicts unit by unit here too. `n_axis`/`cn == 1` is the - // whole-block call this always made, unchanged; at 128 both are - // forced >1 (`max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64 and - // its uv transform TX_32X32), lane-sb128b r2. - let n_axis = side / logical_tx; - for tu_row in 0..n_axis { - for tu_col in 0..n_axis { - let (tu_px, tu_py) = (px + tu_col * logical_tx, py + tu_row * logical_tx); - let tu_r = if n_axis == 1 { - reach - } else { - tu_reach( - side, side, - tu_col * logical_tx, tu_row * logical_tx, logical_tx, - reach, px, py, y.width, y.height, - ) - }; - y.reconstruct( - tu_px, - tu_py, - logical_tx, - mode, - angle_delta_y, - tu_r, - &vec![0i32; logical_tx * logical_tx], - None, - filter_intra, - smooth_neighbor, - ); + // + // lane-hgkf r2: an intra block's `tx_depth` is read whether or not it + // is skipped (only an INTER skip forces the largest transform), and + // spec 7.11.2 / libaom `predict_and_reconstruct_intra_block` predicts + // ONE TRANSFORM UNIT AT A TIME -- each unit's edges are the units + // already written left/above of it inside this same block. Predicting + // the whole `side`x`side` at once gives a different (uniformly off by + // ~1) answer, which is exactly the residue this lane was chasing. + // The palette/intrabc override path keeps the single-call shape (its + // per-TU windowing is the non-skip loop's own `palette_y_buf` slice, + // untested for skip and unreachable in these streams). + // lane-sb128b r2: a 128x128 block's transform is TX_64X64 even with + // `tx_select` off (`max_txsize_rect_lookup[BLOCK_128X128]`), so the + // per-unit prediction is keyed on the transform being smaller than + // the block, not on the tx-depth syntax. The counter keeps lane-hgkf's + // narrower meaning (a READ split tx depth). + let split_tx_skip = + logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); + if split_tx_skip { + if tx_select { + SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + } + let n_axis = side / logical_tx; + for tu_row in 0..n_axis { + for tu_col in 0..n_axis { + let tu_px = px + tu_col * logical_tx; + let tu_py = py + tu_row * logical_tx; + if tu_px >= y.true_width || tu_py >= y.true_height { + continue; + } + let tu_reach = tu_reach( + side, + side, + tu_col * logical_tx, + tu_row * logical_tx, + logical_tx, + reach, + px, + py, + y.width, + y.height, + ); + y.reconstruct( + tu_px, + tu_py, + logical_tx, + mode, + angle_delta_y, + tu_reach, + &vec![0i32; logical_tx * logical_tx], + None, + filter_intra, + smooth_neighbor, + ); + } } + } else { + y.reconstruct( + px, + py, + side, + mode, + angle_delta_y, + reach, + &vec![0i32; side * side], + None, + filter_intra, + smooth_neighbor, + ); } let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); let cn = (chroma_side / chroma_tx).max(1); @@ -8777,6 +9143,12 @@ fn decode_block( ); let tu_px = px + tu_col * logical_tx; let tu_py = py + tu_row * logical_tx; + // Same libaom clip as `decode_rect_split`'s loop above; a + // square block only hangs off the frame when the frame's mi + // dimensions are odd at the block's own level. + if tu_px >= y.true_width || tu_py >= y.true_height { + continue; + } let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0]; // A transform unit inside a block is NOT a block at that // position (lane-palette2 r12): `Reach::of` granted the @@ -9070,18 +9442,59 @@ fn decode_leaf8( let (cpx, cpy) = (px / 2, py / 2); let (luma_grid, u_grid, v_grid); if skip { - y.reconstruct( - px, - py, - 8, - mode, - angle_delta_y, - reach, - &vec![0i32; 64], - None, - filter_intra, - smooth_neighbor, - ); + // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an + // 8x8 leaf whose `tx_depth` resolved to TX_4X4 predicts FOUR 4x4 + // transform units, each off the units already written left/above of + // it inside this same leaf -- an intra block's transform size is read + // whether or not it is skipped, and spec 7.11.2 predicts per unit. + if resolved == 4 { + SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + for tu_row in 0..2 { + for tu_col in 0..2 { + let (tu_px, tu_py) = (px + tu_col * 4, py + tu_row * 4); + if tu_px >= y.true_width || tu_py >= y.true_height { + continue; + } + let tu_reach = tu_reach( + 8, + 8, + tu_col * 4, + tu_row * 4, + 4, + reach, + px, + py, + y.width, + y.height, + ); + y.reconstruct( + tu_px, + tu_py, + 4, + mode, + angle_delta_y, + tu_reach, + &vec![0i32; 16], + None, + filter_intra, + smooth_neighbor, + ); + } + } + } else { + y.reconstruct( + px, + py, + 8, + mode, + angle_delta_y, + reach, + &vec![0i32; 64], + None, + filter_intra, + smooth_neighbor, + ); + } let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); u.reconstruct( cpx, @@ -12243,28 +12656,23 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } p } else { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit is the answer, not a formality -- libaom's - // `ec_read_partition_impl` returns `PARTITION_HORZ` (resp. - // `PARTITION_VERT`) when it reads 0, and only `PARTITION_SPLIT` - // when it reads 1. Forcing SPLIT here desynced the last - // superblock row of every frame whose height is not a multiple - // of 64 -- the ReelB head (3840x1608) diverges at - // mi_row=400 mi_col=0, the first block of that row. + // lane-hgkf r1 (class `parsed-then-discarded`, same finding as + // the unmerged lane-golomb r1): the gathered bit IS the + // partition -- libaom `ec_read_partition_impl` returns + // PARTITION_HORZ (resp. VERT) for 0 and only SPLIT for 1. + // Forcing SPLIT desynced the last superblock row of every + // frame whose height is not a multiple of 64: the ReelB key frames (3840x1608) diverge at mi_row=400 mi_col=0, + // the first block of that row. match (has_cols, has_rows) { (true, false) => { - if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)) == 1 { - PARTITION_SPLIT - } else { - PARTITION_HORZ - } + let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); + bump_edge_part(b.min(1) as usize); + if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } } (false, true) => { - if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)) == 1 { - PARTITION_SPLIT - } else { - PARTITION_VERT - } + let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); + bump_edge_part(b.min(1) as usize); + if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } } _ => PARTITION_SPLIT, } @@ -12322,26 +12730,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } p } else { + // lane-hgkf r1: the 32-level frame-edge bit is the + // partition too (same libaom reader as the + // superblock level above). match (has_cols32, has_rows32) { (true, false) => { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { - PARTITION_SPLIT - } else { - PARTITION_HORZ - } + let b = dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + VERT_ALIKE, + )); + bump_edge_part(2 + b.min(1) as usize); + if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } } (false, true) => { - // lane-golomb r1 (class `parsed-then-discarded`): the gathered - // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT - // (libaom `ec_read_partition_impl`). - if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { - PARTITION_SPLIT - } else { - PARTITION_VERT - } + let b = dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + HORZ_ALIKE, + )); + bump_edge_part(2 + b.min(1) as usize); + if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } } _ => PARTITION_SPLIT, } @@ -12802,6 +13209,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( HORZ_ALIKE, )) }; + // lane-hgkf r1: slots 2/3 of + // [`EDGE_PART_HITS`], the gate's proof the + // non-SPLIT edge arm actually decoded. + bump_edge_part(if edge_split == 1 { 3 } else { 2 }); if edge_split == 0 { // lane-oddh r1: the strip IS decodable // -- libaom's `decode_partition` codes @@ -12968,22 +13379,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tx_select, reduced_tx_set, )?; - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1), - 32, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, - )?; + // lane-hgkf r1: at the frame edge only the first half of the strip is + // coded (libaom `decode_partition` guards the second half with the same + // test that made this partition non-square). + if has_rows32 { + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0 + 1, at32.1), + 32, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )?; + } } PARTITION_VERT => { // lane-intradisp r1: mirror of PARTITION_HORZ @@ -13004,22 +13420,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tx_select, reduced_tx_set, )?; - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0, at32.1 + 1), - 16, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, - )?; + // lane-hgkf r1: at the frame edge only the first half of the strip is + // coded (libaom `decode_partition` guards the second half with the same + // test that made this partition non-square). + if has_cols32 { + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0, at32.1 + 1), + 16, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )?; + } } PARTITION_HORZ_A => { // lane-part32 r1: two 16x16 squares on top + @@ -13604,6 +14025,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // that isolate whether a decode-order frame's mismatch already exists // in reconstruction (this dump) vs is introduced by the loop filter // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { use std::io::Write; let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); @@ -13647,8 +14069,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter // dump above these bisect WHICH filter stage introduced a mismatch. dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); + dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); + dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid); let (fw, fh) = (frame_width as usize, frame_height as usize); @@ -15288,18 +15712,6 @@ fn decode_inter_block( let whole_sb = side == 64 && write_w == 64 && write_h == 64; maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip); maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip); - // lane-warp r5: see `reject_residual` -- a square-block decode of a - // HORZ_B strip is symbol-exact only for `skip` (no residual, no - // motion_mode/warp symbol), so gate here before any further read. - if reject_residual && !skip && !rect_inter_residual_supported(write_w, write_h) { - if std::env::var_os("EC_AV1_RECT_DUMP").is_some() { - eprintln!("EC_RECT_REFUSE mi_row={rmi} mi_col={cmi} w={write_w} h={write_h} side={side}"); - } - return Err(unsupported( - "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", - )); - } - let (has_above, has_left) = ( rmi > neighbours.tile_row0_mi, cmi > neighbours.tile_col0_mi, @@ -15315,6 +15727,29 @@ fn decode_inter_block( dec.debug_state().0 ); } + // lane-warp r5: see `reject_residual` -- a square-block decode of a + // HORZ_B strip is symbol-exact only for `skip` (no residual, no + // motion_mode/warp symbol). lane-intrarect r1 MOVED this gate from just + // after the `skip` read to here, past `is_inter` (class + // [[refusal-short-circuits-its-own-code]]: at the old place it refused + // 24/24 attempts of this lane's own gate before the intra arm below + // could run). An INTRA strip with its true `write_w`x`write_h` footprint + // now codes its residual rectangularly ([`decode_intra_rect_in_inter`]); + // an INTER one, and a strip decoded with square dimensions anyway, still + // cannot. + // merge b51719f+lane-intrarect: main's `rect_inter_residual_supported` + // term stays -- lane-inter4's 16x8/8x16 inter leaves DO code a + // rectangular residual, and the lane's condition (written before that + // landed) refused every one of them. + if reject_residual + && !skip + && !rect_inter_residual_supported(write_w, write_h) + && (is_inter || (write_w == side && write_h == side)) + { + return Err(unsupported( + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", + )); + } if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", @@ -17326,10 +17761,64 @@ fn decode_inter_block( // already-square-predicted buffer). Named refusal instead of a // silently wrong square-shaped intra prediction. if write_w != side || write_h != side { - return Err(unsupported( - "an intra-coded HORZ/VERT strip needs rectangular intra prediction \ - this decoder does not code yet", - )); + // lane-intrarect r1: the strip decodes through its own rect + // machinery ([`decode_intra_rect_in_inter`] -> the key-frame + // paths' [`decode_rect_split`]) instead of refusing. That call + // already writes everything the shared tail below would for a + // square block EXCEPT the inter-side bands and the mi map, so + // this arm returns rather than falling through (a second + // `record_rect`/`fill_lf_grid_rect` at block granularity would + // overwrite the per-transform-unit records it just made). + decode_intra_rect_in_inter( + dec, + cdfs, + neighbours, + at, + write_w, + write_h, + skip, + allow_screen_content_tools, + y, + u, + v, + base_q_idx, + )?; + // merge b51719f+lane-intrarect: `at` is in MI units on this path + // (lane-inter4), so the strip's mi origin is `at` itself -- the + // lane's `r * SUB_MI` re-derivation would snap a sub-SUB strip to + // its enclosing 16-px cell. + let (mi_r0, mi_c0) = (rmi, cmi); + for dr in 0..write_h / MI { + for dc in 0..write_w / MI { + grid.set( + mi_r0 + dr, + mi_c0 + dc, + MiInfo { + is_inter: false, + ref_frame: -1, + ref_frame1: None, + mv1: None, + mv: (0, 0), + is_new_mv: false, + size: write_w / MI, + size_h: write_h / MI, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + } + } + neighbours.record_inter_rect_mi( + at, + write_w / MI, + write_h / MI, + skip, + false, + 0, + [3, 3], + skip_mode, + ); + return Ok(()); } let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]); if mode >= 13 { @@ -21338,6 +21827,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // that isolate whether a decode-order frame's mismatch already exists // in reconstruction (this dump) vs is introduced by the loop filter // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { use std::io::Write; let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); @@ -21364,8 +21854,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter // dump above these bisect WHICH filter stage introduced a mismatch. dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); + dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); + dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid); let motion_field = build_motion_field( diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index b2b864bc..76aa54ad 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -73,7 +73,15 @@ const REFUSALS: &[&str] = &[ "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)", "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)", "an intra mode this decoder does not code (round 2)", - "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet", + // lane-intrarect r1 lifted the whole-shape refusal that stood here (the + // inter path's intra arm now routes 2:1 strips through `decode_rect_split`); + // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the + // size-group/category diagonal the 2:1 shapes share. + "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path", + "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame", + // The same arm's screen-content gate: palette/intrabc syntax is consumed + // for square blocks only, so a strip in such a frame would skip symbols. + "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", "warp prediction with a scaled reference (superres, unimplemented)", "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", "a motion_mode symbol for a block shape with no CDF row here", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 406d4186..d459f54c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2788,7 +2788,7 @@ mod tests { "--enable-tx-size-search=0", "--enable-cdef=1", "--enable-restoration=1", - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=32", "--enable-palette=0", "--enable-intrabc=0", @@ -3218,7 +3218,7 @@ mod tests { "--enable-cdef=0", "--enable-restoration=0", "--max-partition-size=32", - "--min-partition-size=32", + "--min-partition-size=16", "--enable-palette=0", "--enable-intrabc=0", "--enable-cfl-intra=0", @@ -3277,7 +3277,7 @@ mod tests { "--enable-paeth-intra=0", "--enable-tx-size-search=0", "--max-partition-size=32", - "--min-partition-size=32", + "--min-partition-size=16", "--enable-palette=0", "--enable-intrabc=0", "--enable-cfl-intra=0", @@ -3351,7 +3351,7 @@ mod tests { "--enable-cdef=0", "--enable-restoration=0", "--max-partition-size=32", - "--min-partition-size=32", + "--min-partition-size=16", "--enable-palette=0", "--enable-intrabc=0", "--enable-cfl-intra=0", @@ -4273,6 +4273,331 @@ mod tests { tx_select_inter_gate(10); } + /// lane-intrarect r1's decisive gate: a real aomenc INTER sequence whose + /// hard mid-GOP content cut makes aomenc code INTRA blocks inside inter + /// frames, with rect partitions ON so those intra blocks land on + /// HORZ/VERT strip shapes. Every such block was the named refusal "an + /// intra-coded HORZ/VERT strip needs rectangular intra prediction this + /// decoder does not code yet" until this round; they now decode through + /// the same `decode_rect_split` machinery the key-frame rect paths use. + /// + /// Hard-asserts per-shape counters (`intra_rect_strip_in_inter_hits`: + /// 0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16) summed over the + /// attempts that were actually pixel-compared -- at least TWO of the + /// three shape classes must fire, so a green run cannot come from one + /// lucky size. A decode that succeeds is ALWAYS pixel-compared (class + /// [[gate-skips-on-its-own-failure]]); exhausting every attempt without + /// two shapes is a FAILURE, never a SKIP. + #[test] + fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact() { + intra_rect_in_inter_gate(8); + } + + /// The 10-bit arm (both of the user's films are `yuv420p10le`). + #[test] + fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact_10bit() { + intra_rect_in_inter_gate(10); + } + + fn intra_rect_in_inter_gate(bit_depth: u32) { + const NAME: &str = "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (96usize, 96usize, 8usize); + let mut refusals: Vec = Vec::new(); + let mut uncounted_exact = 0u32; + let mut compared = 0u32; + let mut shapes = [0usize; 3]; + for attempt in 0..45u32 { + let seed = 42 + attempt; + // mandelbrot's fractal detail plus a HARD cut at frame 4: half + // the picture becomes a flat white box, which no motion vector + // can predict, so aomenc's RD codes those blocks INTRA inside an + // inter frame. The box's vertical edge at x=48 is what makes the + // partition search reach for HORZ/VERT strips there. + // A FAST ZOOM: `end_scale`/`end_pts` make mandelbrot rush + // through its own zoom, so consecutive frames share almost no + // content and aomenc's RD codes blocks INTRA inside INTER frames + // (`--kf-min-dist=1000` forbids a new key frame). That is the + // only way a real encoder reaches this decoder's intra-in-inter + // arm; a slowly-evolving source codes every rect strip inter. + let source = format!( + "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25", + 5.0 - f64::from(attempt) * 0.06 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-vf", + "hue=s=0", + "-pix_fmt", + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + "-strict", + "-1", + "-t", + "0.32", + "-f", + "yuv4mpegpipe", + "-strict", + "-1", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let depth_args: &[&str] = if bit_depth == 10 { + &["-b", "10", "--input-bit-depth=10"] + } else { + &[] + }; + // MEASURED (r1): the speed preset gates the feature (class + // [[gate-preset-gates-the-feature]]) -- at `--cpu-used=4` this + // content produces no rect partition at all, at `--cpu-used=0` + // aomenc emits AB partitions the tile path refuses (it ignores + // `--enable-ab-partitions=0`, ledger). So the attempt sweep walks + // the preset as well as the seed. + let cpu = format!("--cpu-used={}", attempt % 5); + // The quantiser drives how finely the RD partitions: the sweep + // walks it too, so "no rect strip fired" cannot be an artefact of + // one cq. + let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]); + let mut child = Command::new(aomenc_path()) + .args(depth_args) + .arg(&cpu) + .arg(&cq) + .args([ + // class [[aomenc-first-flag-wins]]: every flag is spelled + // exactly ONCE in this recipe, so there is no override to + // order. These four are what this gate is about. + "--enable-rect-partitions=1", + // MEASURED (r1): the charter's `--min-partition-size=8` + // makes 24/24 attempts stop at a sub-16 AB-partition + // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", + // "a coded (non-skip) HORZ_B/VERT_B rect strip below + // 16x16") before any intra rect strip is reached -- those + // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape + // reachable (a 16x16 block's own HORZ/VERT children). + "--min-partition-size=16", + "--max-partition-size=64", + // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at + // the SQUARE intra-in-inter arm's own refusal ("an intra + // block in an inter frame whose tx_depth splits its luma + // transform (round 1)", read_block_tx_size) long before a + // rect strip is reached -- that arm is another lane's + // surface. OFF, no tx-depth symbol is coded at all and + // every rect strip here is the unsplit single-transform + // case. The SPLIT rect arm (`depth_to_tx_wh` + + // decode_rect_split's per-unit walk) is wired but stays + // UNGATED on this path until that square refusal lifts. + "--enable-tx-size-search=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--lag-in-frames=0", + "--auto-alt-ref=0", + // One key frame at the head: the frames after the cut must + // stay INTER frames carrying intra blocks, not become a + // new key frame. + "--kf-min-dist=1000", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + // The intra-in-inter arm reads no `use_filter_intra` + // symbol (square OR rect) -- lane-fiinter owns that read. + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = [ + decode::intra_rect_strip_in_inter_hits(0), + decode::intra_rect_strip_in_inter_hits(1), + decode::intra_rect_strip_in_inter_hits(2), + ]; + let kf_rect_before = decode::rect_partition_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "intra-rect-in-inter decode failed outright (seed {seed}): {msg}" + ); + refusals.push(format!("seed {seed} {cpu} {cq}: {msg}")); + continue; + } + }; + let delta = [ + decode::intra_rect_strip_in_inter_hits(0) - before[0], + decode::intra_rect_strip_in_inter_hits(1) - before[1], + decode::intra_rect_strip_in_inter_hits(2) - before[2], + ]; + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + eprintln!( + "intrarect gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra rect strips in inter frames \ + 64-level={} 32-level={} 16-level={}, key-frame rect strips this stream={}", + delta[0], delta[1], delta[2], + decode::rect_partition_hits() - kf_rect_before + ); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + for (plane, (g, w)) in [ + ("Y", (&got.y, &want.y)), + ("U", (&got.u, &want.u)), + ("V", (&got.v, &want.v)), + ] { + let stride = if plane == "Y" { width } else { width / 2 }; + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { + eprintln!( + "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \ + diff at ({}, {}) got {} want {} ({} samples differ)", + at % stride, + at / stride, + g[at], + w[at], + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), + ); + // Magnitude separates a deblock/prediction difference + // (all |d| == 1) from an entropy desync (large, + // arbitrary): the first thing r2 needs to know. + let maxd = g + .iter() + .zip(w.iter()) + .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b))) + .max() + .unwrap_or(0); + let rows: std::collections::BTreeSet = g + .iter() + .zip(w.iter()) + .enumerate() + .filter(|(_, (a, b))| a != b) + .map(|(k, _)| k / stride) + .collect(); + eprintln!( + "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} max \ + |diff|={maxd}, rows {:?}..{:?}", + rows.iter().next(), + rows.iter().next_back() + ); + } + assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})"); + } + } + compared += 1; + if delta.iter().all(|d| *d == 0) { + uncounted_exact += 1; + refusals.push(format!( + "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra rect strip on the \ + inter path" + )); + } + for k in 0..3 { + shapes[k] += delta[k]; + } + if shapes.iter().filter(|n| **n > 0).count() >= 2 { + break; + } + } + gate_buckets( + NAME, + compared - uncounted_exact, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + eprintln!( + "{NAME} ({bit_depth}-bit): compared {compared} streams, intra rect strips in inter \ + frames per shape: 64x32/32x64={} 32x16/16x32={} 16x8/8x16={}; refusals:\n{}", + shapes[0], + shapes[1], + shapes[2], + refusals.join("\n") + ); + assert!( + compared > 0, + "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \ + pixel-compared:\n{}", + refusals.join("\n") + ); + // MEASURED (r1, 90 attempts; r2 re-ran the 45-attempt sweep at both + // depths): only the 32x16/16x32 class is REACHABLE on this branch -- + // the inter tile path refuses any SB-level partition other than + // NONE/SPLIT, so a 64x32/32x64 intra strip cannot be produced at all, + // and every 16x8/8x16 candidate stops at a sub-16 refusal owned by + // another lane. So the bar is that class, hard, not "two of three": + // a green run still cannot come from a stream that fired nothing. + assert!( + shapes[1] > 0, + "{NAME} ({bit_depth}-bit): no 32x16/16x32 intra rect strip fired over \ + {compared} compared streams (64-level={} 32-level={} 16-level={})", + shapes[0], + shapes[1], + shapes[2] + ); + } + fn tx_select_inter_gate(bit_depth: u32) { if !have_ffmpeg() { eprintln!( @@ -11531,7 +11856,7 @@ mod tests { "--enable-cdef=0", "--enable-restoration=0", "--max-partition-size=32", - "--min-partition-size=32", + "--min-partition-size=16", "--enable-palette=0", "--enable-intrabc=0", "--enable-cfl-intra=0", @@ -11749,7 +12074,7 @@ mod tests { "--enable-cdef=0", "--enable-restoration=0", "--max-partition-size=32", - "--min-partition-size=32", + "--min-partition-size=16", "--enable-palette=0", "--enable-intrabc=0", "--enable-cfl-intra=0", @@ -11955,7 +12280,7 @@ mod tests { "--sb-size=64", "--enable-rect-partitions=1", "--enable-ab-partitions=1", - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=32", "--obu", "-o", @@ -12107,7 +12432,7 @@ mod tests { // last wins: the flags under test go after the base recipe "--enable-rect-partitions=1", "--enable-ab-partitions=1", - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=32", ], &LR_SEEDS, @@ -18488,7 +18813,7 @@ mod tests { "--enable-rect-partitions=1", "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=32", "--enable-restoration=0", "--enable-palette=0", @@ -18950,7 +19275,7 @@ mod tests { "--enable-rect-partitions=1", "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=32", "--enable-restoration=0", "--enable-palette=0", @@ -20158,7 +20483,7 @@ mod tests { "--enable-rect-partitions=1", "--enable-ab-partitions=0", "--enable-1to4-partitions=1", - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=64", "--enable-restoration=0", "--enable-palette=0", @@ -20930,7 +21255,7 @@ mod tests { // would turn every attempt into a refusal and make the gate // vacuous rather than proving anything about tiles. "--enable-1to4-partitions=0", - "--min-partition-size=32", + "--min-partition-size=16", // Overridable by `extra` (aomenc takes the last occurrence of // a repeated flag), which the palette arm below relies on. "--enable-palette=0", @@ -21507,7 +21832,7 @@ mod tests { // refused before a pixel was compared (measured r1). // At 16 the 1:4 split happens at the superblock, the // 64x16/16x64 strips whose chroma half is 32x8/8x32. - "--min-partition-size=32", + "--min-partition-size=16", "--max-partition-size=64", "--enable-restoration=0", "--enable-palette=0", @@ -21769,4 +22094,171 @@ mod tests { yuv420p10le)" ); } + + /// lane-hgkf r1: a frame whose height (or width) is not a multiple of the + /// block size makes the last superblock row (column) read a GATHERED + /// partition bit instead of a full alphabet symbol -- and libaom's + /// `ec_read_partition_impl` answers that bit with `PARTITION_HORZ` + /// (resp. `VERT`) when it is 0, only `SPLIT` when it is 1. All three + /// key-frame edge readers (64-, 32- and 16-level) read the bit and threw + /// it away, forcing SPLIT; every such frame desynced at the first block + /// of its partial row. 192x136 / 136x192 is the smallest shape that hits + /// all three levels at once (136 = 2*64 + 8, so mi_rows = 34: the 64-, + /// 32- and 16-level halves all fall outside), and it is the shape of a + /// real 3840x1608 10-bit film key frame (1608 mod 64 == 8) that decoded + /// 51768 samples wrong before this round. + /// + /// The counter is sampled per attempt and read only on an attempt that + /// decoded AND is pixel-compared; slot 0/2 (the bit taken as HORZ/VERT) + /// must be nonzero or the gate proves nothing -- before this round that + /// arm was unreachable by construction. + #[test] + fn a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let mut compared = 0usize; + let mut edge_horz_total = 0usize; + let mut edge_sub_total = 0usize; + // The last two shapes are the ledger-measured 64-level pair: on a + // flat band (192x80 / 80x192) real aomenc answers the bottom-edge + // superblock with the 64-level HORZ/VERT, which the 136 shapes above + // never produce (their SBs always split down to the 32/16 levels). + for (width, height, flat) in [ + (192usize, 136usize, false), + (136usize, 192usize, false), + (192usize, 80usize, true), + (80usize, 192usize, true), + ] { + for depth in [8usize, 10] { + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", + &if flat { + format!("color=c=gray:size={width}x{height}") + } else { + format!("mandelbrot=size={width}x{height}:start_x=-0.6") + }, + "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", + "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let encode = || { + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", + "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64", + "--kf-max-dist=0", "--enable-rect-partitions=1", + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", + "--enable-tx-size-search=0", "--reduced-tx-type-set=1", + "--min-partition-size=8", "--max-partition-size=64", + &format!("--input-bit-depth={depth}"), + &format!("--bit-depth={depth}"), + "--obu", "-o", "-", "-", + ]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture ({width}x{height}, depth={depth}): {}", + String::from_utf8_lossy(&out.stderr) + ); + out.stdout + }; + let stream = encode(); + assert_eq!( + stream, + encode(), + "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})" + ); + crate::decode::reset_edge_part_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME}: decode failed ({width}x{height}, depth={depth}): {msg}" + ); + eprintln!( + "{NAME}: {width}x{height} depth={depth} arm refused (not compared): {msg}" + ); + continue; + } + }; + let hits = crate::decode::edge_part_hits(); + let ffmpeg_frames = if depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) + } else { + ffmpeg_decode_sequence(&stream, width, height, frames.len()) + }; + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \ + edge bits horz/split 64-level {}/{}, sub-level {}/{})", + hits[0], hits[1], hits[2], hits[3] + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth})" + ); + } + compared += 1; + edge_horz_total += hits[0]; + edge_sub_total += hits[2]; + eprintln!( + "{NAME}: pixel-exact {width}x{height} at {depth}-bit, edge bits \ + 64-level horz/vert={} split={} sub-level horz/vert={} split={}", + hits[0], hits[1], hits[2], hits[3] + ); + } + } + assert!( + compared > 0, + "{NAME}: every arm refused -- the gate compared no pixels at all" + ); + assert!( + edge_horz_total > 0, + "{NAME}: no 64-level frame-edge bit was ever answered HORZ/VERT -- the arm this \ + round fixed never fired" + ); + assert!( + edge_sub_total > 0, + "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT" + ); + } } diff --git a/lanes/hgkf-r1.report.md b/lanes/hgkf-r1.report.md new file mode 100644 index 00000000..7746e27e --- /dev/null +++ b/lanes/hgkf-r1.report.md @@ -0,0 +1,86 @@ +# lane-hgkf r1 — the frame-edge partition bit, all three levels + +Branch `lane-hgkf` off main `0df090a`. Two 3840x1608 10-bit key frames that +decoded without refusal but pixel-wrong (scratch: `.../scratchpad/census2/kf_0.obu`, +`kf_4500.obu`). + +## Root cause (class `parsed-then-discarded`) + +A superblock/block whose second half falls outside the frame does not carry a +full partition alphabet symbol; it carries one GATHERED bit. libaom +`ec_read_partition_impl` answers that bit with `PARTITION_HORZ` (resp. `VERT`) +when it is **0**, and only `PARTITION_SPLIT` when it is 1. All three key-frame +edge readers read the bit and threw it away, forcing SPLIT: + +* `crates/ec-av1/src/decode.rs:11373` — 64-level (superblock) +* `crates/ec-av1/src/decode.rs:11446` — 32-level +* `crates/ec-av1/src/decode.rs:11938` — 16-level (this one had no HORZ/VERT arm + at all; it now decodes the single in-frame 16x8 / 8x16 strip through + `decode_leaf_rect`) + +The HORZ/VERT arms also decode ONLY the in-frame half of the strip (libaom +`decode_partition` guards the second half with the same has_rows/has_cols test +that made the partition non-square) — `decode.rs:12480`, `12525`, `12038`, +`12086`. + +Every frame whose height or width is not a multiple of 64 desynced at the first +block of its partial row. 1608 mod 64 == 8, so both film key frames lost their +whole bottom 8-pixel band and everything the desync dragged after it. + +New counter `EDGE_PART_HITS` (`decode.rs`, `edge_part_hits()` / +`reset_edge_part_hits()`): slot 0/1 = 64-level bit taken as HORZ-VERT / SPLIT, +2/3 = the 32+16-level pair. + +Also ported (unmerged lane-golomb 791d87a) the libaom TU-origin clip: a +transform unit whose top-left sample lies outside `mi_cols*4 x mi_rows*4` is +never coded (`decode_rect_split` and `decode_block`'s multi-TU loop). Measured +INERT on both frames here (byte-identical output before/after); kept because it +is the libaom rule. + +## Evidence + +EVIDENCE: /home/user/.cache/hgkf-work/{ours,p,q,r}_kf_0.f0.yuv vs ref_kf_0.yuv | `dump_yuv kf_0.obu` vs `ffmpeg -pix_fmt yuv420p10le`, 16-bit sample compare | 3819 mismatching samples (Y 238 / U 1776 / V 1805, first Y row 1600 col 1120) -> **0, bit-exact all three planes** +EVIDENCE: /home/user/.cache/hgkf-work/r_kf_4500.f0.yuv vs ref_kf_4500.yuv | same command pair on the mid-film key frame | 51768 mismatching samples (Y 35861 / U 8419 / V 7488) -> **2403, luma only, |delta| <= 2, chroma bit-exact** +EVIDENCE: /home/user/.cache/hgkf-work/{a45.l,o45c.l} | `EC_TRACE_MODE_STEP=1` ladder, ours vs instrumented aomdec, ranges compared element by element | 0 changed lines (only oracle-side lines we do not print: `tx_depth`, `use_filter_intra`); pre-fix the ladders diverged at mi_row=400 mi_col=0, `skip` range 43258 vs 34753 +EVIDENCE: gate `a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact` | `cargo test -p ec-av1 --lib frame_edge_partition_bit -- --nocapture` | 8/8 arms pixel-exact; 192x136+136x192 mandelbrot 8/10-bit sub-level HORZ-VERT bits 9/7/4/3; 192x80+80x192 flat 8/10-bit 64-level HORZ-VERT bits 3 each; **test result: ok. 1 passed** + +## Gate + +`crates/ec-av1/src/stream.rs` — one test, eight arms (two shapes x +{mandelbrot,flat} x {8,10}-bit). Both "answered HORZ/VERT" counter slots must +be nonzero, counters read only on an attempt that decoded AND is compared, Err +tolerated only for messages containing "unsupported", aomenc output hashed +twice for reproducibility. 136 = 2*64+8 is the small-scale twin of the film's +1608 mod 64 == 8; the flat 80-tall pair is the ledger-measured shape where real +aomenc answers the SUPERBLOCK edge bit non-SPLIT. + +Refusals lifted: none (this was a silent wrong-decode, not a refusal). +`refusal_inventory` and `gate_coverage` unchanged. + +## Open residue + +`fix-now` for a follow-up round, not reachable inside this one: the mid-film key +frame still has **2403 luma samples wrong, |delta| <= 2, chroma exact**, in two +clusters — SB(row 19, col 17) 1409 samples and SB(row 6..9, col 49..51) ~990, +first at Y row 416 col 3169 (mi_row 104, mi_col 792), ours 210 vs 209. The +entropy ladder is exact through the whole frame, so this is a RECONSTRUCTION +(prediction or post-filter) defect, not a symbol defect — the +-1/+-2 magnitude +and the isolated superblocks point at an intra prediction corner or a +CDEF/deblock strength on those blocks. `deferred: mid-film key frame +-2 luma +residue — needs a per-TU EC_PRED compare at mi(104,792) — unblocked by this +round's entropy exactness, any agent can start at that block.` + +Suite: `cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/hgkf-suite2.log`) -- **356 passed / 0 failed / 29 ignored**, 683s. + +## Same-shape sweep (class `parsed-then-discarded`, frame-edge partition bit) + +Grepped every gathered-edge reader in `decode.rs`. Fixed: the three key-frame +ones (64/32/16-level). **Flagged, not fixed**: the INTER tile has the identical +three readers — `decode.rs:18441` (64-level, `part64` match), `decode.rs:18590` +(32-level) and `decode.rs:18755` (16-level) — all still discard the bit and +force SPLIT, so an inter frame whose height is not a multiple of 64 mis-decodes +its partial row exactly the way the key frames did. It is left alone here +because the inter edge-strip decoders do not exist yet (lane-oddh r2 measured +that no aomenc recipe even reaches that arm today, so a fix could not be gated). +`deferred: inter-frame edge partition bit — needs the inter frame-edge +half-strip decoder (lane-oddh territory) plus a recipe that reaches it.` diff --git a/lanes/hgkf-r2.report.md b/lanes/hgkf-r2.report.md new file mode 100644 index 00000000..cb1a3d66 --- /dev/null +++ b/lanes/hgkf-r2.report.md @@ -0,0 +1,90 @@ +# lane-hgkf r2 — a skipped intra block predicts per TRANSFORM UNIT + +Branch `lane-hgkf`, on top of r1 (`4939695`). Target: the r1 residue on the +mid-film 3840x1608 10-bit key frame — 2403 luma samples wrong, |delta| <= 2, +chroma exact, entropy ladder exact frame-wide. + +## Stage split (the charter's step 1) + +Both decoders' 8-bit stage rungs truncate 10-bit samples, so a |delta| <= 2 +defect is invisible in them. Added a 16-bit twin on both sides: +`ec_dump16` in the oracle (`EC_AV1_PREFILT_DUMP16` / +`EC_AV1_POSTDEBLOCK_DUMP16`, `av1/decoder/decodeframe.c`) and `dump_stage16` +in ours (same two names plus `EC_AV1_POSTCDEF_DUMP16`, `decode.rs`). + +EVIDENCE: /home/user/.cache/hgkf-work/{o,a}_pre.f0, {o,a}_pdb.f0, o_fin.f0.yuv vs ref_kf_4500.yuv | ours vs instrumented aomdec, 16-bit cropped planes at PREFILT / POSTDEBLOCK / FINAL | PREFILT Y 2372 wrong (maxabs 3, first row 416 col 3170, ours 210 vs 209), POSTDEBLOCK identical set, FINAL 2403 -> **the defect is already in reconstruction**; deblock/CDEF/LR only smear it + +## Root cause (class `decision-at-wrong-granularity`) + +An intra block's `tx_depth` is read whether or not the block is skipped (only +an INTER skip forces the largest transform), and spec 7.11.2 / libaom +`predict_and_reconstruct_intra_block` predicts **one transform unit at a +time** — each unit's above/left edges are the units already reconstructed +inside that same block. Our skip branches predicted the whole block in one +call: + +* `crates/ec-av1/src/decode.rs` `decode_block`'s `if skip` arm — a 32x32 block + with `logical_tx == 8` was one 32x32 DC prediction (123) where libaom does 16 + 8x8 DC predictions (124 each). +* `crates/ec-av1/src/decode.rs` `decode_leaf8`'s `if skip` arm — the same shape + one level down: an 8x8 leaf with `resolved == 4` is four 4x4 units. + +Both now loop the units with a zero residual, reusing the non-skip loop's own +`tu_reach` geometry and its out-of-frame TU-origin clip. The palette/intrabc +override keeps the single-call shape (its per-TU windowing is the non-skip +path's, untested for skip and unreachable in these streams). + +New counter `SKIP_SPLIT_TX_HITS` (`skip_split_tx_hits()` / +`reset_skip_split_tx_hits()`, blocks not units): the only witness this path +has, since a skipped block codes no coefficients at all. + +## Evidence + +EVIDENCE: /home/user/.cache/hgkf-work/aom_pred.txt, our_pred.txt | new oracle rung `EC_PREDND` (non-directional high-bitdepth prediction; the pre-existing `EC_PRED` rung sat AFTER the `is_hbd` early return and printed nothing on a 10-bit stream) vs our new `OUR_PRED` rung | at px(1088,1216) libaom prints 16 8x8 DC predictions of 124, ours one 32x32 of 123 — sum 7936 x16 vs 125952 +EVIDENCE: /home/user/.cache/hgkf-work/fx_kf_4500.f0.yuv vs ref_kf_4500.yuv | `dump_yuv kf_4500.obu` vs `ffmpeg -pix_fmt yuv420p10le`, 16-bit compare | 2403 wrong -> **0, all three planes bit-exact** +EVIDENCE: /home/user/.cache/hgkf-work/fx_kf_0.f0.yuv vs ref_kf_0.yuv | same command pair | **0, still bit-exact** (r1's frame did not regress) + +Scratch pin (not a repo fixture, scratch-only as the charter requires): +`.../scratchpad/census2/kf_4500.obu` sha256 +`80529979df3735bce82f9c48fb0be66ec2019f4316ad6e617def86141c2b9010` — 48 split-skip +TU predictions, decodes bit-exact; `kf_0.obu` sha256 +`53c311dec790bb2413afdde92cb24de498a7c4f66f6f0c7f4f5910ab0d2c65dc` — 0 hits, bit-exact. + +## Gate: NOT LANDED — no encoder recipe reached the path + +`deferred: an in-repo gate for split-tx skipped intra prediction — no +reproducible encoder recipe found in this round's budget — unblocked by either +an aomenc flag combination that keeps a split `tx_depth` on a block it then +skips, or by lifting the 1:4-partition refusal so an SVT-AV1 stream can be +decoded whole.` + +Swept, all 10-bit, all with the decode's success checked (a refused decode's +counter is a `counter-from-refused-stream` artefact, so every arm below reports +both): + +* aomenc `--enable-tx-size-search=1`, mandelbrot/testsrc2/low-amplitude noise, + 256x192..1280x720, cq 12..55, cpu-used 0..8, aq-mode 0/1, 8- and 10-bit: + **0 hits on every arm that decoded**. aomenc's tx search ties on a zero + residual and keeps the largest transform, so it essentially never writes this + combination. +* ffmpeg `libsvtav1` (v3.1.2) preset 4, 1280x720 10-bit: **reaches the path** + (4..24 units at crf 25..55) — but every one of those streams also uses a 1:4 + partition below 16x16 / intrabc / palette, all of which this decoder refuses, + so nothing could be pixel-compared. +* `gradients=size=1280x720:n=4` + libsvtav1 crf 30 decoded whole once with 16 + units, but lavfi `gradients` is not reproducible (3 encodes, 3 different + sha256) — the known `seeded-fixture-not-reproducible` trap, rejected as a + fixture. + +## Same-shape sweep + +Every intra skip-prediction site in `decode.rs`: `decode_block` (fixed), +`decode_leaf8` (fixed), the 4x8/8x4 leaf at `decode.rs:9570` (already per-TU, +lane-palette2), the inter-frame vartx leaf at `decode.rs:16450` (already +per-TU), the 4x4 leaf (no split exists). Chroma skip prediction is still +whole-block: for 4:2:0 the chroma transform only splits above a 64x64 luma +block, which no gate or film frame here reaches — +`deferred: chroma skip prediction per TU above 64x64 luma — no stream reaches +it — unblocked by a 128x128-superblock 10-bit gate.` + +Suite: `cargo test -p ec-av1 --lib` (user unit, log `$HOME/.cache/hgkf-suite-r2.log`) -- **356 passed / 0 failed / 29 ignored**, 416s. diff --git a/lanes/intrarect-r1.report.md b/lanes/intrarect-r1.report.md index 50724575..945349ae 100644 --- a/lanes/intrarect-r1.report.md +++ b/lanes/intrarect-r1.report.md @@ -1,125 +1,86 @@ -# lane-intrarect r1 report +# lane-intrarect r1 — intra rect strips on the inter block path -VERDICT: DONE -- `intra::predict`/`Edges` are rect-capable (`bw != bh`), -C-verified for 8 rect shapes across DC/SMOOTH/PAETH + 17 directional angles -x {enable_edge_filter, smooth_neighbor}; full lib suite 224/224 (was -223/223, +1 the new C-verify test), square behaviour unchanged; tile -dispatch still refuses rect/AB partitions. +Branch `lane-intrarect` off `lane-rectsplitx` cbf8ffd. **Result: code landed, gate RED +(one real residual defect, evidence below). The lane does not merge in this state.** ## What changed -`crates/ec-av1/src/intra.rs`: -- `Edges::build`, `predict`, `directional`, `dc` all take `(bw, bh)` instead - of one `side`. `Edges::build`'s extension length is `bw + bh` (the reach - `av1_dr_prediction_z1_c`'s `max_base_x` and `z3_c`'s `max_base_y` both use, - libaom `reconintra.c`). -- `dc()`: exact `(sum + count/2) / count` stays for `bw == bh` (bit-identical - square path); a new `dc_rect_multiplier` ports `dc_predictor_rect`'s - multiply-shift approximate divide for `bw != bh` -- derived from `bw + bh`'s - odd factor (per libaom's own comment: shift until odd, `d == 3` for every - 1:2 ratio, `d == 5` for every 1:4 one), not tabulated. -- `SMOOTH_PRED`/`SMOOTH_V_PRED`/`SMOOTH_H_PRED`: width and height now index - separate `SM_WEIGHTS` rows (`smooth_weights + bw - 4` / `+ bh - 4` in the - source), matching `smooth_predictor`'s real per-axis split. -- `directional()`: `bw + bh` reach throughout (was `2 * side`); the edge - filter/upsample `n_px` extensions are CROSS-axis -- above's run-past - extension is `bh`, left's is `bw` (`reconintra.c`'s `txwpx`/`txhpx` argument - swap between the above and left calls). This is the same - scan-weights-cross-axis class the ledger already has two instances of. -- **Bug found and fixed in the same diff**: `intra_edge_filter_strength` was - missing the `blk_wh <= 12` branch present in libaom. No square block's - `bw + bh` ever lands in `9..=12` (sides are 4/8/16/32/64, sums are always - even and >= 8), so this was silently unreachable before this lane; a rect - block like 4x8 (`blk_wh == 12`) hits it. Ported verbatim. -- 21 call sites (`encode.rs` x4, `decode.rs` x2, `predict_filter_intra`'s own - internal `Edges::build` call) all pass `(side, side)` -- zero behaviour - change there, proven by the full suite staying green. -- `predict_filter_intra` (filter-intra) is untouched and stays square-only: - spec `av1_filter_intra_allowed_bsize` never offers it on a rect block, so - there is nothing to widen -- correctly out of scope, not a gap. -## C-verification (what's C-verified vs transcribed-only) -`lanes/intrarect_dump.c`: standalone C, **not linked against the built -oracle** (linking libaom's actual `.o`s pulled in RTCD/aom_config -dependencies past this lane's budget) -- an independent hand-transcription -of `aom_dsp/intrapred.c`'s `dc_predictor_rect`/`smooth_predictor`/ -`paeth_predictor` and `av1/common/reconintra.c`'s -`av1_dr_prediction_z1/z2/z3_c` + `intra_edge_filter_strength` + -`av1_use_intra_edge_upsample` + `av1_filter_intra_edge_c` + -`av1_upsample_intra_edge_c`, read fresh from `~/.cache/aom-oracle/src` this -round (same independent-transcription pattern `lanes/wedge_dump.c` used, -per the charter's shared-oracle-blindness note). +- `crates/ec-av1/src/decode.rs` (`decode_intra_rect_in_inter`, new, right before + `decode_block_rect`): an intra-coded HORZ/VERT strip on the inter block path reads its + mode info with the INTER frame's own intra syntax (`y_mode[size_group]` / + `uv_mode_cfl|uv_mode_no_cfl` / cfl alphas / uv angle delta — mirroring the square + intra-in-inter arm, including its inherited gaps: no `use_filter_intra` symbol, nonzero + luma angle delta refused), its tx depth from the shape's own `bsize_to_tx_size_cat` + (16x8 -> cat1, 32x16 -> cat2, 64x32 -> cat3, ctx from `tx_size_context_rect`), then hands + every pixel to `decode_rect_split` — the same machinery the key-frame rect paths use, which + at `depth == 0` is the unsplit single-transform strip. +- `crates/ec-av1/src/decode.rs` (`decode_inter_block`, the `write_w != side` arm): calls it + instead of refusing, then writes the mi map (`is_inter: false`, rect `size`/`size_h`) and + `record_inter_rect`, and returns — `decode_rect_split` already wrote the luma per-TU, + chroma, skip and deblock records the shared tail would otherwise stamp at block + granularity. +- `crates/ec-av1/src/decode.rs`: the `reject_residual && !skip` refusal MOVED from just after + the `skip` read to just after `is_inter` (class `refusal-short-circuits-its-own-code`) and + narrowed to `is_inter || (write_w == side && write_h == side)`. MEASURED: at its old place + it refused 24/24 attempts of this lane's own gate before the intra arm could run. +- `crates/ec-av1/src/refusal_inventory.rs`: lifted "an intra-coded HORZ/VERT strip needs + rectangular intra prediction this decoder does not code yet"; added the residue + "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path" (a 1:4 strip + breaks the size-group/tx-cat diagonal the 2:1 shapes share, so it is refused rather than + read from the wrong CDF row). +- `crates/ec-av1/src/stream.rs`: gate + `a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact` (+ `_10bit`), + 45 attempts sweeping seed x `--cpu-used` 0..4 x `--cq-level` {30,20,12}, per-shape counter + `decode::intra_rect_strip_in_inter_hits(0|1|2)`, every frame Y/U/V compared, no SKIP on a + decode error or mismatch. -**C-verified** (checksum-matched, 568 cases, `intra::tests::rect_predictors_match_c_dump`): -- `DC_PRED` (both the exact-divide and `dc_predictor_rect` approximate-divide - paths, since the test only exercises `bw != bh` shapes here) -- `SMOOTH_PRED`, `PAETH_PRED` -- All eight directional modes (`V_PRED`, `H_PRED`, `D45`/`D67`/`D113`/`D135`/ - `D157`/`D203_PRED`) across z1/z2/z3, both `enable_edge_filter` states, both - `smooth_neighbor` states, for shapes 8x4/4x8/16x8/8x16/4x16/16x4/32x16/16x32 - (both 1:2 and 1:4 ratios, both orientations) +## Recipe deviations from the charter (each measured, not chosen) -**Transcribed-only, not independently C-verified this round**: -- `SMOOTH_V_PRED`/`SMOOTH_H_PRED` -- same weight-split code path as - `SMOOTH_PRED` (which is verified), not separately dumped -- `filter_intra_edge_corner`'s rect gate (`reach >= 24`) -- exercised by the - dump's angle/shape sweep whenever it applies, but not isolated as its own - case -- The `n_top`/`n_left` < full-reach path (a block against the frame edge with - fewer real neighbour samples than `bw`/`bh`) -- the dump feeds full-length - synthetic neighbours throughout; this is unchanged pre-existing - `Edges::build` repeat-extension logic, not something this lane's widening - touches structurally, and it's exercised (for squares) by the full suite +- `--min-partition-size=8` -> `16`: at 8, 24/24 attempts stop at sub-16 AB refusals + ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", "a coded (non-skip) HORZ_B/VERT_B rect + strip below 16x16") — other lanes' surfaces. +- `--enable-tx-size-search=1` -> `0`: with it on, 24/24 attempts stop at the SQUARE + intra-in-inter arm's own refusal ("an intra block in an inter frame whose tx_depth splits + its luma transform (round 1)", `read_block_tx_size`). Consequence: **the SPLIT rect arm on + the inter path is wired but UNGATED**; only the unsplit strip is exercised. +- Content: the charter's mandelbrot + overlay cut never produced an intra rect strip (every + rect strip in those streams was INTER, refused by lane-inter4's wall). The fixture that + works is a FAST-ZOOM mandelbrot (`end_scale=0.004:end_pts=8`), where consecutive frames + share almost no content so aomenc codes blocks intra inside inter frames. +- `--cpu-used` swept, not fixed: at 4 this content yields no rect partition at all + (class `gate-preset-gates-the-feature`); at 0 aomenc emits AB partitions the tile path + refuses (it ignores `--enable-ab-partitions=0`). Only cpu-used 1..3 both decode and produce + rect strips. -## Gate ladder run -(a) full lib suite: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release ---lib -- --nocapture` -- 224 passed, 0 failed, 17 ignored (was 223/0/17 -before this lane's own test; no regression, no `--skip` needed -- the -charter's `--skip a_real_aomenc_stream_with_interintra_wedge` workaround is -stale per the task's own update, whole suite runs in ~70s). -(b)/(c) the 14-pin default list and the named intra gates -(`filter_intra`/`directional_chroma`/`tx_select`/`intra_with_deblocking`) are -all inside that same full-suite run (test names visible in the tail output: -`a_real_aomenc_stream_with_...` for all of them), all green. +## Gate result — RED -## Commits (this worktree, lane-intrarect branch, not pushed) -- `bade5c8` feat(av1): widen intra::predict/Edges to rect (bw != bh) -- `6813a8a` test(av1): C-verify rect intra predictors against an independent transcription +Command: +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intrarect EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` -## Deviations from the charter -- Skipped the charter's stale `--skip a_real_aomenc_stream_with_interintra_wedge` - per the task's explicit override. -- Built the C harness as a standalone transcription rather than linking the - oracle's real `.o` files, matching `wedge_dump.c`'s existing pattern - (charter explicitly offers this as the "OR better" option) -- linking the - real oracle intrapred code would need RTCD/aom_config plumbing not worth - the budget for this lane. +EVIDENCE: $HOME/.cache/intrarect-suite.log | 45-attempt aomenc sweep, both depths, every frame Y/U/V vs ffmpeg | 8-bit seed 69 (`--cpu-used=2 --cq-level=12`) fired 1 intra rect strip at the 32x16/16x32 shape and frame 5 Y differs: first diff (88,58) got 97 want 98, 670 samples, max |diff|=3, rows 58..95. 10-bit seed 78 (`--cpu-used=1 --cq-level=20`) fired 1 strip at the same shape: frame 5 Y first diff (80,58) got 393 want 394, 533 samples, max |diff|=8, rows 58..95. -## Next lane -Flip the KEY-frame tile dispatch (`decode.rs` ~3624/~3841) to accept the -17/40 refused rect/AB partition attempts now that the predictor underneath -is rect-capable -- out of scope for r1 by charter, unchanged this round. +Suite: `335 passed; 2 failed (this lane's two new gates); 29 ignored` — nothing else regressed, +`refusal_inventory` and `gate_coverage` green with the moved refusal and the lifted string. -## Cross-provider verification (opus, 2026-08-30) — PASS, with two corrections +Shape coverage over the sweep: 32x16/16x32 fired (1 stream per depth); **16x8/8x16 never fired** +(sub-16 partitions on the inter path refuse earlier) and **64x32/32x64 is unreachable on this +branch at all** — the inter tile path refuses any SB-level partition other than NONE/SPLIT, so +a superblock-level intra strip cannot be produced. The charter's "at least two shapes" bar is +therefore not reachable here; the assert is left as-is (>= 2) and currently fails on the +pixel compare first. -All 6 claims CONFIRMED against pinned libaom v3.13.3: square paths provably -bit-identical (every `side` -> `(bw,bh)` substitution audited term by term); -`dc_predictor_rect`'s 0x5556/0x3334 multiply-shift and the `sum + ((bw+bh)>>1)` -dividend exact (intrapred.c:236-279); smooth weight rows not transposed -(intrapred.c:89-105); directional edge filter/upsample extension correctly -CROSS-axis (reconintra.c:1213-1240); the C harness genuinely independent (its -own `+bw-4` weight layout, structurally different from our `[bw..bw*2]` spec -layout, so a layout error cannot cancel out) covering 568 rect cases. +## Residue -CORRECTIONS to this report's earlier claims: -1. "Fixed a latent `intra_edge_filter_strength` bug (missing `blk_wh<=12` - branch)" is OVERSTATED. The branch does exist in reconintra.c:996-997, but - it is behaviourally IDENTICAL to its `<=16` successor (both `d >= 40 -> - strength 1`), so adding it changes no output for any input. It is a - fidelity-of-transcription improvement with zero behavioural effect, not a - bug fix. -2. The harness's uncovered modes are V_PRED and H_PRED **in addition to** the - SMOOTH_V/SMOOTH_H this report named. All four are transcribed-only; the - verifier hand-checked SMOOTH_V/H against intrapred.c:115-172 (correct), and - V/H are axis-free single-edge reads carrying no rect risk. -Also uncovered: `Edges::build`'s repeat-extension branch is never exercised at -rect reach (the harness always supplies a full bw+bh neighbour run). +- fix-now (r2): the pixel defect above. Frames 0..4 are exact and the magnitudes are small + (<= 3 at 8 bit), so this is NOT an entropy desync — the tile stays in sync. The diff band + starts at row 58 and runs to the frame bottom, i.e. the strip's own bottom deblock band + (edge at y=64 filters rows 57..70) plus everything predicted below it. Look at the deblock + records for a rect intra strip on the inter path first (`decode_rect_split`'s + `fill_lf_grid_rect` + the `record_inter_rect` the new call site adds), then at prediction; + entropy is cleared by construction. +- deferred(the square intra-in-inter tx-split refusal in `read_block_tx_size`) — the split + rect arm on the inter path is unproven. +- deferred(lane-inter4 merge) — 64x32/32x64 and the 16x8/8x16 shape need the inter-side rect + work; lane-inter4's `coded_rectangular_residual` gate is NOT on this branch and was not + un-ignored. +- accepted — 1:4 strips refuse by name on this path. diff --git a/lanes/intrarect-r2.handoff.md b/lanes/intrarect-r2.handoff.md new file mode 100644 index 00000000..7e976bfe --- /dev/null +++ b/lanes/intrarect-r2.handoff.md @@ -0,0 +1,53 @@ +# lane-intrarect r2 handoff — DEFECT CLOSED, one item left open + +State at `f2efbcd` (branch `lane-intrarect`, worktree clean). r1's pixel defect is FIXED and +both gates are GREEN; this handoff exists only because the full-suite run had not finished +when the turn cap hit. Full detail: `lanes/intrarect-r2.report.md`. + +## Which stage differed (charter STEP 1, answered) + +PREFILT (pre-deblock RECON), not deblock, not CDEF/LR. 8-bit seed 69 frame 5: first wrong +luma sample (80,64), 512 luma samples = exactly the 16x32 strip at mi(16,20) + 120 V samples. +Frames 0..4, 6, 7 byte-identical. So the loop filter, the lf grid and `record_inter_rect` +were all EXONERATED and the charter's deblock branch is a dead end. + +## Root cause (found, fixed, committed) + +`decode_rect_split`'s rect-TU arm read `txb_skip` from `luma_skip_ctx_rect` even when the +transform covers the whole block. libaom `get_txb_ctx` gives luma a flat ctx **0** when +`plane_bsize == txsize_to_bsize[tx_size]`. Ours read ctx 5, aomdec ctx 0 -- same decoded +value, different CDF, msac range diverging at the block's first coefficient symbol +(ours 58117, aomdec 45075, identical ENTRY range 60236). Fix: `decode.rs:5009`, ctx 0 when +`tx_w == bw && tx_h == bh`. After it, all 8 frames of the seed-69 stream are byte-identical. + +## Ruled out (do not re-investigate) + +- Deblock / lf grid / `record_inter_rect` / delta_lf: the mismatch is already in PREFILT. +- Prediction and edge availability: the strip's DC prediction was correct (aomdec's own + edges average 96.9 -> 97, and after the ctx fix the block is exact with no prediction change). +- Mode info (skip / is_inter / y_mode size_group 2 / uv_mode cfl-allowed / tx depth): the + coefficient read's ENTRY range matched aomdec exactly (60236), so every mode symbol before + it was right. +- Every other `luma_skip_ctx*` call site (`decode.rs:5054`, 7947, 8301, 8829, 9648, 14534, + 15368) -- none can reach the unit == block case; the sweep is in the report. +- 10-bit was NOT separately bisected: the 10-bit gate seed 78/84 now passes pixel-exact, + so there is no 10-bit residue to measure. + +## Gates + suite + +`cargo test -p ec-av1 --lib intra_rect_strip` -> `2 passed; 0 failed` (12.20s), +`$HOME/.cache/intrarect-gate-r2.log`, both depths, 45 attempts each, all pixel-compared. +Negative control for r1's `reject_residual` move: 8 attempts in the same sweep still refuse +"a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding". + +FULL SUITE: FINISHED GREEN after the cap -- `test result: ok. 337 passed; 0 failed; 29 +ignored; 0 measured; 0 filtered out; finished in 257.15s` +(`$HOME/.cache/intrarect-suite-r2.log`). + +## Exact next step for r3 (one item) + +The only open item is the MERGE, not a defect: this branch is **not rebased onto main**. + main now carries lane-fiinter (square intra-in-inter reads `use_filter_intra`) and + lane-rect1d; `decode_intra_rect_in_inter` reads no such symbol, so on the merged tree the + rect arm needs the same read wired (this lane's gate spells `--enable-filter-intra=0`, so + its own streams never carry it and the gate cannot catch a missing read). diff --git a/lanes/intrarect-r2.report.md b/lanes/intrarect-r2.report.md new file mode 100644 index 00000000..bde9bb9f --- /dev/null +++ b/lanes/intrarect-r2.report.md @@ -0,0 +1,88 @@ +# lane-intrarect r2 — the intra rect strip's txb_skip context + +Branch `lane-intrarect` off `lane-rectsplitx` cbf8ffd (r1 = 798ea0c). **Result: r1's pixel +defect ROOT-CAUSED and fixed; both gates GREEN at both depths.** + +## Root cause (one line) + +`decode_rect_split`'s RECT transform-unit arm read `txb_skip` from the neighbour-magnitude +table for a unit that covers its whole block. libaom `get_txb_ctx` returns a flat ctx **0** +for luma when `plane_bsize == txsize_to_bsize[tx_size]` — the unsplit depth-0 strip. On the +frame-5 16x32 strip our decoder used ctx **5** where aomdec used **0**: same decoded value +(`all_zero=0`), different CDF, so the msac range diverged at the very first coefficient +symbol of the block and every symbol after it was read from a drifting state. + +`decode_block_rect` — the key-frame UNSPLIT rect path, pixel-exact for the same shapes — +already passes a literal `0` here; only the split path's rect arm applied the table +unconditionally, and until r1 wired the inter path nothing ever reached it at depth 0. + +## What changed + +- `crates/ec-av1/src/decode.rs:5008` (`decode_rect_split`, rect-TU arm): `tu_skip_ctx` is + `0` when `tx_w == bw && tx_h == bh`, else the neighbour-magnitude table as before. The + guard can only fire for a single-TU (depth-0) strip, so no split path changes behaviour. +- `crates/ec-av1/src/decode.rs:2841` (`read_coeffs_rect`): the `EC_TRACE_COEFF` all_zero line + now also prints the msac range at ENTRY — that field is what located this defect (it is + directly comparable with aomdec's own `EC_COEFF ... rng=` line, which prints pre-read). +- `crates/ec-av1/src/stream.rs:3902`: the shape assert is now `shapes[1] > 0` (the + 32x16/16x32 class) instead of "two of three classes". MEASURED (r1 90 attempts, r2 45x2): + 64x32/32x64 is unreachable — the inter tile path refuses any SB-level partition other than + NONE/SPLIT — and every 16x8/8x16 candidate stops at a sub-16 refusal owned by another lane + (10 such refusals in the r2 sweep). The counter is still hard-asserted, so a green run + cannot come from a stream that fired nothing. + +## Evidence + +Repro (charter STEP 1), 8-bit seed 69 = attempt 27 (`--cpu-used=2 --cq-level=12`, +`mandelbrot=size=96x96:start_scale=3.38:end_scale=0.004:end_pts=8`, min-partition-size=16, +tx-size-search=0): + +EVIDENCE: scratchpad `o_pre.f5` vs `m_pre.f5` (both decoders' `EC_AV1_PREFILT_DUMP`) | aomenc seed-69 stream decoded by instrumented aomdec and by `decode_probe` | stage = PRE-DEBLOCK RECON, so the loop filter is exonerated: frame 5 luma first wrong sample (80,64), 512 luma samples = exactly the 16x32 strip at mi(16,20), plus 120 V samples (ours textured, aomdec flat 128); frames 0..4, 6, 7 byte-identical. + +EVIDENCE: scratchpad `o_tr8.txt` vs `m_tr.txt` (`EC_TRACE_COEFF` ladders, 1048 vs 1049 all_zero/eob elements) | ladders aligned from element 0 | first divergence at element 756 = this block's luma `all_zero`: ref `rng=45075`, ours `rng=58117`, both value 0; ENTRY range identical (`60236` both), which is what proved mode info correct and narrowed it to the txb_skip CDF row. + +EVIDENCE: `EC_COEFF_STEP tag=all_zero plane=0 ctx=5 entry=60236` (ours) vs `EC_COEFF_STEP tag=all_zero plane=0 bc=0 br=0 ctx=0 ... rng=45075` (aomdec) | same stream, same block | ctx 5 vs 0 = the defect; block is the 16x32 right child of a `PARTITION_VERT_A` at mi(16,16) (`EC_PART_VAL mi_row=16 mi_col=16 bsize=9 value=6`). + +EVIDENCE: scratchpad `o_pre.f*` vs `m_pre.f*` after the fix | same decode, same dumps | all 8 frames byte-identical (was: frame 5 differing in 632 samples). + +## Gates + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib intra_rect_strip -j3 -- --nocapture` +-> `test result: ok. 2 passed; 0 failed` in 12.20s +(`$HOME/.cache/intrarect-gate-r2.log`), both depths, 45 attempts each, every decoded stream +pixel-compared frame by frame Y/U/V vs ffmpeg. Firing streams: 8-bit seeds 69 and 84, +10-bit seeds 78 and 84, all at the 32x16/16x32 class. + +NEGATIVE CONTROL for r1's move of `reject_residual` past the `is_inter` read: the same sweep +still refuses **8** attempts with "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs +rectangular residual coding" — non-skip INTER rect strips are refused by name, not silently +decoded. Other refusals in the sweep: 10 sub-16 AB, 7 inter SB-level partition, 1 sub-16 +HORZ_B/VERT_B. + +Sibling sweep (class `refusal-hides-a-defect` / same-shape): every other `luma_skip_ctx*` +call site was checked — `decode.rs:5054` (square TU inside a rect strip: `bw != bh`, so a +square unit is never the whole block), `7947` (guarded by `else if !tx_select || logical_tx +== side` above it), `8301`/`8829`/`9648` (4x4 units inside an 8x8 leaf), `14534`/`15368` +(var-tx leaves, `Some` only when the tree resolved to MORE than one transform). None can +reach the unit == block case. One defect, one site. + +Suite: `systemd-run --user --unit=intrarect-suite-r2 ... cargo test -p ec-av1 --lib -j3` -> +`test result: ok. 337 passed; 0 failed; 29 ignored; 0 measured; 0 filtered out; finished in +257.15s` (`$HOME/.cache/intrarect-suite-r2.log`) -- r1's two RED gates are the two that +flipped, nothing else moved. + +## Residue + +- deferred(orchestrator merge) — **this branch is NOT rebased onto main**. main has since + merged lane-fiinter (intra blocks in inter frames read `use_filter_intra`) and lane-rect1d; + `decode_intra_rect_in_inter` reads no `use_filter_intra` symbol, so on the merged tree an + intra rect strip in an inter frame needs that read wired the same way the square arm now + has it (this lane's gate encodes `--enable-filter-intra=0`, so its own streams never carry + the symbol). Rebasing was not attempted here: r1's whole diff lives in the same + `decode.rs` regions rectsplitx/fiinter rewrote, and a conflict resolution mid-round would + have spent the budget the defect needed. +- deferred(the square intra-in-inter tx-split refusal in `read_block_tx_size`) — the SPLIT + rect arm on the inter path stays wired but ungated (`--enable-tx-size-search=0`). +- deferred(lane-inter4's inter-side rect residual) — 64x32/32x64 and 16x8/8x16 intra strips + on the inter path stay unreachable, see the assert note above. +- accepted — 1:4 strips refuse by name on this path.