forge
Explore
Log in

Don't you dare go Hollow

Merge main 7a47fc1 into lane-sb128b; restore the 13 gate recipes r2 blanket-rewrote to --min-partition-size=32

Browse files at this commit

4bf07dbbb225979cbc16fb73b01a85e1cd8e795aAhmet Kaan GümüşParent: e22a833a13d4a2
Conflict in decode.rs's skipped-block arm resolved by taking main's
(lane-hgkf r2) per-transform-unit prediction with its true_width guard and
SKIP_SPLIT_TX_HITS counter, and broadening its condition from
`tx_select && logical_tx < side` to `logical_tx < side`: at BLOCK_128X128 the
transform is TX_64X64 with no tx-depth syntax at all, so the lane's 128 arm
needs the same per-unit path. The counter keeps its narrow meaning (a READ
split depth).

TASK B root cause: the two inherited 10-bit rect/AB reds were an encoder
recipe defect, not a decoder one -- r2 rewrote --min-partition-size=16 to 32
in 13 gate recipes (main's value at all 13 call sites), which removes the
16-level the AB/rect gates assert. Reverted all 13; the lane's own two 128
gates keep their deliberate 32. Both gates now pass.
crates/ec-av1/src/decode.rsmodified+620 -128
@@ -1443,6 +1443,24 @@ pub(crate) fn palette_split_tx_hits() -> usize {
14431443 PALETTE_SPLIT_TX_HITS.with(|c| c.get())
14441444 }
14451445
1446+// lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform
1447+// and which are therefore predicted one transform unit at a time (a skipped
1448+// block codes no coefficients, so nothing else in the stream witnesses this
1449+// path -- only the pixels do).
1450+thread_local! {
1451+ static SKIP_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1452+}
1453+
1454+/// Current value of [`SKIP_SPLIT_TX_HITS`] (blocks, not units).
1455+pub fn skip_split_tx_hits() -> usize {
1456+ SKIP_SPLIT_TX_HITS.with(|c| c.get())
1457+}
1458+
1459+/// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt.
1460+pub fn reset_skip_split_tx_hits() {
1461+ SKIP_SPLIT_TX_HITS.with(|c| c.set(0));
1462+}
1463+
14461464 // lane-intrainter r1: intra blocks inside an INTER frame whose `tx_depth`
14471465 // symbol split their luma transform, bucketed by block side (8, 16, 32, 64) --
14481466 // the gate's proof that the lifted path actually ran, per size.
@@ -1917,6 +1935,22 @@ pub(crate) fn rect_leaf_coeff_hits() -> usize {
19171935 RECT_LEAF_COEFF_HITS.with(|c| c.get())
19181936 }
19191937
1938+// lane-intrarect r1: how many intra-coded HORZ/VERT strips decoded on the
1939+// INTER block path ([`decode_intra_rect_in_inter`]), per shape class --
1940+// [0] the superblock-level 64x32/32x64, [1] 32x16/16x32, [2] 16x8/8x16.
1941+// Every one of them was the named refusal "an intra-coded HORZ/VERT strip
1942+// needs rectangular intra prediction" before this round.
1943+thread_local! {
1944+ static INTRA_RECT_IN_INTER_HITS: std::cell::Cell<[usize; 3]> =
1945+ const { std::cell::Cell::new([0; 3]) };
1946+}
1947+
1948+/// Current value of [`INTRA_RECT_IN_INTER_HITS`] for one shape class
1949+/// (0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16).
1950+pub(crate) fn intra_rect_strip_in_inter_hits(class: usize) -> usize {
1951+ INTRA_RECT_IN_INTER_HITS.with(|c| c.get()[class])
1952+}
1953+
19201954 // lane-rectx r5: how many times a NON-strip `kf_y_mode` reader
19211955 // ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an
19221956 // above/left mode from the mi-exact map that DIFFERS from its coarse 16x16
@@ -2008,6 +2042,33 @@ thread_local! {
20082042 }
20092043
20102044 /// Current value of [`SB_RECT_HITS`].
2045+// lane-hgkf r1: the frame-edge partition bit, one level each. Slot 0 = a
2046+// 64-level gathered edge bit read as HORZ/VERT, 1 = the same bit read as
2047+// SPLIT, 2/3 = the 32-level pair. A gate asserting slot 0 or 2 proves the
2048+// non-SPLIT edge arm actually decoded (before this round the bit was read and
2049+// thrown away, so that arm was unreachable).
2050+thread_local! {
2051+ static EDGE_PART_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
2052+}
2053+
2054+/// Current value of [`EDGE_PART_HITS`].
2055+pub(crate) fn edge_part_hits() -> [usize; 4] {
2056+ EDGE_PART_HITS.with(|c| c.get())
2057+}
2058+
2059+/// Reset [`EDGE_PART_HITS`] (a gate counts one stream at a time).
2060+pub(crate) fn reset_edge_part_hits() {
2061+ EDGE_PART_HITS.with(|c| c.set([0; 4]));
2062+}
2063+
2064+fn bump_edge_part(slot: usize) {
2065+ EDGE_PART_HITS.with(|c| {
2066+ let mut h = c.get();
2067+ h[slot] += 1;
2068+ c.set(h);
2069+ });
2070+}
2071+
20112072 pub(crate) fn sb_rect_hits() -> usize {
20122073 SB_RECT_HITS.with(|c| c.get())
20132074 }
@@ -3359,7 +3420,7 @@ fn read_coeffs_rect(
33593420 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
33603421 if rect_trace {
33613422 eprintln!(
3362- "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} all_zero={} rng={}",
3423+ "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}",
33633424 all_zero as i32,
33643425 dec.debug_state().0
33653426 );
@@ -5730,6 +5791,16 @@ fn decode_rect_split(
57305791 let tu_mi = (mi_r + tu_row * (tx_h / MI), mi_c + tu_col * (tx_w / MI));
57315792 let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h);
57325793 let (col_off, row_off) = (tu_col * tx_w, tu_row * tx_h);
5794+ // lane-hgkf r1 (ported from lane-golomb 791d87a, unmerged):
5795+ // libaom clips `av1_foreach_transformed_block_in_plane` to
5796+ // `max_blocks_wide/high` (`mb_to_right_edge`/`mb_to_bottom_edge`,
5797+ // i.e. `mi_cols * 4` / `mi_rows * 4`): a transform unit whose
5798+ // TOP-LEFT sample falls outside the frame is never coded. We read
5799+ // coefficients for those phantom units and desynced the stream at
5800+ // the very next symbol.
5801+ if tu_px >= y.true_width || tu_py >= y.true_height {
5802+ continue;
5803+ }
57335804 // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a
57345805 // transform unit INSIDE a block, which is a different rule from
57355806 // the standalone-block table [`Reach::of`] applies -- and the
@@ -5779,7 +5850,19 @@ fn decode_rect_split(
57795850 // own (always DC_PRED) mode -- [`read_plane`] applies that
57805851 // for the square arm, so this one must too.
57815852 let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0];
5782- let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI);
5853+ // libaom `get_txb_ctx`: a LUMA transform that covers its whole
5854+ // block (`plane_bsize == txsize_to_bsize[tx_size]`, i.e. the
5855+ // unsplit depth-0 strip) reads txb_skip ctx 0 flat -- the
5856+ // neighbour-magnitude table is for a unit SMALLER than its
5857+ // block. [`decode_block_rect`]'s own unsplit read passes a
5858+ // literal 0 for the same reason; this arm applied the table
5859+ // unconditionally and desynced every depth-0 rect strip that
5860+ // reached it (lane-intrarect r2: ctx 5 where aomdec read 0).
5861+ let tu_skip_ctx = if tx_w == bw && tx_h == bh {
5862+ 0
5863+ } else {
5864+ neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI)
5865+ };
57835866 let mut coding = cdfs.txb(rect_set, fi_tx_row(m.mode, m.filter_intra));
57845867 let (tu_grid, tu_tx_type) = read_coeffs_rect(
57855868 dec,
@@ -5957,6 +6040,211 @@ fn decode_rect_split(
59576040 Ok(())
59586041 }
59596042
6043+/// One intra-coded HORZ/VERT strip on the INTER block path (lane-intrarect
6044+/// r1) -- the shape [`decode_inter_block`]'s intra arm refused by name
6045+/// because it predicts squares only. Every pixel here goes through the rect
6046+/// machinery the key-frame paths already prove: [`decode_rect_split`], which
6047+/// at `depth == 0` is the unsplit strip as a single transform unit and
6048+/// beyond it the per-unit walk of [`depth_to_tx_wh`].
6049+///
6050+/// What is genuinely different from [`decode_block_rect`] is the mode
6051+/// syntax: on an inter frame an intra block reads `y_mode[size_group]` and
6052+/// `uv_mode` (libaom `read_intra_block_mode_info`, decodemv.c:1065), never
6053+/// the key frame's `kf_y_mode` above/left pair. This mirrors the square
6054+/// intra-in-inter arm's own reads at the rect footprint, including its
6055+/// inherited gaps -- no `use_filter_intra` symbol (every inter gate recipe
6056+/// pins `--enable-filter-intra=0`; lane-fiinter owns that read for both the
6057+/// square and this arm) and a nonzero luma angle delta refused by name.
6058+///
6059+/// The strip's own neighbour records (luma per transform unit, chroma, skip
6060+/// grid, deblock grid) are [`decode_rect_split`]'s; the caller adds the
6061+/// inter-side bands and the mi map.
6062+#[allow(clippy::too_many_arguments)]
6063+fn decode_intra_rect_in_inter(
6064+ dec: &mut SymbolDecoder,
6065+ cdfs: &mut Cdfs,
6066+ neighbours: &mut Neighbours,
6067+ at: (usize, usize),
6068+ bw: usize,
6069+ bh: usize,
6070+ skip: bool,
6071+ allow_screen_content_tools: bool,
6072+ y: &mut PlaneBuf,
6073+ u: &mut PlaneBuf,
6074+ v: &mut PlaneBuf,
6075+ base_q_idx: u8,
6076+) -> Result<()> {
6077+ // `at` is in MI units (the inter path's own unit since lane-inter4);
6078+ // `(r, c)` is the enclosing SUB cell the SUB-granular neighbour bands
6079+ // below are still keyed by.
6080+ let (mi_r, mi_c) = at;
6081+ let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI));
6082+ // `size_group_lookup` (libaom common_data.h) and `bsize_to_tx_size_cat`
6083+ // (blockd.h) for the three 2:1 strip shapes: BLOCK_16X8 -> group 1 /
6084+ // cat 1, BLOCK_32X16 -> 2 / 2, BLOCK_64X32 -> 3 / 3 (the rectsplitx
6085+ // finding -- the category is NOT the same for every strip size).
6086+ // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so
6087+ // it is refused by name rather than read from the wrong CDF row.
6088+ let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {
6089+ (8, 16) => (1usize, 1usize),
6090+ (16, 32) => (2, 2),
6091+ (32, 64) => (3, 3),
6092+ _ => {
6093+ return Err(unsupported(
6094+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path",
6095+ ))
6096+ }
6097+ };
6098+ // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is
6099+ // consumed for square blocks only, so a strip in a screen-content frame
6100+ // would skip symbols the encoder wrote.
6101+ if allow_screen_content_tools {
6102+ return Err(unsupported(
6103+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax \
6104+ is consumed for square blocks only)",
6105+ ));
6106+ }
6107+ let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
6108+ if mode >= 13 {
6109+ return Err(unsupported(
6110+ "an intra mode this decoder does not code (round 2)",
6111+ ));
6112+ }
6113+ // lane-angleinter (merged on main for the square intra-in-inter arm):
6114+ // the delta is read off `angle_delta_cdf[mode - V_PRED]` and feeds the
6115+ // directional predictor; this arm refused a nonzero one before the merge.
6116+ let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
6117+ read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED])
6118+ } else {
6119+ 0
6120+ };
6121+ if angle_delta_y != 0 {
6122+ INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1));
6123+ }
6124+ // `is_cfl_allowed` (spec 5.11.5) caps CFL at 32x32, so the
6125+ // superblock-level strip reads the no-CFL alphabet -- the same split
6126+ // [`read_intra_mode_rect`] makes for [`decode_block_rect64`].
6127+ let cfl_allowed = bw.max(bh) <= 32;
6128+ let uv_mode = if cfl_allowed {
6129+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
6130+ } else {
6131+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
6132+ };
6133+ if (9..=12).contains(&uv_mode) {
6134+ SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1));
6135+ }
6136+ let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED {
6137+ Some(read_cfl_alphas(dec, cdfs))
6138+ } else {
6139+ None
6140+ };
6141+ let uv_predict_mode = if uv_mode == UV_CFL_PRED {
6142+ DC_PRED
6143+ } else {
6144+ uv_mode
6145+ };
6146+ let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
6147+ DIRECTIONAL_UV_HITS.with(|h| h.set(h.get() + 1));
6148+ read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
6149+ } else {
6150+ 0
6151+ };
6152+ if angle_delta_uv != 0 {
6153+ UV_ANGLE_DELTA_HITS.with(|h| h.set(h.get() + 1));
6154+ INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|h| h.set(h.get() + 1));
6155+ }
6156+ // lane-fiinter (merged on main for the square intra-in-inter arm):
6157+ // `read_filter_intra_mode_info` is the tail of
6158+ // `read_intra_block_mode_info`, after the palette syntax (refused whole
6159+ // above for this shape), and `av1_filter_intra_allowed_bsize` admits the
6160+ // 2:1 strips with both sides <= 32 -- their own CDF rows
6161+ // ([`filter_intra_size_class_rect`]).
6162+ let mut filter_intra = None;
6163+ if mode == DC_PRED
6164+ && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)
6165+ && let Some(class) = filter_intra_size_class_rect(bw, bh)
6166+ && dec.symbol(&mut cdfs.filter_intra[class]) != 0
6167+ {
6168+ FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1));
6169+ INTRA_IN_INTER_FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1));
6170+ filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode));
6171+ }
6172+ // The intra-edge filter type is the NEIGHBOUR's mode (libaom
6173+ // `get_filt_type`), luma's off the luma neighbours and chroma's off the
6174+ // chroma ones -- [`decode_block_rect`]'s own pair.
6175+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
6176+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
6177+ if smooth_neighbor {
6178+ SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1));
6179+ }
6180+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
6181+ let depth = if TX_SELECT_INTER.with(std::cell::Cell::get) {
6182+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
6183+ match tx_cat {
6184+ 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]),
6185+ 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]),
6186+ _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]),
6187+ }
6188+ } else {
6189+ 0
6190+ };
6191+ if depth != 0 {
6192+ TX_DEPTH_HITS.with(|h| h.set(h.get() + 1));
6193+ // merge b51719f+lane-intrarect (class merge-cross-product-defect):
6194+ // main's 10-bit `split_transform_intra_block` gate reaches this arm
6195+ // with a nonzero tx depth, and the split rect-TU walk mis-decodes it
6196+ // (2340 luma samples off at seed 51; refusing here restores that gate
6197+ // while the depth-0 strip the lane proved keeps decoding). The lane's
6198+ // own gate never exercised a split strip.
6199+ return Err(unsupported(
6200+ "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame",
6201+ ));
6202+ }
6203+ let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
6204+ let modes = RectStripModes {
6205+ skip,
6206+ mode,
6207+ angle_delta_y,
6208+ uv_predict_mode,
6209+ angle_delta_uv,
6210+ alpha,
6211+ filter_intra,
6212+ smooth_neighbor,
6213+ smooth_neighbor_uv,
6214+ // screen-content frames are refused whole above, so this strip can
6215+ // carry no palette.
6216+ palette_y: None,
6217+ palette_uv: None,
6218+ };
6219+ decode_rect_split(
6220+ dec,
6221+ cdfs,
6222+ neighbours,
6223+ (mi_r, mi_c),
6224+ bw,
6225+ bh,
6226+ tx_w,
6227+ tx_h,
6228+ &modes,
6229+ y,
6230+ u,
6231+ v,
6232+ base_q_idx,
6233+ REDUCED_TX_SET_INTER.with(std::cell::Cell::get),
6234+ )?;
6235+ let class = match bw.max(bh) {
6236+ 64 => 0,
6237+ 32 => 1,
6238+ _ => 2,
6239+ };
6240+ INTRA_RECT_IN_INTER_HITS.with(|h| {
6241+ let mut v = h.get();
6242+ v[class] += 1;
6243+ h.set(v);
6244+ });
6245+ Ok(())
6246+}
6247+
59606248 /// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip
59616249 /// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's
59626250 /// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/
@@ -7966,6 +8254,26 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
79668254 /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
79678255 /// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written
79688256 /// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`.
8257+/// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of
8258+/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) --
8259+/// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE).
8260+fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) {
8261+ use std::io::Write;
8262+ if let Ok(path) = std::env::var(var)
8263+ && let Ok(mut f) = std::fs::File::create(format!("{path}.f0"))
8264+ {
8265+ 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))] {
8266+ for row in 0..h {
8267+ let mut bytes = Vec::with_capacity(w * 2);
8268+ for &s in &p.data[row * p.width..][..w] {
8269+ bytes.extend_from_slice(&s.to_le_bytes());
8270+ }
8271+ let _ = f.write_all(&bytes);
8272+ }
8273+ }
8274+ }
8275+}
8276+
79698277 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
79708278 use std::io::Write;
79718279 if let Ok(path) = std::env::var(var)
@@ -8111,6 +8419,7 @@ impl PlaneBuf {
81118419 /// via [`Self::edges_rect`] and [`crate::intra::predict`]'s own
81128420 /// already-rect-capable `(bw, bh)` pair.
81138421 #[allow(clippy::too_many_arguments)]
8422+ #[track_caller]
81148423 fn reconstruct_rect(
81158424 &mut self,
81168425 x: usize,
@@ -8169,6 +8478,16 @@ impl PlaneBuf {
81698478 }
81708479 prediction
81718480 };
8481+ // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
8482+ // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
8483+ if std::env::var_os("EC_PRED").is_some() {
8484+ let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
8485+ let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();
8486+ let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();
8487+ eprintln!(
8488+ "@{} 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()
8489+ );
8490+ }
81728491 for row in 0..bh {
81738492 for col in 0..bw {
81748493 let idx = row * bw + col;
@@ -8188,6 +8507,7 @@ impl PlaneBuf {
81888507 /// nudges the prediction by [`cfl_scaled`]'s per-sample amount before the
81898508 /// residual is added — `av1_cfl_predict_block`'s own clip-then-add-residual
81908509 /// order (cfl.c).
8510+ #[track_caller]
81918511 fn reconstruct(
81928512 &mut self,
81938513 x: usize,
@@ -8251,6 +8571,16 @@ impl PlaneBuf {
82518571 }
82528572 prediction
82538573 };
8574+ // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
8575+ // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
8576+ if std::env::var_os("EC_PRED").is_some() {
8577+ let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
8578+ let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
8579+ let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
8580+ eprintln!(
8581+ "@{} 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()
8582+ );
8583+ }
82548584 for row in 0..side {
82558585 for col in 0..side {
82568586 let idx = row * side + col;
@@ -8586,39 +8916,75 @@ fn decode_block(
85868916 if skip {
85878917 // A skipped block codes no residual syntax at all (spec 5.11.34):
85888918 // straight prediction, on every plane.
8589- // Intra prediction is per TRANSFORM unit even with nothing coded
8590- // (libaom `predict_and_reconstruct_intra_block` runs inside the
8591- // transform-block loop), so a block whose transform is smaller than
8592- // itself predicts unit by unit here too. `n_axis`/`cn == 1` is the
8593- // whole-block call this always made, unchanged; at 128 both are
8594- // forced >1 (`max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64 and
8595- // its uv transform TX_32X32), lane-sb128b r2.
8596- let n_axis = side / logical_tx;
8597- for tu_row in 0..n_axis {
8598- for tu_col in 0..n_axis {
8599- let (tu_px, tu_py) = (px + tu_col * logical_tx, py + tu_row * logical_tx);
8600- let tu_r = if n_axis == 1 {
8601- reach
8602- } else {
8603- tu_reach(
8604- side, side,
8605- tu_col * logical_tx, tu_row * logical_tx, logical_tx,
8606- reach, px, py, y.width, y.height,
8607- )
8608- };
8609- y.reconstruct(
8610- tu_px,
8611- tu_py,
8612- logical_tx,
8613- mode,
8614- angle_delta_y,
8615- tu_r,
8616- &vec![0i32; logical_tx * logical_tx],
8617- None,
8618- filter_intra,
8619- smooth_neighbor,
8620- );
8919+ //
8920+ // lane-hgkf r2: an intra block's `tx_depth` is read whether or not it
8921+ // is skipped (only an INTER skip forces the largest transform), and
8922+ // spec 7.11.2 / libaom `predict_and_reconstruct_intra_block` predicts
8923+ // ONE TRANSFORM UNIT AT A TIME -- each unit's edges are the units
8924+ // already written left/above of it inside this same block. Predicting
8925+ // the whole `side`x`side` at once gives a different (uniformly off by
8926+ // ~1) answer, which is exactly the residue this lane was chasing.
8927+ // The palette/intrabc override path keeps the single-call shape (its
8928+ // per-TU windowing is the non-skip loop's own `palette_y_buf` slice,
8929+ // untested for skip and unreachable in these streams).
8930+ // lane-sb128b r2: a 128x128 block's transform is TX_64X64 even with
8931+ // `tx_select` off (`max_txsize_rect_lookup[BLOCK_128X128]`), so the
8932+ // per-unit prediction is keyed on the transform being smaller than
8933+ // the block, not on the tx-depth syntax. The counter keeps lane-hgkf's
8934+ // narrower meaning (a READ split tx depth).
8935+ let split_tx_skip =
8936+ logical_tx < side && palette_y_buf.is_none() && intrabc_bufs.is_none();
8937+ if split_tx_skip {
8938+ if tx_select {
8939+ SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
8940+ }
8941+ let n_axis = side / logical_tx;
8942+ for tu_row in 0..n_axis {
8943+ for tu_col in 0..n_axis {
8944+ let tu_px = px + tu_col * logical_tx;
8945+ let tu_py = py + tu_row * logical_tx;
8946+ if tu_px >= y.true_width || tu_py >= y.true_height {
8947+ continue;
8948+ }
8949+ let tu_reach = tu_reach(
8950+ side,
8951+ side,
8952+ tu_col * logical_tx,
8953+ tu_row * logical_tx,
8954+ logical_tx,
8955+ reach,
8956+ px,
8957+ py,
8958+ y.width,
8959+ y.height,
8960+ );
8961+ y.reconstruct(
8962+ tu_px,
8963+ tu_py,
8964+ logical_tx,
8965+ mode,
8966+ angle_delta_y,
8967+ tu_reach,
8968+ &vec![0i32; logical_tx * logical_tx],
8969+ None,
8970+ filter_intra,
8971+ smooth_neighbor,
8972+ );
8973+ }
86218974 }
8975+ } else {
8976+ y.reconstruct(
8977+ px,
8978+ py,
8979+ side,
8980+ mode,
8981+ angle_delta_y,
8982+ reach,
8983+ &vec![0i32; side * side],
8984+ None,
8985+ filter_intra,
8986+ smooth_neighbor,
8987+ );
86228988 }
86238989 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
86248990 let cn = (chroma_side / chroma_tx).max(1);
@@ -8777,6 +9143,12 @@ fn decode_block(
87779143 );
87789144 let tu_px = px + tu_col * logical_tx;
87799145 let tu_py = py + tu_row * logical_tx;
9146+ // Same libaom clip as `decode_rect_split`'s loop above; a
9147+ // square block only hangs off the frame when the frame's mi
9148+ // dimensions are odd at the block's own level.
9149+ if tu_px >= y.true_width || tu_py >= y.true_height {
9150+ continue;
9151+ }
87809152 let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0];
87819153 // A transform unit inside a block is NOT a block at that
87829154 // position (lane-palette2 r12): `Reach::of` granted the
@@ -9070,18 +9442,59 @@ fn decode_leaf8(
90709442 let (cpx, cpy) = (px / 2, py / 2);
90719443 let (luma_grid, u_grid, v_grid);
90729444 if skip {
9073- y.reconstruct(
9074- px,
9075- py,
9076- 8,
9077- mode,
9078- angle_delta_y,
9079- reach,
9080- &vec![0i32; 64],
9081- None,
9082- filter_intra,
9083- smooth_neighbor,
9084- );
9445+ // lane-hgkf r2 (same shape as `decode_block`'s own skip branch): an
9446+ // 8x8 leaf whose `tx_depth` resolved to TX_4X4 predicts FOUR 4x4
9447+ // transform units, each off the units already written left/above of
9448+ // it inside this same leaf -- an intra block's transform size is read
9449+ // whether or not it is skipped, and spec 7.11.2 predicts per unit.
9450+ if resolved == 4 {
9451+ SKIP_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
9452+ for tu_row in 0..2 {
9453+ for tu_col in 0..2 {
9454+ let (tu_px, tu_py) = (px + tu_col * 4, py + tu_row * 4);
9455+ if tu_px >= y.true_width || tu_py >= y.true_height {
9456+ continue;
9457+ }
9458+ let tu_reach = tu_reach(
9459+ 8,
9460+ 8,
9461+ tu_col * 4,
9462+ tu_row * 4,
9463+ 4,
9464+ reach,
9465+ px,
9466+ py,
9467+ y.width,
9468+ y.height,
9469+ );
9470+ y.reconstruct(
9471+ tu_px,
9472+ tu_py,
9473+ 4,
9474+ mode,
9475+ angle_delta_y,
9476+ tu_reach,
9477+ &vec![0i32; 16],
9478+ None,
9479+ filter_intra,
9480+ smooth_neighbor,
9481+ );
9482+ }
9483+ }
9484+ } else {
9485+ y.reconstruct(
9486+ px,
9487+ py,
9488+ 8,
9489+ mode,
9490+ angle_delta_y,
9491+ reach,
9492+ &vec![0i32; 64],
9493+ None,
9494+ filter_intra,
9495+ smooth_neighbor,
9496+ );
9497+ }
90859498 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
90869499 u.reconstruct(
90879500 cpx,
@@ -12243,28 +12656,23 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1224312656 }
1224412657 p
1224512658 } else {
12246- // lane-golomb r1 (class `parsed-then-discarded`): the gathered
12247- // bit is the answer, not a formality -- libaom's
12248- // `ec_read_partition_impl` returns `PARTITION_HORZ` (resp.
12249- // `PARTITION_VERT`) when it reads 0, and only `PARTITION_SPLIT`
12250- // when it reads 1. Forcing SPLIT here desynced the last
12251- // superblock row of every frame whose height is not a multiple
12252- // of 64 -- the ReelB head (3840x1608) diverges at
12253- // mi_row=400 mi_col=0, the first block of that row.
12659+ // lane-hgkf r1 (class `parsed-then-discarded`, same finding as
12660+ // the unmerged lane-golomb r1): the gathered bit IS the
12661+ // partition -- libaom `ec_read_partition_impl` returns
12662+ // PARTITION_HORZ (resp. VERT) for 0 and only SPLIT for 1.
12663+ // Forcing SPLIT desynced the last superblock row of every
12664+ // frame whose height is not a multiple of 64: the ReelB key frames (3840x1608) diverge at mi_row=400 mi_col=0,
12665+ // the first block of that row.
1225412666 match (has_cols, has_rows) {
1225512667 (true, false) => {
12256- if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)) == 1 {
12257- PARTITION_SPLIT
12258- } else {
12259- PARTITION_HORZ
12260- }
12668+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE));
12669+ bump_edge_part(b.min(1) as usize);
12670+ if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
1226112671 }
1226212672 (false, true) => {
12263- if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)) == 1 {
12264- PARTITION_SPLIT
12265- } else {
12266- PARTITION_VERT
12267- }
12673+ let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE));
12674+ bump_edge_part(b.min(1) as usize);
12675+ if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
1226812676 }
1226912677 _ => PARTITION_SPLIT,
1227012678 }
@@ -12322,26 +12730,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1232212730 }
1232312731 p
1232412732 } else {
12733+ // lane-hgkf r1: the 32-level frame-edge bit is the
12734+ // partition too (same libaom reader as the
12735+ // superblock level above).
1232512736 match (has_cols32, has_rows32) {
1232612737 (true, false) => {
12327- // lane-golomb r1 (class `parsed-then-discarded`): the gathered
12328- // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
12329- // (libaom `ec_read_partition_impl`).
12330- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 {
12331- PARTITION_SPLIT
12332- } else {
12333- PARTITION_HORZ
12334- }
12738+ let b = dec.symbol_fixed(&gather(
12739+ &cdfs.partition_w32[ctx32],
12740+ VERT_ALIKE,
12741+ ));
12742+ bump_edge_part(2 + b.min(1) as usize);
12743+ if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ }
1233512744 }
1233612745 (false, true) => {
12337- // lane-golomb r1 (class `parsed-then-discarded`): the gathered
12338- // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT
12339- // (libaom `ec_read_partition_impl`).
12340- if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 {
12341- PARTITION_SPLIT
12342- } else {
12343- PARTITION_VERT
12344- }
12746+ let b = dec.symbol_fixed(&gather(
12747+ &cdfs.partition_w32[ctx32],
12748+ HORZ_ALIKE,
12749+ ));
12750+ bump_edge_part(2 + b.min(1) as usize);
12751+ if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT }
1234512752 }
1234612753 _ => PARTITION_SPLIT,
1234712754 }
@@ -12802,6 +13209,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1280213209 HORZ_ALIKE,
1280313210 ))
1280413211 };
13212+ // lane-hgkf r1: slots 2/3 of
13213+ // [`EDGE_PART_HITS`], the gate's proof the
13214+ // non-SPLIT edge arm actually decoded.
13215+ bump_edge_part(if edge_split == 1 { 3 } else { 2 });
1280513216 if edge_split == 0 {
1280613217 // lane-oddh r1: the strip IS decodable
1280713218 // -- libaom's `decode_partition` codes
@@ -12968,22 +13379,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1296813379 tx_select,
1296913380 reduced_tx_set,
1297013381 )?;
12971- decode_block_rect(
12972- &mut dec,
12973- &mut cdfs,
12974- &mut neighbours,
12975- (at32.0 + 1, at32.1),
12976- 32,
12977- 16,
12978- &mut y,
12979- &mut u,
12980- &mut v,
12981- enable_filter_intra,
12982- allow_screen_content_tools,
12983- base_q_idx,
12984- tx_select,
12985- reduced_tx_set,
12986- )?;
13382+ // lane-hgkf r1: at the frame edge only the first half of the strip is
13383+ // coded (libaom `decode_partition` guards the second half with the same
13384+ // test that made this partition non-square).
13385+ if has_rows32 {
13386+ decode_block_rect(
13387+ &mut dec,
13388+ &mut cdfs,
13389+ &mut neighbours,
13390+ (at32.0 + 1, at32.1),
13391+ 32,
13392+ 16,
13393+ &mut y,
13394+ &mut u,
13395+ &mut v,
13396+ enable_filter_intra,
13397+ allow_screen_content_tools,
13398+ base_q_idx,
13399+ tx_select,
13400+ reduced_tx_set,
13401+ )?;
13402+ }
1298713403 }
1298813404 PARTITION_VERT => {
1298913405 // lane-intradisp r1: mirror of PARTITION_HORZ
@@ -13004,22 +13420,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1300413420 tx_select,
1300513421 reduced_tx_set,
1300613422 )?;
13007- decode_block_rect(
13008- &mut dec,
13009- &mut cdfs,
13010- &mut neighbours,
13011- (at32.0, at32.1 + 1),
13012- 16,
13013- 32,
13014- &mut y,
13015- &mut u,
13016- &mut v,
13017- enable_filter_intra,
13018- allow_screen_content_tools,
13019- base_q_idx,
13020- tx_select,
13021- reduced_tx_set,
13022- )?;
13423+ // lane-hgkf r1: at the frame edge only the first half of the strip is
13424+ // coded (libaom `decode_partition` guards the second half with the same
13425+ // test that made this partition non-square).
13426+ if has_cols32 {
13427+ decode_block_rect(
13428+ &mut dec,
13429+ &mut cdfs,
13430+ &mut neighbours,
13431+ (at32.0, at32.1 + 1),
13432+ 16,
13433+ 32,
13434+ &mut y,
13435+ &mut u,
13436+ &mut v,
13437+ enable_filter_intra,
13438+ allow_screen_content_tools,
13439+ base_q_idx,
13440+ tx_select,
13441+ reduced_tx_set,
13442+ )?;
13443+ }
1302313444 }
1302413445 PARTITION_HORZ_A => {
1302513446 // lane-part32 r1: two 16x16 squares on top +
@@ -13604,6 +14025,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1360414025 // that isolate whether a decode-order frame's mismatch already exists
1360514026 // in reconstruction (this dump) vs is introduced by the loop filter
1360614027 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
14028+ dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1360714029 if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
1360814030 use std::io::Write;
1360914031 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -13647,8 +14069,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1364714069 // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
1364814070 // dump above these bisect WHICH filter stage introduced a mismatch.
1364914071 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
14072+ dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1365014073 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
1365114074 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
14075+ dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1365214076 apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);
1365314077
1365414078 let (fw, fh) = (frame_width as usize, frame_height as usize);
@@ -15288,18 +15712,6 @@ fn decode_inter_block(
1528815712 let whole_sb = side == 64 && write_w == 64 && write_h == 64;
1528915713 maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip);
1529015714 maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip);
15291- // lane-warp r5: see `reject_residual` -- a square-block decode of a
15292- // HORZ_B strip is symbol-exact only for `skip` (no residual, no
15293- // motion_mode/warp symbol), so gate here before any further read.
15294- if reject_residual && !skip && !rect_inter_residual_supported(write_w, write_h) {
15295- if std::env::var_os("EC_AV1_RECT_DUMP").is_some() {
15296- eprintln!("EC_RECT_REFUSE mi_row={rmi} mi_col={cmi} w={write_w} h={write_h} side={side}");
15297- }
15298- return Err(unsupported(
15299- "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
15300- ));
15301- }
15302-
1530315715 let (has_above, has_left) = (
1530415716 rmi > neighbours.tile_row0_mi,
1530515717 cmi > neighbours.tile_col0_mi,
@@ -15315,6 +15727,29 @@ fn decode_inter_block(
1531515727 dec.debug_state().0
1531615728 );
1531715729 }
15730+ // lane-warp r5: see `reject_residual` -- a square-block decode of a
15731+ // HORZ_B strip is symbol-exact only for `skip` (no residual, no
15732+ // motion_mode/warp symbol). lane-intrarect r1 MOVED this gate from just
15733+ // after the `skip` read to here, past `is_inter` (class
15734+ // [[refusal-short-circuits-its-own-code]]: at the old place it refused
15735+ // 24/24 attempts of this lane's own gate before the intra arm below
15736+ // could run). An INTRA strip with its true `write_w`x`write_h` footprint
15737+ // now codes its residual rectangularly ([`decode_intra_rect_in_inter`]);
15738+ // an INTER one, and a strip decoded with square dimensions anyway, still
15739+ // cannot.
15740+ // merge b51719f+lane-intrarect: main's `rect_inter_residual_supported`
15741+ // term stays -- lane-inter4's 16x8/8x16 inter leaves DO code a
15742+ // rectangular residual, and the lane's condition (written before that
15743+ // landed) refused every one of them.
15744+ if reject_residual
15745+ && !skip
15746+ && !rect_inter_residual_supported(write_w, write_h)
15747+ && (is_inter || (write_w == side && write_h == side))
15748+ {
15749+ return Err(unsupported(
15750+ "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
15751+ ));
15752+ }
1531815753 if std::env::var_os("EC_AV1_TELL").is_some() {
1531915754 eprintln!(
1532015755 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
@@ -17326,10 +17761,64 @@ fn decode_inter_block(
1732617761 // already-square-predicted buffer). Named refusal instead of a
1732717762 // silently wrong square-shaped intra prediction.
1732817763 if write_w != side || write_h != side {
17329- return Err(unsupported(
17330- "an intra-coded HORZ/VERT strip needs rectangular intra prediction \
17331- this decoder does not code yet",
17332- ));
17764+ // lane-intrarect r1: the strip decodes through its own rect
17765+ // machinery ([`decode_intra_rect_in_inter`] -> the key-frame
17766+ // paths' [`decode_rect_split`]) instead of refusing. That call
17767+ // already writes everything the shared tail below would for a
17768+ // square block EXCEPT the inter-side bands and the mi map, so
17769+ // this arm returns rather than falling through (a second
17770+ // `record_rect`/`fill_lf_grid_rect` at block granularity would
17771+ // overwrite the per-transform-unit records it just made).
17772+ decode_intra_rect_in_inter(
17773+ dec,
17774+ cdfs,
17775+ neighbours,
17776+ at,
17777+ write_w,
17778+ write_h,
17779+ skip,
17780+ allow_screen_content_tools,
17781+ y,
17782+ u,
17783+ v,
17784+ base_q_idx,
17785+ )?;
17786+ // merge b51719f+lane-intrarect: `at` is in MI units on this path
17787+ // (lane-inter4), so the strip's mi origin is `at` itself -- the
17788+ // lane's `r * SUB_MI` re-derivation would snap a sub-SUB strip to
17789+ // its enclosing 16-px cell.
17790+ let (mi_r0, mi_c0) = (rmi, cmi);
17791+ for dr in 0..write_h / MI {
17792+ for dc in 0..write_w / MI {
17793+ grid.set(
17794+ mi_r0 + dr,
17795+ mi_c0 + dc,
17796+ MiInfo {
17797+ is_inter: false,
17798+ ref_frame: -1,
17799+ ref_frame1: None,
17800+ mv1: None,
17801+ mv: (0, 0),
17802+ is_new_mv: false,
17803+ size: write_w / MI,
17804+ size_h: write_h / MI,
17805+ is_global_mv0: false,
17806+ is_global_mv1: false,
17807+ },
17808+ );
17809+ }
17810+ }
17811+ neighbours.record_inter_rect_mi(
17812+ at,
17813+ write_w / MI,
17814+ write_h / MI,
17815+ skip,
17816+ false,
17817+ 0,
17818+ [3, 3],
17819+ skip_mode,
17820+ );
17821+ return Ok(());
1733317822 }
1733417823 let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]);
1733517824 if mode >= 13 {
@@ -21338,6 +21827,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2133821827 // that isolate whether a decode-order frame's mismatch already exists
2133921828 // in reconstruction (this dump) vs is introduced by the loop filter
2134021829 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
21830+ dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2134121831 if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
2134221832 use std::io::Write;
2134321833 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -21364,8 +21854,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2136421854 // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
2136521855 // dump above these bisect WHICH filter stage introduced a mismatch.
2136621856 dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
21857+ dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2136721858 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
2136821859 dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
21860+ dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2136921861 apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);
2137021862
2137121863 let motion_field = build_motion_field(
crates/ec-av1/src/refusal_inventory.rsmodified+9 -1
@@ -73,7 +73,15 @@ const REFUSALS: &[&str] = &[
7373 "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)",
7474 "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)",
7575 "an intra mode this decoder does not code (round 2)",
76- "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
76+ // lane-intrarect r1 lifted the whole-shape refusal that stood here (the
77+ // inter path's intra arm now routes 2:1 strips through `decode_rect_split`);
78+ // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the
79+ // size-group/category diagonal the 2:1 shapes share.
80+ "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path",
81+ "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame",
82+ // The same arm's screen-content gate: palette/intrabc syntax is consumed
83+ // for square blocks only, so a strip in such a frame would skip symbols.
84+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
7785 "warp prediction with a scaled reference (superres, unimplemented)",
7886 "an 8x8 partition leaf under a scaled reference (superres, unimplemented)",
7987 "a motion_mode symbol for a block shape with no CDF row here",
crates/ec-av1/src/stream.rsmodified+505 -13
@@ -2788,7 +2788,7 @@ mod tests {
27882788 "--enable-tx-size-search=0",
27892789 "--enable-cdef=1",
27902790 "--enable-restoration=1",
2791- "--min-partition-size=32",
2791+ "--min-partition-size=16",
27922792 "--max-partition-size=32",
27932793 "--enable-palette=0",
27942794 "--enable-intrabc=0",
@@ -3218,7 +3218,7 @@ mod tests {
32183218 "--enable-cdef=0",
32193219 "--enable-restoration=0",
32203220 "--max-partition-size=32",
3221- "--min-partition-size=32",
3221+ "--min-partition-size=16",
32223222 "--enable-palette=0",
32233223 "--enable-intrabc=0",
32243224 "--enable-cfl-intra=0",
@@ -3277,7 +3277,7 @@ mod tests {
32773277 "--enable-paeth-intra=0",
32783278 "--enable-tx-size-search=0",
32793279 "--max-partition-size=32",
3280- "--min-partition-size=32",
3280+ "--min-partition-size=16",
32813281 "--enable-palette=0",
32823282 "--enable-intrabc=0",
32833283 "--enable-cfl-intra=0",
@@ -3351,7 +3351,7 @@ mod tests {
33513351 "--enable-cdef=0",
33523352 "--enable-restoration=0",
33533353 "--max-partition-size=32",
3354- "--min-partition-size=32",
3354+ "--min-partition-size=16",
33553355 "--enable-palette=0",
33563356 "--enable-intrabc=0",
33573357 "--enable-cfl-intra=0",
@@ -4273,6 +4273,331 @@ mod tests {
42734273 tx_select_inter_gate(10);
42744274 }
42754275
4276+ /// lane-intrarect r1's decisive gate: a real aomenc INTER sequence whose
4277+ /// hard mid-GOP content cut makes aomenc code INTRA blocks inside inter
4278+ /// frames, with rect partitions ON so those intra blocks land on
4279+ /// HORZ/VERT strip shapes. Every such block was the named refusal "an
4280+ /// intra-coded HORZ/VERT strip needs rectangular intra prediction this
4281+ /// decoder does not code yet" until this round; they now decode through
4282+ /// the same `decode_rect_split` machinery the key-frame rect paths use.
4283+ ///
4284+ /// Hard-asserts per-shape counters (`intra_rect_strip_in_inter_hits`:
4285+ /// 0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16) summed over the
4286+ /// attempts that were actually pixel-compared -- at least TWO of the
4287+ /// three shape classes must fire, so a green run cannot come from one
4288+ /// lucky size. A decode that succeeds is ALWAYS pixel-compared (class
4289+ /// [[gate-skips-on-its-own-failure]]); exhausting every attempt without
4290+ /// two shapes is a FAILURE, never a SKIP.
4291+ #[test]
4292+ fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact() {
4293+ intra_rect_in_inter_gate(8);
4294+ }
4295+
4296+ /// The 10-bit arm (both of the user's films are `yuv420p10le`).
4297+ #[test]
4298+ fn a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact_10bit() {
4299+ intra_rect_in_inter_gate(10);
4300+ }
4301+
4302+ fn intra_rect_in_inter_gate(bit_depth: u32) {
4303+ const NAME: &str = "a_real_aomenc_inter_sequence_with_an_intra_rect_strip_decodes_pixel_exact";
4304+ if !have_ffmpeg() {
4305+ eprintln!("SKIP {NAME}: no ffmpeg");
4306+ return;
4307+ }
4308+ if !have_aomenc() {
4309+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4310+ return;
4311+ }
4312+ let (width, height, frame_count) = (96usize, 96usize, 8usize);
4313+ let mut refusals: Vec<String> = Vec::new();
4314+ let mut uncounted_exact = 0u32;
4315+ let mut compared = 0u32;
4316+ let mut shapes = [0usize; 3];
4317+ for attempt in 0..45u32 {
4318+ let seed = 42 + attempt;
4319+ // mandelbrot's fractal detail plus a HARD cut at frame 4: half
4320+ // the picture becomes a flat white box, which no motion vector
4321+ // can predict, so aomenc's RD codes those blocks INTRA inside an
4322+ // inter frame. The box's vertical edge at x=48 is what makes the
4323+ // partition search reach for HORZ/VERT strips there.
4324+ // A FAST ZOOM: `end_scale`/`end_pts` make mandelbrot rush
4325+ // through its own zoom, so consecutive frames share almost no
4326+ // content and aomenc's RD codes blocks INTRA inside INTER frames
4327+ // (`--kf-min-dist=1000` forbids a new key frame). That is the
4328+ // only way a real encoder reaches this decoder's intra-in-inter
4329+ // arm; a slowly-evolving source codes every rect strip inter.
4330+ let source = format!(
4331+ "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25",
4332+ 5.0 - f64::from(attempt) * 0.06
4333+ );
4334+ let y4m = Command::new("ffmpeg")
4335+ .args([
4336+ "-v",
4337+ "error",
4338+ "-f",
4339+ "lavfi",
4340+ "-i",
4341+ &source,
4342+ "-vf",
4343+ "hue=s=0",
4344+ "-pix_fmt",
4345+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
4346+ "-strict",
4347+ "-1",
4348+ "-t",
4349+ "0.32",
4350+ "-f",
4351+ "yuv4mpegpipe",
4352+ "-strict",
4353+ "-1",
4354+ "-",
4355+ ])
4356+ .stdin(Stdio::null())
4357+ .stdout(Stdio::piped())
4358+ .stderr(Stdio::piped())
4359+ .output()
4360+ .expect("ffmpeg failed to run");
4361+ assert!(
4362+ y4m.status.success(),
4363+ "ffmpeg fixture: {}",
4364+ String::from_utf8_lossy(&y4m.stderr)
4365+ );
4366+ let depth_args: &[&str] = if bit_depth == 10 {
4367+ &["-b", "10", "--input-bit-depth=10"]
4368+ } else {
4369+ &[]
4370+ };
4371+ // MEASURED (r1): the speed preset gates the feature (class
4372+ // [[gate-preset-gates-the-feature]]) -- at `--cpu-used=4` this
4373+ // content produces no rect partition at all, at `--cpu-used=0`
4374+ // aomenc emits AB partitions the tile path refuses (it ignores
4375+ // `--enable-ab-partitions=0`, ledger). So the attempt sweep walks
4376+ // the preset as well as the seed.
4377+ let cpu = format!("--cpu-used={}", attempt % 5);
4378+ // The quantiser drives how finely the RD partitions: the sweep
4379+ // walks it too, so "no rect strip fired" cannot be an artefact of
4380+ // one cq.
4381+ let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]);
4382+ let mut child = Command::new(aomenc_path())
4383+ .args(depth_args)
4384+ .arg(&cpu)
4385+ .arg(&cq)
4386+ .args([
4387+ // class [[aomenc-first-flag-wins]]: every flag is spelled
4388+ // exactly ONCE in this recipe, so there is no override to
4389+ // order. These four are what this gate is about.
4390+ "--enable-rect-partitions=1",
4391+ // MEASURED (r1): the charter's `--min-partition-size=8`
4392+ // makes 24/24 attempts stop at a sub-16 AB-partition
4393+ // refusal ("a HORZ_A/HORZ_B/VERT_A partition below 16x16",
4394+ // "a coded (non-skip) HORZ_B/VERT_B rect strip below
4395+ // 16x16") before any intra rect strip is reached -- those
4396+ // are other lanes' surfaces. 16 keeps the 16x8/8x16 shape
4397+ // reachable (a 16x16 block's own HORZ/VERT children).
4398+ "--min-partition-size=16",
4399+ "--max-partition-size=64",
4400+ // MEASURED (r1): with tx-size search ON, 24/24 attempts stop at
4401+ // the SQUARE intra-in-inter arm's own refusal ("an intra
4402+ // block in an inter frame whose tx_depth splits its luma
4403+ // transform (round 1)", read_block_tx_size) long before a
4404+ // rect strip is reached -- that arm is another lane's
4405+ // surface. OFF, no tx-depth symbol is coded at all and
4406+ // every rect strip here is the unsplit single-transform
4407+ // case. The SPLIT rect arm (`depth_to_tx_wh` +
4408+ // decode_rect_split's per-unit walk) is wired but stays
4409+ // UNGATED on this path until that square refusal lifts.
4410+ "--enable-tx-size-search=0",
4411+ "--codec=av1",
4412+ "--passes=1",
4413+ "--end-usage=q",
4414+ "--lag-in-frames=0",
4415+ "--auto-alt-ref=0",
4416+ // One key frame at the head: the frames after the cut must
4417+ // stay INTER frames carrying intra blocks, not become a
4418+ // new key frame.
4419+ "--kf-min-dist=1000",
4420+ "--kf-max-dist=1000",
4421+ "--threads=1",
4422+ "--row-mt=0",
4423+ "--enable-order-hint=0",
4424+ "--enable-warped-motion=0",
4425+ "--enable-obmc=0",
4426+ "--enable-masked-comp=0",
4427+ "--enable-interintra-comp=0",
4428+ "--enable-dist-wtd-comp=0",
4429+ "--enable-diff-wtd-comp=0",
4430+ "--enable-onesided-comp=0",
4431+ "--enable-interintra-wedge=0",
4432+ "--enable-smooth-interintra=0",
4433+ "--enable-ab-partitions=0",
4434+ "--enable-1to4-partitions=0",
4435+ // The intra-in-inter arm reads no `use_filter_intra`
4436+ // symbol (square OR rect) -- lane-fiinter owns that read.
4437+ "--enable-filter-intra=0",
4438+ "--enable-smooth-intra=0",
4439+ "--enable-paeth-intra=0",
4440+ "--enable-directional-intra=0",
4441+ "--enable-angle-delta=0",
4442+ "--enable-cdef=0",
4443+ "--enable-restoration=0",
4444+ "--enable-palette=0",
4445+ "--enable-intrabc=0",
4446+ "--enable-cfl-intra=0",
4447+ "--enable-ref-frame-mvs=0",
4448+ "--obu",
4449+ "-o",
4450+ "-",
4451+ "-",
4452+ ])
4453+ .stdin(Stdio::piped())
4454+ .stdout(Stdio::piped())
4455+ .stderr(Stdio::piped())
4456+ .spawn()
4457+ .expect("aomenc failed to start");
4458+ child
4459+ .stdin
4460+ .take()
4461+ .expect("aomenc stdin")
4462+ .write_all(&y4m.stdout)
4463+ .expect("writing y4m to aomenc");
4464+ let out = child.wait_with_output().expect("aomenc failed to run");
4465+ assert!(
4466+ out.status.success(),
4467+ "aomenc refused the fixture: {}",
4468+ String::from_utf8_lossy(&out.stderr)
4469+ );
4470+ let stream = out.stdout;
4471+ let before = [
4472+ decode::intra_rect_strip_in_inter_hits(0),
4473+ decode::intra_rect_strip_in_inter_hits(1),
4474+ decode::intra_rect_strip_in_inter_hits(2),
4475+ ];
4476+ let kf_rect_before = decode::rect_partition_hits();
4477+ let frames = match decode_stream(&stream) {
4478+ Ok(frames) => frames,
4479+ Err(e) => {
4480+ let msg = e.to_string();
4481+ assert!(
4482+ msg.contains("unsupported"),
4483+ "intra-rect-in-inter decode failed outright (seed {seed}): {msg}"
4484+ );
4485+ refusals.push(format!("seed {seed} {cpu} {cq}: {msg}"));
4486+ continue;
4487+ }
4488+ };
4489+ let delta = [
4490+ decode::intra_rect_strip_in_inter_hits(0) - before[0],
4491+ decode::intra_rect_strip_in_inter_hits(1) - before[1],
4492+ decode::intra_rect_strip_in_inter_hits(2) - before[2],
4493+ ];
4494+ let ffmpeg_frames = if bit_depth == 10 {
4495+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
4496+ } else {
4497+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
4498+ };
4499+ assert_eq!(frames.len(), frame_count);
4500+ eprintln!(
4501+ "intrarect gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra rect strips in inter frames \
4502+ 64-level={} 32-level={} 16-level={}, key-frame rect strips this stream={}",
4503+ delta[0], delta[1], delta[2],
4504+ decode::rect_partition_hits() - kf_rect_before
4505+ );
4506+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4507+ for (plane, (g, w)) in [
4508+ ("Y", (&got.y, &want.y)),
4509+ ("U", (&got.u, &want.u)),
4510+ ("V", (&got.v, &want.v)),
4511+ ] {
4512+ let stride = if plane == "Y" { width } else { width / 2 };
4513+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
4514+ eprintln!(
4515+ "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \
4516+ diff at ({}, {}) got {} want {} ({} samples differ)",
4517+ at % stride,
4518+ at / stride,
4519+ g[at],
4520+ w[at],
4521+ g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
4522+ );
4523+ // Magnitude separates a deblock/prediction difference
4524+ // (all |d| == 1) from an entropy desync (large,
4525+ // arbitrary): the first thing r2 needs to know.
4526+ let maxd = g
4527+ .iter()
4528+ .zip(w.iter())
4529+ .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b)))
4530+ .max()
4531+ .unwrap_or(0);
4532+ let rows: std::collections::BTreeSet<usize> = g
4533+ .iter()
4534+ .zip(w.iter())
4535+ .enumerate()
4536+ .filter(|(_, (a, b))| a != b)
4537+ .map(|(k, _)| k / stride)
4538+ .collect();
4539+ eprintln!(
4540+ "intrarect gate {bit_depth}-bit seed={seed}: frame {i} {plane} max \
4541+ |diff|={maxd}, rows {:?}..{:?}",
4542+ rows.iter().next(),
4543+ rows.iter().next_back()
4544+ );
4545+ }
4546+ assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})");
4547+ }
4548+ }
4549+ compared += 1;
4550+ if delta.iter().all(|d| *d == 0) {
4551+ uncounted_exact += 1;
4552+ refusals.push(format!(
4553+ "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra rect strip on the \
4554+ inter path"
4555+ ));
4556+ }
4557+ for k in 0..3 {
4558+ shapes[k] += delta[k];
4559+ }
4560+ if shapes.iter().filter(|n| **n > 0).count() >= 2 {
4561+ break;
4562+ }
4563+ }
4564+ gate_buckets(
4565+ NAME,
4566+ compared - uncounted_exact,
4567+ uncounted_exact,
4568+ refusals.len() - uncounted_exact as usize,
4569+ );
4570+ eprintln!(
4571+ "{NAME} ({bit_depth}-bit): compared {compared} streams, intra rect strips in inter \
4572+ frames per shape: 64x32/32x64={} 32x16/16x32={} 16x8/8x16={}; refusals:\n{}",
4573+ shapes[0],
4574+ shapes[1],
4575+ shapes[2],
4576+ refusals.join("\n")
4577+ );
4578+ assert!(
4579+ compared > 0,
4580+ "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \
4581+ pixel-compared:\n{}",
4582+ refusals.join("\n")
4583+ );
4584+ // MEASURED (r1, 90 attempts; r2 re-ran the 45-attempt sweep at both
4585+ // depths): only the 32x16/16x32 class is REACHABLE on this branch --
4586+ // the inter tile path refuses any SB-level partition other than
4587+ // NONE/SPLIT, so a 64x32/32x64 intra strip cannot be produced at all,
4588+ // and every 16x8/8x16 candidate stops at a sub-16 refusal owned by
4589+ // another lane. So the bar is that class, hard, not "two of three":
4590+ // a green run still cannot come from a stream that fired nothing.
4591+ assert!(
4592+ shapes[1] > 0,
4593+ "{NAME} ({bit_depth}-bit): no 32x16/16x32 intra rect strip fired over \
4594+ {compared} compared streams (64-level={} 32-level={} 16-level={})",
4595+ shapes[0],
4596+ shapes[1],
4597+ shapes[2]
4598+ );
4599+ }
4600+
42764601 fn tx_select_inter_gate(bit_depth: u32) {
42774602 if !have_ffmpeg() {
42784603 eprintln!(
@@ -11531,7 +11856,7 @@ mod tests {
1153111856 "--enable-cdef=0",
1153211857 "--enable-restoration=0",
1153311858 "--max-partition-size=32",
11534- "--min-partition-size=32",
11859+ "--min-partition-size=16",
1153511860 "--enable-palette=0",
1153611861 "--enable-intrabc=0",
1153711862 "--enable-cfl-intra=0",
@@ -11749,7 +12074,7 @@ mod tests {
1174912074 "--enable-cdef=0",
1175012075 "--enable-restoration=0",
1175112076 "--max-partition-size=32",
11752- "--min-partition-size=32",
12077+ "--min-partition-size=16",
1175312078 "--enable-palette=0",
1175412079 "--enable-intrabc=0",
1175512080 "--enable-cfl-intra=0",
@@ -11955,7 +12280,7 @@ mod tests {
1195512280 "--sb-size=64",
1195612281 "--enable-rect-partitions=1",
1195712282 "--enable-ab-partitions=1",
11958- "--min-partition-size=32",
12283+ "--min-partition-size=16",
1195912284 "--max-partition-size=32",
1196012285 "--obu",
1196112286 "-o",
@@ -12107,7 +12432,7 @@ mod tests {
1210712432 // last wins: the flags under test go after the base recipe
1210812433 "--enable-rect-partitions=1",
1210912434 "--enable-ab-partitions=1",
12110- "--min-partition-size=32",
12435+ "--min-partition-size=16",
1211112436 "--max-partition-size=32",
1211212437 ],
1211312438 &LR_SEEDS,
@@ -18488,7 +18813,7 @@ mod tests {
1848818813 "--enable-rect-partitions=1",
1848918814 "--enable-ab-partitions=0",
1849018815 "--enable-1to4-partitions=0",
18491- "--min-partition-size=32",
18816+ "--min-partition-size=16",
1849218817 "--max-partition-size=32",
1849318818 "--enable-restoration=0",
1849418819 "--enable-palette=0",
@@ -18950,7 +19275,7 @@ mod tests {
1895019275 "--enable-rect-partitions=1",
1895119276 "--enable-ab-partitions=0",
1895219277 "--enable-1to4-partitions=0",
18953- "--min-partition-size=32",
19278+ "--min-partition-size=16",
1895419279 "--max-partition-size=32",
1895519280 "--enable-restoration=0",
1895619281 "--enable-palette=0",
@@ -20158,7 +20483,7 @@ mod tests {
2015820483 "--enable-rect-partitions=1",
2015920484 "--enable-ab-partitions=0",
2016020485 "--enable-1to4-partitions=1",
20161- "--min-partition-size=32",
20486+ "--min-partition-size=16",
2016220487 "--max-partition-size=64",
2016320488 "--enable-restoration=0",
2016420489 "--enable-palette=0",
@@ -20930,7 +21255,7 @@ mod tests {
2093021255 // would turn every attempt into a refusal and make the gate
2093121256 // vacuous rather than proving anything about tiles.
2093221257 "--enable-1to4-partitions=0",
20933- "--min-partition-size=32",
21258+ "--min-partition-size=16",
2093421259 // Overridable by `extra` (aomenc takes the last occurrence of
2093521260 // a repeated flag), which the palette arm below relies on.
2093621261 "--enable-palette=0",
@@ -21507,7 +21832,7 @@ mod tests {
2150721832 // refused before a pixel was compared (measured r1).
2150821833 // At 16 the 1:4 split happens at the superblock, the
2150921834 // 64x16/16x64 strips whose chroma half is 32x8/8x32.
21510- "--min-partition-size=32",
21835+ "--min-partition-size=16",
2151121836 "--max-partition-size=64",
2151221837 "--enable-restoration=0",
2151321838 "--enable-palette=0",
@@ -21769,4 +22094,171 @@ mod tests {
2176922094 yuv420p10le)"
2177022095 );
2177122096 }
22097+
22098+ /// lane-hgkf r1: a frame whose height (or width) is not a multiple of the
22099+ /// block size makes the last superblock row (column) read a GATHERED
22100+ /// partition bit instead of a full alphabet symbol -- and libaom's
22101+ /// `ec_read_partition_impl` answers that bit with `PARTITION_HORZ`
22102+ /// (resp. `VERT`) when it is 0, only `SPLIT` when it is 1. All three
22103+ /// key-frame edge readers (64-, 32- and 16-level) read the bit and threw
22104+ /// it away, forcing SPLIT; every such frame desynced at the first block
22105+ /// of its partial row. 192x136 / 136x192 is the smallest shape that hits
22106+ /// all three levels at once (136 = 2*64 + 8, so mi_rows = 34: the 64-,
22107+ /// 32- and 16-level halves all fall outside), and it is the shape of a
22108+ /// real 3840x1608 10-bit film key frame (1608 mod 64 == 8) that decoded
22109+ /// 51768 samples wrong before this round.
22110+ ///
22111+ /// The counter is sampled per attempt and read only on an attempt that
22112+ /// decoded AND is pixel-compared; slot 0/2 (the bit taken as HORZ/VERT)
22113+ /// must be nonzero or the gate proves nothing -- before this round that
22114+ /// arm was unreachable by construction.
22115+ #[test]
22116+ fn a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact() {
22117+ const NAME: &str =
22118+ "a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact";
22119+ let _gate_lock = lock_gate_counters();
22120+ if !have_ffmpeg() {
22121+ eprintln!("SKIP {NAME}: no ffmpeg");
22122+ return;
22123+ }
22124+ if !have_aomenc() {
22125+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
22126+ return;
22127+ }
22128+ let mut compared = 0usize;
22129+ let mut edge_horz_total = 0usize;
22130+ let mut edge_sub_total = 0usize;
22131+ // The last two shapes are the ledger-measured 64-level pair: on a
22132+ // flat band (192x80 / 80x192) real aomenc answers the bottom-edge
22133+ // superblock with the 64-level HORZ/VERT, which the 136 shapes above
22134+ // never produce (their SBs always split down to the 32/16 levels).
22135+ for (width, height, flat) in [
22136+ (192usize, 136usize, false),
22137+ (136usize, 192usize, false),
22138+ (192usize, 80usize, true),
22139+ (80usize, 192usize, true),
22140+ ] {
22141+ for depth in [8usize, 10] {
22142+ let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
22143+ let y4m = Command::new("ffmpeg")
22144+ .args([
22145+ "-v", "error", "-f", "lavfi", "-i",
22146+ &if flat {
22147+ format!("color=c=gray:size={width}x{height}")
22148+ } else {
22149+ format!("mandelbrot=size={width}x{height}:start_x=-0.6")
22150+ },
22151+ "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1",
22152+ "-f", "yuv4mpegpipe", "-",
22153+ ])
22154+ .stdin(Stdio::null())
22155+ .stdout(Stdio::piped())
22156+ .stderr(Stdio::piped())
22157+ .output()
22158+ .expect("ffmpeg failed to run");
22159+ assert!(
22160+ y4m.status.success(),
22161+ "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}",
22162+ String::from_utf8_lossy(&y4m.stderr)
22163+ );
22164+ let encode = || {
22165+ let mut child = Command::new(aomenc_path())
22166+ .args([
22167+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
22168+ "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64",
22169+ "--kf-max-dist=0", "--enable-rect-partitions=1",
22170+ "--enable-ab-partitions=0", "--enable-1to4-partitions=0",
22171+ "--enable-tx-size-search=0", "--reduced-tx-type-set=1",
22172+ "--min-partition-size=8", "--max-partition-size=64",
22173+ &format!("--input-bit-depth={depth}"),
22174+ &format!("--bit-depth={depth}"),
22175+ "--obu", "-o", "-", "-",
22176+ ])
22177+ .stdin(Stdio::piped())
22178+ .stdout(Stdio::piped())
22179+ .stderr(Stdio::piped())
22180+ .spawn()
22181+ .expect("aomenc failed to start");
22182+ child
22183+ .stdin
22184+ .take()
22185+ .expect("aomenc stdin")
22186+ .write_all(&y4m.stdout)
22187+ .expect("writing y4m to aomenc");
22188+ let out = child.wait_with_output().expect("aomenc failed to run");
22189+ assert!(
22190+ out.status.success(),
22191+ "aomenc refused the fixture ({width}x{height}, depth={depth}): {}",
22192+ String::from_utf8_lossy(&out.stderr)
22193+ );
22194+ out.stdout
22195+ };
22196+ let stream = encode();
22197+ assert_eq!(
22198+ stream,
22199+ encode(),
22200+ "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})"
22201+ );
22202+ crate::decode::reset_edge_part_hits();
22203+ let frames = match decode_stream(&stream) {
22204+ Ok(frames) => frames,
22205+ Err(e) => {
22206+ let msg = e.to_string();
22207+ assert!(
22208+ msg.contains("unsupported"),
22209+ "{NAME}: decode failed ({width}x{height}, depth={depth}): {msg}"
22210+ );
22211+ eprintln!(
22212+ "{NAME}: {width}x{height} depth={depth} arm refused (not compared): {msg}"
22213+ );
22214+ continue;
22215+ }
22216+ };
22217+ let hits = crate::decode::edge_part_hits();
22218+ let ffmpeg_frames = if depth == 10 {
22219+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
22220+ } else {
22221+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
22222+ };
22223+ assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count");
22224+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
22225+ assert_eq!(
22226+ got.y, want.y,
22227+ "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \
22228+ edge bits horz/split 64-level {}/{}, sub-level {}/{})",
22229+ hits[0], hits[1], hits[2], hits[3]
22230+ );
22231+ assert_eq!(
22232+ got.u, want.u,
22233+ "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth})"
22234+ );
22235+ assert_eq!(
22236+ got.v, want.v,
22237+ "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth})"
22238+ );
22239+ }
22240+ compared += 1;
22241+ edge_horz_total += hits[0];
22242+ edge_sub_total += hits[2];
22243+ eprintln!(
22244+ "{NAME}: pixel-exact {width}x{height} at {depth}-bit, edge bits \
22245+ 64-level horz/vert={} split={} sub-level horz/vert={} split={}",
22246+ hits[0], hits[1], hits[2], hits[3]
22247+ );
22248+ }
22249+ }
22250+ assert!(
22251+ compared > 0,
22252+ "{NAME}: every arm refused -- the gate compared no pixels at all"
22253+ );
22254+ assert!(
22255+ edge_horz_total > 0,
22256+ "{NAME}: no 64-level frame-edge bit was ever answered HORZ/VERT -- the arm this \
22257+ round fixed never fired"
22258+ );
22259+ assert!(
22260+ edge_sub_total > 0,
22261+ "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT"
22262+ );
22263+ }
2177222264 }
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.