diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 0ed94a99..d38d4691 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -79,6 +79,10 @@ fn main() { println!( "rect_wedge(8x16,16x8,16x32,32x16,8x32,32x8): compound={rw:?} interintra={rwi:?}" ); + // lane-inter128intra r1: the 128 root's HORZ/VERT half coded INTRA in + // an INTER frame -- the arm this round implemented. + let i128 = ec_av1::stream::intra128_in_inter_counters(); + println!("intra128_in_inter: 128x64={} 64x128={}", i128[0], i128[1]); let sb = ec_av1::stream::sb128_rect_counters(); println!( "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}", diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 7eeed91c..cab34400 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5428,14 +5428,14 @@ impl Neighbours { left_coded |= left.level != 0; vote += dc_vote(left.dc); } - if plane == 0 && std::env::var_os("EC_DCDUMP").is_some() { + if std::env::var_os("EC_DCDUMP").is_some() { let ab: Vec = (0..w_mi) - .map(|k| format!("{:?}/{}", self.above[mi_c + k][0].dc, self.above[mi_c + k][0].level)) + .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) .collect(); let lf: Vec = (0..h_mi) - .map(|k| format!("{:?}/{}", self.left[mi_r + k][0].dc, self.left[mi_r + k][0].level)) + .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) .collect(); - eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); + eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); } (above_coded, left_coded, vote) }) @@ -7466,6 +7466,56 @@ fn decode_intra_rect_in_inter( }); return Ok(()); } + // lane-inter128intra r1: the 128 superblock's PARTITION_HORZ/VERT half + // coded INTRA inside an inter frame. `size_group_lookup` (common_data.h:61) + // puts BLOCK_128X64/64X128/128X128 in group 3 and + // `max_txsize_rect_lookup` caps them at TX_64X64, i.e. the same + // `tx_size_cat3` row [`decode_block_128rect`] already reads -- so the whole + // block decodes through the very body the KEY FRAME path proves for this + // shape (square 64x64 luma units, one TX_32X32 chroma unit per 64x64 mu + // chunk on the offset-10 txb_skip rows, per-TU prediction, the mu-chunk + // `Reach` rule and the frame-edge write clip). The only inter-frame + // differences live inside that body: the mode-info read + // ([`INTRA_IN_INTER_MODE`] -> `y_mode[3]` plus the `skip` this caller + // already read), the `tx_depth` context (the real TXFM_CONTEXT bands) and + // the `set_txfm_ctxs` publication. CfL (>32), filter intra (>32) and + // palette (>64) do not exist at this size and are refused by name there. + // lane-inter128intra r1: OPT-IN ONLY (`EC_INTRA128_IN_INTER=1`) until a + // gate exists. The body below is believed right (it is the key frame's own + // proven body plus the three inter-frame differences), but the three 1080p + // cuts that reach this shape reach it AFTER a pre-existing desync (see the + // lane report: their frame 2 diverges from aomdec inside the superblock at + // mi(0,320), long before mi(128,416)), and no aomenc recipe found so far + // emits a 128-root HORZ/VERT half coded intra in an inter frame -- so + // nothing can currently prove this arm. A refusal is lifted only with a + // gate (COMMON), so the default path still refuses by name below. + if bw.max(bh) == 128 && std::env::var_os("EC_INTRA128_IN_INTER").is_some() { + if allow_screen_content_tools { + return Err(unsupported( + "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ + is consumed for square blocks only)", + )); + } + INTRA_IN_INTER_MODE.with(|c| c.set(Some((3, skip)))); + let res = decode_block_128rect( + dec, + cdfs, + neighbours, + (r, c), + bw, + bh, + y, + u, + v, + base_q_idx, + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), + allow_screen_content_tools, + TX_SELECT_INTER.with(std::cell::Cell::get), + REDUCED_TX_SET_INTER.with(std::cell::Cell::get), + ); + INTRA_IN_INTER_MODE.with(|c| c.set(None)); + return res; + } let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) { (8, 16) => (1usize, 1usize), (16, 32) => (2, 2), @@ -7570,6 +7620,16 @@ fn decode_intra_rect_in_inter( return Ok(()); } let mode = dec.symbol(&mut cdfs.y_mode[size_group]); + // lane-t900 r1: this arm read six mode symbols with no ladder rung of its + // own, so a cross-decoder bisection could only see the block's first + // coefficient. Same names/format as [`read_tx_size`]'s rung. + let step_trace = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); + if step_trace { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=y_mode val={mode} grp={size_group} rng={}", + dec.debug_state().0 + ); + } if mode >= 13 { return Err(unsupported( "an intra mode this decoder does not code (round 2)", @@ -7595,6 +7655,13 @@ fn decode_intra_rect_in_inter( } else { dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) }; + if step_trace { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=uv_mode val={uv_mode} cfl={} rng={}", + u8::from(cfl_allowed), + dec.debug_state().0 + ); + } if (9..=12).contains(&uv_mode) { SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1)); } @@ -7652,7 +7719,7 @@ fn decode_intra_rect_in_inter( 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), }; - if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + if step_trace { eprintln!( "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat={tx_cat} rng={}", dec.debug_state().0 @@ -7831,8 +7898,26 @@ fn decode_block_rect( // pinned HORZ quadrant were wrong from their very first pixel, and why our // range after the read equalled the oracle's range for the whole block. let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); - dec.symbol(&mut cdfs.tx_size_cat2[ctx]) + // lane-t900 r2: on an INTER frame `get_tx_size_context` reads the real + // `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what the 2:1 and + // the 16x4 intra-in-inter strips already do); the key frame's + // deblock-grid approximation is only right where those bands were never + // written. Measured on the 10-bit 1920x792 128-superblock stream, + // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read + // `tx_size_cat2` row 1 where libaom reads row 2. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh) + } else { + tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) + }; + let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}", + dec.debug_state().0 + ); + } + d } else { 0 }; @@ -8315,7 +8400,13 @@ fn decode_leaf_rect( // a constant `false`. let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh); + // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band read + // every other rect reader now does -- a no-op on a key frame. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, leaf_mi, bw, bh) + } else { + tx_size_context_rect(neighbours, leaf_mi, bw, bh) + }; // lane-rectsplitx r1: `bsize_to_tx_size_cat` (libaom `blockd.h`, // `bsize_to_tx_size_depth_table`) is 2 for BLOCK_16X8/BLOCK_8X16, so // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol @@ -8647,11 +8738,37 @@ fn decode_block_rect4( 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]) + // lane-t900 r2: on an INTER frame `get_tx_size_context` reads the real + // `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what the 2:1 and + // the 16x4 intra-in-inter strips already do); the key frame's + // deblock-grid approximation is only right where those bands were never + // written. Measured on the 10-bit 1920x792 128-superblock stream, + // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read + // `tx_size_cat2` row 1 where libaom reads row 2. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh) + } else { + tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) + }; + let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}", + dec.debug_state().0 + ); + } + d } else { 0 }; + // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra + // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`]. + publish_txfm_bands_if_in_inter( + neighbours, + (mi_r, mi_c), + depth_to_tx_wh(bw, bh, depth), + (bw, bh), + ); if depth != 0 { // lane-rectsplitx r1: the per-transform-unit walk, at this strip's // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a @@ -9157,7 +9274,16 @@ fn decode_rect4_16_strip( } else { tx_size_context_rect(neighbours, lmi, bw, bh) }; - dec.symbol(&mut cdfs.tx_size_cat1[ctx]) + let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]); + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}", + lmi.0, + lmi.1, + dec.debug_state().0 + ); + } + d } else { 0 }; @@ -9634,7 +9760,18 @@ fn decode_block_rect64( }; let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + // lane-t900 r2: on an INTER frame `get_tx_size_context` reads the real + // `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what the 2:1 and + // the 16x4 intra-in-inter strips already do); the key frame's + // deblock-grid approximation is only right where those bands were never + // written. Measured on the 10-bit 1920x792 128-superblock stream, + // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read + // `tx_size_cat2` row 1 where libaom reads row 2. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh) + } else { + tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) + }; // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`) // counts `sub_tx_size_map` steps from the block's own max rect // transform down to TX_4X4, minus one -- BLOCK_64X32's chain @@ -9642,10 +9779,25 @@ fn decode_block_rect64( // steps, so this level's category is 3 (the same one a 64x64 square // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF // here was a wrong-table read of a real symbol. - dec.symbol(&mut cdfs.tx_size_cat3[ctx]) + let d = dec.symbol(&mut cdfs.tx_size_cat3[ctx]); + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=3 rng={}", + dec.debug_state().0 + ); + } + d } else { 0 }; + // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra + // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`]. + publish_txfm_bands_if_in_inter( + neighbours, + (mi_r, mi_c), + depth_to_tx_wh(bw, bh, depth), + (bw, bh), + ); if depth != 0 { TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); // lane-rectsplit r1/r4: the superblock-level strip splits its @@ -11657,6 +11809,15 @@ thread_local! { /// Those blocks by resolved intra `tx_depth` (0 = TX_64X64 units, /// 1 = TX_32X32, 2 = TX_16X16) -- proof the depth symbol is really read. pub(crate) static INTRA_SB128_DEPTH_HITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) }; + /// lane-inter128intra r1: the same shapes decoded on the INTER block path + /// (an intra-coded PARTITION_HORZ/VERT half of a 128 superblock inside an + /// inter frame) -- (128x64, 64x128). + pub(crate) static INTRA128_IN_INTER_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) }; +} + +/// [`INTRA128_IN_INTER_HITS`], for a gate's own before/after delta. +pub(crate) fn intra128_in_inter_hits() -> [usize; 2] { + INTRA128_IN_INTER_HITS.with(std::cell::Cell::get) } /// [`INTRA_SB128_HORZ_HITS`] / [`INTRA_SB128_VERT_HITS`] / @@ -11748,8 +11909,17 @@ fn decode_block_128rect( let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c); // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc). + let in_inter = INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some(); let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + // lane-inter128intra r1: on an INTER frame `get_tx_size_context` reads + // the real `TXFM_CONTEXT` bands, and compares them against + // `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` -- TX_64X64 for + // every 128-axis block, hence the `min(64)`. + let ctx = if in_inter { + tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64)) + } else { + tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh) + }; dec.symbol(&mut cdfs.tx_size_cat3[ctx]) } else { 0 @@ -11941,7 +12111,25 @@ fn decode_block_128rect( logical_tx as u8, 0, ); - if bw > bh { + if in_inter { + // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)` + // (libaom `decodeframe.c` `decode_block`) runs for EVERY block of an + // inter frame, intra ones included: an intra block stamps its + // TRANSFORM size over its own footprint in both TXFM_CONTEXT bands. + // A key frame has no var-tx tree and its readers use the deblock grid, + // so this is the inter path's alone. + txfm_partition_update_rect( + neighbours, + (mi_r, mi_c), + (logical_tx, logical_tx), + (bw, bh), + ); + INTRA128_IN_INTER_HITS.with(|c| { + let mut h = c.get(); + h[usize::from(bw < bh)] += 1; + c.set(h); + }); + } else if bw > bh { INTRA_SB128_HORZ_HITS.with(|c| c.set(c.get() + 1)); } else { INTRA_SB128_VERT_HITS.with(|c| c.set(c.get() + 1)); @@ -12958,7 +13146,13 @@ fn decode_leaf_rect8( // and desynced the tile at the very first rect leaf (class // `symbol-consumption-gap`). let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, lmi, bw, bh); + // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band + // read every other rect reader now does -- a no-op on a key frame. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, lmi, bw, bh) + } else { + tx_size_context_rect(neighbours, lmi, bw, bh) + }; dec.symbol(&mut cdfs.tx_size_cat0[ctx]) } else { 0 @@ -13673,6 +13867,46 @@ fn txfm_partition_update( /// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): /// the left column records `tx_size_high` over the parent's own height and /// the above row records `tx_size_wide` over its width. +/// libaom `set_txfm_ctxs` + `txfm_partition_update` (`decodeframe.c`, end of +/// `decode_token_recon_block`): EVERY block of an inter frame publishes its +/// TRANSFORM size into both `TXFM_CONTEXT` bands, intra blocks included. The +/// key frame writes neither (its readers use the deblock grid), so the +/// key-frame bodies reused by [`decode_intra_rect_in_inter`] have to do it +/// themselves when they run inside an inter frame. The 2:1 and 16x4 arms do it +/// at the call site (the transform size comes back to them); the 1:4 arms +/// ([`decode_block_rect4`] / [`decode_block_rect64`]) keep their size inside, +/// so they call this where their own depth resolves. A no-op on a key frame +/// ([`INTRA_IN_INTER_MODE`] unset), where those bands are not read at all. +/// +/// lane-t900 r1 root cause: the HORZ_4 32x8 intra strip at mi(0,312) of an +/// inter frame left `left_txfm[0]` at a stale 32 where libaom's own +/// `set_txfm_ctxs` writes 8, so the intra 8x16 block at mi(0,320) read +/// `tx_size_cat1` row 1 instead of row 0 -- same depth VALUE, different CDF, +/// range 39156 where the reference has 54736 (class tx-grid-published-block-side +/// / early-return-skips-tail). +fn publish_txfm_bands_if_in_inter( + n: &mut Neighbours, + at_mi: (usize, usize), + (tx_w, tx_h): (usize, usize), + (bw, bh): (usize, usize), +) { + if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_none() { + return; + } + let (mi_r, mi_c) = at_mi; + txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh)); + for i in 0..bw / MI { + if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { + *cell = tx_w as u8; + } + } + for i in 0..bh / MI { + if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { + *cell = tx_h as u8; + } + } +} + fn txfm_partition_update_rect( n: &mut Neighbours, (mi_r, mi_c): (usize, usize), @@ -22761,6 +22995,28 @@ fn decode_inter_block( } else { Vec::new() }; + // libaom `av1_reset_entropy_context` / `av1_set_entropy_contexts`: + // `nplanes = 1 + (num_planes - 1) * xd->is_chroma_ref` -- a block that is + // NOT the chroma reference of its 4:2:0 pair codes no chroma transform at + // all, so it leaves its neighbours' CHROMA coefficient contexts exactly as + // it found them. `record_rect_mi`/`record_split_luma_rect_mi` below write + // all three planes unconditionally, and for such a strip the chroma grids + // are all-zero (see the `!has_chroma` arm above) -- that wiped the real + // left-neighbour chroma state, so the PAIR's own `all_zero` then read + // `txb_skip_ctx` one row low (lane-t900 r3, 10-bit 1920x792 stream, + // mi(40,220): base 1 where libaom gathers 2). Snapshot and restore is + // equivalent to not writing them, without threading a flag through both + // recorders. + let saved_chroma_ctx = (!has_chroma).then(|| { + let (w_mi, h_mi) = (write_w / MI, write_h / MI); + let left: Vec<[Neighbour; 2]> = (0..h_mi) + .filter_map(|k| neighbours.left.get(at.0 + k).map(|s| [s[1], s[2]])) + .collect(); + let above: Vec<[Neighbour; 2]> = (0..w_mi) + .filter_map(|k| neighbours.above.get(at.1 + k).map(|s| [s[1], s[2]])) + .collect(); + (left, above) + }); if vartx_leaves.is_some() { // Plane 0 is already correct per transform unit // ([`Neighbours::record_mi_luma`] above); this writes everything else @@ -22794,6 +23050,20 @@ fn decode_inter_block( &[luma_grid, u_grid, v_grid], ); } + if let Some((left, above)) = saved_chroma_ctx { + for (k, v) in left.into_iter().enumerate() { + if let Some(slot) = neighbours.left.get_mut(at.0 + k) { + slot[1] = v[0]; + slot[2] = v[1]; + } + } + for (k, v) in above.into_iter().enumerate() { + if let Some(slot) = neighbours.above.get_mut(at.1 + k) { + slot[1] = v[0]; + slot[2] = v[1]; + } + } + } if let Some((s, u_state, v_state)) = pair_chroma { let (pw, ph) = if s.horz { (16usize, 8usize) } else { (8, 16) }; let round_up_even = |n: usize| n.div_ceil(2) * 2; diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 306bcb0b..9f4311d2 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -160,6 +160,12 @@ pub fn intra_sb128_counters() -> (usize, usize, [usize; 3]) { crate::decode::intra_sb128_hits() } +/// lane-inter128intra r1: the 128 root's HORZ/VERT half coded INTRA inside an +/// INTER frame -- (128x64 blocks, 64x128 blocks). +pub fn intra128_in_inter_counters() -> [usize; 2] { + crate::decode::intra128_in_inter_hits() +} + /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`, /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the /// counter -- it is bumped where the root symbol resolves). diff --git a/lanes/inter128intra-r1.report.md b/lanes/inter128intra-r1.report.md new file mode 100644 index 00000000..564c4751 --- /dev/null +++ b/lanes/inter128intra-r1.report.md @@ -0,0 +1,149 @@ +# lane-inter128intra r1 -- the 128-root HORZ/VERT half coded INTRA in an inter frame + +Branch `lane-inter128intra` (base main `5dd3dcb`), commit `5c114d5`, +worktree `edith_codecs-inter128intra`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-inter128intra`. + +## Verdict up front + +The arm is IMPLEMENTED but **not gated and therefore not lifted**: it decodes +only under `EC_INTRA128_IN_INTER=1`, the named refusal is untouched on the +default path, `refusal_inventory.rs` / `gate_coverage.rs` are unchanged. Two +findings force that: + +1. **The charter's film premise is a downstream artifact** (class + `refusal-from-own-desync`): on `t900` the 128x64 intra arrival at + mi(128,416) sits *after* a pre-existing entropy desync in the same frame. +2. **No aomenc recipe found emits the shape**: 3 recipes x 4 cq values produced + ZERO 128-root HORZ/VERT halves in an inter frame (`inter_128x64=0` on the + decoder side), so there is nothing to gate on yet. + +## Measurement (step 1, before any edit) + +`EC_OBMCREC=1 decode_probe` on the three 2 s cuts of the 10-bit 1920x792 +128-superblock stream: + +| cut | shape | mi | skip | +|---|---|---|---| +| t900 | 128x64 | (128,416) | false | +| t5400 | 128x64 | (192,0) | false | +| t8100 | 128x64 | (192,0) | false | + +EVIDENCE: ~/.cache/rectres-tmp/{t900,t5400,t8100}.obu | EC_OBMCREC=1 decode_probe per cut | 3/3 arrive as a non-skip 128x64, premise shape confirmed + +## Cross-decoder ladder -- the premise is stale + +`t900` truncated to its first 2 frames (`census6/trunc.py`, +`~/.cache/inter128intra-tmp/t900_2.obu`, 85285 B), ours +`EC_TRACE_MODE_STEP=1` vs `~/.cache/aom-oracle/build/aomdec` +`EC_TRACE_MODE=1 EC_TRACE_MODE_STEP=1`: + +- **Key frame exact**: the ordered `EC_IMODE mi_row/mi_col` sequence is + identical for all 2704 blocks (ours has 184 extra lines, all from frame 2's + intra-in-inter blocks, which aomdec does not print at all). +- **Frame 2 last common symbol**: `mi_row=24 mi_col=312 name=tx_depth rng=38975` + -- byte-identical in both traces. +- **First divergence**: the very next superblock, mi(0,320) (pixel 1280,0). + aomdec reads INTRA `tx_depth` for small blocks -- + `(0,320) val=1 ctx=0 cat=1 rng=54736`, `(0,322) rng=53468`, `(0,324)`, + `(2,324)`, `(4,320)`, `(5,320)`… -- while ours reads var-tx + `txfm_split_rect mi=(2,324) ctx=12 rng=53248` then + `txfm_split mi=(4,324) ctx=13 rng=46998`, i.e. we take that block as INTER + where libaom has intra. None of our three rng values (53248 / 46998 / 37590) + occurs anywhere in the reference's frame-2 trace. +- mi(0,320) is decoded **hundreds of blocks before** mi(128,416) in the same + frame, and main's build walks the same path (it refuses only later, at + mi(128,416)) -- so the desync is PRE-EXISTING on main `5dd3dcb`, not caused by + this lane, and the "128x64 intra in an inter frame" shape at that mi is what + the desync produced. + +EVIDENCE: ~/.cache/inter128intra-tmp/{ours.trace,aom.trace,o.f2,a.f2} | trunc t900 to 2 frames, EC_TRACE_MODE_STEP ours vs instrumented aomdec | key frame 2704/2704 blocks identical; frame 2 diverges at SB mi(0,320), last common rng=38975 at mi(24,312) + +## What changed (all inert unless `EC_INTRA128_IN_INTER=1`) + +- `crates/ec-av1/src/decode.rs:7389` `decode_intra_rect_in_inter`: new + `bw.max(bh) == 128` arm -- sets `INTRA_IN_INTER_MODE = Some((3, skip))` + (`size_group_lookup` common_data.h:61 puts BLOCK_128X64/64X128/128X128 in + group 3, verified in the oracle tree) and calls the key frame's own + `decode_block_128rect`, whose `tx_size_cat3` row is already the category a + 128-axis block reads (`max_txsize_rect_lookup` caps at TX_64X64). +- `crates/ec-av1/src/decode.rs:11609` `decode_block_128rect`: the `tx_depth` + context comes from `tx_size_context_txfm_rect(.., bw.min(64), bh.min(64))` + when the block is intra-in-inter (libaom `get_tx_size_context` compares the + TXFM_CONTEXT bands against `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` + = 64 here), and the block publishes `set_txfm_ctxs` over its own footprint + (`txfm_partition_update_rect`) -- the two inter-frame differences the key + frame does not have. Key-frame behaviour is untouched (`in_inter == false`). +- `crates/ec-av1/src/decode.rs:11519` `INTRA128_IN_INTER_HITS` + + `crates/ec-av1/src/stream.rs:156` `intra128_in_inter_counters()` + + `crates/ec-av1/examples/decode_probe.rs:81` prints + `intra128_in_inter: 128x64=.. 64x128=..`. + +## Recipe sweep -- aomenc never picked the shape + +`--sb-size=128 --min-partition-size=64 --enable-rect-partitions=1 +--kf-max-dist=100 --end-usage=q --cpu-used=0 --lag-in-frames=0 --limit=6` +over 256x256 8-bit sources: + +| source | cq | frames | intra128_in_inter | inter_128x64 | +|---|---|---|---|---| +| full-frame temporal noise (`noise=alls=90:allf=t+u:all_seed=43`) | 32 | 6 OK | 0 | 0 | +| same | 55 | 6 OK | 0 | 0 | +| static gray + two 256x64 noise bands at y=64,192 (forces a HORZ split with one intra half) | 20 | 6 OK | 0 | 0 | +| same | 45 | 6 OK | 0 | 0 | + +The decoder-side `inter_128x64` counter is 0 in every arm: aomenc did not +choose the 128-root HORZ/VERT partition in an inter frame at all, so this is a +partition-choice problem, not an intra/inter one -- a gate needs either a +recipe that produces the partition first, or the film-prefix fixture route +(blocked by the desync above). + +EVIDENCE: ~/.cache/inter128intra-tmp/{g_32,g_55,h_20,h_45}.obu | aomenc 4 arms + decode_probe | 4/4 decode OK 6 frames, 128-root rect partitions 0/4 + +## Film cuts (10-bit 1920x792 128-SB, 2 s each) + +| cut | default (refusal untouched) | with `EC_INTRA128_IN_INTER=1` | +|---|---|---| +| t900 | intra-coded 128x64 block on the inter block path | Golomb tail; 128x64=0 (desync kills it inside the first such block) | +| t5400 | intra-coded 128x64 block on the inter block path | Golomb tail; 128x64=453 64x128=20 | +| t6300 | Golomb tail (unchanged from main) | Golomb tail; 0 | +| t8100 | intra-coded 128x64 block on the inter block path | Golomb tail; 128x64=30 | + +The opt-in numbers are NOT a capability claim: every one of those blocks is +downstream of the same class of upstream desync proven for t900, and the +"Golomb tail" wall is itself a desync symptom (`refusal-hides-a-defect`). + +EVIDENCE: ~/.cache/rectres-tmp/{t900,t5400,t6300,t8100}.obu | decode_probe with and without EC_INTRA128_IN_INTER=1 | default stop strings identical to main; opt-in advances past the shape into a Golomb wall + +## Suite + +`cargo test -p ec-av1 --lib` under systemd unit +`inter128intra-suite-r1-1788367879` (MemoryMax=10G), +log `$HOME/.cache/inter128intra-suite.log`: **424 passed; 1 failed; 37 ignored** in 702 s. + +The single failure is +`real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal` +("the rectangular var-tx leaf arm never fired 32x16=0 16x32=0, 0 refusals") -- +PRE-EXISTING and already recorded on the base of the previous lane +(lanes/obmcrec-r1.report.md, verified there in a detached worktree on +`beecb64`); the totals here are byte-identical to that round's. This lane's +whole diff is inert without `EC_INTRA128_IN_INTER=1`, which no test sets, so it +cannot move any counter. Every gate named in the charter (`sb128`, +`intra_rect_block`, `gathered_edge`, `refusal_inventory`, `gate_coverage`) is +inside those 424 passes. + +## Residue + +- fix-now (own lane, blocks this one): the frame-2 desync at SB mi(0,320) of + the 2 s cut at 900 s -- last common symbol mi(24,312) `tx_depth` rng=38975, + first divergence one superblock later where aomdec has intra blocks with + `cat=1` at (0,320)/(0,322)/(0,324)/(2,324) and ours reads var-tx + `txfm_split_rect` at (2,324). Truncated 2-frame witness pinned at + `~/.cache/inter128intra-tmp/t900_2.obu`; both traces kept next to it. +- deferred: the gate for this arm -- needs a recipe that makes aomenc pick a + 128-root HORZ/VERT partition in an INTER frame (0/4 attempts here), or a film + prefix whose counter is > 0 with the stream proven exact up to it (blocked by + the desync above). +- accepted: `128x128` NONE intra-in-inter was not swept -- it never reaches + `decode_intra_rect_in_inter` (that path is entered only when + `write_w != side`), so it is a different call site with its own residue. diff --git a/lanes/t900-r1.handoff.md b/lanes/t900-r1.handoff.md new file mode 100644 index 00000000..f4979cb7 --- /dev/null +++ b/lanes/t900-r1.handoff.md @@ -0,0 +1,100 @@ +# lane-t900 r1 handoff -- 1:4 intra strips in an inter frame never published their TXFM_CONTEXT bands + +Branch `lane-t900` (base main `5dd3dcb`), worktree `edith_codecs-t900`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900`. +Witness: `~/.cache/inter128intra-tmp/t900_2.obu` (2-frame cut of the 10-bit +1920x792 128-superblock stream at 900 s). Ladders regenerated in one round in +`~/.cache/t900-tmp/` (`o3.trace` ours `EC_TRACE_PART=1 EC_TRACE_MODE_STEP=1 +EC_TRACE_MODE=1`, `aom.trace` aomdec `EC_TRACE=1 EC_TRACE_MODE=1 +EC_TRACE_MODE_STEP=1`). + +## First diverging element -- before + +Last common symbol: `mi(24,312) tx_depth rng=38975` (filter-intra 32x32). +First differing element, one superblock later: + +| | ours | aomdec | +|---|---|---| +| `mi(0,320)` `tx_depth` (BLOCK_8X16, cat 1) | val=1 **ctx=1** rng=**39156** | val=1 **ctx=0** rng=**54736** | + +Same VALUE, different CDF ROW -> different range. `EC_TXCTX mi=0,320 +own=8x16 ... left_txfm=32 left=true` -- our left TXFM band held 32 where +libaom's `set_txfm_ctxs` had written 8. + +## Root cause + +The block left of `mi(0,320)` is the first 32x8 strip of a `PARTITION_HORZ_4` +at `mi(0,312)` -- an INTRA strip inside an INTER frame, decoded through the +key frame's own body (`decode_block_rect4`). libaom runs `set_txfm_ctxs` + +`txfm_partition_update` for EVERY block of an inter frame, intra ones +included; the 2:1 arm and the 16x4 arm of `decode_intra_rect_in_inter` do that +at their call sites (the transform size comes back to them), but the **1:4 +arms** (`decode_block_rect4` for 32x8/8x32, `decode_block_rect64` for +64x16/16x64) keep the size inside and published nothing, so both bands stayed +stale across the strip's footprint for the rest of the frame. +Classes: `tx-grid-published-block-side`, `early-return-skips-tail`. + +## Fix (path:line, this branch) + +- `crates/ec-av1/src/decode.rs` `publish_txfm_bands_if_in_inter()` (new, next + to `txfm_partition_update_rect`): `txfm_partition_update_rect` + both + `above_txfm`/`left_txfm` band writes, a no-op unless `INTRA_IN_INTER_MODE` + is set (key frames unchanged, bands unread there). +- called right after the depth symbol resolves in `decode_block_rect4` + (32x8/8x32) and in `decode_block_rect64` (64x16/16x64) -- depth 0 included, + which is the measured case. +- three new `EC_TRACE_MODE_STEP` rungs in `decode_intra_rect_in_inter` + (`y_mode`, `uv_mode`, `tx_depth` with ctx/cat): that arm read six mode + symbols with no rung of its own, so a bisection could previously only see + the block's first coefficient. + +## Ladder -- after + +`mi(0,320)` `tx_depth val=1 ctx=0 cat=1 rng=54736` == aomdec; +`mi(0,322)` `rng=53468` == aomdec; next partition `mi(0,324) bsize=6 rng=36404` +== aomdec. The superblock at mi(0,320) now matches element for element. + +Next difference in the deduped range ladder is at `mi(0,152)` (ours@15464 / +aom@19643): aomdec prints `motion_mode val=2` (WARPED_CAUSAL) + `interp` for +the 32x16 HORZ half, ours prints `txfm_split_rect` -- but BOTH decoders are +back at `rng=37626` on the next block `mi(4,152)` and at `rng=37736` for its +mv, so this is a RUNG-SET artifact (ours reads motion_mode without a rung), +not a proven divergence. Confirm with a rung before treating it as a defect. + +## State of the cut + +- default path: `decode_probe` now walks frame 2 to the known 128x64 wall -- + `REFUSED: an intra-coded 128x64 block on the inter block path` (that arrival + is no longer downstream of a desync; the r1 report's "premise is a + downstream artifact" verdict is now STALE). +- `EC_INTRA128_IN_INTER=1`: **`OK: 1 frames decoded, 1920x792`, + `intra128_in_inter: 128x64=15`** -- the whole 2-frame cut decodes, where r1 + measured a Golomb-tail wall with 128x64=0. + +## Next step (in order) + +1. Pixel-compare the 2-frame cut vs ffmpeg (`EC_PROBE_OUT16`, census6/run6.sh + recipe) with and without `EC_INTRA128_IN_INTER=1`. +2. Re-run the full 2 s cuts `~/.cache/rectres-tmp/{t900,t5400,t6300,t8100}.obu` + (frames, stop string, per-frame exact). +3. If the firing frame is exact, pin the smallest exact prefix + (census4/trunc.py) as `crates/ec-av1/fixtures/reelc_intra128_witness.obu` + (`git add -f` + sha256), gate every plane / every decode-order frame with a + hard counter assert, lift the refusal, drop `EC_INTRA128_IN_INTER`, update + `refusal_inventory.rs` + `gate_coverage.rs`. +4. Full suite as a systemd unit (COMMON recipe). NOT RUN this round. +5. Sibling sweep owed: every other caller of `decode_block_rect4` / + `decode_block_rect64` under `INTRA_IN_INTER_MODE`, and the same + publication question for `decode_block_rect` (2:1 key-frame body) if it is + ever reached in-inter. + +## Deviations + +- Charter forbids rebase/merge, COMMON requires rebasing onto main first: the + charter wins, so this branch is still on `5dd3dcb` and does NOT carry main's + `5d81a67` (vartxsplit) commits. The coordinator's note that main fixed + `decode_block_rect4`'s three exits refers to the frame36 r2 work already in + this base (`6202717`); that fix covers the SPLIT/return tails, not the + inter-frame band publication fixed here -- verified by the measured stale + `left_txfm=32`. +- Suite not run (coordinator instruction). `cargo check -p ec-av1` clean. diff --git a/lanes/t900-r2.handoff.md b/lanes/t900-r2.handoff.md new file mode 100644 index 00000000..1b4b3d79 --- /dev/null +++ b/lanes/t900-r2.handoff.md @@ -0,0 +1,136 @@ +# lane-t900 r2 handoff -- in-inter rect tx-depth context; next wall is the chroma txb_skip ctx + +Branch `lane-t900`, worktree `edith_codecs-t900`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900` (a second `-t900-b` dir was +used for `cargo check` while the suite unit held the first). + +## STEP 1 -- merge of main `5d81a67` (commit `85ce8ff`) + +One conflict, `crates/ec-av1/src/decode.rs`, in the 2:1 intra-in-inter +`tx_depth` rung: HEAD's cached `step_trace` bool vs main's inline +`std::env::var_os("EC_TRACE_MODE_STEP")`. Resolved to HEAD's `step_trace` +(same condition, one env read per block instead of per symbol). + +Publication per exit: NOT one write per exit, but every write is IDENTICAL. +`publish_txfm_bands_if_in_inter` sits right after the depth symbol in +`decode_block_rect4` / `decode_block_rect64` and covers every later exit; +frame36's `txfm_partition_update_rect` tails sit before the split arms' +`return Ok(...)`. Both write `depth_to_tx_wh(bw, bh, depth)` over the same +(bw,bh) footprint, so the split arms write the same bytes twice -- idempotent, +no double-update hazard. Left as-is deliberately (removing either one loses a +different exit). `publish_txfm_bands_if_in_inter` itself also duplicates +`txfm_partition_update_rect`'s two loops with the same values; harmless. + +`cargo check -p ec-av1`: clean. Re-ladder of `t900_2.obu` after the merge: +`mi(0,320) tx_depth val=1 ctx=0 cat=1 rng=54736` still == aomdec, r1's fix +survived the merge. + +## STEP 2 -- ROOT CAUSE FOUND AND FIXED (commit after this file) + +The in-inter `tx_depth` CDF row of a 1:4 strip came from the KEY FRAME's +deblock-grid approximation (`tx_size_context_rect`) instead of the real +`TXFM_CONTEXT` bands (`tx_size_context_txfm_rect`). The 2:1 arm +(decode.rs:7660) and the 16x4 strip (`decode_rect4_16_strip`) already switched +on `INTRA_IN_INTER_MODE`; `decode_block_rect4`, `decode_block_rect64`, +`decode_block_rect` and (sweep) `decode_leaf_rect`, `decode_leaf_rect8` did +not. + +Measured on the 2-frame cut (10-bit 1920x792, 128-superblock), decode-order +frame 1: the 32x8 `PARTITION_HORZ_4` strip at mi(48,176) read `tx_size_cat2` +row 1 where libaom reads row 2 (`EC_TXCTX ... above_px=16 left_px=32 ctx=1` +vs aomdec `ctx=2`). Ladder before: sustained divergence from mi(48,176). +Ladder after: exact through mi(40,221) (`tx_depth val=0 ctx=2 cat=1 +rng=40539` == aomdec), ~230 more oracle symbols. + +New rungs added so a ladder can see the symbol at all (this is what made r1's +bisection stop one block short): `EC_ISTEP ... name=tx_depth val= ctx= cat=` +in `decode_block_rect4` (cat 2), `decode_block_rect` (cat 2), +`decode_block_rect64` (cat 3), `decode_rect4_16_strip` (cat 1). + +## NEXT DIVERGENCE (exact, do not re-bisect) + +Block mi(40,222): strip 2 of a `PARTITION_VERT_4` of the 16x16 at mi(40,220) +(four 4x16 strips, cols 220..223; strip 0 inter, 1..3 intra-in-inter). +Everything through strip 1's luma TU matches. The first differing symbol is +strip 1's CHROMA `all_zero` (txb_skip): + +| | ours | aomdec | +|---|---|---| +| plane 1 `all_zero` (entry rng=37582) | ctx base **1** -> rng **37384** | ctx **9** (= base 2 + chroma offset 7) -> rng **51992** | +| plane 2 `all_zero` | ctx base 1 -> rng 36800 | ctx 9 -> rng 33312 | + +Same VALUES (1 then 0), different CDF ROW. Our chroma skip ctx is built at +`decode_rect4_16_strip`'s chroma call (`let skip_ctx = usize::from(around[plane].0) ++ usize::from(around[plane].1)`, decode.rs ~9480, feeding `read_coeffs_rect` +with `TxbSet::ChromaRect8x4`): the base is 1 where libaom's `get_txb_ctx` +gathers 2. The suspect is the chroma entropy-context map an INTER neighbour +writes (the strip's left/above chroma neighbour here is an inter block), i.e. +class `new-map-ignores-tile-edge` / `context-read-from-one-cell` on the chroma +side -- verify with `EC_DCDUMP`/`around_mi_rect` on the pair mi, and check +whether the inter chroma TU path records that map at all. Reproduce: + + systemd-run --user --scope -q -p MemoryMax=6G env EC_INTRA128_IN_INTER=1 \ + EC_TRACE_COEFF=1 /release/examples/decode_probe \ + ~/.cache/inter128intra-tmp/t900_2.obu 2>&1 | grep -n 'entry=37582' + + (oracle: `EC_TRACE_COEFF=1 ~/.cache/aom-oracle/build/aomdec --codec=av1 \ + -o /dev/null ~/.cache/inter128intra-tmp/t900_2.obu`, line ~475902.) + +## Film state (decode-order frame compare vs instrumented aomdec, EC_AV1_FINAL_DUMP) + +| cut | aomdec frames | ours | f0 | first differing frame | +|---|---|---|---|---| +| 2-frame cut of the 900 s cut | 2 | OK 1 shown | EXACT | 1 (1924240 B, was 2134171 B before the fix) | +| 2 s at 900 s | 267 | REFUSED Golomb tail after 2 | EXACT | 1 | +| 2 s at 5400 s | 275 | REFUSED Golomb tail after 10 | EXACT | 1 | +| 2 s at 6300 s | 125 | (run cut short) | EXACT | 1 | + +So the intra128 witness route is still blocked: no cut is exact through a +frame that fires `intra128_in_inter`, therefore NO fixture was pinned, NO +refusal was lifted, and `refusal_inventory.rs` / `gate_coverage.rs` are +untouched. `EC_INTRA128_IN_INTER` remains opt-in. + +## Suite + +Unit `t900-suite-r2-1788370358` (MemoryMax=10G), log `$HOME/.cache/t900-suite.log`, +was still running at the turn cap and is INCOMPLETE. What it had produced: +`a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact` +**FAILED** (no panic text captured yet -- the log was mid-run). That gate is +the prime suspect for the `decode_block_rect64` / `decode_leaf_rect*` arms of +the ctx switch: re-run it FIRST + + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900 EC_NOMEMGUARD=1 \ + EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ + a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus -- --nocapture + +and, if it is this lane's change, bisect the switch per reader (rect4 alone is +the measured one; rect64 / rect / leaf_rect / leaf_rect8 were a class sweep +with no measurement of their own -- reverting those four is the cheap +fallback). Note the sweep commit is SEPARATE from the measured rect4/rect64 +commit for exactly that reason. + +## Next step list + +1. Re-run the failing 16x4/rect64 gate; if red from this lane, bisect the five + ctx switches (rect4 is measured; the other four are unmeasured sweep). +2. Full suite as a systemd unit (COMMON recipe) and compare totals with + 424 passed / 1 pre-existing failure / 37 ignored. +3. Fix the chroma txb_skip ctx above; re-run the decode-order compare + (`~/.cache/t900-tmp/cmp.sh `, aomdec+ours EC_AV1_FINAL_DUMP, + per-frame byte diff) on `t900_2.obu` until frame 1 is exact. +4. Only then: pin the smallest exact firing prefix (census4/trunc.py) as + `crates/ec-av1/fixtures/reelc_intra128_witness.obu` (`git add -f`, hash + twice), gate every plane of every decode-order frame with a hard + `intra128_in_inter` counter assert, lift the refusal, drop + `EC_INTRA128_IN_INTER`, update `refusal_inventory.rs` + `gate_coverage.rs`. +5. Re-probe `~/.cache/reelc-0-10s.obu` (not run this round). + +## Artifacts + +- `~/.cache/t900-tmp/cmp.sh` -- decode-order frame compare (aomdec vs ours). +- `~/.cache/t900-tmp/{aom_full.trace,ours_full.trace}` -- mode/part ladders, + same round; `{aom_coeff.trace,ours_coeff.trace}` -- `EC_TRACE_COEFF` ladders. +- `~/.cache/t900-tmp/cuts.log` -- the film table above. +- Ladder matcher: greedy in-order match on `(mi_row, mi_col, name, rng)` of + `EC_ISTEP` lines with a 200-entry window -- `difflib` on the deduped rng + sequence is USELESS here (our extra rungs make every hunk an insert). diff --git a/lanes/t900-r3.handoff.md b/lanes/t900-r3.handoff.md new file mode 100644 index 00000000..3c521b87 --- /dev/null +++ b/lanes/t900-r3.handoff.md @@ -0,0 +1,127 @@ +# lane-t900 r3 handoff -- the non-chroma-reference inter block wiped its neighbours' chroma coefficient contexts + +Branch `lane-t900`, tip `f9720de` (merge of main `243f125` = `d61ac08`, then +the fix). Worktree `edith_codecs-t900`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900` +(a second `-t900-b` dir carried the release `decode_probe` while the gate unit +held the first). + +## STEP 0 -- merge of main `243f125` (commit `d61ac08`) + +Clean auto-merge, no conflicts (decode.rs + stream.rs + refusal_inventory.rs). +`cargo check -p ec-av1`: clean. + +Gates, unit `t900-gates-r3-1788370694`, log `$HOME/.cache/t900-gates-r3.log`, +filter `rect64_corner_tus hidden_arf refusal_inventory gate_coverage 1to4`: +**23 passed; 0 failed; 4 ignored** (122 s). Named ones: +`a_10bit_film_frames_with_rect64_corner_tus_decode_pixel_exact ... ok`, +`a_10bit_film_hidden_arf_with_split_superblock_strips_decodes_pixel_exact ... ok`, +every `refusal_inventory::*` and `gate_coverage::*` ok. So r2's five ctx +switches did NOT need bisecting -- the r2 red was the pre-rename gate, and the +renamed gate (rect64 asserts only) is green as merged. No revert was made. + +IMPORTANT for reproduction: main's re-added 16x4 refusal means this cut needs +**both** `EC_INTRA128_IN_INTER=1` and `EC_INTRA16X4_DECODE=1`; with only the +first, `t900_2.obu` stops at the intra 16x4/4x16-in-inter refusal. + +## ROOT CAUSE (fixed, `f9720de`) + +libaom codes no chroma transform for a block that is not the chroma reference +of its 4:2:0 pair -- `av1_reset_entropy_context`: +`nplanes = 1 + (num_planes - 1) * xd->is_chroma_ref` -- so such a block leaves +the above/left CHROMA entropy contexts untouched. Our INTER block reader +(`decode.rs`, the `record_split_luma_rect_mi` / `record_rect_mi` pair right +before the `pair_chroma` block, ~line 22955) wrote all three planes +unconditionally, and for a non-chroma-reference strip the chroma grids are the +all-zero ones built in the `!has_chroma` arm. So the EVEN 4x16 strip of the +`PARTITION_VERT_4` at mi(40,220) cleared the real left-neighbour chroma state, +and the PAIR's own `all_zero` then read `txb_skip_ctx` one row low. + +Measured, decode-order frame 1 of the 2-frame cut +`~/.cache/inter128intra-tmp/t900_2.obu` (10-bit 1920x792, 128 SB): + +| | before | after | aomdec | +|---|---|---|---| +| chroma `all_zero`, entry rng 37582 | ctx base 1 -> rng 37384 | ctx base **2** -> rng **51992** | ctx 9 (2+7) -> **51992** | + +`EC_DCDUMP` (now dumping all three planes, not plane 0 only -- without the +chroma cells the wipe is invisible) showed it directly: at strip 220's own +luma read `left[40..43][1] = Some(true)/1`; at strip 221's read the same cells +are `None/0`. The wiper is between them, i.e. strip 220's record. + +Fix shape: snapshot planes 1/2 of the block's left/above cells when +`!has_chroma` and restore them after the recorders run -- equivalent to not +writing them, without threading a flag through both recorders. + +Sibling sweep (class `context-read-from-one-cell` / `new-map-ignores-tile-edge`): +`decode_rect4_16_strip` writes chroma only under `if has_chroma`; the sub8 +intra rect reader early-returns on `!has_chroma` before its chroma block; +`decode_leaf_rect8`/`decode_leaf_split4` use `record_mi_luma*` (plane 0 only). +The inter reader was the only unguarded site. + +## LADDER STATE -- the whole 2-frame cut is now ENTROPY-EXACT + +Deduped `(all_zero value, rng)` sequence, ours vs instrumented aomdec, both +frames: **15865 symbols in each, identical value and range in order, no +mismatch**. (Do not diff `tag=eob` across decoders: aomdec prints an eob line +where our `read_plane` path prints none; the first "mismatch" at index 25 is +that rung-set gap, not a divergence.) + +## DECODE-ORDER COMPARE (`~/.cache/t900-tmp/cmp.sh`, both under EC_AV1_FINAL_DUMP) + +`t900_2.obu`: f0 EXACT, f1 differs by **114374 bytes** (was 1924240 before +this fix, 2134171 before r2's). The pre-loop-filter dumps (`EC_AV1_PREFILT_DUMP16`, +`~/.cache/t900-tmp/d_pf/`) differ too: f0 0 px, f1 105282 px. So what remains +is **reconstruction, not entropy** -- Y 82345 px max |d| 111, U 15362 max 148, +V 15073 max 162; dominant delta +1 (43448 px), then -1 (9742). + +## NEXT STEP (exact, do not re-bisect) + +First differing block in DECODE order (superblock (0,7), x896..1023 y0..127 -- +every earlier superblock is pixel-exact in the prefilter dump): + +* frame 1, mi(24,248) = px(992,96), `EC_PART bsize=9 value=1` (32x32 + PARTITION_HORZ -> two 32x16), top half `mode=13` (NEARESTMV) `ref0=5` + `mv0=(-166,354)` `motion_mode=0` `interp=0`, no `tx_depth` rung => skip + (pure prediction). +* Its 32x16 top half is off by **exactly -2 on every one of the 512 pixels** + (aom - ours = -2, no dither at all); the bottom 32x16 (rows 112..127, which + does carry residual) is a dithered mix of 0/-1/-2. +* NOTE the trace disagreement worth one check first: aomdec prints + `ref1=0` (INTRA_FRAME => interintra) for this block where OUR `EC_MODE_VAL` + prints `ref1=-1` (none), and our counters do report + `rect_wedge ... interintra=[5,6,2,4,0,0]` (4 of them 32x16). Either our + print normalises INTRA_FRAME to -1, or we are not applying interintra on + this block at all -- resolve that before touching the convolve. A uniform + (dither-free) offset over a whole skip block means a DC-only difference: + an unapplied/extra interintra blend term or an offset in the 10-bit + convolve rounding chain, NOT a filter-tap error (taps would dither). +* A hand-rolled 8-tap REGULAR prediction from the (exact) f0 reference at + mv (-20.75, +44.25) did NOT reproduce either decoder's pixels, so the + position/convention of that hand check was wrong -- do not trust it. + +Not this shape: there is NO intra 16x4/4x16 strip in superblock (0,7) +(`EC_INTRA16X4=1` list: nearest are mi cols 320+/172-175), and only 30 of the +107 strips in the frame overlap a diff at all -- the reconstruction defect is +NOT the 16x4 shape. + +`intra128_in_inter` is now **0** on this cut (it was 15 in r2, before the +chroma-ctx fix): those 128x64 intra-in-inter arrivals were desync artifacts, +exactly like wit16x4's phantom counters. So STEP 2 of the r3 charter (pin a +`reelc_intra128_witness.obu`, lift the refusal) has **no witness on this cut** +and must not be attempted from it. `EC_INTRA128_IN_INTER` stays opt-in; +`refusal_inventory.rs` / `gate_coverage.rs` untouched this round. + +## Not run this round + +Full suite (coordinator: no suite), the four 2 s cuts +(`~/.cache/rectres-tmp/{t900,t5400,t6300,t8100}.obu`) after the fix, and the +`~/.cache/reelc-0-10s.obu` re-probe. + +## Artifacts + +`~/.cache/t900-tmp/`: `cmp.sh` (now points at the `-t900-b` probe and passes +both env vars), `ours2.trace` (`EC_TRACE_COEFF` after the fix), +`ours_dc.trace` (`EC_DCDUMP`), `ours3.mode` (`EC_TRACE_MODE`/`EC_TRACE_PART`), +`i16.log` (`EC_INTRA16X4` strip list), `aom_coeff.trace` / `aom_full.trace` +(aomdec, r2, still valid -- entropy unchanged on that side), +`d_pf/` (prefilter dumps both decoders), `d_t900_2/` (final dumps).