diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 0b71457a..c12507c5 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -140,6 +140,13 @@ fn main() { ); // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular // uv_mode grid instead of the coarse one-slot-per-column map. + println!( + "scaled: leaf8={} sub8={} warpfb={} predict_scaled={}", + ec_av1::decode::scaled_leaf8_hits(), + ec_av1::decode::scaled_sub8_hits(), + ec_av1::decode::scaled_warp_fallback_hits(), + ec_av1::mc::predict_scaled_hits() + ); println!( "uv_mode_grid_override: {}", ec_av1::decode::uv_mode_grid_override_hits() diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5de42315..feeb506b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2068,7 +2068,7 @@ pub(crate) fn scaled_compound_hits() -> usize { } /// Current value of [`SCALED_WARP_FALLBACK_HITS`]. -pub(crate) fn scaled_warp_fallback_hits() -> usize { +pub fn scaled_warp_fallback_hits() -> usize { SCALED_WARP_FALLBACK_HITS.with(|c| c.get()) } @@ -2499,6 +2499,32 @@ pub(crate) fn inter_sub16_split_hits() -> usize { INTER_SUB16_SPLIT_HITS.with(|c| c.get()) } +// lane-t900 r28: how many 16x16 inter splits reached their four 8x8 leaves +// while at least one reference picture was SCALED (superres) -- the counter +// behind the lifted "8x8 partition leaf under a scaled reference" refusal. +thread_local! { + static SCALED_LEAF8_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`SCALED_LEAF8_HITS`]. +pub fn scaled_leaf8_hits() -> usize { + SCALED_LEAF8_HITS.with(|c| c.get()) +} + +// lane-t900 r28: how many sub-8x8 inter blocks (the 4x4 split and the 8x4/4x8 +// rect pair) were predicted from a SCALED reference -- the counter behind the +// lifted "sub-8x8 inter block under a scaled reference" refusal. +thread_local! { + static SCALED_SUB8_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`SCALED_SUB8_HITS`]. +pub fn scaled_sub8_hits() -> usize { + SCALED_SUB8_HITS.with(|c| c.get()) +} + // lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded // real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the // rect coefficient reader itself fired, not just the strip-level partition @@ -21100,8 +21126,20 @@ fn decode_inter_block( None } }; - let warp0 = compound_warp(ref0, is_global_mv0); - let warp1 = compound_warp(ref1, is_global_mv1); + // lane-t900 r28 (class branch-dropped-as-unreachable, swept out + // of the scaled-ref lift): libaom `allow_warp` + // (av1/common/reconinter.c:41) opens with `if (av1_is_scaled(sf)) + // return 0;` PER SLOT, so a compound tap whose own reference is + // scaled (superres) is predicted translationally while its + // sibling may still warp. + let ref_unscaled = |rf: i8| { + ref_planes(rf, ref_y, ref_u, ref_v, other_refs) + .is_ok_and(|(py, _, _)| { + mc::scale_factor(py.width, frame_width) == mc::REF_NO_SCALE + }) + }; + let warp0 = compound_warp(ref0, is_global_mv0).filter(|_| ref_unscaled(ref0)); + let warp1 = compound_warp(ref1, is_global_mv1).filter(|_| ref_unscaled(ref1)); if warp0.is_some() || warp1.is_some() { COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1)); } @@ -22710,18 +22748,13 @@ fn decode_inter_block( // lane-scaledref r1: libaom `allow_warp` // (av1/common/reconinter.c:41) suppresses BOTH local and // global warp under a scaled reference and predicts - // translationally instead -- that fallback is implemented - // below, but the one real aomenc stream this round found - // that reaches it (`--enable-warped-motion=1`, - // `--superres-denominator=16`, seed 47) still mismatches - // ffmpeg at frame 2 luma, so the case stays refused by name - // until it has a green gate rather than shipping wrong - // pixels behind a lifted refusal. + // translationally instead -- the fallback below. lane-t900 + // r28 LIFTED the refusal that sat here: the mismatch r1 + // measured was the 16x4/4x16 strip's sub-8x8 chroma piece, + // which this file used to SKIP under a scaled reference + // (fixed in the same commit), not the warp fallback. if warp_params.is_some() { SCALED_WARP_FALLBACK_HITS.with(|c| c.set(c.get() + 1)); - return Err(unsupported( - "warp prediction with a scaled reference (superres, unimplemented)", - )); } if obmc_selected { SCALED_OBMC_HITS.with(|c| c.set(c.get() + 1)); @@ -22940,19 +22973,25 @@ fn decode_inter_block( // through to the ordinary whole-block predictor. if let Some(s) = strip_chroma.filter(|s| s.has_chroma) && let Some((prev_ref, prev_mv, prev_h, prev_v)) = s.prev - && luma_scale == mc::REF_NO_SCALE { let (piece_w, piece_h) = if s.horz { (8usize, 2usize) } else { (2usize, 8usize) }; - let (_, prev_u, prev_v_plane) = ref_planes(prev_ref, ref_y, ref_u, ref_v, other_refs)?; + // lane-t900 r28 (same-shape sweep of the sub-8x8 scaled-ref + // lift): this piece used to be SKIPPED when the block's + // reference was scaled, which silently left the whole-block + // prediction in place instead of refusing. It scales off the + // PREVIOUS strip's own reference, not this block's. + let (prev_y_plane, prev_u, prev_v_plane) = ref_planes(prev_ref, ref_y, ref_u, ref_v, other_refs)?; + let prev_scale = mc::scale_factor(prev_y_plane.width, frame_width); for (src, dst) in [(prev_u, &mut pred_u), (prev_v_plane, &mut pred_v)] { let mut piece = vec![0u16; piece_w * piece_h]; - mc::predict_with_filters( + mc::predict_maybe_scaled( &src.data, src.width, src.true_width, src.true_height, mv_to_q4(cpx, prev_mv.1, false), mv_to_q4(cpy, prev_mv.0, false), + prev_scale, piece_w, piece_h, prev_h, @@ -24447,10 +24486,13 @@ fn decode_inter_sub8_split4( neighbours.left_ref1[rmi], ); let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; - if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE { - return Err(unsupported( - "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", - )); + // lane-t900 r28: refusal lifted -- this sub-block's own reference may + // be scaled (superres); spec 7.11.3.3's walk is per reference, and + // each of the group's pieces (luma and its 2x2 chroma) carries its + // OWN factor because each can name a different `ref_frame`. + let luma_scale = mc::scale_factor(sref_y.width, frame_width); + if luma_scale != mc::REF_NO_SCALE { + SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1)); } let gm_table = build_gm_mv_table( global_motion, @@ -24612,13 +24654,14 @@ fn decode_inter_sub8_split4( ); piece[i] = Some((ref_frame, mv, h_filter, v_filter)); let mut pred_y = vec![0u16; B4 * B4]; - mc::predict_with_filters( + mc::predict_maybe_scaled( &sref_y.data, sref_y.width, sref_y.true_width, sref_y.true_height, mv_to_q4(px, mv.1, true), mv_to_q4(py, mv.0, true), + luma_scale, B4, B4, h_filter, @@ -24711,7 +24754,9 @@ fn decode_inter_sub8_split4( let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { continue; }; - let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + let (piece_ref_y, sref_u, sref_v) = + ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width); let (ox, oy) = if mixed { (cpx, cpy) } else { @@ -24721,13 +24766,14 @@ fn decode_inter_sub8_split4( let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) }; for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { let mut buf = vec![0u16; pw * ph]; - mc::predict_with_filters( + mc::predict_maybe_scaled( &plane.data, plane.width, plane.true_width, plane.true_height, mv_to_q4(ox, mv.1, false), mv_to_q4(oy, mv.0, false), + piece_scale, pw, ph, h_filter, @@ -25415,10 +25461,10 @@ fn decode_inter_sub8_rect2( neighbours.left_ref1[rmi], ); let (sref_y, _, _) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; - if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE { - return Err(unsupported( - "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", - )); + // lane-t900 r28: refusal lifted -- see the split arm above. + let luma_scale = mc::scale_factor(sref_y.width, frame_width); + if luma_scale != mc::REF_NO_SCALE { + SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1)); } let gm_table = build_gm_mv_table( global_motion, @@ -25581,13 +25627,14 @@ fn decode_inter_sub8_rect2( let mut pred_y = vec![0u16; SIDE * SIDE]; { let mut dense = vec![0u16; bw * bh]; - mc::predict_with_filters( + mc::predict_maybe_scaled( &sref_y.data, sref_y.width, sref_y.true_width, sref_y.true_height, mv_to_q4(px, mv.1, true), mv_to_q4(py, mv.0, true), + luma_scale, bw, bh, h_filter, @@ -25724,7 +25771,9 @@ fn decode_inter_sub8_rect2( let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { continue; }; - let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + let (piece_ref_y, sref_u, sref_v) = + ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width); let (ox, oy) = if mixed { (cpx, cpy) } else if vert { @@ -25741,13 +25790,14 @@ fn decode_inter_sub8_rect2( }; for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { let mut buf = vec![0u16; piece_w * piece_h]; - mc::predict_with_filters( + mc::predict_maybe_scaled( &plane.data, plane.width, plane.true_width, plane.true_height, mv_to_q4(ox, mv.1, false), mv_to_q4(oy, mv.0, false), + piece_scale, piece_w, piece_h, h_filter, @@ -26394,8 +26444,18 @@ fn decode_inter_block8( None } }; - let warp0_c = leaf_compound_warp(ref0, is_global_mv0_c); - let warp1_c = leaf_compound_warp(ref1, is_global_mv1_c); + // lane-t900 r28: same per-slot `allow_warp` scale bail-out as + // the 16x16-and-bigger compound path above. + let leaf_ref_unscaled = |rf: i8| { + ref_planes(rf, ref_y, ref_u, ref_v, other_refs) + .is_ok_and(|(py, _, _)| { + mc::scale_factor(py.width, frame_width) == mc::REF_NO_SCALE + }) + }; + let warp0_c = + leaf_compound_warp(ref0, is_global_mv0_c).filter(|_| leaf_ref_unscaled(ref0)); + let warp1_c = + leaf_compound_warp(ref1, is_global_mv1_c).filter(|_| leaf_ref_unscaled(ref1)); if warp0_c.is_some() || warp1_c.is_some() { COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1)); COMPOUND_WARP_HITS_8.with(|c| c.set(c.get() + 1)); @@ -26929,8 +26989,24 @@ fn decode_inter_block8( // (class wrong-alphabet-same-value). let proj_ok = num_proj_ref(grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, ref_frame) >= 1; - let warp_eligible = allow_warped_motion && !force_integer_mv && proj_ok; - if allow_warped_motion && proj_ok && force_integer_mv { + // lane-t900 r28: the `&& !ref_is_scaled` the note above asked the + // lifter of the 8x8-leaf refusal to add. libaom + // `motion_mode_allowed` (blockd.h) makes WARPED_CAUSAL eligible + // only `if (mbmi->num_proj_ref >= 1 && (allow_warped_motion && + // !av1_is_scaled(xd->block_ref_scale_factors[0])))`, so under a + // scaled reference the ALPHABET shrinks to the 2-symbol obmc one + // -- and with OBMC off no symbol is read at all (class + // wrong-alphabet-same-value: reading the 3-symbol row here + // desynced every warped-motion superres stream at its first + // eligible 8x8 leaf). + let ref_is_scaled = + mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE; + let warp_eligible = + allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok; + if allow_warped_motion && proj_ok && ref_is_scaled { + SCALED_WARP_SUPPRESSED_HITS.with(|c| c.set(c.get() + 1)); + } + if allow_warped_motion && proj_ok && !ref_is_scaled && force_integer_mv { FIMV_ALPHABET_HITS.with(|c| c.set(c.get() + 1)); } if warp_eligible { @@ -27139,7 +27215,11 @@ fn decode_inter_block8( // lane-gmaffine r1: the warp filter REPLACES the translational // prediction just built (libaom builds one or the other), same as // the 16x16+ leaf's own call trio. - if let Some(params) = &warp_params { + // lane-t900 r28: `allow_warp`'s scaled-reference bail-out, which this + // leaf was missing -- it is the defect the 8x8-leaf refusal hid (a + // warped 8x8 leaf over a superres reference; libaom predicts it + // translationally, every symbol still read). + if let Some(params) = warp_params.as_ref().filter(|_| luma_scale == mc::REF_NO_SCALE) { crate::warp::warp_affine( params, &sref_y.data, sref_y.true_width as i32, sref_y.true_height as i32, sref_y.width as i32, &mut pred_y, px as i32, py as i32, SIDE as i32, @@ -29525,31 +29605,19 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) .collect(); - // lane-scaledref r1: `decode_inter_block8` IS - // threaded for a scaled reference now (its - // single-ref, compound and OBMC MC all take - // spec 7.11.3.3's scaled walk), but the one - // recipe that reaches this path at all -- a - // 64x72 superres fixture whose bottom 16-row - // band straddles the true edge, so the - // gathered split bit lands on 8x8 leaves -- - // DESYNCS inside the leaf itself - // (`from_switchable_symbol` handed a 4th - // symbol, mc.rs:200), the same - // below-8x8 desync lane-sub8 r2 left open and - // unrelated to scaling. So the scaled MC here - // is unproven: refuse by name rather than - // ship a capability claim no gate exercises. - // Deleting these six lines is the whole lift - // once the leaf8 desync is fixed. + // lane-t900 r28: the 8x8-leaf refusal under a + // scaled reference is LIFTED -- + // `decode_inter_block8`'s single-ref, + // compound and OBMC MC all take spec + // 7.11.3.3's scaled walk. The counter is what + // proves a gate actually reached a scaled + // leaf rather than a same-size reference. if ref_y.width != frame_width as usize || ref_slots.iter().flatten().any(|(py, _, _)| { py.width != frame_width as usize }) { - return Err(unsupported( - "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", - )); + SCALED_LEAF8_HITS.with(|c| c.set(c.get() + 1)); } let mut prev_leaves: Vec<((usize, usize), bool, bool, i8, Option)> = Vec::new(); for (mr, mc) in leaf_positions { diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index abd850cc..c35cfb72 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -874,6 +874,38 @@ pub fn predict_scaled_kern( }); } +/// [`predict_with_filters`] or [`predict_scaled`], on this reference's own +/// `x_scale_fp` -- the dispatch every inter path needs once a reference can be +/// scaled (superres). `REF_NO_SCALE` takes the ordinary stride-1 path, which +/// keeps [`predict_scaled_hits`] a true count of scaled predictions. +#[allow(clippy::too_many_arguments)] +pub fn predict_maybe_scaled( + reference: &[u16], + stride: usize, + true_width: usize, + true_height: usize, + x_q4: i32, + y_q4: i32, + x_scale_fp: i64, + block_w: usize, + block_h: usize, + h_kind: InterpFilterKind, + v_kind: InterpFilterKind, + dst: &mut [u16], +) { + if x_scale_fp == REF_NO_SCALE { + predict_with_filters( + reference, stride, true_width, true_height, x_q4, y_q4, block_w, block_h, h_kind, + v_kind, dst, + ); + } else { + predict_scaled( + reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp, block_w, + block_h, h_kind, v_kind, dst, + ); + } +} + /// `InterRound1` for a compound ref (spec 7.11.3.2's `isCompound` branch, /// `COMPOUND_ROUND1_BITS` in libaom's `convolve.h`): 4 bits shallower than /// [`INTER_ROUND_1`] so the vertical pass lands in the `CONV_BUF` domain diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 0e53cbb4..28122597 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -32,7 +32,6 @@ const REFUSALS: &[&str] = &[ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", "an OBMC neighbour whose switchable interp filter was never recorded", - "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", "a rectangular inter luma transform unit whose shape has no coefficient table set here", "a rectangular inter chroma transform unit whose shape has no coefficient table set here", "a rectangular transform unit whose shape has no coefficient scan table here", @@ -142,8 +141,6 @@ const REFUSALS: &[&str] = &[ // source, and screen content in the forced bands with a NON-screen // interior. "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", - "warp prediction with a scaled reference (superres, unimplemented)", - "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", "a motion_mode symbol for a block shape with no CDF row here", ]; @@ -349,18 +346,12 @@ const PROVEN: &[(&str, &str)] = &[ "an OBMC neighbour whose switchable interp filter was never recorded", "every_inter_record_publishes_an_obmc_readable_filter", ), - // lane-t900 r27, census: this one is a REAL capability gap, and the gate - // proves it fires by name on real streams -- four fixed-denominator - // `--superres-mode=1` encodes (denoms 10/12/16, warped motion and OBMC - // on) all stop here, while the two `--superres-mode=3` auto encodes pick - // denominator 8 and carry no scaling at all. Its two siblings ("warp - // prediction with a scaled reference", "a sub-8x8 inter block under a - // scaled reference") stay UNPROVEN: this refusal sits in front of them, - // so nothing measures them until the 8x8-leaf gap is lifted. - ( - "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", - "a_superres_census_over_six_real_streams_records_which_scaled_refusals_fire", - ), + // lane-t900 r28: all three scaled-reference (superres) refusals -- the + // 8x8 partition leaf, the sub-8x8 inter block and warp -- are LIFTED and + // gone from this inventory. The gate + // `real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact` + // decodes both lifted shapes byte-exact vs ffmpeg, and the census now + // asserts none of the three strings comes back. ( "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 595fd0d5..6091122c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -1555,11 +1555,15 @@ mod tests { // leaf guard is reached first. Lifting the leaf gap is what makes the // other two measurable, so this gate pins the ORDER, not just a count. assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous"); - assert!( - leaf8 > 0, - "no fixed-denominator recipe reached the 8x8-leaf refusal any more: either the \ - capability landed (drop the refusal) or the recipes stopped scaling" + // lane-t900 r28: all three scaled refusals are LIFTED, so the census + // now pins the opposite shape -- every fixed-denominator recipe must + // DECODE, and none of the three strings may come back. + assert_eq!( + (warp, sub8, leaf8), + (0, 0, 0), + "a scaled-reference refusal came back (warp {warp}, sub8 {sub8}, leaf8 {leaf8})" ); + assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous"); } /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a @@ -14780,6 +14784,152 @@ mod tests { ); } + /// lane-t900 r28: the three scaled-reference (superres) refusals are + /// LIFTED -- an 8x8 partition leaf, a sub-8x8 inter block, and warp -- + /// so two real `--superres-mode=1` streams whose references are all + /// scaled must decode PIXEL-EXACT vs ffmpeg. + /// + /// Arm A drives `--min-partition-size=4` so the split (4x4) and rect + /// (8x4/4x8) sub-8x8 readers and the 8x8 leaf all run over a scaled + /// reference; arm B turns `--enable-warped-motion=1` on, which is the + /// root cause this round fixed: libaom `motion_mode_allowed` drops + /// WARPED_CAUSAL eligibility when `av1_is_scaled(sf)`, so the 8x8 leaf + /// must read the 2-symbol obmc alphabet (here: no symbol at all, OBMC + /// off) instead of the 3-symbol motion_mode row. + /// + /// Each arm hard-asserts its own counter (class `gate-blind-to-feature`): + /// a pixel match with zero scaled leaves/sub-8x8 blocks/suppressed warp + /// eligibilities would prove nothing. + #[test] + fn real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact() { + const NAME: &str = "real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + // Every tool whose scaled-reference path this round does NOT touch is + // off, so a mismatch can only be the lifted paths (the same scoping + // the r10 key+inter superres gate uses). + let common: [&str; 21] = [ + "--codec=av1", "--passes=1", "--end-usage=q", "--threads=1", "--row-mt=0", + "--kf-max-dist=9999", "--lag-in-frames=0", "--auto-alt-ref=0", "--cpu-used=0", + "--sb-size=64", "--superres-mode=1", "--superres-denominator=12", + "--superres-kf-denominator=12", "--enable-obmc=0", "--enable-masked-comp=0", + "--enable-interintra-comp=0", "--enable-tx-size-search=0", "--enable-cdef=0", + "--enable-restoration=0", "--enable-palette=0", "--enable-intrabc=0", + ]; + struct Arm { + name: &'static str, + frames: usize, + cq: &'static str, + extra: [&'static str; 4], + } + let arms = [ + Arm { + name: "sub8+leaf8", + frames: 4, + cq: "--cq-level=4", + extra: [ + "--enable-warped-motion=0", + "--enable-rect-partitions=1", + "--max-partition-size=32", + "--min-partition-size=4", + ], + }, + Arm { + name: "warp", + frames: 6, + cq: "--cq-level=20", + extra: [ + "--enable-warped-motion=1", + "--enable-rect-partitions=1", + "--max-partition-size=32", + "--min-partition-size=8", + ], + }, + ]; + let (width, height) = (96usize, 96usize); + for arm in &arms { + let duration = format!("{}", arm.frames as f64 / 25.0); + let src = format!("mandelbrot=size={width}x{height}:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", + "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!(y4m.status.success(), "{NAME}: ffmpeg refused the fixture"); + let limit = format!("--limit={}", arm.frames); + let mut args: Vec<&str> = common.to_vec(); + args.push(&limit); + args.push(arm.cq); + args.extend_from_slice(&arm.extra); + args.extend_from_slice(&["--obu", "-o", "-", "-"]); + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "{NAME} {}: aomenc refused the recipe: {}", + arm.name, + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let leaf8_before = crate::decode::scaled_leaf8_hits(); + let sub8_before = crate::decode::scaled_sub8_hits(); + let warp_before = crate::decode::scaled_warp_suppressed_hits(); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME} {}: refused: {e}", arm.name)); + assert_eq!(frames.len(), arm.frames, "{NAME} {}", arm.name); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, arm.frames); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} {} frame {i} luma vs ffmpeg", arm.name); + assert_eq!(got.u, want.u, "{NAME} {} frame {i} U vs ffmpeg", arm.name); + assert_eq!(got.v, want.v, "{NAME} {} frame {i} V vs ffmpeg", arm.name); + } + let (leaf8, sub8, warp) = ( + crate::decode::scaled_leaf8_hits() - leaf8_before, + crate::decode::scaled_sub8_hits() - sub8_before, + crate::decode::scaled_warp_suppressed_hits() - warp_before, + ); + eprintln!( + "{NAME} {}: {} frames pixel-exact, scaled leaf8={leaf8} sub8={sub8} \ + warp_suppressed={warp}", + arm.name, arm.frames + ); + if arm.name == "sub8+leaf8" { + assert!(leaf8 > 0 && sub8 > 0, "{NAME} {}: the lifted paths never ran (leaf8={leaf8} sub8={sub8})", arm.name); + } else { + assert!( + warp > 0, + "{NAME} {}: no block reached WARPED_CAUSAL eligibility under a scaled \ + reference, so the alphabet fix is unexercised", + arm.name + ); + } + } + } + /// lane-interintra r1: `--enable-interintra-comp=1` streams must DECODE /// pixel-exact -- the interintra flag/mode/wedge-flag syntax and the /// non-wedge smooth blend are ported. A refusal naming interintra fails