From 787e43e6eebd1172d7217c939de45a7b5c105656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 20 Sep 2026 00:17:51 +0300 Subject: [PATCH] ec-av1: sub-8x8 intrabc reconstruction (WIP) + trace alignment; report The charter's one-routing-predicate hypothesis is REFUTED: the three real-stream stops have three distinct causes (see lanes/av1txrouting.report.md). - Stops 3.3/3.4 ('a sub-8x8 leaf that uses intrabc') are GENUINE sub-8x8 intrabc blocks (instrumented aomdec reads intrabc val=1 and an EC_DV at the same mi positions). Implemented: read_intra_mode_sub8 reads the DV and returns early; read_intrabc_dv generalized to a (n4_w,n4_h) footprint; decode_leaf_split4 / decode_leaf_rect8 reconstruct the leaf via a mc::predict_with_filter frame copy injected through the set_palette_pred override, with the inter coefficient sets and no tx_depth symbol; chroma inherits the LUMA's coded tx_type (av1_get_tx_type treats intrabc as inter) via fctx.intrabc_chroma_tx. record_intrabc_mi_rect publishes a rect footprint. The 4x4 split path is proven symbol-identical to aomdec (luma residual full rng match at allintra (45,52)). The 4x8/8x4 RECT path is NOT yet byte-exact (warped differs at luma row 128, desync at (38,60)) -- WIP. - Stop 3.2 ('a Golomb tail') root cause: 4:4:4 chroma subsampling is not implemented anywhere in the decoder (hardcoded /2 chroma extents); every 4:4:4 stream is silently garbage, none is byte-exact. First divergence at a444-cu6 (0,0): aom chroma TX_8X16 entry rng 39857, ours 4x8. Needs a named sequence-header refusal + a subsampling-threading lane. - Trace prints added at previously-silent tx_depth/intrabc sites so a cross-decoder first-divergence diff aligns. NOT mergeable yet: see the report's section 5 (rect intrabc, the 1:4 rect strip intrabc, the decode_leaf8 dequant panic, the 4:4:4 refusal, inventory re-pin, suite run). --- crates/ec-av1/src/decode.rs | 276 ++++++++++++++++++++++++++++++++--- lanes/av1txrouting.report.md | 181 +++++++++++++++++++++++ 2 files changed, 436 insertions(+), 21 deletions(-) create mode 100644 lanes/av1txrouting.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 8ba409de..7a45110f 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3681,6 +3681,20 @@ pub(crate) fn reset_intrabc_vartx_hits() { /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an /// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`). fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>, fctx: &crate::decode::FrameCtx) { + record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, fctx); +} + +/// [`record_intrabc_mi`] with a true rectangular footprint: `av1_find_mv_refs` +/// takes the block's real `bsize`, so a sub-8x8 `BLOCK_4X8`/`BLOCK_8X4` +/// intrabc leaf must publish a 1x2/2x1 mi span, not a square (lane-av1txr). +fn record_intrabc_mi_rect( + mi_r: usize, + mi_c: usize, + n4_w: usize, + n4_h: usize, + dv: Option<(i32, i32)>, + fctx: &crate::decode::FrameCtx, +) { fctx.intrabc_mi_grid.with(|g| { let mut g = g.borrow_mut(); let Some((grid, _, _)) = g.as_mut() else { @@ -3695,11 +3709,11 @@ fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)> is_new_mv: dv.is_some(), is_global_mv0: false, is_global_mv1: false, - size: n4 as u8, - size_h: n4 as u8, + size: n4_w as u8, + size_h: n4_h as u8, }; - for r in mi_r..mi_r + n4 { - for c in mi_c..mi_c + n4 { + for r in mi_r..mi_r + n4_h { + for c in mi_c..mi_c + n4_w { grid.set(r, c, info); } } @@ -11317,7 +11331,11 @@ fn decode_leaf_rect( // the range diverges silently at the first such leaf and every later // symbol in the tile is read from the wrong place (class // `wrong-alphabet-same-value`, here same alphabet / wrong row). - dec.symbol(&mut cdfs.tx_size_cat1[ctx]) + let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]); + if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { + eprintln!("EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}", leaf_mi.0, leaf_mi.1, dec.debug_state().0); + } + d } else { 0 }; @@ -13232,11 +13250,14 @@ fn read_intra_mode( // that merely allows (but never uses) intrabc. if allow_intrabc { let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; + if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { + eprintln!("EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}", u8::from(use_intrabc), dec.debug_state().0); + } if trace { eprintln!("TRACE use_intrabc value={}", use_intrabc as i32); } if use_intrabc { - let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, side, fctx); + let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (side / MI, side / MI), fctx); if trace { eprintln!("TRACE intrabc dv={dv:?}"); } @@ -15915,7 +15936,7 @@ fn read_intra_mode_sub8( // neighbour's `cdf_index`/prediction two blocks later. seg_w_mi: usize, seg_h_mi: usize, fctx: &crate::decode::FrameCtx, -) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option)> { +) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option, Option<(i32, i32)>)> { let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if ec_istep { @@ -15954,10 +15975,20 @@ fn read_intra_mode_sub8( istep!("dq", 0); if allow_intrabc { let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; + if ec_istep { + eprintln!("EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=intrabc val={} rng={}", u8::from(use_intrabc), dec.debug_state().0); + } if use_intrabc { - return Err(unsupported( - "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", - )); + // lane-av1txr: `read_intrabc_info` (spec 5.11.13) reads the block + // vector right after the flag and RETURNS -- no y/uv mode, angle + // delta, palette, CfL or filter-intra syntax follows, and the + // block is reconstructed by the INTER path (libaom's + // `is_inter_block` counts an intrabc block), so the caller takes + // the frame-copy prediction + inter residual. + let dv = read_intrabc_dv(dec, cdfs, mi_r, mi_c, (seg_w_mi, seg_h_mi), fctx); + fctx.intrabc_dv.with(|c| c.set(Some(dv))); + hit!(INTRABC_HITS); + return Ok((skip, DC_PRED, 0, None, None, Some(dv))); } } let above_ctx = INTRA_MODE_CTX[above_mode]; @@ -16007,7 +16038,7 @@ fn read_intra_mode_sub8( filter_intra = Some(fi_mode); } } - Ok((skip, mode, angle_delta_y, chroma, filter_intra)) + Ok((skip, mode, angle_delta_y, chroma, filter_intra, None)) } /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves @@ -16058,6 +16089,10 @@ fn decode_leaf_split4( let mut leaf_modes = [0usize; 4]; let mut leaf_skips = [false; 4]; let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None; + // lane-av1txr: the chroma-reference (i==3) leaf's block vector when that + // leaf is an intrabc block -- its prediction/reconstruction below is a + // frame copy at this DV, not an intra one. + let mut last_intrabc: Option<(i32, i32)> = None; for i in 0..4usize { let (dr, dc) = (i / 2, i % 2); let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc); @@ -16077,7 +16112,7 @@ fn decode_leaf_split4( }; let has_chroma = i == 3; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); - let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( + let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, filter_intra_size_class(4).expect("BLOCK_4X4 has its own filter_intra row"), skip_ctx, allow_intrabc, lmi.0, lmi.1, 1, 1, fctx, @@ -16091,6 +16126,67 @@ fn decode_leaf_split4( } let (px, py) = (lmi.1 * MI, lmi.0 * MI); let reach = Reach::of(4, px, py, y.width, y.height, fctx); + if let Some(dv) = intrabc { + // lane-av1txr: an intrabc `BLOCK_4X4` leaf -- prediction is the + // CURRENT frame at the block vector (`predict_inter_block`'s + // intrabc arm, spec 7.11.3.4), residual the INTER coefficient set + // (libaom reads `tx_type` off `inter_ext_tx_cdf` for + // `is_inter_block`, which counts intrabc). Published into + // `intrabc_dv` so the group's chroma arm (below, when the + // chroma-reference leaf is the intrabc one) and + // [`record_intrabc_mi`] see it. + flush_recon(fctx, y, u, v); + let mut yb = vec![0u16; 16]; + mc::predict_with_filter( + &y.data, y.width, y.true_width, y.true_height, + mv_to_q4(px, dv.1, true), mv_to_q4(py, dv.0, true), + 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx, + ); + set_palette_pred(yb.clone(), fctx); + if skip { + push_intra(0, px, py, 4, DC_PRED, 0, reach, &ZERO_RESIDUAL[..16], None, None, smooth_neighbor, fctx); + neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); + } else { + let tu_around = neighbours.around_mi(lmi, 4)[0]; + let tu_grid = read_plane( + dec, + cdfs, + if reduced_tx_set { TxbSet::Luma4Inter } else { TxbSet::Luma4InterSet1 }, + scan4, + 0, + tu_around, + DC_PRED, + DC_PRED, + 0, + reach, + y, + px, + py, + 4, + 4, + base_q_idx, + None, + None, + None, + smooth_neighbor, fctx, + )?; + neighbours.record_mi_luma(lmi, 4, &tu_grid); + } + neighbours.fill_skip_grid(lmi, 1, skip); + neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx); + record_intrabc_mi(lmi.0, lmi.1, 1, Some(dv), fctx); + if has_chroma { + last_uv = Some((DC_PRED, 0, None)); + // An intrabc block is an INTER block for `av1_get_tx_type`, so + // the group's chroma inherits the LUMA's coded transform type + // (`xd->tx_type_map` at the co-located luma position) -- the + // luma `read_plane` above just set [`LUMA_TX_TYPE`]. Armed for + // exactly this group's two chroma reads. + fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); + } + last_intrabc = Some(dv); + continue; + } if skip { push_intra(0, px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra, smooth_neighbor, fctx); neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); @@ -16157,6 +16253,38 @@ fn decode_leaf_split4( push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); (Grid::Zero(16), Grid::Zero(16)) + } else if let Some(dv) = last_intrabc { + // lane-av1txr: the chroma-reference leaf was an intrabc block, so the + // group's one chroma unit is a frame copy at that DV too (its residual + // still reads the ordinary `Chroma4` coefficient tables -- libaom + // codes a chroma `tx_type` nowhere). + let mut ub = vec![0u16; 16]; + mc::predict_with_filter( + &u.data, u.width, u.true_width, u.true_height, + mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), + 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + ); + let mut vb = vec![0u16; 16]; + mc::predict_with_filter( + &v.data, v.width, v.true_width, v.true_height, + mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), + 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + ); + let chroma_around = neighbours.around_mi(leaf_mi, 8); + set_palette_pred(ub, fctx); + let ug = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, + 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + set_palette_pred(vb, fctx); + let vg = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, + 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (ug, vg) } else { let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); let chroma_around = neighbours.around_mi(leaf_mi, 8); @@ -16282,6 +16410,8 @@ fn decode_leaf_rect8( let mut leaf_modes = [0usize; 2]; let mut leaf_skips = [false; 2]; let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None; + // lane-av1txr: as [`decode_leaf_split4`]'s own `last_intrabc`. + let mut last_intrabc: Option<(i32, i32)> = None; for i in 0..2usize { let lmi = if vert { (leaf_mi.0, leaf_mi.1 + i) @@ -16302,12 +16432,81 @@ fn decode_leaf_rect8( }; let has_chroma = i == 1; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); - let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( + let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, filter_intra_size_class_rect(bw, bh) .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize"), skip_ctx, allow_intrabc, lmi.0, lmi.1, bw / 4, bh / 4, fctx, )?; + leaf_modes[i] = mode; + leaf_skips[i] = skip; + neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode); + let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); + if let Some(dv) = intrabc { + // lane-av1txr: an intrabc `BLOCK_4X8`/`BLOCK_8X4` leaf. No + // `tx_depth` symbol is coded (libaom `block_signals_txsize` is + // false below 8x8), the prediction is a frame copy at the DV and + // the residual reads the INTER `LumaRect8x4` set. + let (px, py) = (lmi.1 * MI, lmi.0 * MI); + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx); + flush_recon(fctx, y, u, v); + let mut yb = vec![0u16; bw * bh]; + mc::predict_with_filter( + &y.data, y.width, y.true_width, y.true_height, + mv_to_q4(px, dv.1, true), mv_to_q4(py, dv.0, true), + bw, bh, mc::InterpFilterKind::Bilinear, &mut yb, fctx, + ); + set_palette_pred(yb, fctx); + let mut luma_tx = TxType::DctDct; + let grid = if skip { + let zeros = Grid::Zero(bw * bh); + push_intra_rect(0, px, py, bw, bh, DC_PRED, 0, reach, &zeros, None, None, smooth_neighbor, fctx); + zeros + } else { + let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; + let set = if reduced_tx_set { + TxbSet::LumaRect8x4Inter + } else { + TxbSet::LumaRect8x4InterSet1 + }; + let mut coding = cdfs.txb(set, DC_PRED); + let (levels, tx_type) = read_coeffs_rect( + dec, &mut coding, scan, bw, bh, 0, dc_sign_ctx(around.2), TxType::DctDct, + )?; + luma_tx = tx_type; + let residual = dequant_and_inverse_typed_wh( + &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx), + plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tx_type, + ); + push_intra_rect(0, px, py, bw, bh, DC_PRED, 0, reach, &residual, None, None, smooth_neighbor, fctx); + levels + }; + fctx.luma_tx_type.with(|c| c.set(luma_tx)); + let state = neighbour_state(&grid); + for cell in 0..h_mi { + if lmi.0 + cell < neighbours.mi_rows { + neighbours.left[lmi.0 + cell][0] = state; + } + } + for cell in 0..w_mi { + if lmi.1 + cell < neighbours.mi_cols { + neighbours.above[lmi.1 + cell][0] = state; + } + } + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, 0, fctx); + // `record_intrabc_mi` publishes a square `n4`x`n4` footprint; a + // 4x8/8x4 leaf needs its true `w_mi`x`h_mi` (lane-av1txr). + record_intrabc_mi_rect(lmi.0, lmi.1, w_mi, h_mi, Some(dv), fctx); + if has_chroma { + last_uv = Some((DC_PRED, 0, None)); + last_intrabc = Some(dv); + // See [`decode_leaf_split4`]: an intrabc block's chroma + // inherits the luma transform type. + fctx.intrabc_chroma_tx.with(|c| c.set(Some(luma_tx))); + } + continue; + } if filter_intra.is_some() { // lane-fi8 r1: `predict_filter_intra` walks its 4x2 patches over // a true `bw`x`bh` block, so a 4x8/8x4 leaf predicts through the @@ -16343,10 +16542,6 @@ fn decode_leaf_rect8( hit!(TX_DEPTH_HITS); hit!(RECT8_SPLIT_TX_HITS); } - leaf_modes[i] = mode; - leaf_skips[i] = skip; - neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode); - let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); if smooth_neighbor { hit!(SMOOTH_LUMA_HITS); } @@ -16544,6 +16739,38 @@ fn decode_leaf_rect8( push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); (Grid::Zero(16), Grid::Zero(16)) + } else if let Some(dv) = last_intrabc { + // lane-av1txr: the chroma-reference leaf was an intrabc block, so the + // group's one chroma unit is a frame copy at that DV too (its residual + // still reads the ordinary `Chroma4` coefficient tables -- libaom + // codes a chroma `tx_type` nowhere). + let mut ub = vec![0u16; 16]; + mc::predict_with_filter( + &u.data, u.width, u.true_width, u.true_height, + mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), + 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + ); + let mut vb = vec![0u16; 16]; + mc::predict_with_filter( + &v.data, v.width, v.true_width, v.true_height, + mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), + 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + ); + let chroma_around = neighbours.around_mi(leaf_mi, 8); + set_palette_pred(ub, fctx); + let ug = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, + 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + set_palette_pred(vb, fctx); + let vg = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, + 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (ug, vg) } else { let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); let chroma_around = neighbours.around_mi(leaf_mi, 8); @@ -24587,15 +24814,17 @@ fn read_intrabc_dv( cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, - side: usize, fctx: &crate::decode::FrameCtx, + // The block's own mi footprint (`av1_find_mv_refs` takes the real bsize, + // so a sub-8x8 `BLOCK_4X8`/`BLOCK_8X4` leaf scans a 1x2/2x1 neighbourhood + // -- lane-av1txr). + (n4_w, n4_h): (usize, usize), fctx: &crate::decode::FrameCtx, ) -> (i32, i32) { const INTRABC_DELAY_PIXELS: i32 = 256; - let n4 = side / MI; let stack_pred = fctx.intrabc_mi_grid.with(|g| { let g = g.borrow(); g.as_ref().map(|(grid, mi_cols, mi_rows)| { let stack = crate::mvstack::find_mv_stack( - grid, mi_r, mi_c, n4, n4, 0, /* INTRA_FRAME */ + grid, mi_r, mi_c, n4_w, n4_h, 0, /* INTRA_FRAME */ *mi_cols, *mi_rows, ); if stack.nearest_mv == (0, 0) { @@ -24623,7 +24852,12 @@ fn read_intrabc_dv( } // "Ref DV should not have sub-pel" (`assign_dv`): floor to full pel. let pred = ((pred.0 >> 3) * 8, (pred.1 >> 3) * 8); - read_mv(dec, &mut cdfs.dv_comp, &mut cdfs.dv_joint, pred, false, true) + let dv = read_mv(dec, &mut cdfs.dv_comp, &mut cdfs.dv_joint, pred, false, true); + if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { + let (rng, _) = dec.debug_state(); + eprintln!("EC_DV mi_row={mi_r} mi_col={mi_c} dv_col={} dv_row={} rng={rng}", dv.1, dv.0); + } + dv } /// A 1/8-pel motion vector component converted to the 1/16-pel offset diff --git a/lanes/av1txrouting.report.md b/lanes/av1txrouting.report.md new file mode 100644 index 00000000..b3fe064c --- /dev/null +++ b/lanes/av1txrouting.report.md @@ -0,0 +1,181 @@ +# lane-av1-txrouting — the one-routing-predicate hypothesis is REFUTED; work-in-progress + +Base: `main` **0cfb9af5** (2026-09-19). Worktree `../edith_codecs-av1txr`, branch +`lane-av1-txrouting`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txr`. + +**STATUS: WIP, NOT READY TO MERGE.** The 4x4 sub-8x8 intrabc path is proven +symbol-for-symbol correct on a real stream; the 4x8/8x4 rect leaf path is +**not yet byte-exact** (see §5). No gate has been run to completion. + +--- + +## 1. Headline: the scout's "ONE routing predicate" is refuted + +The charter's three stops do **not** share a routing predicate. First-divergence +traces (instrumented `aomdec` oracle at `~/.cache/aom-oracle/build/aomdec` + +`decode_probe`, `EC_TRACE_MODE_STEP`) give each stop a distinct cause: + +| stop | stream (reproduced) | first divergence | real cause | +|---|---|---|---| +| 3.2 / "Golomb tail" | `aomenc 4:4:4 --cpu-used=6/7` | block `(0,0)`, chroma transform entry rng **39857** | **4:4:4 chroma-subsampling is not implemented** (see §3) | +| 3.3 / "sub-8x8 intrabc" | `aomenc --allintra` | block `(45,52)` rng 37280 | a **genuine** 4x4 intrabc block (see §4) | +| 3.4 / "sub-8x8 intrabc" | `aomenc --enable-warped-motion=1 --cpu-used=0` | block `(37,62)` | the same, at a 4x8/8x4 rect leaf | + +The report's §3.2/§3.3 claim that "`aomdec` reads `tx_depth` where ours reads +`txfm_split`/`intrabc`/`uv_mode`" is an **instrumentation artifact**: aomdec's +`read_intrabc_info` had no print, and `read_tx_size_vartx`'s print is gated on +`EC_VARTX`, not `EC_ISTEP`. With the oracle instrumented for both +(`EC_ISTEP name=intrabc`, `EC_DV`, `EC_COEFF`), ours and aomdec read +**identical `intrabc` flags and identical DVs** at these blocks — no desync. + +Similarly the §3.2 "aomdec reads `tx_depth`, ours reads `txfm_split`" claim: +the 4:4:4 divergence is **after** the tx-depth read (both read +`tx_depth val=1 ctx=0 cat=1`) and is a chroma-transform size mismatch, not a +tx-size routing mismatch. + +## 2. Reproduced streams (all re-derivable) + +``` +cd ~/.cache/av1txr +# 4:4:4 (aomenc) -- cu6/cu7 REFUSE, cu4/cu5/cu8 decode-but-wrong +aomenc --codec=av1 --passes=1 --threads=1 --cpu-used=6 --obu -o s/a444-cu6.obu s/s444.y4m +# sub8 intrabc +aomenc --codec=av1 --passes=1 --threads=1 --obu --allintra --cpu-used=6 -o s/allintra.obu s/s420.y4m +aomenc --codec=av1 --passes=1 --threads=1 --obu --enable-warped-motion=1 --cpu-used=0 -o s/warped.obu s/s420.y4m +# (s420.y4m / s444.y4m = ffmpeg testsrc2 320x240 rate 8 dur 3) +``` + +Pre-fix: `allintra`/`allintra0`/`warped` → `REFUSED: a sub-8x8 leaf that uses +intrabc …`; `a444-cu6/7` → `REFUSED: a Golomb tail longer than this decoder +reads`; `a444-cu4/5/8` → `OK` **but garbage**. + +## 3. Stop 3.2 — 4:4:4 is entirely unsupported (root-caused) + +`probe EC_PROBE_OUT8` vs `ffmpeg -pix_fmt yuv420p` for **every** 4:4:4 stream +(`a444-cu4/5/8`, `ff444-cu5..8`) **differs** — the "decoding" 4:4:4 streams are +silently desynced garbage. The fixture story ("`av1-profile1-444` decodes +fine") was never byte-exactness-checked. + +**First divergence (a444-cu6, block `(0,0)`, an 8x16 rect leaf, depth 1):** + +``` +aom: EC_ISTEP tx_depth val=1 ctx=0 cat=1 rng=44248 + EC_COEFF mi_row=0 mi_col=0 plane=0 tx=1 rng=44248 # TX_8X8 + EC_COEFF mi_row=0 mi_col=0 plane=0 tx=1 rng=41886 # TX_8X8 + EC_COEFF mi_row=0 mi_col=0 plane=1 tx=7 rng=39857 # TX_8X16 <-- chroma + EC_COEFF mi_row=0 mi_col=0 plane=2 tx=7 rng=64008 # TX_8X16 +ours: … luma units rng 44248, 41886 (MATCH) … + read_coeffs_rect chroma entry rng=39857, w=4 h=8 # 4:2:0 half <-- DIVERGE +``` + +The decoder hardcodes 4:2:0 chroma extents at every rect site +(`let (chroma_w, chroma_h) = (bw / 2, bh / 2);` — `decode.rs:9476,10888,11378, +11767,12772,14326,15042,26798`) and the probe only ever emits 4:2:0 planes. +`subsampling_x/y` is parsed by `ec-av1-syntax` but **never read by the decoder**. + +**Disposition: needs a `num_planes`/subsampling threading lane** (like the +sibling mono lane). The honest interim fix is a **new named refusal at the +sequence-header level** for `subsampling_x != 1 || subsampling_y != 1` +(`num_planes > 1`), so a 4:4:4/4:2:2 stream refuses by name instead of +producing garbage. **Not yet written** (budget). + +## 4. Stops 3.3 / 3.4 — genuine sub-8x8 intrabc (implemented, WIP) + +The trace proves both streams code **real** sub-8x8 intrabc blocks: +`aomdec`'s instrumented `read_intrabc_info` reads `intrabc val=1` and an +`EC_DV` at `allintra (45,52)/(45,53)` and `warped (37,62)`. libaom's +`av1_allow_intrabc` is a frame-level test with no shape term, and the 4x4 block +`is_chroma_ref` (last sub-block) makes its chroma an intrabc copy too. + +Implemented on the lane (see §6 diff): +- `read_intra_mode_sub8` reads the DV (`read_intrabc_dv`) and RETURNS + (skip, DC_PRED, 0, None, None, Some(dv)) — no mode/uv/filter-intra syntax. +- `read_intrabc_dv` generalized from a square `side` to a `(n4_w, n4_h)` + footprint (rect leaves scan 1x2/2x1, not 2x2). +- `decode_leaf_split4` / `decode_leaf_rect8` reconstruct the intrabc leaf: + `flush_recon` + `mc::predict_with_filter(.., Bilinear)` frame copy injected + via the `set_palette_pred` override slot, residual read through the **inter** + sets (`Luma4Inter`/`Luma4InterSet1`, `LumaRect8x4Inter`/`Set1`), no + `tx_depth` symbol (libaom `block_signals_txsize` false below 8x8), + `record_intrabc_mi(_rect)` publishing the true footprint. +- **Chroma tx-type inheritance** (the subtle one): libaom `av1_get_tx_type` + (blockd.h:1278) gives a non-Y plane the LUMA's `tx_type_map` entry when + `is_inter_block(mbmi)` — **intrabc counts as inter**. So the group's chroma + eob/scan class is the luma's coded type, not `DCT_DCT`. Armed via the + existing `fctx.intrabc_chroma_tx` slot (the square path's mechanism). + +**Evidence the 4x4 path is byte-exact (allintra, block (45,52)):** the luma +intrabc residual traces **identically** to aomdec +(`tx_type txtype=11`/`HDct`, `eob=14`, every `base`/`br`/`sign`/`post_golomb` +rng equal), and ours reaches `(45,53) skip rng=52504` — aomdec's exact value. +With the chroma-inheritance fix the following block's `skip` also matched. + +## 5. What is NOT done (do not merge without it) + +1. **`warped` is not byte-exact.** With the implementation it decodes 24 + frames but `EC_PROBE_OUT8` vs `ffmpeg -pix_fmt yuv420p` differs at byte + **41217** (frame 0, luma row 128), and the entropy desyncs at + `(38,60) skip`: aom 48630 vs ours 60320. The **rect intrabc leaf** + (4x8/8x4) is the suspect: unverified `predict_with_filter` buffer shape, + residual set, or the rect DV scan. +2. **`allintra` now stops one shape later**: `REFUSED: intra block copy on a + HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this + shape)` (the `decode.rs:9122` rect reader). `allintra0` (cpu-used 0) + **panics** at `transform.rs:1134` (a 4x4 dequant given a 1024-entry grid) + via `decode_leaf8` — a further reachable path after the sub8 blocks pass. +3. **4:4:4/4:2:2 named refusal** (§3) not written. +4. **No gates run.** Only `cargo build --release -p ec-av1 --example + decode_probe` (0 errors/warnings) and `cargo check`-equivalent builds. + `cargo test -p ec-av1 --lib` (592/0/60 baseline) NOT run. +5. **Inventory re-pin not done.** §3.3's two refuted PROVEN entries + (`read_golomb_reads_every_value…`, `a_sub8_leaf_census…`) still claim + "unreachable"; they must be re-pinned to reachable-with-witness. The report + §5 tripwire `a_real_libaom_monochrome_key_frame_is_refused_by_name` is + untouched (mono stream unaffected — its `num_planes == 1`). + +## 6. Diff summary (lane, uncommitted-at-first-write) + +`crates/ec-av1/src/decode.rs`: +- `read_intra_mode_sub8`: +`Option<(i32,i32)>` return, intrabc branch (DV read, + early return), `istep!("intrabc")`. +- `read_intrabc_dv`: `side` → `(n4_w, n4_h)`; `EC_DV` trace print; call sites + updated (square path passes `(side/MI, side/MI)`). +- `record_intrabc_mi` split into `record_intrabc_mi_rect` (rect footprint). +- `decode_leaf_split4` + `decode_leaf_rect8`: intrabc leaf arm (frame copy + + inter residual) and intrabc chroma arm (frame copy + `Chroma4`, luma tx-type + inheritance, cleared after). +- Trace prints added at previously-silent `tx_depth`/`intrabc` sites so a + cross-decoder first-divergence diff aligns. + +## 7. Repro / oracle recipes + +``` +# build +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txr cargo build --release -p ec-av1 --example decode_probe + +# byte-exactness, 8-bit +decode_probe x.obu out8.raw # argv[2] = 8-bit planes +ffmpeg -i x.obu -pix_fmt yuv420p -f rawvideo ref8.raw -y +cmp out8.raw ref8.raw +# (EC_PROBE_OUT16 is yuv420p10le and is NOT comparable to ffmpeg's +# yuv420p10le for an 8-bit source — ffmpeg left-shifts, the probe does not. +# Use the 8-bit form for 8-bit streams. This bit me once.) + +# first divergence vs the instrumented oracle +EC_TRACE_MODE_STEP=1 ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null x.obu 2>a.step +EC_TRACE_MODE_STEP=1 decode_probe x.obu 2>o.step +# per-(mi_row,mi_col,name) index compare in python (see §1 method) +``` + +Oracle build: `~/.cache/aom-oracle` (cmake+ninja) instrumented with +`EC_ISTEP name=intrabc` (decodemv.c `read_intrabc_info`), `EC_DV` +(post-`assign_dv`), `EC_COEFF` (decodeframe.c `read_coeffs_tx_intra_block`). + +## 8. Recommended next steps (ordered) + +1. Fix the rect intrabc leaf (warped) — trace the rect leaf's DV/residual vs + aomdec; then verify `EC_PROBE_OUT8` byte-exact. +2. Unblock `allintra`'s 1:4 rect strip intrabc (`decode.rs:9122`) and the + `decode_leaf8` dequant panic. +3. Add the sequence-header subsampling refusal (§3) and re-pin the inventory. +4. Run `cargo test -p ec-av1 --lib` + `cargo check -p ec-av1 --all-targets`.