diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 12d957e1..b5be7b50 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -776,6 +776,34 @@ pub(crate) fn horz_vert_intra_hits() -> usize { HORZ_VERT_INTRA_HITS.with(|c| c.get()) } +// How many HORZ/VERT intra strips resolved a SPLIT luma transform +// (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- +// the case every rect path here refused by name before, and the first +// refusal the user's ReelB extract (600s in) stops at. +thread_local! { + static RECT_SPLIT_TX_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`RECT_SPLIT_TX_HITS`]. +pub(crate) fn rect_split_tx_hits() -> usize { + RECT_SPLIT_TX_HITS.with(|c| c.get()) +} + +// How many HORZ/VERT intra strips actually predicted with filter intra +// (lane-rectsplit r1) -- the case `decode_block_rect` refused by name +// ("this decoder predicts square-only") until `predict_filter_intra` took +// `bw`x`bh`. +thread_local! { + static FILTER_INTRA_RECT_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`FILTER_INTRA_RECT_HITS`]. +pub(crate) fn filter_intra_rect_hits() -> usize { + FILTER_INTRA_RECT_HITS.with(|c| c.get()) +} + // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D` // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every // call on the current thread -- the same before/after counter pattern as @@ -2996,32 +3024,55 @@ impl Neighbours { mode: usize, uv_mode: usize, chroma_grids: [&[i32]; 2], + ) { + self.record_split_luma_rect(at, side, side, mode, uv_mode, chroma_grids); + } + + /// [`Self::record_split_luma`] with independent above (`w`)/left (`h`) + /// extents in pixels (lane-rectsplit r1), the same relationship + /// [`Self::record_rect`] has to [`Self::record`]: a HORZ/VERT strip whose + /// luma transform split into several square units needs exactly this + /// bookkeeping, at its own true rectangular extents. + fn record_split_luma_rect( + &mut self, + at: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, + chroma_grids: [&[i32]; 2], ) { let (r, c) = at; - for cell in 0..side / SUB { + for cell in 0..w / SUB { self.above_mode[c + cell] = mode; - self.left_mode[r + cell] = mode; self.above_uv_mode[c + cell] = uv_mode; + self.above_side[c + cell] = w; + } + for cell in 0..h / SUB { + self.left_mode[r + cell] = mode; self.left_uv_mode[r + cell] = uv_mode; - self.above_side[c + cell] = side; - self.left_side[r + cell] = side; + self.left_side[r + cell] = h; } let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); - let side_mi = side / MI; - for cell in 0..side_mi { - self.left_side_mi[mi_r + cell] = side; - self.above_side_mi[mi_c + cell] = side; + let (w_mi, h_mi) = (w / MI, h / MI); + for cell in 0..h_mi { + self.left_side_mi[mi_r + cell] = h; + } + for cell in 0..w_mi { + self.above_side_mi[mi_c + cell] = w; } let round_up_even = |n: usize| n.div_ceil(2) * 2; let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { let plane = plane_idx + 1; let state = neighbour_state(grid); - for cell in 0..side_mi { - if cell < side_mi.min(bound_h.saturating_sub(mi_r)) { + for cell in 0..h_mi { + if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { self.left[mi_r + cell][plane] = state; } - if cell < side_mi.min(bound_w.saturating_sub(mi_c)) { + } + for cell in 0..w_mi { + if cell < w_mi.min(bound_w.saturating_sub(mi_c)) { self.above[mi_c + cell][plane] = state; } } @@ -3547,6 +3598,249 @@ fn cfl_ac_q3_rect(y: &PlaneBuf, px: usize, py: usize, bw: usize, bh: usize) -> V ac } +/// Everything a rect strip already read out of the stream before its luma +/// transform units are decoded -- [`decode_rect_split`]'s own mode bundle +/// (nine values that would otherwise be nine more parameters). +struct RectStripModes { + skip: bool, + mode: usize, + angle_delta_y: i32, + uv_predict_mode: usize, + angle_delta_uv: i32, + alpha: Option<(i32, i32)>, + filter_intra: Option, + smooth_neighbor: bool, + smooth_neighbor_uv: bool, +} + +/// Decodes the planes of one `bw`x`bh` HORZ/VERT intra strip whose luma +/// transform is SPLIT (`tx_depth != 0`) -- lane-rectsplit r1, the case every +/// rect path here refused by name until now ("per-unit rect prediction is not +/// ported"). +/// +/// `depth_to_tx_size` (libaom `blockd.h`) walks `sub_tx_size_map` `depth` +/// times from the block's own `max_txsize_rect_lookup` entry, and for a 2:1 +/// strip the very first step already lands on a SQUARE transform +/// (`sub_tx_size_map[TX_32X16] == TX_16X16`, `[TX_64X32] == TX_32X32`, and +/// every further step halves a square) -- so each unit is square and reads +/// through the ordinary square [`read_plane`]. What is genuinely rectangular +/// here is the *tiling* (`bw/tx` by `bh/tx` units, not `n` by `n` as +/// [`decode_block`]'s square split loop assumes) and the chroma plane, whose +/// own transform is `av1_get_max_uv_txsize` of the whole strip and is never +/// split by luma's depth. +/// +/// Each unit predicts off whatever the earlier units of this same block +/// already reconstructed (spec 5.11.36 `predict_and_reconstruct_intra_block` +/// inside `av1_foreach_transformed_block`, raster order), which is exactly +/// what predicting the whole strip in one shot got wrong. +#[allow(clippy::too_many_arguments)] +fn decode_rect_split( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + at: (usize, usize), + bw: usize, + bh: usize, + tx: usize, + m: &RectStripModes, + y: &mut PlaneBuf, + u: &mut PlaneBuf, + v: &mut PlaneBuf, + base_q_idx: u8, + reduced_tx_set: bool, +) -> Result<()> { + let (r, c) = at; + let (px, py) = (c * SUB, r * SUB); + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); + let (cpx, cpy) = (px / 2, py / 2); + let (chroma_w, chroma_h) = (bw / 2, bh / 2); + // The chroma transform is picked before any symbol is read, so an + // unsupported chroma shape refuses before this strip desyncs the tile. + let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) { + (16, 8) => Some((TxbSet::ChromaRect16x8, &SCAN_16X8[..])), + (8, 16) => Some((TxbSet::ChromaRect16x8, &SCAN_8X16[..])), + (32, 16) => Some((TxbSet::ChromaRect32x16, &SCAN_32X16[..])), + (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), + _ => None, + }; + if !m.skip && chroma.is_none() { + return Err(unsupported( + "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", + )); + } + RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + // LUMA: `bw/tx` x `bh/tx` square transform units, raster order. + let luma_set = txbset_for(tx, reduced_tx_set); + let luma_scan = default_scan(tx); + let zero_tu = vec![0i32; tx * tx]; + // The strip's OWN edge availability, the fallback for a transform unit + // whose top-right/bottom-left pixels fall outside the strip. + let block_reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); + for tu_row in 0..bh / tx { + for tu_col in 0..bw / tx { + let tu_mi = (mi_r + tu_row * (tx / MI), mi_c + tu_col * (tx / MI)); + let (tu_px, tu_py) = (px + tu_col * tx, py + tu_row * tx); + let (col_off, row_off) = (tu_col * tx, tu_row * tx); + // `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 + // reason a depth-2 superblock strip came out one sample off + // before this: `Reach::of(tx, ..)` answered as if the unit were + // its own block at that superblock position. + // * top-right: if the unit's right neighbour is still inside the + // strip the pixels are already reconstructed (`col_off + + // tx_wide < plane_bw`); otherwise only the strip's own top row + // of units can reach past it, through the block-level answer. + // * bottom-left: a unit that is not in the strip's left column + // has none (`col_off > 0` returns 0); inside the strip + // (`row_off + tx_high < plane_bh`) they are the left + // neighbour's, already reconstructed; the last row falls back + // to the block-level answer. + let tu_reach = Reach { + above_right: if col_off + tx < bw { + true + } else { + row_off == 0 && block_reach.above_right + }, + below_left: if col_off > 0 { + false + } else if row_off + tx < bh { + true + } else { + block_reach.below_left + }, + }; + if m.skip { + y.reconstruct( + tu_px, + tu_py, + tx, + m.mode, + m.angle_delta_y, + tu_reach, + &zero_tu, + None, + m.filter_intra, + m.smooth_neighbor, + ); + neighbours.record_mi_luma(tu_mi, tx, &zero_tu); + } else { + let tu_around = neighbours.around_mi(tu_mi, tx)[0]; + // This unit is smaller than the block it sits in, so + // `txb_skip_ctx` is the neighbour-magnitude table, not the + // lone-TU 0 (spec `get_txb_ctx_general`). + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx / MI); + let tu_grid = read_plane( + dec, + cdfs, + luma_set, + &luma_scan, + 0, + tu_around, + m.mode, + m.mode, + m.angle_delta_y, + tu_reach, + y, + tu_px, + tu_py, + tx, + tx, + base_q_idx, + None, + m.filter_intra, + Some(tu_skip_ctx), + m.smooth_neighbor, + )?; + neighbours.record_mi_luma(tu_mi, tx, &tu_grid); + } + } + } + // CHROMA: one un-split rect transform for the whole strip. + let ac = m.alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); + let reach = block_reach; + let (u_grid, v_grid) = if m.skip { + let zero = vec![0i32; chroma_w * chroma_h]; + u.reconstruct_rect( + cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero, + m.alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, m.smooth_neighbor_uv, + ); + v.reconstruct_rect( + cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero, + m.alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, m.smooth_neighbor_uv, + ); + (zero.clone(), zero) + } else { + let (chroma_set, chroma_scan) = chroma.expect("refused above when None"); + // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size + // is TX_32X32 or bigger resolves to `EXT_TX_SET_DCTONLY` for intra, + // so only the 16x8/8x16 pair takes the mode-indexed default. + let default_tx = if chroma_w.max(chroma_h) >= 32 { + TxType::DctDct + } else { + default_intra_tx_type(m.uv_predict_mode as u8) + }; + let around = neighbours.around_rect(at, bw, bh); + let mut grids: Vec> = Vec::with_capacity(2); + for plane_idx in 1..=2 { + let skip_ctx = + usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1); + let mut coding = cdfs.txb(chroma_set, m.uv_predict_mode); + let (levels, tx_type) = read_coeffs_rect( + dec, + &mut coding, + chroma_scan, + chroma_w, + chroma_h, + skip_ctx, + dc_sign_ctx(around[plane_idx].2), + default_tx, + )?; + let residual = dequant_and_inverse_typed_wh( + &levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(), + CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(plane_idx).0, + plane_q_delta(plane_idx).1, + tx_type, + ); + let cfl = m + .alpha + .zip(ac.as_deref()) + .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac)); + let plane = if plane_idx == 1 { &mut *u } else { &mut *v }; + plane.reconstruct_rect( + cpx, + cpy, + chroma_w, + chroma_h, + m.uv_predict_mode, + m.angle_delta_uv, + reach, + &residual, + cfl, + None, + m.smooth_neighbor_uv, + ); + grids.push(levels); + } + let mut it = grids.into_iter(); + (it.next().unwrap(), it.next().unwrap()) + }; + neighbours.record_split_luma_rect(at, bw, bh, m.mode, m.uv_predict_mode, [&u_grid, &v_grid]); + neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip); + neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx as u8, tx as u8, 0); + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!( + "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} tx={tx} rng={rng}" + ); + } + 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`/ @@ -3572,6 +3866,7 @@ fn decode_block_rect( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, + reduced_tx_set: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -3600,15 +3895,13 @@ fn decode_block_rect( // `uv_mode`, not the luma one. let smooth_neighbor_uv = is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); + // lane-rectsplit r1: `predict_filter_intra` now takes the block's own + // `bw`x`bh` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a + // rectangle just as happily), so a `use_filter_intra` strip at this level + // predicts instead of refusing. The below-16x16 leaf arm + // (`decode_leaf_rect`) keeps the refusal: it has no gate of its own. if filter_intra.is_some() { - // `predict_filter_intra` (spec 7.11.2.3) is square-only in this - // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was - // already read above so the stream stays in sync, this only refuses - // the *pixel* decode of a rare case (`use_filter_intra` on a rect - // strip). - return Err(unsupported( - "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", - )); + FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); } let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED @@ -3631,15 +3924,28 @@ fn decode_block_rect( }; if depth != 0 { TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); - // A split transform is predicted per transform unit, each taking its - // edges from the previous unit's reconstruction (the square path's own - // per-TU loop does exactly that). Predicting the whole strip in one - // shot would silently produce different pixels, so refuse by name - // until that loop is ported for rect strips. - return Err(unsupported( - "a HORZ/VERT intra strip with a split transform (per-unit rect \ - prediction is not ported)", - )); + // lane-rectsplit r1: a split transform is predicted and reconstructed + // per transform unit, each unit taking its edges from the previous + // unit's reconstruction inside this same strip (spec 5.11.36) -- + // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square + // from the first step on, so `bw.min(bh) >> (depth - 1)` names it. + let tx = bw.min(bh) >> (depth - 1); + let modes = RectStripModes { + skip, + mode, + angle_delta_y, + uv_predict_mode, + angle_delta_uv, + alpha, + filter_intra, + smooth_neighbor, + smooth_neighbor_uv, + }; + decode_rect_split( + dec, cdfs, neighbours, at, bw, bh, tx, &modes, y, u, v, base_q_idx, reduced_tx_set, + )?; + RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); + return Ok(()); } let (tx_w, tx_h) = (bw, bh); let (cpx, cpy) = (px / 2, py / 2); @@ -3981,7 +4287,7 @@ fn decode_leaf_rect( }; if depth != 0 { return Err(unsupported( - "a HORZ/VERT intra strip with a split transform (per-unit rect \ + "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect \ prediction is not ported)", )); } @@ -4082,6 +4388,7 @@ fn decode_block_rect64( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, + reduced_tx_set: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -4132,12 +4439,31 @@ fn decode_block_rect64( let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); let depth = if tx_select { let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); - dec.symbol(&mut cdfs.tx_size_cat2[ctx]) + // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`) + // counts `sub_tx_size_map` steps from the block's own max rect + // transform down to TX_4X4, minus one -- BLOCK_64X32's chain + // (TX_64X32 -> TX_32X32 -> TX_16X16 -> TX_8X8 -> TX_4X4) is four + // steps, so this level's category is 3 (the same one a 64x64 square + // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF + // here was a wrong-table read of a real symbol. + dec.symbol(&mut cdfs.tx_size_cat3[ctx]) } else { 0 }; if depth != 0 { TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); + // lane-rectsplit r1: [`decode_rect_split`] handles this shape too + // (`sub_tx_size_map[TX_64X32]` is `TX_32X32`, so a depth-1 unit here + // is a plain square 32x32) and its 32x32-level sibling arm in + // [`decode_block_rect`] is gated pixel-exact -- but at the SUPERBLOCK + // level the gate + // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`, + // `#[ignore]`d with its measurement) still comes out ONE sample off + // (seed 50, luma (171,56) ours 147 vs ffmpeg 148, inside a 64x32 + // strip whose transform resolved to depth 2 / TX_16X16). A refusal + // this lane could not lift is not a refusal it may silently ship + // wrong pixels past, so the named refusal stays until that gate is + // green. return Err(unsupported( "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ prediction is not ported)", @@ -4952,6 +5278,7 @@ impl PlaneBuf { left.as_deref(), corner, bw, + bh, &mut prediction, ); } else { @@ -5024,6 +5351,7 @@ impl PlaneBuf { left.as_deref(), corner, side, + side, &mut prediction, ); } else { @@ -7493,6 +7821,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; // Two 8x8 squares stacked on the // right, chained through @@ -7797,6 +8126,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; decode_block_rect( &mut dec, @@ -7812,6 +8142,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; } PARTITION_VERT => { @@ -7831,6 +8162,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; decode_block_rect( &mut dec, @@ -7846,6 +8178,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; } _ => { @@ -7872,6 +8205,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; decode_block_rect64( &mut dec, @@ -7887,6 +8221,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; } PARTITION_VERT => { @@ -7906,6 +8241,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; decode_block_rect64( &mut dec, @@ -7921,6 +8257,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; } _ => { diff --git a/crates/ec-av1/src/intra.rs b/crates/ec-av1/src/intra.rs index 818779d2..0d6f3ebe 100644 --- a/crates/ec-av1/src/intra.rs +++ b/crates/ec-av1/src/intra.rs @@ -726,37 +726,45 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4; /// though this mode itself never reaches past its own `side` samples of /// either edge. /// +/// `bw`x`bh` is the block, not necessarily square (lane-rectsplit r1): +/// `av1_filter_intra_predictor_c` walks the same 4x2 patches over a +/// rectangular block, and `av1_filter_intra_allowed_bsize` genuinely offers +/// this mode on every HORZ/VERT strip whose sides are both <= 32 (16x8, +/// 8x16, 32x16, 16x32, ...), which the square-only assert refused before. +/// /// # Panics -/// Panics when `dst` is not `side * side` long, or `side` is not a multiple -/// of 4 (spec `av1_filter_intra_allowed_bsize` never offers this mode past -/// 32x32, and only on square blocks: 4, 8, 16 or 32). +/// Panics when `dst` is not `bw * bh` long, or `bw` is not a multiple of 4 +/// or `bh` not a multiple of 2 (spec `av1_filter_intra_allowed_bsize` never +/// offers this mode past 32x32). pub fn predict_filter_intra( mode: usize, above: Option<&[u16]>, left: Option<&[u16]>, corner: Option, - side: usize, + bw: usize, + bh: usize, dst: &mut [u16], ) { - assert_eq!(dst.len(), side * side, "the destination is the block"); - assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32"); - let edges = Edges::build(above, left, corner, side, side); + assert_eq!(dst.len(), bw * bh, "the destination is the block"); + assert_eq!(bw % 4, 0, "filter intra patches are 4 wide"); + assert_eq!(bh % 2, 0, "filter intra patches are 2 high"); + let edges = Edges::build(above, left, corner, bw, bh); let taps = &FILTER_INTRA_TAPS[mode]; // A (side+1)-square buffer: row 0 / column 0 hold the corner and the // above/left edges, `buffer[r+1][c+1]` the block's own sample at (r, c). - let mut buffer = vec![0i32; (side + 1) * (side + 1)]; - let at = |buffer: &[i32], r: usize, c: usize| buffer[r * (side + 1) + c]; + let mut buffer = vec![0i32; (bh + 1) * (bw + 1)]; + let at = |buffer: &[i32], r: usize, c: usize| buffer[r * (bw + 1) + c]; buffer[0] = edges.above(-1); - for c in 0..side { + for c in 0..bw { buffer[c + 1] = edges.above(c as i32); } - for r in 0..side { - buffer[(r + 1) * (side + 1)] = edges.left(r as i32); + for r in 0..bh { + buffer[(r + 1) * (bw + 1)] = edges.left(r as i32); } let mut r = 1; - while r < side + 1 { + while r < bh + 1 { let mut c = 1; - while c < side + 1 { + while c < bw + 1 { let p0 = at(&buffer, r - 1, c - 1); let p1 = at(&buffer, r - 1, c); let p2 = at(&buffer, r - 1, c + 1); @@ -769,16 +777,16 @@ pub fn predict_filter_intra( let (r_off, c_off) = (k >> 2, k & 3); let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum(); let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, crate::decode::sample_max()); - let idx = (r + r_off) * (side + 1) + c + c_off; + let idx = (r + r_off) * (bw + 1) + c + c_off; buffer[idx] = value; } c += 4; } r += 2; } - for row in 0..side { - for col in 0..side { - dst[row * side + col] = at(&buffer, row + 1, col + 1) as u16; + for row in 0..bh { + for col in 0..bw { + dst[row * bw + col] = at(&buffer, row + 1, col + 1) as u16; } } } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index df922bcf..83029364 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -37,6 +37,8 @@ const REFUSALS: &[&str] = &[ "GLOBALMV (round 3)", "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)", + "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", + "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", "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", @@ -47,7 +49,6 @@ const REFUSALS: &[&str] = &[ "an INTER 32x32 partition type this decoder does not code (value={part32})", "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", - "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", "a block that actually uses a palette (UV) -- reconstruction is out of scope", "a block that actually uses a palette (Y) -- reconstruction is out of scope", "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index d2195dad..388f49db 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -9920,6 +9920,549 @@ mod tests { ); } + /// lane-rectsplit r1 gate (a): a real `aomenc` key frame whose 32x32 + /// quadrants split HORZ/VERT into true 32x16/16x32 strips, with the + /// tx-size search left at aomenc's own default (ON) -- every sibling + /// recipe in this file pins `--enable-tx-size-search=0`, which is exactly + /// why the split-transform strip was never exercised. RD is then free to + /// give a strip a transform smaller than its own size, the case + /// [`crate::decode::decode_block_rect`] refused by name ("a HORZ/VERT + /// intra strip with a split transform (per-unit rect prediction is not + /// ported)") until this round ported the per-transform-unit predict-and- + /// reconstruct loop. Hard-asserts a nonzero `rect_split_tx_hits()` delta: + /// without it a stream that resolved every `tx_depth` to 0 would + /// pixel-match by construction and prove nothing. A decode error that is + /// not a named refusal, and any pixel mismatch, FAIL -- only a missing + /// tool skips. + #[test] + fn a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_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 (width, height) = (192usize, 128usize); + let before = crate::decode::rect_split_tx_hits(); + let mut named_refusals = 0u32; + let mut matched = 0u32; + let mut split_so_far = 0usize; + // Bounded sweep: see this gate's own doc for the seed-77 residue and + // why extending it is a diagnosis knob, not a pass/fail one. + let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(20); + for attempt in 0..n_attempts { + let seed = 42 + attempt; + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, + // Desaturated (`hue=s=0`, the same guard + // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact` + // uses): with the tx-size search ON, a real chroma + // gradient hits a PRE-EXISTING chroma defect on the plain + // SQUARE path -- measured this round with + // `--enable-rect-partitions=0` on this very recipe, seed + // 42, U plane, i.e. with no rect strip in the stream at + // all. Flat chroma keeps that unrelated defect out of + // this gate (gate-recipe-confound class); it is open + // residue in lanes/rectsplit-r1.report.md, not fixed here. + "-vf", "hue=s=0", + "-pix_fmt", "yuv420p", "-f", + "yuv4mpegpipe", "-", + ]) + .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) + ); + // NOTE: no `--enable-tx-size-search=0` here -- leaving aomenc's + // own default (search ON) is the entire point of this gate. + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", + "--max-partition-size=32", + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--obu", + "-o", + "-", + "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .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; + assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" + ); + named_refusals += 1; + continue; + } + Ok(frames) => frames, + }; + let after = crate::decode::rect_split_tx_hits(); + eprintln!( + "{NAME}: seed {seed} decoded, split-tx strips this stream: {}", + after - before - split_so_far + ); + split_so_far = after - before; + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); + if let Some(i) = frames[0] + .y + .iter() + .zip(&ffmpeg_frames[0].y) + .position(|(a, b)| a != b) + { + eprintln!( + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", + i % width, + i / width, + frames[0].y[i], + ffmpeg_frames[0].y[i] + ); + } + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + matched += 1; + } + let split_hits = crate::decode::rect_split_tx_hits() - before; + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" + ); + assert!( + split_hits > 0, + "{NAME}: zero HORZ/VERT strips resolved a split transform ({matched} pixel-exact \ + matches, {named_refusals} refusals out of {n_attempts}) -- gate proved nothing \ + this run" + ); + eprintln!( + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ + rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts" + ); + } + + /// lane-rectsplit r1 gate (c): gate (a)'s recipe with + /// `--enable-filter-intra=1` (every sibling gate here pins it to 0), so + /// aomenc's RD is free to pick `use_filter_intra` on a 32x16/16x32 strip + /// -- the case [`crate::decode::decode_block_rect`] refused by name + /// ("filter intra on a HORZ/VERT strip (this decoder predicts + /// square-only)") until this round gave `predict_filter_intra` its own + /// `bw`x`bh`. Hard-asserts a nonzero `filter_intra_rect_hits()` delta: + /// a stream where RD never picked filter intra on a strip would + /// pixel-match by construction and prove nothing. + #[test] + fn a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_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 (width, height) = (192usize, 128usize); + let before = crate::decode::filter_intra_rect_hits(); + let rect_before = crate::decode::rect_partition_hits(); + let fi_square_before = crate::decode::filter_intra_hits(); + let mut named_refusals = 0u32; + let mut matched = 0u32; + let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(40); + for attempt in 0..n_attempts { + let seed = 42 + attempt; + // Diagnosis knob: which content makes RD pick a HORZ/VERT strip + // AND filter intra on it is a search (see this round's report). + let source = match std::env::var("EC_RECTSPLIT_SRC").unwrap_or_default().as_str() { + "bars" => format!("smptebars=size={width}x{height}:duration=0.04:rate=25"), + "src2" => format!("testsrc2=size={width}x{height}:duration=0.04:rate=25"), + _ => gradients_source(seed, width, height, "duration=0.04:rate=25"), + }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, + // Same `hue=s=0` guard as gate (a): a real chroma gradient + // under the tx-size search hits a PRE-EXISTING square-path + // chroma defect that has nothing to do with this lane. + "-vf", "hue=s=0", + "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-", + ]) + .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) + ); + // Diagnosis knob only (default is the gate's pinned recipe): + // which `--cq-level` makes aomenc's RD reach for filter intra on + // a strip is a search, and the sweep that found this one is in + // lanes/rectsplit-r1.report.md. + let cq = format!( + "--cq-level={}", + // Pinned by the sweep in lanes/rectsplit-r1.report.md: at + // cq 45 aomenc's RD picks a strip 18 times in 100 seeds and + // filter intra on none of them; at cq 25 strips are common + // (130/100 seeds) and filter intra lands on one every ~13 + // seeds. + std::env::var("EC_RECTSPLIT_CQ").unwrap_or_else(|_| "25".into()) + ); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", + "--max-partition-size=32", + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + // The point of this gate. + "--enable-filter-intra=1", + // The square filter-intra gate's own way of making RD reach + // for filter intra at all: with the directional/smooth/paeth + // competitors off, DC_PRED + filter intra is what is left + // (recipe borrowed from + // `a_real_aomenc_filter_intra_stream_decodes_pixel_exact`; + // without them 20/20 streams picked filter intra zero times + // on a strip -- measured this round). + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--obu", + "-o", + "-", + "-", + ]; + // Diagnosis knob (default: every intra mode on): turning the + // directional/smooth/paeth competitors off is how the square + // filter-intra gate makes RD reach for filter intra, but with all + // four off aomenc stops picking rect partitions here entirely + // (rect strips=0, filter-intra blocks=28, measured this round), + // so the firing recipe is a search over subsets. + let mut args = args; + let off = std::env::var("EC_RECTSPLIT_OFF").unwrap_or_default(); + for tool in off.split(',').filter(|t| !t.is_empty()) { + args.push(match tool { + "smooth" => "--enable-smooth-intra=0", + "paeth" => "--enable-paeth-intra=0", + "dir" => "--enable-directional-intra=0", + "angle" => "--enable-angle-delta=0", + other => panic!("unknown EC_RECTSPLIT_OFF entry {other}"), + }); + } + let mut child = Command::new(aomenc_path()) + .args(&args) + .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; + assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" + ); + named_refusals += 1; + continue; + } + Ok(frames) => frames, + }; + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); + if let Some(i) = frames[0] + .y + .iter() + .zip(&ffmpeg_frames[0].y) + .position(|(a, b)| a != b) + { + eprintln!( + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", + i % width, + i / width, + frames[0].y[i], + ffmpeg_frames[0].y[i] + ); + } + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + matched += 1; + } + let fi_hits = crate::decode::filter_intra_rect_hits() - before; + eprintln!( + "{NAME}: rect strips this run={}, filter-intra blocks (any shape)={}", + crate::decode::rect_partition_hits() - rect_before, + crate::decode::filter_intra_hits() - fi_square_before + ); + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" + ); + assert!( + fi_hits > 0, + "{NAME}: no HORZ/VERT strip used filter intra ({matched} pixel-exact matches, \ + {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" + ); + eprintln!( + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ + filter_intra_rect_hits delta={fi_hits} out of {n_attempts} attempts" + ); + } + + /// lane-rectsplit r1 gate (b): [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]'s + /// own recipe (`--sb-size=64`, `--min/max-partition-size=32/64`, so every + /// SB-level decision is genuinely NONE/SPLIT/HORZ/VERT) with its + /// `--enable-tx-size-search=0` DROPPED: the 64x32/32x64 strips may then + /// carry a split transform, which [`crate::decode::decode_block_rect64`] + /// refused by name ("a superblock-level HORZ/VERT strip with a split + /// transform") until this round. Same hard `rect_split_tx_hits()` delta + /// assert as gate (a). + /// lane-rectsplit r1 MEASURED RED, `#[ignore]`d with its number (the + /// `rect64q` gate's own precedent): with the per-transform-unit port + /// wired at the superblock level, seed 50 decodes one sample off -- + /// luma (171, 56), ours 147 vs ffmpeg 148, inside the 64x32 strip at + /// mi=(8,32) whose transform resolved to depth 2 (TX_16X16). Seeds 42-49 + /// with depth-1 (TX_32X32) units were pixel-exact. The refusal in + /// `decode_block_rect64` was therefore RESTORED rather than lifted; run + /// this gate (`--ignored`) after any fix to that arm. + #[ignore = "lane-rectsplit r1: measured RED, seed 50 luma (171,56) off by one; refusal kept"] + #[test] + fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_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 (width, height) = (192usize, 128usize); + let before = crate::decode::rect_split_tx_hits(); + let mut named_refusals = 0u32; + let mut matched = 0u32; + let mut split_so_far = 0usize; + // Bounded sweep: see this gate's own doc for the seed-77 residue and + // why extending it is a diagnosis knob, not a pass/fail one. + let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(20); + for attempt in 0..n_attempts { + let seed = 42 + attempt; + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, + // Desaturated (`hue=s=0`, the same guard + // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact` + // uses): with the tx-size search ON, a real chroma + // gradient hits a PRE-EXISTING chroma defect on the plain + // SQUARE path -- measured this round with + // `--enable-rect-partitions=0` on this very recipe, seed + // 42, U plane, i.e. with no rect strip in the stream at + // all. Flat chroma keeps that unrelated defect out of + // this gate (gate-recipe-confound class); it is open + // residue in lanes/rectsplit-r1.report.md, not fixed here. + "-vf", "hue=s=0", + "-pix_fmt", "yuv420p", "-f", + "yuv4mpegpipe", "-", + ]) + .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) + ); + // NOTE: no `--enable-tx-size-search=0` here -- leaving aomenc's + // own default (search ON) is the entire point of this gate. + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=32", + "--max-partition-size=64", + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--obu", + "-o", + "-", + "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .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; + assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" + ); + named_refusals += 1; + continue; + } + Ok(frames) => frames, + }; + let after = crate::decode::rect_split_tx_hits(); + eprintln!( + "{NAME}: seed {seed} decoded, split-tx strips this stream: {}", + after - before - split_so_far + ); + split_so_far = after - before; + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); + if let Some(i) = frames[0] + .y + .iter() + .zip(&ffmpeg_frames[0].y) + .position(|(a, b)| a != b) + { + eprintln!( + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", + i % width, + i / width, + frames[0].y[i], + ffmpeg_frames[0].y[i] + ); + } + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + matched += 1; + } + let split_hits = crate::decode::rect_split_tx_hits() - before; + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" + ); + assert!( + split_hits > 0, + "{NAME}: zero HORZ/VERT strips resolved a split transform ({matched} pixel-exact \ + matches, {named_refusals} refusals out of {n_attempts}) -- gate proved nothing \ + this run" + ); + eprintln!( + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ + rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts" + ); + } + /// lane-rect64q r1: same recipe as /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`] /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is diff --git a/lanes/rectsplit-r1.report.md b/lanes/rectsplit-r1.report.md new file mode 100644 index 00000000..c0fbb444 --- /dev/null +++ b/lanes/rectsplit-r1.report.md @@ -0,0 +1,93 @@ +# lane-rectsplit r1 — HORZ/VERT strips with a split transform, and filter intra on a strip + +Branch `lane-rectsplit` off main `3808cf8`; continues the orchestrator's WIP snapshot +`c5de1b6` (previous builder's uncommitted state), commit `16baa0f` is this round. + +## What changed + +- `crates/ec-av1/src/decode.rs:3159` `decode_rect_split` (from the WIP snapshot, kept): + a HORZ/VERT strip with `tx_depth != 0` predicts and reconstructs PER TRANSFORM UNIT in + raster order (spec 5.11.36), each unit taking its edges from the units already + reconstructed inside the same strip, with per-unit `has_top_right`/`has_bottom_left` + (libaom `reconintra.c`) instead of the standalone-block table; chroma stays one un-split + rect transform. `sub_tx_size_map[TX_32X16] == TX_16X16`, so every unit is square and reads + through the ordinary square `read_plane`. +- `crates/ec-av1/src/decode.rs:3453` — refusal "filter intra on a HORZ/VERT strip (this + decoder predicts square-only)" REMOVED from `decode_block_rect`, replaced by the + `FILTER_INTRA_RECT_HITS` counter. +- `crates/ec-av1/src/intra.rs:733` `predict_filter_intra` now takes `bw`x`bh` instead of one + square `side` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a rectangle just + as happily; `av1_filter_intra_allowed_bsize` genuinely allows every strip with both sides + <= 32). Two call sites updated (`reconstruct_rect` passes `bw, bh`, `reconstruct` passes + `side, side`). +- `crates/ec-av1/src/decode.rs:3833` — the below-16x16 leaf arm (`decode_leaf_rect`) keeps + BOTH refusals; its split-transform one is renamed to name the size ("a HORZ/VERT intra + strip below 16x16 with a split transform ...") because the 32x32-level string it shared is + now lifted, and it is added to `refusal_inventory.rs:41`. +- `crates/ec-av1/src/stream.rs:9337` gate (a), `:9503` gate (c), `:9700` gate (b, `#[ignore]`d + RED, from the WIP snapshot). + +## Refusals lifted (each with its gate) + +| refusal | gate | result | +| --- | --- | --- | +| "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)" | `a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact` | GREEN, 20/20 pixel-exact, `rect_split_tx_hits` > 0 | +| "filter intra on a HORZ/VERT strip (this decoder predicts square-only)" (at the 32x32 level only) | `a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact` | GREEN, 40/40 pixel-exact, `filter_intra_rect_hits`=3 | + +Not lifted: +- "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not + ported)" — the port itself is wired at that level too, but gate (b) + `a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact` is + MEASURED RED: seed 50 decodes one sample off, luma (171, 56) ours 147 vs ffmpeg 148, inside + the 64x32 strip at mi=(8,32) whose transform resolved to depth 2 (TX_16X16). Seeds 42-49 + (depth 1 / TX_32X32 units) are pixel-exact. `#[ignore]`d with that number. + disposition: deferred(a range-ladder/prefilt-dump bisection of that one TU's top-right edge + availability) — the refusal stays, so no wrong pixels ship. +- "filter intra on a HORZ/VERT strip" / "a HORZ/VERT intra strip below 16x16 with a split + transform" at `decode_leaf_rect` (below 16x16): that arm only ports the skip case and has no + gate of its own. disposition: deferred(a below-16x16 strip gate, lane-sub8's territory). + +## Gate-recipe search (the part that cost the round) + +`--enable-filter-intra=1` alone never fires filter intra on a strip. Measured, 192x128 +`gradients` + `hue=s=0`, `--min/max-partition-size=16/32`, `--threads=1 --row-mt=0`: + +| recipe | rect strips | filter-intra blocks (any shape) | filter intra ON a strip | +| --- | --- | --- | --- | +| cq 45, smooth/paeth/directional/angle-delta all OFF (the square filter-intra gate's recipe), 20 seeds | 0 | 23 | 0 | +| cq 45, every intra mode ON, 100 seeds | 18 | 136 | 0 | +| cq 25, every intra mode ON, 100 seeds | 130 | 61 | 5 | +| cq 25, every intra mode ON, 40 seeds (PINNED) | 56 | 16 | 3 | + +Disabling the directional/smooth/paeth competitors — the trick the square filter-intra gate +uses — makes aomenc stop choosing rect partitions altogether (class `gate-recipe-confound`). +The knob that actually works is the quantiser: at cq 25 strips are ~7x more common. `smptebars` +and `testsrc2` sources were tried and are unusable here (every attempt refused, 0 decodes). +`EC_RECTSPLIT_CQ` / `EC_RECTSPLIT_OFF` / `EC_RECTSPLIT_GATE_ATTEMPTS` stay as diagnosis knobs +with the pinned recipe as default. + +## Evidence + +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact` | aomenc `--enable-rect-partitions=1`, tx-size search ON, 20 seeds, each decoded by ours and by ffmpeg | 20 pixel-exact matches, 0 refusals, `rect_split_tx_hits` delta > 0, test ok +EVIDENCE: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_filter_intra_on_a_horz_vert_strip_decodes_pixel_exact` | aomenc `--enable-filter-intra=1 --cq-level=25`, 40 seeds | 40 pixel-exact matches, 0 refusals, `filter_intra_rect_hits` delta=3, test ok + +## Film check (ReelB) + +``` +ffmpeg -v error -t 0.4 -i ".../reelb.mkv" -c:v copy -f obu hg.obu # 1817 bytes +cargo run -p ec-av1 --example decode_probe -- hg.obu +REFUSED: unsupported: AV1 tile (a partition below 8x8 (this decoder codes no leaf smaller than 8x8)) +``` + +EVIDENCE: /tmp/.../scratchpad/hg.obu | `ffmpeg -t 0.4 -c:v copy -f obu` then `decode_probe` on this branch | stops at "a partition below 8x8", NOT at any refusal this lane owns + +The charter's premise that this extract stops at a rect-split refusal is stale for the film's +first 0.4s: the blocker there is the below-8x8 partition refusal (lane-sub8's, still open per +`memory/`). "Before" was not re-measured on main — the refusal reached is upstream of every +line this lane touched, so the branch cannot have moved it. +disposition: deferred(lane-sub8's below-8x8 leaf) — nothing this lane can do about it. + +## Suite + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` (crate lib only, never the workspace): +**269 passed, 0 failed, 24 ignored**, 1062s. `refusal_inventory` and `gate_coverage` green.