forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1422mixll10: skipped intrabc+lossless 4:2:2 leaf writes both chroma rows

Browse files at this commit

dd25ef9589a8e3d6dd193216222c81776e43123dAhmet Kaan GümüşParent: e806f1b451c769
An 8x8 intrabc leaf in a lossless segment at 4:2:2 fell through decode_leaf8's skip-arm else and pushed one 4x4 of a 4x8 chroma plane block. The second row stayed unwritten (sentinel 0). Witness 422_mixll_intrabc_lossless_320x240_5f.obu sha256 9fa1f1d28d61e3096d70908728f9cdfa1a570b9769a3d31e8d385a61c12a2b25, frame 0 U/V (140..143,188..191) 0 vs 664/64. The else now windows the override per 4x4 unit. Gate green, flip control 0 to 1, stash mutation reds [0,16,16]. Reviewer PASS 0.93. The U arm already pushes both planes and the V arm pushes plane 2 again with the same arguments; that second push rewrites samples only and does not republish context.
crates/ec-av1/fixtures/422_mixll_intrabc_lossless_320x240_5f.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+134 -28
@@ -25692,20 +25692,82 @@ fn decode_leaf8(
2569225692 }
2569325693 }
2569425694 } else {
25695- push_intra(
25696- 1,
25697- cpx,
25698- cpy,
25699- csz,
25700- uv_predict_mode,
25701- angle_delta_uv,
25702- reach,
25703- &ZERO_RESIDUAL[..csz * csz],
25704- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
25705- None,
25706- smooth_neighbor_uv,
25707- fctx,
25708- );
25695+ // lane-av1422mixll10: with a prediction override (intrabc's
25696+ // frame copy at the DV, or a palette colour map), a skipped
25697+ // leaf predicts its WHOLE chroma plane block, not one csz x
25698+ // csz corner of it. At 4:2:2 that plane block is 4x8 (csz
25699+ // stays 4), so the single 4x4 push below left rows
25700+ // `cpy+4..cpy+8` unwritten -- sentinel-poisoned at frame 0
25701+ // (cell5 U(140..143,188..191) read 0 against the oracle's
25702+ // 664) because an intrabc+lossless leaf takes exactly this
25703+ // arm (`chroma_units_ll` requires `intrabc_bufs.is_none()`).
25704+ // Window the override per 4x4 unit off the cw-stride buffer,
25705+ // the same slice `read_intra_chroma_lossless` feeds
25706+ // `set_palette_pred` with.
25707+ let (cw, ch) = (8 >> ss_x(fctx), 8 >> ss_y(fctx));
25708+ let has_override = intrabc_bufs.is_some() || palette_uv_bufs.is_some();
25709+ if chroma_422 && has_override && ch == 8 {
25710+ let ub = intrabc_bufs
25711+ .as_ref()
25712+ .map(|(_, ub, _)| ub.clone())
25713+ .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone()));
25714+ let vb = intrabc_bufs
25715+ .as_ref()
25716+ .map(|(_, _, vb)| vb.clone())
25717+ .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone()));
25718+ for (buf, plane) in [(ub, 1usize), (vb, 2usize)] {
25719+ if let Some(buf) = buf {
25720+ for cu_row in 0..2 {
25721+ let cu_reach = tu_reach(
25722+ 8,
25723+ 8,
25724+ 0,
25725+ cu_row * 4,
25726+ 4,
25727+ reach,
25728+ px,
25729+ py,
25730+ y.width,
25731+ y.height,
25732+ fctx,
25733+ );
25734+ set_palette_pred(
25735+ palette_window(&buf, cw, 0, cu_row * 4, 4, 4),
25736+ fctx,
25737+ );
25738+ push_intra(
25739+ plane,
25740+ cpx,
25741+ cpy + cu_row * 4,
25742+ 4,
25743+ uv_predict_mode,
25744+ angle_delta_uv,
25745+ cu_reach,
25746+ &ZERO_RESIDUAL[..16],
25747+ None,
25748+ None,
25749+ smooth_neighbor_uv,
25750+ fctx,
25751+ );
25752+ }
25753+ }
25754+ }
25755+ } else {
25756+ push_intra(
25757+ 1,
25758+ cpx,
25759+ cpy,
25760+ csz,
25761+ uv_predict_mode,
25762+ angle_delta_uv,
25763+ reach,
25764+ &ZERO_RESIDUAL[..csz * csz],
25765+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
25766+ None,
25767+ smooth_neighbor_uv,
25768+ fctx,
25769+ );
25770+ }
2570925771 }
2571025772 if let Some((_, _, vb)) = &intrabc_bufs {
2571125773 set_palette_pred(vb.clone(), fctx);
@@ -25745,20 +25807,64 @@ fn decode_leaf8(
2574525807 }
2574625808 }
2574725809 } else {
25748- push_intra(
25749- 2,
25750- cpx,
25751- cpy,
25752- csz,
25753- uv_predict_mode,
25754- angle_delta_uv,
25755- reach,
25756- &ZERO_RESIDUAL[..csz * csz],
25757- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
25758- None,
25759- smooth_neighbor_uv,
25760- fctx,
25761- );
25810+ // lane-av1422mixll10: same whole-plane-block rule as the U
25811+ // plane above -- with an override, both 4x4 units of the 4x8
25812+ // plane block predict, not just the first.
25813+ let (cw, ch) = (8 >> ss_x(fctx), 8 >> ss_y(fctx));
25814+ let has_override = intrabc_bufs.is_some() || palette_uv_bufs.is_some();
25815+ if chroma_422 && has_override && ch == 8 {
25816+ let vb = intrabc_bufs
25817+ .as_ref()
25818+ .map(|(_, _, vb)| vb.clone())
25819+ .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone()));
25820+ if let Some(vb) = vb {
25821+ for cu_row in 0..2 {
25822+ let cu_reach = tu_reach(
25823+ 8,
25824+ 8,
25825+ 0,
25826+ cu_row * 4,
25827+ 4,
25828+ reach,
25829+ px,
25830+ py,
25831+ y.width,
25832+ y.height,
25833+ fctx,
25834+ );
25835+ set_palette_pred(palette_window(&vb, cw, 0, cu_row * 4, 4, 4), fctx);
25836+ push_intra(
25837+ 2,
25838+ cpx,
25839+ cpy + cu_row * 4,
25840+ 4,
25841+ uv_predict_mode,
25842+ angle_delta_uv,
25843+ cu_reach,
25844+ &ZERO_RESIDUAL[..16],
25845+ None,
25846+ None,
25847+ smooth_neighbor_uv,
25848+ fctx,
25849+ );
25850+ }
25851+ }
25852+ } else {
25853+ push_intra(
25854+ 2,
25855+ cpx,
25856+ cpy,
25857+ csz,
25858+ uv_predict_mode,
25859+ angle_delta_uv,
25860+ reach,
25861+ &ZERO_RESIDUAL[..csz * csz],
25862+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
25863+ None,
25864+ smooth_neighbor_uv,
25865+ fctx,
25866+ );
25867+ }
2576225868 }
2576325869 luma_grid = Grid::Zero(64);
2576425870 u_grid = Grid::Zero(csz * csz);
crates/ec-av1/src/stream.rsmodified+92 -0
@@ -7355,6 +7355,98 @@ pub(crate) mod tests {
73557355 }
73567356 }
73577357
7358+ /// lane-av1422mixll10: a skipped INTRABC 8x8 leaf inside a LOSSLESS
7359+ /// segment of a 4:2:2 frame predicts its whole 4x8 chroma plane block --
7360+ /// both TX_4X4 units, each windowed off the DV frame copy. The defect
7361+ /// arm pushed only the first 4x4 (at `cpy`), leaving rows
7362+ /// `cpy+4..cpy+8` unwritten: frame 0's U(140..143, 188..191) read the
7363+ /// sentinel poison 0 against the oracle's 664 (16 samples, all planes
7364+ /// otherwise exact). Pin `422_mixll_intrabc_lossless_320x240_5f.obu`
7365+ /// (aomenc profile 1, 320x240 yuv422p10le, mixed-lossless AQ segment +
7366+ /// intrabc screen content; 79333 bytes, sha256
7367+ /// `9fa1f1d28d61e3096d70908728f9cdfa1a570b9769a3d31e8d385a61c12a2b25`).
7368+ /// Gate: every frame of all three planes byte-exact against ffmpeg's
7369+ /// `yuv422p10le`, plus the non-vacuity controls (the pin's chroma census
7370+ /// must show coded units, and one flipped oracle sample must move the
7371+ /// count).
7372+ #[test]
7373+ fn a_422_mixll_intrabc_lossless_leaf_predicts_whole_chroma_plane_block() {
7374+ const NAME: &str = "a_422_mixll_intrabc_lossless_leaf_predicts_whole_chroma_plane_block";
7375+ const FILE: &str = "422_mixll_intrabc_lossless_320x240_5f.obu";
7376+ const LEN: usize = 79333;
7377+ const FNV: u64 = 8342335520738450773;
7378+ const W: usize = 320;
7379+ const H: usize = 240;
7380+ const SHOWN: usize = 5;
7381+ let _gate_lock = lock_gate_counters();
7382+ if !have_ffmpeg() {
7383+ eprintln!("SKIP {NAME}: no ffmpeg");
7384+ return;
7385+ }
7386+ let path = crate_pin(FILE);
7387+ let stream = read_pin(&path, LEN, FNV, NAME);
7388+ assert_eq!(
7389+ stream_subsampling(&stream, NAME),
7390+ (1, 0),
7391+ "{NAME}: the pin must really be 4:2:2 (1,0)"
7392+ );
7393+ assert_eq!(
7394+ stream_bit_depth(&stream, NAME),
7395+ 10,
7396+ "{NAME}: the pin is a 10-bit cell"
7397+ );
7398+ let _ = stream_bit_depth(&stream, NAME);
7399+
7400+ let decoded = decode_stream(&stream)
7401+ .unwrap_or_else(|e| panic!("{NAME}: the committed 4:2:2 pin did not decode: {e}"));
7402+ assert_eq!(
7403+ decoded.len(),
7404+ SHOWN,
7405+ "{NAME}: the pin is {SHOWN} shown frames"
7406+ );
7407+ let want = ffmpeg_decode_sequence_422_depth(&stream, W, H, SHOWN, 10, "yuv422p10le");
7408+ assert_eq!(decoded.len(), want.len(), "{NAME}: decoded/frame count");
7409+
7410+ let plane_mismatches = |ours: &[Pic], theirs: &[Pic], plane: u8| -> usize {
7411+ ours.iter()
7412+ .zip(theirs)
7413+ .map(|(a, b)| {
7414+ let (a, b) = match plane {
7415+ 0 => (&a.y, &b.y),
7416+ 1 => (&a.u, &b.u),
7417+ _ => (&a.v, &b.v),
7418+ };
7419+ a.iter().zip(b).filter(|&(x, y)| x != y).count()
7420+ })
7421+ .sum()
7422+ };
7423+ let clean: Vec<usize> = (0..3)
7424+ .map(|p| plane_mismatches(&decoded, &want, p))
7425+ .collect();
7426+ assert_eq!(
7427+ clean,
7428+ vec![0, 0, 0],
7429+ "{NAME}: the fix must be byte-exact against ffmpeg on every plane of every frame; \
7430+ got {clean:?} (16 differs on frame 0 U would be the unwritten 4x4 again)"
7431+ );
7432+
7433+ // Non-vacuity: one flipped oracle U sample must move the U count.
7434+ let mut flipped = want.clone();
7435+ flipped[0].u[188 * (W / 2) + 140] ^= 1;
7436+ let moved: Vec<usize> = (0..3)
7437+ .map(|p| plane_mismatches(&decoded, &flipped, p))
7438+ .collect();
7439+ assert_eq!(
7440+ moved,
7441+ vec![0, 1, 0],
7442+ "{NAME}: one flipped oracle U sample at (140,188) must move the U count 0 -> 1; \
7443+ got {moved:?} -- the comparator does not bite"
7444+ );
7445+ eprintln!(
7446+ "{NAME}: byte-exact vs ffmpeg on all {SHOWN} frames; flip control moved {moved:?}"
7447+ );
7448+ }
7449+
73587450 /// lane-av1oracledepth: the 8-bit `ffmpeg_decode_sequence_444` must REFUSE
73597451 /// a real 10-bit 4:4:4 pin instead of letting ffmpeg convert it down to
73607452 /// `yuv444p`. ffmpeg does not fail on the depth mismatch -- it re-scales