forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1comp3' (d9be6595): compound candidates at the 16x16/8x8 leaves; straddling-leaf mi publication goes through record_mi

Browse files at this commit

8b1a73301319be5949f08e2f997e294e1635b8a0Ahmet Kaan GümüşParent: 691f69e8974f27
BD vs libaom +94.4/+104.3/+66.8 -> +83.0/+99.9/+66.4, vs rav1e
+47.5/+63.6/+10.7 -> +39.7/+60.0/+10.2; compound share 26-34% of inter
blocks; EC_COMP_MISMATCH 0. SPLIT_RD_THRESHOLD re-swept, stays 0.125.
crates/ec-av1/src/encode.rsmodified+259 -92
@@ -190,6 +190,21 @@ fn extra_new_skip_margin() -> f64 {
190 }190 }
191 }191 }
192 192
193+/// 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 compound
195+/// block at any leaf size (`tile::write_inter_frame_leaf`/`..._leaf8` both
196+/// route through `write_compound_block`, which is sized by `bw4`/`bh4`); what
197+/// was missing was the encoder ever forming one below 32x32.
198+const LEAF_COMPOUND: bool = true;
199+
200+/// [`LEAF_COMPOUND`], or what `EC_AV1_LEAF_COMPOUND` names in any build.
201+fn leaf_compound() -> bool {
202+ match std::env::var("EC_AV1_LEAF_COMPOUND").ok() {
203+ Some(v) => v != "0",
204+ None => LEAF_COMPOUND,
205+ }
206+}
207+
193 /// [`LEAF_NEW_MV`], or what `EC_AV1_LEAF_NEWMV` names in a test build.208 /// [`LEAF_NEW_MV`], or what `EC_AV1_LEAF_NEWMV` names in a test build.
194 fn leaf_new_mv() -> bool {209 fn leaf_new_mv() -> bool {
195 match std::env::var("EC_AV1_LEAF_NEWMV").ok() {210 match std::env::var("EC_AV1_LEAF_NEWMV").ok() {
@@ -2813,7 +2828,12 @@ fn code_square_inter(
2813 search: &Search,2828 search: &Search,
2814 mode_bits: &[f64; 13],2829 mode_bits: &[f64; 13],
2815 reference: &Picture,2830 reference: &Picture,
2816- stack: &MvStack, fctx: &crate::decode::FrameCtx,2831+ stack: &MvStack,
2832+ // The COMPOUND stack of each `LAST` + extra-reference pair, built at THIS
2833+ // leaf's own `bw4`/`bh4` (empty on a frame that does not code
2834+ // `reference_select`, and at the straddling call sites).
2835+ compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)],
2836+ fctx: &crate::decode::FrameCtx,
2817 ) -> (BlockCoeffs, f64) {2837 ) -> (BlockCoeffs, f64) {
2818 let (intra_block, intra_cost) =2838 let (intra_block, intra_cost) =
2819 code_square(2839 code_square(
@@ -2950,7 +2970,12 @@ fn code_square_inter(
2950 // not code the movement it split for. Same candidate `search_inter_block`2970 // not code the movement it split for. Same candidate `search_inter_block`
2951 // prices for a whole block -- `motion::search` from `pred_mv`, rounded to2971 // prices for a whole block -- `motion::search` from `pred_mv`, rounded to
2952 // a vector the residual syntax can name -- at this leaf's own side.2972 // a vector the residual syntax can name -- at this leaf's own side.
2953- let mut best = (inter_cost, None);2973+ let mut best: (f64, Option<(Trial, Trial, Trial, bool, InterInfo)>) = (inter_cost, None);
2974+ // This leaf's own `NEWMV` vector, kept whether or not it won the
2975+ // single-reference comparison: it seeds the compound half-new candidate
2976+ // below, exactly as `search_inter_block` seeds its own from the searches
2977+ // it already ran.
2978+ let mut searched_new: Option<(i32, i32)> = None;
2954 if leaf_new_mv() {2979 if leaf_new_mv() {
2955 let source_block = luma.source_block(x, y, side);2980 let source_block = luma.source_block(x, y, side);
2956 let (seeds, seed_n) = mv_seeds(stack);2981 let (seeds, seed_n) = mv_seeds(stack);
@@ -2971,6 +2996,7 @@ fn code_square_inter(
2971 );2996 );
2972 let new_mv = round_to_valid_mv(found.mv, stack.pred_mv);2997 let new_mv = round_to_valid_mv(found.mv, stack.pred_mv);
2973 if let Some(mv_bits) = mv_residual_bits(new_mv, stack.pred_mv) {2998 if let Some(mv_bits) = mv_residual_bits(new_mv, stack.pred_mv) {
2999+ searched_new = Some(new_mv);
2974 // Same reuse as `search_inter_block`: a NEWMV equal to the3000 // Same reuse as `search_inter_block`: a NEWMV equal to the
2975 // stack's NEARESTMV is the same three trials, already run above.3001 // stack's NEARESTMV is the same three trials, already run above.
2976 let (luma_new, u_new, v_new) = if new_mv == mv {3002 let (luma_new, u_new, v_new) = if new_mv == mv {
@@ -3017,15 +3043,170 @@ fn code_square_inter(
3017 luma_new.bits + u_new.bits + v_new.bits3043 luma_new.bits + u_new.bits + v_new.bits
3018 });3044 });
3019 if cost_new < best.0 {3045 if cost_new < best.0 {
3020- best = (cost_new, Some((luma_new, u_new, v_new, skip_new, new_mv)));3046+ best = (
3047+ cost_new,
3048+ Some((
3049+ luma_new,
3050+ u_new,
3051+ v_new,
3052+ skip_new,
3053+ InterInfo {
3054+ ref1: None,
3055+ mv1: (0, 0),
3056+ ref_frame: crate::mvstack::LAST_FRAME,
3057+ mode: InterMode::NewMv,
3058+ mv: new_mv,
3059+ ref_mv_idx: 0,
3060+ },
3061+ )),
3062+ );
3021 }3063 }
3022 }3064 }
3023 }3065 }
3024- if let (cost, Some((luma_new, u_new, v_new, skip_new, new_mv))) = best {3066+
3025- if cost < intra_cost {3067+ // The COMPOUND candidates at this leaf (lane-av1comp3), the same set
3026- let (levels, tx_depth, dcost) = commit_inter_luma(3068+ // `search_inter_block` prices for a whole 32x32 block minus the two that
3027- luma, (x, y), side, new_mv, (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), search, &luma_new, skip_new, fctx,3069+ // need a motion search against the SECOND reference: a leaf never runs
3070+ // one (`NEAREST_NEWMV`/`NEW_NEWMV` would each cost another
3071+ // `motion::search` per extra reference per leaf), so the set here is
3072+ // `NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV` and `NEW_NEARESTMV` off the
3073+ // vector this leaf already searched. Priced with the same static-CDF
3074+ // approximation, plus the compound-only syntax the writer emits.
3075+ for (ref1, g, cstack) in compound.iter().filter(|_| leaf_compound()) {
3076+ let (ref1, g) = (*ref1, *g);
3077+ let uni =
3078+ (crate::mvstack::BWDREF_FRAME..=crate::mvstack::ALTREF_FRAME).contains(&ref1);
3079+ let pair_bits = symbol_bits(&cdf::COMP_MODE[0], 1)
3080+ + if uni {
3081+ symbol_bits(&cdf::COMP_REF_TYPE[0], 1)
3082+ + symbol_bits(&cdf::COMP_REF[0][0], 0)
3083+ + symbol_bits(&cdf::COMP_REF[0][1], 0)
3084+ + symbol_bits(&cdf::COMP_BWDREF[0][0], 1)
3085+ } else {
3086+ symbol_bits(&cdf::COMP_REF_TYPE[0], 0)
3087+ + symbol_bits(&cdf::UNI_COMP_REF[0][0], 0)
3088+ + symbol_bits(&cdf::UNI_COMP_REF[0][1], 1)
3089+ + symbol_bits(&cdf::UNI_COMP_REF[0][2], 1)
3090+ };
3091+ let mode_ctx =
3092+ cdf::COMPOUND_MODE_CTX_MAP[cstack.ref_mv_ctx >> 1][cstack.new_mv_ctx.min(4)];
3093+ let mode_bits_of =
3094+ |mode: usize| pair_bits + symbol_bits(&cdf::INTER_COMPOUND_MODE[mode_ctx], mode);
3095+ let mut ccands: Vec<(((i32, i32), (i32, i32)), f64, InterInfo)> = vec![
3096+ (
3097+ cstack.nearest_mv,
3098+ mode_bits_of(0),
3099+ InterInfo {
3100+ ref_frame: crate::mvstack::LAST_FRAME,
3101+ mode: InterMode::NearestNearestMv,
3102+ mv: cstack.nearest_mv.0,
3103+ mv1: cstack.nearest_mv.1,
3104+ ref1: Some(ref1),
3105+ ref_mv_idx: 0,
3106+ },
3107+ ),
3108+ (
3109+ ((0, 0), (0, 0)),
3110+ mode_bits_of(6),
3111+ InterInfo {
3112+ ref_frame: crate::mvstack::LAST_FRAME,
3113+ mode: InterMode::GlobalGlobalMv,
3114+ mv: (0, 0),
3115+ mv1: (0, 0),
3116+ ref1: Some(ref1),
3117+ ref_mv_idx: 0,
3118+ },
3119+ ),
3120+ ];
3121+ // `NEW_NEARESTMV`: the NEW half is this leaf's own searched vector,
3122+ // its residual priced against compound stack entry 0 (what
3123+ // `assign_compound_mv` predicts from at `ref_mv_idx = 0`).
3124+ let cbase = cstack
3125+ .entries
3126+ .first()
3127+ .map_or(cstack.nearest_mv, |e| (e.mv0, e.mv1));
3128+ if let Some(new_mv) = searched_new {
3129+ if let Some(b0) = mv_residual_bits(new_mv, cbase.0) {
3130+ ccands.push((
3131+ (new_mv, cstack.nearest_mv.1),
3132+ mode_bits_of(3) + b0,
3133+ InterInfo {
3134+ ref_frame: crate::mvstack::LAST_FRAME,
3135+ mode: InterMode::NewNearestMv,
3136+ mv: new_mv,
3137+ mv1: cstack.nearest_mv.1,
3138+ ref1: Some(ref1),
3139+ ref_mv_idx: 0,
3140+ },
3141+ ));
3142+ }
3143+ }
3144+ ccands.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1)));
3145+ ccands.dedup_by_key(|c| c.0);
3146+ let g_luma = (g.y.as_slice(), g.width, luma.true_width, luma.true_height);
3147+ let g_u = (
3148+ g.u.as_slice(),
3149+ g.width / 2,
3150+ chroma[0].true_width,
3151+ chroma[0].true_height,
3152+ );
3153+ let g_v = (
3154+ g.v.as_slice(),
3155+ g.width / 2,
3156+ chroma[1].true_width,
3157+ chroma[1].true_height,
3158+ );
3159+ for (mvs, bits, info) in ccands {
3160+ let luma_c = mc_trial_compound(
3161+ luma, x, y, side, mvs, true,
3162+ (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), g_luma,
3163+ search.base_q_idx, search.deadzone, luma_set, fctx,
3028 );3164 );
3165+ let u_c = mc_trial_compound(
3166+ &chroma[0], x / 2, y / 2, side / 2, mvs, false,
3167+ (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), g_u,
3168+ search.base_q_idx, search.deadzone, chroma_set, fctx,
3169+ );
3170+ let v_c = mc_trial_compound(
3171+ &chroma[1], x / 2, y / 2, side / 2, mvs, false,
3172+ (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), g_v,
3173+ search.base_q_idx, search.deadzone, chroma_set, fctx,
3174+ );
3175+ let skip_c = luma_c.levels.iter().all(|&l| l == 0)
3176+ && u_c.levels.iter().all(|&l| l == 0)
3177+ && v_c.levels.iter().all(|&l| l == 0);
3178+ let cost_c = luma_c.sse
3179+ + u_c.sse
3180+ + v_c.sse
3181+ + search.lambda
3182+ * (skip_bits(skip_c)
3183+ + intra_inter_bits(true)
3184+ + bits
3185+ + if skip_c { 0.0 } else { luma_c.bits + u_c.bits + v_c.bits });
3186+ if cost_c < best.0 {
3187+ best = (cost_c, Some((luma_c, u_c, v_c, skip_c, info)));
3188+ }
3189+ }
3190+ }
3191+
3192+ if let (cost, Some((luma_new, u_new, v_new, skip_new, info))) = best {
3193+ if cost < intra_cost {
3194+ // A compound winner commits the flat trial it was priced from:
3195+ // `commit_inter_luma`'s var-tx trial set is single-reference
3196+ // (`mc_trial`), so a compound leaf codes `tx_depth = 0`.
3197+ // corner-cut: no var-tx split for a compound leaf -- ceiling is
3198+ // the split gain on 16x16 compound blocks; upgrade path is a
3199+ // compound `commit_inter_luma` taking both references.
3200+ let (levels, tx_depth, dcost) = if info.ref1.is_some() {
3201+ luma.commit(x, y, side, &luma_new);
3202+ (luma_new.levels.clone(), 0, 0.0)
3203+ } else {
3204+ commit_inter_luma(
3205+ luma, (x, y), side, info.mv,
3206+ (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3),
3207+ search, &luma_new, skip_new, fctx,
3208+ )
3209+ };
3029 chroma[0].commit(x / 2, y / 2, side / 2, &u_new);3210 chroma[0].commit(x / 2, y / 2, side / 2, &u_new);
3030 chroma[1].commit(x / 2, y / 2, side / 2, &v_new);3211 chroma[1].commit(x / 2, y / 2, side / 2, &v_new);
3031 return (3212 return (
@@ -3040,14 +3221,7 @@ fn code_square_inter(
3040 palette: None,3221 palette: None,
3041 palette_uv: None,3222 palette_uv: None,
3042 tx_depth,3223 tx_depth,
3043- inter: Some(InterInfo {3224+ inter: Some(info),
3044- ref1: None,
3045- mv1: (0, 0),
3046- ref_frame: crate::mvstack::LAST_FRAME,
3047- mode: InterMode::NewMv,
3048- mv: new_mv,
3049- ref_mv_idx: 0,
3050- }),
3051 },3225 },
3052 cost + dcost,3226 cost + dcost,
3053 );3227 );
@@ -5804,6 +5978,30 @@ pub(crate) fn encode_inter_frame(
5804 let stack = find_mv_stack(5978 let stack = find_mv_stack(
5805 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,5979 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
5806 );5980 );
5981+ let cstacks: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> =
5982+ if header.reference_select && leaf_compound() {
5983+ [
5984+ (crate::mvstack::GOLDEN_FRAME, golden),
5985+ (crate::mvstack::ALTREF_FRAME, altref),
5986+ ]
5987+ .into_iter()
5988+ .filter_map(|(r, pic)| {
5989+ pic.map(|p| {
5990+ (
5991+ r,
5992+ p,
5993+ crate::mvstack::find_mv_stack_compound(
5994+ &grid, mi_row, mi_col, 4, 4,
5995+ (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows,
5996+ grid.sign_bias_table(), &[(0, 0); 7], None,
5997+ ),
5998+ )
5999+ })
6000+ })
6001+ .collect()
6002+ } else {
6003+ Vec::new()
6004+ };
5807 let (leaf, leaf_cost) = code_square_inter(6005 let (leaf, leaf_cost) = code_square_inter(
5808 &mut luma,6006 &mut luma,
5809 &mut chroma,6007 &mut chroma,
@@ -5812,7 +6010,7 @@ pub(crate) fn encode_inter_frame(
5812 &search,6010 &search,
5813 &mode_bits_table,6011 &mode_bits_table,
5814 reference,6012 reference,
5815- &stack, fctx,6013+ &stack, &cstacks, fctx,
5816 );6014 );
5817 let leaf_cost = leaf_cost6015 let leaf_cost = leaf_cost
5818 + search.lambda * partition_bits(SUB, false);6016 + search.lambda * partition_bits(SUB, false);
@@ -5841,6 +6039,30 @@ pub(crate) fn encode_inter_frame(
5841 let stack8 = find_mv_stack(6039 let stack8 = find_mv_stack(
5842 &grid, mr, mc, 2, 2, LAST_FRAME, mi_cols, mi_rows,6040 &grid, mr, mc, 2, 2, LAST_FRAME, mi_cols, mi_rows,
5843 );6041 );
6042+ let cstacks8: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> =
6043+ if header.reference_select && leaf_compound() {
6044+ [
6045+ (crate::mvstack::GOLDEN_FRAME, golden),
6046+ (crate::mvstack::ALTREF_FRAME, altref),
6047+ ]
6048+ .into_iter()
6049+ .filter_map(|(r, pic)| {
6050+ pic.map(|p| {
6051+ (
6052+ r,
6053+ p,
6054+ crate::mvstack::find_mv_stack_compound(
6055+ &grid, mr, mc, 2, 2,
6056+ (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows,
6057+ grid.sign_bias_table(), &[(0, 0); 7], None,
6058+ ),
6059+ )
6060+ })
6061+ })
6062+ .collect()
6063+ } else {
6064+ Vec::new()
6065+ };
5844 let (leaf8, cost) = code_square_inter(6066 let (leaf8, cost) = code_square_inter(
5845 &mut luma,6067 &mut luma,
5846 &mut chroma,6068 &mut chroma,
@@ -5849,7 +6071,7 @@ pub(crate) fn encode_inter_frame(
5849 &search,6071 &search,
5850 &mode_bits_table,6072 &mode_bits_table,
5851 reference,6073 reference,
5852- &stack8, fctx,6074+ &stack8, &cstacks8, fctx,
5853 );6075 );
5854 cost8 += cost;6076 cost8 += cost;
5855 record_mi(&mut grid, mr, mc, 2, leaf8.inter);6077 record_mi(&mut grid, mr, mc, 2, leaf8.inter);
@@ -5950,42 +6172,15 @@ pub(crate) fn encode_inter_frame(
5950 &search,6172 &search,
5951 &mode_bits_table,6173 &mode_bits_table,
5952 reference,6174 reference,
5953- &stack, fctx,6175+ &stack, &[], fctx,
5954- );6176+ );
5955- for dr in 0..4 {6177+ // One publication point for every coded leaf
5956- for dc in 0..4 {6178+ // (`record_mi`): this site used to spell the vote
5957- grid.set(6179+ // out with `ref_frame` pinned to LAST and `mv1`
5958- mi_row + dr,6180+ // to (0,0), which is the encoder-grid-drift class
5959- mi_col + dc,6181+ // -- correct only for as long as a leaf can never
5960- match block.inter {6182+ // be compound.
5961- Some(info) => MiInfo {6183+ record_mi(&mut grid, mi_row, mi_col, 4, block.inter);
5962- is_inter: true,
5963- ref_frame: LAST_FRAME,
5964- ref_frame1: NO_REF1,
5965- mv1: (0, 0),
5966- mv: mv16(info.mv),
5967- is_new_mv: matches!(info.mode, InterMode::NewMv),
5968- size: 4,
5969- size_h: 4,
5970- is_global_mv0: false,
5971- is_global_mv1: false,
5972- },
5973- None => MiInfo {
5974- is_inter: false,
5975- ref_frame: -1,
5976- ref_frame1: NO_REF1,
5977- mv1: (0, 0),
5978- mv: (0, 0),
5979- is_new_mv: false,
5980- size: 4,
5981- size_h: 4,
5982- is_global_mv0: false,
5983- is_global_mv1: false,
5984- },
5985- },
5986- );
5987- }
5988- }
5989 leaves.push(block);6184 leaves.push(block);
5990 } else {6185 } else {
5991 let (x_sub, y_sub) = (sc * SUB, sr * SUB);6186 let (x_sub, y_sub) = (sc * SUB, sr * SUB);
@@ -6010,45 +6205,11 @@ pub(crate) fn encode_inter_frame(
6010 &search,6205 &search,
6011 &mode_bits_table,6206 &mode_bits_table,
6012 reference,6207 reference,
6013- &stack, fctx,6208+ &stack, &[], fctx,
6014- );
6015- for dr in 0..2 {
6016- for dc in 0..2 {
6017- grid.set(
6018- mi_row + dr,
6019- mi_col + dc,
6020- match leaf.inter {
6021- Some(info) => MiInfo {
6022- is_inter: true,
6023- ref_frame: LAST_FRAME,
6024- ref_frame1: NO_REF1,
6025- mv1: (0, 0),
6026- mv: mv16(info.mv),
6027- is_new_mv: matches!(
6028- info.mode,
6029- InterMode::NewMv
6030- ),
6031- size: 2,
6032- size_h: 2,
6033- is_global_mv0: false,
6034- is_global_mv1: false,
6035- },
6036- None => MiInfo {
6037- is_inter: false,
6038- ref_frame: -1,
6039- ref_frame1: NO_REF1,
6040- mv1: (0, 0),
6041- mv: (0, 0),
6042- is_new_mv: false,
6043- size: 2,
6044- size_h: 2,
6045- is_global_mv0: false,
6046- is_global_mv1: false,
6047- },
6048- },
6049 );6209 );
6050- }6210+ // Same publication point as the 16x16
6051- }6211+ // straddling leaf above (`record_mi`).
6212+ record_mi(&mut grid, mi_row, mi_col, 2, leaf.inter);
6052 eight.push(leaf);6213 eight.push(leaf);
6053 }6214 }
6054 leaves.push(BlockCoeffs {6215 leaves.push(BlockCoeffs {
@@ -9390,7 +9551,7 @@ mod tests {
9390 })9551 })
9391 };9552 };
9392 let pins: [(u8, usize, u64); 2] =9553 let pins: [(u8, usize, u64); 2] =
9393- [(150, 7103, 0xb9b7_763b_6f18_a887), (60, 26778, 0x4071_f16e_1e5d_87c3)];9554+ [(150, 7084, 0xe6a9_2f62_3855_0eee), (60, 26116, 0xa831_9866_b799_80fc)];
9394 for (q, bytes, hash) in pins {9555 for (q, bytes, hash) in pins {
9395 let encoded = encode_sequence(&source, q, 0.5).unwrap();9556 let encoded = encode_sequence(&source, q, 0.5).unwrap();
9396 assert_eq!(9557 assert_eq!(
@@ -9625,6 +9786,7 @@ mod tests {
9625 let _ = crate::tile::take_ref_hits();9786 let _ = crate::tile::take_ref_hits();
9626 let _ = crate::tile::take_compound_mode_hits();9787 let _ = crate::tile::take_compound_mode_hits();
9627 let _ = crate::tile::take_compound_pair_hits();9788 let _ = crate::tile::take_compound_pair_hits();
9789+ let _ = crate::tile::take_compound_size_hits();
9628 let _ = crate::motion::take_census();9790 let _ = crate::motion::take_census();
9629 let (ours, ours_wall) = match pyramid_from_env() {9791 let (ours, ours_wall) = match pyramid_from_env() {
9630 None => our_ladder(&source, width, height, fctx),9792 None => our_ladder(&source, width, height, fctx),
@@ -9666,6 +9828,7 @@ mod tests {
9666 // picks cannot be what a BD number credits).9828 // picks cannot be what a BD number credits).
9667 let comp_modes = crate::tile::take_compound_mode_hits();9829 let comp_modes = crate::tile::take_compound_mode_hits();
9668 let comp_pairs = crate::tile::take_compound_pair_hits();9830 let comp_pairs = crate::tile::take_compound_pair_hits();
9831+ let comp_sizes = crate::tile::take_compound_size_hits();
9669 let comp_total: usize = comp_modes.iter().sum();9832 let comp_total: usize = comp_modes.iter().sum();
9670 eprintln!(9833 eprintln!(
9671 "{name}: compound {comp_total} of {} inter blocks ({:.1}%); modes \9834 "{name}: compound {comp_total} of {} inter blocks ({:.1}%); modes \
@@ -9677,6 +9840,10 @@ mod tests {
9677 comp_modes[6], comp_modes[7],9840 comp_modes[6], comp_modes[7],
9678 comp_pairs[3], comp_pairs[6],9841 comp_pairs[3], comp_pairs[6],
9679 );9842 );
9843+ eprintln!(
9844+ "{name}: compound by size 8x8 {} 16x16 {} 32x32 {}",
9845+ comp_sizes[1], comp_sizes[2], comp_sizes[3],
9846+ );
9680 // Where the wall-owning stage actually goes: how many candidate9847 // Where the wall-owning stage actually goes: how many candidate
9681 // evaluations (one `mc::predict` + SAD each) a search spends, how9848 // evaluations (one `mc::predict` + SAD each) a search spends, how
9682 // many of them are subpel, and how often the winner is the seed9849 // many of them are subpel, and how often the winner is the seed
crates/ec-av1/src/tile.rsmodified+15 -0
@@ -478,6 +478,19 @@ pub(crate) fn take_compound_pair_hits() -> [usize; 7] {
478 std::array::from_fn(|i| COMPOUND_PAIR_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))478 std::array::from_fn(|i| COMPOUND_PAIR_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
479 }479 }
480 480
481+/// Per-SIZE fire counts of [`write_compound_block`], indexed by
482+/// `log2(bw4)` (1 = 8x8, 2 = 16x16, 3 = 32x32 and up): compound started as a
483+/// 32x32-only tool, so the share by size is what says whether the leaf
484+/// candidates fire at all (gate-blind-to-feature).
485+static COMPOUND_SIZE_HITS: [std::sync::atomic::AtomicUsize; 4] =
486+ [const { std::sync::atomic::AtomicUsize::new(0) }; 4];
487+
488+/// Takes and clears the compound size histogram.
489+#[cfg(test)]
490+pub(crate) fn take_compound_size_hits() -> [usize; 4] {
491+ std::array::from_fn(|i| COMPOUND_SIZE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
492+}
493+
481 /// Writes one COMPOUND_REFERENCE block's whole mode chain -- the writer side494 /// Writes one COMPOUND_REFERENCE block's whole mode chain -- the writer side
482 /// of decode.rs' `read_compound_ref_frames` / `read_inter_compound_mode` /495 /// of decode.rs' `read_compound_ref_frames` / `read_inter_compound_mode` /
483 /// `assign_compound_mv` / `comp_group_idx` / `compound_idx` sequence, in that496 /// `assign_compound_mv` / `comp_group_idx` / `compound_idx` sequence, in that
@@ -615,6 +628,8 @@ fn write_compound_block(
615 COMPOUND_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed);628 COMPOUND_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
616 COMPOUND_PAIR_HITS[(ref1.max(1) - 1) as usize % 7]629 COMPOUND_PAIR_HITS[(ref1.max(1) - 1) as usize % 7]
617 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);630 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
631+ COMPOUND_SIZE_HITS[(bw4.max(1).trailing_zeros() as usize).min(3)]
632+ .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
618 if crate::envflags::env_flag!("EC_COMP_MISMATCH") && (mvs.0 != info.mv || mvs.1 != info.mv1) {633 if crate::envflags::env_flag!("EC_COMP_MISMATCH") && (mvs.0 != info.mv || mvs.1 != info.mv1) {
619 eprintln!(634 eprintln!(
620 "EC_COMP_MISMATCH mode={mode} enc=({:?},{:?}) wrote=({:?},{:?})",635 "EC_COMP_MISMATCH mode={mode} enc=({:?},{:?}) wrote=({:?},{:?})",