diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 41a61679..e233c064 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -34626,6 +34626,89 @@ fn decode_inter_block( u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; mu_chroma = true; + } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 && chroma_side > chroma_tx { + // lane-av1-rect128recon: at ss 0/0 the uv plane block of a + // 64x64 intra block inside an inter frame is 64x64 while + // `av1_get_max_uv_txsize` caps the unit at TX_32X32 -- FOUR + // plane-major TX_32X32 units (libaom + // `decode_token_recon_block`'s plane loop), each with its own + // neighbour context and `get_txb_ctx`'s offset-10 rows (+3 on + // the `txb_skip_chroma_32` table, lane-sb128b r3), each + // stamped immediately so the next unit reads it. The old arm + // read ONE whole-plane unit with the block-level context and + // no offset: three quarters of the plane's residual was never + // read, the unit's `txb_skip` came off the offset-7 row (444 + // witness f2, right-half intra 64x64: U unit (0,0) ctx 0 + // where aom reads 10), and the coded corner was even + // dequantized at the TX_64X64 dqDenom. + let mu_units_n = chroma_side / chroma_tx; + let mut u_acc = vec![0i32; chroma_side * chroma_side]; + let mut v_acc = vec![0i32; chroma_side * chroma_side]; + for plane_idx in 1..=2 { + let buf: &mut PlaneBuf<'static> = + if plane_idx == 1 { &mut *u } else { &mut *v }; + for cu_row in 0..mu_units_n { + for cu_col in 0..mu_units_n { + let cu_mi = ( + at_mi.0 + cu_row * (chroma_tx / MI), + at_mi.1 + cu_col * (chroma_tx / MI), + ); + let cu_around = neighbours.around_mi(cu_mi, chroma_tx); + let cu_reach = crate::decode::tu_reach( + side, + side, + cu_col * chroma_tx, + cu_row * chroma_tx, + chroma_tx, + reach, + px, + py, + y.width, + y.height, fctx, + ); + let cu_grid = read_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + plane_idx, + cu_around[plane_idx], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + buf, + cpx + cu_col * chroma_tx, + cpy + cu_row * chroma_tx, + chroma_tx, + chroma_tx, + base_q_idx, + // CfL is capped at 32x32 (`is_cfl_allowed`), + // so a block this size never carries alpha. + None, + None, + Some(3), + smooth_neighbor_uv, fctx, + )?; + // Immediately, so the NEXT unit reads this one's + // coefficient context. + neighbours.record_mi_chroma( + cu_mi, chroma_tx, chroma_tx, plane_idx, &cu_grid, + ); + hit!(CHROMA_SPLIT_TX_HITS); + let acc = if plane_idx == 1 { &mut u_acc } else { &mut v_acc }; + for rr in 0..chroma_tx { + let start = + (cu_row * chroma_tx + rr) * chroma_side + cu_col * chroma_tx; + acc[start..start + chroma_tx] + .copy_from_slice(&cu_grid[rr * chroma_tx..][..chroma_tx]); + } + } + } + } + mu_chroma = true; + u_grid = Grid::Own(u_acc); + v_grid = Grid::Own(v_acc); } else { if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 06fc1380..35eb9a7f 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5808,20 +5808,20 @@ pub(crate) mod tests { for f in &frames { assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); } - // Frames 0 and 1 are the byte-exact pin for the ss-aware 128-rect - // chroma walk itself (frame 0's keyframe PARTITION_VERT 64x128 and - // frame 1's inter pieces). Frame 2 carries a SEPARATE, named - // residual: its top LR stripe (RU row 0, rows 0..63, all three - // planes) is never loop-restored on this inter frame -- our output - // equals the post-CDEF plane there while the oracle restores it - // (ours-vs-oracle final Y 7308 / U 9685 / V 14012, deterministic; - // recon, deblock and CDEF are byte-exact at PREFILT/POSTDEBLOCK/ - // POSTCDEF). Site: the pipelined LR band accounting - // (`pipe_run_lr`'s `rrows` branch plus the `ls.note`/`ls.close` - // band release in `decode.rs`'s filter pipeline) never flushes RU - // row 0 when the top superblock row carries a 128-root rect block - // (this frame's inter 64x128 at (128,0)). That flush fix is its own - // lane; asserting f2's current samples here would pin the bug. + // All three frames are pinned byte-exact against both oracles (the + // aomdec/ffmpeg arms below run over `.take(3)`): frame 0's keyframe + // PARTITION_VERT 64x128, frame 1's inter pieces, and frame 2 -- whose + // right superblock column (the 128-root VERT piece at the frame edge) + // is three intra blocks (64x64, 64x32, 64x32) whose chroma units ride + // the inter-frame intra tail. That tail read ONE whole-plane chroma + // unit with the block-level context where 4:4:4 codes four + // plane-major TX_32X32 units with per-unit contexts and the + // offset-10 `get_txb_ctx` rows, which left three quarters of the + // planes' residual unread and misaligned the symbol stream from the + // first chroma unit on (f2 PREFILT Y 6952 / U 9568 / V 13496, first + // diffs entering at column 128). Fixed on lane-av1-rect128recon; + // the earlier "LR never restores RU row 0" attribution on this frame + // was a stage-ladder mixup, refuted in lane-av1lrflush r3. // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. if aomdec_path().is_file() { @@ -5847,7 +5847,7 @@ pub(crate) mod tests { let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); let _ = std::fs::remove_dir_all(&dir); assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); - for (i, f) in frames.iter().enumerate().take(2) { + for (i, f) in frames.iter().enumerate().take(3) { let base = i * W * H * 3; for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] @@ -5868,12 +5868,11 @@ pub(crate) mod tests { eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); } - // ffmpeg's decoder: same frames, full-resolution chroma. Same f0/f1 - // scope as the aomdec arm above (frame 2 = the named LR-stripe-0 - // residual). + // ffmpeg's decoder: same frames, full-resolution chroma. Same + // three-frame scope as the aomdec arm above. if have_ffmpeg() { let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); - for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(2) { + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) { for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] .iter() diff --git a/lanes/av1rect128recon.report.md b/lanes/av1rect128recon.report.md new file mode 100644 index 00000000..2f9152d2 --- /dev/null +++ b/lanes/av1rect128recon.report.md @@ -0,0 +1,88 @@ +# lane-av1-rect128recon — the 444_sb128rect witness f2 is byte-exact vs aomdec AND ffmpeg; root cause: the inter-frame intra tail's chroma walk coded ONE whole-plane unit where 4:4:4 codes four TX_32X32 units; gate extended take(2)→take(3) (r1) + +## Outcome + +1. REPRODUCED at HEAD 99232190 (fresh target dir `cargo-target-av1rect128recon`, + fixture sha256 `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80` + re-verified, oracle aomdec `~/.cache/aom-oracle/build` regenerated this + session): frame 2 diverges at PREFILT Y 6952 / U 9568 / V 13496, first diffs + Y (col 128, row 98), U (col 128, row 64), V (col 128, row 0); f0/f1 exact. + Numbers match av1444sbf2 r1 / av1lrflush r3 sample-for-sample. +2. BLOCK-SHAPE CORRECTION (ladder evidence, not inference): the oracle's f2 + top-right superblock root is a gathered-bit SPLIT, and its right column is + INTRA blocks — 64x64 at (128,0), 64x32 at (128,64), 64x32 at (128,96), + 64x64 at (128,128) — not "the inter 64x128 at (128,0)" the earlier lane + reports name. Evidence: oracle `EC_PART`/`EC_PART_VAL` (ctx 14, values + NONE/HORZ at mi (0,32)/(16,32)), `EC_PREDOUT8` per-unit sums, and + `EC_DQCOEFF`. The earlier reports' pixel numbers are all reproduced here; + only the block-shape naming was wrong. +3. FIRST DIVERGENT SYMBOL, pinned by consecutive-TU rng alignment on both + ladders (`EC_COEFF_STEP`, TU-boundary values 60168/55581/51541 matching + line-for-line): the 64x64 intra block's FIRST chroma TX_32X32 unit at + mi (0,32). Ours decoded `txb_skip` off the offset-7 context row (printed + ctx 0); aom reads the offset-10 row (true ctx 10 — the uv plane block + 64x64 is larger than the TX_32X32 unit). Same decoded value (skip), but + the CDF rows differ, so the arithmetic coders consumed different bits and + the rest of frame 2 decodes off a drifting state — bounded, mostly-skip + garbage that still corrupted the block's own V plane (uniform −1: the + missing V residual) and the bottom superblock row. +4. ROOT CAUSE (one site): `decode_inter_block`'s intra tail read the block's + chroma as ONE whole-plane unit (`read_plane` with `chroma_side`/`chroma_tx`, + block-level `around`, no +10 offset) — a 4:2:0-era remnant. At 4:4:4 a + 64x64 plane block is FOUR plane-major TX_32X32 units, each with its own + `around_mi` context and the offset-10 rows. The keyframe path + (`decode_block`'s `cn > 1` loop, lane-av1-444) and the inter tail's own + ss-0/0 arm already did this correctly; the intra-in-inter tail was the one + remaining copy of the old shape. The misnaming in (2) hid this: the + "inter 64x128" framing pointed at Agent044's strip/inter territory, while + the real site is the intra tail. +5. FIX (decode.rs, intra tail chroma chain): new `ss_x==0 && ss_y==0 && + chroma_side > chroma_tx` arm — four plane-major TX_32X32 units, per-unit + `around_mi(cu_mi, 32)`, `Some(3)` skip-ctx offset (+10 convention on our + chroma-32 table), immediate per-unit `record_mi_chroma`, per-unit + `tu_reach`, assembled 64x64 plane grids, `mu_chroma = true` so the + block-tail unit replay re-stamps after the whole-block record (class + `override-slot-on-one-arm`). 4:2:0 is identical by construction: the arm + is ss-gated and `chroma_side == chroma_tx` there still takes the old + single-read path. Class sweep: the only other intra-in-inter chroma arms + are the side>64 mu-chunk walk (already per-unit, correct) and the + rect-strip readers (separate paths, sibling-owned, untouched). +6. RESULT: f2 PREFILT byte-exact; FINAL (full deblock/CDEF/LR pipeline) + byte-exact on ALL THREE frames against BOTH oracles — ours == + `ffmpeg -f rawvideo -pix_fmt yuv444p` byte-for-byte (276480 bytes), and + frame-equal to aomdec's Y4M output (its 12 interleaved `FRAME` markers + stripped). + +## Verification + +- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` + (extended to `.take(3)` in both oracle arms + rewritten scoping comment, + same commit): PASS. +- `cargo check -p ec-av1`: 0 warnings (target `$HOME/.cache/cargo-target-av1rect128recon`). +- sb128 family (`cargo test -p ec-av1 --lib sb128`): 10 passed, 1 ignored. +- 444 family (`--lib 444`): 4 passed (includes the lossless 444 + min-partition-64 inter stream). +- Restoration battery (`EC_AV1_REQUIRE_AOMENC=1 --lib restoration`): + 10 passed, 0 failed. +- chroma family (`--lib chroma`): 28 passed, 0 failed. +- Stage evidence from env-gated rungs on both decoders (EC_PART/EC_PART_VAL, + EC_COEFF_STEP, EC_ECDUMP_IN, EC_PREDOUT8, EC_IMODE, AOMMB, EC_DQCOEFF); + throwaway /tmp scratch only, nothing left in the tree. + +## Decision + +- Gate extended and the stale "LR never restores RU row 0" scoping comment + replaced (that attribution was refuted in lane-av1lrflush r3 as a + stage-ladder mixup) — the deferred same-commit pairing is now discharged. +- Sibling ownership respected: `decode_rect4_16_strip`'s 16x4/strip-tail + territory and the sub-8 leaf paths untouched; the fix lands in + `decode_inter_block`'s intra tail only. +- Named for the record: any future block-shape work must sweep BOTH copies + of the chroma unit walk — `decode_block` (keyframe) and + `decode_inter_block`'s intra tail — plus the inter tail; this defect was + the third copy drifting from the first two. + +## State + +- Commit on lane-av1-rect128recon (no push): decode.rs fix + stream.rs gate + extension/comment + this report.