ec-av1: 444 intra-in-inter tail reads its four chroma units
Browse files at this commit77c2b16cc82693ec58d39aade5c410f4fb9216f4Parent: ef0d01e3 changed files +189 -19
- crates/ec-av1/src/decode.rs +83 -0
- crates/ec-av1/src/stream.rs +18 -19
- lanes/av1rect128recon.report.md +88 -0
crates/ec-av1/src/decode.rsmodified+83 -0
| @@ -34626,6 +34626,89 @@ fn decode_inter_block( | |||
| 34626 | u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; | 34626 | u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) }; |
| 34627 | v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; | 34627 | v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; |
| 34628 | mu_chroma = true; | 34628 | mu_chroma = true; |
| 34629 | + } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 && chroma_side > chroma_tx { | ||
| 34630 | + // lane-av1-rect128recon: at ss 0/0 the uv plane block of a | ||
| 34631 | + // 64x64 intra block inside an inter frame is 64x64 while | ||
| 34632 | + // `av1_get_max_uv_txsize` caps the unit at TX_32X32 -- FOUR | ||
| 34633 | + // plane-major TX_32X32 units (libaom | ||
| 34634 | + // `decode_token_recon_block`'s plane loop), each with its own | ||
| 34635 | + // neighbour context and `get_txb_ctx`'s offset-10 rows (+3 on | ||
| 34636 | + // the `txb_skip_chroma_32` table, lane-sb128b r3), each | ||
| 34637 | + // stamped immediately so the next unit reads it. The old arm | ||
| 34638 | + // read ONE whole-plane unit with the block-level context and | ||
| 34639 | + // no offset: three quarters of the plane's residual was never | ||
| 34640 | + // read, the unit's `txb_skip` came off the offset-7 row (444 | ||
| 34641 | + // witness f2, right-half intra 64x64: U unit (0,0) ctx 0 | ||
| 34642 | + // where aom reads 10), and the coded corner was even | ||
| 34643 | + // dequantized at the TX_64X64 dqDenom. | ||
| 34644 | + let mu_units_n = chroma_side / chroma_tx; | ||
| 34645 | + let mut u_acc = vec![0i32; chroma_side * chroma_side]; | ||
| 34646 | + let mut v_acc = vec![0i32; chroma_side * chroma_side]; | ||
| 34647 | + for plane_idx in 1..=2 { | ||
| 34648 | + let buf: &mut PlaneBuf<'static> = | ||
| 34649 | + if plane_idx == 1 { &mut *u } else { &mut *v }; | ||
| 34650 | + for cu_row in 0..mu_units_n { | ||
| 34651 | + for cu_col in 0..mu_units_n { | ||
| 34652 | + let cu_mi = ( | ||
| 34653 | + at_mi.0 + cu_row * (chroma_tx / MI), | ||
| 34654 | + at_mi.1 + cu_col * (chroma_tx / MI), | ||
| 34655 | + ); | ||
| 34656 | + let cu_around = neighbours.around_mi(cu_mi, chroma_tx); | ||
| 34657 | + let cu_reach = crate::decode::tu_reach( | ||
| 34658 | + side, | ||
| 34659 | + side, | ||
| 34660 | + cu_col * chroma_tx, | ||
| 34661 | + cu_row * chroma_tx, | ||
| 34662 | + chroma_tx, | ||
| 34663 | + reach, | ||
| 34664 | + px, | ||
| 34665 | + py, | ||
| 34666 | + y.width, | ||
| 34667 | + y.height, fctx, | ||
| 34668 | + ); | ||
| 34669 | + let cu_grid = read_plane( | ||
| 34670 | + dec, | ||
| 34671 | + cdfs, | ||
| 34672 | + chroma_set, | ||
| 34673 | + scan_chroma, | ||
| 34674 | + plane_idx, | ||
| 34675 | + cu_around[plane_idx], | ||
| 34676 | + mode, | ||
| 34677 | + uv_predict_mode, | ||
| 34678 | + angle_delta_uv, | ||
| 34679 | + cu_reach, | ||
| 34680 | + buf, | ||
| 34681 | + cpx + cu_col * chroma_tx, | ||
| 34682 | + cpy + cu_row * chroma_tx, | ||
| 34683 | + chroma_tx, | ||
| 34684 | + chroma_tx, | ||
| 34685 | + base_q_idx, | ||
| 34686 | + // CfL is capped at 32x32 (`is_cfl_allowed`), | ||
| 34687 | + // so a block this size never carries alpha. | ||
| 34688 | + None, | ||
| 34689 | + None, | ||
| 34690 | + Some(3), | ||
| 34691 | + smooth_neighbor_uv, fctx, | ||
| 34692 | + )?; | ||
| 34693 | + // Immediately, so the NEXT unit reads this one's | ||
| 34694 | + // coefficient context. | ||
| 34695 | + neighbours.record_mi_chroma( | ||
| 34696 | + cu_mi, chroma_tx, chroma_tx, plane_idx, &cu_grid, | ||
| 34697 | + ); | ||
| 34698 | + hit!(CHROMA_SPLIT_TX_HITS); | ||
| 34699 | + let acc = if plane_idx == 1 { &mut u_acc } else { &mut v_acc }; | ||
| 34700 | + for rr in 0..chroma_tx { | ||
| 34701 | + let start = | ||
| 34702 | + (cu_row * chroma_tx + rr) * chroma_side + cu_col * chroma_tx; | ||
| 34703 | + acc[start..start + chroma_tx] | ||
| 34704 | + .copy_from_slice(&cu_grid[rr * chroma_tx..][..chroma_tx]); | ||
| 34705 | + } | ||
| 34706 | + } | ||
| 34707 | + } | ||
| 34708 | + } | ||
| 34709 | + mu_chroma = true; | ||
| 34710 | + u_grid = Grid::Own(u_acc); | ||
| 34711 | + v_grid = Grid::Own(v_acc); | ||
| 34629 | } else { | 34712 | } else { |
| 34630 | if let Some((ub, _)) = &palette_uv_bufs { | 34713 | if let Some((ub, _)) = &palette_uv_bufs { |
| 34631 | set_palette_pred(ub.clone(), fctx); | 34714 | set_palette_pred(ub.clone(), fctx); |
crates/ec-av1/src/stream.rsmodified+18 -19
| @@ -5808,20 +5808,20 @@ pub(crate) mod tests { | |||
| 5808 | for f in &frames { | 5808 | for f in &frames { |
| 5809 | assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | 5809 | assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); |
| 5810 | } | 5810 | } |
| 5811 | - // Frames 0 and 1 are the byte-exact pin for the ss-aware 128-rect | 5811 | + // All three frames are pinned byte-exact against both oracles (the |
| 5812 | - // chroma walk itself (frame 0's keyframe PARTITION_VERT 64x128 and | 5812 | + // aomdec/ffmpeg arms below run over `.take(3)`): frame 0's keyframe |
| 5813 | - // frame 1's inter pieces). Frame 2 carries a SEPARATE, named | 5813 | + // PARTITION_VERT 64x128, frame 1's inter pieces, and frame 2 -- whose |
| 5814 | - // residual: its top LR stripe (RU row 0, rows 0..63, all three | 5814 | + // right superblock column (the 128-root VERT piece at the frame edge) |
| 5815 | - // planes) is never loop-restored on this inter frame -- our output | 5815 | + // is three intra blocks (64x64, 64x32, 64x32) whose chroma units ride |
| 5816 | - // equals the post-CDEF plane there while the oracle restores it | 5816 | + // the inter-frame intra tail. That tail read ONE whole-plane chroma |
| 5817 | - // (ours-vs-oracle final Y 7308 / U 9685 / V 14012, deterministic; | 5817 | + // unit with the block-level context where 4:4:4 codes four |
| 5818 | - // recon, deblock and CDEF are byte-exact at PREFILT/POSTDEBLOCK/ | 5818 | + // plane-major TX_32X32 units with per-unit contexts and the |
| 5819 | - // POSTCDEF). Site: the pipelined LR band accounting | 5819 | + // offset-10 `get_txb_ctx` rows, which left three quarters of the |
| 5820 | - // (`pipe_run_lr`'s `rrows` branch plus the `ls.note`/`ls.close` | 5820 | + // planes' residual unread and misaligned the symbol stream from the |
| 5821 | - // band release in `decode.rs`'s filter pipeline) never flushes RU | 5821 | + // first chroma unit on (f2 PREFILT Y 6952 / U 9568 / V 13496, first |
| 5822 | - // row 0 when the top superblock row carries a 128-root rect block | 5822 | + // diffs entering at column 128). Fixed on lane-av1-rect128recon; |
| 5823 | - // (this frame's inter 64x128 at (128,0)). That flush fix is its own | 5823 | + // the earlier "LR never restores RU row 0" attribution on this frame |
| 5824 | - // lane; asserting f2's current samples here would pin the bug. | 5824 | + // was a stage-ladder mixup, refuted in lane-av1lrflush r3. |
| 5825 | 5825 | ||
| 5826 | // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | 5826 | // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. |
| 5827 | if aomdec_path().is_file() { | 5827 | if aomdec_path().is_file() { |
| @@ -5847,7 +5847,7 @@ pub(crate) mod tests { | |||
| 5847 | let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | 5847 | let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); |
| 5848 | let _ = std::fs::remove_dir_all(&dir); | 5848 | let _ = std::fs::remove_dir_all(&dir); |
| 5849 | assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | 5849 | assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); |
| 5850 | - for (i, f) in frames.iter().enumerate().take(2) { | 5850 | + for (i, f) in frames.iter().enumerate().take(3) { |
| 5851 | let base = i * W * H * 3; | 5851 | let base = i * W * H * 3; |
| 5852 | for ((plane, off), p) in | 5852 | for ((plane, off), p) in |
| 5853 | [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | 5853 | [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] |
| @@ -5868,12 +5868,11 @@ pub(crate) mod tests { | |||
| 5868 | eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | 5868 | eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); |
| 5869 | } | 5869 | } |
| 5870 | 5870 | ||
| 5871 | - // ffmpeg's decoder: same frames, full-resolution chroma. Same f0/f1 | 5871 | + // ffmpeg's decoder: same frames, full-resolution chroma. Same |
| 5872 | - // scope as the aomdec arm above (frame 2 = the named LR-stripe-0 | 5872 | + // three-frame scope as the aomdec arm above. |
| 5873 | - // residual). | ||
| 5874 | if have_ffmpeg() { | 5873 | if have_ffmpeg() { |
| 5875 | let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | 5874 | let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); |
| 5876 | - for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(2) { | 5875 | + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) { |
| 5877 | for (p, (g, r)) in | 5876 | for (p, (g, r)) in |
| 5878 | [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | 5877 | [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] |
| 5879 | .iter() | 5878 | .iter() |
lanes/av1rect128recon.report.mdadded+88 -0
| @@ -0,0 +1,88 @@ | |||
| 1 | +# 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) | ||
| 2 | + | ||
| 3 | +## Outcome | ||
| 4 | + | ||
| 5 | +1. REPRODUCED at HEAD 99232190 (fresh target dir `cargo-target-av1rect128recon`, | ||
| 6 | + fixture sha256 `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80` | ||
| 7 | + re-verified, oracle aomdec `~/.cache/aom-oracle/build` regenerated this | ||
| 8 | + session): frame 2 diverges at PREFILT Y 6952 / U 9568 / V 13496, first diffs | ||
| 9 | + Y (col 128, row 98), U (col 128, row 64), V (col 128, row 0); f0/f1 exact. | ||
| 10 | + Numbers match av1444sbf2 r1 / av1lrflush r3 sample-for-sample. | ||
| 11 | +2. BLOCK-SHAPE CORRECTION (ladder evidence, not inference): the oracle's f2 | ||
| 12 | + top-right superblock root is a gathered-bit SPLIT, and its right column is | ||
| 13 | + INTRA blocks — 64x64 at (128,0), 64x32 at (128,64), 64x32 at (128,96), | ||
| 14 | + 64x64 at (128,128) — not "the inter 64x128 at (128,0)" the earlier lane | ||
| 15 | + reports name. Evidence: oracle `EC_PART`/`EC_PART_VAL` (ctx 14, values | ||
| 16 | + NONE/HORZ at mi (0,32)/(16,32)), `EC_PREDOUT8` per-unit sums, and | ||
| 17 | + `EC_DQCOEFF`. The earlier reports' pixel numbers are all reproduced here; | ||
| 18 | + only the block-shape naming was wrong. | ||
| 19 | +3. FIRST DIVERGENT SYMBOL, pinned by consecutive-TU rng alignment on both | ||
| 20 | + ladders (`EC_COEFF_STEP`, TU-boundary values 60168/55581/51541 matching | ||
| 21 | + line-for-line): the 64x64 intra block's FIRST chroma TX_32X32 unit at | ||
| 22 | + mi (0,32). Ours decoded `txb_skip` off the offset-7 context row (printed | ||
| 23 | + ctx 0); aom reads the offset-10 row (true ctx 10 — the uv plane block | ||
| 24 | + 64x64 is larger than the TX_32X32 unit). Same decoded value (skip), but | ||
| 25 | + the CDF rows differ, so the arithmetic coders consumed different bits and | ||
| 26 | + the rest of frame 2 decodes off a drifting state — bounded, mostly-skip | ||
| 27 | + garbage that still corrupted the block's own V plane (uniform −1: the | ||
| 28 | + missing V residual) and the bottom superblock row. | ||
| 29 | +4. ROOT CAUSE (one site): `decode_inter_block`'s intra tail read the block's | ||
| 30 | + chroma as ONE whole-plane unit (`read_plane` with `chroma_side`/`chroma_tx`, | ||
| 31 | + block-level `around`, no +10 offset) — a 4:2:0-era remnant. At 4:4:4 a | ||
| 32 | + 64x64 plane block is FOUR plane-major TX_32X32 units, each with its own | ||
| 33 | + `around_mi` context and the offset-10 rows. The keyframe path | ||
| 34 | + (`decode_block`'s `cn > 1` loop, lane-av1-444) and the inter tail's own | ||
| 35 | + ss-0/0 arm already did this correctly; the intra-in-inter tail was the one | ||
| 36 | + remaining copy of the old shape. The misnaming in (2) hid this: the | ||
| 37 | + "inter 64x128" framing pointed at Agent044's strip/inter territory, while | ||
| 38 | + the real site is the intra tail. | ||
| 39 | +5. FIX (decode.rs, intra tail chroma chain): new `ss_x==0 && ss_y==0 && | ||
| 40 | + chroma_side > chroma_tx` arm — four plane-major TX_32X32 units, per-unit | ||
| 41 | + `around_mi(cu_mi, 32)`, `Some(3)` skip-ctx offset (+10 convention on our | ||
| 42 | + chroma-32 table), immediate per-unit `record_mi_chroma`, per-unit | ||
| 43 | + `tu_reach`, assembled 64x64 plane grids, `mu_chroma = true` so the | ||
| 44 | + block-tail unit replay re-stamps after the whole-block record (class | ||
| 45 | + `override-slot-on-one-arm`). 4:2:0 is identical by construction: the arm | ||
| 46 | + is ss-gated and `chroma_side == chroma_tx` there still takes the old | ||
| 47 | + single-read path. Class sweep: the only other intra-in-inter chroma arms | ||
| 48 | + are the side>64 mu-chunk walk (already per-unit, correct) and the | ||
| 49 | + rect-strip readers (separate paths, sibling-owned, untouched). | ||
| 50 | +6. RESULT: f2 PREFILT byte-exact; FINAL (full deblock/CDEF/LR pipeline) | ||
| 51 | + byte-exact on ALL THREE frames against BOTH oracles — ours == | ||
| 52 | + `ffmpeg -f rawvideo -pix_fmt yuv444p` byte-for-byte (276480 bytes), and | ||
| 53 | + frame-equal to aomdec's Y4M output (its 12 interleaved `FRAME` markers | ||
| 54 | + stripped). | ||
| 55 | + | ||
| 56 | +## Verification | ||
| 57 | + | ||
| 58 | +- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` | ||
| 59 | + (extended to `.take(3)` in both oracle arms + rewritten scoping comment, | ||
| 60 | + same commit): PASS. | ||
| 61 | +- `cargo check -p ec-av1`: 0 warnings (target `$HOME/.cache/cargo-target-av1rect128recon`). | ||
| 62 | +- sb128 family (`cargo test -p ec-av1 --lib sb128`): 10 passed, 1 ignored. | ||
| 63 | +- 444 family (`--lib 444`): 4 passed (includes the lossless 444 | ||
| 64 | + min-partition-64 inter stream). | ||
| 65 | +- Restoration battery (`EC_AV1_REQUIRE_AOMENC=1 --lib restoration`): | ||
| 66 | + 10 passed, 0 failed. | ||
| 67 | +- chroma family (`--lib chroma`): 28 passed, 0 failed. | ||
| 68 | +- Stage evidence from env-gated rungs on both decoders (EC_PART/EC_PART_VAL, | ||
| 69 | + EC_COEFF_STEP, EC_ECDUMP_IN, EC_PREDOUT8, EC_IMODE, AOMMB, EC_DQCOEFF); | ||
| 70 | + throwaway /tmp scratch only, nothing left in the tree. | ||
| 71 | + | ||
| 72 | +## Decision | ||
| 73 | + | ||
| 74 | +- Gate extended and the stale "LR never restores RU row 0" scoping comment | ||
| 75 | + replaced (that attribution was refuted in lane-av1lrflush r3 as a | ||
| 76 | + stage-ladder mixup) — the deferred same-commit pairing is now discharged. | ||
| 77 | +- Sibling ownership respected: `decode_rect4_16_strip`'s 16x4/strip-tail | ||
| 78 | + territory and the sub-8 leaf paths untouched; the fix lands in | ||
| 79 | + `decode_inter_block`'s intra tail only. | ||
| 80 | +- Named for the record: any future block-shape work must sweep BOTH copies | ||
| 81 | + of the chroma unit walk — `decode_block` (keyframe) and | ||
| 82 | + `decode_inter_block`'s intra tail — plus the inter tail; this defect was | ||
| 83 | + the third copy drifting from the first two. | ||
| 84 | + | ||
| 85 | +## State | ||
| 86 | + | ||
| 87 | +- Commit on lane-av1-rect128recon (no push): decode.rs fix + stream.rs gate | ||
| 88 | + extension/comment + this report. | ||