diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 2d3a9fc6..01e96969 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/src/decode.rs b/crates/ec-av1/src/decode.rs index ea4a8fc4..d101dc8a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3745,6 +3745,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 @@ -3811,17 +3815,28 @@ pub fn intrabc_rect_vartx_hits() -> usize { } /// 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 { @@ -15671,23 +15686,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); @@ -16055,25 +16078,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 @@ -16082,35 +16134,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, @@ -16120,12 +16185,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, @@ -16140,12 +16205,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])`): @@ -16257,6 +16332,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 diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 82d1dd3b..a683cbca 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -176,7 +176,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", ]; @@ -462,10 +473,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", @@ -589,7 +603,11 @@ mod tests { .chain(REFUSALS) .map(|&s| s.to_owned()) .collect(); - assert!(found.len() >= 30, "the refusal scan found only {} reasons -- it is broken, not the decoder", found.len()); + assert!( + found.len() >= 30, + "the refusal scan found only {} reasons -- it is broken, not the decoder", + found.len() + ); let added: Vec<&String> = found.difference(&listed).collect(); assert!( @@ -635,9 +653,14 @@ mod tests { let mut found: BTreeSet = BTreeSet::new(); for (i, _) in src.match_indices("\"SKIP ") { let rest = &src[i + "\"SKIP ".len()..]; - let Some(colon) = rest.find(':') else { continue }; + let Some(colon) = rest.find(':') else { + continue; + }; let name = &rest[..colon]; - if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') { + if !name + .chars() + .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') + { continue; } // The tail of the message says what was skipped. Only "{e}" -- the @@ -650,7 +673,10 @@ mod tests { } } let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect(); - let added: Vec<&String> = found.iter().filter(|n| !listed.contains(n.as_str())).collect(); + let added: Vec<&String> = found + .iter() + .filter(|n| !listed.contains(n.as_str())) + .collect(); assert!( added.is_empty(), "these gates turn a decode error into a printed SKIP and are not declared: \ @@ -723,9 +749,18 @@ mod tests { fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() { // (the refusal in the fallback arm, the alphabet its CDF codes) let blocks: [(&str, usize); 4] = [ - ("a 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1), - ("an INTER 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1), - ("a 128x128 superblock partition value outside the 8-symbol alphabet", crate::cdf::PARTITION_W128[0].len() - 1), + ( + "a 32x32 partition type this decoder does not code", + crate::cdf::PARTITION_W32[0].len() - 1, + ), + ( + "an INTER 32x32 partition type this decoder does not code", + crate::cdf::PARTITION_W32[0].len() - 1, + ), + ( + "a 128x128 superblock partition value outside the 8-symbol alphabet", + crate::cdf::PARTITION_W128[0].len() - 1, + ), // lane-t900 r24: the key-frame superblock root. Its `part` is // either a `partition_w64` symbol or, at a frame edge, one of the // three gathered outcomes (PARTITION_HORZ, PARTITION_VERT, @@ -779,7 +814,10 @@ mod tests { "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \ is a real gap in its {alphabet}-value alphabet, not a dead refusal", i + 1, - missing.iter().map(|v| PARTITION_NAMES[*v]).collect::>() + missing + .iter() + .map(|v| PARTITION_NAMES[*v]) + .collect::>() ); } assert_eq!( @@ -833,7 +871,11 @@ mod tests { .next() .unwrap_or("") .to_owned(); - assert!(!var.is_empty(), "the chain at decode.rs:{} tests nothing", head + 1); + assert!( + !var.is_empty(), + "the chain at decode.rs:{} tests nothing", + head + 1 + ); // Walk up collecting every branch head of this chain, each read to // the line that opens its body. @@ -843,7 +885,8 @@ mod tests { loop { i -= 1; let t = lines[i].trim_start(); - if indent(lines[i]) != outer || !(t.starts_with("} else if ") || t.starts_with("if ")) + if indent(lines[i]) != outer + || !(t.starts_with("} else if ") || t.starts_with("if ")) { if i == 0 { break; @@ -893,7 +936,10 @@ mod tests { "the chain at decode.rs:{} refuses {reason:?} but no branch names {:?} -- that \ is a real gap in its {alphabet}-value alphabet, not a dead refusal", head + 1, - missing.iter().map(|v| PARTITION_NAMES[*v]).collect::>() + missing + .iter() + .map(|v| PARTITION_NAMES[*v]) + .collect::>() ); } assert_eq!(found, chains.len()); @@ -996,11 +1042,18 @@ mod tests { values.insert(((1u64 << length) - 2) as u32); } let max = *values.iter().max().unwrap(); - assert_eq!(max, (1u32 << 20) - 2, "the enumeration misses the spec's own ceiling"); + assert_eq!( + max, + (1u32 << 20) - 2, + "the enumeration misses the spec's own ceiling" + ); // A coefficient is masked to 20 bits (spec 5.11.39), and the base and // base-range syntax contribute at most 15 of that before the tail, so // this is the largest tail a legal coefficient can need. - assert!(max >= 0xF_FFFF - 15, "the ceiling is below the largest legal tail"); + assert!( + max >= 0xF_FFFF - 15, + "the ceiling is below the largest legal tail" + ); for value in values { match roundtrip(value) { Ok(read) => assert_eq!(read, value, "the Golomb tail {value} read back as {read}"), @@ -1056,7 +1109,11 @@ mod tests { ]; assert_eq!(alphabets[0].1, 13, "the y_mode alphabet changed size"); for group in &crate::cdf::Y_MODE { - assert_eq!(group.len() - 1, alphabets[0].1, "the y_mode rows disagree on width"); + assert_eq!( + group.len() - 1, + alphabets[0].1, + "the y_mode rows disagree on width" + ); } let src = include_str!("decode.rs"); @@ -1064,12 +1121,17 @@ mod tests { let mut sites = 0usize; for (i, line) in lines.iter().enumerate() { let t = line.trim(); - let Some(rest) = t.strip_prefix("if mode >= ") else { continue }; + let Some(rest) = t.strip_prefix("if mode >= ") else { + continue; + }; let Some(threshold) = rest.trim_end_matches(" {").parse::().ok() else { continue; }; // Only the guards carrying THIS refusal. - if !lines[i..(i + 4).min(lines.len())].join("\n").contains(REFUSAL) { + if !lines[i..(i + 4).min(lines.len())] + .join("\n") + .contains(REFUSAL) + { continue; } sites += 1; @@ -1099,7 +1161,10 @@ mod tests { i + 1 ); } - assert_eq!(sites, 3, "the intra-mode guard is at three sites, found {sites}"); + assert_eq!( + sites, 3, + "the intra-mode guard is at three sites, found {sites}" + ); } /// lane-t900 r31, ENUMERATION for "a HORZ/VERT intra strip in a @@ -1159,7 +1224,10 @@ mod tests { } } } - assert!(with_128 > 0, "enumeration is vacuous -- no 128-sided footprint was tried"); + assert!( + with_128 > 0, + "enumeration is vacuous -- no 128-sided footprint was tried" + ); assert_eq!( allowed_at_128, 0, "a footprint with a 128-pixel side passed av1_allow_palette's bound -- the \ @@ -1271,11 +1339,17 @@ mod tests { // (3) The two tables, read out of decode_rect_split's own text: every // `(w, h) =>` / `(w, h) |` match arm head between the table's `let` // and the guard that follows it. - let body_at = src.find("fn decode_rect_split(").expect("decode_rect_split is gone"); + let body_at = src + .find("fn decode_rect_split(") + .expect("decode_rect_split is gone"); let body = &src[body_at..]; let slice = |from: &str, to: &str| -> &str { - let a = body.find(from).unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split")); - let b = body[a..].find(to).unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split")); + let a = body + .find(from) + .unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split")); + let b = body[a..] + .find(to) + .unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split")); &body[a..a + b] }; let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> { @@ -1348,7 +1422,10 @@ mod tests { } } } - assert_eq!(checked, 40, "the strip domain is not the ten rect shapes x four depths"); + assert_eq!( + checked, 40, + "the strip domain is not the ten rect shapes x four depths" + ); } /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a @@ -1458,9 +1535,15 @@ mod tests { } continue; } - let Some(rest) = line.strip_prefix('(') else { continue }; - let Some((pair, _)) = rest.split_once(") =>") else { continue }; - let Some((a, b)) = pair.split_once(',') else { continue }; + let Some(rest) = line.strip_prefix('(') else { + continue; + }; + let Some((pair, _)) = rest.split_once(") =>") else { + continue; + }; + let Some((a, b)) = pair.split_once(',') else { + continue; + }; let bw: usize = a.trim().parse().expect("arm bw"); let bh: usize = b.trim().parse().expect("arm bh"); assert!( @@ -1472,9 +1555,18 @@ mod tests { seen.push((bw, bh)); arms += 1; } - assert!(arms >= 10, "only {arms} arms parsed -- the table's shape changed"); - assert!(saw_none_fallback, "filter_intra_size_class_rect lost its `_ => None` fallback"); - assert!(saw_square_delegate, "filter_intra_size_class_rect lost its square-delegate arm"); + assert!( + arms >= 10, + "only {arms} arms parsed -- the table's shape changed" + ); + assert!( + saw_none_fallback, + "filter_intra_size_class_rect lost its `_ => None` fallback" + ); + assert!( + saw_square_delegate, + "filter_intra_size_class_rect lost its square-delegate arm" + ); // The guard arm delegates square strips to `filter_intra_size_class`; // drive the delegate directly, so a widening there turns THIS test red // (the numeric walk never reaches the guard arm). @@ -1524,7 +1616,10 @@ mod tests { ); } } - assert_eq!(sites, 8, "the call-site audit found {sites} sites, not the 8 it enumerated"); + assert_eq!( + sites, 8, + "the call-site audit found {sites} sites, not the 8 it enumerated" + ); } /// Every entry of [`PROVEN`] must still name a live refusal and a test @@ -1543,7 +1638,9 @@ mod tests { "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string" ); assert!( - sources.iter().any(|src| src.contains(&format!("fn {gate}("))), + sources + .iter() + .any(|src| src.contains(&format!("fn {gate}("))), "{reason:?} names the proving test {gate}, which exists in neither stream.rs \ nor decode.rs" ); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 1dcca8c2..c4b7b165 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -7187,12 +7187,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"; @@ -7249,11 +7249,106 @@ 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 /// those also keep `allow_intrabc` -- the frame-level premise of the /// refusal "an intrabc block under TxMode::Select", read out of the 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.