Fire-share census + the smooth-gradient witness for the key 64x64 intra root
Browse files at this commitbbc059f1a0e80776a700f914560b7a701831ccf5Parent: f5d8b45- test
- fire-share census + the smooth-gradient witness for the key 64x64 intra root
5 changed files +84 -6
- crates/ec-av1/src/encode.rs +19 -6
- lanes/i64.report.md +53 -0
- lanes/i64/bin-r1 +0 -0
- lanes/i64/r1-off.log +6 -0
- lanes/i64/r1-on.log +6 -0
crates/ec-av1/src/encode.rsmodified+19 -6
| @@ -460,11 +460,15 @@ pub(crate) const I64_ROOT: bool = true; | ||
| 460 | 460 | /// How many key-frame superblocks were coded as one 64x64 intra block since |
| 461 | 461 | /// the last [`take_i64_root_hits`], so a gate reports the fire rate rather |
| 462 | 462 | /// 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]; | |
| 464 | 467 | |
| 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)) | |
| 468 | 472 | } |
| 469 | 473 | |
| 470 | 474 | /// [`I64_ROOT`], or what `EC_AV1_I64` names. |
| @@ -6624,6 +6628,7 @@ pub(crate) fn encode_key_frame_inner( | ||
| 6624 | 6628 | && y64 + SUPERBLOCK <= luma.true_height; |
| 6625 | 6629 | let mut sb64: Option<(f64, BlockCoeffs, [(Vec<u8>, Vec<CoefCtx>); 3])> = None; |
| 6626 | 6630 | if sb64_legal { |
| 6631 | + I64_HITS[1].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6627 | 6632 | let base = snapshot(&luma, &chroma, (x64, y64), SUPERBLOCK); |
| 6628 | 6633 | let (c64, r64) = (sb_col * 4, sb_row * 4); |
| 6629 | 6634 | let (block, cost) = code_square( |
| @@ -6830,7 +6835,7 @@ pub(crate) fn encode_key_frame_inner( | ||
| 6830 | 6835 | above_mode[sb_col * 4 + cell] = block.mode; |
| 6831 | 6836 | left_mode[sb_row * 4 + cell] = block.mode; |
| 6832 | 6837 | } |
| 6833 | - I64_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6838 | + I64_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6834 | 6839 | let mode = block.mode; |
| 6835 | 6840 | coded.push((index, Superblock::Whole(block), vec![mode])); |
| 6836 | 6841 | } |
| @@ -11086,7 +11091,8 @@ mod tests { | ||
| 11086 | 11091 | } |
| 11087 | 11092 | let _ = take_i64_root_hits(); |
| 11088 | 11093 | 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"); | |
| 11090 | 11096 | assert!( |
| 11091 | 11097 | roots >= 8, |
| 11092 | 11098 | "a smooth-gradient key frame coded only {roots} whole 64x64 intra roots of 12" |
| @@ -15538,6 +15544,13 @@ mod tests { | ||
| 15538 | 15544 | // superblocks stayed whole, and how many of those coded a |
| 15539 | 15545 | // residual, split that residual's luma, or took a compound |
| 15540 | 15546 | // 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 | + ); | |
| 15541 | 15554 | eprintln!( |
| 15542 | 15555 | "{name}: 64x64 roots {} (with a residual {}, split luma {}, compound {})", |
| 15543 | 15556 | 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 | +|---|---|---|---|---| |