# lane-i64 — the KEY frame's 64x64 intra root Branch `lane-i64`, base `7b0e08b9`. Scope: `crates/ec-av1/src/encode.rs`'s key-frame partition search, the pieces of `code_square`/`search_chroma` a 64-sided block needs, `speed.rs`, tests. ## What landed The key search offers the whole superblock as ONE intra block before it searches the four 32x32 quadrants, and takes whichever costs less at one lambda — the shape the inter frame's 64 root (`search_skip_64`) already had. * `code_square` reaches `side == SUPERBLOCK`: `TxbSet::Luma64` (the coded 32x32 corner `code_from_prediction` already hands back for a 64-point transform) plus one `TxbSet::Chroma32` per chroma plane — exactly the three sets the writer's `Superblock::Whole` arm codes. * Every mode the 32 search offers, angle-delta refinement included (the machinery is side-generic). No CfL (`search_chroma` gates at `side <= 32`, spec `is_cfl_allowed`), no filter intra (`filter_intra_size_class` has no 64 row), no transform-depth split (the writer's arm takes a 32-sided level grid, so only depth 0 is representable) — the block still PAYS its `TX_SIZE_CAT3` zero so the 64-vs-four-32 comparison is fair. * Three defects the 64 side exposed, each a real bound and not a new feature: the intra edge buffers were sized `2 * BLOCK` (a 64-wide block reads up to 128 samples above), `intra_predict_u8`'s scratch topped out at `BLOCK * BLOCK`, and `search_chroma` handed a 32x32 chroma transform an ADST type — `av1_get_ext_tx_set_type` resolves chroma at `tx_size_sqr >= TX_32X32` to `EXT_TX_SET_DCTONLY`, which the DECODER already did (`decode.rs`'s `side >= 32` arm) and the transform asserts. * Early-out: `split_rd_breakout_at(b64_breakout_threshold(), ...)`, the same preset-CLAMPED 0.125 the inter root uses, so a looser `SPLIT_RD` at a high preset never withholds four quadrant searches here either. * Refused on an `allow_intrabc` frame: the quadrant searches carry DV state (`Ibc::last_dv`) that a discarded trial would desync. * `EC_AV1_I64=0` in any build; `speed::I64_ROOT` on at every preset. ## Exactness witness `encode::tests::a_smooth_gradient_key_frame_codes_whole_superblocks_and_decodes_exactly` — a 256x192 smooth gradient at q120: **12 of 12** superblocks coded as one 64x64 intra root, and both our decoder and ffmpeg produce the encoder's own reconstruction sample-exact on all three planes. ## Pricer `crate::tile::predicted_coeff_bits_sb` already carried the `Superblock::Whole` arm (Luma64 + two Chroma32, lane-tx64 wrote it for exactly this shape), so the variant needed no new price; `predicted_coeff_bits_track_the_tile_the_writer_wrote` is green. ## Gates Two arms of ONE build in parallel, `EC_AV1_I64=0` vs default. The OFF arm reproduces the base's screen and bars rows to the digit, so the baseline is this build's own (the charter's film numbers predate the lane-sse merge in the base commit; screen +33.4/-23.8 and the bars rows land exactly). ### 12-frame `bd_rate_screen_native` (native crop, gop 12) — `lanes/i64/r1-{off,on}.log` | row | OFF (control) | ON (shipped) | key 64 intra roots | wall ours OFF -> ON | |---|---|---|---|---| | bars 1080p | +1.8% / -14.4% | +1.9% / -14.3% | 1532 of 1920 (79.8%) | 39.3s -> 38.8s | | bars 2160p | +12.6% / -9.9% | +12.7% / -9.8% | 1703 of 1920 (88.7%) | 41.1s -> 39.9s | | film A 1920x768 | +34.8% / +5.0% | **+33.2% / +3.7%** | 452 of 1440 (31.4%) | 78.2s -> 80.3s | | film B 1920x1024 | +47.0% / +16.5% | **+42.4% / +12.2%** | 862 of 1920 (44.9%) | 77.8s -> 79.7s | | screen capture | +33.4% / -23.8% | **+32.8% / -24.2%** | 877 of 1920 (45.7%) | 42.7s -> 42.3s | Keep rule: both film rows improve on BOTH columns (film A -1.6/-1.3, film B -4.6/-4.3) and screen is 0.6/0.4 BETTER, not worse — so the root ships on screen frames too (its palette and 32x32-chroma paths are exercised there: 45.7% of the capture's superblocks are coded whole). The two bars rows move +0.1 the wrong way, which the keep rule does not cover and which is inside what one partition decision costs on a synthetic pattern. Film wall +2.6%: one 64x64 trial per superblock on 1 frame in 12. ### Long-GOP `bd_rate_film_long_gop` (48 frames, gop 48) — `lanes/i64/lg-{off,on}.log` | row | OFF | ON (shipped) | wall ours OFF -> ON | |---|---|---|---| | film A 1920x768 | +36.7% / -0.4% | **+36.5% / -0.6%** | 339.5s -> 338.3s | | film B 1920x1024 | +115.5% / +23.2% | **+113.1% / +21.6%** | 292.7s -> 299.6s | Both rows better on both columns, at 1 key frame in 48 — a fifth of the 12-frame gain, which is what one frame in 48 instead of one in 12 predicts. ### Speed 6 — `lanes/i64/s6-{off,on}.log` | row | OFF | ON | roots | |---|---|---|---| | bars 1080p | +72.1% / +44.9% | +72.1% / +44.9% | 79.9% | | bars 2160p | +68.3% / +33.7% | +68.1% / +33.6% | 88.7% | | film A | +42.9% / +11.4% | **+41.3% / +10.1%** | 35.9% | | film B | +60.9% / +28.0% | **+56.1% / +23.6%** | 49.8% | | screen | +40.3% / -20.0% | **+39.7% / -20.4%** | 45.8% | Every row is equal or better, wall within noise (film A 33.8s -> 34.3s, film B 32.4s -> 33.4s), so `speed::I64_ROOT` is on at every preset. The early-out reads `b64_breakout_threshold`, i.e. the preset's looser `SPLIT_RD` never withholds the four quadrant searches here (lane-b64's own defect, fixed in lane-tx64 and inherited here rather than repeated). DECISION: **KEEP, default on at every preset.** `EC_AV1_I64=0` restores the split-only key search byte for byte (proven by the OFF arm holding the old pins). ## Invariants - Byte pins re-taken (the keep rule passed): 9808 -> **9843** (q=150) and 35791 -> **35834** (q=60); `EC_AV1_I64=0` holds the OLD pair on this build, checked before the re-take. - At presets 0 AND 6, `EC_COMP_MISMATCH=1` silent throughout: `tile_bytes_do_not_depend_on_the_thread_count --include-ignored`, `the_facade_codes_the_same_bytes_as_encode_sequence`, `predicted_coeff_bits_track_the_tile_the_writer_wrote` — all green. - `every_speed_preset_decodes_sample_exact_through_both_decoders --ignored`: green (speeds 0, 3, 6, 10). - `timeout 900 cargo check --workspace --all-targets -j4`: 0 errors, 0 ec-av1 warnings (21 pre-existing ec-opus, 1 ec-vorbis). - Full lib suite (release binary, `--test-threads=4`): **565 passed / 0 failed / 44 ignored**, 770.8 s (`lanes/i64/suite2.log`) — 564 expected plus this lane's witness. ## The defect the first suite run found (fixed by a named corner-cut) The first full-suite run was RED on three tests, all caused by the root: * `stream::tests::a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg` — at **248x152**, whose bottom-right superblock is cut on BOTH axes, that corner's CHROMA came out three ways different (our writer's own reconstruction, our decoder and ffmpeg all disagree; LUMA stays exact, and the 15 other sizes in the sweep pass). Class `last-block-desync-reads-as-reconstruction`: the whole-64 write publishes a chroma neighbour state the doubly-cut tail block reads differently. FIXED conservatively: the root is offered only on a frame whose true size is a whole number of superblocks (`mi_cols % SB_MI == 0 && mi_rows % SB_MI == 0`), a corner-cut whose ceiling is written at the guard. Every BD-gate clip and both real films are superblock aligned, so no measured number moves. * `decode::tests::a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg` — its 128x128 smooth field is now coded as four whole 64x64 roots, and filter intra stops at 32x32, so the fixture's own fire assert (`no block took filter intra`) fired. The fixture carries a step edge through every superblock now: 5 filter-intra blocks, pixel-exact through ffmpeg again. * The lane's own witness asserted a PROCESS-GLOBAL counter (`offered == 12`) and read 13 under `--test-threads=4`. It asserts the per-FRAME mode count (`encoded.modes.len() == 12`) instead. ## Deferred - `deferred: a depth-1 (four TX_32X32) luma split under the key 64x64 root — the writer's `Superblock::Whole` arm takes a 32-sided level grid, so only TX_64X64 is representable there — unblocked by widening that arm's grid to 64 and teaching `predicted_coeff_bits_sb` the same four-unit slice `predicted_coeff_bits`'s `Whole64` arm already has.` - `deferred: the 64x64 root on an `allow_intrabc` frame — the quadrant searches mutate `Ibc::last_dv`, which a discarded trial would desync — unblocked by snapshotting the `Ibc` state around the trial.` - `deferred: a 64x64 root the true frame edge CUTS THROUGH (the inter side's `EC_AV1_B64EDGE`) — the key writer refuses a superblock that is half outside — unblocked by the `has_half` arm the inter writer already has.`