ec-av1: reconstruct skipped sub8 intrabc chroma
Browse files at this commit2c4214864d0beaef1b5402237b66f915f72e9d9aParent: e72b9473 changed files +172 -32
- crates/ec-av1/src/decode.rs +49 -24
- crates/ec-av1/src/stream.rs +18 -8
- lanes/av1loss64.report.md +105 -0
crates/ec-av1/src/decode.rsmodified+49 -24
| @@ -17884,7 +17884,7 @@ fn decode_leaf_rect8( | ||
| 17884 | 17884 | neighbours.above_uv_mode[c] = uv_predict_mode; |
| 17885 | 17885 | neighbours.left_uv_mode[r] = uv_predict_mode; |
| 17886 | 17886 | neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); |
| 17887 | - let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] { | |
| 17887 | + let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] && last_intrabc.is_none() { | |
| 17888 | 17888 | // A skipped chroma block still gets its CfL contribution: libaom's |
| 17889 | 17889 | // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` |
| 17890 | 17890 | // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) |
| @@ -17914,37 +17914,62 @@ fn decode_leaf_rect8( | ||
| 17914 | 17914 | } |
| 17915 | 17915 | (Grid::Zero(16), Grid::Zero(16)) |
| 17916 | 17916 | } else if let Some(dv) = last_intrabc { |
| 17917 | - // lane-av1txr: the chroma-reference leaf was an intrabc block, so the | |
| 17918 | - // group's one chroma unit is a frame copy at that DV too (its residual | |
| 17919 | - // still reads the ordinary `Chroma4` coefficient tables -- libaom | |
| 17920 | - // codes a chroma `tx_type` nowhere). | |
| 17917 | + // A 4:2:0 `BLOCK_4X8`/`BLOCK_8X4` leaf maps to a clamped chroma | |
| 17918 | + // `BLOCK_4X4` (`get_plane_block_size`, blockd.h:1184; `set_plane_n4`, | |
| 17919 | + // av1_common_int.h:1344). The chroma reference is still the whole | |
| 17920 | + // 8x8 group's 4x4 plane block at `(cpx, cpy)`, so prediction uses the | |
| 17921 | + // group's destination origin, not the odd-mi leaf's nominal 2x4/4x2 | |
| 17922 | + // extent. The old route treated a skipped intrabc leaf as skipped | |
| 17923 | + // intra and predicted this block with DC, first differing at | |
| 17924 | + // mi(46,52), U(104,92), while consuming identical symbols. | |
| 17925 | + let chroma_mv_x = mv_to_q4(cpx, dv.1, false); | |
| 17926 | + let chroma_mv_y = mv_to_q4(cpy, dv.0, false); | |
| 17927 | + // `decode_reconstruct_tx` reads no chroma coefficients for a skipped | |
| 17928 | + // intrabc block, but an unskipped one reads the ordinary Chroma4 | |
| 17929 | + // tables; chroma inherits no coded tx_type of its own. | |
| 17921 | 17930 | let mut ub = vec![0u16; 16]; |
| 17922 | 17931 | mc::predict_with_filter( |
| 17923 | 17932 | &u.data, u.width, u.true_width, u.true_height, |
| 17924 | - mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), | |
| 17925 | - 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, | |
| 17933 | + chroma_mv_x, chroma_mv_y, 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, | |
| 17926 | 17934 | ); |
| 17927 | 17935 | let mut vb = vec![0u16; 16]; |
| 17928 | 17936 | mc::predict_with_filter( |
| 17929 | 17937 | &v.data, v.width, v.true_width, v.true_height, |
| 17930 | - mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), | |
| 17931 | - 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, | |
| 17938 | + chroma_mv_x, chroma_mv_y, 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, | |
| 17932 | 17939 | ); |
| 17933 | - let chroma_around = neighbours.around_mi(leaf_mi, 8); | |
| 17934 | - set_palette_pred(ub, fctx); | |
| 17935 | - let ug = read_plane( | |
| 17936 | - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, | |
| 17937 | - 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | |
| 17938 | - None, None, None, smooth_neighbor_uv, fctx, | |
| 17939 | - )?; | |
| 17940 | - set_palette_pred(vb, fctx); | |
| 17941 | - let vg = read_plane( | |
| 17942 | - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, | |
| 17943 | - 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | |
| 17944 | - None, None, None, smooth_neighbor_uv, fctx, | |
| 17945 | - )?; | |
| 17946 | - fctx.intrabc_chroma_tx.with(|c| c.set(None)); | |
| 17947 | - (ug, vg) | |
| 17940 | + if leaf_skips[1] { | |
| 17941 | + // `skip_txfm` still reconstructs an intrabc prediction, but | |
| 17942 | + // libaom's `decode_reconstruct_tx` reads NO chroma coefficients. | |
| 17943 | + // The ordinary skipped-intra arm above is therefore not valid for | |
| 17944 | + // an intrabc leaf: use the copied, clamped 4x4 prediction directly. | |
| 17945 | + push_mc_rect( | |
| 17946 | + 1, cpx, cpy, 4, 4, 4, Pred::Inline(&ub, 4), | |
| 17947 | + &ZERO_RESIDUAL[..16], fctx, | |
| 17948 | + ); | |
| 17949 | + push_mc_rect( | |
| 17950 | + 2, cpx, cpy, 4, 4, 4, Pred::Inline(&vb, 4), | |
| 17951 | + &ZERO_RESIDUAL[..16], fctx, | |
| 17952 | + ); | |
| 17953 | + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); | |
| 17954 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | |
| 17955 | + (Grid::Zero(16), Grid::Zero(16)) | |
| 17956 | + } else { | |
| 17957 | + let chroma_around = neighbours.around_mi(leaf_mi, 8); | |
| 17958 | + set_palette_pred(ub, fctx); | |
| 17959 | + let ug = read_plane( | |
| 17960 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, | |
| 17961 | + 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | |
| 17962 | + None, None, None, smooth_neighbor_uv, fctx, | |
| 17963 | + )?; | |
| 17964 | + set_palette_pred(vb, fctx); | |
| 17965 | + let vg = read_plane( | |
| 17966 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, | |
| 17967 | + 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | |
| 17968 | + None, None, None, smooth_neighbor_uv, fctx, | |
| 17969 | + )?; | |
| 17970 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | |
| 17971 | + (ug, vg) | |
| 17972 | + } | |
| 17948 | 17973 | } else { |
| 17949 | 17974 | let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); |
| 17950 | 17975 | let chroma_around = neighbours.around_mi(leaf_mi, 8); |
crates/ec-av1/src/stream.rsmodified+18 -8
| @@ -5148,12 +5148,12 @@ pub(crate) mod tests { | ||
| 5148 | 5148 | /// `EC_ECDUMP` against the instrumented aomdec) -- a coefficient-walk |
| 5149 | 5149 | /// desync at byte 61712 with every mode symbol still matching. |
| 5150 | 5150 | /// |
| 5151 | - /// This stream is the same source at `--min-partition-size=8`, which | |
| 5152 | - /// keeps sub-8x8 partitions out: post-fix it is full-frame exact. The | |
| 5153 | - /// `--min-partition-size=4` sibling still is not -- its remaining | |
| 5154 | - /// divergence is a sub-8x8 4x8-leaf chroma reconstruction defect with the | |
| 5155 | - /// entropy ladder fully synced (first diff U(92,104), luma byte-exact), | |
| 5156 | - /// deferred to the sub-8x8 lane family (lanes/av1loss64.report.md). | |
| 5151 | + /// This gate uses the same `--min-partition-size=4` arm that reaches the | |
| 5152 | + /// sub-8x8 VERT -> 4x8 skipped-intrabc leaf. Post-fix it is full-frame | |
| 5153 | + /// exact: the skip path uses libaom's clamped 4x4 chroma intrabc | |
| 5154 | + /// prediction (`decodeframe.c:1011-1065`, `reconinter_template.inc:186-207`) | |
| 5155 | + /// instead of the ordinary skipped-intra DC predictor. The old route first | |
| 5156 | + /// differed at U(104,92) with the entropy ladder fully synced. | |
| 5157 | 5157 | /// |
| 5158 | 5158 | /// Fail-pre-fix, measured on the ed12fe52 probe: differs at byte 41120 |
| 5159 | 5159 | /// (the chroma-clip class, fixed in the same lane). Single-mutation on |
| @@ -5166,16 +5166,23 @@ pub(crate) mod tests { | ||
| 5166 | 5166 | eprintln!("SKIP {NAME}: no ffmpeg"); |
| 5167 | 5167 | return; |
| 5168 | 5168 | } |
| 5169 | - let stream = lossless_sb128_testsrc2(320, 242, &["--min-partition-size=8"]); | |
| 5169 | + let stream = lossless_sb128_testsrc2(320, 242, &["--min-partition-size=4"]); | |
| 5170 | 5170 | crate::decode::reset_loss64_hits(); |
| 5171 | + crate::decode::reset_skipped_intrabc_chroma_arm_hits(); | |
| 5171 | 5172 | let ours = decode_stream(&stream) |
| 5172 | 5173 | .unwrap_or_else(|e| panic!("{NAME}: decodes: {e}")); |
| 5173 | 5174 | let resets = crate::decode::skip_lossless_band_reset_hits(); |
| 5175 | + let intrabc_skips = crate::decode::skipped_intrabc_chroma_arm_hits(); | |
| 5174 | 5176 | assert!( |
| 5175 | 5177 | resets > 0, |
| 5176 | 5178 | "{NAME}: this stream coded NO skipped lossless intrabc rect strip -- \ |
| 5177 | 5179 | the fixed body was never reached (class gate-blind-to-feature)" |
| 5178 | 5180 | ); |
| 5181 | + assert!( | |
| 5182 | + intrabc_skips > 0, | |
| 5183 | + "{NAME}: this stream coded NO skipped sub-8x8 intrabc chroma leaf -- \ | |
| 5184 | + the clamped chroma prediction fix was never reached (class gate-blind-to-feature)" | |
| 5185 | + ); | |
| 5179 | 5186 | let refs = ffmpeg_decode_sequence(&stream, 320, 242, 1); |
| 5180 | 5187 | assert_eq!(ours.len(), 1, "{NAME}: frame count"); |
| 5181 | 5188 | for (plane, (g, r)) in [(&ours[0].y, &refs[0].y), (&ours[0].u, &refs[0].u), (&ours[0].v, &refs[0].v)] |
| @@ -5185,7 +5192,10 @@ pub(crate) mod tests { | ||
| 5185 | 5192 | let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); |
| 5186 | 5193 | assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ from ffmpeg"); |
| 5187 | 5194 | } |
| 5188 | - eprintln!("{NAME}: full-frame exact, {resets} band resets"); | |
| 5195 | + eprintln!( | |
| 5196 | + "{NAME}: full-frame exact, {resets} band resets, \ | |
| 5197 | + {intrabc_skips} skipped intrabc chroma predictions" | |
| 5198 | + ); | |
| 5189 | 5199 | } |
| 5190 | 5200 | |
| 5191 | 5201 | /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and |
lanes/av1loss64.report.mdadded+105 -0
| @@ -0,0 +1,105 @@ | ||
| 1 | +# lane-av1-loss64 — lossless sb128 full-frame exact, including skipped sub-8x8 intrabc chroma | |
| 2 | + | |
| 3 | +Base: `main` **ed12fe52** (rect14 merged). Worktree | |
| 4 | +`/home/user/Documents/Code/Rust/edith_codecs-av1l64`, branch | |
| 5 | +`lane-av1-loss64`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss64`, | |
| 6 | +`TMPDIR=$HOME/.cache/tmp-av1loss64`. Nothing pushed. | |
| 7 | + | |
| 8 | +## 1. Headline | |
| 9 | + | |
| 10 | +The lane closes the lossless `sb-size=128` 320x240 acceptance arm at | |
| 11 | +full-frame sample exactness. It also fixes the remaining 4:8/8:4 sub-8x8 | |
| 12 | +chroma prediction defect in a skipped intrabc leaf. The first source fix is | |
| 13 | +committed as `0226fc11` (`ec-av1: clip lossless chroma TUs and reset skip bands`); | |
| 14 | +the skipped-intrabc chroma fix and its gate are the follow-up commit on this | |
| 15 | +branch. | |
| 16 | + | |
| 17 | +Verified gates: | |
| 18 | + | |
| 19 | +``` | |
| 20 | +a_lossless_sb128_square_frame_clips_overhanging_chroma_tus | |
| 21 | + 2 arms full-frame exact, 192 chroma units clipped | |
| 22 | + | |
| 23 | +a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands | |
| 24 | + full-frame exact, 1 band resets, 3 skipped intrabc chroma predictions | |
| 25 | +``` | |
| 26 | + | |
| 27 | +The first gate is the required 320x240 lossless sb128 full-frame witness. The | |
| 28 | +second is a 320x242 sibling generated with `--min-partition-size=4`; it reaches | |
| 29 | +the sub-8x8 VERT -> 4x8 skipped-intrabc leaf and is also full-frame exact. | |
| 30 | + | |
| 31 | +## 2. Root causes | |
| 32 | + | |
| 33 | +Two independent defects were present in the cancelled WIP: | |
| 34 | + | |
| 35 | +* A lossless chroma transform unit at a frame edge was read with the nominal | |
| 36 | + geometry instead of libaom's clipped per-plane geometry. The decoder could | |
| 37 | + read or reconstruct outside the valid chroma plane footprint. | |
| 38 | +* In `decode_leaf_rect8`, a 4:8/8:4 chroma-reference leaf with `skip_txfm=1` | |
| 39 | + and `use_intrabc=1` was sent through the ordinary skipped-intra branch. | |
| 40 | + That branch predicts chroma with DC/CfL, but libaom still reconstructs a | |
| 41 | + skipped intrabc block from its motion-compensated copy; skip only suppresses | |
| 42 | + residual coefficient reads. The entropy ladder remained synchronized while | |
| 43 | + the first wrong sample was U(104,92) at luma mi(46,52). | |
| 44 | + | |
| 45 | +For 4:2:0, libaom clamps a 4x8/8x4 leaf's chroma plane block to `BLOCK_4X4`: | |
| 46 | +`set_plane_n4` in `av1_common_int.h:1344` and `get_plane_block_size` in | |
| 47 | +`blockd.h:1184`. The fix therefore predicts a 4x4 U and V block at the group's | |
| 48 | +chroma origin `(cpx, cpy)`, using the intrabc DV, and writes no chroma | |
| 49 | +coefficients on the skipped route. An unskipped intrabc leaf keeps the ordinary | |
| 50 | +`Chroma4` coefficient walk over the same 4x4 prediction. Both routes disarm | |
| 51 | +`intrabc_chroma_tx`. | |
| 52 | + | |
| 53 | +The lossless skip-band fix resets the complete luma entropy-band footprint | |
| 54 | +before the next block. Its measured sibling previously left a stale band and | |
| 55 | +read the next `txb_skip_ctx` differently from libaom. | |
| 56 | + | |
| 57 | +## 3. Repro and exactness | |
| 58 | + | |
| 59 | +Oracle: `~/.cache/aom-oracle/build/aomenc`; pixel reference: ffmpeg. | |
| 60 | + | |
| 61 | +The sub-8x8 witness was generated from `testsrc2=s=320x242:r=25`, one frame, | |
| 62 | +with `--lossless=1 --sb-size=128 --enable-1to4-partitions=1 | |
| 63 | +--min-partition-size=4 --obu`. The committed-lane release probe and ffmpeg | |
| 64 | +reference have identical decoded bytes (`diff 0`). Artifact hashes: | |
| 65 | + | |
| 66 | +``` | |
| 67 | +obu: 1fe5edc300a378c486abe385dad8251f3f21452f04e5a6f60f69feb48e58c8cb | |
| 68 | +ref8: 421ca38c91a133e78b84a9a3c9f79defbddbc7163a0b3088a176f4cd50179728 | |
| 69 | +ours: f8fc6c3248e6d8782ebccd88d46f7254aa8915fd4deaf62b7b92953599709eda | |
| 70 | +``` | |
| 71 | + | |
| 72 | +Before the chroma-route fix, Y was exact but U/V differed at 2,488 samples; | |
| 73 | +the first difference was U(104,92). After the fix, all Y/U/V samples are exact. | |
| 74 | +The gate reports three reached skipped-intrabc chroma predictions and one | |
| 75 | +lossless band reset, so neither fix is gate-blind. | |
| 76 | + | |
| 77 | +## 4. Changed paths | |
| 78 | + | |
| 79 | +* `crates/ec-av1/src/decode.rs`: clip lossless chroma TU geometry; clear the | |
| 80 | + skipped lossless entropy bands; route skipped sub-8x8 intrabc chroma through | |
| 81 | + clamped 4x4 motion-compensated prediction; add the engagement hit used by the | |
| 82 | + gate. | |
| 83 | +* `crates/ec-av1/src/stream.rs`: change the lossless skip-band gate to the | |
| 84 | + min-partition-size=4 witness and assert both the band-reset and skipped | |
| 85 | + intrabc-chroma counters. | |
| 86 | + | |
| 87 | +No refusal string, encoder path, or unrelated decode seat was changed. | |
| 88 | + | |
| 89 | +## 5. Verification run | |
| 90 | + | |
| 91 | +Targeted commands, all with private lane target and temp directories: | |
| 92 | + | |
| 93 | +``` | |
| 94 | +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ | |
| 95 | + a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands -- --nocapture | |
| 96 | +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ | |
| 97 | + a_lossless_sb128_square_frame_clips_overhanging_chroma_tus -- --nocapture | |
| 98 | +``` | |
| 99 | + | |
| 100 | +Both passed. The release `decode_probe` was rebuilt and independently compared | |
| 101 | +to ffmpeg for the 320x242 min4 witness; all planes were byte exact. | |
| 102 | + | |
| 103 | +The project-wide suite, 0-warning parity sweep, and the cross-lane acceptance | |
| 104 | +arms (mono, 10-bit `reelb_*`, CDF-disabled, 4:4:4 refusal, qmatrix refusal) are | |
| 105 | +owned by the main agent and were not run in this lane. |