From 07efe788bd35f66737139e9558ed49d2d7687ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 6 Sep 2026 13:46:38 +0300 Subject: [PATCH] test(av1): the BD census prints the LEAF compound mode histogram The frame-wide histogram cannot say whether a compound mode reaches the leaves, which is the only question the leaf compound steps ask. --- crates/ec-av1/src/encode.rs | 8 ++++++++ crates/ec-av1/src/tile.rs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index da680a2c..99127ac0 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -9987,6 +9987,7 @@ mod tests { let _ = crate::tile::take_compound_mode_hits(); let _ = crate::tile::take_compound_pair_hits(); let _ = crate::tile::take_compound_size_hits(); + let _ = crate::tile::take_compound_leaf_mode_hits(); let _ = crate::motion::take_census(); let (ours, ours_wall) = match pyramid_from_env() { None => our_ladder(name, &source, width, height, fctx), @@ -10029,6 +10030,7 @@ mod tests { let comp_modes = crate::tile::take_compound_mode_hits(); let comp_pairs = crate::tile::take_compound_pair_hits(); let comp_sizes = crate::tile::take_compound_size_hits(); + let comp_leaf = crate::tile::take_compound_leaf_mode_hits(); let comp_total: usize = comp_modes.iter().sum(); eprintln!( "{name}: compound {comp_total} of {} inter blocks ({:.1}%); modes \ @@ -10040,6 +10042,12 @@ mod tests { comp_modes[6], comp_modes[7], comp_pairs[3], comp_pairs[6], ); + eprintln!( + "{name}: leaf (16x16 and below) compound modes NEAREST_NEAREST {} \ + NEAR_NEAR {} NEAREST_NEW {} NEW_NEAREST {} GLOBAL_GLOBAL {} NEW_NEW {}", + comp_leaf[0], comp_leaf[1], comp_leaf[2], comp_leaf[3], comp_leaf[6], + comp_leaf[7], + ); eprintln!( "{name}: compound by size 8x8 {} 16x16 {} 32x32 {}", comp_sizes[1], comp_sizes[2], comp_sizes[3], diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 1eec6119..fe4ff5a3 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -491,6 +491,23 @@ pub(crate) fn take_compound_size_hits() -> [usize; 4] { std::array::from_fn(|i| COMPOUND_SIZE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed)) } +/// The compound mode histogram of the LEAVES alone (`bw4 <= 4`, so 16x16 and +/// below). The frame-wide histogram above cannot say whether a mode reaches +/// the leaves at all, which is exactly the question every leaf compound step +/// asks (gate-blind-to-feature): before lane-av1comp4 gave a leaf its second +/// reference search, the two half-new modes were structurally impossible +/// there and screen capture's leaf compound was 100% `NEAREST_NEARESTMV`. +static COMPOUND_LEAF_MODE_HITS: [std::sync::atomic::AtomicUsize; 8] = + [const { std::sync::atomic::AtomicUsize::new(0) }; 8]; + +/// Takes and clears the leaf-only compound mode histogram. +#[cfg(test)] +pub(crate) fn take_compound_leaf_mode_hits() -> [usize; 8] { + std::array::from_fn(|i| { + COMPOUND_LEAF_MODE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed) + }) +} + /// Writes one COMPOUND_REFERENCE block's whole mode chain -- the writer side /// of decode.rs' `read_compound_ref_frames` / `read_inter_compound_mode` / /// `assign_compound_mv` / `comp_group_idx` / `compound_idx` sequence, in that @@ -630,6 +647,9 @@ fn write_compound_block( .fetch_add(1, std::sync::atomic::Ordering::Relaxed); COMPOUND_SIZE_HITS[(bw4.max(1).trailing_zeros() as usize).min(3)] .fetch_add(1, std::sync::atomic::Ordering::Relaxed); + if bw4 <= 4 { + COMPOUND_LEAF_MODE_HITS[mode].fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } if crate::envflags::env_flag!("EC_COMP_MISMATCH") && (mvs.0 != info.mv || mvs.1 != info.mv1) { eprintln!( "EC_COMP_MISMATCH mode={mode} enc=({:?},{:?}) wrote=({:?},{:?})",