forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1comp4' (d9490b51): second-reference motion search at the leaves (NEAREST_NEW / NEW_NEW), compound stacks at the straddling leaves

Browse files at this commit

020b822416a672ce6619b40a98e97e0708051167Ahmet Kaan GümüşParent: 81d8241e75ad89
BD vs libaom +83.0/+99.9/+54.5 -> +79.9/+94.6/+54.5, vs rav1e
+39.7/+60.0/+1.1 -> +37.3/+55.7/+1.1; margin 0.8 swept; mismatches 0.
Compound var-tx measured and rejected (small residuals: the per-unit
txb_skip/eob symbols cost more than the static estimate prices).
crates/ec-av1/src/encode.rsmodified+202 -42
@@ -190,6 +190,42 @@ fn extra_new_skip_margin() -> f64 {
190 }190 }
191 }191 }
192 192
193+/// The margin on a LEAF's SECOND-reference motion search, the same early-out
194+/// shape [`EXTRA_NEW_SKIP_MARGIN`] gives a whole block's extra-reference
195+/// `NEWMV`: the search is skipped when that reference's own
196+/// `NEAREST_NEARESTMV` vector already prices this many times better than the
197+/// leaf's `LAST` search found. `0.0` never skips.
198+///
199+/// Swept on the BD gate over 0.15/0.35/0.6/0.8/1.2 and 0.0, reading BD vs
200+/// libaom (1080p/2160p/screen) against the extra `motion::search` calls at
201+/// 2160p (38195 with no second-reference search at all):
202+/// 0.15 +81.7/+97.4/+54.5 at 41286, 0.35 +81.4/+96.7 at 43093,
203+/// 0.6 +80.6/+95.5 at 44843, 0.8 +79.9/+94.6 at 47008, 1.2 +80.2/+94.2 at
204+/// 77882, never-skip +79.7/+94.1 at 81801. 0.8 takes the whole gain the
205+/// unskipped search buys (-3.1/-5.3 off the +83.0/+99.9 base) for a quarter
206+/// of its extra searches; past it the calls double for another -0.3/-0.5.
207+/// Screen capture is BYTE-IDENTICAL at every margin -- its leaf compound is
208+/// all `NEAREST_NEARESTMV` and no searched second vector ever wins there --
209+/// so the margin is pure wall on that content (+10% searches at 0.8).
210+const LEAF_SECOND_NEW_MARGIN: f64 = 0.8;
211+
212+/// [`LEAF_SECOND_NEW_MARGIN`], swept by `EC_AV1_LEAF_SECOND_MARGIN`; the
213+/// search itself is switched off by `EC_AV1_LEAF_SECOND_NEWMV=0`.
214+fn leaf_second_new_margin() -> f64 {
215+ match std::env::var("EC_AV1_LEAF_SECOND_MARGIN").ok() {
216+ Some(v) => v.parse().unwrap_or(LEAF_SECOND_NEW_MARGIN),
217+ None => LEAF_SECOND_NEW_MARGIN,
218+ }
219+}
220+
221+/// Whether a leaf searches its SECOND reference at all (lane-av1comp4).
222+fn leaf_second_new_mv() -> bool {
223+ match std::env::var("EC_AV1_LEAF_SECOND_NEWMV").ok() {
224+ Some(v) => v != "0",
225+ None => true,
226+ }
227+}
228+
193 /// Whether a 16x16 or 8x8 inter LEAF is offered the compound candidates the229 /// Whether a 16x16 or 8x8 inter LEAF is offered the compound candidates the
194 /// whole 32x32 block is (lane-av1comp3). The writer already codes a compound230 /// whole 32x32 block is (lane-av1comp3). The writer already codes a compound
195 /// block at any leaf size (`tile::write_inter_frame_leaf`/`..._leaf8` both231 /// block at any leaf size (`tile::write_inter_frame_leaf`/`..._leaf8` both
@@ -3286,6 +3322,49 @@ fn search_chroma(
3286 /// search, so `NEARESTMV`-or-intra is this function's deliberate first cut3322 /// search, so `NEARESTMV`-or-intra is this function's deliberate first cut
3287 /// (see `write_inter_frame_leaf`'s doc comment).3323 /// (see `write_inter_frame_leaf`'s doc comment).
3288 #[allow(clippy::too_many_arguments)]3324 #[allow(clippy::too_many_arguments)]
3325+/// The compound MV stack of each `LAST` + extra-reference pair at one leaf,
3326+/// as [`code_square_inter`] wants them: empty on a frame that codes no
3327+/// `reference_select`, or when the leaf compound candidates are switched off.
3328+/// One helper because THREE leaf call sites need it -- the split quadrants
3329+/// and, since lane-av1comp4, both straddling-edge sites, which used to pass
3330+/// `&[]` and so coded no compound block anywhere along the frame's true edge.
3331+#[allow(clippy::too_many_arguments)]
3332+fn leaf_compound_stacks<'a>(
3333+ grid: &MiGrid,
3334+ mi_row: usize,
3335+ mi_col: usize,
3336+ bw4: usize,
3337+ bh4: usize,
3338+ mi_cols: usize,
3339+ mi_rows: usize,
3340+ reference_select: bool,
3341+ golden: Option<&'a Picture>,
3342+ altref: Option<&'a Picture>,
3343+) -> Vec<(i8, &'a Picture, crate::mvstack::CompoundMvStack)> {
3344+ if !(reference_select && leaf_compound()) {
3345+ return Vec::new();
3346+ }
3347+ [
3348+ (crate::mvstack::GOLDEN_FRAME, golden),
3349+ (crate::mvstack::ALTREF_FRAME, altref),
3350+ ]
3351+ .into_iter()
3352+ .filter_map(|(r, pic)| {
3353+ pic.map(|p| {
3354+ (
3355+ r,
3356+ p,
3357+ crate::mvstack::find_mv_stack_compound(
3358+ grid, mi_row, mi_col, bw4, bh4,
3359+ (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows,
3360+ grid.sign_bias_table(), &[(0, 0); 7], None,
3361+ ),
3362+ )
3363+ })
3364+ })
3365+ .collect()
3366+}
3367+
3289 fn code_square_inter(3368 fn code_square_inter(
3290 luma: &mut Plane,3369 luma: &mut Plane,
3291 chroma: &mut [Plane; 2],3370 chroma: &mut [Plane; 2],
@@ -3443,8 +3522,11 @@ fn code_square_inter(
3443 // below, exactly as `search_inter_block` seeds its own from the searches3522 // below, exactly as `search_inter_block` seeds its own from the searches
3444 // it already ran.3523 // it already ran.
3445 let mut searched_new: Option<(i32, i32)> = None;3524 let mut searched_new: Option<(i32, i32)> = None;
3525+ // What that search cost, kept for the second reference's own early-out
3526+ // below (`None` when this leaf ran no search at all).
3527+ let mut searched_new_cost: Option<f64> = None;
3528+ let source_block = luma.source_block(x, y, side);
3446 if leaf_new_mv() {3529 if leaf_new_mv() {
3447- let source_block = luma.source_block(x, y, side);
3448 let (seeds, seed_n) = mv_seeds(stack);3530 let (seeds, seed_n) = mv_seeds(stack);
3449 let found = motion::search(3531 let found = motion::search(
3450 ref_luma.0,3532 ref_luma.0,
@@ -3462,6 +3544,7 @@ fn code_square_inter(
3462 1,3544 1,
3463 );3545 );
3464 let new_mv = round_to_valid_mv(found.mv, stack.pred_mv);3546 let new_mv = round_to_valid_mv(found.mv, stack.pred_mv);
3547+ searched_new_cost = Some(found.cost);
3465 if let Some(mv_bits) = mv_residual_bits(new_mv, stack.pred_mv) {3548 if let Some(mv_bits) = mv_residual_bits(new_mv, stack.pred_mv) {
3466 searched_new = Some(new_mv);3549 searched_new = Some(new_mv);
3467 // Same reuse as `search_inter_block`: a NEWMV equal to the3550 // Same reuse as `search_inter_block`: a NEWMV equal to the
@@ -3532,13 +3615,12 @@ fn code_square_inter(
3532 }3615 }
3533 3616
3534 // The COMPOUND candidates at this leaf (lane-av1comp3), the same set3617 // The COMPOUND candidates at this leaf (lane-av1comp3), the same set
3535- // `search_inter_block` prices for a whole 32x32 block minus the two that3618+ // `search_inter_block` prices for a whole 32x32 block:
3536- // need a motion search against the SECOND reference: a leaf never runs3619+ // `NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV`, `NEW_NEARESTMV` off the vector
3537- // one (`NEAREST_NEWMV`/`NEW_NEWMV` would each cost another3620+ // this leaf already searched, and -- since lane-av1comp4 gave the leaf a
3538- // `motion::search` per extra reference per leaf), so the set here is3621+ // SECOND-reference search of its own -- `NEAREST_NEWMV` and `NEW_NEWMV`
3539- // `NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV` and `NEW_NEARESTMV` off the3622+ // too. Priced with the same static-CDF approximation, plus the
3540- // vector this leaf already searched. Priced with the same static-CDF3623+ // compound-only syntax the writer emits.
3541- // approximation, plus the compound-only syntax the writer emits.
3542 for (ref1, g, cstack) in compound.iter().filter(|_| leaf_compound()) {3624 for (ref1, g, cstack) in compound.iter().filter(|_| leaf_compound()) {
3543 let (ref1, g) = (*ref1, *g);3625 let (ref1, g) = (*ref1, *g);
3544 let uni =3626 let uni =
@@ -3585,13 +3667,48 @@ fn code_square_inter(
3585 },3667 },
3586 ),3668 ),
3587 ];3669 ];
3588- // `NEW_NEARESTMV`: the NEW half is this leaf's own searched vector,3670+ // Every compound MV residual here is priced against compound stack
3589- // its residual priced against compound stack entry 0 (what3671+ // entry 0, which is what `assign_compound_mv` predicts from at
3590- // `assign_compound_mv` predicts from at `ref_mv_idx = 0`).3672+ // `ref_mv_idx = 0` -- so it is also what the second-reference search
3673+ // below seeds from and rounds to, and no candidate it finds can then
3674+ // fail `mv_residual_bits`.
3591 let cbase = cstack3675 let cbase = cstack
3592 .entries3676 .entries
3593 .first()3677 .first()
3594 .map_or(cstack.nearest_mv, |e| (e.mv0, e.mv1));3678 .map_or(cstack.nearest_mv, |e| (e.mv0, e.mv1));
3679+ // This leaf's SECOND-reference motion search (lane-av1comp4). Without
3680+ // it a leaf could only name a stack vector for the second half, and
3681+ // screen capture showed the consequence: every leaf compound block
3682+ // there was `NEAREST_NEARESTMV`. Skipped, like `search_inter_block`'s
3683+ // extra-reference `NEWMV`, when this reference's own
3684+ // `NEAREST_NEARESTMV` vector already prices `margin` times better
3685+ // than the `LAST` search of this same leaf did -- one candidate
3686+ // evaluation standing in for a whole search.
3687+ let margin = leaf_second_new_margin();
3688+ let mut second_new: Option<(i32, i32)> = None;
3689+ if leaf_second_new_mv() {
3690+ let skip = margin > 0.0
3691+ && searched_new_cost.is_some_and(|last| {
3692+ motion::cost_at(
3693+ &g.y, g.width, luma.true_width, luma.true_height, &source_block, x, y,
3694+ side, side, cstack.nearest_mv.1, cbase.1, search.lambda, fctx,
3695+ ) * margin
3696+ <= last
3697+ });
3698+ if !skip {
3699+ let mut seeds = [(0, 0); 4];
3700+ let mut seed_n = 1;
3701+ for e in cstack.entries.iter().take(3) {
3702+ seeds[seed_n] = e.mv1;
3703+ seed_n += 1;
3704+ }
3705+ let found = motion::search(
3706+ &g.y, g.width, luma.true_width, luma.true_height, &source_block, x, y, side,
3707+ side, cbase.1, &seeds[..seed_n], search.lambda, fctx, ref_distance(ref1),
3708+ );
3709+ second_new = Some(round_to_valid_mv(found.mv, cbase.1));
3710+ }
3711+ }
3595 if let Some(new_mv) = searched_new {3712 if let Some(new_mv) = searched_new {
3596 if let Some(b0) = mv_residual_bits(new_mv, cbase.0) {3713 if let Some(b0) = mv_residual_bits(new_mv, cbase.0) {
3597 ccands.push((3714 ccands.push((
@@ -3608,6 +3725,40 @@ fn code_square_inter(
3608 ));3725 ));
3609 }3726 }
3610 }3727 }
3728+ // `NEAREST_NEWMV` and `NEW_NEWMV`: the NEW halves are the two
3729+ // searches this leaf ran, each residual priced against `cbase`.
3730+ if let Some(mv1) = second_new {
3731+ if let Some(b1) = mv_residual_bits(mv1, cbase.1) {
3732+ ccands.push((
3733+ (cstack.nearest_mv.0, mv1),
3734+ mode_bits_of(2) + b1,
3735+ InterInfo {
3736+ ref_frame: crate::mvstack::LAST_FRAME,
3737+ mode: InterMode::NearestNewMv,
3738+ mv: cstack.nearest_mv.0,
3739+ mv1,
3740+ ref1: Some(ref1),
3741+ ref_mv_idx: 0,
3742+ },
3743+ ));
3744+ if let Some((new_mv, b0)) =
3745+ searched_new.and_then(|m| mv_residual_bits(m, cbase.0).map(|b| (m, b)))
3746+ {
3747+ ccands.push((
3748+ (new_mv, mv1),
3749+ mode_bits_of(7) + b0 + b1,
3750+ InterInfo {
3751+ ref_frame: crate::mvstack::LAST_FRAME,
3752+ mode: InterMode::NewNewMv,
3753+ mv: new_mv,
3754+ mv1,
3755+ ref1: Some(ref1),
3756+ ref_mv_idx: 0,
3757+ },
3758+ ));
3759+ }
3760+ }
3761+ }
3611 ccands.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1)));3762 ccands.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1)));
3612 ccands.dedup_by_key(|c| c.0);3763 ccands.dedup_by_key(|c| c.0);
3613 let g_luma = (g.y.as_slice(), g.width, luma.true_width, luma.true_height);3764 let g_luma = (g.y.as_slice(), g.width, luma.true_width, luma.true_height);
@@ -3661,9 +3812,16 @@ fn code_square_inter(
3661 // A compound winner commits the flat trial it was priced from:3812 // A compound winner commits the flat trial it was priced from:
3662 // `commit_inter_luma`'s var-tx trial set is single-reference3813 // `commit_inter_luma`'s var-tx trial set is single-reference
3663 // (`mc_trial`), so a compound leaf codes `tx_depth = 0`.3814 // (`mc_trial`), so a compound leaf codes `tx_depth = 0`.
3664- // corner-cut: no var-tx split for a compound leaf -- ceiling is3815+ // lane-av1comp4 BUILT that upgrade (a `commit_inter_luma`
3665- // the split gain on 16x16 compound blocks; upgrade path is a3816+ // predicting each half-side trial from BOTH references, verified
3666- // compound `commit_inter_luma` taking both references.3817+ // byte-identical to this when its split is disabled) and MEASURED
3818+ // it a loss: vs libaom +83.5/+99.7/+54.9 at no margin against the
3819+ // +83.0/+99.9/+54.5 here, and +83.3/+100.2/+54.9, +83.8/+99.5/
3820+ // +54.9, +83.3/+100.0/+54.9 at split margins 0.02/0.05/0.15. A
3821+ // compound block's residual is small enough that the four extra
3822+ // per-unit txb_skip/eob symbols cost more ladder bytes than this
3823+ // encoder's static-CDF estimate prices them at, so the local RD
3824+ // win does not convert. The flat trial stays.
3667 let (levels, tx_depth, dcost) = if info.ref1.is_some() {3825 let (levels, tx_depth, dcost) = if info.ref1.is_some() {
3668 luma.commit(x, y, side, &luma_new);3826 luma.commit(x, y, side, &luma_new);
3669 (luma_new.levels.clone(), 0, 0.0)3827 (luma_new.levels.clone(), 0, 0.0)
@@ -6504,30 +6662,10 @@ pub(crate) fn encode_inter_frame(
6504 let stack = find_mv_stack(6662 let stack = find_mv_stack(
6505 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,6663 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
6506 );6664 );
6507- let cstacks: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> =6665+ let cstacks = leaf_compound_stacks(
6508- if header.reference_select && leaf_compound() {6666+ &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows,
6509- [6667+ header.reference_select, golden, altref,
6510- (crate::mvstack::GOLDEN_FRAME, golden),6668+ );
6511- (crate::mvstack::ALTREF_FRAME, altref),
6512- ]
6513- .into_iter()
6514- .filter_map(|(r, pic)| {
6515- pic.map(|p| {
6516- (
6517- r,
6518- p,
6519- crate::mvstack::find_mv_stack_compound(
6520- &grid, mi_row, mi_col, 4, 4,
6521- (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows,
6522- grid.sign_bias_table(), &[(0, 0); 7], None,
6523- ),
6524- )
6525- })
6526- })
6527- .collect()
6528- } else {
6529- Vec::new()
6530- };
6531 let (leaf, leaf_cost) = code_square_inter(6669 let (leaf, leaf_cost) = code_square_inter(
6532 &mut luma,6670 &mut luma,
6533 &mut chroma,6671 &mut chroma,
@@ -6690,6 +6828,10 @@ pub(crate) fn encode_inter_frame(
6690 let stack = find_mv_stack(6828 let stack = find_mv_stack(
6691 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,6829 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
6692 );6830 );
6831+ let cstacks = leaf_compound_stacks(
6832+ &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows,
6833+ header.reference_select, golden, altref,
6834+ );
6693 let (block, _) = code_square_inter(6835 let (block, _) = code_square_inter(
6694 &mut luma,6836 &mut luma,
6695 &mut chroma,6837 &mut chroma,
@@ -6698,7 +6840,7 @@ pub(crate) fn encode_inter_frame(
6698 &search,6840 &search,
6699 &mode_bits_table,6841 &mode_bits_table,
6700 reference,6842 reference,
6701- &stack, &[], fctx,6843+ &stack, &cstacks, fctx,
6702 );6844 );
6703 // One publication point for every coded leaf6845 // One publication point for every coded leaf
6704 // (`record_mi`): this site used to spell the vote6846 // (`record_mi`): this site used to spell the vote
@@ -6723,6 +6865,10 @@ pub(crate) fn encode_inter_frame(
6723 let stack = find_mv_stack(6865 let stack = find_mv_stack(
6724 &grid, mi_row, mi_col, 2, 2, LAST_FRAME, mi_cols, mi_rows,6866 &grid, mi_row, mi_col, 2, 2, LAST_FRAME, mi_cols, mi_rows,
6725 );6867 );
6868+ let cstacks = leaf_compound_stacks(
6869+ &grid, mi_row, mi_col, 2, 2, mi_cols, mi_rows,
6870+ header.reference_select, golden, altref,
6871+ );
6726 let (leaf, _) = code_square_inter(6872 let (leaf, _) = code_square_inter(
6727 &mut luma,6873 &mut luma,
6728 &mut chroma,6874 &mut chroma,
@@ -6731,7 +6877,7 @@ pub(crate) fn encode_inter_frame(
6731 &search,6877 &search,
6732 &mode_bits_table,6878 &mode_bits_table,
6733 reference,6879 reference,
6734- &stack, &[], fctx,6880+ &stack, &cstacks, fctx,
6735 );6881 );
6736 // Same publication point as the 16x166882 // Same publication point as the 16x16
6737 // straddling leaf above (`record_mi`).6883 // straddling leaf above (`record_mi`).
@@ -9210,7 +9356,13 @@ mod tests {
9210 #[test]9356 #[test]
9211 fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {9357 fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
9212 let fctx = &crate::decode::FrameCtx::new();9358 let fctx = &crate::decode::FrameCtx::new();
9213- let (width, height) = (128usize, 64usize);9359+ // 256x128, not the 128x64 this started at: once a leaf could search
9360+ // its second reference (lane-av1comp4) the small card's every
9361+ // eligible block went to a compound winner, which commits its flat
9362+ // transform, and the split below stopped firing on content that
9363+ // still splits at every larger size ([[gate-blind-to-feature]] --
9364+ // the guard is right, the fixture had shrunk under it).
9365+ let (width, height) = (256usize, 128usize);
9214 let pictures: Vec<Picture> =9366 let pictures: Vec<Picture> =
9215 (0..5).map(|i| panned_test_card(width, height, i * 3)).collect();9367 (0..5).map(|i| panned_test_card(width, height, i * 3)).collect();
9216 let _ = take_inter_tx_split_hits();9368 let _ = take_inter_tx_split_hits();
@@ -10242,7 +10394,7 @@ mod tests {
10242 })10394 })
10243 };10395 };
10244 let pins: [(u8, usize, u64); 2] =10396 let pins: [(u8, usize, u64); 2] =
10245- [(150, 7084, 0xe6a9_2f62_3855_0eee), (60, 26116, 0xa831_9866_b799_80fc)];10397+ [(150, 7084, 0x00bc_da74_e540_28d7), (60, 25905, 0x1623_f794_727e_0716)];
10246 for (q, bytes, hash) in pins {10398 for (q, bytes, hash) in pins {
10247 let encoded = encode_sequence(&source, q, 0.5).unwrap();10399 let encoded = encode_sequence(&source, q, 0.5).unwrap();
10248 assert_eq!(10400 assert_eq!(
@@ -10485,6 +10637,7 @@ mod tests {
10485 let _ = crate::tile::take_compound_mode_hits();10637 let _ = crate::tile::take_compound_mode_hits();
10486 let _ = crate::tile::take_compound_pair_hits();10638 let _ = crate::tile::take_compound_pair_hits();
10487 let _ = crate::tile::take_compound_size_hits();10639 let _ = crate::tile::take_compound_size_hits();
10640+ let _ = crate::tile::take_compound_leaf_mode_hits();
10488 let _ = crate::motion::take_census();10641 let _ = crate::motion::take_census();
10489 let (ours, ours_wall) = match pyramid_from_env() {10642 let (ours, ours_wall) = match pyramid_from_env() {
10490 None => our_ladder(name, &source, width, height, fctx),10643 None => our_ladder(name, &source, width, height, fctx),
@@ -10527,6 +10680,7 @@ mod tests {
10527 let comp_modes = crate::tile::take_compound_mode_hits();10680 let comp_modes = crate::tile::take_compound_mode_hits();
10528 let comp_pairs = crate::tile::take_compound_pair_hits();10681 let comp_pairs = crate::tile::take_compound_pair_hits();
10529 let comp_sizes = crate::tile::take_compound_size_hits();10682 let comp_sizes = crate::tile::take_compound_size_hits();
10683+ let comp_leaf = crate::tile::take_compound_leaf_mode_hits();
10530 let comp_total: usize = comp_modes.iter().sum();10684 let comp_total: usize = comp_modes.iter().sum();
10531 eprintln!(10685 eprintln!(
10532 "{name}: compound {comp_total} of {} inter blocks ({:.1}%); modes \10686 "{name}: compound {comp_total} of {} inter blocks ({:.1}%); modes \
@@ -10538,6 +10692,12 @@ mod tests {
10538 comp_modes[6], comp_modes[7],10692 comp_modes[6], comp_modes[7],
10539 comp_pairs[3], comp_pairs[6],10693 comp_pairs[3], comp_pairs[6],
10540 );10694 );
10695+ eprintln!(
10696+ "{name}: leaf (16x16 and below) compound modes NEAREST_NEAREST {} \
10697+ NEAR_NEAR {} NEAREST_NEW {} NEW_NEAREST {} GLOBAL_GLOBAL {} NEW_NEW {}",
10698+ comp_leaf[0], comp_leaf[1], comp_leaf[2], comp_leaf[3], comp_leaf[6],
10699+ comp_leaf[7],
10700+ );
10541 eprintln!(10701 eprintln!(
10542 "{name}: compound by size 8x8 {} 16x16 {} 32x32 {}",10702 "{name}: compound by size 8x8 {} 16x16 {} 32x32 {}",
10543 comp_sizes[1], comp_sizes[2], comp_sizes[3],10703 comp_sizes[1], comp_sizes[2], comp_sizes[3],
crates/ec-av1/src/tile.rsmodified+20 -0
@@ -539,6 +539,23 @@ pub(crate) fn take_compound_size_hits() -> [usize; 4] {
539 std::array::from_fn(|i| COMPOUND_SIZE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))539 std::array::from_fn(|i| COMPOUND_SIZE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
540 }540 }
541 541
542+/// The compound mode histogram of the LEAVES alone (`bw4 <= 4`, so 16x16 and
543+/// below). The frame-wide histogram above cannot say whether a mode reaches
544+/// the leaves at all, which is exactly the question every leaf compound step
545+/// asks (gate-blind-to-feature): before lane-av1comp4 gave a leaf its second
546+/// reference search, the two half-new modes were structurally impossible
547+/// there and screen capture's leaf compound was 100% `NEAREST_NEARESTMV`.
548+static COMPOUND_LEAF_MODE_HITS: [std::sync::atomic::AtomicUsize; 8] =
549+ [const { std::sync::atomic::AtomicUsize::new(0) }; 8];
550+
551+/// Takes and clears the leaf-only compound mode histogram.
552+#[cfg(test)]
553+pub(crate) fn take_compound_leaf_mode_hits() -> [usize; 8] {
554+ std::array::from_fn(|i| {
555+ COMPOUND_LEAF_MODE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed)
556+ })
557+}
558+
542 /// Writes one COMPOUND_REFERENCE block's whole mode chain -- the writer side559 /// Writes one COMPOUND_REFERENCE block's whole mode chain -- the writer side
543 /// of decode.rs' `read_compound_ref_frames` / `read_inter_compound_mode` /560 /// of decode.rs' `read_compound_ref_frames` / `read_inter_compound_mode` /
544 /// `assign_compound_mv` / `comp_group_idx` / `compound_idx` sequence, in that561 /// `assign_compound_mv` / `comp_group_idx` / `compound_idx` sequence, in that
@@ -678,6 +695,9 @@ fn write_compound_block(
678 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);695 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
679 COMPOUND_SIZE_HITS[(bw4.max(1).trailing_zeros() as usize).min(3)]696 COMPOUND_SIZE_HITS[(bw4.max(1).trailing_zeros() as usize).min(3)]
680 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);697 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
698+ if bw4 <= 4 {
699+ COMPOUND_LEAF_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
700+ }
681 if crate::envflags::env_flag!("EC_COMP_MISMATCH") && (mvs.0 != info.mv || mvs.1 != info.mv1) {701 if crate::envflags::env_flag!("EC_COMP_MISMATCH") && (mvs.0 != info.mv || mvs.1 != info.mv1) {
682 eprintln!(702 eprintln!(
683 "EC_COMP_MISMATCH mode={mode} enc=({:?},{:?}) wrote=({:?},{:?})",703 "EC_COMP_MISMATCH mode={mode} enc=({:?},{:?}) wrote=({:?},{:?})",