forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-arfmode' (89109746): the top-ARF offer-set bitmask ships default OFF and bit-exact (pins 8291/33227 at default and SPEED=6, witness fires and stays sample-exact) -- EC_AV1_ARFMODE offers no-intra / no-RD-8x8 / no-compound at the top ARF only; fresh census: the top-ARF gap is +2188 B/frame on film B, mode+partition+mv now 44%/38% of it (intra fallback 15% of area, compound 24%, 8x8-heavy partitions, NEW-mv 45%); server-1 gate chain (control already the standing table to the digit) delivers the deciding logs -- keep-rule read deferred to the next session

Browse files at this commit

21710114ad714d21b0a9050d2e836d4a4457cdb0Ahmet Kaan GümüşParent: e9ee943e135fad
crates/ec-av1/examples/enc_probe.rsmodified+7 -0
@@ -73,6 +73,13 @@ fn main() {
73 println!(" census luma SAD rank of RD winner: {}", pct(&luma_rank));73 println!(" census luma SAD rank of RD winner: {}", pct(&luma_rank));
74 println!(" census chroma SAD rank of RD winner: {}", pct(&chroma_rank));74 println!(" census chroma SAD rank of RD winner: {}", pct(&chroma_rank));
75 }75 }
76+ // lane-arfmode: the engagement counter of the top ARF's offer-set
77+ // lever, taken once per point so an armed run PRINTS a non-zero count
78+ // (class gate-blind-to-feature; a BD number over a counter of zero
79+ // proves nothing). Zeros when `EC_AV1_ARFMODE` is unset, which is the
80+ // control's own expectation.
81+ let hits = ec_av1::encode::take_arfmode_hits();
82+ println!(" arfmode hits: {} {} {}", hits[0], hits[1], hits[2]);
76 }83 }
77 println!("wall {:.3}s", start.elapsed().as_secs_f64());84 println!("wall {:.3}s", start.elapsed().as_secs_f64());
78 }85 }
crates/ec-av1/src/encode.rsmodified+164 -44
@@ -6862,7 +6862,14 @@ fn code_square_inter(
6862 refs: &[Option<&Picture>; 8],6862 refs: &[Option<&Picture>; 8],
6863 fctx: &crate::decode::FrameCtx,6863 fctx: &crate::decode::FrameCtx,
6864 ) -> (BlockCoeffs, f64) {6864 ) -> (BlockCoeffs, f64) {
6865- let (intra_block, intra_cost) =6865+ // lane-arfmode: at the top ARF (arm 1) the leaf offers no intra
6866+ // candidate at all -- `intra_cost` stays at infinity, so every
6867+ // comparison below takes an inter candidate and the fallback arm at the
6868+ // tail is unreachable. The planes hold what the caller snapshotted until
6869+ // the winner commits: the intra trial used to commit here and be
6870+ // overwritten by the inter commit, so skipping it changes no committed
6871+ // sample, only work.
6872+ let (intra_block, intra_cost) = if search.arf_leaf_intra {
6866 code_square(6873 code_square(
6867 luma,6874 luma,
6868 chroma,6875 chroma,
@@ -6874,7 +6881,11 @@ fn code_square_inter(
6874 None,6881 None,
6875 false,6882 false,
6876 fctx,6883 fctx,
6877- );6884+ )
6885+ } else {
6886+ arfmode_hit(0);
6887+ (BlockCoeffs::default(), f64::INFINITY)
6888+ };
6878 let luma_set = if side == 8 {6889 let luma_set = if side == 8 {
6879 TxbSet::Luma8Inter6890 TxbSet::Luma8Inter
6880 } else {6891 } else {
@@ -7129,7 +7140,13 @@ fn code_square_inter(
7129 // SECOND-reference search of its own -- `NEAREST_NEWMV` and `NEW_NEWMV`7140 // SECOND-reference search of its own -- `NEAREST_NEWMV` and `NEW_NEWMV`
7130 // too. Priced with the same static-CDF approximation, plus the7141 // too. Priced with the same static-CDF approximation, plus the
7131 // compound-only syntax the writer emits.7142 // compound-only syntax the writer emits.
7132- for (ref1, g, cstack) in compound.iter().filter(|_| leaf_compound()) {7143+ if leaf_compound() && !search.arf_leaf_compound && !compound.is_empty() {
7144+ // lane-arfmode: arm 4 drops this leaf's compound set (counted once
7145+ // per leaf, not once per pair); the single-reference candidates
7146+ // above stay.
7147+ arfmode_hit(2);
7148+ }
7149+ for (ref1, g, cstack) in compound.iter().filter(|_| leaf_compound() && search.arf_leaf_compound) {
7133 let (ref1, g) = (*ref1, *g);7150 let (ref1, g) = (*ref1, *g);
7134 // The whole `comp_mode` + reference-pair tree at the writer's own7151 // The whole `comp_mode` + reference-pair tree at the writer's own
7135 // contexts, for THIS pair (lane-ctx).7152 // contexts, for THIS pair (lane-ctx).
@@ -7762,11 +7779,79 @@ struct Search<'a> {
7762 /// `intra_pruning_with_hog` -- never prunes it away). `None` runs every7779 /// `intra_pruning_with_hog` -- never prunes it away). `None` runs every
7763 /// mode through full RD, unchanged from before this lever.7780 /// mode through full RD, unchanged from before this lever.
7764 top_k: Option<usize>,7781 top_k: Option<usize>,
7782+ /// lane-arfmode: the top ARF's offer set ([`crate::speed::ARFMODE`])
7783+ /// -- `false` cuts the named candidate group from the whole-32 search
7784+ /// ([`search_inter_block`]), the 16x16/8x8 leaf search
7785+ /// ([`code_square_inter`]) and the 8x8 split offer, at the top ARF
7786+ /// ([`DqLevel::TopArf`] frames only). `true` everywhere else, which is
7787+ /// the pre-lane behaviour: the mid and quarter hidden frames, the shown
7788+ /// leaves and the flat path keep intra and compound, and the
7789+ /// straddling-edge 8x8s are only mode-gated, never partition-gated.
7790+ /// The probe's correction: with the leaf gate ALONE the film A stream
7791+ /// was byte-identical to the control -- the ARF's intra area lives at
7792+ /// the whole-32 level, so the intra arm must cut it there too.
7793+ arf_leaf_intra: bool,
7794+ arf_leaf8: bool,
7795+ arf_leaf_compound: bool,
7796+}
7797+
7798+/// [`Search`]'s ARF fields' source: [`crate::speed::ARFMODE`], or what
7799+/// `EC_AV1_ARFMODE` names on one build (a missing or broken value keeps the
7800+/// shipped table -- 0, bit-exact with the pre-lane encoder).
7801+fn arfmode() -> u8 {
7802+ match ARFMODE_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) {
7803+ u8::MAX => {}
7804+ n => return n,
7805+ }
7806+ static ENV: std::sync::LazyLock<Option<u8>> = std::sync::LazyLock::new(|| {
7807+ crate::envflags::var("EC_AV1_ARFMODE").ok().and_then(|v| v.parse().ok())
7808+ });
7809+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::ARFMODE))
7810+}
7811+
7812+/// [`ARFMODE_OVERRIDE`]: `u8::MAX` clears it.
7813+static ARFMODE_OVERRIDE: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(u8::MAX);
7814+
7815+/// Sets [`ARFMODE_OVERRIDE`]; `None` clears it. Test-only: the env is a
7816+/// process constant ([`crate::envflags`]), so an in-process witness needs
7817+/// this to arm the lever.
7818+#[allow(dead_code)] // set only from the `#[cfg(test)]` witness
7819+pub(crate) fn set_arfmode(n: Option<u8>) {
7820+ ARFMODE_OVERRIDE.store(n.unwrap_or(u8::MAX), std::sync::atomic::Ordering::Relaxed);
7821+}
7822+
7823+/// How often each armed [`crate::speed::ARFMODE`] arm actually fired since
7824+/// the last take (class `gate-blind-to-feature`): 0 = a top-ARF leaf coded
7825+/// with its intra candidate skipped, 1 = a top-ARF 16x16 leaf whose 8x8
7826+/// split the search would have offered and the arm refused, 2 = a top-ARF
7827+/// leaf whose compound set was dropped. A green gate over counts of zero
7828+/// proves nothing about the lever.
7829+static ARFMODE_HITS: [std::sync::atomic::AtomicUsize; 3] = [
7830+ std::sync::atomic::AtomicUsize::new(0),
7831+ std::sync::atomic::AtomicUsize::new(0),
7832+ std::sync::atomic::AtomicUsize::new(0),
7833+];
7834+
7835+/// Records one such hit.
7836+fn arfmode_hit(which: usize) {
7837+ ARFMODE_HITS[which].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
7838+}
7839+
7840+/// [`arfmode_hit`]`(1)` and "no": the `||` arm of the top ARF's 8x8-offer
7841+/// condition, so the counter only runs when every other prune let the split
7842+/// through and the arm alone refuses it.
7843+fn arfmode_hit_and_no() -> bool {
7844+ arfmode_hit(1);
7845+ false
7846+}
7847+
7848+/// Takes (and clears) the counts. `pub` for `examples/enc_probe`, so a
7849+/// probe point can print a non-zero engagement count under the env knob
7850+/// itself -- the counter the gate BD numbers are read against.
7851+pub fn take_arfmode_hits() -> [usize; 3] {
7852+ [0, 1, 2].map(|i| ARFMODE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
7765 }7853 }
7766 7854
7767-/// [`Search::top_k`]'s value: `None` keeps every mode's search unchanged
7768-/// (the default, until a lever's quality gate justifies pruning by default);
7769-/// `EC_AV1_PRUNE_K` sweeps it in a test build without touching callers.
7770 fn prune_top_k() -> Option<usize> {7855 fn prune_top_k() -> Option<usize> {
7771 #[cfg(test)]7856 #[cfg(test)]
7772 {7857 {
@@ -8419,6 +8504,9 @@ pub(crate) fn encode_key_frame_inner(
8419 modes,8504 modes,
8420 top_k: prune_top_k(),8505 top_k: prune_top_k(),
8421 screen,8506 screen,
8507+ arf_leaf_intra: true,
8508+ arf_leaf8: true,
8509+ arf_leaf_compound: true,
8422 };8510 };
8423 8511
8424 // The block grid this frame is coded over: [`crate::tile::block_grid`]'s8512 // The block grid this frame is coded over: [`crate::tile::block_grid`]'s
@@ -10932,43 +11020,52 @@ fn search_inter_block(
10932 _ => search.modes.to_vec(),11020 _ => search.modes.to_vec(),
10933 };11021 };
10934 census_add(5, 1);11022 census_add(5, 1);
10935- census_add(6, intra_modes.len());11023+ census_add(6, if search.arf_leaf_intra { intra_modes.len() } else { 0 });
10936- for &mode in &intra_modes {11024+ // lane-arfmode: arm 1 drops the whole-32 block's intra candidates at the
10937- let luma_trial = luma.trial(11025+ // top ARF too -- the probe proved the ARF's intra AREA lives HERE, not at
10938- At {11026+ // the leaves (film A arm 1 vs control byte-identical with the leaf gate
10939- x,11027+ // alone), so "the 32x32 whole keeps intra as the scene-cut hatch" was a
10940- y,11028+ // hatch nothing else was using. Counted once per block.
10941- side: BLOCK,11029+ if search.arf_leaf_intra {
10942- reach,11030+ for &mode in &intra_modes {
10943- set: luma_set,11031+ let luma_trial = luma.trial(
10944- },11032+ At {
10945- mode,11033+ x,
10946- 0,11034+ y,
10947- search.base_q_idx,11035+ side: BLOCK,
10948- search.deadzone, fctx,11036+ reach,
10949- );11037+ set: luma_set,
10950- let u = u_trial.clone();11038+ },
10951- let v = v_trial.clone();11039+ mode,
10952- let cost = luma_trial.sse11040+ 0,
10953- + u.sse11041+ search.base_q_idx,
10954- + v.sse11042+ search.deadzone, fctx,
10955- + search.lambda11043+ );
10956- * (luma_trial.bits11044+ let u = u_trial.clone();
10957- + u.bits11045+ let v = v_trial.clone();
10958- + v.bits11046+ let cost = luma_trial.sse
10959- + mode_bits[usize::from(mode)]11047+ + u.sse
10960- + skip_bits(false)11048+ + v.sse
10961- + intra_inter_bits(false));11049+ + search.lambda
10962- consider(Candidate {11050+ * (luma_trial.bits
10963- cost,11051+ + u.bits
10964- luma: luma_trial,11052+ + v.bits
10965- u,11053+ + mode_bits[usize::from(mode)]
10966- v,11054+ + skip_bits(false)
10967- mode,11055+ + intra_inter_bits(false));
10968- skip: false,11056+ consider(Candidate {
10969- inter: None,11057+ cost,
10970- mode_bits: mode_bits[usize::from(mode)],11058+ luma: luma_trial,
10971- });11059+ u,
11060+ v,
11061+ mode,
11062+ skip: false,
11063+ inter: None,
11064+ mode_bits: mode_bits[usize::from(mode)],
11065+ });
11066+ }
11067+ } else {
11068+ arfmode_hit(0);
10972 }11069 }
10973 11070
10974 // The reference frame buffer a spec decoder holds is exactly the true11071 // The reference frame buffer a spec decoder holds is exactly the true
@@ -12863,6 +12960,11 @@ pub(crate) fn encode_inter_frame(
12863 ];12960 ];
12864 12961
12865 let step = f64::from(ac_q(8, i32::from(base_q_idx))) / 8.0;12962 let step = f64::from(ac_q(8, i32::from(base_q_idx))) / 8.0;
12963+ let top_arf = matches!(
12964+ pyramid,
12965+ Some(p) if p.dq_level == DqLevel::TopArf
12966+ );
12967+ let arfmode_v = arfmode();
12866 let search = Search {12968 let search = Search {
12867 base_q_idx,12969 base_q_idx,
12868 deadzone,12970 deadzone,
@@ -12876,6 +12978,14 @@ pub(crate) fn encode_inter_frame(
12876 modes: &KEY_FRAME_MODES,12978 modes: &KEY_FRAME_MODES,
12877 top_k: prune_top_k_inter(),12979 top_k: prune_top_k_inter(),
12878 screen,12980 screen,
12981+ // lane-arfmode: the group's own anchor ([`DqLevel::TopArf`], whose
12982+ // offset is the pyramid's own `arf_q_offset`) reads its leaf offer
12983+ // set from [`crate::speed::ARFMODE`]; every other frame -- the mid
12984+ // and quarter hidden frames, the leaves, the flat path -- keeps the
12985+ // full set.
12986+ arf_leaf_intra: !top_arf || arfmode_v & 1 == 0,
12987+ arf_leaf8: !top_arf || arfmode_v & 2 == 0,
12988+ arf_leaf_compound: !top_arf || arfmode_v & 4 == 0,
12879 };12989 };
12880 let mode_bits_table = inter_mode_bits();12990 let mode_bits_table = inter_mode_bits();
12881 // lane-av1tpl: one lambda factor per 64x64 superblock, from how much of12991 // lane-av1tpl: one lambda factor per 64x64 superblock, from how much of
@@ -13586,7 +13696,17 @@ pub(crate) fn encode_inter_frame(
13586 let eight = (!leaf.skip13696 let eight = (!leaf.skip
13587 && !split_rd_breakout(leaf_cost, SUB, search.lambda)13697 && !split_rd_breakout(leaf_cost, SUB, search.lambda)
13588 && (breakout == 0 || leaf.luma.len() > breakout)13698 && (breakout == 0 || leaf.luma.len() > breakout)
13589- && split_inter_8())13699+ && split_inter_8()
13700+ // lane-arfmode: arm 2 makes 16x16 the top
13701+ // ARF's leaf floor -- the RD-optional 8x8
13702+ // comparison is not offered. Counted only
13703+ // when every other prune let it through,
13704+ // so the counter means "refused", not
13705+ // "never considered". The spec-forced 8x8s
13706+ // at a straddling 16x16 (the
13707+ // `sub_positions` path below) are a
13708+ // different site and stay.
13709+ && (search.arf_leaf8 || arfmode_hit_and_no()))
13590 .then(|| {13710 .then(|| {
13591 restore(13711 restore(
13592 &mut luma, &mut chroma, (lx, ly), SUB, &leaf_base,13712 &mut luma, &mut chroma, (lx, ly), SUB, &leaf_base,
crates/ec-av1/src/encoder.rsmodified+93 -0
@@ -3971,6 +3971,99 @@ mod tests {
3971 crate::speed::set_speed(was);3971 crate::speed::set_speed(was);
3972 }3972 }
3973 3973
3974+ /// lane-arfmode: the top ARF's leaf offer set. Three guards in one
3975+ /// witness, over 17 pictures at gop 32 (three groups, so several top
3976+ /// ARFs) at q=60 -- the lookahead witness's lesson: at a fine q the
3977+ /// anchor carries real coefficients, so a cut that moves only the
3978+ /// hidden frame's internal decisions cannot hide behind "everything
3979+ /// quantized to the same bytes":
3980+ ///
3981+ /// 1. OFF (default and explicit `Some(0)`) is byte-identical -- the
3982+ /// shipped table is 0 and the lever is bit-exact when off;
3983+ /// 2. each armed mode (1 no intra, 2 no 8x8, 4 no compound) really
3984+ /// FIRES -- its own [`crate::encode::take_arfmode_hits`] counter
3985+ /// moves (class `gate-blind-to-feature`) -- and MOVES THE STREAM;
3986+ /// 3. the coding order and levels never change, and every armed stream
3987+ /// decodes sample-exact through `decode_stream` AND ffmpeg.
3988+ #[test]
3989+ fn the_arf_leaf_offer_set_fires_moves_the_stream_and_decodes_sample_exact() {
3990+ let _knobs = crate::speed::knob_write();
3991+ let was = crate::speed::speed();
3992+ crate::speed::set_speed(0);
3993+ crate::encode::force_screen(Some(false));
3994+ let (width, height) = (128usize, 128usize);
3995+ let run = |mode: Option<u8>| -> (Vec<u8>, Vec<Packet>) {
3996+ crate::encode::set_arfmode(mode);
3997+ let _ = crate::encode::take_arfmode_hits();
3998+ let config = EncoderConfig {
3999+ base_q_idx: 60,
4000+ width,
4001+ height,
4002+ gop: 32,
4003+ colour: Colour::Bt709Limited,
4004+ tile_cols_log2: 0,
4005+ tile_rows_log2: 0,
4006+ };
4007+ let mut enc = Av1Encoder::with_pyramid(config, Pyramid::default()).unwrap();
4008+ // Groups at three luma LEVELS (the base ramp 40/110/180): the
4009+ // middle group's top ARF sits halfway between the two dark/light
4010+ // anchors its slots hold, which is exactly where neither
4011+ // single-reference prediction nor intra wins by default -- the
4012+ // AVERAGE of two references (compound) and the DC of the new
4013+ // level (intra) do. Without this the synthetic cards' noise
4014+ // quantizes to skip and no arm can move anything (measured:
4015+ // 516 intra trials skipped, zero won, stream identical).
4016+ let sources: Vec<Picture> = (0..17)
4017+ .map(|t| {
4018+ let mut p = noisy_card(width, height, t);
4019+ let shift = 70i32 * (t / 8) as i32;
4020+ for v in p.y.iter_mut() {
4021+ *v = (i32::from(*v) + shift).clamp(0, 255) as u16;
4022+ }
4023+ p
4024+ })
4025+ .collect();
4026+ let packets = encode_all(&mut enc, &sources);
4027+ (concat(&packets), packets)
4028+ };
4029+ let (off, off_packets) = run(None);
4030+ let (explicit_off, _) = run(Some(0));
4031+ assert_eq!(off, explicit_off, "mode 0 is not bit-exact with the default");
4032+ for (mode, arm) in [(1u8, 0usize), (2, 1), (4, 2)] {
4033+ let (on, packets) = run(Some(mode));
4034+ let hits = crate::encode::take_arfmode_hits();
4035+ assert_eq!(
4036+ packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(),
4037+ off_packets.iter().map(|p| (p.order, p.key, p.level)).collect::<Vec<_>>(),
4038+ "mode {mode}: coding order/levels moved"
4039+ );
4040+ assert!(
4041+ hits[arm] > 0,
4042+ "mode {mode}: its counter never fired ({hits:?}) -- the lever is \
4043+ gate-blind on this fixture",
4044+ );
4045+ assert_ne!(
4046+ off, on,
4047+ "mode {mode} left the stream byte-identical despite {} firing hits",
4048+ hits[arm],
4049+ );
4050+ eprintln!("mode {mode}: {} -> {} B, hits {hits:?}", off.len(), on.len());
4051+ let ours = crate::stream::decode_stream(&on).expect("our decoder");
4052+ assert_eq!(ours.len(), 17, "mode {mode}: our decoder's picture count");
4053+ if !have_ffmpeg() {
4054+ continue;
4055+ }
4056+ let theirs = ffmpeg_decode_luma(&on, width, height);
4057+ assert_eq!(theirs.len(), 17, "mode {mode}: ffmpeg's picture count");
4058+ for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() {
4059+ let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect();
4060+ assert!(got == *b, "mode {mode}, frame {i}: ours differs from ffmpeg");
4061+ }
4062+ }
4063+ crate::encode::set_arfmode(None);
4064+ crate::speed::set_speed(was);
4065+ }
4066+
3974 fn pyramid_round_trip(pyramid: Pyramid, hidden: usize) {4067 fn pyramid_round_trip(pyramid: Pyramid, hidden: usize) {
3975 let (width, height) = (128usize, 128usize);4068 let (width, height) = (128usize, 128usize);
3976 let config = EncoderConfig {4069 let config = EncoderConfig {
crates/ec-av1/src/speed.rsmodified+21 -0
@@ -460,6 +460,27 @@ pub(crate) const ARF_TF_WIN: [usize; 11] = [3; 11];
460 /// so [`ARF_TF`] stays where lane-arftf put it.460 /// so [`ARF_TF`] stays where lane-arftf put it.
461 pub(crate) const ARF_TF_WIN_FUT: [usize; 11] = [3; 11];461 pub(crate) const ARF_TF_WIN_FUT: [usize; 11] = [3; 11];
462 462
463+/// lane-arfmode: the top ARF's offer set, as a bitmask -- `1` the group's
464+/// own anchor ([`crate::encode::DqLevel::TopArf`]) offers no INTRA
465+/// candidate at any block size (the whole-32 search and the 16x16/8x8
466+/// leaves), `2` a 16x16 leaf under it is not offered the 8x8 split, `4` the
467+/// leaves offer no compound candidates; combinations OR, `0` (the default)
468+/// is bit-exact with the pre-lane encoder. `EC_AV1_ARFMODE=<n>` overrides
469+/// it. The spec-forced 8x8s at straddling edges are untouched -- only
470+/// RD-optional offers are cut; the mid and quarter hidden frames and every
471+/// shown leaf keep the full set.
472+///
473+/// The census it answers to (lanes/arfmode.charter.md, at 0d81d6c5): the top
474+/// ARF's syntax gap against rav1e's own ARF at the same position is
475+/// film A +1337 / film B +971 B a frame across mode+mv+partition, and the
476+/// mode family is carried by syntax rav1e does not spend there -- an intra
477+/// fallback whose 4-15% area share de-optimizes the shared `intra_inter`
478+/// CDF (ours 138 B/frame against its 10 on film B), compound at 19-24% of
479+/// the area against its 0%, and an 8x8 split rate 2.4x its own. CAUTION the
480+/// same census records: on the grain film even rav1e keeps 12.3% intra area
481+/// at its ARF, so arm 1's residual risk is concentrated exactly there.
482+pub(crate) const ARFMODE: [u8; 11] = [0; 11];
483+
463 /// lane-lookahead: whether [`crate::encoder::Av1Encoder`] holds one whole484 /// lane-lookahead: whether [`crate::encoder::Av1Encoder`] holds one whole
464 /// mini-GOP of lookahead -- the next group's sources are buffered before the485 /// mini-GOP of lookahead -- the next group's sources are buffered before the
465 /// current group's top ARF is coded, so that ARF has display-FUTURE pictures486 /// current group's top ARF is coded, so that ARF has display-FUTURE pictures
lanes/arfmode.charter.mdadded+154 -0
@@ -0,0 +1,154 @@
1+# lane-arfmode — the top ARF's mode/partition syntax
2+
3+Worktree `edith_codecs-arfmode`, branch `lane-arfmode`, base `0d81d6c5`. The
4+lane the arffilt reconciliation defers: "the top ARF's mode/partition gap
5+(+871 B/frame, 2196 blocks vs rav1e's 1507) — the residual half of the census
6+is done, the syntax half is not". The +871 was written at lane-arfpred's base
7+`35874aef`, before the temporal filter, the tpl future map, `arf_altref` and
8+the 128 roots shipped; this lane re-measures the gap at its own base, forms
9+the lever from what is LEFT of it, and takes it to the deciding gate.
10+
11+## 1. Prior art — reconciled, nothing rebuilt
12+
13+| prior lane | what it established at the top ARF | state at this base |
14+|---|---|---|
15+| lane-arfcen | the per-level stream census; the gap sits in the six pictures coded at distance 8 | instrument shipped (`EC_CENSUS_PERFRAME=1`) |
16+| lane-arfpred | `arf_pred_census` (lag is NOT the cause); the +871 B mode/partition decomposition; `arf_temporal_filter` shipped at strength 3 | residual half attacked; syntax half deferred to THIS lane |
17+| lane-arftf | filter strength 3 -> 2, bracketed; mid-ARF filter refuted | shipped (`EC_AV1_ARF_TF`) |
18+| lane-lookahead | one-group lookahead; symmetric +-3 filter window | shipped (`EC_AV1_LOOKAHEAD`, `ARF_TF_WIN_FUT`) |
19+| lane-tplfut / lane-tplhalf / lane-tplfut-arf | the tpl future map at the ARF — shipped, re-measured ON (film B -1.0/-0.6); the arffilt pointer to it was stale | shipped (`TPL_FUT=2`, `HALF=2`, `WIN=11`) |
20+| lane-arfq / lane-keyq | ARF q offsets and key allocation swept | no mode/partition lever |
21+| lane-arfcen arm 2 (`arf_altref`) | the top ARF's second, distinct past anchor — what its compound candidates read | shipped |
22+| lanes av1comp3/av1comp4 | leaf compound candidates (5 shapes) shipped GLOBALLY — never A/B'd at the ARF alone | open at ARF granularity |
23+| lanes census-filmB / census-longgop | level allocation; leaves already cheap at 48 pictures | context |
24+
25+No knob named `EC_AV1_ARFMODE` or similar exists; nothing here is a second
26+convention beside a shipped one. The census instrument
27+(`examples/syntax_census`, `EC_AV1_BITCENSUS=1 EC_CENSUS_PERFRAME=1`) is the
28+charter's reader — ours and rav1e measured by the same decoder.
29+
30+## 2. The fresh census at `0d81d6c5` — where the gap is NOW
31+
32+Recipe: the long-GOP gate's own window and crops, ours `enc_probe gate 0 48
33+150`, rav1e `speed 6 quantizer 110` from the 8-bit yuv (a 10-bit rav1e stream
34+does not decode in our reader — PSNR reads 2 dB; the 8-bit re-cut reproduces
35+arfpred's table to the digit: rav1e top ARF 3872 B/frame, PSNR-Y 45.97,
36+base_q_idx 104). `EC_CENSUS_TABLES=24`.
37+
38+### 2.1 Family decomposition, B/frame, ours (q118, 6 ARFs) vs rav1e (q104, 11 ARFs)
39+
40+| family | film A ours | film A rav1e | A delta | film B ours | film B rav1e | B delta |
41+|---|---|---|---|---|---|---|
42+| coeff | 6216 | 4568 | +1647 | 2938 | 1996 | +942 |
43+| literal | 1928 | 1459 | +469 | 959 | 730 | +229 |
44+| **mode** | **1845** | **1102** | **+744** | **1137** | **608** | **+530** |
45+| **mv** | **974** | **520** | **+454** | **719** | **410** | **+310** |
46+| **partition** | **330** | **191** | **+139** | **256** | **125** | **+131** |
47+| txsize+txtype | 79 | 4 | +75 | 48 | 2 | +46 |
48+| **total** | **11374** | **7846** | **+3528** | **6060** | **3872** | **+2188** |
49+
50+The total gap is down from +3120 to +2188 on film B (the merged levers took
51+~930 B/frame off the top ARF), and its SHAPE flipped: mode+partition+mv
52+(+971 on film B, +1337 on film A) is now 44%/38% of the gap and the single
53+biggest mode-family carrier is syntax this encoder OFFERS and rav1e does not
54+spend at its ARF.
55+
56+### 2.2 What the mode family buys (per-table, B/frame, from the census's own table shares)
57+
58+| table | A ours | A rav1e | B ours | B rav1e |
59+|---|---|---|---|---|
60+| skip | 228.0 | 226.4 | 184.8 | 132.8 |
61+| intra_inter | 194.5 | 76.3 | 138.3 | 10.2 |
62+| comp_mode | 193.0 | 0 | 119.7 | 0 |
63+| y_mode | 184.9 | 58.4 | 78.2 | 2.5 |
64+| inter_compound_mode | 162.7 | 0 | 66.9 | 0 |
65+| uv_mode_cfl | 205.5 | ~0 | 24.7 | 0 |
66+| new_mv | 157.2 | 201.7 | 145.6 | 143.5 |
67+| motion_mode | 90.4 | 0 | 63.9 | 0 |
68+| drl_mode | — | — | 58.3 | 7.0 |
69+| ref_mv | — | 171.4 | 31.2 | 120.1 |
70+| segment_id | 0 | 118.4 | 0 | 70.7 |
71+
72+Three carriers, all ARF-specific:
73+
74+1. **The intra fallback poisons shared CDFs.** Ours codes 4.0% (film B) /
75+ 15.0% (film A) of the ARF's AREA intra where rav1e codes 0.5% / 12.3%;
76+ the per-block `intra_inter` symbol then costs ours 138 B/frame on film B
77+ where rav1e pays 10 — the CDF is adapted to a 1-in-5 intra rate instead
78+ of 1-in-200. The intra blocks' own mode syntax (y_mode, uv_mode_cfl,
79+ filter_intra) rides on top. CAUTION: on film A even rav1e keeps 12.3%
80+ intra area — there the intra fallback is CONTENT (grain), not waste.
81+2. **Compound at the ARF: ours 18.8%/23.8% of area, rav1e 0.0% on both
82+ films.** The trio (comp_mode + inter_compound_mode + comp_ref_type) costs
83+ ~200 B/frame (film B) to ~360 (film A). Never A/B'd at the ARF alone.
84+3. **The partition mix is 8x8-heavy**: ours 23.3%/31.3% of blocks are 8x8
85+ against rav1e's 13.1%/26.3%, and ours codes 1876/2782 blocks a frame
86+ against 1507/2272 — every extra leaf pays its own skip + intra_inter +
87+ ref + mode + mv symbols. Ours takes the 8x8 split at 2.4x rav1e's rate on
88+ film B.
89+
90+NEWMV share of single-ref modes: ours ~45% both films, rav1e ~25% — the
91++310/+454 mv column is block count plus longer mv residuals.
92+
93+## 3. The lever — `EC_AV1_ARFMODE` (default OFF = bit-exact)
94+
95+A per-frame offer-set change, TOP ARF ONLY (`DqLevel::TopArf` — the group's
96+own anchor, `arf_q_offset`), leaves only; the 32x32 whole keeps its full
97+offer set as the scene-cut hatch, and spec-forced 8x8s at straddling edges
98+are untouched. Bitmask, values OR-able:
99+
100+| value | arm | census target |
101+|---|---|---|
102+| 1 | ARF leaves (16x16/8x8) offer NO intra candidate: the leaf search runs its inter set only | intra_inter + y_mode + uv_mode_cfl + filter_intra, and the CDF de-poisoning across every block |
103+| 2 | 16x16 is the ARF's leaf floor: the RD-optional 8x8 split is not offered | partition + the three extra leaves' mode/mv syntax per split |
104+| 4 | ARF leaves offer NO compound candidates | comp_mode + inter_compound_mode + comp_ref_type (~200-360 B/frame) |
105+| 3 / 5 / 6 / 7 | combinations | — |
106+
107+`speed::ARFMODE: [u8; 11]` ships the gate's disposition per preset;
108+`EC_AV1_ARFMODE=<n>` overrides for A/B on one build. OFF (0, the default)
109+must be byte-exact with the pre-lane encoder — pins `(150, 8291)`,
110+`(60, 33227)` hold at the default and at `EC_AV1_SPEED=6`.
111+
112+## 4. Witnesses BEFORE gates
113+
114+* Pins at the default AND `EC_AV1_SPEED=6` (OFF bit-exactness).
115+* Engagement counters (class `gate-blind-to-feature`): `ARFMODE_HITS` —
116+ [0] ARF leaves coded with the intra trial skipped, [1] ARF 8x8 offers
117+ refused, [2] ARF leaves with compound not offered — asserted > 0 on a real
118+ film encode, and the armed stream must MOVE.
119+* Every witness stream decodes sample-exact through `decode_stream` AND
120+ ffmpeg at the usual picture counts.
121+
122+## 5. Measurement ladder
123+
124+1. Local two-point probe (film A and film B, q150 + q90, bytes at equal PSNR)
125+ prunes dead arms before any server time (arfpred's rule: the probe is a weak
126+ proxy — it PRUNES, it does not PROMOTE; surviving arms go to the gate).
127+2. server-1 (`user@host-e`), managed skill `ec-av1-remote-gate-runners`
128+ (repo-arfmode, target-arfmode, fixtures symlink, `.git` stub, PATH shim
129+ inside the unit, chain as a user unit, linger on): `bd_rate_film_long_gop`
130+ control first — must reproduce the standing table (film A +20.9/-9.0,
131+ film B +70.4/-2.2) +-0.2/cell — then the surviving arms, one gate at a
132+ time, LOADAVG before/after each.
133+3. `bd_rate_screen_native` (five rows) for the disposition arm — at 12 frames
134+ `group_target` forms ONE group of 11 whose ARF IS a `TopArf`, so the
135+ native gate ENGAGES this lever (no blindness claim; the arm runs).
136+
137+## 6. Keep rule and disposition
138+
139+One film row >=0.5 BD down on a column, the other film flat (±0.3), screen
140+not worse 0.3, wall <=+15%. Met -> default ON at the measured presets, pins
141+re-taken at the default and `EC_AV1_SPEED=6`, three-lane lib suite (fixtures
142+symlinked), `cargo check --workspace --all-targets -j4`. Not met -> default
143+OFF / revert, document.
144+
145+## 7. Risks
146+
147+* Arm 1 on film A: 15% intra area would flip to inter where even rav1e keeps
148+ 12% — the residual cost may eat the syntax win on the grain film exactly.
149+* Arm 2: the 8x8 splits it refuses won RD; the syntax win (~280 B/frame
150+ film B by the block arithmetic) has to beat the residual regression.
151+* Arm 4: the two-ref prediction win at the ARF is real (arf_altref exists
152+ for it); only the syntax half is measured.
153+* The probe has mispredicted gate signs before (arfpred); nothing ships off
154+ a probe alone.
lanes/arfmode.report.mdadded+194 -0
@@ -0,0 +1,194 @@
1+# lane-arfmode — the top ARF's mode/partition syntax: re-censused, lever formed, gated
2+
3+Worktree `edith_codecs-arfmode`, branch `lane-arfmode`, base `0d81d6c5`.
4+Charter: `lanes/arfmode.charter.md` (commit `f4da20b5`). The deferred lever
5+from the arffilt reconciliation — "the top ARF's mode/partition gap
6+(+871 B/frame, 2196 blocks vs rav1e's 1507)" — measured at ITS OWN base
7+first, because five merged encoder waves had moved the stream since
8+lane-arfpred wrote the number.
9+
10+## 1. Prior art — reconciled (charter §1)
11+
12+The residual half of the census was attacked by lane-arfpred/arftf/lookahead
13+(the temporal filter, strength 2, ±3 window, one-group lookahead) and
14+lane-tplfut/-tplhalf/-tplfut-arf (the tpl future map at the ARF, re-measured
15+ON at −1.0/−0.6 film B). `arf_altref` (lane-arfcen arm 2) gives the top ARF
16+its two distinct past anchors; leaf compound candidates shipped globally in
17+lanes av1comp3/4 — never A/B'd at the ARF alone. No ARF offer-set knob
18+existed; `EC_AV1_ARFMODE` is not a second convention beside anything.
19+
20+## 2. The fresh census at `0d81d6c5`
21+
22+The gate's own window and crops; ours `enc_probe gate 0 48 150`, rav1e
23+`speed 6 quantizer 110` cut from the 8-BIT yuv (a librav1e encode fed
24+straight from the 10-bit mkv produces a yuv420p10le OBU our reader scores at
25+2 dB against the 8-bit source — the 8-bit path reproduces arfpred's table to
26+the digit: rav1e top ARF 3872 B/frame, q104, PSNR-Y 45.97).
27+
28+### 2.1 Family decomposition, B/frame (ours: 6 ARFs @ q118; rav1e: 11 @ q104)
29+
30+| family | film A ours | film A rav1e | A Δ | film B ours | film B rav1e | B Δ |
31+|---|---|---|---|---|---|---|
32+| coeff | 6216 | 4568 | +1647 | 2938 | 1996 | +942 |
33+| literal | 1928 | 1459 | +469 | 959 | 730 | +229 |
34+| **mode** | **1845** | **1102** | **+744** | **1137** | **608** | **+530** |
35+| **mv** | **974** | **520** | **+454** | **719** | **410** | **+310** |
36+| **partition** | **330** | **191** | **+139** | **256** | **125** | **+131** |
37+| txsize+txtype | 79 | 4 | +75 | 48 | 2 | +46 |
38+| **total** | **11374** | **7846** | **+3528** | **6060** | **3872** | **+2188** |
39+
40+The total gap fell +3120 → +2188 on film B (the merged levers took ~930
41+B/frame off the top ARF), and its SHAPE flipped: mode+partition+mv is now
42+44% (film B) / 38% (film A) of the gap — the syntax half the arffilt
43+reconciliation deferred is the bigger half now.
44+
45+### 2.2 What the mode family buys (per-table B/frame, census table shares)
46+
47+| table | A ours | A rav1e | B ours | B rav1e |
48+|---|---|---|---|---|
49+| skip | 228.0 | 226.4 | 184.8 | 132.8 |
50+| intra_inter | 194.5 | 76.3 | 138.3 | 10.2 |
51+| comp_mode | 193.0 | 0 | 119.7 | 0 |
52+| y_mode | 184.9 | 58.4 | 78.2 | 2.5 |
53+| inter_compound_mode | 162.7 | 0 | 66.9 | 0 |
54+| uv_mode_cfl | 205.5 | ~0 | 24.7 | 0 |
55+| new_mv | 157.2 | 201.7 | 145.6 | 143.5 |
56+| motion_mode | 90.4 | 0 | 63.9 | 0 |
57+| segment_id | 0 | 118.4 | 0 | 70.7 |
58+
59+Three carriers, all ARF-specific: (1) the intra fallback — ours codes
60+15.0%/4.0% of the ARF's AREA intra (A/B) against rav1e's 12.3%/0.5%, and the
61+per-block `intra_inter` symbol costs ours 138 B/frame where rav1e pays 10 on
62+film B: the shared CDF is adapted to a 1-in-5 intra rate instead of 1-in-200;
63+(2) compound at the ARF — ours 23.8%/18.8% of area, rav1e 0.0% on BOTH
64+films; (3) an 8x8-heavy partition mix — ours 31.3%/23.3% of blocks are 8x8
65+against rav1e's 26.3%/13.1%, 1876/2782 blocks a frame against 1507/2272.
66+
67+## 3. The lever — `EC_AV1_ARFMODE` (default OFF = bit-exact)
68+
69+`speed::ARFMODE: [u8; 11]` (all 0), `EC_AV1_ARFMODE=<n>` overrides on one
70+build; bitmask over the TOP ARF's offer set (`DqLevel::TopArf` only — the
71+mid/quarter hidden frames, the shown leaves and the flat path keep
72+everything):
73+
74+| bit | arm |
75+|---|---|
76+| 1 | no INTRA candidate at the top ARF — the whole-32 search's intra loop AND the 16x16/8x8 leaf search's intra trial |
77+| 2 | 16x16 is the leaf floor — the RD-optional 8x8 split is not offered |
78+| 4 | no compound candidates at the leaves |
79+
80+The spec-forced 8x8s at straddling 16x16s are a different site and stay;
81+OFF is bit-exact (pins below).
82+
83+### The probe's first correction, on the record
84+
85+The charter scoped arm 1 to the LEAVES and kept the whole-32's intra as "the
86+scene-cut hatch". The first real-content probe (film A, q150 AND q90) came
87+back byte-identical to the control: the top ARF's intra AREA lives
88+entirely in `search_inter_block`'s whole-32 intra loop, and the hatch was a
89+hatch nothing else was using. Arm 1 was widened to the whole-32 loop
90+(commit `f1bbf3a0`); the charter's deviation is this paragraph.
91+
92+## 4. Witnesses (BEFORE gates)
93+
94+| witness | result |
95+|---|---|
96+| `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins` | PASS at the default AND `EC_AV1_SPEED=6` — pins `(150, 8291, 0x1f00bb0eb099a27f)`, `(60, 33227, 0x57ee6b1f8eacd881)` hold (OFF = bit-exact) |
97+| `encoder::tests::the_arf_leaf_offer_set_fires_moves_the_stream_and_decodes_sample_exact` | PASS — at 17 pictures/gop 32, q60, on a three-level luma-ramp fixture (the middle group's top ARF sits between its two anchors, where neither single-ref nor intra wins by default): explicit `ARFMODE=0` byte-identical to the default; modes 1/2/4 each fire their OWN engagement counter (580/113/568 hits) AND move the stream (5241 → 5194/5230/5238 B); coding order and levels unchanged; every armed stream decodes sample-exact through `decode_stream` AND ffmpeg |
98+| real-content engagement + stream-moves (the two-point probe) | film A arm 1: `arfmode hits: 94088` intra trials skipped at q150 (130584 at q90), stream fnv1a MOVES; arms 2/4 likewise (15407/81432 counts); film B all three arms fire and move — printed per point by `enc_probe`, never assumed |
99+| `encoder::tests::the_lookahead_holds_one_group_and_still_codes_every_picture` + `the_future_tpl_window_still_codes_every_picture_and_moves_the_stream` | PASS (adjacent-lever interference check: 2 passed) |
100+
101+(The fixture lesson, for the next lever of this shape: on `noisy_card` alone
102+NO arm can move anything — 516 intra trials skipped, zero won, stream
103+identical — because the noise quantizes to skip under both candidates. The
104+level ramp is what makes intra/compound competitive on synthetic content.)
105+
106+## 5. Two-point probe (film A/B, q150 + q90, bytes at the control's own PSNR)
107+
108+| arm | film A | film B | hits/point (A q150 / B q150) |
109+|---|---|---|---|
110+| 1 intra-off | −0.28% | **−2.61%** | 94088 / 73248 |
111+| 2 no-8x8 | **−2.05%** | **−2.49%** | 15407 / 11523 |
112+| 4 compound-off | −1.58% | −0.30% | 81432 / 63060 |
113+
114+Nothing dead, nothing promoted on a probe alone (arfpred's rule): the gate
115+arms are 2, 3 = 1|2, and 7 = 1|2|4 against the control.
116+
117+## 6. The deciding gates — server-1, `bd_rate_film_long_gop` (48 pictures)
118+
119+`user@host-e`, managed skill recipe: repo-arfmode, target-arfmode,
120+fixtures symlink, `.git` stub (re-fixed after the re-sync — see §9),
121+warm-compiled, one gate at a time, chain as a user unit, linger on.
122+LOADAVG before → after each gate from the chain log.
123+
124+| gate | film A | film B | wall A (ours) | wall B (ours) |
125+|---|---|---|---|---|
126+| control (`EC_AV1_ARFMODE` unset) | GATE-LGC-A | GATE-LGC-B | WALL-LGC-A | WALL-LGC-B |
127+| arm 2 | GATE-LGA2-A | GATE-LGA2-B | WALL-LGA2-A | WALL-LGA2-B |
128+| arm 3 = 1\|2 | GATE-LGA3-A | GATE-LGA3-B | WALL-LGA3-A | WALL-LGA3-B |
129+| arm 7 = 1\|2\|4 | GATE-LGA7-A | GATE-LGA7-B | WALL-LGA7-A | WALL-LGA7-B |
130+
131+### Control — measured, film A row in hand
132+
133+The chain (below) measured the control's film A row before this report was
134+written (the lane's request budget ran out mid-chain; the chain is a user
135+unit on the server with linger on, so it continues without this session):
136+
137+| gate | film A | wall A (ours) |
138+|---|---|---|
139+| control | **+20.9% / −9.0% — the standing table to the digit** | 1283.6 s |
140+
141+The control reproducing the standing table is the gate's precondition for
142+trusting arm deltas; it holds.
143+
144+### Arm gates — PENDING, chain running on server-1
145+
146+`GATE lgc` started 03:20:46 UTC with `GATE lga2` → `lga3` → `lga7` behind
147+it, one gate at a time (~52 min each ≈ done by ~07:40 UTC). Read, do not
148+re-run:
149+
150+ ssh user@host-e cat /home/user/gates/chain-arfmode.log # per-gate START/EXIT + LOADAVG pairs
151+ ssh user@host-e grep -E '^\| (film|bars|screen)' /home/user/gates/arfmode-{lgc,lga2,lga3,lga7}.log
152+
153+Each log row is `film | ladder points | BD vs libaom | BD vs rav1e | ours:libaom:rav1e walls`.
154+The keep rule reads each arm against the control: one film row ≥0.5 BD
155+down, the other film flat ±0.3; screen rows not worse 0.3; wall ≤ +15%.
156+
157+## 7. Guard gate — `bd_rate_screen_native` (12 pictures, five rows)
158+
159+PENDING — run AFTER the long-GOP verdict picks the disposition arm, same
160+recipe, both arms (this lever ENGAGES at the native gate's shape: 12 frames
161+→ gop 12 → one group of 11 → its ARF is a `DqLevel::TopArf` — the arm is
162+NOT its control):
163+
164+ env for control: (none) env for arm N: EC_AV1_ARFMODE=N
165+ cargo test -p ec-av1 --release --lib -- --ignored --exact --nocapture \
166+ encode::tests::bd_rate_screen_native
167+
168+## 8. Keep rule and disposition
169+
170+**Default OFF — unchanged, byte-exact.** The gate evidence is still
171+accumulating (chain above), and the ON disposition requires it; until a
172+reader applies §6's rule to the finished logs and re-runs the native pair,
173+`speed::ARFMODE` ships `[0; 11]`, the pins hold at `(150, 8291)` /
174+`(60, 33227)`, and `EC_AV1_ARFMODE=<n>` arms the lever for A/B on one
175+build. fix-now | deferred(<the §6 log read + the native pair, unblocked the
176+moment the chain lands>) — every other acceptance item (prior-art
177+reconciliation, gap decomposition, lever, witnesses with printed non-zero
178+counts, probe, control reproduction) is done and committed.
179+
180+## 9. What this lane did NOT do
181+
182+* `deferred: the compound trio at the ARF alone (arm 4): the probe reads
183+ film A −1.58% / film B −0.30% — worth a gate if a later lane can afford
184+ one; the gate's arm 7 carries it only in combination.`
185+* `deferred: motion_mode/warp syntax at the ARF (64-90 B/frame, rav1e 0) —
186+ untouched; warp is a shipped default and an ARF-only cut is a fresh
187+ measurement.`
188+* `deferred: segmentation (rav1e pays 70-118 B/frame of segment_id at its
189+ ARF to buy cheap skip) — ours codes no segments at all; a whole lane.`
190+* `deferred: NEW-mv share at the ARF (ours ~45% vs rav1e ~26%) — driven by
191+ the lag-8 anchor pair; the mv column (+310/+454) is block count plus
192+ longer residuals, not a syntax lever.`
193+
194+No merge, no push.