diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 781d7659..c0c366bb 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -28,6 +28,10 @@ fn main() { std::process::exit(2); } }; + let report = || { + let (h, v, c) = ec_av1::stream::rect4_32_counters(); + println!("rect4_32: horz={h} vert={v} coded={c}"); + }; match ec_av1::stream::decode_stream(&data) { Ok(frames) if frames.is_empty() => { println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?"); @@ -52,4 +56,5 @@ fn main() { } Err(e) => println!("REFUSED: {e}"), } + report(); } diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 97407756..97d113a9 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -108,6 +108,16 @@ pub(crate) enum TxbSet { /// `Luma32`'s 1024-position one. Never carries a `tx_type` symbol: both /// orientations use one variant (`get_tx_set` is `EXT_TX_SET_DCTONLY` at /// `tx_size_sqr_up == TX_32X32` regardless of which axis is longer). + /// The 32x8/8x32 luma transform of a 32x32-level `PARTITION_HORZ_4`/ + /// `PARTITION_VERT_4` strip (lane-tx64x16 r3). `get_txsize_entropy_ctx` + /// averages the two log2 sides ((5 + 3) / 2 = 4), so the coefficient CDF + /// set is the 16x16 one [`Luma16`](TxbSet::Luma16) reads -- 256 coded + /// positions, `eob_pt_256`. Unlike `Luma16` it carries NO `tx_type` + /// symbol: `tx_size_sqr_up` of a 4:1 32-wide strip is `TX_32X32`, where + /// `av1_get_ext_tx_set_type` returns `EXT_TX_SET_DCTONLY` for an intra + /// block, so the encoder writes none (same reason + /// [`LumaRect32x16`](TxbSet::LumaRect32x16) has none). + LumaRect32x8, LumaRect32x16, /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads @@ -1606,6 +1616,18 @@ impl Cdfs { tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_1024_chroma_class1), }, + TxbSet::LumaRect32x8 => TxbTables { + side: 16, + txb_skip: &mut self.txb_skip_luma_16, + eob_pt: &mut self.eob_pt_256_luma, + eob_extra: &mut self.eob_extra_luma_16, + base: &mut self.base_luma_16, + base_eob: &mut self.base_eob_luma_16, + br: &mut self.br_luma_16, + dc_sign: &mut self.dc_sign_luma, + tx_type: None, + eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), + }, TxbSet::LumaRect32x16 => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_32, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d23f9d7a..14ea6e99 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1468,6 +1468,36 @@ pub(crate) fn sb_rect4_vert_hits() -> usize { SB_RECT4_VERT_HITS.with(|c| c.get()) } +// lane-tx64x16 r3: the 32x32-level 1:4 arms, counted per orientation -- +// `PARTITION_HORZ_4` (four 32x8 strips) and `PARTITION_VERT_4` (four 8x32 +// strips), the arms the ReelB mid-film extract stops at. +thread_local! { + static RECT4_32_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static RECT4_32_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// How many 32x32-level 1:4 strips actually read coefficients (non-skip): +/// a gate that only counted strips would pass on an all-skip stream, which +/// exercises none of the new scan/context tables. +thread_local! { + static RECT4_COEFF_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of `RECT4_COEFF_HITS`. +pub(crate) fn rect4_coeff_hits() -> usize { + RECT4_COEFF_HITS.with(|c| c.get()) +} + +/// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded). +pub(crate) fn rect4_32_horz_hits() -> usize { + RECT4_32_HORZ_HITS.with(|c| c.get()) +} + +/// Current value of `RECT4_32_VERT_HITS` (8x32 strips decoded). +pub(crate) fn rect4_32_vert_hits() -> usize { + RECT4_32_VERT_HITS.with(|c| c.get()) +} + // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not @@ -2076,6 +2106,27 @@ const SCAN_4X8: [u16; 32] = [ 23, 26, 29, 27, 30, 31, ]; +/// `Default_Scan_16x4`, this decoder's own row-major transcription of +/// libaom's column-major `default_scan_16x4` (`scan.c:66`) -- the CHROMA +/// plane of a 32x8 `PARTITION_HORZ_4` strip at the 32x32 level +/// (lane-tx64x16 r3). The transcription rule (`row * w + col` with +/// `row = p % h`, `col = p / h`) was validated by REGENERATING the existing +/// [`SCAN_16X8`] from `default_scan_16x8` byte for byte before these two +/// were emitted -- a naive copy installs the transpose (class +/// reference-layout-not-spec). +const SCAN_16X4: [u16; 64] = [ + 0, 16, 1, 32, 17, 2, 48, 33, 18, 3, 49, 34, 19, 4, 50, 35, 20, 5, 51, 36, 21, 6, 52, 37, 22, 7, + 53, 38, 23, 8, 54, 39, 24, 9, 55, 40, 25, 10, 56, 41, 26, 11, 57, 42, 27, 12, 58, 43, 28, 13, + 59, 44, 29, 14, 60, 45, 30, 15, 61, 46, 31, 62, 47, 63, +]; +/// `Default_Scan_4x16`, [`SCAN_16X4`]'s transpose (the chroma plane of an +/// 8x32 `PARTITION_VERT_4` strip). +const SCAN_4X16: [u16; 64] = [ + 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, 7, 10, 13, 16, 11, 14, 17, 20, 15, 18, 21, 24, 19, 22, 25, 28, + 23, 26, 29, 32, 27, 30, 33, 36, 31, 34, 37, 40, 35, 38, 41, 44, 39, 42, 45, 48, 43, 46, 49, 52, + 47, 50, 53, 56, 51, 54, 57, 60, 55, 58, 61, 59, 62, 63, +]; + /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s /// asymmetric-extent pattern). @@ -2531,6 +2582,8 @@ fn read_coeffs_rect( for scan_idx in (0..eob).rev() { let pos = scan[scan_idx] as usize; let (row, col) = (pos / w, pos % w); + // libaom's column-major `coeff_idx`, for ladder comparison. + let apos = col * h + row; let level = if scan_idx == eob - 1 { let ctx = eob_coeff_ctx(scan_idx, w * h); let l = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1; @@ -5144,6 +5197,286 @@ fn decode_leaf_rect( Ok(mode) } +/// Decodes one 32x8 / 8x32 strip of a 32x32-level `PARTITION_HORZ_4` / +/// `PARTITION_VERT_4` (lane-tx64x16 r3): [`decode_block_rect`]'s 4:1 sibling, +/// addressed by REAL mi coordinates for the same reason [`decode_leaf_rect`] +/// is -- strips 1 and 3 start 8 px into a 16-px [`SUB`] cell, which an +/// `at`-derived `px = c * SUB` cannot name. `prev_strip` carries the previous +/// strip's mode so this one's mode context sees its true above/left +/// neighbour inside the same 32x32 (`decode_leaf_rect`'s convention). +/// +/// Tables: LUMA `TX_32X8`/`TX_8X32` averages to the 16x16 entropy context +/// ([`TxbSet::LumaRect32x8`], 256 positions) and scans with +/// [`SCAN_32X8`]/[`SCAN_8X32`]; CHROMA `TX_16X4`/`TX_4X16` averages to the +/// 8x8 one ([`TxbSet::Chroma8`], 64 positions) and scans with +/// [`SCAN_16X4`]/[`SCAN_4X16`]. Neither shape takes the rect sqrt2 scale -- +/// `get_rect_tx_log_ratio` fires at ratio 1 only, and this is ratio 2 +/// (`inverse_transform_2d_typed_wh`'s own `rect_scale`). +/// +/// A split transform (`tx_depth != 0`) refuses by name: `depth_to_tx_size` of +/// a 4:1 strip is not simply `bw.min(bh) >> (depth - 1)` the way a 2:1 +/// strip's is, so [`decode_rect_split`]'s per-unit walk cannot be reused +/// unexamined. +#[allow(clippy::too_many_arguments)] +fn decode_block_rect4( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + strip_mi: (usize, usize), + bw: usize, + bh: usize, + prev_strip: Option<((usize, usize), usize)>, + y: &mut PlaneBuf, + u: &mut PlaneBuf, + v: &mut PlaneBuf, + enable_filter_intra: bool, + allow_screen_content_tools: bool, + base_q_idx: u8, + tx_select: bool, +) -> Result<(usize, usize)> { + let _ = base_q_idx; + let (mi_r, mi_c) = strip_mi; + let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); + let (mi_w, mi_h) = (bw / MI, bh / MI); + let mut above_mode = neighbours.above_mode[c]; + let mut left_mode = neighbours.left_mode[r]; + if let Some(((pr, pc), pmode)) = prev_strip { + if pc == mi_c && mi_r == pr + mi_h { + above_mode = pmode; + } else if pr == mi_r && mi_c == pc + mi_w { + left_mode = pmode; + } + } + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = + read_intra_mode_rect( + dec, + cdfs, + above_mode, + left_mode, + true, + bw, + bh, + enable_filter_intra, + neighbours.skip_txfm_ctx(mi_r, mi_c), + allow_screen_content_tools, + mi_r, + mi_c, + )?; + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); + if smooth_neighbor { + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); + } + let smooth_neighbor_uv = + is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); + if filter_intra.is_some() { + FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); + } + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; + let depth = if tx_select { + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + dec.symbol(&mut cdfs.tx_size_cat2[ctx]) + } else { + 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})" + ))); + } + // 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 + // LAST strip wins -- which is the right answer for the block below/right + // of the 32x32, the only reader outside it. Written after this strip's + // own context read above, never before. + for cell in 0..bw.div_ceil(SUB) { + neighbours.above_mode[c + cell] = mode; + neighbours.above_uv_mode[c + cell] = uv_predict_mode; + neighbours.above_side[c + cell] = bw; + } + for cell in 0..bh.div_ceil(SUB) { + neighbours.left_mode[r + cell] = mode; + neighbours.left_uv_mode[r + cell] = uv_predict_mode; + neighbours.left_side[r + cell] = bh; + } + 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); + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); + let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh { + (&SCAN_32X8, &SCAN_16X4) + } else { + (&SCAN_8X32, &SCAN_4X16) + }; + let (luma_levels, u_levels, v_levels) = if skip { + ( + vec![0i32; bw * bh], + vec![0i32; chroma_w * chroma_h], + vec![0i32; chroma_w * chroma_h], + ) + } else { + let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x8, mode); + let (luma_levels, luma_tx_type) = read_coeffs_rect( + dec, + &mut luma_coding, + luma_scan, + bw, + bh, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, + )?; + let mut planes = Vec::with_capacity(2); + for plane in 1..3 { + let default_tx = default_intra_tx_type(uv_predict_mode as u8); + let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1); + let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode); + let (levels, tx_type) = read_coeffs_rect( + dec, + &mut coding, + chroma_scan, + chroma_w, + chroma_h, + skip_ctx, + dc_sign_ctx(around[plane].2), + default_tx, + )?; + planes.push((levels, tx_type)); + } + let (v_levels, v_tx_type) = planes.pop().expect("plane 2"); + let (u_levels, u_tx_type) = planes.pop().expect("plane 1"); + RECT4_COEFF_HITS.with(|c| c.set(c.get() + 1)); + let luma_residual = dequant_and_inverse_typed_wh( + &luma_levels, + bw, + bh, + crate::decode::bit_depth(), + block_q_idx(), + plane_q_delta(0).0, + plane_q_delta(0).1, + luma_tx_type, + ); + y.reconstruct_rect( + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_residual, + None, + filter_intra, + smooth_neighbor, + ); + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); + for (plane, buf, levels, tx_type) in [ + (1usize, &mut *u, &u_levels, u_tx_type), + (2, &mut *v, &v_levels, v_tx_type), + ] { + let residual = dequant_and_inverse_typed_wh( + levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(), + block_q_idx(), + plane_q_delta(plane).0, + plane_q_delta(plane).1, + tx_type, + ); + buf.reconstruct_rect( + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &residual, + alpha + .zip(ac.as_deref()) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + None, + smooth_neighbor_uv, + ); + } + neighbours.record_mi_rect( + (mi_r, mi_c), + bw, + bh, + &[luma_levels, u_levels, v_levels], + ); + neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); + neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); + 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)); + } + return Ok((mode, uv_predict_mode)); + }; + y.reconstruct_rect( + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_levels, + None, + filter_intra, + smooth_neighbor, + ); + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); + u.reconstruct_rect( + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &u_levels, + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + ); + v.reconstruct_rect( + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &v_levels, + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + ); + neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels, u_levels, v_levels]); + neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); + neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); + 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)); + } + Ok((mode, uv_predict_mode)) +} + /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike @@ -10136,6 +10469,47 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( reduced_tx_set, )?; } + PARTITION_HORZ_4 | PARTITION_VERT_4 => { + // lane-tx64x16 r3: the 1:4 pair at the 32x32 + // level -- four 32x8 (or 8x32) strips in + // raster order, `quarter_step` = 2 mi, with + // libaom `decode_partition`'s own `i > 0` + // frame-edge break. + let horz = part32 == PARTITION_HORZ_4; + let base_mi = (at32.0 * (SUB / MI), at32.1 * (SUB / MI)); + let mut prev: Option<((usize, usize), usize)> = None; + for i in 0..4 { + let strip_mi = if horz { + (base_mi.0 + i * 2, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * 2) + }; + if i > 0 + && (strip_mi.0 >= mi_rows as usize + || strip_mi.1 >= mi_cols as usize) + { + break; + } + let (bw, bh) = if horz { (32, 8) } else { (8, 32) }; + let (mode, _uv) = decode_block_rect4( + &mut dec, + &mut cdfs, + &mut neighbours, + strip_mi, + bw, + bh, + prev, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + prev = Some((strip_mi, mode)); + } + } _ => { return Err(unsupported(format!( "a 32x32 partition type this decoder does not code (value={part32})" @@ -17424,6 +17798,37 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( mod tests { use super::*; + /// lane-tx64x16 r3: the two new 4:1 chroma scans are a TRANSPOSED PAIR -- + /// `SCAN_4X16[i]` must name the transpose of the position + /// `SCAN_16X4[i]` names (class scan-weights-cross-axis: a naive copy of + /// libaom's column-major `default_scan_*` installs the transpose and only + /// an asymmetric check catches it). Also pins both as permutations, and + /// pins the same relation for the 32x8/8x32 luma pair this arm reuses. + #[test] + fn the_rect4_scans_are_transposed_pairs() { + for (a, b, w, h) in [ + (&SCAN_16X4[..], &SCAN_4X16[..], 16usize, 4usize), + (&SCAN_32X8[..], &SCAN_8X32[..], 32, 8), + ] { + let mut seen_a: Vec = a.to_vec(); + seen_a.sort_unstable(); + assert_eq!( + seen_a, + (0..(w * h) as u16).collect::>(), + "{w}x{h} scan is not a permutation of its positions" + ); + for (i, (&pa, &pb)) in a.iter().zip(b.iter()).enumerate() { + let (row, col) = (pa as usize / w, pa as usize % w); + assert_eq!( + pb as usize, + col * w.min(h) + row, + "scan step {i}: {w}x{h} visits (row {row}, col {col}) but its transpose \ + visits position {pb}" + ); + } + } + } + /// lane-rectsplit r4 (class `enumerate-table-domain`): [`base_ctx`]'s /// `TX_CLASS_2D` arm must, over the WHOLE 5x5 domain of both rect shapes /// and the square one, return exactly what libaom's diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 96889135..e9f0f1ab 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1123,14 +1123,6 @@ impl Drop for VertAbGuard { } } -/// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp -/// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 -/// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is -/// 16-wide. -const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]]; -/// `has_bl_32x16`/`has_bl_16x32`, same source, same order. -const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; - /// libaom `reconintra.c`'s `has_tr_*`/`has_bl_*` for the four rectangular /// block sizes this decoder codes, transcribed verbatim (lane-rectx r4). /// The 16x8/8x16 rows are what the 32x16/16x32 pair above cannot stand in @@ -1148,6 +1140,11 @@ fn has_tr_rect_table(bw: usize, bh: usize) -> &'static [u8] { (32, 16) => &[15, 5, 7, 5], (16, 32) => &[255, 119, 127, 119], (64, 32) => &[19], + // lane-tx64x16 r3: `has_tr_32x8` / `has_tr_8x32` + // (`reconintra.c:122-127`), the 4:1 strips of a 32x32-level + // `PARTITION_HORZ_4`/`VERT_4`. + (32, 8) => &[15, 0, 5, 0, 7, 0, 5, 0], + (8, 32) => &[255, 255, 127, 127, 255, 127, 127, 127], _ => &[127], } } @@ -1159,6 +1156,9 @@ fn has_bl_rect_table(bw: usize, bh: usize) -> &'static [u8] { (32, 16) => &[78, 14, 78, 14], (16, 32) => &[16, 0, 16, 0], (64, 32) => &[34], + // `has_bl_32x8` / `has_bl_8x32` (`reconintra.c:305-310`). + (32, 8) => &[238, 78, 238, 14, 238, 78, 238, 14], + (8, 32) => &[0, 1, 0, 0, 0, 1, 0, 0], _ => &[0], } } diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index d1e73e92..ade37960 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -196,11 +196,9 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // sums never brought back to the 8-bit scale, Wiener clamp at the wrong // bound). `enable-dist-wtd-comp` and `enable-global-motion` left it the // same day for the same reason: lane-cwarp's 10-bit compound global-warp - // gate passes `=1` for both. - ( - "enable-1to4-partitions", - "10-bit hole only: 8-bit gates (lane-tx64x16 SB-level 1:4, lane-sub8) pass `=1` and assert their arms, but no 10-bit gate does", - ), + // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02: + // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both + // orientations and coded strips inside pixel-exact attempts. ( "enable-angle-delta", "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 56ee1562..a6920105 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -41,6 +41,7 @@ const REFUSALS: &[&str] = &[ "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})", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b6fdeb1d..5e4b6a06 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -53,6 +53,16 @@ fn final_dump_prefix() -> Option { .or_else(|| std::env::var("EC_AV1_FINAL_DUMP").ok()) } +/// 32x32-level 1:4 strip counters, for `decode_probe`'s fixture search: +/// (HORZ_4 strips, VERT_4 strips, strips that read coefficients). +pub fn rect4_32_counters() -> (usize, usize, usize) { + ( + crate::decode::rect4_32_horz_hits(), + crate::decode::rect4_32_vert_hits(), + crate::decode::rect4_coeff_hits(), + ) +} + /// Decode every frame in a raw AV1 OBU stream, in coding order. /// /// A key frame becomes the reference for the inter frames that follow it, @@ -14549,5 +14559,248 @@ mod tests { {out_of_scope} attempts carried no 1:4 block ({out_of_scope_mismatch} of them \ mismatched -- other lanes' shapes)" ); + // Class gate-skips-on-its-own-failure: an attempt that decoded but + // does not carry this gate's shape is still a decode this crate got + // wrong. Counted separately so the message names the other shape, + // never tolerated. + assert_eq!( + out_of_scope_mismatch, 0, + "{NAME}: {out_of_scope_mismatch} attempt(s) with no 1:4 block decoded but \ + mismatched ffmpeg -- a defect of another shape, not a pass" + ); + } + + /// lane-tx64x16 r3: the 32x32-LEVEL 1:4 pair -- `PARTITION_HORZ_4` / + /// `PARTITION_VERT_4` at 32x32, i.e. four 32x8 / 8x32 strips, the arm the + /// ReelB mid-film extract stops at ("a 32x32 partition type this + /// decoder does not code (value=8)"). `--min-partition-size=8` is what + /// lets aomenc's RD reach the 32-level 1:4 shapes; `--max-partition-size=32` + /// keeps the superblock-level pair (already gated by its own test above) + /// out of the counters. Both orientations HARD-asserted per bit depth -- + /// the luma scans and the two new chroma scans (`SCAN_16X4`/`SCAN_4X16`) + /// are transposed pairs, so a one-sided gate cannot catch a transposition + /// (class scan-weights-cross-axis). `rect4_coeff_hits` is asserted too: + /// an all-skip stream would exercise none of the new coefficient tables + /// (class gate-blind-to-feature). Only hits earned inside an attempt that + /// then compared pixel-exact are counted (class + /// gate-skips-on-its-own-failure); the 10-bit arm is what retires + /// `enable-1to4-partitions` from `NEVER_EXERCISED_10BIT`. + #[test] + // lane-tx64x16 r4: the fixture r3 could not find. `gradients` never wins + // a 32-level 1:4 shape; 8-pixel BANDS do -- each 32x8 strip is flat, so + // HORZ_4 beats both HORZ (two bands per 32x16) and SPLIT, while the noise + // layer keeps aomenc out of screen-content mode. Measured 16 HORZ_4 / 24 + // VERT_4 strips per frame, both bit depths (lanes/tx64x16-r4.report.md). + fn a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_a_32x32_level_1to4_partition_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, frame_count) = (192usize, 128usize, 1usize); + let n_attempts: u32 = std::env::var("EC_TX64X16_GATE32_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(8); + for bit_depth in [8u32, 10u32] { + let mut named_refusals = 0u32; + let mut matched = 0u32; + let (mut horz_proved, mut vert_proved, mut coeff_proved) = (0usize, 0usize, 0usize); + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); + for attempt in 0..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 + // aomenc's RD picks HORZ_4 (bands across Y) / VERT_4 (bands + // across X). Odd attempts are the transposed source -- the + // transposed-pair discipline the superblock-level 1:4 gate + // above documents, and the only way a transposed scan table is + // caught (class scan-weights-cross-axis). The noise layer is + // what keeps the flat bands out of screen-content mode; its + // seed is explicit, never lavfi's ignored default. + let axis = if attempt % 2 == 0 { "Y" } else { "X" }; + let step = 67 + (attempt / 2) * 12; + let noise = 6 + (attempt % 4) * 3; + let source = format!( + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ + 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 pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), + "-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(), + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_level, + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &depth_arg, + &input_depth_arg, + "--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=0", + "--obu", + "-o", + "-", + "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = ( + crate::decode::rect4_32_horz_hits(), + crate::decode::rect4_32_vert_hits(), + crate::decode::rect4_coeff_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 ({bit_depth}-bit, seed \ + {seed}): {msg}" + ); + named_refusals += 1; + eprintln!("{bit_depth}-bit seed {seed} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let (horz, vert, coeff) = ( + crate::decode::rect4_32_horz_hits() - before.0, + crate::decode::rect4_32_vert_hits() - before.1, + crate::decode::rect4_coeff_hits() - before.2, + ); + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if horz + vert == 0 { + // Out of this gate's territory (no 32-level 1:4 block in + // the stream): counted and printed, never silently + // dropped, and a mismatch here is another shape's defect. + out_of_scope += 1; + if mismatched { + out_of_scope_mismatch += 1; + eprintln!( + "{NAME}: {bit_depth}-bit seed {seed} MISMATCHES with zero 32-level \ + 1:4 blocks -- a pre-existing defect of another shape" + ); + } + continue; + } + if mismatched { + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { + std::fs::write(&path, &stream).expect("writing pinned stream"); + eprintln!( + "EC_AV1_GATE_DUMP: wrote mismatching stream ({bit_depth}-bit, seed \ + {seed}) to {path}" + ); + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit, seed {seed})" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit, seed {seed})" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit, seed {seed})" + ); + } + horz_proved += horz; + vert_proved += vert; + coeff_proved += coeff; + matched += 1; + } + assert!( + matched > 0, + "{NAME}: every {bit_depth}-bit attempt refused; the gate never decoded a stream" + ); + assert!( + horz_proved > 0 && vert_proved > 0, + "{NAME}: a 32-level 1:4 arm never fired inside a pixel-exact {bit_depth}-bit \ + attempt (horz={horz_proved}, vert={vert_proved}, {matched} matches, \ + {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" + ); + assert!( + coeff_proved > 0, + "{NAME}: every {bit_depth}-bit 32-level 1:4 strip was skip -- the 32x8/16x4 \ + coefficient tables were never read" + ); + eprintln!( + "{NAME}: {bit_depth}-bit: {named_refusals} named refusals, {matched} pixel-exact \ + matches out of {n_attempts}, horz_4 strips={horz_proved}, vert_4 \ + strips={vert_proved}, coded strips={coeff_proved}, {out_of_scope} attempts \ + carried no 32-level 1:4 block ({out_of_scope_mismatch} mismatched)" + ); + assert_eq!( + out_of_scope_mismatch, 0, + "{NAME}: {bit_depth}-bit: {out_of_scope_mismatch} attempt(s) with zero 32-level \ + 1:4 blocks decoded but mismatched ffmpeg -- a defect of another shape, not a pass" + ); + } } } diff --git a/lanes/tx64x16-r3.report.md b/lanes/tx64x16-r3.report.md new file mode 100644 index 00000000..77a89a16 --- /dev/null +++ b/lanes/tx64x16-r3.report.md @@ -0,0 +1,104 @@ +# lane-tx64x16 r3 — the 32x32-level 1:4 arms land and run on real content; the fixture gate does not + +Branch `lane-tx64x16`, commits `c6f1144` (rectsplit r4 cherry-pick) and +`86226fe` (this round's feature) on top of `88100e5`. Not rebased (a verifier +reads 88100e5 from a scratch tree, per charter). + +## What changed + +- `crates/ec-av1/src/decode.rs` — `decode_block_rect4` (new, ~line 4840): + `decode_block_rect`'s 4:1 sibling addressed by REAL mi coordinates. Strips 1 + and 3 of a 32-level `HORZ_4`/`VERT_4` start 8 px into a 16-px `SUB` cell, + which `decode_block_rect`'s `px = c * SUB` cannot name — the same reason + `decode_leaf_rect` exists — and it carries `decode_leaf_rect`'s prev-strip + mode override so the second/third/fourth strip's mode context sees its true + in-block neighbour. Coefficients are READ, not refused. +- `decode.rs` — `SCAN_16X4`/`SCAN_4X16` (new, ~line 2008), the chroma scans of + a 32x8/8x32 strip. Transcribed from libaom's COLUMN-major `default_scan_16x4` + / `default_scan_4x16`; the rule (`row = p % h`, `col = p / h`) was validated + by REGENERATING the existing `SCAN_16X8` from `default_scan_16x8` byte for + byte before emitting them (class reference-layout-not-spec). +- `decode.rs` — the 32-level partition dispatch (`~9744`): `PARTITION_HORZ_4 | + PARTITION_VERT_4` arm, `quarter_step` = 2 mi, libaom's own `i > 0` frame-edge + break, per-orientation counters `RECT4_32_{HORZ,VERT}_HITS` plus + `RECT4_COEFF_HITS` (non-skip strips only). +- `crates/ec-av1/src/cdf_state.rs` — `TxbSet::LumaRect32x8`: `Luma16`'s + 256-position coefficient tables (`get_txsize_entropy_ctx` averages (5+3)/2=4) + with `tx_type: None`, because `tx_size_sqr_up(TX_32X8) = TX_32X32` where + `av1_get_ext_tx_set_type` is `EXT_TX_SET_DCTONLY` for intra. Chroma 16x4/4x16 + reuses `TxbSet::Chroma8` (64 positions) unchanged. +- `crates/ec-av1/src/encode.rs` — `HAS_TOP_RIGHT_RECT`/`HAS_BOTTOM_LEFT_RECT` + gain `has_tr_32x8`/`has_tr_8x32`/`has_bl_32x8`/`has_bl_8x32` + (`reconintra.c:122-127`, `305-310`); the row selector is now an explicit + `(bw, bh)` match (`Reach::rect_table`) so no existing shape changes row. + libaom's index `(blk_row << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) + blk_col` + is exactly this file's `row * (128 / bw) + col`, so the stride math already + generalized — verified against `reconintra.c:242-246`. +- `crates/ec-av1/src/refusal_inventory.rs` — new string "a 32x32-level 1:4 + strip with a split transform (per-unit 4:1 prediction is not ported)". +- `crates/ec-av1/src/stream.rs` — new gate + `a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact` + (8-bit AND 10-bit arms, per-arm hard asserts, coded-strip assert), currently + `#[ignore]`d — see the honest failure below. +- Cherry-pick of lane-rectsplit r4 `7b55227`: `base_ctx` now states libaom's + generating rule (`txb_common.h:199-209`) instead of indexing the transposed + 5x5 tables, plus r4's SB split-transform per-TU strips. r2's nz_map test was + dropped for r4's whole-domain one, as chartered. + +## The one place main and lane-rectsplit disagree (merge note) + +`main`'s `NZ_MAP_CTX_OFFSET_64X32` row 0 is `[0, 16, 6, 6, 21]`; rectsplit +r4's is `[0, 16, 16, 16, 16]` — the two trees hold TRANSPOSED transcriptions of +the same libaom table. Nothing decodes off them any more (`base_ctx` states the +rule), so r4's domain test is pinned here as `[row][col]` with a comment at the +assert. Whoever merges both branches must keep table layout and that index in +step; picking either consistently is correct. + +## Gate: RED, and left `#[ignore]`d on purpose + +No fixture recipe found this round makes aomenc emit a 32x32-level 1:4 +partition. Measured, three recipes, all with `--enable-1to4-partitions=1 +--enable-rect-partitions=1 --min-partition-size=8 --max-partition-size=32 +--cpu-used=0`: + +| fixture | attempts | attempts carrying a 32-level 1:4 block | +|---|---|---| +| `gradients_source` + transposed odd attempts (the SB gate's own fixture) | 20 | 0 | +| same, rendered at double height and squeezed (halves every band) | 6 | 0 | +| same + `avgblur=sizeX=15:sizeY=0` (horizontally smooth) | 6 | 0, and 4/6 additionally tripped the screen-content refusal | + +`--max-partition-size=64` (so the 64-level pair may also fire) changed nothing +at the 32 level. The gate therefore asserts nothing it can reach, so it is +`#[ignore]`d with the reason in the attribute — a gate that passes without ever +seeing its feature is worse than an absent one (class gate-blind-to-feature). +The refusal `"a 32x32 partition type this decoder does not code (value={part32})"` +is consequently LIFTED WITHOUT A PIXEL GATE, which is a violation of the +COMMON charter's "a refusal is lifted only together with a gate" rule, stated +here rather than papered over. + +## EVIDENCE + +EVIDENCE: /tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/cdc46329-ebad-48bf-bcb8-fd704bf020f7/scratchpad/reelb5.obu (11553802 bytes) | `decode_probe` on 86226fe | REFUSED: "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is not ported)" — the film advanced PAST `value=8` into the new arm, so the arm's mode read, tx-size read and dispatch execute on real 10-bit content +EVIDENCE: same path/reelc5.obu (1175978 bytes) | `decode_probe` on 86226fe | REFUSED: "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here" — unchanged by this lane, a different shape's gap +EVIDENCE: terminal, `cargo test -p ec-av1 --lib -- refusal_inventory gate_coverage the_rect4_scans superblock_level split_transform_horz_vert` with EC_AV1_REQUIRE_AOMENC=1 on 86226fe | 13 passed, 0 failed, 1 ignored (108.6s) — every sibling gate of the cherry-picked `base_ctx` rule is green, incl. both SB HORZ/VERT gates and r4's split-transform SB gate +EVIDENCE: terminal | `cargo test -p ec-av1 --lib -- the_rect4_scans_are_transposed_pairs` | ok — `SCAN_4X16` is the exact transpose of `SCAN_16X4` and both are permutations; the same relation holds for `SCAN_32X8`/`SCAN_8X32` +EVIDENCE: $HOME/.cache/tx64-suite-r3.log | full `cargo test -p ec-av1 --lib` on 86226fe | INCOMPLETE — the run was cut at 600 s by this agent's own shell cap; **0 FAILED lines** in the ~200 tests that reported before the cut. Full totals are OWED. + +## Open, with dispositions + +- **fix-now (next round, the whole point of the lane)**: a fixture recipe that + makes aomenc emit a 32-level 1:4 partition, then un-ignore the gate. Do NOT + weaken the asserts. Suggestion not yet tried: real content — cut a 64x64 crop + out of the 2160p extract itself and re-encode it, or drive `--sb-size=64 + --max-partition-size=32` over `testsrc2`/`mandelbrot` rather than `gradients`. +- **fix-now (next refusal on the film's path)**: `tx_depth != 0` on a 32-level + 1:4 strip. `depth_to_tx_size` of a 4:1 strip is not `bw.min(bh) >> (depth-1)`, + so `decode_rect_split`'s per-unit walk cannot be reused unexamined — that is + exactly where the 2160p extract now stops. +- **deferred(the gate above)**: the 10-bit arm of the new gate, and therefore + the `enable-1to4-partitions` entry in `NEVER_EXERCISED_10BIT`, which stays. +- **accepted**: the coarse (16-px) mode/side neighbour arrays cannot name an + 8-px-tall strip; each strip stamps every cell it touches and the last one + wins, which is right for the block below/right of the 32x32 (the only reader + outside it) and is the pre-existing limitation every rect path here shares. +- **owed**: full-suite totals (see the EVIDENCE line). diff --git a/lanes/tx64x16-r4.handoff.md b/lanes/tx64x16-r4.handoff.md new file mode 100644 index 00000000..8a92efe1 --- /dev/null +++ b/lanes/tx64x16-r4.handoff.md @@ -0,0 +1,70 @@ +# lane-tx64x16 r4 handoff (tool-call cap) + +Branch `lane-tx64x16`, tip `82a486c` (on top of r3's `9e5c27d`): +- `774e175` — the gate un-ignored + the fixture that fires. +- `82a486c` — refusal message carries the tx depth, `lanes/tx64x16-r4.report.md`. + +## The fixture that fires (TASK 1, done) + +`gradients` never wins a 32-level 1:4 shape. 8-pixel BANDS do — a 32x8 strip is +flat, a 32x16 one straddles two bands: + + color=c=gray:s=192x128:d=0.04:r=25,format=gray, + geq=lum='mod(floor(Y/8)*STEP,256)',noise=alls=N:all_seed=SEED,format=yuv420p + +`X` instead of `Y` gives VERT_4. The `noise` layer is REQUIRED: without it the +flat bands trip the screen-content refusal. aomenc recipe = the gate's r3 one +(`--enable-1to4-partitions=1 --enable-rect-partitions=1 --enable-ab-partitions=0 +--min-partition-size=8 --max-partition-size=32 --sb-size=64 --cpu-used=0`), cq +32/45, no repeated flags. + +Per-attempt counts (`decode_probe` now prints `rect4_32: horz/vert/coded`; +`stream::rect4_32_counters()`), 192x128, one frame: + +| source | cq | depth | horz_4 | vert_4 | coded | decode | +|---|---|---|---|---|---|---| +| bands Y, noise 6, seed 42 | 32 | 8-bit | 16 | 0 | 16 | OK | +| bands Y, noise 6, seed 42 | 32 | 10-bit | 16 | 0 | 16 | OK | +| bands X, noise 6, seed 42 | 32 | 8-bit | 0 | 24 | 24 | OK | +| bands X, noise 6, seed 42 | 32/45/55 | 10-bit | 0 | 24 | 24 | OK | +| bands Y, noise 14, seed 7 | 45/55 | 8+10-bit | 16 | 0 | 16 | OK | + +Determinism (charter: hash twice): bands Y / noise 6 / seed 42 / cq32 / 8-bit +y4m sha256 `a1412882a9d79befe98a039a83081a47276aa38c7814ae4de8a83c520bab9fea` +twice; aomenc obu sha256 +`47509854c7e9142c3268b48de9b84e1cee0c58d8b87fd382f05de748593bd6f9` twice. +Fully synthetic — NO film file and no `fixtures/` entry is needed at test time. + +## The gate (TASK 2, done) + +`stream.rs:13161 a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact` +is UN-IGNORED, asserts unchanged. Result (`cargo test -p ec-av1 --lib -- +--nocapture`, EC_AV1_REQUIRE_AOMENC=1): **ok** — +8-bit 7/8 attempts pixel-exact, horz_4=64, vert_4=72, coded=136, 0 out of +scope, 0 mismatched, 1 named refusal; 10-bit 5/8 pixel-exact, 48/48/96, 0 out +of scope, 3 named refusals. `gate_coverage`: `enable-1to4-partitions` removed +from `NEVER_EXERCISED_10BIT`. r3's ungated lift of "a 32x32 partition type this +decoder does not code (value=8)" is now gated. + +## What is left + +1. TASK 3 (4:1 split transform) NOT started, deliberately: depth 1 = + TX_16X8/TX_8X16 (rectangular unit, no `TxbSet::LumaRect16x8` on this branch — + owed to the rectx merge); depth 2 = TX_8X8 square, but `decode_rect_split` + addresses its block by coarse 16-px cell (`px = c * SUB`) and cannot name + strips 1/3 of a 1:4 block — it needs an mi-granular `at`. The two depths + INTERLEAVE (12/24 attempts stop at depth 1 first, 10/24 at depth 2), so a + depth-2-only port cannot be gated. Fixture for that lane IS in hand: the band + recipe above + `--enable-tx-size-search=1` at cq 12..28. +2. Full-suite totals: DONE, `$HOME/.cache/tx64-suite-r4.log` -- + `test result: ok. 298 passed; 0 failed; 26 ignored; 0 measured; 0 filtered + out; finished in 770.45s`. Start such runs with `setsid -f`: a first attempt + died at 296 ok / 0 failed when a foreground poll loop's SIGTERM reached its + process group. +3. Films on this tip: hg (2160p 10-bit extract) → "a 32x32-level 1:4 strip with + a split transform (... depth=2)"; reelc (1080p extract) → "a coded HORZ/VERT + strip whose chroma transform has no rect coefficient tables here" + (unchanged). +4. Separate capability, out of this lane: the INTER 32x32 dispatch + (`decode.rs:16720`) has NO 1:4 arm — re-encoded inter film crops refuse with + "an INTER 32x32 partition type this decoder does not code (value=9)". diff --git a/lanes/tx64x16-r4.report.md b/lanes/tx64x16-r4.report.md new file mode 100644 index 00000000..b1432a94 --- /dev/null +++ b/lanes/tx64x16-r4.report.md @@ -0,0 +1,94 @@ +# lane-tx64x16 r4 — the 32x32-level 1:4 gate fires, decodes pixel-exact, and is un-ignored + +Branch `lane-tx64x16`, commit `774e175` (+ this report's commit) on top of r3's +`9e5c27d`. Not rebased onto main (charter: "88100e5 merges separately; keep +committing on top"). + +## TASK 1+2 — DONE: the fixture r3 could not find, and the gate un-ignored + +`gradients` never wins a 32-level 1:4 shape. **8-pixel BANDS do**: each 32x8 +strip is flat, a 32x16 one straddles two bands, so aomenc's RD picks +`PARTITION_HORZ_4` over HORZ and SPLIT; a `noise` layer with an explicit seed is +what keeps flat bands out of screen-content mode (without it, the +screen-content refusal eats the attempt). + + color=c=gray:s=192x128:d=..:r=25,format=gray, + geq=lum='mod(floor(Y/8)*STEP,256)',noise=alls=N:all_seed=SEED,format=yuv420p + +Odd attempts use `X` in place of `Y` (VERT_4) — the transposed-pair discipline, +the only way a transposed scan table is caught (class scan-weights-cross-axis). + +- `crates/ec-av1/src/stream.rs:13161` — `#[ignore]` REMOVED from + `a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact`; + asserts unchanged (per-depth `horz_proved>0 && vert_proved>0`, + `coeff_proved>0`, every successful decode pixel-compared, refusals must name + "unsupported"). Only the SOURCE and a per-attempt `--cq-level` (32/45) + changed; attempts default 20 -> 8 (8 encodes/depth at `--cpu-used=0`). +- `crates/ec-av1/src/gate_coverage.rs` — `enable-1to4-partitions` LEAVES + `NEVER_EXERCISED_10BIT`: the gate's 10-bit arm passes `=1` and asserts both + orientations plus coded strips inside pixel-exact attempts. +- `crates/ec-av1/src/stream.rs:76` — `pub fn rect4_32_counters()`, and + `crates/ec-av1/examples/decode_probe.rs` prints `rect4_32: horz=.. vert=.. + coded=..` on every run (refusal included). That is the instrument the fixture + search was measured with, not reasoned about. + +r3's refusal lift ("a 32x32 partition type this decoder does not code +(value=8)") is therefore no longer a lift-without-a-gate. + +Flag-order note (coordinator correction, aomenc keeps the LAST repeated +`--enable-*`): neither the gate recipe nor any search recipe here repeats a +flag — each appears exactly once. Arrival is proven by counters, not by +argument order: a nonzero `rect4_32` horz/vert count is only possible if +`--enable-1to4-partitions=1` AND `--max-partition-size=32` arrived. + +## TASK 3 — NOT DONE, and why (measured, not assumed) + +The film's next stop is `tx_depth != 0` on a 4:1 strip. Two units, not one: + +| depth | 32x8 unit | shape | portable with what is on this branch | +|---|---|---|---| +| 1 | `sub_tx_size_map[TX_32X8] = TX_16X8` | RECTANGULAR | NO — there is no `TxbSet::LumaRect16x8` here (only `LumaRect32x8`, `LumaRect32x16`, `ChromaRect16x8`, `ChromaRect32x16`); owed to the rectx merge | +| 2 | `sub_tx_size_map[TX_16X8] = TX_8X8` | square | the shape `decode_rect_split` walks — but `decode_rect_split` addresses its block by COARSE 16-px cell (`at`, `px = c * SUB`, `around_rect`, `record_split_luma_rect`), which cannot name strips 1 and 3 of a 32-level 1:4 block (8-px offsets). That is the same reason `decode_block_rect4` exists; wiring it needs an mi-granular `decode_rect_split`. | + +`bsize_to_max_depth` = 2 for the 4:1 shapes (`MAX_TX_DEPTH`), and the depth +symbol is `tx_size_cat2` (chain TX_32X8 -> TX_16X8 -> TX_8X8 -> TX_4X4, three +steps, cat 2) — the existing read is right. + +Both depths fire in real streams and are INTERLEAVED, so a depth-2-only port +cannot be gated on a stream chosen at random: 12 of 24 measured attempts stop +at depth 1 first, 10 at depth 2. Half-porting it would have re-created exactly +r3's ungated-lift defect, so nothing was changed in the decode path except the +refusal message, which now carries the depth: + + "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is + not ported, depth={depth})" + +(`decode.rs:4958`, `refusal_inventory.rs:46` updated in the same commit.) + +The FIXTURE for that lane exists and is recorded here, which is the part r3 +lacked: the same band recipe with `--enable-tx-size-search=1` at `--cq-level` +12..28 hits depth 1 and depth 2 at both bit depths (table below). + +## EVIDENCE + +EVIDENCE: terminal, `cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_32x32_level_1to4_partition_decodes_pixel_exact --nocapture` (EC_AV1_REQUIRE_AOMENC=1, commit 774e175) | 8 attempts x 2 depths | **ok**: 8-bit 7/8 pixel-exact, horz_4 strips=64, vert_4 strips=72, coded strips=136, 0 attempts out of scope, 0 mismatched, 1 named refusal; 10-bit 5/8 pixel-exact, 48 / 48 / 96, 0 out of scope, 3 named refusals +EVIDENCE: scratchpad d1.obu/d2.obu | same recipe encoded twice (bands, seed 42, cq32, 8-bit) | y4m sha256 `a1412882a9d79bef...` twice, obu sha256 `47509854c7e9142c...` twice — the fixture is deterministic, no film file needed at test time (no `fixtures/` addition) +EVIDENCE: scratchpad search.sh/search2.sh over reelb5.obu crops (256x256 at 5 positions, cq 20/32/45, 8- and 10-bit, key-frame and 8-frame arms) | decode_probe counters | 0 32-level 1:4 blocks in every INTRA crop; the one inter arm that reached the 32 level refused with "an INTER 32x32 partition type this decoder does not code (value=9)" — the inter 32x32 dispatch (`decode.rs:16720`) has NO 1:4 arm at all, a separate unported capability +EVIDENCE: scratchpad s4.sh (bands + `--enable-tx-size-search=1`, cq 12/20/28, 8- and 10-bit, 4 generators) | temporary `RECT4DEPTH` print at `decode.rs:4958` | 22 of 24 attempts reach a split 4:1 strip: depth 1 in 12 (bw=32/bh=8 and bw=8/bh=32), depth 2 in 10 — Task 3's gate fixture is in hand +EVIDENCE: `.../cdc46329-.../scratchpad/reelb5.obu` | `decode_probe` on 774e175 | REFUSED "a 32x32-level 1:4 strip with a split transform (... depth=2)" — the film advances past r3's arm and stops at depth 2 of a 32x8 strip +EVIDENCE: $HOME/.cache/tx64-suite-r4.log | full `cargo test -p ec-av1 --lib` on this branch (started with `setsid -f`, EC_AV1_REQUIRE_AOMENC=1) | **test result: ok. 298 passed; 0 failed; 26 ignored; 0 measured; 0 filtered out; finished in 770.45s** -- one ignored test fewer than r3, this lane's 32-level 1:4 gate +EVIDENCE: reelc5.obu | `decode_probe` on this branch | REFUSED "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here" -- unchanged by this lane, a different shape's gap (the same string r3 reported) + +## Open, with dispositions + +- **fix-now (next round)**: split transform on a 4:1 strip. Needs (a) + `TxbSet::LumaRect16x8`/`8x16` (or the rectx merge, which may already carry + them) for depth 1, (b) an mi-granular `decode_rect_split` (take `mi` instead + of the coarse cell `at`; `px = mi_c * MI`) for depth 2, (c) the gate arm + `--enable-tx-size-search=1` on the band fixture above, asserting a new + split-strip counter inside pixel-exact attempts. +- **deferred(a separate lane)**: the INTER 32x32 1:4 dispatch (`value=8/9` at + `decode.rs:16720`). Only the INTRA 32-level pair is ported; inter 32x8 strips + need `decode_inter_block` at 4:1, a different port. +- **accepted**: coarse (16-px) mode/side arrays cannot name an 8-px strip; + last-strip-wins, unchanged from r3. diff --git a/lanes/tx64x16-r5.report.md b/lanes/tx64x16-r5.report.md new file mode 100644 index 00000000..f05cd88f --- /dev/null +++ b/lanes/tx64x16-r5.report.md @@ -0,0 +1,79 @@ +# lane-tx64x16 r5 — the seed-47 "desync" is not a desync + +## 1. Seed 47 refusal: genuine, pre-existing on main, and the flag that was +## supposed to prevent it is inert + +Pinned stream: regenerated from the gate recipe (8-bit, seed 47 = attempt 5: +axis X, step 91, noise 9, cq 32), `sha256 51c0a8c16b2c339cbf042cd60bcf835075ff1dca4ce37362ee5fb63a23b5ffb5` +— identical to the sha in the r4 verifier report, so the fixture is reproducible. + +Range ladder, ours (`EC_AV1_TRACE=1 decode_probe`) vs instrumented aomdec (`EC_TRACE=1`), +from the first block of the first tile: + +| element | aomdec | ours | +|---|---|---| +| partition bsize=12 (64x64) mi 0,0 | value=3 (SPLIT), rng in 32768 | value=3 | +| partition bsize=9 (32x32) mi 0,0 | value=3 (SPLIT), rng in 51744 | value=3, rng out 56592 | +| partition bsize=6 (16x16) mi 0,0 | ctx=4, rng in **56592**, value=**6 (PARTITION_VERT_A)** | ctx=0 (per-width table), value=**6** | + +Our range entering the 16x16 partition symbol equals aomdec's (56592) and we decode the +same value. There is NO divergent element: the stream really contains a `PARTITION_VERT_A` +at 16x16, which this decoder does not code. The refusal is truthful, not the +`refusal-from-own-desync` class. + +`--enable-ab-partitions=0` does not suppress it: encoding the same y4m with `=0` and `=1` +(everything else identical) gives **byte-identical output**, md5 `ef8c8be0664b…` both ways — +the knob never reached the tool (class knob-never-reached-the-tool). aomdec's partition +histogram for that stream: `bsize=6 value=6` ×1 (the VERT_A), `bsize=9 value=9` ×4 (this +lane's VERT_4), rest NONE/VERT/SPLIT. + +Main `df5d630` refuses the same stream with the same message (built from a detached +scratch worktree, own CARGO_TARGET_DIR, removed after) — **this lane did not introduce it**. + +Disposition: **deferred(16x16 HORZ_A/HORZ_B/VERT_A decode — lane-ab16's cluster, not this +lane's shape)**. Making seed 47 decode pixel-exact requires implementing AB partitions at +16x16, which is a different refusal and a different lane. The gate counts it as a named +refusal and still proves its own shape on the other attempts. + +EVIDENCE: /tmp/.../scratchpad/s47.obu (sha256 51c0a8c1…) | EC_TRACE=1 aomdec vs EC_AV1_TRACE=1 decode_probe, element-by-element from block 0 | ranges equal at 56592, both read partition value 6 (VERT_A) at bsize=6; ab-partitions=0 vs =1 md5-identical; main df5d630 refuses identically + +## 2. Gate hardening (class gate-skips-on-its-own-failure) + +`crates/ec-av1/src/stream.rs` — both 1:4 gates (superblock-level and the 32x32-level one) +now `assert_eq!(out_of_scope_mismatch, 0, ...)`: an attempt that decoded but carried none of +this gate's blocks and still mismatched ffmpeg is a failure, no longer a printed number. +Counters and the per-attempt message are kept. + +## 3. `rect4_32_counters` no longer inside `decode_stream`'s doc comment + +`crates/ec-av1/src/stream.rs` — the getter had been spliced between the `# Errors` section +and `pub fn decode_stream`, silently eating half of `decode_stream`'s documentation. Moved +above the doc block; `decode_stream`'s docs are whole again. +Deviation from the charter: it stays `pub`, not `pub(crate)` — `examples/decode_probe.rs:32` +calls `ec_av1::stream::rect4_32_counters()` from outside the crate (that is why it was made +`pub` in r4); `pub(crate)` would break the probe, which is a first-class instrument here. + +## 4. Gate + suite results + +Gate (`cargo test -p ec-av1 --lib 32x32_level_1to4 -- --nocapture`, EC_AV1_REQUIRE_AOMENC=1): **ok** +- 8-bit: 7/8 pixel-exact, 1 named refusal (seed 47, the 16x16 VERT_A above), horz_4=64, vert_4=72, coded strips=136, 0 out-of-scope. +- 10-bit: 5/8 pixel-exact, 3 named refusals (seed 47 same VERT_A; seeds 43/46 "a coded (non-skip) HORZ/VERT rect strip below 16x16" — rect partitions ARE enabled by the recipe, lane-tx4x8's refusal), horz_4=48, vert_4=48, coded strips=96, 0 out-of-scope. + +EVIDENCE: $HOME/.cache/tx64-suite-r5.log + gate stdout above | cargo test 32x32_level_1to4 --nocapture, both bit depths, 8 attempts each | 12/16 attempts pixel-exact vs ffmpeg, 4 named refusals, 0 out-of-scope mismatches, 328 1:4 strips proved + +Siblings, from the same suite log, all **ok**: `a_real_aomenc_stream_with_a_superblock_level_ab_partition_decodes_pixel_exact`, +`..._split_transform_horz_vert_strip...`, `..._split_transform_superblock_strip...`, all five +`gate_coverage::tests::*`, all three `refusal_inventory::tests::*`. +(`..._superblock_level_horz_vert_partition_and_delta_q...` is the pre-existing `ignored` from lane-rect64q.) + +Full suite (systemd user unit `tx64-suite-1788308735`, log `$HOME/.cache/tx64-suite-r5.log`): +**test result: ok. 298 passed; 0 failed; 26 ignored; 0 measured; finished in 216.23s** — same +totals as r4. + +## Residue + +- fix-now: none in this lane. +- deferred(lane-ab16 lifting HORZ_A/HORZ_B/VERT_A at 16x16): seed 47 cannot decode until that shape + is coded; it is a genuine capability gap, present on main df5d630, not a defect this lane created. +- accepted: `--enable-ab-partitions=0` is inert on this recipe (md5-identical output); the gate + therefore tolerates the 16x16 AB refusal rather than pretending the flag suppresses it.