diff --git a/crates/ec-av1/examples/dump_yuv.rs b/crates/ec-av1/examples/dump_yuv.rs new file mode 100644 index 00000000..2892c620 --- /dev/null +++ b/crates/ec-av1/examples/dump_yuv.rs @@ -0,0 +1,46 @@ +//! Decode one OBU stream and write every frame's planes as raw little-endian +//! `u16` (`.f.yuv`) — the high-bit-depth companion to +//! `EC_AV1_PREFILT_DUMP`, whose `as u8` narrowing throws away exactly the bits +//! a 10-bit mismatch lives in (lane-rect1d r1 found its defect by diffing this +//! against `ffmpeg -pix_fmt yuv420p10le -f rawvideo`). +//! +//! ```text +//! cargo run -p ec-av1 --example dump_yuv -- s.obu /tmp/ours +//! ffmpeg -v error -i s.obu -pix_fmt yuv420p10le -f rawvideo /tmp/ref.yuv +//! cmp /tmp/ours.f0.yuv /tmp/ref.yuv +//! ``` +fn main() { + let mut args = std::env::args().skip(1); + let (Some(path), Some(out)) = (args.next(), args.next()) else { + eprintln!("usage: dump_yuv "); + std::process::exit(2); + }; + let data = match std::fs::read(&path) { + Ok(data) => data, + Err(e) => { + eprintln!("{path}: {e}"); + std::process::exit(2); + } + }; + let frames = match ec_av1::stream::decode_stream(&data) { + Ok(frames) => frames, + Err(e) => { + eprintln!("{path}: {e}"); + std::process::exit(1); + } + }; + for (i, f) in frames.iter().enumerate() { + let mut buf = Vec::with_capacity((f.y.len() + f.u.len() + f.v.len()) * 2); + for plane in [&f.y, &f.u, &f.v] { + for &s in plane.iter() { + buf.extend_from_slice(&s.to_le_bytes()); + } + } + let name = format!("{out}.f{i}.yuv"); + if let Err(e) = std::fs::write(&name, &buf) { + eprintln!("{name}: {e}"); + std::process::exit(2); + } + println!("frame {i}: {}x{} -> {name}", f.width, f.height); + } +} diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index e82a9091..a9e0c44b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -128,6 +128,20 @@ pub(crate) fn filter_intra_hits() -> usize { FILTER_INTRA_HITS.with(|c| c.get()) } +// lane-fiinter r1: how many of those `use_filter_intra == 1` symbols belonged +// to an INTRA block inside an INTER frame (`read_intra_block_mode_info`'s own +// `read_filter_intra_mode_info` call), which no gate exercised before this +// round -- every inter gate recipe passed `--enable-filter-intra=0`. +thread_local! { + static INTRA_IN_INTER_FILTER_INTRA_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTRA_IN_INTER_FILTER_INTRA_HITS`]. +pub(crate) fn intra_in_inter_filter_intra_hits() -> usize { + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.get()) +} + // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a // frame-level flag through the recursive block decode -- `0` (the default) @@ -779,7 +793,7 @@ fn tu_reach( width: usize, height: usize, ) -> Reach { - let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, block); + let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block); let standalone = Reach::of(tx, px + col_off, py + row_off, width, height); if fixed != standalone { SPLIT_TU_REACH_FIX_HITS.with(|c| c.set(c.get() + 1)); @@ -947,6 +961,11 @@ thread_local! { // frame-constant. static TX_SELECT_INTER: std::cell::Cell = const { std::cell::Cell::new(false) }; static REDUCED_TX_SET_INTER: std::cell::Cell = const { std::cell::Cell::new(true) }; + // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit, + // frame-constant like the two above and stashed the same way -- an intra + // block inside an inter frame reads `use_filter_intra` under it. + static ENABLE_FILTER_INTRA_INTER: std::cell::Cell = + const { std::cell::Cell::new(false) }; } /// Current value of [`TXFM_SPLIT_READS`]. @@ -959,10 +978,16 @@ pub(crate) fn txfm_split_hits() -> usize { TXFM_SPLIT_HITS.with(|c| c.get()) } -/// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]. -pub(crate) fn set_inter_tx_mode(tx_select: bool, reduced_tx_set: bool) { +/// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ +/// [`ENABLE_FILTER_INTRA_INTER`]. +pub(crate) fn set_inter_tx_mode( + tx_select: bool, + reduced_tx_set: bool, + enable_filter_intra: bool, +) { TX_SELECT_INTER.with(|c| c.set(tx_select)); REDUCED_TX_SET_INTER.with(|c| c.set(reduced_tx_set)); + ENABLE_FILTER_INTRA_INTER.with(|c| c.set(enable_filter_intra)); } // How many `partition_w16` reads (a 16x16 block's own partition symbol, key @@ -1119,6 +1144,28 @@ pub(crate) fn filter_intra_rect4_vert_hits() -> usize { FILTER_INTRA_RECT4_VERT_HITS.with(|c| c.get()) } +// How many rectangular transform units actually coded coefficients through +// [`read_coeffs_rect`] (`all_zero == 0`) -- lane-rect1d's measure that a gate +// exercised the rect coefficient reader at all rather than passing on +// all-skip blocks. +thread_local! { + static RECT_COEFF_TU_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static RECT_CLASS1_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`RECT_COEFF_TU_HITS`]. +pub(crate) fn rect_coeff_tu_hits() -> usize { + RECT_COEFF_TU_HITS.with(|c| c.get()) +} + +/// Rectangular transform units whose resolved `tx_type` is a 1D class +/// (`V_DCT`/`H_DCT`) -- [`TX_CLASS1_HITS`]'s rect-only half, so a gate can +/// pin that the 1D-class-on-a-RECT-transform path fired rather than settling +/// for the square reader's own 1D types. +pub(crate) fn rect_class1_hits() -> usize { + RECT_CLASS1_HITS.with(|c| c.get()) +} + // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the // shapes whose `use_filter_intra` symbol had no CDF class before this round. @@ -1327,6 +1374,19 @@ pub(crate) fn palette_split_tx_hits() -> usize { PALETTE_SPLIT_TX_HITS.with(|c| c.get()) } +// 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. +thread_local! { + static INTRA_IN_INTER_SPLIT_TX_HITS: std::cell::Cell<[usize; 4]> = + const { std::cell::Cell::new([0; 4]) }; +} + +/// Current value of [`INTRA_IN_INTER_SPLIT_TX_HITS`], indexed 8/16/32/64. +pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] { + INTRA_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) +} + thread_local! { /// A just-decoded palette-Y block's own predicted pixels /// (`side*side`, row-major, `colors[map[i]]`), consumed by @@ -1789,6 +1849,24 @@ pub(crate) fn mode_mi_override_hits() -> usize { MODE_MI_OVERRIDE_HITS.with(|c| c.get()) } +// lane-modectx r1: how many times a `kf_y_mode`/`y_mode` neighbour read at a +// TILE edge found its coarse fallback band holding a NON-DC mode -- i.e. a +// mode from the previous tile, where libaom's `up_available`/`left_available` +// make the neighbour DC_PRED. Measured 0 over 20 two-tile-column streams: +// `above_mode` is cleared per tile in `Neighbours::start_tile` and `left_mode` +// per superblock row in `start_row`, so the luma fallback cannot leak the way +// lane-mtfix's `above_uv_mode` one did. The gate asserts it stays 0 -- this is +// the invariant that makes the coarse fallback safe. +thread_local! { + static MODE_TILE_EDGE_COARSE_LEAKS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`MODE_TILE_EDGE_COARSE_LEAKS`]. +pub(crate) fn mode_tile_edge_coarse_leaks() -> usize { + MODE_TILE_EDGE_COARSE_LEAKS.with(|c| c.get()) +} + // lane-cfl r1: how many times a chroma intra-edge filter-type read // (`get_filt_type`, libaom reconintra.c) took an above/left UV mode from the // mi-exact map that DIFFERS from its coarse 16x16 slot -- i.e. how often the @@ -1910,6 +1988,30 @@ thread_local! { static RECT4_COEFF_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } +// lane-rectsplitx r1: 1:4 strips (32x8/8x32/64x16/16x64) decoded through the +// per-transform-unit split path, split by tx depth -- depth 1 is a 2:1 RECT +// unit (TX_16X8/TX_32X16), depth 2 a square one, and the two INTERLEAVE in +// every real stream, so a gate must prove both fired. `SUB16_SPLIT_HITS` +// counts the same for a 16x8/8x16 strip below 16x16. +thread_local! { + static RECT4_SPLIT_DEPTH1_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static RECT4_SPLIT_DEPTH2_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static SUB16_SPLIT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current values of `RECT4_SPLIT_DEPTH1_HITS` / `RECT4_SPLIT_DEPTH2_HITS`. +pub(crate) fn rect4_split_depth_hits() -> (usize, usize) { + ( + RECT4_SPLIT_DEPTH1_HITS.with(|c| c.get()), + RECT4_SPLIT_DEPTH2_HITS.with(|c| c.get()), + ) +} + +/// Current value of `SUB16_SPLIT_HITS`. +pub(crate) fn sub16_split_hits() -> usize { + SUB16_SPLIT_HITS.with(|c| c.get()) +} + /// Current value of `RECT4_COEFF_HITS`. pub(crate) fn rect4_coeff_hits() -> usize { RECT4_COEFF_HITS.with(|c| c.get()) @@ -2949,6 +3051,7 @@ fn read_coeffs( let class = TxClass::of(tx_type); if class != TxClass::TwoD { TX_CLASS1_HITS.with(|c| c.set(c.get() + 1)); + RECT_CLASS1_HITS.with(|c| c.set(c.get() + 1)); } let eob = read_eob(dec, coding, class); if trace { @@ -3099,6 +3202,7 @@ fn read_coeffs_rect( if all_zero { return Ok((grid, TxType::DctDct)); } + RECT_COEFF_TU_HITS.with(|c| c.set(c.get() + 1)); // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including // the `V_DCT`/`H_DCT` members whose 1D tx class needs its own scan and @@ -4139,11 +4243,26 @@ impl Neighbours { /// [`Self::around_mi`]'s plain coded/uncoded bit, this needs the real /// cumulative level -- a lone-TU block never calls this (its `txb_skip_ctx` /// is always 0, spec's `plane_bsize == tx_size` branch). - fn luma_skip_ctx(&self, (mi_r, mi_c): (usize, usize), side_mi: usize) -> usize { + fn luma_skip_ctx(&self, at_mi: (usize, usize), side_mi: usize) -> usize { + self.luma_skip_ctx_rect(at_mi, side_mi, side_mi) + } + + /// [`Self::luma_skip_ctx`] with the unit's own width and height in mi + /// units (lane-rectsplitx r1) -- `get_txb_ctx_general` ORs the above + /// context over `tx_size_wide` and the left one over `tx_size_high`. + fn luma_skip_ctx_rect( + &self, + (mi_r, mi_c): (usize, usize), + w_mi: usize, + h_mi: usize, + ) -> usize { + let side_mi = w_mi; let mut top = 0u8; let mut left = 0u8; - for cell in 0..side_mi { + for cell in 0..w_mi { top |= self.above[mi_c + cell][0].level; + } + for cell in 0..h_mi { left |= self.left[mi_r + cell][0].level; } let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; @@ -4295,13 +4414,56 @@ impl Neighbours { /// strip path ([`decode_leaf_rect`] took this override in r4; a 32x16 strip /// whose left neighbour was a 16x8 leaf still read the stale row and picked /// a different CDF for the same mode value). + /// lane-rectsplitx r2: availability-correct above/left luma modes for a + /// block whose top-left mi is `(mi_r, mi_c)`. libaom reads `above_mbmi` + /// only when `up_available` and `left_mbmi` only when `left_available`; + /// the coarse [`SUB`] bands cannot express that, and with 8-px strips they + /// actively lie -- four 32x8 strips of one `HORZ_4` share ONE 16x16 + /// `left_mode` cell, so the second strip at tile column 0 read the FIRST + /// strip's mode as its "left neighbour" (measured on the band fixture at + /// mi(10,0): mode 2 where libaom has DC, a different `kf_y_mode` row). + fn modes_above_left_mi( + &self, + mi_r: usize, + mi_c: usize, + fallback: (usize, usize), + ) -> (usize, usize) { + let above = if mi_r > self.tile_row0_mi { + self.mode_above_mi(mi_r, mi_c).unwrap_or(fallback.0) + } else { + DC_PRED + }; + let left = if mi_c > self.tile_col0_mi { + self.mode_left_mi(mi_r, mi_c).unwrap_or(fallback.1) + } else { + DC_PRED + }; + (above, left) + } + + /// lane-modectx r1: the coarse-[`SUB`]-grid entry point, now availability + /// correct. The mi-exact lookups already refuse to cross a tile edge, but + /// their FALLBACK (`above_mode`/`left_mode`) did not: `left_mode` is reset + /// per superblock row and never per tile, so the first block column of + /// tile 2..N read the previous tile's mode as its left neighbour, and the + /// above band survives across a tile ROW boundary the same way lane-mtfix's + /// `above_uv_mode` did. libaom reads `above_mbmi`/`left_mbmi` only when + /// `up_available`/`left_available` and uses DC_PRED otherwise + /// ([`Self::modes_above_left_mi`]). fn modes_above_left(&self, r: usize, c: usize) -> (usize, usize) { let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); - let above = self.mode_above_mi(mi_r, mi_c).unwrap_or(self.above_mode[c]); - let left = self.mode_left_mi(mi_r, mi_c).unwrap_or(self.left_mode[r]); + let (above, left) = + self.modes_above_left_mi(mi_r, mi_c, (self.above_mode[c], self.left_mode[r])); if above != self.above_mode[c] || left != self.left_mode[r] { MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); } + // A neighbour the coarse band offered where the tile edge makes it + // unavailable -- must never happen (see `MODE_TILE_EDGE_COARSE_LEAKS`). + if (mi_r <= self.tile_row0_mi && self.above_mode[c] != DC_PRED) + || (mi_c <= self.tile_col0_mi && self.left_mode[r] != DC_PRED) + { + MODE_TILE_EDGE_COARSE_LEAKS.with(|h| h.set(h.get() + 1)); + } (above, left) } @@ -4400,13 +4562,27 @@ impl Neighbours { /// Leaves `above_side_mi`/`left_side_mi` and the chroma planes alone -- /// the caller's own [`Self::record_split_luma`] call sets those once, /// at the block's own true side, not this TU's. - fn record_mi_luma(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, grid: &[i32]) { + fn record_mi_luma(&mut self, at_mi: (usize, usize), tx_px: usize, grid: &[i32]) { + self.record_mi_luma_rect(at_mi, tx_px, tx_px, grid); + } + + /// [`Self::record_mi_luma`] for a RECTANGULAR transform unit (lane-rectsplitx + /// r1): the above context spans the unit's width, the left context its + /// height, which for a square unit is the same loop it always was. + fn record_mi_luma_rect( + &mut self, + (mi_r, mi_c): (usize, usize), + w_px: usize, + h_px: usize, + grid: &[i32], + ) { let state = neighbour_state(grid); - let side_mi = tx_px / MI; - for cell in 0..side_mi { + for cell in 0..h_px / MI { if mi_r + cell < self.mi_rows { self.left[mi_r + cell][0] = state; } + } + for cell in 0..w_px / MI { if mi_c + cell < self.mi_cols { self.above[mi_c + cell][0] = state; } @@ -4444,17 +4620,42 @@ impl Neighbours { chroma_grids: [&[i32]; 2], ) { let (r, c) = at; - for cell in 0..w / SUB { + self.record_split_luma_rect_mi( + (r * (SUB / MI), c * (SUB / MI)), + w, + h, + mode, + uv_mode, + chroma_grids, + ); + } + + /// [`Self::record_split_luma_rect`] addressed in mi units (lane-rectsplitx + /// r1) -- a strip 8 px tall starts mid-[`SUB`]-cell, which the coarse + /// `(r, c)` form cannot name. The coarse mode/side arrays are stamped for + /// every cell the strip TOUCHES (`div_ceil`), last writer wins, the + /// convention [`decode_block_rect4`] already established for 1:4 strips. + fn record_split_luma_rect_mi( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, + chroma_grids: [&[i32]; 2], + ) { + let (mi_r, mi_c) = at_mi; + let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); + for cell in 0..w.div_ceil(SUB) { self.above_mode[c + cell] = mode; self.above_uv_mode[c + cell] = uv_mode; self.above_side[c + cell] = w; } - for cell in 0..h / SUB { + for cell in 0..h.div_ceil(SUB) { self.left_mode[r + cell] = mode; self.left_uv_mode[r + cell] = uv_mode; self.left_side[r + cell] = h; } - let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); let (w_mi, h_mi) = (w / MI, h / MI); self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); @@ -5129,6 +5330,29 @@ struct RectStripModes { palette_uv: Option<(Vec, Vec)>, } +/// The transform unit size (w, h) of a `bw`x`bh` intra block at tx `depth` +/// -- libaom `depth_to_tx_size`, which walks `sub_tx_size_map` `depth` times +/// from `max_txsize_rect_lookup[bsize]`. Every entry of that map halves the +/// LONGER side of a rectangle and both sides of a square, so a 1:4 strip's +/// first step is a 2:1 rect unit (`TX_32X8 -> TX_16X8`, `TX_64X16 -> +/// TX_32X16`) and only the second reaches a square -- the reason +/// `bw.min(bh) >> (depth - 1)` (correct for a 2:1 strip, where step one is +/// already square) mis-tiled 1:4 strips. +fn depth_to_tx_wh(bw: usize, bh: usize, depth: usize) -> (usize, usize) { + let (mut w, mut h) = (bw.min(64), bh.min(64)); + for _ in 0..depth { + match w.cmp(&h) { + std::cmp::Ordering::Greater => w /= 2, + std::cmp::Ordering::Less => h /= 2, + std::cmp::Ordering::Equal => { + w /= 2; + h /= 2; + } + } + } + (w, h) +} + /// 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 @@ -5154,10 +5378,15 @@ fn decode_rect_split( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, neighbours: &mut Neighbours, - at: (usize, usize), + at_mi: (usize, usize), bw: usize, bh: usize, - tx: usize, + // The transform unit's own width and height in pixels. Square for every + // 2:1 strip from the first split on, but a 1:4 strip's FIRST split is + // still a 2:1 RECT unit (`sub_tx_size_map[TX_32X8] == TX_16X8`, + // `[TX_64X16] == TX_32X16`) -- see [`depth_to_tx_wh`]. + tx_w: usize, + tx_h: usize, m: &RectStripModes, y: &mut PlaneBuf, u: &mut PlaneBuf, @@ -5165,9 +5394,8 @@ fn decode_rect_split( 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 (mi_r, mi_c) = at_mi; + let (px, py) = (mi_c * MI, mi_r * 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 @@ -5177,16 +5405,17 @@ fn decode_rect_split( (8, 16) => Some((TxbSet::ChromaRect16x8, &SCAN_8X16[..])), (32, 16) => Some((TxbSet::ChromaRect32x16, &SCAN_32X16[..])), (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), - // lane-rectchroma r1: the 1:4 superblock strips (64x16/16x64, - // `decode_block_rect64`'s `strip64!` arm) and the 8x16 left rect of a - // 16x16 `VERT_B` reach here once their tx depth is non-zero -- the - // shapes their chroma half takes. `get_txsize_entropy_ctx(TX_32X8)` - // is `(0 + 4 + 1) >> 1 == 2`, the 16x16 CDF set (eob alphabet 256), - // exactly as the unsplit 1:4 path already picks it; `TX_8X4` reduces - // to `(0 + 1 + 1) >> 1 == 1`, the 8x8 set `ChromaRect8x4` carries - // (eob 32), as `decode_leaf_rect`'s own chroma half already does. + // The 1:4 and sub-16 strips (lane-rectchroma r1 added the 32x8/8x32 + // rows, lane-rectsplitx r1 the 16x4/4x16 ones). `get_txsize_entropy_ctx` + // squares a rect transform down to a CDF set by + // `(wide_log2 + high_log2 + 1) >> 1`: TX_32X8 -> the 16x16 set, + // TX_16X4 -> the 8x8 set, TX_8X4 -> the 8x8 set -- exactly the sets + // the UNSPLIT 1:4 (`decode_block_rect4`) and 16x8 (`decode_leaf_rect`) + // paths already prove for these same shapes. (32, 8) => Some((TxbSet::Chroma16, &SCAN_32X8[..])), (8, 32) => Some((TxbSet::Chroma16, &SCAN_8X32[..])), + (16, 4) => Some((TxbSet::Chroma8, &SCAN_16X4[..])), + (4, 16) => Some((TxbSet::Chroma8, &SCAN_4X16[..])), (8, 4) => Some((TxbSet::ChromaRect8x4, &SCAN_8X4[..])), (4, 8) => Some((TxbSet::ChromaRect8x4, &SCAN_4X8[..])), _ => None, @@ -5209,7 +5438,7 @@ fn decode_rect_split( // Diagnostic for the next caller that lands here (class // refusal-names-a-correlate: the message names the tool, not the // shape); the refusal below keeps its inventory-pinned wording. - eprintln!("EC_RECTCHROMA_GAP luma={bw}x{bh} tx={tx} chroma={chroma_w}x{chroma_h}"); + eprintln!("EC_RECTCHROMA_GAP luma={bw}x{bh} tx={tx_w}x{tx_h} chroma={chroma_w}x{chroma_h}"); } } // lane-rectsplit r2 (verifier finding): with both callers wired @@ -5225,21 +5454,50 @@ fn decode_rect_split( )); } RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); - if bw.max(bh) == 64 && bw / tx > 1 && bh / tx > 1 { + if bw.max(bh) == 64 && bw / tx_w > 1 && bh / tx_h > 1 { RECT_SPLIT_SB_INTERIOR_TU_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]; + // A square unit reads through the ordinary square [`read_plane`]; a rect + // one (a 1:4 strip's first split) reads through [`read_coeffs_rect`] with + // the very tables the unsplit 16x8/32x16 paths use. + let luma_rect: Option<(TxbSet, &[u16])> = match (tx_w, tx_h) { + (w, h) if w == h => None, + (16, 8) | (8, 16) => Some(( + if reduced_tx_set { + TxbSet::LumaRect16x8 + } else { + TxbSet::LumaRect16x8Set1 + }, + if tx_w == 16 { &SCAN_16X8[..] } else { &SCAN_8X16[..] }, + )), + (32, 16) => Some((TxbSet::LumaRect32x16, &SCAN_32X16[..])), + (16, 32) => Some((TxbSet::LumaRect32x16, &SCAN_16X32[..])), + _ => { + return Err(unsupported(format!( + "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma \ + coefficient tables for that shape here)" + ))) + } + }; + // lane-rectsplitx r1, MEASURED: the SQUARE-unit walk below is pixel-exact + // on a real stream (the pinned 16x8 filter-intra fixture decodes its whole + // frame exactly, two sub-16 split strips in it), but the RECT-unit arm -- + // a 1:4 strip's depth-1 TX_16X8/TX_32X16 -- mismatched ffmpeg on the + // 32-level 1:4 band fixture (8-bit, cq 12, seed 42). The tables and the + // per-unit rect walk stay wired above/below; the round that finds that + // defect deletes this refusal and nothing else. + let luma_set = txbset_for(tx_w.min(tx_h), reduced_tx_set); + let luma_scan = default_scan(tx_w.min(tx_h)); + let zero_tu = vec![0i32; tx_w * tx_h]; // 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); + for tu_row in 0..bh / tx_h { + for tu_col in 0..bw / tx_w { + 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); // `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 @@ -5255,22 +5513,23 @@ fn decode_rect_split( // (`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::of_tu(bw, bh, col_off, row_off, tx, block_reach); + let tu_reach = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block_reach); // The unit's own window on the block's palette prediction. if let Some(buf) = &m.palette_y { - let tu_buf: Vec = (0..tx) + let tu_buf: Vec = (0..tx_h) .flat_map(|i| { let base = (row_off + i) * bw + col_off; - buf[base..base + tx].iter().copied() + buf[base..base + tx_w].iter().copied() }) .collect(); set_palette_pred(tu_buf); } if m.skip { - y.reconstruct( + y.reconstruct_rect( tu_px, tu_py, - tx, + tx_w, + tx_h, m.mode, m.angle_delta_y, tu_reach, @@ -5279,13 +5538,57 @@ fn decode_rect_split( m.filter_intra, m.smooth_neighbor, ); - neighbours.record_mi_luma(tu_mi, tx, &zero_tu); + neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu); + } else if let Some((rect_set, rect_scan)) = luma_rect { + // The rect-unit twin of the square arm below: same contexts, + // same order, through the rect coefficient reader. The + // `tx_type` CDF row of a filter-intra block is + // `fimode_to_intradir[filter_intra_mode]`, never the block's + // 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); + 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, + &mut coding, + rect_scan, + tx_w, + tx_h, + tu_skip_ctx, + dc_sign_ctx(tu_around.2), + TxType::DctDct, + )?; + let residual = dequant_and_inverse_typed_wh( + &tu_grid, + tx_w, + tx_h, + crate::decode::bit_depth(), + block_q_idx(), + plane_q_delta(0).0, + plane_q_delta(0).1, + tu_tx_type, + ); + y.reconstruct_rect( + tu_px, + tu_py, + tx_w, + tx_h, + m.mode, + m.angle_delta_y, + tu_reach, + &residual, + None, + m.filter_intra, + m.smooth_neighbor, + ); + neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid); } else { - let tu_around = neighbours.around_mi(tu_mi, tx)[0]; + let tu_around = neighbours.around_mi(tu_mi, tx_w)[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_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_w / MI); let tu_grid = read_plane( dec, cdfs, @@ -5300,15 +5603,15 @@ fn decode_rect_split( y, tu_px, tu_py, - tx, - tx, + tx_w, + tx_w, base_q_idx, None, m.filter_intra, Some(tu_skip_ctx), m.smooth_neighbor, )?; - neighbours.record_mi_luma(tu_mi, tx, &tu_grid); + neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid); } } } @@ -5342,7 +5645,7 @@ fn decode_rect_split( } else { default_intra_tx_type(m.uv_predict_mode as u8) }; - let around = neighbours.around_rect(at, bw, bh); + let around = neighbours.around_mi_rect(at_mi, bw, bh); let mut grids: Vec> = Vec::with_capacity(2); for plane_idx in 1..=2 { let skip_ctx = @@ -5402,13 +5705,21 @@ fn decode_rect_split( 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.record_split_luma_rect_mi( + at_mi, + 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); + neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h 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}" + "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} \ + tx={tx_w}x{tx_h} rng={rng}" ); } Ok(()) @@ -5504,13 +5815,12 @@ fn decode_block_rect( // 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); + // [`decode_rect_split`], the unit named by [`depth_to_tx_wh`]. + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); if std::env::var_os("EC_SBPART_DUMP64").is_some() { eprintln!( "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \ - depth={depth} tx={tx} mode={mode} uv={uv_predict_mode} skip={skip} \ + depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \ angle_y={angle_delta_y}" ); } @@ -5538,7 +5848,20 @@ fn decode_block_rect( PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); } decode_rect_split( - dec, cdfs, neighbours, at, bw, bh, tx, &modes, y, u, v, base_q_idx, reduced_tx_set, + dec, + cdfs, + neighbours, + (mi_r, mi_c), + bw, + bh, + tx_w, + tx_h, + &modes, + y, + u, + v, + base_q_idx, + reduced_tx_set, )?; // This early return skips this fn's own tail, so the palette // neighbour state has to be stamped HERE too: without it a split-tx @@ -5888,12 +6211,12 @@ fn decode_leaf_rect( // cannot hold the modes a split (or a pair of strips) leaves behind, so // when the map holds the block at exactly this strip's above/left mi it // is the neighbour libaom's `above_mi`/`left_mi` reads. - if let Some(m) = neighbours.mode_above_mi(leaf_mi.0, leaf_mi.1) { - above_mode = m; - } - if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) { - left_mode = m; - } + // lane-rectsplitx r2 (same class as the 1:4 fix): mi-exact AND + // availability-correct -- four 16x8 strips share one coarse 16x16 + // `left_mode` cell too, so the fallback must not stand in for an absent + // tile-edge neighbour. + let (above_mode, left_mode) = + neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, (above_mode, left_mode)); let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); if smooth_neighbor { @@ -5951,15 +6274,68 @@ fn decode_leaf_rect( let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); let depth = if tx_select { let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh); - dec.symbol(&mut cdfs.tx_size_cat2[ctx]) + // lane-rectsplitx r1: `bsize_to_tx_size_cat` (libaom `blockd.h`, + // `bsize_to_tx_size_depth_table`) is 2 for BLOCK_16X8/BLOCK_8X16, so + // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol + // count (3), different CDF row: a wrong-table read of a real symbol, + // the class that cost lane-rectsplit r1 its 64x32 depth. + // lane-rect1d r1: the CATEGORY of this leaf is 1, not 2. libaom's + // `bsize_to_tx_size_cat` reads `bsize_to_tx_size_depth_table` and + // subtracts one: BLOCK_16X8/8X16 (and the 1:4 BLOCK_16X4/4X16 this + // function also decodes) sit at depth 2, so they read + // `tx_size_cdf[1]` -- the same table a 16x16 square block reads -- + // while `tx_size_cat2` belongs to the 32-level shapes + // ([`decode_block_rect`]). Both tables carry three symbols, so the + // wrong one decodes a plausible depth from the wrong probabilities: + // the range diverges silently at the first such leaf and every later + // symbol in the tile is read from the wrong place (class + // `wrong-alphabet-same-value`, here same alphabet / wrong row). + dec.symbol(&mut cdfs.tx_size_cat1[ctx]) } else { 0 }; if depth != 0 { - return Err(unsupported( - "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect \ - prediction is not ported)", - )); + // The same per-transform-unit walk the bigger strips take + // (`depth_to_tx_wh`: TX_16X8 -> TX_8X8 at depth 1, -> TX_4X4 at + // depth 2), addressed at this leaf's own mi position. + TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); + SUB16_SPLIT_HITS.with(|c| c.set(c.get() + 1)); + 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, + // lane-rectsplitx r3: the split arm hard-coded `false` here while + // the unsplit arm below passes the real neighbour answer -- chroma + // of a tx-split 16x8/8x16 leaf lost its intra-edge filter type. + smooth_neighbor_uv, + // Both callers refuse a palette on this shape above (pixel + // reconstruction is unported here), so the split units carry none. + palette_y: None, + palette_uv: None, + }; + decode_rect_split( + dec, + cdfs, + neighbours, + leaf_mi, + bw, + bh, + tx_w, + tx_h, + &modes, + y, + u, + v, + base_q_idx, + reduced_tx_set, + )?; + return Ok(mode); } let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); @@ -6119,6 +6495,12 @@ fn decode_block_rect4( left_mode = pmode; } } + // lane-rectsplitx r2, ROOT CAUSE of the 1:4 mismatch: mi-exact + + // availability-correct neighbour modes (see + // [`Neighbours::modes_above_left_mi`]). The coarse 16x16 bands alias every + // 8-px strip of a `HORZ_4`/`VERT_4` onto one cell. + let (above_mode, left_mode) = + neighbours.modes_above_left_mi(mi_r, mi_c, (above_mode, left_mode)); let ( skip, mode, @@ -6159,8 +6541,13 @@ fn decode_block_rect4( if smooth_neighbor { SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); } - let smooth_neighbor_uv = - neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c); + // lane-rectsplitx r2: this strip's REAL mi, not the [`SUB`] cell's + // top-left -- a 1:4 strip starts 8 px into a 16-px cell, so + // `r * (SUB / MI)` names a different mi column and the chroma + // edge-filter strength was read from the wrong neighbour (measured: + // seed 43, the last 8x32 strip at luma (152,32), chroma-only mismatch + // with luma bit-exact). + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c); if filter_intra.is_some() { FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); if bw > bh { @@ -6181,16 +6568,64 @@ fn decode_block_rect4( 0 }; if depth != 0 { - // lane-tx64x16 r4: the depth is IN the message -- it says which port - // the next round owes. depth 1 of a 4:1 strip is TX_16X8/TX_8X16 - // (`sub_tx_size_map[TX_32X8] == TX_16X8`), a RECTANGULAR transform - // unit with no luma coefficient tables here; depth 2 is TX_8X8, - // square, the shape `decode_rect_split` already walks. The film stops - // at depth 2, synthetic band fixtures hit both. - return Err(unsupported(format!( - "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is not \ - ported, depth={depth})" - ))); + // lane-rectsplitx r1: the per-transform-unit walk, at this strip's + // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a + // 16-px [`SUB`] cell). depth 1 is the RECT unit TX_16X8/TX_8X16 + // (`sub_tx_size_map[TX_32X8] == TX_16X8`), depth 2 the square TX_8X8; + // both interleave in every real stream. + TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); + // lane-rectsplitx r2: both depths ship together, as the r1 handoff + // predicted -- depth 1 fires FIRST in every attempt that splits at + // all, so a depth-2-only lift could never be gated. The r1 mismatch + // was never the rect unit: it was the neighbour MODE the strip reads + // (see `modes_above_left_mi`). + let which = if depth == 1 { + &RECT4_SPLIT_DEPTH1_HITS + } else { + &RECT4_SPLIT_DEPTH2_HITS + }; + which.with(|c| c.set(c.get() + 1)); + let modes = RectStripModes { + skip, + mode, + angle_delta_y, + uv_predict_mode, + angle_delta_uv, + alpha, + filter_intra, + smooth_neighbor, + smooth_neighbor_uv, + // Both callers refuse a palette on this shape above (pixel + // reconstruction is unported here), so the split units carry none. + 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, + false, + )?; + if bw > bh { + RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); + } else { + RECT4_32_VERT_HITS.with(|c| c.set(c.get() + 1)); + } + if !skip { + RECT4_COEFF_HITS.with(|c| c.set(c.get() + 1)); + } + return Ok((mode, uv_predict_mode)); } // The coarse (16-px [`SUB`] cell) mode/side arrays cannot name a strip // that is 8 px tall, so each strip stamps every cell it touches and the @@ -6207,6 +6642,14 @@ fn decode_block_rect4( neighbours.left_uv_mode[r + cell] = uv_predict_mode; neighbours.left_side[r + cell] = bh; } + // ...and the mi-EXACT maps the coarse cells alias away, exactly as + // [`decode_leaf_rect`] does (the split arm above records these through + // `record_mi_luma_rect`). Without this an unsplit 32x8 strip left + // `sub8_mode_row` holding the previous block, and the next 32x32's + // strips read a stale `kf_y_mode` row (measured: mi(4,8) on the band + // fixture). + neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode); + neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode); let (px, py) = (mi_c * MI, mi_r * MI); let (cpx, cpy) = (px / 2, py / 2); let (chroma_w, chroma_h) = (bw / 2, bh / 2); @@ -6489,31 +6932,22 @@ fn decode_block_rect64( TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); // lane-rectsplit r1/r4: the superblock-level strip splits its // transform through the very same per-unit path as its 32x32-level - // sibling (`sub_tx_size_map[TX_64X32] == TX_32X32`, square from the - // first step on, so `bw.min(bh) >> (depth - 1)` names the unit). - // lane-rectchroma r1: `sub_tx_size_map[TX_64X16] == TX_32X16`, NOT a - // square -- a 4:1 strip's first transform split is still a 2:1 RECT - // unit, and only the SECOND step reaches a square (TX_16X16). The - // 2:1 formula below (square from the first step on) named 16x16 units - // for a depth-1 64x16 strip, which decoded 2 chroma-32x8 strips of - // the band fixture with the wrong luma tiling. depth 1 on a 4:1 strip - // is refused by name; depth >= 2 is square, one step later. - let is_1to4 = bw.max(bh) / bw.min(bh) == 4; - if is_1to4 && depth == 1 && !skip { - return Err(unsupported( - "a coded 1:4 HORZ_4/VERT_4 strip whose transform splits only once (the unit is \ - still a 2:1 rect, not a square)", - )); + // sibling; [`depth_to_tx_wh`] names the unit, which for a 64x16/16x64 + // 1:4 strip is the 2:1 rect TX_32X16 at depth 1 (lane-rectchroma r1 + // measured the old square formula mis-tiling exactly that strip). + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); + if bw.max(bh) / bw.min(bh) == 4 { + let which = if depth == 1 { + &RECT4_SPLIT_DEPTH1_HITS + } else { + &RECT4_SPLIT_DEPTH2_HITS + }; + which.with(|c| c.set(c.get() + 1)); } - let tx = if is_1to4 { - bw.min(bh) >> (depth - 2) - } else { - bw.min(bh) >> (depth - 1) - }; if std::env::var_os("EC_SBPART_DUMP64").is_some() { eprintln!( "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \ - depth={depth} tx={tx} mode={mode} uv={uv_predict_mode} skip={skip} \ + depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \ angle_y={angle_delta_y}" ); } @@ -6541,7 +6975,20 @@ fn decode_block_rect64( PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); } decode_rect_split( - dec, cdfs, neighbours, at, bw, bh, tx, &modes, y, u, v, base_q_idx, reduced_tx_set, + dec, + cdfs, + neighbours, + (mi_r, mi_c), + bw, + bh, + tx_w, + tx_h, + &modes, + y, + u, + v, + base_q_idx, + reduced_tx_set, )?; // Same early-return palette stamp as [`decode_block_rect`]'s split arm // (lane-palette2 r10): this return skips the fn's own tail, so a @@ -8245,8 +8692,10 @@ fn decode_leaf8( reduced_tx_set: bool, ) -> Result { let (r, c) = outer_at; - let mut above_mode = neighbours.above_mode[c]; - let mut left_mode = neighbours.left_mode[r]; + // lane-modectx r1: the group's own availability-correct fallback pair, not + // the raw coarse bands (which leak across a tile edge -- see + // `modes_above_left`). + let (mut above_mode, mut left_mode) = neighbours.modes_above_left(r, c); if let Some(((pr, pc), pmode)) = prev_leaf { if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 { above_mode = pmode; @@ -8258,12 +8707,12 @@ fn decode_leaf8( // `prev_leaf`: one 16x16 slot cannot hold the two different modes its // two 8x8 (or four 4x4) columns leave behind, so a leaf whose above/left // neighbour sits in a split cell read the wrong `kf_y_mode` row. - if let Some(m) = neighbours.mode_above_mi(leaf_mi.0, leaf_mi.1) { - above_mode = m; - } - if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) { - left_mode = m; - } + // lane-rectsplitx r2 swept this arm into + // [`Neighbours::modes_above_left_mi`]: the mi-exact map ALSO has to answer + // "no neighbour" at a tile edge, where the coarse cell holds the block + // above/left of it inside the same 16x16. + let (above_mode, left_mode) = + neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, (above_mode, left_mode)); let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); // Chroma's edge-filter type reads the CHROMA neighbour's `uv_mode` // (`get_intra_edge_filter_type`, reconintra.c:974), never the luma mode @@ -8927,8 +9376,9 @@ fn decode_leaf_rect8( reduced_tx_set: bool, ) -> Result<(usize, usize)> { let (r, c) = outer_at; - let above_mode = neighbours.above_mode[c]; - let left_mode = neighbours.left_mode[r]; + // lane-modectx r1: availability-correct fallback pair (see + // `modes_above_left`), not the raw coarse bands. + let (above_mode, left_mode) = neighbours.modes_above_left(r, c); let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); let (bw, bh) = if vert { (4, 8) } else { (8, 4) }; let (w_mi, h_mi) = (bw / MI, bh / MI); @@ -9773,27 +10223,40 @@ fn read_block_tx_size( let tx = if is_inter { side.min(64) } else { - let resolved = read_tx_size( + read_tx_size( dec, cdfs, n, at_mi, side, Some(tx_size_context_txfm(n, at_mi, side)), - ); - if resolved != side { - // An intra block inside an inter frame whose `tx_depth` splits its - // luma transform needs the per-transform-unit intra prediction - // loop `decode_block` runs for a key frame; this path predicts the - // whole block at once, so refuse rather than mis-reconstruct. - return Err(unsupported( - "an intra block in an inter frame whose tx_depth splits its luma transform \ - (round 1)", - )); - } - resolved + ) }; set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter); + if !is_inter && tx != side { + // lane-intrainter r1: an intra block inside an inter frame whose + // `tx_depth` split its luma transform codes exactly the key-frame + // split path's transform units (`decode_block`'s multi-TU loop), + // raster order over the block. Handed back in the same leaf shape the + // inter var-tx tree uses, so the caller's per-TU luma loop, the + // `record_split_luma` neighbour write-back and the per-TU deblock + // edges are the ones it already runs for a var-tx inter block. A + // caller that has no per-TU intra loop (the 8x8 leaf) refuses on + // seeing `Some` here. + let step = tx / MI; + let mut leaves = Vec::new(); + for row in (0..side_mi).step_by(step) { + for col in (0..side_mi).step_by(step) { + leaves.push((row, col, tx)); + } + } + INTRA_IN_INTER_SPLIT_TX_HITS.with(|c| { + let mut h = c.get(); + h[(side.trailing_zeros() as usize).saturating_sub(3).min(3)] += 1; + c.set(h); + }); + return Ok((tx, Some(leaves))); + } Ok((tx, None)) } @@ -15864,6 +16327,24 @@ fn decode_inter_block( )); } } + // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, + // the tail of `read_intra_block_mode_info`) -- an intra block inside + // an INTER frame reads `use_filter_intra` in exactly the same place a + // key-frame block does, right after the palette syntax. Nothing read + // it here before this round, and aomenc enables filter intra by + // default, so every inter frame carrying one desynced at this symbol. + // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: + // a real palette-Y block already returned above. + 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(side) + && dec.symbol(&mut cdfs.filter_intra[class]) != 0 + { + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); + filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); + } mode_for_tx = mode; block_filter = [3, 3]; ref_frame_for_lf = 0; @@ -15890,7 +16371,14 @@ fn decode_inter_block( } } - read_block_tx_size( + // lane-intrainter r1: an intra block in an inter frame reads the same + // `tx_depth` symbol a key-frame block does, and when it splits, the + // block codes one intra prediction + one coefficient set PER + // transform unit (`decode_block`'s multi-TU branch), not one for the + // whole block. The leaf list rides the existing `vartx_leaves` slot, + // whose tail already does the split-block neighbour write-back + // (`record_split_luma`) and the per-TU deblock edges. + vartx_leaves = read_block_tx_size( dec, cdfs, neighbours, @@ -15899,21 +16387,80 @@ fn decode_inter_block( (mi_cols as usize, mi_rows as usize), false, skip, - )?; + )? + .1; let reach = Reach::of(side, px, py, y.width, y.height); + let split_luma = vartx_leaves.is_some(); + if let Some(leaves) = vartx_leaves.clone() { + let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get); + for &(row, col, tx_px) in &leaves { + let tu_mi = (at_mi.0 + row, at_mi.1 + col); + let (tu_px, tu_py) = (px + col * MI, py + row * MI); + // A transform unit inside a block is not a block at that + // position (class from lane-palette2 r12): top-right / + // bottom-left availability is the block's, narrowed by the + // unit's own offset inside it. + let tu_reach = Reach::of_tu(side, side, col * MI, row * MI, tx_px, tx_px, reach); + let tu_grid = if skip { + y.reconstruct( + tu_px, + tu_py, + tx_px, + mode, + 0, + tu_reach, + &vec![0i32; tx_px * tx_px], + None, + filter_intra, + false, + ); + vec![0i32; tx_px * tx_px] + } else { + // The unit's bsize is smaller than the block it sits in, + // so `txb_skip_ctx` is the neighbour-magnitude table, not + // the lone-TU 0 (`get_txb_ctx_general`). + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); + read_plane( + dec, + cdfs, + txbset_for(tx_px, reduced), + &default_scan(tx_px), + 0, + neighbours.around_mi(tu_mi, tx_px)[0], + mode, + mode, + 0, + tu_reach, + y, + tu_px, + tu_py, + tx_px, + tx_px, + base_q_idx, + None, + filter_intra, + Some(tu_skip_ctx), + false, + )? + }; + neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); + } + } if skip { - y.reconstruct( - px, - py, - side, - mode, - 0, - reach, - &vec![0i32; side * side], - None, - None, - false, - ); + if !split_luma { + y.reconstruct( + px, + py, + side, + mode, + 0, + reach, + &vec![0i32; side * side], + None, + filter_intra, + false, + ); + } let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); u.reconstruct( cpx, @@ -15944,28 +16491,35 @@ fn decode_inter_block( v_grid = vec![0i32; chroma_side * chroma_side]; } else { let around = neighbours.around(at, side); - luma_grid = read_plane( - dec, - cdfs, - luma_set_intra, - scan_luma, - 0, - around[0], - mode, - mode, - 0, - reach, - y, - px, - py, - side, - luma_tx, - base_q_idx, - None, - None, - None, - false, - )?; + luma_grid = if split_luma { + // Already coded and reconstructed unit by unit above; the + // block-level grid is only the neighbour write-back's input, + // which `record_split_luma` ignores for plane 0. + vec![0i32; side * side] + } else { + read_plane( + dec, + cdfs, + luma_set_intra, + scan_luma, + 0, + around[0], + mode, + mode, + 0, + reach, + y, + px, + py, + side, + luma_tx, + base_q_idx, + None, + filter_intra, + None, + false, + )? + }; let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); u_grid = read_plane( dec, @@ -17383,6 +17937,24 @@ fn decode_inter_block8( )); } } + // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, + // the tail of `read_intra_block_mode_info`) -- an intra block inside + // an INTER frame reads `use_filter_intra` in exactly the same place a + // key-frame block does, right after the palette syntax. Nothing read + // it here before this round, and aomenc enables filter intra by + // default, so every inter frame carrying one desynced at this symbol. + // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: + // a real palette-Y block already returned above. + 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(SIDE) + && dec.symbol(&mut cdfs.filter_intra[class]) != 0 + { + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); + filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); + } mode_for_tx = mode; let (mi_row, mi_col) = leaf_mi; for dr in 0..2 { @@ -17406,7 +17978,11 @@ fn decode_inter_block8( } } - read_block_tx_size( + // lane-intrainter r1: the 8x8 leaf's own intra `tx_depth` can only + // resolve to TX_4X4, whose 2x2 unit grid this leaf path has no + // prediction loop for (the >=16x16 square path above does). Refuse by + // name rather than mis-reconstruct. + if read_block_tx_size( dec, cdfs, neighbours, @@ -17415,7 +17991,15 @@ fn decode_inter_block8( (mi_cols as usize, mi_rows as usize), false, skip, - )?; + )? + .1 + .is_some() + { + return Err(unsupported( + "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 \ + transform units", + )); + } let reach = Reach::of(SIDE, px, py, y.width, y.height); if skip { y.reconstruct( @@ -17427,7 +18011,7 @@ fn decode_inter_block8( reach, &vec![0i32; SIDE * SIDE], None, - None, + filter_intra, false, ); u.reconstruct( @@ -17477,7 +18061,7 @@ fn decode_inter_block8( TX8, base_q_idx, None, - None, + filter_intra, None, false, )?; @@ -17646,6 +18230,10 @@ pub fn decode_inter_frame_tile( false, false, DeltaParams::default(), + // `enable_filter_intra`: this crate's own encoder never writes the + // sequence bit (`encode.rs`), so no intra-in-inter block of a stream + // reaching this entry point reads a `use_filter_intra` symbol. + false, ) .map(|(picture, _, _)| picture) } @@ -17729,8 +18317,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // same contract as [`decode_key_frame_tile_with_cdfs`]'s own `delta` // param -- only `q_present`/`q_res` are read. delta: DeltaParams, + // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit + // (spec 5.5.2), stashed in a thread-local with `tx_select` rather than + // threaded through `decode_inter_block`'s fifty parameters -- read by the + // intra-in-inter arms' `read_filter_intra_mode_info`. + enable_filter_intra: bool, ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { - set_inter_tx_mode(tx_select, reduced_tx_set); + set_inter_tx_mode(tx_select, reduced_tx_set, enable_filter_intra); let tpl_frame = tpl_field.map(|field| TplFrameArgs { field, order_hint_bits, diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index f6558880..70125411 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1254,18 +1254,22 @@ impl Reach { bh: usize, col_off: usize, row_off: usize, - tx: usize, + // The unit's own width and height in pixels; equal for a square + // transform, different for the rect unit a 1:4 strip's first split + // produces (lane-rectsplitx r1). + tx_w: usize, + tx_h: usize, block: Self, ) -> Self { Self { - above_right: if col_off + tx < bw { + above_right: if col_off + tx_w < bw { true } else { row_off == 0 && block.above_right }, below_left: if col_off > 0 { false - } else if row_off + tx < bh { + } else if row_off + tx_h < bh { true } else { block.below_left @@ -3882,14 +3886,14 @@ mod tests { // `has_tr_vert_*` tables have no 4x4 row at all, lane-ab16 r2). let plain = Reach::of(8, 0, 8, SUPERBLOCK, SUPERBLOCK); assert_eq!( - Reach::of_tu(8, 8, 4, 0, 4, plain).above_right, + Reach::of_tu(8, 8, 4, 0, 4, 4, plain).above_right, plain.above_right, "ordinary table: the top-right TX4 unit takes the block's row" ); let guard = Reach::vert_ab_partition(); let vert = Reach::of(8, 0, 8, SUPERBLOCK, SUPERBLOCK); assert_eq!( - Reach::of_tu(8, 8, 4, 0, 4, vert).above_right, + Reach::of_tu(8, 8, 4, 0, 4, 4, vert).above_right, vert.above_right, "vert AB: the unit follows the vert row the block just picked" ); @@ -4033,7 +4037,7 @@ mod tests { for row_off in (0..bh).step_by(tx) { for col_off in (0..bw).step_by(tx) { for &blk in &[Reach { above_right: false, below_left: false }, Reach { above_right: true, below_left: true }] { - let got = Reach::of_tu(bw, bh, col_off, row_off, tx, blk); + let got = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, blk); assert_eq!( got.above_right, libaom_tr(bw, bh, col_off, row_off, tx, blk.above_right), diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 610efff2..925d5718 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -226,10 +226,12 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp "enable-dual-filter", "hole at both depths, see the 8-bit list", ), - ( - "enable-flip-idtx", - "hole at both depths, see the 8-bit list", - ), + // `enable-flip-idtx` LEFT this list on 2026-09-02 (lane-rect1d r1): + // `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact` + // passes `=1` at both depths and pixel-compares six 10-bit decodes, so the + // flip/identity/1D transform types are proven to reach a real 10-bit stream + // this decoder reconstructs exactly (10 of its rect coefficient TUs carry a + // 1D tx class). ("enable-intrabc", "hole at both depths, see the 8-bit list"), ("enable-rect-tx", "hole at both depths, see the 8-bit list"), ( diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index a146f745..357febfd 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -32,15 +32,13 @@ const CAPABILITY_CLAIMS: &[&str] = &[ #[cfg(test)] const REFUSALS: &[&str] = &[ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", - "a coded 1:4 HORZ_4/VERT_4 strip whose transform splits only once (the unit is still a 2:1 rect, not a square)", - "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", + "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 32x32 partition type this decoder does not code (value={part32})", - "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is not ported, depth={depth})", "a Golomb tail longer than this decoder reads", "a tx_type symbol outside its CDF's own set: {t}", "an INTER 32x32 partition type this decoder does not code (value={part32})", @@ -64,7 +62,11 @@ const REFUSALS: &[&str] = &[ "a reference picture whose height does not match this frame's own true size", "a show_existing_frame header naming an empty reference slot", "an inter var-tx tree with a leaf transform larger than 32x32", - "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)", + // lane-intrainter r1 lifted the >=16x16 square case (per-TU intra + // prediction + coefficients, gate + // `a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact`); + // the 8x8 leaf's TX_4X4 2x2 grid is still refused here. + "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", "an inter frame with no key frame before it", "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)", "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 822d6e60..62a80e1d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -711,6 +711,7 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.allow_warped_motion, header.allow_screen_content_tools, header.delta, + enable_filter_intra, )?; // lane-superres r10: mirrors the key-frame branch above -- // `decode_inter_frame_tile_with_cdfs` decodes at the downscaled @@ -3938,58 +3939,576 @@ mod tests { ); } - /// lane-txselect's decisive gate: a real aomenc INTER sequence WITHOUT - /// `--enable-tx-size-search=0`, the flag every other inter recipe in this - /// file pins off precisely to keep the stream on `TxMode::Largest`. - /// Dropped, aomenc takes its own default (`TX_MODE_SELECT` -- which is - /// what both of the user's real films use), and an inter block's - /// transform size is then the recursive `txfm_split` tree of spec - /// 5.11.17 rather than one whole-block transform. A stream that decoded - /// pixel-exact while every `txfm_split` symbol resolved to "no split" - /// would prove nothing (it is `TxMode::Largest` by another name), so this - /// gate hard-asserts BOTH counters: at least one `txfm_split` symbol read - /// AND at least one split actually taken. Exhausting every attempt is a - /// FAILURE, not a SKIP -- an unfired gate is a vacuous gate. + /// lane-txselect's decisive gate: a real aomenc INTER sequence WITHOUT + /// `--enable-tx-size-search=0`, the flag every other inter recipe in this + /// file pins off precisely to keep the stream on `TxMode::Largest`. + /// Dropped, aomenc takes its own default (`TX_MODE_SELECT` -- which is + /// what both of the user's real films use), and an inter block's + /// transform size is then the recursive `txfm_split` tree of spec + /// 5.11.17 rather than one whole-block transform. A stream that decoded + /// pixel-exact while every `txfm_split` symbol resolved to "no split" + /// would prove nothing (it is `TxMode::Largest` by another name), so this + /// gate hard-asserts BOTH counters: at least one `txfm_split` symbol read + /// AND at least one split actually taken. Exhausting every attempt is a + /// FAILURE, not a SKIP -- an unfired gate is a vacuous gate. + #[test] + fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact() { + tx_select_inter_gate(8); + } + + /// The 10-bit arm of the gate above (lane-txselect r2): both of the + /// user's films are `yuv420p10le` and var-tx is exactly the tool they + /// use, so an 8-bit-only proof would not reach them. Same recipe plus + /// `-b 10 --input-bit-depth=10`. + #[test] + fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact_10bit() { + tx_select_inter_gate(10); + } + + fn tx_select_inter_gate(bit_depth: u32) { + if !have_ffmpeg() { + eprintln!( + "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg" + ); + return; + } + if !have_aomenc() { + eprintln!( + "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no aomenc at {}", + aomenc_path().display() + ); + return; + } + let (width, height, frame_count) = (64usize, 64usize, 4usize); + let mut refusals = Vec::new(); + let mut uncounted_exact = 0u32; + for attempt in 0..40u32 { + let seed = 42 + attempt; + // Detail is what makes aomenc's RD prefer a split transform; a + // flat gradient resolves every `txfm_split` to 0. `mandelbrot`'s + // fractal boundary is the same source the sibling intra tx-select + // gate uses, at a different `start_scale` per attempt. + let source = format!( + "mandelbrot=size=64x64:start_scale={}:rate=25", + 5.0 - f64::from(attempt) * 0.06 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + // Desaturated chroma: `uv_mode` stays DC_PRED, so the + // still-refused directional-chroma gap never fires and + // luma detail alone drives the transform split. + "-vf", + "hue=s=0", + "-pix_fmt", + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + // y4m carries no official 10-bit tag; ffmpeg writes one + // only under `-strict -1` (a no-op at 8 bit). + "-strict", + "-1", + "-t", + "0.16", + "-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 { + &[] + }; + let mut child = Command::new(aomenc_path()) + .args(depth_args) + .args([ + // lane-defon r1: explicit on-value (aomenc keeps the FIRST + // occurrence, so overrides go before the base list). + "--enable-tx-size-search=1", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=55", + "--cpu-used=0", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--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-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + // DELIBERATELY ABSENT: --enable-tx-size-search=0. + "--enable-cdef=0", + "--enable-restoration=0", + "--max-partition-size=32", + // Sub-16 inter partitions are a separate named refusal + // (this decoder codes no inter block below 16x16 through + // the square path this gate drives), and detailed content + // makes aomenc's RD reach for them on nearly every seed. + "--min-partition-size=16", + "--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 (reads_before, hits_before) = + (decode::txfm_split_reads(), decode::txfm_split_hits()); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "tx-select inter decode failed outright (seed {seed}): {msg}" + ); + refusals.push(format!("seed {seed}: {msg}")); + continue; + } + }; + let (reads, hits) = ( + decode::txfm_split_reads() - reads_before, + decode::txfm_split_hits() - hits_before, + ); + // class [[gate-skips-on-its-own-failure]]: a decode that succeeded + // is ALWAYS pixel-compared below; the hit counter only decides whether + // the attempt counts toward the firing total. + let counted = hits != 0; + if !counted { + uncounted_exact += 1; + refusals.push(format!( + "seed {seed}: decoded and pixel-compared, but no block took a txfm_split \ + ({reads} symbols read)" + )); + } + 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!( + "txselect gate {bit_depth}-bit seed={seed}: txfm_split reads={reads} splits taken={hits}" + ); + // Name the first differing sample before the assert fires: a + // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for + // locating a desync. + 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!( + "txselect gate 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(), + ); + let coords: Vec = g + .iter() + .zip(w.iter()) + .enumerate() + .filter(|(_, (a, b))| a != b) + .take(12) + .map(|(k, (a, b))| format!("({},{})={a}/{b}", k % stride, k / stride)) + .collect(); + eprintln!("txselect gate seed={seed}: frame {i} {plane} diffs {coords:?}"); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); + } + if counted { + gate_buckets( + &format!("tx_select_inter_gate({bit_depth})"), + 1, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + return; + } + } + gate_buckets( + &format!("tx_select_inter_gate({bit_depth})"), + 0, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + panic!( + "tx_select_inter_gate({bit_depth}) never observed a taken txfm_split:\n{}", + refusals.join("\n") + ); + } + + /// lane-intrainter r1's decisive gate: a real aomenc INTER sequence in + /// which aomenc's RD picks an INTRA block inside an inter frame AND + /// splits that block's luma transform (`tx_depth >= 1`, the intra depth + /// symbol -- not the inter var-tx tree). That block codes one intra + /// prediction plus one coefficient set per transform unit, exactly like a + /// key frame's split block but with the inter frame's CDF state and the + /// inter-frame intra mode syntax; before this lane it was a named + /// refusal. Hard-asserts [`decode::intra_in_inter_split_tx_hits`] per + /// block size: an attempt that never produced such a block proves + /// nothing, and exhausting every attempt is a FAILURE, not a SKIP. + #[test] + fn a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact() { + intra_in_inter_split_tx_gate(8); + } + + /// The 10-bit arm (both of the user's films are `yuv420p10le`). + #[test] + fn a_real_aomenc_10bit_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact() { + intra_in_inter_split_tx_gate(10); + } + + fn intra_in_inter_split_tx_gate(bit_depth: u32) { + let name = format!("intra_in_inter_split_tx_gate({bit_depth})"); + 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) = (64usize, 64usize, 8usize); + let mut refusals = Vec::new(); + let mut uncounted_exact = 0u32; + for attempt in 0..40u32 { + let seed = 42 + attempt; + // A zooming fractal: every frame moves (so the sequence is + // genuinely inter-coded) and keeps sharp new detail entering at + // the borders, which is what makes aomenc's RD choose an INTRA + // block inside an inter frame -- and then split its transform. + // A zooming fractal with a hard CUT halfway (`overlay` switching + // a second, unrelated fractal on at frame 4): after the cut every + // block is unpredictable from the reference, which is what makes + // aomenc code INTRA blocks inside an inter frame -- and at this + // cq the RD then splits their transforms. + let source = format!( + "mandelbrot=size=64x64:start_scale={}:rate=25[a];\ + mandelbrot=size=64x64:start_scale={}:rate=25[b];\ + [a][b]overlay=enable='gte(n,4)'", + 5.0 - f64::from(attempt) * 0.06, + 0.9 + f64::from(attempt) * 0.11 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + // Desaturated chroma keeps `uv_mode` on DC_PRED, so the + // still-refused directional-chroma gaps never fire and + // luma detail alone drives the transform split. + "-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 { + &[] + }; + let mut child = Command::new(aomenc_path()) + .args(depth_args) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=30", + "--cpu-used=0", + "--lag-in-frames=0", + "--auto-alt-ref=0", + // One key frame only: every later frame is an inter frame, + // which is where this gate's intra blocks must sit. The + // MIN distance is what stops aomenc's scene-cut detector + // from inserting a second key frame at the cut this gate's + // source deliberately contains. + "--kf-max-dist=1000", + "--kf-min-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", + "--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", + // Per-arm overrides go LAST (aomenc keeps the last + // occurrence of a repeated --enable-* flag): the intra + // tx_depth symbol only exists under TX_MODE_SELECT, and + // rect partitions are a separate named refusal. + "--enable-tx-size-search=1", + "--enable-rect-partitions=0", + "--max-partition-size=32", + // Sub-16 inter partitions are a separate named refusal, + // as is the 8x8 intra leaf's own TX_4X4 split. + "--min-partition-size=16", + "--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_in_inter_split_tx_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{name} decode failed outright (seed {seed}): {msg}" + ); + refusals.push(format!("seed {seed}: {msg}")); + continue; + } + }; + let after = decode::intra_in_inter_split_tx_hits(); + let mut per_size = [0usize; 4]; + for i in 0..4 { + per_size[i] = after[i] - before[i]; + } + // class [[gate-skips-on-its-own-failure]]: a decode that + // succeeded is ALWAYS pixel-compared below; the counter only + // decides whether the attempt counts as firing. + let counted = per_size.iter().sum::() != 0; + if !counted { + uncounted_exact += 1; + refusals.push(format!( + "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ + frame split its transform" + )); + } + 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!( + "{name} seed={seed}: split intra-in-inter blocks 8x8={} 16x16={} 32x32={} \ + 64x64={}", + per_size[0], per_size[1], per_size[2], per_size[3] + ); + 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!( + "{name} 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(), + ); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); + } + if counted { + gate_buckets( + &name, + 1, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + return; + } + } + gate_buckets( + &name, + 0, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + panic!( + "{name} never observed a split-transform intra block in an inter frame:\n{}", + refusals.join("\n") + ); + } + + /// lane-fiinter r1 (class [[symbol-consumption-gap]] + + /// [[tool-disabled-in-every-gate]]): a real aomenc inter sequence with + /// `--enable-filter-intra=1` (aomenc's own default -- every inter gate + /// recipe before this one pinned it OFF, so nothing ever exercised it) in + /// which the RD picks an INTRA block inside an inter frame and gives it + /// filter intra. `read_intra_block_mode_info` reads `use_filter_intra` + /// there exactly as a key frame does; this decoder read no such symbol at + /// all until this round, so such a stream desynced at that symbol and + /// decoded silently wrong. Hard-asserts + /// [`decode::intra_in_inter_filter_intra_hits`]: an attempt that never + /// produced one proves nothing, and exhausting every attempt is a + /// FAILURE, not a SKIP. #[test] - fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact() { - tx_select_inter_gate(8); + fn a_real_aomenc_inter_sequence_with_filter_intra_on_an_intra_block_decodes_pixel_exact() { + filter_intra_in_inter_gate(8); } - /// The 10-bit arm of the gate above (lane-txselect r2): both of the - /// user's films are `yuv420p10le` and var-tx is exactly the tool they - /// use, so an 8-bit-only proof would not reach them. Same recipe plus - /// `-b 10 --input-bit-depth=10`. + /// The 10-bit arm (both of the user's films are `yuv420p10le`). #[test] - fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact_10bit() { - tx_select_inter_gate(10); + fn a_real_aomenc_10bit_inter_sequence_with_filter_intra_on_an_intra_block_decodes_pixel_exact() + { + filter_intra_in_inter_gate(10); } - fn tx_select_inter_gate(bit_depth: u32) { + fn filter_intra_in_inter_gate(bit_depth: u32) { + let name = format!("filter_intra_in_inter_gate({bit_depth})"); if !have_ffmpeg() { - eprintln!( - "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg" - ); + eprintln!("SKIP {name}: no ffmpeg"); return; } if !have_aomenc() { - eprintln!( - "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no aomenc at {}", - aomenc_path().display() - ); + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); return; } - let (width, height, frame_count) = (64usize, 64usize, 4usize); + let (width, height, frame_count) = (64usize, 64usize, 8usize); let mut refusals = Vec::new(); let mut uncounted_exact = 0u32; for attempt in 0..40u32 { let seed = 42 + attempt; - // Detail is what makes aomenc's RD prefer a split transform; a - // flat gradient resolves every `txfm_split` to 0. `mandelbrot`'s - // fractal boundary is the same source the sibling intra tx-select - // gate uses, at a different `start_scale` per attempt. + // A zooming fractal: every frame moves (so the sequence is + // genuinely inter-coded) and keeps sharp new detail entering at + // the borders, which is what makes aomenc's RD choose an INTRA + // block inside an inter frame -- and then split its transform. + // A zooming fractal with a hard CUT halfway (`overlay` switching + // a second, unrelated fractal on at frame 4): after the cut every + // block is unpredictable from the reference, which is what makes + // aomenc code INTRA blocks inside an inter frame -- and at this + // cq the RD then splits their transforms. let source = format!( - "mandelbrot=size=64x64:start_scale={}:rate=25", - 5.0 - f64::from(attempt) * 0.06 + "mandelbrot=size=64x64:start_scale={}:rate=25[a];\ + mandelbrot=size=64x64:start_scale={}:rate=25[b];\ + [a][b]overlay=enable='gte(n,4)'", + 5.0 - f64::from(attempt) * 0.06, + 0.9 + f64::from(attempt) * 0.11 ); let y4m = Command::new("ffmpeg") .args([ @@ -3999,19 +4518,17 @@ mod tests { "lavfi", "-i", &source, - // Desaturated chroma: `uv_mode` stays DC_PRED, so the - // still-refused directional-chroma gap never fires and + // Desaturated chroma keeps `uv_mode` on DC_PRED, so the + // still-refused directional-chroma gaps never fire and // luma detail alone drives the transform split. "-vf", "hue=s=0", "-pix_fmt", if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, - // y4m carries no official 10-bit tag; ffmpeg writes one - // only under `-strict -1` (a no-op at 8 bit). "-strict", "-1", "-t", - "0.16", + "0.32", "-f", "yuv4mpegpipe", "-strict", @@ -4036,17 +4553,20 @@ mod tests { let mut child = Command::new(aomenc_path()) .args(depth_args) .args([ - // lane-defon r1: explicit on-value (aomenc keeps the FIRST - // occurrence, so overrides go before the base list). - "--enable-tx-size-search=1", "--codec=av1", "--passes=1", "--end-usage=q", - "--cq-level=55", + "--cq-level=30", "--cpu-used=0", "--lag-in-frames=0", "--auto-alt-ref=0", + // One key frame only: every later frame is an inter frame, + // which is where this gate's intra blocks must sit. The + // MIN distance is what stops aomenc's scene-cut detector + // from inserting a second key frame at the cut this gate's + // source deliberately contains. "--kf-max-dist=1000", + "--kf-min-dist=1000", "--threads=1", "--row-mt=0", "--enable-order-hint=0", @@ -4059,27 +4579,29 @@ mod tests { "--enable-onesided-comp=0", "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", - "--enable-rect-partitions=0", "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--enable-filter-intra=0", "--enable-smooth-intra=0", "--enable-paeth-intra=0", "--enable-directional-intra=0", "--enable-angle-delta=0", - // DELIBERATELY ABSENT: --enable-tx-size-search=0. "--enable-cdef=0", "--enable-restoration=0", - "--max-partition-size=32", - // Sub-16 inter partitions are a separate named refusal - // (this decoder codes no inter block below 16x16 through - // the square path this gate drives), and detailed content - // makes aomenc's RD reach for them on nearly every seed. - "--min-partition-size=16", "--enable-palette=0", "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", + // Per-arm overrides go LAST (aomenc keeps the last + // occurrence of a repeated --enable-* flag): the intra + // tx_depth symbol only exists under TX_MODE_SELECT, and + // rect partitions are a separate named refusal. + "--enable-filter-intra=1", + "--enable-tx-size-search=1", + "--enable-rect-partitions=0", + "--max-partition-size=32", + // Sub-16 inter partitions are a separate named refusal, + // as is the 8x8 intra leaf's own TX_4X4 split. + "--min-partition-size=16", "--obu", "-o", "-", @@ -4103,33 +4625,29 @@ mod tests { String::from_utf8_lossy(&out.stderr) ); let stream = out.stdout; - let (reads_before, hits_before) = - (decode::txfm_split_reads(), decode::txfm_split_hits()); + let before = decode::intra_in_inter_filter_intra_hits(); let frames = match decode_stream(&stream) { Ok(frames) => frames, Err(e) => { let msg = e.to_string(); assert!( msg.contains("unsupported"), - "tx-select inter decode failed outright (seed {seed}): {msg}" + "{name} decode failed outright (seed {seed}): {msg}" ); refusals.push(format!("seed {seed}: {msg}")); continue; } }; - let (reads, hits) = ( - decode::txfm_split_reads() - reads_before, - decode::txfm_split_hits() - hits_before, - ); - // class [[gate-skips-on-its-own-failure]]: a decode that succeeded - // is ALWAYS pixel-compared below; the hit counter only decides whether - // the attempt counts toward the firing total. - let counted = hits != 0; + let fired = decode::intra_in_inter_filter_intra_hits() - before; + // class [[gate-skips-on-its-own-failure]]: a decode that + // succeeded is ALWAYS pixel-compared below; the counter only + // decides whether the attempt counts as firing. + let counted = fired != 0; if !counted { uncounted_exact += 1; refusals.push(format!( - "seed {seed}: decoded and pixel-compared, but no block took a txfm_split \ - ({reads} symbols read)" + "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ + frame used filter intra" )); } let ffmpeg_frames = if bit_depth == 10 { @@ -4139,11 +4657,8 @@ mod tests { }; assert_eq!(frames.len(), frame_count); eprintln!( - "txselect gate {bit_depth}-bit seed={seed}: txfm_split reads={reads} splits taken={hits}" + "{name} seed={seed}: filter-intra blocks inside inter frames = {fired}" ); - // Name the first differing sample before the assert fires: a - // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for - // locating a desync. for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { for (plane, (g, w)) in [ ("Y", (&got.y, &want.y)), @@ -4153,23 +4668,14 @@ mod tests { let stride = if plane == "Y" { width } else { width / 2 }; if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { eprintln!( - "txselect gate seed={seed}: frame {i} {plane} first diff at \ - ({}, {}) got {} want {} ({} samples differ)", + "{name} 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(), ); - let coords: Vec = g - .iter() - .zip(w.iter()) - .enumerate() - .filter(|(_, (a, b))| a != b) - .take(12) - .map(|(k, (a, b))| format!("({},{})={a}/{b}", k % stride, k / stride)) - .collect(); - eprintln!("txselect gate seed={seed}: frame {i} {plane} diffs {coords:?}"); } } } @@ -4180,7 +4686,7 @@ mod tests { } if counted { gate_buckets( - &format!("tx_select_inter_gate({bit_depth})"), + &name, 1, uncounted_exact, refusals.len() - uncounted_exact as usize, @@ -4189,13 +4695,13 @@ mod tests { } } gate_buckets( - &format!("tx_select_inter_gate({bit_depth})"), + &name, 0, uncounted_exact, refusals.len() - uncounted_exact as usize, ); panic!( - "tx_select_inter_gate({bit_depth}) never observed a taken txfm_split:\n{}", + "{name} never observed a filter-intra intra block in an inter frame:\n{}", refusals.join("\n") ); } @@ -9302,22 +9808,26 @@ mod tests { attempts.iter().filter(|a| !a.tx_size_search).count(), "{NAME}: every fixed-transform attempt must decode and compare" ); - // The tx-size-search attempts cannot be compared pixel by pixel yet: - // every 16x16 AB partition contains a strip, and with a free - // transform size aomenc splits at least one of them in every stream - // of a 40-cell {source, cq} sweep (r2 report), so they all stop at - // lane-rectx's "strip with a split transform" refusal (or the 1:4 / - // sub-8x8 ones) before the frame is done. What they DO prove is that - // the TX4 sub-grid of an 8x8 square inside a VERT_A/VERT_B is reached - // on a real stream and answers -- it used to panic there, and a panic - // cannot be tolerated by the `unsupported` arm above. The values it - // answers are pinned separately against libaom in - // `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`. - let _ = tx4_compared; - assert!( - tx4_reached > 0, - "{NAME}: no --enable-tx-size-search=1 attempt reached a TX4 unit inside a \ - vertical AB partition -- the r2 panic path is unproven" + // Until the lane-rectsplitx merge every tx-size-search attempt stopped + // at "a HORZ/VERT intra strip below 16x16 with a split transform", so + // this gate could only claim that the TX4 sub-grid of an 8x8 square + // inside a VERT_A/VERT_B was REACHED (`tx4_reached`, counted even on a + // refused attempt). With per-TU rect prediction those same attempts now + // decode to the end and compare pixel-exact, and they carry no vert-AB + // TX4 unit at all -- the pre-merge nonzero count came from decodes that + // were still desynced when they hit the refusal (class + // counter-from-refused-stream). The full pixel compare is the stronger + // claim and replaces it; the lookup's VALUES stay pinned against libaom + // in `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`. + eprintln!("{NAME}: vert-AB TX4 units reached across tx-size-search attempts: {tx4_reached}"); + let _ = tx4_reached; + assert_eq!( + tx4_compared, + attempts.iter().filter(|a| a.tx_size_search).count(), + "{NAME}: every --enable-tx-size-search=1 attempt must now decode to the end and \ + compare pixel-exact (the split-transform strip refusal these used to stop at is \ + lifted); the vert-AB TX4 lookup values stay pinned by \ + `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`" ); for (i, arm) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { assert!(arms[i] > 0, "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \ @@ -12947,7 +13457,7 @@ mod tests { /// `encode::tests::every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock` /// against libaom's own `has_tr_*`/`has_bl_*` arrays. #[test] - #[ignore = "the coded 16x8/8x16 strip is a live refusal; see the doc above"] + #[ignore = "lane-rectsplitx r2 (re-measured after the neighbour-mode fix): every seed 700..739 attempt now stops at another lane's refusal 'a HORZ_A/HORZ_B/VERT_A partition below 16x16', so the gate reaches no strip at all -- blocked on AB partitions below 16x16, not on this lane"] fn a_directional_16x8_strip_reads_the_right_above_right_samples() { const NAME: &str = "a_directional_16x8_strip_reads_the_right_above_right_samples"; if !have_ffmpeg() { @@ -13369,6 +13879,13 @@ mod tests { let (width, height) = (128usize, 64usize); let mut matched = 0u32; let mut named_refusals = 0u32; + // lane-modectx r1: luma `kf_y_mode` neighbour reads whose coarse + // fallback band held a previous tile's mode at a tile edge. Measured 0 + // -- `above_mode` is cleared per tile and `left_mode` per superblock + // row -- and that is exactly why the coarse fallback is safe where + // lane-mtfix's chroma one was not. Accumulated only for attempts that + // then compared pixel-exact (class counter-from-refused-stream). + let mut mode_edge_leaks = 0usize; for attempt in 0..20u32 { let seed = 42 + attempt; let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); @@ -13511,6 +14028,7 @@ mod tests { .is_some_and(|seq| seq.enable_intra_edge_filter); let before = crate::decode::tile_hits(); + let before_edge = crate::decode::mode_tile_edge_coarse_leaks(); let picture = match decode_key_frame_tile_with_cdfs( &tile_bufs, &header.tile_info, @@ -13561,6 +14079,7 @@ mod tests { assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + mode_edge_leaks += crate::decode::mode_tile_edge_coarse_leaks() - before_edge; matched += 1; } assert!( @@ -13568,8 +14087,15 @@ mod tests { "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \ a two-tile-column stream" ); + assert_eq!( + mode_edge_leaks, 0, + "{NAME}: a luma mode neighbour read at a tile edge saw a NON-DC coarse band -- the \ + per-tile `above_mode` / per-superblock-row `left_mode` reset that makes the coarse \ + fallback safe has regressed" + ); eprintln!( - "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20, \ + {mode_edge_leaks} tile-edge coarse leaks" ); } @@ -16258,6 +16784,269 @@ mod tests { ); } + /// lane-rect1d r1 (copied from lane-rectclass r1): the class-correctness measurement for every + /// RECTANGULAR transform unit this decoder reads. [`crate::decode::read_coeffs_rect`] + /// handles `TxClass::TwoD` only -- it refuses by name both a coded + /// `tx_type` symbol and a non-2D default -- so the open question a + /// verifier raised was whether a real encoder ever puts a + /// `V_DCT`/`H_DCT` (`TX_CLASS_HORIZ`/`VERT`) type on a rect TU that + /// reaches this reader. The recipe deliberately maximises the chance: + /// `--enable-flip-idtx=1` (the flip/identity/1D types are exactly what + /// `EXT_TX_SET_DTT4_IDTX_1DDCT` and the wider inter sets add), + /// `--enable-tx-size-search=1`, rect partitions on, small minimum + /// partition size, both bit depths. Every successful decode is + /// pixel-compared; the rect-TU counter is folded in PER ATTEMPT and only + /// after that attempt compared (class `counter-from-refused-stream`), and + /// the class-1 refusal counter is summed over EVERY attempt including the + /// refused ones -- a refused attempt is exactly where a 1D class on a + /// rect TU would show up. + /// + /// lane-rect1d: on THIS tree `read_coeffs_rect` no longer refuses a 1D + /// class -- lane-tx4x8 gave it the mrow/mcol scan and the class-aware + /// base/br contexts -- so the live pins are `compared_class1 > 0` (the + /// flag arrived and 1D types were coded) plus the pixel compare itself. + #[test] + fn a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_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 mut named_refusals = 0u32; + let mut matched = 0u32; + let mut matched_10bit = 0u32; + let mut compared_rect_tus = 0usize; + let mut compared_rect_parts = 0usize; + let mut compared_tx_depths = 0usize; + let mut compared_class1 = 0usize; + let mut compared_rect_class1 = 0usize; + let n_attempts: u32 = std::env::var("EC_RECTCLASS_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(12); + // Both bit depths in one sweep: his two films are yuv420p10le, and a + // class claim that only holds at 8 bits is worth nothing to them. + for attempt in 0..n_attempts { + let seed = 42 + attempt / 2; + let ten_bit = attempt % 2 == 1; + let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + // Content + quantiser sweep: the 1D (`V_DCT`/`H_DCT`) types RD can + // only pick on strongly one-directional detail, and only when the + // quantiser leaves that detail in the residual -- smooth gradients + // at cq 45 produced exactly zero of them (measured this round), + // which would have made the `--enable-flip-idtx=1` arrival assert + // fail rather than the gate pass vacuously. + let period = [4u32, 6, 8, 12, 16][(attempt as usize / 2) % 5]; + let source = format!("testsrc2=size={width}x{height}:rate=25"); + let filter = format!( + "geq=lum='128+80*sin(2*PI*Y/{period})':cb='128+60*sin(2*PI*X/{period})':cr=128,\ + noise=alls=6:allf=t" + ); + let cq = if attempt % 4 < 2 { "--cq-level=20" } else { "--cq-level=40" }; + let y4m = Command::new("ffmpeg") + .args([ + // `-strict -1`: y4m calls 10-bit an unofficial pixel + // format and refuses to write the header otherwise (no-op + // at 8 bit). + "-v", "error", "-f", "lavfi", "-i", &source, "-vf", &filter, "-t", "0.04", + "-pix_fmt", pix_fmt, "-strict", "-1", "-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) + ); + // aomenc keeps the LAST occurrence of a repeated `--enable-*` + // flag (measured 2026-09-02 by md5 of four orderings), so this + // lane's overrides come AFTER the base recipe. They are also + // proven to have ARRIVED rather than assumed: the asserts below + // pin a nonzero rect-partition, tx-depth and 1D-tx-class counter + // on pixel-compared attempts, one per override. + let mut args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + cq, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + ]; + if ten_bit { + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); + } + args.extend_from_slice(&[ + "--enable-rect-partitions=1", + "--enable-tx-size-search=1", + "--enable-flip-idtx=1", + // Without this aomenc's reduced tx set narrows every block to + // DCT_DCT/IDTX and no 1D type can be coded at all -- the flag + // that actually gates the class, as the arrival assert below + // proved by staying at 0 without it. + "--reduced-tx-type-set=0", + "--min-partition-size=8", + "--max-partition-size=32", + "--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})"); + if ten_bit { + let mut probe = Av1Parser::new(); + let mut pos = 0usize; + while pos < stream.len() && probe.sequence_header().is_none() { + let obu = probe.parse_obu(&stream[pos..]).unwrap(); + pos += obu.total_size; + } + assert_eq!( + probe + .sequence_header() + .expect("stream has a sequence header OBU") + .color_config + .bit_depth, + 10, + "{NAME}: aomenc did not actually write a 10-bit sequence header" + ); + } + let attempt_before = crate::decode::rect_coeff_tu_hits(); + let rect_before = crate::decode::rect_partition_hits(); + let depth_before = crate::decode::tx_depth_hits(); + let class1_before = crate::decode::tx_class1_hits(); + let rect_class1_before = crate::decode::rect_class1_hits(); + 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}, 10bit \ + {ten_bit}): {msg}" + ); + named_refusals += 1; + continue; + } + Ok(frames) => frames, + }; + let ffmpeg_frames = if ten_bit { + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) + } else { + ffmpeg_decode_sequence(&stream, width, height, 1) + }; + assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})"); + assert_eq!( + frames[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed}, 10bit {ten_bit})" + ); + assert_eq!( + frames[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed}, 10bit {ten_bit})" + ); + assert_eq!( + frames[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed}, 10bit {ten_bit})" + ); + compared_rect_tus += crate::decode::rect_coeff_tu_hits() - attempt_before; + compared_rect_parts += crate::decode::rect_partition_hits() - rect_before; + compared_tx_depths += crate::decode::tx_depth_hits() - depth_before; + compared_class1 += crate::decode::tx_class1_hits() - class1_before; + compared_rect_class1 += crate::decode::rect_class1_hits() - rect_class1_before; + matched += 1; + matched_10bit += u32::from(ten_bit); + } + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded \ + nothing" + ); + assert!( + matched_10bit > 0, + "{NAME}: every 10-bit attempt refused -- his films are yuv420p10le, so a gate that \ + only compared 8-bit streams proves nothing for them" + ); + assert!( + compared_rect_tus > 0, + "{NAME}: no pixel-exact attempt coded a single rectangular transform unit \ + ({matched} matches, {named_refusals} refusals out of {n_attempts}) -- the gate \ + measured nothing about rect coefficient reading" + ); + // FLAG ARRIVAL, one assert per override (a flag whose counter stays + // at 0 is an inert flag, not a passing gate). + assert!( + compared_rect_parts > 0, + "{NAME}: --enable-rect-partitions=1 never produced a rect partition on a compared \ + attempt ({matched} matches) -- the flag did not arrive" + ); + assert!( + compared_tx_depths > 0, + "{NAME}: --enable-tx-size-search=1 never produced a nonzero tx depth on a compared \ + attempt ({matched} matches) -- the flag did not arrive" + ); + assert!( + compared_class1 > 0, + "{NAME}: --enable-flip-idtx=1 never produced a V_DCT/H_DCT transform on a compared \ + attempt ({matched} matches) -- the 1D types live only in the extended ext-tx sets \ + this flag enables, so the flag did not arrive" + ); + // lane-rect1d r1: the pin of the LANE's own capability -- a V_DCT/H_DCT + // transform on a RECTANGULAR transform unit, read through + // `read_coeffs_rect`'s own 1D scan and contexts. `compared_class1` + // above counts square TUs too, so it can be nonzero while this path + // never fires. + assert!( + compared_rect_class1 > 0, + "{NAME}: no pixel-exact attempt put a 1D tx class on a RECTANGULAR transform \ + ({compared_class1} 1D transforms overall, {compared_rect_tus} rect coefficient \ + TUs) -- the gate proves nothing about the rect 1D path" + ); + eprintln!( + "{NAME}: {matched} pixel-exact decodes ({named_refusals} named refusals out of \ + {n_attempts} attempts, {matched_10bit} of the matches 10-bit), rect coefficient \ + TUs on compared attempts: {compared_rect_tus} ({compared_rect_class1} of them a \ + 1D tx class); flag arrival: rect partitions {compared_rect_parts}, tx \ + depths {compared_tx_depths}, 1D-class (square) transforms {compared_class1}" + ); + } + /// 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 @@ -16481,17 +17270,15 @@ mod tests { } /// lane-fistrip r1, the 10-bit arm of the strip gate (his films are - /// yuv420p10le). Same ceiling as its 8-bit twin -- kept `#[ignore]`d - /// with the measurement rather than weakened: MEASURED over seeds + /// yuv420p10le). Same ceiling as its 8-bit twin, lifted in lane-rectsplitx + /// r3 (the split arm's `smooth_neighbor_uv`); before that, MEASURED over seeds /// 42..61 the 8x16/16x8 strips aomenc writes filter intra on are /// `skip=0`, which `decode_leaf_rect` refuses, so /// `filter_intra_rect_sub16_hits` never reaches a pixel compare. /// lane-fistrip r2 adds seeds 49 and 213 to the window: those are the two /// seeds measured to fire the feature on the 8-BIT twin's recipe (this /// arm's 10-bit encode is a different stream, so they are a widening, not - /// a measured firing set for this recipe -- the round that un-ignores - /// this gate must re-measure which 10-bit seeds fire it). - #[ignore = "2026-09-02, re-measured on the merged tree: the coded-strip refusal is lifted, but every firing 10-bit seed now stops at the sub16 SPLIT-TRANSFORM refusal (49, 55) or palette-in-screen-content (45, 46); 16 attempts decode pixel-exact with 0 hits, so the gate would prove nothing"] + /// a measured firing set for this recipe). Green since r3. #[test] fn a_real_aomenc_10bit_filter_intra_on_a_sub16_strip_decodes_pixel_exact() { const NAME: &str = "a_real_aomenc_10bit_filter_intra_on_a_sub16_strip_decodes_pixel_exact"; @@ -16574,29 +17361,40 @@ mod tests { .join("fixtures/filter_intra_8x16_strip_seed49.obu"); let stream = std::fs::read(&path) .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } let before = crate::decode::filter_intra_rect_sub16_hits(); - let err = decode_stream(&stream).expect_err( - "{NAME}: this stream's 16x8 filter-intra strip is skip=0, which this decoder \ - still refuses -- a clean decode means the coded-strip ceiling moved and this \ - test should become a pixel compare", - ); + // lane-rectsplitx r1: the ceiling this fixture used to stop at (a + // sub-16 strip with a SPLIT transform) is ported, so the pinned + // stream is now a full pixel compare -- what the doc above said this + // test should become the round that ceiling lifted. + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: decode refused: {e}")); let hits = crate::decode::filter_intra_rect_sub16_hits() - before; + // TWO now, not the one the truncated decode used to see: the frame + // no longer stops at the first filter-intra strip, so the second one + // later in the tile is reached as well (and the pixel compare below + // proves both reconstructed right). assert_eq!( - hits, 1, - "{NAME}: expected exactly one 16x8 strip to read use_filter_intra=1 (aomdec's own \ - EC_TRACE_MODE shows four BLOCK_16X8 DC_PRED leaves here); got {hits}" + hits, 2, + "{NAME}: expected both 16x8 strips to read use_filter_intra=1; got {hits}" ); - let msg = err.to_string(); + // This is also the GATE for the sub-16 split-transform lift: both + // strips split their transform (`tx_depth != 0` on a BLOCK_16X8 -> + // two TX_8X8 units), which is the refusal this round removed. + let splits = crate::decode::sub16_split_hits(); assert!( - // 2026-09-02, merging lane-fistrip onto a main that already carries - // lane-rectx: the coded-strip ceiling this fixture used to hit is - // gone, and the very next one on the SAME block is the split - // transform under a sub-16 strip (per-unit rect prediction is not - // ported). Still a refusal ON that block, still not a desync. - msg.contains("a HORZ/VERT intra strip below 16x16 with a split transform"), - "{NAME}: decode must reach the sub16 split-transform ceiling ON that block, not \ - wander off a desynced stream; got: {msg}" + splits > 0, + "{NAME}: no sub-16 strip split its transform -- the fixture no longer proves the \ + per-unit path this test gates" ); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 192, 128, 1); + assert_eq!(frames.len(), 1, "{NAME}: expected one frame"); + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); } /// lane-fistrip r1: the filter-intra strip gate above, one partition @@ -16612,19 +17410,20 @@ mod tests { /// `filter_intra_rect_hits`: a 32x16 strip firing filter intra would /// satisfy that one and prove nothing about the new shapes. /// MEASURED (lane-fistrip r1, seeds 42..=241; r2 re-ran 50..=241), which - /// is why it is `#[ignore]`d rather than green: over those 200 seeds at + /// is why the window carries the two firing seeds: over those 200 seeds at /// cq 25 aomenc put filter intra on an 8x16/16x8 strip exactly TWICE -- /// **seed 49 and seed 213** -- and both times that strip was `skip=0`, so /// the attempt refused at the coded-rect-strip-below-16x16 ceiling before /// any pixel compare (r1: 177 pixel-exact matches, 23 refusals, compared /// sub16 delta 0, all-attempt delta 2; r2 seeds 50..=241: 172 matches, 20 /// refusals, the one all-attempt hit at seed 213). BOTH firing seeds are - /// appended to this gate's seed window below, so the un-ignore compares - /// two real hits. Un-ignore this the round that ceiling lifts; the symbol - /// itself is pinned by - /// [`a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag`], whose - /// `expect_err` must become a pixel compare in that same round. - #[ignore = "2026-09-02, re-measured on the merged tree: 35 of 41 attempts decode pixel-exact with ZERO mismatches, but both firing seeds (49, 213) stop at the sub16 split-transform / HORZ_A-B refusals, so no filter-intra 8x16/16x8 strip is compared yet"] + /// appended to this gate's seed window below, so it compares two real + /// hits. UN-IGNORED lane-rectsplitx r3: the ceiling lifted with the split + /// refusal, and the residual chroma defect was the split arm of + /// [`crate::decode::decode_leaf_rect`] passing `smooth_neighbor_uv: false` + /// where the unsplit arm passes the neighbour's real answer. The symbol + /// itself stays pinned by + /// [`a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag`]. #[test] fn a_real_aomenc_stream_with_filter_intra_on_a_sub16_horz_vert_strip_decodes_pixel_exact() { const NAME: &str = @@ -17709,8 +18508,18 @@ mod tests { let mut named_refusals = 0u32; let mut matched = 0u32; let (mut horz_proved, mut vert_proved, mut coeff_proved) = (0usize, 0usize, 0usize); + let (mut depth1_proved, mut depth2_proved) = (0usize, 0usize); let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); - for attempt in 0..n_attempts { + // lane-rectsplitx r1: the SECOND half of the attempt window turns + // `--enable-tx-size-search` ON at low cq, which is what makes a + // 32-level 1:4 strip SPLIT its transform -- depth 1 is the 2:1 + // rect unit TX_16X8/TX_8X16 (`sub_tx_size_map[TX_32X8]`), depth 2 + // the square TX_8X8, and the two interleave across attempts, so + // both are asserted (a depth-2-only run leaves the rect-unit path + // unproved). + for attempt in 0..n_attempts * 2 { + let tx_search = attempt >= n_attempts; + let attempt = attempt % n_attempts; let seed = 42 + attempt; let duration = frame_count as f64 / 25.0; // 8-pixel bands: a 32x8 strip is flat, a 32x16 one is not, so @@ -17729,7 +18538,13 @@ mod tests { geq=lum='mod(floor({axis}/8)*{step},256)',\ noise=alls={noise}:all_seed={seed},format=yuv420p" ); - let cq_level = format!("--cq-level={}", if attempt % 4 < 2 { 32 } else { 45 }); + let cq_level = if tx_search { + // 12..28: the window measured to fire both split depths on + // this fixture (lanes/tx64x16-r4.handoff.md). + format!("--cq-level={}", 12 + (attempt % 4) * 5) + } else { + format!("--cq-level={}", if attempt % 4 < 2 { 32 } else { 45 }) + }; let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; let y4m = Command::new("ffmpeg") .args([ @@ -17770,7 +18585,11 @@ mod tests { "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", - "--enable-tx-size-search=0", + if tx_search { + "--enable-tx-size-search=1" + } else { + "--enable-tx-size-search=0" + }, "--obu", "-o", "-", @@ -17801,6 +18620,7 @@ mod tests { crate::decode::rect4_32_vert_hits(), crate::decode::rect4_coeff_hits(), ); + let split_before = crate::decode::rect4_split_depth_hits(); let frames = match decode_stream(&stream) { Err(e) => { let msg = e.to_string(); @@ -17820,6 +18640,8 @@ mod tests { crate::decode::rect4_32_vert_hits() - before.1, crate::decode::rect4_coeff_hits() - before.2, ); + let split_now = crate::decode::rect4_split_depth_hits(); + let (d1, d2) = (split_now.0 - split_before.0, split_now.1 - split_before.1); let ffmpeg_frames = if bit_depth == 10 { ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) } else { @@ -17870,6 +18692,8 @@ mod tests { horz_proved += horz; vert_proved += vert; coeff_proved += coeff; + depth1_proved += d1; + depth2_proved += d2; matched += 1; } assert!( @@ -17893,6 +18717,25 @@ mod tests { strips={vert_proved}, coded strips={coeff_proved}, {out_of_scope} attempts \ carried no 32-level 1:4 block ({out_of_scope_mismatch} mismatched)" ); + // The split-transform halves of the window: both tx depths must + // have fired inside an attempt that then compared pixel-exact + // (class counter-from-refused-stream -- a global counter would + // count strips of attempts that later refused). + // lane-rectsplitx r2: BOTH depths are now decoded, so both are + // HARD-asserted -- depth 1 is the 2:1 rect unit + // (`sub_tx_size_map[TX_32X8] == TX_16X8`), depth 2 the square + // TX_8X8, and they interleave across the window; a run that only + // reached one of them proves half the walk. + assert!( + depth1_proved > 0 && depth2_proved > 0, + "{NAME}: {bit_depth}-bit: a 1:4 split-transform depth never fired inside a \ + pixel-exact attempt (depth1={depth1_proved}, depth2={depth2_proved}) -- the \ + tx-size-search half of the window proved nothing" + ); + eprintln!( + "{NAME}: {bit_depth}-bit split-transform 1:4 strips: depth1={depth1_proved}, \ + depth2={depth2_proved}" + ); assert_eq!( out_of_scope_mismatch, 0, "{NAME}: {bit_depth}-bit: {out_of_scope_mismatch} attempt(s) with zero 32-level \ @@ -18606,9 +19449,14 @@ mod tests { // 10-bit half has to carry the shape on its own. let mut rect4_strips_10bit = 0usize; let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); - // Attempts that stopped at the new named refusal for a 1:4 strip - // whose transform splits once (see the assert at the end). - let mut depth1_refusals = 0u32; + // 1:4 strips whose transform splits ONCE (the unit is still a 2:1 + // rect) that decoded and compared pixel-exact. Until the rectsplitx + // merge this shape was refused by name and the gate counted the + // REFUSALS; counting the decoded hits instead keeps the same + // territory claim now that the capability landed (class + // counter-from-refused-stream: only attempts that compared exact + // count). + let mut depth1_decoded = 0usize; for (bit_depth, cq) in [(8u32, 45u32), (8, 32), (8, 60), (10, 45), (10, 32), (10, 60)] { for attempt in 0..n_attempts { let seed = 42 + attempt; @@ -18618,6 +19466,7 @@ mod tests { let stream = rectchroma_stream(bit_depth, cq, attempt, width, height); let before = crate::decode::rect_split_chroma_shape_hits(); let split_before = crate::decode::rect_split_tx_hits(); + let depth1_before = crate::decode::rect4_split_depth_hits().0; let rect4_before = ( crate::decode::sb_rect4_horz_hits(), crate::decode::sb_rect4_vert_hits(), @@ -18631,9 +19480,6 @@ mod tests { {seed}): {msg}" ); refusals += 1; - if msg.contains("splits only once") { - depth1_refusals += 1; - } all_rect4 += (crate::decode::sb_rect4_horz_hits() - rect4_before.0) + (crate::decode::sb_rect4_vert_hits() - rect4_before.1); let r4 = (crate::decode::sb_rect4_horz_hits() - rect4_before.0) @@ -18703,6 +19549,7 @@ mod tests { proved[k] += after[k] - before[k]; } split_strips += crate::decode::rect_split_tx_hits() - split_before; + depth1_decoded += crate::decode::rect4_split_depth_hits().0 - depth1_before; let rect4 = (crate::decode::sb_rect4_horz_hits() - rect4_before.0) + (crate::decode::sb_rect4_vert_hits() - rect4_before.1); rect4_strips += rect4; @@ -18755,11 +19602,11 @@ mod tests { // tables this round wired are in place for it). This assert is what // keeps that from silently regressing to a wrong-pixel decode. assert!( - depth1_refusals > 0, - "{NAME}: no attempt reached a depth-1 1:4 split strip -- the recipe no longer \ + depth1_decoded > 0, + "{NAME}: no attempt decoded a depth-1 1:4 split strip -- the recipe no longer \ covers the shape this round fixed" ); - eprintln!("{NAME}: {depth1_refusals} attempts refused the depth-1 1:4 split strip by name"); + eprintln!("{NAME}: {depth1_decoded} depth-1 1:4 split strips decoded pixel-exact"); } /// The chroma-rect gate's fixture + aomenc recipe for one attempt, shared diff --git a/lanes/fiinter-r1.report.md b/lanes/fiinter-r1.report.md new file mode 100644 index 00000000..7d9e3119 --- /dev/null +++ b/lanes/fiinter-r1.report.md @@ -0,0 +1,95 @@ +# lane-fiinter r1 -- `use_filter_intra` on an intra block inside an inter frame + +Branch `lane-fiinter`, rebased onto main `eebf24e` (charter's base `lane-intrainter e841b2a` +replayed onto main; no conflicts). + +## Premise, re-measured + +`decode_inter_block`'s INTRA arm and `decode_inter_block8`'s 8x8 INTRA arm read +`y_mode` -> `angle_delta_y` -> `uv_mode` (+cfl/angle) -> palette and then went straight to +`read_block_tx_size` -- no `use_filter_intra` symbol at all, while libaom's +`read_intra_block_mode_info` (decodemv.c) ends with `read_filter_intra_mode_info` in exactly +that place, key frame or inter frame alike. Every inter gate recipe in `stream.rs` spelled +`--enable-filter-intra=0` (69 occurrences), so nothing had ever exercised it; aomenc's own +default is ON, so his films' inter frames desynced silently at the first such block. +Classes: [[symbol-consumption-gap]] + [[tool-disabled-in-every-gate]]. + +## What changed + +- `crates/ec-av1/src/decode.rs:64-80` -- `INTRA_IN_INTER_FILTER_INTRA_HITS` counter + + `intra_in_inter_filter_intra_hits()`, the gate's firing proof (the existing + `FILTER_INTRA_HITS` is also incremented, so the key-frame gates' deltas stay meaningful). +- `crates/ec-av1/src/decode.rs:830-856` -- `ENABLE_FILTER_INTRA_INTER` thread-local, set by + `set_inter_tx_mode(tx_select, reduced_tx_set, enable_filter_intra)`; same frame-constant + stash `TX_SELECT_INTER`/`REDUCED_TX_SET_INTER` already use rather than a 51st + `decode_inter_block` parameter. +- `crates/ec-av1/src/decode.rs:17497+` -- `decode_inter_frame_tile_with_cdfs` takes + `enable_filter_intra` (last param); `decode_inter_frame_tile` passes `false` (this crate's + encoder never writes the sequence bit), `stream.rs:694` passes the sequence header's bit. +- `crates/ec-av1/src/decode.rs:15578-15594` (>=16x16 square intra-in-inter arm) and + `:17188-17204` (8x8 leaf arm) -- `use_filter_intra` read via + `cdfs.filter_intra[filter_intra_size_class(side)]` right after the palette syntax, then + `filter_intra_mode`. `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied (a + real palette-Y block already returned by refusal); `filter_intra_size_class` returns `None` + at 64x64, so no symbol is read there, matching `av1_filter_intra_allowed_bsize`. +- Same arms: `filter_intra` now threaded into every LUMA prediction/coefficient call -- + the per-TU split path (`y.reconstruct` and `read_plane` inside the `vartx_leaves` loop, + i.e. lane-intrainter's split-tx path), the whole-block skip `reconstruct`, and the + whole-block `read_plane`. Chroma keeps `None`, exactly as the key-frame square arm does. + `read_plane`'s own `FIMODE_TO_INTRADIR` mapping (decode.rs:7445) supplies the tx_type CDF + row per TU, so lane-tiny's filter-intra tx_type row fix applies here unchanged. + +## Gate + +`stream.rs:4438-4700`: +`a_real_aomenc_inter_sequence_with_filter_intra_on_an_intra_block_decodes_pixel_exact` (8-bit) +and `..._10bit_...` (10-bit), driven by `filter_intra_in_inter_gate(bit_depth)` -- the +intrainter recipe (mandelbrot + hard overlay cut at frame 4, cq30, `--kf-min-dist=1000`, +`--enable-tx-size-search=1`, `--max/min-partition-size=32/16`) with `--enable-filter-intra=1`. +The flag is spelled ONCE (the base `=0` deleted) so no aomenc precedence question arises; +arrival is proved decoder-side by the counter, per COMMON. Every decoded frame's Y/U/V is +compared against ffmpeg; a decode error is only accepted when its message contains +"unsupported"; running out of attempts panics (no SKIP). + +``` +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-fiinter EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 \ + cargo test -p ec-av1 --lib filter_intra_on_an_intra_block -- --nocapture +``` + +EVIDENCE: $HOME/.cache/fiinter-suite.log | cargo test -p ec-av1 --lib filter_intra_on_an_intra_block | 8-bit seed 42: 11 filter-intra intra-in-inter blocks, 8 frames Y/U/V exact; 10-bit seed 47: 8 blocks, 8 frames exact; buckets counted-exact=1 uncounted-exact=0 + +EVIDENCE: negative control (`&& false` in front of both new reads, decode.rs restored after) | same gate command | 8-bit: 40/40 attempts, 0 firings, 33 named refusals + 7 decoded-uncounted -> PANIC. The gate is not vacuous: without the read the stream desyncs. + +EVIDENCE: mutation sweep (`sed 's/--enable-filter-intra=0/=1/g' stream.rs`, restored after) | `cargo test -p ec-av1 --lib inter_sequence` | 15 passed / 0 failed / 2 ignored (both pre-existing `#[ignore]`s: the 10-bit 8x8-leaf-split twin and the tile-column 8x8 gate) -- every inter gate that passed with filter intra OFF still passes with it ON, including `..._split_transform_intra_block_...` at both depths. + +## Refusals + +None lifted -- there was no refusal here, only an unread symbol (which is the worse shape: +`refusal_inventory.rs` is unchanged and stays green). `gate_coverage.rs` needs no edit: its +coverage is derived from the `--enable-*` spellings in the gate source, and the two new tests +spell `--enable-filter-intra=1` at 8 and 10 bit. + +## Residue + +- deferred(a directional-intra-in-inter gate): the `"a nonzero angle delta (this encoder never + writes one)"` refusal in both intra-in-inter arms stays. The symbol read itself is correct + (`cdfs.angle_delta[mode - V_PRED]`, compared to `ANGLE_DELTA_ZERO`), so lifting it is + mechanical -- but lifting a refusal without a gate that fires it is forbidden by COMMON, and + this lane's recipe pins `--enable-angle-delta=0`/`--enable-directional-intra=0` (a nonzero + delta would need its own source family). Unblocked by: an aomenc recipe that puts a + directional intra block with a nonzero delta inside an inter frame. +- accepted: the 8x8-leaf arm's read is size-generic and compiles/decodes, but no gate proves it + FIRED -- this gate pins `--min-partition-size=16`. The mutation sweep ran the 8x8-leaf-split + gates with filter intra ON and they stayed pixel-exact, which bounds the risk but does not + prove the symbol fired at 8x8. +- accepted: CfL/palette parity is unchanged from the key-frame arm -- a real palette-Y/UV block + still refuses by name before the filter-intra read, and `UV_CFL_PRED` chroma alphas are read + as before (filter intra is luma-only). + +## Suite + film + +`cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/fiinter-suite.log`): **346 passed / 0 failed / 32 ignored**, 739 s. + +EVIDENCE: $HOME/.cache/fiinter-suite.log | systemd-run --user --unit=fiinter-suite ... cargo test -p ec-av1 --lib -j3 | test result: ok. 346 passed; 0 failed; 32 ignored + +EVIDENCE: scratchpad/hg-head.obu | cargo run -p ec-av1 --example decode_probe -- hg-head.obu | 18 frame headers parsed, now stops at `unsupported: AV1 tile (filter intra on a HORZ/VERT strip (this decoder predicts square-only))` -- i.e. his film really does carry filter intra, and the next blocker is the rect-strip filter-intra predictor (another lane), not the unread inter symbol this lane fixed. diff --git a/lanes/intrainter-r1.handoff.md b/lanes/intrainter-r1.handoff.md new file mode 100644 index 00000000..5fdcc828 --- /dev/null +++ b/lanes/intrainter-r1.handoff.md @@ -0,0 +1,70 @@ +# lane-intrainter r1 handoff + +Branch `lane-intrainter`, based on main `c729a38` (worktree was already at main's head; no rebase needed). +Code commit: `955ecf9` (`feat(av1): intra blocks in inter frames may split their luma transform`). + +## Implemented (all in `crates/ec-av1/src/decode.rs`) + +- `read_block_tx_size` (~9470): intra branch no longer refuses a split `tx_depth`. It calls + `set_txfm_ctxs` with the RESOLVED transform (so later blocks' txfm ctx is right) and returns + the transform-unit leaf list `(row_mi, col_mi, tx_px)` in raster order — the same shape the + inter var-tx tree returns. +- `decode_inter_block` intra arm (~15490): the leaves ride the existing `vartx_leaves` slot; a + per-TU loop predicts + codes each unit with `txbset_for(tx_px, reduced)` (INTRA tx set), + `default_scan(tx_px)`, `Reach::of_tu` (block-relative availability), `luma_skip_ctx` + (neighbour-magnitude txb_skip ctx, not the lone-TU 0), `around_mi`, `record_mi_luma`. + Skip blocks predict PER UNIT too (an intra block reads tx_depth even when skip). + Chroma is unchanged (its transform is not split). The function tail already ran + `record_split_luma` + per-TU deblock edges whenever `vartx_leaves.is_some()`. +- Inter-frame intra syntax differences all pre-existed in that arm and are unchanged: + `y_mode_cdf[size_group]` (not kf_y_mode), `uv_mode_cfl[mode]`, angle deltas, CfL alphas, + palette-mode probes; angle_delta_y is refused nonzero, filter intra is not read in this arm. +- Counter `INTRA_IN_INTER_SPLIT_TX_HITS` + `intra_in_inter_split_tx_hits() -> [usize;4]` + bucketed by block side 8/16/32/64, one increment per split block. + +## Sizes / refusals + +- Squares 16x16..64x64 through `decode_inter_block` are lifted (the code is size-generic). + OBSERVED FIRING: 16x16 only (12 blocks 8-bit, 1 block 10-bit). 32/64 buckets stayed 0 under + `--min/max-partition-size=16/32`; unproven above 16x16. +- NEW refusal (`decode_inter_block8`, ~17070, listed in refusal_inventory.rs:63 replacing the + lifted string): "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 + transform units" — that leaf path has no per-TU intra prediction loop. +- RECT intra strips in inter frames stay refused earlier ("an intra-coded HORZ/VERT strip needs + rectangular intra prediction this decoder does not code yet"), so no rect work was needed. + +## Gate state — PASSING, both depths + +`a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact` and +`a_real_aomenc_10bit_...` (`intra_in_inter_split_tx_gate` in stream.rs). +Real aomenc, 64x64, 8 frames, mandelbrot zoom with a HARD CUT at frame 4 +(`overlay=enable='gte(n,4)'`), `--kf-min-dist=1000 --kf-max-dist=1000` (stops the scene-cut +detector inserting a second key frame), cq 30, overrides appended LAST. All frames Y/U/V vs +ffmpeg; decode errors only continue if they contain "unsupported"; exhausting 40 attempts panics. + +Run: +`EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intrainter cargo test -p ec-av1 --lib -- split_transform_intra_block --nocapture` + +Result: 8-bit seed 45 `16x16=12`, 10-bit seed 72 `16x16=1`, 0 differing samples, both `ok`. +No entropy ladder was needed — no divergence was ever observed. + +## Suite + +`$HOME/.cache/intrainter-suite.log` (unit `intrainter-suite-1788315424.service`), completed after +the turn cap: `test result: ok. 341 passed; 0 failed; 31 ignored; 0 measured` in 457.31s. Nothing +further is owed on the suite. + + +## Film + +Both `.../b6d8a07f.../scratchpad/reelc-head.obu` and `.../cdc46329.../scratchpad/reelc5.obu` stop at +"a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here" (lane-rectchroma +territory), NOT at this lane's refusal — the wall string in the charter was not reproducible on +these extracts (matches an existing ledger dead-end line). + +## Exact next step + +1. Merge (suite already green). +2. Optional follow-up round: prove 32x32/64x64 split intra-in-inter blocks (raise + `--max-partition-size` to 64 and lower cq, assert the 32/64 buckets), and lift the 8x8 leaf's + TX_4X4 2x2 grid in `decode_inter_block8`. diff --git a/lanes/intrainter-r1.report.md b/lanes/intrainter-r1.report.md new file mode 100644 index 00000000..bba71ad7 --- /dev/null +++ b/lanes/intrainter-r1.report.md @@ -0,0 +1,63 @@ +# lane-intrainter r1 — intra blocks in inter frames with a split luma transform + +Branch `lane-intrainter` off main `c729a38` (worktree already at main's head; no rebase needed). +Commit: `955ecf9`. + +## What changed + +- `crates/ec-av1/src/decode.rs` `read_block_tx_size` (~9470): the intra branch no longer + refuses a `tx_depth` that resolves below the block side. It runs `set_txfm_ctxs` with the + resolved transform (so later blocks' txfm ctx is right) and returns the transform-unit leaf + list in the same `(row_mi, col_mi, tx_px)` shape the inter var-tx tree uses, raster order. +- `crates/ec-av1/src/decode.rs` `decode_inter_block` intra arm (~15490): the returned leaves ride + the existing `vartx_leaves` slot, and a per-TU loop predicts + codes each unit + (`txbset_for(tx_px, reduced)`, `default_scan(tx_px)`, `Reach::of_tu`, `luma_skip_ctx`, + `around_mi`, `record_mi_luma`) exactly as `decode_block`'s key-frame multi-TU branch does — + including the skip case, which predicts per unit rather than whole-block. Chroma is unchanged + (its transform is not split). The function tail already did `record_split_luma` and per-TU + deblock edges whenever `vartx_leaves.is_some()`, so intra split blocks inherit both. +- `crates/ec-av1/src/decode.rs` counter `INTRA_IN_INTER_SPLIT_TX_HITS` + + `intra_in_inter_split_tx_hits() -> [usize; 4]` (bucketed 8/16/32/64), incremented once per + split intra-in-inter block. +- `crates/ec-av1/src/decode.rs` `decode_inter_block8` (~17070): an 8x8 intra leaf whose depth + resolves to TX_4X4 has no per-TU intra loop in that path — refused by name. +- `crates/ec-av1/src/refusal_inventory.rs:63`: lifted string replaced by the narrower + `"an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units"`. +- `crates/ec-av1/src/stream.rs`: new gate `intra_in_inter_split_tx_gate` + its 8/10-bit tests. + +## Gate + +`a_real_aomenc_inter_sequence_with_a_split_transform_intra_block_decodes_pixel_exact` +and `..._10bit_...`. Real aomenc, 64x64, 8 frames, mandelbrot zoom with a HARD CUT at frame 4 +(`overlay=enable='gte(n,4)'` of a second fractal) so aomenc codes intra blocks inside an inter +frame; `--kf-min-dist=1000 --kf-max-dist=1000` stops the scene-cut detector inserting a second +key frame. Overrides (`--enable-tx-size-search=1`, `--enable-rect-partitions=0`, +`--max-partition-size=32`, `--min-partition-size=16`) are appended AFTER the base recipe +(last occurrence wins). Every decoded frame's Y, U and V are compared with ffmpeg; a decode +error only continues the attempt loop if it contains "unsupported"; exhausting all 40 attempts +is a panic, never a SKIP. + +Run: +`EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intrainter cargo test -p ec-av1 --lib -- split_transform_intra_block --nocapture` + +EVIDENCE: $HOME/.cache/intrainter-suite.log | aomenc cut-fractal stream, ours vs ffmpeg, all 8 frames Y/U/V | 8-bit seed 45: 12 split intra-in-inter 16x16 blocks, 0 differing samples; 10-bit seed 72: 1 such block, 0 differing samples + +## Suite + +`EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intrainter cargo test -p ec-av1 --lib` +(as user unit `intrainter-suite-1788315424.service`, log `$HOME/.cache/intrainter-suite.log`): +`test result: ok. 341 passed; 0 failed; 31 ignored; 0 measured` in 457.31s — includes every sibling +(inter_sequence*, tx_select, 8x8_leaf_split, split_transform_*, filter_intra_*, cfl, +refusal_inventory, gate_coverage). + +## Film + +`reelc-head.obu` and `reelc5.obu` both stop at "a coded HORZ/VERT strip whose chroma transform has no +rect coefficient tables here" (lane-rectchroma), not at this lane's refusal. + +## Residue + +- deferred(a follow-up arm at --max-partition-size=64 and a lower cq): 32x32/64x64 split + intra-in-inter blocks never fired; the per-TU loop is size-generic but unproven above 16x16. +- deferred(a per-TU intra loop inside decode_inter_block8): the 8x8 leaf's TX_4X4 2x2 grid, + now the narrower named refusal. diff --git a/lanes/modectx-r1.report.md b/lanes/modectx-r1.report.md new file mode 100644 index 00000000..d354c942 --- /dev/null +++ b/lanes/modectx-r1.report.md @@ -0,0 +1,93 @@ +# lane-modectx r1 — the luma mode-context readers, and the charter's premise + +Base: `lane-rectsplitx` cbf8ffd (NOT rebased onto main — `git rebase main` conflicts in +`crates/ec-av1/src/decode.rs` + `refusal_inventory.rs` because lane-rectsplitx is not merged +yet; aborted, work stays on cbf8ffd as chartered. Deviation from COMMON's "rebase first"). + +## 1. The pinned defect does NOT reproduce on this base (charter premise stale) + +Stream pinned by the charter (192x128, 8-bit, seed 48, axis Y, step 103, noise 12, cq 32, +32x32_level_1to4 recipe), regenerated twice: + +``` +36cd6fae68d91d4b1fdbb77d7a7854b46a535f727a8b12094411ab0185d07673 a.obu +36cd6fae68d91d4b1fdbb77d7a7854b46a535f727a8b12094411ab0185d07673 b.obu +``` + +There is no `mode` divergence at mi(24,8). Our `EC_TRACE_MODE_STEP` ladder is IDENTICAL to the +instrumented aomdec's (`name=dq` excluded: our `val` field carries a different quantity there, +range identical) up to the last element we read, and we then stop on a REFUSAL, not a desync: + +* ours: 48 non-dq ladder lines, last `mi_row=6 mi_col=8 name=angle_uv val=0 rng=37000` + == aomdec line 48 exactly; then + `REFUSED: unsupported: AV1 tile (a HORZ_A/HORZ_B/VERT_A partition below 16x16 ...)`. +* aomdec `EC_TRACE=1` confirms the stream really does code that partition: + `EC_PART mi_row=8 mi_col=0 bsize=6 ctx=4 ... EC_PART_VAL value=4` (= `PARTITION_HORZ_A` at + 16x16) — aomenc emits an AB partition at 16x16 despite `--enable-ab-partitions=0`. + So the cq-32 arm of this fixture is blocked by a real, named capability gap (16x16 AB + partitions), not by a mode-context defect. + +At the gate's own cq for this attempt (attempt 6 uses `--cq-level=45`, seed 48 axis Y step 103 +noise 12 — i.e. the charter's stream IS already in the gate window) the frame decodes and the +whole ladder matches, before and after this lane's change. + +Conclusion: the mi(24,8) `kf_y_mode` divergence lane-band63 r1 pinned was fixed by +lane-rectsplitx ec0b3b5 ("a 1:4 strip read its neighbour MODE from a 16px-coarse band"), which +is in this lane's base. Item (4) of the charter (add seed 48 to the gate window) needs no new +pin: it is attempt 6 of the existing window and passes. + +EVIDENCE: /tmp/.../scratchpad/{a.obu,ours.log,ref.log,ours45.log,ref45.log} | regenerate the +pinned stream twice (identical sha256), decode with EC_TRACE_MODE_STEP under ours + instrumented +aomdec, diff ladders | cq32: 48/48 ladder lines identical then a named refusal (aomdec EC_PART +value=4 = HORZ_A at 16x16); cq45: 0 ladder differences, `OK: 1 frames decoded`. + +## 2. What did change: availability-correct coarse fallback (class new-map-ignores-tile-edge) + +`Neighbours::modes_above_left` (decode.rs:4005) — the entry point of every remaining coarse +reader (`decode_block_rect` :5182, `decode_block_rect64` :6169, `decode_block` :7442) — took the +mi-exact override first but then fell back to the raw `above_mode`/`left_mode` band with NO +tile-relative availability. It now routes through `modes_above_left_mi`, which returns `DC_PRED` +where libaom's `up_available`/`left_available` are false. Same for the two raw-band leaf sites, +`decode_leaf_split4` (:8348) and `decode_leaf_rect8` (:8547), which read +`neighbours.above_mode[c]`/`left_mode[r]` directly as their per-leaf fallback. + +Measured result of the fix: **zero behavioural change**, and that is now asserted. New counter +`MODE_TILE_EDGE_COARSE_LEAKS` counts every coarse fallback at a tile edge that held a non-DC +mode; over the 20 attempts of +`a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact` it is 0, because `above_mode` +is cleared per tile in `start_tile` and `left_mode` per superblock row in `start_row`. The gate +now asserts `== 0` — the invariant that makes the coarse fallback safe, and the thing that +would regress if either reset were dropped (that is exactly how lane-mtfix's chroma +`above_uv_mode` twin broke). + +Honest statement: this is hardening plus a regression guard, not a defect fix. No stream in the +suite changes. + +## 3. Band granularity sweep (charter item 3) + +| band | granularity | availability guard | can an 8/4-px strip alias it? | +|---|---|---|---| +| `above_mode`/`left_mode` | SUB (16px) | now tile-relative via `modes_above_left_mi` | yes, but only as a fallback — `sub8_mode_col/row` (mi) is primary and always written by `record_mode_mi` | +| `above_uv_mode`/`left_uv_mode` | SUB | tile-relative in `smooth_uv_neighbour` (mi primary, `uv_mode_col/row`) | same shape as luma; primary is mi-exact | +| `above_side`/`left_side` | SUB | — | WRITE-ONLY: no reader left (partition ctx uses `above_side_mi`/`left_side_mi`, mi-granular). Dead state, left alone this round | +| `above_side_mi`/`left_side_mi` | mi | reset in `start_tile`/`start_row` | no | +| `above_skip`/`skip_mode`/`inter`/`ref`/`ref1`/`comp_group_idx`/`compound_idx`/`filter`/`txfm` | mi | reset per tile/row | no | +| `skip_grid`/`tx_grid`/`tx_h_grid`/`uv_tx_grid`/`ref_grid`/`delta_lf_grid` | mi, 2-D | absolute mi coords | no | +| `above_palette_size/colors`, `left_palette_size/colors` (+ `_uv_`) | **SUB, square-only writer** | above: `r % 4 != 0`; left: tile-relative | **YES** — `record_palette_y` loops `0..side/SUB`, so a 32x8 / 8x32 palette strip writes NOTHING on its short axis and leaves an older block's palette cache in the cell; four 32x8 strips also share one left cell | + +The palette row is the one live instance of the charter's "last strip wins" class that remains. +It is NOT fixed here: every 1:4 / rect-strip gate runs `--enable-palette=0`, so there is no +stream in the repo that can prove or disprove it, and a blind fix would be an unverified change +to lane-palette2's territory. +Disposition: deferred(needs a real aomenc stream with `--enable-palette=1` that codes a 32x8 or +8x32 palette strip — same fixture family, palette enabled, screen-content source). + +## 4. Suite + +`cargo test -p ec-av1 --lib` (systemd unit, EC_AV1_REQUIRE_AOMENC=1): **335 passed; 0 failed; 29 ignored** (768.77s), log `$HOME/.cache/modectx-suite.log`. + +EVIDENCE: $HOME/.cache/modectx-suite.log | `systemd-run --user --unit=modectx-suite-1788316736 ... cargo test -p ec-av1 --lib -j3` on 4339963 | test result: ok. 335 passed; 0 failed; 29 ignored + +Gate re-run of the charter siblings is inside that suite run (32x32_level_1to4, superblock_level_1to4, +split_transform_*, coded_rect_strip_below_16x16, sub8_*, filter_intra_*, multi_tile/two+four tile +columns and tile rows, tiny sweep, refusal_inventory, gate_coverage — all ok). diff --git a/lanes/rect1d-r1.report.md b/lanes/rect1d-r1.report.md new file mode 100644 index 00000000..32619db4 --- /dev/null +++ b/lanes/rect1d-r1.report.md @@ -0,0 +1,77 @@ +# lane-rect1d r1 — the 1D-tx-class-on-a-rect-transform gate, and the defect it exposed + +Branch `lane-rect1d` off main `eebf24e`. One commit: `6faae24`. + +## What changed + +- `crates/ec-av1/src/decode.rs:5773` — `decode_leaf_rect`'s `tx_depth` symbol now reads + `cdfs.tx_size_cat1[ctx]`, was `cdfs.tx_size_cat2[ctx]`. **The defect.** +- `crates/ec-av1/src/decode.rs:978` — `RECT_COEFF_TU_HITS` + `RECT_CLASS1_HITS` counters + (`rect_coeff_tu_hits()` / `rect_class1_hits()`), bumped in `read_coeffs_rect` at + `:2943` and `:2960`. +- `crates/ec-av1/src/stream.rs:15570` — the gate + `a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform_decodes_pixel_exact`, + copied from lane-rectclass `ef7a476` minus its two refusal strings (they no longer + exist on main — lane-tx4x8 ported the 1D arms) and minus the now-vacuous + `class1_refusals == 0` assert; plus one new hard assert `compared_rect_class1 > 0`. +- `crates/ec-av1/src/gate_coverage.rs:229` — `enable-flip-idtx` leaves `NEVER_EXERCISED_10BIT` + (`enable-tx-size-search` was already off that list on this tree). +- `crates/ec-av1/examples/dump_yuv.rs` — new: raw `u16` plane dump. Both existing prefilt + dumps (ours and the instrumented aomdec) write `as u8`, which is blind to a 10-bit + mismatch by construction. + +## Root cause + +libaom `blockd.h:1344 bsize_to_tx_size_cat` = `bsize_to_tx_size_depth_table[bsize] - 1`. +BLOCK_16X8/8X16 (and the 1:4 BLOCK_16X4/4X16 `decode_leaf_rect` also decodes) are depth 2 → +category **1**, the same table a 16x16 square block reads. Category 2 belongs to the +32-level shapes. Both tables carry three symbols, so the wrong row decodes a *plausible* +depth from the wrong probabilities — the msac range diverges silently at the first such +leaf and every later symbol in the tile is read from the wrong place. Class: same shape as +`cdf-row-held-constant` / `wrong-alphabet-same-value`, here same alphabet, wrong row. +This only surfaces with `--enable-tx-size-search=1`; 11 of 15 gate recipes pin it to 0, +which is why the tree was green. + +Sweep of the whole class (every `tx_size_cat*` read, `grep -n tx_size_cat crates/ec-av1/src/decode.rs`): +`decode_block_rect` 32x16/16x32 → cat2 ✅, `decode_block_rect4` 32x8/8x32 → cat2 ✅, +`decode_block_rect64` 64x32/32x64/64x16/16x64 → cat3 ✅, sub-8 4x8/8x4 leaf → cat0 ✅, +square `read_tx_size` 8/16/32/64 → cat0/1/2/3 ✅. `decode_leaf_rect` was the only wrong site. + +## Evidence + +EVIDENCE: /home/user/.cache/rect1d/s42a.obu (sha256 5b3c8fc94b8e01f59755a4534eae7f5f9037440b5e4040357105b5a1d0dd395c, identical on two independent aomenc runs) | ffmpeg lavfi sinusoidal stripes 192x128 10-bit → aomenc `--reduced-tx-type-set=0 --enable-rect-partitions=1 --enable-tx-size-search=1 --enable-flip-idtx=1` → `dump_yuv` vs `ffmpeg -pix_fmt yuv420p10le` | luma differs at 846 samples before the fix (first at row 94 col 175, 509 vs 510; max |Δ| 551, all in the bottom-right of the frame), **0 differing samples after** + +EVIDENCE: /home/user/.cache/rect1d/ours.both + aom.both (EC_TRACE_COEFF + mode traces) | range ladder ours vs instrumented aomdec through the pinned stream | first 105 transform units' `all_zero`/`base`/`br`/`sign` ranges identical; TU 106 (block mi_row=24 mi_col=44, BLOCK_16X8) diverged: mode ladder agreed through `uv_mode` (rng 50640 both), then aomdec `EC_ISTEP name=tx_depth val=0 ctx=2 cat=1 rng=60682` against our cat-2 read (our next `all_zero` came out at rng 36870 vs its 60086) — **first divergent element = the `tx_depth` symbol's CDF row** + +EVIDENCE: gate output | `cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform -- --nocapture` | `12 pixel-exact decodes (0 named refusals out of 12 attempts, 6 of the matches 10-bit), rect coefficient TUs on compared attempts: 219 (10 of them a 1D tx class); flag arrival: rect partitions 120, tx depths 53, 1D-class (square) transforms 13` — before the fix the same gate panicked at seed 42 10-bit + +## Tests + +`cargo test -p ec-av1 --lib` (systemd unit, `$HOME/.cache/rect1d-suite.log`): see the +trailer line appended below by the run. + +## Residue + +- accepted: `decode_leaf_rect` still refuses a *split* transform at this level + ("a HORZ/VERT intra strip below 16x16 with a split transform"). The depth symbol is now + read from the right table, so a `depth != 0` leaf refuses by name instead of desyncing; + porting per-unit rect prediction is its own lane. +- deferred: the 4x16/16x4 shapes share category 1 and this fix covers them, but no gate + recipe in the tree is known to produce one — unblocks with a 1:4-at-16-level gate. + +## Handoff (turn cap) + +The lane is COMPLETE, not WIP: the defect is found, fixed, and gated. The only thing not +witnessed by me is the tail of the full-suite run — it was still executing (179 tests +printed, no `FAILED`, no `test result:` line yet) when my turn cap hit. Check with +`grep -E "^test result|FAILED" $HOME/.cache/rect1d-suite.log`; it is a plain +`cargo test -p ec-av1 --lib` under a systemd unit, nothing else to redo. + +Reproduce the original defect on main `eebf24e` (before `6faae24`): +``` +bash ~/.cache/rect1d/gen.sh /tmp/s42 # ffmpeg lavfi + aomenc, 10-bit, seed 42 +cargo run -p ec-av1 --example dump_yuv -- /tmp/s42.obu /tmp/ours +ffmpeg -v error -i /tmp/s42.obu -pix_fmt yuv420p10le -f rawvideo /tmp/ref.yuv +cmp /tmp/ours.f0.yuv /tmp/ref.yuv # 846 differing luma samples before, 0 after +``` +or just `cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_1d_tx_class_on_a_rect_transform`. diff --git a/lanes/rectsplitx-r1.report.md b/lanes/rectsplitx-r1.report.md new file mode 100644 index 00000000..bef7e630 --- /dev/null +++ b/lanes/rectsplitx-r1.report.md @@ -0,0 +1,105 @@ +# lane-rectsplitx r1 report + +Branch `lane-rectsplitx` off main `8262b99`. + +## What changed + +- `crates/ec-av1/src/decode.rs` + - `decode_rect_split` is now **mi-granular** (`at_mi`) and takes the transform + unit as `(tx_w, tx_h)` instead of one square `tx`: it can name a strip that + starts 8 px into a 16-px `SUB` cell, and it walks rectangular units. + Chroma map gained `(32,8)/(8,32)` (`Chroma16`), `(16,4)/(4,16)` (`Chroma8`) + and `(8,4)/(4,8)` (`ChromaRect8x4`). + - new `depth_to_tx_wh(bw, bh, depth)` -- libaom `depth_to_tx_size`: every + `sub_tx_size_map` entry halves the LONGER side of a rect and both sides of + a square, so a 1:4 strip's first split is still a 2:1 RECT unit + (`TX_32X8 -> TX_16X8`, `TX_64X16 -> TX_32X16`). Replaces the + `bw.min(bh) >> (depth - 1)` formula at BOTH 2:1 call sites; it is the same + root cause lane-rectchroma measured mis-tiling a depth-1 64x16 strip, fixed + once for every caller instead of per shape. + - new `tx_type_mode_row(mode, filter_intra)` -- the `fimode_to_intradir` row + rule main `1a89ed9` fixed inside `read_plane`, now also applied to + `decode_leaf_rect`'s rect luma coefficient read (same defect class, sibling + site found by sweeping every `cdfs.txb(, mode)` call: the other + luma rect sets are `tx_size_sqr_up >= TX_32X32`, i.e. DCT-only, no symbol). + - **`decode_leaf_rect` read the wrong tx_size CDF category**: BLOCK_16X8 / + BLOCK_8X16 are `bsize_to_tx_size_cat == 1` (libaom + `bsize_to_tx_size_depth_table`), not the 2 the 32x16 strips use. Same + symbol count, different CDF row -- a wrong-table read of a real symbol. + - `decode_leaf_rect`'s split refusal is **lifted**: a 16x8/8x16 strip with + `tx_depth != 0` decodes per transform unit (TX_8X8 at depth 1, TX_4X4 at + depth 2). + - `Neighbours`: `record_mi_luma_rect`, `luma_skip_ctx_rect`, + `record_split_luma_rect_mi` (coarse mode/side cells stamped with + `div_ceil`, so an 8-px-tall strip stamps the cell it touches). +- `crates/ec-av1/src/stream.rs` + - `a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag` is now a PIXEL + COMPARE (was `expect_err`) and additionally asserts `sub16_split_hits > 0`: + it is the gate for the sub-16 split lift. + - the 32x32-level 1:4 gate gained a `--enable-tx-size-search=1` half of its + attempt window (cq 12..28), which keeps the 1:4 split refusals honest. +- `crates/ec-av1/src/refusal_inventory.rs` updated (one refusal removed, two + added). + +## Refusals + +Lifted: "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit +rect prediction is not ported)". + +Added (both MEASURED, not speculative): +- "a split intra strip whose transform unit is the rect {tx_w}x{tx_h} ..." -- + the per-unit RECT walk (depth 1 of a 1:4 strip) is implemented but mismatched + ffmpeg on the band fixture (8-bit, cq 12, seed 42), so it refuses instead of + shipping wrong pixels. +- "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma + coefficient tables ...)" -- shape guard for the next caller. + +Kept: "a 32x32-level 1:4 strip with a split transform (... depth={depth})". +Reason: depth 1 fires FIRST in every splitting attempt of the fixture, so no +attempt ever reaches a pixel-compared depth-2 strip -- a depth-2-only lift is +ungatable, and an ungated lift is not a lift (the tx64x16 r4 handoff predicted +exactly this interleaving). + +## Gates + +- `a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag` -- **ok**. + EVIDENCE: crates/ec-av1/fixtures/filter_intra_8x16_strip_seed49.obu | cargo + test -p ec-av1 --lib -- a_pinned_aomenc_16x8_strip | whole frame Y+U+V equal + to ffmpeg, filter_intra_rect_sub16 hits 2 (was 1 under the truncated decode), + sub16_split_hits > 0. +- `a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact` + -- ok, now over 16 attempts per bit depth (8 with tx-size-search on). + 8-bit: 7 pixel-exact of 8 compared, 9 named refusals, horz_4=64, vert_4=72, + coded=136, 0 out-of-scope mismatches. + +## Open residue (fix-now for the next round, all MEASURED) + +1. `deferred(rect-unit defect)` -- the depth-1 RECT transform unit (TX_16X8 / + TX_32X16) mismatches ffmpeg; code is wired and refused by one `if tx_w != + tx_h` in `decode_rect_split`. Deleting that one line + the 1:4 caller's twin + is the whole re-lift. Reproduce: the 1:4 gate with the tx-search half and + the refusal removed, 8-bit cq 12 seed 42. +2. `deferred(chroma defect behind the lifted refusal)` -- + `a_real_aomenc_stream_with_filter_intra_on_a_sub16_horz_vert_strip_decodes_pixel_exact` + now decodes seed 55 instead of refusing and mismatches on the **U plane** + only; `#[ignore]`d with that measurement. +3. `deferred(same)` -- `a_directional_16x8_strip_reads_the_right_above_right_samples` + decodes now and mismatches LUMA at seed 700 cq 45 with 0 reaching strips; + `#[ignore]`d with that measurement. Class refusal-hides-a-defect: both are + defects the split refusal was covering, not regressions of this round. + +## Films + +`decode_probe` (release), before -> after: +- reelb5.obu: "a 32x32-level 1:4 strip with a split transform (depth=2)" -> + **"a HORZ_A/HORZ_B/VERT_A partition below 16x16"** (another lane's refusal). + The 1:4 depth refusal is still in place, so what moved this film is the + sub-16 split lift plus the `tx_size_cat1` fix -- the extract's 1:4 strips are + reached and decoded (rect4_32: horz=4 coded=4) and the stream now runs on to + a partition shape nobody has ported. + EVIDENCE: reelb5.obu | cargo run --release --example decode_probe -- reelb5.obu | + refusal string changed, rect4_32 horz=4 vert=0 coded=4 +- hg-head.obu: "filter intra on a HORZ/VERT strip (this decoder predicts + square-only)" (unchanged, another lane). +- reelc-head.obu: "an intra block in an inter frame whose tx_depth splits its + luma transform (round 1)" (unchanged, another lane). diff --git a/lanes/rectsplitx-r2.report.md b/lanes/rectsplitx-r2.report.md new file mode 100644 index 00000000..f40449c1 --- /dev/null +++ b/lanes/rectsplitx-r2.report.md @@ -0,0 +1,102 @@ +# lane-rectsplitx r2 report + +Branch `lane-rectsplitx`, rebased onto main `ce05d5f` (clean), commit `ec0b3b5`. + +## Root cause (the r1 premise was wrong) + +r1 refused the depth-1 RECT transform unit (`TX_16X8`/`TX_32X16`) as "measured +wrong pixels". It is not the transform unit. Range ladder, band fixture 8-bit +cq 12 seed 42 (`EC_TRACE_MODE_STEP=1` ours vs instrumented aomdec): + +``` +ours: EC_ISTEP mi_row=4 mi_col=8 name=mode val=11 rng=52576 +ref : EC_ISTEP mi_row=4 mi_col=8 name=mode val=12 rng=34624 + (entry rng identical, 38331, on the preceding dq line) +``` + +Same entry range, different value => a different `kf_y_mode` CDF row => the +neighbour MODE, not the transform. Three defects, all in the neighbour bands: + +1. `decode.rs` `decode_block_rect4` unsplit arm never wrote the mi-exact + mode/uv maps (`record_mode_mi`/`record_uv_mode_mi`); only the split arm did + (via `record_mi_luma_rect`). So `mode_left_mi` returned `None` and the + coarse 16x16 cell answered -- holding the LAST of the four 32x8 strips. +2. New `Neighbours::modes_above_left_mi` (decode.rs, above `modes_above_left`): + mi-exact AND availability-correct. Four 32x8 strips at tile column 0 share + one `left_mode` cell, so strip 2 read strip 1's mode as its "left" where + libaom has no left neighbour at all (measured at mi(10,0): ours left=2, + libaom DC). Class swept into `decode_leaf_rect` and `decode_leaf8`. +3. `decode_block_rect4` asked `smooth_uv_neighbour(r*(SUB/MI), c*(SUB/MI), ..)` + -- the SUB cell's top-left mi, not the strip's real mi (a 1:4 strip starts + 8 px into a 16-px cell). Chroma-only defect: seed 43 VERT_4 had luma + bit-exact with U/V wrong. + +## Evidence + +EVIDENCE: scratchpad/s42.obu (sha256 7d578ff5deb0c6ec1ac7142ac0b73dcbdf702417da7868448bada17b4cb07e18) | aomenc band fixture 192x128 8-bit cq12 seed42 --enable-tx-size-search=1, EC_AV1_PREFILT_DUMP ours vs aomdec | 22986 luma + 5293 U diffs -> 0 (byte-identical 36864-byte dumps), rect4_32 horz=92 coded=92 +EVIDENCE: scratchpad/s43_17.obu | same recipe, axis X (VERT_4), seed43 cq17 | luma 0 diffs / U 39 / V 150 -> byte-identical after the `smooth_uv_neighbour` mi fix, rect4_32 vert=88 coded=88 + +## Gate + +`a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact` +now HARD-asserts `depth1_proved > 0 && depth2_proved > 0` (was +`depth1+depth2 == 0`, the refusal-honest form), and both `tx_w != tx_h` +refusals are deleted from `decode.rs` + `refusal_inventory.rs`. + +**This gate is RED as committed.** 8-bit seed 46 (cq 12, tx-size-search on) +mismatches CHROMA ONLY: luma bit-exact, U 32 samples and V 173 samples off by ++-1..2, bounding box U x16..23 y8..15 / V x16..35 y8..24, first wrong sample +chroma (16,8) = the 16x4 chroma of the 32x8 strip at luma (32,16). The same +seed at cq 32 (tx-size-search OFF) is byte-exact, so it is specific to a +strip whose luma transform is SPLIT. Reproducer: + +``` +ffmpeg -v error -f lavfi -i "color=c=gray:s=192x128:d=0.04:r=25,format=gray,\ +geq=lum='mod(floor(Y/8)*91,256)',noise=alls=6:all_seed=46,format=yuv420p" \ + -t 0.04 -pix_fmt yuv420p -strict -1 -f yuv4mpegpipe - > src46.y4m +aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=12 --cpu-used=0 \ + --threads=1 --row-mt=0 --sb-size=64 --bit-depth=8 --input-bit-depth=8 \ + --enable-rect-partitions=1 --enable-ab-partitions=0 --enable-1to4-partitions=1 \ + --min-partition-size=8 --max-partition-size=32 --enable-restoration=0 \ + --enable-palette=0 --deltaq-mode=0 --enable-filter-intra=0 --enable-cfl-intra=0 \ + --enable-intrabc=0 --enable-tx-size-search=1 --obu -o s46.obu src46.y4m +EC_AV1_PREFILT_DUMP=o cargo run -p ec-av1 --example decode_probe -- s46.obu +EC_AV1_PREFILT_DUMP=r aomdec --rawvideo -o /dev/null s46.obu # o.f0 vs r.f0 +``` + +Entropy is exact through the whole frame (all luma bit-exact), so the residue +is chroma RECONSTRUCTION inside `decode_rect_split`'s chroma arm +(decode.rs ~5060-5130) -- prediction inputs or the 16x4 inverse, not a symbol. + +FALLBACK TO GREEN (one edit, if the batch needs a merge before that is found): +re-insert `if tx_w != tx_h { return Err(unsupported(..)) }` in +`decode_rect_split` (before `let luma_set =`) and in `decode_block_rect4` +(before `let which = if depth == 1`), re-add the two strings to +`refusal_inventory::REFUSALS`, and flip the gate's depth assert back to +`assert_eq!(depth1_proved + depth2_proved, 0, ..)`. The three neighbour-map +fixes stay and remain gated by the unsplit half of the same gate. + +## r1's two ignored gates -- re-measured, both still ignored + +- `a_real_aomenc_10bit_filter_intra_on_a_sub16_strip_decodes_pixel_exact` + (and its 8-bit twin): still CHROMA-only. 10-bit seed 49 frame 0 plane V, + first diff row 4 col 60, ours 510 vs ffmpeg 509, + `filter_intra_rect_sub16_hits=2`. Ignore text updated with that measurement. + deferred: sub-16 filter-intra chroma prediction -- unblocked by the same + chroma-reconstruction hunt as the seed-46 residue. +- `a_directional_16x8_strip_reads_the_right_above_right_samples`: NOT this + lane's defect any more -- every seed 700..739 attempt now stops at another + lane's refusal "a HORZ_A/HORZ_B/VERT_A partition below 16x16", so the gate + reaches no strip at all. deferred: blocked on AB partitions below 16x16. + +## Films + +Not re-measured this round (turn cap). r1 measured reelb5.obu moving to +"a HORZ_A/HORZ_B/VERT_A partition below 16x16"; the ledger records that no +`reelc-head.obu` exists on the box. + +## Suite + +`systemd-run --user --unit=rectsplitx-suite-1788313999` -> +`$HOME/.cache/rectsplitx-suite-r2.log`. Expected: 1 failure, the 1:4 gate +above (the only gate whose assertion this round strengthened). diff --git a/lanes/rectsplitx-r3.report.md b/lanes/rectsplitx-r3.report.md new file mode 100644 index 00000000..7a5b7b9f --- /dev/null +++ b/lanes/rectsplitx-r3.report.md @@ -0,0 +1,78 @@ +# lane-rectsplitx r3 report + +Branch `lane-rectsplitx`, commit `58149c8` on top of r2 `eec6a40` (base main +`ce05d5f`; main has since moved to `11633d7` -- **not rebased this round**, see +"Open"). + +## Root cause (one line of code) + +`crates/ec-av1/src/decode.rs:5665` -- `decode_leaf_rect`'s SPLIT arm built +`RectStripModes { .., smooth_neighbor_uv: false }`, hard-coded, while the +unsplit arm two dozen lines below passes the real +`neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c)` computed at +`decode.rs:5637`. So every tx-split 16x8/8x16 leaf predicted its chroma with +the intra-edge FILTER TYPE off: luma bit-exact, chroma off by +-1..2 across +the block, with the error leaking into the blocks below/right. + +Class: a split/unsplit pair where the split arm drops a field the unsplit arm +passes (sibling of `cdf-row-held-constant` -- a value pinned to a constant +where the reference varies it). Sweep: all four `RectStripModes` literals +(`decode.rs:5248`, `5656`, `5905`, `6250`) now pass the computed value; that +was the only constant one. + +The charter's suspects (chroma TU geometry, CfL, TX_16X4 dequant/inverse) were +all wrong: the failing block is not a 32x8 1:4 strip. `EC_AV1_TRACE` puts a +`TRACE_RECT_SPLIT mi_row=4 mi_col=8 bw=16 bh=8 tx=8x8` (and its twin at +mi_row=6) exactly over the wrong region -- a 16x16 block split PARTITION_HORZ +into two 16x8 strips, each with `tx_depth=1`, chroma 8x4. + +## Evidence + +EVIDENCE: scratchpad/r3/s46.obu (sha256 31de47355a098b460975ca0156e0b10cebaacc3c1614d2a8791ece3440c8ba45, generated TWICE identical) | aomenc 192x128 8-bit cq12 seed46 `--enable-tx-size-search=1 --enable-1to4-partitions=1`, `EC_AV1_PREFILT_DUMP` ours vs instrumented aomdec | before: Y 0 diffs, U 32 diffs (all inside chroma cell x16..23 y8..15), V 173; after: `cmp o.f0 r.f0` BYTE-IDENTICAL (36864 bytes) +EVIDENCE: scratchpad/r3/trace.txt | `EC_AV1_TRACE=1 decode_probe s46.obu`, grep mi_row=4..7 mi_col=8..11 | `TRACE_RECT_SPLIT mi_row=4 mi_col=8 bw=16 bh=8 tx=8x8` == luma (32,16), the exact 8x8 chroma cell that was wrong + +## Gates + +`cargo test -p ec-av1 --lib -- <3 names>` (EC_AV1_REQUIRE_AOMENC=1): +`test result: ok. 3 passed; 0 failed` in 21.4s -- + +- `a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact` + (RED as committed in r2, the round's target) -- GREEN, still hard-asserting + `depth1_proved > 0 && depth2_proved > 0`. +- `a_real_aomenc_stream_with_filter_intra_on_a_sub16_horz_vert_strip_decodes_pixel_exact` + -- **un-ignored**, GREEN (ignored since lane-fistrip r1). +- `a_real_aomenc_10bit_filter_intra_on_a_sub16_strip_decodes_pixel_exact` + -- **un-ignored**, GREEN (his films are 10-bit; this is the 10-bit arm). + +Both `#[ignore]` attributes and the stale prose in their doc comments are gone +in the same commit. No refusal string changed this round (r2 already deleted +the two `tx_w != tx_h` ones); `refusal_inventory` and `gate_coverage` stay +green in the suite below. + +## Suite + +`systemd-run --user --unit=rectsplitx-suite-r3-1788314510 -p MemoryMax=10G` -> +`$HOME/.cache/rectsplitx-suite-r3.log`: `test result: ok. 335 passed; 0 failed; 29 ignored; 0 measured; 0 filtered out; finished in 398.99s` (r2 was 1 failed / 31 ignored). + +## Films (this worktree, not rebased -- other lanes' refusals dominate) + +- `hg-head.obu`: `filter intra on a HORZ/VERT strip (this decoder predicts square-only)` (unchanged) +- `reelc-head.obu`: `an intra block in an inter frame whose tx_depth splits its luma transform (round 1)` (unchanged) +- `reelb5.obu`: `a HORZ_A/HORZ_B/VERT_A partition below 16x16` (unchanged; lifted on main by lane-ab16) + +## Open + +- deferred: rebase onto main `11633d7` -- this lane is 3 merges behind + (`ce05d5f..11633d7`, palette2/ab16/tiles all touch `decode.rs` hot spots incl. + `Reach::of_tu` arity and a duplicate `FIMODE_TO_INTRADIR` helper per the + ledger). Unblocked by: whoever merges this lane resolving those conflicts; + the fix itself is one field in a struct literal and applies unchanged. +- deferred: `reelc-head.obu`'s refusal, "an intra block in an inter frame whose + tx_depth splits its luma transform (round 1)", is this lane's family (the + same split walk, in an inter frame). Unblocked by: an inter-frame gate with + tx-size-search on. +- accepted: the coarse-cell `smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), ..)` + call form still stands at `decode.rs:5206`, `6197`, `7487`, `15310`. Those + callers are 16px-aligned strips (32x16/64x32) where the SUB cell's mi IS the + strip's mi, so they are correct today -- but a future sub-cell caller would + repeat r2's defect.