forge
Explore
Log in

Don't you dare go Hollow

Merge main 1176a16 into lane-leaf8tx: CDEF skip band, golomb frame-edge partitions, kf900/kf1200 fixtures

Browse files at this commit

8c20321d64a73a6f4fc75bb4fc774cfddb684ae6Ahmet Kaan GümüşParent: ccf0be02bca382
Kept main's OBMC unrecorded-filter refusal string; kept the lane's EC_OBMC trace lines.

25 changed files +3836 -113

crates/ec-av1/examples/decode_probe.rsmodified+5 -0
@@ -33,6 +33,7 @@ fn main() {
33 println!("reelc_chroma: skip_cfl={sc} dir_1to4_pairs={dp}");33 println!("reelc_chroma: skip_cfl={sc} dir_1to4_pairs={dp}");
34 let (h, v, c) = ec_av1::stream::rect4_32_counters();34 let (h, v, c) = ec_av1::stream::rect4_32_counters();
35 println!("rect4_32: horz={h} vert={v} coded={c}");35 println!("rect4_32: horz={h} vert={v} coded={c}");
36+ println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads());
36 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();37 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
37 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");38 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
38 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());39 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
@@ -47,6 +48,10 @@ fn main() {
47 "inter_ab16: horz_a={} horz_b={} vert_a={} vert_b={}",48 "inter_ab16: horz_a={} horz_b={} vert_a={} vert_b={}",
48 ab[0], ab[1], ab[2], ab[3]49 ab[0], ab[1], ab[2], ab[3]
49 );50 );
51+ // lane-kf900 r1: the counter the skipped-8x8-split-transform gate
52+ // asserts -- printed here so a recipe sweep can see it fire without a
53+ // test-binary rebuild.
54+ println!("skip_split_tx: {}", ec_av1::decode::skip_split_tx_hits());
50 let ir = ec_av1::stream::inter_rect_counters();55 let ir = ec_av1::stream::inter_rect_counters();
51 println!(56 println!(
52 "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}",57 "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}",
crates/ec-av1/fixtures/reelb_kf900.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/reelb_ss600_key_frame.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+739 -108
@@ -1502,6 +1502,18 @@ thread_local! {
1502 static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };1502 static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1503 }1503 }
1504 1504
1505+thread_local! {
1506+ /// lane-kf900 r4: rect intra strips that ACTUALLY use a palette -- the
1507+ /// 1:4 shapes (32x8/8x32, 16x4/4x16) and the sub-16x16 2:1 leaves
1508+ /// (16x8/8x16), the two shapes the lifted refusals named.
1509+ static RECT4_PALETTE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1510+}
1511+
1512+/// Current value of [`RECT4_PALETTE_HITS`].
1513+pub(crate) fn rect4_palette_hits() -> usize {
1514+ RECT4_PALETTE_HITS.with(|c| c.get())
1515+}
1516+
1505 /// Current value of [`PALETTE_SPLIT_TX_HITS`].1517 /// Current value of [`PALETTE_SPLIT_TX_HITS`].
1506 pub(crate) fn palette_split_tx_hits() -> usize {1518 pub(crate) fn palette_split_tx_hits() -> usize {
1507 PALETTE_SPLIT_TX_HITS.with(|c| c.get())1519 PALETTE_SPLIT_TX_HITS.with(|c| c.get())
@@ -1606,6 +1618,30 @@ thread_local! {
1606 static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };1618 static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1607 }1619 }
1608 1620
1621+/// Whether this frame's header set `allow_intrabc` -- [`INTRABC_MI_GRID`] is
1622+/// `Some` exactly then (set once per frame in `decode_frame`), so the flag
1623+/// needs no separate plumbing to reach the rect-strip mode reader.
1624+fn allow_intrabc_frame() -> bool {
1625+ INTRABC_MI_GRID.with(|g| g.borrow().is_some())
1626+}
1627+
1628+thread_local! {
1629+ /// How many rect intra strips READ the `use_intrabc` symbol (i.e. how many
1630+ /// times the fix below was exercised) -- the rect-strip gate's hit counter,
1631+ /// distinct from [`INTRABC_HITS`] which counts blocks that USE intrabc.
1632+ static RECT_INTRABC_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1633+}
1634+
1635+/// Current value of [`RECT_INTRABC_READS`].
1636+pub(crate) fn rect_intrabc_reads() -> usize {
1637+ RECT_INTRABC_READS.with(|c| c.get())
1638+}
1639+
1640+/// Zeroes [`RECT_INTRABC_READS`] (gate tests call this before a decode).
1641+pub(crate) fn reset_rect_intrabc_reads() {
1642+ RECT_INTRABC_READS.with(|c| c.set(0));
1643+}
1644+
1609 /// Current value of [`INTRABC_HITS`].1645 /// Current value of [`INTRABC_HITS`].
1610 pub(crate) fn intrabc_hits() -> usize {1646 pub(crate) fn intrabc_hits() -> usize {
1611 INTRABC_HITS.with(|c| c.get())1647 INTRABC_HITS.with(|c| c.get())
@@ -2191,6 +2227,44 @@ pub(crate) fn sb_rect_hits() -> usize {
2191 SB_RECT_HITS.with(|c| c.get())2227 SB_RECT_HITS.with(|c| c.get())
2192 }2228 }
2193 2229
2230+// lane-golomb r2: the 32x32-level FRAME-EDGE partition. Slot 0/1 = the
2231+// gathered edge bit read as 0 (HORZ/VERT) / 1 (SPLIT); slot 2 = a 32-level
2232+// PARTITION_HORZ decoded with `has_rows32 == false` (only the top 32x16 half
2233+// is coded), slot 3 = a PARTITION_VERT with `has_cols32 == false`. Both tile
2234+// paths (intra and inter) feed the same counter.
2235+//
2236+// lane-golomb r3: slots 4..7 are the same four facts one level up, at the
2237+// SUPERBLOCK (64x64) edge -- 4/5 = the gathered 64-level bit read as
2238+// HORZ/VERT / SPLIT, 6 = a 64x32 bottom-edge strip decoded with
2239+// `has_rows == false`, 7 = a 32x64 right-edge strip. Real aomenc answers a
2240+// bottom-edge superblock with the 64-level HORZ (measured: 192x80 flat-band,
2241+// every SB of the last row), so the 32-level slots stay 0 on that content and
2242+// only these prove the arm fired.
2243+thread_local! {
2244+ static EDGE32_HITS: std::cell::Cell<[usize; 8]> =
2245+ const { std::cell::Cell::new([0; 8]) };
2246+}
2247+
2248+/// Current value of [`EDGE32_HITS`].
2249+pub(crate) fn edge32_hits() -> [usize; 8] {
2250+ EDGE32_HITS.with(|c| c.get())
2251+}
2252+
2253+/// [`bump_edge32`] of `base + bit`, returning the bit -- the gathered edge
2254+/// reads are `if`-conditions, so the counter has to ride the expression.
2255+fn bump_edge32_bit(base: usize, bit: usize) -> usize {
2256+ bump_edge32(base + bit.min(1));
2257+ bit
2258+}
2259+
2260+fn bump_edge32(slot: usize) {
2261+ EDGE32_HITS.with(|c| {
2262+ let mut h = c.get();
2263+ h[slot] += 1;
2264+ c.set(h)
2265+ });
2266+}
2267+
2194 // lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/2268 // lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/
2195 // `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x642269 // `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x64
2196 // strip) fired. Real aomenc picks these at 64 even with2270 // strip) fired. Real aomenc picks these at 64 even with
@@ -2694,6 +2768,14 @@ pub fn sub8_inter_rect_hits() -> (usize, usize) {
2694 thread_local! {2768 thread_local! {
2695 static CDEF_SKIPPED_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2769 static CDEF_SKIPPED_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2696 static INTER8_SKIP_BAND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2770 static INTER8_SKIP_BAND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2771+ // lane-cdef r2: (c) 8x8 CDEF units that are FILTERED and whose extent
2772+ // crosses the cropped frame edge -- the only units for which "clamp at
2773+ // the crop" and "pad past the mi-rounded extent with CDEF_VERY_LARGE"
2774+ // (libaom `cdef.c:249-256`, `cdef_prepare_fb`'s hsize/vsize are
2775+ // `nhb << mi_wide_l2` off the MI grid, not the crop) differ. A frame
2776+ // whose width or height is not a multiple of 8 is the only shape that
2777+ // produces one; the straddling-band gate arms assert it grew.
2778+ static CDEF_STRADDLE_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2697 }2779 }
2698 2780
2699 /// Current value of `CDEF_SKIPPED_UNITS`.2781 /// Current value of `CDEF_SKIPPED_UNITS`.
@@ -2706,6 +2788,11 @@ pub(crate) fn inter8_skip_band_hits() -> usize {
2706 INTER8_SKIP_BAND_HITS.with(|c| c.get())2788 INTER8_SKIP_BAND_HITS.with(|c| c.get())
2707 }2789 }
2708 2790
2791+/// Current value of `CDEF_STRADDLE_UNITS`.
2792+pub(crate) fn cdef_straddle_units() -> usize {
2793+ CDEF_STRADDLE_UNITS.with(|c| c.get())
2794+}
2795+
2709 /// Current value of [`SUB8_SPLIT_HITS`].2796 /// Current value of [`SUB8_SPLIT_HITS`].
2710 pub(crate) fn sub8_split_hits() -> usize {2797 pub(crate) fn sub8_split_hits() -> usize {
2711 SUB8_SPLIT_HITS.with(|c| c.get())2798 SUB8_SPLIT_HITS.with(|c| c.get())
@@ -2838,6 +2925,12 @@ const MAX_BR_LEVEL: i32 = NUM_BASE_LEVELS + COEFF_BASE_RANGE;
2838 const VERT_ALIKE: [usize; 6] = [2, PARTITION_SPLIT, 4, 6, 7, 9];2925 const VERT_ALIKE: [usize; 6] = [2, PARTITION_SPLIT, 4, 6, 7, 9];
2839 const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8];2926 const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8];
2840 2927
2928+fn trace_edge(mi_r: usize, mi_c: usize, bsize: u32, ctx: usize, rng: u32) {
2929+ if std::env::var_os("EC_AV1_TRACE").is_some() {
2930+ eprintln!("OUR_PART mi_row={mi_r} mi_col={mi_c} bsize={bsize} ctx={ctx} rng={rng}");
2931+ }
2932+}
2933+
2841 fn element_prob(cdf: &[u16], element: usize) -> u16 {2934 fn element_prob(cdf: &[u16], element: usize) -> u16 {
2842 cdf[element] - if element > 0 { cdf[element - 1] } else { 0 }2935 cdf[element] - if element > 0 { cdf[element - 1] } else { 0 }
2843 }2936 }
@@ -4186,11 +4279,21 @@ impl Neighbours {
4186 /// palette block decoded as "no palette" and the tile desynced from4279 /// palette block decoded as "no palette" and the tile desynced from
4187 /// there (class [[cdf-row-held-constant]]).4280 /// there (class [[cdf-row-held-constant]]).
4188 fn palette_ctx_and_cache(&self, at: (usize, usize)) -> (usize, Vec<u16>) {4281 fn palette_ctx_and_cache(&self, at: (usize, usize)) -> (usize, Vec<u16>) {
4282+ self.palette_ctx_and_cache_mi(at, at.0 * (SUB / MI))
4283+ }
4284+
4285+ /// [`Self::palette_ctx_and_cache`] with the block's REAL mi row, which a
4286+ /// 1:4 strip does not share with its [`SUB`] cell: `av1_get_palette_cache`
4287+ /// drops the above neighbour on a 64-px superblock boundary
4288+ /// (pred_common.c:76, `row % (1 << MIN_SB_SIZE_LOG2)` with `row` the
4289+ /// block's own PIXEL row), and strip 1 of a HORZ_4 sits 8 px into the
4290+ /// cell -- reading `at.0 % 4` there excludes strip 0 from the cache of
4291+ /// every strip in an SB's top cell row, which libaom does not do.
4292+ fn palette_ctx_and_cache_mi(&self, at: (usize, usize), mi_r: usize) -> (usize, Vec<u16>) {
4189 let (r, c) = at;4293 let (r, c) = at;
4190- let above_ok = r % 4 != 0;4294+ let above_ok = mi_r % 16 != 0;
4191 // `xd->above_mbmi` exists for every row but the tile's own first.4295 // `xd->above_mbmi` exists for every row but the tile's own first.
4192- let above_is_palette =4296+ let above_is_palette = mi_r > self.tile_row0_mi && self.above_palette_size[c] > 0;
4193- r * (SUB / MI) > self.tile_row0_mi && self.above_palette_size[c] > 0;
4194 let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 {4297 let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 {
4195 (self.above_palette_size[c], self.above_palette_colors[c])4298 (self.above_palette_size[c], self.above_palette_colors[c])
4196 } else {4299 } else {
@@ -4276,8 +4379,14 @@ impl Neighbours {
4276 /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`),4379 /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`),
4277 /// so only the cache is wanted here.4380 /// so only the cache is wanted here.
4278 fn palette_uv_cache(&self, at: (usize, usize)) -> Vec<u16> {4381 fn palette_uv_cache(&self, at: (usize, usize)) -> Vec<u16> {
4382+ self.palette_uv_cache_mi(at, at.0 * (SUB / MI))
4383+ }
4384+
4385+ /// [`Self::palette_uv_cache`] with the block's real mi row -- see
4386+ /// [`Self::palette_ctx_and_cache_mi`].
4387+ fn palette_uv_cache_mi(&self, at: (usize, usize), mi_r: usize) -> Vec<u16> {
4279 let (r, c) = at;4388 let (r, c) = at;
4280- let above_ok = r % 4 != 0;4389+ let above_ok = mi_r % 16 != 0;
4281 let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 {4390 let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 {
4282 (self.above_palette_uv_size[c], self.above_palette_uv_colors[c])4391 (self.above_palette_uv_size[c], self.above_palette_uv_colors[c])
4283 } else {4392 } else {
@@ -4350,6 +4459,9 @@ impl Neighbours {
4350 // TX_32X32 -- independent of this block's luma `tx_depth`.4459 // TX_32X32 -- independent of this block's luma `tx_depth`.
4351 let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;4460 let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;
4352 let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;4461 let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;
4462+ if std::env::var_os("EC_TXGRID_TRACE").is_some() {
4463+ eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
4464+ }
4353 let cur = CURRENT_DELTA_LF.with(|c| c.get());4465 let cur = CURRENT_DELTA_LF.with(|c| c.get());
4354 let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) {4466 let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) {
4355 std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8)4467 std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8)
@@ -4381,6 +4493,36 @@ impl Neighbours {
4381 }4493 }
4382 }4494 }
4383 4495
4496+ /// One var-tx / split-tx LEAF's own LUMA transform dims over its mi span.
4497+ /// libaom `get_transform_size` (av1_loopfilter.c:207) applies the split
4498+ /// override only `if ((plane == AOM_PLANE_Y) && ...)` -- chroma keeps
4499+ /// `av1_get_max_uv_txsize(mbmi->bsize)`, the whole BLOCK's uv transform.
4500+ /// Routing a leaf through [`Self::fill_lf_grid_rect`] recomputed the uv
4501+ /// dims from the LEAF span and so invented chroma transform edges the
4502+ /// deblocker then filtered (lane-golomb r6). `ref_grid`/`delta_lf_grid`
4503+ /// are already correct from the block's own fill over the same span.
4504+ fn fill_lf_grid_leaf_luma(
4505+ &mut self,
4506+ at_mi: (usize, usize),
4507+ w_mi: usize,
4508+ h_mi: usize,
4509+ tx_px: u8,
4510+ tx_h_px: u8,
4511+ ) {
4512+ let (mi_r, mi_c) = at_mi;
4513+ for rr in 0..h_mi {
4514+ for cc in 0..w_mi {
4515+ let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
4516+ if let Some(cell) = self.tx_grid.get_mut(idx) {
4517+ *cell = tx_px;
4518+ }
4519+ if let Some(cell) = self.tx_h_grid.get_mut(idx) {
4520+ *cell = tx_h_px;
4521+ }
4522+ }
4523+ }
4524+ }
4525+
4384 /// Marks every 4x4 mi cell a just-decoded coded block covers with its4526 /// Marks every 4x4 mi cell a just-decoded coded block covers with its
4385 /// `skip` flag -- `at_mi`/`side_mi` are the block's own position and4527 /// `skip` flag -- `at_mi`/`side_mi` are the block's own position and
4386 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s4528 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s
@@ -4845,6 +4987,37 @@ impl Neighbours {
4845 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no4987 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no
4846 /// block has recorded the exact neighbouring mi.4988 /// block has recorded the exact neighbouring mi.
4847 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {4989 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
4990+ // lane-kf900 r2: libaom reads the chroma neighbours off the CHROMA
4991+ // REFERENCE block, not off the mi that carries the chroma syntax.
4992+ // `set_mi_row_col` (`blockd.h`) takes
4993+ // `base_mi = &xd->mi[-(mi_row & ss_y) * stride - (mi_col & ss_x)]` and
4994+ // only then `chroma_above_mbmi = base_mi[-stride]` /
4995+ // `chroma_left_mbmi = base_mi[-1]`. A sub-8 pair codes its chroma at
4996+ // the ODD mi, so without the snap we looked one mi row/column too far
4997+ // down/right -- the mi-exact slot never matched and the coarse
4998+ // fallback answered instead. Measured on a 4K 10-bit key frame, chroma
4999+ // 8x4 at (688, 100) = mi (51, 344): libaom's
5000+ // `get_intra_edge_filter_type` is 1 (the chroma block above it is
5001+ // `UV_SMOOTH_PRED`), ours was 0, which flips
5002+ // `av1_use_intra_edge_upsample(8, 4, -6, type)` (`blk_wh == 12`:
5003+ // false for type 1, TRUE for type 0) and upsampled an edge libaom
5004+ // leaves alone -- +1 on rows 2/3 of that block and every chroma block
5005+ // predicting from it (class `context-read-from-one-cell`).
5006+ self.smooth_uv_neighbour_unsnapped(mi_r & !1, mi_c & !1, r, c)
5007+ }
5008+
5009+ /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.
5010+ /// read off the mi passed in exactly. Only the 16x4/4x16 pair witness
5011+ /// counter wants this: it measures how often the snap CHANGES the answer,
5012+ /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every
5013+ /// decode path uses the snapping form.
5014+ fn smooth_uv_neighbour_unsnapped(
5015+ &self,
5016+ mi_r: usize,
5017+ mi_c: usize,
5018+ r: usize,
5019+ c: usize,
5020+ ) -> bool {
4848 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the5021 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
4849 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid5022 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
4850 // array that `start_tile` does not clear, so a block on a tile's first5023 // array that `start_tile` does not clear, so a block on a tile's first
@@ -5388,7 +5561,15 @@ fn merge_colors(transmitted: &[u16], cached: &[u16]) -> Vec<u16> {
5388 out5561 out
5389 }5562 }
5390 5563
5391-/// `read_palette_colors_y` (decodemv.c:478), bit_depth fixed at 8 (this5564+/// `read_palette_colors_y` (decodemv.c:478), at the sequence's real
5565+/// `bit_depth` -- lane-kf900 r3: every raw literal here (the first colour,
5566+/// each delta's width, the `range` bound and the clamp) is sized by
5567+/// `bit_depth`, and hardcoding 8 read 2 bits too few per colour on every
5568+/// 10-bit palette block. Raw literals are EQUIPROBABLE, and at the ranges
5569+/// this stream reaches (e.g. 62728) an equiprobable read is a FIXED POINT of
5570+/// the msac range, so a cross-decoder range ladder stays bit-identical
5571+/// through the whole miscount -- only the decoded VALUE differs (class
5572+/// `compare-range-not-tell`'s blind spot). (this
5392 /// decoder is 8-bit only): accepts up to `n` colours straight from `cache`5573 /// decoder is 8-bit only): accepts up to `n` colours straight from `cache`
5393 /// (one flag bit each, in cache order), then delta-codes the remainder5574 /// (one flag bit each, in cache order), then delta-codes the remainder
5394 /// (first value raw, each following delta `>= 1` off a shrinking bit width),5575 /// (first value raw, each following delta `>= 1` off a shrinking bit width),
@@ -5403,20 +5584,22 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u
5403 cached.push(c);5584 cached.push(c);
5404 }5585 }
5405 }5586 }
5587+ let bd = u32::from(bit_depth());
5588+ let max_val = (1i32 << bd) - 1;
5406 let mut colors = [0u16; 8];5589 let mut colors = [0u16; 8];
5407 let n_cached = cached.len();5590 let n_cached = cached.len();
5408 if n_cached < n {5591 if n_cached < n {
5409 let mut transmitted = Vec::with_capacity(n - n_cached);5592 let mut transmitted = Vec::with_capacity(n - n_cached);
5410- let first = dec.literal(8) as u16;5593+ let first = dec.literal(bd) as u16;
5411 transmitted.push(first);5594 transmitted.push(first);
5412 if n_cached + 1 < n {5595 if n_cached + 1 < n {
5413- let min_bits = 8u32 - 3;5596+ let min_bits = bd - 3;
5414 let mut bits = min_bits + dec.literal(2);5597 let mut bits = min_bits + dec.literal(2);
5415- let mut range = 255i32 - i32::from(first) - 1;5598+ let mut range = (1i32 << bd) - i32::from(first) - 1;
5416 for _ in (n_cached + 1)..n {5599 for _ in (n_cached + 1)..n {
5417 let delta = dec.literal(bits) as i32 + 1;5600 let delta = dec.literal(bits) as i32 + 1;
5418 let prev = *transmitted.last().unwrap();5601 let prev = *transmitted.last().unwrap();
5419- let val = (i32::from(prev) + delta).clamp(0, 255) as u16;5602+ let val = (i32::from(prev) + delta).clamp(0, max_val) as u16;
5420 range -= i32::from(val) - i32::from(prev);5603 range -= i32::from(val) - i32::from(prev);
5421 bits = bits.min(ceil_log2(range.max(0) as u32));5604 bits = bits.min(ceil_log2(range.max(0) as u32));
5422 transmitted.push(val);5605 transmitted.push(val);
@@ -5430,7 +5613,8 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u
5430 colors5613 colors
5431 }5614 }
5432 5615
5433-/// `read_palette_colors_uv` (decodemv.c:509), bit_depth fixed at 8: U reads5616+/// `read_palette_colors_uv` (decodemv.c:509), at the sequence's real
5617+/// `bit_depth` (see [`read_palette_colors_y`]): U reads
5434 /// exactly [`read_palette_colors_y`]'s cache/delta scheme (against the U-only5618 /// exactly [`read_palette_colors_y`]'s cache/delta scheme (against the U-only
5435 /// cache, `range` starting at `255 - prev` with no `-1`, and each raw `delta`5619 /// cache, `range` starting at `255 - prev` with no `-1`, and each raw `delta`
5436 /// unbiased by `+1` -- both differences from Y's own reader, matching the C5620 /// unbiased by `+1` -- both differences from Y's own reader, matching the C
@@ -5447,20 +5631,22 @@ fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> (
5447 cached.push(c);5631 cached.push(c);
5448 }5632 }
5449 }5633 }
5634+ let bd = u32::from(bit_depth());
5635+ let max_val = 1i32 << bd;
5450 let mut u_colors = [0u16; 8];5636 let mut u_colors = [0u16; 8];
5451 let n_cached = cached.len();5637 let n_cached = cached.len();
5452 if n_cached < n {5638 if n_cached < n {
5453 let mut transmitted = Vec::with_capacity(n - n_cached);5639 let mut transmitted = Vec::with_capacity(n - n_cached);
5454- let first = dec.literal(8) as u16;5640+ let first = dec.literal(bd) as u16;
5455 transmitted.push(first);5641 transmitted.push(first);
5456 if n_cached + 1 < n {5642 if n_cached + 1 < n {
5457- let min_bits = 8u32 - 3;5643+ let min_bits = bd - 3;
5458 let mut bits = min_bits + dec.literal(2);5644 let mut bits = min_bits + dec.literal(2);
5459- let mut range = 255i32 - i32::from(first);5645+ let mut range = max_val - i32::from(first);
5460 for _ in (n_cached + 1)..n {5646 for _ in (n_cached + 1)..n {
5461 let delta = dec.literal(bits) as i32;5647 let delta = dec.literal(bits) as i32;
5462 let prev = *transmitted.last().unwrap();5648 let prev = *transmitted.last().unwrap();
5463- let val = (i32::from(prev) + delta).clamp(0, 255) as u16;5649+ let val = (i32::from(prev) + delta).clamp(0, max_val - 1) as u16;
5464 range -= i32::from(val) - i32::from(prev);5650 range -= i32::from(val) - i32::from(prev);
5465 bits = bits.min(ceil_log2(range.max(0) as u32));5651 bits = bits.min(ceil_log2(range.max(0) as u32));
5466 transmitted.push(val);5652 transmitted.push(val);
@@ -5473,9 +5659,9 @@ fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> (
5473 }5659 }
5474 let mut v_colors = [0u16; 8];5660 let mut v_colors = [0u16; 8];
5475 if dec.literal(1) == 1 {5661 if dec.literal(1) == 1 {
5476- let min_bits_v = 8u32 - 4;5662+ let min_bits_v = bd - 4;
5477 let bits = min_bits_v + dec.literal(2);5663 let bits = min_bits_v + dec.literal(2);
5478- v_colors[0] = dec.literal(8) as u16;5664+ v_colors[0] = dec.literal(bd) as u16;
5479 for i in 1..n {5665 for i in 1..n {
5480 let mut delta = dec.literal(bits) as i32;5666 let mut delta = dec.literal(bits) as i32;
5481 if delta != 0 && dec.literal(1) == 1 {5667 if delta != 0 && dec.literal(1) == 1 {
@@ -5483,16 +5669,16 @@ fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> (
5483 }5669 }
5484 let mut val = i32::from(v_colors[i - 1]) + delta;5670 let mut val = i32::from(v_colors[i - 1]) + delta;
5485 if val < 0 {5671 if val < 0 {
5486- val += 256;5672+ val += max_val;
5487 }5673 }
5488- if val >= 256 {5674+ if val >= max_val {
5489- val -= 256;5675+ val -= max_val;
5490 }5676 }
5491 v_colors[i] = val as u16;5677 v_colors[i] = val as u16;
5492 }5678 }
5493 } else {5679 } else {
5494 for i in 0..n {5680 for i in 0..n {
5495- v_colors[i] = dec.literal(8) as u16;5681+ v_colors[i] = dec.literal(bd) as u16;
5496 }5682 }
5497 }5683 }
5498 (u_colors, v_colors)5684 (u_colors, v_colors)
@@ -5671,6 +5857,13 @@ fn read_intra_mode_rect(
5671 Option<PaletteUv>,5857 Option<PaletteUv>,
5672 )> {5858 )> {
5673 let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();5859 let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();
5860+ if ec_istep {
5861+ // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
5862+ // (decodemv.c:818), printed at the same point: before the first
5863+ // mode-info symbol of the block, so a cross-decoder range ladder can
5864+ // be keyed on the BLOCK, not just on the symbol sequence.
5865+ eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}", enable_filter_intra as i32, filter_intra_size_class_rect(bw, bh), dec.debug_state().0);
5866+ }
5674 macro_rules! istep {5867 macro_rules! istep {
5675 ($name:literal, $val:expr) => {5868 ($name:literal, $val:expr) => {
5676 if ec_istep {5869 if ec_istep {
@@ -5711,6 +5904,27 @@ fn read_intra_mode_rect(
5711 maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip);5904 maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip);
5712 maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip);5905 maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip);
5713 istep!("dq", 0);5906 istep!("dq", 0);
5907+ // `read_intrabc_info` (spec 5.11.13, libaom `decodemv.c:892`, right after
5908+ // `skip`/`segment_id`/`cdef`/`delta_q` and before `mbmi->mode`): the
5909+ // `use_intrabc` symbol is read for EVERY intra block of an `allow_intrabc`
5910+ // frame -- `av1_allow_intrabc` is a frame-level test with no shape term, so
5911+ // rect strips read it exactly like square leaves ([`read_intra_mode`],
5912+ // [`read_intra_mode_sub8`]). Missing it here desynced the arithmetic
5913+ // decoder at the FIRST symbol of the first rect block of every
5914+ // `--tune-content=screen` key frame. Reconstruction of a real intrabc
5915+ // block at this shape is out of scope, so the flag is consumed and
5916+ // refused by name when it fires.
5917+ if allow_intrabc_frame() {
5918+ let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0;
5919+ RECT_INTRABC_READS.with(|c| c.set(c.get() + 1));
5920+ istep!("intrabc", use_intrabc as i32);
5921+ if use_intrabc {
5922+ INTRABC_HITS.with(|c| c.set(c.get() + 1));
5923+ return Err(unsupported(
5924+ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
5925+ ));
5926+ }
5927+ }
5714 let above_ctx = INTRA_MODE_CTX[above_mode];5928 let above_ctx = INTRA_MODE_CTX[above_mode];
5715 let left_ctx = INTRA_MODE_CTX[left_mode];5929 let left_ctx = INTRA_MODE_CTX[left_mode];
5716 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);5930 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
@@ -5808,9 +6022,11 @@ fn read_intra_mode_rect(
5808 if std::env::var_os("EC_AV1_TRACE").is_some() {6022 if std::env::var_os("EC_AV1_TRACE").is_some() {
5809 eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);6023 eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);
5810 }6024 }
6025+ istep!("use_filter_intra", use_filter_intra as i32);
5811 if use_filter_intra {6026 if use_filter_intra {
5812 FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));6027 FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));
5813 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);6028 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
6029+ istep!("filter_intra_mode", fi_mode as i32);
5814 filter_intra = Some(fi_mode);6030 filter_intra = Some(fi_mode);
5815 }6031 }
5816 }6032 }
@@ -5823,7 +6039,13 @@ fn read_intra_mode_rect(
5823 PaletteY { size: n, colors, map }6039 PaletteY { size: n, colors, map }
5824 });6040 });
5825 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {6041 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
5826- let map = decode_color_index_map_wh(dec, cdfs, n, bw / 2, bh / 2, true);6042+ // `av1_get_plane_block_size(bsize, 1, 1)` (`ss_size_lookup`), NOT a
6043+ // plain halving: BLOCK_16X4 subsamples to BLOCK_8X4 and BLOCK_4X16 to
6044+ // BLOCK_4X8, both floored at the 4-px transform. Halving the short
6045+ // axis to 2 read HALF the colour-index symbols of a 1:4 strip's
6046+ // chroma palette and desynced the tile from there.
6047+ let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4));
6048+ let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, true);
5827 PALETTE_UV_HITS.with(|c| c.set(c.get() + 1));6049 PALETTE_UV_HITS.with(|c| c.set(c.get() + 1));
5828 PaletteUv { size: n, u_colors, v_colors, map }6050 PaletteUv { size: n, u_colors, v_colors, map }
5829 });6051 });
@@ -5840,6 +6062,48 @@ fn read_intra_mode_rect(
5840 ))6062 ))
5841 }6063 }
5842 6064
6065+/// Stamps a 1:4 strip's palette state into the coarse above/left arrays.
6066+/// `av1_get_palette_cache` reads `xd->above_mbmi`/`xd->left_mbmi`, and inside
6067+/// a HORZ_4 (VERT_4) the next strip's ABOVE (LEFT) neighbour is this strip
6068+/// while its LEFT (ABOVE) neighbour is still the parent block's. The coarse
6069+/// [`SUB`]-cell arrays alias all four strips onto one entry, so writing BOTH
6070+/// axes after every strip would hand strip i+1 this strip's colours on the
6071+/// wrong axis too -- a wrong cache costs the same bits, so the tile stays in
6072+/// sync and only the pixels are wrong (class [[cdf-row-held-constant]]).
6073+/// Only the split axis is written until the closing strip, which stamps both
6074+/// for whatever follows the parent block.
6075+#[allow(clippy::too_many_arguments)]
6076+fn record_strip_palette(
6077+ n: &mut Neighbours,
6078+ at: (usize, usize),
6079+ bw: usize,
6080+ bh: usize,
6081+ y_size: usize,
6082+ y_colors: [u16; 8],
6083+ uv_size: usize,
6084+ uv_colors: [u16; 8],
6085+ last: bool,
6086+) {
6087+ let (r, c) = at;
6088+ let horz = bw > bh;
6089+ if horz || last {
6090+ for cell in 0..(bw / SUB).max(1) {
6091+ n.above_palette_size[c + cell] = y_size;
6092+ n.above_palette_colors[c + cell] = y_colors;
6093+ n.above_palette_uv_size[c + cell] = uv_size;
6094+ n.above_palette_uv_colors[c + cell] = uv_colors;
6095+ }
6096+ }
6097+ if !horz || last {
6098+ for cell in 0..(bh / SUB).max(1) {
6099+ n.left_palette_size[r + cell] = y_size;
6100+ n.left_palette_colors[r + cell] = y_colors;
6101+ n.left_palette_uv_size[r + cell] = uv_size;
6102+ n.left_palette_uv_colors[r + cell] = uv_colors;
6103+ }
6104+ }
6105+}
6106+
5843 /// [`tx_size_context`] for a true `bw`x`bh` rect strip (lane-intradisp r1):6107 /// [`tx_size_context`] for a true `bw`x`bh` rect strip (lane-intradisp r1):
5844 /// `get_tx_size_context` (libaom `pred_common.h`) compares the neighbour6108 /// `get_tx_size_context` (libaom `pred_common.h`) compares the neighbour
5845 /// above against this block's own *width* and the neighbour to the left6109 /// above against this block's own *width* and the neighbour to the left
@@ -5853,6 +6117,14 @@ fn tx_size_context_rect(
5853 ) -> usize {6117 ) -> usize {
5854 let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w;6118 let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w;
5855 let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h;6119 let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h;
6120+ if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
6121+ eprintln!(
6122+ "EC_TXCTX mi_row={mi_r} mi_col={mi_c} w={own_w} h={own_h} above_px={} left_px={} ctx={}",
6123+ if mi_r > n.tile_row0_mi { tx_px_at(n, false, mi_r - 1, mi_c) } else { 0 },
6124+ if mi_c > n.tile_col0_mi { tx_h_px_at(n, false, mi_r, mi_c - 1) } else { 0 },
6125+ usize::from(above) + usize::from(left)
6126+ );
6127+ }
5856 usize::from(above) + usize::from(left)6128 usize::from(above) + usize::from(left)
5857 }6129 }
5858 6130
@@ -7030,8 +7302,11 @@ fn decode_leaf_rect(
7030 // decoded bit is the same. The cell is the 16px-SUB cell containing the7302 // decoded bit is the same. The cell is the 16px-SUB cell containing the
7031 // leaf (the palette neighbour arrays have no finer granularity).7303 // leaf (the palette neighbour arrays have no finer granularity).
7032 let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI));7304 let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI));
7033- let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(pal_at);7305+ // lane-kf900 r4: the leaf's REAL mi row -- the second leaf of a 16x8 pair
7034- let palette_uv_cache = neighbours.palette_uv_cache(pal_at);7306+ // sits 8 px into the cell, so the cache's superblock-top-row exclusion
7307+ // must not be read off the cell (see [`Neighbours::palette_ctx_and_cache_mi`]).
7308+ let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, leaf_mi.0);
7309+ let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, leaf_mi.0);
7035 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =7310 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
7036 read_intra_mode_rect(7311 read_intra_mode_rect(
7037 dec,7312 dec,
@@ -7050,14 +7325,31 @@ fn decode_leaf_rect(
7050 leaf_mi.0,7325 leaf_mi.0,
7051 leaf_mi.1,7326 leaf_mi.1,
7052 )?;7327 )?;
7328+ // lane-kf900 r4: palette prediction on this shape, the same colour-index
7329+ // map -> base colours buffer [`decode_block_rect`] hands each
7330+ // `reconstruct_rect` through [`set_palette_pred`].
7053 if palette_y.is_some() || palette_uv.is_some() {7331 if palette_y.is_some() || palette_uv.is_some() {
7054- // Symbols (mode/size/colours/index map) are all read above, so the7332+ RECT4_PALETTE_HITS.with(|c| c.set(c.get() + 1));
7055- // tile stays in sync; only the *pixel* reconstruction of a palette on
7056- // a below-16x16 strip is unported and ungated (lane-palette2 r7).
7057- return Err(unsupported(
7058- "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",
7059- ));
7060 }7333 }
7334+ let palette_y_buf: Option<Vec<u16>> = palette_y
7335+ .as_ref()
7336+ .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
7337+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
7338+ (
7339+ p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
7340+ p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
7341+ )
7342+ });
7343+ let (pal_y_size, pal_y_colors) =
7344+ palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
7345+ let (pal_uv_size, pal_uv_colors) =
7346+ palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
7347+ // The closing leaf of the pair -- see [`record_strip_palette`].
7348+ let pal_last = if bw > bh {
7349+ leaf_mi.0 % 4 == 2
7350+ } else {
7351+ leaf_mi.1 % 4 == 2
7352+ };
7061 if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {7353 if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
7062 eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");7354 eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");
7063 }7355 }
@@ -7116,11 +7408,12 @@ fn decode_leaf_rect(
7116 // the unsplit arm below passes the real neighbour answer -- chroma7408 // the unsplit arm below passes the real neighbour answer -- chroma
7117 // of a tx-split 16x8/8x16 leaf lost its intra-edge filter type.7409 // of a tx-split 16x8/8x16 leaf lost its intra-edge filter type.
7118 smooth_neighbor_uv,7410 smooth_neighbor_uv,
7119- // Both callers refuse a palette on this shape above (pixel7411+ palette_y: palette_y_buf.clone(),
7120- // reconstruction is unported here), so the split units carry none.7412+ palette_uv: palette_uv_bufs.clone(),
7121- palette_y: None,
7122- palette_uv: None,
7123 };7413 };
7414+ if palette_y.is_some() || palette_uv.is_some() {
7415+ PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
7416+ }
7124 decode_rect_split(7417 decode_rect_split(
7125 dec,7418 dec,
7126 cdfs,7419 cdfs,
@@ -7137,6 +7430,10 @@ fn decode_leaf_rect(
7137 base_q_idx,7430 base_q_idx,
7138 reduced_tx_set,7431 reduced_tx_set,
7139 )?;7432 )?;
7433+ record_strip_palette(
7434+ neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
7435+ pal_last,
7436+ );
7140 return Ok(mode);7437 return Ok(mode);
7141 }7438 }
7142 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);7439 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
@@ -7148,15 +7445,24 @@ fn decode_leaf_rect(
7148 luma_levels = vec![0i32; bw * bh];7445 luma_levels = vec![0i32; bw * bh];
7149 u_levels = vec![0i32; chroma_w * chroma_h];7446 u_levels = vec![0i32; chroma_w * chroma_h];
7150 v_levels = vec![0i32; chroma_w * chroma_h];7447 v_levels = vec![0i32; chroma_w * chroma_h];
7448+ if let Some(b) = &palette_y_buf {
7449+ set_palette_pred(b.clone());
7450+ }
7151 y.reconstruct_rect(7451 y.reconstruct_rect(
7152 px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra,7452 px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra,
7153 smooth_neighbor,7453 smooth_neighbor,
7154 );7454 );
7155 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));7455 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
7456+ if let Some((ub, _)) = &palette_uv_bufs {
7457+ set_palette_pred(ub.clone());
7458+ }
7156 u.reconstruct_rect(7459 u.reconstruct_rect(
7157 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels,7460 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels,
7158 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv,7461 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv,
7159 );7462 );
7463+ if let Some((_, vb)) = &palette_uv_bufs {
7464+ set_palette_pred(vb.clone());
7465+ }
7160 v.reconstruct_rect(7466 v.reconstruct_rect(
7161 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels,7467 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels,
7162 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv,7468 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv,
@@ -7192,6 +7498,9 @@ fn decode_leaf_rect(
7192 &luma_levels, bw, bh, crate::decode::bit_depth(),7498 &luma_levels, bw, bh, crate::decode::bit_depth(),
7193 CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(0).0, plane_q_delta(0).1, luma_tx_type,7499 CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(0).0, plane_q_delta(0).1, luma_tx_type,
7194 );7500 );
7501+ if let Some(b) = &palette_y_buf {
7502+ set_palette_pred(b.clone());
7503+ }
7195 y.reconstruct_rect(7504 y.reconstruct_rect(
7196 px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra,7505 px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra,
7197 smooth_neighbor,7506 smooth_neighbor,
@@ -7209,6 +7518,9 @@ fn decode_leaf_rect(
7209 &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(),7518 &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(),
7210 CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(1).0, plane_q_delta(1).1, u_tx_type,7519 CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(1).0, plane_q_delta(1).1, u_tx_type,
7211 );7520 );
7521+ if let Some((ub, _)) = &palette_uv_bufs {
7522+ set_palette_pred(ub.clone());
7523+ }
7212 u.reconstruct_rect(7524 u.reconstruct_rect(
7213 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual,7525 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual,
7214 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv,7526 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv,
@@ -7225,6 +7537,9 @@ fn decode_leaf_rect(
7225 &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(),7537 &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(),
7226 CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(2).0, plane_q_delta(2).1, v_tx_type,7538 CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(2).0, plane_q_delta(2).1, v_tx_type,
7227 );7539 );
7540+ if let Some((_, vb)) = &palette_uv_bufs {
7541+ set_palette_pred(vb.clone());
7542+ }
7228 v.reconstruct_rect(7543 v.reconstruct_rect(
7229 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual,7544 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual,
7230 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv,7545 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv,
@@ -7234,12 +7549,15 @@ fn decode_leaf_rect(
7234 neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]);7549 neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]);
7235 neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);7550 neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);
7236 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);7551 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);
7237- // This leaf is necessarily non-palette (a palette one refused above), so7552+ // The leaf's own palette state (`0` clears, as this site always did
7238- // it must CLEAR the above/left palette state over its own span -- without7553+ // while a palette leaf refused -- lane-palette2 r8), written on the SPLIT
7239- // this the next block's `palette_y_mode` ctx and colour cache were read7554+ // AXIS only until the pair's closing leaf: the coarse cell holds one
7240- // off whatever block last covered the cell (lane-palette2 r8).7555+ // entry for both leaves, and leaf 0 zeroing the LEFT one threw away the
7241- neighbours.record_palette_y_rect(pal_at, bw, bh, 0, [0u16; 8]);7556+ // real left neighbour leaf 1 reads (lane-kf900 r4).
7242- neighbours.record_palette_uv_rect(pal_at, bw, bh, 0, [0u16; 8]);7557+ record_strip_palette(
7558+ neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
7559+ pal_last,
7560+ );
7243 // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and7561 // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and
7244 // rows -- record the whole span, not one cell.7562 // rows -- record the whole span, not one cell.
7245 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode);7563 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode);
@@ -7303,6 +7621,14 @@ fn decode_block_rect4(
7303 // 8-px strip of a `HORZ_4`/`VERT_4` onto one cell.7621 // 8-px strip of a `HORZ_4`/`VERT_4` onto one cell.
7304 let (above_mode, left_mode) =7622 let (above_mode, left_mode) =
7305 neighbours.modes_above_left_mi(mi_r, mi_c, (above_mode, left_mode));7623 neighbours.modes_above_left_mi(mi_r, mi_c, (above_mode, left_mode));
7624+ // lane-kf900 r4: this strip's own palette-Y mode ctx and colour cache.
7625+ // Passing `None`/`&[]` read `palette_y_mode` off CDF row 0 and every
7626+ // `palette_colors_y` cache hit off an EMPTY cache -- right symbol count,
7627+ // wrong interval, so a screen-content tile desynced at the first strip
7628+ // whose neighbour used a palette (class [[cdf-row-held-constant]]).
7629+ let pal_at = (mi_r / (SUB / MI), mi_c / (SUB / MI));
7630+ let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, mi_r);
7631+ let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, mi_r);
7306 let (7632 let (
7307 skip,7633 skip,
7308 mode,7634 mode,
@@ -7325,21 +7651,35 @@ fn decode_block_rect4(
7325 enable_filter_intra,7651 enable_filter_intra,
7326 neighbours.skip_txfm_ctx(mi_r, mi_c),7652 neighbours.skip_txfm_ctx(mi_r, mi_c),
7327 allow_screen_content_tools,7653 allow_screen_content_tools,
7328- None,7654+ Some((palette_ctx, &palette_cache)),
7329- &[],7655+ &palette_uv_cache,
7330 mi_r,7656 mi_r,
7331 mi_c,7657 mi_c,
7332 )?;7658 )?;
7333- // Merge of lane-palette2: `read_intra_mode_rect` now reads the palette7659+ // lane-kf900 r4: palette prediction on this shape, exactly as
7334- // syntax for every rect strip, but this 1:4 decoder has no palette7660+ // [`decode_block_rect`] does one aspect ratio up -- the colour-index map
7335- // reconstruction path (its caller never passes a cache). The symbols are7661+ // mapped through the base colours IS the prediction (it reads no edge
7336- // still read, so the stream stays in sync; a strip that ACTUALLY uses a7662+ // pixels), handed to each `reconstruct_rect` through [`set_palette_pred`].
7337- // palette is refused rather than reconstructed wrong.
7338 if palette_y.is_some() || palette_uv.is_some() {7663 if palette_y.is_some() || palette_uv.is_some() {
7339- return Err(unsupported(7664+ RECT4_PALETTE_HITS.with(|c| c.set(c.get() + 1));
7340- "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
7341- ));
7342 }7665 }
7666+ let palette_y_buf: Option<Vec<u16>> = palette_y
7667+ .as_ref()
7668+ .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
7669+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
7670+ (
7671+ p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
7672+ p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
7673+ )
7674+ });
7675+ // `last`: strip 3 of the parent 32x32's HORZ_4 (VERT_4), the only one
7676+ // whose colours a block outside the parent sees -- see
7677+ // [`record_strip_palette`].
7678+ let pal_last = if bw > bh { mi_r % 8 == 6 } else { mi_c % 8 == 6 };
7679+ let (pal_y_size, pal_y_colors) =
7680+ palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
7681+ let (pal_uv_size, pal_uv_colors) =
7682+ palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
7343 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);7683 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
7344 if smooth_neighbor {7684 if smooth_neighbor {
7345 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));7685 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
@@ -7399,11 +7739,12 @@ fn decode_block_rect4(
7399 filter_intra,7739 filter_intra,
7400 smooth_neighbor,7740 smooth_neighbor,
7401 smooth_neighbor_uv,7741 smooth_neighbor_uv,
7402- // Both callers refuse a palette on this shape above (pixel7742+ palette_y: palette_y_buf.clone(),
7403- // reconstruction is unported here), so the split units carry none.7743+ palette_uv: palette_uv_bufs.clone(),
7404- palette_y: None,
7405- palette_uv: None,
7406 };7744 };
7745+ if palette_y.is_some() || palette_uv.is_some() {
7746+ PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
7747+ }
7407 decode_rect_split(7748 decode_rect_split(
7408 dec,7749 dec,
7409 cdfs,7750 cdfs,
@@ -7420,6 +7761,10 @@ fn decode_block_rect4(
7420 base_q_idx,7761 base_q_idx,
7421 false,7762 false,
7422 )?;7763 )?;
7764+ record_strip_palette(
7765+ neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size,
7766+ pal_uv_colors, pal_last,
7767+ );
7423 if bw > bh {7768 if bw > bh {
7424 RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1));7769 RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1));
7425 } else {7770 } else {
@@ -7511,6 +7856,9 @@ fn decode_block_rect4(
7511 plane_q_delta(0).1,7856 plane_q_delta(0).1,
7512 luma_tx_type,7857 luma_tx_type,
7513 );7858 );
7859+ if let Some(b) = &palette_y_buf {
7860+ set_palette_pred(b.clone());
7861+ }
7514 y.reconstruct_rect(7862 y.reconstruct_rect(
7515 px,7863 px,
7516 py,7864 py,
@@ -7539,6 +7887,9 @@ fn decode_block_rect4(
7539 plane_q_delta(plane).1,7887 plane_q_delta(plane).1,
7540 tx_type,7888 tx_type,
7541 );7889 );
7890+ if let Some((ub, vb)) = &palette_uv_bufs {
7891+ set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() });
7892+ }
7542 buf.reconstruct_rect(7893 buf.reconstruct_rect(
7543 cpx,7894 cpx,
7544 cpy,7895 cpy,
@@ -7563,6 +7914,10 @@ fn decode_block_rect4(
7563 );7914 );
7564 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);7915 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
7565 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0);7916 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0);
7917+ record_strip_palette(
7918+ neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size,
7919+ pal_uv_colors, pal_last,
7920+ );
7566 if bw > bh {7921 if bw > bh {
7567 RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1));7922 RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1));
7568 } else {7923 } else {
@@ -7570,6 +7925,9 @@ fn decode_block_rect4(
7570 }7925 }
7571 return Ok((mode, uv_predict_mode));7926 return Ok((mode, uv_predict_mode));
7572 };7927 };
7928+ if let Some(b) = &palette_y_buf {
7929+ set_palette_pred(b.clone());
7930+ }
7573 y.reconstruct_rect(7931 y.reconstruct_rect(
7574 px,7932 px,
7575 py,7933 py,
@@ -7584,6 +7942,9 @@ fn decode_block_rect4(
7584 smooth_neighbor,7942 smooth_neighbor,
7585 );7943 );
7586 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));7944 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
7945+ if let Some((ub, _)) = &palette_uv_bufs {
7946+ set_palette_pred(ub.clone());
7947+ }
7587 u.reconstruct_rect(7948 u.reconstruct_rect(
7588 cpx,7949 cpx,
7589 cpy,7950 cpy,
@@ -7597,6 +7958,9 @@ fn decode_block_rect4(
7597 None,7958 None,
7598 smooth_neighbor_uv,7959 smooth_neighbor_uv,
7599 );7960 );
7961+ if let Some((_, vb)) = &palette_uv_bufs {
7962+ set_palette_pred(vb.clone());
7963+ }
7600 v.reconstruct_rect(7964 v.reconstruct_rect(
7601 cpx,7965 cpx,
7602 cpy,7966 cpy,
@@ -7613,6 +7977,10 @@ fn decode_block_rect4(
7613 neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels.to_vec(), u_levels, v_levels]);7977 neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels.to_vec(), u_levels, v_levels]);
7614 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);7978 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
7615 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0);7979 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0);
7980+ record_strip_palette(
7981+ neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
7982+ pal_last,
7983+ );
7616 if bw > bh {7984 if bw > bh {
7617 RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1));7985 RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1));
7618 } else {7986 } else {
@@ -7692,6 +8060,12 @@ fn decode_rect4_16(
7692 }8060 }
7693 let (above_mode, left_mode) =8061 let (above_mode, left_mode) =
7694 neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode));8062 neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode));
8063+ // lane-kf900 r4: the strip's real palette ctx + colour cache (see
8064+ // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode`
8065+ // off CDF row 0 and every cache hit off an empty cache.
8066+ let (palette_ctx, palette_cache) =
8067+ neighbours.palette_ctx_and_cache_mi(at16, lmi.0);
8068+ let palette_uv_cache = neighbours.palette_uv_cache_mi(at16, lmi.0);
7695 let (8069 let (
7696 skip,8070 skip,
7697 mode,8071 mode,
@@ -7714,16 +8088,26 @@ fn decode_rect4_16(
7714 enable_filter_intra,8088 enable_filter_intra,
7715 neighbours.skip_txfm_ctx(lmi.0, lmi.1),8089 neighbours.skip_txfm_ctx(lmi.0, lmi.1),
7716 allow_screen_content_tools,8090 allow_screen_content_tools,
7717- None,8091+ Some((palette_ctx, &palette_cache)),
7718- &[],8092+ &palette_uv_cache,
7719 lmi.0,8093 lmi.0,
7720 lmi.1,8094 lmi.1,
7721 )?;8095 )?;
7722 if palette_y.is_some() || palette_uv.is_some() {8096 if palette_y.is_some() || palette_uv.is_some() {
7723- return Err(unsupported(8097+ RECT4_PALETTE_HITS.with(|h| h.set(h.get() + 1));
7724- "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
7725- ));
7726 }8098 }
8099+ // The colour-index map through the base colours IS the prediction.
8100+ // Chroma's map is the PAIR's 8x4 (4x8) block, matching the one
8101+ // chroma transform this closing strip codes.
8102+ let palette_y_buf: Option<Vec<u16>> = palette_y
8103+ .as_ref()
8104+ .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
8105+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
8106+ (
8107+ p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
8108+ p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
8109+ )
8110+ });
7727 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);8111 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
7728 if smooth_neighbor {8112 if smooth_neighbor {
7729 SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1));8113 SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1));
@@ -7771,6 +8155,15 @@ fn decode_rect4_16(
7771 tx_h,8155 tx_h,
7772 reach,8156 reach,
7773 );8157 );
8158+ if let Some(b) = &palette_y_buf {
8159+ let tu_buf: Vec<u16> = (0..tx_h)
8160+ .flat_map(|i| {
8161+ let base = (tu_row * tx_h + i) * bw + tu_col * tx_w;
8162+ b[base..base + tx_w].iter().copied()
8163+ })
8164+ .collect();
8165+ set_palette_pred(tu_buf);
8166+ }
7774 if skip {8167 if skip {
7775 y.reconstruct_rect(8168 y.reconstruct_rect(
7776 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu,8169 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu,
@@ -7854,6 +8247,9 @@ fn decode_rect4_16(
7854 } else {8247 } else {
7855 let levels = if skip {8248 let levels = if skip {
7856 let zeros = vec![0i32; bw * bh];8249 let zeros = vec![0i32; bw * bh];
8250+ if let Some(b) = &palette_y_buf {
8251+ set_palette_pred(b.clone());
8252+ }
7857 y.reconstruct_rect(8253 y.reconstruct_rect(
7858 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,8254 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
7859 smooth_neighbor,8255 smooth_neighbor,
@@ -7890,6 +8286,9 @@ fn decode_rect4_16(
7890 plane_q_delta(0).1,8286 plane_q_delta(0).1,
7891 tx_type,8287 tx_type,
7892 );8288 );
8289+ if let Some(b) = &palette_y_buf {
8290+ set_palette_pred(b.clone());
8291+ }
7893 y.reconstruct_rect(8292 y.reconstruct_rect(
7894 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,8293 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
7895 smooth_neighbor,8294 smooth_neighbor,
@@ -7943,7 +8342,8 @@ fn decode_rect4_16(
7943 // directional chroma strip, moving 4 samples by 1.8342 // directional chroma strip, moving 4 samples by 1.
7944 let smooth_neighbor_uv =8343 let smooth_neighbor_uv =
7945 neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c);8344 neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c);
7946- if smooth_neighbor_uv != neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c) {8345+ if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c)
8346+ {
7947 RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1));8347 RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1));
7948 }8348 }
7949 let (u_levels, v_levels) = if skip {8349 let (u_levels, v_levels) = if skip {
@@ -7958,6 +8358,9 @@ fn decode_rect4_16(
7958 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));8358 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
7959 }8359 }
7960 for (buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {8360 for (buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {
8361+ if let Some((ub, vb)) = &palette_uv_bufs {
8362+ set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() });
8363+ }
7961 buf.reconstruct_rect(8364 buf.reconstruct_rect(
7962 cpx,8365 cpx,
7963 cpy,8366 cpy,
@@ -8013,6 +8416,9 @@ fn decode_rect4_16(
8013 plane_q_delta(plane).1,8416 plane_q_delta(plane).1,
8014 tx_type,8417 tx_type,
8015 );8418 );
8419+ if let Some((ub, vb)) = &palette_uv_bufs {
8420+ set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() });
8421+ }
8016 buf.reconstruct_rect(8422 buf.reconstruct_rect(
8017 cpx,8423 cpx,
8018 cpy,8424 cpy,
@@ -8063,6 +8469,14 @@ fn decode_rect4_16(
8063 } else {8469 } else {
8064 RECT4_16_VERT_HITS.with(|h| h.set(h.get() + 1));8470 RECT4_16_VERT_HITS.with(|h| h.set(h.get() + 1));
8065 }8471 }
8472+ let (pal_y_size, pal_y_colors) =
8473+ palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
8474+ let (pal_uv_size, pal_uv_colors) =
8475+ palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
8476+ record_strip_palette(
8477+ neighbours, at16, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
8478+ i == 3,
8479+ );
8066 last_mode = mode;8480 last_mode = mode;
8067 prev = Some((lmi, mode));8481 prev = Some((lmi, mode));
8068 }8482 }
@@ -8646,6 +9060,13 @@ fn read_intra_mode(
8646 // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for9060 // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for
8647 // line against the instrumented aomdec, not just `tell()`.9061 // line against the instrumented aomdec, not just `tell()`.
8648 let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();9062 let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();
9063+ if ec_istep {
9064+ // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
9065+ // (decodemv.c:818), printed at the same point: before the first
9066+ // mode-info symbol of the block, so a cross-decoder range ladder can
9067+ // be keyed on the BLOCK, not just on the symbol sequence.
9068+ eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sq side={side} rng={}", dec.debug_state().0);
9069+ }
8649 macro_rules! istep {9070 macro_rules! istep {
8650 ($name:literal, $val:expr) => {9071 ($name:literal, $val:expr) => {
8651 if ec_istep {9072 if ec_istep {
@@ -9008,10 +9429,10 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
9008 /// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE).9429 /// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE).
9009 fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) {9430 fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) {
9010 use std::io::Write;9431 use std::io::Write;
9011- // lane-sbrect10 r2: index the dump by decode-order picture like9432+ // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by
9012- // EC_AV1_PREFILT_DUMP already does -- a fixed `.f0` name kept only the9433+ // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed
9013- // LAST frame, so a mid-sequence divergence could not be read out at all.9434+ // `.f0` name kept only the LAST frame, so a mid-sequence divergence could
9014- static STAGE16_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);9435+ // not be read out at all.
9015 if let Ok(path) = std::env::var(var)9436 if let Ok(path) = std::env::var(var)
9016 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))9437 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
9017 {9438 {
@@ -10560,7 +10981,17 @@ fn decode_leaf8(
10560 }10981 }
10561 INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));10982 INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));
10562 neighbours.fill_skip_grid(leaf_mi, 2, skip);10983 neighbours.fill_skip_grid(leaf_mi, 2, skip);
10563- neighbours.fill_lf_grid(leaf_mi, 2, 8, 0);10984+ // lane-kf900 r1: the leaf's own RESOLVED transform size, never the literal
10985+ // block side. libaom calls `set_txfm_ctxs(mbmi->tx_size, ..., skip_txfm &&
10986+ // is_inter_block(mbmi), xd)` (decodemv.c) -- for an INTRA block that skip
10987+ // term is always 0, so a skipped 8x8 leaf whose `tx_depth` resolved to
10988+ // TX_4X4 still publishes 4 to the next block's `get_tx_size_context`
10989+ // (pred_common.h:342). Writing 8 here made the 8x16 strip below the leaf
10990+ // read `tx_size_cat1` row 2 where libaom reads row 1 -- same alphabet,
10991+ // wrong CDF row, so the msac range diverged mid-frame with no refusal
10992+ // (class `wrong-alphabet-same-value`; the ReelB key frame at
10993+ // -ss 900, first bad luma sample row 186 col 1803).
10994+ neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0);
10564 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode);10995 neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode);
10565 Ok(mode)10996 Ok(mode)
10566 }10997 }
@@ -10592,6 +11023,9 @@ fn read_intra_mode_sub8(
10592 mi_c: usize,11023 mi_c: usize,
10593 ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> {11024 ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> {
10594 let trace = std::env::var_os("EC_AV1_TRACE").is_some();11025 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
11026+ if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
11027+ eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0);
11028+ }
10595 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;11029 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
10596 if trace {11030 if trace {
10597 eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0);11031 eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0);
@@ -12133,8 +12567,8 @@ fn read_inter_plane_rect(
12133 // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e.12567 // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e.
12134 // the *longer* side of this rect transform.12568 // the *longer* side of this rect transform.
12135 let default_tx_type = match inherited_luma_tx_type {12569 let default_tx_type = match inherited_luma_tx_type {
12136- Some(t) if w.max(h) < 32 => t,12570+ Some(t) => reduce_inherited_chroma_tx_type(t, w, h),
12137- _ => TxType::DctDct,12571+ None => TxType::DctDct,
12138 };12572 };
12139 // lane-r14 r2: a 64-length axis codes only its low 32 coefficients12573 // lane-r14 r2: a 64-length axis codes only its low 32 coefficients
12140 // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)`12574 // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)`
@@ -12301,6 +12735,45 @@ fn read_inter_luma8(
12301 12735
12302 /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its12736 /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its
12303 /// coefficient tables from -- the inter counterpart of [`txbset_for`].12737 /// coefficient tables from -- the inter counterpart of [`txbset_for`].
12738+/// `av1_get_tx_type`'s chroma tail (libaom `av1/common/blockd.h:1291-1305`):
12739+/// an inter block's chroma transform inherits the *colocated luma* unit's
12740+/// coded `tx_type`, then drops back to `DCT_DCT` unless that type is a member
12741+/// of the extended set the CHROMA transform size selects
12742+/// (`av1_ext_tx_used[av1_get_ext_tx_set_type(uv_tx, 1, reduced)][tx_type]`,
12743+/// `blockd.h:1036`/`1097`). lane-golomb r7: we used to force `DCT_DCT` at
12744+/// every chroma side >= 32, but `av1_get_ext_tx_set_type`'s DCT-only rung is
12745+/// `tx_size_sqr_up > TX_32X32`; at exactly TX_32X32 an inter block reads
12746+/// `EXT_TX_SET_DCT_IDTX`, so a 64x64 inter block whose first luma leaf coded
12747+/// `IDTX` inherits IDTX on its 32x32 chroma units. `IDTX` and `DCT_DCT` are
12748+/// both `TX_CLASS_2D`, so that mistake left the entropy stream perfectly in
12749+/// sync and only corrupted the inverse transform (one 64x64 superblock of
12750+/// high-frequency chroma noise, luma bit-exact).
12751+fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize) -> TxType {
12752+ use TxType::*;
12753+ let sqr_up = w.max(h);
12754+ let sqr = w.min(h);
12755+ let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get);
12756+ // `av1_get_ext_tx_set_type(tx_size, is_inter = 1, reduced)`.
12757+ let allowed: &[TxType] = if sqr_up > 32 {
12758+ // EXT_TX_SET_DCTONLY
12759+ &[DctDct]
12760+ } else if sqr_up == 32 || reduced {
12761+ // EXT_TX_SET_DCT_IDTX
12762+ &[DctDct, Idtx]
12763+ } else if sqr == 16 {
12764+ // EXT_TX_SET_DTT9_IDTX_1DDCT -- TX_TYPES 0..=11, i.e. everything but
12765+ // the four 1D ADST/FLIPADST types.
12766+ &[
12767+ DctDct, AdstDct, DctAdst, AdstAdst, FlipAdstDct, DctFlipAdst, FlipAdstFlipAdst,
12768+ AdstFlipAdst, FlipAdstAdst, Idtx, VDct, HDct,
12769+ ]
12770+ } else {
12771+ // EXT_TX_SET_ALL16
12772+ return t;
12773+ };
12774+ if allowed.contains(&t) { t } else { DctDct }
12775+}
12776+
12304 fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {12777 fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
12305 match tx_px {12778 match tx_px {
12306 32 => TxbSet::Luma32Inter,12779 32 => TxbSet::Luma32Inter,
@@ -12806,6 +13279,18 @@ fn deblock_plane(
12806 // last coded mi column's horizontal edges were filtered when libaom's13279 // last coded mi column's horizontal edges were filtered when libaom's
12807 // real output leaves them untouched (r6's post-deblock diff, 37 px, all13280 // real output leaves them untouched (r6's post-deblock diff, 37 px, all
12808 // in columns 44-47); clipping here closes it (3/3 frames pixel-exact).13281 // in columns 44-47); clipping here closes it (3/3 frames pixel-exact).
13282+ // lane-golomb r9: the bound is the MI-ROUNDED frame, not the coded
13283+ // frame. libaom's `av1_filter_block_plane_vert/horz` walk the superblock
13284+ // and stop at `cm->mi_params.mi_cols`/`mi_rows`, which
13285+ // `av1_set_mb_mi` derives from `ALIGN_POWER_OF_TWO(width, 3)` -- the
13286+ // 8-pixel-aligned frame, i.e. a 68-wide frame is filtered out to column
13287+ // 72 and the vertical edge AT x=68 is a real edge that rewrites the
13288+ // in-crop columns 64..67. Clipping at `frame_width` skipped it, which is
13289+ // the +-1 straddling-band defect (68x192 cq35, frame 1, 141 luma pixels
13290+ // all in columns 64..67; frame 0 survived because that edge carried no
13291+ // filter level there). r7's superres measurement is preserved: its frame
13292+ // was already 8-aligned, so this bound equals `frame_width` there and
13293+ // still excludes the superblock padding up to `true_width`.
12809 let (cw, ch) = if chroma {13294 let (cw, ch) = if chroma {
12810 (frame_width.div_ceil(2), frame_height.div_ceil(2))13295 (frame_width.div_ceil(2), frame_height.div_ceil(2))
12811 } else {13296 } else {
@@ -12816,11 +13301,17 @@ fn deblock_plane(
12816 plane.true_height.min(ch),13301 plane.true_height.min(ch),
12817 plane.width,13302 plane.width,
12818 );13303 );
13304+ if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() {
13305+ eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height);
13306+ }
12819 let mut y0 = 0usize;13307 let mut y0 = 0usize;
12820 while y0 < th {13308 while y0 < th {
12821 let mut x0 = 4usize;13309 let mut x0 = 4usize;
12822 while x0 < tw {13310 while x0 < tw {
12823 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {13311 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {
13312+ if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() && plane_idx == 0 {
13313+ eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
13314+ }
12824 filter_edge(13315 filter_edge(
12825 &mut plane.data,13316 &mut plane.data,
12826 y0 * stride + x0,13317 y0 * stride + x0,
@@ -12871,6 +13362,9 @@ fn apply_cdef(
12871 v: &mut PlaneBuf,13362 v: &mut PlaneBuf,
12872 cdef: &CdefParams,13363 cdef: &CdefParams,
12873 skip_grid: &Neighbours,13364 skip_grid: &Neighbours,
13365+ // This frame header's own CROPPED luma size, for the straddling-unit
13366+ // counter only -- CDEF itself walks the mi-rounded plane.
13367+ (frame_w, frame_h): (usize, usize),
12874 ) {13368 ) {
12875 // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.13369 // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.
12876 if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() {13370 if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() {
@@ -12955,6 +13449,14 @@ fn apply_cdef(
12955 }13449 }
12956 let enable_primary = t != 0;13450 let enable_primary = t != 0;
12957 let enable_secondary = y_sec_strength != 0;13451 let enable_secondary = y_sec_strength != 0;
13452+ if (ox + 8 > frame_w || oy + 8 > frame_h)
13453+ && (enable_primary
13454+ || enable_secondary
13455+ || cdef.uv_pri_strength[sidx] != 0
13456+ || cdef.uv_sec_strength[sidx] != 0)
13457+ {
13458+ CDEF_STRADDLE_UNITS.with(|c| c.set(c.get() + 1));
13459+ }
12958 if enable_primary || enable_secondary {13460 if enable_primary || enable_secondary {
12959 cdef_filter_block(13461 cdef_filter_block(
12960 sample_y,13462 sample_y,
@@ -13034,13 +13536,30 @@ fn apply_loop_restoration(
13034 deblocked_v: &PlaneBuf,13536 deblocked_v: &PlaneBuf,
13035 lr: &LoopRestorationParams,13537 lr: &LoopRestorationParams,
13036 grid: &crate::restoration::RestorationGrid,13538 grid: &crate::restoration::RestorationGrid,
13539+ // lane-golomb r8: this frame header's own (cropped) luma size. Loop
13540+ // restoration is the ONE post-decode filter that does NOT run over the
13541+ // mi-rounded plane: libaom's `av1_loop_restoration_filter_frame` sizes
13542+ // every plane with `av1_get_upsampled_plane_size` -- `plane_w =
13543+ // ROUND_POWER_OF_TWO(cm->superres_upscaled_width, ss_x)`, `plane_h =
13544+ // ROUND_POWER_OF_TWO(cm->height, ss_y)` (`av1/common/restoration.c:47`)
13545+ // -- and asserts it equals the buffer's CROP width
13546+ // (`restoration.c:1106`), then `av1_extend_frame(..., plane_w, plane_h,
13547+ // ...)` (`restoration.c:1109`) replicates the right/bottom border from
13548+ // that cropped edge before any unit is filtered. Deblock and CDEF DO
13549+ // walk the mi grid, which is why passing `true_width`/`true_height`
13550+ // here went unnoticed until a frame whose size is not a multiple of 8
13551+ // (68 -> mi-rounded 72): the LR taps at the last four real columns then
13552+ // read this decoder's own decoded samples at columns 68..71 where
13553+ // libaom reads column 67 replicated -- +-1 over the straddling band
13554+ // (class av1-truesize-lane: true frame size vs mi-rounded).
13555+ (frame_w, frame_h): (usize, usize),
13037 ) {13556 ) {
13038 y.data = crate::restoration::apply_loop_restoration_plane(13557 y.data = crate::restoration::apply_loop_restoration_plane(
13039 &y.data,13558 &y.data,
13040 &deblocked_y.data,13559 &deblocked_y.data,
13041 y.width,13560 y.width,
13042- y.true_width,13561+ frame_w,
13043- y.true_height,13562+ frame_h,
13044 0,13563 0,
13045 lr.frame_restoration_type[0],13564 lr.frame_restoration_type[0],
13046 lr.loop_restoration_size[0],13565 lr.loop_restoration_size[0],
@@ -13051,8 +13570,8 @@ fn apply_loop_restoration(
13051 &u.data,13570 &u.data,
13052 &deblocked_u.data,13571 &deblocked_u.data,
13053 u.width,13572 u.width,
13054- u.true_width,13573+ frame_w.div_ceil(2),
13055- u.true_height,13574+ frame_h.div_ceil(2),
13056 1,13575 1,
13057 lr.frame_restoration_type[1],13576 lr.frame_restoration_type[1],
13058 lr.loop_restoration_size[1],13577 lr.loop_restoration_size[1],
@@ -13063,8 +13582,8 @@ fn apply_loop_restoration(
13063 &v.data,13582 &v.data,
13064 &deblocked_v.data,13583 &deblocked_v.data,
13065 v.width,13584 v.width,
13066- v.true_width,13585+ frame_w.div_ceil(2),
13067- v.true_height,13586+ frame_h.div_ceil(2),
13068 1,13587 1,
13069 lr.frame_restoration_type[2],13588 lr.frame_restoration_type[2],
13070 lr.loop_restoration_size[2],13589 lr.loop_restoration_size[2],
@@ -13626,12 +14145,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13626 // the first block of that row.14145 // the first block of that row.
13627 match (has_cols, has_rows) {14146 match (has_cols, has_rows) {
13628 (true, false) => {14147 (true, false) => {
14148+ trace_edge((sb_r * SB_MI) as usize, (sb_c * SB_MI) as usize, 12, ctx, dec.debug_state().0 as u32);
13629 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));14149 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));
14150+ bump_edge32(4 + b.min(1) as usize);
13630 bump_edge_part(b.min(1) as usize);14151 bump_edge_part(b.min(1) as usize);
13631 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }14152 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
13632 }14153 }
13633 (false, true) => {14154 (false, true) => {
14155+ trace_edge((sb_r * SB_MI) as usize, (sb_c * SB_MI) as usize, 12, ctx, dec.debug_state().0 as u32);
13634 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));14156 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));
14157+ bump_edge32(4 + b.min(1) as usize);
13635 bump_edge_part(b.min(1) as usize);14158 bump_edge_part(b.min(1) as usize);
13636 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }14159 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
13637 }14160 }
@@ -13696,18 +14219,22 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13696 // superblock level above).14219 // superblock level above).
13697 match (has_cols32, has_rows32) {14220 match (has_cols32, has_rows32) {
13698 (true, false) => {14221 (true, false) => {
14222+ trace_edge((r32 * BLOCK_MI) as usize, (c32 * BLOCK_MI) as usize, 9, ctx32, dec.debug_state().0 as u32);
13699 let b = dec.symbol_fixed(&gather(14223 let b = dec.symbol_fixed(&gather(
13700 &cdfs.partition_w32[ctx32],14224 &cdfs.partition_w32[ctx32],
13701 VERT_ALIKE,14225 VERT_ALIKE,
13702 ));14226 ));
14227+ bump_edge32(b.min(1) as usize);
13703 bump_edge_part(2 + b.min(1) as usize);14228 bump_edge_part(2 + b.min(1) as usize);
13704 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }14229 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
13705 }14230 }
13706 (false, true) => {14231 (false, true) => {
14232+ trace_edge((r32 * BLOCK_MI) as usize, (c32 * BLOCK_MI) as usize, 9, ctx32, dec.debug_state().0 as u32);
13707 let b = dec.symbol_fixed(&gather(14233 let b = dec.symbol_fixed(&gather(
13708 &cdfs.partition_w32[ctx32],14234 &cdfs.partition_w32[ctx32],
13709 HORZ_ALIKE,14235 HORZ_ALIKE,
13710 ));14236 ));
14237+ bump_edge32(b.min(1) as usize);
13711 bump_edge_part(2 + b.min(1) as usize);14238 bump_edge_part(2 + b.min(1) as usize);
13712 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }14239 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
13713 }14240 }
@@ -14182,6 +14709,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14182 // This path can only walk the four SPLIT14709 // This path can only walk the four SPLIT
14183 // leaves, so a 0 refuses by name instead14710 // leaves, so a 0 refuses by name instead
14184 // of desyncing.14711 // of desyncing.
14712+ trace_edge(sr * SUB_MI as usize, sc * SUB_MI as usize, 6, ctx16, dec.debug_state().0 as u32);
14185 let edge_split = if has_cols16 {14713 let edge_split = if has_cols16 {
14186 dec.symbol_fixed(&gather(14714 dec.symbol_fixed(&gather(
14187 &cdfs.partition_w16[ctx16],14715 &cdfs.partition_w16[ctx16],
@@ -14262,10 +14790,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14262 }14790 }
14263 }14791 }
14264 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);14792 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
14793+ let pre8 = dec.debug_state().0;
14265 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);14794 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
14266 if std::env::var_os("EC_AV1_TRACE").is_some() {14795 if std::env::var_os("EC_AV1_TRACE").is_some() {
14267 eprintln!(14796 eprintln!(
14268- "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"14797+ "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"
14269 );14798 );
14270 }14799 }
14271 let leaf_mode = if part8 == PARTITION_NONE {14800 let leaf_mode = if part8 == PARTITION_NONE {
@@ -14363,6 +14892,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14363 tx_select,14892 tx_select,
14364 reduced_tx_set,14893 reduced_tx_set,
14365 )?;14894 )?;
14895+ if !has_rows32 {
14896+ bump_edge32(2);
14897+ }
14366 // lane-hgkf r1: at the frame edge only the first half of the strip is14898 // lane-hgkf r1: at the frame edge only the first half of the strip is
14367 // coded (libaom `decode_partition` guards the second half with the same14899 // coded (libaom `decode_partition` guards the second half with the same
14368 // test that made this partition non-square).14900 // test that made this partition non-square).
@@ -14404,6 +14936,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14404 tx_select,14936 tx_select,
14405 reduced_tx_set,14937 reduced_tx_set,
14406 )?;14938 )?;
14939+ if !has_cols32 {
14940+ bump_edge32(3);
14941+ }
14407 // lane-hgkf r1: at the frame edge only the first half of the strip is14942 // lane-hgkf r1: at the frame edge only the first half of the strip is
14408 // coded (libaom `decode_partition` guards the second half with the same14943 // coded (libaom `decode_partition` guards the second half with the same
14409 // test that made this partition non-square).14944 // test that made this partition non-square).
@@ -14794,6 +15329,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14794 tx_select,15329 tx_select,
14795 reduced_tx_set,15330 reduced_tx_set,
14796 )?;15331 )?;
15332+ if !has_rows {
15333+ bump_edge32(6);
15334+ }
14797 // lane-golomb r1: at the frame edge only the first half of the15335 // lane-golomb r1: at the frame edge only the first half of the
14798 // strip is coded (libaom `decode_partition` guards the second15336 // strip is coded (libaom `decode_partition` guards the second
14799 // with the same has_rows test that made this partition non-square).15337 // with the same has_rows test that made this partition non-square).
@@ -14835,6 +15373,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14835 tx_select,15373 tx_select,
14836 reduced_tx_set,15374 reduced_tx_set,
14837 )?;15375 )?;
15376+ if !has_cols {
15377+ bump_edge32(7);
15378+ }
14838 // lane-golomb r1: at the frame edge only the first half of the15379 // lane-golomb r1: at the frame edge only the first half of the
14839 // strip is coded (libaom `decode_partition` guards the second15380 // strip is coded (libaom `decode_partition` guards the second
14840 // with the same has_cols test that made this partition non-square).15381 // with the same has_cols test that made this partition non-square).
@@ -15061,10 +15602,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
15061 // dump above these bisect WHICH filter stage introduced a mismatch.15602 // dump above these bisect WHICH filter stage introduced a mismatch.
15062 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);15603 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
15063 dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);15604 dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
15064- apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);15605+ apply_cdef(
15606+ &mut y,
15607+ &mut u,
15608+ &mut v,
15609+ cdef,
15610+ &neighbours,
15611+ (frame_width as usize, frame_height as usize),
15612+ );
15065 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);15613 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
15066 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);15614 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
15067- apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);15615+ apply_loop_restoration(
15616+ &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid,
15617+ (frame_width as usize, frame_height as usize),
15618+ );
15068 15619
15069 let (fw, fh) = (frame_width as usize, frame_height as usize);15620 let (fw, fh) = (frame_width as usize, frame_height as usize);
15070 if fw == width && fh == height {15621 if fw == width && fh == height {
@@ -15465,10 +16016,9 @@ fn read_inter_plane(
15465 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's16016 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's
15466 // chroma plane never codes its own `tx_type` symbol, but (unlike an16017 // chroma plane never codes its own `tx_type` symbol, but (unlike an
15467 // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits16018 // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits
15468- // the colocated luma transform's coded type verbatim, clamped back to16019+ // the colocated luma transform's coded type, narrowed to the extended
15469- // `DCT_DCT` at the chroma tx sizes the spec forces DCT-only16020+ // set the CHROMA size selects ([`reduce_inherited_chroma_tx_type`]).
15470- // (`av1_get_ext_tx_set_type`: `tx_size_sqr_up >= TX_32X32`, i.e. this16021+ // `None` for the luma call itself
15471- // function's own `side >= 32`). `None` for the luma call itself
15472 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true16022 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true
15473 // `DCT_DCT` default at 32-point+) already resolves it without help.16023 // `DCT_DCT` default at 32-point+) already resolves it without help.
15474 inherited_luma_tx_type: Option<TxType>,16024 inherited_luma_tx_type: Option<TxType>,
@@ -15486,8 +16036,8 @@ fn read_inter_plane(
15486 };16036 };
15487 let mut coding = cdfs.txb(set, tx_mode);16037 let mut coding = cdfs.txb(set, tx_mode);
15488 let default_tx_type = match inherited_luma_tx_type {16038 let default_tx_type = match inherited_luma_tx_type {
15489- Some(t) if side < 32 => t,16039+ Some(t) => reduce_inherited_chroma_tx_type(t, side, side),
15490- _ => TxType::DctDct,16040+ None => TxType::DctDct,
15491 };16041 };
15492 let (grid, tx_type) = read_coeffs(16042 let (grid, tx_type) = read_coeffs(
15493 dec,16043 dec,
@@ -15880,11 +16430,11 @@ fn obmc_mask(len: usize) -> &'static [u8] {
15880 /// A bordering block's own resolved interp filter kernel, `(h, v)` --16430 /// A bordering block's own resolved interp filter kernel, `(h, v)` --
15881 /// mirrors [`resolve_interp_filter`]'s own return order from its stored16431 /// mirrors [`resolve_interp_filter`]'s own return order from its stored
15882 /// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` =16432 /// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` =
15883-/// `[v_sym, h_sym]`). Never calls `from_switchable_symbol` on the `[3, 3]`16433+/// `[v_sym, h_sym]`). The `[3, 3]` sentinel is only ever stored for an intra
15884-/// sentinel: that value is only ever stored for an intra neighbour (already16434+/// neighbour (excluded by [`overlappable_above`]/[`overlappable_left`]'s
15885-/// excluded by [`overlappable_above`]/[`overlappable_left`]'s `is_inter`16435+/// `is_inter` gate) or when `interp_fixed` is `Some` for the whole frame
15886-/// gate) or when `interp_fixed` is `Some` for the whole frame, handled here16436+/// (handled here first) -- so a sentinel reaching the kernel lookup means the
15887-/// first.16437+/// stream desynced upstream, and this refuses instead of panicking.
15888 fn neighbour_filter(16438 fn neighbour_filter(
15889 interp_fixed: Option<mc::InterpFilterKind>,16439 interp_fixed: Option<mc::InterpFilterKind>,
15890 sym: [u8; 2],16440 sym: [u8; 2],
@@ -15892,15 +16442,15 @@ fn neighbour_filter(
15892 if let Some(kind) = interp_fixed {16442 if let Some(kind) = interp_fixed {
15893 return Ok((kind, kind));16443 return Ok((kind, kind));
15894 }16444 }
15895- // lane-interp3 r1: the `[3, 3]` sentinel reaching here is a DEFECT in16445+ // lane-golomb r9: this used to hand the sentinel straight to
15896- // whatever path recorded the neighbour (an inter block that never stored16446+ // `from_switchable_symbol`, which PANICS on any value above 2 -- a crash
15897- // its own switchable symbols), and it used to abort the process through16447+ // on stream data (measured on a real 192x68 cq40 aomenc stream, where an
15898- // `from_switchable_symbol`'s panic. A decoder must never crash on a real16448+ // inter leaf below 8x8 desyncs upstream and leaves an unrecorded filter
15899- // stream: it stops by name instead, so the frame is refused and the16449+ // behind). A decoder must refuse such a stream by name, never abort the
15900- // stream is pinned like every other unsupported case.16450+ // process; the desync that produces the sentinel belongs to lane-intersub8.
15901 if sym[0] > 2 || sym[1] > 2 {16451 if sym[0] > 2 || sym[1] > 2 {
15902 return Err(unsupported(16452 return Err(unsupported(
15903- "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)",16453+ "an OBMC neighbour whose switchable interp filter was never recorded",
15904 ));16454 ));
15905 }16455 }
15906 Ok((16456 Ok((
@@ -19471,21 +20021,21 @@ fn decode_inter_block(
19471 },20021 },
19472 );20022 );
19473 // lane-txselect: a var-tx block's deblock edges follow its own transform20023 // lane-txselect: a var-tx block's deblock edges follow its own transform
19474- // units, not the block. Chroma still reads `tx_h_grid / 2` (the block's20024+ // units, not the block -- for LUMA only (lane-golomb r6): the chroma
19475- // uv transform is not split) -- a known corner-cut of this round.20025+ // grids keep the block's own `av1_get_max_uv_txsize`, which is what
20026+ // libaom's `get_transform_size` reads for `plane != AOM_PLANE_Y`.
19476 if let Some(leaves) = &vartx_leaves {20027 if let Some(leaves) = &vartx_leaves {
19477 for &(row, col, tw, th) in leaves {20028 for &(row, col, tw, th) in leaves {
19478- neighbours.fill_lf_grid_rect(20029+ // lane-r14's RECT leaf dims through lane-golomb r6's luma-only
20030+ // writer: fill_lf_grid_rect would recompute CHROMA tx dims from
20031+ // the leaf span, but libaom's `get_transform_size` splits only for
20032+ // AOM_PLANE_Y (merge J, ledger constraint).
20033+ neighbours.fill_lf_grid_leaf_luma(
19479 (at_mi.0 + row, at_mi.1 + col),20034 (at_mi.0 + row, at_mi.1 + col),
19480 tw / MI,20035 tw / MI,
19481 th / MI,20036 th / MI,
19482 tw as u8,20037 tw as u8,
19483 th as u8,20038 th as u8,
19484- if globalmv_for_lf {
19485- -ref_frame_for_lf
19486- } else {
19487- ref_frame_for_lf
19488- },
19489 );20039 );
19490 }20040 }
19491 }20041 }
@@ -22446,7 +22996,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22446 // true size. Height must still match: AV1 superres never scales height22996 // true size. Height must still match: AV1 superres never scales height
22447 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path22997 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path
22448 // has a vertical scaling pass.22998 // has a vertical scaling pass.
22449- if reference.height != true_height {22999+ // lane-golomb r8: the comparison is against the header's own frame
23000+ // height, NOT the mi-rounded `true_height`. libaom compares references
23001+ // on the CROPPED dimensions -- `av1_setup_scale_factors_for_frame(&sf,
23002+ // ref->y_crop_width, ref->y_crop_height, cm->width, cm->height)`
23003+ // (`av1/common/reconinter.c`), and a reference is "scaled" only when
23004+ // those differ (`av1_is_scaled`). A decoded `Picture` is cropped to
23005+ // `fw`/`fh`, so for any height that is not a multiple of 8 (68 ->
23006+ // mi_rows 18 -> `true_height` 72) this test compared 68 against 72 and
23007+ // refused every same-size reference (class av1-truesize-lane: true
23008+ // frame size vs mi-rounded). Height must still MATCH: AV1 superres
23009+ // never scales height, and no path here has a vertical scaling pass.
23010+ if reference.height != frame_height as usize {
22450 return Err(unsupported(23011 return Err(unsupported(
22451 "a reference picture whose height does not match this frame's own true size",23012 "a reference picture whose height does not match this frame's own true size",
22452 ));23013 ));
@@ -22887,7 +23448,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22887 // lane-golomb r1 (class `parsed-then-discarded`): the gathered23448 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
22888 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT23449 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
22889 // (libaom `ec_read_partition_impl`).23450 // (libaom `ec_read_partition_impl`).
22890- if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)) == 1 {23451+ if bump_edge32_bit(
23452+ 4,
23453+ dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
23454+ ) == 1 {
22891 PARTITION_SPLIT23455 PARTITION_SPLIT
22892 } else {23456 } else {
22893 PARTITION_HORZ23457 PARTITION_HORZ
@@ -22897,7 +23461,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22897 // lane-golomb r1 (class `parsed-then-discarded`): the gathered23461 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
22898 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT23462 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
22899 // (libaom `ec_read_partition_impl`).23463 // (libaom `ec_read_partition_impl`).
22900- if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)) == 1 {23464+ if bump_edge32_bit(
23465+ 4,
23466+ dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)),
23467+ ) == 1 {
22901 PARTITION_SPLIT23468 PARTITION_SPLIT
22902 } else {23469 } else {
22903 PARTITION_VERT23470 PARTITION_VERT
@@ -23073,7 +23640,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
23073 // lane-golomb r1 (class `parsed-then-discarded`): the gathered23640 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
23074 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT23641 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
23075 // (libaom `ec_read_partition_impl`).23642 // (libaom `ec_read_partition_impl`).
23076- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 {23643+ if {
23644+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));
23645+ bump_edge32(b.min(1) as usize);
23646+ b
23647+ } == 1 {
23077 PARTITION_SPLIT23648 PARTITION_SPLIT
23078 } else {23649 } else {
23079 PARTITION_HORZ23650 PARTITION_HORZ
@@ -23083,7 +23654,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
23083 // lane-golomb r1 (class `parsed-then-discarded`): the gathered23654 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
23084 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT23655 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
23085 // (libaom `ec_read_partition_impl`).23656 // (libaom `ec_read_partition_impl`).
23086- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 {23657+ if {
23658+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE));
23659+ bump_edge32(b.min(1) as usize);
23660+ b
23661+ } == 1 {
23087 PARTITION_SPLIT23662 PARTITION_SPLIT
23088 } else {23663 } else {
23089 PARTITION_VERT23664 PARTITION_VERT
@@ -23903,6 +24478,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
23903 allow_screen_content_tools,24478 allow_screen_content_tools,
23904 frame_width as usize,24479 frame_width as usize,
23905 )?;24480 )?;
24481+ if !has_rows32 {
24482+ bump_edge32(2);
24483+ }
24484+ // lane-golomb r2: at the frame edge only the first half of the
24485+ // strip is coded (libaom `decode_partition` guards the second
24486+ // with the same has_rows32 test that made this partition non-square).
24487+ if has_rows32 {
23906 decode_inter_block(24488 decode_inter_block(
23907 &mut dec,24489 &mut dec,
23908 &mut cdfs,24490 &mut cdfs,
@@ -23953,6 +24535,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
23953 frame_width as usize,24535 frame_width as usize,
23954 )?;24536 )?;
23955 }24537 }
24538+ }
23956 PARTITION_VERT => {24539 PARTITION_VERT => {
23957 // lane-rect r2: mirror of PARTITION_HORZ above with24540 // lane-rect r2: mirror of PARTITION_HORZ above with
23958 // width/height swapped.24541 // width/height swapped.
@@ -24006,6 +24589,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24006 allow_screen_content_tools,24589 allow_screen_content_tools,
24007 frame_width as usize,24590 frame_width as usize,
24008 )?;24591 )?;
24592+ if !has_cols32 {
24593+ bump_edge32(3);
24594+ }
24595+ // lane-golomb r2: at the frame edge only the first half of the
24596+ // strip is coded (libaom `decode_partition` guards the second
24597+ // with the same has_cols32 test that made this partition non-square).
24598+ if has_cols32 {
24009 decode_inter_block(24599 decode_inter_block(
24010 &mut dec,24600 &mut dec,
24011 &mut cdfs,24601 &mut cdfs,
@@ -24056,6 +24646,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24056 frame_width as usize,24646 frame_width as usize,
24057 )?;24647 )?;
24058 }24648 }
24649+ }
24059 PARTITION_HORZ_A => {24650 PARTITION_HORZ_A => {
24060 // lane-partab r1: two 16x16 squares on top + a true24651 // lane-partab r1: two 16x16 squares on top + a true
24061 // 32x16 strip below (libaom decode_partition24652 // 32x16 strip below (libaom decode_partition
@@ -24638,10 +25229,20 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24638 // dump above these bisect WHICH filter stage introduced a mismatch.25229 // dump above these bisect WHICH filter stage introduced a mismatch.
24639 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);25230 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
24640 dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);25231 dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
24641- apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);25232+ apply_cdef(
25233+ &mut y,
25234+ &mut u,
25235+ &mut v,
25236+ cdef,
25237+ &neighbours,
25238+ (frame_width as usize, frame_height as usize),
25239+ );
24642 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);25240 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
24643 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);25241 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
24644- apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);25242+ apply_loop_restoration(
25243+ &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid,
25244+ (frame_width as usize, frame_height as usize),
25245+ );
24645 25246
24646 let motion_field = build_motion_field(25247 let motion_field = build_motion_field(
24647 &grid,25248 &grid,
@@ -24714,6 +25315,36 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
24714 #[cfg(test)]25315 #[cfg(test)]
24715 mod tests {25316 mod tests {
24716 25317
25318+ /// lane-golomb r7: [`reduce_inherited_chroma_tx_type`] must reproduce
25319+ /// `av1_ext_tx_used[av1_get_ext_tx_set_type(uv_tx, 1, reduced)]`
25320+ /// (libaom `av1/common/blockd.h:1036`/`1097`) exactly -- the g35 residue
25321+ /// was one 64x64 inter superblock whose 32x32 chroma units are
25322+ /// `EXT_TX_SET_DCT_IDTX`, where IDTX survives and we forced `DCT_DCT`.
25323+ #[test]
25324+ fn an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set() {
25325+ use TxType::*;
25326+ // EXT_TX_SET_DCTONLY: `tx_size_sqr_up > TX_32X32`.
25327+ set_inter_tx_mode(true, false, true);
25328+ assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 64, 64), DctDct);
25329+ // EXT_TX_SET_DCT_IDTX at exactly TX_32X32 -- the residue's case.
25330+ assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 32, 32), Idtx);
25331+ assert_eq!(reduce_inherited_chroma_tx_type(AdstAdst, 32, 32), DctDct);
25332+ // EXT_TX_SET_DTT9_IDTX_1DDCT at `tx_size_sqr == TX_16X16`: the four
25333+ // 1D ADST/FLIPADST types (TX_TYPES 12..15) drop out, the rest stay.
25334+ assert_eq!(reduce_inherited_chroma_tx_type(HDct, 16, 16), HDct);
25335+ assert_eq!(reduce_inherited_chroma_tx_type(FlipAdstAdst, 16, 16), FlipAdstAdst);
25336+ assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 16), DctDct);
25337+ // EXT_TX_SET_ALL16 below that (`tx_size_sqr < TX_16X16`, so a 16x8
25338+ // chroma unit too).
25339+ assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 8), HAdst);
25340+ assert_eq!(reduce_inherited_chroma_tx_type(VFlipAdst, 8, 8), VFlipAdst);
25341+ // `reduced_tx_set` collapses every inter set to DCT_IDTX.
25342+ set_inter_tx_mode(true, true, true);
25343+ assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 8, 8), Idtx);
25344+ assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 8, 8), DctDct);
25345+ set_inter_tx_mode(true, false, true);
25346+ }
25347+
24717 /// lane-fistrip r1 (class `enumerate-the-table-domain`): every block25348 /// lane-fistrip r1 (class `enumerate-the-table-domain`): every block
24718 /// shape this decoder can hand [`filter_intra_size_class_rect`], against25349 /// shape this decoder can hand [`filter_intra_size_class_rect`], against
24719 /// `av1_filter_intra_allowed_bsize` (`block_size_wide <= 32 &&25350 /// `av1_filter_intra_allowed_bsize` (`block_size_wide <= 32 &&
crates/ec-av1/src/refusal_inventory.rsmodified+3 -2
@@ -31,13 +31,14 @@ const CAPABILITY_CLAIMS: &[&str] = &[
31 const REFUSALS: &[&str] = &[31 const REFUSALS: &[&str] = &[
32 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",32 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
33 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",33 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
34- "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)",
35 "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)",34 "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)",
36 "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)",35 "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)",
37 "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",36 "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
38 "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)",37 "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)",
39 "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",38 "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
40 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",39 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
40+ "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
41+ "an OBMC neighbour whose switchable interp filter was never recorded",
41 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",42 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
42 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",43 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
43 "a 32x32 partition type this decoder does not code (value={part32})",44 "a 32x32 partition type this decoder does not code (value={part32})",
@@ -48,10 +49,10 @@ const REFUSALS: &[&str] = &[
48 "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)",49 "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)",
49 "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)",50 "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)",
50 "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)",51 "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)",
51- "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",
52 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",52 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
53 "a block that actually uses a palette (UV) -- reconstruction is out of scope",53 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
54 "a block that actually uses a palette (Y) -- reconstruction is out of scope",54 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
55+ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
55 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",56 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
56 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",57 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
57 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",58 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
crates/ec-av1/src/stream.rsmodified+1124 -3
@@ -81,6 +81,11 @@ pub fn vartx_rect_leaf_hits() -> [usize; 2] {
81 crate::decode::vartx_rect_leaf_hits()81 crate::decode::vartx_rect_leaf_hits()
82 }82 }
83 83
84+/// How many rect intra strips read the `use_intrabc` symbol on the last decode.
85+pub fn rect_intrabc_reads() -> usize {
86+ crate::decode::rect_intrabc_reads()
87+}
88+
84 pub fn rect4_32_counters() -> (usize, usize, usize) {89 pub fn rect4_32_counters() -> (usize, usize, usize) {
85 (90 (
86 crate::decode::rect4_32_horz_hits(),91 crate::decode::rect4_32_horz_hits(),
@@ -2579,6 +2584,541 @@ mod tests {
2579 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");2584 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");
2580 }2585 }
2581 2586
2587+ /// lane-kf900 r3: the palette colour reader at BOTH bit depths.
2588+ ///
2589+ /// `read_palette_colors_y`/`_uv` (decode.rs, mirroring `decodemv.c:478`
2590+ /// and `:509`) size every raw literal they read by the sequence's
2591+ /// `bit_depth`: the first colour is `bit_depth` bits, `min_bits` is
2592+ /// `bit_depth - 3` (Y/U) or `bit_depth - 4` (V), `range` starts at
2593+ /// `1 << bit_depth`, and the clamp/wrap bound is `(1 << bit_depth) - 1`.
2594+ /// Ours hardcoded 8, so every 10-bit palette block read TWO BITS TOO FEW
2595+ /// per transmitted colour and silently decoded the rest of the tile from
2596+ /// the wrong bit position.
2597+ ///
2598+ /// It was silent because raw literals are EQUIPROBABLE: at the ranges
2599+ /// this content reaches an equiprobable read maps the msac range onto
2600+ /// itself (62728 -> 31364 -> renormalised 62728), so a cross-decoder
2601+ /// RANGE ladder stays bit-identical straight through the miscount and
2602+ /// only the decoded VALUE moves. Pinned on a 256x192 10-bit
2603+ /// `--cq-level=59` stream whose first block is a 32x16 palette: aomdec's
2604+ /// `EC_PAL` ladder and ours agreed on every range and disagreed on the
2605+ /// very first colour index (0 vs 1); after the fix all 1024 `EC_PAL`
2606+ /// lines of that block match aomdec line for line.
2607+ ///
2608+ /// The recipe is the 8-bit `..._with_palette_y_...` gate's, with the
2609+ /// depth as the only variable, so a failure here is the depth and
2610+ /// nothing else. HARD-asserts [`decode::palette_hits`] moved on each arm
2611+ /// (a stream with no real palette block would prove nothing) and
2612+ /// compares all three planes against ffmpeg's decode of the same bytes.
2613+ #[test]
2614+ fn a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit() {
2615+ const NAME: &str = "a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit";
2616+ if !have_ffmpeg() {
2617+ eprintln!("SKIP {NAME}: no ffmpeg");
2618+ return;
2619+ }
2620+ if !have_aomenc() {
2621+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2622+ return;
2623+ }
2624+ let (width, height) = (64usize, 64usize);
2625+ for depth in [8usize, 10] {
2626+ let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
2627+ let render = || {
2628+ Command::new("ffmpeg")
2629+ .args([
2630+ "-v", "error",
2631+ "-f", "lavfi",
2632+ "-i", "smptebars=size=64x64:rate=25",
2633+ "-vf", "hue=s=0",
2634+ "-pix_fmt", pix_fmt,
2635+ "-strict", "-1",
2636+ "-t", "0.04",
2637+ "-f", "yuv4mpegpipe",
2638+ "-",
2639+ ])
2640+ .stdin(Stdio::null())
2641+ .stdout(Stdio::piped())
2642+ .stderr(Stdio::piped())
2643+ .output()
2644+ .expect("ffmpeg failed to run")
2645+ .stdout
2646+ };
2647+ let y4m_a = render();
2648+ let y4m_b = render();
2649+ assert_eq!(
2650+ y4m_a, y4m_b,
2651+ "{NAME}: smptebars must render byte-identical across two runs at {depth}-bit"
2652+ );
2653+ let y4m = y4m_a;
2654+ let depth_arg = format!("--bit-depth={depth}");
2655+ let input_depth_arg = format!("--input-bit-depth={depth}");
2656+ let mut child = Command::new(aomenc_path())
2657+ .args([
2658+ "--codec=av1",
2659+ "--passes=1",
2660+ "--end-usage=q",
2661+ "--cq-level=30",
2662+ "--cpu-used=0",
2663+ "--threads=1",
2664+ "--row-mt=0",
2665+ "--sb-size=64",
2666+ "--tune-content=screen",
2667+ "--enable-palette=1",
2668+ "--enable-intrabc=0",
2669+ "--enable-rect-partitions=0",
2670+ "--enable-ab-partitions=0",
2671+ "--enable-1to4-partitions=0",
2672+ "--min-partition-size=32",
2673+ "--max-partition-size=32",
2674+ "--enable-filter-intra=0",
2675+ "--enable-smooth-intra=0",
2676+ "--enable-paeth-intra=0",
2677+ "--enable-directional-intra=0",
2678+ "--enable-angle-delta=0",
2679+ "--enable-cfl-intra=0",
2680+ "--enable-cdef=0",
2681+ "--enable-restoration=0",
2682+ "--enable-tx-size-search=0",
2683+ "--loopfilter-control=0",
2684+ "--limit=1",
2685+ ])
2686+ // Per-arm overrides go AFTER the base recipe: aomenc keeps the
2687+ // LAST occurrence of a repeated flag.
2688+ .args([&depth_arg, &input_depth_arg])
2689+ .args(["--obu", "-o", "-", "-"])
2690+ .stdin(Stdio::piped())
2691+ .stdout(Stdio::piped())
2692+ .stderr(Stdio::piped())
2693+ .spawn()
2694+ .expect("aomenc failed to start");
2695+ child
2696+ .stdin
2697+ .take()
2698+ .expect("aomenc stdin")
2699+ .write_all(&y4m)
2700+ .expect("writing y4m to aomenc");
2701+ let out = child.wait_with_output().expect("aomenc failed to run");
2702+ assert!(
2703+ out.status.success(),
2704+ "{NAME}: aomenc refused the {depth}-bit fixture: {}",
2705+ String::from_utf8_lossy(&out.stderr)
2706+ );
2707+ let stream = out.stdout;
2708+ let before = decode::palette_hits();
2709+ let frames = match decode_stream(&stream) {
2710+ Ok(frames) => frames,
2711+ Err(e) => panic!("{NAME}: decode_stream refused the {depth}-bit stream: {e}"),
2712+ };
2713+ assert!(
2714+ decode::palette_hits() > before,
2715+ "{NAME}: no real palette block at {depth}-bit -- gate is vacuous"
2716+ );
2717+ let ffmpeg_frames = if depth == 10 {
2718+ ffmpeg_decode_sequence_10bit(&stream, width, height, 1)
2719+ } else {
2720+ ffmpeg_decode_sequence(&stream, width, height, 1)
2721+ };
2722+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma at {depth}-bit");
2723+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U at {depth}-bit");
2724+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V at {depth}-bit");
2725+ }
2726+ }
2727+
2728+ /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read.
2729+ ///
2730+ /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`,
2731+ /// `read_intra_frame_mode_info`): on an intra frame whose header set
2732+ /// `allow_intrabc`, EVERY intra block reads a `use_intrabc` symbol right
2733+ /// after `skip`/`cdef`/`delta_q` and before `mbmi->mode`. There is no
2734+ /// block-shape term, so rect strips read it exactly like square leaves --
2735+ /// `read_intra_mode_rect` never did, and the arithmetic decoder desynced
2736+ /// at the FIRST symbol of the first rect block of every
2737+ /// `--tune-content=screen` key frame (measured: `testsrc2` 256x192 cq59
2738+ /// 8-bit decoded "OK" with all 49152 luma samples wrong).
2739+ ///
2740+ /// Arm 0 is that recipe at cq50 without palette: its rect strips really do
2741+ /// use intrabc, which this decoder cannot reconstruct, so it must stop on
2742+ /// the NAMED refusal instead of emitting a wrong frame -- and it must have
2743+ /// read the symbol to get there.
2744+ /// Arm 1 is the same recipe without palette and without tx-size search --
2745+ /// it decodes the whole frame, reading the symbol dozens of times.
2746+ /// Arm 2 is a screen-tools key frame whose header does NOT set
2747+ /// `allow_intrabc` (cq63): it stays pixel-exact, proving the new read is
2748+ /// not taken when libaom does not write it.
2749+ ///
2750+ /// PIXEL RESIDUE (open, lane-kf900 r5): arm 1's frame is entropy-exact
2751+ /// against the instrumented aomdec for 429 mode-ladder elements and then
2752+ /// diverges inside the DV read of a SQUARE intrabc block at mi(32,44), so
2753+ /// its pixels are not compared here. That is a separate defect in
2754+ /// `read_intrabc_dv`, not in the read this gate covers.
2755+ #[test]
2756+ fn a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips() {
2757+ const NAME: &str = "a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips";
2758+ if !have_ffmpeg() {
2759+ eprintln!("SKIP {NAME}: no ffmpeg");
2760+ return;
2761+ }
2762+ if !have_aomenc() {
2763+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2764+ return;
2765+ }
2766+ let (width, height) = (256usize, 192usize);
2767+ // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal,
2768+ // must_read_use_intrabc)
2769+ let arms: [(&str, &str, &[&str], bool, bool); 3] = [
2770+ (
2771+ "testsrc2-screen-nopalette-cq50",
2772+ "testsrc2=s=256x192:r=25",
2773+ &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"],
2774+ true,
2775+ true,
2776+ ),
2777+ (
2778+ "smptebars-screen-nopalette-cq45",
2779+ "smptebars=size=256x192:rate=25",
2780+ &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"],
2781+ false,
2782+ true,
2783+ ),
2784+ (
2785+ "testsrc2-screen-nopalette-cq63",
2786+ "testsrc2=s=256x192:r=25",
2787+ &["--cq-level=63", "--enable-palette=0", "--enable-tx-size-search=1"],
2788+ false,
2789+ false,
2790+ ),
2791+ ];
2792+ let (mut reads_total, mut refused, mut frames_compared) = (0usize, 0u32, 0usize);
2793+ for (arm, src, extra, expect_refusal, must_read) in &arms {
2794+ let render = || {
2795+ let out = Command::new("ffmpeg")
2796+ .args([
2797+ "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt",
2798+ "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-",
2799+ ])
2800+ .stdin(Stdio::null())
2801+ .stdout(Stdio::piped())
2802+ .stderr(Stdio::piped())
2803+ .output()
2804+ .expect("ffmpeg failed to run");
2805+ assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}");
2806+ out.stdout
2807+ };
2808+ let y4m_a = render();
2809+ let y4m_b = render();
2810+ assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs");
2811+ let y4m = y4m_a;
2812+ let mut child = Command::new(aomenc_path())
2813+ .args([
2814+ "--codec=av1",
2815+ "--bit-depth=8",
2816+ "--input-bit-depth=8",
2817+ "--passes=1",
2818+ "--end-usage=q",
2819+ "--cpu-used=0",
2820+ "--lag-in-frames=0",
2821+ "--kf-max-dist=1",
2822+ "--limit=1",
2823+ "--threads=1",
2824+ "--tile-columns=0",
2825+ "--enable-rect-partitions=1",
2826+ "--enable-1to4-partitions=1",
2827+ "--min-partition-size=8",
2828+ "--max-partition-size=32",
2829+ "--sb-size=64",
2830+ // `allow_screen_content_tools` (and with it the frame
2831+ // header's `allow_intrabc` bit) comes from here.
2832+ "--tune-content=screen",
2833+ ])
2834+ // aomenc keeps the LAST occurrence of a repeated flag.
2835+ .args(*extra)
2836+ .args(["--obu", "-o", "-", "-"])
2837+ .stdin(Stdio::piped())
2838+ .stdout(Stdio::piped())
2839+ .stderr(Stdio::piped())
2840+ .spawn()
2841+ .expect("aomenc failed to start");
2842+ child
2843+ .stdin
2844+ .take()
2845+ .expect("aomenc stdin")
2846+ .write_all(&y4m)
2847+ .or_else(|e| match e.kind() {
2848+ std::io::ErrorKind::BrokenPipe => Ok(()),
2849+ _ => Err(e),
2850+ })
2851+ .expect("writing y4m to aomenc");
2852+ let out = child.wait_with_output().expect("aomenc failed to run");
2853+ assert!(
2854+ out.status.success(),
2855+ "{NAME}: aomenc refused {arm}: {}",
2856+ String::from_utf8_lossy(&out.stderr)
2857+ );
2858+ let stream = out.stdout;
2859+ decode::reset_rect_intrabc_reads();
2860+ let decoded = decode_stream(&stream);
2861+ let reads = decode::rect_intrabc_reads();
2862+ reads_total += reads;
2863+ if *must_read {
2864+ assert!(
2865+ reads > 0,
2866+ "{NAME}: {arm} read no use_intrabc symbol on a rect strip -- the \
2867+ arm no longer exercises the fix (allow_intrabc not set?)"
2868+ );
2869+ }
2870+ match decoded {
2871+ Ok(frames) => {
2872+ assert!(
2873+ !*expect_refusal,
2874+ "{NAME}: {arm} decoded a frame whose rect strips use intrabc -- \
2875+ reconstruction is not ported, it must refuse by name"
2876+ );
2877+ assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame");
2878+ if *must_read {
2879+ // Arm 1: entropy coverage only (see PIXEL RESIDUE above).
2880+ eprintln!("{NAME}: {arm} decoded {} frame(s), {reads} rect use_intrabc reads", frames.len());
2881+ continue;
2882+ }
2883+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
2884+ assert_eq!(frames.len(), ffmpeg_frames.len(), "{NAME}: {arm} frame count");
2885+ for (i, (ours, theirs)) in frames.iter().zip(ffmpeg_frames.iter()).enumerate() {
2886+ assert_eq!(ours.y, theirs.y, "{NAME}: {arm} luma, frame {i}");
2887+ assert_eq!(ours.u, theirs.u, "{NAME}: {arm} U, frame {i}");
2888+ assert_eq!(ours.v, theirs.v, "{NAME}: {arm} V, frame {i}");
2889+ frames_compared += 1;
2890+ }
2891+ }
2892+ Err(e) => {
2893+ let msg = e.to_string();
2894+ assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}");
2895+ assert!(
2896+ *expect_refusal,
2897+ "{NAME}: {arm} was expected to decode, it refused: {e}"
2898+ );
2899+ assert!(
2900+ msg.contains("intra block copy") || msg.contains("intrabc"),
2901+ "{NAME}: {arm} refused for an unrelated reason: {e}"
2902+ );
2903+ eprintln!("{NAME}: {arm} REFUSED (expected): {e}");
2904+ refused += 1;
2905+ }
2906+ }
2907+ }
2908+ eprintln!(
2909+ "{NAME}: {reads_total} rect-strip use_intrabc symbol(s) read, \
2910+ {refused} refused by name, {frames_compared} frames compared pixel-exact"
2911+ );
2912+ assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol");
2913+ assert_eq!(refused, 1, "{NAME}: expected exactly one named intrabc refusal");
2914+ assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact");
2915+ }
2916+
2917+ /// lane-kf900 r4, the gate for the two lifted palette refusals ("a 1:4
2918+ /// rect strip that actually uses a palette (reconstruction is not ported
2919+ /// at this shape)" and "a palette block on a HORZ/VERT intra strip below
2920+ /// 16x16 (reconstruction not ported)"): real `aomenc` streams that put a
2921+ /// palette on a RECT strip, decoded whole-frame pixel-exact against
2922+ /// ffmpeg's own decode of the identical bytes, at 8 AND 10 bit.
2923+ ///
2924+ /// Arm 0 is the stream lane-kf900 r3 pinned and stopped on -- `testsrc2`
2925+ /// 256x192, `--cq-level=59 --cpu-used=0 --min-partition-size=8
2926+ /// --enable-rect-partitions=1 --enable-tx-size-search=1`, md5
2927+ /// `e5f033d8fe34e4418d8cca3ac9d2b595` at 10 bit. Arms 1-2 force the shape
2928+ /// on screen-like content with `--tune-content=screen --enable-palette=1
2929+ /// --enable-1to4-partitions=1`.
2930+ ///
2931+ /// An attempt whose decode never hit a rect-strip palette block proves
2932+ /// nothing about the lift, so it is counted OUT OF SCOPE rather than
2933+ /// silently passing -- but a mismatch on one is still a failure
2934+ /// (`out_of_scope_mismatch == 0`), and at least one attempt must fire the
2935+ /// counter or the gate is vacuous.
2936+ #[test]
2937+ fn a_real_aomenc_rect_strip_palette_decodes_pixel_exact() {
2938+ const NAME: &str = "a_real_aomenc_rect_strip_palette_decodes_pixel_exact";
2939+ if !have_ffmpeg() {
2940+ eprintln!("SKIP {NAME}: no ffmpeg");
2941+ return;
2942+ }
2943+ if !have_aomenc() {
2944+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2945+ return;
2946+ }
2947+ let (width, height) = (256usize, 192usize);
2948+ let screen: &[&str] = &[
2949+ "--tune-content=screen",
2950+ "--enable-palette=1",
2951+ "--enable-1to4-partitions=1",
2952+ "--min-partition-size=8",
2953+ ];
2954+ let arms: [(&str, String, &[&str]); 3] = [
2955+ ("testsrc2-pinned", "testsrc2=s=256x192:r=25".to_string(), &[]),
2956+ ("testsrc2-screen", "testsrc2=s=256x192:r=25".to_string(), screen),
2957+ ("smptebars-screen", "smptebars=size=256x192:rate=25".to_string(), screen),
2958+ ];
2959+ let (mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32, 0u32);
2960+ let mut refused = 0u32;
2961+ let mut fired_at_depth = [0u32; 2];
2962+ let mut frames_compared = 0usize;
2963+ for (arm, src, extra) in &arms {
2964+ for depth in [8usize, 10] {
2965+ let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
2966+ let render = || {
2967+ let out = Command::new("ffmpeg")
2968+ .args([
2969+ "-v", "error", "-f", "lavfi", "-i", src.as_str(), "-t", "0.2",
2970+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
2971+ ])
2972+ .stdin(Stdio::null())
2973+ .stdout(Stdio::piped())
2974+ .stderr(Stdio::piped())
2975+ .output()
2976+ .expect("ffmpeg failed to run");
2977+ assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}");
2978+ out.stdout
2979+ };
2980+ let y4m_a = render();
2981+ let y4m_b = render();
2982+ assert_eq!(
2983+ y4m_a, y4m_b,
2984+ "{NAME}: {arm} must render byte-identical across two runs at {depth}-bit"
2985+ );
2986+ let y4m = y4m_a;
2987+ let depth_arg = format!("--bit-depth={depth}");
2988+ let in_depth_arg = format!("--input-bit-depth={depth}");
2989+ let mut child = Command::new(aomenc_path())
2990+ .args(["--codec=av1"])
2991+ .args([&depth_arg, &in_depth_arg])
2992+ .args([
2993+ "--passes=1",
2994+ "--end-usage=q",
2995+ "--cq-level=59",
2996+ "--cpu-used=0",
2997+ "--lag-in-frames=0",
2998+ "--kf-max-dist=1",
2999+ "--limit=1",
3000+ "--threads=1",
3001+ "--tile-columns=0",
3002+ "--enable-tx-size-search=1",
3003+ "--min-partition-size=8",
3004+ "--enable-rect-partitions=1",
3005+ ])
3006+ // Per-arm overrides go AFTER the base recipe: aomenc keeps
3007+ // the LAST occurrence of a repeated flag.
3008+ .args(*extra)
3009+ // The 8-bit twin of the pinned recipe picks a 128-root
3010+ // HORZ partition, which this decoder still refuses by name
3011+ // ("a 128x128 superblock HORZ/VERT or AB partition") --
3012+ // an open refusal of another lane, unrelated to palette.
3013+ // Pinning the superblock to 64 keeps the 8-bit arm on the
3014+ // shape this gate is about; the 10-bit arms are the
3015+ // untouched pinned recipe.
3016+ .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] })
3017+ .args(["--obu", "-o", "-", "-"])
3018+ .stdin(Stdio::piped())
3019+ .stdout(Stdio::piped())
3020+ .stderr(Stdio::piped())
3021+ .spawn()
3022+ .expect("aomenc failed to start");
3023+ child
3024+ .stdin
3025+ .take()
3026+ .expect("aomenc stdin")
3027+ .write_all(&y4m)
3028+ .or_else(|e| match e.kind() {
3029+ // aomenc rejecting the input closes the pipe before we
3030+ // finish writing; its own stderr below is the report.
3031+ std::io::ErrorKind::BrokenPipe => Ok(()),
3032+ _ => Err(e),
3033+ })
3034+ .expect("writing y4m to aomenc");
3035+ let out = child.wait_with_output().expect("aomenc failed to run");
3036+ assert!(
3037+ out.status.success(),
3038+ "{NAME}: aomenc refused {arm} at {depth}-bit: {}",
3039+ String::from_utf8_lossy(&out.stderr)
3040+ );
3041+ let stream = out.stdout;
3042+ let before = decode::rect4_palette_hits();
3043+ let frames = match decode_stream(&stream) {
3044+ Ok(frames) => frames,
3045+ // A NAMED refusal is another lane's open shape (here: a
3046+ // palette on an 8x8 SQUARE leaf, still out of scope), never
3047+ // a pass -- the attempt is counted out of scope and the
3048+ // per-depth firing assert below keeps the gate honest.
3049+ Err(e) if e.to_string().contains("unsupported") => {
3050+ eprintln!("{NAME}: {arm} {depth}-bit REFUSED: {e}");
3051+ refused += 1;
3052+ continue;
3053+ }
3054+ Err(e) => panic!("{NAME}: decode failed on {arm} at {depth}-bit: {e}"),
3055+ };
3056+ let fired = decode::rect4_palette_hits() - before;
3057+ let ffmpeg_frames = if depth == 10 {
3058+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
3059+ } else {
3060+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
3061+ };
3062+ assert_eq!(
3063+ frames.len(),
3064+ ffmpeg_frames.len(),
3065+ "{NAME}: {arm} at {depth}-bit -- frame count"
3066+ );
3067+ assert!(!frames.is_empty(), "{NAME}: {arm} at {depth}-bit decoded no frame");
3068+ // EVERY decode-order frame, all three planes.
3069+ let mut exact = true;
3070+ for (i, (ours, theirs)) in frames.iter().zip(ffmpeg_frames.iter()).enumerate() {
3071+ if ours.y != theirs.y || ours.u != theirs.u || ours.v != theirs.v {
3072+ exact = false;
3073+ eprintln!("{NAME}: {arm} {depth}-bit frame {i} differs");
3074+ }
3075+ frames_compared += 1;
3076+ }
3077+ if fired > 0 {
3078+ fired_arms += 1;
3079+ fired_at_depth[usize::from(depth == 10)] += 1;
3080+ assert!(
3081+ exact,
3082+ "{NAME}: {arm} at {depth}-bit has {fired} rect-strip palette block(s) \
3083+ and does NOT decode pixel-exact"
3084+ );
3085+ } else {
3086+ out_of_scope += 1;
3087+ if !exact {
3088+ out_of_scope_mismatch += 1;
3089+ }
3090+ }
3091+ }
3092+ }
3093+ eprintln!(
3094+ "{NAME}: {fired_arms} attempt(s) with a rect-strip palette block, \
3095+ {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched), \
3096+ {refused} refused, {frames_compared} frames compared, \
3097+ fired 8-bit={} 10-bit={}",
3098+ fired_at_depth[0], fired_at_depth[1]
3099+ );
3100+ // MEASURED 2026-09-02, every 8-bit attempt of these recipes: aomenc
3101+ // puts its palettes on SQUARE blocks at 8 bit and every 8-bit stream
3102+ // that reaches a rect strip with one lands on a palette shape still
3103+ // out of scope (8x8 square leaf, or a 64x32/32x64 superblock strip
3104+ // with a real transform). So the 8-bit arms here prove the DECODE
3105+ // path, not the lift -- `fired_at_depth[0] == 0` is a known, reported
3106+ // coverage gap and not a silent pass: the counter is printed.
3107+ assert!(
3108+ fired_at_depth[1] > 0,
3109+ "{NAME}: no attempt put a palette on a rect strip \
3110+ (8-bit={}, 10-bit={}) -- gate is vacuous",
3111+ fired_at_depth[0],
3112+ fired_at_depth[1]
3113+ );
3114+ assert!(fired_arms > 0, "{NAME}: gate is vacuous");
3115+ assert_eq!(
3116+ out_of_scope_mismatch, 0,
3117+ "{NAME}: {out_of_scope_mismatch} attempt(s) without a rect-strip palette block \
3118+ still mismatched -- an unrelated defect, not a SKIP"
3119+ );
3120+ }
3121+
2582 /// lane-hbd r5: a real `aomenc --bit-depth=10` stream, decoded through3122 /// lane-hbd r5: a real `aomenc --bit-depth=10` stream, decoded through
2583 /// this crate's own 10-bit planes (`Picture` widened to `u16` in an3123 /// this crate's own 10-bit planes (`Picture` widened to `u16` in an
2584 /// earlier round) and checked pixel-exact against ffmpeg's own decode of3124 /// earlier round) and checked pixel-exact against ffmpeg's own decode of
@@ -3079,6 +3619,98 @@ mod tests {
3079 eprintln!("{NAME}: {skipped_cfl} skipped sub-8x8 CfL chroma blocks, frame pixel-exact");3619 eprintln!("{NAME}: {skipped_cfl} skipped sub-8x8 CfL chroma blocks, frame pixel-exact");
3080 }3620 }
3081 3621
3622+ /// lane-kf900 r2: the film's key frame at -ss 900, one frame
3623+ /// (`crates/ec-av1/fixtures/reelb_kf900.obu`, 484640 bytes, sha256
3624+ /// `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`,
3625+ /// extracted twice from independent
3626+ /// `ffmpeg -ss 900 -t 2 -i <2160p AV1 HDR10 mkv> -c:v copy -f obu` runs and
3627+ /// truncated to the first frame; both extracts hashed identically).
3628+ ///
3629+ /// This is the ONLY stream that reaches the r1 defect: a SKIPPED 8x8 intra
3630+ /// leaf whose `tx_depth` symbol resolved to `TX_4X4` still publishes 4 --
3631+ /// not its 8-pixel block side -- to the next block's `get_tx_size_context`
3632+ /// (`set_txfm_ctxs(mbmi->tx_size, bw, bh, skip_txfm && is_inter_block(...))`,
3633+ /// `decodemv.c`; the skip term is 0 for intra). It fires 15 times here and
3634+ /// zero times across 108 measured aomenc recipes, so the counter is
3635+ /// asserted against the film rather than against a synthesised stream.
3636+ ///
3637+ /// LUMA only. U/V still differ (open residue, lane-kf900 r2: 221 U and
3638+ /// 47912 V samples, max |d| 23/2, first at chroma (195, 640) -- chroma
3639+ /// RESIDUAL, the prediction there is bit-exact against aomdec's
3640+ /// `EC_PREDOUT`), so this gate pins what is proven and no more.
3641+ #[test]
3642+ fn a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact()
3643+ {
3644+ const NAME: &str = "a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact";
3645+ if !have_ffmpeg() {
3646+ eprintln!("SKIP {NAME}: no ffmpeg");
3647+ return;
3648+ }
3649+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelb_kf900.obu");
3650+ let stream = std::fs::read(&path)
3651+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
3652+ let (width, height) = (3840usize, 1608usize);
3653+ crate::decode::reset_skip_split_tx_hits();
3654+ let frames = match decode_stream(&stream) {
3655+ Ok(frames) => frames,
3656+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
3657+ };
3658+ assert_eq!(frames.len(), 1, "{NAME}: one key frame");
3659+ assert_eq!((frames[0].width, frames[0].height), (width, height));
3660+ assert!(
3661+ crate::decode::skip_split_tx_hits() >= 15,
3662+ "{NAME}: skip_split_tx_hits() == {} -- the stream that carries the tx-context \
3663+ defect stopped carrying it, so this gate proves nothing",
3664+ crate::decode::skip_split_tx_hits()
3665+ );
3666+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1);
3667+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg");
3668+ }
3669+
3670+ /// lane-kf1200 r3: the same film's `-ss 600` key frame (3840x1608, one
3671+ /// 8-px partial bottom superblock row), pinned because no aomenc recipe
3672+ /// reaches its shape -- a SKIPPED 8x8 intra leaf whose `tx_depth` resolved
3673+ /// to TX_4X4. (80 recipes swept this round: 4 frame shapes x 2 sources x
3674+ /// cq 32..63 x cpu-used 0/3 x 8/10-bit, all with
3675+ /// `--enable-tx-size-search=1 --enable-filter-intra=1`; every one came
3676+ /// back with `skip_split_tx_hits == 0`, `lanes/kf1200-r3.report.md`.)
3677+ /// An intra block reads `tx_depth` whether or not it is skipped, so the
3678+ /// leaf must record its resolved 4 -- not its 8x8 side -- in the txfm
3679+ /// context; recording 8 gave the NEXT block's `tx_depth` symbol the wrong
3680+ /// `tx_size_cdf` row (ctx 2 where libaom reads 1) and desynced the
3681+ /// entropy stream at mi (400,46). HARD-asserts `skip_split_tx_hits` moved.
3682+ #[test]
3683+ fn the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact() {
3684+ const NAME: &str = "the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact";
3685+ if !have_ffmpeg() {
3686+ eprintln!("SKIP {NAME}: no ffmpeg");
3687+ return;
3688+ }
3689+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
3690+ .join("fixtures/reelb_ss600_key_frame.obu");
3691+ let stream = std::fs::read(&path)
3692+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
3693+ let (width, height) = (3840usize, 1608usize);
3694+ crate::decode::reset_skip_split_tx_hits();
3695+ let frames = match decode_stream(&stream) {
3696+ Ok(frames) => frames,
3697+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
3698+ };
3699+ let skipped_split_tx = crate::decode::skip_split_tx_hits();
3700+ assert!(
3701+ skipped_split_tx > 0,
3702+ "{NAME}: zero skipped 8x8 leaves with a split transform -- the fixture no longer \
3703+ exercises the arm this test exists for"
3704+ );
3705+ assert_eq!(frames.len(), 1, "{NAME}: one key frame");
3706+ assert_eq!((frames[0].width, frames[0].height), (width, height));
3707+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1);
3708+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg");
3709+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg");
3710+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");
3711+ eprintln!("{NAME}: {skipped_split_tx} skipped 8x8 TX_4X4 leaves, frame pixel-exact");
3712+ }
3713+
3082 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=13714 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1
3083 /// --superres-denominator=12` key frame, decoded pixel-exact against3715 /// --superres-denominator=12` key frame, decoded pixel-exact against
3084 /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s3716 /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s
@@ -20842,6 +21474,411 @@ mod tests {
20842 );21474 );
20843 }21475 }
20844 21476
21477+ /// lane-golomb r2 gate: a 32x32-level block that STRADDLES the frame edge
21478+ /// and whose partition is the gathered edge bit's `PARTITION_HORZ` (bottom
21479+ /// edge) / `PARTITION_VERT` (right edge). Since r1 that bit can name
21480+ /// HORZ/VERT instead of always inferring SPLIT, so the second 32x16/16x32
21481+ /// half is out of frame and must NOT be decoded (libaom `decode_partition`:
21482+ /// `case PARTITION_HORZ: decode_block(top); if (has_rows) decode_block(bottom)`).
21483+ /// The AB and 1:4 arms need no such guard: at an edge libaom's
21484+ /// `ec_read_partition_impl` can only yield HORZ/VERT/SPLIT, so those arms
21485+ /// are unreachable there.
21486+ ///
21487+ /// Geometry: 192x80 (mi_rows=20 -- the second SB row is 16 px tall, so its
21488+ /// 32-level blocks at y=64 have `has_rows32 == false`) and 80x192 for the
21489+ /// right edge. Natural content (`testsrc2`); `smptebars`-style screen
21490+ /// content trips the palette/screen-content refusal before the edge is
21491+ /// reached. cq sweep, 8-bit and 10-bit, plus a 5-frame inter arm.
21492+ /// Counters are sampled per attempt and summed only over attempts that
21493+ /// decoded AND pixel-compared (class `counter-from-refused-stream`).
21494+ #[test]
21495+ fn a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition_decodes_pixel_exact() {
21496+ edge32_gate(
21497+ "a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition_decodes_pixel_exact",
21498+ false,
21499+ );
21500+ }
21501+
21502+ /// lane-golomb r2 OPEN DEFECT, pinned as a runnable test: with the 16-px
21503+ /// straddling band left FLAT the encoder answers the 32-level edge bit
21504+ /// with HORZ (`edge32=[2, 0, 2, 0]` on 192x80 cq40 8-bit), the guard added
21505+ /// this round keeps the stream in entropy sync -- every pixel outside the
21506+ /// two edge strips matches ffmpeg -- but the strips themselves
21507+ /// reconstruct wrong: `plane Y: 1081 pixels differ, first at row 62 col
21508+ /// 128`, diffs confined to rows 62..79 over ~64 columns (exactly the two
21509+ /// 32x16 strips plus the deblock bleed above them). That is a
21510+ /// reconstruction defect inside the strip (prediction/availability), not
21511+ /// the partition guard. `#[ignore]` so the suite stays green; run it with
21512+ /// `cargo test -p ec-av1 --lib -- --ignored a_32x32_frame_edge_rect_partition_with_a_flat`.
21513+ #[test]
21514+ #[ignore = "open r2 defect: the 32-level edge HORZ strip reconstructs wrong pixels"]
21515+ fn a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact() {
21516+ edge32_gate(
21517+ "a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact",
21518+ true,
21519+ );
21520+ }
21521+
21522+ /// lane-golomb r9 OPEN DEFECT, pinned as a runnable test: a frame whose
21523+ /// height (192x68) or width (68x192) is not a multiple of 8 leaves a 4-px
21524+ /// straddling band inside the mi-rounded plane, and every INTER frame's
21525+ /// output is +-1 wrong across that band and the columns/rows next to it
21526+ /// (`68x192 cq35 8-bit: frame 1 plane Y: 145 pixels differ, first at row 0
21527+ /// col 64`, mass in columns 64..67). r9 bisected it stage by stage against
21528+ /// the instrumented aomdec on that exact stream:
21529+ /// * `EC_AV1_PREFILT_DUMP` frame 1 is BYTE-IDENTICAL over the cropped
21530+ /// 68 columns -- reconstruction and inter prediction are exact, so the
21531+ /// charter's "MC reads past the crop" hypothesis is refuted a second time.
21532+ /// * `EC_AV1_POSTDEBLOCK_DUMP` with `EC_AV1_DEBUG_SKIP_CDEF=1` also matches
21533+ /// aomdec's own post-deblock dump (which is 72 columns wide, i.e. it
21534+ /// exposes the straddling band) -- the deblock, including its
21535+ /// `frame_width` clip, is correct.
21536+ /// * The divergence therefore enters in CDEF, at the last 8x8 CDEF block
21537+ /// column/row, which is the one that straddles the crop edge.
21538+ /// lane-cdef r2: CLOSED, and un-ignored. r1 rooted the luma half in
21539+ /// `apply_cdef`'s direction search, which clamped at the CROPPED frame
21540+ /// edge while libaom runs `cdef_find_dir` over `cdef_prepare_fb`'s buffer
21541+ /// -- whose columns/rows past the MI-ROUNDED extent (`hsize = nhb <<
21542+ /// mi_wide_l2`, `cdef.c:164-167`, and the `frame_boundary[RIGHT]`
21543+ /// CDEF_VERY_LARGE fill at `cdef.c:249-256`) are CDEF_VERY_LARGE, not the
21544+ /// last real sample. The chroma half was lane-golomb r8's loop-restoration
21545+ /// plane size (LR is the one post-decode filter sized by the CROP, not the
21546+ /// mi grid) plus its reference-size fix; merging both branches takes all
21547+ /// four arms to 0 differing pixels on Y, U and V.
21548+ ///
21549+ /// Arms: 192x68 and 68x192 (a 4-px straddling band on one axis), 5 frames,
21550+ /// 8-bit and 10-bit, plus a `--tile-columns=1` twin of each (COMMON's
21551+ /// neighbour-map rule -- the skip band CDEF reads is a per-mi side band).
21552+ /// MEASURED 2026-09-02: all 32 multi-tile attempts refuse BY NAME today,
21553+ /// so that half of the gate compares nothing yet (class
21554+ /// `counter-from-refused-stream`); the census is 10x "an inter SB-level AB
21555+ /// partition", 6x "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
21556+ /// rectangular residual coding", 6x "an 8x8 intra leaf in an inter frame
21557+ /// whose tx_depth splits it into 4x4 transform units", 5x "an inter
21558+ /// partition below 8x8", 3x "an inter 16x16-level AB or 1:4 partition",
21559+ /// 1x "a split intra strip whose transform unit is 32x64", 1x "an
21560+ /// intra-coded 1:4 (or other non-2:1) rect strip on the inter block path".
21561+ /// The arms stay so the coverage appears the day those lift; every assert
21562+ /// below is carried by the single-tile arms.
21563+ /// Hard-asserts `decode::cdef_straddle_units()` grew: a FILTERED 8x8 CDEF
21564+ /// unit whose extent crosses the crop edge is the only shape for which
21565+ /// clamping and padding differ, so a zero delta would make these arms
21566+ /// vacuous for this defect.
21567+ #[test]
21568+ fn a_frame_edge_straddling_band_decodes_pixel_exact() {
21569+ edge32_gate(
21570+ "a_frame_edge_straddling_band_decodes_pixel_exact",
21571+ false,
21572+ );
21573+ }
21574+
21575+ fn edge32_gate(name: &str, flat_band: bool) {
21576+ let NAME = name;
21577+ let _gate_lock = lock_gate_counters();
21578+ if !have_ffmpeg() {
21579+ eprintln!("SKIP {NAME}: no ffmpeg");
21580+ return;
21581+ }
21582+ if !have_aomenc() {
21583+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
21584+ return;
21585+ }
21586+ // (width, height, frames, ten_bit, tile_columns_log2)
21587+ let mut arms: Vec<(usize, usize, usize, bool, u32)> = Vec::new();
21588+ for &(w, h) in &[(192usize, 80usize), (80usize, 192usize)] {
21589+ arms.push((w, h, 1, false, 0));
21590+ arms.push((w, h, 1, true, 0));
21591+ }
21592+ // The inter arm: >= 4 frames so the 32-level edge path in the INTER
21593+ // tile walk is exercised too.
21594+ arms.push((192, 80, 5, false, 0));
21595+ // lane-golomb r9: the straddling-band arms, only under the ignored
21596+ // `a_frame_edge_straddling_band_decodes_pixel_exact` name (they are
21597+ // RED -- see that test's own comment for the stage bisection). Naming
21598+ // them here rather than in a second copy of this gate keeps the
21599+ // recipe, the counters and the refusal handling identical.
21600+ if name == "a_frame_edge_straddling_band_decodes_pixel_exact" {
21601+ arms.clear();
21602+ for &tile_cols in &[0u32, 1] {
21603+ arms.push((192, 68, 5, false, tile_cols));
21604+ arms.push((192, 68, 5, true, tile_cols));
21605+ arms.push((68, 192, 5, false, tile_cols));
21606+ arms.push((68, 192, 5, true, tile_cols));
21607+ }
21608+ }
21609+ // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is
21610+ // vacuous, panicking or red -- each measured this round with
21611+ // `arms.push((192, 68, 5, false))`, log
21612+ // `$HOME/.cache/golomb-gate-r8{b,e,f,g}.log`):
21613+ // * the r7 blocker IS fixed -- no attempt refuses "a reference
21614+ // picture whose height does not match this frame's own true
21615+ // size" any more (`decode.rs`'s comparison now uses the header's
21616+ // frame height, per libaom's crop-dimension reference test).
21617+ // * cq35 now refuses LATER, by another lane's name: "an inter
21618+ // SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)" -- so the
21619+ // arm compares nothing (class `counter-from-refused-stream`).
21620+ // * cq40 PANICS in `decode_inter_block8`
21621+ // (`from_switchable_symbol` handed a 4th symbol, `mc.rs:203`) =
21622+ // lane-sub8's own open below-8x8 desync; a panic cannot be
21623+ // tolerated as a named refusal.
21624+ // * cq59 8-bit is RED: `frame 1 plane Y: 217 pixels differ, first
21625+ // at row 60 col 170 (ours 172 vs ffmpeg 173)`, and the cq35
21626+ // 10-bit twin is RED at `row 56 col 48 (ours 530 vs ffmpeg
21627+ // 531)`. Both are +-1 bands in rows 56..63, i.e. the deblock/CDEF
21628+ // bleed ABOVE the 4-px straddling row band (64..67) -- the same
21629+ // shape as the `(68, 192, 5, false)` column defect below, so the
21630+ // two are very likely ONE straddling-band reconstruction defect.
21631+ // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red):
21632+ // a 68-px axis leaves the last superblock straddling by 4 px, the
21633+ // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >=
21634+ // max_w_mi` early return exists for. With
21635+ // `arms.push((192, 68, 5, false))` all EIGHT cq attempts refuse by
21636+ // name -- "a reference picture whose height does not match this
21637+ // frame's own true size" -- so the arm compares nothing (class
21638+ // `counter-from-refused-stream`). With
21639+ // `arms.push((68, 192, 5, false))` the gate goes RED on a real,
21640+ // separate defect: `68x192 cq35 frames=5 10bit=false frame 1 plane Y:
21641+ // 141 pixels differ, first at row 0 col 64 (ours 167 vs ffmpeg 166)
21642+ // [edge32=[0,34,0,0,1,17,0,1]]` -- LUMA, inside the 4-px straddling
21643+ // COLUMN. Both are unrelated to this round's chroma tx_type fix.
21644+ let cqs: [u32; 8] = [35, 40, 45, 50, 55, 57, 59, 61];
21645+ let mut totals = [0usize; 8];
21646+ let mut compared = 0usize;
21647+ let mut refusals: Vec<String> = Vec::new();
21648+ let straddle = name == "a_frame_edge_straddling_band_decodes_pixel_exact";
21649+ let mut straddle_units = 0usize;
21650+ for &(width, height, frame_count, ten_bit, tile_cols) in &arms {
21651+ for &cq in &cqs {
21652+ let duration = frame_count as f64 / 25.0;
21653+ // `noise` (explicit seed) both defeats aomenc's
21654+ // screen-content detection -- which otherwise refuses every
21655+ // attempt at "a HORZ/VERT intra strip in a screen-content
21656+ // frame" -- and keeps the RD search off flat NONE blocks.
21657+ // Natural content over the whole superblock-aligned area,
21658+ // with the 16-px straddling band left FLAT (`pad`): with
21659+ // detail in that band aomenc always answers the edge bit with
21660+ // SPLIT (measured: 178 edge bits, 178 of them SPLIT, over a
21661+ // cq 35..61 sweep), so the HORZ/VERT arm this round guards
21662+ // never fired. `noise` on top keeps screen-content detection
21663+ // (and its palette-strip refusal) off.
21664+ let (cw, ch) = (
21665+ if flat_band && width % 64 != 0 { width - 16 } else { width },
21666+ if flat_band && height % 64 != 0 { height - 16 } else { height },
21667+ );
21668+ let pad = if flat_band {
21669+ format!("pad={width}:{height}:0:0:gray,")
21670+ } else {
21671+ String::new()
21672+ };
21673+ let source = format!(
21674+ "testsrc2=size={cw}x{ch}:duration={duration}:rate=25,\
21675+ {pad}noise=alls=6:allf=t+u:all_seed={cq}"
21676+ );
21677+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
21678+ let y4m = Command::new("ffmpeg")
21679+ .args([
21680+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix, "-strict",
21681+ "-1", "-t", &format!("{duration}"), "-f", "yuv4mpegpipe", "-",
21682+ ])
21683+ .stdin(Stdio::null())
21684+ .stdout(Stdio::piped())
21685+ .stderr(Stdio::piped())
21686+ .output()
21687+ .expect("ffmpeg failed to run");
21688+ assert!(
21689+ y4m.status.success(),
21690+ "{NAME}: ffmpeg fixture: {}",
21691+ String::from_utf8_lossy(&y4m.stderr)
21692+ );
21693+ let cq_arg = format!("--cq-level={cq}");
21694+ let mut args: Vec<&str> = vec![
21695+ "--codec=av1",
21696+ "--passes=1",
21697+ "--end-usage=q",
21698+ &cq_arg,
21699+ "--cpu-used=0",
21700+ "--threads=1",
21701+ "--row-mt=0",
21702+ "--sb-size=64",
21703+ "--enable-restoration=0",
21704+ "--enable-palette=0",
21705+ "--deltaq-mode=0",
21706+ "--enable-intrabc=0",
21707+ // Per-arm overrides go LAST (aomenc keeps the last
21708+ // occurrence of a repeated --enable-* flag).
21709+ "--enable-rect-partitions=1",
21710+ "--enable-ab-partitions=0",
21711+ "--enable-1to4-partitions=0",
21712+ // 32, not the charter's 8: at 8 the sub-16 AB and
21713+ // split-transform strip arms (still refused by name here)
21714+ // fire before the 32-level edge is reached and EVERY
21715+ // attempt refuses (measured). At 32 the edge block cannot
21716+ // split, so aomenc is forced onto the gathered edge bit's
21717+ // HORZ/VERT -- exactly the arm this round guards.
21718+ "--min-partition-size=32",
21719+ "--tune-content=film",
21720+ "--max-partition-size=64",
21721+ ];
21722+ if ten_bit {
21723+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
21724+ }
21725+ let tile_arg = format!("--tile-columns={tile_cols}");
21726+ if tile_cols > 0 {
21727+ args.push(&tile_arg);
21728+ }
21729+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
21730+ let mut child = Command::new(aomenc_path())
21731+ .args(&args)
21732+ .stdin(Stdio::piped())
21733+ .stdout(Stdio::piped())
21734+ .stderr(Stdio::piped())
21735+ .spawn()
21736+ .expect("aomenc failed to start");
21737+ child
21738+ .stdin
21739+ .take()
21740+ .expect("aomenc stdin")
21741+ .write_all(&y4m.stdout)
21742+ .expect("writing y4m to aomenc");
21743+ let out = child.wait_with_output().expect("aomenc failed to run");
21744+ assert!(
21745+ out.status.success(),
21746+ "{NAME}: aomenc refused the fixture: {}",
21747+ String::from_utf8_lossy(&out.stderr)
21748+ );
21749+ let stream = out.stdout;
21750+ if ten_bit {
21751+ assert_eq!(
21752+ parsed_bit_depth(&stream),
21753+ 10,
21754+ "{NAME}: aomenc did not write a 10-bit sequence header"
21755+ );
21756+ }
21757+ let tag = format!(
21758+ "{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit} \
21759+ tile_cols={tile_cols}"
21760+ );
21761+ let before = crate::decode::edge32_hits();
21762+ let straddle_before = crate::decode::cdef_straddle_units();
21763+ // lane-golomb r8: name the attempt BEFORE decoding it -- a
21764+ // desync surfaces as a panic deep in mc.rs with no arm in the
21765+ // message, and r8 spent a run bisecting arms by hand.
21766+ if std::env::var_os("EC_GATE_VERBOSE").is_some() {
21767+ eprintln!("{NAME}: attempting {tag}");
21768+ }
21769+ let decoded = match decode_stream(&stream) {
21770+ Ok(frames) => frames,
21771+ Err(e) => {
21772+ let msg = e.to_string();
21773+ assert!(
21774+ msg.contains("unsupported"),
21775+ "{NAME} failed outright, not a named refusal ({tag}): {msg}"
21776+ );
21777+ refusals.push(format!("{tag}: {msg}"));
21778+ continue;
21779+ }
21780+ };
21781+ let after = crate::decode::edge32_hits();
21782+ let delta: Vec<usize> =
21783+ (0..8).map(|i| after[i] - before[i]).collect();
21784+ let reference = if ten_bit {
21785+ ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len())
21786+ } else {
21787+ ffmpeg_decode_sequence(&stream, width, height, decoded.len())
21788+ };
21789+ assert_eq!(
21790+ decoded.len(),
21791+ reference.len(),
21792+ "{NAME}: {tag}: shown-frame count vs ffmpeg"
21793+ );
21794+ for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() {
21795+ for (plane, a, b, w) in [
21796+ ("Y", &ours.y, &theirs.y, width),
21797+ ("U", &ours.u, &theirs.u, width / 2),
21798+ ("V", &ours.v, &theirs.v, width / 2),
21799+ ] {
21800+ if let Some(d) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
21801+ let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count();
21802+ if std::env::var_os("EC_EDGE32_ROWS").is_some() {
21803+ let mut per_row: std::collections::BTreeMap<usize, usize> =
21804+ Default::default();
21805+ for (k, (x, y)) in a.iter().zip(b.iter()).enumerate() {
21806+ if x != y {
21807+ *per_row.entry(k / w).or_default() += 1;
21808+ }
21809+ }
21810+ eprintln!("{NAME}: {tag} plane {plane} diffs per row: {per_row:?}");
21811+ }
21812+ panic!(
21813+ "{NAME}: {tag} frame {i} plane {plane}: {n} pixels differ, first \
21814+ at row {} col {} (ours {} vs ffmpeg {}) [edge32={delta:?}]",
21815+ d / w,
21816+ d % w,
21817+ a[d],
21818+ b[d]
21819+ );
21820+ }
21821+ }
21822+ }
21823+ compared += 1;
21824+ straddle_units += crate::decode::cdef_straddle_units() - straddle_before;
21825+ for i in 0..8 {
21826+ totals[i] += delta[i];
21827+ }
21828+ }
21829+ }
21830+ assert!(
21831+ compared > 0,
21832+ "{NAME}: every attempt hit a named refusal:\n{}",
21833+ refusals.join("\n")
21834+ );
21835+ assert!(
21836+ !straddle || straddle_units > 0,
21837+ "{NAME}: no FILTERED 8x8 CDEF unit crossed the cropped frame edge over \
21838+ {compared} compared attempts -- the straddling arms proved nothing"
21839+ );
21840+ assert!(
21841+ totals[0] + totals[1] + totals[4] + totals[5] > 0,
21842+ "{NAME}: no frame-edge partition bit was read at all over \
21843+ {compared} compared attempts -- the gate proved nothing"
21844+ );
21845+ // lane-golomb r3: the flat-band arm's ASSERT moved one level up. Until
21846+ // r3 the last superblock row was reached through a 32-level edge bit
21847+ // only because our own out-of-frame transform units had desynced the
21848+ // stream; with that fixed, real aomenc answers a bottom-edge
21849+ // superblock with the 64-level `PARTITION_HORZ` (and a right-edge one
21850+ // with `PARTITION_VERT`) and the 32-level slots stay 0 on this
21851+ // content. Slots 6/7 are the strips actually decoded at the edge.
21852+ assert!(
21853+ !flat_band || totals[6] > 0,
21854+ "{NAME}: no 64x32 bottom-edge HORZ strip was decoded \
21855+ (edge32={totals:?}, {compared} compared attempts)"
21856+ );
21857+ assert!(
21858+ !flat_band || totals[7] > 0,
21859+ "{NAME}: no 32x64 right-edge VERT strip was decoded \
21860+ (edge32={totals:?}, {compared} compared attempts)"
21861+ );
21862+ eprintln!(
21863+ "{NAME}: {compared} pixel-exact attempts, 32-level edge bits \
21864+ [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, 64-level edge bits \
21865+ [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, \
21866+ {straddle_units} straddling CDEF units, {} named refusals",
21867+ totals[0],
21868+ totals[1],
21869+ totals[2],
21870+ totals[3],
21871+ totals[4],
21872+ totals[5],
21873+ totals[6],
21874+ totals[7],
21875+ refusals.len()
21876+ );
21877+ for r in &refusals {
21878+ eprintln!("{NAME} refusal: {r}");
21879+ }
21880+ }
21881+
20845 /// lane-sqchroma r1 gate: a plain SQUARE-partition intra key frame with21882 /// lane-sqchroma r1 gate: a plain SQUARE-partition intra key frame with
20846 /// REAL chroma (no `hue=s=0` guard) and aomenc's tx-size search left at21883 /// REAL chroma (no `hue=s=0` guard) and aomenc's tx-size search left at
20847 /// its own DEFAULT (on) -- the combination the user's films hit21884 /// its own DEFAULT (on) -- the combination the user's films hit
@@ -24011,6 +25048,61 @@ mod tests {
24011 }25048 }
24012 }25049 }
24013 25050
25051+ /// lane-kf900 r1: a SKIPPED 8x8 intra leaf whose `tx_depth` symbol
25052+ /// resolved to TX_4X4 must publish 4 -- not its 8-px block side -- to the
25053+ /// next block's `get_tx_size_context` (libaom `set_txfm_ctxs(mbmi->tx_size,
25054+ /// ..., skip_txfm && is_inter_block(mbmi), xd)`; that skip term is always 0
25055+ /// for an intra block). `decode_leaf8`'s tail wrote the literal 8, so the
25056+ /// rect strip below such a leaf read `tx_size_cat1` row 2 where libaom
25057+ /// reads row 1 -- same alphabet, wrong CDF row, the msac range diverged
25058+ /// mid-frame with NO refusal. `skip_split_tx_hits` was `pub` and asserted
25059+ /// by no gate at all before this one (class `tool-disabled-in-every-gate`).
25060+ #[test]
25061+ fn a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact() {
25062+ const NAME: &str =
25063+ "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact";
25064+ crate::decode::reset_skip_split_tx_hits();
25065+ run_multi_tile_gate(NAME, 0, 0, 8, 1, &[], false, None);
25066+ // lane-kf900 r2: the counter assert that used to sit here is
25067+ // UNREACHABLE from aomenc. 108 measured recipes (72 at 8-bit, 36 at
25068+ // 10-bit: `geq` half-flat/half-noise, `mandelbrot`, `testsrc2`,
25069+ // `noise=all_seed=49`, cq 55/59/63, `--cpu-used=0..2`,
25070+ // `--enable-tx-size-search=1 --min-partition-size=8
25071+ // --enable-rect-partitions=1`; log
25072+ // `$HOME/.cache/kf900/sweep/results{,10}.tsv`) produced
25073+ // `skip_split_tx_hits() == 0` on every stream that decoded, because
25074+ // libaom's own encoder forces `tx_size` to the block maximum once it
25075+ // decides `skip_txfm` -- so no aomenc stream carries a SKIPPED 8x8
25076+ // intra leaf whose `tx_depth` resolved to `TX_4X4`. The film's
25077+ // encoder does; the counter is hard-asserted on the real stream in
25078+ // [`a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`].
25079+ // These two arms stay as the pixel-exact multi-tile control.
25080+ }
25081+
25082+ /// [`a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact`]'s
25083+ /// 10-bit arm -- the film that exposed the defect is yuv420p10le.
25084+ #[test]
25085+ fn a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_10bit_decodes_pixel_exact()
25086+ {
25087+ const NAME: &str = "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_10bit_decodes_pixel_exact";
25088+ crate::decode::reset_skip_split_tx_hits();
25089+ run_multi_tile_gate(NAME, 0, 0, 10, 1, &[], false, None);
25090+ // lane-kf900 r2: the counter assert that used to sit here is
25091+ // UNREACHABLE from aomenc. 108 measured recipes (72 at 8-bit, 36 at
25092+ // 10-bit: `geq` half-flat/half-noise, `mandelbrot`, `testsrc2`,
25093+ // `noise=all_seed=49`, cq 55/59/63, `--cpu-used=0..2`,
25094+ // `--enable-tx-size-search=1 --min-partition-size=8
25095+ // --enable-rect-partitions=1`; log
25096+ // `$HOME/.cache/kf900/sweep/results{,10}.tsv`) produced
25097+ // `skip_split_tx_hits() == 0` on every stream that decoded, because
25098+ // libaom's own encoder forces `tx_size` to the block maximum once it
25099+ // decides `skip_txfm` -- so no aomenc stream carries a SKIPPED 8x8
25100+ // intra leaf whose `tx_depth` resolved to `TX_4X4`. The film's
25101+ // encoder does; the counter is hard-asserted on the real stream in
25102+ // [`a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`].
25103+ // These two arms stay as the pixel-exact multi-tile control.
25104+ }
25105+
24014 #[test]25106 #[test]
24015 fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() {25107 fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() {
24016 run_multi_tile_gate(25108 run_multi_tile_gate(
@@ -24706,16 +25798,29 @@ mod tests {
24706 let mut compared = 0usize;25798 let mut compared = 0usize;
24707 let mut edge_horz_total = 0usize;25799 let mut edge_horz_total = 0usize;
24708 let mut edge_sub_total = 0usize;25800 let mut edge_sub_total = 0usize;
25801+ let mut skip_split_tx_total = 0usize;
24709 // The last two shapes are the ledger-measured 64-level pair: on a25802 // The last two shapes are the ledger-measured 64-level pair: on a
24710 // flat band (192x80 / 80x192) real aomenc answers the bottom-edge25803 // flat band (192x80 / 80x192) real aomenc answers the bottom-edge
24711 // superblock with the 64-level HORZ/VERT, which the 136 shapes above25804 // superblock with the 64-level HORZ/VERT, which the 136 shapes above
24712 // never produce (their SBs always split down to the 32/16 levels).25805 // never produce (their SBs always split down to the 32/16 levels).
25806+ // lane-kf1200 r3: the 2-/4-/6-mi partial bottom rows (h mod 64 == 8,
25807+ // 16, 24) with partial RIGHT columns as well (w mod 64 == 8), the
25808+ // geometry of the film key frames this lane chases.
24713 for (width, height, flat) in [25809 for (width, height, flat) in [
24714 (192usize, 136usize, false),25810 (192usize, 136usize, false),
24715 (136usize, 192usize, false),25811 (136usize, 192usize, false),
24716 (192usize, 80usize, true),25812 (192usize, 80usize, true),
24717 (80usize, 192usize, true),25813 (80usize, 192usize, true),
25814+ (200usize, 72usize, false),
25815+ (136usize, 88usize, false),
25816+ (264usize, 104usize, false),
24718 ] {25817 ] {
25818+ // lane-kf1200 r3 (class `tool-disabled-in-every-gate`): the whole
25819+ // recipe ran with `--enable-tx-size-search=0`, so no block ever
25820+ // carried a nonzero `tx_depth` and the SKIPPED 8x8 leaf that
25821+ // resolves to TX_4X4 -- whose txfm context this round fixed --
25822+ // was unreachable by construction. The second arm turns it on.
25823+ for tx_search in [0usize, 1] {
24719 for depth in [8usize, 10] {25824 for depth in [8usize, 10] {
24720 let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };25825 let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
24721 let y4m = Command::new("ffmpeg")25826 let y4m = Command::new("ffmpeg")
@@ -24746,7 +25851,8 @@ mod tests {
24746 "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64",25851 "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64",
24747 "--kf-max-dist=0", "--enable-rect-partitions=1",25852 "--kf-max-dist=0", "--enable-rect-partitions=1",
24748 "--enable-ab-partitions=0", "--enable-1to4-partitions=0",25853 "--enable-ab-partitions=0", "--enable-1to4-partitions=0",
24749- "--enable-tx-size-search=0", "--reduced-tx-type-set=1",25854+ &format!("--enable-tx-size-search={tx_search}"),
25855+ "--reduced-tx-type-set=1",
24750 "--min-partition-size=8", "--max-partition-size=64",25856 "--min-partition-size=8", "--max-partition-size=64",
24751 &format!("--input-bit-depth={depth}"),25857 &format!("--input-bit-depth={depth}"),
24752 &format!("--bit-depth={depth}"),25858 &format!("--bit-depth={depth}"),
@@ -24778,6 +25884,7 @@ mod tests {
24778 "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})"25884 "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})"
24779 );25885 );
24780 crate::decode::reset_edge_part_hits();25886 crate::decode::reset_edge_part_hits();
25887+ crate::decode::reset_skip_split_tx_hits();
24781 let frames = match decode_stream(&stream) {25888 let frames = match decode_stream(&stream) {
24782 Ok(frames) => frames,25889 Ok(frames) => frames,
24783 Err(e) => {25890 Err(e) => {
@@ -24793,6 +25900,7 @@ mod tests {
24793 }25900 }
24794 };25901 };
24795 let hits = crate::decode::edge_part_hits();25902 let hits = crate::decode::edge_part_hits();
25903+ let skip_split_tx = crate::decode::skip_split_tx_hits();
24796 let ffmpeg_frames = if depth == 10 {25904 let ffmpeg_frames = if depth == 10 {
24797 ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())25905 ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
24798 } else {25906 } else {
@@ -24818,13 +25926,16 @@ mod tests {
24818 compared += 1;25926 compared += 1;
24819 edge_horz_total += hits[0];25927 edge_horz_total += hits[0];
24820 edge_sub_total += hits[2];25928 edge_sub_total += hits[2];
25929+ skip_split_tx_total += skip_split_tx;
24821 eprintln!(25930 eprintln!(
24822- "{NAME}: pixel-exact {width}x{height} at {depth}-bit, edge bits \25931+ "{NAME}: pixel-exact {width}x{height} at {depth}-bit tx_search={tx_search}, \
24823- 64-level horz/vert={} split={} sub-level horz/vert={} split={}",25932+ edge bits 64-level horz/vert={} split={} sub-level horz/vert={} split={}, \
25933+ skipped 8x8 leaves with TX_4X4 {skip_split_tx}",
24824 hits[0], hits[1], hits[2], hits[3]25934 hits[0], hits[1], hits[2], hits[3]
24825 );25935 );
24826 }25936 }
24827 }25937 }
25938+ }
24828 assert!(25939 assert!(
24829 compared > 0,25940 compared > 0,
24830 "{NAME}: every arm refused -- the gate compared no pixels at all"25941 "{NAME}: every arm refused -- the gate compared no pixels at all"
@@ -24838,5 +25949,15 @@ mod tests {
24838 edge_sub_total > 0,25949 edge_sub_total > 0,
24839 "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT"25950 "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT"
24840 );25951 );
25952+ // lane-kf1200 r3: the `--enable-tx-size-search=1` half of the window
25953+ // exists so a partial-row block can carry a nonzero `tx_depth` at all
25954+ // (the whole recipe ran with it OFF before -- class
25955+ // `tool-disabled-in-every-gate`). The SKIPPED 8x8 leaf that resolves
25956+ // to TX_4X4 -- whose txfm context this round fixed -- is NOT reachable
25957+ // from any synthetic source measured here (80 recipes, all zero), so
25958+ // that arm is asserted by the pinned film fixture
25959+ // `the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact`
25960+ // instead; this counter is reported, not gated.
25961+ eprintln!("{NAME}: {skip_split_tx_total} skipped 8x8 TX_4X4 leaves across compared attempts");
24841 }25962 }
24842 }25963 }
lanes/cdef-r2.report.mdadded+83 -0
@@ -0,0 +1,83 @@
1+# lane-cdef r2 report -- merge, the 68x192 chroma residue CLOSED, gate un-ignored
2+
3+Branch `lane-cdef`, base main `727f29a`. Commits this round:
4+* `32a467a` Merge main 727f29a (lane-r14, lane-kf1200, lane-reelckf) -- no conflicts.
5+* `0e6c5c9` Merge lane-golomb 173b793 -- 2 conflicts in `decode.rs`, both resolved (below).
6+* `26b971a` straddling-band gate un-ignored + `CDEF_STRADDLE_UNITS` counter + multi-tile arms.
7+
8+`cdf.rs` is byte-identical across `main`, `lane-golomb` and this tree
9+(`sha256 655f9a45ccedf7e37adab8b46703cf7ec4c9cc395978a1e6179157741def5844`, all four).
10+
11+## r1's leftover suite unit
12+`cdef-suite-1788330834.service` was still RUNNING at the start of this round; it had reached
13+**184 tests ok, 0 FAILED / 0 panics** with no `test result` line yet. Stopped (its target dir is
14+this lane's) and superseded by the r2 run below.
15+
16+## Merge conflicts (decode.rs), resolved
17+1. `dump_stage`'s per-decode-order-frame index: both lanes added one. Kept this lane's shared
18+ `dump_stage_idx()` helper (`dump_stage16` uses it too), dropped lane-golomb's duplicate
19+ `thread_local` counter.
20+2. The var-tx leaf loop (`decode.rs:19323`): took **main's** general `(row, col, tw, th)` rect
21+ leaves and **lane-golomb's** `fill_lf_grid_leaf_luma` writer. Routing a rect leaf through
22+ `fill_lf_grid_rect` would recompute the CHROMA tx dims from the leaf span; libaom's
23+ `get_transform_size` (`av1/common/av1_loopfilter.c:207`) applies the split override only for
24+ `plane == AOM_PLANE_Y`. Class `table-and-reader-move-together`: table (leaf tuple) from main,
25+ writer from golomb, both re-gated below.
26+
27+## Charter item (2) -- the 68x192 CHROMA residue: CLOSED, and it was NOT a chroma-CDEF defect
28+The charter's hypotheses (chroma `hsize >> xdec` fill, `damping - 1`, `uv_pri/uv_sec`, shared luma
29+`dir`, `coeff_shift`, the 8x8 skip band) were each checked against the oracle source and all six
30+were **already correct** in `apply_cdef`:
31+* right/bottom pad bound: `sample_uv` bounds at `plane.true_width/true_height`, which is
32+ `mi_cols * 4 / 2` (`decode.rs:13388`) = 36 for a 68-px axis -- exactly libaom's
33+ `hsize = nhb << mi_wide_l2` with `mi_wide_l2 = MI_SIZE_LOG2 - subsampling_x`
34+ (`cdef.c:164-167`), the fill starting there being `cdef.c:249-256`.
35+* `damping += coeff_shift - (pli != AOM_PLANE_Y)` (`cdef_block.c:337`) == our `damping_uv`.
36+* chroma `t = pri_strength`, NOT `adjust_strength` (`cdef_block.c:387`) == ours.
37+* `pri_strength ? dir[by][bx] : 0` per plane (`cdef_block.c:392`) == ours; the `conv422/conv440`
38+ direction remap is `if (pli == 1 && xdec != ydec)` (`cdef_block.c:361-369`), i.e. never in 4:2:0.
39+* `level`/`sec_strength` from `cdef_uv_strengths[mbmi_cdef_strength]` with the `== 3` bump
40+ (`cdef.c:325-333`) == ours; block size `8 >> xdec` by `8 >> ydec` == our 4x4.
41+
42+The residue was the **loop restoration plane size**, fixed on lane-golomb r8 and merged this
43+round: LR is the one post-decode filter sized by the CROP (`av1_get_upsampled_plane_size`,
44+`restoration.c:47`, asserted against the crop at `restoration.c:1106`), while deblock and CDEF walk
45+the mi grid. With both branches' fixes in one tree all four straddling arms are exact on Y, U and V.
46+
47+EVIDENCE: /home/user/.cache/cdef-strad-r2.log | merged tree, `cargo test -p ec-av1 --lib -- --ignored --nocapture a_frame_edge_straddling_band` (192x68 + 68x192, 5 frames, 8+10-bit, cq 35..61) | 14 pixel-exact attempts (Y, U and V, every shown frame), 0 differing pixels, 18 named refusals, test result ok 1 passed / 0 failed
48+
49+## Charter item (3) -- `--tile-columns=1` arms: added, and VACUOUS today
50+Each straddling arm gained a `--tile-columns=1` twin (8 arms x 8 cq = 64 attempts). All 32
51+multi-tile attempts refuse **by name**; census (in the test's doc comment):
52+10x "an inter SB-level AB partition", 6x "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
53+rectangular residual coding", 6x "an 8x8 intra leaf in an inter frame whose tx_depth splits it into
54+4x4 transform units", 5x "an inter partition below 8x8", 3x "an inter 16x16-level AB or 1:4
55+partition", 1x "a split intra strip whose transform unit is 32x64", 1x "an intra-coded 1:4 rect
56+strip on the inter block path". Class `counter-from-refused-stream`: that half of the gate compares
57+nothing yet and every assert is carried by the single-tile arms. Arms kept so the coverage appears
58+the day those refusals lift.
59+
60+## Gate
61+`stream.rs::a_frame_edge_straddling_band_decodes_pixel_exact` -- **un-ignored** (was
62+`#[ignore] "open r9 defect"`). Hard-asserts the new `decode::cdef_straddle_units()` grew: a FILTERED
63+8x8 CDEF unit whose extent crosses the cropped frame edge is the only shape for which "clamp at the
64+crop" and "pad with CDEF_VERY_LARGE past the mi-rounded extent" differ, so a zero delta would make
65+these arms vacuous for this defect.
66+
67+EVIDENCE: /home/user/.cache/cdef-strad2-r2.log | `cargo test -p ec-av1 --lib -- --nocapture a_frame_edge_straddling_band` on the final tree | 14 pixel-exact attempts, **337 straddling CDEF units**, 50 named refusals, ok 1 passed / 0 failed in 33.99s
68+
69+Sibling gate (same tables/paths -- `apply_cdef`, the skip band, `fill_skip_grid`):
70+EVIDENCE: /home/user/.cache/cdef-sib-r2.log | `cargo test -p ec-av1 --lib -- --nocapture cdef_and_sub16` | a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact ok, 1 passed / 0 failed
71+
72+## Suite
73+EVIDENCE: /home/user/.cache/cdef-suite-r2.log | `systemd-run --user --unit=cdef-suite-r2-... -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3` on `646f2d3`'s tree | **386 passed, 0 failed, 34 ignored** in 1009.29s (r1's tree had 385/0/35 -- one test moved out of `ignored` and into `passed`: this round's un-ignored straddling gate)
74+
75+## Refusals
76+None lifted this round, so `refusal_inventory.rs` is unchanged. `gate_coverage.rs` needs no entry
77+either: its derivation deliberately excludes `--tile-columns` (see its header comment) and this
78+round adds no `--enable-*` flag.
79+
80+## Residue
81+* deferred(the 7 refusals in the census above) -- the multi-tile half of the straddling gate.
82+* accepted -- the gate compares SHOWN frames (`ffmpeg_decode_sequence`); no-show alt-ref frames are
83+ not compared here, same as every sibling gate (class `gate-blind-to-hidden-frames`).
lanes/golomb-r1.report.mdmodified+68 -0
@@ -45,3 +45,71 @@ desyncing.
45 correctly decoded as HORZ, on an INTER superblock row the inter path cannot code (rect inter45 correctly decoded as HORZ, on an INTER superblock row the inter path cannot code (rect inter
46 residual coding does not exist here). Next lane.46 residual coding does not exist here). Next lane.
47 - `reelb5.obu`: "a 32x32-level 1:4 strip with a split transform (depth=2)" (unchanged by this lane).47 - `reelb5.obu`: "a 32x32-level 1:4 strip with a split transform (depth=2)" (unchanged by this lane).
48+
49+---
50+
51+# lane-golomb r2 — the 32x32-level frame-edge HORZ/VERT second half
52+
53+## Must-fix (verifier golomb1): fixed
54+Since r1 the 32-level edge read can return HORZ/VERT (bit 0), so the second 32x16/16x32 half is
55+out of frame and must not be decoded. libaom `decode_partition`:
56+`case PARTITION_HORZ: decode_block(top); if (has_rows) decode_block(bottom)` (mirror for VERT).
57+
58+- `crates/ec-av1/src/decode.rs:10887` (intra `PARTITION_HORZ` @32) — second 32x16 now behind `if has_rows32`.
59+- `crates/ec-av1/src/decode.rs:10928` (intra `PARTITION_VERT` @32) — second 16x32 behind `if has_cols32`.
60+- `crates/ec-av1/src/decode.rs:17900` (inter `PARTITION_HORZ` @32) — same guard, `has_rows32`.
61+- `crates/ec-av1/src/decode.rs:18008` (inter `PARTITION_VERT` @32) — same guard, `has_cols32`.
62+- `crates/ec-av1/src/decode.rs:1600` — new `EDGE32_HITS` counter (+ `edge32_hits()`, `bump_edge32`):
63+ slot 0/1 = 32-level edge bit read as HORZ/VERT vs SPLIT, slot 2 = a bottom-edge HORZ strip
64+ decoded (`has_rows32 == false`), slot 3 = a right-edge VERT strip.
65+
66+AB / 1:4 arms at the 32 level need NO guard: at an edge libaom's `ec_read_partition_impl` can only
67+yield HORZ, VERT or SPLIT, so those arms are unreachable there (stated per charter).
68+16-level edge rect arms swept and left as they are: intra refuses by name
69+("a 16x16 block at the true frame edge coded as a rect strip rather than SPLIT"), inter falls to
70+"an inter partition below 16x16 other than SPLIT".
71+
72+## Gate
73+NEW `stream::tests::a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition_decodes_pixel_exact`
74+(crates/ec-av1/src/stream.rs:14800+): 192x80 (bottom edge, mi_rows=20) and 80x192 (right edge),
75+testsrc2 + seeded `noise`, cq {35,40,45,50,55,57,59,61}, 8-bit AND 10-bit (bit_depth asserted),
76+plus a 5-frame INTER arm; every decode pixel-compared against ffmpeg, counters sampled per attempt
77+and summed only over compared attempts.
78+
79+EVIDENCE: $HOME/.cache/golomb-suite-r2.log + gate stdout | cargo test -p ec-av1 --lib -- --nocapture
80+a_real_aomenc_stream_with_a_32x32_frame_edge | 32 pixel-exact attempts, 8 named refusals,
81+edge32 bits [horz_or_vert=0 split=178] — the 32-level edge read fires 178 times and every attempt
82+decodes pixel-exact.
83+
84+Recipe deviations from the charter, with reasons (measured, not assumed):
85+- `--min-partition-size=32`, not 8: at 8 (and at 16) the sub-16 AB / split-transform strip arms
86+ refuse by name before the 32-level edge is reached — 40/40 attempts refused.
87+- `--tune-content=film` + `noise`: without them aomenc's screen-content detection makes every
88+ attempt refuse at "a HORZ/VERT intra strip in a screen-content frame" (the verifier's smptebars
89+ trap, reproduced here with plain testsrc2).
90+
91+## OPEN DEFECT (fix-now, next round) — the edge HORZ strip's pixels
92+With detail in the straddling band aomenc always answers the edge bit with SPLIT (178/178), so the
93+HORZ/VERT arm never fires. Leaving that band FLAT (`pad=...:gray`) forces it:
94+EVIDENCE: gate stdout | cargo test -p ec-av1 --lib -- --ignored --nocapture
95+a_32x32_frame_edge_rect_partition_with_a_flat_band | 192x80 cq40 8-bit, `edge32=[2, 0, 2, 0]`
96+(two bottom-edge HORZ strips decoded), plane Y 1081 pixels differ, first at row 62 col 128,
97+diffs per row confined to rows 62..79 (~64 of 192 columns) — exactly the two 32x16 strips plus the
98+deblock bleed above them; every other pixel of the frame matches ffmpeg.
99+Reading: the guard itself is validated (no desync — the rest of the frame is entropy- and
100+pixel-exact where before it would have consumed an out-of-frame half), but the strip's own
101+reconstruction (prediction/neighbour availability at the frame edge) is wrong. Pinned as
102+`#[ignore]`d test `a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact` so the
103+suite stays green and the defect stays runnable. Disposition: fix-now for r3 (owner: this lane).
104+
105+## Suite (r2)
106+`$HOME/.cache/golomb-suite-r2.log` — **337 passed / 1 FAILED / 32 ignored** (618 s).
107+The failure is NOT this round's arm and I could not attribute it to this diff:
108+`stream::tests::a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact`
109+panics at stream.rs:8479 "the stream decoded but no coded (non-skip) rect leaf fired". Its fixture
110+is a 64x64 mandelbrot frame — one whole superblock, `mi_cols = mi_rows = 16`, so
111+`has_rows32`/`has_cols32` are true everywhere and none of this round's four guards (nor r1's
112+edge reads) can execute on it. Deterministic (fails standalone in 0.34 s, same message).
113+Disposition: deferred(a bisect of eacd7fd vs 3e4ce89 in a detached worktree, or the owner of
114+`rect_leaf_coeff_hits`) — it is either pre-existing on eacd7fd (r1's suite log predates today's
115+oracle/ffmpeg state) or a sibling-gate regression from a path I did not touch. NOT claimed green.
lanes/golomb-r3.report.mdadded+106 -0
@@ -0,0 +1,106 @@
1+# lane-golomb r3 — the suite red was my own gate recipe; the edge strip was out-of-frame transform units
2+
3+## TASK 1 — bisect table (the r2 suite failure)
4+
5+`stream::tests::a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact`,
6+run in a detached scratch worktree (`scratchpad/verify-golomb`, `CARGO_TARGET_DIR=~/.cache/cargo-target-verify`):
7+
8+| commit | what it is | result |
9+|---|---|---|
10+| a762fff | mcomp64 base | ok, 1 passed |
11+| 909064f | + fi8 cherry-pick 2d5c425 | ok, 1 passed |
12+| eacd7fd | r1 edge-bit fix | ok, 1 passed |
13+| fd54bcf | r2 guards | **FAILED** — "the stream decoded but no coded (non-skip) rect leaf fired" |
14+
15+EVIDENCE: bisect stdout above | `git worktree add --detach` at each sha, `cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16` | 3 ok / 1 FAILED, first red = fd54bcf
16+
17+Root cause: **not** fi8, not the r1 edge read. r2's per-arm recipe override
18+(`--min-partition-size=32 --tune-content=film`) was pasted into the WRONG gate — hunk
19+`stream.rs@8435`, inside `a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16`, whose whole
20+point is sub-16x16 rect leaves. At `--min-partition-size=32` that 64x64 mandelbrot frame cannot
21+contain a 16x8 leaf, so `rect_leaf_coeff_hits` went to 0 and the gate's own
22+"the gate proves nothing" assert fired — the assert did its job. Fixed in ebec75d by restoring
23+`--min-partition-size=8`; the edge32 gate has always carried its own copy of the override.
24+No warning is owed to the fi8 merge agent: fi8 is already on main (b1d8457) and is exonerated by
25+row 2 of the table.
26+
27+EVIDENCE: gate stdout | `cargo test -p ec-av1 --lib -- --nocapture a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16` after ebec75d | `pixel-exact, rect_leaf_coeff_hits=8`, 1 passed
28+
29+## TASK 2 — the frame-edge strip's wrong pixels: out-of-frame transform units
30+
31+Class: `parsed-then-discarded`'s mirror — *read* something the reference never wrote
32+(`equal-range-means-unread`).
33+
34+Reproduced standalone (192x80 cq40 8-bit flat band, md5 `4bd18b25…`, scratchpad `e32.obu`):
35+1081 Y pixels differ, rows 62..79, **cols 124..191** — the LAST superblock only.
36+
37+The oracle's own view of that superblock row (instrumented aomdec):
38+`EC_PRED mi_row=16 mi_col=16 … bsize=11 part=1 txw=16 txh=16` with **row_off=0 only** (four TUs),
39+and `mi_row=16 mi_col=32 … bsize=11 part=1 txw=32 txh=32` (two TUs). `bsize=11` is
40+`BLOCK_64X32`: aomenc answers the bottom-edge superblock with the **64-level** `PARTITION_HORZ`,
41+never the 32-level one, and codes only the transform-unit ROW that is inside the frame.
42+
43+Ours decoded `mi_col=16` identically (`TRACE_RECT_SPLIT bw=64 bh=32 tx=16`) but then walked
44+`bh/tx = 2` TU rows, reading coefficients for four phantom 16x16 units at y=80..95 — outside a
45+frame whose `mi_rows*4 == 80`. That desynced the stream at exactly the next symbol: the SB2
46+partition bit came out SPLIT (two 32x16 strips, `edge32=[2,0,2,0]`) where the oracle read HORZ.
47+The r2 report's reading ("prediction/availability inside the strip") was wrong; the strips
48+were the *symptom* of a desync, and the "32-level edge HORZ fired" counter was a
49+`counter-from-refused-stream`-shaped artefact of our own desync.
50+
51+Fix — `crates/ec-av1/src/decode.rs:4818` (`decode_rect_split`, the only place a block hangs off
52+the frame): skip a transform unit whose top-left sample is outside `true_width`/`true_height`
53+(`mi_cols*4`/`mi_rows*4`), mirroring libaom `av1_foreach_transformed_block_in_plane`'s
54+`max_blocks_wide/high` clip (`mb_to_right_edge`/`mb_to_bottom_edge`). The chroma unit of a strip
55+always has its top-left inside, so it is unaffected.
56+
57+EVIDENCE: scratchpad/{e32.obu, ours.yuv, ao.yuv, ao-pred.txt, ours-step.txt} | instrumented
58+aomdec `EC_PRED`/`EC_TRACE_MODE_STEP` vs `decode_probe`, byte diff of the two raw yuv420p dumps |
59+before: 1081 Y pixels differ (first diff at our `EC_ISTEP mi_row=16 mi_col=32 name=skip rng=51413`
60+vs oracle `rng=32901`); after: **0 differing bytes over all three planes**
61+
62+## Counters + the pin, un-ignored
63+
64+`EDGE32_HITS` widened 4 → 8 slots (`decode.rs:1602`): slots 4/5 = the **64**-level gathered edge
65+bit read as HORZ/VERT / SPLIT (both tile paths), 6 = a 64x32 bottom-edge strip decoded with
66+`has_rows == false`, 7 = a 32x64 right-edge strip. Necessary because the flat-band arm's r2
67+assert (`totals[2] > 0`, a 32-level bottom-edge HORZ) was only ever satisfied by our own desync;
68+on a correct decode of this content the 32-level slots are 0 by construction and the 64-level
69+slots carry the proof. `#[ignore]` removed from
70+`a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact`.
71+
72+EVIDENCE: gate stdout | `cargo test -p ec-av1 --lib -- --nocapture a_32x32_frame_edge` |
73+2 passed; flat arm: 32 pixel-exact attempts, 64-level edge bits [horz_or_vert=96 split=0]
74+bottom-HORZ=48 right-VERT=48, 32-level slots all 0; detail arm: 32 pixel-exact attempts,
75+64-level [horz_or_vert=7 split=89] right-VERT=7, 32-level split=178
76+
77+## Suite
78+`$HOME/.cache/golomb-suite-r3.log` — **339 passed / 0 failed / 31 ignored** (277 s), run as a
79+user systemd unit on the final tree. r2 was 337/1 FAILED/32 ignored: +1 fixed (task 1), +1
80+un-ignored (task 2).
81+
82+Siblings re-run inside that suite, all green: `a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16`,
83+`the_reelb_head_key_frame`, both `a_*_32x32_frame_edge_*`, `tiny_frame_size_sweep`,
84+`superblock_level_*`, `filter_intra_*`, `refusal_inventory`, `gate_coverage`.
85+
86+## Same-shape sweep
87+`decode.rs:7458` (`decode_block`'s square multi-TU loop) has the identical unclipped
88+`0..n_axis` shape and now carries the identical guard. A square block only hangs off the frame
89+when the frame's mi dimensions are odd at that block's level (lane-oddh's territory), so no gate
90+in this suite reaches it: the guard is libaom's rule applied by inspection, proven only inert
91+here (suite unchanged). `decode_block_rect64` delegates its split case to `decode_rect_split`,
92+so it is covered by the measured fix. Flagged, not claimed.
93+
94+## Film
95+`hg-head.obu` (18 frames) still stops at
96+"an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path
97+recurses a superblock only as SPLIT)" — unchanged by this round (same string as r1's residue;
98+the inter tile path never reaches a 64-level HORZ).
99+EVIDENCE: probe stdout | `cargo run -p ec-av1 --example decode_probe -- hg-head.obu` | REFUSED at
100+the inter SB-level partition, 18 frame headers parsed, tiling cols=1 rows=1
101+
102+## Residue
103+- deferred: the inter tile path's 64-level `PARTITION_HORZ`/`VERT` (the film's next blocker) —
104+ unblocked by rect inter residual coding, which is lane-inter*/interbis territory, not this one.
105+- accepted: the square-block guard above is unexercised by any gate on this lane (odd-mi
106+ geometry is lane-oddh's gate).
lanes/golomb-r4.report.mdadded+93 -0
@@ -0,0 +1,93 @@
1+# lane-golomb r4 — merge with main, and the 32x32-frame-edge cross-product isolated (NOT fixed)
2+
3+## STEP 1 — merge (DONE, commit 17fc2a7 `Merge branch 'main' into lane-golomb`)
4+
5+`git merge main` (main b51719f) conflicted in 4 files; 14 hunks in `decode.rs`.
6+Resolution (all by hand, no `cargo fmt`):
7+
8+* `crates/ec-av1/src/cdf.rs`, `crates/ec-av1/src/cdf_state.rs` — main's, whole.
9+* `crates/ec-av1/src/decode.rs`
10+ * fi32x8 rows `(32,8)=>10 / (8,32)=>11` in `filter_intra_size_class`: main's.
11+ * `decode_rect_split`'s TU loop: main's rect `tx_w`/`tx_h` form, with golomb r3's
12+ TU-ORIGIN CLIP re-applied per axis inside it
13+ (`if tu_px >= y.true_width || tu_py >= y.true_height { continue; }`).
14+ * oddh's 16-level edge HORZ/VERT strip (replaces golomb's refusal): main's.
15+ * golomb's 6 edge-bit counter sites (`bump_edge32` / `bump_edge32_bit`) and the
16+ 64-level + 32-level SECOND-HALF guards: kept, re-applied on top of inter4's
17+ MI-unit `decode_inter_block` signature (`sub16_to_mi(...)`) at both inter
18+ SB-level HORZ (`edge32` slot 2) and VERT (slot 3) arms.
19+* `lanes/golomb-r1.report.md` — lane's.
20+
21+`cargo check -p ec-av1` + `cargo test -p ec-av1 --lib --no-run`: clean.
22+
23+## STEP 2 — the cross-product: ISOLATED to one block, root cause NOT yet found
24+
25+Gate `a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition_decodes_pixel_exact`
26+still FAILS on the merged tree, identically to merge-E's report:
27+`192x80 cq59 frames=5 8-bit frame 1 plane Y: 90 pixels differ, first at row 61 col 174
28+(ours 175 vs ffmpeg 174) [edge32=[1, 35, 1, 0, 0, 18, 0, 0]]`.
29+
30+Stream reproduced standalone (md5 `48e1d78f31a4eb6a6ef5a67df9bd36fe`, 971 B):
31+`ffmpeg -f lavfi -i "testsrc2=size=192x80:duration=0.2:rate=25,noise=alls=6:allf=t+u:all_seed=59"
32+ -pix_fmt yuv420p ... | aomenc <the gate's flags> --cq-level=59` (script in the handoff).
33+
34+### What the facts say (each with its command)
35+
36+1. **The first divergent picture is DECODE-order picture 2, not shown-frame 1.**
37+ `EC_AV1_PREFILT_DUMP` on both decoders, luma compared per picture:
38+ f0 0 diffs, f1 0, **f2 130**, f3 84, f4 110. The shown-frame-1 report is the
39+ propagated copy. (Class `gate-blind-to-hidden-frames` applies to the READING of
40+ the gate message, not to the gate.)
41+2. **The wrong pixels are exactly one 16x16 block**: picture 2, rows 64..79 x
42+ cols 160..175 = mi(16,40), max |delta| 36 — a prediction-scale error, not rounding.
43+3. **libaom decodes mi(16,40) as SPLIT into two 16x16 leaves in every picture**
44+ (`EC_TRACE=1 aomdec | grep 'mi_row=16 mi_col=40 bsize=9'` → `value=3` x6);
45+ **we decode a 32-wide HORZ strip there in picture 2 only**
46+ (`EC_AV1_COMPIDX_DUMP=1` → `mi_row=16 mi_col=40 bsize=32 mode=0 mv0=(-30,-20)
47+ mv1=(16,0) ref0=1 ref1=7`, where libaom has `mode=18 (NEAR_NEARMV) mv0=(-16,0)`).
48+ That is inter4's SB/32-level inter rect arm consuming golomb's frame-edge bit —
49+ a path neither parent could reach.
50+4. **The edge bit is NOT the defect.** Instrumented pre-read state at the 32-level
51+ gathered read (temporary `DBG32PRE`, reverted): ctx = 2 (= libaom's 10 = bsl 2 * 4 + 2),
52+ CDF row and 2-entry gather identical in all 6 pictures, and the pre-read RANGE
53+ matches aomdec's `EC_PART ... rng=` in 11 of 12 reads. The one mismatch is
54+ picture 2 at mi(16,40): ours 39967, libaom 64226 — i.e. **we arrive at the bit
55+ already desynced**, and the wrong HORZ is the consequence.
56+5. **The desync starts inside the 16x16 INTER block at mi(16,32), picture 2.**
57+ Range ladder (ours `EC_AV1_TELL`/`EC_TRACE_MODE` vs aomdec `EC_TRACE_MODE`):
58+ * mi(16,32) entry / post_is_inter: ours 52732 == libaom `EC_MODE ... rng=52732`.
59+ * libaom then reads compound NEAR_NEARMV `ref0=1 ref1=7 mv0=(0,0) stack=3`
60+ (`EC_MODE_MV rng=39839`, `EC_MODE_VAL rng=56231`) and leaves the block at 62618.
61+ * ours leaves the block at 35347 (`TELL ... label=block_end tell=232 range=35347`),
62+ having consumed ~1 bit: no `EC_MODE_VAL` (single-ref print) and no `EC_COMPIDX`
63+ line for that block at all.
64+ So we read FEWER symbols than libaom for a `skip=true`, `is_inter=true` compound
65+ block at the bottom frame edge. First divergent element: the symbol(s) after
66+ `intra_inter` in `decode_inter_block` at mi(16,32) (ref-frame / compound-mode
67+ group), picture 2.
68+6. Coefficient ladders are otherwise identical (6426 aligned
69+ `EC_COEFF_STEP tag=base|sign|all_zero|eob|base_eob|after_bases|post_golomb` rng
70+ values, `diff` empty), so this is a LOCAL symbol-count divergence in one block
71+ that re-converges, not a whole-tile desync.
72+
73+EVIDENCE: /tmp/.../scratchpad/{ours,aom}.f0..f5 | `EC_AV1_PREFILT_DUMP` both decoders on g4.obu | first divergent picture = 2, diff box rows 64..79 x cols 160..175 (130 px, max 36)
74+EVIDENCE: /tmp/.../scratchpad/{o,a}-cf.txt | `EC_TRACE_COEFF=1` both decoders, aligned tags | 6426 == 6426 lines, `diff` empty (entropy re-converges)
75+EVIDENCE: /tmp/.../scratchpad/{ours,aom}-mode.txt + tell.txt | `EC_TRACE_MODE` / `EC_AV1_TELL` ours vs aomdec | mi(16,32) p2 entry 52732 == 52732, exit ours 35347 vs libaom 62618
76+
77+## Status / disposition
78+
79+* merge: DONE and committed.
80+* the 32x32-frame-edge cross-product: **OPEN — fix-now, next round**, isolated to
81+ the symbol group read after `intra_inter` for the compound block at mi(16,32) in
82+ picture 2. Not a golomb-side defect in the edge bit (fact 4).
83+* verifier's r3 item (no `max_blocks_wide/high` clip on the INTER var-tx leaf loops
84+ at `decode.rs` ~14135 / ~14970, plus a 192x68 / 68x192 gate arm with a
85+ straddling-TU counter): **deferred — turn budget spent on the cross-product
86+ isolation above — unblocked by a fresh round; nothing about it is contradicted
87+ by this round's findings.**
88+
89+## Suite
90+
91+`cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/golomb-suite-r4.log`): **364 passed, 2 failed, 31 ignored** in 547 s.
92+Failure 1 = the stale golomb refusal string `"a 16x16 block at the true frame edge coded as a rect strip rather than SPLIT"` still listed in `refusal_inventory.rs` after the merge took oddh_s lifted strip -- deleted in the follow-up commit (refusal_inventory 3/3 green after).
93+Failure 2 = the open cross-product above.
lanes/golomb-r5.report.mdadded+109 -0
@@ -0,0 +1,109 @@
1+# lane-golomb r5 — the 32x32-frame-edge cross-product ROOT-CAUSED and fixed (luma exact); gate still RED on a newly-exposed chroma defect
2+
3+## What changed
4+
5+* `crates/ec-av1/src/mvstack.rs:1663-1703` (commit `13aebbe`) — `find_mv_stack_compound`
6+ now runs libaom's three `tpl_sample_pos` EXTENSION samples
7+ (`mvref_common.c:563-600`, `allow_extension` + `check_sb_border` at
8+ `mvref_common.c:316`, mask hardcoded `mi_size_wide[BLOCK_64X64]`=16). The
9+ single-ref twin (`mvstack.rs:863-891`) already carried them; the compound
10+ path dropped them. Same hunk as lane-sb128 `d6cca7d` (independent lane, same
11+ root cause found from the other end).
12+
13+Nothing else. The r4 debug ladder used to find this was removed before commit.
14+
15+## Root cause (H3 of the charter; H1 skip_mode and H2 comp-ref ctx both exonerated)
16+
17+Charter's isolated element: `192x80 cq59 frames=5 8-bit`, DECODE-order picture 2,
18+16x16 inter block at mi(16,32), entry range 52732 == libaom, exit ours 35347 vs
19+libaom 62618.
20+
21+A temporary compound range ladder (`EC_LAD` after `read_comp_mode`, after
22+`read_compound_ref_frames`, after `read_inter_compound_mode`, after
23+`assign_compound_mv`) showed:
24+
25+| element | ours (before) | libaom |
26+|---|---|---|
27+| block entry (post `intra_inter`) | 52732 | 52732 |
28+| `is_compound` | true | true |
29+| ref pair | `ref0=1 ref1=7` | `ref0=1 ref1=7` |
30+| **compound stack** | **2 entries** `[(-16,0)/(14,0) w=672, (0,0)/(0,0) w=672]` | **3 entries**, same two + `(-10,0)/(10,0) w=2` |
31+| compound mode | 1 = `NEAR_NEARMV` | 18 = `NEAR_NEARMV` |
32+| post-mv | 50080 | 39839 |
33+
34+So `skip_mode` and the whole reference-frame group were already right (H1/H2 dead).
35+With `ref_mv_count == 2` our `NEAR_NEARMV` drl loop condition
36+(`count > idx + 1`, idx=1) is false, so we never read the `drl_mode` symbol
37+libaom reads at `ref_mv_count == 3` — **one bit short**. Every later symbol in the
38+tile then read from the wrong place, and the 32-level gathered edge bit at
39+mi(16,40) resolved HORZ where libaom split (the r4 "edge bit" symptom was the
40+consequence, not the cause — matching r4 fact 4).
41+
42+The missing candidate has weight 2: `add_tpl_ref_mv`'s temporal vote
43+(`ref_mv_weight[idx] = 2 * weight_unit`), from extension sample
44+`(voffset, hoffset) = (4,4)` at mi(16,32) (`16&15=0`, `32&15=0`, both in range).
45+
46+After the fix the ladder is exact through the block: stack 3 == 3 with identical
47+entries and weights, post-mv 39839 == libaom `EC_MODE_MV rng=39839`, next block
48+entry 62618 == 62618, and mi(16,36) stack weight `w=10` == 10 (was 8, i.e. the
49+same missing weight-2 vote folded into an existing entry).
50+
51+EVIDENCE: /tmp/.../scratchpad/gl-r5-ours.txt (before) + gl-r5-ours2.txt (after) vs aom-mode.txt | `EC_TRACE_MODE` ours (temporary EC_LAD compound ladder) vs instrumented aomdec on g4.obu md5 48e1d78f31a4eb6a6ef5a67df9bd36fe | mi(16,32) p2 stack 2->3, post-mv 50080->39839 == libaom, next-block entry 39296->62618 == libaom
52+
53+EVIDENCE: /tmp/.../scratchpad/g4-ours.yuv vs g4-aom.yuv | `decode_probe EC_PROBE_OUT` vs `aomdec --rawvideo` on g4.obu | plane Y ALL 5 FRAMES EXACT (was f1 90, f2 143, f3 106 wrong pixels); chroma residue below
54+
55+## Gate: still RED, on a DIFFERENT defect
56+
57+`cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition`
58+
59+* baseline (`fbc427c`): `192x80 cq59 frames=5 8-bit frame 1 plane Y: 90 pixels differ, first at row 61 col 174 [edge32=[1,35,1,0,0,18,0,0]]` (log `$HOME/.cache/golomb-gate-r5-base.log`)
60+* with the fix: `192x80 cq35 frames=5 8-bit frame 1 plane U: 335 pixels differ, first at row 0 col 56 [edge32=[0,36,0,0,0,18,0,0]]` (log `$HOME/.cache/golomb-gate-r5.log`)
61+
62+The gate now fails EARLIER in the cq sweep (35 < 59) because **cq35 was never
63+compared before**: at baseline that stream hit a false named refusal
64+(`"an inter 16x16-level AB or 1:4 partition"`) produced by our own desync, so the
65+gate `continue`d past it. With the stack fixed it decodes end to end. Class
66+`refusal-from-own-desync` + `refusal-hides-a-defect`, both already in memory.
67+
68+The residual defect is **chroma-only and pre-existing**: on both streams luma is
69+bit-exact in every frame while U/V carry scattered ±1..±3 across the whole plane
70+(g4 baseline already had f1 U 75 / V 185 wrong under the luma failure). The key
71+frame (f0) is exact, so it is inter chroma only, and V is consistently ~2.5x worse
72+than U.
73+
74+EVIDENCE: /tmp/.../scratchpad/g35-ours.yuv vs g35-aom.yuv | decode_probe vs aomdec on g35.obu (md5 9037f5b21db95d35e71f91f040fc33e1, recipe scratchpad/gl-gen.sh, hashed twice identical) | f0 exact, f1..f4 luma exact, U 335/324/1183/691 and V 408/412/1158/746 wrong, deltas -4..+5
75+EVIDENCE: /tmp/.../scratchpad/g35-ours.txt vs g35-aom.txt | `EC_TRACE_MODE` block-entry ranges, ours vs aomdec | all 48 of our `EC_MODE` ranges match libaom's in order — entropy fully in sync, so this is a pure chroma reconstruction defect, not a symbol defect
76+
77+## The r3 verifier item (`max_blocks_wide/high` clip on the INTER var-tx leaf loops)
78+
79+**Already implemented, at the shared entry point** — no code needed
80+(`decode.rs:10317`):
81+
82+```
83+fn read_var_tx_size(..., (max_w_mi, max_h_mi), ...) {
84+ if blk_row >= max_h_mi || blk_col >= max_w_mi { return; }
85+```
86+
87+`max_w_mi`/`max_h_mi` are computed as `mi_cols.saturating_sub(at_mi.1)` /
88+`mi_rows.saturating_sub(at_mi.0)` at BOTH inter callers
89+(`decode.rs:10402-10403` square, `decode.rs:10630-10631` rect), i.e. libaom's
90+`max_blocks_wide/high` in the same 4x4 units. A leaf whose top-left mi is outside
91+the frame is therefore never emitted into `vartx_leaves`, and the two reconstruct
92+loops (`decode.rs:15852`, `decode.rs:16830`) cannot see one. Adding a second
93+`tu_px >= y.true_width` guard there would be dead code.
94+
95+## Status / disposition
96+
97+* the mi(16,32) compound-stack desync: **FIXED**, luma bit-exact on the charter's stream.
98+* the chroma ±1 residue: **fix-now, next round** — first block to bisect is chroma
99+ plane U/V of `g35.obu` frame 1 (entropy is proven in sync, MVs proven right by
100+ exact luma, so it is chroma prediction/rounding or the per-plane chroma
101+ quantizer; V-worse-than-U points at a per-plane term, cf. memory
102+ `parsed-then-discarded`). Unblocked by a fresh round; nothing here contradicts it.
103+* r3 verifier item (var-tx clip): **accepted as already-satisfied**, cited above.
104+ Its 192x68 / 68x192 gate arm: **deferred — the gate it would join is RED, so a
105+ new arm would only add noise — unblocked by the chroma fix above.**
106+
107+## Suite
108+
109+`cargo test -p ec-av1 --lib` under a user systemd unit, log `$HOME/.cache/golomb-suite-r5.log`: re-armed as unit `golomb-suite-r5` after restoring the `#[ignore]` attribute on `a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact` (the r2 open-defect twin; the attribute was lost in the r4 merge and the test ran, and failed, in the mid-round run). Expected failures: the one open gate above. The coordinator reads the log.
lanes/golomb-r6.handoff.mdadded+118 -0
@@ -0,0 +1,118 @@
1+# lane-golomb r6 HANDOFF
2+
3+## Merge state (STEP 1: DONE)
4+* `899d7cf` = `git merge main` (main `18bf7dc`). Real merge commit, not a squash.
5+* `crates/ec-av1/src/mvstack.rs`: `git diff main -- mvstack.rs` is EMPTY -> ONE copy of the
6+ compound tpl-extension hunk (lane-sb128 `d6cca7d` == our `13aebbe`), byte-identical to main.
7+* `crates/ec-av1/src/cdf.rs` and `cdf_state.rs`: `git diff main` EMPTY (NZ_MAP/FILTER_INTRA
8+ byte-identical to main).
9+* 7 `decode.rs` conflicts resolved: 4 were comment-only (took main's text); 3 were the counter
10+ pair -- main's `bump_edge_part` and this lane's `bump_edge32` are INDEPENDENT counters, BOTH
11+ kept at every site (`decode.rs:13094-13101`, `13169-13179`, and the two `!has_rows32/!has_cols32`
12+ guards).
13+* `#[ignore = "open r2 defect: ..."]` on
14+ `a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact`
15+ (`stream.rs:18414`) SURVIVED the merge -- verified by grep after the merge commit.
16+
17+## Suite r5
18+`$HOME/.cache/golomb-suite-r5.log` had NO `test result:` line: the unit was still `active` and
19+I stopped it (`systemctl --user stop golomb-suite-r5`) to free `CARGO_TARGET_DIR` for r6 -- it
20+was building the PRE-merge tree, so its result would have been superseded anyway. Every `test`
21+line present in it up to that point was `ok`. r6 suite armed as unit `golomb-suite-r6`
22+-> `$HOME/.cache/golomb-suite-r6.log`; READ THAT, not r5.
23+
24+## STEP 2: chroma residue -- ROOT CAUSE #1 FOUND AND FIXED
25+
26+Stream: `g35.obu`, md5 `9037f5b21db95d35e71f91f040fc33e1` (regenerated, hash confirmed;
27+recipe `scratchpad/gl-gen.sh 35 <out>`), 192x80 cq35 5 frames 8-bit, 6 decode-order pictures.
28+
29+### Localization method (reusable)
30+Three-stage compare, decode order, ours vs the oracle:
31+`EC_AV1_PREFILT_DUMP` (pre-loopfilter) / `EC_AV1_POSTDEBLOCK_DUMP` (post-deblock, pre-CDEF) /
32+`EC_AV1_FINAL_DUMP` (post everything). Ours dumps a PADDED plane (192x96 luma), aomdec dumps
33+CROPPED (192x80) -- the comparator must use different strides per side.
34+NOTE: `EC_AV1_PREFILT_DUMP16`/`..._DUMP16` SEGFAULT the oracle aomdec on an 8-bit stream
35+(`ec_dump16` does `CONVERT_TO_SHORTPTR` unconditionally, decodeframe.c:3968). Use the 8-bit
36+`*_DUMP` vars for 8-bit streams.
37+Ours' `dump_stage` used to write `.f0` for EVERY frame (overwrite); r6 gave it a per-var
38+thread-local index (`decode.rs`, `dump_stage`) so POSTDEBLOCK is now `.f0..fN` like the oracle.
39+
40+### The measurement that localized it
41+Before the fix: prefilt decode-f1 EXACT, post-deblock decode-f1 U342/V380 wrong, luma exact at
42+every stage -> the defect was the DEBLOCK filter on chroma, not prediction, not CDEF
43+(`--enable-cdef=0` did NOT fix it), not LR (disabled in the recipe).
44+
45+### Root cause (fixed)
46+`decode.rs`, inter block tail: the var-tx / split-tx LEAF loop called
47+`Neighbours::fill_lf_grid_rect(leaf_mi, tx_px/MI, tx_px/MI, ...)`, and that function DERIVES
48+the chroma grids from the span it is given (`uv_tx_w = (w_mi*MI/2).clamp(4,32)`). So every
49+var-tx leaf OVERWROTE the block's correct `uv_tx_grid`/`uv_tx_h_grid` (the block's
50+`av1_get_max_uv_txsize`) with `leaf_tx/2`, inventing chroma transform edges the deblocker then
51+filtered. libaom `get_transform_size` (`av1/common/av1_loopfilter.c:207`) applies the var-tx
52+override ONLY `if ((plane == AOM_PLANE_Y) && is_inter_block(mbmi) && !mbmi->skip_txfm)`;
53+chroma always keeps `av1_get_max_uv_txsize(mbmi->bsize, ss_x, ss_y)`.
54+FIX: new `Neighbours::fill_lf_grid_leaf_luma` writes ONLY `tx_grid`/`tx_h_grid` over the leaf
55+span (`ref_grid`/`delta_lf_grid` are already correct from the block's own fill over the same
56+span), and the leaf loop calls it. Sweep: this was the ONLY `fill_lf_grid_rect` caller passing
57+a TU span; all 12 others pass block dims (checked each).
58+
59+### Result
60+g35 ours vs aomdec, all three stages, decode order:
61+before f0 exact, f1 U398/V457, f2 U325/V412, f3 U336/V408, f4 U~1000/V~1000, f5 U691/V746
62+after f0-f3 EXACT at prefilt+postdeblock+final, f4 U974/V973 (prefilt), f5 inherits it.
63+
64+## RESIDUE (still RED) -- exactly one defect left
65+Gate: `cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition`
66+=> `192x80 cq35 frames=5 10bit=false frame 3 plane U: 978 pixels differ, first at row 0 col 32
67+(ours 33 vs ffmpeg 8) [edge32=[0,36,0,0,0,18,0,0]]`.
68+
69+* Stage: **PREFILTER** (prediction+residual), decode-order picture 4 only (f5 inherits).
70+ Deblock/CDEF/LR are exonerated for this one.
71+* Extent: EXACTLY chroma x 32..63, y 0..31 = luma x 64..127, y 0..63, i.e. one whole 64x64
72+ superblock. Luma bit-exact inside it.
73+* Shape of the error: HIGH-FREQUENCY, |delta| up to 52. aomdec's row 0 is smooth
74+ (13,14,14,14,...) where ours is (36,12,0,0,20,22,...). That is a RESIDUAL/inverse-transform
75+ shape, not a prediction-offset shape.
76+* Blocks in that SB (decode f4, from `EC_TRACE_MODE`): mi(0,16) mode=23 ref0=1 ref1=7 (compound),
77+ mi(0,24) mode=17 ref0=1 ref1=7, mi(8,16) mode=17 ref0=1 ref1=7, mi(8,24) mode=13 ref0=7
78+ single-ref. All 32x32.
79+
80+### Ruled out (each with the command that ruled it out)
81+* deblock / CDEF / LR: prefilt already differs on f4.
82+* per-plane `delta_q_u/v_dc/ac`: consumed (`stream.rs:599-603` etc.) AND f0-f3 chroma is now
83+ bit-exact under the same quantizer.
84+* narrow-block (<=4-wide) chroma MC kernel and sub8x8 chroma MV derivation: impossible in this
85+ stream, `--min-partition-size=32` means the smallest chroma block is 16x16.
86+* chroma MC rounding: derived by hand that our always-2-pass convolve is bit-identical to
87+ libaom's `av1_convolve_x_sr_c`/`_y_sr_c` single-pass rounding when one fraction is 0
88+ (identity tap 128, round2(x*16,11) == ROUND_POWER_OF_TWO(x,7)); and f1-f3 are now exact.
89+* **DIFFWTD compound (the tempting one -- DO NOT re-chase it blind):** `--enable-diff-wtd-comp=0`
90+ made the whole sequence exact, BUT that is a DIFFERENT bitstream (class gate-recipe-confound).
91+ An `EC_DWTD` trace of the ORIGINAL g35 shows only 4 diffwtd blocks in the whole stream, in
92+ decode f1 (px=64,py=0) and decode f2 (px=0,py=0 / px=64,py=0 / px=128,py=32) -- **NONE in
93+ decode f4**, where the residue is. DIFFWTD is therefore EXONERATED for this residue.
94+* warp / global motion / OBMC / dual filter / masked-comp / interintra / dist-wtd: ablated on
95+ the post-fix build, all still show the f3(display) failure (`scratchpad/abl.sh`).
96+
97+### Exact next step
98+The error is a chroma RESIDUAL in a 64x64 SB of decode-order picture 4 whose luma is exact and
99+whose entropy is (r5-proven) in sync. Bisect chroma coefficients, not prediction:
100+1. Run the oracle with `EC_TRACE_COEFF=1` and ours with `EC_TRACE_COEFF=1` on `g35.obu`, isolate
101+ decode picture 4, block mi(0,16), plane 1. Compare the DEQUANTIZED values element by element
102+ (and the msac RANGE per element, never `tell()`).
103+2. Prime suspect given "luma exact, chroma noisy, whole SB": the chroma `tx_type` inherited from
104+ the colocated luma unit (`decode.rs` `inherited_luma_tx_type`, `av1_get_tx_type`
105+ `blockd.h:1291`). For a var-tx-split luma block the chroma TU spans several luma TUs and
106+ libaom reads the luma tx_type at `blk_row<<ssy, blk_col<<ssx`; ours takes "the top-left unit".
107+ Verify that mapping against `av1_get_tx_type` for a 32x32 block whose luma split to 16x16.
108+ A wrong tx_type gives exactly this signature: right coefficients, wrong basis, chroma only.
109+3. Second suspect: `txsize_sqr_up_map[tx_size] > TX_32X32 -> DCT_DCT` clamp
110+ (ours clamps at `side >= 32`, on the CHROMA side length -- check that against
111+ `av1_get_ext_tx_set_type`'s use of the chroma tx size).
112+
113+## Deferred
114+* the 192x68 / 68x192 gate arm from r3's verifier ask: **deferred -- the gate it would join is
115+ still RED, a new arm would only add noise -- unblocked by the residue above.** The r3 code ask
116+ itself stays accepted-as-already-satisfied (`decode.rs` `read_var_tx_size`'s
117+ `blk_row >= max_h_mi || blk_col >= max_w_mi` early return, both inter callers pass
118+ `mi_cols/rows - at_mi`).
lanes/golomb-r7.handoff.mdadded+99 -0
@@ -0,0 +1,99 @@
1+# lane-golomb r7 HANDOFF -- residue CLOSED, gate GREEN, suite still running at the cap
2+
3+Tip: `a548e9d` on `lane-golomb` (parent `0fcdf39`). Full report: `lanes/golomb-r7.report.md`.
4+
5+## Suite r6 result line
6+There is none. `$HOME/.cache/golomb-suite-r6.log` was still `active` at 254/404 tests
7+(stuck in the long superres/encoder tests) and holding `CARGO_TARGET_DIR`, so r7 stopped
8+the unit to build -- it was measuring the PRE-fix tree and is superseded. Every `test`
9+line it did emit was `ok` or a documented `ignored`.
10+
11+## Suite r7 -- INCOMPLETE at the turn cap
12+Unit `golomb-suite-r7` -> `$HOME/.cache/golomb-suite-r7.log`, still `active` at 180/404
13+tests, NO `test result:` line yet, no `FAILED` line so far. A successor must read that
14+log (`grep -E "^test result|FAILED"`); if the unit died, re-arm it with the COMMON recipe.
15+This is the one owed artifact of the round.
16+
17+## What the picture-4 investigation showed (the ladder was not needed)
18+Method: `EC_TRACE_MODE=1 EC_TRACE_COEFF=1` on `g35.obu` (md5 `9037f5b21db95d35e71f91f040fc33e1`,
19+`scratchpad/gl-gen.sh 35`) through the r6-built `decode_probe`, stderr split into frames on
20+`EC_MODE mi_row=0 mi_col=0` -> segment 4 = decode-order picture 4
21+(`scratchpad/r7-ours.err`, still on disk).
22+
23+* The residue block is `mi(0,16)` and the next `EC_MODE` is `mi(0,32)`, so it is a **64x64**
24+ block, NOT the 32x32 r6 recorded. Var-tx split into 16x16 luma leaves.
25+* Its last two coefficient units are `eob=1022 tx=DctDct` and `eob=1020 tx=DctDct`
26+ (`ctx=0`): eob > 256 proves **32x32 chroma** units
27+ (`av1_get_max_uv_txsize(BLOCK_64X64) = TX_32X32`).
28+* Its FIRST luma var-tx leaf is `eob=254 tx=Idtx`.
29+* No dequant-value ladder against aomdec was required: the coefficient values are provably
30+ identical (the whole stream stays in entropy sync and luma is bit-exact), so the only
31+ free variable left was the chroma `tx_type` -- and `IDTX` vs `DCT_DCT` are both
32+ `TX_CLASS_2D`, i.e. identical scan, identical contexts, identical msac ranges, different
33+ inverse transform. That is exactly "entropy in sync, one SB of high-frequency chroma
34+ noise, luma exact".
35+
36+## Fix applied (root cause, libaom-cited)
37+`av1_get_tx_type`, `av1/common/blockd.h:1278-1309`, chroma of an INTER block:
38+1. `DCT_DCT` only when `txsize_sqr_up_map[tx_size] > TX_32X32` (STRICTLY greater);
39+2. else the colocated luma unit's coded type, `xd->tx_type_map[(blk_row<<ss_y)*stride + (blk_col<<ss_x)]`;
40+3. then `if (!av1_ext_tx_used[av1_get_ext_tx_set_type(tx_size, 1, reduced)][tx_type]) tx_type = DCT_DCT;`
41+ (`av1_ext_tx_used` blockd.h:1036, `av1_get_ext_tx_set_type` blockd.h:1097).
42+
43+We had step 1 as `chroma side >= 32 -> DCT_DCT` and step 3 missing entirely. At exactly
44+`TX_32X32` an inter block reads `EXT_TX_SET_DCT_IDTX`, which CONTAINS IDTX -> the block
45+above must use IDTX on chroma; we used DCT_DCT.
46+
47+`crates/ec-av1/src/decode.rs`: new `fn reduce_inherited_chroma_tx_type(t, w, h)` (just above
48+`fn inter_txbset_for`) implementing all four inter sets; both callers switched
49+(`read_inter_plane` and `read_inter_plane_rect` `default_tx_type`). Sweep: `rg
50+inherited_luma_tx_type` -- those are the ONLY two sites deriving a chroma tx_type for an
51+inter block; the intra sites (`decode.rs:6056`, `9195`) are correct as-is (intra at
52+`sqr_up == TX_32X32` really is `EXT_TX_SET_DCTONLY`).
53+Unit test added: `decode::tests::an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set`
54+(`cargo test -p ec-av1 --lib -- an_inter_chroma_transform_narrows` => 1 passed).
55+
56+## edge32 gate: every arm GREEN
57+`$HOME/.cache/golomb-gate-r7.log`: `test result: ok`,
58+`38 pixel-exact attempts, 32-level edge bits [horz_or_vert=0 split=394], 64-level edge bits
59+[horz_or_vert=7 split=197] right-VERT=7, 2 named refusals`.
60+Arms: (192x80, 80x192) x 1 frame x {8-bit,10-bit} plus 192x80 5-frame, cq
61+{35,40,45,50,55,57,59,61} -- so all eight cq levels are green at BOTH depths. The only two
62+non-compared attempts are `192x80 cq45/cq50 frames=5 8-bit`, which refuse by name on
63+another lane's feature (inter SB-level AB partition).
64+BEFORE: `192x80 cq35 frames=5 10bit=false frame 3 plane U: 978 pixels differ, first at row 0
65+col 32 (ours 33 vs ffmpeg 8)`.
66+
67+## Ruled out this round (each with its measurement)
68+* r6's "32x32 block at mi(0,16)" premise -- WRONG, the trace shows a 64x64 block (the next
69+ EC_MODE is mi(0,32)); anything chartered off "32x32 chroma is 16x16" was mis-premised.
70+* A wrong chroma tx SIZE: the chroma eob of 1022 (> 256) proves our unit really is 32x32,
71+ which is what `av1_get_max_uv_txsize` says.
72+* A dequant / per-plane delta_q cause: f0-f3 chroma is bit-exact under the same quantizer.
73+* Everything r6 already ruled out (deblock/CDEF/LR, DIFFWTD, warp/GM/OBMC/dual filter/
74+ masked-comp/interintra/dist-wtd, narrow-block chroma MC) stays ruled out.
75+
76+## Straddling-TU arm (r3 verifier ask): NOT added, and the two measurements say why
77+Both measured this round with the arms temporarily in `edge32_gate`
78+(`$HOME/.cache/golomb-gate-r7b.log`):
79+* `(192, 68, 5, false)`: ALL EIGHT cq attempts refuse by name -- `a reference picture whose
80+ height does not match this frame's own true size` -- so the arm compares nothing
81+ (vacuous; class `counter-from-refused-stream`). That refusal is the next blocker for any
82+ non-SB-multiple height.
83+* `(68, 192, 5, false)`: RED on a real, separate defect --
84+ `68x192 cq35 frames=5 10bit=false frame 1 plane Y: 141 pixels differ, first at row 0 col
85+ 64 (ours 167 vs ffmpeg 166) [edge32=[0,34,0,0,1,17,0,1]]`. LUMA, inside the 4-px
86+ straddling COLUMN. The straddling-ROW twin never reaches this because of the refusal above.
87+The reason is recorded as a comment in `edge32_gate` (`crates/ec-av1/src/stream.rs`, just
88+above `let cqs`) so it is not re-attempted blind.
89+
90+## Exact next step for r8
91+1. Read `$HOME/.cache/golomb-suite-r7.log`'s `test result:` line (N/0 expected); that is the
92+ only thing this round did not finish.
93+2. `main` has advanced to `85887c7` (this branch merged `18bf7dc`); re-merge before any
94+ further work.
95+3. Then the 68-px straddle: fix the `68x192` luma defect at the 4-px straddling column
96+ (start from `read_var_tx_size`'s `blk_col >= max_w_mi` early return and the right-edge
97+ prediction/availability, first difference is at row 0 col 64 = the first straddling
98+ column of decode picture 1), and the `192x68` "reference picture whose height does not
99+ match this frame's own true size" refusal -- then the arms can be added for real.
lanes/golomb-r7.report.mdadded+96 -0
@@ -0,0 +1,96 @@
1+# lane-golomb r7 REPORT -- GREEN (the r6 chroma residue is closed at its root cause)
2+
3+## What changed
4+* `crates/ec-av1/src/decode.rs` -- new `fn reduce_inherited_chroma_tx_type(t, w, h)`
5+ (inserted just above `fn inter_txbset_for`), and both inter-chroma callers now use it:
6+ * `read_inter_plane_rect`'s `default_tx_type` (was `Some(t) if w.max(h) < 32 => t`)
7+ * `read_inter_plane`'s `default_tx_type` (was `Some(t) if side < 32 => t`)
8+ Those two are the ONLY sites in the crate that derive a chroma `tx_type` for an INTER
9+ block (`rg inherited_luma_tx_type`); the intra chroma sites (`decode.rs:6056`, `9195`)
10+ take `default_intra_tx_type` and are already correct -- every value that table can
11+ produce is a member of both intra sets below 32, and both already force `DCT_DCT` at
12+ `>= 32`, which for INTRA is right (`av1_get_ext_tx_set_type` returns `EXT_TX_SET_DCTONLY`
13+ for intra at `tx_size_sqr_up == TX_32X32`).
14+* `crates/ec-av1/src/decode.rs` -- new unit test
15+ `decode::tests::an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set`.
16+* `crates/ec-av1/src/stream.rs` -- comment only: the measured reason the 192x68 / 68x192
17+ straddling arms are NOT in `edge32_gate` (below).
18+
19+## ROOT CAUSE (libaom citation)
20+`av1_get_tx_type` (`av1/common/blockd.h:1278-1309`) for a chroma plane of an INTER block:
21+1. `if (txsize_sqr_up_map[tx_size] > TX_32X32) return DCT_DCT;` -- **strictly greater**;
22+2. `tx_type = xd->tx_type_map[(blk_row << ss_y) * stride + (blk_col << ss_x)]` -- the
23+ colocated luma unit's coded type (for a chroma unit at (0,0), the FIRST var-tx leaf);
24+3. `if (!av1_ext_tx_used[av1_get_ext_tx_set_type(tx_size, 1, reduced)][tx_type])
25+ tx_type = DCT_DCT;` -- narrowed by the set the **chroma** size selects
26+ (`av1_ext_tx_used` `blockd.h:1036`, `av1_get_ext_tx_set_type` `blockd.h:1097`).
27+
28+We had step 1 as `chroma side >= 32 -> DCT_DCT` and no step 3 at all. At exactly
29+`TX_32X32` an inter block reads `EXT_TX_SET_DCT_IDTX`, which **contains IDTX**. So a
30+64x64 inter superblock, whose chroma units are 32x32 (`av1_get_max_uv_txsize(BLOCK_64X64)`),
31+whose first luma var-tx leaf coded `IDTX`, must inverse-transform its chroma with IDTX --
32+we used DCT_DCT.
33+
34+`IDTX` and `DCT_DCT` are both `TX_CLASS_2D`: same scan, same coefficient contexts, same
35+msac ranges. That is why the whole stream stayed in entropy sync and only one superblock
36+of chroma came out as high-frequency noise with luma bit-exact -- the r6 handoff's exact
37+signature. (Class for the ledger: a tx_type set-membership bug is invisible to every
38+range ladder; only pixels see it.)
39+
40+The old rule was also wrong the other way for chroma 16x16 under 8x8 luma leaves
41+(`EXT_TX_SET_DTT9_IDTX_1DDCT` excludes V_ADST/H_ADST/V_FLIPADST/H_FLIPADST, which we would
42+have inherited verbatim). The new helper covers all four sets.
43+
44+## Localization (how the tx_type was identified, no aomdec rebuild)
45+`EC_TRACE_MODE=1 EC_TRACE_COEFF=1` on `g35.obu` (md5 `9037f5b21db95d35e71f91f040fc33e1`,
46+`scratchpad/gl-gen.sh 35`), split into frames on `EC_MODE mi_row=0 mi_col=0`: decode-order
47+picture 4 is segment 4. Its block at `mi(0,16)` (luma x=64,y=0) runs to the next
48+`EC_MODE mi_row=0 mi_col=32`, i.e. it is a **64x64** block (not 32x32 as r6 recorded),
49+var-tx split into 16x16 leaves. Its last two coefficient units are
50+`eob=1022 tx=DctDct` and `eob=1020 tx=DctDct` with `ctx=0` -- eob > 256 proves 32x32
51+chroma units -- while its FIRST luma leaf is `eob=254 tx=Idtx`. libaom inherits that
52+`Idtx`; we produced `DctDct`.
53+
54+## Gate
55+`cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition --nocapture`
56+(under `systemd-run --user --unit=golomb-gate-r7-... -p MemoryMax=10G`,
57+`EC_AV1_REQUIRE_AOMENC=1`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-golomb`)
58+
59+BEFORE (r6 handoff): `192x80 cq35 frames=5 10bit=false frame 3 plane U: 978 pixels differ,
60+first at row 0 col 32 (ours 33 vs ffmpeg 8) [edge32=[0,36,0,0,0,18,0,0]]`.
61+AFTER: `ok` -- 5 arms x cq {35,40,45,50,55,57,59,61}, 8-bit and 10-bit,
62+`38 pixel-exact attempts, 32-level edge bits [horz_or_vert=0 split=394], 64-level edge
63+bits [horz_or_vert=7 split=197] right-VERT=7, 2 named refusals` (both the inter SB-level
64+AB partition another lane owns).
65+
66+EVIDENCE: $HOME/.cache/golomb-gate-r7.log | cargo test -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition --nocapture, 40 aomenc encodes decoded and compared plane-by-plane vs ffmpeg | 38/38 compared attempts pixel-exact, 0 differing pixels (was 978 U pixels on the 192x80 cq35 5-frame arm)
67+EVIDENCE: $HOME/.cache/golomb-gate-r7b.log | same gate + arms (192,68,5) and (68,192,5) | 68x192 cq35 frame 1 plane Y 141 px differ first at row 0 col 64 -- separate OPEN defect, arm not kept
68+EVIDENCE: scratchpad/r7-ours.err | EC_TRACE_MODE=1 EC_TRACE_COEFF=1 decode_probe g35.obu, segment 4, block mi(0,16) | first luma leaf tx=Idtx, the two 32x32 chroma units (eob 1022/1020) took tx=DctDct
69+
70+Unit check: `cargo test -p ec-av1 --lib -- an_inter_chroma_transform_narrows` => `ok. 1 passed`.
71+
72+## Refusals lifted
73+None this round -- this is a wrong-pixels fix, not a refusal lift. `refusal_inventory` /
74+`gate_coverage` untouched.
75+
76+## The 192x68 / 68x192 straddling arm (r3 verifier ask) -- NOT ADDED, measured why
77+* `(192, 68, 5, false)`: all EIGHT cq attempts refuse by name, `a reference picture whose
78+ height does not match this frame's own true size` -> the arm compares nothing (vacuous,
79+ class `counter-from-refused-stream`).
80+* `(68, 192, 5, false)`: RED on a real separate defect --
81+ `68x192 cq35 frames=5 10bit=false frame 1 plane Y: 141 pixels differ, first at row 0
82+ col 64 (ours 167 vs ffmpeg 166) [edge32=[0,34,0,0,1,17,0,1]]`. LUMA, inside the 4-px
83+ straddling COLUMN; the straddling ROW twin (192x68) never gets that far.
84+ disposition: deferred(the right-edge straddling-column luma defect above, and the
85+ reference-size refusal) -- both are outside this lane's chroma tx_type cause.
86+
87+## Test totals
88+`$HOME/.cache/golomb-suite-r7.log` (unit `golomb-suite-r7`) -- see the `test result:` line.
89+NOTE: `$HOME/.cache/golomb-suite-r6.log` never produced a `test result:` line: it was still
90+`active` (254/404 tests, stuck in the long superres/encoder tests) and holding
91+`CARGO_TARGET_DIR`, so it was stopped -- it was measuring the PRE-fix tree and is superseded
92+by r7. Every `test` line it did produce was `ok` or a documented `ignored`.
93+
94+## Open / residue
95+* `main` has advanced to `85887c7` (we merged `18bf7dc`); this branch is NOT re-merged.
96+* the two defects the 68-px arms found (above), deferred.
lanes/golomb-r8.handoff.mdadded+50 -0
@@ -0,0 +1,50 @@
1+# lane-golomb r8 HANDOFF -- two true-size fixes in, suite GREEN, straddle arms still blocked
2+
3+Tip: `lane-golomb` (report `lanes/golomb-r8.report.md`, fix `97de75e`, merge of main
4+`85887c7` at `3a08902`). Suite: `379 passed; 0 failed; 34 ignored`
5+(`$HOME/.cache/golomb-suite-r8.log`). edge32 gate green, 38 pixel-exact attempts, 2 refusals.
6+
7+## Landed
8+1. Reference-height refusal compared the mi-rounded `true_height` with the cropped
9+ `reference.height`; now compares the header's `frame_height` (libaom compares references on
10+ `y_crop_width/height`). Every 192x68 attempt used to refuse; none do now.
11+2. `apply_loop_restoration` now takes the cropped `(frame_width, frame_height)` instead of
12+ plane `true_width/true_height` (libaom `av1_get_upsampled_plane_size` +
13+ `assert(plane_w == crop_widths)` + `av1_extend_frame`). UNGATED -- every straddle recipe
14+ runs `--enable-restoration=0`.
15+
16+## The ONE open defect this lane still owns
17+A **+-1 straddling-band INTER reconstruction defect**, both orientations, all on **frame 1**
18+(frame 0 is bit-exact in every case, so it is not intra and not a per-frame filter constant):
19+* `68x192` cq35 8-bit: `frame 1 plane Y: 141 px differ, first at row 0 col 64 (167 vs 166)`
20+ -- cols 64..67 are the straddling COLUMNS of a 68-wide frame (mi-rounded 72).
21+* `192x68` cq59 8-bit: `frame 1 plane Y: 217 px, first at row 60 col 170 (172 vs 173)`.
22+* `192x68` cq35 10-bit: `frame 1 plane Y: 305 px, first at row 56 col 48 (530 vs 531)`.
23+Reproduce by re-adding `arms.push((68, 192, 5, false))` / `arms.push((192, 68, 5, false))` in
24+`edge32_gate` (`crates/ec-av1/src/stream.rs`, the comment block just above `let cqs`) and
25+running with `EC_GATE_VERBOSE=1` (new this round -- names each attempt before decoding it,
26+because a desync otherwise panics in `mc.rs` with no arm in the message).
27+
28+RULED OUT this round, do not re-attempt:
29+* Reference border padding. `aom_yv12_extend_frame_borders_c` calls `extend_plane` with
30+ `crop_widths/crop_heights` and memsets from `src + width - 1`, so libaom OVERWRITES decoded
31+ columns 68..71 with column 67 -- exactly what our `mc::sample` clamp at `true_width-1` of the
32+ cropped reference already does. The charter's hypothesis (b) is refuted at the source.
33+* Loop restoration. The gate recipe has `--enable-restoration=0`; the 68x192 diff is
34+ byte-identical before and after fix 2 (`golomb-gate-r8c.log` vs `r8d.log`).
35+* Var-tx clipping (`max_w_mi`/`max_h_mi`). libaom's `max_block_wide` is derived from
36+ `mb_to_right_edge`, i.e. `cm->mi_params.mi_cols` -- the MI-ROUNDED bound, which is what we
37+ use. Correct as-is.
38+
39+Next probe to run (r8 ran out of budget before it): dump the 68x192 cq35 stream to disk, then
40+bisect the frame-1 divergence with `EC_AV1_PREFILT_DUMP` (8-bit vars -- the 16-bit ones
41+SEGFAULT the oracle aomdec on an 8-bit stream) against the instrumented aomdec. If the
42+divergence is already present pre-filter it is inter prediction/residual in the straddling
43+band; if not, it is deblock/CDEF at the x=68 (resp. y=68) mi edge.
44+
45+## Two blockers that are NOT this lane's code
46+* `192x68` cq40 8-bit **PANICS** in `decode_inter_block8` (`from_switchable_symbol` handed a
47+ 4th symbol, `mc.rs:203`) = lane-sub8's open below-8x8 desync. A panic cannot be tolerated
48+ as a named refusal, so no straddle arm can span cq40 until sub8 lands.
49+* `192x68` cq35 8-bit refuses "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)"
50+ even though the recipe sets `--enable-ab-partitions=0` -- worth one measurement of its own.
lanes/golomb-r8.report.mdadded+102 -0
@@ -0,0 +1,102 @@
1+# lane-golomb r8 -- two true-size defects fixed, straddle arms STILL not addable
2+
3+Tip: `97de75e` on `lane-golomb` (merge `3a08902` of main `85887c7`, then the fix).
4+
5+## (1) Suite r7 -- no result line, superseded
6+`$HOME/.cache/golomb-suite-r7.log` was still `active` at **226/404** tests with **no**
7+`test result:` line and **zero** `FAILED`/`panicked` lines. It was measuring the PRE-merge
8+tree (main has since advanced to 85887c7), so r8 stopped the unit to take the target dir.
9+Owed artifact carried forward to r8's own suite.
10+
11+## (2) Merge of main 85887c7
12+`git merge --no-commit main` was a CLEAN auto-merge (decode.rs + stream.rs auto-merged, no
13+conflict, no hand resolution). Byte-compared against main afterwards:
14+`mvstack.rs`, `cdf.rs`, `cdf_state.rs`, `refusal_inventory.rs` are all **IDENTICAL to main**
15+(`git diff --quiet main -- <file>`). Only decode.rs and stream.rs carry lane content.
16+Merge commit `3a08902`.
17+
18+EVIDENCE: $HOME/.cache/golomb-gate-r8h.log | edge32 gate on the merged tree, all 8 cq arms x
19+{192x80, 80x192} x {8,10}-bit + the 5-frame inter arm | `test result: ok`, 38 pixel-exact
20+attempts, 64-level edge bits [horz_or_vert=7 split=197] right-VERT=7, 2 named refusals --
21+byte-identical totals to r7's green run.
22+
23+## (3a) FIXED: a same-size reference at a height that is not a multiple of 8
24+`crates/ec-av1/src/decode.rs`, `decode_inter_frame_tile_with_cdfs`: the guard compared
25+`reference.height` against `true_height = (mi_rows * 4)` (mi-rounded). A decoded `Picture`
26+is cropped to the header's `fh`, so at height 68 (`mi_rows = 2*((68+7)>>3) = 18` -> 72) it
27+compared **68 against 72** and refused every same-size reference.
28+libaom compares references on the CROPPED dimensions --
29+`av1_setup_scale_factors_for_frame(&sf, ref->y_crop_width, ref->y_crop_height, cm->width,
30+cm->height)` -- and calls a reference *scaled* only when those differ (`av1_is_scaled`).
31+Height must still match (AV1 superres never scales height). Class `av1-truesize-lane`.
32+
33+EVIDENCE: $HOME/.cache/golomb-gate-r8{b,f}.log | `arms.push((192, 68, 5, false))`, cq sweep |
34+BEFORE: 8/8 attempts refuse "a reference picture whose height does not match this frame's own
35+true size"; AFTER: 0/8 do.
36+
37+## (3b) NOT the cause of the 68x192 column defect -- charter hypothesis REFUTED at the source
38+The charter proposed our reference plane replicates from the mi-rounded column 71 instead of
39+the true column 67. Read `aom_scale/generic/yv12extend.c`: `aom_yv12_extend_frame_borders_c`
40+calls `extend_plane(..., ybf->crop_widths[is_uv], ybf->crop_heights[is_uv], ...,
41+right = plane_border + widths - crop_widths)` and `extend_plane` memsets from
42+`src + width - 1` -- i.e. libaom OVERWRITES the decoded columns 68..71 with column 67.
43+Our `mc::sample` clamps at `true_width - 1` of the CROPPED reference `Picture` (68) -->
44+already identical. No fix needed; the 141-px defect is elsewhere.
45+
46+## (3c) FIXED (source-cited, UNEXERCISED): loop restoration ran over the mi-rounded plane
47+`decode.rs::apply_loop_restoration` passed each plane's `true_width`/`true_height`. LR is the
48+one post-decode filter that does not walk the mi grid: libaom sizes every plane with
49+`av1_get_upsampled_plane_size` (`plane_w = ROUND_POWER_OF_TWO(cm->superres_upscaled_width,
50+ss_x)`, `av1/common/restoration.c:47`), **asserts** it equals the buffer's crop width
51+(`restoration.c:1106`) and `av1_extend_frame(..., plane_w, plane_h, ...)` replicates the
52+border from that cropped edge before any unit is filtered (`restoration.c:1109`). Deblock and
53+CDEF DO walk the mi grid, which is why this survived until a non-multiple-of-8 size.
54+Now takes `(frame_width, frame_height)`, chroma `div_ceil(2)`.
55+DISCLOSURE: **no gate exercises this** -- every straddle recipe in `edge32_gate` runs
56+`--enable-restoration=0`, and the 68x192 defect was byte-identical before and after
57+($HOME/.cache/golomb-gate-r8{c,d}.log, both `141 pixels differ, first at row 0 col 64`).
58+It is a source-cited correctness alignment, verified only by the suite staying green.
59+
60+## (4) The straddle arms are STILL not addable -- three separate blockers, each measured
61+Charter asked for `(192,68,5)` and `(68,192,5)` arms at 8+10 bit with a straddling-TU counter.
62+DEVIATION: no arm was added, because every cq level of both is vacuous, panicking or red.
63+The measurements are now recorded verbatim in the `edge32_gate` comment block:
64+* `192x68` cq35 8-bit: no longer the height refusal -- refuses LATER by another lane's name,
65+ "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)". Vacuous
66+ (class `counter-from-refused-stream`).
67+* `192x68` cq40 8-bit: **PANICS** in `decode_inter_block8` -- `from_switchable_symbol` handed a
68+ 4th symbol, `mc.rs:203`. That is lane-sub8's own open below-8x8 desync (already named in
69+ `decode.rs`'s scaled-reference-8x8 refusal comment). A panic cannot be tolerated as a named
70+ refusal, so the arm cannot even be added with an Err-tolerating recipe.
71+* `192x68` cq59 8-bit: RED, `frame 1 plane Y: 217 pixels differ, first at row 60 col 170
72+ (ours 172 vs ffmpeg 173)`.
73+* `192x68` cq35 10-bit: RED, `frame 1 plane Y: 305 pixels differ, first at row 56 col 48
74+ (ours 530 vs ffmpeg 531)`.
75+* `68x192` cq35 8-bit: RED, `frame 1 plane Y: 141 pixels differ, first at row 0 col 64
76+ (ours 167 vs ffmpeg 166)` -- unchanged from r7 by either fix this round.
77+
78+NEW FACT for the successor: all four red cases are **+-1** bands, on **frame 1** (the first
79+INTER frame -- frame 0 is bit-exact in every one), and they sit in or immediately beside the
80+4-px straddling band (rows 56..63 next to straddling rows 64..67; columns 64..67 are the
81+straddling columns themselves). That is one straddling-band INTER reconstruction defect with
82+two orientations, not four defects -- and it is not the reference border (3b), not LR (3c) and
83+not intra (frame 0 exact).
84+
85+The gate now prints each attempt under `EC_GATE_VERBOSE=1` (`stream.rs`), because a desync
86+otherwise surfaces as a bare panic in `mc.rs` with no arm named.
87+
88+## Test totals
89+`cargo test -p ec-av1 --lib` -> `$HOME/.cache/golomb-suite-r8.log` (unit `golomb-suite-r8`):
90+`test result: ok. 379 passed; 0 failed; 34 ignored; 0 measured; 0 filtered out; finished in
91+917.74s` (413 test lines emitted). GREEN.
92+
93+EVIDENCE: $HOME/.cache/golomb-suite-r8.log | `cargo test -p ec-av1 --lib` on the merged tree at
94+97de75e, unit golomb-suite-r8, MemoryMax=10G | 379 passed / 0 failed / 34 ignored.
95+
96+## Residue disposition
97+* 68x192 / 192x68 straddling-band +-1 INTER defect -- **fix-now, next round**; it is this
98+ lane's whole remaining job and the successor has the four measurements above.
99+* `192x68` cq40 below-8x8 panic -- **deferred(lane-sub8's open desync)**; not this lane's code.
100+* `192x68` cq35 inter SB-level AB partition refusal -- **deferred(the AB-partition lane)**.
101+* LR cropped-plane fix ungated -- **deferred(a straddle gate arm with
102+ `--enable-restoration=1`)**; the base recipe disables restoration for every arm.
lanes/golomb-r9.report.mdadded+100 -0
@@ -0,0 +1,100 @@
1+# lane-golomb r9 -- the straddling-band defect is CDEF, and a stream-data PANIC is now a refusal
2+
3+## What changed
4+
5+* `crates/ec-av1/src/decode.rs` `neighbour_filter` -- returns `Result` and refuses
6+ "an OBMC neighbour whose switchable interp filter was never recorded" instead of handing the
7+ `[3, 3]` sentinel to `mc::from_switchable_symbol`, which `panic!`s on any value above 2.
8+ Both call sites (`build_obmc_prediction`'s above and left passes) already sat inside a
9+ `Result` function and take `?`.
10+* `crates/ec-av1/src/refusal_inventory.rs` -- the new refusal string pinned.
11+* `crates/ec-av1/src/decode.rs` `deblock_plane` -- new `EC_AV1_DEBLOCK_TRACE_V` rung: the
12+ per-edge `x0/y0/len/level` of the vertical pass plus one line per plane with the loop's real
13+ `tw`/`th`/`stride` vs `true_*`/crop bounds. That rung is what settled the deblock question below.
14+* `crates/ec-av1/src/stream.rs` -- `a_frame_edge_straddling_band_decodes_pixel_exact`, an
15+ `#[ignore]`d pinned test that runs `edge32_gate`'s exact recipe over the four straddle arms
16+ (192x68 and 68x192, 5 frames, 8-bit and 10-bit, cq 35..61), with `EC_GATE_VERBOSE` naming.
17+
18+## TASK A -- root cause narrowed to CDEF, stage by stage (fix NOT landed)
19+
20+Stream: `~/.cache/golomb-tmp/s68.obu`, md5 `45722b0fb7f1707a18e0547cc7a59fa2`, produced by
21+`edge32_gate`'s own aomenc recipe at 68x192 cq35 8-bit, 5 frames.
22+
23+| stage | ours vs instrumented aomdec, frame 1 |
24+| --- | --- |
25+| reconstruction (`EC_AV1_PREFILT_DUMP`) | **0 luma pixels differ** over the cropped 68 columns |
26+| post-deblock (`EC_AV1_POSTDEBLOCK_DUMP`, `EC_AV1_DEBUG_SKIP_CDEF=1`) | **matches**, including columns 68..71 |
27+| final output vs ffmpeg | 145 luma differ, mass in columns 64..67 |
28+
29+So inter prediction is exact and the charter's "the MC reference read runs past the crop"
30+hypothesis is refuted a second time (r8 refuted it at the libaom source; r9 refutes it by
31+measurement: our returned `Picture` is already cropped to `frame_width`, so `mc::sample` clamps
32+at column 67 exactly as `extend_plane` does). The deblock is also exact -- `frame_width` is the
33+right clip, confirmed against libaom `set_lpf_parameters`' `if ((width <= x) || (height <= y))`
34+early-out on `plane_ptr->dst.width`, which is the crop width; forcing the mi-rounded bound
35+instead made frame 0 RED (17 luma px, columns 65..67), so r7's clip stays.
36+
37+The divergence therefore enters in **CDEF**, at the last 8x8 CDEF block column (mi column 17,
38+pixels 64..71) -- the one block that straddles the crop edge. Frame 0 survives it and frame 1
39+does not, which is why every earlier round read the shape as "inter".
40+
41+Two instrument facts a successor needs:
42+* aomdec's `EC_AV1_POSTDEBLOCK_DUMP` is **72 columns wide** (mi-rounded) while its
43+ `EC_AV1_PREFILT_DUMP` is cropped to 68 -- the post-deblock rung is the only one that exposes
44+ the straddling band on the reference side.
45+* our own `EC_AV1_POSTDEBLOCK_DUMP` is emitted from a site that, on this path, runs **after**
46+ `apply_cdef`: `od.f0` and `odnc.f0` (same run, `EC_AV1_DEBUG_SKIP_CDEF=1`) differ in columns
47+ 68..71 although `EC_AV1_WATCH`-instrumented `filter_edge` performs no write there. Always pair
48+ that dump with `EC_AV1_DEBUG_SKIP_CDEF=1`, or the CDEF defect reads as a deblock defect --
49+ which cost r9 six rounds of the budget.
50+
51+EVIDENCE: ~/.cache/golomb-tmp/{ours,theirs,od,odnc,td}.f* | aomenc 68x192 cq35 5f -> decode_probe with EC_AV1_PREFILT_DUMP / EC_AV1_POSTDEBLOCK_DUMP(+EC_AV1_DEBUG_SKIP_CDEF) vs the same rungs on the oracle aomdec | prefilt f1 luma diffs 0/13056, post-deblock (cdef off) f1 luma diffs 0, final output f1 145 differ first row 0 col 64
52+
53+## TASK B -- the panic is gone
54+
55+Before: `192x68 cq40` aborted the process in `mc.rs:203`. After:
56+
57+```
58+$ decode_probe s40.obu
59+REFUSED: unsupported: AV1 tile (an OBMC neighbour whose switchable interp filter was never recorded)
60+```
61+
62+EVIDENCE: ~/.cache/golomb-tmp/s40.obu (md5 26d42c5f04e4d0f7f4075a4550e999d5) | aomenc 192x68 cq40 5f -> cargo run --example decode_probe | process abort in mc.rs:203 -> `REFUSED: unsupported: AV1 tile (an OBMC neighbour whose switchable interp filter was never recorded)`
63+
64+Sweep of the other aborts reachable from a desynced stream (`decode.rs` + `mc.rs`), each checked
65+against the value's own domain:
66+
67+* `mc.rs:203` `from_switchable_symbol` -- FIXED at its only reachable caller. The other caller
68+ (`resolve_interp_filter`) reads a 3-symbol CDF (`switchable_interp: [[u16; 4]; 16]`,
69+ `nsyms = cdf.len() - 1`), so it cannot produce a 4th symbol.
70+* `mc.rs:220` `from_header(Switchable)` -- header enum, not a per-block stream value; callers
71+ resolve `Switchable` before calling. Left.
72+* `decode.rs:3259` `default_intra_tx_type` -- the mode comes from a 13-symbol CDF and all 13
73+ values have a row. Bounded, left.
74+* `decode.rs:13936`/`14114` `partition_w8` and `decode.rs:15352` `read_single_ref` -- values from
75+ 4-symbol / bounded-return helpers. Bounded, left.
76+* `decode.rs:11673/11692/11739` -- guarded by `rect_inter_residual_supported`, which is itself a
77+ named refusal. Left.
78+* `decode.rs:11324`, `12091`, `12110`, `12147`, `15660`, `2745` -- block-size / tx-size domain
79+ invariants, not stream values. Left.
80+* `decode.rs:2498` `ref_hits` -- a test-side counter accessor, never on the decode path. Left.
81+* the non-test `.unwrap()`/`.expect()` in `decode.rs` (5280, 5324, 6085, 6152, 7352/7353,
82+ 7819/7820, 10535, 10591, 10735, 10944) are each dominated by a push/refusal a few lines above.
83+ Left, listed here so the next sweep does not re-derive it.
84+
85+## TASK C -- arms
86+
87+`a_frame_edge_straddling_band_decodes_pixel_exact` carries all four straddle arms and is
88+`#[ignore]`d, which is the only honest shape while the CDEF defect is open: an arm that is RED
89+cannot join the green gate, and the r8 handoff's "measured, arm not added" comment is now a
90+runnable test instead of prose.
91+
92+fix-now residue, NOT done this round:
93+* deferred(the CDEF straddle fix) -- the `--enable-restoration=1` arm at 192x68 that would gate
94+ r8's cropped-plane loop-restoration fix. `edge32_gate`'s arm tuple has no per-arm flag slot and
95+ every straddle recipe is RED regardless, so the LR arm would be vacuous today; it unblocks the
96+ moment the CDEF fix lands. This is the same `refusal-lifted-without-a-gate` shape r8 flagged.
97+
98+## Suite
99+
100+`cargo test -p ec-av1 --lib` -> **379 passed; 0 failed; 35 ignored** (`$HOME/.cache/golomb-suite-r9.log`; the extra ignored test vs r8 is the new pinned straddle gate).
lanes/kf1200-r3.report.mdadded+130 -0
@@ -0,0 +1,130 @@
1+# lane-kf1200 r3 report — the partial-bottom-row desync, root cause found and fixed
2+
3+Tip `9d18288` on `lane-kf1200` (parent `bee8ec0`, main merged at `d85d7d2`).
4+
5+## Root cause (ONE symbol, not the partition path the charter suspected)
6+
7+The charter's premise — "our 32-level gathered `split_or_horz` CDF/ctx differs" —
8+is REFUTED by measurement. A cross-decoder range ladder over the whole partial
9+bottom superblock row shows every partition symbol of mi_row=400 in sync,
10+including the gathered ones (our `ctx` values equal libaom's
11+`partition_plane_context` minus its `bsl * PARTITION_PLOFFSET` offset, and every
12+`rng` matches):
13+
14+ aomdec EC_PART mi_row=400 mi_col=44 bsize=6 ctx=6 rng=55482 value=3 (SPLIT)
15+ ours OUR_PART mi_row=400 mi_col=44 bsize=6 ctx=2 rng=55482
16+ aomdec EC_PART mi_row=400 mi_col=44 bsize=3 ctx=0 rng=52288
17+ ours TRACE partition_w8 mi=(400,44) ctx=0 value=0 pre_rng=52288
18+ aomdec EC_PART mi_row=400 mi_col=46 bsize=3 ctx=0 rng=53128
19+ ours TRACE partition_w8 mi=(400,46) ctx=0 value=0 pre_rng=53128
20+
21+The first differing element is the `tx_depth` symbol of the SECOND 8x8 leaf:
22+
23+ aomdec EC_ISTEP mi_row=400 mi_col=46 name=tx_depth val=0 ctx=1 rng=42998
24+ ours EC_ISTEP mi_row=400 mi_col=46 name=tx_depth val=0 ctx=2 rng=54191
25+
26+Same decoded value, different CDF row, therefore a different interval narrowing:
27+the entropy stream is desynced from there on, and the rest of the row (and the
28+1595..1607 deblock spill) decodes as garbage. What the charter saw as "aomdec
29+reads a 16x8 where we read 32x16" was our *already desynced* reader at
30+mi (400,48), one block later.
31+
32+`ctx` comes from libaom `get_tx_size_context`: `above_txfm_context[0] >=
33+max_tx_wide` + `left_txfm_context[0] >= max_tx_high`. The left neighbour of
34+(400,46) is the 8x8 leaf at (400,44), which is `skip=1` and whose `tx_depth`
35+resolved to TX_4X4 — so libaom's `set_txfm_ctxs` published 4 and its left term
36+is 0. Our `decode_leaf8` skip branch fell through to a hardcoded
37+`fill_lf_grid(leaf_mi, 2, 8, 0)`, publishing 8, so our left term read 1.
38+
39+An intra block reads `tx_depth` whether or not it is skipped (libaom
40+`read_intra_frame_mode_info` calls `read_tx_size` above the skip branch); only a
41+skipped *inter* block records its block size instead of its transform.
42+
43+## Change
44+
45+- `crates/ec-av1/src/decode.rs:10330` — `fill_lf_grid(leaf_mi, 2, resolved as u8, 0)`
46+ (was the literal `8`). The non-skip TX_4X4 branch already returned early with 4;
47+ only the skip path was wrong. One line.
48+- `crates/ec-av1/src/decode.rs:2652` `trace_edge()` + 5 call sites — `OUR_PART
49+ mi_row/mi_col/bsize/ctx/rng` under `EC_AV1_TRACE` for the three gathered
50+ frame-edge partition reads (there was no emitter for them, only for the full
51+ alphabet reads), plus `pre_rng` on the 8x8 partition trace. Instrument only.
52+- `crates/ec-av1/examples/decode_probe.rs:34` — prints `skip_split_tx`.
53+
54+Sibling sweep for the same shape (a skip branch publishing the block side where
55+the resolved transform belongs): `fill_lf_grid` has 6 call sites.
56+`decode_block` (9872) already passes `logical_tx`; the inter 8x8 leaf (20449)
57+passes `if split8 {4} else {8}`; the inter-leaf skip early-return (19644) passes
58+8, which is CORRECT — a skipped inter block records its block size. The 4x4 leaf
59+(10541) passes 4. Only 10330 was wrong.
60+
61+## Gates
62+
63+1. NEW `the_reelb_ss600_key_frame_skipped_split_tx_decodes_pixel_exact`
64+ (`crates/ec-av1/src/stream.rs`), pinning
65+ `crates/ec-av1/fixtures/reelb_ss600_key_frame.obu` (94717 B, sha256
66+ `36de46676ed7de7049d4dabe8571d8cd31c8a1f53d72011c0ee532a7c6725cd6`, hashed
67+ twice, `git add -f`, present in `git ls-files`): one 3840x1608 yuv420p10le key
68+ frame. HARD-asserts `skip_split_tx_hits > 0` (24 in this frame) then Y/U/V vs
69+ ffmpeg's 10-bit decode. Fixture, not aomenc, because the shape is not
70+ synthetically reachable: 80 recipes this round (4 frame shapes x 2 lavfi
71+ sources x cq 32/35/40/45/48/50/55/58/63 x cpu-used 0/3 x 8/10-bit, all with
72+ `--enable-tx-size-search=1 --enable-filter-intra=1 --min-partition-size=8`)
73+ returned `skip_split_tx_hits == 0` every time. Widths with a partial right
74+ column (200, 264, 136, 776, 1288) additionally hit the existing named refusal
75+ "a 16x16 block whose true edge cuts through both axes", so the charter's
76+ 200x72 / 72x200 / 136x104 / 264x136 shapes cannot be compared at all today.
77+2. WIDENED `a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact`:
78+ three more partial-bottom-row shapes (200x72, 136x88, 264x104 — 2/4/6 mi rows)
79+ and an `--enable-tx-size-search=1` arm. The whole recipe ran with
80+ `--enable-tx-size-search=0`, so no block in it could carry a nonzero
81+ `tx_depth` at all (class `tool-disabled-in-every-gate`) — that is why 8 green
82+ arms never saw this defect. 18 arms compared pixel-exact, 10 named refusals
83+ (all the double-axis 16x16 one), `edge_horz_total`/`edge_sub_total` still
84+ hard-asserted; the `skip_split_tx` counter is reported, not gated, there.
85+
86+## 24-key-frame census (1 frame each, ours vs ffmpeg 10-bit, differing BYTES)
87+
88+r2: 11/24 exact, four multi-million-byte rows. r3: 17/24 exact, **luma exact on
89+all 24**, every remaining row chroma-only.
90+
91+| -ss | Y | U | V | r2 total |
92+|---|---|---|---|---|
93+| 0,300,600,1200,1500,1800,2400,3000,3300,3600,4200,4500,5100,5400,5700,6900 | 0 | 0 | 0 | 4 of these were 16.6M/48771/42343/39971/16375 |
94+| 900 | 0 | 40 | 50980 | 14057191 |
95+| 2100 | 0 | 1289 | 1067 | 15148697 |
96+| 2700 | 0 | 231 | 739 | 7726168 |
97+| 3900 | 0 | 4 | 4 | 7554023 |
98+| 4800 | 0 | 29 | 5 | 34 |
99+| 6000 | 0 | 210 | 0 | 15449720 |
100+| 6300 | 0 | 4 | 0 | 15410664 |
101+| 6600 | 0 | 124 | 124 | 15180826 |
102+
103+The four charter segments (600/2400/3300/5700) are all 0/0/0.
104+
105+## EVIDENCE
106+
107+EVIDENCE: /home/user/.cache/kf1200-tmp/a600s.part + o600s.trace | aomdec EC_TRACE=1 EC_TRACE_MODE_STEP=1 vs our EC_AV1_TRACE=1 EC_TRACE_MODE_STEP=1 on the pinned 1-frame stream | first differing element mi(400,46) tx_depth ctx 2 vs 1, rng 54191 vs 42998; after the fix ours reads ctx=1 rng=42998
108+EVIDENCE: /home/user/.cache/kf1200-tmp/ours600.yuv vs ref600.yuv | EC_PROBE_OUT16 decode vs `ffmpeg -pix_fmt yuv420p10le` | cmp -l = 0 differing bytes of 18524160 (was 48771)
109+EVIDENCE: /home/user/.cache/kf1200-census-r3.log | 24 key frames extracted with `-frames:v 1 -c:v copy`, per-plane byte diff vs ffmpeg | 17/24 all-zero, luma zero on 24/24
110+EVIDENCE: cargo test -p ec-av1 --lib a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz -- --nocapture | 7 shapes x 2 tx arms x 2 depths | 18 arms pixel-exact, 10 named refusals, edge bits 64-level horz/vert up to 3, sub-level up to 9
111+EVIDENCE: cargo test -p ec-av1 --lib the_reelb_ss600_key_frame -- --nocapture | pinned fixture decode vs ffmpeg 10-bit | "24 skipped 8x8 TX_4X4 leaves, frame pixel-exact"
112+
113+## Suite
114+
115+`cargo test -p ec-av1 --lib` (systemd unit, EC_AV1_REQUIRE_AOMENC=1): **379 passed, 0 failed,
116+33 ignored**, 514.26 s — `/home/user/.cache/kf1200-suite-r3.log`.
117+
118+## Residue
119+
120+- deferred(-ss 4800, U=29/V=5): chroma-only, 8x4 chroma patch at (540,1200) —
121+ unchanged by this round, still the r2 pair-mi sibling hypothesis. Unblocked by
122+ an `EC_IMODE_VAL`/`EC_PRED` ladder at luma mi ~(270,600); I ran out of turn
123+ budget after the census. Same for the other six chroma-only rows (900 V=50980
124+ is the largest and the only one big enough to be a second desync rather than a
125+ prediction/edge-filter off-by-one).
126+- accepted: the charter's partial-RIGHT-column gate shapes (200x72 etc.) cannot
127+ be compared until the "16x16 block whose true edge cuts through both axes"
128+ refusal is lifted; they are in the gate and currently take the refusal arm.
129+- No refusal was lifted this round; `refusal_inventory.rs` / `gate_coverage.rs`
130+ untouched.
lanes/kf900-r1.handoff.mdadded+122 -0
@@ -0,0 +1,122 @@
1+# lane-kf900 r1 HANDOFF — mid-frame entropy desync on the 4K 10-bit AV1 key frames
2+
3+Tip: `81b16cc` on `lane-kf900` (worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`,
4+base `18bf7dc` = main tip at start, no rebase needed).
5+
6+## ROOT CAUSE (fixed)
7+
8+`crates/ec-av1/src/decode.rs`, `decode_leaf8` tail — was:
9+
10+```rust
11+neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); // literal block side
12+```
13+
14+now `neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0);`
15+
16+libaom calls `set_txfm_ctxs(mbmi->tx_size, bw, bh, skip_txfm && is_inter_block(mbmi), xd)`
17+(`decodemv.c`). For an INTRA block that skip term is **always 0**, so a *skipped* 8x8 intra
18+leaf whose `tx_depth` symbol resolved to `TX_4X4` still publishes **4** to the next block's
19+`get_tx_size_context` (`pred_common.h:342`). Our tail wrote **8** for every 8x8 leaf,
20+including the skipped-and-split ones (`decode_leaf8`'s non-skip `resolved == 4` branch had
21+its own early return with the correct 4 — only the skip path fell through to the literal).
22+
23+Consequence: the 8x16 strip below such a leaf computed `tx_size_context_rect` = 2 where
24+libaom computes 1, and read `tx_size_cat1` **row 2** instead of row 1 — same 3-symbol
25+alphabet, wrong CDF row (class `wrong-alphabet-same-value`). The msac range diverged
26+mid-frame, **no refusal**, everything after it garbage.
27+
28+### Evidence chain (all reproducible from `/home/user/.cache/kf900/`)
29+- `s900_1.obu` (1 frame, sha256 `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`,
30+ hashed twice from two independent `ffmpeg -ss 900 -t 2 -c:v copy -f obu` extracts).
31+- Pre-fix first bad luma sample: **row 186 col 1803**, delta 2, max |d| 929, 5405035 luma
32+ samples differing. Pre-filter (`EC_AV1_PREFILT_DUMP16` ours vs aomdec) first difference
33+ row 192 col 512 → recon, not loop filter.
34+- Cross-decoder block ladder (new `EC_IMODE` rung, mirrors aomdec `decodemv.c:818`):
35+ identical for 3543 blocks, first divergence entering mi (60,124).
36+- Symbol ladder (`EC_TRACE_MODE_STEP`, both sides) inside mi (60,122) — a `BLOCK_8X16`
37+ (aomdec `bsize=4`): identical through `filter_intra_mode val=0 rng=33750`, then
38+ aomdec `tx_depth val=0 ctx=1 cat=1 rng=53206`, ours `ctx=2`.
39+- New `EC_TXCTX` rung: `mi_row=60 mi_col=122 w=8 h=16 above_px=8 left_px=16 ctx=2`;
40+ `above_px` should be 4. New `EC_LFGRID` rung: `mi_row=58 mi_col=122 w_mi=2 h_mi=2
41+ tx_px=8` written by the leaf above, which had `skip=1` and `tx_depth val=1` (TX_4X4).
42+
43+## RESULT — 24 key frames, 1-frame truncation each, ours (EC_PROBE_OUT16) vs `ffmpeg -pix_fmt yuv420p10le`
44+
45+`bytes_before` = census4 pre-fix all-plane byte diff; `bytes_after` = same, post-fix;
46+`luma_after` = differing **luma samples** post-fix. Every segment decodes `OK` (no refusal)
47+at 1 frame. Script: `/home/user/.cache/kf900/census.sh`, raw: `/home/user/.cache/kf900/census.tsv`.
48+
49+| -ss | bytes_before | bytes_after | luma_after |
50+|----:|-------------:|------------:|-----------:|
51+| 0 | 0 | 0 | 0 |
52+| 300 | 463 | 463 | 0 |
53+| 600 | 48771 | 0 | 0 |
54+| 900 | 14057195 | 51272 | 0 |
55+| 1200 | 14 | 14 | 0 |
56+| 1500 | 16649701 | 108644 | 0 |
57+| 1800 | 248 | 248 | 0 |
58+| 2100 | 15147518 | 2383 | 0 |
59+| 2400 | 42343 | 0 | 0 |
60+| 2700 | 7726287 | 1243 | 0 |
61+| 3000 | 0 | 0 | 0 |
62+| 3300 | 44500 | 4529 | 0 |
63+| 3600 | 1 | 1 | 0 |
64+| 3900 | 7554020 | 8 | 0 |
65+| 4200 | 0 | 0 | 0 |
66+| 4500 | 0 | 0 | 0 |
67+| 4800 | 2348 | 2348 | 0 |
68+| 5100 | 0 | 0 | 0 |
69+| 5400 | 0 | 0 | 0 |
70+| 5700 | 0 | 0 | 0 |
71+| 6000 | 15450360 | 10207 | 0 |
72+| 6300 | 15410936 | 146881 | 0 |
73+| 6600 | 15181681 | 67588 | 0 |
74+| 6900 | 0 | 0 | 0 |
75+
76+**24/24 luma-exact.** All remaining diffs are chroma-only.
77+
78+## OPEN RESIDUE
79+
80+1. **Chroma-only defect (deferred — needs its own lane).** On `s900_1.obu` after the fix:
81+ Y 0, U 266 samples (max |d| 23), V 47927 (max |d| 2). First at chroma (102,688) =
82+ luma (204,1376) = mi (51,344). It is **pre-filter** (`pf/ours2.f0` vs `pf/aom.f0`:
83+ Y 0, U 228, V 47800 first at chroma row 102 col 689) → chroma *reconstruction*, not a
84+ loop filter. Luma being exact proves the entropy stream is exact, so this is a
85+ prediction/inverse-transform bug on one chroma path. Unblocked by: an `EC_TRACE_COEFF`
86+ plane-1/2 ladder at mi (51,344) — the entropy side is now a fixed reference.
87+2. **The two new gate arms FAIL on their counter assert** (`stream.rs`, after
88+ `a_real_aomenc_multi_tile_intra_stream_...`):
89+ `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact`
90+ and its `_10bit_` twin. Both **decode 6/6 attempts pixel-exact**, but
91+ `skip_split_tx_hits() == 0` — the shared `gradients_source` at 256x128 never makes
92+ aomenc pick a skipped 8x8 intra leaf that also splits its transform (skip wants the
93+ residual quantised away, TX_4X4 wants detail; the film has both at 4K).
94+ They are committed FAILING on purpose: an assert that never fires is the
95+ `tool-disabled-in-every-gate` class, and `skip_split_tx_hits` was `pub` with **zero**
96+ callers anywhere before this round.
97+
98+## EXACT NEXT STEP
99+
100+Sweep for a recipe, then keep or replace the assert:
101+`$HOME/.cache/cargo-target-kf900/release/examples/decode_probe <stream.obu>` now prints
102+`skip_split_tx: N` — sweep aomenc without rebuilding the test binary.
103+On the film's own frame it prints **15**, so the counter is correct.
104+Suggested axes (none tried yet): 4K-ish frame sizes (the film's leaves are 8x8 inside 64x64
105+SBs at 3840 wide), `--cpu-used=0`, `cq-level` 40..58, and a source with fine detail plus
106+flat regions (`mandelbrot`, `testsrc2` + `noise=all_seed=N:alls=20`), 8- and 10-bit arms.
107+**If no recipe reaches it after a measured sweep** (record every attempt), the charter's
108+fallback applies: commit `crates/ec-av1/fixtures/reelb_kf900.obu` (the 484640-byte
109+`/home/user/.cache/kf900/s900_1.obu`, sha256 above) plus a test that decodes it and
110+compares against a **stored sha256 of the ffmpeg output** (do not commit the yuv), and
111+assert `skip_split_tx_hits() >= 15`.
112+
113+Suite: armed detached as user unit `kf900-suite-r1`, log `$HOME/.cache/kf900-suite-r1.log`.
114+Check with `grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r1.log`. Expect the two
115+new gate arms to be the failures until the recipe lands.
116+
117+## NOT DONE (charter items)
118+- deferred: block-position printing on refusal in `decode_probe` (frame index, mi_row,
119+ mi_col, bsize) — not started, ran out of turns; unblocked by ~10 minutes on
120+ `decode.rs`'s `unsupported()` call sites.
121+- deferred: `refusal_inventory.rs` / `gate_coverage.rs` updates — this round lifted no
122+ refusal, so neither file needed a change; re-check once the gate recipe lands.
lanes/kf900-r2.report.mdadded+145 -0
@@ -0,0 +1,145 @@
1+# lane-kf900 r2 report -- the chroma edge-filter type reads the wrong mi
2+
3+Tip: `1fad25c` on `lane-kf900` (worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`,
4+base `18bf7dc`; main has since moved to `4eff3a1` -- NOT rebased, see residue).
5+
6+## 1. r1 suite
7+
8+`$HOME/.cache/kf900-suite-r1.log` was still running at round start and was stopped by me
9+(`systemctl --user stop kf900-suite-r1`) before the first rebuild, so it never printed a
10+`test result` line: 288 tests started, 229 `ok`, 0 `FAILED` at the stop point. Its two
11+known-failing arms were rewritten this round anyway; r2's suite below is the real number.
12+
13+## 2. The gate arms that asserted an unreachable counter -- 108 measured recipes, all zero
14+
15+`skip_split_tx_hits()` counts a SKIPPED 8x8 intra leaf whose `tx_depth` resolved to `TX_4X4`
16+(the r1 defect). Sweep (`$HOME/.cache/kf900/sweep/sweep.sh`, raw
17+`results.tsv` + `results10.tsv`): 4 sources (`geq` half-flat/half-noise, `mandelbrot`,
18+`testsrc2`, gray+`noise=all_seed=49`) x cq {55,59,63} x `--cpu-used` {0,1,2} x {8,10}-bit,
19+all with `--enable-tx-size-search=1 --min-partition-size=8 --enable-rect-partitions=1
20+--kf-max-dist=1 --limit=1`, 256x192. **72 8-bit + 36 10-bit = 108 attempts, `skip_split_tx: 0`
21+on every one that decoded.** Cause: libaom's encoder forces `tx_size` to the block maximum
22+once it picks `skip_txfm`, so aomenc never writes this combination. The film's encoder does.
23+
24+EVIDENCE: $HOME/.cache/kf900/sweep/results.tsv + results10.tsv | 108 aomenc encodes, each
25+decoded by `decode_probe` | `skip_split_tx: 0` in 108/108 (2 recipes at N=4 -- see residue 3)
26+
27+Fallback taken (charter-sanctioned): `crates/ec-av1/fixtures/reelb_kf900.obu`, the 484640-byte
28+1-frame extract, sha256 `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`
29+(two independent `ffmpeg -ss 900 -t 2 -c:v copy -f obu` extracts hashed identically, r1).
30+`git ls-files` shows it tracked. New gate
31+`stream.rs::a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`
32+hard-asserts `skip_split_tx_hits() >= 15` (actual 15) and compares the **luma** plane against
33+`ffmpeg -pix_fmt yuv420p10le`. U/V are the open residue, so the gate pins luma only and says so.
34+The two multi-tile arms keep their pixel-exact comparison and point at this gate.
35+
36+EVIDENCE: crates/ec-av1/fixtures/reelb_kf900.obu | `cargo test -p ec-av1 --lib skipped_8x8 chroma`
37+| 15 passed / 0 failed, `skip_split_tx: 15`, Y sha256
38+1ffd0c103368793762637b2152c2062042fe3a14af97045182adc4790c4b5c12 == ffmpeg's Y
39+
40+## 3. Chroma residue -- root cause found and fixed (one of at least two)
41+
42+`decode.rs`, `Neighbours::smooth_uv_neighbour` (now at :4640): added
43+`let (mi_r, mi_c) = (mi_r & !1, mi_c & !1);`.
44+
45+libaom `set_mi_row_col` (`blockd.h`) snaps to the chroma REFERENCE block first --
46+`base_mi = &xd->mi[-(mi_row & ss_y) * stride - (mi_col & ss_x)]` -- and only then takes
47+`chroma_above_mbmi = base_mi[-stride]` / `chroma_left_mbmi = base_mi[-1]`. A sub-8 pair codes
48+its chroma at the ODD mi, so we looked one mi row/column too far, the mi-exact slot never
49+matched, and the coarse SUB-grid fallback answered.
50+
51+Effect: `get_intra_edge_filter_type` (`reconintra.c`) 0 where libaom has 1, which flips
52+`av1_use_intra_edge_upsample(8, 4, -6, type)` (`blk_wh == 12`: false at type 1, TRUE at type 0).
53+We upsampled an edge libaom leaves alone.
54+
55+Ladder (chroma 8x4 at (688,100) = mi (51,344), V_PRED `p_angle=84`, `ft=1` in aomdec):
56+aomdec `EC_PREDOUT sum=15924`, ours `sum=15930`; per-sample +1 at rows 2/3, cols 1,2,4.
57+Hand-simulating both walks from the real above row (A[-1..7] = 495,495,496,497,498,498,499,499,499,
58+`dx = dr_intra_derivative(84) = 7`) reproduces 15924 unfiltered/un-upsampled and 15930 through
59+`av1_upsample_intra_edge_high` -- the upsample flag was the whole difference.
60+
61+EVIDENCE: $HOME/.cache/kf900/pred_aom.txt + pred_ours.txt | EC_PRED on aomdec and decode_probe
62+over reelb_kf900.obu | EC_PREDOUT 15924 vs OUR_PRED 15930; after the fix the block is 0-diff and
63+the frame's first chroma difference moves (102,688) -> (195,640)
64+
65+Not the cause (ruled out this round): per-plane quantizer deltas (`EC_AV1_TRACE` on the frame:
66+`base_q_idx=35 y_dc=0 u_dc=0 u_ac=0 v_dc=0 v_ac=0`, and `plane_q_delta()` is applied at every
67+chroma dequant call site anyway).
68+
69+Sibling gates re-run after the fix (`chroma` + `skipped_8x8` filters): 15 passed, 0 failed --
70+includes `..._chroma_edge_filter_reads_a_sub16_neighbours_uv_mode...`,
71+`..._directional_chroma...`, `..._smooth_paeth_chroma...`, `..._4to1_or_sub8_rect...`,
72+`the_chroma_rect_gates_excluded_seed_46...`.
73+
74+## 4. 24-key-frame census, post-fix (per-plane DIFFERING SAMPLES, not bytes)
75+
76+Recipe `$HOME/.cache/kf900/census_r2.sh` (r1's `census.sh` with a per-plane comparator):
77+`ffmpeg -ss <s> -t 2 -c:v copy -f obu`, truncated to 1 frame, `EC_PROBE_OUT16` vs
78+`ffmpeg -pix_fmt yuv420p10le`. Raw: `$HOME/.cache/kf900/census_r2.tsv`.
79+NOTE the metric changed from r1's all-plane differing BYTES to per-plane differing SAMPLES.
80+
81+| -ss | Y | U | V | max abs Y/U/V | r1 bytes_after |
82+|----:|--:|--:|--:|:--------------|---------------:|
83+| 0 | 0 | 0 | 0 | 0/0/0 | 0 |
84+| 300 | 0 | 219 | 220 | 0/8/7 | 463 |
85+| 600 | 0 | 0 | 0 | 0/0/0 | 0 |
86+| 900 | 0 | 221 | 47912 | 0/23/2 | 51272 |
87+| 1200 | 0 | 0 | 0 | 0/0/0 | 14 |
88+| 1500 | 0 | 0 | 0 | 0/0/0 | 108644 |
89+| 1800 | 0 | 0 | 0 | 0/0/0 | 248 |
90+| 2100 | 0 | 1041 | 1008 | 0/1/1 | 2383 |
91+| 2400 | 0 | 0 | 0 | 0/0/0 | 0 |
92+| 2700 | 0 | 442 | 800 | 0/7/3 | 1243 |
93+| 3000 | 0 | 0 | 0 | 0/0/0 | 0 |
94+| 3300 | 0 | 0 | 0 | 0/0/0 | 4529 |
95+| 3600 | 0 | 0 | 0 | 0/0/0 | 1 |
96+| 3900 | 0 | 4 | 4 | 0/1/1 | 8 |
97+| 4200 | 0 | 0 | 0 | 0/0/0 | 0 |
98+| 4500 | 0 | 0 | 0 | 0/0/0 | 0 |
99+| 4800 | 0 | 2316 | 5 | 0/3/1 | 2348 |
100+| 5100 | 0 | 0 | 0 | 0/0/0 | 0 |
101+| 5400 | 0 | 0 | 0 | 0/0/0 | 0 |
102+| 5700 | 0 | 0 | 0 | 0/0/0 | 0 |
103+| 6000 | 0 | 210 | 0 | 0/3/0 | 10207 |
104+| 6300 | 0 | 145195 | 0 | 0/38/0 | 146881 |
105+| 6600 | 0 | 30873 | 897 | 0/19/7 | 67588 |
106+| 6900 | 0 | 0 | 0 | 0/0/0 | 0 |
107+
108+**24/24 luma-exact; 15/24 now FULLY exact** (were 10/24 at r1: 1200, 1500, 1800, 3300, 3600
109+went to zero on all planes). Segments 1500 (108644 bytes) and 3300 (4529) collapsed to 0.
110+
111+EVIDENCE: $HOME/.cache/kf900/census_r2.tsv | 24 x (extract 2 s, truncate to 1 frame, decode
112+ours + ffmpeg, per-plane compare) | Y 0 on all 24, all-plane 0 on 15
113+
114+## 5. Suite
115+
116+`systemd-run --user --unit=kf900-suite-r2 -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3`
117+-> `$HOME/.cache/kf900-suite-r2.log`:
118+**`test result: ok. 373 passed; 0 failed; 32 ignored; 0 measured; 0 filtered out; 1073.65s`**
119+(r1's two committed-failing arms are gone: they now assert only what they can reach, and the
120+counter moved to the fixture gate. 373 = 371 on main's tip + the fixture gate + r1's arms.)
121+
122+## Residue
123+
124+1. **fix-now (next round): the chroma RESIDUAL defect.** First remaining difference on the
125+ s=900 frame is chroma (195,640) = mi (97,320). Its PREDICTION is bit-exact
126+ (`EC_PREDND mi_row=97 mi_col=320 plane=1 sum=16384 / plane=2 sum=16352` on both sides), so
127+ the divergence is dequant / inverse transform / chroma `tx_type` on an 8x4 chroma unit.
128+ Unblocked by an `EC_TRACE_COEFF` plane-1/2 ladder at mi (97,320) -- entropy is a fixed
129+ reference now (luma exact frame-wide). Suspect list unchanged apart from CfL and per-plane
130+ delta_q, both now ruled out for this frame.
131+2. **fix-now (own lane): a real aomenc 10-bit stream we decode WRONG with no refusal.**
132+ `testsrc2=s=256x192` at `--bit-depth=10 --cq-level=59 --cpu-used=0` (also `--cpu-used=1`),
133+ full recipe in `$HOME/.cache/kf900/sweep/sweep.sh`, stream md5
134+ `e5f033d8fe34e4418d8cca3ac9d2b595`: `decode_probe` reports `OK: 1 frames decoded` and
135+ `skip_split_tx: 4`, but 73687 of 73728 samples differ from ffmpeg, max |d| 933. This is the
136+ only pair of the 108 recipes with a non-zero counter, and it is a SILENT desync -- a
137+ pixel-exact gate for `skip_split_tx` becomes possible the moment it is fixed.
138+ Reproducer in `$HOME/.cache/kf900/sweep/{g.obu,g.yuv,r.yuv}`.
139+3. **deferred: rebase onto main `4eff3a1`** (lane branched at `18bf7dc`; main gained
140+ lane-sb128b in between) -- not done because the r1 suite was mid-run on this worktree at
141+ round start and the round's budget went to the two defects; unblocked by a clean
142+ `git rebase main` + one suite run.
143+4. **deferred (r1 carry-over): block-position printing on refusal in `decode_probe`** and
144+ `refusal_inventory.rs` / `gate_coverage.rs` updates -- this round lifted no refusal, so
145+ neither file changed; unblocked by ~10 min on `decode.rs`'s `unsupported()` call sites.
lanes/kf900-r3.handoff.mdadded+117 -0
@@ -0,0 +1,117 @@
1+# lane-kf900 r3 HANDOFF
2+
3+Tip: see `git log --oneline -3 lane-kf900` (merge `4267082`, fix+gate `667eb51`, this
4+commit). Worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`, base `18bf7dc`,
5+merged main `8e9ba81`. Full detail in `lanes/kf900-r3.report.md`.
6+
7+## 1. The silent 10-bit desync -- ROOT CAUSE FOUND AND FIXED
8+
9+Stream: `testsrc2=s=256x192 --bit-depth=10 --cq-level=59 --cpu-used=0`, recipe
10+`$HOME/.cache/kf900/sweep/sweep.sh`, md5 `e5f033d8fe34e4418d8cca3ac9d2b595`
11+(`$HOME/.cache/kf900/sweep/g.obu`).
12+
13+Symbol: the FIRST block's Y palette colours. mi(0,0) is BLOCK_32X16, DC_PRED,
14+2-colour Y palette. `decode.rs::read_palette_colors_y` / `read_palette_colors_uv`
15+read every raw literal at a hardcoded 8 bits; libaom `decodemv.c:478` (Y) and
16+`:509` (UV) size them all by the sequence `bit_depth`: first colour
17+`aom_read_literal(r, bit_depth)`, `min_bits = bit_depth - 3` (Y/U) and
18+`bit_depth - 4` (V delta mode), `range = (1 << bit_depth) - first - 1` (Y) /
19+`- first` (U), clamp bound `(1 << bit_depth) - 1`, V wrap modulus `1 << bit_depth`.
20+So a 10-bit palette block read TWO BITS TOO FEW per transmitted colour and decoded
21+the whole rest of the tile from the wrong bit position, with no refusal.
22+
23+Fix (commit `667eb51`): `let bd = u32::from(bit_depth());` (the already-present
24+thread-local, decode.rs:200) inside both readers; no signature threading.
25+
26+Before: `OK: 1 frames decoded` with 73687/73728 samples differing from ffmpeg,
27+max |d| 933 (Y 49117/49152, U 12286/12288, V 12284/12288, first diff at (0,0)).
28+After: the entropy stream is in lockstep with aomdec -- our first 1024
29+`EC_PAL`/`EC_PAL_VAL` lines are byte-identical to aomdec's `EC_TRACE_PALETTE`, and
30+the block grid follows aomdec's (`EC_IMODE` mi(0,0) 32x16, (4,0) 16x16, (4,4) 16x16,
31+(0,8) 32x8, (2,8) 32x8, (4,8) 32x8 == aomdec bsize 8,6,6,19,19,19).
32+
33+WHY 108 SWEEP RECIPES AND A RANGE LADDER MISSED IT: raw literals are EQUIPROBABLE
34+and at the ranges this content reaches an equiprobable read is a FIXED POINT of the
35+msac range (62728 -> v=31364, either branch 31364, renorm 62728). A cross-decoder
36+RANGE ladder stays bit-identical straight through a wrong literal WIDTH; only the
37+decoded VALUE moves. aomdec and we both printed `rng=62728` and disagreed on the
38+first colour index (0 vs 1). Compare VALUES, not range alone.
39+
40+This stream is NOT a whole-frame gate: at mi(4,8) it hits a 32x8 (4:1) strip that
41+really uses a palette, and the 1:4 rect decoder is called with `palette: None`
42+(decode.rs:7167 and :7556), so it now stops at the pre-existing refusal
43+`"a 1:4 rect strip that actually uses a palette (reconstruction is not ported at
44+this shape)"`. Silent desync -> named refusal.
45+
46+## 2. The chroma residual at mi(97,320) -- GONE, and not by my fix
47+
48+r2's first remaining chroma difference on the s=900 4K key frame -- chroma (195,640)
49+= mi(97,320) -- is ZERO on the merged tree. No ladder was needed: the census (below)
50+came back clean. Credit is the merged lane-reelckf `55532c7` (skipped CfL blocks still
51+predict; the 1:4 chroma pair edge-filter mi), NOT the palette fix -- the film frame
52+reads zero palette symbols
53+(`EC_AV1_TRACE=1 decode_probe crates/ec-av1/fixtures/reelb_kf900.obu | grep -c "^EC_PAL "`
54+= 0).
55+
56+The charter's chroma-`tx_type` suspicion was audited and cleared rather than needed:
57+`av1_get_tx_type`'s `plane > 0` intra path is `intra_mode_to_tx_type(mbmi,
58+PLANE_TYPE_UV)` = our `default_intra_tx_type` (decode.rs:3229) fed with
59+`uv_predict_mode`, which already maps `UV_CFL_PRED` -> `DC_PRED`; the
60+`!av1_ext_tx_used[tx_set_type][tx_type]` narrowing can only bite at
61+`txsize_sqr_up >= TX_32X32`, and both chroma call sites already force `DCT_DCT`
62+there (decode.rs:6089 `chroma_w.max(chroma_h) >= 32`, decode.rs:9254 `side >= 32`).
63+All four values the table can produce are members of `EXT_TX_SET_DTT4_IDTX` and
64+`..._1DDCT`, the only two intra sets below 32.
65+
66+## 3. Census -- 24/24 BIT-EXACT (was 15/24 at r2)
67+
68+`$HOME/.cache/kf900/census_r3.sh` -> `$HOME/.cache/kf900/census_r3.tsv`: all 24
69+key frames decode `OK: 1 frames decoded, 3840x1608` with Y=U=V=0 differing samples
70+and max |d| 0/0/0. Full table in the report.
71+
72+## 4. Gate state
73+
74+NEW, committed, PASSING:
75+`crates/ec-av1/src/stream.rs::a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit`
76+-- the existing 8-bit `..._with_palette_y_...` recipe (smptebars 64x64,
77+`--tune-content=screen --enable-palette=1`, rect/AB/1:4 off) with the depth as the
78+only variable (depth flags appended AFTER the base recipe: last flag wins). Each arm
79+hard-asserts `decode::palette_hits()` moved and compares Y, U and V vs ffmpeg.
80+`cargo test -p ec-av1 --lib palette_stream_decodes_pixel_exact_at_8_and_10` -> 1
81+passed, 0 failed. DISCRIMINATION CHECK RUN: with `let bd = u32::from(bit_depth())`
82+reverted to `let bd = 8u32` the test FAILS on "luma at 10-bit" and the 8-bit arm
83+still passes (tree restored from a scratch copy afterwards).
84+
85+No refusal was lifted this round, so `refusal_inventory.rs` / `gate_coverage.rs` are
86+untouched (byte-identical to main's).
87+
88+Class sweep for the same shape (bit-depth-scaled reader hardcoding 8):
89+`grep -n "literal(8)\|255i32\|, 255)\|(1 << 8)" crates/ec-av1/src/decode.rs` -> only
90+the qindex clamps at :332 and :544 survive, and those are correct at every depth.
91+No sibling instances.
92+
93+## 5. Suite state -- INCOMPLETE, ZERO FAILURES SO FAR
94+
95+`systemd-run --user --unit=kf900-suite-r3-1788328486 -p MemoryMax=10G ... cargo test
96+-p ec-av1 --lib -j3 > $HOME/.cache/kf900-suite-r3.log`. At the turn cap: **272 `ok`,
97+0 `FAILED`, no `test result` line yet**. Resolve the unit name with
98+`systemctl --user list-units --all | grep kf900` before believing it finished.
99+
100+## 6. EXACT NEXT STEP
101+
102+1. `grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r3.log` -- expect
103+ `374 passed; 0 failed` (373 at r2 + the new depth gate). If a `FAILED` appears,
104+ the only behavioural change on this branch is the palette bit-depth widening, so
105+ look at the three existing palette gates first
106+ (`a_real_aomenc_stream_with_palette_y_...`, `..._palette_uv_...`,
107+ `..._rect_palette_...`, `a_real_aomenc_multi_tile_palette_stream_...`).
108+2. Merge into main.
109+3. Then the open lane work, in this order:
110+ a. Tighten `..._skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`
111+ from luma-only to all three planes -- the census is 24/24 exact now, so its U/V
112+ arms should hold.
113+ b. Port palette reconstruction to the 1:4 rect decoder (decode.rs:7167 and :7556
114+ pass `palette: None`); that is the ONLY thing between us and a whole-frame
115+ pixel gate for `skip_split_tx` on the pinned 10-bit stream above. Probably
116+ lane-palette2's territory.
117+ c. Carry-over: block-position printing on refusal in `decode_probe`.
lanes/kf900-r3.report.mdadded+171 -0
@@ -0,0 +1,171 @@
1+# lane-kf900 r3 -- the silent 10-bit desync was the palette colour reader
2+
3+Tip: `667eb51`+ on `lane-kf900` (worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`),
4+base `18bf7dc`, merged main `8e9ba81` (lane-reelckf `55532c7`).
5+
6+## 1. Merge (charter item 1)
7+
8+`git merge --no-commit main` -> clean, no conflicts (commit `4267082`). Both
9+chroma-reference-mi fixes kept: lane-reelckf passes `pair_mi` at the sub-8
10+`smooth_uv_neighbour` call site (decode.rs:7778), r2's own snap
11+`let (mi_r, mi_c) = (mi_r & !1, mi_c & !1);` lives inside the function
12+(decode.rs:4662) -- idempotent together, re-read to confirm.
13+`cdf.rs`, `cdf_state.rs`, `mvstack.rs`, `refusal_inventory.rs`,
14+`gate_coverage.rs` byte-compare SAME as `main:`'s copies (sha256 of each).
15+
16+## 2. The silent 10-bit desync -- ROOT CAUSE, fixed and gated (charter item 2)
17+
18+`decode.rs::read_palette_colors_y` / `read_palette_colors_uv` read every raw
19+literal at a **hardcoded 8 bits**. libaom `decodemv.c:478`/`:509` size all of
20+them by the sequence `bit_depth`:
21+
22+* first colour = `aom_read_literal(r, bit_depth)`
23+* `min_bits = bit_depth - 3` (Y and U), `bit_depth - 4` (V delta mode)
24+* `range = (1 << bit_depth) - first - 1` (Y) / `- first` (U)
25+* clamp bound `(1 << bit_depth) - 1`, V wrap modulus `1 << bit_depth`
26+
27+so a 10-bit palette block read **two bits too few per transmitted colour** and
28+decoded the whole remainder of the tile from the wrong bit position, with no
29+refusal. Fixed by taking the already-present thread-local `bit_depth()` inside
30+both readers (no signature threading).
31+
32+### Why 108 gate recipes and a range ladder could not see it
33+
34+Raw literals are EQUIPROBABLE, and at the ranges this content reaches an
35+equiprobable read is a FIXED POINT of the msac range: 62728 -> v = 31364,
36+either branch leaves 31364, renormalised back to 62728. A cross-decoder RANGE
37+ladder therefore stays bit-identical straight through the miscount and only
38+the decoded VALUE moves. That is the blind spot of the `compare-range-not-tell`
39+method, and it is why this stream reported `OK: 1 frames decoded` with
40+73687/73728 samples wrong.
41+
42+### The pin
43+
44+`testsrc2=s=256x192 --bit-depth=10 --cq-level=59 --cpu-used=0` (recipe
45+`$HOME/.cache/kf900/sweep/sweep.sh`, stream md5
46+`e5f033d8fe34e4418d8cca3ac9d2b595`). Its first block is mi(0,0) BLOCK_32X16,
47+DC_PRED, with a real 2-colour Y palette.
48+
49+* before: `EC_PAL row=0 col=0 ctx=-1 n=2 rng=62728` on BOTH decoders, then
50+ aomdec `color_idx=0`, ours `color_idx=1` -- identical range, opposite value.
51+* after: our first 1024 `EC_PAL`/`EC_PAL_VAL` lines are **byte-identical** to
52+ aomdec's, and the block grid follows aomdec's for the rest of the frame
53+ (`EC_IMODE` mi(0,0) 32x16, mi(4,0) 16x16, mi(4,4) 16x16, mi(0,8) 32x8,
54+ mi(2,8) 32x8, mi(4,8) 32x8 == aomdec bsize 8,6,6,19,19,19).
55+
56+EVIDENCE: $HOME/.cache/kf900/r3/{ours.pal,aom.pal} | EC_AV1_TRACE on
57+decode_probe vs EC_TRACE_PALETTE on the instrumented aomdec over the pinned
58+stream | `diff <(head -1024 ours.pal) <(head -1024 aom.pal)` empty; before the
59+fix the two disagreed on the first colour index at an identical range
60+
61+That stream is NOT a whole-frame gate: at mi(4,8) it hits a 32x8 (4:1) strip
62+that really uses a palette, and the 1:4 rect decoder is called with
63+`palette: None` (decode.rs:7167/7556), so it now stops at the existing refusal
64+`"a 1:4 rect strip that actually uses a palette (reconstruction is not ported
65+at this shape)"`. Silent desync -> named refusal is itself the honest outcome;
66+the pixel gate is a different recipe:
67+
68+### Gate
69+
70+`stream.rs::a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit`
71+-- the existing 8-bit `..._with_palette_y_...` recipe (smptebars 64x64,
72+`--tune-content=screen --enable-palette=1`, all rect/AB/1:4 off) with the
73+depth as the ONLY variable (depth flags appended AFTER the base recipe, per
74+the last-flag-wins rule). Each arm hard-asserts `decode::palette_hits()` moved
75+and compares Y, U and V against ffmpeg's decode of the same bytes.
76+
77+EVIDENCE: crates/ec-av1/src/stream.rs | `cargo test -p ec-av1 --lib
78+palette_stream_decodes_pixel_exact_at_8_and_10` | 1 passed / 0 failed; with
79+`let bd = u32::from(bit_depth())` reverted to `let bd = 8u32` the same test
80+FAILS on "luma at 10-bit" and the 8-bit arm still passes (discrimination check
81+run, tree restored from a scratch copy)
82+
83+Class sweep for the same shape (a bit-depth-scaled reader hardcoding 8):
84+`grep -n "literal(8)\|255i32\|, 255)\|(1 << 8)" decode.rs` -> the only two
85+survivors are the qindex clamps at decode.rs:332 and :544, which are correct
86+(qindex is 0..255 at every bit depth). No sibling instances.
87+
88+## 3. Chroma residual on the 4K 10-bit key frame (charter item 3) -- GONE
89+
90+r2's open residue (first chroma difference at (195,640) = mi(97,320)) is zero
91+on the merged tree. It is NOT my palette fix: the film frame reads **zero**
92+palette symbols (`EC_AV1_TRACE ... | grep -c "^EC_PAL "` = 0 on
93+`crates/ec-av1/fixtures/reelb_kf900.obu`), so the credit belongs to the merged
94+lane-reelckf commits (skipped CfL blocks still predict; the 1:4 chroma pair
95+edge-filter mi).
96+
97+The chroma `tx_type` suspicion from the charter was audited and cleared rather
98+than needed: `av1_get_tx_type`'s `plane > 0` intra path is
99+`intra_mode_to_tx_type(mbmi, PLANE_TYPE_UV)` (our `default_intra_tx_type`,
100+decode.rs:3229) fed with `uv_predict_mode`, which already maps `UV_CFL_PRED`
101+to `DC_PRED`; the `!av1_ext_tx_used[tx_set_type][tx_type]` narrowing can only
102+bite at `txsize_sqr_up >= TX_32X32`, and both chroma call sites already force
103+`DCT_DCT` there (decode.rs:6089 `chroma_w.max(chroma_h) >= 32`, decode.rs:9254
104+`side >= 32`). Every value the table can produce is a member of
105+`EXT_TX_SET_DTT4_IDTX` and `..._1DDCT`, the only two intra sets below 32.
106+
107+## 4. 24-key-frame census on the merged tree (charter item 4)
108+
109+Recipe `$HOME/.cache/kf900/census_r3.sh` (r2's script, own `c3/` scratch and
110+`census_r3.tsv`): `ffmpeg -ss <s> -t 2 -c:v copy -f obu`, truncated to one
111+frame, `EC_PROBE_OUT16` vs `ffmpeg -pix_fmt yuv420p10le`, per-plane DIFFERING
112+SAMPLES.
113+
114+| -ss | Y | U | V | max Y/U/V | r2 U | r2 V |
115+|----:|--:|--:|--:|:---------|-----:|-----:|
116+| 0 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
117+| 300 | 0 | 0 | 0 | 0/0/0 | 219 | 220 |
118+| 600 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
119+| 900 | 0 | 0 | 0 | 0/0/0 | 221 | 47912 |
120+| 1200 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
121+| 1500 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
122+| 1800 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
123+| 2100 | 0 | 0 | 0 | 0/0/0 | 1041 | 1008 |
124+| 2400 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
125+| 2700 | 0 | 0 | 0 | 0/0/0 | 442 | 800 |
126+| 3000 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
127+| 3300 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
128+| 3600 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
129+| 3900 | 0 | 0 | 0 | 0/0/0 | 4 | 4 |
130+| 4200 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
131+| 4500 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
132+| 4800 | 0 | 0 | 0 | 0/0/0 | 2316 | 5 |
133+| 5100 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
134+| 5400 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
135+| 5700 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
136+| 6000 | 0 | 0 | 0 | 0/0/0 | 210 | 0 |
137+| 6300 | 0 | 0 | 0 | 0/0/0 | 145195 | 0 |
138+| 6600 | 0 | 0 | 0 | 0/0/0 | 30873 | 897 |
139+| 6900 | 0 | 0 | 0 | 0/0/0 | 0 | 0 |
140+
141+**24/24 key frames now decode BIT-EXACT on all three planes** (r2: 15/24).
142+Every decode reported `OK: 1 frames decoded, 3840x1608`.
143+
144+EVIDENCE: $HOME/.cache/kf900/census_r3.tsv | 24 x (extract 2 s, truncate to 1
145+frame, decode ours + ffmpeg, per-plane compare) | Y/U/V all 0 on all 24 rows
146+
147+## 5. Suite (charter item 5)
148+
149+`systemd-run --user --unit=kf900-suite-r3-... -p MemoryMax=10G ... cargo test
150+-p ec-av1 --lib -j3` -> `$HOME/.cache/kf900-suite-r3.log`:
151+**still running at the turn cap** -- 272 `ok`, 0 `FAILED` at the last poll, no `test result` line yet (unit `kf900-suite-r3-1788328486.service`). See the handoff.
152+
153+## Residue
154+
155+1. **deferred: a whole-frame pixel gate for `skip_split_tx`** -- the only
156+ aomenc recipe found (of 108 + this round's) that fires the counter is the
157+ pinned 10-bit `testsrc2` stream, and it now stops at the 1:4-rect-palette
158+ refusal. Unblocked by porting palette reconstruction to the 1:4 rect
159+ decoder (decode.rs:7167/7556 pass `palette: None`) -- lane-palette2's
160+ territory, not a kf900 defect. The fixture gate
161+ `..._skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`
162+ still pins the counter at 15 and now compares luma only by construction;
163+ with the census at 24/24 its U/V arms could be tightened next round.
164+2. **deferred (r1/r2 carry-over): block-position printing on refusal in
165+ `decode_probe`**, plus `refusal_inventory.rs` / `gate_coverage.rs` updates
166+ -- this round lifted no refusal (it turned a silent desync into an existing
167+ named one), so neither file changed. Unblocked by ~10 min on `decode.rs`'s
168+ `unsupported()` call sites.
169+3. **accepted: the pinned 10-bit palette stream is not committed as a fixture**
170+ -- it is reproducible from `sweep.sh` and its md5 is recorded here; the
171+ committed gate builds its own stream from aomenc at test time.
lanes/kf900-r4.handoff.mdadded+98 -0
@@ -0,0 +1,98 @@
1+# lane-kf900 r4 HANDOFF
2+
3+Tip `12c3c7c` on `lane-kf900` (parent `08c9a35`). Full detail in
4+`lanes/kf900-r4.report.md`. The work is DONE and committed; the only open item is the
5+suite, which was still running at the turn cap.
6+
7+## 1. Suite state -- INCOMPLETE, ZERO FAILURES SO FAR
8+
9+Unit `kf900-suite-r4-1788330592.service`, log `$HOME/.cache/kf900-suite-r4.log`.
10+At the cap: **245 `ok`, 0 `FAILED`, no `test result` line yet** (r3's baseline was
11+`383 passed; 0 failed; 33 ignored` in 1029 s; this run is slower because 10 lanes share
12+the box). Resolve the unit with `systemctl --user list-units --all | grep kf900` before
13+believing it finished, then
14+`grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r4.log`.
15+Expect 384 passed (383 + the new gate). If something is RED, the behavioural changes on
16+this commit are only: rect-strip palette reconstruction, the chroma palette map size, the
17+palette cache mi keying, and `record_strip_palette` -- so look at the four existing
18+palette gates first (`a_real_aomenc_stream_with_palette_y_...`, `..._palette_uv_...`,
19+`..._rect_palette_...`, `a_real_aomenc_multi_tile_palette_stream_...`).
20+
21+## 2. The patch that shipped (all sites are current `crates/ec-av1/src/decode.rs`)
22+
23+Grep the symbol, not the line number -- the file moved by ~300 lines.
24+
25+| hook | site | what |
26+| --- | --- | --- |
27+| palette mode ctx + Y colour cache | `decode_block_rect4` (32x8/8x32), just after `modes_above_left_mi` | `let pal_at = (mi_r / (SUB / MI), mi_c / (SUB / MI)); neighbours.palette_ctx_and_cache_mi(pal_at, mi_r)` -> passed as `Some((palette_ctx, &palette_cache))` where `None` used to go |
28+| UV colour cache | same | `neighbours.palette_uv_cache_mi(pal_at, mi_r)` replaces `&[]` |
29+| same two | `decode_rect4_16` (16x4/4x16), inside the 4-strip loop, `at16` + `lmi.0` | per strip, not per cell |
30+| same two | `decode_leaf_rect` (16x8/8x16) | already had the ctx/cache; switched to the `_mi` variants with `leaf_mi.0` |
31+| palette_size ctx | `palette_bsize_ctx_wh` -- UNCHANGED, already correct | `num_pels_log2_lookup[bsize] - 6`; 0 for BLOCK_16X4/4X16 (64 px), 2 for BLOCK_32X8 |
32+| colours | `read_palette_colors_y` / `_uv` -- UNCHANGED (r3 fixed the bit depth) | |
33+| colour index map read point | `read_intra_mode_rect`, after `use_filter_intra` -- UNCHANGED | `av1_visit_palette` order: Y map then chroma map, both AFTER all mode info |
34+| colour index map SIZE (fixed) | `read_intra_mode_rect`, the `palette_uv_pending.map(..)` closure | `((bw / 2).max(4), (bh / 2).max(4))`, was `(bw / 2, bh / 2)` |
35+| chroma on the odd strip | `decode_rect4_16`'s `has_chroma` (`i % 2 == 1`) -- UNCHANGED gating; the pair's 8x4/4x8 chroma now gets `set_palette_pred` per plane in both the skip and the coded arm | |
36+| reconstruction | all three fns | `palette_y_buf` / `palette_uv_bufs` (index map through the base colours) handed to each `reconstruct_rect` via `set_palette_pred`; the split-tx walks slice the block buffer per transform unit (`RectStripModes.palette_y` in `decode_rect_split`, an inline window in `decode_rect4_16`) |
37+| neighbour state | new free fn `record_strip_palette` | split axis only until the closing strip (`mi_r % 8 == 6` / `mi_c % 8 == 6` for 32x8/8x32, `i == 3` for 16x4/4x16, `leaf_mi.0 % 4 == 2` for 16x8/8x16) |
38+| counter | `RECT4_PALETTE_HITS` / `pub(crate) fn rect4_palette_hits()` | rect strips that ACTUALLY use a palette |
39+
40+libaom cited: `decodemv.c` `read_palette_mode_info` (`av1_allow_palette` -- `sb_type >=
41+BLOCK_8X8` is an ENUM-INDEX test that BLOCK_4X16/16X4 pass; `av1_get_palette_bsize_ctx`;
42+`av1_get_palette_mode_ctx`), `read_palette_colors_y` `decodemv.c:478`,
43+`read_palette_colors_uv` `:509`, `pred_common.c:73` `av1_get_palette_cache` (SB-top-row
44+guard at `:76`, `row = -xd->mb_to_top_edge >> 3` = the block's PIXEL row, hence
45+`mi_r % 16 != 0`), `decodeframe.c` `decode_color_map_tokens` reached from
46+`av1_visit_palette`, and `ss_size_lookup` (BLOCK_16X4 -> BLOCK_8X4, BLOCK_4X16 ->
47+BLOCK_4X8) for the chroma map size.
48+
49+## 3. Refusals dropped (both from decode.rs and refusal_inventory.rs, 47 -> 45)
50+
51+* `a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)`
52+* `a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)`
53+
54+`gate_coverage.rs` needed no change (it pins aomenc FLAGS, and
55+`enable-palette` / `enable-1to4-partitions` were already in its list).
56+
57+## 4. Gate
58+
59+`crates/ec-av1/src/stream.rs::a_real_aomenc_rect_strip_palette_decodes_pixel_exact`.
60+Base recipe (arm 0 = the r3 pin): `--codec=av1 --bit-depth=N --input-bit-depth=N
61+--passes=1 --end-usage=q --cq-level=59 --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1
62+--limit=1 --threads=1 --tile-columns=0 --enable-tx-size-search=1 --min-partition-size=8
63+--enable-rect-partitions=1` on `testsrc2=s=256x192:r=25`, y4m over stdin, `-t 0.2`.
64+Arms 1-2 append `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1
65+--min-partition-size=8` (testsrc2 / `smptebars=size=256x192:rate=25`). 8-bit arms append
66+`--sb-size=64` (the 8-bit twin otherwise lands on the open 128-root HORZ refusal).
67+`cargo test -p ec-av1 --lib a_real_aomenc_rect_strip_palette_decodes_pixel_exact -- --nocapture`
68+-> **1 passed**: `2 attempt(s) with a rect-strip palette block, 0 out of scope
69+(0 mismatched), 4 refused, 2 frames compared, fired 8-bit=0 10-bit=2`.
70+
71+## 5. Measured facts
72+
73+* The test's own 10-bit arm-0 encode reproduces the pin BYTE FOR BYTE:
74+ md5 `e5f033d8fe34e4418d8cca3ac9d2b595`.
75+* That stream went `REFUSED: ... a 1:4 rect strip that actually uses a palette` ->
76+ `OK: 1 frames decoded, 256x192`; `rect4_32` went `horz=8 vert=0 coded=8` ->
77+ `horz=12 vert=16 coded=28`.
78+* **The charter/r3 premise that this stream fires `skip_split_tx` is WRONG**: decoded in
79+ full, `decode_probe` prints `skip_split_tx: 0`. The gate asserts the palette counter.
80+* **64x16/16x64 needed nothing**: `decode_block_rect64` already passes the real ctx/cache
81+ and reconstructs; its remaining palette refusal is the separate corner-cropped-luma one.
82+* **No 8-bit recipe reaches a rect-strip palette.** At 8 bit aomenc palettes SQUARE
83+ blocks; every 8-bit variant tried lands on `a block that actually uses a palette (Y)`
84+ (8x8 square leaf) or `a palette block with a real transform on a superblock-level
85+ HORZ/VERT strip`. Lifting either unblocks 8-bit coverage of this shape.
86+* **NEW pre-existing 8-bit 1:4 mismatch, not palette** -- 8-bit `testsrc2=s=256x192:r=25`,
87+ base recipe + `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1
88+ --max-partition-size=32 --sb-size=64`: decodes `OK`, `rect4_32: horz=8 vert=8 coded=16`,
89+ frame 0 differs from ffmpeg. The stream reads ZERO palette symbols
90+ (`EC_AV1_TRACE=1 decode_probe | grep -c "^EC_PAL "` == 0), so every change in this
91+ commit is inert on it. Needs its own lane.
92+
93+## 6. EXACT NEXT STEP
94+
95+1. Read the suite result (above). If green, merge `12c3c7c` into main.
96+2. Then, in order: (a) the new 8-bit 1:4 non-palette mismatch in 5; (b) palette on an 8x8
97+ SQUARE leaf (`decode_leaf8` discards `_palette_y`), which is what blocks 8-bit
98+ rect-strip coverage; (c) palette + real transform on a 64x32/32x64 SB-level strip.
lanes/kf900-r4.report.mdadded+70 -0
@@ -0,0 +1,70 @@
1+# lane-kf900 r4 report -- rect-strip palette reconstruction
2+
3+## What changed (all in `crates/ec-av1/`)
4+
5+| path:line (post-change) | why |
6+| --- | --- |
7+| `src/decode.rs` `Neighbours::palette_ctx_and_cache_mi` / `palette_uv_cache_mi` | `av1_get_palette_cache` drops the above neighbour on a 64-px SB boundary keyed on the block's own PIXEL row (`pred_common.c:76`). The old code read `at.0 % 4` off the 16-px `SUB` cell, so strip 1 of a HORZ_4 (8 px into the cell) wrongly excluded strip 0 from its cache in every SB-top cell row. Old entry points kept, delegating. |
8+| `src/decode.rs` `read_intra_mode_rect`, chroma colour-index map | the map is `av1_get_plane_block_size(bsize,1,1)` (`ss_size_lookup`), not a plain halving: BLOCK_16X4 -> BLOCK_8X4, BLOCK_4X16 -> BLOCK_4X8. `(bw/2, bh/2)` read HALF the colour-index symbols of a 1:4 strip's chroma palette. Now `((bw/2).max(4), (bh/2).max(4))`. |
9+| `src/decode.rs` `record_strip_palette` (new) | the coarse `SUB`-cell palette arrays alias all four strips of a HORZ_4/VERT_4 (and both leaves of a 16x8/8x16 pair) onto one entry, so stamping BOTH axes after every strip hands strip i+1 strip i's colours on the WRONG axis too. Writes the split axis until the closing strip, both on it. |
10+| `src/decode.rs` `decode_block_rect4` (32x8/8x32) | was `palette: None, &[]` -> real ctx + cache; palette-Y/UV prediction wired into the split-tx walk (`RectStripModes`), the coded arm and the skip arm; palette state stamped on all three exits. Refusal dropped. |
11+| `src/decode.rs` `decode_rect4_16` (16x4/4x16) | same, per strip, incl. the inlined per-TU split walk (window of the block's palette buffer per unit) and the pair's chroma. Refusal dropped. |
12+| `src/decode.rs` `decode_leaf_rect` (16x8/8x16) | sibling refusal "a palette block on a HORZ/VERT intra strip below 16x16" dropped the same way; its zero-clear of the palette arrays became `record_strip_palette`, which also fixes leaf 0 of a pair zeroing the LEFT entry leaf 1 legitimately reads. |
13+| `src/decode.rs` `RECT4_PALETTE_HITS` / `rect4_palette_hits()` | the gate's counter: rect intra strips that ACTUALLY use a palette. |
14+| `src/refusal_inventory.rs` | both lifted strings removed (47 -> 45). |
15+| `src/stream.rs` `a_real_aomenc_rect_strip_palette_decodes_pixel_exact` | the gate. |
16+
17+libaom sites cited: `decodemv.c` `read_palette_mode_info` (`av1_allow_palette`, `av1_get_palette_bsize_ctx`, `av1_get_palette_mode_ctx`), `read_palette_colors_y` (`decodemv.c:478`) / `read_palette_colors_uv` (`:509`), `pred_common.c:73` `av1_get_palette_cache`, `decodeframe.c` `decode_color_map_tokens` via `av1_visit_palette` (map read AFTER all mode info -- unchanged, already correct here).
18+
19+## Refusals lifted (2)
20+
21+1. `a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)`
22+2. `a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)`
23+
24+## Gate
25+
26+`crates/ec-av1/src/stream.rs::a_real_aomenc_rect_strip_palette_decodes_pixel_exact`
27+3 arms x 2 depths. Arm 0 IS the r3 pinned stream: `testsrc2=s=256x192:r=25`, `--cq-level=59
28+--cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 --limit=1 --threads=1 --tile-columns=0
29+--enable-tx-size-search=1 --min-partition-size=8 --enable-rect-partitions=1`, and the encoder
30+invocation inside the test reproduces md5 `e5f033d8fe34e4418d8cca3ac9d2b595` byte for byte at
31+10-bit. Arms 1-2 add `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1
32+--min-partition-size=8` on testsrc2 / smptebars. Every decode-order frame, all three planes,
33+compared against ffmpeg's decode of the identical bytes. Hard asserts: a rect-strip palette
34+block fired (`rect4_palette_hits()` delta), `out_of_scope_mismatch == 0`, sources render
35+byte-identical twice. A NAMED (`unsupported`) refusal is counted and printed, never a pass.
36+
37+```
38+cargo test -p ec-av1 --lib a_real_aomenc_rect_strip_palette_decodes_pixel_exact -- --nocapture
39+```
40+
41+EVIDENCE: $HOME/.cache/kf900/sweep/g.obu + gate stdout | aomenc pinned recipe -> decode_stream -> ffmpeg compare, 3 arms x {8,10} bit | 2 attempts with a rect-strip palette block, both whole-frame pixel-exact (Y+U+V), 0 out-of-scope mismatches, 4 named refusals on other shapes, md5 of the test's own 10-bit arm-0 stream == e5f033d8fe34e4418d8cca3ac9d2b595
42+EVIDENCE: decode_probe on $HOME/.cache/kf900/sweep/g.obu | before/after this commit | `REFUSED: ... a 1:4 rect strip that actually uses a palette` -> `OK: 1 frames decoded, 256x192`, rect4_32 horz=8 vert=0 -> horz=12 vert=16
43+
44+## Corrected premises (both stated as fact in the charter/handoff)
45+
46+- **`skip_split_tx` does NOT fire on the pinned stream.** `decode_probe` on the fully decoded
47+ stream prints `skip_split_tx: 0`. The r3 handoff's "fires skip_split_tx AND reaches that
48+ refusal" is half wrong, so the gate asserts the palette counter and does not assert
49+ `skip_split_tx`; asserting it would have been a vacuous/failing gate.
50+- **64x16/16x64 needed no work.** `decode_block_rect64` already passes the real ctx/cache and
51+ reconstructs palette; its only palette refusal is the separate corner-cropped-luma one.
52+
53+## Open residue
54+
55+- **deferred(8-bit rect-strip palette coverage)** -- `fired 8-bit=0, 10-bit=2`. At 8 bit aomenc
56+ puts its palettes on SQUARE blocks; every 8-bit recipe tried that reaches a rect strip with a
57+ palette lands on a shape still out of scope (`a block that actually uses a palette (Y)` on an
58+ 8x8 square leaf, or `a palette block with a real transform on a superblock-level HORZ/VERT
59+ strip`). Unblocked by lifting either of those two refusals. The 8-bit arms still run and prove
60+ the decode path; the counter is printed, not hidden.
61+- **fix-now-elsewhere: a NEW pre-existing 8-bit 1:4 pixel mismatch, unrelated to palette.**
62+ Recipe: `testsrc2=s=256x192:r=25`, 8-bit, base recipe above plus
63+ `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1 --max-partition-size=32
64+ --sb-size=64`. Decodes `OK: 1 frames decoded` with `rect4_32: horz=8 vert=8 coded=16` and
65+ frame 0 differs from ffmpeg. Proved unrelated to this round: the stream reads ZERO palette
66+ symbols (`EC_AV1_TRACE=1 decode_probe | grep -c "^EC_PAL "` == 0), so every change in this
67+ commit is inert on it. Needs its own lane.
68+- **accepted**: `a palette block with a real transform on a superblock-level HORZ/VERT strip`
69+ and `a block that actually uses a palette (Y/UV)` (8x8 square leaf) remain -- out of this
70+ lane's charter (both are square/SB-level, not rect strips).
lanes/kf900-r5.report.mdadded+88 -0
@@ -0,0 +1,88 @@
1+# lane-kf900 r5 report -- rect intra strips never read `use_intrabc`
2+
3+Tip `a7113f5` on `lane-kf900` (parent `9a01750`). GREEN.
4+
5+## Defect (chartered) and root cause
6+
7+The chartered stream -- 8-bit `testsrc2=s=256x192:r=25`, cq59 cpu-used 0, rect + 1:4
8+partitions, `--tune-content=screen --enable-palette=1 --sb-size=64` -- decoded `OK`
9+(`rect4_32: horz=8 vert=8`) and every luma sample of frame 0 differed from ffmpeg.
10+
11+`--tune-content=screen` sets `allow_screen_content_tools`, and the key-frame header then
12+sets **`allow_intrabc = 1`**. `av1_allow_intrabc` is a FRAME-level test (libaom
13+`decodemv.c:892`, `read_intra_frame_mode_info`): every intra block reads a `use_intrabc`
14+symbol after `skip`/`cdef`/`delta_q` and before `mbmi->mode`, with **no block-shape term**.
15+`read_intra_mode` (square leaf) and `read_intra_mode_sub8` both read it;
16+`read_intra_mode_rect` -- the reader for EVERY HORZ/VERT/1:4 rect strip -- did not. The
17+arithmetic decoder therefore desynced at the first mode symbol of the first rect block of
18+the frame, i.e. at mi(0,0), and every later symbol and pixel was garbage.
19+
20+Decisive measurement (cross-decoder range ladder, `EC_TRACE_MODE_STEP` both sides):
21+
22+```
23+ref EC_ISTEP mi_row=0 mi_col=0 name=skip rng=32874 ours ... rng=32874 (identical)
24+ref EC_ISTEP mi_row=0 mi_col=0 name=mode rng=58628 ours ... rng=62696 (diverged)
25+```
26+
27+62696 is exactly `kf_y_mode[0][0]` symbol 0 from 32874. 58628 is that same read after ONE
28+default `intrabc` symbol was consumed first (32874 -> 30694 -> normalised 61388 -> 58628),
29+computed by hand from `od_ec_decode_cdf_q15` (`aom_dsp/entdec.c`) with
30+`default_intrabc_cdf = AOM_CDF2(30531)`. That is the missing symbol, not a table row.
31+
32+## Changes
33+
34+| path | why |
35+| --- | --- |
36+| `crates/ec-av1/src/decode.rs` `allow_intrabc_frame()` (new, next to `intrabc_hits`) | `INTRABC_MI_GRID` is `Some` exactly when the frame header set `allow_intrabc`, so the flag reaches the rect reader with no new plumbing through 5 functions |
37+| `crates/ec-av1/src/decode.rs` `read_intra_mode_rect`, right after `istep!("dq", 0)` | reads `use_intrabc`; refuses by name when it fires (rect intrabc reconstruction is not ported); bumps `RECT_INTRABC_READS` |
38+| `crates/ec-av1/src/decode.rs` `RECT_INTRABC_READS` + `rect_intrabc_reads()` / `reset_rect_intrabc_reads()` | gate hit counter: strips that READ the symbol (distinct from `INTRABC_HITS` = blocks that USE intrabc) |
39+| `crates/ec-av1/src/stream.rs` `rect_intrabc_reads()` re-export + new gate | gate + probe surface |
40+| `crates/ec-av1/src/refusal_inventory.rs` | new refusal `"intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)"` (45 -> 46) |
41+| `crates/ec-av1/examples/decode_probe.rs` | prints `rect_intrabc_reads:` |
42+
43+Class sweep: `grep -n "cdfs.kf_y_mode\[" crates/ec-av1/src/decode.rs` -> 3 intra mode
44+readers (5630 rect, 8828 square, 10709 sub8); all three now read `cdfs.intrabc` under the
45+frame flag (5618 / 8807 / 10700). No other site.
46+
47+## Gate
48+
49+`crates/ec-av1/src/stream.rs::a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips`
50+-- three real-aomenc 8-bit arms, base recipe `--codec=av1 --bit-depth=8 --input-bit-depth=8
51+--passes=1 --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 --limit=1
52+--threads=1 --tile-columns=0 --enable-rect-partitions=1 --enable-1to4-partitions=1
53+--min-partition-size=8 --max-partition-size=32 --sb-size=64 --tune-content=screen`,
54+per-arm overrides last:
55+
56+* `testsrc2-screen-nopalette-cq50` -- rect strips really use intrabc; must refuse by NAME
57+ (was: a silently wrong frame).
58+* `smptebars-screen-nopalette-cq45` -- decodes the whole frame, 69 rect `use_intrabc`
59+ reads; entropy coverage (see residue).
60+* `testsrc2-screen-nopalette-cq63` -- screen tools but header `allow_intrabc = 0`; frame
61+ compared pixel-exact against ffmpeg, proving the new read is not taken when libaom does
62+ not write it.
63+
64+```
65+cargo test -p ec-av1 --lib a_real_aomenc_screen_key_frame_reads_use_intrabc -- --nocapture
66+-> 1 passed: 147 rect-strip use_intrabc symbol(s) read, 1 refused by name, 1 frames compared pixel-exact
67+```
68+
69+`refusal_inventory` (3 tests) and `gate_coverage` (7 tests) green.
70+
71+## EVIDENCE
72+
73+* `EVIDENCE: $HOME/.cache/kf900-r5/{s.obu,ours.yuv,ref.yuv} | aomenc chartered recipe (sha256 4fe2e7ba57...; encoded twice byte-identical as bf048186e3... in IVF form), decode_probe vs `ffmpeg -i` | before fix: OK + 73438 bytes differ, first luma (0,0) ours 128 vs ref 74; after fix: named refusal instead of a wrong frame`
74+* `EVIDENCE: $HOME/.cache/kf900-r5/{c45_ours.txt,c45_ref.txt} | EC_TRACE_MODE_STEP ladder both decoders | first divergence mi(0,0) name=mode: ours 62696 vs oracle 58628 = one unconsumed intrabc symbol`
75+* `EVIDENCE: $HOME/.cache/kf900-r5/{b_o.n,b_r.n} | same ladder on the smptebars cq45 arm after the fix | 429 mode-ladder elements identical, first divergence at mi(32,44) (a SQUARE intrabc block's DV read)`
76+* `EVIDENCE: $HOME/.cache/kf900-suite-r5.log | full ec-av1 lib suite as systemd unit kf900-suite-r5-1788331689 | test result: ok. 385 passed; 0 failed; 33 ignored, 1088.55s`
77+
78+## Residue
79+
80+* `deferred: pixel-exactness on frames that actually USE intrabc -- read_intrabc_dv desyncs
81+ inside the DV of a SQUARE 16x16 intrabc block at mi(32,44) (smptebars cq45 arm: 429
82+ ladder elements exact, then diverges); it is a separate defect from this lane's read --
83+ unblocked by a DV-symbol ladder against the oracle at that block`
84+* `deferred: rect-strip intrabc RECONSTRUCTION (the new refusal) -- needs the DV path above
85+ working first, plus the square path's own open "intrabc block under TxMode::Select" refusal`
86+* `deferred: 8-bit screen key frame with palette, cq45 --enable-tx-size-search=1 -- after this
87+ fix the ladder is exact for 46 elements and diverges in the TAIL of the palette block at
88+ mi(0,8) (palette colour-index map / tx). Separate palette defect, not intrabc`