128x128 superblocks by default, and the lane report
Browse files at this commitcfb8167e25ae7f749b0be56eec332eea1ea2b076Parent: 1e4efce- feat
- 128x128 superblocks by default, and the lane report
2 changed files +108 -7
- crates/ec-av1/src/encode.rs +29 -7
- lanes/b128.report.md +79 -0
crates/ec-av1/src/encode.rsmodified+29 -7
| @@ -5860,11 +5860,27 @@ fn cfl_on() -> bool { | ||
| 5860 | 5860 | /// (`EC_AV1_FILTER_INTRA=0` switches both off, which is how the lane measured |
| 5861 | 5861 | /// its own on/off pair -- and how every byte pin written before it still |
| 5862 | 5862 | /// reproduces). It is also a speed lever: on at preset 0, off above it. |
| 5863 | -// lane-sb128: `use_128x128_superblock` (spec 5.5.1). Off by default until | |
| 5864 | -// the BD gate says otherwise; `EC_AV1_SB128=1` turns it on for the whole | |
| 5865 | -// process (a sequence-header field, so it cannot change mid-stream anyway), | |
| 5866 | -// the same env-flag shape `EC_AV1_FILTER_INTRA` uses. NOT an `EncoderConfig` | |
| 5867 | -// field: that struct is built by 90 literal sites in this workspace. | |
| 5863 | +// lane-sb128: `use_128x128_superblock` (spec 5.5.1). `EC_AV1_SB128=0` turns | |
| 5864 | +// it off for the whole process (a sequence-header field, so it cannot change | |
| 5865 | +// mid-stream anyway), the same env-flag shape `EC_AV1_FILTER_INTRA` uses. | |
| 5866 | +// NOT an `EncoderConfig` field: that struct is built by 90 literal sites in | |
| 5867 | +// this workspace. | |
| 5868 | + | |
| 5869 | +/// Whether a sequence codes 128x128 superblocks when the environment says | |
| 5870 | +/// nothing. ON since lane-b128 gave the 128 root a real `PARTITION_NONE` | |
| 5871 | +/// candidate ([`search_root_128`]): with SPLIT-only roots the size was pure | |
| 5872 | +/// cost (lane-sb128b measured film B +24.9 -> +37.5 vs libaom), and with the | |
| 5873 | +/// 128x128 block in it every row of the native BD gate is down or flat on | |
| 5874 | +/// both columns (BD-rate vs libaom cpu-6 / rav1e s6, 12 frames): | |
| 5875 | +/// | |
| 5876 | +/// | row | 64 superblocks | 128 + the 128 root | | |
| 5877 | +/// |---|---|---| | |
| 5878 | +/// | bars 1080p | -2.6 / -18.3 | **-3.3 / -18.9** | | |
| 5879 | +/// | bars 2160p | +8.8 / -13.2 | **+7.9 / -14.0** | | |
| 5880 | +/// | film A | +20.6 / -5.1 | **+20.4 / -5.2** | | |
| 5881 | +/// | film B | +24.8 / -2.1 | **+24.2 / -2.5** | | |
| 5882 | +/// | screen capture | +14.6 / -33.2 | **+14.4 / -33.2** | | |
| 5883 | +pub(crate) const SB128_DEFAULT: bool = true; | |
| 5868 | 5884 | |
| 5869 | 5885 | /// Whether this process's sequences code 128x128 superblocks. An ENCODER |
| 5870 | 5886 | /// knob (like `speed::SPEED`), never read by a decode: read through a |
| @@ -5877,7 +5893,9 @@ pub(crate) fn sb128_on() -> bool { | ||
| 5877 | 5893 | use std::sync::atomic::Ordering::Relaxed; |
| 5878 | 5894 | match ENC_SB128.load(Relaxed) { |
| 5879 | 5895 | 2 => { |
| 5880 | - let on = crate::envflags::var("EC_AV1_SB128").ok().is_some_and(|v| v != "0"); | |
| 5896 | + let on = crate::envflags::var("EC_AV1_SB128") | |
| 5897 | + .ok() | |
| 5898 | + .map_or(SB128_DEFAULT, |v| v != "0"); | |
| 5881 | 5899 | ENC_SB128.store(u8::from(on), Relaxed); |
| 5882 | 5900 | on |
| 5883 | 5901 | } |
| @@ -16914,8 +16932,12 @@ mod tests { | ||
| 16914 | 16932 | // ([`crate::motion::MV_SUBPEL_ITERS`]), so every inter block's vector |
| 16915 | 16933 | // -- and with it its residual -- moved: 8325 -> 8288 bytes at q=150 |
| 16916 | 16934 | // and 33014 -> 33090 at q=60. |
| 16935 | + // Re-taken on lane-b128: sequences code 128x128 superblocks by | |
| 16936 | + // default now ([`SB128_DEFAULT`]), and their roots can leave a whole | |
| 16937 | + // 128x128 block whole -- 8288 -> 8303 bytes at q=150 and 33090 -> | |
| 16938 | + // 33132 at q=60. `EC_AV1_SB128=0` restores the 64-superblock stream. | |
| 16917 | 16939 | let pins: [(u8, usize, u64); 2] = |
| 16918 | - [(150, 8288, 0x241d_8115_0a6d_0f34), (60, 33090, 0x7e02_777c_01b4_f035)]; | |
| 16940 | + [(150, 8303, 0x0368_e400_f09d_02ba), (60, 33132, 0x884b_c219_5ea9_6416)]; | |
| 16919 | 16941 | let coded: Vec<(u8, usize, u64)> = pins |
| 16920 | 16942 | .iter() |
| 16921 | 16943 | .map(|&(q, _, _)| { |
lanes/b128.report.mdadded+79 -0
| @@ -0,0 +1,79 @@ | ||
| 1 | +# lane-b128 — a real 128x128 root under `EC_AV1_SB128` | |
| 2 | + | |
| 3 | +Three results: | |
| 4 | + | |
| 5 | +1. **Task 0 (the drl pricer) is a STALE premise, and now has its enumeration | |
| 6 | + test.** The charter's `encode.rs:8722` mis-pricing was already closed by | |
| 7 | + the lane-sb128b merge on the WRITER side; the pricer's own offer set is | |
| 8 | + provably clamp-free against its own stack. | |
| 9 | +2. **The 128x128 `PARTITION_NONE` root is implemented, witnessed and | |
| 10 | + MEASURED** — and it turns lane-sb128b's refutation around: film B | |
| 11 | + +24.2%/−2.5% vs libaom cpu-6 / rav1e s6 with 128 superblocks ON, against | |
| 12 | + the SPLIT-only arm's +37.5%/+7.3%. | |
| 13 | +3. **HORZ/VERT (128x64, 64x128) are deferred** — see the disposition below. | |
| 14 | + | |
| 15 | +## 1. Task 0 — the drl offer set, enumerated | |
| 16 | + | |
| 17 | +`crate::tile::signalled_drl_idx(entries, start, target)` is the writer's | |
| 18 | +clamp rule as one pure function (`write_drl_idx`'s own walk now carries a | |
| 19 | +`debug_assert_eq!` against it, so the two cannot drift). The pricer's offer | |
| 20 | +set is enumerated against it over every stack size 0..=4, for both the | |
| 21 | +`NEWMV` (`best_new_mv_syntax`) and the `NEARMV` (`entries.get(idx)`) arms: | |
| 22 | + | |
| 23 | + cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer | |
| 24 | + test encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal ... ok | |
| 25 | + | |
| 26 | +GREEN as written: `best_new_mv_syntax` breaks at `entries.len() <= idx`, | |
| 27 | +which is exactly `write_drl_idx`'s `entries.len() > idx + 1` condition, so | |
| 28 | +no offered index is ever clamped **against the same stack**. Byte effect: | |
| 29 | +none — the pins are byte-identical (below). The residual error the report | |
| 30 | +open item names is entirely the SEARCH-time vs WRITE-time stack divergence | |
| 31 | +(lane-sb128b's second open item), which no change on this line can reach. | |
| 32 | + | |
| 33 | +## 2. The 128 root | |
| 34 | + | |
| 35 | +### What moved | |
| 36 | + | |
| 37 | +- `tile.rs` — `Quadrant::Whole128(BlockCoeffs)`; `write_sb128_root` takes the | |
| 38 | + partition value; `write_inter_block_128` writes the block (`skip`, | |
| 39 | + `is_inter`, the reference/mode chain at a 32x32-mi window, motion mode, tx | |
| 40 | + syntax, mi grid + neighbour bands over all 32 mi cells); the inter tile | |
| 41 | + loop skips the root's remaining three 64x64 cells, mirroring the decoder's | |
| 42 | + own `sb128_none`; `partition_bits` gained the 128 row; | |
| 43 | + `signalled_drl_idx`; `take_sb128_none_hits`. | |
| 44 | +- `encode.rs` — `search_root_128` (the candidate, its legality and its | |
| 45 | + lambda), `search_skip_64` parameterised by `side`, the tile search loop | |
| 46 | + restructured into ROOTS x cells, the 128-vs-four decision, | |
| 47 | + `take_b128_none_hits`, the `EC_AV1_B128_CENSUS=1` per-frame line. | |
| 48 | + | |
| 49 | +### Deliberate limits (deviations from the charter, each with its reason) | |
| 50 | + | |
| 51 | +- **SKIP only.** A 128x128 block's residual is four TX_64X64 luma units | |
| 52 | + interleaved with a TX_32X32 chroma pair per 64x64 mu chunk (the chroma | |
| 53 | + units on the offset-10 `txb_skip` rows), plus one `txfm_partition` symbol | |
| 54 | + per chunk. Neither the writer nor `Plane::code_from_prediction` has that | |
| 55 | + path; `write_inter_block_128` REFUSES a non-skip block rather than coding | |
| 56 | + one wrong. `search_root_128` therefore offers `residual: false`. | |
| 57 | +- **Single reference only.** The compound arm at 128 would go through | |
| 58 | + `write_compound_block` at a window size it has never been exercised at. | |
| 59 | +- **Inter frames only.** A key frame's 128 root still writes SPLIT. | |
| 60 | +- **HORZ / VERT deferred.** Two 128x64 / 64x128 blocks need rect neighbour | |
| 61 | + recording and rect prediction/SSE on the WRITER and SEARCH sides (the | |
| 62 | + decoder already reads both, lane-sb128c r7); the square NONE arm reuses | |
| 63 | + every existing square helper unchanged. | |
| 64 | + | |
| 65 | +### Witness (red before / green after) | |
| 66 | + | |
| 67 | +`encode::tests::a_128_superblock_clip_whose_root_search_codes_128x128_blocks_decodes_exact` | |
| 68 | +(`--ignored`, it moves the process-global superblock size): | |
| 69 | + | |
| 70 | + cargo test -p ec-av1 --release --lib -- --ignored \ | |
| 71 | + a_128_superblock_clip_whose_root_search --nocapture | |
| 72 | + 128x128 PARTITION_NONE blocks: search won 406, writer coded 406 | |
| 73 | + test ... ok | |
| 74 | + | |
| 75 | +8 frames, 1280x768, a slow pan over `smptebars` at `force_sb128(true)`: | |
| 76 | +**406** 128x128 blocks coded, every frame sample-exact against the encoder's | |
| 77 | +own reconstruction through `decode_stream` AND through ffmpeg. RED before | |
| 78 | +this lane by construction: `write_sb128_root` wrote `PARTITION_SPLIT` at | |
| 79 | +every root, so the count was 0 and no such block existed to decode. |