forge
Explore
Log in

Don't you dare go Hollow

Chroma edge-filter type read the neighbours of the wrong mi -- a sub-8 pair codes its chroma at the ODD mi, libaom reads them off the chroma REFERENCE block

Browse files at this commit

589ba1a898b0d7262610347fb81f1f8180c5397bAhmet Kaan GümüşParent: 9753274
  • fix
    • chroma edge-filter type read the neighbours of the wrong mi -- a sub-8 pair codes its chroma at the ODD mi, libaom reads them off the chroma REFERENCE block
Show full message
fix(av1): chroma edge-filter type read the neighbours of the wrong mi -- a sub-8 pair codes its chroma at the ODD mi, libaom reads them off the chroma REFERENCE block

`Neighbours::smooth_uv_neighbour` took the caller's mi as-is. libaom's
`set_mi_row_col` (blockd.h) first snaps to the chroma reference block,
`base_mi = &xd->mi[-(mi_row & ss_y) * stride - (mi_col & ss_x)]`, and only
then reads `chroma_above_mbmi = base_mi[-stride]` / `chroma_left_mbmi =
base_mi[-1]`. For a sub-8 pair, whose chroma syntax lives at the odd mi, we
looked one mi row/column too far and the mi-exact slot never matched, so the
coarse SUB-grid fallback answered instead.

Consequence: `get_intra_edge_filter_type` came out 0 where libaom has 1,
which flips `av1_use_intra_edge_upsample(8, 4, -6, type)` (`blk_wh == 12`:
false at type 1, TRUE at type 0). We upsampled an edge libaom leaves alone.

Measured on the 2160p 10-bit key frame at -ss 900 (now
crates/ec-av1/fixtures/reelb_kf900.obu): chroma 8x4 at (688, 100) = mi (51, 344),
V_PRED p_angle=84, aomdec EC_PREDOUT sum 15924 vs ours 15930 (+1 on rows 2/3
at cols 1, 2, 4 -- reproduced exactly by the upsampled z1 walk in a
hand-simulation). First chroma difference on that frame moves from (102, 688)
to (195, 640), a residual-side defect whose prediction is bit-exact.

Gate: crates/ec-av1/fixtures/reelb_kf900.obu (484640 bytes, sha256
a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83, two
independent extracts hashed identically) decoded LUMA-exact vs ffmpeg with a
hard `skip_split_tx_hits() >= 15` assert -- the r1 tx-size-context defect. That
counter is unreachable from aomenc: 108 measured recipes (72 8-bit, 36 10-bit;
geq half-flat/half-noise, mandelbrot, testsrc2, noise seed 49, cq 55/59/63,
cpu-used 0..2, tx-size-search + min-partition-size=8 + rect partitions) all
report 0, because libaom's encoder forces tx_size to the block maximum once it
picks skip_txfm. The two multi-tile arms that carried the impossible assert
keep their pixel-exact comparison and name the fixture gate instead.
crates/ec-av1/fixtures/reelb_kf900.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+17 -0
@@ -4638,6 +4638,23 @@ impl Neighbours {
4638 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no4638 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no
4639 /// block has recorded the exact neighbouring mi.4639 /// block has recorded the exact neighbouring mi.
4640 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {4640 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
4641+ // lane-kf900 r2: libaom reads the chroma neighbours off the CHROMA
4642+ // REFERENCE block, not off the mi that carries the chroma syntax.
4643+ // `set_mi_row_col` (`blockd.h`) takes
4644+ // `base_mi = &xd->mi[-(mi_row & ss_y) * stride - (mi_col & ss_x)]` and
4645+ // only then `chroma_above_mbmi = base_mi[-stride]` /
4646+ // `chroma_left_mbmi = base_mi[-1]`. A sub-8 pair codes its chroma at
4647+ // the ODD mi, so without the snap we looked one mi row/column too far
4648+ // down/right -- the mi-exact slot never matched and the coarse
4649+ // fallback answered instead. Measured on a 4K 10-bit key frame, chroma
4650+ // 8x4 at (688, 100) = mi (51, 344): libaom's
4651+ // `get_intra_edge_filter_type` is 1 (the chroma block above it is
4652+ // `UV_SMOOTH_PRED`), ours was 0, which flips
4653+ // `av1_use_intra_edge_upsample(8, 4, -6, type)` (`blk_wh == 12`:
4654+ // false for type 1, TRUE for type 0) and upsampled an edge libaom
4655+ // leaves alone -- +1 on rows 2/3 of that block and every chroma block
4656+ // predicting from it (class `context-read-from-one-cell`).
4657+ let (mi_r, mi_c) = (mi_r & !1, mi_c & !1);
4641 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the4658 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
4642 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid4659 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
4643 // array that `start_tile` does not clear, so a block on a tile's first4660 // array that `start_tile` does not clear, so a block on a tile's first
crates/ec-av1/src/stream.rsmodified+76 -12
@@ -2973,6 +2973,54 @@ mod tests {
2973 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");2973 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");
2974 }2974 }
2975 2975
2976+ /// lane-kf900 r2: the film's key frame at -ss 900, one frame
2977+ /// (`crates/ec-av1/fixtures/reelb_kf900.obu`, 484640 bytes, sha256
2978+ /// `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`,
2979+ /// extracted twice from independent
2980+ /// `ffmpeg -ss 900 -t 2 -i <2160p AV1 HDR10 mkv> -c:v copy -f obu` runs and
2981+ /// truncated to the first frame; both extracts hashed identically).
2982+ ///
2983+ /// This is the ONLY stream that reaches the r1 defect: a SKIPPED 8x8 intra
2984+ /// leaf whose `tx_depth` symbol resolved to `TX_4X4` still publishes 4 --
2985+ /// not its 8-pixel block side -- to the next block's `get_tx_size_context`
2986+ /// (`set_txfm_ctxs(mbmi->tx_size, bw, bh, skip_txfm && is_inter_block(...))`,
2987+ /// `decodemv.c`; the skip term is 0 for intra). It fires 15 times here and
2988+ /// zero times across 108 measured aomenc recipes, so the counter is
2989+ /// asserted against the film rather than against a synthesised stream.
2990+ ///
2991+ /// LUMA only. U/V still differ (open residue, lane-kf900 r2: 221 U and
2992+ /// 47912 V samples, max |d| 23/2, first at chroma (195, 640) -- chroma
2993+ /// RESIDUAL, the prediction there is bit-exact against aomdec's
2994+ /// `EC_PREDOUT`), so this gate pins what is proven and no more.
2995+ #[test]
2996+ fn a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact()
2997+ {
2998+ const NAME: &str = "a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact";
2999+ if !have_ffmpeg() {
3000+ eprintln!("SKIP {NAME}: no ffmpeg");
3001+ return;
3002+ }
3003+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelb_kf900.obu");
3004+ let stream = std::fs::read(&path)
3005+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
3006+ let (width, height) = (3840usize, 1608usize);
3007+ crate::decode::reset_skip_split_tx_hits();
3008+ let frames = match decode_stream(&stream) {
3009+ Ok(frames) => frames,
3010+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
3011+ };
3012+ assert_eq!(frames.len(), 1, "{NAME}: one key frame");
3013+ assert_eq!((frames[0].width, frames[0].height), (width, height));
3014+ assert!(
3015+ crate::decode::skip_split_tx_hits() >= 15,
3016+ "{NAME}: skip_split_tx_hits() == {} -- the stream that carries the tx-context \
3017+ defect stopped carrying it, so this gate proves nothing",
3018+ crate::decode::skip_split_tx_hits()
3019+ );
3020+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1);
3021+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg");
3022+ }
3023+
2976 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=13024 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1
2977 /// --superres-denominator=12` key frame, decoded pixel-exact against3025 /// --superres-denominator=12` key frame, decoded pixel-exact against
2978 /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s3026 /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s
@@ -21530,12 +21578,20 @@ mod tests {
21530 "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact";21578 "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact";
21531 crate::decode::reset_skip_split_tx_hits();21579 crate::decode::reset_skip_split_tx_hits();
21532 run_multi_tile_gate(NAME, 0, 0, 8, 1, &[], false, None);21580 run_multi_tile_gate(NAME, 0, 0, 8, 1, &[], false, None);
21533- if have_ffmpeg() && have_aomenc() {21581+ // lane-kf900 r2: the counter assert that used to sit here is
21534- assert!(21582+ // UNREACHABLE from aomenc. 108 measured recipes (72 at 8-bit, 36 at
21535- crate::decode::skip_split_tx_hits() > 0,21583+ // 10-bit: `geq` half-flat/half-noise, `mandelbrot`, `testsrc2`,
21536- "{NAME}: no skipped 8x8 intra leaf split its transform -- the gate proves nothing"21584+ // `noise=all_seed=49`, cq 55/59/63, `--cpu-used=0..2`,
21537- );21585+ // `--enable-tx-size-search=1 --min-partition-size=8
21538- }21586+ // --enable-rect-partitions=1`; log
21587+ // `$HOME/.cache/kf900/sweep/results{,10}.tsv`) produced
21588+ // `skip_split_tx_hits() == 0` on every stream that decoded, because
21589+ // libaom's own encoder forces `tx_size` to the block maximum once it
21590+ // decides `skip_txfm` -- so no aomenc stream carries a SKIPPED 8x8
21591+ // intra leaf whose `tx_depth` resolved to `TX_4X4`. The film's
21592+ // encoder does; the counter is hard-asserted on the real stream in
21593+ // [`a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`].
21594+ // These two arms stay as the pixel-exact multi-tile control.
21539 }21595 }
21540 21596
21541 /// [`a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact`]'s21597 /// [`a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact`]'s
@@ -21546,12 +21602,20 @@ mod tests {
21546 const NAME: &str = "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_10bit_decodes_pixel_exact";21602 const NAME: &str = "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_10bit_decodes_pixel_exact";
21547 crate::decode::reset_skip_split_tx_hits();21603 crate::decode::reset_skip_split_tx_hits();
21548 run_multi_tile_gate(NAME, 0, 0, 10, 1, &[], false, None);21604 run_multi_tile_gate(NAME, 0, 0, 10, 1, &[], false, None);
21549- if have_ffmpeg() && have_aomenc() {21605+ // lane-kf900 r2: the counter assert that used to sit here is
21550- assert!(21606+ // UNREACHABLE from aomenc. 108 measured recipes (72 at 8-bit, 36 at
21551- crate::decode::skip_split_tx_hits() > 0,21607+ // 10-bit: `geq` half-flat/half-noise, `mandelbrot`, `testsrc2`,
21552- "{NAME}: no skipped 8x8 intra leaf split its transform -- the gate proves nothing"21608+ // `noise=all_seed=49`, cq 55/59/63, `--cpu-used=0..2`,
21553- );21609+ // `--enable-tx-size-search=1 --min-partition-size=8
21554- }21610+ // --enable-rect-partitions=1`; log
21611+ // `$HOME/.cache/kf900/sweep/results{,10}.tsv`) produced
21612+ // `skip_split_tx_hits() == 0` on every stream that decoded, because
21613+ // libaom's own encoder forces `tx_size` to the block maximum once it
21614+ // decides `skip_txfm` -- so no aomenc stream carries a SKIPPED 8x8
21615+ // intra leaf whose `tx_depth` resolved to `TX_4X4`. The film's
21616+ // encoder does; the counter is hard-asserted on the real stream in
21617+ // [`a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`].
21618+ // These two arms stay as the pixel-exact multi-tile control.
21555 }21619 }
21556 21620
21557 #[test]21621 #[test]