forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' into lane-sbrect10

Browse files at this commit

e122a2d3baa70c3d7b6c10f092060ceb3671b21eAhmet Kaan GümüşParent: a531b22a13d4a2
crates/ec-av1/src/decode.rsmodified+615 -108
@@ -1383,6 +1383,24 @@ pub(crate) fn palette_split_tx_hits() -> usize {
13831383 PALETTE_SPLIT_TX_HITS.with(|c| c.get())
13841384 }
13851385
1386+// lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform
1387+// and which are therefore predicted one transform unit at a time (a skipped
1388+// block codes no coefficients, so nothing else in the stream witnesses this
1389+// path -- only the pixels do).
1390+thread_local! {
1391+ static SKIP_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1392+}
1393+
1394+/// Current value of [`SKIP_SPLIT_TX_HITS`] (blocks, not units).
1395+pub fn skip_split_tx_hits() -> usize {
1396+ SKIP_SPLIT_TX_HITS.with(|c| c.get())
1397+}
1398+
1399+/// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt.
1400+pub fn reset_skip_split_tx_hits() {
1401+ SKIP_SPLIT_TX_HITS.with(|c| c.set(0));
1402+}
1403+
13861404 // lane-intrainter r1: intra blocks inside an INTER frame whose `tx_depth`
13871405 // symbol split their luma transform, bucketed by block side (8, 16, 32, 64) --
13881406 // the gate's proof that the lifted path actually ran, per size.
@@ -1857,6 +1875,22 @@ pub(crate) fn rect_leaf_coeff_hits() -> usize {
18571875 RECT_LEAF_COEFF_HITS.with(|c| c.get())
18581876 }
18591877
1878+// lane-intrarect r1: how many intra-coded HORZ/VERT strips decoded on the
1879+// INTER block path ([`decode_intra_rect_in_inter`]), per shape class --
1880+// [0] the superblock-level 64x32/32x64, [1] 32x16/16x32, [2] 16x8/8x16.
1881+// Every one of them was the named refusal "an intra-coded HORZ/VERT strip
1882+// needs rectangular intra prediction" before this round.
1883+thread_local! {
1884+ static INTRA_RECT_IN_INTER_HITS: std::cell::Cell<[usize; 3]> =
1885+ const { std::cell::Cell::new([0; 3]) };
1886+}
1887+
1888+/// Current value of [`INTRA_RECT_IN_INTER_HITS`] for one shape class
1889+/// (0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16).
1890+pub(crate) fn intra_rect_strip_in_inter_hits(class: usize) -> usize {
1891+ INTRA_RECT_IN_INTER_HITS.with(|c| c.get()[class])
1892+}
1893+
18601894 // lane-rectx r5: how many times a NON-strip `kf_y_mode` reader
18611895 // ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an
18621896 // above/left mode from the mi-exact map that DIFFERS from its coarse 16x16
@@ -1948,6 +1982,33 @@ thread_local! {
19481982 }
19491983
19501984 /// Current value of [`SB_RECT_HITS`].
1985+// lane-hgkf r1: the frame-edge partition bit, one level each. Slot 0 = a
1986+// 64-level gathered edge bit read as HORZ/VERT, 1 = the same bit read as
1987+// SPLIT, 2/3 = the 32-level pair. A gate asserting slot 0 or 2 proves the
1988+// non-SPLIT edge arm actually decoded (before this round the bit was read and
1989+// thrown away, so that arm was unreachable).
1990+thread_local! {
1991+ static EDGE_PART_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
1992+}
1993+
1994+/// Current value of [`EDGE_PART_HITS`].
1995+pub(crate) fn edge_part_hits() -> [usize; 4] {
1996+ EDGE_PART_HITS.with(|c| c.get())
1997+}
1998+
1999+/// Reset [`EDGE_PART_HITS`] (a gate counts one stream at a time).
2000+pub(crate) fn reset_edge_part_hits() {
2001+ EDGE_PART_HITS.with(|c| c.set([0; 4]));
2002+}
2003+
2004+fn bump_edge_part(slot: usize) {
2005+ EDGE_PART_HITS.with(|c| {
2006+ let mut h = c.get();
2007+ h[slot] += 1;
2008+ c.set(h);
2009+ });
2010+}
2011+
19512012 pub(crate) fn sb_rect_hits() -> usize {
19522013 SB_RECT_HITS.with(|c| c.get())
19532014 }
@@ -3311,7 +3372,7 @@ fn read_coeffs_rect(
33113372 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
33123373 if rect_trace {
33133374 eprintln!(
3314- "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} all_zero={} rng={}",
3375+ "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}",
33153376 all_zero as i32,
33163377 dec.debug_state().0
33173378 );
@@ -5678,6 +5739,16 @@ fn decode_rect_split(
56785739 let tu_mi = (mi_r + tu_row * (tx_h / MI), mi_c + tu_col * (tx_w / MI));
56795740 let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h);
56805741 let (col_off, row_off) = (tu_col * tx_w, tu_row * tx_h);
5742+ // lane-hgkf r1 (ported from lane-golomb 791d87a, unmerged):
5743+ // libaom clips `av1_foreach_transformed_block_in_plane` to
5744+ // `max_blocks_wide/high` (`mb_to_right_edge`/`mb_to_bottom_edge`,
5745+ // i.e. `mi_cols * 4` / `mi_rows * 4`): a transform unit whose
5746+ // TOP-LEFT sample falls outside the frame is never coded. We read
5747+ // coefficients for those phantom units and desynced the stream at
5748+ // the very next symbol.
5749+ if tu_px >= y.true_width || tu_py >= y.true_height {
5750+ continue;
5751+ }
56815752 // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a
56825753 // transform unit INSIDE a block, which is a different rule from
56835754 // the standalone-block table [`Reach::of`] applies -- and the
@@ -5727,7 +5798,19 @@ fn decode_rect_split(
57275798 // own (always DC_PRED) mode -- [`read_plane`] applies that
57285799 // for the square arm, so this one must too.
57295800 let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0];
5730- let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI);
5801+ // libaom `get_txb_ctx`: a LUMA transform that covers its whole
5802+ // block (`plane_bsize == txsize_to_bsize[tx_size]`, i.e. the
5803+ // unsplit depth-0 strip) reads txb_skip ctx 0 flat -- the
5804+ // neighbour-magnitude table is for a unit SMALLER than its
5805+ // block. [`decode_block_rect`]'s own unsplit read passes a
5806+ // literal 0 for the same reason; this arm applied the table
5807+ // unconditionally and desynced every depth-0 rect strip that
5808+ // reached it (lane-intrarect r2: ctx 5 where aomdec read 0).
5809+ let tu_skip_ctx = if tx_w == bw && tx_h == bh {
5810+ 0
5811+ } else {
5812+ neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI)
5813+ };
57315814 let mut coding = cdfs.txb(rect_set, fi_tx_row(m.mode, m.filter_intra));
57325815 let (tu_grid, tu_tx_type) = read_coeffs_rect(
57335816 dec,
@@ -5905,6 +5988,211 @@ fn decode_rect_split(
59055988 Ok(())
59065989 }
59075990
5991+/// One intra-coded HORZ/VERT strip on the INTER block path (lane-intrarect
5992+/// r1) -- the shape [`decode_inter_block`]'s intra arm refused by name
5993+/// because it predicts squares only. Every pixel here goes through the rect
5994+/// machinery the key-frame paths already prove: [`decode_rect_split`], which
5995+/// at `depth == 0` is the unsplit strip as a single transform unit and
5996+/// beyond it the per-unit walk of [`depth_to_tx_wh`].
5997+///
5998+/// What is genuinely different from [`decode_block_rect`] is the mode
5999+/// syntax: on an inter frame an intra block reads `y_mode[size_group]` and
6000+/// `uv_mode` (libaom `read_intra_block_mode_info`, decodemv.c:1065), never
6001+/// the key frame's `kf_y_mode` above/left pair. This mirrors the square
6002+/// intra-in-inter arm's own reads at the rect footprint, including its
6003+/// inherited gaps -- no `use_filter_intra` symbol (every inter gate recipe
6004+/// pins `--enable-filter-intra=0`; lane-fiinter owns that read for both the
6005+/// square and this arm) and a nonzero luma angle delta refused by name.
6006+///
6007+/// The strip's own neighbour records (luma per transform unit, chroma, skip
6008+/// grid, deblock grid) are [`decode_rect_split`]'s; the caller adds the
6009+/// inter-side bands and the mi map.
6010+#[allow(clippy::too_many_arguments)]
6011+fn decode_intra_rect_in_inter(
6012+ dec: &mut SymbolDecoder,
6013+ cdfs: &mut Cdfs,
6014+ neighbours: &mut Neighbours,
6015+ at: (usize, usize),
6016+ bw: usize,
6017+ bh: usize,
6018+ skip: bool,
6019+ allow_screen_content_tools: bool,
6020+ y: &mut PlaneBuf,
6021+ u: &mut PlaneBuf,
6022+ v: &mut PlaneBuf,
6023+ base_q_idx: u8,
6024+) -> Result<()> {
6025+ // `at` is in MI units (the inter path's own unit since lane-inter4);
6026+ // `(r, c)` is the enclosing SUB cell the SUB-granular neighbour bands
6027+ // below are still keyed by.
6028+ let (mi_r, mi_c) = at;
6029+ let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI));
6030+ // `size_group_lookup` (libaom common_data.h) and `bsize_to_tx_size_cat`
6031+ // (blockd.h) for the three 2:1 strip shapes: BLOCK_16X8 -> group 1 /
6032+ // cat 1, BLOCK_32X16 -> 2 / 2, BLOCK_64X32 -> 3 / 3 (the rectsplitx
6033+ // finding -- the category is NOT the same for every strip size).
6034+ // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so
6035+ // it is refused by name rather than read from the wrong CDF row.
6036+ let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {
6037+ (8, 16) => (1usize, 1usize),
6038+ (16, 32) => (2, 2),
6039+ (32, 64) => (3, 3),
6040+ _ => {
6041+ return Err(unsupported(
6042+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path",
6043+ ))
6044+ }
6045+ };
6046+ // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is
6047+ // consumed for square blocks only, so a strip in a screen-content frame
6048+ // would skip symbols the encoder wrote.
6049+ if allow_screen_content_tools {
6050+ return Err(unsupported(
6051+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax \
6052+ is consumed for square blocks only)",
6053+ ));
6054+ }
6055+ let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
6056+ if mode >= 13 {
6057+ return Err(unsupported(
6058+ "an intra mode this decoder does not code (round 2)",
6059+ ));
6060+ }
6061+ // lane-angleinter (merged on main for the square intra-in-inter arm):
6062+ // the delta is read off `angle_delta_cdf[mode - V_PRED]` and feeds the
6063+ // directional predictor; this arm refused a nonzero one before the merge.
6064+ let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
6065+ read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED])
6066+ } else {
6067+ 0
6068+ };
6069+ if angle_delta_y != 0 {
6070+ INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1));
6071+ }
6072+ // `is_cfl_allowed` (spec 5.11.5) caps CFL at 32x32, so the
6073+ // superblock-level strip reads the no-CFL alphabet -- the same split
6074+ // [`read_intra_mode_rect`] makes for [`decode_block_rect64`].
6075+ let cfl_allowed = bw.max(bh) <= 32;
6076+ let uv_mode = if cfl_allowed {
6077+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
6078+ } else {
6079+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
6080+ };
6081+ if (9..=12).contains(&uv_mode) {
6082+ SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1));
6083+ }
6084+ let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED {
6085+ Some(read_cfl_alphas(dec, cdfs))
6086+ } else {
6087+ None
6088+ };
6089+ let uv_predict_mode = if uv_mode == UV_CFL_PRED {
6090+ DC_PRED
6091+ } else {
6092+ uv_mode
6093+ };
6094+ let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
6095+ DIRECTIONAL_UV_HITS.with(|h| h.set(h.get() + 1));
6096+ read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
6097+ } else {
6098+ 0
6099+ };
6100+ if angle_delta_uv != 0 {
6101+ UV_ANGLE_DELTA_HITS.with(|h| h.set(h.get() + 1));
6102+ INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|h| h.set(h.get() + 1));
6103+ }
6104+ // lane-fiinter (merged on main for the square intra-in-inter arm):
6105+ // `read_filter_intra_mode_info` is the tail of
6106+ // `read_intra_block_mode_info`, after the palette syntax (refused whole
6107+ // above for this shape), and `av1_filter_intra_allowed_bsize` admits the
6108+ // 2:1 strips with both sides <= 32 -- their own CDF rows
6109+ // ([`filter_intra_size_class_rect`]).
6110+ let mut filter_intra = None;
6111+ if mode == DC_PRED
6112+ && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)
6113+ && let Some(class) = filter_intra_size_class_rect(bw, bh)
6114+ && dec.symbol(&mut cdfs.filter_intra[class]) != 0
6115+ {
6116+ FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1));
6117+ INTRA_IN_INTER_FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1));
6118+ filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode));
6119+ }
6120+ // The intra-edge filter type is the NEIGHBOUR's mode (libaom
6121+ // `get_filt_type`), luma's off the luma neighbours and chroma's off the
6122+ // chroma ones -- [`decode_block_rect`]'s own pair.
6123+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
6124+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
6125+ if smooth_neighbor {
6126+ SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1));
6127+ }
6128+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
6129+ let depth = if TX_SELECT_INTER.with(std::cell::Cell::get) {
6130+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
6131+ match tx_cat {
6132+ 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]),
6133+ 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]),
6134+ _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]),
6135+ }
6136+ } else {
6137+ 0
6138+ };
6139+ if depth != 0 {
6140+ TX_DEPTH_HITS.with(|h| h.set(h.get() + 1));
6141+ // merge b51719f+lane-intrarect (class merge-cross-product-defect):
6142+ // main's 10-bit `split_transform_intra_block` gate reaches this arm
6143+ // with a nonzero tx depth, and the split rect-TU walk mis-decodes it
6144+ // (2340 luma samples off at seed 51; refusing here restores that gate
6145+ // while the depth-0 strip the lane proved keeps decoding). The lane's
6146+ // own gate never exercised a split strip.
6147+ return Err(unsupported(
6148+ "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame",
6149+ ));
6150+ }
6151+ let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
6152+ let modes = RectStripModes {
6153+ skip,
6154+ mode,
6155+ angle_delta_y,
6156+ uv_predict_mode,
6157+ angle_delta_uv,
6158+ alpha,
6159+ filter_intra,
6160+ smooth_neighbor,
6161+ smooth_neighbor_uv,
6162+ // screen-content frames are refused whole above, so this strip can
6163+ // carry no palette.
6164+ palette_y: None,
6165+ palette_uv: None,
6166+ };
6167+ decode_rect_split(
6168+ dec,
6169+ cdfs,
6170+ neighbours,
6171+ (mi_r, mi_c),
6172+ bw,
6173+ bh,
6174+ tx_w,
6175+ tx_h,
6176+ &modes,
6177+ y,
6178+ u,
6179+ v,
6180+ base_q_idx,
6181+ REDUCED_TX_SET_INTER.with(std::cell::Cell::get),
6182+ )?;
6183+ let class = match bw.max(bh) {
6184+ 64 => 0,
6185+ 32 => 1,
6186+ _ => 2,
6187+ };
6188+ INTRA_RECT_IN_INTER_HITS.with(|h| {
6189+ let mut v = h.get();
6190+ v[class] += 1;
6191+ h.set(v);
6192+ });
6193+ Ok(())
6194+}
6195+
59086196 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip
59096197 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's
59106198 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/
@@ -8342,6 +8630,26 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
83428630 /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
83438631 /// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written
83448632 /// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`.
8633+/// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of
8634+/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) --
8635+/// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE).
8636+fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) {
8637+ use std::io::Write;
8638+ if let Ok(path) = std::env::var(var)
8639+ && let Ok(mut f) = std::fs::File::create(format!("{path}.f0"))
8640+ {
8641+ for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] {
8642+ for row in 0..h {
8643+ let mut bytes = Vec::with_capacity(w * 2);
8644+ for &s in &p.data[row * p.width..][..w] {
8645+ bytes.extend_from_slice(&s.to_le_bytes());
8646+ }
8647+ let _ = f.write_all(&bytes);
8648+ }
8649+ }
8650+ }
8651+}
8652+
83458653 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
83468654 use std::io::Write;
83478655 if let Ok(path) = std::env::var(var)
@@ -8487,6 +8795,7 @@ impl PlaneBuf {
84878795 /// via [`Self::edges_rect`] and [`crate::intra::predict`]'s own
84888796 /// already-rect-capable `(bw, bh)` pair.
84898797 #[allow(clippy::too_many_arguments)]
8798+ #[track_caller]
84908799 fn reconstruct_rect(
84918800 &mut self,
84928801 x: usize,
@@ -8545,6 +8854,16 @@ impl PlaneBuf {
85458854 }
85468855 prediction
85478856 };
8857+ // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
8858+ // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
8859+ if std::env::var_os("EC_PRED").is_some() {
8860+ let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
8861+ let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();
8862+ let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();
8863+ eprintln!(
8864+ "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller()
8865+ );
8866+ }
85488867 for row in 0..bh {
85498868 for col in 0..bw {
85508869 let idx = row * bw + col;
@@ -8564,6 +8883,7 @@ impl PlaneBuf {
85648883 /// nudges the prediction by [`cfl_scaled`]'s per-sample amount before the
85658884 /// residual is added — `av1_cfl_predict_block`'s own clip-then-add-residual
85668885 /// order (cfl.c).
8886+ #[track_caller]
85678887 fn reconstruct(
85688888 &mut self,
85698889 x: usize,
@@ -8627,6 +8947,16 @@ impl PlaneBuf {
86278947 }
86288948 prediction
86298949 };
8950+ // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
8951+ // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
8952+ if std::env::var_os("EC_PRED").is_some() {
8953+ let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
8954+ let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
8955+ let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
8956+ eprintln!(
8957+ "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller()
8958+ );
8959+ }
86308960 for row in 0..side {
86318961 for col in 0..side {
86328962 let idx = row * side + col;
@@ -8958,18 +9288,69 @@ fn decode_block(
89589288 if skip {
89599289 // A skipped block codes no residual syntax at all (spec 5.11.34):
89609290 // straight prediction, on every plane.
8961- y.reconstruct(
8962- px,
8963- py,
8964- side,
8965- mode,
8966- angle_delta_y,
8967- reach,
8968- &vec![0i32; side * side],
8969- None,
8970- filter_intra,
8971- smooth_neighbor,
8972- );
9291+ //
9292+ // lane-hgkf r2: an intra block's `tx_depth` is read whether or not it
9293+ // is skipped (only an INTER skip forces the largest transform), and
9294+ // spec 7.11.2 / libaom `predict_and_reconstruct_intra_block` predicts
9295+ // ONE TRANSFORM UNIT AT A TIME -- each unit's edges are the units
9296+ // already written left/above of it inside this same block. Predicting
9297+ // the whole `side`x`side` at once gives a different (uniformly off by
9298+ // ~1) answer, which is exactly the residue this lane was chasing.
9299+ // The palette/intrabc override path keeps the single-call shape (its
9300+ // per-TU windowing is the non-skip loop's own `palette_y_buf` slice,
9301+ // untested for skip and unreachable in these streams).
9302+ let split_tx_skip =
9303+ tx_select && logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none();
9304+ if split_tx_skip {
9305+ SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
9306+ let n_axis = side / logical_tx;
9307+ for tu_row in 0..n_axis {
9308+ for tu_col in 0..n_axis {
9309+ let tu_px = px + tu_col * logical_tx;
9310+ let tu_py = py + tu_row * logical_tx;
9311+ if tu_px >= y.true_width || tu_py >= y.true_height {
9312+ continue;
9313+ }
9314+ let tu_reach = tu_reach(
9315+ side,
9316+ side,
9317+ tu_col * logical_tx,
9318+ tu_row * logical_tx,
9319+ logical_tx,
9320+ reach,
9321+ px,
9322+ py,
9323+ y.width,
9324+ y.height,
9325+ );
9326+ y.reconstruct(
9327+ tu_px,
9328+ tu_py,
9329+ logical_tx,
9330+ mode,
9331+ angle_delta_y,
9332+ tu_reach,
9333+ &vec![0i32; logical_tx * logical_tx],
9334+ None,
9335+ filter_intra,
9336+ smooth_neighbor,
9337+ );
9338+ }
9339+ }
9340+ } else {
9341+ y.reconstruct(
9342+ px,
9343+ py,
9344+ side,
9345+ mode,
9346+ angle_delta_y,
9347+ reach,
9348+ &vec![0i32; side * side],
9349+ None,
9350+ filter_intra,
9351+ smooth_neighbor,
9352+ );
9353+ }
89739354 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
89749355 if let Some((ub, _)) = &palette_uv_bufs {
89759356 set_palette_pred(ub.clone());
@@ -9106,6 +9487,12 @@ fn decode_block(
91069487 );
91079488 let tu_px = px + tu_col * logical_tx;
91089489 let tu_py = py + tu_row * logical_tx;
9490+ // Same libaom clip as `decode_rect_split`'s loop above; a
9491+ // square block only hangs off the frame when the frame's mi
9492+ // dimensions are odd at the block's own level.
9493+ if tu_px >= y.true_width || tu_py >= y.true_height {
9494+ continue;
9495+ }
91099496 let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0];
91109497 // A transform unit inside a block is NOT a block at that
91119498 // position (lane-palette2 r12): `Reach::of` granted the
@@ -9381,18 +9768,59 @@ fn decode_leaf8(
93819768 let (cpx, cpy) = (px / 2, py / 2);
93829769 let (luma_grid, u_grid, v_grid);
93839770 if skip {
9384- y.reconstruct(
9385- px,
9386- py,
9387- 8,
9388- mode,
9389- angle_delta_y,
9390- reach,
9391- &vec![0i32; 64],
9392- None,
9393- filter_intra,
9394- smooth_neighbor,
9395- );
9771+ // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an
9772+ // 8x8 leaf whose `tx_depth` resolved to TX_4X4 predicts FOUR 4x4
9773+ // transform units, each off the units already written left/above of
9774+ // it inside this same leaf -- an intra block's transform size is read
9775+ // whether or not it is skipped, and spec 7.11.2 predicts per unit.
9776+ if resolved == 4 {
9777+ SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
9778+ for tu_row in 0..2 {
9779+ for tu_col in 0..2 {
9780+ let (tu_px, tu_py) = (px + tu_col * 4, py + tu_row * 4);
9781+ if tu_px >= y.true_width || tu_py >= y.true_height {
9782+ continue;
9783+ }
9784+ let tu_reach = tu_reach(
9785+ 8,
9786+ 8,
9787+ tu_col * 4,
9788+ tu_row * 4,
9789+ 4,
9790+ reach,
9791+ px,
9792+ py,
9793+ y.width,
9794+ y.height,
9795+ );
9796+ y.reconstruct(
9797+ tu_px,
9798+ tu_py,
9799+ 4,
9800+ mode,
9801+ angle_delta_y,
9802+ tu_reach,
9803+ &vec![0i32; 16],
9804+ None,
9805+ filter_intra,
9806+ smooth_neighbor,
9807+ );
9808+ }
9809+ }
9810+ } else {
9811+ y.reconstruct(
9812+ px,
9813+ py,
9814+ 8,
9815+ mode,
9816+ angle_delta_y,
9817+ reach,
9818+ &vec![0i32; 64],
9819+ None,
9820+ filter_intra,
9821+ smooth_neighbor,
9822+ );
9823+ }
93969824 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
93979825 u.reconstruct(
93989826 cpx,
@@ -12375,28 +12803,23 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1237512803 }
1237612804 p
1237712805 } else {
12378- // lane-golomb r1 (class `parsed-then-discarded`): the gathered
12379- // bit is the answer, not a formality -- libaom's
12380- // `ec_read_partition_impl` returns `PARTITION_HORZ` (resp.
12381- // `PARTITION_VERT`) when it reads 0, and only `PARTITION_SPLIT`
12382- // when it reads 1. Forcing SPLIT here desynced the last
12383- // superblock row of every frame whose height is not a multiple
12384- // of 64 -- the ReelB head (3840x1608) diverges at
12385- // mi_row=400 mi_col=0, the first block of that row.
12806+ // lane-hgkf r1 (class `parsed-then-discarded`, same finding as
12807+ // the unmerged lane-golomb r1): the gathered bit IS the
12808+ // partition -- libaom `ec_read_partition_impl` returns
12809+ // PARTITION_HORZ (resp. VERT) for 0 and only SPLIT for 1.
12810+ // Forcing SPLIT desynced the last superblock row of every
12811+ // frame whose height is not a multiple of 64: the ReelB key frames (3840x1608) diverge at mi_row=400 mi_col=0,
12812+ // the first block of that row.
1238612813 match (has_cols, has_rows) {
1238712814 (true, false) => {
12388- if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)) == 1 {
12389- PARTITION_SPLIT
12390- } else {
12391- PARTITION_HORZ
12392- }
12815+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));
12816+ bump_edge_part(b.min(1) as usize);
12817+ if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
1239312818 }
1239412819 (false, true) => {
12395- if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)) == 1 {
12396- PARTITION_SPLIT
12397- } else {
12398- PARTITION_VERT
12399- }
12820+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));
12821+ bump_edge_part(b.min(1) as usize);
12822+ if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
1240012823 }
1240112824 _ => PARTITION_SPLIT,
1240212825 }
@@ -12454,26 +12877,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1245412877 }
1245512878 p
1245612879 } else {
12880+ // lane-hgkf r1: the 32-level frame-edge bit is the
12881+ // partition too (same libaom reader as the
12882+ // superblock level above).
1245712883 match (has_cols32, has_rows32) {
1245812884 (true, false) => {
12459- // lane-golomb r1 (class `parsed-then-discarded`): the gathered
12460- // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
12461- // (libaom `ec_read_partition_impl`).
12462- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 {
12463- PARTITION_SPLIT
12464- } else {
12465- PARTITION_HORZ
12466- }
12885+ let b = dec.symbol_fixed(&gather(
12886+ &cdfs.partition_w32[ctx32],
12887+ VERT_ALIKE,
12888+ ));
12889+ bump_edge_part(2 + b.min(1) as usize);
12890+ if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
1246712891 }
1246812892 (false, true) => {
12469- // lane-golomb r1 (class `parsed-then-discarded`): the gathered
12470- // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
12471- // (libaom `ec_read_partition_impl`).
12472- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 {
12473- PARTITION_SPLIT
12474- } else {
12475- PARTITION_VERT
12476- }
12893+ let b = dec.symbol_fixed(&gather(
12894+ &cdfs.partition_w32[ctx32],
12895+ HORZ_ALIKE,
12896+ ));
12897+ bump_edge_part(2 + b.min(1) as usize);
12898+ if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
1247712899 }
1247812900 _ => PARTITION_SPLIT,
1247912901 }
@@ -12957,6 +13379,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1295713379 HORZ_ALIKE,
1295813380 ))
1295913381 };
13382+ // lane-hgkf r1: slots 2/3 of
13383+ // [`EDGE_PART_HITS`], the gate's proof the
13384+ // non-SPLIT edge arm actually decoded.
13385+ bump_edge_part(if edge_split == 1 { 3 } else { 2 });
1296013386 if edge_split == 0 {
1296113387 // lane-oddh r1: the strip IS decodable
1296213388 // -- libaom's `decode_partition` codes
@@ -13123,22 +13549,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1312313549 tx_select,
1312413550 reduced_tx_set,
1312513551 )?;
13126- decode_block_rect(
13127- &mut dec,
13128- &mut cdfs,
13129- &mut neighbours,
13130- (at32.0 + 1, at32.1),
13131- 32,
13132- 16,
13133- &mut y,
13134- &mut u,
13135- &mut v,
13136- enable_filter_intra,
13137- allow_screen_content_tools,
13138- base_q_idx,
13139- tx_select,
13140- reduced_tx_set,
13141- )?;
13552+ // lane-hgkf r1: at the frame edge only the first half of the strip is
13553+ // coded (libaom `decode_partition` guards the second half with the same
13554+ // test that made this partition non-square).
13555+ if has_rows32 {
13556+ decode_block_rect(
13557+ &mut dec,
13558+ &mut cdfs,
13559+ &mut neighbours,
13560+ (at32.0 + 1, at32.1),
13561+ 32,
13562+ 16,
13563+ &mut y,
13564+ &mut u,
13565+ &mut v,
13566+ enable_filter_intra,
13567+ allow_screen_content_tools,
13568+ base_q_idx,
13569+ tx_select,
13570+ reduced_tx_set,
13571+ )?;
13572+ }
1314213573 }
1314313574 PARTITION_VERT => {
1314413575 // lane-intradisp r1: mirror of PARTITION_HORZ
@@ -13159,22 +13590,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1315913590 tx_select,
1316013591 reduced_tx_set,
1316113592 )?;
13162- decode_block_rect(
13163- &mut dec,
13164- &mut cdfs,
13165- &mut neighbours,
13166- (at32.0, at32.1 + 1),
13167- 16,
13168- 32,
13169- &mut y,
13170- &mut u,
13171- &mut v,
13172- enable_filter_intra,
13173- allow_screen_content_tools,
13174- base_q_idx,
13175- tx_select,
13176- reduced_tx_set,
13177- )?;
13593+ // lane-hgkf r1: at the frame edge only the first half of the strip is
13594+ // coded (libaom `decode_partition` guards the second half with the same
13595+ // test that made this partition non-square).
13596+ if has_cols32 {
13597+ decode_block_rect(
13598+ &mut dec,
13599+ &mut cdfs,
13600+ &mut neighbours,
13601+ (at32.0, at32.1 + 1),
13602+ 16,
13603+ 32,
13604+ &mut y,
13605+ &mut u,
13606+ &mut v,
13607+ enable_filter_intra,
13608+ allow_screen_content_tools,
13609+ base_q_idx,
13610+ tx_select,
13611+ reduced_tx_set,
13612+ )?;
13613+ }
1317813614 }
1317913615 PARTITION_HORZ_A => {
1318013616 // lane-part32 r1: two 16x16 squares on top +
@@ -13759,6 +14195,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1375914195 // that isolate whether a decode-order frame's mismatch already exists
1376014196 // in reconstruction (this dump) vs is introduced by the loop filter
1376114197 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
14198+ dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1376214199 if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
1376314200 use std::io::Write;
1376414201 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -13802,8 +14239,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1380214239 // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
1380314240 // dump above these bisect WHICH filter stage introduced a mismatch.
1380414241 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
14242+ dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1380514243 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
1380614244 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
14245+ dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1380714246 apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);
1380814247
1380914248 let (fw, fh) = (frame_width as usize, frame_height as usize);
@@ -15461,18 +15900,6 @@ fn decode_inter_block(
1546115900 let whole_sb = side == 64 && write_w == 64 && write_h == 64;
1546215901 maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip);
1546315902 maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip);
15464- // lane-warp r5: see `reject_residual` -- a square-block decode of a
15465- // HORZ_B strip is symbol-exact only for `skip` (no residual, no
15466- // motion_mode/warp symbol), so gate here before any further read.
15467- if reject_residual && !skip && !rect_inter_residual_supported(write_w, write_h) {
15468- if std::env::var_os("EC_AV1_RECT_DUMP").is_some() {
15469- eprintln!("EC_RECT_REFUSE mi_row={rmi} mi_col={cmi} w={write_w} h={write_h} side={side}");
15470- }
15471- return Err(unsupported(
15472- "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
15473- ));
15474- }
15475-
1547615903 let (has_above, has_left) = (
1547715904 rmi > neighbours.tile_row0_mi,
1547815905 cmi > neighbours.tile_col0_mi,
@@ -15488,6 +15915,29 @@ fn decode_inter_block(
1548815915 dec.debug_state().0
1548915916 );
1549015917 }
15918+ // lane-warp r5: see `reject_residual` -- a square-block decode of a
15919+ // HORZ_B strip is symbol-exact only for `skip` (no residual, no
15920+ // motion_mode/warp symbol). lane-intrarect r1 MOVED this gate from just
15921+ // after the `skip` read to here, past `is_inter` (class
15922+ // [[refusal-short-circuits-its-own-code]]: at the old place it refused
15923+ // 24/24 attempts of this lane's own gate before the intra arm below
15924+ // could run). An INTRA strip with its true `write_w`x`write_h` footprint
15925+ // now codes its residual rectangularly ([`decode_intra_rect_in_inter`]);
15926+ // an INTER one, and a strip decoded with square dimensions anyway, still
15927+ // cannot.
15928+ // merge b51719f+lane-intrarect: main's `rect_inter_residual_supported`
15929+ // term stays -- lane-inter4's 16x8/8x16 inter leaves DO code a
15930+ // rectangular residual, and the lane's condition (written before that
15931+ // landed) refused every one of them.
15932+ if reject_residual
15933+ && !skip
15934+ && !rect_inter_residual_supported(write_w, write_h)
15935+ && (is_inter || (write_w == side && write_h == side))
15936+ {
15937+ return Err(unsupported(
15938+ "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
15939+ ));
15940+ }
1549115941 if std::env::var_os("EC_AV1_TELL").is_some() {
1549215942 eprintln!(
1549315943 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
@@ -17499,10 +17949,64 @@ fn decode_inter_block(
1749917949 // already-square-predicted buffer). Named refusal instead of a
1750017950 // silently wrong square-shaped intra prediction.
1750117951 if write_w != side || write_h != side {
17502- return Err(unsupported(
17503- "an intra-coded HORZ/VERT strip needs rectangular intra prediction \
17504- this decoder does not code yet",
17505- ));
17952+ // lane-intrarect r1: the strip decodes through its own rect
17953+ // machinery ([`decode_intra_rect_in_inter`] -> the key-frame
17954+ // paths' [`decode_rect_split`]) instead of refusing. That call
17955+ // already writes everything the shared tail below would for a
17956+ // square block EXCEPT the inter-side bands and the mi map, so
17957+ // this arm returns rather than falling through (a second
17958+ // `record_rect`/`fill_lf_grid_rect` at block granularity would
17959+ // overwrite the per-transform-unit records it just made).
17960+ decode_intra_rect_in_inter(
17961+ dec,
17962+ cdfs,
17963+ neighbours,
17964+ at,
17965+ write_w,
17966+ write_h,
17967+ skip,
17968+ allow_screen_content_tools,
17969+ y,
17970+ u,
17971+ v,
17972+ base_q_idx,
17973+ )?;
17974+ // merge b51719f+lane-intrarect: `at` is in MI units on this path
17975+ // (lane-inter4), so the strip's mi origin is `at` itself -- the
17976+ // lane's `r * SUB_MI` re-derivation would snap a sub-SUB strip to
17977+ // its enclosing 16-px cell.
17978+ let (mi_r0, mi_c0) = (rmi, cmi);
17979+ for dr in 0..write_h / MI {
17980+ for dc in 0..write_w / MI {
17981+ grid.set(
17982+ mi_r0 + dr,
17983+ mi_c0 + dc,
17984+ MiInfo {
17985+ is_inter: false,
17986+ ref_frame: -1,
17987+ ref_frame1: None,
17988+ mv1: None,
17989+ mv: (0, 0),
17990+ is_new_mv: false,
17991+ size: write_w / MI,
17992+ size_h: write_h / MI,
17993+ is_global_mv0: false,
17994+ is_global_mv1: false,
17995+ },
17996+ );
17997+ }
17998+ }
17999+ neighbours.record_inter_rect_mi(
18000+ at,
18001+ write_w / MI,
18002+ write_h / MI,
18003+ skip,
18004+ false,
18005+ 0,
18006+ [3, 3],
18007+ skip_mode,
18008+ );
18009+ return Ok(());
1750618010 }
1750718011 let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]);
1750818012 if mode >= 13 {
@@ -21477,6 +21981,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2147721981 // that isolate whether a decode-order frame's mismatch already exists
2147821982 // in reconstruction (this dump) vs is introduced by the loop filter
2147921983 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
21984+ dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2148021985 if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
2148121986 use std::io::Write;
2148221987 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -21503,8 +22008,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2150322008 // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
2150422009 // dump above these bisect WHICH filter stage introduced a mismatch.
2150522010 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
22011+ dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2150622012 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
2150722013 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
22014+ dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2150822015 apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);
2150922016
2151022017 let motion_field = build_motion_field(
crates/ec-av1/src/refusal_inventory.rsmodified+9 -1
@@ -68,7 +68,15 @@ const REFUSALS: &[&str] = &[
6868 "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)",
6969 "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)",
7070 "an intra mode this decoder does not code (round 2)",
71- "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
71+ // lane-intrarect r1 lifted the whole-shape refusal that stood here (the
72+ // inter path's intra arm now routes 2:1 strips through `decode_rect_split`);
73+ // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the
74+ // size-group/category diagonal the 2:1 shapes share.
75+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path",
76+ "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame",
77+ // The same arm's screen-content gate: palette/intrabc syntax is consumed
78+ // for square blocks only, so a strip in such a frame would skip symbols.
79+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
7280 "warp prediction with a scaled reference (superres, unimplemented)",
7381 "an 8x8 partition leaf under a scaled reference (superres, unimplemented)",
7482 "a motion_mode symbol for a block shape with no CDF row here",
crates/ec-av1/src/stream.rsmodified+492 -0
@@ -4251,6 +4251,331 @@ mod tests {
42514251 tx_select_inter_gate(10);
42524252 }
42534253
4254+ /// lane-intrarect r1's decisive gate: a real aomenc INTER sequence whose
4255+ /// hard mid-GOP content cut makes aomenc code INTRA blocks inside inter
4256+ /// frames, with rect partitions ON so those intra blocks land on
4257+ /// HORZ/VERT strip shapes. Every such block was the named refusal "an
4258+ /// intra-coded HORZ/VERT strip needs rectangular intra prediction this
4259+ /// decoder does not code yet" until this round; they now decode through
4260+ /// the same `decode_rect_split` machinery the key-frame rect paths use.
4261+ ///
4262+ /// Hard-asserts per-shape counters (`intra_rect_strip_in_inter_hits`:
4263+ /// 0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16) summed over the
4264+ /// attempts that were actually pixel-compared -- at least TWO of the
4265+ /// three shape classes must fire, so a green run cannot come from one
4266+ /// lucky size. A decode that succeeds is ALWAYS pixel-compared (class
4267+ /// [[gate-skips-on-its-own-failure]]); exhausting every attempt without
4268+ /// two shapes is a FAILURE, never a SKIP.
4269+ #[test]
4270+ fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact() {
4271+ intra_rect_in_inter_gate(8);
4272+ }
4273+
4274+ /// The 10-bit arm (both of the user's films are `yuv420p10le`).
4275+ #[test]
4276+ fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact_10bit() {
4277+ intra_rect_in_inter_gate(10);
4278+ }
4279+
4280+ fn intra_rect_in_inter_gate(bit_depth: u32) {
4281+ const NAME: &str = "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact";
4282+ if !have_ffmpeg() {
4283+ eprintln!("SKIP {NAME}: no ffmpeg");
4284+ return;
4285+ }
4286+ if !have_aomenc() {
4287+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4288+ return;
4289+ }
4290+ let (width, height, frame_count) = (96usize, 96usize, 8usize);
4291+ let mut refusals: Vec<String> = Vec::new();
4292+ let mut uncounted_exact = 0u32;
4293+ let mut compared = 0u32;
4294+ let mut shapes = [0usize; 3];
4295+ for attempt in 0..45u32 {
4296+ let seed = 42 + attempt;
4297+ // mandelbrot's fractal detail plus a HARD cut at frame 4: half
4298+ // the picture becomes a flat white box, which no motion vector
4299+ // can predict, so aomenc's RD codes those blocks INTRA inside an
4300+ // inter frame. The box's vertical edge at x=48 is what makes the
4301+ // partition search reach for HORZ/VERT strips there.
4302+ // A FAST ZOOM: `end_scale`/`end_pts` make mandelbrot rush
4303+ // through its own zoom, so consecutive frames share almost no
4304+ // content and aomenc's RD codes blocks INTRA inside INTER frames
4305+ // (`--kf-min-dist=1000` forbids a new key frame). That is the
4306+ // only way a real encoder reaches this decoder's intra-in-inter
4307+ // arm; a slowly-evolving source codes every rect strip inter.
4308+ let source = format!(
4309+ "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25",
4310+ 5.0 - f64::from(attempt) * 0.06
4311+ );
4312+ let y4m = Command::new("ffmpeg")
4313+ .args([
4314+ "-v",
4315+ "error",
4316+ "-f",
4317+ "lavfi",
4318+ "-i",
4319+ &source,
4320+ "-vf",
4321+ "hue=s=0",
4322+ "-pix_fmt",
4323+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
4324+ "-strict",
4325+ "-1",
4326+ "-t",
4327+ "0.32",
4328+ "-f",
4329+ "yuv4mpegpipe",
4330+ "-strict",
4331+ "-1",
4332+ "-",
4333+ ])
4334+ .stdin(Stdio::null())
4335+ .stdout(Stdio::piped())
4336+ .stderr(Stdio::piped())
4337+ .output()
4338+ .expect("ffmpeg failed to run");
4339+ assert!(
4340+ y4m.status.success(),
4341+ "ffmpeg fixture: {}",
4342+ String::from_utf8_lossy(&y4m.stderr)
4343+ );
4344+ let depth_args: &[&str] = if bit_depth == 10 {
4345+ &["-b", "10", "--input-bit-depth=10"]
4346+ } else {
4347+ &[]
4348+ };
4349+ // MEASURED (r1): the speed preset gates the feature (class
4350+ // [[gate-preset-gates-the-feature]]) -- at `--cpu-used=4` this
4351+ // content produces no rect partition at all, at `--cpu-used=0`
4352+ // aomenc emits AB partitions the tile path refuses (it ignores
4353+ // `--enable-ab-partitions=0`, ledger). So the attempt sweep walks
4354+ // the preset as well as the seed.
4355+ let cpu = format!("--cpu-used={}", attempt % 5);
4356+ // The quantiser drives how finely the RD partitions: the sweep
4357+ // walks it too, so "no rect strip fired" cannot be an artefact of
4358+ // one cq.
4359+ let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]);
4360+ let mut child = Command::new(aomenc_path())
4361+ .args(depth_args)
4362+ .arg(&cpu)
4363+ .arg(&cq)
4364+ .args([
4365+ // class [[aomenc-first-flag-wins]]: every flag is spelled
4366+ // exactly ONCE in this recipe, so there is no override to
4367+ // order. These four are what this gate is about.
4368+ "--enable-rect-partitions=1",
4369+ // MEASURED (r1): the charter's `--min-partition-size=8`
4370+ // makes 24/24 attempts stop at a sub-16 AB-partition
4371+ // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16",
4372+ // "a coded (non-skip) HORZ_B/VERT_B rect strip below
4373+ // 16x16") before any intra rect strip is reached -- those
4374+ // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape
4375+ // reachable (a 16x16 block's own HORZ/VERT children).
4376+ "--min-partition-size=16",
4377+ "--max-partition-size=64",
4378+ // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at
4379+ // the SQUARE intra-in-inter arm's own refusal ("an intra
4380+ // block in an inter frame whose tx_depth splits its luma
4381+ // transform (round 1)", read_block_tx_size) long before a
4382+ // rect strip is reached -- that arm is another lane's
4383+ // surface. OFF, no tx-depth symbol is coded at all and
4384+ // every rect strip here is the unsplit single-transform
4385+ // case. The SPLIT rect arm (`depth_to_tx_wh` +
4386+ // decode_rect_split's per-unit walk) is wired but stays
4387+ // UNGATED on this path until that square refusal lifts.
4388+ "--enable-tx-size-search=0",
4389+ "--codec=av1",
4390+ "--passes=1",
4391+ "--end-usage=q",
4392+ "--lag-in-frames=0",
4393+ "--auto-alt-ref=0",
4394+ // One key frame at the head: the frames after the cut must
4395+ // stay INTER frames carrying intra blocks, not become a
4396+ // new key frame.
4397+ "--kf-min-dist=1000",
4398+ "--kf-max-dist=1000",
4399+ "--threads=1",
4400+ "--row-mt=0",
4401+ "--enable-order-hint=0",
4402+ "--enable-warped-motion=0",
4403+ "--enable-obmc=0",
4404+ "--enable-masked-comp=0",
4405+ "--enable-interintra-comp=0",
4406+ "--enable-dist-wtd-comp=0",
4407+ "--enable-diff-wtd-comp=0",
4408+ "--enable-onesided-comp=0",
4409+ "--enable-interintra-wedge=0",
4410+ "--enable-smooth-interintra=0",
4411+ "--enable-ab-partitions=0",
4412+ "--enable-1to4-partitions=0",
4413+ // The intra-in-inter arm reads no `use_filter_intra`
4414+ // symbol (square OR rect) -- lane-fiinter owns that read.
4415+ "--enable-filter-intra=0",
4416+ "--enable-smooth-intra=0",
4417+ "--enable-paeth-intra=0",
4418+ "--enable-directional-intra=0",
4419+ "--enable-angle-delta=0",
4420+ "--enable-cdef=0",
4421+ "--enable-restoration=0",
4422+ "--enable-palette=0",
4423+ "--enable-intrabc=0",
4424+ "--enable-cfl-intra=0",
4425+ "--enable-ref-frame-mvs=0",
4426+ "--obu",
4427+ "-o",
4428+ "-",
4429+ "-",
4430+ ])
4431+ .stdin(Stdio::piped())
4432+ .stdout(Stdio::piped())
4433+ .stderr(Stdio::piped())
4434+ .spawn()
4435+ .expect("aomenc failed to start");
4436+ child
4437+ .stdin
4438+ .take()
4439+ .expect("aomenc stdin")
4440+ .write_all(&y4m.stdout)
4441+ .expect("writing y4m to aomenc");
4442+ let out = child.wait_with_output().expect("aomenc failed to run");
4443+ assert!(
4444+ out.status.success(),
4445+ "aomenc refused the fixture: {}",
4446+ String::from_utf8_lossy(&out.stderr)
4447+ );
4448+ let stream = out.stdout;
4449+ let before = [
4450+ decode::intra_rect_strip_in_inter_hits(0),
4451+ decode::intra_rect_strip_in_inter_hits(1),
4452+ decode::intra_rect_strip_in_inter_hits(2),
4453+ ];
4454+ let kf_rect_before = decode::rect_partition_hits();
4455+ let frames = match decode_stream(&stream) {
4456+ Ok(frames) => frames,
4457+ Err(e) => {
4458+ let msg = e.to_string();
4459+ assert!(
4460+ msg.contains("unsupported"),
4461+ "intra-rect-in-inter decode failed outright (seed {seed}): {msg}"
4462+ );
4463+ refusals.push(format!("seed {seed} {cpu} {cq}: {msg}"));
4464+ continue;
4465+ }
4466+ };
4467+ let delta = [
4468+ decode::intra_rect_strip_in_inter_hits(0) - before[0],
4469+ decode::intra_rect_strip_in_inter_hits(1) - before[1],
4470+ decode::intra_rect_strip_in_inter_hits(2) - before[2],
4471+ ];
4472+ let ffmpeg_frames = if bit_depth == 10 {
4473+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
4474+ } else {
4475+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
4476+ };
4477+ assert_eq!(frames.len(), frame_count);
4478+ eprintln!(
4479+ "intrarect gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra rect strips in inter frames \
4480+ 64-level={} 32-level={} 16-level={}, key-frame rect strips this stream={}",
4481+ delta[0], delta[1], delta[2],
4482+ decode::rect_partition_hits() - kf_rect_before
4483+ );
4484+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4485+ for (plane, (g, w)) in [
4486+ ("Y", (&got.y, &want.y)),
4487+ ("U", (&got.u, &want.u)),
4488+ ("V", (&got.v, &want.v)),
4489+ ] {
4490+ let stride = if plane == "Y" { width } else { width / 2 };
4491+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
4492+ eprintln!(
4493+ "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \
4494+ diff at ({}, {}) got {} want {} ({} samples differ)",
4495+ at % stride,
4496+ at / stride,
4497+ g[at],
4498+ w[at],
4499+ g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
4500+ );
4501+ // Magnitude separates a deblock/prediction difference
4502+ // (all |d| == 1) from an entropy desync (large,
4503+ // arbitrary): the first thing r2 needs to know.
4504+ let maxd = g
4505+ .iter()
4506+ .zip(w.iter())
4507+ .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b)))
4508+ .max()
4509+ .unwrap_or(0);
4510+ let rows: std::collections::BTreeSet<usize> = g
4511+ .iter()
4512+ .zip(w.iter())
4513+ .enumerate()
4514+ .filter(|(_, (a, b))| a != b)
4515+ .map(|(k, _)| k / stride)
4516+ .collect();
4517+ eprintln!(
4518+ "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} max \
4519+ |diff|={maxd}, rows {:?}..{:?}",
4520+ rows.iter().next(),
4521+ rows.iter().next_back()
4522+ );
4523+ }
4524+ assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})");
4525+ }
4526+ }
4527+ compared += 1;
4528+ if delta.iter().all(|d| *d == 0) {
4529+ uncounted_exact += 1;
4530+ refusals.push(format!(
4531+ "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra rect strip on the \
4532+ inter path"
4533+ ));
4534+ }
4535+ for k in 0..3 {
4536+ shapes[k] += delta[k];
4537+ }
4538+ if shapes.iter().filter(|n| **n > 0).count() >= 2 {
4539+ break;
4540+ }
4541+ }
4542+ gate_buckets(
4543+ NAME,
4544+ compared - uncounted_exact,
4545+ uncounted_exact,
4546+ refusals.len() - uncounted_exact as usize,
4547+ );
4548+ eprintln!(
4549+ "{NAME} ({bit_depth}-bit): compared {compared} streams, intra rect strips in inter \
4550+ frames per shape: 64x32/32x64={} 32x16/16x32={} 16x8/8x16={}; refusals:\n{}",
4551+ shapes[0],
4552+ shapes[1],
4553+ shapes[2],
4554+ refusals.join("\n")
4555+ );
4556+ assert!(
4557+ compared > 0,
4558+ "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \
4559+ pixel-compared:\n{}",
4560+ refusals.join("\n")
4561+ );
4562+ // MEASURED (r1, 90 attempts; r2 re-ran the 45-attempt sweep at both
4563+ // depths): only the 32x16/16x32 class is REACHABLE on this branch --
4564+ // the inter tile path refuses any SB-level partition other than
4565+ // NONE/SPLIT, so a 64x32/32x64 intra strip cannot be produced at all,
4566+ // and every 16x8/8x16 candidate stops at a sub-16 refusal owned by
4567+ // another lane. So the bar is that class, hard, not "two of three":
4568+ // a green run still cannot come from a stream that fired nothing.
4569+ assert!(
4570+ shapes[1] > 0,
4571+ "{NAME} ({bit_depth}-bit): no 32x16/16x32 intra rect strip fired over \
4572+ {compared} compared streams (64-level={} 32-level={} 16-level={})",
4573+ shapes[0],
4574+ shapes[1],
4575+ shapes[2]
4576+ );
4577+ }
4578+
42544579 fn tx_select_inter_gate(bit_depth: u32) {
42554580 if !have_ffmpeg() {
42564581 eprintln!(
@@ -21433,4 +21758,171 @@ mod tests {
2143321758 yuv420p10le)"
2143421759 );
2143521760 }
21761+
21762+ /// lane-hgkf r1: a frame whose height (or width) is not a multiple of the
21763+ /// block size makes the last superblock row (column) read a GATHERED
21764+ /// partition bit instead of a full alphabet symbol -- and libaom's
21765+ /// `ec_read_partition_impl` answers that bit with `PARTITION_HORZ`
21766+ /// (resp. `VERT`) when it is 0, only `SPLIT` when it is 1. All three
21767+ /// key-frame edge readers (64-, 32- and 16-level) read the bit and threw
21768+ /// it away, forcing SPLIT; every such frame desynced at the first block
21769+ /// of its partial row. 192x136 / 136x192 is the smallest shape that hits
21770+ /// all three levels at once (136 = 2*64 + 8, so mi_rows = 34: the 64-,
21771+ /// 32- and 16-level halves all fall outside), and it is the shape of a
21772+ /// real 3840x1608 10-bit film key frame (1608 mod 64 == 8) that decoded
21773+ /// 51768 samples wrong before this round.
21774+ ///
21775+ /// The counter is sampled per attempt and read only on an attempt that
21776+ /// decoded AND is pixel-compared; slot 0/2 (the bit taken as HORZ/VERT)
21777+ /// must be nonzero or the gate proves nothing -- before this round that
21778+ /// arm was unreachable by construction.
21779+ #[test]
21780+ fn a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact() {
21781+ const NAME: &str =
21782+ "a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact";
21783+ let _gate_lock = lock_gate_counters();
21784+ if !have_ffmpeg() {
21785+ eprintln!("SKIP {NAME}: no ffmpeg");
21786+ return;
21787+ }
21788+ if !have_aomenc() {
21789+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
21790+ return;
21791+ }
21792+ let mut compared = 0usize;
21793+ let mut edge_horz_total = 0usize;
21794+ let mut edge_sub_total = 0usize;
21795+ // The last two shapes are the ledger-measured 64-level pair: on a
21796+ // flat band (192x80 / 80x192) real aomenc answers the bottom-edge
21797+ // superblock with the 64-level HORZ/VERT, which the 136 shapes above
21798+ // never produce (their SBs always split down to the 32/16 levels).
21799+ for (width, height, flat) in [
21800+ (192usize, 136usize, false),
21801+ (136usize, 192usize, false),
21802+ (192usize, 80usize, true),
21803+ (80usize, 192usize, true),
21804+ ] {
21805+ for depth in [8usize, 10] {
21806+ let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
21807+ let y4m = Command::new("ffmpeg")
21808+ .args([
21809+ "-v", "error", "-f", "lavfi", "-i",
21810+ &if flat {
21811+ format!("color=c=gray:size={width}x{height}")
21812+ } else {
21813+ format!("mandelbrot=size={width}x{height}:start_x=-0.6")
21814+ },
21815+ "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1",
21816+ "-f", "yuv4mpegpipe", "-",
21817+ ])
21818+ .stdin(Stdio::null())
21819+ .stdout(Stdio::piped())
21820+ .stderr(Stdio::piped())
21821+ .output()
21822+ .expect("ffmpeg failed to run");
21823+ assert!(
21824+ y4m.status.success(),
21825+ "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}",
21826+ String::from_utf8_lossy(&y4m.stderr)
21827+ );
21828+ let encode = || {
21829+ let mut child = Command::new(aomenc_path())
21830+ .args([
21831+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
21832+ "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64",
21833+ "--kf-max-dist=0", "--enable-rect-partitions=1",
21834+ "--enable-ab-partitions=0", "--enable-1to4-partitions=0",
21835+ "--enable-tx-size-search=0", "--reduced-tx-type-set=1",
21836+ "--min-partition-size=8", "--max-partition-size=64",
21837+ &format!("--input-bit-depth={depth}"),
21838+ &format!("--bit-depth={depth}"),
21839+ "--obu", "-o", "-", "-",
21840+ ])
21841+ .stdin(Stdio::piped())
21842+ .stdout(Stdio::piped())
21843+ .stderr(Stdio::piped())
21844+ .spawn()
21845+ .expect("aomenc failed to start");
21846+ child
21847+ .stdin
21848+ .take()
21849+ .expect("aomenc stdin")
21850+ .write_all(&y4m.stdout)
21851+ .expect("writing y4m to aomenc");
21852+ let out = child.wait_with_output().expect("aomenc failed to run");
21853+ assert!(
21854+ out.status.success(),
21855+ "aomenc refused the fixture ({width}x{height}, depth={depth}): {}",
21856+ String::from_utf8_lossy(&out.stderr)
21857+ );
21858+ out.stdout
21859+ };
21860+ let stream = encode();
21861+ assert_eq!(
21862+ stream,
21863+ encode(),
21864+ "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})"
21865+ );
21866+ crate::decode::reset_edge_part_hits();
21867+ let frames = match decode_stream(&stream) {
21868+ Ok(frames) => frames,
21869+ Err(e) => {
21870+ let msg = e.to_string();
21871+ assert!(
21872+ msg.contains("unsupported"),
21873+ "{NAME}: decode failed ({width}x{height}, depth={depth}): {msg}"
21874+ );
21875+ eprintln!(
21876+ "{NAME}: {width}x{height} depth={depth} arm refused (not compared): {msg}"
21877+ );
21878+ continue;
21879+ }
21880+ };
21881+ let hits = crate::decode::edge_part_hits();
21882+ let ffmpeg_frames = if depth == 10 {
21883+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
21884+ } else {
21885+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
21886+ };
21887+ assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count");
21888+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
21889+ assert_eq!(
21890+ got.y, want.y,
21891+ "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \
21892+ edge bits horz/split 64-level {}/{}, sub-level {}/{})",
21893+ hits[0], hits[1], hits[2], hits[3]
21894+ );
21895+ assert_eq!(
21896+ got.u, want.u,
21897+ "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth})"
21898+ );
21899+ assert_eq!(
21900+ got.v, want.v,
21901+ "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth})"
21902+ );
21903+ }
21904+ compared += 1;
21905+ edge_horz_total += hits[0];
21906+ edge_sub_total += hits[2];
21907+ eprintln!(
21908+ "{NAME}: pixel-exact {width}x{height} at {depth}-bit, edge bits \
21909+ 64-level horz/vert={} split={} sub-level horz/vert={} split={}",
21910+ hits[0], hits[1], hits[2], hits[3]
21911+ );
21912+ }
21913+ }
21914+ assert!(
21915+ compared > 0,
21916+ "{NAME}: every arm refused -- the gate compared no pixels at all"
21917+ );
21918+ assert!(
21919+ edge_horz_total > 0,
21920+ "{NAME}: no 64-level frame-edge bit was ever answered HORZ/VERT -- the arm this \
21921+ round fixed never fired"
21922+ );
21923+ assert!(
21924+ edge_sub_total > 0,
21925+ "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT"
21926+ );
21927+ }
2143621928 }
lanes/hgkf-r1.report.mdadded+86 -0
@@ -0,0 +1,86 @@
1+# lane-hgkf r1 — the frame-edge partition bit, all three levels
2+
3+Branch `lane-hgkf` off main `0df090a`. Two 3840x1608 10-bit key frames that
4+decoded without refusal but pixel-wrong (scratch: `.../scratchpad/census2/kf_0.obu`,
5+`kf_4500.obu`).
6+
7+## Root cause (class `parsed-then-discarded`)
8+
9+A superblock/block whose second half falls outside the frame does not carry a
10+full partition alphabet symbol; it carries one GATHERED bit. libaom
11+`ec_read_partition_impl` answers that bit with `PARTITION_HORZ` (resp. `VERT`)
12+when it is **0**, and only `PARTITION_SPLIT` when it is 1. All three key-frame
13+edge readers read the bit and threw it away, forcing SPLIT:
14+
15+* `crates/ec-av1/src/decode.rs:11373` — 64-level (superblock)
16+* `crates/ec-av1/src/decode.rs:11446` — 32-level
17+* `crates/ec-av1/src/decode.rs:11938` — 16-level (this one had no HORZ/VERT arm
18+ at all; it now decodes the single in-frame 16x8 / 8x16 strip through
19+ `decode_leaf_rect`)
20+
21+The HORZ/VERT arms also decode ONLY the in-frame half of the strip (libaom
22+`decode_partition` guards the second half with the same has_rows/has_cols test
23+that made the partition non-square) — `decode.rs:12480`, `12525`, `12038`,
24+`12086`.
25+
26+Every frame whose height or width is not a multiple of 64 desynced at the first
27+block of its partial row. 1608 mod 64 == 8, so both film key frames lost their
28+whole bottom 8-pixel band and everything the desync dragged after it.
29+
30+New counter `EDGE_PART_HITS` (`decode.rs`, `edge_part_hits()` /
31+`reset_edge_part_hits()`): slot 0/1 = 64-level bit taken as HORZ-VERT / SPLIT,
32+2/3 = the 32+16-level pair.
33+
34+Also ported (unmerged lane-golomb 791d87a) the libaom TU-origin clip: a
35+transform unit whose top-left sample lies outside `mi_cols*4 x mi_rows*4` is
36+never coded (`decode_rect_split` and `decode_block`'s multi-TU loop). Measured
37+INERT on both frames here (byte-identical output before/after); kept because it
38+is the libaom rule.
39+
40+## Evidence
41+
42+EVIDENCE: /home/user/.cache/hgkf-work/{ours,p,q,r}_kf_0.f0.yuv vs ref_kf_0.yuv | `dump_yuv kf_0.obu` vs `ffmpeg -pix_fmt yuv420p10le`, 16-bit sample compare | 3819 mismatching samples (Y 238 / U 1776 / V 1805, first Y row 1600 col 1120) -> **0, bit-exact all three planes**
43+EVIDENCE: /home/user/.cache/hgkf-work/r_kf_4500.f0.yuv vs ref_kf_4500.yuv | same command pair on the mid-film key frame | 51768 mismatching samples (Y 35861 / U 8419 / V 7488) -> **2403, luma only, |delta| <= 2, chroma bit-exact**
44+EVIDENCE: /home/user/.cache/hgkf-work/{a45.l,o45c.l} | `EC_TRACE_MODE_STEP=1` ladder, ours vs instrumented aomdec, ranges compared element by element | 0 changed lines (only oracle-side lines we do not print: `tx_depth`, `use_filter_intra`); pre-fix the ladders diverged at mi_row=400 mi_col=0, `skip` range 43258 vs 34753
45+EVIDENCE: gate `a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact` | `cargo test -p ec-av1 --lib frame_edge_partition_bit -- --nocapture` | 8/8 arms pixel-exact; 192x136+136x192 mandelbrot 8/10-bit sub-level HORZ-VERT bits 9/7/4/3; 192x80+80x192 flat 8/10-bit 64-level HORZ-VERT bits 3 each; **test result: ok. 1 passed**
46+
47+## Gate
48+
49+`crates/ec-av1/src/stream.rs` — one test, eight arms (two shapes x
50+{mandelbrot,flat} x {8,10}-bit). Both "answered HORZ/VERT" counter slots must
51+be nonzero, counters read only on an attempt that decoded AND is compared, Err
52+tolerated only for messages containing "unsupported", aomenc output hashed
53+twice for reproducibility. 136 = 2*64+8 is the small-scale twin of the film's
54+1608 mod 64 == 8; the flat 80-tall pair is the ledger-measured shape where real
55+aomenc answers the SUPERBLOCK edge bit non-SPLIT.
56+
57+Refusals lifted: none (this was a silent wrong-decode, not a refusal).
58+`refusal_inventory` and `gate_coverage` unchanged.
59+
60+## Open residue
61+
62+`fix-now` for a follow-up round, not reachable inside this one: the mid-film key
63+frame still has **2403 luma samples wrong, |delta| <= 2, chroma exact**, in two
64+clusters — SB(row 19, col 17) 1409 samples and SB(row 6..9, col 49..51) ~990,
65+first at Y row 416 col 3169 (mi_row 104, mi_col 792), ours 210 vs 209. The
66+entropy ladder is exact through the whole frame, so this is a RECONSTRUCTION
67+(prediction or post-filter) defect, not a symbol defect — the +-1/+-2 magnitude
68+and the isolated superblocks point at an intra prediction corner or a
69+CDEF/deblock strength on those blocks. `deferred: mid-film key frame +-2 luma
70+residue — needs a per-TU EC_PRED compare at mi(104,792) — unblocked by this
71+round's entropy exactness, any agent can start at that block.`
72+
73+Suite: `cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/hgkf-suite2.log`) -- **356 passed / 0 failed / 29 ignored**, 683s.
74+
75+## Same-shape sweep (class `parsed-then-discarded`, frame-edge partition bit)
76+
77+Grepped every gathered-edge reader in `decode.rs`. Fixed: the three key-frame
78+ones (64/32/16-level). **Flagged, not fixed**: the INTER tile has the identical
79+three readers — `decode.rs:18441` (64-level, `part64` match), `decode.rs:18590`
80+(32-level) and `decode.rs:18755` (16-level) — all still discard the bit and
81+force SPLIT, so an inter frame whose height is not a multiple of 64 mis-decodes
82+its partial row exactly the way the key frames did. It is left alone here
83+because the inter edge-strip decoders do not exist yet (lane-oddh r2 measured
84+that no aomenc recipe even reaches that arm today, so a fix could not be gated).
85+`deferred: inter-frame edge partition bit — needs the inter frame-edge
86+half-strip decoder (lane-oddh territory) plus a recipe that reaches it.`
lanes/hgkf-r2.report.mdadded+90 -0
@@ -0,0 +1,90 @@
1+# lane-hgkf r2 — a skipped intra block predicts per TRANSFORM UNIT
2+
3+Branch `lane-hgkf`, on top of r1 (`4939695`). Target: the r1 residue on the
4+mid-film 3840x1608 10-bit key frame — 2403 luma samples wrong, |delta| <= 2,
5+chroma exact, entropy ladder exact frame-wide.
6+
7+## Stage split (the charter's step 1)
8+
9+Both decoders' 8-bit stage rungs truncate 10-bit samples, so a |delta| <= 2
10+defect is invisible in them. Added a 16-bit twin on both sides:
11+`ec_dump16` in the oracle (`EC_AV1_PREFILT_DUMP16` /
12+`EC_AV1_POSTDEBLOCK_DUMP16`, `av1/decoder/decodeframe.c`) and `dump_stage16`
13+in ours (same two names plus `EC_AV1_POSTCDEF_DUMP16`, `decode.rs`).
14+
15+EVIDENCE: /home/user/.cache/hgkf-work/{o,a}_pre.f0, {o,a}_pdb.f0, o_fin.f0.yuv vs ref_kf_4500.yuv | ours vs instrumented aomdec, 16-bit cropped planes at PREFILT / POSTDEBLOCK / FINAL | PREFILT Y 2372 wrong (maxabs 3, first row 416 col 3170, ours 210 vs 209), POSTDEBLOCK identical set, FINAL 2403 -> **the defect is already in reconstruction**; deblock/CDEF/LR only smear it
16+
17+## Root cause (class `decision-at-wrong-granularity`)
18+
19+An intra block's `tx_depth` is read whether or not the block is skipped (only
20+an INTER skip forces the largest transform), and spec 7.11.2 / libaom
21+`predict_and_reconstruct_intra_block` predicts **one transform unit at a
22+time** — each unit's above/left edges are the units already reconstructed
23+inside that same block. Our skip branches predicted the whole block in one
24+call:
25+
26+* `crates/ec-av1/src/decode.rs` `decode_block`'s `if skip` arm — a 32x32 block
27+ with `logical_tx == 8` was one 32x32 DC prediction (123) where libaom does 16
28+ 8x8 DC predictions (124 each).
29+* `crates/ec-av1/src/decode.rs` `decode_leaf8`'s `if skip` arm — the same shape
30+ one level down: an 8x8 leaf with `resolved == 4` is four 4x4 units.
31+
32+Both now loop the units with a zero residual, reusing the non-skip loop's own
33+`tu_reach` geometry and its out-of-frame TU-origin clip. The palette/intrabc
34+override keeps the single-call shape (its per-TU windowing is the non-skip
35+path's, untested for skip and unreachable in these streams).
36+
37+New counter `SKIP_SPLIT_TX_HITS` (`skip_split_tx_hits()` /
38+`reset_skip_split_tx_hits()`, blocks not units): the only witness this path
39+has, since a skipped block codes no coefficients at all.
40+
41+## Evidence
42+
43+EVIDENCE: /home/user/.cache/hgkf-work/aom_pred.txt, our_pred.txt | new oracle rung `EC_PREDND` (non-directional high-bitdepth prediction; the pre-existing `EC_PRED` rung sat AFTER the `is_hbd` early return and printed nothing on a 10-bit stream) vs our new `OUR_PRED` rung | at px(1088,1216) libaom prints 16 8x8 DC predictions of 124, ours one 32x32 of 123 — sum 7936 x16 vs 125952
44+EVIDENCE: /home/user/.cache/hgkf-work/fx_kf_4500.f0.yuv vs ref_kf_4500.yuv | `dump_yuv kf_4500.obu` vs `ffmpeg -pix_fmt yuv420p10le`, 16-bit compare | 2403 wrong -> **0, all three planes bit-exact**
45+EVIDENCE: /home/user/.cache/hgkf-work/fx_kf_0.f0.yuv vs ref_kf_0.yuv | same command pair | **0, still bit-exact** (r1's frame did not regress)
46+
47+Scratch pin (not a repo fixture, scratch-only as the charter requires):
48+`.../scratchpad/census2/kf_4500.obu` sha256
49+`80529979df3735bce82f9c48fb0be66ec2019f4316ad6e617def86141c2b9010` — 48 split-skip
50+TU predictions, decodes bit-exact; `kf_0.obu` sha256
51+`53c311dec790bb2413afdde92cb24de498a7c4f66f6f0c7f4f5910ab0d2c65dc` — 0 hits, bit-exact.
52+
53+## Gate: NOT LANDED — no encoder recipe reached the path
54+
55+`deferred: an in-repo gate for split-tx skipped intra prediction — no
56+reproducible encoder recipe found in this round's budget — unblocked by either
57+an aomenc flag combination that keeps a split `tx_depth` on a block it then
58+skips, or by lifting the 1:4-partition refusal so an SVT-AV1 stream can be
59+decoded whole.`
60+
61+Swept, all 10-bit, all with the decode's success checked (a refused decode's
62+counter is a `counter-from-refused-stream` artefact, so every arm below reports
63+both):
64+
65+* aomenc `--enable-tx-size-search=1`, mandelbrot/testsrc2/low-amplitude noise,
66+ 256x192..1280x720, cq 12..55, cpu-used 0..8, aq-mode 0/1, 8- and 10-bit:
67+ **0 hits on every arm that decoded**. aomenc's tx search ties on a zero
68+ residual and keeps the largest transform, so it essentially never writes this
69+ combination.
70+* ffmpeg `libsvtav1` (v3.1.2) preset 4, 1280x720 10-bit: **reaches the path**
71+ (4..24 units at crf 25..55) — but every one of those streams also uses a 1:4
72+ partition below 16x16 / intrabc / palette, all of which this decoder refuses,
73+ so nothing could be pixel-compared.
74+* `gradients=size=1280x720:n=4` + libsvtav1 crf 30 decoded whole once with 16
75+ units, but lavfi `gradients` is not reproducible (3 encodes, 3 different
76+ sha256) — the known `seeded-fixture-not-reproducible` trap, rejected as a
77+ fixture.
78+
79+## Same-shape sweep
80+
81+Every intra skip-prediction site in `decode.rs`: `decode_block` (fixed),
82+`decode_leaf8` (fixed), the 4x8/8x4 leaf at `decode.rs:9570` (already per-TU,
83+lane-palette2), the inter-frame vartx leaf at `decode.rs:16450` (already
84+per-TU), the 4x4 leaf (no split exists). Chroma skip prediction is still
85+whole-block: for 4:2:0 the chroma transform only splits above a 64x64 luma
86+block, which no gate or film frame here reaches —
87+`deferred: chroma skip prediction per TU above 64x64 luma — no stream reaches
88+it — unblocked by a 128x128-superblock 10-bit gate.`
89+
90+Suite: `cargo test -p ec-av1 --lib` (user unit, log `$HOME/.cache/hgkf-suite-r2.log`) -- **356 passed / 0 failed / 29 ignored**, 416s.
lanes/intrarect-r1.report.mdmodified+73 -112
@@ -1,125 +1,86 @@
1-# lane-intrarect r1 report
1+# lane-intrarect r1 — intra rect strips on the inter block path
22
3-VERDICT: DONE -- `intra::predict`/`Edges` are rect-capable (`bw != bh`),
4-C-verified for 8 rect shapes across DC/SMOOTH/PAETH + 17 directional angles
5-x {enable_edge_filter, smooth_neighbor}; full lib suite 224/224 (was
6-223/223, +1 the new C-verify test), square behaviour unchanged; tile
7-dispatch still refuses rect/AB partitions.
3+Branch `lane-intrarect` off `lane-rectsplitx` cbf8ffd. **Result: code landed, gate RED
4+(one real residual defect, evidence below). The lane does not merge in this state.**
85
96 ## What changed
10-`crates/ec-av1/src/intra.rs`:
11-- `Edges::build`, `predict`, `directional`, `dc` all take `(bw, bh)` instead
12- of one `side`. `Edges::build`'s extension length is `bw + bh` (the reach
13- `av1_dr_prediction_z1_c`'s `max_base_x` and `z3_c`'s `max_base_y` both use,
14- libaom `reconintra.c`).
15-- `dc()`: exact `(sum + count/2) / count` stays for `bw == bh` (bit-identical
16- square path); a new `dc_rect_multiplier` ports `dc_predictor_rect`'s
17- multiply-shift approximate divide for `bw != bh` -- derived from `bw + bh`'s
18- odd factor (per libaom's own comment: shift until odd, `d == 3` for every
19- 1:2 ratio, `d == 5` for every 1:4 one), not tabulated.
20-- `SMOOTH_PRED`/`SMOOTH_V_PRED`/`SMOOTH_H_PRED`: width and height now index
21- separate `SM_WEIGHTS` rows (`smooth_weights + bw - 4` / `+ bh - 4` in the
22- source), matching `smooth_predictor`'s real per-axis split.
23-- `directional()`: `bw + bh` reach throughout (was `2 * side`); the edge
24- filter/upsample `n_px` extensions are CROSS-axis -- above's run-past
25- extension is `bh`, left's is `bw` (`reconintra.c`'s `txwpx`/`txhpx` argument
26- swap between the above and left calls). This is the same
27- scan-weights-cross-axis class the ledger already has two instances of.
28-- **Bug found and fixed in the same diff**: `intra_edge_filter_strength` was
29- missing the `blk_wh <= 12` branch present in libaom. No square block's
30- `bw + bh` ever lands in `9..=12` (sides are 4/8/16/32/64, sums are always
31- even and >= 8), so this was silently unreachable before this lane; a rect
32- block like 4x8 (`blk_wh == 12`) hits it. Ported verbatim.
33-- 21 call sites (`encode.rs` x4, `decode.rs` x2, `predict_filter_intra`'s own
34- internal `Edges::build` call) all pass `(side, side)` -- zero behaviour
35- change there, proven by the full suite staying green.
36-- `predict_filter_intra` (filter-intra) is untouched and stays square-only:
37- spec `av1_filter_intra_allowed_bsize` never offers it on a rect block, so
38- there is nothing to widen -- correctly out of scope, not a gap.
397
40-## C-verification (what's C-verified vs transcribed-only)
41-`lanes/intrarect_dump.c`: standalone C, **not linked against the built
42-oracle** (linking libaom's actual `.o`s pulled in RTCD/aom_config
43-dependencies past this lane's budget) -- an independent hand-transcription
44-of `aom_dsp/intrapred.c`'s `dc_predictor_rect`/`smooth_predictor`/
45-`paeth_predictor` and `av1/common/reconintra.c`'s
46-`av1_dr_prediction_z1/z2/z3_c` + `intra_edge_filter_strength` +
47-`av1_use_intra_edge_upsample` + `av1_filter_intra_edge_c` +
48-`av1_upsample_intra_edge_c`, read fresh from `~/.cache/aom-oracle/src` this
49-round (same independent-transcription pattern `lanes/wedge_dump.c` used,
50-per the charter's shared-oracle-blindness note).
8+- `crates/ec-av1/src/decode.rs` (`decode_intra_rect_in_inter`, new, right before
9+ `decode_block_rect`): an intra-coded HORZ/VERT strip on the inter block path reads its
10+ mode info with the INTER frame's own intra syntax (`y_mode[size_group]` /
11+ `uv_mode_cfl|uv_mode_no_cfl` / cfl alphas / uv angle delta — mirroring the square
12+ intra-in-inter arm, including its inherited gaps: no `use_filter_intra` symbol, nonzero
13+ luma angle delta refused), its tx depth from the shape's own `bsize_to_tx_size_cat`
14+ (16x8 -> cat1, 32x16 -> cat2, 64x32 -> cat3, ctx from `tx_size_context_rect`), then hands
15+ every pixel to `decode_rect_split` — the same machinery the key-frame rect paths use, which
16+ at `depth == 0` is the unsplit single-transform strip.
17+- `crates/ec-av1/src/decode.rs` (`decode_inter_block`, the `write_w != side` arm): calls it
18+ instead of refusing, then writes the mi map (`is_inter: false`, rect `size`/`size_h`) and
19+ `record_inter_rect`, and returns — `decode_rect_split` already wrote the luma per-TU,
20+ chroma, skip and deblock records the shared tail would otherwise stamp at block
21+ granularity.
22+- `crates/ec-av1/src/decode.rs`: the `reject_residual && !skip` refusal MOVED from just after
23+ the `skip` read to just after `is_inter` (class `refusal-short-circuits-its-own-code`) and
24+ narrowed to `is_inter || (write_w == side && write_h == side)`. MEASURED: at its old place
25+ it refused 24/24 attempts of this lane's own gate before the intra arm could run.
26+- `crates/ec-av1/src/refusal_inventory.rs`: lifted "an intra-coded HORZ/VERT strip needs
27+ rectangular intra prediction this decoder does not code yet"; added the residue
28+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path" (a 1:4 strip
29+ breaks the size-group/tx-cat diagonal the 2:1 shapes share, so it is refused rather than
30+ read from the wrong CDF row).
31+- `crates/ec-av1/src/stream.rs`: gate
32+ `a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact` (+ `_10bit`),
33+ 45 attempts sweeping seed x `--cpu-used` 0..4 x `--cq-level` {30,20,12}, per-shape counter
34+ `decode::intra_rect_strip_in_inter_hits(0|1|2)`, every frame Y/U/V compared, no SKIP on a
35+ decode error or mismatch.
5136
52-**C-verified** (checksum-matched, 568 cases, `intra::tests::rect_predictors_match_c_dump`):
53-- `DC_PRED` (both the exact-divide and `dc_predictor_rect` approximate-divide
54- paths, since the test only exercises `bw != bh` shapes here)
55-- `SMOOTH_PRED`, `PAETH_PRED`
56-- All eight directional modes (`V_PRED`, `H_PRED`, `D45`/`D67`/`D113`/`D135`/
57- `D157`/`D203_PRED`) across z1/z2/z3, both `enable_edge_filter` states, both
58- `smooth_neighbor` states, for shapes 8x4/4x8/16x8/8x16/4x16/16x4/32x16/16x32
59- (both 1:2 and 1:4 ratios, both orientations)
37+## Recipe deviations from the charter (each measured, not chosen)
6038
61-**Transcribed-only, not independently C-verified this round**:
62-- `SMOOTH_V_PRED`/`SMOOTH_H_PRED` -- same weight-split code path as
63- `SMOOTH_PRED` (which is verified), not separately dumped
64-- `filter_intra_edge_corner`'s rect gate (`reach >= 24`) -- exercised by the
65- dump's angle/shape sweep whenever it applies, but not isolated as its own
66- case
67-- The `n_top`/`n_left` < full-reach path (a block against the frame edge with
68- fewer real neighbour samples than `bw`/`bh`) -- the dump feeds full-length
69- synthetic neighbours throughout; this is unchanged pre-existing
70- `Edges::build` repeat-extension logic, not something this lane's widening
71- touches structurally, and it's exercised (for squares) by the full suite
39+- `--min-partition-size=8` -> `16`: at 8, 24/24 attempts stop at sub-16 AB refusals
40+ ("a HORZ_A/HORZ_B/VERT_A partition below 16x16", "a coded (non-skip) HORZ_B/VERT_B rect
41+ strip below 16x16") — other lanes' surfaces.
42+- `--enable-tx-size-search=1` -> `0`: with it on, 24/24 attempts stop at the SQUARE
43+ intra-in-inter arm's own refusal ("an intra block in an inter frame whose tx_depth splits
44+ its luma transform (round 1)", `read_block_tx_size`). Consequence: **the SPLIT rect arm on
45+ the inter path is wired but UNGATED**; only the unsplit strip is exercised.
46+- Content: the charter's mandelbrot + overlay cut never produced an intra rect strip (every
47+ rect strip in those streams was INTER, refused by lane-inter4's wall). The fixture that
48+ works is a FAST-ZOOM mandelbrot (`end_scale=0.004:end_pts=8`), where consecutive frames
49+ share almost no content so aomenc codes blocks intra inside inter frames.
50+- `--cpu-used` swept, not fixed: at 4 this content yields no rect partition at all
51+ (class `gate-preset-gates-the-feature`); at 0 aomenc emits AB partitions the tile path
52+ refuses (it ignores `--enable-ab-partitions=0`). Only cpu-used 1..3 both decode and produce
53+ rect strips.
7254
73-## Gate ladder run
74-(a) full lib suite: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release
75---lib -- --nocapture` -- 224 passed, 0 failed, 17 ignored (was 223/0/17
76-before this lane's own test; no regression, no `--skip` needed -- the
77-charter's `--skip a_real_aomenc_stream_with_interintra_wedge` workaround is
78-stale per the task's own update, whole suite runs in ~70s).
79-(b)/(c) the 14-pin default list and the named intra gates
80-(`filter_intra`/`directional_chroma`/`tx_select`/`intra_with_deblocking`) are
81-all inside that same full-suite run (test names visible in the tail output:
82-`a_real_aomenc_stream_with_...` for all of them), all green.
55+## Gate result — RED
8356
84-## Commits (this worktree, lane-intrarect branch, not pushed)
85-- `bade5c8` feat(av1): widen intra::predict/Edges to rect (bw != bh)
86-- `6813a8a` test(av1): C-verify rect intra predictors against an independent transcription
57+Command:
58+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intrarect EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3`
8759
88-## Deviations from the charter
89-- Skipped the charter's stale `--skip a_real_aomenc_stream_with_interintra_wedge`
90- per the task's explicit override.
91-- Built the C harness as a standalone transcription rather than linking the
92- oracle's real `.o` files, matching `wedge_dump.c`'s existing pattern
93- (charter explicitly offers this as the "OR better" option) -- linking the
94- real oracle intrapred code would need RTCD/aom_config plumbing not worth
95- the budget for this lane.
60+EVIDENCE: $HOME/.cache/intrarect-suite.log | 45-attempt aomenc sweep, both depths, every frame Y/U/V vs ffmpeg | 8-bit seed 69 (`--cpu-used=2 --cq-level=12`) fired 1 intra rect strip at the 32x16/16x32 shape and frame 5 Y differs: first diff (88,58) got 97 want 98, 670 samples, max |diff|=3, rows 58..95. 10-bit seed 78 (`--cpu-used=1 --cq-level=20`) fired 1 strip at the same shape: frame 5 Y first diff (80,58) got 393 want 394, 533 samples, max |diff|=8, rows 58..95.
9661
97-## Next lane
98-Flip the KEY-frame tile dispatch (`decode.rs` ~3624/~3841) to accept the
99-17/40 refused rect/AB partition attempts now that the predictor underneath
100-is rect-capable -- out of scope for r1 by charter, unchanged this round.
62+Suite: `335 passed; 2 failed (this lane's two new gates); 29 ignored` — nothing else regressed,
63+`refusal_inventory` and `gate_coverage` green with the moved refusal and the lifted string.
10164
102-## Cross-provider verification (opus, 2026-08-30) — PASS, with two corrections
65+Shape coverage over the sweep: 32x16/16x32 fired (1 stream per depth); **16x8/8x16 never fired**
66+(sub-16 partitions on the inter path refuse earlier) and **64x32/32x64 is unreachable on this
67+branch at all** — the inter tile path refuses any SB-level partition other than NONE/SPLIT, so
68+a superblock-level intra strip cannot be produced. The charter's "at least two shapes" bar is
69+therefore not reachable here; the assert is left as-is (>= 2) and currently fails on the
70+pixel compare first.
10371
104-All 6 claims CONFIRMED against pinned libaom v3.13.3: square paths provably
105-bit-identical (every `side` -> `(bw,bh)` substitution audited term by term);
106-`dc_predictor_rect`'s 0x5556/0x3334 multiply-shift and the `sum + ((bw+bh)>>1)`
107-dividend exact (intrapred.c:236-279); smooth weight rows not transposed
108-(intrapred.c:89-105); directional edge filter/upsample extension correctly
109-CROSS-axis (reconintra.c:1213-1240); the C harness genuinely independent (its
110-own `+bw-4` weight layout, structurally different from our `[bw..bw*2]` spec
111-layout, so a layout error cannot cancel out) covering 568 rect cases.
72+## Residue
11273
113-CORRECTIONS to this report's earlier claims:
114-1. "Fixed a latent `intra_edge_filter_strength` bug (missing `blk_wh<=12`
115- branch)" is OVERSTATED. The branch does exist in reconintra.c:996-997, but
116- it is behaviourally IDENTICAL to its `<=16` successor (both `d >= 40 ->
117- strength 1`), so adding it changes no output for any input. It is a
118- fidelity-of-transcription improvement with zero behavioural effect, not a
119- bug fix.
120-2. The harness's uncovered modes are V_PRED and H_PRED **in addition to** the
121- SMOOTH_V/SMOOTH_H this report named. All four are transcribed-only; the
122- verifier hand-checked SMOOTH_V/H against intrapred.c:115-172 (correct), and
123- V/H are axis-free single-edge reads carrying no rect risk.
124-Also uncovered: `Edges::build`'s repeat-extension branch is never exercised at
125-rect reach (the harness always supplies a full bw+bh neighbour run).
74+- fix-now (r2): the pixel defect above. Frames 0..4 are exact and the magnitudes are small
75+ (<= 3 at 8 bit), so this is NOT an entropy desync — the tile stays in sync. The diff band
76+ starts at row 58 and runs to the frame bottom, i.e. the strip's own bottom deblock band
77+ (edge at y=64 filters rows 57..70) plus everything predicted below it. Look at the deblock
78+ records for a rect intra strip on the inter path first (`decode_rect_split`'s
79+ `fill_lf_grid_rect` + the `record_inter_rect` the new call site adds), then at prediction;
80+ entropy is cleared by construction.
81+- deferred(the square intra-in-inter tx-split refusal in `read_block_tx_size`) — the split
82+ rect arm on the inter path is unproven.
83+- deferred(lane-inter4 merge) — 64x32/32x64 and the 16x8/8x16 shape need the inter-side rect
84+ work; lane-inter4's `coded_rectangular_residual` gate is NOT on this branch and was not
85+ un-ignored.
86+- accepted — 1:4 strips refuse by name on this path.
lanes/intrarect-r2.handoff.mdadded+53 -0
@@ -0,0 +1,53 @@
1+# lane-intrarect r2 handoff — DEFECT CLOSED, one item left open
2+
3+State at `f2efbcd` (branch `lane-intrarect`, worktree clean). r1's pixel defect is FIXED and
4+both gates are GREEN; this handoff exists only because the full-suite run had not finished
5+when the turn cap hit. Full detail: `lanes/intrarect-r2.report.md`.
6+
7+## Which stage differed (charter STEP 1, answered)
8+
9+PREFILT (pre-deblock RECON), not deblock, not CDEF/LR. 8-bit seed 69 frame 5: first wrong
10+luma sample (80,64), 512 luma samples = exactly the 16x32 strip at mi(16,20) + 120 V samples.
11+Frames 0..4, 6, 7 byte-identical. So the loop filter, the lf grid and `record_inter_rect`
12+were all EXONERATED and the charter's deblock branch is a dead end.
13+
14+## Root cause (found, fixed, committed)
15+
16+`decode_rect_split`'s rect-TU arm read `txb_skip` from `luma_skip_ctx_rect` even when the
17+transform covers the whole block. libaom `get_txb_ctx` gives luma a flat ctx **0** when
18+`plane_bsize == txsize_to_bsize[tx_size]`. Ours read ctx 5, aomdec ctx 0 -- same decoded
19+value, different CDF, msac range diverging at the block's first coefficient symbol
20+(ours 58117, aomdec 45075, identical ENTRY range 60236). Fix: `decode.rs:5009`, ctx 0 when
21+`tx_w == bw && tx_h == bh`. After it, all 8 frames of the seed-69 stream are byte-identical.
22+
23+## Ruled out (do not re-investigate)
24+
25+- Deblock / lf grid / `record_inter_rect` / delta_lf: the mismatch is already in PREFILT.
26+- Prediction and edge availability: the strip's DC prediction was correct (aomdec's own
27+ edges average 96.9 -> 97, and after the ctx fix the block is exact with no prediction change).
28+- Mode info (skip / is_inter / y_mode size_group 2 / uv_mode cfl-allowed / tx depth): the
29+ coefficient read's ENTRY range matched aomdec exactly (60236), so every mode symbol before
30+ it was right.
31+- Every other `luma_skip_ctx*` call site (`decode.rs:5054`, 7947, 8301, 8829, 9648, 14534,
32+ 15368) -- none can reach the unit == block case; the sweep is in the report.
33+- 10-bit was NOT separately bisected: the 10-bit gate seed 78/84 now passes pixel-exact,
34+ so there is no 10-bit residue to measure.
35+
36+## Gates + suite
37+
38+`cargo test -p ec-av1 --lib intra_rect_strip` -> `2 passed; 0 failed` (12.20s),
39+`$HOME/.cache/intrarect-gate-r2.log`, both depths, 45 attempts each, all pixel-compared.
40+Negative control for r1's `reject_residual` move: 8 attempts in the same sweep still refuse
41+"a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding".
42+
43+FULL SUITE: FINISHED GREEN after the cap -- `test result: ok. 337 passed; 0 failed; 29
44+ignored; 0 measured; 0 filtered out; finished in 257.15s`
45+(`$HOME/.cache/intrarect-suite-r2.log`).
46+
47+## Exact next step for r3 (one item)
48+
49+The only open item is the MERGE, not a defect: this branch is **not rebased onto main**.
50+ main now carries lane-fiinter (square intra-in-inter reads `use_filter_intra`) and
51+ lane-rect1d; `decode_intra_rect_in_inter` reads no such symbol, so on the merged tree the
52+ rect arm needs the same read wired (this lane's gate spells `--enable-filter-intra=0`, so
53+ its own streams never carry it and the gate cannot catch a missing read).
lanes/intrarect-r2.report.mdadded+88 -0
@@ -0,0 +1,88 @@
1+# lane-intrarect r2 — the intra rect strip's txb_skip context
2+
3+Branch `lane-intrarect` off `lane-rectsplitx` cbf8ffd (r1 = 798ea0c). **Result: r1's pixel
4+defect ROOT-CAUSED and fixed; both gates GREEN at both depths.**
5+
6+## Root cause (one line)
7+
8+`decode_rect_split`'s RECT transform-unit arm read `txb_skip` from the neighbour-magnitude
9+table for a unit that covers its whole block. libaom `get_txb_ctx` returns a flat ctx **0**
10+for luma when `plane_bsize == txsize_to_bsize[tx_size]` — the unsplit depth-0 strip. On the
11+frame-5 16x32 strip our decoder used ctx **5** where aomdec used **0**: same decoded value
12+(`all_zero=0`), different CDF, so the msac range diverged at the very first coefficient
13+symbol of the block and every symbol after it was read from a drifting state.
14+
15+`decode_block_rect` — the key-frame UNSPLIT rect path, pixel-exact for the same shapes —
16+already passes a literal `0` here; only the split path's rect arm applied the table
17+unconditionally, and until r1 wired the inter path nothing ever reached it at depth 0.
18+
19+## What changed
20+
21+- `crates/ec-av1/src/decode.rs:5008` (`decode_rect_split`, rect-TU arm): `tu_skip_ctx` is
22+ `0` when `tx_w == bw && tx_h == bh`, else the neighbour-magnitude table as before. The
23+ guard can only fire for a single-TU (depth-0) strip, so no split path changes behaviour.
24+- `crates/ec-av1/src/decode.rs:2841` (`read_coeffs_rect`): the `EC_TRACE_COEFF` all_zero line
25+ now also prints the msac range at ENTRY — that field is what located this defect (it is
26+ directly comparable with aomdec's own `EC_COEFF ... rng=` line, which prints pre-read).
27+- `crates/ec-av1/src/stream.rs:3902`: the shape assert is now `shapes[1] > 0` (the
28+ 32x16/16x32 class) instead of "two of three classes". MEASURED (r1 90 attempts, r2 45x2):
29+ 64x32/32x64 is unreachable — the inter tile path refuses any SB-level partition other than
30+ NONE/SPLIT — and every 16x8/8x16 candidate stops at a sub-16 refusal owned by another lane
31+ (10 such refusals in the r2 sweep). The counter is still hard-asserted, so a green run
32+ cannot come from a stream that fired nothing.
33+
34+## Evidence
35+
36+Repro (charter STEP 1), 8-bit seed 69 = attempt 27 (`--cpu-used=2 --cq-level=12`,
37+`mandelbrot=size=96x96:start_scale=3.38:end_scale=0.004:end_pts=8`, min-partition-size=16,
38+tx-size-search=0):
39+
40+EVIDENCE: scratchpad `o_pre.f5` vs `m_pre.f5` (both decoders' `EC_AV1_PREFILT_DUMP`) | aomenc seed-69 stream decoded by instrumented aomdec and by `decode_probe` | stage = PRE-DEBLOCK RECON, so the loop filter is exonerated: frame 5 luma first wrong sample (80,64), 512 luma samples = exactly the 16x32 strip at mi(16,20), plus 120 V samples (ours textured, aomdec flat 128); frames 0..4, 6, 7 byte-identical.
41+
42+EVIDENCE: scratchpad `o_tr8.txt` vs `m_tr.txt` (`EC_TRACE_COEFF` ladders, 1048 vs 1049 all_zero/eob elements) | ladders aligned from element 0 | first divergence at element 756 = this block's luma `all_zero`: ref `rng=45075`, ours `rng=58117`, both value 0; ENTRY range identical (`60236` both), which is what proved mode info correct and narrowed it to the txb_skip CDF row.
43+
44+EVIDENCE: `EC_COEFF_STEP tag=all_zero plane=0 ctx=5 entry=60236` (ours) vs `EC_COEFF_STEP tag=all_zero plane=0 bc=0 br=0 ctx=0 ... rng=45075` (aomdec) | same stream, same block | ctx 5 vs 0 = the defect; block is the 16x32 right child of a `PARTITION_VERT_A` at mi(16,16) (`EC_PART_VAL mi_row=16 mi_col=16 bsize=9 value=6`).
45+
46+EVIDENCE: scratchpad `o_pre.f*` vs `m_pre.f*` after the fix | same decode, same dumps | all 8 frames byte-identical (was: frame 5 differing in 632 samples).
47+
48+## Gates
49+
50+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib intra_rect_strip -j3 -- --nocapture`
51+-> `test result: ok. 2 passed; 0 failed` in 12.20s
52+(`$HOME/.cache/intrarect-gate-r2.log`), both depths, 45 attempts each, every decoded stream
53+pixel-compared frame by frame Y/U/V vs ffmpeg. Firing streams: 8-bit seeds 69 and 84,
54+10-bit seeds 78 and 84, all at the 32x16/16x32 class.
55+
56+NEGATIVE CONTROL for r1's move of `reject_residual` past the `is_inter` read: the same sweep
57+still refuses **8** attempts with "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
58+rectangular residual coding" — non-skip INTER rect strips are refused by name, not silently
59+decoded. Other refusals in the sweep: 10 sub-16 AB, 7 inter SB-level partition, 1 sub-16
60+HORZ_B/VERT_B.
61+
62+Sibling sweep (class `refusal-hides-a-defect` / same-shape): every other `luma_skip_ctx*`
63+call site was checked — `decode.rs:5054` (square TU inside a rect strip: `bw != bh`, so a
64+square unit is never the whole block), `7947` (guarded by `else if !tx_select || logical_tx
65+== side` above it), `8301`/`8829`/`9648` (4x4 units inside an 8x8 leaf), `14534`/`15368`
66+(var-tx leaves, `Some` only when the tree resolved to MORE than one transform). None can
67+reach the unit == block case. One defect, one site.
68+
69+Suite: `systemd-run --user --unit=intrarect-suite-r2 ... cargo test -p ec-av1 --lib -j3` ->
70+`test result: ok. 337 passed; 0 failed; 29 ignored; 0 measured; 0 filtered out; finished in
71+257.15s` (`$HOME/.cache/intrarect-suite-r2.log`) -- r1's two RED gates are the two that
72+flipped, nothing else moved.
73+
74+## Residue
75+
76+- deferred(orchestrator merge) — **this branch is NOT rebased onto main**. main has since
77+ merged lane-fiinter (intra blocks in inter frames read `use_filter_intra`) and lane-rect1d;
78+ `decode_intra_rect_in_inter` reads no `use_filter_intra` symbol, so on the merged tree an
79+ intra rect strip in an inter frame needs that read wired the same way the square arm now
80+ has it (this lane's gate encodes `--enable-filter-intra=0`, so its own streams never carry
81+ the symbol). Rebasing was not attempted here: r1's whole diff lives in the same
82+ `decode.rs` regions rectsplitx/fiinter rewrote, and a conflict resolution mid-round would
83+ have spent the budget the defect needed.
84+- deferred(the square intra-in-inter tx-split refusal in `read_block_tx_size`) — the SPLIT
85+ rect arm on the inter path stays wired but ungated (`--enable-tx-size-search=0`).
86+- deferred(lane-inter4's inter-side rect residual) — 64x32/32x64 and 16x8/8x16 intra strips
87+ on the inter path stay unreachable, see the assert note above.
88+- accepted — 1:4 strips refuse by name on this path.