forge
Explore
Log in

Don't you dare go Hollow

wip(rectchroma2): merge lane-golomb 173b793 + partial work from the interrupted round

Browse files at this commit

51ce8e820ecfdd14a5bd712eba06cc52c3bf5976Ahmet Kaan GümüşParent: e49934b414fb70
Conflict resolutions: dump_stage per-picture index keeps the thread-local
counter; var-tx leaf lf grid keeps main's rect (tw,th) leaves with golomb's
luma-only fill (libaom get_transform_size splits only for AOM_PLANE_Y).
crates/ec-av1/src/decode.rsmodified+299 -41
@@ -2121,6 +2121,44 @@ pub(crate) fn sb_rect_hits() -> usize {
2121 SB_RECT_HITS.with(|c| c.get())2121 SB_RECT_HITS.with(|c| c.get())
2122 }2122 }
2123 2123
2124+// lane-golomb r2: the 32x32-level FRAME-EDGE partition. Slot 0/1 = the
2125+// gathered edge bit read as 0 (HORZ/VERT) / 1 (SPLIT); slot 2 = a 32-level
2126+// PARTITION_HORZ decoded with `has_rows32 == false` (only the top 32x16 half
2127+// is coded), slot 3 = a PARTITION_VERT with `has_cols32 == false`. Both tile
2128+// paths (intra and inter) feed the same counter.
2129+//
2130+// lane-golomb r3: slots 4..7 are the same four facts one level up, at the
2131+// SUPERBLOCK (64x64) edge -- 4/5 = the gathered 64-level bit read as
2132+// HORZ/VERT / SPLIT, 6 = a 64x32 bottom-edge strip decoded with
2133+// `has_rows == false`, 7 = a 32x64 right-edge strip. Real aomenc answers a
2134+// bottom-edge superblock with the 64-level HORZ (measured: 192x80 flat-band,
2135+// every SB of the last row), so the 32-level slots stay 0 on that content and
2136+// only these prove the arm fired.
2137+thread_local! {
2138+ static EDGE32_HITS: std::cell::Cell<[usize; 8]> =
2139+ const { std::cell::Cell::new([0; 8]) };
2140+}
2141+
2142+/// Current value of [`EDGE32_HITS`].
2143+pub(crate) fn edge32_hits() -> [usize; 8] {
2144+ EDGE32_HITS.with(|c| c.get())
2145+}
2146+
2147+/// [`bump_edge32`] of `base + bit`, returning the bit -- the gathered edge
2148+/// reads are `if`-conditions, so the counter has to ride the expression.
2149+fn bump_edge32_bit(base: usize, bit: usize) -> usize {
2150+ bump_edge32(base + bit.min(1));
2151+ bit
2152+}
2153+
2154+fn bump_edge32(slot: usize) {
2155+ EDGE32_HITS.with(|c| {
2156+ let mut h = c.get();
2157+ h[slot] += 1;
2158+ c.set(h)
2159+ });
2160+}
2161+
2124 // lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/2162 // lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/
2125 // `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x642163 // `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x64
2126 // strip) fired. Real aomenc picks these at 64 even with2164 // strip) fired. Real aomenc picks these at 64 even with
@@ -4291,6 +4329,36 @@ impl Neighbours {
4291 }4329 }
4292 }4330 }
4293 4331
4332+ /// One var-tx / split-tx LEAF's own LUMA transform dims over its mi span.
4333+ /// libaom `get_transform_size` (av1_loopfilter.c:207) applies the split
4334+ /// override only `if ((plane == AOM_PLANE_Y) && ...)` -- chroma keeps
4335+ /// `av1_get_max_uv_txsize(mbmi->bsize)`, the whole BLOCK's uv transform.
4336+ /// Routing a leaf through [`Self::fill_lf_grid_rect`] recomputed the uv
4337+ /// dims from the LEAF span and so invented chroma transform edges the
4338+ /// deblocker then filtered (lane-golomb r6). `ref_grid`/`delta_lf_grid`
4339+ /// are already correct from the block's own fill over the same span.
4340+ fn fill_lf_grid_leaf_luma(
4341+ &mut self,
4342+ at_mi: (usize, usize),
4343+ w_mi: usize,
4344+ h_mi: usize,
4345+ tx_px: u8,
4346+ tx_h_px: u8,
4347+ ) {
4348+ let (mi_r, mi_c) = at_mi;
4349+ for rr in 0..h_mi {
4350+ for cc in 0..w_mi {
4351+ let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
4352+ if let Some(cell) = self.tx_grid.get_mut(idx) {
4353+ *cell = tx_px;
4354+ }
4355+ if let Some(cell) = self.tx_h_grid.get_mut(idx) {
4356+ *cell = tx_h_px;
4357+ }
4358+ }
4359+ }
4360+ }
4361+
4294 /// Marks every 4x4 mi cell a just-decoded coded block covers with its4362 /// Marks every 4x4 mi cell a just-decoded coded block covers with its
4295 /// `skip` flag -- `at_mi`/`side_mi` are the block's own position and4363 /// `skip` flag -- `at_mi`/`side_mi` are the block's own position and
4296 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s4364 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s
@@ -8953,8 +9021,22 @@ fn dump_stage_idx(var: &str) -> usize {
8953 9021
8954 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {9022 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
8955 use std::io::Write;9023 use std::io::Write;
9024+ // lane-golomb r6: one file per DECODE-order picture, like aomdec's own
9025+ // `ec_dump16` static index -- a single `.f0` overwritten every frame made
9026+ // the post-deblock stage uncomparable across a sequence.
9027+ thread_local! {
9028+ static STAGE_IDX: std::cell::RefCell<std::collections::HashMap<String, usize>> =
9029+ std::cell::RefCell::new(std::collections::HashMap::new());
9030+ }
9031+ let idx = STAGE_IDX.with(|m| {
9032+ let mut m = m.borrow_mut();
9033+ let e = m.entry(var.to_string()).or_insert(0);
9034+ let i = *e;
9035+ *e += 1;
9036+ i
9037+ });
8956 if let Ok(path) = std::env::var(var)9038 if let Ok(path) = std::env::var(var)
8957- && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))9039+ && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}"))
8958 {9040 {
8959 for p in [y, u, v] {9041 for p in [y, u, v] {
8960 let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect();9042 let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect();
@@ -12042,8 +12124,8 @@ fn read_inter_plane_rect(
12042 // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e.12124 // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e.
12043 // the *longer* side of this rect transform.12125 // the *longer* side of this rect transform.
12044 let default_tx_type = match inherited_luma_tx_type {12126 let default_tx_type = match inherited_luma_tx_type {
12045- Some(t) if w.max(h) < 32 => t,12127+ Some(t) => reduce_inherited_chroma_tx_type(t, w, h),
12046- _ => TxType::DctDct,12128+ None => TxType::DctDct,
12047 };12129 };
12048 // lane-r14 r2: a 64-length axis codes only its low 32 coefficients12130 // lane-r14 r2: a 64-length axis codes only its low 32 coefficients
12049 // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)`12131 // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)`
@@ -12210,6 +12292,45 @@ fn read_inter_luma8(
12210 12292
12211 /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its12293 /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its
12212 /// coefficient tables from -- the inter counterpart of [`txbset_for`].12294 /// coefficient tables from -- the inter counterpart of [`txbset_for`].
12295+/// `av1_get_tx_type`'s chroma tail (libaom `av1/common/blockd.h:1291-1305`):
12296+/// an inter block's chroma transform inherits the *colocated luma* unit's
12297+/// coded `tx_type`, then drops back to `DCT_DCT` unless that type is a member
12298+/// of the extended set the CHROMA transform size selects
12299+/// (`av1_ext_tx_used[av1_get_ext_tx_set_type(uv_tx, 1, reduced)][tx_type]`,
12300+/// `blockd.h:1036`/`1097`). lane-golomb r7: we used to force `DCT_DCT` at
12301+/// every chroma side >= 32, but `av1_get_ext_tx_set_type`'s DCT-only rung is
12302+/// `tx_size_sqr_up > TX_32X32`; at exactly TX_32X32 an inter block reads
12303+/// `EXT_TX_SET_DCT_IDTX`, so a 64x64 inter block whose first luma leaf coded
12304+/// `IDTX` inherits IDTX on its 32x32 chroma units. `IDTX` and `DCT_DCT` are
12305+/// both `TX_CLASS_2D`, so that mistake left the entropy stream perfectly in
12306+/// sync and only corrupted the inverse transform (one 64x64 superblock of
12307+/// high-frequency chroma noise, luma bit-exact).
12308+fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize) -> TxType {
12309+ use TxType::*;
12310+ let sqr_up = w.max(h);
12311+ let sqr = w.min(h);
12312+ let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get);
12313+ // `av1_get_ext_tx_set_type(tx_size, is_inter = 1, reduced)`.
12314+ let allowed: &[TxType] = if sqr_up > 32 {
12315+ // EXT_TX_SET_DCTONLY
12316+ &[DctDct]
12317+ } else if sqr_up == 32 || reduced {
12318+ // EXT_TX_SET_DCT_IDTX
12319+ &[DctDct, Idtx]
12320+ } else if sqr == 16 {
12321+ // EXT_TX_SET_DTT9_IDTX_1DDCT -- TX_TYPES 0..=11, i.e. everything but
12322+ // the four 1D ADST/FLIPADST types.
12323+ &[
12324+ DctDct, AdstDct, DctAdst, AdstAdst, FlipAdstDct, DctFlipAdst, FlipAdstFlipAdst,
12325+ AdstFlipAdst, FlipAdstAdst, Idtx, VDct, HDct,
12326+ ]
12327+ } else {
12328+ // EXT_TX_SET_ALL16
12329+ return t;
12330+ };
12331+ if allowed.contains(&t) { t } else { DctDct }
12332+}
12333+
12213 fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {12334 fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
12214 match tx_px {12335 match tx_px {
12215 32 => TxbSet::Luma32Inter,12336 32 => TxbSet::Luma32Inter,
@@ -12715,6 +12836,18 @@ fn deblock_plane(
12715 // last coded mi column's horizontal edges were filtered when libaom's12836 // last coded mi column's horizontal edges were filtered when libaom's
12716 // real output leaves them untouched (r6's post-deblock diff, 37 px, all12837 // real output leaves them untouched (r6's post-deblock diff, 37 px, all
12717 // in columns 44-47); clipping here closes it (3/3 frames pixel-exact).12838 // in columns 44-47); clipping here closes it (3/3 frames pixel-exact).
12839+ // lane-golomb r9: the bound is the MI-ROUNDED frame, not the coded
12840+ // frame. libaom's `av1_filter_block_plane_vert/horz` walk the superblock
12841+ // and stop at `cm->mi_params.mi_cols`/`mi_rows`, which
12842+ // `av1_set_mb_mi` derives from `ALIGN_POWER_OF_TWO(width, 3)` -- the
12843+ // 8-pixel-aligned frame, i.e. a 68-wide frame is filtered out to column
12844+ // 72 and the vertical edge AT x=68 is a real edge that rewrites the
12845+ // in-crop columns 64..67. Clipping at `frame_width` skipped it, which is
12846+ // the +-1 straddling-band defect (68x192 cq35, frame 1, 141 luma pixels
12847+ // all in columns 64..67; frame 0 survived because that edge carried no
12848+ // filter level there). r7's superres measurement is preserved: its frame
12849+ // was already 8-aligned, so this bound equals `frame_width` there and
12850+ // still excludes the superblock padding up to `true_width`.
12718 let (cw, ch) = if chroma {12851 let (cw, ch) = if chroma {
12719 (frame_width.div_ceil(2), frame_height.div_ceil(2))12852 (frame_width.div_ceil(2), frame_height.div_ceil(2))
12720 } else {12853 } else {
@@ -12725,11 +12858,17 @@ fn deblock_plane(
12725 plane.true_height.min(ch),12858 plane.true_height.min(ch),
12726 plane.width,12859 plane.width,
12727 );12860 );
12861+ if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() {
12862+ eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height);
12863+ }
12728 let mut y0 = 0usize;12864 let mut y0 = 0usize;
12729 while y0 < th {12865 while y0 < th {
12730 let mut x0 = 4usize;12866 let mut x0 = 4usize;
12731 while x0 < tw {12867 while x0 < tw {
12732 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {12868 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {
12869+ if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() && plane_idx == 0 {
12870+ eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
12871+ }
12733 filter_edge(12872 filter_edge(
12734 &mut plane.data,12873 &mut plane.data,
12735 y0 * stride + x0,12874 y0 * stride + x0,
@@ -12943,13 +13082,30 @@ fn apply_loop_restoration(
12943 deblocked_v: &PlaneBuf,13082 deblocked_v: &PlaneBuf,
12944 lr: &LoopRestorationParams,13083 lr: &LoopRestorationParams,
12945 grid: &crate::restoration::RestorationGrid,13084 grid: &crate::restoration::RestorationGrid,
13085+ // lane-golomb r8: this frame header's own (cropped) luma size. Loop
13086+ // restoration is the ONE post-decode filter that does NOT run over the
13087+ // mi-rounded plane: libaom's `av1_loop_restoration_filter_frame` sizes
13088+ // every plane with `av1_get_upsampled_plane_size` -- `plane_w =
13089+ // ROUND_POWER_OF_TWO(cm->superres_upscaled_width, ss_x)`, `plane_h =
13090+ // ROUND_POWER_OF_TWO(cm->height, ss_y)` (`av1/common/restoration.c:47`)
13091+ // -- and asserts it equals the buffer's CROP width
13092+ // (`restoration.c:1106`), then `av1_extend_frame(..., plane_w, plane_h,
13093+ // ...)` (`restoration.c:1109`) replicates the right/bottom border from
13094+ // that cropped edge before any unit is filtered. Deblock and CDEF DO
13095+ // walk the mi grid, which is why passing `true_width`/`true_height`
13096+ // here went unnoticed until a frame whose size is not a multiple of 8
13097+ // (68 -> mi-rounded 72): the LR taps at the last four real columns then
13098+ // read this decoder's own decoded samples at columns 68..71 where
13099+ // libaom reads column 67 replicated -- +-1 over the straddling band
13100+ // (class av1-truesize-lane: true frame size vs mi-rounded).
13101+ (frame_w, frame_h): (usize, usize),
12946 ) {13102 ) {
12947 y.data = crate::restoration::apply_loop_restoration_plane(13103 y.data = crate::restoration::apply_loop_restoration_plane(
12948 &y.data,13104 &y.data,
12949 &deblocked_y.data,13105 &deblocked_y.data,
12950 y.width,13106 y.width,
12951- y.true_width,13107+ frame_w,
12952- y.true_height,13108+ frame_h,
12953 0,13109 0,
12954 lr.frame_restoration_type[0],13110 lr.frame_restoration_type[0],
12955 lr.loop_restoration_size[0],13111 lr.loop_restoration_size[0],
@@ -12960,8 +13116,8 @@ fn apply_loop_restoration(
12960 &u.data,13116 &u.data,
12961 &deblocked_u.data,13117 &deblocked_u.data,
12962 u.width,13118 u.width,
12963- u.true_width,13119+ frame_w.div_ceil(2),
12964- u.true_height,13120+ frame_h.div_ceil(2),
12965 1,13121 1,
12966 lr.frame_restoration_type[1],13122 lr.frame_restoration_type[1],
12967 lr.loop_restoration_size[1],13123 lr.loop_restoration_size[1],
@@ -12972,8 +13128,8 @@ fn apply_loop_restoration(
12972 &v.data,13128 &v.data,
12973 &deblocked_v.data,13129 &deblocked_v.data,
12974 v.width,13130 v.width,
12975- v.true_width,13131+ frame_w.div_ceil(2),
12976- v.true_height,13132+ frame_h.div_ceil(2),
12977 1,13133 1,
12978 lr.frame_restoration_type[2],13134 lr.frame_restoration_type[2],
12979 lr.loop_restoration_size[2],13135 lr.loop_restoration_size[2],
@@ -13536,11 +13692,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13536 match (has_cols, has_rows) {13692 match (has_cols, has_rows) {
13537 (true, false) => {13693 (true, false) => {
13538 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));13694 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));
13695+ bump_edge32(4 + b.min(1) as usize);
13539 bump_edge_part(b.min(1) as usize);13696 bump_edge_part(b.min(1) as usize);
13540 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }13697 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
13541 }13698 }
13542 (false, true) => {13699 (false, true) => {
13543 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));13700 let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));
13701+ bump_edge32(4 + b.min(1) as usize);
13544 bump_edge_part(b.min(1) as usize);13702 bump_edge_part(b.min(1) as usize);
13545 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }13703 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
13546 }13704 }
@@ -13609,6 +13767,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13609 &cdfs.partition_w32[ctx32],13767 &cdfs.partition_w32[ctx32],
13610 VERT_ALIKE,13768 VERT_ALIKE,
13611 ));13769 ));
13770+ bump_edge32(b.min(1) as usize);
13612 bump_edge_part(2 + b.min(1) as usize);13771 bump_edge_part(2 + b.min(1) as usize);
13613 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }13772 if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
13614 }13773 }
@@ -13617,6 +13776,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
13617 &cdfs.partition_w32[ctx32],13776 &cdfs.partition_w32[ctx32],
13618 HORZ_ALIKE,13777 HORZ_ALIKE,
13619 ));13778 ));
13779+ bump_edge32(b.min(1) as usize);
13620 bump_edge_part(2 + b.min(1) as usize);13780 bump_edge_part(2 + b.min(1) as usize);
13621 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }13781 if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
13622 }13782 }
@@ -14272,6 +14432,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14272 tx_select,14432 tx_select,
14273 reduced_tx_set,14433 reduced_tx_set,
14274 )?;14434 )?;
14435+ if !has_rows32 {
14436+ bump_edge32(2);
14437+ }
14275 // lane-hgkf r1: at the frame edge only the first half of the strip is14438 // lane-hgkf r1: at the frame edge only the first half of the strip is
14276 // coded (libaom `decode_partition` guards the second half with the same14439 // coded (libaom `decode_partition` guards the second half with the same
14277 // test that made this partition non-square).14440 // test that made this partition non-square).
@@ -14313,6 +14476,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14313 tx_select,14476 tx_select,
14314 reduced_tx_set,14477 reduced_tx_set,
14315 )?;14478 )?;
14479+ if !has_cols32 {
14480+ bump_edge32(3);
14481+ }
14316 // lane-hgkf r1: at the frame edge only the first half of the strip is14482 // lane-hgkf r1: at the frame edge only the first half of the strip is
14317 // coded (libaom `decode_partition` guards the second half with the same14483 // coded (libaom `decode_partition` guards the second half with the same
14318 // test that made this partition non-square).14484 // test that made this partition non-square).
@@ -14703,6 +14869,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14703 tx_select,14869 tx_select,
14704 reduced_tx_set,14870 reduced_tx_set,
14705 )?;14871 )?;
14872+ if !has_rows {
14873+ bump_edge32(6);
14874+ }
14706 // lane-golomb r1: at the frame edge only the first half of the14875 // lane-golomb r1: at the frame edge only the first half of the
14707 // strip is coded (libaom `decode_partition` guards the second14876 // strip is coded (libaom `decode_partition` guards the second
14708 // with the same has_rows test that made this partition non-square).14877 // with the same has_rows test that made this partition non-square).
@@ -14744,6 +14913,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14744 tx_select,14913 tx_select,
14745 reduced_tx_set,14914 reduced_tx_set,
14746 )?;14915 )?;
14916+ if !has_cols {
14917+ bump_edge32(7);
14918+ }
14747 // lane-golomb r1: at the frame edge only the first half of the14919 // lane-golomb r1: at the frame edge only the first half of the
14748 // strip is coded (libaom `decode_partition` guards the second14920 // strip is coded (libaom `decode_partition` guards the second
14749 // with the same has_cols test that made this partition non-square).14921 // with the same has_cols test that made this partition non-square).
@@ -14966,7 +15138,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
14966 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);15138 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
14967 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);15139 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
14968 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);15140 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
14969- apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);15141+ apply_loop_restoration(
15142+ &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid,
15143+ (frame_width as usize, frame_height as usize),
15144+ );
14970 15145
14971 let (fw, fh) = (frame_width as usize, frame_height as usize);15146 let (fw, fh) = (frame_width as usize, frame_height as usize);
14972 if fw == width && fh == height {15147 if fw == width && fh == height {
@@ -15358,10 +15533,9 @@ fn read_inter_plane(
15358 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's15533 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's
15359 // chroma plane never codes its own `tx_type` symbol, but (unlike an15534 // chroma plane never codes its own `tx_type` symbol, but (unlike an
15360 // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits15535 // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits
15361- // the colocated luma transform's coded type verbatim, clamped back to15536+ // the colocated luma transform's coded type, narrowed to the extended
15362- // `DCT_DCT` at the chroma tx sizes the spec forces DCT-only15537+ // set the CHROMA size selects ([`reduce_inherited_chroma_tx_type`]).
15363- // (`av1_get_ext_tx_set_type`: `tx_size_sqr_up >= TX_32X32`, i.e. this15538+ // `None` for the luma call itself
15364- // function's own `side >= 32`). `None` for the luma call itself
15365 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true15539 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true
15366 // `DCT_DCT` default at 32-point+) already resolves it without help.15540 // `DCT_DCT` default at 32-point+) already resolves it without help.
15367 inherited_luma_tx_type: Option<TxType>,15541 inherited_luma_tx_type: Option<TxType>,
@@ -15379,8 +15553,8 @@ fn read_inter_plane(
15379 };15553 };
15380 let mut coding = cdfs.txb(set, tx_mode);15554 let mut coding = cdfs.txb(set, tx_mode);
15381 let default_tx_type = match inherited_luma_tx_type {15555 let default_tx_type = match inherited_luma_tx_type {
15382- Some(t) if side < 32 => t,15556+ Some(t) => reduce_inherited_chroma_tx_type(t, side, side),
15383- _ => TxType::DctDct,15557+ None => TxType::DctDct,
15384 };15558 };
15385 let (grid, tx_type) = read_coeffs(15559 let (grid, tx_type) = read_coeffs(
15386 dec,15560 dec,
@@ -15773,22 +15947,33 @@ fn obmc_mask(len: usize) -> &'static [u8] {
15773 /// A bordering block's own resolved interp filter kernel, `(h, v)` --15947 /// A bordering block's own resolved interp filter kernel, `(h, v)` --
15774 /// mirrors [`resolve_interp_filter`]'s own return order from its stored15948 /// mirrors [`resolve_interp_filter`]'s own return order from its stored
15775 /// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` =15949 /// `[u8; 2]` (`Neighbours::above_filter`/`left_filter`, `[sym0, sym1]` =
15776-/// `[v_sym, h_sym]`). Never calls `from_switchable_symbol` on the `[3, 3]`15950+/// `[v_sym, h_sym]`). The `[3, 3]` sentinel is only ever stored for an intra
15777-/// sentinel: that value is only ever stored for an intra neighbour (already15951+/// neighbour (excluded by [`overlappable_above`]/[`overlappable_left`]'s
15778-/// excluded by [`overlappable_above`]/[`overlappable_left`]'s `is_inter`15952+/// `is_inter` gate) or when `interp_fixed` is `Some` for the whole frame
15779-/// gate) or when `interp_fixed` is `Some` for the whole frame, handled here15953+/// (handled here first) -- so a sentinel reaching the kernel lookup means the
15780-/// first.15954+/// stream desynced upstream, and this refuses instead of panicking.
15781 fn neighbour_filter(15955 fn neighbour_filter(
15782 interp_fixed: Option<mc::InterpFilterKind>,15956 interp_fixed: Option<mc::InterpFilterKind>,
15783 sym: [u8; 2],15957 sym: [u8; 2],
15784-) -> (mc::InterpFilterKind, mc::InterpFilterKind) {15958+) -> Result<(mc::InterpFilterKind, mc::InterpFilterKind)> {
15785 if let Some(kind) = interp_fixed {15959 if let Some(kind) = interp_fixed {
15786- return (kind, kind);15960+ return Ok((kind, kind));
15961+ }
15962+ // lane-golomb r9: this used to hand the sentinel straight to
15963+ // `from_switchable_symbol`, which PANICS on any value above 2 -- a crash
15964+ // on stream data (measured on a real 192x68 cq40 aomenc stream, where an
15965+ // inter leaf below 8x8 desyncs upstream and leaves an unrecorded filter
15966+ // behind). A decoder must refuse such a stream by name, never abort the
15967+ // process; the desync that produces the sentinel belongs to lane-intersub8.
15968+ if sym[0] > 2 || sym[1] > 2 {
15969+ return Err(unsupported(
15970+ "an OBMC neighbour whose switchable interp filter was never recorded",
15971+ ));
15787 }15972 }
15788- (15973+ Ok((
15789 mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize),15974 mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize),
15790 mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize),15975 mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize),
15791- )15976+ ))
15792 }15977 }
15793 15978
15794 /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh15979 /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh
@@ -16066,7 +16251,7 @@ fn obmc_blend(
16066 let (h_kind, v_kind) = neighbour_filter(16251 let (h_kind, v_kind) = neighbour_filter(
16067 interp_fixed,16252 interp_fixed,
16068 neighbours.above_filter[mi_col + off4],16253 neighbours.above_filter[mi_col + off4],
16069- );16254+ )?;
16070 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;16255 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
16071 let nb_scale = mc::scale_factor(ny.width, frame_width);16256 let nb_scale = mc::scale_factor(ny.width, frame_width);
16072 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);16257 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
@@ -16085,7 +16270,7 @@ fn obmc_blend(
16085 let (h_kind, v_kind) = neighbour_filter(16270 let (h_kind, v_kind) = neighbour_filter(
16086 interp_fixed,16271 interp_fixed,
16087 neighbours.left_filter[mi_row + off4],16272 neighbours.left_filter[mi_row + off4],
16088- );16273+ )?;
16089 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;16274 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
16090 let nb_scale = mc::scale_factor(ny.width, frame_width);16275 let nb_scale = mc::scale_factor(ny.width, frame_width);
16091 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);16276 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
@@ -19200,21 +19385,20 @@ fn decode_inter_block(
19200 },19385 },
19201 );19386 );
19202 // lane-txselect: a var-tx block's deblock edges follow its own transform19387 // lane-txselect: a var-tx block's deblock edges follow its own transform
19203- // units, not the block. Chroma still reads `tx_h_grid / 2` (the block's19388+ // units, not the block -- for LUMA only (lane-golomb r6): the chroma
19204- // uv transform is not split) -- a known corner-cut of this round.19389+ // grids keep the block's own `av1_get_max_uv_txsize`, which is what
19390+ // libaom's `get_transform_size` reads for `plane != AOM_PLANE_Y`.
19205 if let Some(leaves) = &vartx_leaves {19391 if let Some(leaves) = &vartx_leaves {
19392+ // lane-golomb r6 x main: rect leaves (tw,th), but the LUMA-only fill --
19393+ // fill_lf_grid_rect would recompute chroma tx dims from the leaf span,
19394+ // while libaom's get_transform_size splits only for AOM_PLANE_Y.
19206 for &(row, col, tw, th) in leaves {19395 for &(row, col, tw, th) in leaves {
19207- neighbours.fill_lf_grid_rect(19396+ neighbours.fill_lf_grid_leaf_luma(
19208 (at_mi.0 + row, at_mi.1 + col),19397 (at_mi.0 + row, at_mi.1 + col),
19209 tw / MI,19398 tw / MI,
19210 th / MI,19399 th / MI,
19211 tw as u8,19400 tw as u8,
19212 th as u8,19401 th as u8,
19213- if globalmv_for_lf {
19214- -ref_frame_for_lf
19215- } else {
19216- ref_frame_for_lf
19217- },
19218 );19402 );
19219 }19403 }
19220 }19404 }
@@ -20941,7 +21125,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20941 // true size. Height must still match: AV1 superres never scales height21125 // true size. Height must still match: AV1 superres never scales height
20942 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path21126 // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path
20943 // has a vertical scaling pass.21127 // has a vertical scaling pass.
20944- if reference.height != true_height {21128+ // lane-golomb r8: the comparison is against the header's own frame
21129+ // height, NOT the mi-rounded `true_height`. libaom compares references
21130+ // on the CROPPED dimensions -- `av1_setup_scale_factors_for_frame(&sf,
21131+ // ref->y_crop_width, ref->y_crop_height, cm->width, cm->height)`
21132+ // (`av1/common/reconinter.c`), and a reference is "scaled" only when
21133+ // those differ (`av1_is_scaled`). A decoded `Picture` is cropped to
21134+ // `fw`/`fh`, so for any height that is not a multiple of 8 (68 ->
21135+ // mi_rows 18 -> `true_height` 72) this test compared 68 against 72 and
21136+ // refused every same-size reference (class av1-truesize-lane: true
21137+ // frame size vs mi-rounded). Height must still MATCH: AV1 superres
21138+ // never scales height, and no path here has a vertical scaling pass.
21139+ if reference.height != frame_height as usize {
20945 return Err(unsupported(21140 return Err(unsupported(
20946 "a reference picture whose height does not match this frame's own true size",21141 "a reference picture whose height does not match this frame's own true size",
20947 ));21142 ));
@@ -21380,7 +21575,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
21380 // lane-golomb r1 (class `parsed-then-discarded`): the gathered21575 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
21381 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT21576 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
21382 // (libaom `ec_read_partition_impl`).21577 // (libaom `ec_read_partition_impl`).
21383- if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)) == 1 {21578+ if bump_edge32_bit(
21579+ 4,
21580+ dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
21581+ ) == 1 {
21384 PARTITION_SPLIT21582 PARTITION_SPLIT
21385 } else {21583 } else {
21386 PARTITION_HORZ21584 PARTITION_HORZ
@@ -21390,7 +21588,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
21390 // lane-golomb r1 (class `parsed-then-discarded`): the gathered21588 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
21391 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT21589 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
21392 // (libaom `ec_read_partition_impl`).21590 // (libaom `ec_read_partition_impl`).
21393- if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)) == 1 {21591+ if bump_edge32_bit(
21592+ 4,
21593+ dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)),
21594+ ) == 1 {
21394 PARTITION_SPLIT21595 PARTITION_SPLIT
21395 } else {21596 } else {
21396 PARTITION_VERT21597 PARTITION_VERT
@@ -21565,7 +21766,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
21565 // lane-golomb r1 (class `parsed-then-discarded`): the gathered21766 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
21566 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT21767 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
21567 // (libaom `ec_read_partition_impl`).21768 // (libaom `ec_read_partition_impl`).
21568- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 {21769+ if {
21770+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));
21771+ bump_edge32(b.min(1) as usize);
21772+ b
21773+ } == 1 {
21569 PARTITION_SPLIT21774 PARTITION_SPLIT
21570 } else {21775 } else {
21571 PARTITION_HORZ21776 PARTITION_HORZ
@@ -21575,7 +21780,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
21575 // lane-golomb r1 (class `parsed-then-discarded`): the gathered21780 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
21576 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT21781 // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
21577 // (libaom `ec_read_partition_impl`).21782 // (libaom `ec_read_partition_impl`).
21578- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 {21783+ if {
21784+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE));
21785+ bump_edge32(b.min(1) as usize);
21786+ b
21787+ } == 1 {
21579 PARTITION_SPLIT21788 PARTITION_SPLIT
21580 } else {21789 } else {
21581 PARTITION_VERT21790 PARTITION_VERT
@@ -22302,6 +22511,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22302 allow_screen_content_tools,22511 allow_screen_content_tools,
22303 frame_width as usize,22512 frame_width as usize,
22304 )?;22513 )?;
22514+ if !has_rows32 {
22515+ bump_edge32(2);
22516+ }
22517+ // lane-golomb r2: at the frame edge only the first half of the
22518+ // strip is coded (libaom `decode_partition` guards the second
22519+ // with the same has_rows32 test that made this partition non-square).
22520+ if has_rows32 {
22305 decode_inter_block(22521 decode_inter_block(
22306 &mut dec,22522 &mut dec,
22307 &mut cdfs,22523 &mut cdfs,
@@ -22352,6 +22568,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22352 frame_width as usize,22568 frame_width as usize,
22353 )?;22569 )?;
22354 }22570 }
22571+ }
22355 PARTITION_VERT => {22572 PARTITION_VERT => {
22356 // lane-rect r2: mirror of PARTITION_HORZ above with22573 // lane-rect r2: mirror of PARTITION_HORZ above with
22357 // width/height swapped.22574 // width/height swapped.
@@ -22405,6 +22622,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22405 allow_screen_content_tools,22622 allow_screen_content_tools,
22406 frame_width as usize,22623 frame_width as usize,
22407 )?;22624 )?;
22625+ if !has_cols32 {
22626+ bump_edge32(3);
22627+ }
22628+ // lane-golomb r2: at the frame edge only the first half of the
22629+ // strip is coded (libaom `decode_partition` guards the second
22630+ // with the same has_cols32 test that made this partition non-square).
22631+ if has_cols32 {
22408 decode_inter_block(22632 decode_inter_block(
22409 &mut dec,22633 &mut dec,
22410 &mut cdfs,22634 &mut cdfs,
@@ -22455,6 +22679,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22455 frame_width as usize,22679 frame_width as usize,
22456 )?;22680 )?;
22457 }22681 }
22682+ }
22458 PARTITION_HORZ_A => {22683 PARTITION_HORZ_A => {
22459 // lane-partab r1: two 16x16 squares on top + a true22684 // lane-partab r1: two 16x16 squares on top + a true
22460 // 32x16 strip below (libaom decode_partition22685 // 32x16 strip below (libaom decode_partition
@@ -23033,7 +23258,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
23033 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);23258 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
23034 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);23259 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
23035 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);23260 dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
23036- apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);23261+ apply_loop_restoration(
23262+ &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid,
23263+ (frame_width as usize, frame_height as usize),
23264+ );
23037 23265
23038 let motion_field = build_motion_field(23266 let motion_field = build_motion_field(
23039 &grid,23267 &grid,
@@ -23106,6 +23334,36 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
23106 #[cfg(test)]23334 #[cfg(test)]
23107 mod tests {23335 mod tests {
23108 23336
23337+ /// lane-golomb r7: [`reduce_inherited_chroma_tx_type`] must reproduce
23338+ /// `av1_ext_tx_used[av1_get_ext_tx_set_type(uv_tx, 1, reduced)]`
23339+ /// (libaom `av1/common/blockd.h:1036`/`1097`) exactly -- the g35 residue
23340+ /// was one 64x64 inter superblock whose 32x32 chroma units are
23341+ /// `EXT_TX_SET_DCT_IDTX`, where IDTX survives and we forced `DCT_DCT`.
23342+ #[test]
23343+ fn an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set() {
23344+ use TxType::*;
23345+ // EXT_TX_SET_DCTONLY: `tx_size_sqr_up > TX_32X32`.
23346+ set_inter_tx_mode(true, false, true);
23347+ assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 64, 64), DctDct);
23348+ // EXT_TX_SET_DCT_IDTX at exactly TX_32X32 -- the residue's case.
23349+ assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 32, 32), Idtx);
23350+ assert_eq!(reduce_inherited_chroma_tx_type(AdstAdst, 32, 32), DctDct);
23351+ // EXT_TX_SET_DTT9_IDTX_1DDCT at `tx_size_sqr == TX_16X16`: the four
23352+ // 1D ADST/FLIPADST types (TX_TYPES 12..15) drop out, the rest stay.
23353+ assert_eq!(reduce_inherited_chroma_tx_type(HDct, 16, 16), HDct);
23354+ assert_eq!(reduce_inherited_chroma_tx_type(FlipAdstAdst, 16, 16), FlipAdstAdst);
23355+ assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 16), DctDct);
23356+ // EXT_TX_SET_ALL16 below that (`tx_size_sqr < TX_16X16`, so a 16x8
23357+ // chroma unit too).
23358+ assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 8), HAdst);
23359+ assert_eq!(reduce_inherited_chroma_tx_type(VFlipAdst, 8, 8), VFlipAdst);
23360+ // `reduced_tx_set` collapses every inter set to DCT_IDTX.
23361+ set_inter_tx_mode(true, true, true);
23362+ assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 8, 8), Idtx);
23363+ assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 8, 8), DctDct);
23364+ set_inter_tx_mode(true, false, true);
23365+ }
23366+
23109 /// lane-fistrip r1 (class `enumerate-the-table-domain`): every block23367 /// lane-fistrip r1 (class `enumerate-the-table-domain`): every block
23110 /// shape this decoder can hand [`filter_intra_size_class_rect`], against23368 /// shape this decoder can hand [`filter_intra_size_class_rect`], against
23111 /// `av1_filter_intra_allowed_bsize` (`block_size_wide <= 32 &&23369 /// `av1_filter_intra_allowed_bsize` (`block_size_wide <= 32 &&
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
@@ -34,6 +34,7 @@ const REFUSALS: &[&str] = &[
34 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",34 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
35 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",35 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
36 "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",36 "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
37+ "an OBMC neighbour whose switchable interp filter was never recorded",
37 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",38 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
38 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",39 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
39 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",40 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
crates/ec-av1/src/stream.rsmodified+360 -0
@@ -19870,6 +19870,366 @@ mod tests {
19870 );19870 );
19871 }19871 }
19872 19872
19873+ /// lane-golomb r2 gate: a 32x32-level block that STRADDLES the frame edge
19874+ /// and whose partition is the gathered edge bit's `PARTITION_HORZ` (bottom
19875+ /// edge) / `PARTITION_VERT` (right edge). Since r1 that bit can name
19876+ /// HORZ/VERT instead of always inferring SPLIT, so the second 32x16/16x32
19877+ /// half is out of frame and must NOT be decoded (libaom `decode_partition`:
19878+ /// `case PARTITION_HORZ: decode_block(top); if (has_rows) decode_block(bottom)`).
19879+ /// The AB and 1:4 arms need no such guard: at an edge libaom's
19880+ /// `ec_read_partition_impl` can only yield HORZ/VERT/SPLIT, so those arms
19881+ /// are unreachable there.
19882+ ///
19883+ /// Geometry: 192x80 (mi_rows=20 -- the second SB row is 16 px tall, so its
19884+ /// 32-level blocks at y=64 have `has_rows32 == false`) and 80x192 for the
19885+ /// right edge. Natural content (`testsrc2`); `smptebars`-style screen
19886+ /// content trips the palette/screen-content refusal before the edge is
19887+ /// reached. cq sweep, 8-bit and 10-bit, plus a 5-frame inter arm.
19888+ /// Counters are sampled per attempt and summed only over attempts that
19889+ /// decoded AND pixel-compared (class `counter-from-refused-stream`).
19890+ #[test]
19891+ fn a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition_decodes_pixel_exact() {
19892+ edge32_gate(
19893+ "a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition_decodes_pixel_exact",
19894+ false,
19895+ );
19896+ }
19897+
19898+ /// lane-golomb r2 OPEN DEFECT, pinned as a runnable test: with the 16-px
19899+ /// straddling band left FLAT the encoder answers the 32-level edge bit
19900+ /// with HORZ (`edge32=[2, 0, 2, 0]` on 192x80 cq40 8-bit), the guard added
19901+ /// this round keeps the stream in entropy sync -- every pixel outside the
19902+ /// two edge strips matches ffmpeg -- but the strips themselves
19903+ /// reconstruct wrong: `plane Y: 1081 pixels differ, first at row 62 col
19904+ /// 128`, diffs confined to rows 62..79 over ~64 columns (exactly the two
19905+ /// 32x16 strips plus the deblock bleed above them). That is a
19906+ /// reconstruction defect inside the strip (prediction/availability), not
19907+ /// the partition guard. `#[ignore]` so the suite stays green; run it with
19908+ /// `cargo test -p ec-av1 --lib -- --ignored a_32x32_frame_edge_rect_partition_with_a_flat`.
19909+ #[test]
19910+ #[ignore = "open r2 defect: the 32-level edge HORZ strip reconstructs wrong pixels"]
19911+ fn a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact() {
19912+ edge32_gate(
19913+ "a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact",
19914+ true,
19915+ );
19916+ }
19917+
19918+ /// lane-golomb r9 OPEN DEFECT, pinned as a runnable test: a frame whose
19919+ /// height (192x68) or width (68x192) is not a multiple of 8 leaves a 4-px
19920+ /// straddling band inside the mi-rounded plane, and every INTER frame's
19921+ /// output is +-1 wrong across that band and the columns/rows next to it
19922+ /// (`68x192 cq35 8-bit: frame 1 plane Y: 145 pixels differ, first at row 0
19923+ /// col 64`, mass in columns 64..67). r9 bisected it stage by stage against
19924+ /// the instrumented aomdec on that exact stream:
19925+ /// * `EC_AV1_PREFILT_DUMP` frame 1 is BYTE-IDENTICAL over the cropped
19926+ /// 68 columns -- reconstruction and inter prediction are exact, so the
19927+ /// charter's "MC reads past the crop" hypothesis is refuted a second time.
19928+ /// * `EC_AV1_POSTDEBLOCK_DUMP` with `EC_AV1_DEBUG_SKIP_CDEF=1` also matches
19929+ /// aomdec's own post-deblock dump (which is 72 columns wide, i.e. it
19930+ /// exposes the straddling band) -- the deblock, including its
19931+ /// `frame_width` clip, is correct.
19932+ /// * The divergence therefore enters in CDEF, at the last 8x8 CDEF block
19933+ /// column/row, which is the one that straddles the crop edge.
19934+ /// `#[ignore]` so the suite stays green; run it with
19935+ /// `cargo test -p ec-av1 --lib -- --ignored a_frame_edge_straddling_band`.
19936+ #[test]
19937+ #[ignore = "open r9 defect: CDEF at the last straddling 8x8 block column/row"]
19938+ fn a_frame_edge_straddling_band_decodes_pixel_exact() {
19939+ edge32_gate(
19940+ "a_frame_edge_straddling_band_decodes_pixel_exact",
19941+ false,
19942+ );
19943+ }
19944+
19945+ fn edge32_gate(name: &str, flat_band: bool) {
19946+ let NAME = name;
19947+ let _gate_lock = lock_gate_counters();
19948+ if !have_ffmpeg() {
19949+ eprintln!("SKIP {NAME}: no ffmpeg");
19950+ return;
19951+ }
19952+ if !have_aomenc() {
19953+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
19954+ return;
19955+ }
19956+ // (width, height, frames, ten_bit)
19957+ let mut arms: Vec<(usize, usize, usize, bool)> = Vec::new();
19958+ for &(w, h) in &[(192usize, 80usize), (80usize, 192usize)] {
19959+ arms.push((w, h, 1, false));
19960+ arms.push((w, h, 1, true));
19961+ }
19962+ // The inter arm: >= 4 frames so the 32-level edge path in the INTER
19963+ // tile walk is exercised too.
19964+ arms.push((192, 80, 5, false));
19965+ // lane-golomb r9: the straddling-band arms, only under the ignored
19966+ // `a_frame_edge_straddling_band_decodes_pixel_exact` name (they are
19967+ // RED -- see that test's own comment for the stage bisection). Naming
19968+ // them here rather than in a second copy of this gate keeps the
19969+ // recipe, the counters and the refusal handling identical.
19970+ if name == "a_frame_edge_straddling_band_decodes_pixel_exact" {
19971+ arms.clear();
19972+ arms.push((192, 68, 5, false));
19973+ arms.push((192, 68, 5, true));
19974+ arms.push((68, 192, 5, false));
19975+ arms.push((68, 192, 5, true));
19976+ }
19977+ // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is
19978+ // vacuous, panicking or red -- each measured this round with
19979+ // `arms.push((192, 68, 5, false))`, log
19980+ // `$HOME/.cache/golomb-gate-r8{b,e,f,g}.log`):
19981+ // * the r7 blocker IS fixed -- no attempt refuses "a reference
19982+ // picture whose height does not match this frame's own true
19983+ // size" any more (`decode.rs`'s comparison now uses the header's
19984+ // frame height, per libaom's crop-dimension reference test).
19985+ // * cq35 now refuses LATER, by another lane's name: "an inter
19986+ // SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)" -- so the
19987+ // arm compares nothing (class `counter-from-refused-stream`).
19988+ // * cq40 PANICS in `decode_inter_block8`
19989+ // (`from_switchable_symbol` handed a 4th symbol, `mc.rs:203`) =
19990+ // lane-sub8's own open below-8x8 desync; a panic cannot be
19991+ // tolerated as a named refusal.
19992+ // * cq59 8-bit is RED: `frame 1 plane Y: 217 pixels differ, first
19993+ // at row 60 col 170 (ours 172 vs ffmpeg 173)`, and the cq35
19994+ // 10-bit twin is RED at `row 56 col 48 (ours 530 vs ffmpeg
19995+ // 531)`. Both are +-1 bands in rows 56..63, i.e. the deblock/CDEF
19996+ // bleed ABOVE the 4-px straddling row band (64..67) -- the same
19997+ // shape as the `(68, 192, 5, false)` column defect below, so the
19998+ // two are very likely ONE straddling-band reconstruction defect.
19999+ // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red):
20000+ // a 68-px axis leaves the last superblock straddling by 4 px, the
20001+ // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >=
20002+ // max_w_mi` early return exists for. With
20003+ // `arms.push((192, 68, 5, false))` all EIGHT cq attempts refuse by
20004+ // name -- "a reference picture whose height does not match this
20005+ // frame's own true size" -- so the arm compares nothing (class
20006+ // `counter-from-refused-stream`). With
20007+ // `arms.push((68, 192, 5, false))` the gate goes RED on a real,
20008+ // separate defect: `68x192 cq35 frames=5 10bit=false frame 1 plane Y:
20009+ // 141 pixels differ, first at row 0 col 64 (ours 167 vs ffmpeg 166)
20010+ // [edge32=[0,34,0,0,1,17,0,1]]` -- LUMA, inside the 4-px straddling
20011+ // COLUMN. Both are unrelated to this round's chroma tx_type fix.
20012+ let cqs: [u32; 8] = [35, 40, 45, 50, 55, 57, 59, 61];
20013+ let mut totals = [0usize; 8];
20014+ let mut compared = 0usize;
20015+ let mut refusals: Vec<String> = Vec::new();
20016+ for &(width, height, frame_count, ten_bit) in &arms {
20017+ for &cq in &cqs {
20018+ let duration = frame_count as f64 / 25.0;
20019+ // `noise` (explicit seed) both defeats aomenc's
20020+ // screen-content detection -- which otherwise refuses every
20021+ // attempt at "a HORZ/VERT intra strip in a screen-content
20022+ // frame" -- and keeps the RD search off flat NONE blocks.
20023+ // Natural content over the whole superblock-aligned area,
20024+ // with the 16-px straddling band left FLAT (`pad`): with
20025+ // detail in that band aomenc always answers the edge bit with
20026+ // SPLIT (measured: 178 edge bits, 178 of them SPLIT, over a
20027+ // cq 35..61 sweep), so the HORZ/VERT arm this round guards
20028+ // never fired. `noise` on top keeps screen-content detection
20029+ // (and its palette-strip refusal) off.
20030+ let (cw, ch) = (
20031+ if flat_band && width % 64 != 0 { width - 16 } else { width },
20032+ if flat_band && height % 64 != 0 { height - 16 } else { height },
20033+ );
20034+ let pad = if flat_band {
20035+ format!("pad={width}:{height}:0:0:gray,")
20036+ } else {
20037+ String::new()
20038+ };
20039+ let source = format!(
20040+ "testsrc2=size={cw}x{ch}:duration={duration}:rate=25,\
20041+ {pad}noise=alls=6:allf=t+u:all_seed={cq}"
20042+ );
20043+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
20044+ let y4m = Command::new("ffmpeg")
20045+ .args([
20046+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix, "-strict",
20047+ "-1", "-t", &format!("{duration}"), "-f", "yuv4mpegpipe", "-",
20048+ ])
20049+ .stdin(Stdio::null())
20050+ .stdout(Stdio::piped())
20051+ .stderr(Stdio::piped())
20052+ .output()
20053+ .expect("ffmpeg failed to run");
20054+ assert!(
20055+ y4m.status.success(),
20056+ "{NAME}: ffmpeg fixture: {}",
20057+ String::from_utf8_lossy(&y4m.stderr)
20058+ );
20059+ let cq_arg = format!("--cq-level={cq}");
20060+ let mut args: Vec<&str> = vec![
20061+ "--codec=av1",
20062+ "--passes=1",
20063+ "--end-usage=q",
20064+ &cq_arg,
20065+ "--cpu-used=0",
20066+ "--threads=1",
20067+ "--row-mt=0",
20068+ "--sb-size=64",
20069+ "--enable-restoration=0",
20070+ "--enable-palette=0",
20071+ "--deltaq-mode=0",
20072+ "--enable-intrabc=0",
20073+ // Per-arm overrides go LAST (aomenc keeps the last
20074+ // occurrence of a repeated --enable-* flag).
20075+ "--enable-rect-partitions=1",
20076+ "--enable-ab-partitions=0",
20077+ "--enable-1to4-partitions=0",
20078+ // 32, not the charter's 8: at 8 the sub-16 AB and
20079+ // split-transform strip arms (still refused by name here)
20080+ // fire before the 32-level edge is reached and EVERY
20081+ // attempt refuses (measured). At 32 the edge block cannot
20082+ // split, so aomenc is forced onto the gathered edge bit's
20083+ // HORZ/VERT -- exactly the arm this round guards.
20084+ "--min-partition-size=32",
20085+ "--tune-content=film",
20086+ "--max-partition-size=64",
20087+ ];
20088+ if ten_bit {
20089+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
20090+ }
20091+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
20092+ let mut child = Command::new(aomenc_path())
20093+ .args(&args)
20094+ .stdin(Stdio::piped())
20095+ .stdout(Stdio::piped())
20096+ .stderr(Stdio::piped())
20097+ .spawn()
20098+ .expect("aomenc failed to start");
20099+ child
20100+ .stdin
20101+ .take()
20102+ .expect("aomenc stdin")
20103+ .write_all(&y4m.stdout)
20104+ .expect("writing y4m to aomenc");
20105+ let out = child.wait_with_output().expect("aomenc failed to run");
20106+ assert!(
20107+ out.status.success(),
20108+ "{NAME}: aomenc refused the fixture: {}",
20109+ String::from_utf8_lossy(&out.stderr)
20110+ );
20111+ let stream = out.stdout;
20112+ if ten_bit {
20113+ assert_eq!(
20114+ parsed_bit_depth(&stream),
20115+ 10,
20116+ "{NAME}: aomenc did not write a 10-bit sequence header"
20117+ );
20118+ }
20119+ let tag = format!("{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit}");
20120+ let before = crate::decode::edge32_hits();
20121+ // lane-golomb r8: name the attempt BEFORE decoding it -- a
20122+ // desync surfaces as a panic deep in mc.rs with no arm in the
20123+ // message, and r8 spent a run bisecting arms by hand.
20124+ if std::env::var_os("EC_GATE_VERBOSE").is_some() {
20125+ eprintln!("{NAME}: attempting {tag}");
20126+ }
20127+ let decoded = match decode_stream(&stream) {
20128+ Ok(frames) => frames,
20129+ Err(e) => {
20130+ let msg = e.to_string();
20131+ assert!(
20132+ msg.contains("unsupported"),
20133+ "{NAME} failed outright, not a named refusal ({tag}): {msg}"
20134+ );
20135+ refusals.push(format!("{tag}: {msg}"));
20136+ continue;
20137+ }
20138+ };
20139+ let after = crate::decode::edge32_hits();
20140+ let delta: Vec<usize> =
20141+ (0..8).map(|i| after[i] - before[i]).collect();
20142+ let reference = if ten_bit {
20143+ ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len())
20144+ } else {
20145+ ffmpeg_decode_sequence(&stream, width, height, decoded.len())
20146+ };
20147+ assert_eq!(
20148+ decoded.len(),
20149+ reference.len(),
20150+ "{NAME}: {tag}: shown-frame count vs ffmpeg"
20151+ );
20152+ for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() {
20153+ for (plane, a, b, w) in [
20154+ ("Y", &ours.y, &theirs.y, width),
20155+ ("U", &ours.u, &theirs.u, width / 2),
20156+ ("V", &ours.v, &theirs.v, width / 2),
20157+ ] {
20158+ if let Some(d) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
20159+ let n = a.iter().zip(b.iter()).filter(|(x, y)| x != y).count();
20160+ if std::env::var_os("EC_EDGE32_ROWS").is_some() {
20161+ let mut per_row: std::collections::BTreeMap<usize, usize> =
20162+ Default::default();
20163+ for (k, (x, y)) in a.iter().zip(b.iter()).enumerate() {
20164+ if x != y {
20165+ *per_row.entry(k / w).or_default() += 1;
20166+ }
20167+ }
20168+ eprintln!("{NAME}: {tag} plane {plane} diffs per row: {per_row:?}");
20169+ }
20170+ panic!(
20171+ "{NAME}: {tag} frame {i} plane {plane}: {n} pixels differ, first \
20172+ at row {} col {} (ours {} vs ffmpeg {}) [edge32={delta:?}]",
20173+ d / w,
20174+ d % w,
20175+ a[d],
20176+ b[d]
20177+ );
20178+ }
20179+ }
20180+ }
20181+ compared += 1;
20182+ for i in 0..8 {
20183+ totals[i] += delta[i];
20184+ }
20185+ }
20186+ }
20187+ assert!(
20188+ compared > 0,
20189+ "{NAME}: every attempt hit a named refusal:\n{}",
20190+ refusals.join("\n")
20191+ );
20192+ assert!(
20193+ totals[0] + totals[1] + totals[4] + totals[5] > 0,
20194+ "{NAME}: no frame-edge partition bit was read at all over \
20195+ {compared} compared attempts -- the gate proved nothing"
20196+ );
20197+ // lane-golomb r3: the flat-band arm's ASSERT moved one level up. Until
20198+ // r3 the last superblock row was reached through a 32-level edge bit
20199+ // only because our own out-of-frame transform units had desynced the
20200+ // stream; with that fixed, real aomenc answers a bottom-edge
20201+ // superblock with the 64-level `PARTITION_HORZ` (and a right-edge one
20202+ // with `PARTITION_VERT`) and the 32-level slots stay 0 on this
20203+ // content. Slots 6/7 are the strips actually decoded at the edge.
20204+ assert!(
20205+ !flat_band || totals[6] > 0,
20206+ "{NAME}: no 64x32 bottom-edge HORZ strip was decoded \
20207+ (edge32={totals:?}, {compared} compared attempts)"
20208+ );
20209+ assert!(
20210+ !flat_band || totals[7] > 0,
20211+ "{NAME}: no 32x64 right-edge VERT strip was decoded \
20212+ (edge32={totals:?}, {compared} compared attempts)"
20213+ );
20214+ eprintln!(
20215+ "{NAME}: {compared} pixel-exact attempts, 32-level edge bits \
20216+ [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, 64-level edge bits \
20217+ [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, {} named refusals",
20218+ totals[0],
20219+ totals[1],
20220+ totals[2],
20221+ totals[3],
20222+ totals[4],
20223+ totals[5],
20224+ totals[6],
20225+ totals[7],
20226+ refusals.len()
20227+ );
20228+ for r in &refusals {
20229+ eprintln!("{NAME} refusal: {r}");
20230+ }
20231+ }
20232+
19873 /// lane-sqchroma r1 gate: a plain SQUARE-partition intra key frame with20233 /// lane-sqchroma r1 gate: a plain SQUARE-partition intra key frame with
19874 /// REAL chroma (no `hue=s=0` guard) and aomenc's tx-size search left at20234 /// REAL chroma (no `hue=s=0` guard) and aomenc's tx-size search left at
19875 /// its own DEFAULT (on) -- the combination the user's films hit20235 /// its own DEFAULT (on) -- the combination the user's films hit
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).