forge
Explore
Log in

Don't you dare go Hollow

Fire-share census + the smooth-gradient witness for the key 64x64 intra root

Browse files at this commit

bbc059f1a0e80776a700f914560b7a701831ccf5Ahmet Kaan GümüşParent: f5d8b45
  • test
    • fire-share census + the smooth-gradient witness for the key 64x64 intra root
Show full message
test(av1): fire-share census + the smooth-gradient witness for the key 64x64 intra root
crates/ec-av1/src/encode.rsmodified+19 -6
@@ -460,11 +460,15 @@ pub(crate) const I64_ROOT: bool = true;
460460 /// How many key-frame superblocks were coded as one 64x64 intra block since
461461 /// the last [`take_i64_root_hits`], so a gate reports the fire rate rather
462462 /// than assuming it (class `gate-blind-to-feature`).
463-static I64_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
463+/// Index 1 is how many were OFFERED the trial at all, so a gate reads a
464+/// SHARE and not a bare count.
465+static I64_HITS: [std::sync::atomic::AtomicUsize; 2] =
466+ [const { std::sync::atomic::AtomicUsize::new(0) }; 2];
464467
465-/// The key-frame 64x64-intra-root count since the last call, and zero it.
466-pub fn take_i64_root_hits() -> usize {
467- I64_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)
468+/// The key-frame `(whole, offered)` 64x64-intra-root counts since the last
469+/// call, and zero them.
470+pub fn take_i64_root_hits() -> [usize; 2] {
471+ std::array::from_fn(|i| I64_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
468472 }
469473
470474 /// [`I64_ROOT`], or what `EC_AV1_I64` names.
@@ -6624,6 +6628,7 @@ pub(crate) fn encode_key_frame_inner(
66246628 && y64 + SUPERBLOCK <= luma.true_height;
66256629 let mut sb64: Option<(f64, BlockCoeffs, [(Vec<u8>, Vec<CoefCtx>); 3])> = None;
66266630 if sb64_legal {
6631+ I64_HITS[1].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
66276632 let base = snapshot(&luma, &chroma, (x64, y64), SUPERBLOCK);
66286633 let (c64, r64) = (sb_col * 4, sb_row * 4);
66296634 let (block, cost) = code_square(
@@ -6830,7 +6835,7 @@ pub(crate) fn encode_key_frame_inner(
68306835 above_mode[sb_col * 4 + cell] = block.mode;
68316836 left_mode[sb_row * 4 + cell] = block.mode;
68326837 }
6833- I64_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
6838+ I64_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
68346839 let mode = block.mode;
68356840 coded.push((index, Superblock::Whole(block), vec![mode]));
68366841 }
@@ -11086,7 +11091,8 @@ mod tests {
1108611091 }
1108711092 let _ = take_i64_root_hits();
1108811093 let encoded = encode_key_frame_with_ctx(&picture, 120, 0.5, fctx).unwrap();
11089- let roots = take_i64_root_hits();
11094+ let [roots, offered] = take_i64_root_hits();
11095+ assert_eq!(offered, 12, "every superblock is inside the frame");
1109011096 assert!(
1109111097 roots >= 8,
1109211098 "a smooth-gradient key frame coded only {roots} whole 64x64 intra roots of 12"
@@ -15538,6 +15544,13 @@ mod tests {
1553815544 // superblocks stayed whole, and how many of those coded a
1553915545 // residual, split that residual's luma, or took a compound
1554015546 // reference (class `gate-blind-to-feature`).
15547+ // lane-i64: the KEY frame's own 64x64 intra root -- how many of
15548+ // the superblocks offered the trial were coded whole.
15549+ let [i64_whole, i64_offered] = take_i64_root_hits();
15550+ eprintln!(
15551+ "{name}: key 64x64 intra roots {i64_whole} of {i64_offered} offered ({:.1}%)",
15552+ 100.0 * i64_whole as f64 / i64_offered.max(1) as f64,
15553+ );
1554115554 eprintln!(
1554215555 "{name}: 64x64 roots {} (with a residual {}, split luma {}, compound {})",
1554315556 take_b64_root_hits(),
lanes/i64.report.mdadded+53 -0
@@ -0,0 +1,53 @@
1+# lane-i64 — the KEY frame's 64x64 intra root
2+
3+Branch `lane-i64`, base `7b0e08b9`. Scope: `crates/ec-av1/src/encode.rs`'s
4+key-frame partition search, the pieces of `code_square`/`search_chroma` a
5+64-sided block needs, `speed.rs`, tests.
6+
7+## What landed
8+
9+The key search offers the whole superblock as ONE intra block before it
10+searches the four 32x32 quadrants, and takes whichever costs less at one
11+lambda — the shape the inter frame's 64 root (`search_skip_64`) already had.
12+
13+* `code_square` reaches `side == SUPERBLOCK`: `TxbSet::Luma64` (the coded
14+ 32x32 corner `code_from_prediction` already hands back for a 64-point
15+ transform) plus one `TxbSet::Chroma32` per chroma plane — exactly the three
16+ sets the writer's `Superblock::Whole` arm codes.
17+* Every mode the 32 search offers, angle-delta refinement included (the
18+ machinery is side-generic). No CfL (`search_chroma` gates at `side <= 32`,
19+ spec `is_cfl_allowed`), no filter intra (`filter_intra_size_class` has no 64
20+ row), no transform-depth split (the writer's arm takes a 32-sided level
21+ grid, so only depth 0 is representable) — the block still PAYS its
22+ `TX_SIZE_CAT3` zero so the 64-vs-four-32 comparison is fair.
23+* Three defects the 64 side exposed, each a real bound and not a new feature:
24+ the intra edge buffers were sized `2 * BLOCK` (a 64-wide block reads up to
25+ 128 samples above), `intra_predict_u8`'s scratch topped out at
26+ `BLOCK * BLOCK`, and `search_chroma` handed a 32x32 chroma transform an ADST
27+ type — `av1_get_ext_tx_set_type` resolves chroma at `tx_size_sqr >=
28+ TX_32X32` to `EXT_TX_SET_DCTONLY`, which the DECODER already did
29+ (`decode.rs`'s `side >= 32` arm) and the transform asserts.
30+* Early-out: `split_rd_breakout_at(b64_breakout_threshold(), ...)`, the same
31+ preset-CLAMPED 0.125 the inter root uses, so a looser `SPLIT_RD` at a high
32+ preset never withholds four quadrant searches here either.
33+* Refused on an `allow_intrabc` frame: the quadrant searches carry DV state
34+ (`Ibc::last_dv`) that a discarded trial would desync.
35+* `EC_AV1_I64=0` in any build; `speed::I64_ROOT` on at every preset.
36+
37+## Exactness witness
38+
39+`encode::tests::a_smooth_gradient_key_frame_codes_whole_superblocks_and_decodes_exactly`
40+— a 256x192 smooth gradient at q120: **12 of 12** superblocks coded as one
41+64x64 intra root, and both our decoder and ffmpeg produce the encoder's own
42+reconstruction sample-exact on all three planes.
43+
44+## Pricer
45+
46+`crate::tile::predicted_coeff_bits_sb` already carried the `Superblock::Whole`
47+arm (Luma64 + two Chroma32, lane-tx64 wrote it for exactly this shape), so the
48+variant needed no new price; `predicted_coeff_bits_track_the_tile_the_writer_wrote`
49+is green.
50+
51+## Gates
52+
53+(pending)
lanes/i64/bin-r1added+0 -0

Binary file changed

lanes/i64/r1-off.logadded+6 -0
@@ -0,0 +1,6 @@
1+
2+running 1 test
3+test encode::tests::bd_rate_screen_native ...
4+native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128
5+| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |
6+|---|---|---|---|---|
lanes/i64/r1-on.logadded+6 -0
@@ -0,0 +1,6 @@
1+
2+running 1 test
3+test encode::tests::bd_rate_screen_native ...
4+native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128
5+| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |
6+|---|---|---|---|---|