diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index e3ecb30e..a21cbdfc 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -3167,6 +3167,16 @@ pub const TXB_SKIP_CHROMA_16_Q3: [[u16; 3]; 3] = /// TXB_SKIP_CHROMA_32, q-context 3: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 121..=255. pub const TXB_SKIP_CHROMA_32_Q3: [[u16; 3]; 3] = [[4656, 32768, 0], [16074, 32768, 0], [24704, 32768, 0]]; + +/// `av1_default_txb_skip_cdfs[q][TX_32X32][10..13]` (token_cdfs.h): libaom's +/// chroma `txb_skip_ctx` offset is 10 instead of 7 when the plane block is +/// LARGER than the transform (`get_txb_ctx`), which in AV1 happens only for a +/// 128x128 block's four TX_32X32 chroma units -- the offset-7 rows above are +/// every other case (lane-sb128b r3). +pub const TXB_SKIP_CHROMA_32_BIG_Q0: [[u16; 3]; 3] = [[146, 32768, 0], [5132, 32768, 0], [31657, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG_Q1: [[u16; 3]; 3] = [[641, 32768, 0], [22265, 32768, 0], [31452, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG: [[u16; 3]; 3] = [[3082, 32768, 0], [20982, 32768, 0], [29443, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG_Q3: [[u16; 3]; 3] = [[1806, 32768, 0], [14645, 32768, 0], [25336, 32768, 0]]; /// EOB_EXTRA_LUMA_16, q-context 3: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 121..=255. pub const EOB_EXTRA_LUMA_16_Q3: [[u16; 3]; 9] = [ [19941, 32768, 0], diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 7eef9418..89334535 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -399,7 +399,10 @@ pub(crate) struct Cdfs { /// The all-zero flag of a 16x16 chroma transform. pub txb_skip_chroma_16: [[u16; 3]; 3], /// The all-zero flag of a 32x32 chroma transform. - pub txb_skip_chroma_32: [[u16; 3]; 3], + /// SIX contexts, not three: rows 0..3 are libaom's `txb_skip_ctx` 7..9 + /// (chroma transform == its plane block) and rows 3..6 its 10..12 (plane + /// block larger, i.e. a 128x128 block's four TX_32X32 chroma units). + pub txb_skip_chroma_32: [[u16; 3]; 6], /// The end-of-block group of a luma transform of 1024 positions. pub eob_pt_1024_luma: [u16; 12], /// The same, for chroma. @@ -1253,13 +1256,23 @@ impl Cdfs { cdf::TXB_SKIP_CHROMA_16, cdf::TXB_SKIP_CHROMA_16_Q3, ), - txb_skip_chroma_32: pick( - q_ctx, - cdf::TXB_SKIP_CHROMA_32_Q0, - cdf::TXB_SKIP_CHROMA_32_Q1, - cdf::TXB_SKIP_CHROMA_32, - cdf::TXB_SKIP_CHROMA_32_Q3, - ), + txb_skip_chroma_32: { + let small = pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_32_Q0, + cdf::TXB_SKIP_CHROMA_32_Q1, + cdf::TXB_SKIP_CHROMA_32, + cdf::TXB_SKIP_CHROMA_32_Q3, + ); + let big = pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_32_BIG_Q0, + cdf::TXB_SKIP_CHROMA_32_BIG_Q1, + cdf::TXB_SKIP_CHROMA_32_BIG, + cdf::TXB_SKIP_CHROMA_32_BIG_Q3, + ); + [small[0], small[1], small[2], big[0], big[1], big[2]] + }, eob_pt_1024_luma: pick( q_ctx, cdf::EOB_PT_1024_LUMA_Q0, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5c5825e1..ed9a1188 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -310,10 +310,12 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_ if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 { return; } - // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which - // it computes against the 64x64 root; under a 128 superblock no leaf this - // decoder codes can be the whole superblock (the root is always SPLIT). - if is_whole_sb && !sb128() && skip { + // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, + // computed against the sequence's own superblock size (lane-sb128b r1: + // it used to be hardcoded against 64 and disabled under `sb128`, which a + // `PARTITION_NONE` 128x128 root -- itself the whole superblock -- makes + // wrong). + if is_whole_sb && skip { return; } let mut abs = dec.symbol(&mut cdfs.delta_q) as i32; @@ -369,10 +371,12 @@ fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 { return; } - // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which - // it computes against the 64x64 root; under a 128 superblock no leaf this - // decoder codes can be the whole superblock (the root is always SPLIT). - if is_whole_sb && !sb128() && skip { + // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, + // computed against the sequence's own superblock size (lane-sb128b r1: + // it used to be hardcoded against 64 and disabled under `sb128`, which a + // `PARTITION_NONE` 128x128 root -- itself the whole superblock -- makes + // wrong). + if is_whole_sb && skip { return; } let multi = DELTA_LF_MULTI.with(|c| c.get()); @@ -4873,6 +4877,32 @@ impl Neighbours { self.record_mi_luma_rect(at_mi, tx_px, tx_px, grid); } + /// [`Self::record_mi_luma`] for ONE CHROMA transform unit of a block whose + /// uv plane block is several units (lane-sb128b r2: a 128x128 block's + /// 64x64 uv plane block is four TX_32X32 units, `av1_get_max_uv_txsize`). + /// `w_px`/`h_px` are the unit's extent in LUMA pixels -- the chroma + /// coefficient-context arrays are indexed by luma mi, the convention + /// [`Self::record_split_luma_rect_mi`] already writes them in, frame-edge + /// clamp included. + fn record_mi_chroma( + &mut self, + (mi_r, mi_c): (usize, usize), + w_px: usize, + h_px: usize, + plane: usize, + grid: &[i32], + ) { + let round_up_even = |n: usize| n.div_ceil(2) * 2; + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); + let state = neighbour_state(grid); + for cell in 0..(h_px / MI).min(bound_h.saturating_sub(mi_r)) { + self.left[mi_r + cell][plane] = state; + } + for cell in 0..(w_px / MI).min(bound_w.saturating_sub(mi_c)) { + self.above[mi_c + cell][plane] = state; + } + } + /// [`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. @@ -8432,8 +8462,12 @@ fn read_intra_mode( // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. maybe_read_cdef_idx(dec, mi_r, mi_c, skip); istep!("cdef", 0); - maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip); - maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip); + // lane-sb128b r1: "this leaf IS the superblock" is `side == sb_size`, not + // a hardcoded 64 -- a `PARTITION_NONE` 128x128 root is the whole + // superblock and skips `delta_q` exactly like a 64 one under a 64 root. + let whole_sb = side == sb_mi_cur() as usize * 4; + maybe_read_delta_q(dec, cdfs, mi_r, mi_c, whole_sb, skip); + maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, whole_sb, skip); istep!("dq", 0); // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before @@ -9132,7 +9166,12 @@ fn read_plane( let skip_ctx = if plane_idx == 0 { luma_skip_ctx.unwrap_or(0) } else { - usize::from(around.0) + usize::from(around.1) + // libaom `get_txb_ctx`: a chroma unit's context is + // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the + // plane block is bigger than the transform. Our chroma tables hold the + // offset-7 rows first, so the caller adds 3 for the bigger-block case + // (only a 128x128 block's TX_32X32 chroma units, lane-sb128b r3). + usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0) }; // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's // `intra_ext_tx_cdf` row is indexed by `fimode_to_intradir[filter_intra_mode]`, @@ -9317,7 +9356,11 @@ fn decode_block( let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); (resolved, if resolved == 64 { 32 } else { resolved }) } else { - (side, luma_tx) + // lane-sb128b r1: `max_txsize_rect_lookup[BLOCK_128X128]` is + // TX_64X64, so a 128x128 block is always FOUR luma transform units + // even with `tx_select` off -- the TU loop below, never the + // single-unit path. + (side.min(64), luma_tx) }; if tx_select && logical_tx < side && uv_mode != DC_PRED { SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1)); @@ -9422,10 +9465,17 @@ fn decode_block( // The palette/intrabc override path keeps the single-call shape (its // per-TU windowing is the non-skip loop's own `palette_y_buf` slice, // untested for skip and unreachable in these streams). + // lane-sb128b r2: a 128x128 block's transform is TX_64X64 even with + // `tx_select` off (`max_txsize_rect_lookup[BLOCK_128X128]`), so the + // per-unit prediction is keyed on the transform being smaller than + // the block, not on the tx-depth syntax. The counter keeps lane-hgkf's + // narrower meaning (a READ split tx depth). let split_tx_skip = - tx_select && logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); + logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none(); if split_tx_skip { - SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + if tx_select { + SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + } let n_axis = side / logical_tx; for tu_row in 0..n_axis { for tu_col in 0..n_axis { @@ -9475,41 +9525,62 @@ fn decode_block( ); } let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone()); - } - u.reconstruct( - cpx, - cpy, - chroma_side, - uv_predict_mode, - angle_delta_uv, - reach, - &vec![0i32; chroma_side * chroma_side], - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), - None, - smooth_neighbor_uv, - ); - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone()); + let cn = (chroma_side / chroma_tx).max(1); + for cu_row in 0..cn { + for cu_col in 0..cn { + let luma_span = chroma_tx * 2; + let cu_r = if cn == 1 { + reach + } else { + tu_reach( + side, side, + cu_col * luma_span, cu_row * luma_span, luma_span, + reach, px, py, y.width, y.height, + ) + }; + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); + } + u.reconstruct( + cu_x, + cu_y, + chroma_tx, + uv_predict_mode, + angle_delta_uv, + cu_r, + &vec![0i32; chroma_tx * chroma_tx], + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + ); + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); + } + v.reconstruct( + cu_x, + cu_y, + chroma_tx, + uv_predict_mode, + angle_delta_uv, + cu_r, + &vec![0i32; chroma_tx * chroma_tx], + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + ); + } } - v.reconstruct( - cpx, - cpy, - chroma_side, - uv_predict_mode, - angle_delta_uv, - reach, - &vec![0i32; chroma_side * chroma_side], - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), - None, - smooth_neighbor_uv, - ); let luma_grid = vec![0i32; side * side]; let u_grid = vec![0i32; chroma_side * chroma_side]; let v_grid = vec![0i32; chroma_side * chroma_side]; neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); - } else if !tx_select || logical_tx == side { + } else if logical_tx == side { + // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`. + // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so + // that arm was redundant -- and wrong at 128, where + // `max_txsize_rect_lookup` caps the block's transform at 64 and the + // block is four units whether or not `tx_select` is on. // A single luma transform unit -- the old path, unchanged (including // the 64x64 corner case, `logical_tx == side == 64` with // `coeff_tx_side == 32`). @@ -9602,8 +9673,27 @@ fn decode_block( // the earlier tiles in this same block already wrote -- the same // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. let n_axis = side / logical_tx; - for tu_row in 0..n_axis { - for tu_col in 0..n_axis { + let cn = (chroma_side / chroma_tx).max(1); + // libaom's transform-block loop is over 64x64 luma "mu" chunks + // (`decode_token_recon_block`: `mu_blocks_wide/high` = + // `mi_size_wide[BLOCK_64X64]`), and it codes EVERY PLANE of a chunk + // before moving to the next one. Below 128 a block is a single chunk, + // so this is byte-for-byte the all-luma-then-all-chroma order that has + // always run; at 128 the four quadrants interleave Y,U,V per quadrant + // and reading all four luma units first desyncs the tile at the second + // one (lane-sb128b r3, measured against aomdec's `EC_TRACE_COEFF`). + let nchunk = (side / 64).max(1); + // `cn > 1` means the uv plane block is larger than the uv transform, + // which moves libaom's chroma `txb_skip_ctx` offset from 7 to 10. + let chroma_ctx_offset = if cn > 1 { Some(3) } else { None }; + let tpc = (n_axis / nchunk).max(1); + let cpc = (cn / nchunk).max(1); + let mut last_grids = [Vec::new(), Vec::new()]; + let mut units: Vec<((usize, usize), usize, Vec, Vec)> = Vec::new(); + for ch_row in 0..nchunk { + for ch_col in 0..nchunk { + for tu_row in ch_row * tpc..(ch_row + 1) * tpc { + for tu_col in ch_col * tpc..(ch_col + 1) * tpc { let tu_mi = ( mi_r + tu_row * (logical_tx / MI), mi_c + tu_col * (logical_tx / MI), @@ -9664,7 +9754,11 @@ fn decode_block( tu_px, tu_py, logical_tx, - logical_tx, + // The unit's own COEFFICIENT grid, half its side at + // TX_64X64 (a 64-point transform codes nothing past 32); + // identical to `logical_tx` at every smaller size + // (lane-sb128b r1). + coeff_tx_side, base_q_idx, None, filter_intra, @@ -9682,59 +9776,81 @@ fn decode_block( neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); } } + // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where + // this still runs after every luma unit of the block. let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); - let chroma_around = neighbours.around(at, side); - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone()); + // The block's uv plane block is `chroma_side` across but its uv + // transform is `chroma_tx` (`av1_get_max_uv_txsize` = + // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`): + // identical at every size up to 64x64, but a 128x128 block's 64x64 uv + // plane block adjusts TX_64X64 down to TX_32X32, so each plane is + // FOUR units (lane-sb128b r2) -- one per mu chunk. + for cu_row in ch_row * cpc..(ch_row + 1) * cpc { + for cu_col in ch_col * cpc..(ch_col + 1) * cpc { + // The chroma context arrays are indexed in LUMA mi, so this + // unit's anchor is its own luma quadrant: `chroma_tx` chroma + // pixels span `2 * chroma_tx` luma ones. + let luma_span = chroma_tx * 2; + let cu_mi = ( + mi_r + cu_row * (luma_span / MI), + mi_c + cu_col * (luma_span / MI), + ); + let cu_around = neighbours.around_mi(cu_mi, luma_span); + let cu_reach = if cn == 1 { + reach + } else { + tu_reach( + side, side, + cu_col * luma_span, cu_row * luma_span, luma_span, + reach, px, py, y.width, y.height, + ) + }; + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); + } + let u_grid = read_plane( + dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode, + uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y, + chroma_tx, chroma_tx, base_q_idx, + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), + None, chroma_ctx_offset, smooth_neighbor_uv, + )?; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); + } + let v_grid = read_plane( + dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode, + uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y, + chroma_tx, chroma_tx, base_q_idx, + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), + None, chroma_ctx_offset, smooth_neighbor_uv, + )?; + if cn > 1 { + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + // Immediately, so the NEXT unit of this same block reads + // this one's coefficient context (libaom's chroma + // `txb_skip_ctx` for the second quadrant is 11, i.e. base + // 1 from this left neighbour -- measured against aomdec). + // The same writes are replayed after `record_split_luma` + // below, which would otherwise clobber them whole-block. + neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 1, &u_grid); + neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 2, &v_grid); + units.push((cu_mi, luma_span, u_grid.clone(), v_grid.clone())); + } + last_grids = [u_grid, v_grid]; + } } - let u_grid = read_plane( - dec, - cdfs, - chroma_set, - scans.1, - 1, - chroma_around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, - )?; - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone()); } - let v_grid = read_plane( - dec, - cdfs, - chroma_set, - scans.1, - 2, - chroma_around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, - )?; - neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&u_grid, &v_grid]); + } + // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma + // context write; at `cn > 1` the per-unit writes above are what the + // next block reads, so they run after this (last writer wins). + neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&last_grids[0], &last_grids[1]]); + for (cu_mi, luma_span, u_grid, v_grid) in &units { + neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_grid); + neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_grid); + } } // Unconditional, `size == 0` for a non-palette block: clears any stale // neighbour palette state the same way [`Neighbours::record`] always @@ -11141,8 +11257,14 @@ fn read_tx_size( // key-frame path's own deblock-grid approximation. ctx_override: Option, ) -> usize { - let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side)); - let depth = match side { + // `max_txsize_rect_lookup[bsize]` (libaom `read_selected_tx_size` / + // `get_tx_size_context`): a block wider than 64 still tops out at + // TX_64X64, so BLOCK_128X128 reads BLOCK_64X64's own category (its depth + // chain 64->32->16->8->4 is the same four steps) and resolves against 64, + // never against its own 128 side (lane-sb128b r1). + let max_tx = side.min(64); + let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, max_tx)); + let depth = match max_tx { 8 => { dec.symbol(&mut cdfs.tx_size_cat0[ctx]) } @@ -11155,7 +11277,7 @@ fn read_tx_size( 64 => { dec.symbol(&mut cdfs.tx_size_cat3[ctx]) } - _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), + _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"), }; if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { let (rng, _) = dec.debug_state(); @@ -11167,7 +11289,7 @@ fn read_tx_size( if depth != 0 { TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); } - side >> depth + max_tx >> depth } /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's @@ -12774,6 +12896,29 @@ fn sb_visit_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32, /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this /// decoder codes, the other seven arms refuse by name. #[allow(clippy::too_many_arguments)] +thread_local! { + /// How many 128x128 superblock roots resolved to `PARTITION_NONE` -- one + /// whole 128x128 block (lane-sb128b r1's gate counter). + pub(crate) static PART128_NONE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// [`PART128_NONE_HITS`], for a gate's own before/after delta. +pub(crate) fn part128_none_hits() -> usize { + PART128_NONE_HITS.with(std::cell::Cell::get) +} + +thread_local! { + /// How many CHROMA transform units were coded inside a block whose uv + /// plane block is more than one unit (lane-sb128b r2 -- only a 128x128 + /// block, four per plane). + pub(crate) static CHROMA_SPLIT_TX_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// [`CHROMA_SPLIT_TX_HITS`], for a gate's own before/after delta. +pub(crate) fn chroma_split_tx_hits() -> usize { + CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get) +} + fn read_sb128_root( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, @@ -12788,7 +12933,7 @@ fn read_sb128_root( sb_c: u32, mi_cols: u32, mi_rows: u32, -) -> Result<()> { +) -> Result { let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI); crate::restoration::read_lr( dec, @@ -12839,13 +12984,20 @@ fn read_sb128_root( } } }; - if part128 != PARTITION_SPLIT { + // lane-sb128b r1: `PARTITION_NONE` -- one 128x128 block -- is decoded by + // the key-frame caller below. The six remaining arms (HORZ/VERT and the + // four AB shapes) still need the rect/AB machinery at this size. + if part128 != PARTITION_SPLIT && part128 != PARTITION_NONE { return Err(unsupported( - "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)", + "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", )); } - PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); - Ok(()) + if part128 == PARTITION_SPLIT { + PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); + } else { + PART128_NONE_HITS.with(|c| c.set(c.get() + 1)); + } + Ok(part128) } pub(crate) fn decode_key_frame_tile_with_cdfs( @@ -13023,10 +13175,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( ); TILE_HITS.with(|c| c.set(c.get() + 1)); + // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` -- + // its one block covers all four 64x64 quadrants, so the remaining three + // visits of this superblock code nothing at all. + let mut sb128_none = false; for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { if row_start { neighbours.start_row(); } + if sb_start { + sb128_none = false; + } + if sb128_none { + continue; + } { // lane-sb128 r1: the 128 root. Its loop-restoration units are read // once for the whole 128x128 (spec 5.11.57 is called with the @@ -13034,7 +13196,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT // recurses into the four 64x64 quadrants this decoder codes. if sb128 && sb_start { - read_sb128_root( + let part128 = read_sb128_root( &mut dec, &mut cdfs, &neighbours, @@ -13046,6 +13208,62 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( mi_cols, mi_rows, )?; + if part128 == PARTITION_NONE { + // One 128x128 intra block: four TX_64X64 luma units and a + // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` + // of a 128x128 block is TX_64X64 over its 64x64 uv plane + // block). No CfL, no filter intra, no palette at this size -- + // [`read_intra_mode`]'s own size gates already say so. + sb128_none = true; + CDEF_TRANSMITTED.with(|c| c.set(false)); + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at128, + SB * 2, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + (&scan32, &scan32), + false, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + )?; + // libaom writes one `cdef_strength` into the block's own + // `MB_MODE_INFO`, which every mi cell of the block -- + // hence all four 64x64 CDEF units -- points at; our grid + // is per-unit, so the read (which only ever lands in the + // top-left unit, `read_cdef`'s index 0) is copied across. + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + CDEF_IDX_GRID.with(|g| { + let mut g = g.borrow_mut(); + let cols = CDEF_SB_COLS.with(|c| c.get()); + if cols > 0 && q_r * cols + q_c < g.len() { + let idx = g[q_r * cols + q_c]; + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { + let i = (q_r + dr) * cols + q_c + dc; + if q_c + dc < cols && i < g.len() { + g[i] = idx; + } + } + } + }); + continue; + } } if !sb128 { crate::restoration::read_lr( @@ -20656,7 +20874,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } { if sb128 && sb_start { - read_sb128_root( + if read_sb128_root( &mut dec, &mut cdfs, &neighbours, @@ -20667,7 +20885,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( sb_c, mi_cols, mi_rows, - )?; + )? != PARTITION_SPLIT + { + // lane-sb128b r1 decodes a `PARTITION_NONE` 128 root on + // KEY frames only; an inter 128x128 leaf needs whole-block + // MC, OBMC and compound at a size this path has never run. + return Err(unsupported( + "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", + )); + } } if !sb128 { crate::restoration::read_lr( diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 9581323a..4ab1f2c6 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -42,7 +42,8 @@ const REFUSALS: &[&str] = &[ "a tx_type symbol outside its CDF's own set: {t}", "an INTER 32x32 partition type this decoder does not code (value={part32})", "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", - "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)", + "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", + "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index df1c1676..bdd1513d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -18175,6 +18175,162 @@ mod tests { ); } + /// lane-sb128b r1 gate: a real `aomenc --sb-size=128` KEY frame whose 128 + /// roots resolve to `PARTITION_NONE` -- one whole 128x128 intra block, + /// four TX_64X64 luma transform units and FOUR TX_32X32 chroma units per + /// plane (`av1_get_max_uv_txsize(BLOCK_128X128)` is + /// `av1_get_adjusted_tx_size` of its 64x64 uv plane block's TX_64X64, so + /// TX_32X32) -- lane-sb128b r2's `chroma_split_tx_hits` asserts them. The r1 gate above pins `--max-partition-size=64`, which + /// makes every 128 root a forced SPLIT and leaves this arm unexercised. + /// Smooth gradients at a high `--cq-level` are what make the RD search + /// keep a whole 128x128 block; `part128_none_hits` HARD-asserts it did. + #[test] + fn a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_key_frame_with_a_128x128_none_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 render = |seed: u32, width: usize, height: usize, ten_bit: bool| -> Vec { + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let out = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", + &gradients_source(seed, width, height, "duration=0.04:rate=25"), + "-pix_fmt", pix, "-strict", "-1", "-t", "0.04", + "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + out.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + out.stdout + }; + let mut matched = 0u32; + let mut named_refusals = 0u32; + let mut none_arms = 0u32; + // (seed, cq, width, height, 10-bit). 384x384 is a 3x3 grid of whole + // 128 superblocks; 256x256 a 2x2. + let arms: Vec<(u32, &str, usize, usize, bool)> = vec![ + (42, "--cq-level=63", 384, 384, false), + (43, "--cq-level=55", 384, 384, false), + (44, "--cq-level=63", 256, 256, false), + (45, "--cq-level=63", 384, 384, true), + ]; + for (seed, cq, width, height, ten_bit) in arms { + let y4m = render(seed, width, height, ten_bit); + let mut args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", cq, + "--cpu-used=0", "--threads=1", "--row-mt=0", + "--sb-size=128", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=16", + "--enable-restoration=1", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-intrabc=0", + "--enable-tx-size-search=0", + "--limit=1", + ]; + if ten_bit { + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); + } + args.extend_from_slice(&["--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) + .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::part128_none_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}): {msg}" + ); + named_refusals += 1; + eprintln!("seed {seed} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let want = if ten_bit { + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) + } else { + ffmpeg_decode_sequence(&stream, width, height, 1) + }; + assert_eq!(frames.len(), 1); + for (i, (got, want)) in frames.iter().zip(&want).enumerate() { + for (name, a, b, w) in [ + ("Y", &got.y, &want.y, width), + ("U", &got.u, &want.u, width / 2), + ("V", &got.v, &want.v, width / 2), + ] { + let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count(); + let first = a.iter().zip(b.iter()).position(|(x, y)| x != y); + assert_eq!( + n, 0, + "{NAME} frame {i} {name} vs ffmpeg (seed {seed}): {n} differ, first row {} col {} ours {:?} ffmpeg {:?}", + first.unwrap_or(0) / w, + first.unwrap_or(0) % w, + first.map(|k| a[k]), + first.map(|k| b[k]), + ); + } + } + let hits = crate::decode::part128_none_hits() - before; + eprintln!("seed {seed} cq {cq} {width}x{height}: part128_none_hits +{hits}"); + if hits > 0 { + none_arms += 1; + } + matched += 1; + } + assert!( + matched > 0, + "{NAME}: every attempt refused; the gate never decoded a stream" + ); + assert!( + none_arms > 0, + "{NAME}: {matched} stream(s) decoded pixel-exact but NOT ONE 128 root was \ + PARTITION_NONE -- the arm this gate exists for never fired" + ); + eprintln!( + "{NAME}: {matched} pixel-exact ({none_arms} with a 128 NONE root), \ + {named_refusals} named refusals, part128_none_hits={}", + crate::decode::part128_none_hits() + ); + } + #[test] #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] fn sb128_r2_control_sb64() { diff --git a/lanes/sb128b-r1.report.md b/lanes/sb128b-r1.report.md new file mode 100644 index 00000000..95d7da0a --- /dev/null +++ b/lanes/sb128b-r1.report.md @@ -0,0 +1,103 @@ +# lane-sb128b r1 — the 128 root's `PARTITION_NONE` arm (key frames) + +Branch `lane-sb128b` off `lane-sb128` 807c110, worktree `edith_codecs-sb128b`, commit `ceec9fa`. + +## ReelC first — the charter's premise is FALSE on ReelC's key frame + +EVIDENCE: `$HOME/.cache/sb128b-work/reelc2s.obu` (fresh cut, `ffmpeg -t 2 -c:v copy -f obu` +off the real film, 1428 bytes) | release `decode_probe` under a 6G scope with `EC_AV1_TRACE=1` +| **90 `partition_w128` symbols, value=3 (`PARTITION_SPLIT`) on every one** (ctx 3 x70, ctx 2 +x14, ctx 1 x5, ctx 0 x1); the run then stops at `an inter frame under a 128x128 superblock`. +Same numbers on the pre-existing `reelc-head.obu`. + +So ReelC's KEY frame is 100% SPLIT at the 128 root — the key-frame 128 arms are **not** its +blocker, and TASK 4's "the inter arms" is where ReelC's non-SPLIT roots live (r2 saw them only +with the inter refusal locally lifted). Charter premise "ReelC's key frame is the first thing to +decode / stops at a TASK-B arm" corrected here, measured, not argued. + +## What landed (all against libaom, each cited) + +`crates/ec-av1/src/decode.rs` +- `read_sb128_root` (11286) returns the root partition; the key-frame loop (11536) decodes + `PARTITION_NONE` as one 128x128 block and skips the superblock's other three visits + (`sb128_none`). The inter loop refuses any non-SPLIT root by name. +- `read_tx_size` (10003): `max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64 → a 128 block + reads BLOCK_64X64's own `tx_size_cat3` and resolves `max_tx >> depth`, and + `get_tx_size_context` is asked about 64, not 128. +- `decode_block`: the single-TU arm was `!tx_select || logical_tx == side`. Without `tx_select` + `logical_tx` IS `side` at every size <= 64, so the first half was redundant — and wrong at + 128. Now `logical_tx == side`, and the non-select resolve is `(side.min(64), luma_tx)`, so a + 128 block is always four TX_64X64 units. The TU loop passes the unit's **coefficient** side + (32 at TX_64X64), not its transform side. +- `delta_q`/`delta_lf` "this leaf IS the superblock" is now `side == sb_size` (was a hardcoded + 64 plus a `!sb128()` disable) — a NONE 128 root is the whole superblock. +- the 128 block's one `cdef_idx` read is copied to all four 64x64 CDEF units (libaom's four + units share one `MB_MODE_INFO`). + +`crates/ec-av1/src/stream.rs`: new gate (below). `refusal_inventory.rs`: the single +"partition other than SPLIT" string splits into three named arms. + +## Gate + +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` — real aomenc +`--sb-size=128` with **no** `--max-partition-size` (the r1 gate's flag is exactly what made +every 128 root a forced SPLIT), smooth gradients at `--cq-level=63/55`, 384x384 + 256x256, +8- and 10-bit, `--enable-tx-size-search=0`. `#[ignore]`d: it is a reproducer, not a pass. + +EVIDENCE: `cargo test -p ec-av1 --lib -- --nocapture a_real_aomenc_key_frame_with_a_128x128_none` +| aomenc 384x384 cq63 seed 42, decoded then compared to ffmpeg | the NONE arm **fires** and the +tile decodes end to end (no desync panic, no refusal), but frame 0 luma differs from ffmpeg at +138523 of 147456 samples, first at row 0 col 60, magnitudes 1..3 (ours 114/113 where ffmpeg has +115) — a reconstruction difference, not an entropy blow-up. + +Two earlier failures on the way, both fixed and both real defects of the generalisation: +`transform.rs:843 index out of bounds (len 64, index 64)` = the redundant `!tx_select` arm +above sending a 128-wide inverse transform; then the pixel deltas. + +## Root cause of the residual (found, not guessed) + +`av1_get_max_uv_txsize` = `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`. +The uv plane block of a 128x128 is 64x64 → TX_64X64 → **adjusted to TX_32X32**. A 128 block's +chroma is therefore FOUR TX_32X32 units per plane, and `decode_block` codes exactly one +whole-plane chroma unit. That is the desync, and it also means the charter's +"one chroma TU of 64x64 per plane / new chroma TX_64X64 path" is wrong: **no `TxbSet::Chroma64` +is needed at all.** I had transcribed the 16 libaom `[TX_64X64][PLANE_TYPE_UV]` CDF tables and +wired the variant before finding this; that work is reverted (`cdf.rs`/`cdf_state.rs` are +untouched in this commit) rather than shipped as dead code. + +## Refusals + +- `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 + root)` — NOT lifted, TASKs 2/3, not started. +- `a 128x128 superblock PARTITION_NONE root on an inter frame (...)` — NOT lifted, TASK 4. +- `a 128x128 PARTITION_NONE block's chroma (its 64x64 uv plane block is four TX_32X32 units, + and this decoder codes one whole-plane chroma unit per block)` — NEW, guards the arm this + round built. fix-now(r2): give `decode_block` a chroma TU loop (2x2 TX_32X32, `TxbSet::Chroma32`, + per-unit `chroma_skip_ctx`, grids assembled for `record_split_luma`) — unblocked by that loop; + the gate above is the reproducer and flips green the moment it is right. +- `intrabc under a 128x128 superblock` — accepted, unchanged. + +## Suite + +`cargo test -p ec-av1 --lib` under user unit `sb128b-suite-1788322151.service`, +log `$HOME/.cache/sb128b-suite.log` — result appended below by the handoff line in the report +message. The 7 rect/AB reds inherited from 807c110 (r2's `deferred: attribute the 7`) are the +sibling lane's; this round touched no rect/AB path. + +## Deferred + +- deferred: TASK 2/3 (HORZ/VERT + AB at 128) — not started — unblocked by the chroma TU loop + plus rect handling at 128. +- deferred: TASK 4 (inter 128 NONE) — refused by name — unblocked by the same loop and the + sibling lane's inter residue. +- deferred: `tx_select` at 128 (`read_tx_size` now handles it, cat3 against 64) is UNTESTED — + every gate arm here runs `--enable-tx-size-search=0` — unblocked by an r2 arm with it on. + +## Suite state at hand-off (honest, incomplete) + +`sb128b-suite-1788322151.service` was STILL RUNNING when this round hit its tool-call ceiling. +At that point the log showed **2 failures, both inherited from 807c110's rect/AB cluster**: +`a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact`, +`a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact`. +No total ("test result:" line) yet — read `$HOME/.cache/sb128b-suite.log` for the final count +before merging. NOT a clean-suite claim. diff --git a/lanes/sb128b-r2.report.md b/lanes/sb128b-r2.report.md new file mode 100644 index 00000000..7d425798 --- /dev/null +++ b/lanes/sb128b-r2.report.md @@ -0,0 +1,97 @@ +# lane-sb128b r2 — ReelC's key frame is BIT-EXACT; the 128 chroma TU loop; the 128 root's residual + +Branch `lane-sb128b`, worktree `edith_codecs-sb128b`, commits `4e13f60`, `1524838`, `c415a31` +(off r1's `d3bc8da` + `git merge main` b51719f, clean). + +## FIRST: the ReelC KEY-frame pixel check (the charter's first task — first ReelC pixel measurement ever) + +EVIDENCE: `$HOME/.cache/sb128b-work/{reelckf0.obu,ours.f0.yuv,ref.yuv}` | +`ffmpeg -ss 0 -t 2 -c:v copy -frames:v 1 -f obu` off the real film (74 B, 1920x792 yuv420p10le) +→ `dump_yuv` (release, 6G scope) vs `ffmpeg -pix_fmt yuv420p10le -f rawvideo` | +**`cmp` says BYTES EQUAL — ReelC's key frame decodes BIT-EXACT (4 561 920 bytes, 0 differing samples).** + +It was NOT exact before the merge. Pre-merge measurement (same artifacts, r1's tree): +Y 36448 samples off (max |d| 2), U/V 9483 each (max |d| 4), all inside the bottom partial +superblock row — luma rows 765..791 (768 = 6*128, frame is 792 tall) plus 3 deblock rows above, +`+1` per 16-row band, ref uniformly flat (this key frame is black). `git merge main` (lane-oddh's +odd-frame-size work) removes it entirely. Class: [[stale-premise lanes]] — the lane's base +predates the fix. + +ReelC now stops at `an inter frame under a 128x128 superblock` (probe on the 2 s cut, 72 frame +headers parsed) — the sibling lane-sb128 r3's residue, exactly as r1 predicted. + +## Merge seam (had to be fixed before anything could run) + +main b51719f re-introduced lane-oddh's blanket refusal `a sequence using 128x128 superblocks on a +frame larger than 64x64` (stream.rs) — textually a clean merge, semantically a lane-killer (the +ledger's recorded `merge seam` constraint). Deleted, with its inventory line, and its gate +`a_real_aomenc_128x128_superblock_stream_is_refused_by_name` turned into +`..._decodes_pixel_exact`. + +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_128x128_superblock_stream gate_coverage` | +real aomenc 64x72 mandelbrot `--cpu-used=0 --sb-size=128` (`use_128x128_superblock` asserted in +the stream), decoded vs ffmpeg | **ok — 10 passed, 0 failed**; the frame's Y/U/V match ffmpeg +sample for sample. One recipe change was needed and is unrelated to the 128 root: at 64x72 +aomenc also picks `PARTITION_HORZ_4` below 16x16, so the gate now passes +`--enable-1to4-partitions=0 --min-partition-size=16` (gate_coverage green with it). + +## TASK A — the chroma half of a 128x128 `PARTITION_NONE` block (landed, not yet exact) + +`crates/ec-av1/src/decode.rs` +- `decode_block`'s multi-TU arm now codes `cn = chroma_side / chroma_tx` **squared** chroma units + per plane instead of one whole-plane unit. `av1_get_max_uv_txsize(BLOCK_128X128)` = + `av1_get_adjusted_tx_size(max_txsize_rect_lookup[BLOCK_64X64])` = TX_32X32, so a 128 block is + 2x2 TX_32X32 per plane; `cn == 1` (every block at 64 and below) is byte-for-byte the read this + always did. Per unit: `around_mi` gathered over the unit's own 64-luma-pixel span (which is + also its `txb_skip_ctx`, `read_plane`'s chroma branch), `tu_reach` on the matching luma + quadrant, own `set_palette_pred`. +- `Neighbours::record_mi_chroma` (new, next to `record_mi_luma`): per-unit chroma coefficient + context, luma-mi indexed with `record_split_luma_rect_mi`'s own frame-edge clamp. Applied + AFTER `record_split_luma` so the per-unit state is what the next block reads. +- The `skip` arm predicts per transform unit now (libaom predicts inside the transform-block + loop); `n_axis == 1` / `cn == 1` is the unchanged whole-block call. +- counter `chroma_split_tx_hits()`. + +**Result: not pixel-exact, so the refusal is BACK, reworded to what was measured.** +EVIDENCE: `$HOME/.cache/sb128b-work/g42.obu` (the gate's own arm reproduced by hand: gradients +seed 42, 384x384, cq63, `--sb-size=128 --cpu-used=0 --enable-tx-size-search=0`) | `dump_yuv` vs +`ffmpeg -pix_fmt yuv420p` | 139162/147456 luma samples differ, first at row 0 col 60 (ours 114, +ffmpeg 115). **ffmpeg's row 0 is a CONSTANT 115 across the whole first unit where ours ramps +115 → 112**, and the stream is 76 bytes: the mode and the DC agree, our first TX_64X64 luma unit +reads AC coefficients libaom never wrote. So the divergence is inside that unit's coefficient +read, not in chroma and not in prediction. + +Refusal now reads: `a 128x128 PARTITION_NONE block (four TX_64X64 luma and four TX_32X32 chroma +units all decode, but the first unit's coefficients already carry AC where libaom has DC only -- +lane-sb128b r2's open entropy residual)`. Gate +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` stays `#[ignore]`d as +the reproducer, with its plane asserts rewritten to LOCATE the divergence (count + first +row/col/values) instead of printing 147 456 samples. + +Also corrected in that gate's doc: r1 wrote "ONE TX_64X64 chroma unit per plane / `TxbSet::Chroma64`"; +the truth is four TX_32X32 and no `Chroma64` set exists or is needed. + +## Not done + +- deferred: TASK A's `tx_select` at 128 arm (`--enable-tx-size-search=1`) — not added — unblocked + by the NONE arm being exact at all (an inexact arm cannot gate a tx-depth counter). +- deferred: TASK B (HORZ/VERT + AB at 128) — not started, refused by name + (`a 128x128 superblock HORZ/VERT or AB partition`) — unblocked by the same residual. +- deferred: TASK C (inter 128) — not started, refused by name on both this tree and the sibling's + (`an inter frame under a 128x128 superblock`) — unblocked by lane-sb128 r3 lifting its inter + root refusal; nothing of TASK C was written, so nothing is "ready behind" it. +- `git merge lane-sb128` NOT done: the sibling's tip is `dbf15a4` (gate-recipe fix only, no + inter-128 lift yet), so there was nothing to take. + +## Suite + +r2's first run (`$HOME/.cache/sb128b-suite-r2.log`, unit `sb128b-suite-r2-1788322817.service`) was +armed at the intermediate commit `1524838` and is superseded. Its FAILED list: the 2 rect/AB reds +inherited from 807c110 (`a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact`, +`a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact`) — **still red after +`git merge main` b51719f, so main did NOT fix them** — plus the two 128 gates that this round's +final commit resolves (`..._128x128_superblock_stream...` now green, +`..._128x128_none_partition...` now `#[ignore]`d). +The authoritative run for `c415a31` is unit `sb128b-suite-r2b-1788323051.service` → +`$HOME/.cache/sb128b-suite-r2b.log`; it was still running at this round's tool-call ceiling. +NOT a clean-suite claim: read that log for the totals before merging. diff --git a/lanes/sb128b-r3.report.md b/lanes/sb128b-r3.report.md new file mode 100644 index 00000000..47828ed8 --- /dev/null +++ b/lanes/sb128b-r3.report.md @@ -0,0 +1,101 @@ +# lane-sb128b r3 — the 128x128 PARTITION_NONE block decodes PIXEL-EXACT (3 root causes), the 10-bit reds were a recipe defect + +Branch `lane-sb128b`, worktree `edith_codecs-sb128b`, commits `dd6f934` (merge main 7a47fc1 + TASK B), +`f2b6f1c` (TASK A), `7ceb309` (merge main 18bf7dc / lane-sb128 5ea5ec8). + +## TASK A — the 128 NONE residual: THREE root causes, none of them where r2 pointed + +r2 read "our first TX_64X64 luma unit reads AC coefficients libaom never wrote". Measured with a +range ladder (instrumented `aomdec` `EC_TRACE_COEFF` vs our `EC_TRACE_COEFF`) that premise is +WRONG: the first luma unit is identical symbol for symbol and range for range +(`all_zero ctx=1 rng=59208 / eob=3 rng=41268 / base_eob level=5 rng=44688 / ... / rng=36616`). +The divergence is at the SECOND element of the block, and it is three separate defects: + +1. **Plane order.** libaom's `decode_token_recon_block` loops 64x64 luma "mu" chunks + (`mu_blocks_wide/high = mi_size_wide[BLOCK_64X64]`) and codes EVERY PLANE of a chunk before the + next chunk. The oracle ladder is Y(0,0) U(0,0) V(0,0) Y(0,16) U(0,8) V(0,8) ... — Y,U,V per + quadrant. We read all four luma units and then all chroma units. Below 128 a block is one chunk, + so the fix (`nchunk = side/64`, luma TUs then chroma units per chunk) is byte-for-byte the old + order at every size the decoder already handled. +2. **The chroma `txb_skip_ctx` offset.** `get_txb_ctx`: chroma ctx is + `combine_entropy_contexts(above,left)` **+7** normally, **+10** when the plane block is LARGER + than the transform. A 128 block's 64x64 uv plane block with TX_32X32 units is AV1's only such + case, and our chroma table only ever carried the offset-7 rows (`txb_skip_chroma_*: [[u16;3];3]`). + Oracle read ctx=10, we read ctx=0. Added `TXB_SKIP_CHROMA_32_BIG{,_Q0,_Q1,_Q3}` from + `av1_default_txb_skip_cdfs[q][TX_32X32][10..13]` (token_cdfs.h, all four q contexts, verified by + re-deriving the existing offset-7 rows from the same array), `txb_skip_chroma_32` is six rows, + caller adds 3 when `cn > 1`. +3. **Deferred chroma context writes.** r2 recorded each chroma unit's coefficient context only + after the whole block, so the second quadrant read ctx 10 where the oracle reads 11 (base 1 from + its left neighbour inside the same block). Now recorded per unit inside the loop; the + post-`record_split_luma` replay stays, because that call would otherwise clobber them whole-block. + +Files: `crates/ec-av1/src/decode.rs` (mu-chunk loop + `chroma_ctx_offset` + per-unit record + +`read_plane`'s chroma `skip_ctx`), `crates/ec-av1/src/cdf.rs` (4 tables), +`crates/ec-av1/src/cdf_state.rs` (`txb_skip_chroma_32` 3 -> 6 rows). + +EVIDENCE: `$HOME/.cache/sb128b-work/{s44.obu,ref44.yuv,ours44.yuv.f0.yuv,ref.ladder}` | +aomenc gate-arm-3 recipe (seed 44 gradients 256x256 cq63 `--sb-size=128 --cpu-used=0 +--enable-tx-size-search=0 ...`), `EC_TRACE_COEFF` ladders of aomdec and `dump_yuv`, then +`dump_yuv` vs `ffmpeg -pix_fmt yuv420p` | **48 `txb_skip` symbols, ranges identical one for one; +0 of 98304 samples differ (pixel-exact)**. Before the fix: 60857 luma samples differed. + +REFUSAL LIFTED (with its gate): `a 128x128 PARTITION_NONE block (...)` deleted from `decode.rs` and +`refusal_inventory.rs`; `a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` +un-`#[ignore]`d. +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact --nocapture` | +4 real-aomenc arms (384x384 seed 42 cq63, 384x384 seed 43 cq55, 256x256 seed 44 cq63, 384x384 seed 45 +10-bit) decoded vs ffmpeg | **ok — 4/4 pixel-exact, 0 named refusals, `part128_none_hits=31`** +(9+9+4+9 128-NONE roots). Sibling gates `a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact`, +`refusal_inventory`, `gate_coverage` re-run green in the same invocation (14 passed / 0 failed). + +## TASK B — the 2 inherited 10-bit reds were an ENCODER RECIPE defect + +`git show main:crates/ec-av1/src/stream.rs` vs the lane's: r2 rewrote `--min-partition-size=16` to +`32` at **13** call sites that main has at 16, including both failing gates. 32 removes the 16-level +the rect/AB gates assert. Reverted all 13 (the lane's own two 128 gates keep their deliberate 32). +EVIDENCE: `cargo test -p ec-av1 --lib -- a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact refusal_inventory gate_coverage` | +recipe reverted, rebuilt, re-run | **ok — 14 passed, 0 failed**. Class: +[[gate-recipe-confound]] / the ledger's "a gate that decodes pixel-exact with counter 0 is an +encoder-recipe defect". Swept: those 13 are every 16->32 rewrite in the lane. + +## TASK C — merges + +`git merge main` twice: 7a47fc1 (one conflict, `decode.rs`'s skipped-block arm: took main's +lane-hgkf per-TU prediction + `true_width` guard + `SKIP_SPLIT_TX_HITS`, broadened its condition +from `tx_select && logical_tx < side` to `logical_tx < side` because a 128 block's transform is +TX_64X64 with no tx-depth syntax; the counter keeps its narrow `tx_select` meaning), then 18bf7dc +(= lane-sb128 5ea5ec8; three conflicts in `stream.rs`, ALL resolved to main's side per the batch +coordinator, so main's single seam gate `a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact` +survives and lane-oddh's seam refusal stays deleted). `cdf.rs` merged clean; its NZ_MAP and +FILTER_INTRA regions are byte-identical to main's (`git diff main -- crates/ec-av1/src/cdf.rs` shows +only the four new `TXB_SKIP_CHROMA_32_BIG*` tables). + +## Suite + +EVIDENCE: `$HOME/.cache/sb128b-suite-r3.log` (unit `sb128b-suite-r3-1788323779.service`, tip +`7ceb309`) | `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` | +**test result: ok. 371 passed; 0 failed; 32 ignored; 473.61s** — GREEN. + +## ReelC key frame + +EVIDENCE: `$HOME/.cache/sb128b-work/{reelckf0.obu,reelcours.yuv.f0.yuv,ref.yuv}` | r2's recipe +(`ffmpeg -t 2 -c:v copy -f obu` off the film, 1920x792 yuv420p10le), `dump_yuv` under a 6G scope vs +ffmpeg's rawvideo | **`cmp` says BYTES EQUAL — 4 561 920 bytes, 0 differing samples.** + +Film probe on the 2 s cut (`decode_probe reelc2s.obu`) still stops at +`an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64 +superblock root only)` — main 18bf7dc (lane-sb128 5ea5ec8) did NOT lift this one on this tree. + +## Open residue + +- deferred: `a 128x128 superblock HORZ/VERT or AB partition` — not started; every 128 root in the + four gate arms resolves NONE or SPLIT, so nothing here is measured. Unblocked by an aomenc recipe + that actually emits a 128-level HORZ/VERT (r2's seed-42 "HORZ/VERT at 128" sighting was our own + desync talking — class [[refusal-from-own-desync]]: with the entropy fixed, that same stream + reads nine NONE roots). +- deferred: `a 128x128 superblock PARTITION_NONE root on an inter frame` and + `an inter frame under a 128x128 superblock` (the ReelC blocker) — inter path untouched this round; + unblocked by the inter tile path recursing a 128 root. +- deferred: the `--enable-tx-size-search=1` arm at 128 (a read tx_depth under a 128 NONE root) — + the four arms all pin `=0`; unblocked now that the NONE arm is exact, so it is a one-arm follow-up.