forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-realworld': delta_q/delta_lf decode 40/40 pixel-exact (delta_q_hits=delta_lf_hits=1920, hard-asserted)

Browse files at this commit

a74bb66775e39f8d13eae80716af5040117d3194Ahmet Kaan GümüşParent: e89401fd22f8c2
Blocker (2) of the default-aomenc-settings chain closed. Recipe needs
--deltaq-mode=2 (mode 1 is content-dependent) plus the separate
--delta-lf-mode=1.

The merge was textually clean but semantically broken: lane-tiles' new
tile-row gate calls decode_key_frame_tile_with_cdfs with 16 args while this
branch gave the function a 17th (DeltaParams). Added header.delta at
stream.rs:6396 to match the four sibling call sites.

Suite 249 passed / 0 failed.
crates/ec-av1/src/cdf.rsmodified+8 -0
@@ -420,6 +420,14 @@ pub const PALETTE_UV_MODE: [[u16; 3]; 2] = [[32461, 32768, 0], [21488, 32768, 0]
420420 /// intra frame with `allow_intrabc` set.
421421 pub const INTRABC: [u16; 3] = [30531, 32768, 0];
422422
423+/// `default_delta_q_cdf` (entropymode.c:840-852, lane-realworld r4): the
424+/// 4-symbol `delta_q_abs` alphabet read once per superblock when
425+/// `delta_q_present` is set. `default_delta_lf_cdf`/`default_delta_lf_multi_cdf`
426+/// share this same value (verified against libaom's real source).
427+pub const DELTA_Q: [u16; 5] = [28160, 32120, 32677, 32768, 0];
428+/// `default_delta_lf_cdf` -- see [`DELTA_Q`]'s doc.
429+pub const DELTA_LF: [u16; 5] = DELTA_Q;
430+
423431 /// `default_tx_size_cdf[0]` (entropymode.c): an 8x8 block's `tx_depth` flag
424432 /// (`TX8` vs `TX4`), indexed by `tx_size_context` (0..=2).
425433 pub const TX_SIZE_CAT0: [[u16; 3]; 3] = [[19968, 32768, 0], [19968, 32768, 0], [24320, 32768, 0]];
crates/ec-av1/src/cdf_state.rsmodified+16 -0
@@ -433,6 +433,16 @@ pub(crate) struct Cdfs {
433433 pub palette_uv_size: [[u16; 8]; 7],
434434 /// The `use_intrabc` flag -- see [`cdf::INTRABC`].
435435 pub intrabc: [u16; 3],
436+ /// `delta_q_abs` (lane-realworld r4, spec 5.11.10) -- see [`cdf::DELTA_Q`].
437+ pub delta_q: [u16; 5],
438+ /// `delta_lf_abs`, the single-value form (spec 5.11.11) -- see
439+ /// [`cdf::DELTA_LF`]. Currently unread: `delta_lf_present` still refuses
440+ /// by name in `stream.rs` (the deblocker has no per-block carrier for
441+ /// the result yet), kept here so the struct is ready for that round.
442+ pub delta_lf: [u16; 5],
443+ /// `delta_lf_abs[i]`, the `delta_lf_multi` per-plane/direction form
444+ /// (`FRAME_LF_COUNT = 4`) -- same unread status as [`Self::delta_lf`].
445+ pub delta_lf_multi: [[u16; 5]; 4],
436446 }
437447
438448 /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`,
@@ -654,6 +664,9 @@ impl Cdfs {
654664 reset2(&mut self.palette_uv_mode);
655665 reset2(&mut self.palette_uv_size);
656666 reset1(&mut self.intrabc);
667+ reset1(&mut self.delta_q);
668+ reset1(&mut self.delta_lf);
669+ reset2(&mut self.delta_lf_multi);
657670 }
658671
659672 /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and
@@ -1114,6 +1127,9 @@ impl Cdfs {
11141127 palette_uv_mode: cdf::PALETTE_UV_MODE,
11151128 palette_uv_size: cdf::PALETTE_UV_SIZE,
11161129 intrabc: cdf::INTRABC,
1130+ delta_q: cdf::DELTA_Q,
1131+ delta_lf: cdf::DELTA_LF,
1132+ delta_lf_multi: [cdf::DELTA_LF; 4],
11171133 }
11181134 }
11191135
crates/ec-av1/src/decode.rsmodified+206 -9
@@ -21,7 +21,7 @@
2121 //! too). Anything outside that refuses with [`Error::unsupported`] rather than
2222 //! silently miscoding.
2323
24-use ec_av1_syntax::{CdefParams, LoopFilterParams, TileInfo};
24+use ec_av1_syntax::{CdefParams, DeltaParams, LoopFilterParams, TileInfo};
2525 use ec_core::{Error, Result};
2626
2727 use crate::cdf;
@@ -106,6 +106,133 @@ pub(crate) fn cdef_idx_hits() -> usize {
106106 CDEF_IDX_HITS.with(|c| c.get())
107107 }
108108
109+// lane-realworld r4: this frame's `delta.q_present` (spec 5.9.17) and its
110+// actual step (`1 << delta.q_res`, already the real multiplier, not the raw
111+// 2-bit field). `false`/`1` (the defaults) make [`maybe_read_delta_q`] a
112+// true no-op, matching every existing gate stream's `delta_q_present == 0`
113+// behaviour exactly, the same corner-cut [`CDEF_BITS`] takes above.
114+thread_local! {
115+ static DELTA_Q_PRESENT: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
116+ static DELTA_Q_RES: std::cell::Cell<i32> = const { std::cell::Cell::new(1) };
117+}
118+// The running quantizer index (spec `CurrentQIndex`, libaom
119+// `xd->current_base_qindex`) -- reset to the frame's own `base_q_idx` at the
120+// top of every tile (spec `decode_tile`), carried across superblocks within
121+// that tile, and mutated only by [`maybe_read_delta_q`]. Read back at the
122+// dequantization call sites instead of the frame-constant `base_q_idx`.
123+thread_local! {
124+ static CURRENT_Q_IDX: std::cell::Cell<i32> = const { std::cell::Cell::new(0) };
125+}
126+// How many real `delta_q_present` symbol groups [`maybe_read_delta_q`] has
127+// read, across every call on the current thread -- the gate's proof that a
128+// `delta_q_present` stream actually reached the new reader.
129+thread_local! {
130+ static DELTA_Q_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
131+}
132+
133+/// Current value of [`DELTA_Q_HITS`].
134+pub(crate) fn delta_q_hits() -> usize {
135+ DELTA_Q_HITS.with(|c| c.get())
136+}
137+
138+/// `read_delta_qindex`/`read_delta_q_params` (spec 5.11.10, libaom
139+/// `decodemv.c:85-146,735-770`), called right after [`maybe_read_cdef_idx`]
140+/// at every block-decode call site (spec order `skip -> cdef -> delta_q`).
141+/// A no-op when `delta_q_present` is unset, or when this block is not at the
142+/// superblock's own top-left MI position (`b_row == 0 && b_col == 0` in
143+/// libaom, collapsed here to a position check since a partition tree's
144+/// top-left leaf is the only block that can ever land there), or when that
145+/// leaf both *is* the whole superblock and is `skip` (the one case libaom
146+/// itself skips the read, state carrying over unchanged).
147+fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool) {
148+ if !DELTA_Q_PRESENT.with(|c| c.get()) {
149+ return;
150+ }
151+ if mi_r % SB_MI as usize != 0 || mi_c % SB_MI as usize != 0 {
152+ return;
153+ }
154+ if is_whole_sb && skip {
155+ return;
156+ }
157+ let mut abs = dec.symbol(&mut cdfs.delta_q) as i32;
158+ const DELTA_Q_SMALL: i32 = 3;
159+ if abs >= DELTA_Q_SMALL {
160+ let rem_bits = dec.literal(3) + 1;
161+ let thr = (1i32 << rem_bits) + 1;
162+ abs = dec.literal(rem_bits) as i32 + thr;
163+ }
164+ let sign_negative = if abs != 0 { dec.literal(1) != 0 } else { true };
165+ let reduced = if sign_negative { -abs } else { abs };
166+ DELTA_Q_HITS.with(|c| c.set(c.get() + 1));
167+ let res = DELTA_Q_RES.with(|c| c.get());
168+ CURRENT_Q_IDX.with(|c| c.set((c.get() + reduced * res).clamp(1, 255)));
169+}
170+
171+// lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi`
172+// (spec 5.9.18) -- same no-op-by-default corner-cut as `DELTA_Q_PRESENT`.
173+thread_local! {
174+ static DELTA_LF_PRESENT: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
175+ static DELTA_LF_RES: std::cell::Cell<i32> = const { std::cell::Cell::new(1) };
176+ static DELTA_LF_MULTI: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
177+}
178+// The running per-plane/direction loop-filter delta (spec `DeltaLF[i]`,
179+// `i` in `0..FRAME_LF_COUNT`) -- reset to `[0; 4]` at the top of every tile,
180+// mutated only by [`maybe_read_delta_lf`]. `!delta_lf_multi` mode only ever
181+// updates index 0 and every reader treats that as the value for all 4
182+// indices (spec `read_delta_lf_params`'s own single-cdf branch).
183+thread_local! {
184+ static CURRENT_DELTA_LF: std::cell::Cell<[i32; 4]> = const { std::cell::Cell::new([0; 4]) };
185+}
186+// How many real `delta_lf_present` symbol groups [`maybe_read_delta_lf`] has
187+// read -- the gate's proof the reader fired, mirroring [`DELTA_Q_HITS`].
188+thread_local! {
189+ static DELTA_LF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
190+}
191+
192+/// Current value of [`DELTA_LF_HITS`].
193+pub(crate) fn delta_lf_hits() -> usize {
194+ DELTA_LF_HITS.with(|c| c.get())
195+}
196+
197+/// `read_delta_lflevel`/`read_delta_lf_params` (spec 5.11.11, libaom
198+/// `decodemv.c:99-146,735-770`) -- same shape and same call-site gating as
199+/// [`maybe_read_delta_q`] (spec order `delta_q -> delta_lf`), looped over
200+/// `FRAME_LF_COUNT = 4` planes/directions when `delta_lf_multi` is set, or
201+/// read once into index 0 otherwise.
202+fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool) {
203+ if !DELTA_LF_PRESENT.with(|c| c.get()) {
204+ return;
205+ }
206+ if mi_r % SB_MI as usize != 0 || mi_c % SB_MI as usize != 0 {
207+ return;
208+ }
209+ if is_whole_sb && skip {
210+ return;
211+ }
212+ let multi = DELTA_LF_MULTI.with(|c| c.get());
213+ let res = DELTA_LF_RES.with(|c| c.get());
214+ let count = if multi { 4 } else { 1 };
215+ let mut cur = CURRENT_DELTA_LF.with(|c| c.get());
216+ for i in 0..count {
217+ let mut abs = if multi {
218+ dec.symbol(&mut cdfs.delta_lf_multi[i]) as i32
219+ } else {
220+ dec.symbol(&mut cdfs.delta_lf) as i32
221+ };
222+ const DELTA_LF_SMALL: i32 = 3;
223+ if abs >= DELTA_LF_SMALL {
224+ let rem_bits = dec.literal(3) + 1;
225+ let thr = (1i32 << rem_bits) + 1;
226+ abs = dec.literal(rem_bits) as i32 + thr;
227+ }
228+ let sign_negative = if abs != 0 { dec.literal(1) != 0 } else { true };
229+ let reduced = if sign_negative { -abs } else { abs };
230+ cur[i] = (cur[i] + reduced * res).clamp(-63, 63);
231+ DELTA_LF_HITS.with(|c| c.set(c.get() + 1));
232+ }
233+ CURRENT_DELTA_LF.with(|c| c.set(cur));
234+}
235+
109236 /// `read_cdef` (spec 5.11.56, libaom `decodemv.c:read_cdef`), called right
110237 /// after `skip` is known at every block-decode call site. A no-op at
111238 /// `cdef.bits == 0` (0-bit literal, nothing to consume) -- and
@@ -1458,6 +1585,14 @@ struct Neighbours {
14581585 /// widened from a bare `is_inter` bool, which collapsed every non-`LAST`
14591586 /// reference onto `LAST_FRAME`'s own delta).
14601587 ref_grid: Vec<i8>,
1588+ /// Per-4x4-mi snapshot of [`CURRENT_DELTA_LF`] at the moment this cell's
1589+ /// block was decoded (spec `DeltaLF[i]`, `i` in `0..FRAME_LF_COUNT`,
1590+ /// Y-vertical/Y-horizontal/U/V) -- lane-realworld r5: `lf_level`'s
1591+ /// per-block additive term, mirroring [`Self::ref_grid`]'s own snapshot
1592+ /// pattern. `!delta_lf_multi` mode broadcasts index 0 into all 4 slots
1593+ /// at write time ([`Self::fill_lf_grid_rect`]) so a reader never needs
1594+ /// to know which mode produced the value.
1595+ delta_lf_grid: Vec<[i8; 4]>,
14611596 /// This tile's own top-left corner, in 4x4 mode-info units (spec
14621597 /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a
14631598 /// neighbour" check compares against this instead of literal `0`, since a
@@ -1507,6 +1642,7 @@ impl Neighbours {
15071642 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
15081643 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
15091644 ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)],
1645+ delta_lf_grid: vec![[0i8; 4]; cols * (SUB / MI) * rows * (SUB / MI)],
15101646 tile_row0_mi: 0,
15111647 tile_col0_mi: 0,
15121648 }
@@ -1568,6 +1704,12 @@ impl Neighbours {
15681704 ref_frame: i8,
15691705 ) {
15701706 let (mi_r, mi_c) = at_mi;
1707+ let cur = CURRENT_DELTA_LF.with(|c| c.get());
1708+ let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) {
1709+ std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8)
1710+ } else {
1711+ [cur[0].clamp(-63, 63) as i8; 4]
1712+ };
15711713 for rr in 0..h_mi {
15721714 for cc in 0..w_mi {
15731715 let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
@@ -1580,6 +1722,9 @@ impl Neighbours {
15801722 if let Some(cell) = self.ref_grid.get_mut(idx) {
15811723 *cell = ref_frame;
15821724 }
1725+ if let Some(cell) = self.delta_lf_grid.get_mut(idx) {
1726+ *cell = snapshot;
1727+ }
15831728 }
15841729 }
15851730 }
@@ -2139,6 +2284,11 @@ fn read_intra_mode_rect(
21392284 }
21402285 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
21412286 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
2287+ // A HORZ/VERT rect strip is never the whole superblock (`bw`/`bh` never
2288+ // both 64 here -- see this fn's own doc), so `is_whole_sb` is always
2289+ // `false`.
2290+ maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip);
2291+ maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip);
21422292 let above_ctx = INTRA_MODE_CTX[above_mode];
21432293 let left_ctx = INTRA_MODE_CTX[left_mode];
21442294 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
@@ -2466,7 +2616,7 @@ fn decode_block_rect(
24662616 bw,
24672617 bh,
24682618 8,
2469- i32::from(base_q_idx),
2619+ CURRENT_Q_IDX.with(|c| c.get()),
24702620 luma_tx_type,
24712621 );
24722622 y.reconstruct_rect(
@@ -2505,7 +2655,7 @@ fn decode_block_rect(
25052655 chroma_w,
25062656 chroma_h,
25072657 8,
2508- i32::from(base_q_idx),
2658+ CURRENT_Q_IDX.with(|c| c.get()),
25092659 u_tx_type,
25102660 );
25112661 u.reconstruct_rect(
@@ -2543,7 +2693,7 @@ fn decode_block_rect(
25432693 chroma_w,
25442694 chroma_h,
25452695 8,
2546- i32::from(base_q_idx),
2696+ CURRENT_Q_IDX.with(|c| c.get()),
25472697 v_tx_type,
25482698 );
25492699 v.reconstruct_rect(
@@ -2612,6 +2762,8 @@ fn read_intra_mode(
26122762 // spec order (see the comment below on `read_intrabc_info`): `skip`,
26132763 // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here.
26142764 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
2765+ maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip);
2766+ maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip);
26152767 // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at
26162768 // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before
26172769 // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an
@@ -3161,7 +3313,7 @@ fn read_plane(
31613313 }
31623314 full
31633315 };
3164- let residual = dequant_and_inverse_typed(&levels, side, 8, i32::from(base_q_idx), tx_type);
3316+ let residual = dequant_and_inverse_typed(&levels, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type);
31653317 if std::env::var_os("EC_AV1_TRACE").is_some() {
31663318 eprintln!(
31673319 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
@@ -4198,7 +4350,7 @@ fn unit_log2(px: u32) -> i32 {
41984350 /// the flat `mode_deltas[1]` this used before was a `LAST_FRAME`-reachable
41994351 /// wrong delta on every `GLOBALMV` block, masked while any `GOLDEN_FRAME`
42004352 /// block anywhere aborted the whole stream's decode before comparison).
4201-fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, ref_frame: i8) -> i32 {
4353+fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, ref_frame: i8, delta_lf: i32) -> i32 {
42024354 let base = i32::from(if plane_idx == 0 {
42034355 lf.level[dir]
42044356 } else if plane_idx == 1 {
@@ -4206,6 +4358,10 @@ fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, ref_frame: i8)
42064358 } else {
42074359 lf.level[3]
42084360 });
4361+ // spec 7.14.4: the per-superblock `DeltaLF` term applies before the
4362+ // ref/mode delta scaling below, and regardless of `delta_enabled`
4363+ // (that flag only gates `ref_deltas`/`mode_deltas`).
4364+ let base = (base + delta_lf).clamp(0, 63);
42094365 if !lf.delta_enabled {
42104366 return base;
42114367 }
@@ -4257,9 +4413,12 @@ fn edge_params(
42574413 tx_h_px_at(n, chroma, pv_mi_r, pv_mi_c)
42584414 };
42594415 let pv_ref = n.ref_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c];
4416+ let delta_idx = if plane_idx == 0 { dir } else { plane_idx + 1 };
4417+ let cur_delta_lf = i32::from(n.delta_lf_grid[mi_r * n.skip_grid_cols_mi + mi_c][delta_idx]);
4418+ let pv_delta_lf = i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]);
42604419
4261- let cur_level = lf_level(lf, plane_idx, dir, cur_ref);
4262- let pv_level = lf_level(lf, plane_idx, dir, pv_ref);
4420+ let cur_level = lf_level(lf, plane_idx, dir, cur_ref, cur_delta_lf);
4421+ let pv_level = lf_level(lf, plane_idx, dir, pv_ref, pv_delta_lf);
42634422 if cur_level == 0 && pv_level == 0 {
42644423 return None;
42654424 }
@@ -4759,6 +4918,7 @@ pub fn decode_key_frame_tile(
47594918 allow_screen_content_tools: bool,
47604919 allow_intrabc: bool,
47614920 ) -> Result<Picture> {
4921+ let delta = DeltaParams::default();
47624922 let single_tile = TileInfo {
47634923 mi_col_starts: vec![0, mi_cols],
47644924 mi_row_starts: vec![0, mi_rows],
@@ -4781,6 +4941,7 @@ pub fn decode_key_frame_tile(
47814941 reduced_tx_set,
47824942 allow_screen_content_tools,
47834943 allow_intrabc,
4944+ delta,
47844945 )
47854946 .map(|(picture, _)| picture)
47864947 }
@@ -4810,6 +4971,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48104971 reduced_tx_set: bool,
48114972 allow_screen_content_tools: bool,
48124973 allow_intrabc: bool,
4974+ // lane-realworld r4: this frame header's own `delta` (spec 5.9.17/5.9.18)
4975+ // -- only `q_present`/`q_res` are actually read ([`maybe_read_delta_q`]);
4976+ // `stream.rs` still refuses a frame with `lf_present` set before this
4977+ // function is ever called.
4978+ delta: DeltaParams,
48134979 ) -> Result<(Picture, Cdfs)> {
48144980 if mi_cols == 0 || mi_rows == 0 {
48154981 return Err(unsupported("a frame with no mode-info grid"));
@@ -4819,6 +4985,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48194985 CDEF_BITS.with(|c| c.set(cdef.bits));
48204986 CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));
48214987 CDEF_IDX_GRID.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]);
4988+ DELTA_Q_PRESENT.with(|c| c.set(delta.q_present));
4989+ DELTA_Q_RES.with(|c| c.set(1i32 << delta.q_res));
4990+ DELTA_LF_PRESENT.with(|c| c.set(delta.lf_present));
4991+ DELTA_LF_RES.with(|c| c.set(1i32 << delta.lf_res));
4992+ DELTA_LF_MULTI.with(|c| c.set(delta.lf_multi));
48224993 let (cols32, rows32) = block_grid(mi_cols, mi_rows);
48234994 let (true_width, true_height) = ((mi_cols * 4) as usize, (mi_rows * 4) as usize);
48244995 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
@@ -4898,6 +5069,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48985069 let (sb_c0, sb_c1) = ((mi_col0 / SB_MI).min(sb_cols), mi_col1.div_ceil(SB_MI).min(sb_cols));
48995070
49005071 let mut cdfs = base_cdfs.clone();
5072+ // spec `decode_tile`: `CurrentQIndex` resets to the frame's own
5073+ // `base_q_idx` at the top of every tile, not once per frame.
5074+ CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));
5075+ CURRENT_DELTA_LF.with(|c| c.set([0; 4]));
49015076 if std::env::var_os("EC_AV1_TRACE").is_some() {
49025077 eprintln!(
49035078 "TRACE key_tile_bytes tile={tile_num} len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}",
@@ -5680,7 +5855,7 @@ fn read_inter_plane(
56805855 dc_sign_ctx(around.2),
56815856 default_tx_type,
56825857 )?;
5683- let residual = dequant_and_inverse_typed(&grid, side, 8, i32::from(base_q_idx), tx_type);
5858+ let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type);
56845859 plane.reconstruct_mc(x, y, side, prediction, &residual);
56855860 Ok((grid, tx_type))
56865861 }
@@ -6771,6 +6946,8 @@ fn decode_inter_block(
67716946 let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);
67726947 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
67736948 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);
6949+ maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip);
6950+ maybe_read_delta_lf(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip);
67746951 // lane-warp r5: see `reject_residual` -- a square-block decode of a
67756952 // HORZ_B strip is symbol-exact only for `skip` (no residual, no
67766953 // motion_mode/warp symbol), so gate here before any further read.
@@ -8541,6 +8718,9 @@ fn decode_inter_block8(
85418718 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
85428719 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
85438720 maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
8721+ // Always a `BLOCK_8X8` leaf here, never the whole superblock.
8722+ maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
8723+ maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
85448724
85458725 let (has_above, has_left) = (
85468726 leaf_mi.0 > neighbours.tile_row0_mi,
@@ -9527,6 +9707,7 @@ pub fn decode_inter_frame_tile(
95279707 false,
95289708 false,
95299709 false,
9710+ DeltaParams::default(),
95309711 )
95319712 .map(|(picture, _, _)| picture)
95329713 }
@@ -9597,6 +9778,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
95979778 // palette syntax libaom's `read_intra_block_mode_info` reads under the
95989779 // same `av1_allow_palette` gate as the key-frame path.
95999780 allow_screen_content_tools: bool,
9781+ // lane-realworld r5: this frame header's own `delta` (spec 5.9.17/5.9.18),
9782+ // same contract as [`decode_key_frame_tile_with_cdfs`]'s own `delta`
9783+ // param -- only `q_present`/`q_res` are read.
9784+ delta: DeltaParams,
96009785 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {
96019786 let tpl_frame = tpl_field.map(|field| TplFrameArgs {
96029787 field,
@@ -9745,6 +9930,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
97459930
97469931 let base_cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx)));
97479932 let mut result_cdfs = base_cdfs.clone();
9933+ // spec `decode_tile`: `CurrentQIndex`/`DeltaLF` reset to the frame's own
9934+ // `base_q_idx`/zero at the top of every tile, not once per frame (mirrors
9935+ // `decode_key_frame_tile_with_cdfs`'s per-tile reset below); the
9936+ // delta_q/delta_lf presence/resolution flags themselves are frame-level
9937+ // and set once here.
9938+ DELTA_Q_PRESENT.with(|c| c.set(delta.q_present));
9939+ DELTA_Q_RES.with(|c| c.set(1i32 << delta.q_res));
9940+ DELTA_LF_PRESENT.with(|c| c.set(delta.lf_present));
9941+ DELTA_LF_RES.with(|c| c.set(1i32 << delta.lf_res));
9942+ DELTA_LF_MULTI.with(|c| c.set(delta.lf_multi));
97489943 let mut neighbours = Neighbours::new(
97499944 cols as usize * 2,
97509945 rows as usize * 2,
@@ -9774,6 +9969,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
97749969 mi_col1.div_ceil(SB_MI).min(sb_cols),
97759970 );
97769971 let mut cdfs = base_cdfs.clone();
9972+ CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));
9973+ CURRENT_DELTA_LF.with(|c| c.set([0; 4]));
97779974 let mut dec = SymbolDecoder::new(data);
97789975 // lane-comppin r9: tile-entry range, the earliest point comparable
97799976 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
@@ -50,7 +50,6 @@ const REFUSALS: &[&str] = &[
5050 "a block that actually uses intrabc (this decoder never reconstructs one)",
5151 "a frame OBU with no tile group",
5252 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
53- "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)",
5453 "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)",
5554 "a frame with no mode-info grid",
5655 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",
crates/ec-av1/src/stream.rsmodified+211 -6
@@ -170,6 +170,11 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
170170 // intrabc call at all -- that symbol is intra-frame-only). A
171171 // genuine palette/intrabc use still refuses by name deeper in the
172172 // block readers, so no whole-frame refusal is needed here anymore.
173+ // lane-realworld r5: both delta_q (maybe_read_delta_q, CURRENT_Q_IDX)
174+ // and delta_lf (maybe_read_delta_lf, CURRENT_DELTA_LF ->
175+ // Neighbours::delta_lf_grid -> lf_level) are now read and applied;
176+ // no whole-frame refusal needed here anymore.
177+ //
173178 // Both AV1 files in this box's own library (a 2160p HDR10 encode and a
174179 // 1080p one, probed 2026-08-30 through `examples/decode_probe`) are
175180 // `yuv420p10le`, and every buffer this decoder reconstructs into --
@@ -189,12 +194,6 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
189194 "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)",
190195 ));
191196 }
192- if header.delta.q_present || header.delta.lf_present {
193- return Err(Error::unsupported(
194- "AV1 decode_stream",
195- "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)",
196- ));
197- }
198197 if header.segmentation.enabled {
199198 return Err(Error::unsupported(
200199 "AV1 decode_stream",
@@ -415,6 +414,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
415414 header.reduced_tx_set,
416415 header.allow_screen_content_tools,
417416 header.allow_intrabc,
417+ header.delta,
418418 )?;
419419 // A key frame codes no inter blocks -- its own saved motion
420420 // field has no cells set, matching libaom's own "intra frame
@@ -499,6 +499,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
499499 header.is_motion_mode_switchable,
500500 header.allow_warped_motion,
501501 header.allow_screen_content_tools,
502+ header.delta,
502503 )?
503504 };
504505 // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's
@@ -6187,6 +6188,7 @@ mod tests {
61876188 header.reduced_tx_set,
61886189 header.allow_screen_content_tools,
61896190 header.allow_intrabc,
6191+ header.delta,
61906192 ) {
61916193 Err(e) => {
61926194 let msg = e.to_string();
@@ -6392,6 +6394,7 @@ mod tests {
63926394 header.reduced_tx_set,
63936395 header.allow_screen_content_tools,
63946396 header.allow_intrabc,
6397+ header.delta,
63956398 ) {
63966399 Err(e) => {
63976400 let msg = e.to_string();
@@ -6705,6 +6708,7 @@ mod tests {
67056708 header.reduced_tx_set,
67066709 header.allow_screen_content_tools,
67076710 header.allow_intrabc,
6711+ header.delta,
67086712 ) {
67096713 Err(e) => {
67106714 let msg = e.to_string();
@@ -7042,6 +7046,207 @@ mod tests {
70427046 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
70437047 );
70447048 }
7049+ /// lane-realworld r6: r5 ported `maybe_read_delta_q`/`maybe_read_delta_lf`
7050+ /// and removed the whole-frame refusal, but no fixture anywhere set
7051+ /// `delta_lf_present` -- the removal was unproven. `--deltaq-mode=2`
7052+ /// (`DELTA_Q_PERCEPTUAL`, checked against libaom's own
7053+ /// `encodeframe.c:2192-2225`) sets `delta_q_present_flag` unconditionally
7054+ /// once `base_qindex > 0` (unlike the default `--deltaq-mode=1`
7055+ /// `DELTA_Q_OBJECTIVE`, which additionally requires an alt-ref-eligible
7056+ /// frame and `allow_deltaq_mode`'s own RD search); `--delta-lf-mode=1`
7057+ /// then ANDs `delta_lf_present_flag` on top
7058+ /// (`tool_cfg->enable_deltalf_mode`, `av1_cx_iface.c:1269-1270`). 128x64
7059+ /// (2 SBs; this decoder hardcodes 64px SBs) is the charter's minimum for
7060+ /// a per-superblock symbol to have somewhere to differ; `--cpu-used=4`
7061+ /// (not the other gates' `=0`) sidesteps the multi-SB
7062+ /// HORZ_4/VERT_B-at-part64 gap the cdef gate's own comment documents
7063+ /// (lane-realworld r2 dead-end, part64 only covers NONE/SPLIT). Note:
7064+ /// libaom hardcodes `delta_lf_multi = DEFAULT_DELTA_LF_MULTI == 0`
7065+ /// (`enums.h:73`) with no CLI flag to set it -- this gate cannot and
7066+ /// does not claim to exercise this decoder's `delta_lf_multi` branch;
7067+ /// only the single-plane path is gate-proven.
7068+ #[test]
7069+ fn a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact() {
7070+ const NAME: &str = "a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact";
7071+ let _gate_lock = lock_gate_counters();
7072+ if !have_ffmpeg() {
7073+ eprintln!("SKIP {NAME}: no ffmpeg");
7074+ return;
7075+ }
7076+ if !have_aomenc() {
7077+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
7078+ return;
7079+ }
7080+ let (width, height, frame_count) = (128usize, 64usize, 24usize);
7081+ let mut named_refusals = 0u32;
7082+ let mut matched = 0u32;
7083+ let n_attempts: u32 = std::env::var("EC_DELTAQ_GATE_ATTEMPTS")
7084+ .ok()
7085+ .and_then(|s| s.parse().ok())
7086+ .unwrap_or(40);
7087+ for attempt in 0..n_attempts {
7088+ let seed = 42 + attempt;
7089+ let duration = frame_count as f64 / 25.0;
7090+ // Mandelbrot's varying local contrast is what gives
7091+ // DELTA_Q_PERCEPTUAL's per-superblock RD something to
7092+ // differentiate; flat gradients risk every superblock
7093+ // resolving the same delta.
7094+ let source = format!(
7095+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
7096+ sx = -0.6 + 0.005 * (attempt as f64),
7097+ sy = -0.4 + 0.005 * (attempt as f64)
7098+ );
7099+ let y4m = Command::new("ffmpeg")
7100+ .args([
7101+ "-v",
7102+ "error",
7103+ "-f",
7104+ "lavfi",
7105+ "-i",
7106+ &source,
7107+ "-t",
7108+ &duration.to_string(),
7109+ "-pix_fmt",
7110+ "yuv420p",
7111+ "-f",
7112+ "yuv4mpegpipe",
7113+ "-",
7114+ ])
7115+ .stdin(Stdio::null())
7116+ .stdout(Stdio::piped())
7117+ .stderr(Stdio::piped())
7118+ .output()
7119+ .expect("ffmpeg failed to run");
7120+ assert!(
7121+ y4m.status.success(),
7122+ "ffmpeg fixture: {}",
7123+ String::from_utf8_lossy(&y4m.stderr)
7124+ );
7125+ let args: Vec<&str> = vec![
7126+ "--codec=av1",
7127+ "--passes=1",
7128+ "--end-usage=q",
7129+ "--cq-level=45",
7130+ "--cpu-used=4",
7131+ "--aq-mode=0",
7132+ "--deltaq-mode=2",
7133+ "--delta-lf-mode=1",
7134+ "--kf-max-dist=1000",
7135+ "--threads=1",
7136+ "--row-mt=0",
7137+ "--sb-size=64",
7138+ "--auto-alt-ref=1",
7139+ "--lag-in-frames=16",
7140+ "--enable-fwd-kf=0",
7141+ "--enable-order-hint=1",
7142+ "--enable-warped-motion=1",
7143+ "--enable-global-motion=0",
7144+ "--enable-obmc=1",
7145+ "--tune-content=default",
7146+ "--enable-masked-comp=1",
7147+ "--enable-dist-wtd-comp=0",
7148+ "--enable-interintra-comp=1",
7149+ "--enable-onesided-comp=0",
7150+ "--enable-interintra-wedge=0",
7151+ "--enable-smooth-interintra=1",
7152+ "--enable-rect-partitions=0",
7153+ "--enable-ab-partitions=0",
7154+ "--enable-1to4-partitions=0",
7155+ "--enable-filter-intra=0",
7156+ "--enable-smooth-intra=0",
7157+ "--enable-paeth-intra=0",
7158+ "--enable-directional-intra=0",
7159+ "--enable-angle-delta=0",
7160+ "--enable-tx-size-search=0",
7161+ "--enable-cdef=1",
7162+ "--enable-restoration=0",
7163+ "--max-partition-size=32",
7164+ "--min-partition-size=32",
7165+ "--enable-palette=0",
7166+ "--enable-intrabc=0",
7167+ "--enable-cfl-intra=0",
7168+ "--enable-ref-frame-mvs=0",
7169+ "--obu",
7170+ "-o",
7171+ "-",
7172+ "-",
7173+ ];
7174+ let mut child = Command::new(aomenc_path())
7175+ .args(&args)
7176+ .stdin(Stdio::piped())
7177+ .stdout(Stdio::piped())
7178+ .stderr(Stdio::piped())
7179+ .spawn()
7180+ .expect("aomenc failed to start");
7181+ child
7182+ .stdin
7183+ .take()
7184+ .expect("aomenc stdin")
7185+ .write_all(&y4m.stdout)
7186+ .expect("writing y4m to aomenc");
7187+ let out = child.wait_with_output().expect("aomenc failed to run");
7188+ assert!(
7189+ out.status.success(),
7190+ "aomenc refused the fixture: {}",
7191+ String::from_utf8_lossy(&out.stderr)
7192+ );
7193+ let stream = out.stdout;
7194+ let frames = match decode_stream(&stream) {
7195+ Err(e) => {
7196+ let msg = e.to_string();
7197+ assert!(
7198+ msg.contains("unsupported"),
7199+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
7200+ );
7201+ assert!(
7202+ !msg.contains("delta_q") && !msg.contains("delta_lf"),
7203+ "{NAME} refused on delta_q/delta_lf (seed {seed}) -- that read is ported: {msg}"
7204+ );
7205+ named_refusals += 1;
7206+ eprintln!("seed {seed} refusal: {msg}");
7207+ continue;
7208+ }
7209+ Ok(frames) => frames,
7210+ };
7211+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
7212+ assert_eq!(frames.len(), frame_count);
7213+ let mismatched = frames
7214+ .iter()
7215+ .zip(&ffmpeg_frames)
7216+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
7217+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
7218+ std::fs::write(&path, &stream).expect("writing pinned stream");
7219+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
7220+ }
7221+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
7222+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
7223+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
7224+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
7225+ }
7226+ matched += 1;
7227+ }
7228+ assert!(
7229+ matched > 0,
7230+ "{NAME}: every attempt refused on other capabilities ({named_refusals} refusals); \
7231+ the gate never exercised delta_q/delta_lf"
7232+ );
7233+ assert!(
7234+ crate::decode::delta_q_hits() > 0,
7235+ "{NAME}: {matched} pixel-exact matches but zero delta_q symbol groups fired -- \
7236+ the reader is unexercised"
7237+ );
7238+ assert!(
7239+ crate::decode::delta_lf_hits() > 0,
7240+ "{NAME}: {matched} pixel-exact matches but zero delta_lf symbol groups fired -- \
7241+ the reader is unexercised"
7242+ );
7243+ eprintln!(
7244+ "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
7245+ out of {n_attempts}, delta_q_hits={}, delta_lf_hits={}",
7246+ crate::decode::delta_q_hits(),
7247+ crate::decode::delta_lf_hits()
7248+ );
7249+ }
70457250
70467251 /// lane-tiles r7: the gate stage 2 (r6, commit 8899fc1) shipped without
70477252 /// -- a real >1-tile-column stream with a genuine INTER frame (not just
lanes/realworld-r4.charter.mdadded+52 -0
@@ -0,0 +1,52 @@
1+# lane-realworld r4 — delta_q / delta_lf
2+
3+At the lane tip (main merged in). Read `lanes/realworld-r3.report.md` — it is a
4+typing plan, verified against the real libaom source. Do NOT re-derive it
5+(class `worker-cap-spent-reading`). Job 1 (the part64 silent desync) is CLOSED
6+and merged to main.
7+
8+## What r3 verified for you
9+- Default CDFs, from `~/.cache/aom-oracle/src/av1/common/entropymode.c:840-852`:
10+ `DELTA_Q`, `DELTA_LF` and `DELTA_LF_MULTI[4]` are all
11+ `[28160, 32120, 32677, 32768, 0]`. `FRAME_LF_COUNT = 4`,
12+ `MAX_LOOP_FILTER = 63`, `DELTA_Q_SMALL = DELTA_LF_SMALL = 3`.
13+- The read gate collapses to a per-superblock `Cell<bool>` exactly like
14+ `CDEF_TRANSMITTED` (decode.rs:82) — libaom's `b_row == 0 && b_col == 0` check
15+ is always true for a partition tree's first-decoded leaf.
16+- Only FOUR call sites need the new read, the same four `maybe_read_cdef_idx`
17+ already uses: `read_intra_mode_rect`, `read_intra_mode`, `decode_inter_block`,
18+ `decode_inter_block8` (line numbers have shifted since r3 — find them by the
19+ `maybe_read_cdef_idx` calls).
20+- `base_q_idx: u8` is passed through ~90 sites but READ at only 2, both
21+ `dequant_and_inverse_typed` calls. A `CURRENT_Q_IDX` thread-local reset per
22+ tile and read at those 2 sites reproduces AV1's running quantizer without
23+ threading a parameter through every signature.
24+- Open design question, the one genuinely new piece: `DeltaLF` reaching the
25+ deblocker (`lf_level` / `edge_params`) has no per-block carrier —
26+ `MiGrid` / `fill_lf_grid` needs a new field. Do the quantizer half first and
27+ commit it; the loop-filter half can refuse by name in between.
28+
29+## CDF wiring is four sites
30+Struct field, defaults array, save/restore, per-frame counter reset. In this
31+codebase `reset2`/`reset3` are length-generic and save/restore is a whole-struct
32+Clone, so the defaults array is what needs hand-checking — but VERIFY the
33+counter reset covers the new tables (class `cdf-counter-not-reset`: a missing
34+reset gives right values at the wrong adaptation rate).
35+
36+## Then the gate
37+Remove the stream.rs refusal ("a frame with delta_q_present or delta_lf_present
38+set"), and gate it: `EC_AV1_REQUIRE_AOMENC=1`, `-t <seconds>` on the ffmpeg
39+generate, fixture through `gradients_source`, aomenc `--threads=1 --row-mt=0
40+--sb-size=64` (this decoder hardcodes 64px superblocks) plus whatever turns
41+delta_q on (`--deltaq-mode=`, and `--aq-mode`); the fixture needs MORE THAN ONE
42+SUPERBLOCK or a per-superblock symbol can never fire. HARD-assert a thread-local
43+firing count.
44+
45+Merge note: main is at 53b319b with `gate_coverage.rs` and
46+`refusal_inventory.rs`. Report every refusal string you add or remove, verbatim.
47+
48+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld`; foreground
49+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling
50+worktrees have live agents — never build in or edit them. Never push, never
51+merge, never touch `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN
52+STEP. End with `lanes/realworld-r4.report.md`, VERDICT on line 1.
lanes/realworld-r5.charter.mdadded+37 -0
@@ -0,0 +1,37 @@
1+# lane-realworld r5 — finish delta_q / delta_lf
2+
3+At dbfd67c — r4's work (cdf.rs, cdf_state.rs, decode.rs), committed verbatim by
4+the orchestrator at its cap and **never seen to compile**.
5+`lanes/realworld-r4.charter.md` is still binding; `lanes/realworld-r3.report.md`
6+is the verified typing plan. Do not re-derive either.
7+
8+1. `cargo check`, fix whatever r4 left mid-edit, then the full suite. Getting
9+ dbfd67c green is the whole job until it is green. COMMIT.
10+2. Finish the quantizer half: the `CURRENT_Q_IDX` thread-local reset per tile
11+ and read at the 2 real dequant sites (r3 proved `base_q_idx` is passed
12+ through ~90 sites but read at only 2). Refuse the loop-filter half by name in
13+ between if it is not ready. COMMIT.
14+3. The `DeltaLF` -> deblocker path: `MiGrid` / `fill_lf_grid` needs a new
15+ per-block field. This is the one genuinely new design piece. COMMIT.
16+4. Remove the stream.rs refusal and gate it: `EC_AV1_REQUIRE_AOMENC=1`,
17+ `-t <seconds>` on the ffmpeg generate, fixture through `gradients_source`,
18+ aomenc `--threads=1 --row-mt=0 --sb-size=64` plus `--deltaq-mode=`/`--aq-mode`,
19+ MORE THAN ONE SUPERBLOCK (a per-superblock symbol cannot fire otherwise), and
20+ a HARD-asserted thread-local firing count.
21+
22+Reminders that cost other lanes a round: the CDF counter reset must cover the
23+new tables (class `cdf-counter-not-reset`); do not put a refusal in front of the
24+code you just added and then claim it runs (class
25+`refusal-short-circuits-its-own-code`) — prove the new read fires with a counter
26+while the frame still refuses; and main now FAILS the suite if a gate turns a
27+decode error into a printed SKIP, so write the gate as an attempt loop that
28+requires at least one decode.
29+
30+Merge note: main is at 91a08e8 with `gate_coverage.rs` and
31+`refusal_inventory.rs`. Report every refusal string you add or remove, verbatim.
32+
33+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld`; foreground
34+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling
35+worktrees have live agents — never build in or edit them. Never push, never
36+merge, never touch `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN
37+STEP. End with `lanes/realworld-r5.report.md`, VERDICT on line 1.
lanes/realworld-r5.report.mdadded+103 -0
@@ -0,0 +1,103 @@
1+# lane-realworld r5 report
2+
3+VERDICT: Job 1 (get dbfd67c green) DONE, committed (70372d1, c185755).
4+Job 2 (delta_q/delta_lf) both halves now read and applied, committed
5+(70372d1 for delta_q's compile-completion, a830d87 for delta_lf's new
6+deblocker path). Job 2's gate (charter step 4, a real aomenc stream with
7+`--deltaq-mode=`/`--aq-mode` proving live firing) is UNSTARTED -- next
8+lever, see below.
9+
10+## Job 1 -- dbfd67c green (70372d1, c185755)
11+r4 had wired `delta: DeltaParams` all the way through
12+`decode_key_frame_tile_with_cdfs` (including its 2 stream.rs call sites,
13+its own tile-loop `DELTA_Q_PRESENT`/`DELTA_Q_RES`/`CURRENT_Q_IDX` reset)
14+but never touched `decode_inter_frame_tile_with_cdfs`'s own signature --
15+its one public wrapper (`decode_inter_frame_tile`) was already passing
16+`DeltaParams::default()` as an extra, unaccepted argument. Added the
17+`delta: DeltaParams` param to `decode_inter_frame_tile_with_cdfs`, the
18+matching `DELTA_Q_PRESENT`/`DELTA_Q_RES`/`CURRENT_Q_IDX` reset at its own
19+single-tile entry point (mirroring the key-frame per-tile reset), and
20+`header.delta` at stream.rs's inter-frame call site plus its test-only
21+key-frame call site (stream.rs:6179, a `#[cfg(test)]` path r4 missed).
22+Narrowed the whole-frame refusal from `q_present || lf_present` to
23+`lf_present` alone (delta_q was already genuinely read on both frame
24+types once this compiled), and updated `refusal_inventory.rs`'s
25+`REFUSALS` list to the narrowed string. `EC_AV1_REQUIRE_AOMENC=1 cargo
26+test -p ec-av1 --lib -j4`: **242 passed, 0 failed, 17 ignored** (r3's
27+234/0/17 plus lane-tiles/lane-realworld merges already on `main` before
28+this worktree branched).
29+
30+## Job 2 -- delta_lf's new deblocker path (a830d87)
31+Exactly the piece r3 flagged as needing a real design pass, not a narrow
32+substitution:
33+
34+- `CURRENT_DELTA_LF: Cell<[i32; 4]>` (spec `DeltaLF[FRAME_LF_COUNT]`),
35+ reset to `[0; 4]` at the top of every tile in both
36+ `decode_key_frame_tile_with_cdfs` and `decode_inter_frame_tile_with_cdfs`
37+ (mirroring `CURRENT_Q_IDX`'s own per-tile reset), plus
38+ `DELTA_LF_PRESENT`/`DELTA_LF_RES`/`DELTA_LF_MULTI` set from
39+ `header.delta` the same way `DELTA_Q_PRESENT`/`DELTA_Q_RES` already were.
40+- `maybe_read_delta_lf` (decode.rs, next to `maybe_read_delta_q`): same
41+ 4-symbol-CDF-then-Golomb-tail-then-sign shape, called right after
42+ `maybe_read_delta_q` at all 4 existing block-decode call sites (spec
43+ order `delta_q -> delta_lf`). Loops over 4 planes/directions when
44+ `delta_lf_multi` (reading `cdfs.delta_lf_multi[i]`, r4's already-wired
45+ CDF), or reads once into index 0 against `cdfs.delta_lf` otherwise.
46+ `DELTA_LF_HITS`/`delta_lf_hits()` mirror `DELTA_Q_HITS` for a future
47+ gate's firing count.
48+- New `Neighbours::delta_lf_grid: Vec<[i8; 4]>` field, snapshotted per
49+ 4x4-mi block in `fill_lf_grid_rect` (the one function every existing
50+ `fill_lf_grid`/`fill_lf_grid_rect` call site already routes through, so
51+ no call-site changes needed) -- `!delta_lf_multi` mode broadcasts
52+ `DeltaLF[0]` into all 4 slots at write time, so `lf_level`'s reader
53+ never needs to know which mode produced the value, matching
54+ `ref_grid`'s existing snapshot pattern exactly.
55+- `lf_level` takes a new `delta_lf: i32` param, applied to the base level
56+ (`clamp(0, 63)`) *before* the existing `ref_deltas`/`mode_deltas`
57+ scaling and regardless of `lf.delta_enabled` (spec 7.14.4: that flag
58+ only gates the ref/mode terms, not `DeltaLF`). `edge_params` looks up
59+ `delta_lf_grid` at both the current and previous mi position via a new
60+ `plane_idx/dir -> FRAME_LF_COUNT` index map (`0`/`1` for Y
61+ vertical/horizontal, `2`/`3` for U/V), the same two-position lookup
62+ pattern it already uses for `ref_grid`.
63+- Removed the stream.rs `delta_lf_present` refusal entirely (both halves
64+ of Job 2 are now read and applied). `refusal_inventory.rs`'s `REFUSALS`
65+ list: removed `"a frame with delta_lf_present set (this decoder never
66+ applies per-superblock loop-filter deltas)"`, no replacement string.
67+
68+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4`: **242 passed, 0
69+failed, 17 ignored** -- unchanged from Job 1's number, because no
70+existing fixture sets `delta_lf_present`. This means the new deblocker
71+path is **code-verified against the spec/libaom read shape**, not yet
72+gate-proven against a real aomenc stream that actually exercises it.
73+
74+## Refusal strings changed this lane (verbatim)
75+- Removed: `"a frame with delta_q_present or delta_lf_present set (this
76+ decoder never reads the per-superblock delta symbols)"`.
77+- Added then removed within this same lane (never landed on `main`):
78+ `"a frame with delta_lf_present set (this decoder never applies
79+ per-superblock loop-filter deltas)"` -- present after commit 70372d1,
80+ removed by commit a830d87. Net effect for merge purposes: the old
81+ combined refusal is gone, no new refusal string replaces it.
82+
83+## Next lever -- charter step 4, the gate
84+Not started this round (turn budget spent on Jobs 1-2's design/wiring).
85+Needed: a real aomenc stream with `--deltaq-mode=1` or `--aq-mode=1`
86+(reliably sets `delta_q_present`) plus a recipe that also sets
87+`delta_lf_present`/`delta_lf_multi` (aomenc's `--deltaq-mode` alone may
88+not set `lf_present` -- needs checking against aomenc's own CLI, not
89+assumed), gradients source through `gradients_source`, `--threads=1
90+--row-mt=0 --sb-size=64`, MORE THAN ONE SUPERBLOCK (128x64+), and a
91+hard-asserted `delta_q_hits()`/`delta_lf_hits()` firing count in an
92+attempt loop (never a printed SKIP on decode error, per the charter's
93+class reminder). `DELTA_Q_HITS`/`DELTA_LF_HITS`/`delta_q_hits()`/
94+`delta_lf_hits()` are already in place from this round's work, ready for
95+that gate to call.
96+
97+## Merge note
98+`gate_coverage.rs`/`refusal_inventory.rs` guards this worktree doesn't
99+carry: `refusal_inventory.rs`'s own `REFUSALS` list was already updated
100+in this worktree (main-tracked file), so the merge just needs the diff
101+as-is -- no separate main-only edit required for the refusal list itself.
102+`gate_coverage.rs` (main-only) will need the eventual gate test's name
103+added when Job 2's gate lands.
lanes/realworld-r6.charter.mdadded+55 -0
@@ -0,0 +1,55 @@
1+# lane-realworld r6 — gate what r5 removed
2+
3+At 15fe79a. Read `lanes/realworld-r5.report.md`.
4+
5+## Where you stand
6+r5 finished both halves: `maybe_read_delta_q` / `maybe_read_delta_lf`, the
7+`CURRENT_Q_IDX` / `CURRENT_DELTA_LF` thread-locals, `Neighbours::delta_lf_grid`
8+written by `fill_lf_grid_rect`, and `lf_level` / `edge_params` applying the
9+per-block delta before ref/mode scaling (spec 7.14.4). Four green commits, suite
10+242/0 twice. Good round.
11+
12+**It also removed the whole-frame refusal, and no fixture anywhere sets
13+`delta_lf_present`.** So the capability is code-verified against the spec's
14+shape and nothing more — the `DELTA_Q_HITS` / `DELTA_LF_HITS` counters exist but
15+have never been observed above zero. Until that gate exists, the removal is an
16+unproven claim and this branch does not merge to main. Writing it is job one;
17+nothing else in this lane matters until it is done.
18+
19+If the gate cannot be made to fire, restore a narrow refusal for the half that
20+is unproven, in the same commit. That is the honest outcome, not a failure.
21+
22+## Job 1 — the gate
23+Real aomenc stream, `--deltaq-mode=1` and/or `--aq-mode=1`, 128x64 or larger,
24+`--threads=1 --row-mt=0 --sb-size=64` (this decoder hardcodes 64px
25+superblocks), fixture through `gradients_source`, ffmpeg generate bounded with
26+`-t <seconds>`, written as an attempt loop that requires at least one decode
27+(main FAILS the suite if a gate turns a decode error into a printed SKIP).
28+Hard-assert `delta_q_hits() > 0` AND `delta_lf_hits() > 0`.
29+
30+r5's own warning, worth taking seriously: verify against real aomenc output that
31+its CLI flags actually set `delta_lf_present` / `delta_lf_multi` — `--deltaq-mode`
32+may only ever set `delta_q_present`. If the encoder will not produce delta_lf at
33+all, say so with the command you ran, and refuse that half by name rather than
34+shipping it unproven. A per-superblock symbol also cannot fire in a
35+single-superblock fixture; size the frame accordingly.
36+
37+## Then
38+Nothing else is assigned to this lane. If turns remain after the gate is green,
39+take `--enable-intrabc` — the last entry besides palette on main's
40+`gate_coverage.rs` `NEVER_EXERCISED` list — or say in the report that the lane
41+is clear.
42+
43+## Merge note
44+Main is at eebbdd1 and now refuses `bit_depth != 8` by name: both AV1 films in
45+this box's library are 10-bit and reached your delta_q refusal, which is what
46+surfaced that `Picture`'s planes are `Vec<u8>`. Your branch removes the delta
47+refusal from `refusal_inventory.rs`; main has since added the bit-depth one and
48+reworded three partition refusals. Report every refusal string you add, remove
49+or reword, verbatim.
50+
51+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld`; foreground
52+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling
53+worktrees have live agents — never build in or edit them. Never push, never
54+merge into `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP.
55+End with `lanes/realworld-r6.report.md`, VERDICT on line 1.
lanes/realworld-r6.report.mdadded+108 -0
@@ -0,0 +1,108 @@
1+# lane-realworld r6 report
2+
3+VERDICT: Job 1 (gate delta_q/delta_lf before merge) DONE, committed
4+(6981ef5). Both halves are now gate-proven against a real aomenc stream,
5+not just code-verified against the spec's shape. "Then" item
6+(`--enable-intrabc`) declined this round -- see below, lane says clear.
7+
8+## Job 1 -- the gate (6981ef5)
9+
10+r5 warned its own removal of the whole-frame `delta_q_present ||
11+delta_lf_present` refusal was unproven: no fixture anywhere set
12+`delta_lf_present`. Verified against libaom source before writing any
13+encoder flags, per the charter's own instruction not to assume:
14+
15+- `--deltaq-mode` help text says "requires --enable-tpl-model=1" but
16+ `enable_tpl_model` defaults to `1` (`av1_cx_iface.c:234`), so nothing
17+ extra was needed there.
18+- The **default** `--deltaq-mode=1` (`DELTA_Q_OBJECTIVE`) additionally
19+ gates `delta_q_present_flag` on `gf_group->update_type == LF_UPDATE`
20+ and `allow_deltaq_mode(cpi)`'s own RD search returning a negative
21+ cost sum across every superblock (`encodeframe.c:2192-2211`) -- an
22+ extra, content-dependent condition worth avoiding for a gate that
23+ needs to fire reliably.
24+- `--deltaq-mode=2` (`DELTA_Q_PERCEPTUAL`) skips that branch entirely:
25+ `delta_q_present_flag = deltaq_mode != NO_DELTA_Q`, gated only by
26+ `base_qindex > 0` (guaranteed by `--cq-level=45`, nonzero). Used this
27+ instead of the charter's suggested `--deltaq-mode=1`/`--aq-mode=1`.
28+- `--delta-lf-mode=1` sets `extra_cfg->deltalf_mode`, which
29+ `tool_cfg->enable_deltalf_mode = (deltaq_mode != NO_DELTA_Q) &&
30+ extra_cfg->deltalf_mode` (`av1_cx_iface.c:1269-1270`) ANDs onto
31+ `delta_lf_present_flag = delta_q_present_flag &&
32+ enable_deltalf_mode` (`encodeframe.c:2217-2218`). This flag is real
33+ and does exactly what the charter asked to confirm: r5's worry that
34+ `--deltaq-mode` alone might never set `delta_lf_present` was correct
35+ -- `--delta-lf-mode=1` is the separate flag needed.
36+- 128x64 (2 superblocks; this decoder hardcodes 64px SBs) is the
37+ charter's own minimum for a per-superblock symbol to have anywhere to
38+ differ.
39+- `--cpu-used=4` (not `=0`, which every other multi-SB gate here avoids
40+ per the cdef gate's own documented dead-end: aomenc's RD at
41+ `--cpu-used=0` picks HORZ_4/VERT_B at part64 regardless of the
42+ rect/ab/1to4-partition flags, and this decoder's intra part64 match
43+ only covers NONE/SPLIT). Reused the cdef gate's exact working
44+ toolset otherwise (same `--enable-*` flags, same mandelbrot-source
45+ seed sweep for RD diversity).
46+
47+New test `a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact`
48+(`crates/ec-av1/src/stream.rs`, appended at EOF): 40/40 attempts
49+pixel-exact vs `ffmpeg`, `delta_q_hits()=1920`, `delta_lf_hits()=1920` at
50+the end of the run, both hard-asserted `> 0` (not soft-skipped --
51+r5's `--deltaq-mode`/`--delta-lf-mode` combination fires reliably on
52+every attempt, unlike the wedge-interintra gate's occasional zero-hit
53+run). Also asserts any `"unsupported"` refusal does not name
54+`delta_q`/`delta_lf` -- that capability is ported, a refusal naming it
55+would be a regression.
56+
57+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4`: **243 passed,
58+0 failed, 17 ignored** (r5's 242 plus this one new gate).
59+
60+### One documented gap, not gate-provable
61+
62+libaom hardcodes `delta_q_info.delta_lf_multi = DEFAULT_DELTA_LF_MULTI`
63+(`enums.h:73`, value `0`) in the encoder's own frame-setup path with **no
64+CLI flag that ever sets it to 1** (confirmed by grepping every
65+`delta_lf_multi =` assignment in `av1/encoder/`: only the one hardcoded
66+default). This gate therefore proves the single-plane
67+`!delta_lf_multi` branch of `maybe_read_delta_lf` (the branch every real
68+aomenc stream can ever produce) but cannot and does not claim to
69+exercise the 4-plane `delta_lf_multi` loop -- that path stays
70+code-verified against the spec's read shape only, same disposition r5
71+left the whole feature in, now narrowed to just this one sub-branch.
72+Not a refusal (the code correctly handles `delta_lf_multi=false`, which
73+is the only value a real encoder ever writes), just a residual
74+proof-gap worth naming per the charter's own standard.
75+
76+## Refusal strings changed this lane
77+
78+None. The whole-frame refusal was already removed by r5; this round
79+added a gate, not a code change to `decode.rs` or
80+`refusal_inventory.rs`.
81+
82+## "Then" -- `--enable-intrabc`
83+
84+Declined this round; lane says clear. `decode.rs:2767-2786` already
85+documents why in its own comment (lane-screen scope): actual intra
86+block copy needs `assign_dv`'s DV-prediction machinery this decoder
87+does not carry (`av1_find_mv_refs`/`av1_find_ref_dv` equivalents --
88+DV-specific validity checks against tile/frame boundaries, a DV
89+predictor stack distinct from the existing NEWMV mv-stack, then
90+integer-pel same-frame block-copy prediction with decoded-region
91+bounds checks). Every comparable feature already landed in this repo
92+(warp, OBMC, interintra, masked compound, wedge) took multiple
93+dedicated lane-rounds each per the ledger; attempting a full IntraBC
94+landing in whatever budget remained after Job 1 risked either a
95+shallow/wrong port (a new desync class, per this repo's own extensive
96+history of exactly that) or leaving genuinely unfinished work
97+uncommitted at the turn cap. Job 1 was the charter's stated priority
98+("nothing else in this lane matters until it is done"); IntraBC is
99+sized for its own dedicated lane, not a "then, if turns remain" addendum.
100+
101+## Merge note
102+
103+No refusal strings added/removed/reworded. `gate_coverage.rs`'s
104+`NEVER_EXERCISED` derivation only tracks `--enable-*` flags (verified by
105+reading its parser); `--deltaq-mode=`/`--delta-lf-mode=` are not
106+`--enable-*` flags so this new gate needs no entry there, and
107+`gate_coverage.rs` itself is unmodified. `crates/ec-av1/src/stream.rs`
108+is the only file touched this round.
lanes/realworld-r7.charter.mdadded+49 -0
@@ -0,0 +1,49 @@
1+# lane-realworld r7 — merge main, then start high bit depth
2+
3+At 48562d6. Read `lanes/realworld-r6.report.md`.
4+
5+## Job 1 — merge `main` into this branch and resolve it yourself
6+`git merge main` from this worktree. Main is at 92d8beb and has landed a lot
7+since this branch forked: multi-tile decode (gated), CDEF index reads, chroma
8+smooth/paeth/directional, a `bit_depth != 8` refusal, three reworded partition
9+refusals, dead-binding cleanup in `decode_stream`, and three guard tests. The
10+merge conflicts in nine places — eight in `stream.rs` (mostly gate bodies) and
11+one in `decode.rs`'s inter tile function, where main's per-tile loop meets your
12+`DeltaParams` threading. **You** resolve it: a wrong resolution there is a
13+silent decode bug, and you know which side owns each hunk. Suite green, then
14+COMMIT. Your delta_q/delta_lf work is finished and gated (40/40 pixel-exact,
15+`delta_q_hits`/`delta_lf_hits` = 1920 each), so this is the last thing standing
16+between it and main.
17+
18+Keep, while resolving: main's `refusal_inventory.rs` entry
19+`"a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)"`,
20+and the reworded partition refusals — do not reintroduce any string claiming an
21+encoder never writes a case.
22+
23+## Job 2, if turns remain — high bit depth
24+This is the critical path to the user's own files. Both AV1 files in this box's
25+library (`~/Downloads/reelb.mkv` and
26+`~/Videos/Films/reelc.mkv`) are `yuv420p10le`, and both now stop on
27+that bit-depth refusal. `Picture`'s `y`/`u`/`v` are `Vec<u8>`; nothing in
28+`decode.rs` reads `bit_depth` at all, though `transform.rs` already takes and
29+uses it (`row_clamp = bit_depth + 8`, `col_clamp = max(bit_depth + 6, 16)`).
30+
31+Scope for this round is the SHAPE, not the whole feature: work out what widening
32+the planes costs — `Picture` and `PlaneBuf` sample type, the prediction and
33+filter paths that assume `u8`, and what `ffmpeg_decode_sequence` must do to
34+produce a 10-bit reference for a gate. Write it down as a typing plan the way
35+`lanes/realworld-r3.report.md` did for delta_q; that report is why r5 could
36+implement both halves in one round. Land nothing half-wired.
37+
38+The two films are the eventual gate: probe them with
39+`cargo run -p ec-av1 --example decode_probe -- <stream.obu>`, extracting with
40+`ffmpeg -i <file> -t 3 -c:v copy -f obu` (note `-f obu` — an IVF decodes as zero
41+frames rather than as an error). Expect a new refusal to appear behind the
42+bit-depth one; that is progress, and its name is the next lane's charter.
43+
44+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld`; foreground
45+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling
46+worktrees have live agents — never build in or edit them. Never push, never
47+merge into `main` (merging main INTO this branch is job 1 and is fine). 75-turn
48+cap, does not reset: COMMIT AT EVERY GREEN STEP. End with
49+`lanes/realworld-r7.report.md`, VERDICT on line 1.
lanes/realworld-r7.report.mdadded+189 -0
@@ -0,0 +1,189 @@
1+# lane-realworld r7 report
2+
3+VERDICT: Job 1 (merge main into lane-realworld) DONE, gated green, committed
4+(f2e516f). Job 2 (high-bit-depth typing plan) DONE as scope-only, written
5+below; no code changed for it, nothing half-wired.
6+
7+## Job 1 -- merge (f2e516f)
8+
9+`git merge main` (main at 92d8beb) hit the nine conflicts the charter named:
10+eight hunks in `crates/ec-av1/src/stream.rs`, one in
11+`decode_inter_frame_tile_with_cdfs` in `crates/ec-av1/src/decode.rs`.
12+
13+- `stream.rs` line ~173-204: kept HEAD's comment (delta_q/delta_lf already
14+ read/applied, r5) plus main's new bit-depth refusal (`"a stream whose bit
15+ depth is not 8..."`, kept verbatim per the charter); dropped main's
16+ now-stale `"a frame with delta_q_present or delta_lf_present set..."`
17+ refusal since that capability is this branch's own finished work.
18+- `stream.rs` lines ~6545-6893: these seven remaining conflict markers were
19+ git's line-based diff conflating two *different* new test functions HEAD
20+ and main each appended at the same spot (HEAD's
21+ `a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact`, main's
22+ `a_real_aomenc_stream_with_two_tile_columns_and_an_inter_frame_decodes_pixel_exact`)
23+ -- not a real overlap. Resolved by pulling each side's complete function
24+ from `git show HEAD:.../stream.rs` / `git show main:.../stream.rs` and
25+ placing both, intact and un-interleaved, one after the other.
26+- `decode.rs` (`decode_inter_frame_tile_with_cdfs`): main reworked the
27+ function from a single tile-wide decoder into the same per-tile loop
28+ `decode_key_frame_tile_with_cdfs` already had (fresh `cdfs`/`dec` per
29+ tile, `base_cdfs`/`result_cdfs` split). HEAD's delta_q/delta_lf state
30+ setup (`DELTA_Q_PRESENT`/`DELTA_Q_RES`/`DELTA_LF_PRESENT`/`DELTA_LF_RES`/
31+ `DELTA_LF_MULTI`, all frame-level and `q_present`/`res` etc from
32+ `DeltaParams`) now lives once before the loop, same as the intra tile
33+ function; `CURRENT_Q_IDX`/`CURRENT_DELTA_LF` (both genuinely per-tile,
34+ spec `decode_tile` resets `CurrentQIndex` at the top of every tile) moved
35+ inside the loop, mirroring `decode_key_frame_tile_with_cdfs`'s own
36+ `CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)))` /
37+ `CURRENT_DELTA_LF.with(|c| c.set([0; 4]))` pair placed right where that
38+ function creates its own per-tile `cdfs`/`dec`.
39+- One knock-on compile error the merge exposed, not a conflict: main's
40+ `a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact` test
41+ (auto-merged cleanly, no conflict marker) calls
42+ `decode_key_frame_tile_with_cdfs` directly and was missing the trailing
43+ `delta: DeltaParams` argument this branch's signature already carries
44+ (r4). Added `header.delta` (the struct is `Copy`, same pattern every
45+ other call site in the file already uses) to fix the E0061.
46+
47+`export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld && EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4`:
48+**246 passed, 0 failed, 17 ignored** (was 243 pre-merge on this branch, 239
49+pre-merge on main; the merge is additive, no regressions).
50+
51+No refusal strings added/removed/reworded beyond what main already carried
52+in (the bit-depth refusal, kept verbatim; the three reworded partition
53+refusals, untouched by this merge).
54+
55+## Job 2 -- high bit depth: typing plan, not implemented
56+
57+Both real files in this box's library
58+(`~/Downloads/reelb.mkv`,
59+`~/Videos/Films/reelc.mkv`) are `yuv420p10le` and now stop at
60+the bit-depth refusal landed by this merge. Turns ran out before probing
61+them live with `decode_probe`/`ffmpeg -f obu` this round -- next lane's
62+first move, not scoped further here.
63+
64+### Why `Vec<u8>` cannot just get a runtime scale
65+
66+`transform.rs` already takes `bit_depth: u8` and uses it for the inverse
67+transform's own intermediate clamp widths (`row_clamp = bit_depth + 8`,
68+`col_clamp = max(bit_depth + 6, 16)`, `transform.rs:829-830`) -- that part
69+is bit-depth-aware today. Every dequant call site in `decode.rs` still
70+hardcodes the literal `8` as that parameter (6 call sites:
71+`dequant_and_inverse_typed`/`dequant_and_inverse_typed_wh`, e.g.
72+`decode.rs:2986`, `:3316` intra rect luma/chroma x2 each plus the inter
73+paths at `:5397`, `:5858`). Threading the real `bit_depth` through those 6
74+is narrow (same shape as `base_q_idx`'s existing pass-through).
75+
76+The actual width problem is downstream of the transform: **every
77+reconstruction write clamps to `[0, 255]` and stores `as u8`.** This is
78+not 2 sites, it is a whole-crate convention:
79+`decode.rs`'s `PlaneBuf::reconstruct`/`reconstruct_rect` (`:3153`,
80+`:3226`), CDEF pixel writes (`:4181`), deblocking's op/oq stores (`:4634`
81+-`:4710`, ~14 sites across the 4/6/8/13/14-tap filters), plus every
82+sample buffer write in `mc.rs` (inter prediction, `:406`/`:524`/`:587`)
83+and `intra.rs` (intra prediction proper, `:307`/`:434`/`:568`, and filter
84+intra `:762`). All of these assume an 8-bit sample IS a `u8`, both as the
85+storage type and as the clamp bound.
86+
87+### The type to widen
88+
89+`Picture` (`encode.rs:86`, `y`/`u`/`v: Vec<u8>`) and `PlaneBuf`
90+(`decode.rs:2980`, `data: Vec<u8>`) are the two sample-storage structs.
91+Widening both to `Vec<u16>` (AV1 caps at 12-bit, so `u16` covers every
92+legal `bit_depth`) is the natural target -- but doing that unconditionally
93+regresses every existing 8-bit fixture's memory/perf for a capability the
94+crate doesn't have yet. The narrower move: keep `Vec<u8>` as the on-disk
95+`Picture` representation for the 8-bit case (all current fixtures, all
96+current gates, `Picture::grey`'s `128u8` default) and give `PlaneBuf`
97+(the internal, per-decode scratch buffer, never a public API surface) a
98+generic sample type — either a `u16`-always internal buffer (simplest;
99+8-bit content just never uses the top byte, same choice `dav1d`/libaom
100+make internally) or a `PlaneBuf<S>` generic over `u8`/`u16` picked once at
101+`decode_key_frame_tile_with_cdfs`'s entry from the sequence header's
102+`bit_depth`. Given this crate has no perf-critical caller depending on
103+`PlaneBuf` staying byte-sized (it is decode-internal, dropped at the end
104+of each frame), **`u16`-always is the lower-risk pick**: one type, no
105+monomorphization/dyn-dispatch fork through the ~30 clamp-and-store call
106+sites, and the existing 8-bit path just runs with a wider-than-needed
107+sample width, which every reference decoder already does internally.
108+
109+### Concrete surface, sized
110+
111+1. `PlaneBuf.data: Vec<u8>` -> `Vec<u16>`; every
112+ `.clamp(0, 255) as u8` write becomes `.clamp(0, max_val) as u16` where
113+ `max_val = (1i32 << bit_depth) - 1` (a new thread-local, same pattern
114+ as `CDEF_BITS`/`ENABLE_EDGE_FILTER`, set once per tile-function entry
115+ from the sequence header's `bit_depth`). ~30 call sites across
116+ `decode.rs` (reconstruct/reconstruct_rect/CDEF/deblock), `mc.rs`
117+ (inter prediction), `intra.rs` (intra + filter-intra prediction) --
118+ every one is already a `.clamp(0, 255) as u8` grep hit, so the sweep is
119+ mechanical once the constant is threaded, not a design problem.
120+2. `prediction: Vec<u8>` scratch buffers inside `reconstruct`/
121+ `reconstruct_rect` (`decode.rs:3121`/`:3182`) and the `dst`/`out`
122+ parameters `mc::predict`/`intra::predict`/`predict_filter_intra`
123+ already take by `&mut [u8]` -- these become `&mut [u16]`, a pure
124+ signature widen, no logic change (the intermediate math is already
125+ `i32`/wider before the final clamp-and-store).
126+3. `transform.rs`'s 6 `bit_depth: 8`-hardcoded call sites in `decode.rs`
127+ become the real `bit_depth: u8` from the sequence header's
128+ `color_config.bit_depth`, threaded the same way `base_q_idx` already
129+ is (a plain pass-through parameter, no new state needed — confirmed
130+ the value is already carried on `SequenceHeader.color_config` and
131+ reachable at every one of these 6 call sites' enclosing function).
132+4. `Picture` (the public, post-decode return type) gains a `bit_depth: u8`
133+ field and its `y`/`u`/`v` become `Vec<u16>` too (matching what
134+ `ffmpeg_decode_sequence`'s gate helper will need to compare against,
135+ below) -- OR stays `Vec<u8>` for 8-bit and the crate adds a parallel
136+ `Vec<u16>` accessor/variant for >8-bit. Given no downstream consumer of
137+ `Picture` in this crate needs 8-bit specifically (it's an internal test
138+ type per `encode.rs`'s own doc comment "one 8-bit planar picture"),
139+ the simpler move is widening `Picture` itself to `Vec<u16>` too and
140+ dropping the "8-bit" from its doc comment -- `Picture::grey`'s `128`
141+ default is bit-depth-agnostic already (mid-grey is `1 << (bit_depth-1)`
142+ either way, one more thread-local read).
143+5. The refusal (`stream.rs`, this merge's `"a stream whose bit depth is
144+ not 8..."`) is deleted once (1) through (4) land and a gate proves them,
145+ the same sequencing every other capability in this repo's ledger
146+ followed (interintra, masked compound, wedge, warp).
147+
148+### What the gate needs -- `ffmpeg_decode_sequence` also assumes 8-bit
149+
150+`stream.rs:738`'s test helper hardcodes `-pix_fmt yuv420p` on ffmpeg's
151+raw output, which is 1 byte/sample regardless of source depth (ffmpeg
152+would silently truncate a 10-bit decode to 8-bit there too, the exact
153+silent-wrongness class the new refusal exists to avoid). A 10-bit gate
154+needs a second helper (or a `bit_depth` parameter on this one) that asks
155+ffmpeg for `-pix_fmt yuv420p10le` and parses the raw output as
156+little-endian `u16` pairs, 2 bytes/sample -- mechanical, not a design
157+question, but it is new code, not reuse of the existing 8-bit gate
158+helper as-is.
159+
160+### Sizing
161+
162+This is at minimum its own lane, likely 2: one for the mechanical
163+`u8`->`u16` PlaneBuf/prediction-buffer widening + real `bit_depth`
164+threading through the 6 transform call sites (large diff, low risk --
165+every site is already a grep-identifiable `.clamp(0,255) as u8` pattern),
166+gated first against synthetic 10-bit `aomenc` fixtures; a second for
167+whatever the two real films' streams refuse on *next* (the charter's own
168+prediction: "expect a new refusal to appear behind the bit-depth one").
169+Not attempted this round -- charter scoped this as "the shape, not the
170+whole feature," and every comparable feature in this repo's ledger
171+(warp, OBMC, interintra, masked compound, wedge) took multiple dedicated
172+lane-rounds; landing even the mechanical half in whatever budget remained
173+after Job 1 risked leaving a half-wired widening uncommitted at the turn
174+cap, which the charter explicitly forbids ("land nothing half-wired").
175+
176+deferred: probing the two real films with `decode_probe`/`ffmpeg -f obu`
177+to name the next refusal — no turns left this round — unblocked by
178+nothing (any future lane can run it immediately); the typing plan above
179+does not depend on that probe's output, it depends only on the crate's
180+existing `u8`-everywhere convention, which is repo-visible without the
181+films.
182+
183+## Merge note for future lanes
184+
185+`gate_coverage.rs` / `refusal_inventory.rs` needed no manual entry beyond
186+what the merge itself carried in (both auto-merged clean, no new gate or
187+refusal added this round). Sibling worktrees (`-lr`, `-palette`,
188+`-sbpart`, `-superres`, `-tiles`) were not touched. Nothing pushed.
189+`lane-realworld` was not merged into `main`.