forge
Explore
Log in

Don't you dare go Hollow

A skipped sub-8x8 chroma block dropped its CfL alpha entirely

Browse files at this commit

f4f89dfa20db681d2f24270d2b4aa2cfb2d0a497Ahmet Kaan GümüşParent: 28188f3
  • fix
    • a skipped sub-8x8 chroma block dropped its CfL alpha entirely
Show full message
fix(av1): a skipped sub-8x8 chroma block dropped its CfL alpha entirely

Both sub-8x8 leaf paths (decode.rs:10554 4-leaf, :10916 2-leaf) passed
`None` for the CfL argument in their `skip_txfm` arm, so a chroma block
with `uv_mode == UV_CFL_PRED` and no residual reconstructed as flat DC.
libaom's `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)
calls `cfl_predict_block` whenever `mbmi->uv_mode == UV_CFL_PRED`;
`skip_txfm` only drops the residual, never the alpha.

Sweep of the class: every `reconstruct`/`reconstruct_rect` chroma call
site was checked for a literal `None` in the cfl slot -- the rect skip
arms (6015/6519/8078) already pass it, and the one remaining `None`
(20284) sits behind a refusal that forces `uv_mode == DC_PRED`.

Gate: a new pinned 1-frame 3840x1608 10-bit AV1 key frame fixture plus a
test that hard-asserts `skip_cfl_hits > 0` (the shape fires exactly once
in that frame; lane-reelckf r1 already burned 20 aomenc recipes hunting a
skipped sub-8x8 CfL block and never produced one, so a synthetic gate is
out of reach). Before the fix 463 bytes of that frame's chroma were
wrong; after it the frame is pixel-exact against ffmpeg.
crates/ec-av1/fixtures/reelb_ss300_key_frame.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+31 -4
@@ -2202,6 +2202,15 @@ thread_local! {
2202 /// the shape that made 4 chroma samples of the ReelB `-ss 1200`2202 /// the shape that made 4 chroma samples of the ReelB `-ss 1200`
2203 /// key frame miss by 1. Zero here means a gate never exercised the fix.2203 /// key frame miss by 1. Zero here means a gate never exercised the fix.
2204 static RECT4_16_UV_PAIR_FILT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2204 static RECT4_16_UV_PAIR_FILT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2205+ /// lane-kf1200 r2: sub-8x8 chroma blocks that are `skip_txfm` AND
2206+ /// `UV_CFL_PRED` -- the arm that used to drop the CfL alpha entirely.
2207+ static SKIP_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2208+}
2209+
2210+/// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape
2211+/// that reconstructed as flat DC before lane-kf1200 r2).
2212+pub fn skip_cfl_hits() -> usize {
2213+ SKIP_CFL_HITS.with(|c| c.get())
2205 }2214 }
2206 2215
2207 /// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type`2216 /// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type`
@@ -10538,8 +10547,17 @@ fn decode_leaf_split4(
10538 neighbours.left_uv_mode[r] = uv_predict_mode;10547 neighbours.left_uv_mode[r] = uv_predict_mode;
10539 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);10548 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
10540 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {10549 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {
10541- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10550+ // A skipped chroma block still gets its CfL contribution: libaom's
10542- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10551+ // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`
10552+ // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)
10553+ // whenever `mbmi->uv_mode == UV_CFL_PRED`, before any residual is
10554+ // added -- `skip_txfm` only drops the residual, never the alpha.
10555+ let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
10556+ if alpha.is_some() {
10557+ SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
10558+ }
10559+ u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv);
10560+ v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv);
10543 (vec![0i32; 16], vec![0i32; 16])10561 (vec![0i32; 16], vec![0i32; 16])
10544 } else {10562 } else {
10545 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));10563 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
@@ -10891,8 +10909,17 @@ fn decode_leaf_rect8(
10891 neighbours.left_uv_mode[r] = uv_predict_mode;10909 neighbours.left_uv_mode[r] = uv_predict_mode;
10892 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);10910 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
10893 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] {10911 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] {
10894- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10912+ // A skipped chroma block still gets its CfL contribution: libaom's
10895- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10913+ // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`
10914+ // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)
10915+ // whenever `mbmi->uv_mode == UV_CFL_PRED`, before any residual is
10916+ // added -- `skip_txfm` only drops the residual, never the alpha.
10917+ let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
10918+ if alpha.is_some() {
10919+ SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
10920+ }
10921+ u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv);
10922+ v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv);
10896 (vec![0i32; 16], vec![0i32; 16])10923 (vec![0i32; 16], vec![0i32; 16])
10897 } else {10924 } else {
10898 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));10925 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
crates/ec-av1/src/stream.rsmodified+41 -0
@@ -2973,6 +2973,47 @@ 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-kf1200 r2: the same film's `-ss 300` key frame, pinned because no
2977+ /// aomenc recipe reaches its shape -- a SKIPPED sub-8x8 chroma block whose
2978+ /// `uv_mode` is `UV_CFL_PRED`. (lane-reelckf r1 burned 20 recipes across cq
2979+ /// 40..63 and nine lavfi sources hunting exactly this block and never got
2980+ /// one; ledger dead-end "never produced a SKIPPED 1:4 or sub-8x8 CfL
2981+ /// block".) Before the fix the two sub-8x8 skip arms passed `None` for the
2982+ /// CfL argument, so the block reconstructed as flat DC and 463 bytes of
2983+ /// this frame's chroma were wrong. HARD-asserts `skip_cfl_hits` moved, so
2984+ /// the fixture cannot silently stop exercising the arm.
2985+ #[test]
2986+ fn the_reelb_ss300_key_frame_skipped_cfl_decodes_pixel_exact() {
2987+ const NAME: &str = "the_reelb_ss300_key_frame_skipped_cfl_decodes_pixel_exact";
2988+ if !have_ffmpeg() {
2989+ eprintln!("SKIP {NAME}: no ffmpeg");
2990+ return;
2991+ }
2992+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
2993+ .join("fixtures/reelb_ss300_key_frame.obu");
2994+ let stream = std::fs::read(&path)
2995+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
2996+ let (width, height) = (3840usize, 1608usize);
2997+ let before = crate::decode::skip_cfl_hits();
2998+ let frames = match decode_stream(&stream) {
2999+ Ok(frames) => frames,
3000+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
3001+ };
3002+ let skipped_cfl = crate::decode::skip_cfl_hits() - before;
3003+ assert!(
3004+ skipped_cfl > 0,
3005+ "{NAME}: zero skipped sub-8x8 CfL blocks -- the fixture no longer \
3006+ exercises the arm this test exists for"
3007+ );
3008+ assert_eq!(frames.len(), 1, "{NAME}: one key frame");
3009+ assert_eq!((frames[0].width, frames[0].height), (width, height));
3010+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1);
3011+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg");
3012+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg");
3013+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");
3014+ eprintln!("{NAME}: {skipped_cfl} skipped sub-8x8 CfL chroma blocks, frame pixel-exact");
3015+ }
3016+
2976 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=13017 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1
2977 /// --superres-denominator=12` key frame, decoded pixel-exact against3018 /// --superres-denominator=12` key frame, decoded pixel-exact against
2978 /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s3019 /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s