diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index b2bd29f9..bc745700 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -5860,11 +5860,27 @@ fn cfl_on() -> bool { /// (`EC_AV1_FILTER_INTRA=0` switches both off, which is how the lane measured /// its own on/off pair -- and how every byte pin written before it still /// reproduces). It is also a speed lever: on at preset 0, off above it. -// lane-sb128: `use_128x128_superblock` (spec 5.5.1). Off by default until -// the BD gate says otherwise; `EC_AV1_SB128=1` turns it on for the whole -// process (a sequence-header field, so it cannot change mid-stream anyway), -// the same env-flag shape `EC_AV1_FILTER_INTRA` uses. NOT an `EncoderConfig` -// field: that struct is built by 90 literal sites in this workspace. +// lane-sb128: `use_128x128_superblock` (spec 5.5.1). `EC_AV1_SB128=0` turns +// it off for the whole process (a sequence-header field, so it cannot change +// mid-stream anyway), the same env-flag shape `EC_AV1_FILTER_INTRA` uses. +// NOT an `EncoderConfig` field: that struct is built by 90 literal sites in +// this workspace. + +/// Whether a sequence codes 128x128 superblocks when the environment says +/// nothing. ON since lane-b128 gave the 128 root a real `PARTITION_NONE` +/// candidate ([`search_root_128`]): with SPLIT-only roots the size was pure +/// cost (lane-sb128b measured film B +24.9 -> +37.5 vs libaom), and with the +/// 128x128 block in it every row of the native BD gate is down or flat on +/// both columns (BD-rate vs libaom cpu-6 / rav1e s6, 12 frames): +/// +/// | row | 64 superblocks | 128 + the 128 root | +/// |---|---|---| +/// | bars 1080p | -2.6 / -18.3 | **-3.3 / -18.9** | +/// | bars 2160p | +8.8 / -13.2 | **+7.9 / -14.0** | +/// | film A | +20.6 / -5.1 | **+20.4 / -5.2** | +/// | film B | +24.8 / -2.1 | **+24.2 / -2.5** | +/// | screen capture | +14.6 / -33.2 | **+14.4 / -33.2** | +pub(crate) const SB128_DEFAULT: bool = true; /// Whether this process's sequences code 128x128 superblocks. An ENCODER /// knob (like `speed::SPEED`), never read by a decode: read through a @@ -5877,7 +5893,9 @@ pub(crate) fn sb128_on() -> bool { use std::sync::atomic::Ordering::Relaxed; match ENC_SB128.load(Relaxed) { 2 => { - let on = crate::envflags::var("EC_AV1_SB128").ok().is_some_and(|v| v != "0"); + let on = crate::envflags::var("EC_AV1_SB128") + .ok() + .map_or(SB128_DEFAULT, |v| v != "0"); ENC_SB128.store(u8::from(on), Relaxed); on } @@ -16914,8 +16932,12 @@ mod tests { // ([`crate::motion::MV_SUBPEL_ITERS`]), so every inter block's vector // -- and with it its residual -- moved: 8325 -> 8288 bytes at q=150 // and 33014 -> 33090 at q=60. + // Re-taken on lane-b128: sequences code 128x128 superblocks by + // default now ([`SB128_DEFAULT`]), and their roots can leave a whole + // 128x128 block whole -- 8288 -> 8303 bytes at q=150 and 33090 -> + // 33132 at q=60. `EC_AV1_SB128=0` restores the 64-superblock stream. let pins: [(u8, usize, u64); 2] = - [(150, 8288, 0x241d_8115_0a6d_0f34), (60, 33090, 0x7e02_777c_01b4_f035)]; + [(150, 8303, 0x0368_e400_f09d_02ba), (60, 33132, 0x884b_c219_5ea9_6416)]; let coded: Vec<(u8, usize, u64)> = pins .iter() .map(|&(q, _, _)| { diff --git a/lanes/b128.report.md b/lanes/b128.report.md new file mode 100644 index 00000000..88a3a9b6 --- /dev/null +++ b/lanes/b128.report.md @@ -0,0 +1,79 @@ +# lane-b128 — a real 128x128 root under `EC_AV1_SB128` + +Three results: + +1. **Task 0 (the drl pricer) is a STALE premise, and now has its enumeration + test.** The charter's `encode.rs:8722` mis-pricing was already closed by + the lane-sb128b merge on the WRITER side; the pricer's own offer set is + provably clamp-free against its own stack. +2. **The 128x128 `PARTITION_NONE` root is implemented, witnessed and + MEASURED** — and it turns lane-sb128b's refutation around: film B + +24.2%/−2.5% vs libaom cpu-6 / rav1e s6 with 128 superblocks ON, against + the SPLIT-only arm's +37.5%/+7.3%. +3. **HORZ/VERT (128x64, 64x128) are deferred** — see the disposition below. + +## 1. Task 0 — the drl offer set, enumerated + +`crate::tile::signalled_drl_idx(entries, start, target)` is the writer's +clamp rule as one pure function (`write_drl_idx`'s own walk now carries a +`debug_assert_eq!` against it, so the two cannot drift). The pricer's offer +set is enumerated against it over every stack size 0..=4, for both the +`NEWMV` (`best_new_mv_syntax`) and the `NEARMV` (`entries.get(idx)`) arms: + + cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer + test encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal ... ok + +GREEN as written: `best_new_mv_syntax` breaks at `entries.len() <= idx`, +which is exactly `write_drl_idx`'s `entries.len() > idx + 1` condition, so +no offered index is ever clamped **against the same stack**. Byte effect: +none — the pins are byte-identical (below). The residual error the report +open item names is entirely the SEARCH-time vs WRITE-time stack divergence +(lane-sb128b's second open item), which no change on this line can reach. + +## 2. The 128 root + +### What moved + +- `tile.rs` — `Quadrant::Whole128(BlockCoeffs)`; `write_sb128_root` takes the + partition value; `write_inter_block_128` writes the block (`skip`, + `is_inter`, the reference/mode chain at a 32x32-mi window, motion mode, tx + syntax, mi grid + neighbour bands over all 32 mi cells); the inter tile + loop skips the root's remaining three 64x64 cells, mirroring the decoder's + own `sb128_none`; `partition_bits` gained the 128 row; + `signalled_drl_idx`; `take_sb128_none_hits`. +- `encode.rs` — `search_root_128` (the candidate, its legality and its + lambda), `search_skip_64` parameterised by `side`, the tile search loop + restructured into ROOTS x cells, the 128-vs-four decision, + `take_b128_none_hits`, the `EC_AV1_B128_CENSUS=1` per-frame line. + +### Deliberate limits (deviations from the charter, each with its reason) + +- **SKIP only.** A 128x128 block's residual is four TX_64X64 luma units + interleaved with a TX_32X32 chroma pair per 64x64 mu chunk (the chroma + units on the offset-10 `txb_skip` rows), plus one `txfm_partition` symbol + per chunk. Neither the writer nor `Plane::code_from_prediction` has that + path; `write_inter_block_128` REFUSES a non-skip block rather than coding + one wrong. `search_root_128` therefore offers `residual: false`. +- **Single reference only.** The compound arm at 128 would go through + `write_compound_block` at a window size it has never been exercised at. +- **Inter frames only.** A key frame's 128 root still writes SPLIT. +- **HORZ / VERT deferred.** Two 128x64 / 64x128 blocks need rect neighbour + recording and rect prediction/SSE on the WRITER and SEARCH sides (the + decoder already reads both, lane-sb128c r7); the square NONE arm reuses + every existing square helper unchanged. + +### Witness (red before / green after) + +`encode::tests::a_128_superblock_clip_whose_root_search_codes_128x128_blocks_decodes_exact` +(`--ignored`, it moves the process-global superblock size): + + cargo test -p ec-av1 --release --lib -- --ignored \ + a_128_superblock_clip_whose_root_search --nocapture + 128x128 PARTITION_NONE blocks: search won 406, writer coded 406 + test ... ok + +8 frames, 1280x768, a slow pan over `smptebars` at `force_sb128(true)`: +**406** 128x128 blocks coded, every frame sample-exact against the encoder's +own reconstruction through `decode_stream` AND through ffmpeg. RED before +this lane by construction: `write_sb128_root` wrote `PARTITION_SPLIT` at +every root, so the count was 0 and no such block existed to decode.