forge
Explore
Log in

Don't you dare go Hollow

The tile writers walk 128x128 superblocks under EC_AV1_SB128

Browse files at this commit

d2e10de1e982958ec3a31bf8e30564f877c50719Ahmet Kaan GümüşParent: f82ceec
  • feat
    • the tile writers walk 128x128 superblocks under EC_AV1_SB128
Show full message
feat(av1): the tile writers walk 128x128 superblocks under EC_AV1_SB128

The sequence bit, a 128 partition root whose only arm is SPLIT into the four
64x64 superblocks the encoder already codes, loop restoration read once over
the 128 span (and its unit size forced to 128, the smallest a 128 superblock
can signal), and libaom's TL/TR/BL/BR visit order.

The writer's no-neighbour partition sentinel moves 64 -> 128 to match the
decoder's: at 64 it is byte-neutral, at the 128 root it put the symbol on CDF
row 3 instead of row 0.
crates/ec-av1/src/decode.rsmodified+14 -5
@@ -158,7 +158,12 @@ impl FrameCtx {
158158 /// predecessor was born with.
159159 pub(crate) fn new() -> Self {
160160 Self {
161- sb128_flag: std::cell::Cell::new(false),
161+ // lane-sb128: an ENCODER context starts at the sequence size
162+ // this process encodes (`crate::encode::sb128_on`) so the mode
163+ // search's own `Reach` and the filter search's internal decodes
164+ // agree with the tile writer; every real decode overwrites it
165+ // from the parsed sequence header (`set_sb128`, stream.rs).
166+ sb128_flag: std::cell::Cell::new(crate::encode::sb128_on()),
162167 lossless_flag: std::cell::Cell::new(false),
163168 cdef_bits: std::cell::Cell::new(0),
164169 bit_depth: std::cell::Cell::new(8),
@@ -203,7 +208,11 @@ impl FrameCtx {
203208 inter_last_mc: std::cell::Cell::new(None),
204209 enable_edge_filter: std::cell::Cell::new(false),
205210 last_frame_wide_margin: std::cell::RefCell::new(None),
206- reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),
211+ reach_sb_px: std::cell::Cell::new(if crate::encode::sb128_on() {
212+ 128
213+ } else {
214+ crate::encode::SUPERBLOCK
215+ }),
207216 grain_bit_depth: std::cell::Cell::new(8),
208217 recon_ops: std::cell::RefCell::new(Vec::new()),
209218 recon_spare: std::cell::RefCell::new(Vec::new()),
@@ -407,14 +416,14 @@ pub(crate) fn part128_split_hits() -> usize {
407416 /// has 8 symbols (no `PARTITION_HORZ_4`/`_VERT_4` at `BLOCK_128X128`, spec
408417 /// `partition_cdf_length`), so its forced-split gather sums 5 elements where
409418 /// the 64/32 levels sum 6.
410-fn gather_of(cdf: &[u16], elements: &[usize]) -> [u16; 3] {
419+pub(crate) fn gather_of(cdf: &[u16], elements: &[usize]) -> [u16; 3] {
411420 let split: u16 = elements.iter().map(|&e| element_prob(cdf, e)).sum();
412421 [32768 - split, 32768, 0]
413422 }
414423
415424 /// [`VERT_ALIKE`]/[`HORZ_ALIKE`] without the 1:4 arms, for the 128 root.
416-const VERT_ALIKE128: [usize; 5] = [2, PARTITION_SPLIT, 4, 6, 7];
417-const HORZ_ALIKE128: [usize; 5] = [1, PARTITION_SPLIT, 4, 5, 6];
425+pub(crate) const VERT_ALIKE128: [usize; 5] = [2, PARTITION_SPLIT, 4, 6, 7];
426+pub(crate) const HORZ_ALIKE128: [usize; 5] = [1, PARTITION_SPLIT, 4, 5, 6];
418427
419428 // How many `use_filter_intra` symbols this decoder has read as `1`, across
420429 // every call on the current thread -- the cheap counter [`filter_intra_hits`] gate
crates/ec-av1/src/encode.rsmodified+36 -8
@@ -1547,7 +1547,7 @@ pub(crate) fn key_frame_headers_colour(
15471547 frame_height_bits,
15481548 max_frame_width: w,
15491549 max_frame_height: h,
1550- use_128x128_superblock: false,
1550+ use_128x128_superblock: sb128_on(),
15511551 // lane-fintra: the encoder's intra search offers the five recursive
15521552 // filter-intra modes on eligible blocks, so the sequence bit is set
15531553 // whenever that search is on (`EC_AV1_FILTER_INTRA=0` switches both
@@ -4654,6 +4654,28 @@ fn cfl_on() -> bool {
46544654 /// (`EC_AV1_FILTER_INTRA=0` switches both off, which is how the lane measured
46554655 /// its own on/off pair -- and how every byte pin written before it still
46564656 /// reproduces). It is also a speed lever: on at preset 0, off above it.
4657+// lane-sb128: `use_128x128_superblock` (spec 5.5.1). Off by default until
4658+// the BD gate says otherwise; `EC_AV1_SB128=1` turns it on for the whole
4659+// process (a sequence-header field, so it cannot change mid-stream anyway),
4660+// the same env-flag shape `EC_AV1_FILTER_INTRA` uses. NOT an `EncoderConfig`
4661+// field: that struct is built by 90 literal sites in this workspace.
4662+
4663+/// Whether this process's sequences code 128x128 superblocks.
4664+pub(crate) fn sb128_on() -> bool {
4665+ static ENV: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {
4666+ crate::envflags::var("EC_AV1_SB128").ok().is_some_and(|v| v != "0")
4667+ });
4668+ *ENV
4669+}
4670+
4671+/// The luma loop-restoration unit size this sequence codes: a 128 superblock
4672+/// cannot signal the 64 unit at all (spec `lr_params` reads ONE bit there,
4673+/// `RESTORATION_TILESIZE_MAX >> (2 - (shift + 1))`, so the smallest unit is
4674+/// 128), which is the one filter parameter the superblock size moves.
4675+pub(crate) fn lr_unit() -> u32 {
4676+ if sb128_on() { 128 } else { 64 }
4677+}
4678+
46574679 pub(crate) fn filter_intra_on() -> bool {
46584680 #[cfg(test)]
46594681 if let Some(forced) = FILTER_INTRA_FORCE.with(std::cell::Cell::get) {
@@ -7004,8 +7026,8 @@ pub(crate) fn encode_key_frame_inner(
70047026 // (`av1_lr_count_units` rounds to nearest, so a short last unit is
70057027 // swallowed by the one before it), for the tile writer's own per-unit
70067028 // walk.
7007- let lr_horz = crate::restoration::count_units(header.frame_width, 64) as u32;
7008- let lr_vert = crate::restoration::count_units(header.frame_height, 64) as u32;
7029+ let lr_horz = crate::restoration::count_units(header.frame_width, lr_unit()) as u32;
7030+ let lr_vert = crate::restoration::count_units(header.frame_height, lr_unit()) as u32;
70097031 // Every tile is coded from this frame's OWN starting tables and leaves
70107032 // its own end state behind (spec 5.11.1: each tile resets the CDFs, the
70117033 // loop-restoration reference and its neighbour contexts), so the tiles
@@ -7017,7 +7039,8 @@ pub(crate) fn encode_key_frame_inner(
70177039 -> Result<Vec<Vec<u8>>> {
70187040 let (out, _) = write_tiles(layout.count(), usize::MAX, |index| {
70197041 crate::tile::arm_cdef_idx(bits, sb_cols, grid.to_vec());
7020- crate::tile::arm_lr(64, lr_horz, lr_vert, units.to_vec());
7042+ crate::tile::arm_lr(lr_unit(), lr_horz, lr_vert, units.to_vec());
7043+ crate::tile::arm_sb128(sb128_on());
70217044 let mut cdfs = start_cdfs.0.clone();
70227045 crate::tile::arm_screen(screen);
70237046 crate::tile::arm_filter_intra(filter_intra_on());
@@ -7302,9 +7325,13 @@ fn pick_and_apply_filters(
73027325 // rather than decoding the re-coded tile. Cleared at the end instead.
73037326 let mut lr = LoopRestorationParams::default();
73047327 if lr_on {
7328+ let unit = lr_unit();
73057329 let mut want = LoopRestorationParams {
7306- loop_restoration_size: [64, 64, 64],
7330+ loop_restoration_size: [unit, unit, unit],
73077331 uses_lr: true,
7332+ // spec `lr_params`: `RESTORATION_TILESIZE_MAX >> (2 - shift)`, so
7333+ // 0 is the 64 unit and 1 the 128 one a 128 superblock forces.
7334+ lr_unit_shift: u8::from(unit == 128),
73087335 ..LoopRestorationParams::default()
73097336 };
73107337 want.frame_restoration_type[0] = ec_av1_syntax::RestorationType::Wiener;
@@ -10446,8 +10473,8 @@ pub(crate) fn encode_inter_frame(
1044610473 let switchable_motion_mode = header.is_motion_mode_switchable;
1044710474 let warped_motion = header.allow_warped_motion;
1044810475 let order_hint_bits = seq.order_hint_bits;
10449- let lr_horz = crate::restoration::count_units(header.frame_width, 64) as u32;
10450- let lr_vert = crate::restoration::count_units(header.frame_height, 64) as u32;
10476+ let lr_horz = crate::restoration::count_units(header.frame_width, lr_unit()) as u32;
10477+ let lr_vert = crate::restoration::count_units(header.frame_height, lr_unit()) as u32;
1045110478 // What this frame stores is the LARGEST tile's end-of-tile tables --
1045210479 // its own header's `context_update_tile_id` (spec 7.20), which
1045310480 // `tile_info_of` set to exactly that tile.
@@ -10462,7 +10489,8 @@ pub(crate) fn encode_inter_frame(
1046210489 -> Result<Vec<Vec<u8>>> {
1046310490 let (out, stored) = write_tiles(layout.count(), store_tile, |index| {
1046410491 crate::tile::arm_cdef_idx(bits, sb_cols, cdef_grid.to_vec());
10465- crate::tile::arm_lr(64, lr_horz, lr_vert, units.to_vec());
10492+ crate::tile::arm_lr(lr_unit(), lr_horz, lr_vert, units.to_vec());
10493+ crate::tile::arm_sb128(sb128_on());
1046610494 crate::tile::arm_sign_bias(sign_bias);
1046710495 // Thread-locals: every tile job arms its own worker.
1046810496 crate::tile::arm_reference_select(reference_select_bit);
crates/ec-av1/src/tile.rsmodified+172 -19
@@ -85,19 +85,123 @@ pub(crate) fn arm_lr(
8585 });
8686 }
8787
88+// ---------------------------------------------------------------------------
89+// lane-sb128: the sequence's `use_128x128_superblock`. Armed per tile write
90+// like [`arm_lr`] (the encoder codes one tile at a time per thread) rather
91+// than threaded through every writer signature. When set, the two tile
92+// writers walk 128x128 superblocks -- loop restoration and one
93+// `partition_w128` symbol at the 128 root, then the four 64x64 quadrants in
94+// libaom `decode_partition`'s own TL, TR, BL, BR order -- which is exactly
95+// what `crate::decode::read_sb128_root` reads.
96+
97+thread_local! {
98+ static SB128: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
99+}
100+
101+/// Arms the next tile write with the sequence's 128x128 superblock size.
102+pub(crate) fn arm_sb128(on: bool) {
103+ SB128.with(|c| c.set(on));
104+}
105+
106+/// Whether the next tile write codes 128x128 superblocks ([`arm_sb128`]).
107+fn sb128_armed() -> bool {
108+ SB128.with(std::cell::Cell::get)
109+}
110+
111+/// The order a tile's 64x64 superblock cells are written in, mirroring
112+/// `crate::decode::sb_visit_order` exactly: plain raster at a 64 superblock,
113+/// and TL/TR/BL/BR inside each 128x128 superblock (in raster order over the
114+/// 128 grid) at a 128 one. The two flags mark the first cell of a superblock
115+/// ROW (where the left neighbour context resets) and the first cell of a
116+/// superblock (where the 128 root's own restoration units and partition
117+/// symbol are written).
118+fn sb_write_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32, u32, bool, bool)> {
119+ let mut out = Vec::new();
120+ if !sb128 {
121+ for r in r0..r1 {
122+ for c in c0..c1 {
123+ out.push((r, c, c == c0, true));
124+ }
125+ }
126+ return out;
127+ }
128+ let mut r = r0;
129+ while r < r1 {
130+ let mut first_in_row = true;
131+ let mut c = c0;
132+ while c < c1 {
133+ let mut first_in_sb = true;
134+ for qr in 0..2 {
135+ for qc in 0..2 {
136+ let (rr, cc) = (r + qr, c + qc);
137+ if rr >= r1 || cc >= c1 {
138+ continue;
139+ }
140+ out.push((rr, cc, first_in_row, first_in_sb));
141+ first_in_row = false;
142+ first_in_sb = false;
143+ }
144+ }
145+ c += 2;
146+ }
147+ r += 2;
148+ }
149+ out
150+}
151+
152+/// The 128x128 superblock root ([`sb_write_order`]'s `sb_start` cells): the
153+/// units its own 128-sample span covers, then the partition symbol. Only
154+/// `PARTITION_SPLIT` is written -- the four 64x64 quadrants below are today's
155+/// superblocks -- and at a root the true frame edge cuts, the DECIDING
156+/// gathered bit the decoder reads instead (`read_sb128_root`).
157+fn write_sb128_root(
158+ enc: &mut SymbolEncoder,
159+ cdfs: &mut Cdfs,
160+ neighbours: &Neighbours,
161+ sb_r: u32,
162+ sb_c: u32,
163+ mi_cols: u32,
164+ mi_rows: u32,
165+) {
166+ let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI);
167+ write_lr(enc, cdfs, mi_r128, mi_c128, SB_MI * 2);
168+ let at128 = ((mi_r128 / 4) as usize, (mi_c128 / 4) as usize);
169+ let ctx128 = neighbours.partition_ctx(at128, 128);
170+ let (has_cols128, has_rows128) = (mi_c128 + SB_MI < mi_cols, mi_r128 + SB_MI < mi_rows);
171+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
172+ eprintln!("WTRACE partition_w128 ctx={ctx128} cols={has_cols128} rows={has_rows128}");
173+ }
174+ match (has_cols128, has_rows128) {
175+ (true, true) => enc.symbol(PARTITION_SPLIT, &mut cdfs.partition_w128[ctx128]),
176+ // As at the 64 root: the gathered CDF is built for the read and
177+ // thrown away, so nothing adapts here. Value 1 is SPLIT.
178+ (true, false) => enc.symbol_fixed(
179+ 1,
180+ &crate::decode::gather_of(&cdfs.partition_w128[ctx128], &crate::decode::VERT_ALIKE128),
181+ ),
182+ (false, true) => enc.symbol_fixed(
183+ 1,
184+ &crate::decode::gather_of(&cdfs.partition_w128[ctx128], &crate::decode::HORZ_ALIKE128),
185+ ),
186+ // Both halves outside: the split is the only partition left and the
187+ // decoder reads nothing.
188+ (false, false) => {}
189+ }
190+}
191+
88192 /// `read_lr`'s write side, called once at the top of every superblock,
89193 /// before its partition symbol: writes the units this superblock's own
90194 /// mi span covers (`av1_loop_restoration_corners_in_sb`; no superres, so the
91195 /// column scaling is the plain mi one).
92-fn write_lr(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, mi_row: u32, mi_col: u32) {
196+fn write_lr(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, mi_row: u32, mi_col: u32, span: u32) {
93197 LR_PLAN.with(|c| {
94198 let mut plan = c.borrow_mut();
95199 let Some(plan) = plan.as_mut() else { return };
96200 let unit = plan.unit_size;
97201 let rcol0 = (mi_col * 4).div_ceil(unit);
98- let rcol1 = ((mi_col + SB_MI_W) * 4).div_ceil(unit).min(plan.horz_units);
202+ let rcol1 = ((mi_col + span) * 4).div_ceil(unit).min(plan.horz_units);
99203 let rrow0 = (mi_row * 4).div_ceil(unit);
100- let rrow1 = ((mi_row + SB_MI_W) * 4).div_ceil(unit).min(plan.vert_units);
204+ let rrow1 = ((mi_row + span) * 4).div_ceil(unit).min(plan.vert_units);
101205 for rrow in rrow0..rrow1 {
102206 for rcol in rcol0..rcol1 {
103207 let info = plan.units[(rcol + rrow * plan.horz_units) as usize];
@@ -177,9 +281,14 @@ impl TileLayout {
177281 pub(crate) fn new(mi_cols: u32, mi_rows: u32, cols_log2: u32, rows_log2: u32) -> Self {
178282 let (cols32, rows32) = block_grid(mi_cols, mi_rows);
179283 let (sb_cols, sb_rows) = (cols32.div_ceil(2), rows32.div_ceil(2));
284+ // lane-sb128: a tile boundary is a SUPERBLOCK boundary, so under a
285+ // 128 superblock the starts are laid out on the 128 grid and then
286+ // doubled back into the 64-cell units the writers walk.
287+ let unit = u32::from(crate::encode::sb128_on()) + 1;
180288 let starts = |total: u32, log2: u32| {
181- let step = total.div_ceil(1 << log2).max(1);
182- let mut v: Vec<u32> = (0..total).step_by(step as usize).collect();
289+ let total128 = total.div_ceil(unit);
290+ let step = total128.div_ceil(1 << log2).max(1);
291+ let mut v: Vec<u32> = (0..total128).step_by(step as usize).map(|s| s * unit).collect();
183292 v.push(total);
184293 v
185294 };
@@ -1696,6 +1805,14 @@ const TX4: usize = 4;
16961805 /// Side of a superblock, in samples, which is the size a block outside the
16971806 /// tile reads as.
16981807 const SB: usize = 64;
1808+
1809+/// The `above_side`/`left_side` value a cell with no coded neighbour holds
1810+/// (tile start, superblock-row start) -- the writer's copy of
1811+/// `crate::decode::NO_NEIGHBOUR_SIDE`, and 128 for the same reason: at 64 it
1812+/// reads identically at every level up to 64x64 but sets the bit at the
1813+/// `BLOCK_128X128` root (64 * 2 <= 128), putting that root's partition symbol
1814+/// on CDF row 3 where libaom uses row 0.
1815+const NO_NEIGHBOUR_SIDE: usize = 128;
16991816 /// Side of the smallest block the writer codes, in samples, which is the grid
17001817 /// the neighbour bookkeeping is kept on.
17011818 const SUB: usize = 16;
@@ -1947,10 +2064,10 @@ impl Neighbours {
19472064 left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)],
19482065 above_mode: vec![DC_PRED; cols],
19492066 left_mode: vec![DC_PRED; rows],
1950- above_side: vec![SB; cols],
1951- left_side: vec![SB; rows],
1952- above_side_mi: vec![SB; cols * (SUB / MI)],
1953- left_side_mi: vec![SB; rows * (SUB / MI)],
2067+ above_side: vec![NO_NEIGHBOUR_SIDE; cols],
2068+ left_side: vec![NO_NEIGHBOUR_SIDE; rows],
2069+ above_side_mi: vec![NO_NEIGHBOUR_SIDE; cols * (SUB / MI)],
2070+ left_side_mi: vec![NO_NEIGHBOUR_SIDE; rows * (SUB / MI)],
19542071 above_skip: vec![false; cols * (SUB / MI)],
19552072 left_skip: vec![false; rows * (SUB / MI)],
19562073 above_inter: vec![false; cols * (SUB / MI)],
@@ -2003,8 +2120,8 @@ impl Neighbours {
20032120 fn start_row(&mut self) {
20042121 self.left.iter_mut().for_each(|l| *l = Default::default());
20052122 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
2006- self.left_side.iter_mut().for_each(|s| *s = SB);
2007- self.left_side_mi.iter_mut().for_each(|s| *s = SB);
2123+ self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
2124+ self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
20082125 self.left_skip.iter_mut().for_each(|s| *s = false);
20092126 self.left_inter.iter_mut().for_each(|i| *i = false);
20102127 self.left_ref.iter_mut().for_each(|r| *r = -1);
@@ -2648,10 +2765,28 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs(
26482765 // off.
26492766 let mut cdfs = cdfs;
26502767 let mut enc = SymbolEncoder::new();
2651- for sb_r in tile.sb_row0..tile.sb_row1.min(sb_rows) {
2652- neighbours.start_row();
2653- for sb_c in tile.sb_col0..tile.sb_col1.min(sb_cols) {
2654- write_lr(&mut enc, &mut cdfs, sb_r * SB_MI_W, sb_c * SB_MI_W);
2768+ let sb128 = sb128_armed();
2769+ // lane-sb128: at a 128 superblock the four 64x64 cells of each root are
2770+ // written in libaom's own TL/TR/BL/BR order, the root's restoration units
2771+ // and partition symbol first; at a 64 one this is plain raster and every
2772+ // cell is its own superblock, i.e. byte-identical to the loop before.
2773+ for (sb_r, sb_c, row_start, sb_start) in sb_write_order(
2774+ tile.sb_row0,
2775+ tile.sb_row1.min(sb_rows),
2776+ tile.sb_col0,
2777+ tile.sb_col1.min(sb_cols),
2778+ sb128,
2779+ ) {
2780+ if row_start {
2781+ neighbours.start_row();
2782+ }
2783+ if sb128 && sb_start {
2784+ write_sb128_root(&mut enc, &mut cdfs, &neighbours, sb_r, sb_c, mi_cols, mi_rows);
2785+ }
2786+ {
2787+ if !sb128 {
2788+ write_lr(&mut enc, &mut cdfs, sb_r * SB_MI_W, sb_c * SB_MI_W, SB_MI_W);
2789+ }
26552790 let at = (sb_r as usize * 4, sb_c as usize * 4);
26562791 let ctx = neighbours.partition_ctx(at, SB);
26572792 ec_rng_trace(|| {
@@ -5809,10 +5944,28 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
58095944 vec![0i32; TX16 * TX16],
58105945 ];
58115946
5812- for sb_r in tile.sb_row0..tile.sb_row1.min(sb_rows) {
5813- neighbours.start_row();
5814- for sb_c in tile.sb_col0..tile.sb_col1.min(sb_cols) {
5815- write_lr(&mut enc, &mut cdfs, sb_r * SB_MI_W, sb_c * SB_MI_W);
5947+ let sb128 = sb128_armed();
5948+ // lane-sb128: at a 128 superblock the four 64x64 cells of each root are
5949+ // written in libaom's own TL/TR/BL/BR order, the root's restoration units
5950+ // and partition symbol first; at a 64 one this is plain raster and every
5951+ // cell is its own superblock, i.e. byte-identical to the loop before.
5952+ for (sb_r, sb_c, row_start, sb_start) in sb_write_order(
5953+ tile.sb_row0,
5954+ tile.sb_row1.min(sb_rows),
5955+ tile.sb_col0,
5956+ tile.sb_col1.min(sb_cols),
5957+ sb128,
5958+ ) {
5959+ if row_start {
5960+ neighbours.start_row();
5961+ }
5962+ if sb128 && sb_start {
5963+ write_sb128_root(&mut enc, &mut cdfs, &neighbours, sb_r, sb_c, mi_cols, mi_rows);
5964+ }
5965+ {
5966+ if !sb128 {
5967+ write_lr(&mut enc, &mut cdfs, sb_r * SB_MI_W, sb_c * SB_MI_W, SB_MI_W);
5968+ }
58165969 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);
58175970 let sb_ctx = neighbours.partition_ctx(sb_at, SB);
58185971 // spec `decode_partition`'s hasRows/hasCols (5.11.4): a superblock
lanes/sb128.report.mdadded+42 -0
@@ -0,0 +1,42 @@
1+# lane-sb128 -- 128x128 superblocks in the encoder
2+
3+## Step 1: the sequence option, SPLIT-only roots (structural cost)
4+
5+`EC_AV1_SB128=1` writes `use_128x128_superblock = 1` in the sequence header
6+and makes both tile writers walk 128x128 superblocks: loop restoration and
7+one `partition_w128` symbol at the 128 root, then the four 64x64 quadrants
8+(today's superblocks, unchanged) in libaom's TL/TR/BL/BR order. Every
9+partition decision below the root is identical to the 64-superblock encoder,
10+so the whole cost of the step is the extra partition symbols plus the moved
11+loop-restoration unit size.
12+
13+NOT an `EncoderConfig` field (deviation from the charter, stated): that
14+struct is built by 90 literal sites in this workspace, so a new public field
15+is a 90-file diff for a knob whose default the gate decides. `EC_AV1_SB128`
16+follows `EC_AV1_FILTER_INTRA`'s existing shape.
17+
18+### What moved
19+
20+- `crates/ec-av1/src/tile.rs` -- `arm_sb128` + `sb_write_order` (an exact
21+ mirror of `decode::sb_visit_order`) + `write_sb128_root` (LR over the 128
22+ span, then `PARTITION_SPLIT` off `partition_w128`, or the DECIDING gathered
23+ bit at a root the frame edge cuts); `write_lr` takes its span; the
24+ no-neighbour partition sentinel is 128, not 64.
25+- `crates/ec-av1/src/encode.rs` -- `sb128_on()`, `lr_unit()` (a 128
26+ superblock cannot signal the 64 restoration unit at all), the sequence bit,
27+ both tile-write arming sites.
28+- `crates/ec-av1/src/decode.rs` -- `gather_of`/`VERT_ALIKE128`/`HORZ_ALIKE128`
29+ exported to the writer; an encoder `FrameCtx` starts at this process's
30+ superblock size so the search's `Reach` and the filter search's internal
31+ decodes agree with the writer.
32+
33+### Root cause found on the way
34+
35+The writer's `Neighbours` used 64 as its "no neighbour" partition side. That
36+reads identically at every level up to 64x64 but sets the bit at the 128 root
37+(`64 * 2 <= 128`), so the writer coded the root's partition symbol off CDF
38+row 3 while the decoder read row 0 -- a first-symbol desync that decoded the
39+whole frame as one 128x128 intra block. The decoder had already fixed its own
40+copy (`decode::NO_NEIGHBOUR_SIDE`, lane-sb128 r1); the writer's copy had not
41+moved. Class: *table and reader move together*.
42+