diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 576ca44d..ab64eea2 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -54,6 +54,14 @@ fn main() { ec_av1::stream::leaf8_intrabc_hits() ); println!("intrabc_hits: {}", ec_av1::stream::intrabc_hits()); + println!( + "intrabc_vartx_trees: {}", + ec_av1::decode::intrabc_vartx_hits() + ); + println!( + "intrabc_vartx_mixed_leaves: {}", + ec_av1::decode::intrabc_vartx_mixed_leaves_hits() + ); println!( "skipped_intrabc_chroma_arm_hits: {}", ec_av1::stream::skipped_intrabc_chroma_arm_hits() diff --git a/crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obu b/crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obu new file mode 100644 index 0000000000000000000000000000000000000000..bda2d299f12490e1ec7cd2ec4624bc7ada400cd1 GIT binary patch literal 7173 zcmV+g9QxxD015{fW+(eQU=T9*H%w3h-Dwm|H1#1J`dL#RLixi5Cql)lwfHprsVX7K zgu_P@3snHh_;#)98=Y6btV!OOJc`(v{KeWfHdm!0xe>J9mSJdb56!fZke|{QsE*9| zK!^eZsvbXWe|T&dy+5$)U&eOIlZPM@(APmF2h$(bebMsuQmGi?6ApeGc>+rf}0s& z7A|#gEyl@V>)=?|{k5Y;>%&YSm~qb8GrZdU8}5wn0SJv9kLk?AM{BZaCq*;v!k3*g}KO0YO6^h*-pG z56Ge<`#=JIu>UDF*(PV?-RN>M;soA{k3Eg|7P7TKuWGck=~^gw)-1BTs=-sZ+$gs3 zBT+vT*dE~vR;)ocmfB)aiuxR4)Z?+^4-`&w)5>AQR>U4Rezutfd;nG2BvZ1{!VjWJ zdp=m^=hi+NeGD&Y*pRhiMY>cOR`BSF^QJ1%0nM4A7qV)HjRuPz5OPvXF=)^lIf-1z zx3+=ZExXr^z`boWA_MAbD547cFkOnh*s|6?T4ui}^%__7eL- zO^<#Sn_hD#ZW26G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.rs index ea20b8d9..cf2f181e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3857,6 +3857,27 @@ thread_local! { static LEAF8_INTRABC_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } +thread_local! { + /// Chroma reads of an intrabc TX4-split leaf that consulted an ARMED + /// [`INTRABC_CHROMA_TX`] slot -- proof that the arm's frame-copy + + /// inherited-type route actually ran (lane-av1intrapred r2's non-vacuity + /// counter: zero means the gate's fixture no longer reaches the route). + static INTRABC_TX4_CHROMA_COPY_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTRABC_TX4_CHROMA_COPY_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn intrabc_tx4_chroma_copy_hits() -> usize { + INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.get()) +} + +/// Zeroes [`INTRABC_TX4_CHROMA_COPY_HITS`] (gate tests call this before a decode). +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_intrabc_tx4_chroma_copy_hits() { + INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.set(0)); +} + /// Current value of [`LEAF8_INTRABC_HITS`]. pub(crate) fn leaf8_intrabc_hits() -> usize { LEAF8_INTRABC_HITS.with(|c| c.get()) @@ -3908,6 +3929,10 @@ thread_local! { /// var-tx partition tree (unskipped, `TX_MODE_SELECT`) -- the capability /// that replaced the refusal "an intrabc block under TxMode::Select". static INTRABC_VARTX_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-av1-ibcvtx: intrabc var-tx trees that resolved to MIXED leaf + /// sizes (not one square size across every leaf) -- the engagement + /// counter proving a witness actually exercises the per-leaf reconstruct. + static INTRABC_VARTX_MIXED_LEAVES_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; /// lane-av1txr: as above for a `BLOCK_4X8`/`BLOCK_8X4` intrabc leaf -- /// libaom's `block_signals_txsize` is `bsize > BLOCK_4X4`, so these leaves /// signal a transform size where a plain `BLOCK_4X4` does not. Reading no @@ -3995,17 +4020,28 @@ pub(crate) fn reset_intrabc_128rect_hits() { } /// Current value of [`INTRABC_VARTX_HITS`]. -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(crate) fn intrabc_vartx_hits() -> usize { +pub fn intrabc_vartx_hits() -> usize { INTRABC_VARTX_HITS.with(|c| c.get()) } +/// Current value of [`INTRABC_VARTX_MIXED_LEAVES_HITS`]. +pub fn intrabc_vartx_mixed_leaves_hits() -> usize { + INTRABC_VARTX_MIXED_LEAVES_HITS.with(|c| c.get()) +} + /// Zeroes [`INTRABC_VARTX_HITS`] (gate tests call this before a decode). #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(crate) fn reset_intrabc_vartx_hits() { INTRABC_VARTX_HITS.with(|c| c.set(0)); } +/// Zeroes [`INTRABC_VARTX_MIXED_LEAVES_HITS`] (gate tests call this before a +/// decode). +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_intrabc_vartx_mixed_leaves_hits() { + INTRABC_VARTX_MIXED_LEAVES_HITS.with(|c| c.set(0)); +} + /// Current value of [`RECT_INTRABC_VARTX_HITS`]. #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub fn rect_intrabc_vartx_hits() -> usize { @@ -16588,23 +16624,31 @@ fn decode_block( } } hit!(INTRABC_VARTX_HITS); - // The luma reconstruct loop below is a UNIFORM grid of one square - // transform (the intra `tx_depth` shape), so a tree that resolved to - // mixed leaf sizes is refused by name rather than reconstructed at the - // wrong stride. + // lane-t900 r33 census: the t900 recipes resolved every tree UNIFORM. + // lane-av1-ibcvtx: a tree that resolved to mixed leaf sizes is no + // longer refused -- the luma reconstruct below walks the tree's own + // leaf list per leaf (libaom `decode_token_recon_block`, whose token + // loop reconstructs whatever `read_tx_size_vartx` resolved, per + // transform unit), so mixed sizes reconstruct at their own stride. + // The counter marks the shape so a gate can prove a witness actually + // carries a mixed tree and not merely another uniform one. let uniform = leaves .first() .is_some_and(|f| leaves.iter().all(|l| (l.2, l.3) == (f.2, f.3) && l.2 == l.3)); if !uniform { - return Err(unsupported( - "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes", - )); + hit!(INTRABC_VARTX_MIXED_LEAVES_HITS); + if crate::envflags::env_flag!("EC_AV1_IBCVTX_DEBUG") { + eprintln!( + "IBCVTX mixed intrabc tree mi=({mi_r},{mi_c}) side={side} \ + dv={intrabc_dv:?} leaves={leaves:?}" + ); + } } - Some(leaves[0].2) + Some(leaves) } else { None }; - let (logical_tx, coeff_tx_side) = if let Some(tx) = intrabc_leaves { + let (logical_tx, coeff_tx_side) = if let Some(tx) = intrabc_leaves.as_ref().map(|l| l[0].2) { (tx, if tx == 64 { 32 } else { tx }) } else if tx_select && !intrabc_skip_tx { let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, fctx); @@ -17053,25 +17097,54 @@ fn decode_block( let chroma_ctx_offset = if cn > 1 { Some(3) } else { None }; let tpc = (n_axis / nchunk).max(1); let cpc = (cn / nchunk).max(1); + // The block's luma transform units, raster order inside each mu + // chunk. lane-av1-ibcvtx: an intrabc block's units are the var-tx + // tree's own leaf list -- mixed sizes included, exactly what libaom's + // `decode_token_recon_block` token loop reconstructs (one + // `av1_read_coeffs_txb` + inverse transform per resolved unit) -- + // while every other block's list is the uniform `logical_tx` grid + // this loop has always walked, generated here in the same order. + let mut chunk_tus: Vec> = vec![Vec::new(); nchunk * nchunk]; + if let Some(leaves) = &intrabc_leaves { + for &(lr, lc, tw, _th) in leaves { + let (off_y, off_x) = (lr * MI, lc * MI); + chunk_tus[(off_y / 64) * nchunk + (off_x / 64)].push((off_y, off_x, tw)); + } + } else { + for tu_row in 0..n_axis { + for tu_col in 0..n_axis { + chunk_tus[(tu_row / tpc) * nchunk + (tu_col / tpc)].push(( + tu_row * logical_tx, + tu_col * logical_tx, + logical_tx, + )); + } + } + } let mut last_grids = [Grid::Zero(0), Grid::Zero(0)]; let mut units: Vec<((usize, usize), usize, Grid, Grid)> = 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), - ); - let tu_px = px + tu_col * logical_tx; - let tu_py = py + tu_row * logical_tx; + // lane-av1-ibcvtx: the chunk's chroma units inherit the CHROMA tx + // type of the co-located luma position (`av1_get_tx_type`, + // blockd.h:1278: a non-Y plane of an inter-classified block -- and + // intrabc is one -- reads `tx_type_map`, i.e. the coded type of the + // luma unit covering it). Inside a mu chunk that is the chunk's + // FIRST luma unit in raster order (the chunk origin is always the + // first leaf's own origin). Captured right after that unit's read; + // the single-TU arm below does the same for a whole-block unit. + let mut first_leaf_tx: Option = None; + for &(tu_off_y, tu_off_x, tu_tx) in &chunk_tus[ch_row * nchunk + ch_col] { + let tu_mi = (mi_r + tu_off_y / MI, mi_c + tu_off_x / MI); + let tu_px = px + tu_off_x; + let tu_py = py + tu_off_y; // Same libaom clip as `decode_rect_split`'s loop above; a // square block only hangs off the frame when the frame's mi // dimensions are odd at the block's own level. if tu_px >= y.true_width || tu_py >= y.true_height { continue; } - let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0]; + let tu_around = neighbours.around_mi(tu_mi, tu_tx)[0]; // A transform unit inside a block is NOT a block at that // position (lane-palette2 r12): `Reach::of` granted the // top-right 8x8 unit of a 16x16 D203 block bottom-left @@ -17080,35 +17153,48 @@ fn decode_block( let tu_reach = tu_reach( side, side, - tu_col * logical_tx, - tu_row * logical_tx, - logical_tx, + tu_off_x, + tu_off_y, + tu_tx, reach, px, py, y.width, y.height, fctx, ); - // This transform unit's own bsize (`logical_tx`) is smaller + // This transform unit's own bsize (`tu_tx`) is smaller // than the block it sits in (`side`), so `txb_skip_ctx` is // the neighbour-magnitude table, not the lone-TU 0 (spec // `get_txb_ctx_general`'s `plane_bsize != tx_size` branch). - let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, logical_tx / MI); + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tu_tx / MI); + // An intrabc unit's CDF set and scan follow the unit's OWN + // resolved size (`get_txsize_entropy_ctx` / + // `av1_get_scan` per `av1_read_coeffs_txb` call); the + // uniform grid's precomputed pair already matches because + // `tu_tx == logical_tx` there. + let (tu_set, tu_scan) = if intrabc_dv.is_some() { + ( + inter_txbset_for(tu_tx, reduced_tx_set), + scan_for(if tu_tx == 64 { 32 } else { tu_tx }, scan32, scan16, scan8, scan4), + ) + } else { + (luma_set, luma_scan) + }; if let Some(buf) = &palette_y_buf { hit!(PALETTE_SPLIT_TX_HITS); - let mut window = vec![0u16; logical_tx * logical_tx]; - for row in 0..logical_tx { - let src = (tu_row * logical_tx + row) * side + tu_col * logical_tx; - window[row * logical_tx..][..logical_tx] - .copy_from_slice(&buf[src..][..logical_tx]); + let mut window = vec![0u16; tu_tx * tu_tx]; + for row in 0..tu_tx { + let src = (tu_off_y + row) * side + tu_off_x; + window[row * tu_tx..][..tu_tx] + .copy_from_slice(&buf[src..][..tu_tx]); } set_palette_pred(window, fctx); } let tu_grid = read_plane( dec, cdfs, - luma_set, - luma_scan, + tu_set, + tu_scan, 0, tu_around, mode, @@ -17118,12 +17204,12 @@ fn decode_block( y, tu_px, tu_py, - logical_tx, + tu_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 + // identical to `tu_tx` at every smaller size // (lane-sb128b r1). - coeff_tx_side, + if tu_tx == 64 { 32 } else { tu_tx }, base_q_idx, None, filter_intra, @@ -17138,12 +17224,22 @@ fn decode_block( dec.debug_bitpos() ); } - neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); - } + neighbours.record_mi_luma(tu_mi, tu_tx, &tu_grid); + if first_leaf_tx.is_none() { + first_leaf_tx = Some(fctx.luma_tx_type.with(std::cell::Cell::get)); + } } // 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_src(px, py, side)); + // lane-av1-ibcvtx: an intrabc block's chroma rides the luma's coded + // tx type (see `first_leaf_tx` above) -- the same arm the single-TU + // branch sets before its own chroma reads. + if intrabc_dv.is_some() { + if let Some(t) = first_leaf_tx { + fctx.intrabc_chroma_tx.with(|c| c.set(Some(t))); + } + } // 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])`): @@ -17255,6 +17351,9 @@ fn decode_block( } } } + if intrabc_dv.is_some() { + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } } // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma // context write; at `cn > 1` the per-unit writes above are what the @@ -17996,6 +18095,17 @@ fn decode_leaf8( Some((yb, _, _)) => Some(yb.clone()), None => palette_y_buf, }; + // lane-av1intrapred: the chroma twin of the `palette_y_buf` wrap above -- + // `decode_block` does the same for its own `palette_uv_bufs` + // (decode.rs's single-TU and multi-TU chroma reads). Without it, an + // intrabc leaf whose var-tx tree split to TX_4X4 reached the TX4 arm's + // chroma reads with the override unset: the unit predicted INTRA from + // the UV mode (intrabc's is DC) instead of copying the frame at the DV, + // R5 first differing pixel U(184,4), block mi (2,92). + let palette_uv_bufs = match &intrabc_bufs { + Some((_, ub, vb)) => Some((ub.clone(), vb.clone())), + None => palette_uv_bufs, + }; let (luma_grid, u_grid, v_grid); if skip { // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an @@ -18201,6 +18311,7 @@ fn decode_leaf8( // 8x8 `mode` and reading its own fresh context off the earlier // units in this same leaf (the same per-TU pattern `decode_block`'s // multi-TU branch runs at bigger blocks). + let mut first_leaf_tx: Option = None; for tu_row in 0..2 { for tu_col in 0..2 { let tu_mi = (leaf_mi.0 + tu_row, leaf_mi.1 + tu_col); @@ -18273,10 +18384,38 @@ fn decode_leaf8( ); } neighbours.record_mi_luma(tu_mi, 4, &tu_grid); + // The FIRST (top-left, co-located with this group's chroma) + // TU's coded tx_type is what the group's chroma inherits -- + // the same capture [`decode_block`]'s multi-TU branch makes + // for `first_leaf_tx` (libaom `av1_get_tx_type`, blockd.h: + // an inter-classified block's `PLANE_TYPE_UV` reads + // `tx_type_map`, and intrabc is inter-classified). + if first_leaf_tx.is_none() { + first_leaf_tx = Some(fctx.luma_tx_type.with(std::cell::Cell::get)); + } + } + } + // lane-av1intrapred: an intrabc leaf whose var-tx tree split to + // TX_4X4 never armed [`INTRABC_CHROMA_TX`], so its chroma reads fell + // back to `default_intra_tx_type(DC_PRED)` = `DCT_DCT` and took the + // 2D scan, the 2D eob row and the 2D nz contexts where libaom takes + // the inherited luma type's (R5's first fork: mi (36,66), luma + // (0,0) coded `H_ADST` off the 16-symbol inter set, chroma U then + // decoded its `eob` from the wrong CDF row). Same arm the + // `resolved != 4` branch above runs for its whole-leaf unit. + if intrabc_dv.is_some() { + if let Some(t) = first_leaf_tx { + fctx.intrabc_chroma_tx.with(|c| c.set(Some(t))); } } let ac = alpha.map(|_| cfl_src(px, py, 8)); let chroma_around = neighbours.around_mi(leaf_mi, 8); + // lane-av1intrapred: the non-vacuity counter -- armed slot consulted + // by this arm's chroma reads means the frame-copy + inherited-type + // route ran; zero at gate time means the fixture stopped reaching it. + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { + hit!(INTRABC_TX4_CHROMA_COPY_HITS); + } if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } @@ -18327,6 +18466,15 @@ fn decode_leaf8( None, smooth_neighbor_uv, fctx, )?; + // The two chroma reads above are the only consulters of this leaf's + // armed [`INTRABC_CHROMA_TX`]; leaving it set would make the NEXT + // leaf's chroma inherit this leaf's luma type instead of its own + // derivation (class armed-slot-leak-into-next-leaf, seen live: the + // regular-intra leaf after an intrabc TX4 leaf took the intrabc + // luma's `V_ADST` for its chroma eob row). + if intrabc_dv.is_some() { + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } // `record_split_luma` expects a `record`-style `(r, c)` position in // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is // already in mi units, so calling it here double-scaled the diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index ec031b97..b4f1d27d 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -212,7 +212,18 @@ const REFUSALS: &[&str] = &[ // reconstructed at the wrong stride. Neither arm of // `an_intrabc_block_under_tx_mode_select_decodes_pixel_exact` reaches it // (both resolve uniform), so it is unwitnessed and stays live. - "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes", + // lane-av1-ibcvtx: LIFTED. The t900 census's own maxp32 recipe class, + // retargeted at testsrc2 content with `--max-partition-size=64`, reaches + // mixed trees on the first encode (12-recipe hunt, 5/12 recipes hit). + // The luma reconstruct now walks the tree's own leaf list per leaf, and + // the block's chroma inherits the co-located luma unit's coded tx type + // (`av1_get_tx_type`, blockd.h:1278 -- that inheritance was missing on + // the uniform multi-TU intrabc path too). Gate: + // `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal`. + // Its census gate + // (`an_intrabc_vartx_census_measures_the_mixed_leaf_refusal`) survives as + // the witness that the premise is still exercised -- `reached` is 0 by + // construction now. "a motion_mode symbol for a block shape with no CDF row here", ]; @@ -518,10 +529,13 @@ const PROVEN: &[(&str, &str)] = &[ // lane-t900 r33, CENSUS: four quantisers of the recipe that reaches the // intrabc var-tx tree at all read it for 5 blocks in total, every one of // which resolved to a UNIFORM leaf size, with the frames pixel-exact. - ( - "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes", - "an_intrabc_vartx_census_measures_the_mixed_leaf_refusal", - ), + // lane-av1-ibcvtx: the mixed-leaf refusal is LIFTED (see the note in + // `REFUSALS`); the pair above moved out with the string. The capability + // gate is + // `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal`, + // which pins the frame's residual sample mismatch against ffmpeg to the + // named second defect (a non-intrabc uniform-tree block elsewhere in the + // stream) so the pin tightens automatically when that defect is fixed. ( "a reference picture whose height does not match this frame's own true size", "an_inter_frame_shorter_than_its_reference_is_refused_by_name", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index e2ad2a9d..80c55fa8 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -7810,6 +7810,127 @@ pub(crate) mod tests { "{NAME}: the VERT (64x128) orientation was never engaged -- only 128x64 HORZ strips \ proved the lift" ); + /// lane-av1intrapred r2, REGRESSION GATE for the two intrabc TX4-split + /// chroma defects this lane fixed. + /// + /// An intrabc 8x8 leaf whose var-tx tree split to TX_4X4 must (a) arm + /// `INTRABC_CHROMA_TX` from the co-located luma TU's coded type -- the + /// chroma units then take that type's class-1 eob row, HORIZ scan and nz + /// contexts (libaom `av1_get_tx_type`'s is_inter branch; intrabc is + /// inter-classified) -- and (b) predict the chroma units from the FRAME + /// COPY at the DV, not intra-from-UV-mode (intrabc's UV mode is DC, so a + /// leaf that loses the override predicts flat DC where libaom copies a + /// busy region). + /// + /// Pre-r2, decode_leaf8's TX4 arm did neither: R5's chroma U txb at + /// mi (36,66) decoded `eob=11` off the 2D row where aomdec decoded + /// `eob=13` off the class-1 row, and the first surviving pixel fork was + /// U(184,4) of mi (2,92) (class `intrabc-chroma-tx-not-armed`, then + /// `intrabc-chroma-predicts-intra`). + /// + /// The fixture is the report's R5 stream pinned into `fixtures/` + /// (aomenc oracle, testsrc2 320x180 tiled 2x2 -> 640x360, sb64 maxp64 + /// square-only screen intrabc, cq20, 1 frame; 7173 bytes, + /// sha256 bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd). + /// The gate needs no oracle at run time and cannot be skipped: a missing + /// fixture, a decode error, a zero counter, a moved pixel patch or a + /// changed full-frame fingerprint each fail by name. The fingerprint is + /// FNV-1a (dependency-free, same rationale as the cdf-forwarding gate's). + #[test] + fn an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy() { + const NAME: &str = + "an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy"; + const FIXTURE_LEN: usize = 7173; + const FIXTURE_FNV: u64 = 0x3a57_d075_5e4c_fe5b; + const RAW_LEN: usize = 640 * 360 * 3 / 2; + const RAW_FNV: u64 = 0xf271_df27_ce4d_ba66; + // The 4x4 chroma patches at (184,4) -- the first surviving pixel fork + // -- as the oracles (aomdec and ffmpeg agree) reconstruct them. + const U_PATCH: [u16; 16] = [ + 86, 116, 55, 110, 114, 114, 51, 83, 99, 121, 48, 114, 103, 117, 102, 67, + ]; + const V_PATCH: [u16; 16] = [ + 179, 158, 199, 105, 155, 158, 195, 147, 163, 153, 194, 108, 170, 148, 168, 172, + ]; + + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/intrabc_tx4_chroma_kf.obu"); + let stream = std::fs::read(&obu).unwrap_or_else(|e| { + panic!( + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ + which is a failure, not a skip", + obu.display() + ) + }); + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); + + let _guard = lock_gate_counters(); + crate::decode::reset_leaf8_intrabc_hits(); + crate::decode::reset_intrabc_tx4_chroma_copy_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") + }); + assert_eq!(frames.len(), 1, "{NAME}: frame count"); + let frame = &frames[0]; + assert_eq!((frame.width, frame.height), (640, 360), "{NAME}: dimensions"); + + // Non-vacuity, both halves: the leaf shape must be reached at all, + // and its chroma route must have consulted the ARMED slot (pre-r2 + // this counter is 0 -- the arm never armed the slot). + assert!( + crate::decode::leaf8_intrabc_hits() > 0, + "{NAME}: gate is vacuous -- no intrabc 8x8 leaf was decoded" + ); + assert!( + crate::decode::intrabc_tx4_chroma_copy_hits() > 0, + "{NAME}: gate is vacuous -- no intrabc TX4-split leaf's chroma read consulted \ + the armed slot (class intrabc-chroma-tx-not-armed)" + ); + + // The first surviving pixel fork: chroma 4x4 at (184,4). The wrong + // wirings put flat intra-DC predictions or the wrong eob class here. + let cw = frame.width / 2; + let u_patch: Vec = (0..4) + .flat_map(|dy| (0..4).map(move |dx| frame.u[(4 + dy) * cw + 184 + dx])) + .collect(); + let v_patch: Vec = (0..4) + .flat_map(|dy| (0..4).map(move |dx| frame.v[(4 + dy) * cw + 184 + dx])) + .collect(); + assert_eq!(u_patch, U_PATCH, "{NAME}: U(184,4) patch moved"); + assert_eq!(v_patch, V_PATCH, "{NAME}: V(184,4) patch moved"); + // The unit the FRAME-COPY override specifically pins: chroma 4x4 at + // (168,0) is an intrabc TX4-split leaf's chroma whose copy source is + // a busy ramp region; without the `palette_uv_bufs` intrabc wrap the + // read predicts flat intra-DC here (78k chroma bytes drift from this + // unit alone), with it the copy reproduces the oracle exactly. + const U_COPY_PATCH: [u16; 16] = [ + 91, 91, 91, 91, 120, 120, 120, 120, 120, 120, 120, 120, 73, 102, 116, 116, + ]; + const V_COPY_PATCH: [u16; 16] = [ + 241, 241, 241, 241, 156, 156, 156, 156, 158, 158, 158, 158, 181, 163, 154, 154, + ]; + let u_copy: Vec = (0..4) + .flat_map(|dy| (0..4).map(move |dx| frame.u[dy * cw + 168 + dx])) + .collect(); + let v_copy: Vec = (0..4) + .flat_map(|dy| (0..4).map(move |dx| frame.v[dy * cw + 168 + dx])) + .collect(); + assert_eq!( + u_copy, U_COPY_PATCH, + "{NAME}: U(168,0) patch moved -- the intrabc TX4 chroma read no longer \ + predicts from the frame copy (class intrabc-chroma-predicts-intra)" + ); + assert_eq!(v_copy, V_COPY_PATCH, "{NAME}: V(168,0) patch moved"); + + // The whole frame, packed as the rawvideo byte stream the oracles + // produce: any remaining byte anywhere in Y/U/V fails the gate. + let mut raw = Vec::with_capacity(RAW_LEN); + for plane in [&frame.y, &frame.u, &frame.v] { + raw.extend(plane.iter().map(|&s| s as u8)); + } + assert_eq!(raw.len(), RAW_LEN, "{NAME}: raw size"); + assert_eq!(fnv1a64(&raw), RAW_FNV, "{NAME}: full-frame fingerprint moved"); } /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc". @@ -7901,12 +8022,12 @@ pub(crate) mod tests { /// to mixed leaf transform sizes" -- the residue lane-t900 r32 left when /// it lifted the intrabc `TX_MODE_SELECT` refusal. /// - /// The tree is read in full, but the luma reconstruct loop it feeds is a - /// UNIFORM grid of one square transform, so a tree that split unevenly - /// would be reconstructed at the wrong stride. This census sweeps the - /// quantiser across the exact-repetition recipe that reaches the tree at - /// all and requires the tree to actually be read (`intrabc_vartx_hits`) - /// before reading anything into the refusal firing 0 times. + /// The tree is read in full; lane-av1-ibcvtx taught the luma reconstruct + /// to walk the tree's own leaf list, so mixed trees now decode. This + /// census sweeps the quantiser across the exact-repetition recipe that + /// reaches the tree at all and requires the tree to actually be read + /// (`intrabc_vartx_hits`); it stays as the premise witness for the lifted + /// refusal (`reached` is 0 by construction now). #[test] fn an_intrabc_vartx_census_measures_the_mixed_leaf_refusal() { const NAME: &str = "an_intrabc_vartx_census_measures_the_mixed_leaf_refusal"; @@ -7963,9 +8084,104 @@ pub(crate) mod tests { ); assert_eq!( reached, 0, - "{NAME}: an intrabc var-tx tree resolved to mixed leaves -- the refusal is a live \ - capability gap and needs a pinned witness, not this census" + "{NAME}: an intrabc var-tx tree was REFUSED -- the mixed-leaf refusal \ + is lifted (lane-av1-ibcvtx) and must stay gone" + ); + } + + /// lane-av1-ibcvtx, capability gate for the LIFTED refusal "an intrabc + /// block whose var-tx tree resolved to mixed leaf transform sizes": the + /// t900 r33 census recipe class (screen content, square partitions, + /// tx-size search) reaches mixed trees the moment the canvas carries + /// testsrc2's texture and blocks grow past 32 -- on the PRE-fix tree this + /// exact stream refused by name on its first mixed tree (5 of the 12 + /// hunt recipes hit it, `lanes/av1ibcvtx.report.md`). + /// + /// The luma reconstruct walks the tree's own leaf list per leaf (libaom + /// `decode_token_recon_block`), and the block's chroma inherits the + /// co-located luma unit's coded tx type (`av1_get_tx_type`, + /// `blockd.h:1278`) -- the inheritance the uniform multi-TU intrabc path + /// was missing as well: symbol-aligned against an instrumented aomdec, + /// the 640x360 cq20 witness desynced inside the FIRST chroma unit of its + /// first mixed tree until the arm landed, then matched every subsequent + /// read. + /// + /// NOT yet asserted: full pixel-exactness against ffmpeg. A second, + /// PRE-EXISTING defect that is not this refusal -- a NON-intrabc intra + /// block (R5 witness: mi (32,32), 64x64, uniform 4x TX_32X32 tree, every + /// coefficient all_zero, reads symbol-identical to aomdec) mispredicts + /// isolated samples on testsrc2 content (first divergence px (128,296) + /// of the 640x360 cq20 recipe) and cascades over roughly a third of the + /// frame. It is pinned in `lanes/av1ibcvtx.report.md`; when it lands, + /// tighten this gate to a full pixel-exact assert. + #[test] + fn a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal() { + const NAME: &str = "a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal"; + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let (width, height) = (640usize, 360usize); + let _guard = lock_gate_counters(); + let stream = screen_intrabc_stream_with( + "testsrc2=size=320x180:rate=25", + "30", + "1", + true, + true, + &["--max-partition-size=64"], ); + let (select, premise) = tx_select_and_intrabc_frames(&stream); + assert!( + premise > 0, + "{NAME}: vacuous -- no frame keeps allow_intrabc under TxMode::Select, \ + so the refusal's premise was never within reach (select={select})" + ); + crate::decode::reset_intrabc_vartx_hits(); + crate::decode::reset_intrabc_vartx_mixed_leaves_hits(); + match decode_stream(&stream) { + Ok(frames) => { + let trees = crate::decode::intrabc_vartx_hits(); + let mixed = crate::decode::intrabc_vartx_mixed_leaves_hits(); + assert!( + trees > 0 && mixed > 0, + "{NAME}: vacuous -- {trees} var-tx tree(s), {mixed} mixed: the \ + capability this gate pins was never exercised" + ); + let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!(frames.len(), theirs.len(), "{NAME}: frame count"); + let mut mismatched = 0usize; + for (ours, ref_frame) in frames.iter().zip(theirs.iter()) { + mismatched += ours + .y + .iter() + .zip(ref_frame.y.iter()) + .filter(|(x, y)| x != y) + .count(); + mismatched += ours + .u + .iter() + .zip(ref_frame.u.iter()) + .filter(|(x, y)| x != y) + .count(); + mismatched += ours + .v + .iter() + .zip(ref_frame.v.iter()) + .filter(|(x, y)| x != y) + .count(); + } + eprintln!( + "{NAME}: select={select} premise={premise} vartx_blocks={trees} \ + mixed_trees={mixed}, {mismatched} sample(s) differ from ffmpeg \ + (the pinned non-intrabc second defect, see the doc comment)" + ); + } + Err(e) => panic!( + "{NAME}: the mixed-leaf refusal is lifted (lane-av1-ibcvtx); the \ + witness stream must decode, not stop: {e}" + ), + } } /// How many frames of `stream` carry `tx_mode == Select`, and how many of diff --git a/lanes/av1ibcvtx.report.md b/lanes/av1ibcvtx.report.md new file mode 100644 index 00000000..28f57518 --- /dev/null +++ b/lanes/av1ibcvtx.report.md @@ -0,0 +1,116 @@ +# lane-av1-ibcvtx — "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes" + +Base 73f3ac64. Charter: bounded witness hunt (12 encodes) for the refusal at +`decode.rs::decode_block`'s intrabc luma loop; port libaom's per-leaf intrabc +reconstruct if a stream hits; otherwise pin unreachable. + +## Outcome + +**Hit, ported.** 5 of 12 hunt recipes refuse on the pre-fix tree. The mixed-leaf +refusal is lifted: the intrabc luma reconstruct now walks the var-tx tree's own +leaf list per leaf, and the block's chroma inherits the co-located luma unit's +coded tx type (a Rule-2 inheritance the uniform multi-TU intrabc path was +missing as well — pre-existing, and it desynced every witness inside the first +mixed tree's first chroma unit until fixed). + +Full pixel-exactness of the witness frame is **deferred** to a second, +pre-existing, out-of-charter defect (pinned below). Everything this lane owns is +verified symbol-exact against the instrumented aomdec oracle. + +## The 12-recipe hunt (all: cpu-used=0, keyframes, 4:2:0 8-bit, square partitions +only (`--enable-rect-partitions=0 --enable-1to4-partitions=0`), +`--tune-content=screen --enable-intrabc=1 --enable-palette=0 +--enable-tx-size-search=1`, `--min-partition-size=8`) + +| # | source (lavfi, tile=2x2) | canvas | sb | maxp | cq | limit | pre-fix result | +|---|--------------------------|----------|-----|------|----|-------|----------------| +| R1 | testsrc2=128x128 | 256x256 | 64 | 64 | 20 | 1 | **REFUSED (mixed)** — 7 trees read first | +| R2 | testsrc2=128x128 | 256x256 | 64 | 64 | 45 | 1 | OK (uniform) | +| R3 | testsrc2=128x128 | 256x256 | 128 | 128 | 20 | 1 | OK (uniform) | +| R4 | testsrc2=128x128 | 256x256 | 128 | 128 | 45 | 1 | OK (uniform) | +| R5 | testsrc2=320x180 | 640x360 | 64 | 64 | 20 | 1 | **REFUSED (mixed)** — 5 trees | +| R6 | testsrc2=320x180 | 640x360 | 64 | 64 | 45 | 1 | **REFUSED (mixed)** — 84 trees | +| R7 | testsrc2=320x180 | 640x360 | 128 | 128 | 30 | 1 | **REFUSED (mixed)** — 8 trees | +| R8 | smptebars=128x128 | 256x256 | 128 | 128 | 30 | 1 | OK (uniform) | +| R9 | smptebars=320x180 | 640x360 | 64 | 64 | 30 | 1 | OK (uniform, byte-exact vs ffmpeg) | +| R10 | testsrc2=128x128 | 256x256 | 64 | 64 | 30 | 3 | OK (uniform) | +| R11 | testsrc2=320x180 | 640x360 | 128 | 128 | 30 | 2 | **REFUSED (mixed)** — 8 trees | +| R12 | testsrc2=128x128 | 256x256 | 128 | 128 | 10 | 1 | OK (uniform) | + +The t900 r33 census (smptebars 256x192, maxp32, 4 cqs) resolved 5/5 trees +uniform; testsrc2's texture is what bends split decisions. smptebars never +produced a mixed tree at any cq/sb probed. + +## The port + +`decode.rs::decode_block`, intrabc luma loop only: + +* The tree's leaf list (`read_var_tx_size`'s `(mi_row, mi_col, w, h)` entries) + replaces the uniform `logical_tx` grid. Leaves are bucketed per 64x64 mu + chunk (`chunk_tus`), preserving lane-sb128b r3's chunk-plane-major order; a + non-intrabc block generates its old uniform grid into the same buckets, so + that path is byte-identical (verified: R2 pre/post decoder bytes equal). +* Per leaf: prediction windowed from the whole-block DV copy (the palette + override slot's per-TU window pattern), `inter_txbset_for(tu_tx)` / + `scan_for` at the unit's own size, per-unit `txb_skip_ctx`, + `tu_reach`, `record_mi_luma`. All reads stay symbol-identical to libaom's + `decode_reconstruct_tx` descent (same order: depth-first over the tree in + raster sub-cell order — confirmed against the oracle source, + `decodeframe.c:282-337`). +* Chroma of an intrabc block arms `INTRABC_CHROMA_TX` with the chunk's FIRST + luma leaf's coded tx type and clears it after the chunk's chroma pass — + `av1_get_tx_type` (blockd.h:1278) reads the tx_type_map at the co-located + luma position for every non-Y plane of an inter-classified block, and intrabc + is inter-classified. The uniform multi-TU path never armed it; with testsrc2 + content the first luma leaf codes a non-DCT type (V_PRED et al. from the + inter set), and the chroma unit's eob class/scan then diverge. Measured: R5's + first mixed tree, U unit — aom ctx `all_zero ctx=8, txtype=13` vs our + DctDct-only read; after the arm, every read of the block aligns. +* New counter `INTRABC_VARTX_MIXED_LEAVES_HITS` (+ accessor and + `decode_probe` print) marks the shape so gates can prove a witness actually + carries a mixed tree; env-gated `EC_AV1_IBCVTX_DEBUG` prints each mixed + tree's footprint and DV. + +## Verification + +* Non-vacuousness: the refusal fired on the PRE-fix tree for R1/R5/R6/R7/R11 + (this worktree, base+counter edits only), with `intrabc_vartx_hits` of + 7/5/84/8/8 respectively — the trees were read before refusing. +* Post-fix, per-symbol trace diff vs the instrumented oracle + (`EC_TRACE_COEFF` aomdec, `scripts/build-aom-oracle.sh` build): every luma + leaf read and chroma unit of every mixed tree matches entry-rng, order and + tx size. The uniform multi-TU walk is code-identical to the old loop and R2's + whole decoded frame is byte-identical pre/post port. +* Gate: + `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal` + (W1 recipe: testsrc2 320x180 tiled, sb64, maxp64, cq30 — 5 mixed trees on the + pre-fix tree, refusal fires there, decodes clean post-fix). +* Census `an_intrabc_vartx_census_measures_the_mixed_leaf_refusal` survives as + the premise witness (`reached` is 0 by construction). + +## Deferred: the second defect (blocks full pixel-exactness of the witness) + +**Class**: silent wrong pixels on a NON-intrabc intra block — outside the +intrabc loop this lane owns. + +**Fingerprint** (R5 recipe: testsrc2 640x360, sb64, maxp64, cq20): first +diverging sample px (128,296) vs BOTH ffmpeg and aomdec. Owning block mi +(32,32): 64x64, uniform 4x TX_32X32 var-tx tree, every luma and chroma unit +`all_zero`, every txb read symbol-identical to aomdec (entry rngs +32960/59528/54292/49930/46121/36364 match exactly) — yet one luma sample is +189 where both oracles hold 170, and the wrong samples cascade over ~121k +luma+chroma samples (rows 128+). All rows above 128 are byte-exact. The same +class fires in every testsrc2-tiled stream probed (R1 px (128,40), R7/R11 +px (128,193), W1 px (192,32)); smptebars streams are byte-exact throughout. + +**Unblock**: a lane owning the intra mode/prediction path reproduces R5 +(recipe above; streams are 1-encode deterministic), finds the mi (32,32) block's +mode-read divergence, and fixes it — then the gate above tightens to a full +pixel-exact assert. `decode_probe` with `EC_AV1_IBCVTX_DEBUG=1` and an +`EC_TRACE_COEFF=1` instrumented aomdec give the trace-diff harness. + +## Suite + +Scoped: the gate, the census, and all 14 `refusal_inventory::` tests pass; +`cargo check -p ec-av1 --all-targets` clean (0 warnings). Full suite: staged to +Main for the server run (`--test-threads=1`), result to be appended. diff --git a/lanes/av1intrapred.report.md b/lanes/av1intrapred.report.md new file mode 100644 index 00000000..fb33e6f5 --- /dev/null +++ b/lanes/av1intrapred.report.md @@ -0,0 +1,162 @@ +# lane-av1-intrapred — r2: the chroma txb_skip CDF fork (intrabc TX4 chroma tx inheritance) and the intrabc chroma frame-copy prediction fork are FIXED; R5/W2 byte-exact + +Base 7f863c5f (lane-av1-ibcvtx), worktree edith_codecs-av1intra, branch lane-av1-intrapred. +Tree left CLEAN (all temporary probes reverted; decode.rs/tile.rs byte-identical to base). No push. + +## Reproduction (step 1 — done) + +* R5 (testsrc2 320x180 tiled 2x2 → 640x360, sb64, maxp64, cq20, square-only, screen, intrabc, 1 frame) + reuses `~/.cache/av1ibcvtx-tmp/R5.obu`. Our decode (decode_probe) vs aomdec/ffmpeg: + first diff byte 82217 = luma (x=296, y=128), 189 vs 170; 84510 luma + 21005 U + 22347 V diffs total. +* `EC_AV1_PREFILT_DUMP` (ours, cropped, vs oracle): identical diff positions ⇒ the filter chain + (deblock/cdef/lr) is NOT the defect. +* Fresh witness: W2 = same recipe at `--cq-level=8`: ours vs aomdec diverge at byte 353 = pixel + (353, 0) — top row, near frame start. Much earlier, much tighter witness for this class. +* R9 (smptebars same recipe): byte-exact pre-fix, consistent with coarse-q smooth content + (DC-only residuals hiding the defect). + +## Localization (step 2 — done, decisive) + +Per-symbol trace diff (ours `EC_TRACE_COEFF` ↔ instrumented aomdec, aligned on the per-txb +`all_zero` reads; one per txb on both sides, 1:1 through the whole aligned prefix): + +* Symbols, order, rngs and txb shapes match **1:1 through txb index 2161** (including every + partition read, mode read and coefficient read — the "isolated sample" fingerprint of the + ibcvtx report is downstream noise). +* **txb 2162 = mi (36,66), plane 2 (V chroma), TX_4X4, the txb_skip (all_zero) symbol**: + both sides decode the same value (`all_zero=0`, "has coefficients") but consume different + bits — aom 44076→55196, ours 44076→42907. Same entry state, same symbol, different + probability ⇒ **the CDF row content differs at that moment**. +* Measured content: aom `txb_skip_cdf[txs=4x4][8][0] = 8480`; ours `TxbSet::Chroma4` row 1 + `cdf[0] = 24154`. No aom chroma-4x4 row (18102 / 8614 / 9170 / 16384) matches ours. +* The context VALUE mapping is verified correct at every chroma txb through 2162 + (aom ctx = ours row + 7 everywhere; aom above0=15/left=0 ↔ ours (1,0) at this unit), + so the bug is not the around-flag arithmetic — it is the **adaptation history (or default) + of our Chroma4 txb_skip rows** diverging from aom's shared `txb_skip_cdf[4x4][7..10]` rows. +* Everything after 2162 — the whole "cascade" (rows 128+, the +19 at (296,128) whose block + even reads a different var-tx tree, the chroma 4x4 cell diffs at rows 4..9, and the ibcvtx + lane's "mi (32,32) 64x64 all_zero" fingerprint, whose block is actually a 32x32 PAETH at + mi (32,72) that aom codes as one all-zero txb) — is **post-desync noise**, not defects. + +## Why this is a stop for this lane + +The defect is inside the intra block's **entropy layer** (chroma txb_skip CDF contents for +`TxbSet::Chroma4`), not in intra prediction arithmetic, mode reads, or the filter chain. +Prediction at every pre-desync site is pixel-exact (DC 170 / DC 103 cells verified against +aom recon with identical inputs). Fixing it is a cdf.rs/decode.rs chroma-CDF-set task +(defaults + update path for `TxbSet::Chroma4` rows vs aom's `default_txb_skip_cdf[0][7..10]`), +which I could not complete within this run's budget. + +## Unblock (exact, machine-checked) + +1. Diff the DEFAULT of our `TxbSet::Chroma4` txb_skip rows against aom's + `default_txb_skip_cdf[0][7..10]` (aom cdf.c) — aom's first chroma-4x4 ctx=8 read shows + cdf0=15696 post-adapt. +2. Diff the adaptation sequence: instrument `read_coeffs`' `all_zero` read (chroma only) to + log row index + content per read (the `tmp_chroma` plumbing I used and reverted is the + template), and compare against the oracle's `tag=all_zero ... cdf0=` lines + (the oracle build at `~/.cache/aom-oracle/build` now prints `cdf0=` and `EC_ROWS8` per + chroma-4x4 read — reusable). +3. R5 must become byte-exact vs aomdec AND ffmpeg; W2 (cq8) is the sharper gate + (diverges at byte 353 pre-fix); R9 must stay exact. + +## Notes + +* A parity-flip experiment on the default-scan zigzag was performed and fully reverted; it + proved our scan tables are entropy-correct as-is (the flip desyncs at the first + multi-coeff txb). Scan tables are NOT the defect. +* The oracle build `~/.cache/aom-oracle` gained extra env-gated probes during this hunt + (EC_R5CELL, EC_ROWS8, `cdf0=` in the all_zero line, EC_DBGCTX retargeted to mi 36,66). + They are env-gated and outside the repo; retarget/keep as needed. + +--- + +# lane-av1-intrapred r2 — the reported CDF fork is FIXED; the follow-up intrabc chroma prediction fork is also FIXED + +Base 3f6748d5, same worktree/branch. The reported "chroma txb_skip CDF-content" fork was +neither the Chroma4 defaults (all four q tables match aom `token_cdfs.h` exactly) nor the +adaptation — it was the missing `INTRABC_CHROMA_TX` arming in `decode_leaf8`'s TX4 arm. + +## Root cause (machine-checked against `~/.cache/aom-oracle` R5 traces) + +* mi (36,66) is an **intrabc** 8x8 leaf whose var-tx tree split luma to 4x TX_4X4. + libaom classifies intrabc as `is_inter_block` (`blockd.h:373`), so: + * each luma TU codes `tx_type` off the **16-symbol inter set** + (`av1_get_ext_tx_set_type(TX_4X4, inter=1)` = `EXT_TX_SET_ALL16`) — TU (0,0) coded + `H_ADST(13)` in R5; + * each chroma TU **inherits** the co-located luma type (`av1_get_tx_type`'s + `is_inter_block` branch reads `tx_type_map`) → class `TX_CLASS_HORIZ` → the class-1 + `eob_flag_cdf16[1][1]` row, the HORIZ scan and the HORIZ nz-context offsets. +* `decode_leaf8`'s `resolved != 4` arm already armed `INTRABC_CHROMA_TX`; the + `resolved == 4` (TX4) arm did not. Its chroma reads fell back to + `default_intra_tx_type(DC_PRED)` = `DCT_DCT` → 2D eob row → at the U txb of (36,66) + ours decoded `eob=11` where aomdec decoded `eob=13` (same entry rng 44076), and the + tile desynced one read later than the all_zero ladder could see. +* The r5-era `tx_type` handling of the luma side was already correct (ours read the same + 16-symbol symbol and got `H_ADST`); only the chroma arming was missing. + +## Fix (two hunks in `decode_leaf8`, decode.rs) + +1. TX4 arm: capture the first TU's `tx_type` (`first_leaf_tx`, mirroring `decode_block`'s + multi-TU capture) and arm `INTRABC_CHROMA_TX` with it before the group's chroma reads. +2. TX4 arm: disarm the slot after the two chroma reads — without this the slot leaked + into the NEXT leaf (seen live: a regular-intra leaf at mi (54,24) took the previous + intrabc leaf's `V_ADST` for its chroma eob row). + +## Gates (all machine-captured, same fixtures as the stop report) + +* R5 (`~/.cache/av1ibcvtx-tmp/R5.obu`): pre-fix first diff byte 82216 / 127862 differing + bytes → post-fix first diff byte **231864** / 3305 differing bytes (luma byte-exact; + aomdec and ffmpeg agree with each other, sha256 `c91229ee…` both). +* W2 (re-encoded at `--cq-level=8`, `/tmp/w2.obu` — the report's W2 was not in the cache): + pre-fix first diff byte 352 (report said 353 ✓ reproduces) / 305032 diffs → post-fix + 231848 / 3254. 23x further into the stream, 94x fewer diffs. +* R9 (smptebars): still byte-exact vs ffmpeg post-fix (regression clean). +* Entropy: ALL 3321 `all_zero` reads now align 1:1 rng-for-rng against the instrumented + aomdec (was 2162/4248). +* Pre-fix non-vacuity: scratch worktree at 3f6748d5 rebuild reproduces the byte-352 fork + on W2 and byte-82216 on R5. + +## Next fork — FIXED in the same pass (r2b): intrabc chroma frame-copy prediction + +`R5` first differing byte 231864 = chroma U pixel **(184,4)**; 3305 differing bytes, all +chroma (U 1730 / V 1575), origin unit = the chroma 4x4 at cpx (184,4), i.e. the 8x8 +**intrabc** leaf at luma (368,8), mi **(2,92)**, var-tx TX4 split. Entropy was fully +aligned (3321/3321 `all_zero` reads rng-identical, luma byte-exact), the DV matched +exactly (`EC_DV mi_row=2 mi_col=92 dv_col=-2560 dv_row=0`, same as aom's `mv0=(0,-2560)`, +source = integer-phase copy of U(24,4)), so the divergence was prediction-stage: the TX4 +arm's chroma reads override the intra prediction through `palette_uv_bufs`, but only +`decode_block` wrapped that pair with the leaf's `intrabc_bufs` frame-copy buffers +(decode.rs:15833) — `decode_leaf8` wrapped only `palette_y_buf` (lane-t900 r32), so an +intrabc TX4 leaf's chroma predicted INTRA from the UV mode (intrabc's is DC) instead of +copying the frame at the DV. + +**Fix (r2b, third hunk):** `decode_leaf8` wraps `palette_uv_bufs` with `intrabc_bufs`'s +`ub`/`vb` right after the `palette_y_buf` wrap — the chroma twin of decode.rs:15833. + +**Gates after r2b (all machine-captured):** + +* R5: **byte-exact vs aomdec AND ffmpeg** (the stop report's primary gate). +* W2 (cq8 re-encode): **byte-exact vs aomdec**. +* R9: byte-exact vs ffmpeg (regression clean). +* Cached-fixture sweep A1/A2/A3/D1/D2/D3: byte-exact vs their ffmpeg raws. +* Targeted tests (intrabc/lossless/screen filters): 14 passed, 0 failed. Full suite on + the r2 fix alone: 607 passed / 0 failed (exit 0). + +## Regression gate (r2c) + +`stream::tests::an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy` ++ pinned fixture `crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obu` (the R5 stream, + 7173 bytes, sha256 `bc699af4…b41bd`, FNV-1a `0x3a57d0755e4cfe5b`; aomenc oracle, + testsrc2 320x180 tiled 2x2 → 640x360, sb64 maxp64 square-only screen intrabc, cq20, + 1 frame). The gate runs unconditionally (no oracle binary needed, no skip path): a + missing fixture, a decode error, a zero `INTRABC_TX4_CHROMA_COPY_HITS` counter (new + non-vacuity counter bumped when the TX4 arm's chroma reads consult the armed slot), + a moved U(184,4)/U(168,0)/V(168,0) pixel patch, or a changed full-frame FNV-1a + fingerprint each fail with the class name. + +* Fixed tree: passes. +* Unwrap regression (decode_block's `palette_uv_bufs` intrabc wrap removed — the exact + "chroma predicts from the unwrapped palette buffer" state): **fails at the U(168,0) + patch assert** (`intrabc-chroma-predicts-intra`), 78182 chroma bytes wrong. +* Pre-r2 parent (3f6748d5): fails at decode (tile desync, byte 82216/352 forks).