diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 558fd162..ace747fc 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -8083,15 +8083,24 @@ impl Neighbours { // One pass over the cells accumulating all three planes, not one pass // per plane: the three planes of a cell live in the same // `[Neighbour; 3]` (6 bytes), so the per-plane form loaded the same - // cache lines three times (lane-publish). + // cache lines three times (lane-publish). Clamp each edge to the true + // frame extent: a block at the right/bottom edge may be padded beyond + // `mi_cols`/`mi_rows`, and libaom's unavailable context is zero there. + let above_mi = side_mi.min(self.mi_cols.saturating_sub(mi_c)); + let left_mi = side_mi.min(self.mi_rows.saturating_sub(mi_r)); let mut out = [(false, false, 0i32); 3]; - for cell in 0..side_mi { + for cell in 0..above_mi { let above = &self.above[mi_c + cell]; - let left = &self.left[mi_r + cell]; for (plane, o) in out.iter_mut().enumerate() { o.0 |= above[plane].level != 0; + o.2 += dc_vote(above[plane].dc); + } + } + for cell in 0..left_mi { + let left = &self.left[mi_r + cell]; + for (plane, o) in out.iter_mut().enumerate() { o.1 |= left[plane].level != 0; - o.2 += dc_vote(above[plane].dc) + dc_vote(left[plane].dc); + o.2 += dc_vote(left[plane].dc); } } out @@ -8108,16 +8117,18 @@ impl Neighbours { /// mode-info units, mirroring [`Self::around_mi`]. fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { let (w_mi, h_mi) = (w / MI, h / MI); + let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); + let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); // [`Self::around_mi`]'s single pass, with the two extents split. let mut out = [(false, false, 0i32); 3]; - for cell in 0..w_mi { + for cell in 0..above_mi { let above = &self.above[mi_c + cell]; for (plane, o) in out.iter_mut().enumerate() { o.0 |= above[plane].level != 0; o.2 += dc_vote(above[plane].dc); } } - for cell in 0..h_mi { + for cell in 0..left_mi { let left = &self.left[mi_r + cell]; for (plane, o) in out.iter_mut().enumerate() { o.1 |= left[plane].level != 0; @@ -8127,10 +8138,10 @@ impl Neighbours { if crate::envflags::env_flag!("EC_DCDUMP") { for (plane, o) in out.iter().enumerate() { let vote = o.2; - let ab: Vec = (0..w_mi) + let ab: Vec = (0..above_mi) .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) .collect(); - let lf: Vec = (0..h_mi) + let lf: Vec = (0..left_mi) .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) .collect(); eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); @@ -8160,20 +8171,22 @@ impl Neighbours { h_mi: usize, ) -> usize { let side_mi = w_mi; + let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); + let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); let mut top = 0u8; let mut left = 0u8; - for cell in 0..w_mi { + for cell in 0..above_mi { top |= self.above[mi_c + cell][0].level; } - for cell in 0..h_mi { + for cell in 0..left_mi { left |= self.left[mi_r + cell][0].level; } let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; if crate::envflags::env_flag!("EC_ECDUMP") { let ab: Vec = - (0..w_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect(); + (0..above_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect(); let lf: Vec = - (0..h_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect(); + (0..left_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect(); eprintln!( "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},]", ab.join(","), lf.join(",") @@ -31953,6 +31966,7 @@ fn decode_inter_sub8_split4( // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false. let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; + let ec_skip_post = if std::env::var_os("EC_DBG_SUB8").is_some() { Some(dec.debug_state().0) } else { None }; inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false, fctx); maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); @@ -31968,6 +31982,9 @@ fn decode_inter_sub8_split4( neighbours.left_inter[rmi], ); let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; + if std::env::var_os("EC_DBG_SUB8").is_some() { + eprintln!("EC_DBG piece mi=({rmi},{cmi}) skip={skip} skipctx={skip_ctx} skip_post={:?} is_inter={is_inter} iictx={ii_ctx} post={}", ec_skip_post, dec.debug_state().0); + } if !is_inter { if crate::envflags::env_flag!("EC_SUB8INTRA") { eprintln!( @@ -32291,6 +32308,82 @@ fn decode_inter_sub8_split4( } neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid); } + // lane-av1-444: `is_chroma_reference` is unconditional at ss 0/0 + // (av1_common_int.h:1459 -- `!subsampling_x`/`!subsampling_y` force + // both disjuncts true), so at 4:4:4 this 4x4 sub-block codes its own + // 4x4 U and V units right after its luma, plane order 0,1,2 per leaf + // (aomdec EC_COEFF on `av1-profile1-444.ivf` frame 1). Chroma MC is + // the piece's own mv and filters at the piece's own pixel position + // (ss 0: the chroma planes share luma's grid), and each unit's + // tx_type is its own piece's luma type -- a TX_4X4 codes no tx_type + // symbol, so DctDct. + if chroma_444 { + let (pc_ref, pc_mv, pc_hf, pc_vf) = piece[i].expect("inter piece recorded above"); + let build_c = move |_y: &mut PlaneBuf<'static>, + _u: &mut PlaneBuf<'static>, + _v: &mut PlaneBuf<'static>, + fctx: &crate::decode::FrameCtx, + out: &mut [Vec; 3]| { + let Some((pc_ref_y, sref_u, sref_v)) = ref_planes_deferred(pc_ref, refpix) else { + return; + }; + let pc_scale = mc::scale_factor(pc_ref_y.width, frame_width); + let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); + let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { + let mut buf = vec![0u16; B4 * B4]; + mc::predict_maybe_scaled( + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(px, pc_mv.1, ss_x(fctx)), + mv_to_q4(py, pc_mv.0, ss_x(fctx)), + pc_scale, + B4, + B4, + pc_hf, + pc_vf, + &mut buf, fctx, + ); + dst.copy_from_slice(&buf); + } + out[1] = pred_u; + out[2] = pred_v; + }; + let (pred_cu, pred_cv): (Vec, Vec); + let (su, sv) = if recon_deferred(fctx) { + push_pred(fctx, build_c); + ( + Pred::Cur { plane: 1, stride: B4, off: 0 }, + Pred::Cur { plane: 2, stride: B4, off: 0 }, + ) + } else { + let mut built: [Vec; 3] = Default::default(); + build_c(y, u, v, fctx, &mut built); + let [_, bu, bv] = built; + (pred_cu, pred_cv) = (bu, bv); + (Pred::Inline(&pred_cu, B4), Pred::Inline(&pred_cv, B4)) + }; + if skip { + push_mc(1, px, py, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx); + push_mc(2, px, py, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx); + neighbours.record_mi_chroma(lmi, B4, B4, 1, &ZERO_RESIDUAL[..B4 * B4]); + neighbours.record_mi_chroma(lmi, B4, B4, 2, &ZERO_RESIDUAL[..B4 * B4]); + } else { + let ca = neighbours.around_mi(lmi, B4); + let (ug, _) = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, ca[1], 0, u, px, py, B4, base_q_idx, + su, Some(TxType::DctDct), None, fctx, + )?; + let (vg, _) = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, ca[2], 0, v, px, py, B4, base_q_idx, + sv, Some(TxType::DctDct), None, fctx, + )?; + neighbours.record_mi_chroma(lmi, B4, B4, 1, &ug); + neighbours.record_mi_chroma(lmi, B4, B4, 2, &vg); + } + } neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED); neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false); // lane-inter16ab r8 (same-shape sweep of the intra-strip band gap): @@ -32305,7 +32398,22 @@ fn decode_inter_sub8_split4( } // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded // and reconstructed the group's one chroma unit itself. - if !intra_chroma { + // lane-av1-444: at ss 0/0 the group unit does not exist -- every piece + // coded its own U/V inside the loop above. The mode-level bookkeeping + // below still runs for both subsamplings: an inter 4x4 piece's + // `mbmi->uv_mode` is the DC_PRED default and no piece can be a palette + // block, exactly as the 4:2:0 path already published. + neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map + // needs EVERY writer): a sub-8x8 group published no palette state, so + // once an 8x8 leaf of the same row can BE a palette block, the group + // left the row's band holding that earlier block's size and the next + // intra block read `av1_get_palette_mode_ctx` one too high (measured: + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` + // needs `bsize >= BLOCK_8X8`), so the group always clears. + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); + if !chroma_444 && !intra_chroma { // Chroma, once for the whole group, on the last sub-block's own `skip` // flag -- prediction from all four sub-blocks (2x2 pieces), residual as // one TX_4X4 unit per plane. @@ -32411,16 +32519,6 @@ fn decode_inter_sub8_split4( note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded); (ug, vg) }; - neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); - // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map - // needs EVERY writer): a sub-8x8 group published no palette state, so - // once an 8x8 leaf of the same row can BE a palette block, the group - // left the row's band holding that earlier block's size and the next - // intra block read `av1_get_palette_mode_ctx` one too high (measured: - // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers - // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` - // needs `bsize >= BLOCK_8X8`), so the group always clears. - record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); let round_up_even = |n: usize| n.div_ceil(2) * 2; let bound_h = round_up_even(neighbours.mi_rows); let bound_w = round_up_even(neighbours.mi_cols); @@ -37671,7 +37769,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( let leaf_mi = (mr as usize, mc as usize); let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_state().0); } + let ec_dbg_pre = dec.debug_state().0; let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if std::env::var_os("EC_DBG_SUB8").is_some() { + let ec_dbg_post = dec.debug_state().0; + eprintln!("EC_DBG b8 mi=({},{}) ctx={leaf_ctx} val={part8} pre={ec_dbg_pre} post={ec_dbg_post}", leaf_mi.0, leaf_mi.1); + } if part8 == PARTITION_SPLIT { // lane-intersub8: four BLOCK_4X4 inter // sub-blocks, chroma once per 8x8. diff --git a/lanes/av1444.report.md b/lanes/av1444.report.md index 0c5cd18a..487c9df2 100644 --- a/lanes/av1444.report.md +++ b/lanes/av1444.report.md @@ -85,21 +85,87 @@ panics (see below). Full suite NOT run. | shape | disposition | | --- | --- | | 4:2:2 (`ss_x != ss_y`) | refused by name. Gate re-scoped, not re-run | -| 64-axis intra strips with split luma transforms at 4:4:4 (`decode_rect_split` chroma (64,16)/(64,32)/(16,64) with tx < block) | panics, not a named refusal. The `chroma_tiled` unit loop exists but the residual reaching `reconstruct_rect` is sized for a 4:2:0 unit somewhere in this path | -| `av1-profile1-444.ivf` | not byte-exact (panic above). Refusal-gate flip to witness gate NOT done | -| inter square 64x64 at 4:4:4 (var-tx and single-TU) | unwitnessed — the square inter chroma path codes one unit; libaom codes four TX_32X32. No stream has exercised it yet | -| full `cargo test -p ec-av1` | NOT run. Do not claim green | -| 0-warning parity | not measured this round | +| inter rect2 sub8 (8x4/4x8 pieces) at 4:4:4 per-piece chroma | unported — `decode_inter_sub8_rect2` still codes the 4:2:0 group unit | +| `decode_inter_sub8_split4` per-piece chroma eob CDF adaptation | wall (below), first mismatch deep in frame 1 | +| full `cargo test -p ec-av1` | NOT run this round. Do not claim green | +| 0-warning parity | build is warning-clean (`cargo build --release -p ec-av1 --example decode_probe`); full-suite parity not measured | + +## Continuation 4 (2026-09-23, Av1X444Cont4) + +1. **Edge panic fixed (Rauf's clamp, verified bug-for-bug, committed)**: + `around_mi`/`around_mi_rect`/`luma_skip_ctx_rect` clamp each walk to + `mi_cols`/`mi_rows`. libaom facts checked: the above/left entropy+coeff + arrays are `aom_calloc(aligned_mi_cols, ..)` per tile row + (alloccommon.c:437-448, `ALIGN_POWER_OF_TWO(mi_cols, MAX_MIB_SIZE_LOG2)` = + exactly 80 for the 320 px fixture) — zero-initialized and never written + beyond the frame extent, and `get_txb_ctx_general` (txb_common.h:281) + walks only the TXB's own span, so beyond-frame cells contribute ZERO to + every context on libaom's side too. The clamp reproduces exactly that; + there is no edge sample extension for these entropy-context arrays. The + fixture's `reconstruct_rect len 64 index 64` panic is gone: the probe + decodes all 60 frames, exit 0. +2. **Fixture frame 0 (first shown frame) still byte-exact** vs ffmpeg + yuv444p after the above (re-verified every round). +3. **decode_idx 1 (hidden inter, base_q 57, show_frame=0) root-caused and + partially fixed**: the frame's first partition reads + (`w64/w32/w16` all SPLIT at mi (0,0)) were in sync, but aom reads an + **8x8-level `partition_w8` symbol** before each 8x8 leaf of the inter + walker too (the keyframe walker already read it; the inter walker reads + it silently — the missing *per-piece chroma* was the real gap): + at ss 0/0 `is_chroma_reference` is unconditional + (av1_common_int.h:1459 — `!subsampling_x/y` force both disjuncts true), + so every 4x4 piece of a `partition_w8 == SPLIT` group codes its OWN 4x4 + U and V unit right after its luma, plane order 0,1,2 per leaf. + `decode_inter_sub8_split4` coded the 4:2:0 group unit instead. Fixed: + per-piece chroma MC (piece's own mv/filters, ss 0) + per-piece + `read_inter_plane` + `record_mi_chroma`; the group unit is now gated + `!chroma_444`, with `record_uv_mode_mi`/`record_strip_palette` hoisted so + they run at both subsamplings. Result: the coefficient-step ladder + against instrumented aomdec moved from first mismatch at step 387 to + step 925 (15 chroma TUs + the whole (0,2) group and (2,0)/(2,2) 8x8 + blocks now bit-identical; all `partition_w8` values match through + mi (2,6)). +4. **Current wall (precisely localized)**: decode_idx 1, the (2,6) split4 + group's piece-0 U TU (4x4, ss 0/0). Both sides read the identical + `all_zero` symbol (rng 34242, value 0), then the `eob_pt` read diverges: + aom eob=4, ours eob=2, from identical pre-state. Instrumented oracle + (`EC_EOBPT_CDF` print added to decodetxb.c, `ninja aomdec` rebuild) shows + aom's `eob_flag_cdf16[PLANE_UV][0]` contents at that read = + `[30271, 28672, 23902, 15775]` — heavily adapted — while ours + (`eob_pt_16_chroma`, bound `cdf_state.rs:1841`) is still near its default + `[6764, 8165, 12733, 17250]`. So aom's chroma-4x4-2D eob CDF instance + receives adaptation from reads our model routes elsewhere (or misses): + the next suspects are (a) `decode_inter_sub8_rect2`'s per-piece chroma + (still the 4:2:0 group unit — aom codes per-piece 8x4/4x8 chroma units, + same 16-coeff eob class), and (b) the intra 16x4/4x16 strips' chroma + units in inter frames (`intra16x4_in_inter` 16x4=68 4x16=24), whose + 4x4-class eob reads must land on the same `eob_flag_cdf16[UV][2D]` + instance. Tooling left in place: `EC_DBG_SUB8=1` (per-b8 partition + value/pre/post rng, per-piece skip/is_inter), `EC_TRACE_PART=1` + (EC_PART-style partition walk), oracle-side `EC_EOBPT_CDF=1` + (per-4x4-eob CDF contents + mi). Comparison harness: + `EC_TRACE_COEFF=1 aomdec` vs `EC_TRACE_COEFF=1 decode_probe` on + `$HOME/.cache/av1444/f2.obu` (2-frame cut), diff with the 15 + instrument-only chroma `tx_type` lines dropped. +5. Regression arms after the change: 420 square IDENTICAL, 444 square + filters off IDENTICAL, 444 square filters on IDENTICAL, forced-64x64 + 444 IDENTICAL (witness scripts, rerun this round). +6. **Frame-output policy note**: `decode_probe` writes only SHOWN frames + (`is_shown` gate); aomdec/ffmpeg likewise. The first shown frame is + decode_idx 0; decode_idx 1..5 are hidden alt-ref/LF-update frames — they + still must decode bit-exactly because every later shown frame references + them. ## Next -1. Fix the `decode_rect_split` 64-axis-strip chroma at 4:4:4 (the - len-64 panic): trace which unit feeds `reconstruct_rect` a 64-long - residual; the `chroma_tiled` arm's (32,16)/(16,32) rect units go - through `read_coeffs_rect` + `dequant_and_inverse_typed_wh` — check - the scratch/grid sizing against libaom's two-unit plane-major order. -2. Then the inter square-64 four-unit chroma (mirror the intra fix). +1. Fix the chroma-4x4 eob CDF adaptation-source mismatch (see wall above): + diff `eob_flag_cdf16[UV][2D]` adaptation sources per TU — port + `decode_inter_sub8_rect2` per-piece chroma (8x4/4x8 units, same + 16-coeff eob class) and verify the intra 16x4/4x16 strips' chroma + units land on `eob_flag_cdf16[UV][2D]` at 4:4:4. +2. Then re-run the ladder: divergence should move past (2,6)U; iterate + until decode_idx 1 is bit-exact, then frames 2..59. 3. Then the fixture end-to-end vs ffmpeg; flip the refusal gate (`a_non_420_subsampled_sequence_header_is_refused_by_name` re-scope) - to a fixture witness gate. + to a fixture witness gate; witness or refuse inter square 64x64 444. 4. Full suite `--test-threads=1`, 0-warning parity, update this report.