Merge lane-av1chromarect: 4:4:4 intra-BC rect-strip chroma is sized and walked per unit
Browse files at this commit4 changed files +909 -140
- crates/ec-av1/fixtures/r512.obu +0 -0
- crates/ec-av1/src/decode.rs +369 -140
- crates/ec-av1/src/stream.rs +152 -0
- lanes/av1chromarect.report.md +388 -0
crates/ec-av1/fixtures/r512.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+369 -140
| @@ -4708,6 +4708,16 @@ thread_local! { | |||
| 4708 | /// be satisfied by any older route. | 4708 | /// be satisfied by any older route. |
| 4709 | static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> = | 4709 | static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> = |
| 4710 | const { std::cell::Cell::new(0) }; | 4710 | const { std::cell::Cell::new(0) }; |
| 4711 | + /// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips | ||
| 4712 | + /// ([`decode_intrabc_owned_rect`]) whose chroma plane block was sized | ||
| 4713 | + /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where | ||
| 4714 | + /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies | ||
| 4715 | + /// no halving of its own. At 4:2:0 the two forms are the same arithmetic, | ||
| 4716 | + /// so a `>= 1` witness can only come from a stream that is not 4:2:0. | ||
| 4717 | + /// EXCLUSIVE to this arm: no other caller sizes a 128-root intra-BC | ||
| 4718 | + /// strip's chroma plane block. | ||
| 4719 | + static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> = | ||
| 4720 | + const { std::cell::Cell::new(0) }; | ||
| 4711 | } | 4721 | } |
| 4712 | 4722 | ||
| 4713 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, | 4723 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, |
| @@ -4751,6 +4761,18 @@ pub(crate) fn reset_ibc_rect_chroma_footprint_444_hits() { | |||
| 4751 | IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); | 4761 | IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); |
| 4752 | } | 4762 | } |
| 4753 | 4763 | ||
| 4764 | +/// lane-av1chromarect: [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`]. | ||
| 4765 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4766 | +pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize { | ||
| 4767 | + IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get()) | ||
| 4768 | +} | ||
| 4769 | + | ||
| 4770 | +/// lane-av1chromarect: zeroes [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`]. | ||
| 4771 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4772 | +pub(crate) fn reset_ibc_owned_rect_chroma_footprint_444_hits() { | ||
| 4773 | + IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); | ||
| 4774 | +} | ||
| 4775 | + | ||
| 4754 | /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. | 4776 | /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. |
| 4755 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates | 4777 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| 4756 | pub fn intrabc_rect_lossless_chroma4_hits() -> usize { | 4778 | pub fn intrabc_rect_lossless_chroma4_hits() -> usize { |
| @@ -10407,6 +10429,20 @@ impl Neighbours { | |||
| 10407 | mode: usize, | 10429 | mode: usize, |
| 10408 | uv_mode: usize, | 10430 | uv_mode: usize, |
| 10409 | grids: &[&[i32]; 3], | 10431 | grids: &[&[i32]; 3], |
| 10432 | + ) { | ||
| 10433 | + self.record_rect_mi_modes(at_mi, w, h, mode, uv_mode); | ||
| 10434 | + self.record_mi_rect(at_mi, w, h, grids); | ||
| 10435 | + } | ||
| 10436 | + | ||
| 10437 | + /// [`Self::record_rect_mi`]'s mode and transform-size half, without the | ||
| 10438 | + /// coefficient-context stamp. | ||
| 10439 | + fn record_rect_mi_modes( | ||
| 10440 | + &mut self, | ||
| 10441 | + at_mi: (usize, usize), | ||
| 10442 | + w: usize, | ||
| 10443 | + h: usize, | ||
| 10444 | + mode: usize, | ||
| 10445 | + uv_mode: usize, | ||
| 10410 | ) { | 10446 | ) { |
| 10411 | let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); | 10447 | let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); |
| 10412 | // lane-inter4 r2: a strip whose own footprint runs past the frame's | 10448 | // lane-inter4 r2: a strip whose own footprint runs past the frame's |
| @@ -10430,7 +10466,28 @@ impl Neighbours { | |||
| 10430 | } | 10466 | } |
| 10431 | self.record_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, mode); | 10467 | self.record_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, mode); |
| 10432 | self.record_uv_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, uv_mode); | 10468 | self.record_uv_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, uv_mode); |
| 10433 | - self.record_mi_rect(at_mi, w, h, grids); | 10469 | + } |
| 10470 | + | ||
| 10471 | + /// lane-av1chromarect: [`Self::record_rect_mi`] for a block whose uv | ||
| 10472 | + /// plane block is SEVERAL transform units, each of which stamped its own | ||
| 10473 | + /// span through [`Self::record_mi_chroma`]. Writing one whole-block state | ||
| 10474 | + /// over them is the `override-slot-on-one-arm` class: libaom keeps the | ||
| 10475 | + /// per-unit above/left contexts distinct, and the next block's first | ||
| 10476 | + /// unit reads them. The luma plane has one unit here, so it is stamped | ||
| 10477 | + /// exactly as the whole-block record stamps it. | ||
| 10478 | + fn record_rect_mi_luma_only( | ||
| 10479 | + &mut self, | ||
| 10480 | + at_mi: (usize, usize), | ||
| 10481 | + w: usize, | ||
| 10482 | + h: usize, | ||
| 10483 | + mode: usize, | ||
| 10484 | + uv_mode: usize, | ||
| 10485 | + luma_grid: &[i32], | ||
| 10486 | + ) { | ||
| 10487 | + self.record_rect_mi_modes(at_mi, w, h, mode, uv_mode); | ||
| 10488 | + fill_span(&mut self.left_side_mi, at_mi.0, h / MI, h as u8); | ||
| 10489 | + fill_span(&mut self.above_side_mi, at_mi.1, w / MI, w as u8); | ||
| 10490 | + self.record_mi_luma_rect(at_mi, w, h, luma_grid); | ||
| 10434 | } | 10491 | } |
| 10435 | 10492 | ||
| 10436 | /// The coefficient-context half of [`Self::record`], taking the block's | 10493 | /// The coefficient-context half of [`Self::record`], taking the block's |
| @@ -10630,6 +10687,39 @@ impl Neighbours { | |||
| 10630 | mode: usize, | 10687 | mode: usize, |
| 10631 | uv_mode: usize, | 10688 | uv_mode: usize, |
| 10632 | chroma_grids: [&[i32]; 2], | 10689 | chroma_grids: [&[i32]; 2], |
| 10690 | + ) { | ||
| 10691 | + self.record_split_luma_rect_mi_modes(at_mi, w, h, mode, uv_mode); | ||
| 10692 | + let (mi_r, _) = at_mi; | ||
| 10693 | + let (w_mi, h_mi) = (w / MI, h / MI); | ||
| 10694 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 10695 | + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | ||
| 10696 | + for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { | ||
| 10697 | + let plane = plane_idx + 1; | ||
| 10698 | + let state = neighbour_state(grid); | ||
| 10699 | + for cell in 0..h_mi { | ||
| 10700 | + if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { | ||
| 10701 | + self.left[mi_r + cell][plane] = state; | ||
| 10702 | + } | ||
| 10703 | + } | ||
| 10704 | + for cell in 0..w_mi { | ||
| 10705 | + if cell < w_mi.min(bound_w.saturating_sub(at_mi.1)) { | ||
| 10706 | + self.above[at_mi.1 + cell][plane] = state; | ||
| 10707 | + } | ||
| 10708 | + } | ||
| 10709 | + } | ||
| 10710 | + } | ||
| 10711 | + | ||
| 10712 | + /// [`Self::record_split_luma_rect_mi`]'s mode and transform-size half, | ||
| 10713 | + /// without the per-plane coefficient stamp -- see | ||
| 10714 | + /// [`Self::record_rect_mi_luma_only`] for why a multi-unit chroma block | ||
| 10715 | + /// must not take the whole-block stamp. | ||
| 10716 | + fn record_split_luma_rect_mi_modes( | ||
| 10717 | + &mut self, | ||
| 10718 | + at_mi: (usize, usize), | ||
| 10719 | + w: usize, | ||
| 10720 | + h: usize, | ||
| 10721 | + mode: usize, | ||
| 10722 | + uv_mode: usize, | ||
| 10633 | ) { | 10723 | ) { |
| 10634 | let (mi_r, mi_c) = at_mi; | 10724 | let (mi_r, mi_c) = at_mi; |
| 10635 | let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | 10725 | let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); |
| @@ -10655,22 +10745,6 @@ impl Neighbours { | |||
| 10655 | self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); | 10745 | self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); |
| 10656 | fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); | 10746 | fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); |
| 10657 | fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); | 10747 | fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); |
| 10658 | - let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 10659 | - let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | ||
| 10660 | - for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { | ||
| 10661 | - let plane = plane_idx + 1; | ||
| 10662 | - let state = neighbour_state(grid); | ||
| 10663 | - for cell in 0..h_mi { | ||
| 10664 | - if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { | ||
| 10665 | - self.left[mi_r + cell][plane] = state; | ||
| 10666 | - } | ||
| 10667 | - } | ||
| 10668 | - for cell in 0..w_mi { | ||
| 10669 | - if cell < w_mi.min(bound_w.saturating_sub(mi_c)) { | ||
| 10670 | - self.above[mi_c + cell][plane] = state; | ||
| 10671 | - } | ||
| 10672 | - } | ||
| 10673 | - } | ||
| 10674 | } | 10748 | } |
| 10675 | } | 10749 | } |
| 10676 | 10750 | ||
| @@ -16838,25 +16912,31 @@ fn decode_intrabc_owned_rect( | |||
| 16838 | ) -> Result<()> { | 16912 | ) -> Result<()> { |
| 16839 | let _ = base_q_idx; | 16913 | let _ = base_q_idx; |
| 16840 | let (px, py) = (mi_c * MI, mi_r * MI); | 16914 | let (px, py) = (mi_c * MI, mi_r * MI); |
| 16841 | - // lane-av1chromahalvings r5: libaom-WRONG at 4:4:4 -- `av1_get_max_uv_txsize` | 16915 | + // lane-av1chromarect: libaom does NOT halve a 128-root intra-BC strip's |
| 16842 | - // is `ss_size_lookup[bsize]` and `get_vartx_max_txsize` (blockd.h:1447) reads | 16916 | + // chroma plane block. `av1_get_max_uv_txsize` (blockd.h:1372) is |
| 16843 | - // that plane block as `max_txsize_rect_lookup[plane_bsize]`, so chroma extent | 16917 | + // `max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, ss_y)]` run |
| 16844 | - // == luma extent at ss (0,0) -- and the chroma MV origins below are the | 16918 | + // through `av1_get_adjusted_tx_size`, and `get_plane_block_size` is |
| 16845 | - // prediction half of the same defect. MEASURED on the 4:4:4 LOSSY witness | 16919 | + // `ss_size_lookup[bsize]` -- at 4:4:4 the chroma plane block is the block's |
| 16846 | - // fixtures/r512.obu, chroma-only, luma byte-exact on both inter frames. | 16920 | + // OWN footprint, so the extent below and the eight chroma MV origin pairs |
| 16847 | - // BLOCKED, not missing: with the ss-derived extent the decode REFUSES -- | 16921 | + // that follow must be `>> ss_x` / `>> ss_y`, not `/ 2`. At 4:2:0 |
| 16848 | - // "a rectangular inter chroma transform unit whose shape has no coefficient | 16922 | + // (`ss_x == ss_y == 1`) the two forms are the same arithmetic. |
| 16849 | - // table set here" -- because a 4:4:4 32x64 chroma plane block needs a | 16923 | + // MEASURED on the 4:4:4 LOSSY witness `fixtures/r512.obu` (6948 B, 3 |
| 16850 | - // `TxbSet` this crate lacks. The fix is a new coefficient set, not a swap. | 16924 | + // frames, 5 strips through this function): with the halving, frame 0 |
| 16851 | - // Left as the halving deliberately: turning a decoding stream into a | 16925 | + // diverges from the aomdec oracle in 166229 Y / 155383 U / 153498 V |
| 16852 | - // refusal is a behaviour change with its own decision. See | 16926 | + // samples and both later frames keep luma byte-exact while 74708 U + |
| 16853 | - // lanes/av1chromahalvings.report.md r5. | 16927 | + // 73501 V (f1) and 9216 U + 8192 V (f2) are wrong -- chroma-only, which is |
| 16928 | + // what makes this a chroma-sizing defect and not a block-geometry one. | ||
| 16929 | + // Re-measured by this lane; see lanes/av1chromarect.report.md. | ||
| 16854 | if crate::envflags::env_flag!("EC_HALVSWEEP") { | 16930 | if crate::envflags::env_flag!("EC_HALVSWEEP") { |
| 16855 | eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}"); | 16931 | eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}"); |
| 16856 | } | 16932 | } |
| 16857 | - let (cw, ch) = (bw / 2, bh / 2); | 16933 | + let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx)); |
| 16934 | + let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); | ||
| 16858 | let side = bw.max(bh); | 16935 | let side = bw.max(bh); |
| 16859 | let cside = cw.max(ch); | 16936 | let cside = cw.max(ch); |
| 16937 | + if ss_x(fctx) == 0 && ss_y(fctx) == 0 { | ||
| 16938 | + hit!(IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS); | ||
| 16939 | + } | ||
| 16860 | let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); | 16940 | let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); |
| 16861 | let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get); | 16941 | let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get); |
| 16862 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); | 16942 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); |
| @@ -16871,30 +16951,8 @@ fn decode_intrabc_owned_rect( | |||
| 16871 | 16951 | ||
| 16872 | flush_recon(fctx, y, u, v); | 16952 | flush_recon(fctx, y, u, v); |
| 16873 | let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx); | 16953 | let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx); |
| 16874 | - let pred_u = predict_intrabc_window( | 16954 | + let pred_u = predict_intrabc_window(u, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx); |
| 16875 | - u, | 16955 | + let pred_v = predict_intrabc_window(v, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx); |
| 16876 | - px / 2, | ||
| 16877 | - py / 2, | ||
| 16878 | - cw, | ||
| 16879 | - ch, | ||
| 16880 | - dv_col, | ||
| 16881 | - dv_row, | ||
| 16882 | - false, | ||
| 16883 | - cside, | ||
| 16884 | - fctx, | ||
| 16885 | - ); | ||
| 16886 | - let pred_v = predict_intrabc_window( | ||
| 16887 | - v, | ||
| 16888 | - px / 2, | ||
| 16889 | - py / 2, | ||
| 16890 | - cw, | ||
| 16891 | - ch, | ||
| 16892 | - dv_col, | ||
| 16893 | - dv_row, | ||
| 16894 | - false, | ||
| 16895 | - cside, | ||
| 16896 | - fctx, | ||
| 16897 | - ); | ||
| 16898 | 16956 | ||
| 16899 | let mi_cols = 2 * y.true_width.div_ceil(8); | 16957 | let mi_cols = 2 * y.true_width.div_ceil(8); |
| 16900 | let mi_rows = 2 * y.true_height.div_ceil(8); | 16958 | let mi_rows = 2 * y.true_height.div_ceil(8); |
| @@ -16928,8 +16986,8 @@ fn decode_intrabc_owned_rect( | |||
| 16928 | ); | 16986 | ); |
| 16929 | push_mc_rect( | 16987 | push_mc_rect( |
| 16930 | 1, | 16988 | 1, |
| 16931 | - px / 2, | 16989 | + cpx, |
| 16932 | - py / 2, | 16990 | + cpy, |
| 16933 | cside, | 16991 | cside, |
| 16934 | cw, | 16992 | cw, |
| 16935 | ch, | 16993 | ch, |
| @@ -16939,8 +16997,8 @@ fn decode_intrabc_owned_rect( | |||
| 16939 | ); | 16997 | ); |
| 16940 | push_mc_rect( | 16998 | push_mc_rect( |
| 16941 | 2, | 16999 | 2, |
| 16942 | - px / 2, | 17000 | + cpx, |
| 16943 | - py / 2, | 17001 | + cpy, |
| 16944 | cside, | 17002 | cside, |
| 16945 | cw, | 17003 | cw, |
| 16946 | ch, | 17004 | ch, |
| @@ -16976,6 +17034,8 @@ fn decode_intrabc_owned_rect( | |||
| 16976 | u_grid = Grid::Zero(cside * cside); | 17034 | u_grid = Grid::Zero(cside * cside); |
| 16977 | v_grid = Grid::Zero(cside * cside); | 17035 | v_grid = Grid::Zero(cside * cside); |
| 16978 | } else if let Some(ls) = leaves.as_ref() { | 17036 | } else if let Some(ls) = leaves.as_ref() { |
| 17037 | + let mut leaf_types: Vec<(usize, usize, usize, usize, TxType)> = | ||
| 17038 | + Vec::with_capacity(ls.len()); | ||
| 16979 | for (idx, &(row, col, tw, th)) in ls.iter().enumerate() { | 17039 | for (idx, &(row, col, tw, th)) in ls.iter().enumerate() { |
| 16980 | let tu_mi = (mi_r + row, mi_c + col); | 17040 | let tu_mi = (mi_r + row, mi_c + col); |
| 16981 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); | 17041 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| @@ -17018,6 +17078,7 @@ fn decode_intrabc_owned_rect( | |||
| 17018 | fctx, | 17078 | fctx, |
| 17019 | )? | 17079 | )? |
| 17020 | }; | 17080 | }; |
| 17081 | + leaf_types.push((row, col, tw, th, tt)); | ||
| 17021 | if idx == 0 { | 17082 | if idx == 0 { |
| 17022 | luma_tx_type = tt; | 17083 | luma_tx_type = tt; |
| 17023 | } | 17084 | } |
| @@ -17033,43 +17094,66 @@ fn decode_intrabc_owned_rect( | |||
| 17033 | } | 17094 | } |
| 17034 | } | 17095 | } |
| 17035 | luma_grid = Grid::Zero(side * side); | 17096 | luma_grid = Grid::Zero(side * side); |
| 17036 | - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); | 17097 | + if cw.min(32) != cw || ch.min(32) != ch { |
| 17037 | - let (ug, _) = read_inter_plane_rect( | 17098 | + // lane-av1chromarect: more than one chroma transform unit (the |
| 17038 | - dec, | 17099 | + // 4:4:4 32x64/64x32 plane block). See the helper. |
| 17039 | - cdfs, | 17100 | + let (ug, vg) = read_intrabc_rect_chroma_split( |
| 17040 | - rect_inter_chroma_set(cw, ch)?, | 17101 | + dec, |
| 17041 | - (cw, ch), | 17102 | + cdfs, |
| 17042 | - cside, | 17103 | + neighbours, |
| 17043 | - 1, | 17104 | + (mi_r, mi_c), |
| 17044 | - around[1], | 17105 | + (cpx, cpy), |
| 17045 | - 0, | 17106 | + (cw, ch), |
| 17046 | - u, | 17107 | + cside, |
| 17047 | - px / 2, | 17108 | + &pred_u, |
| 17048 | - py / 2, | 17109 | + &pred_v, |
| 17049 | - Pred::Inline(&pred_u, cside), | 17110 | + &leaf_types, |
| 17050 | - Some(luma_tx_type), | 17111 | + luma_tx_type, |
| 17051 | - None, | 17112 | + u, |
| 17052 | - fctx, | 17113 | + v, |
| 17053 | - )?; | 17114 | + fctx, |
| 17054 | - let (vg, _) = read_inter_plane_rect( | 17115 | + )?; |
| 17055 | - dec, | 17116 | + u_grid = ug; |
| 17056 | - cdfs, | 17117 | + v_grid = vg; |
| 17057 | - rect_inter_chroma_set(cw, ch)?, | 17118 | + } else { |
| 17058 | - (cw, ch), | 17119 | + let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); |
| 17059 | - cside, | 17120 | + let (ug, _) = read_inter_plane_rect( |
| 17060 | - 2, | 17121 | + dec, |
| 17061 | - around[2], | 17122 | + cdfs, |
| 17062 | - 0, | 17123 | + rect_inter_chroma_set(cw, ch)?, |
| 17063 | - v, | 17124 | + (cw, ch), |
| 17064 | - px / 2, | 17125 | + cside, |
| 17065 | - py / 2, | 17126 | + 1, |
| 17066 | - Pred::Inline(&pred_v, cside), | 17127 | + around[1], |
| 17067 | - Some(luma_tx_type), | 17128 | + 0, |
| 17068 | - None, | 17129 | + u, |
| 17069 | - fctx, | 17130 | + cpx, |
| 17070 | - )?; | 17131 | + cpy, |
| 17071 | - u_grid = ug; | 17132 | + Pred::Inline(&pred_u, cside), |
| 17072 | - v_grid = vg; | 17133 | + Some(luma_tx_type), |
| 17134 | + None, | ||
| 17135 | + fctx, | ||
| 17136 | + )?; | ||
| 17137 | + let (vg, _) = read_inter_plane_rect( | ||
| 17138 | + dec, | ||
| 17139 | + cdfs, | ||
| 17140 | + rect_inter_chroma_set(cw, ch)?, | ||
| 17141 | + (cw, ch), | ||
| 17142 | + cside, | ||
| 17143 | + 2, | ||
| 17144 | + around[2], | ||
| 17145 | + 0, | ||
| 17146 | + v, | ||
| 17147 | + cpx, | ||
| 17148 | + cpy, | ||
| 17149 | + Pred::Inline(&pred_v, cside), | ||
| 17150 | + Some(luma_tx_type), | ||
| 17151 | + None, | ||
| 17152 | + fctx, | ||
| 17153 | + )?; | ||
| 17154 | + u_grid = ug; | ||
| 17155 | + v_grid = vg; | ||
| 17156 | + } | ||
| 17073 | } else { | 17157 | } else { |
| 17074 | let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); | 17158 | let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); |
| 17075 | let (g, tt) = read_inter_plane_rect( | 17159 | let (g, tt) = read_inter_plane_rect( |
| @@ -17091,53 +17175,93 @@ fn decode_intrabc_owned_rect( | |||
| 17091 | )?; | 17175 | )?; |
| 17092 | luma_tx_type = tt; | 17176 | luma_tx_type = tt; |
| 17093 | luma_grid = g; | 17177 | luma_grid = g; |
| 17094 | - let (ug, _) = read_inter_plane_rect( | 17178 | + if cw.min(32) != cw || ch.min(32) != ch { |
| 17095 | - dec, | 17179 | + // lane-av1chromarect: more than one chroma transform unit (the |
| 17096 | - cdfs, | 17180 | + // 4:4:4 32x64/64x32 plane block). See the helper. |
| 17097 | - rect_inter_chroma_set(cw, ch)?, | 17181 | + let (ug, vg) = read_intrabc_rect_chroma_split( |
| 17098 | - (cw, ch), | 17182 | + dec, |
| 17099 | - cside, | 17183 | + cdfs, |
| 17100 | - 1, | 17184 | + neighbours, |
| 17101 | - around[1], | 17185 | + (mi_r, mi_c), |
| 17102 | - 0, | 17186 | + (cpx, cpy), |
| 17103 | - u, | 17187 | + (cw, ch), |
| 17104 | - px / 2, | 17188 | + cside, |
| 17105 | - py / 2, | 17189 | + &pred_u, |
| 17106 | - Pred::Inline(&pred_u, cside), | 17190 | + &pred_v, |
| 17107 | - Some(luma_tx_type), | 17191 | + &[], |
| 17108 | - None, | 17192 | + luma_tx_type, |
| 17109 | - fctx, | 17193 | + u, |
| 17110 | - )?; | 17194 | + v, |
| 17111 | - let (vg, _) = read_inter_plane_rect( | 17195 | + fctx, |
| 17112 | - dec, | 17196 | + )?; |
| 17113 | - cdfs, | 17197 | + u_grid = ug; |
| 17114 | - rect_inter_chroma_set(cw, ch)?, | 17198 | + v_grid = vg; |
| 17115 | - (cw, ch), | 17199 | + } else { |
| 17116 | - cside, | 17200 | + let (ug, _) = read_inter_plane_rect( |
| 17117 | - 2, | 17201 | + dec, |
| 17118 | - around[2], | 17202 | + cdfs, |
| 17119 | - 0, | 17203 | + rect_inter_chroma_set(cw, ch)?, |
| 17120 | - v, | 17204 | + (cw, ch), |
| 17121 | - px / 2, | 17205 | + cside, |
| 17122 | - py / 2, | 17206 | + 1, |
| 17123 | - Pred::Inline(&pred_v, cside), | 17207 | + around[1], |
| 17124 | - Some(luma_tx_type), | 17208 | + 0, |
| 17125 | - None, | 17209 | + u, |
| 17126 | - fctx, | 17210 | + cpx, |
| 17127 | - )?; | 17211 | + cpy, |
| 17128 | - u_grid = ug; | 17212 | + Pred::Inline(&pred_u, cside), |
| 17129 | - v_grid = vg; | 17213 | + Some(luma_tx_type), |
| 17214 | + None, | ||
| 17215 | + fctx, | ||
| 17216 | + )?; | ||
| 17217 | + let (vg, _) = read_inter_plane_rect( | ||
| 17218 | + dec, | ||
| 17219 | + cdfs, | ||
| 17220 | + rect_inter_chroma_set(cw, ch)?, | ||
| 17221 | + (cw, ch), | ||
| 17222 | + cside, | ||
| 17223 | + 2, | ||
| 17224 | + around[2], | ||
| 17225 | + 0, | ||
| 17226 | + v, | ||
| 17227 | + cpx, | ||
| 17228 | + cpy, | ||
| 17229 | + Pred::Inline(&pred_v, cside), | ||
| 17230 | + Some(luma_tx_type), | ||
| 17231 | + None, | ||
| 17232 | + fctx, | ||
| 17233 | + )?; | ||
| 17234 | + u_grid = ug; | ||
| 17235 | + v_grid = vg; | ||
| 17236 | + } | ||
| 17130 | } | 17237 | } |
| 17131 | drop(restore); | 17238 | drop(restore); |
| 17239 | + // lane-av1chromarect: when the chroma plane block was walked as SEVERAL | ||
| 17240 | + // transform units, each unit stamped its own span through | ||
| 17241 | + // `record_mi_chroma` and the whole-block stamp below would overwrite them | ||
| 17242 | + // with one state (class `override-slot-on-one-arm`). libaom keeps the | ||
| 17243 | + // per-unit above/left contexts distinct; the next block's first unit | ||
| 17244 | + // reads them. | ||
| 17245 | + // `!skip` matters: a SKIPPED strip reads no chroma unit at all (its whole | ||
| 17246 | + // chroma plane block is one `push_mc_rect` of `ZERO_RESIDUAL`), so no | ||
| 17247 | + // per-unit `record_mi_chroma` ran and the whole-block chroma stamp below | ||
| 17248 | + // is still the only one that happens. | ||
| 17249 | + let chroma_split_units = !skip && (cw.min(32) != cw || ch.min(32) != ch); | ||
| 17132 | if leaves.is_some() { | 17250 | if leaves.is_some() { |
| 17133 | - neighbours.record_split_luma_rect_mi( | 17251 | + if chroma_split_units { |
| 17134 | - (mi_r, mi_c), | 17252 | + neighbours.record_split_luma_rect_mi_modes((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED); |
| 17135 | - bw, | 17253 | + } else { |
| 17136 | - bh, | 17254 | + neighbours.record_split_luma_rect_mi( |
| 17137 | - DC_PRED, | 17255 | + (mi_r, mi_c), |
| 17138 | - DC_PRED, | 17256 | + bw, |
| 17139 | - [&u_grid, &v_grid], | 17257 | + bh, |
| 17140 | - ); | 17258 | + DC_PRED, |
| 17259 | + DC_PRED, | ||
| 17260 | + [&u_grid, &v_grid], | ||
| 17261 | + ); | ||
| 17262 | + } | ||
| 17263 | + } else if chroma_split_units { | ||
| 17264 | + neighbours.record_rect_mi_luma_only((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, &luma_grid); | ||
| 17141 | } else { | 17265 | } else { |
| 17142 | neighbours.record_rect_mi( | 17266 | neighbours.record_rect_mi( |
| 17143 | (mi_r, mi_c), | 17267 | (mi_r, mi_c), |
| @@ -17173,6 +17297,111 @@ fn decode_intrabc_owned_rect( | |||
| 17173 | Ok(()) | 17297 | Ok(()) |
| 17174 | } | 17298 | } |
| 17175 | 17299 | ||
| 17300 | +/// The chroma plane block of a 128-root intra-BC HORZ/VERT strip when that | ||
| 17301 | +/// plane block needs MORE THAN ONE transform unit -- the 4:4:4 cell, and the | ||
| 17302 | +/// 4:2:0 cell of a strip with a 128-px axis. | ||
| 17303 | +/// | ||
| 17304 | +/// libaom never forms a 64-point CHROMA transform. `get_vartx_max_txsize` | ||
| 17305 | +/// (blockd.h:1447) returns `av1_get_adjusted_tx_size(max_txsize_rect_lookup | ||
| 17306 | +/// [plane_bsize])` and `av1_get_adjusted_tx_size` maps `TX_32X64`/`TX_64X32` | ||
| 17307 | +/// to `TX_32X32`; `decode_token_recon_block` (decodeframe.c:994-1004) then | ||
| 17308 | +/// steps the plane block by that size's mi units, and | ||
| 17309 | +/// `decode_reconstruct_tx`'s `tx_size == plane_tx_size || plane` arm never | ||
| 17310 | +/// recurses for chroma -- the same statement from the other side. So a 4:4:4 | ||
| 17311 | +/// 32x64 chroma plane block is TWO stacked `TX_32X32` units, each with its | ||
| 17312 | +/// own eob, its own scan and its own coefficient context, NOT one 32x64 unit | ||
| 17313 | +/// whose coded corner happens to be 32x32: `av1_get_max_eob`'s 64-axis | ||
| 17314 | +/// truncation is a LUMA rule, and a chroma plane block is never 64 points | ||
| 17315 | +/// long to begin with. | ||
| 17316 | +/// | ||
| 17317 | +/// That is exactly the tiling [`read_inter_rect_chroma`] implements | ||
| 17318 | +/// (`(write_chroma_w.min(32), write_chroma_h.min(32))` and the `nx * ny` | ||
| 17319 | +/// walk); this is the same walk for a caller that keeps its own grid | ||
| 17320 | +/// assembly and neighbour recording. The single-unit case is deliberately | ||
| 17321 | +/// NOT routed through here, so at 4:2:0 and at every 4:4:4 shape below 64 | ||
| 17322 | +/// the caller keeps its own one-unit read verbatim. | ||
| 17323 | +#[allow(clippy::too_many_arguments)] | ||
| 17324 | +fn read_intrabc_rect_chroma_split( | ||
| 17325 | + dec: &mut SymbolDecoder, | ||
| 17326 | + cdfs: &mut Cdfs, | ||
| 17327 | + neighbours: &mut Neighbours, | ||
| 17328 | + (mi_r, mi_c): (usize, usize), | ||
| 17329 | + (cpx, cpy): (usize, usize), | ||
| 17330 | + (cw, ch): (usize, usize), | ||
| 17331 | + cside: usize, | ||
| 17332 | + pred_u: &[u16], | ||
| 17333 | + pred_v: &[u16], | ||
| 17334 | + leaf_tx_types: &[(usize, usize, usize, usize, TxType)], | ||
| 17335 | + luma_tx_type: TxType, | ||
| 17336 | + u: &mut PlaneBuf<'static>, | ||
| 17337 | + v: &mut PlaneBuf<'static>, | ||
| 17338 | + fctx: &crate::decode::FrameCtx, | ||
| 17339 | +) -> Result<(Grid, Grid)> { | ||
| 17340 | + let (uw, uh) = (cw.min(32), ch.min(32)); | ||
| 17341 | + let (nx, ny) = (cw / uw, ch / uh); | ||
| 17342 | + let set = rect_inter_chroma_set(uw, uh)?; | ||
| 17343 | + let assembled_h = ch.max(cside); | ||
| 17344 | + let mut assembled: [Vec<i32>; 2] = [ | ||
| 17345 | + vec![0i32; cside * assembled_h], | ||
| 17346 | + vec![0i32; cside * assembled_h], | ||
| 17347 | + ]; | ||
| 17348 | + for plane_idx in 1..=2 { | ||
| 17349 | + let (src, buf) = if plane_idx == 1 { | ||
| 17350 | + (pred_u, &mut *u) | ||
| 17351 | + } else { | ||
| 17352 | + (pred_v, &mut *v) | ||
| 17353 | + }; | ||
| 17354 | + for cu_row in 0..ny { | ||
| 17355 | + for cu_col in 0..nx { | ||
| 17356 | + let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx)); | ||
| 17357 | + let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI)); | ||
| 17358 | + let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y); | ||
| 17359 | + let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); | ||
| 17360 | + let cu_pred = Pred::Inline(src, cside).offset(cu_row * uh * cside + cu_col * uw); | ||
| 17361 | + // libaom's `av1_get_tx_type` (blockd.h:1287) reads | ||
| 17362 | + // `xd->tx_type_map` at the chroma unit's OWN position scaled | ||
| 17363 | + // back to luma, so a unit sitting over a luma leaf that coded | ||
| 17364 | + // nothing takes that leaf's stamp, not the block-level one. | ||
| 17365 | + let rel_mi = (cu_mi.0 - mi_r, cu_mi.1 - mi_c); | ||
| 17366 | + let inherit_tx_type = | ||
| 17367 | + covering_leaf_tx_type(leaf_tx_types, rel_mi).or(Some(luma_tx_type)); | ||
| 17368 | + let cu_grid = read_inter_plane_rect( | ||
| 17369 | + dec, | ||
| 17370 | + cdfs, | ||
| 17371 | + set, | ||
| 17372 | + (uw, uh), | ||
| 17373 | + cside, | ||
| 17374 | + plane_idx, | ||
| 17375 | + cu_around[plane_idx], | ||
| 17376 | + 0, | ||
| 17377 | + buf, | ||
| 17378 | + cu_x, | ||
| 17379 | + cu_y, | ||
| 17380 | + cu_pred, | ||
| 17381 | + inherit_tx_type, | ||
| 17382 | + // `get_txb_ctx`: plus 10 when the plane block is bigger | ||
| 17383 | + // than the transform -- the same offset-3 convention | ||
| 17384 | + // `read_inter_rect_chroma` passes on this arm. | ||
| 17385 | + Some(3), | ||
| 17386 | + fctx, | ||
| 17387 | + )? | ||
| 17388 | + .0; | ||
| 17389 | + // Immediately, so the next unit of this block reads this one's | ||
| 17390 | + // coefficient context (libaom updates the chroma above/left | ||
| 17391 | + // contexts per unit). | ||
| 17392 | + neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &cu_grid); | ||
| 17393 | + let dst = &mut assembled[plane_idx - 1]; | ||
| 17394 | + for rr in 0..uh { | ||
| 17395 | + let start = (cu_row * uh + rr) * cside + cu_col * uw; | ||
| 17396 | + dst[start..start + uw].copy_from_slice(&cu_grid[rr * uw..][..uw]); | ||
| 17397 | + } | ||
| 17398 | + } | ||
| 17399 | + } | ||
| 17400 | + } | ||
| 17401 | + let [ug, vg] = assembled; | ||
| 17402 | + Ok((Grid::Own(ug), Grid::Own(vg))) | ||
| 17403 | +} | ||
| 17404 | + | ||
| 17176 | fn predict_intrabc_window( | 17405 | fn predict_intrabc_window( |
| 17177 | plane: &PlaneBuf<'_>, | 17406 | plane: &PlaneBuf<'_>, |
| 17178 | px: usize, | 17407 | px: usize, |
crates/ec-av1/src/stream.rsmodified+152 -0
| @@ -140,6 +140,23 @@ pub fn reset_ibc444rect_hits() { | |||
| 140 | crate::decode::reset_ibc444rect_hits() | 140 | crate::decode::reset_ibc444rect_hits() |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | +/// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips whose chroma plane | ||
| 144 | +/// block was sized `bw >> ss_x` by `bh >> ss_y` rather than the hardcoded | ||
| 145 | +/// 4:2:0 halving -- i.e. the 4:4:4 (and 4:4:0) cells, where | ||
| 146 | +/// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies no | ||
| 147 | +/// halving of its own. At 4:2:0 the two forms are the same arithmetic, so a | ||
| 148 | +/// `>= 1` witness can only come from a stream that is not 4:2:0. EXCLUSIVE to | ||
| 149 | +/// `decode_intrabc_owned_rect`: no other caller sizes a 128-root intra-BC | ||
| 150 | +/// strip's chroma plane block. | ||
| 151 | +pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize { | ||
| 152 | + crate::decode::ibc_owned_rect_chroma_footprint_444_hits() | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +/// Gate-side reset for the lane-av1chromarect counter above. | ||
| 156 | +pub fn reset_ibc_owned_rect_chroma_footprint_444_hits() { | ||
| 157 | + crate::decode::reset_ibc_owned_rect_chroma_footprint_444_hits() | ||
| 158 | +} | ||
| 159 | + | ||
| 143 | /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 | 160 | /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 |
| 144 | /// r22) -- the counter a screen-content witness gate reads to prove it | 161 | /// r22) -- the counter a screen-content witness gate reads to prove it |
| 145 | /// exercises the inter-frame palette path, not the key frame's. | 162 | /// exercises the inter-frame palette path, not the key frame's. |
| @@ -48682,4 +48699,139 @@ pub(crate) mod tests { | |||
| 48682 | (lanes/ibc444c.report.md r2), NOT an assertion" | 48699 | (lanes/ibc444c.report.md r2), NOT an assertion" |
| 48683 | ); | 48700 | ); |
| 48684 | } | 48701 | } |
| 48702 | + | ||
| 48703 | + /// lane-av1chromarect: the 128-root intra-BC HORZ/VERT strip's chroma | ||
| 48704 | + /// plane block, on the 4:4:4 LOSSY witness `fixtures/r512.obu` that | ||
| 48705 | + /// reaches `decode_intrabc_owned_rect` five times. | ||
| 48706 | + /// | ||
| 48707 | + /// The extent is the ss-derived one (`bw >> ss_x` by `bh >> ss_y`; | ||
| 48708 | + /// `av1_get_max_uv_txsize` = `ss_size_lookup[bsize]`, blockd.h:1372), and | ||
| 48709 | + /// the plane block is walked by `get_vartx_max_txsize` steps -- a 4:4:4 | ||
| 48710 | + /// 32x64 luma block's chroma plane block is 32x64, which libaom codes as | ||
| 48711 | + /// TWO `TX_32X32` units, not as one 32x64 transform. | ||
| 48712 | + /// | ||
| 48713 | + /// This gate WAS the refusal assertion "a rectangular inter chroma | ||
| 48714 | + /// transform unit whose shape has no coefficient table set here", put | ||
| 48715 | + /// there one commit earlier so that the day the arm landed it would go | ||
| 48716 | + /// RED and force this rewrite. The refusal string is GONE from the | ||
| 48717 | + /// witness's decode because nothing reaches it any more, not because it | ||
| 48718 | + /// was deleted: `rect_inter_chroma_set` still refuses (32, 64) and the | ||
| 48719 | + /// string is still in the source, it is just not on this path any more. | ||
| 48720 | + /// | ||
| 48721 | + /// The assertion is a per-(frame, plane) EXACT PREFIX against the | ||
| 48722 | + /// instrumented aomdec, the same shape as the sibling | ||
| 48723 | + /// `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`. The | ||
| 48724 | + /// floors are MEASURED, and each one only grows: | ||
| 48725 | + /// | ||
| 48726 | + /// * luma is byte-exact on ALL THREE frames (786432/786432 samples). | ||
| 48727 | + /// Before the fix frame 0 luma was 166229 samples wrong from 65728 -- | ||
| 48728 | + /// the halving's chroma misread desynced the tile. | ||
| 48729 | + /// * frame 2 is byte-exact on all three planes. Before the fix it was | ||
| 48730 | + /// 9216 U + 8192 V wrong. | ||
| 48731 | + /// * frames 0 and 1 carry an OPEN chroma fork at a DIFFERENT site (see | ||
| 48732 | + /// lanes/av1chromarect.report.md); the floors below are the exact | ||
| 48733 | + /// prefixes, not a claim that the tail is right. | ||
| 48734 | + #[test] | ||
| 48735 | + fn a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes() { | ||
| 48736 | + const NAME: &str = | ||
| 48737 | + "a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes"; | ||
| 48738 | + const FILE: &str = "r512.obu"; | ||
| 48739 | + const LEN: usize = 6948; | ||
| 48740 | + /// 512x512 8-bit 4:4:4, one plane. | ||
| 48741 | + const PLANE: usize = 512 * 512; | ||
| 48742 | + /// First differing sample per (frame, plane), decode order. | ||
| 48743 | + const EXACT_PREFIX: [[usize; 3]; 3] = [ | ||
| 48744 | + [PLANE, 229728, 229728], | ||
| 48745 | + [PLANE, 65704, 65704], | ||
| 48746 | + [PLANE, PLANE, PLANE], | ||
| 48747 | + ]; | ||
| 48748 | + let path = | ||
| 48749 | + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}")); | ||
| 48750 | + let stream = std::fs::read(&path) | ||
| 48751 | + .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}")); | ||
| 48752 | + assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved"); | ||
| 48753 | + assert_444_header(&stream, NAME, 8); | ||
| 48754 | + | ||
| 48755 | + let _guard = lock_gate_counters(); | ||
| 48756 | + reset_ibc_owned_rect_chroma_footprint_444_hits(); | ||
| 48757 | + // The refusal this gate used to assert must NOT be what happens now. | ||
| 48758 | + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | ||
| 48759 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 48760 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 48761 | + let obu = dir.join("in.obu"); | ||
| 48762 | + std::fs::write(&obu, &stream).expect("writing the stream"); | ||
| 48763 | + let aom_prefix = dir.join("aom"); | ||
| 48764 | + let out = Command::new(aomdec_path()) | ||
| 48765 | + .args(["--codec=av1", "-o"]) | ||
| 48766 | + .arg(dir.join("out.y4m")) | ||
| 48767 | + .arg(&obu) | ||
| 48768 | + .env("EC_AV1_FINAL_DUMP", &aom_prefix) | ||
| 48769 | + .stdin(Stdio::null()) | ||
| 48770 | + .stdout(Stdio::piped()) | ||
| 48771 | + .stderr(Stdio::piped()) | ||
| 48772 | + .output() | ||
| 48773 | + .expect("aomdec failed to run"); | ||
| 48774 | + assert!( | ||
| 48775 | + out.status.success(), | ||
| 48776 | + "{NAME}: the oracle aomdec refused the stream: {}", | ||
| 48777 | + String::from_utf8_lossy(&out.stderr) | ||
| 48778 | + ); | ||
| 48779 | + let ours_prefix = dir.join("ours"); | ||
| 48780 | + set_final_dump_prefix(Some(ours_prefix.display().to_string())); | ||
| 48781 | + let decoded = decode_stream(&stream); | ||
| 48782 | + set_final_dump_prefix(None); | ||
| 48783 | + if let Err(e) = decoded { | ||
| 48784 | + panic!( | ||
| 48785 | + "{NAME}: this decoder refused the witness: {e} -- the chroma plane block is \ | ||
| 48786 | + sized ss-wide and walked in `get_vartx_max_txsize` units, so the 4:4:4 32x64 \ | ||
| 48787 | + plane block is two TX_32X32 units, NOT the rect unit the refusal named" | ||
| 48788 | + ); | ||
| 48789 | + } | ||
| 48790 | + let hits = ibc_owned_rect_chroma_footprint_444_hits(); | ||
| 48791 | + assert_eq!( | ||
| 48792 | + hits, 5, | ||
| 48793 | + "{NAME}: {hits} 128-root intra-BC strip(s) sized at 4:4:4, not 5 -- the witness \ | ||
| 48794 | + stopped exercising the arm" | ||
| 48795 | + ); | ||
| 48796 | + assert!( | ||
| 48797 | + !std::fs::read(format!("{}.f0", ours_prefix.display())) | ||
| 48798 | + .unwrap_or_default() | ||
| 48799 | + .is_empty(), | ||
| 48800 | + "{NAME}: our decoder wrote no frame" | ||
| 48801 | + ); | ||
| 48802 | + for f in 0..3 { | ||
| 48803 | + let aom_dump = std::fs::read(format!("{}.f{f}", aom_prefix.display())) | ||
| 48804 | + .unwrap_or_else(|e| panic!("{NAME}: oracle dump f{f} missing: {e}")); | ||
| 48805 | + let our_dump = std::fs::read(format!("{}.f{f}", ours_prefix.display())) | ||
| 48806 | + .unwrap_or_else(|e| panic!("{NAME}: our dump f{f} missing: {e}")); | ||
| 48807 | + assert_eq!( | ||
| 48808 | + our_dump.len(), | ||
| 48809 | + 3 * PLANE, | ||
| 48810 | + "{NAME}: frame {f} is not 8-bit 4:4:4 512x512" | ||
| 48811 | + ); | ||
| 48812 | + assert_eq!( | ||
| 48813 | + our_dump.len(), | ||
| 48814 | + aom_dump.len(), | ||
| 48815 | + "{NAME}: frame {f} length differs" | ||
| 48816 | + ); | ||
| 48817 | + for (plane, name) in [(0usize, "Y"), (1, "U"), (2, "V")] { | ||
| 48818 | + let at = plane * PLANE; | ||
| 48819 | + let floor = EXACT_PREFIX[f][plane]; | ||
| 48820 | + if our_dump[at..at + floor] == aom_dump[at..at + floor] { | ||
| 48821 | + continue; | ||
| 48822 | + } | ||
| 48823 | + let first = (0..floor) | ||
| 48824 | + .find(|&s| our_dump[at + s] != aom_dump[at + s]) | ||
| 48825 | + .unwrap_or(floor); | ||
| 48826 | + panic!( | ||
| 48827 | + "{NAME}: frame {f} plane {name} diverges from the oracle at sample {first} \ | ||
| 48828 | + of {PLANE} (x={}, y={}) -- the exact prefix this gate pins is {floor} and \ | ||
| 48829 | + it only grows", | ||
| 48830 | + first % 512, | ||
| 48831 | + first / 512 | ||
| 48832 | + ); | ||
| 48833 | + } | ||
| 48834 | + } | ||
| 48835 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 48836 | + } | ||
| 48685 | } | 48837 | } |
lanes/av1chromarect.report.mdadded+388 -0
| @@ -0,0 +1,388 @@ | |||
| 1 | +# lane-av1chromarect — 4:4:4 chroma extent + multi-unit walk at the 128-root intra-BC strip | ||
| 2 | + | ||
| 3 | +Worktree `~/.cache/wt/av1chromarect`, branch `lane-av1chromarect`, base | ||
| 4 | +`edffad9e` ("Merge lane-chromahalvings-r5: EC_HALVSWEEP rungs"). All edits are | ||
| 5 | +absolute-pathed inside this worktree; `git -C ~/Documents/Code/Rust/edith_codecs | ||
| 6 | +status --porcelain` printed nothing after every edit batch. | ||
| 7 | + | ||
| 8 | +Target: `decode_intrabc_owned_rect` (`crates/ec-av1/src/decode.rs:16897`) — the | ||
| 9 | +128-root intra-BC HORZ/VERT strip path (`BLOCK_128X64` / `BLOCK_64X128` and the | ||
| 10 | +`decode_block_rect64` strips under them). | ||
| 11 | + | ||
| 12 | +## 0. Provenance of the witness | ||
| 13 | + | ||
| 14 | +`crates/ec-av1/fixtures/r512.obu`, 6948 B, git blob | ||
| 15 | +`bff992e98d01fed6ec73ed35ddd73f9fa482d19f`. It is on **`lane-chromahalvings-r3`** | ||
| 16 | +and on no other ref of that lane (`lane-chromahalvings` and | ||
| 17 | +`lane-chromahalvings-r5` both lack it, and so does `main`): | ||
| 18 | + | ||
| 19 | + $ for r in lane-chromahalvings-r3 lane-chromahalvings lane-chromahalvings-r5 main; do | ||
| 20 | + printf "%s " "$r"; git cat-file -e "$r:crates/ec-av1/fixtures/r512.obu" 2>/dev/null \ | ||
| 21 | + && git rev-parse "$r:crates/ec-av1/fixtures/r512.obu" || echo MISSING; done | ||
| 22 | + lane-chromahalvings-r3 bff992e98d01fed6ec73ed35ddd73f9fa482d19f | ||
| 23 | + lane-chromahalvings MISSING | ||
| 24 | + lane-chromahalvings-r5 MISSING | ||
| 25 | + main MISSING | ||
| 26 | + $ git hash-object crates/ec-av1/fixtures/r512.obu | ||
| 27 | + bff992e98d01fed6ec73ed35ddd73f9fa482d19f | ||
| 28 | + | ||
| 29 | +Recipe (from `lanes/av1chromahalvings.report.md` r4, re-stated so the pin is | ||
| 30 | +reproducible): testsrc2 512x512 yuv444p 8-bit, `--sb-size=128 --enable-intrabc=1 | ||
| 31 | +--enable-palette=1 --cq-level=50 --enable-rect-partitions=1 | ||
| 32 | +--enable-1to4-partitions=1 --min-partition-size=4 --max-partition-size=128 | ||
| 33 | +--tune-content=screen --profile=1 --obu`, 3 frames. | ||
| 34 | + | ||
| 35 | +## 1. The defect, and the red-before MEASURED HERE | ||
| 36 | + | ||
| 37 | +`decode_intrabc_owned_rect` sized its chroma plane block `(bw / 2, bh / 2)` and | ||
| 38 | +passed `px / 2, py / 2` at eight sites as the chroma MV origins. libaom does not | ||
| 39 | +halve there: `av1_get_max_uv_txsize` (blockd.h:1372) is | ||
| 40 | +`av1_get_adjusted_tx_size(max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, | ||
| 41 | +ss_y)])` and `get_plane_block_size` is `ss_size_lookup[bsize]`, so at ss (0,0) | ||
| 42 | +the chroma plane block **is** the luma footprint. At 4:2:0 (`ss_x == ss_y == 1`) | ||
| 43 | +`>> 1` and `/ 2` are the same arithmetic, which is why the bug was invisible | ||
| 44 | +until a 4:4:4 witness existed. | ||
| 45 | + | ||
| 46 | +Red-before, on the **unpatched** line in this worktree, per-plane sample counts | ||
| 47 | +against the instrumented aomdec (`aomdec --codec=av1` with | ||
| 48 | +`EC_AV1_FINAL_DUMP`, ours with `set_final_dump_prefix`; 512x512 8-bit 4:4:4, | ||
| 49 | +786432 B per frame, three frames, both sides in decode order): | ||
| 50 | + | ||
| 51 | + f0 Y 166229 wrong from 65728 | U 155383 from 32848 | V 153498 from 32848 total 475110 | ||
| 52 | + f1 Y 0 (byte-exact) | U 74708 from 49282 | V 73501 from 49280 total 148209 | ||
| 53 | + f2 Y 0 (byte-exact) | U 9216 from 114880 | V 8192 from 229760 total 17408 | ||
| 54 | + | ||
| 55 | +Luma byte-exact on f1 and f2 while chroma is wrong is the signature that makes | ||
| 56 | +this a chroma-plane sizing defect and not a block-geometry one. The numbers | ||
| 57 | +reproduce the previous lane's r4 measurement exactly. | ||
| 58 | + | ||
| 59 | +## 2. What the blocker's own refusal was actually asking for | ||
| 60 | + | ||
| 61 | +The previous lane's r4/r5 finding was that the ss-derived extent REFUSES | ||
| 62 | +`fixtures/r512.obu` with | ||
| 63 | + | ||
| 64 | + unsupported: AV1 tile (a rectangular inter chroma transform unit whose shape | ||
| 65 | + has no coefficient table set here) | ||
| 66 | + | ||
| 67 | +and concluded the fix needs a new `TxbSet` — `ChromaRect32x64` / `ChromaRect64x32` | ||
| 68 | +— with its own CDF set, `rect_scan` and rect `base_ctx_rect` / `br_ctx_rect`. | ||
| 69 | +**That conclusion is wrong, and the wrongness is the finding.** | ||
| 70 | + | ||
| 71 | +The refusal names the shape the crate HANDED `rect_inter_chroma_set`, not the | ||
| 72 | +shape libaom codes. With the ss extent a 4:4:4 32x64 luma block's chroma plane | ||
| 73 | +block is 32x64, and this crate read it as one rect transform. libaom never forms | ||
| 74 | +a 64-point CHROMA transform: | ||
| 75 | + | ||
| 76 | +* `get_vartx_max_txsize` (blockd.h:1447) — | ||
| 77 | + `return av1_get_adjusted_tx_size(max_txsize_rect_lookup[bsize]);` for `plane != 0`. | ||
| 78 | +* `av1_get_adjusted_tx_size` (blockd.h, just above `av1_get_max_uv_txsize`) maps | ||
| 79 | + `TX_64X32 → TX_32X32` and `TX_32X64 → TX_32X32`, and returns everything else | ||
| 80 | + unchanged. | ||
| 81 | +* `max_txsize_rect_lookup[BLOCK_SIZES_ALL]` (common_data.h:126) has | ||
| 82 | + `BLOCK_32X64 → TX_32X64`, `BLOCK_64X32 → TX_64X32`. | ||
| 83 | +* `decode_token_recon_block` (decodeframe.c:994-1004) steps the plane block by | ||
| 84 | + `tx_size_*_unit[max_tx_size]`, i.e. 4 mi per axis, and | ||
| 85 | + `decode_reconstruct_tx`'s `if (tx_size == plane_tx_size || plane)` arm never | ||
| 86 | + recurses for chroma — the same statement from the other side. | ||
| 87 | + | ||
| 88 | +So a 4:4:4 32x64 chroma plane block is **two stacked `TX_32X32` units**, each | ||
| 89 | +with its own eob, its own scan and its own coefficient context. `TX_32X32` is | ||
| 90 | +already in the crate: `rect_inter_chroma_set(32, 32) → TxbSet::Chroma32` | ||
| 91 | +(decode.rs:28919, the arm `lane-av1-444` added). What was missing was not a | ||
| 92 | +coefficient set but the **walk** that hands the crate `2 x 32x32` instead of | ||
| 93 | +`1 x 32x64`. | ||
| 94 | + | ||
| 95 | +The 64-axis truncation `read_inter_plane_rect` does internally | ||
| 96 | +(`let (cw, ch) = (w.min(32), h.min(32));` + `extend_corner`, decode.rs:29532) is | ||
| 97 | +libaom's `av1_get_max_eob` rule, and that rule is a LUMA rule: a chroma plane | ||
| 98 | +block is never 64 points long in the first place. Routing a 4:4:4 32x64 chroma | ||
| 99 | +plane block through one 32x64 unit would have produced a new `TxbSet` that no | ||
| 100 | +stream can ever exercise — a coefficient table with no bitstream, which is the | ||
| 101 | +worst kind of green. | ||
| 102 | + | ||
| 103 | +### What shipped instead | ||
| 104 | + | ||
| 105 | +* `read_intrabc_rect_chroma_split` (decode.rs, after | ||
| 106 | + `decode_intrabc_owned_rect`): the same `(cw.min(32), ch.min(32))` / `nx * ny` | ||
| 107 | + tiling `read_inter_rect_chroma` already implements for the other rect paths, | ||
| 108 | + for a caller that keeps its own grid assembly and neighbour recording. It is | ||
| 109 | + entered ONLY when `cw.min(32) != cw || ch.min(32) != ch`, so at 4:2:0 and at | ||
| 110 | + every 4:4:4 shape below 64 the caller's own one-unit read is untouched | ||
| 111 | + byte-for-byte. | ||
| 112 | +* Per unit: its own `around_mi_rect(cu_mi, span_x, span_y)` gather, its own | ||
| 113 | + `(cpx + cu_col*uw, cpy + cu_row*uh)` origin, its own prediction slice, its own | ||
| 114 | + `covering_leaf_tx_type(...)` inheritance (`av1_get_tx_type`, blockd.h:1287, | ||
| 115 | + reads `xd->tx_type_map` at the unit's own position), the `get_txb_ctx` plus-10 | ||
| 116 | + offset as `Some(3)`, and `record_mi_chroma` immediately so the next unit | ||
| 117 | + reads this one's context. | ||
| 118 | +* `record_split_luma_rect_mi_modes` / `record_rect_mi_luma_only` (new, extracted | ||
| 119 | + from `record_split_luma_rect_mi` / `record_rect_mi`): when the chroma plane | ||
| 120 | + block was walked as several units, the whole-block coefficient stamp would | ||
| 121 | + overwrite the per-unit spans with one state (the `override-slot-on-one-arm` | ||
| 122 | + class, the same reason the lossless arm sets `mu_chroma = true`). The flag is | ||
| 123 | + `!skip && …`: a SKIPPED strip reads no chroma unit at all (its whole plane | ||
| 124 | + block is one `push_mc_rect` of `ZERO_RESIDUAL`), so no per-unit stamp ran and | ||
| 125 | + the whole-block stamp is still the only one that happens. | ||
| 126 | + | ||
| 127 | +### The two pieces the charter asked for, and why they are not needed | ||
| 128 | + | ||
| 129 | +* **CDF set** — `Chroma32` (`cdf_state.rs`), the exact | ||
| 130 | + `get_txsize_entropy_ctx(TX_32X32)` tables. Nothing new. | ||
| 131 | +* **`rect_scan`** — a `TX_32X32` unit is square, so | ||
| 132 | + `read_inter_plane_rect` takes its `(cw, ch) == (32, 32)` branch and reads | ||
| 133 | + `default_scan(TX32)` (decode.rs:29546); `rect_scan` is never called. Nothing | ||
| 134 | + new. | ||
| 135 | +* **rect `base_ctx_rect` / `br_ctx_rect`** — same reason: those are the rect | ||
| 136 | + forms of the 2:1 and 4:1 nz-map offsets, and no 2:1 or 4:1 chroma unit exists | ||
| 137 | + at 4:4:4 for this block shape. Nothing new. The call the new walk makes is | ||
| 138 | + byte-identical to the one `read_inter_rect_chroma` already makes for the | ||
| 139 | + 4:4:4 four-unit arms proven by `lane-av1chrtx`. | ||
| 140 | + | ||
| 141 | +## 3. Result on the witness, and the OPEN fork that remains | ||
| 142 | + | ||
| 143 | +Same oracle, same comparison, after the fix: | ||
| 144 | + | ||
| 145 | + f0 Y 0 (byte-exact) | U 7488 from 229728 | V 8128 from 229728 total 15616 | ||
| 146 | + f1 Y 0 (byte-exact) | U 22571 from 65704 | V 41782 from 65704 total 64353 | ||
| 147 | + f2 Y 0 (byte-exact) | U 0 | V 0 0 | ||
| 148 | + | ||
| 149 | +Wrong samples over the whole stream: **640727 → 79969** (−87.5 %). Luma is | ||
| 150 | +byte-exact on all three frames (786432/786432 samples; it was 166229 wrong on | ||
| 151 | +f0). Frame 2 is byte-exact on all three planes (it was 9216 U + 8192 V wrong). | ||
| 152 | + | ||
| 153 | +Reach proof for the site, `EC_HALVSWEEP=1` (the rung is main's, merge | ||
| 154 | +`edffad9e`), five strips on this witness, `mi` in 4-px units: | ||
| 155 | + | ||
| 156 | + EC_HALV ibc_owned mi=(32,40) bw=32 bh=64 skip=false | ||
| 157 | + EC_HALV ibc_owned mi=(48,64) bw=32 bh=64 skip=true | ||
| 158 | + EC_HALV ibc_owned mi=(64,108) bw=16 bh=64 skip=true | ||
| 159 | + EC_HALV ibc_owned mi=(112,96) bw=32 bh=64 skip=true | ||
| 160 | + EC_HALV ibc_owned mi=(112,104) bw=32 bh=64 skip=true | ||
| 161 | + | ||
| 162 | +(The previous lane reported 6 and named `mi=(72,32) 64x32 skip=false`. On this | ||
| 163 | +base the count is 5 and that block is not reached. The witness blob is | ||
| 164 | +byte-identical, so the difference is the tree, not the stream — the same | ||
| 165 | +stale-verdict hazard the previous lane's r4 recorded, re-measured rather than | ||
| 166 | +inherited.) | ||
| 167 | + | ||
| 168 | +### The residual is a DIFFERENT site, and it is NOT this lane's | ||
| 169 | + | ||
| 170 | +Both remaining regions are chroma-only, bounded, and luma-clean, so they are | ||
| 171 | +reconstruction defects rather than entropy desyncs: | ||
| 172 | + | ||
| 173 | +* f0: 128 dirty 8x8 cells, bbox x=352..=504, y=448..=504 — the last 64 rows of | ||
| 174 | + the frame. Strip #4's own footprint (x=384..=416) is CLEAN; strip #5's | ||
| 175 | + (x=416..=448) is dirty, and so is everything to its right. | ||
| 176 | +* f1: 362 dirty 8x8 cells (U) / 667 (V), bbox x=128..=368 / 128..=408, | ||
| 177 | + y=128..=504, first dirty cell (168,128) PARTIAL (56 of 64 samples). | ||
| 178 | + | ||
| 179 | +Ruled out by measurement, not by argument: | ||
| 180 | + | ||
| 181 | +* **CfL.** `cfl_ac_q3_at` (decode.rs:20179) is the other `bw / 2, bh / 2` site | ||
| 182 | + in this wave and is out of scope (another agent owns it). A temporary probe at | ||
| 183 | + both its callers (`cfl_ac_q3`, `cfl_ac_q3_rect`) over the whole witness: | ||
| 184 | + | ||
| 185 | + $ EC_ZZCFL=1 cargo test -p ec-av1 --lib <witness> -- --nocapture | grep -c ZZCFL | ||
| 186 | + 0 | ||
| 187 | + | ||
| 188 | + The witness codes NO CfL block, so `cfl_ac_q3_at` cannot be the residual. (The | ||
| 189 | + probe was removed before the commit; it is not in the diff.) | ||
| 190 | +* **The skip arm's record.** Forcing `chroma_split_units` true for skipped | ||
| 191 | + strips as well changes neither number — the f0 band and the f1 region are | ||
| 192 | + identical with and without it. | ||
| 193 | +* **This lane's helper.** The per-unit prediction slice's column term | ||
| 194 | + (`cu_col * uw`) is dead on this witness (`nx == 1`), so mutating it leaves the | ||
| 195 | + gate green; the row term does bite (see §5, M5). | ||
| 196 | + | ||
| 197 | +NOT DONE, explicitly: the f0 and f1 chroma residue above. It is not attributable | ||
| 198 | +to `decode_intrabc_owned_rect` from the evidence I have, and I did not identify | ||
| 199 | +its site. It is stated as a measured open fork, with numbers, rather than | ||
| 200 | +absorbed into a "wrong by exactly N" expectation. | ||
| 201 | + | ||
| 202 | +## 4. Gates | ||
| 203 | + | ||
| 204 | +### 4.1 The refusal gate went in FIRST, and it went RED | ||
| 205 | + | ||
| 206 | +Commit 1 (`58629693`) pins the witness, lands the ss-derived extent and the eight | ||
| 207 | +MV origin pairs, and adds | ||
| 208 | +`a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_coefficient_set` | ||
| 209 | +— which asserts, on purpose, that the witness is REFUSED with the exact string | ||
| 210 | +`a rectangular inter chroma transform unit whose shape has no coefficient table | ||
| 211 | +set here`, and that exactly one strip reached the corrected extent before the | ||
| 212 | +decode stopped. It cites this lane in the test. Without it the witness would be | ||
| 213 | +a pin with nothing watching it. | ||
| 214 | + | ||
| 215 | +Commit 2 replaces that test with | ||
| 216 | +`a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes`, the | ||
| 217 | +pixel-exactness assertion the refusal gate was there to force. | ||
| 218 | + | ||
| 219 | +The refusal string is gone from the witness's decode because nothing reaches it, | ||
| 220 | +not because it was deleted: `rect_inter_chroma_set` still refuses `(32, 64)` and | ||
| 221 | +`(64, 32)`, the string is still in `decode.rs:28938` and in | ||
| 222 | +`refusal_inventory.rs:55`, and the gate | ||
| 223 | +`every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan` | ||
| 224 | +(which names all three rect refusals and asserts they are still in the source) | ||
| 225 | +still passes. | ||
| 226 | + | ||
| 227 | +### 4.2 Non-vacuity: the route counter, and three mutations | ||
| 228 | + | ||
| 229 | +`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS` counts 128-root intra-BC strips whose | ||
| 230 | +chroma plane block was sized at ss (0,0). At 4:2:0 the corrected and halving | ||
| 231 | +forms are identical, so `>= 1` cannot be satisfied by a 4:2:0 stream, and the | ||
| 232 | +arm is exclusive to this function. The gate asserts `hits == 5`. | ||
| 233 | + | ||
| 234 | +Mutation proofs against the gate, each reverted after: | ||
| 235 | + | ||
| 236 | +| # | mutation | result | | ||
| 237 | +| --- | --- | --- | | ||
| 238 | +| M1 | `bw >> ss_x` / `bh >> ss_y` and `px >> ss_x` / `py >> ss_y` back to `/ 2` | **RED** — `assertion left == right failed: 6 128-root intra-BC strip(s) sized at 4:4:4, not 5` (the counter bites: with the halving a sixth strip reaches the arm) | | ||
| 239 | +| M3 | `(nx, ny) = (cw / uw, ch / uh)` → `(ch / uh, cw / uw)` | **RED** — `frame 0 plane Y diverges from the oracle at sample 65728 of 262144 (x=192, y=128)` | | ||
| 240 | +| M5 | `let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh)` → `(cpx, cpy)` | **RED** — `frame 0 plane U diverges from the oracle at sample 65696 of 262144 (x=160, y=128)` | | ||
| 241 | + | ||
| 242 | +A fourth mutation (dropping the `cu_col * uw` term from the prediction slice) | ||
| 243 | +left the gate GREEN — correctly, because `nx == 1` on this witness makes that | ||
| 244 | +term dead here. Recorded because a green mutation is a fact about coverage, not | ||
| 245 | +about the gate. | ||
| 246 | + | ||
| 247 | +The gate's own shape, per (frame, plane) exact prefix against the oracle, with | ||
| 248 | +the floors it pins: `[[262144, 229728, 229728], [262144, 65704, 65704], | ||
| 249 | +[262144, 262144, 262144]]` — the same honest "exact prefix that only grows" form | ||
| 250 | +as the sibling `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`. | ||
| 251 | +It is a floor, not an exactness claim: §3 says exactly what it does not cover. | ||
| 252 | + | ||
| 253 | +## 5. Gate families re-quoted | ||
| 254 | + | ||
| 255 | +`cargo check -p ec-av1 --all-targets` clean (no errors, no warnings) before every | ||
| 256 | +run, on a private `CARGO_TARGET_DIR`; a green gate alongside a build error would | ||
| 257 | +have been a stale binary. | ||
| 258 | + | ||
| 259 | + $ EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 \ | ||
| 260 | + cargo test -p ec-av1 --lib -- a_444 lossless_444 intrabc_rect 444_lossless -- --nocapture | ||
| 261 | + test result: ok. 33 passed; 0 failed; 0 ignored; 0 measured; 730 filtered out | ||
| 262 | + | ||
| 263 | +That set contains the 4:4:4-lossless family (`a_lossless_444_*`, | ||
| 264 | +`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units`, | ||
| 265 | +`a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`), the intrabc_rect | ||
| 266 | +family (`a_444_intrabc_rect4_reads_its_own_chroma_plane_block`, | ||
| 267 | +`a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units`, | ||
| 268 | +`a_lossless_444_intrabc_rect_replay_steps_by_the_units_own_mi_footprint`, | ||
| 269 | +`a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands`, | ||
| 270 | +`a_coded_rect_intrabc_block_reconstructs_in_both_orientations`) and — the 4:2:0 | ||
| 271 | +identity arm — `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, | ||
| 272 | +which decodes the pinned 4:2:0 twin (`420_intrabc_rect4_witness.obu`) through | ||
| 273 | +`decode_all_frames_vs_oracle`. | ||
| 274 | + | ||
| 275 | +The wider 121-test `rect intrabc ibc chroma 444 420 subsampl` family, tip vs | ||
| 276 | +the base commit, is in §6. | ||
| 277 | + | ||
| 278 | +## 6. 121-test family: tip vs base | ||
| 279 | + | ||
| 280 | +One filtered run per tree, same filter string, same env, separate private | ||
| 281 | +`CARGO_TARGET_DIR` each (a shared-shape target dir is exactly how the previous | ||
| 282 | +lane got a stale verdict): | ||
| 283 | + | ||
| 284 | + $ EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ | ||
| 285 | + -- rect intrabc ibc chroma 444 420 subsampl -- --nocapture | ||
| 286 | + | ||
| 287 | +| tree | result | | ||
| 288 | +| --- | --- | | ||
| 289 | +| base `edffad9e` (`~/.cache/wt/av1chromarect-base`, detached) | `ok. 137 passed; 0 failed; 5 ignored; 0 measured; 620 filtered out; finished in 288.38s` | | ||
| 290 | +| tip `lane-av1chromarect` | `ok. 138 passed; 0 failed; 5 ignored; 0 measured; 620 filtered out; finished in 295.84s` | | ||
| 291 | + | ||
| 292 | +The set difference of the two passing-test lists is exactly one line: | ||
| 293 | + | ||
| 294 | + 34a35 | ||
| 295 | + > test stream::tests::a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes | ||
| 296 | + | ||
| 297 | +The same 5 tests are `#[ignore]`d in both trees (two superblock-size globals, a | ||
| 298 | +directional sweep, an intrabc probe needing the real-library manifest, and the | ||
| 299 | +rectx recipe sweep). Nothing regressed, nothing was silently dropped. | ||
| 300 | + | ||
| 301 | +Inside that family, the 4:2:0 identity is carried by | ||
| 302 | +`a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, which decodes | ||
| 303 | +the pinned 4:2:0 twin `420_intrabc_rect4_witness.obu` through | ||
| 304 | +`decode_all_frames_vs_oracle` (every frame byte-exact vs aomdec) and | ||
| 305 | +`a_444_intrabc_rect4_reads_its_own_chroma_plane_block`; the 4:4:4-lossless arm | ||
| 306 | +by the `a_lossless_444_*` set; the intrabc_rect arm by | ||
| 307 | +`a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units`, | ||
| 308 | +`a_lossless_444_intrabc_rect_replay_steps_by_the_units_own_mi_footprint`, | ||
| 309 | +`a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands`, | ||
| 310 | +`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units` and | ||
| 311 | +`a_coded_rect_intrabc_block_reconstructs_in_both_orientations`. | ||
| 312 | + | ||
| 313 | +## 7. Gap row — `decode_intra_sub8_leaf` has no `chroma_422` arm | ||
| 314 | + | ||
| 315 | +`crates/ec-av1/src/decode.rs:45594`, body ends at `46422`. It carries a | ||
| 316 | +`chroma_444` branch set and **zero** `chroma_422` mentions inside the body | ||
| 317 | +(`awk 'NR>=45594 && NR<=46422' | grep -c chroma_422` → `0`; the two | ||
| 318 | +`chroma_422` mentions at 45394/45406 belong to the enclosing | ||
| 319 | +`decode_intra_split`, not to this function). | ||
| 320 | + | ||
| 321 | +The 4:4:4 branches it owns, and what each falls back to at 4:2:2: | ||
| 322 | + | ||
| 323 | +| line | what the `chroma_444` arm does | what 4:2:2 gets instead | | ||
| 324 | +| --- | --- | --- | | ||
| 325 | +| 46083 | `let chroma_444 = ss_x == 0 && ss_y == 0` | `false` at (1,0) | | ||
| 326 | +| 46086 | `unit_x, unit_y = (px, py)` | `(cpx, cpy)` — the 4:2:0 double halving; at (1,0) the width halves and the height does not | | ||
| 327 | +| 46088-46093 | `reach_c` = the piece's own rect reach at 4:4:4 | `group_reach` (an 8x8 group reach) | | ||
| 328 | +| 46095 | `band_r, band_c` from `lmi` | from `r, c` (the group) | | ||
| 329 | +| 46101-46102 | `smooth_uv_neighbour` sampled at `lmi` | sampled at `gr, gc` | | ||
| 330 | +| 46115 | `record_uv_mode_mi(lmi, w_mi, h_mi)` | `record_uv_mode_mi(gr, gc, 2, 2)` — a 2x2 group stamp | | ||
| 331 | +| 46122 | `cfl_src_rect(px, py, bw, bh)` | not taken | | ||
| 332 | +| 46134, 46198 | the non-square 4:4:4 unit shape arms | not taken | | ||
| 333 | +| 46340-46341 | chroma per-unit gather at `lmi` with a 4-px step | at `group_mi` with an 8-px step | | ||
| 334 | +| 46399 | the 4:4:4 publish/stamp half | the `!chroma_444 && !chroma_422` fallbacks (45394/45406 in the enclosing `decode_intra_split`) | | ||
| 335 | + | ||
| 336 | +The shape the missing arm would have to be: at 4:2:2 `ss_size_lookup` maps an | ||
| 337 | +8x4 block to `BLOCK_INVALID` (common_data.c:38) and no `TX_4X8` chroma unit | ||
| 338 | +exists, so a 4:2:2 sub-8 leaf's chroma is coded CHUNKED, exactly the | ||
| 339 | +`invalid_ss_plane` case `read_inter_rect_chroma` already special-cases | ||
| 340 | +(decode.rs:29328, `(4, 32)` at ss (1,0) → `(4, 8)` units). | ||
| 341 | + | ||
| 342 | +**Caller set — exactly two sites, and BOTH are already 4:2:2-aware:** | ||
| 343 | + | ||
| 344 | +1. `decode.rs:44724` — the `BLOCK_4X4` leaf of the sub-8x8 intra-in-inter split | ||
| 345 | + arm. It passes | ||
| 346 | + `has_chroma = chroma_444 || (cmi & 1 == 1 && chroma_422) || i == 3` | ||
| 347 | + (libaom's `is_chroma_reference`, `av1_common_int.h:1459`: BOTH odd-column | ||
| 348 | + pieces at 4:2:2). | ||
| 349 | +2. `decode.rs:46610` — the `(bw, bh)` 8x8/4x8/8x4 piece. It passes | ||
| 350 | + `has_chroma = piece_is_chroma_ref(i)`, and `piece_is_chroma_ref` | ||
| 351 | + (decode.rs:46534) has an explicit `else if chroma_422 { !vert || ((gc + i) & 1) == 1 }` | ||
| 352 | + branch. | ||
| 353 | + | ||
| 354 | +So the callers compute the 4:2:2 chroma-reference rule correctly and the leaf | ||
| 355 | +body has no geometry arm to honour it. This is a latent gap, not a live bug: the | ||
| 356 | +crate refuses 4:2:2 by name at the sequence header | ||
| 357 | +(`"a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder | ||
| 358 | +decodes 4:2:0 and 4:4:4; 4:2:2 is not ported"`, `refusal_inventory.rs:119`, gate | ||
| 359 | +`a_non_420_subsampled_sequence_header_is_refused_by_name`, stream.rs:2258), so | ||
| 360 | +`chroma_422` is always `false` when this function runs. Not implemented here, by | ||
| 361 | +charter. | ||
| 362 | + | ||
| 363 | +## 8. Scope boundaries, stated | ||
| 364 | + | ||
| 365 | +* `cfl_ac_q3_at` (decode.rs:20179, `let (cw, ch) = (bw / 2, bh / 2);`, no | ||
| 366 | + `fctx`) — **untouched, another lane owns it.** §3 measures that the witness | ||
| 367 | + codes no CfL, so it is not this witness's residual either. | ||
| 368 | +* `suppress_internal_lf_edges` — **not re-fixed.** C1 (wave 3d, on this base) | ||
| 369 | + already threads `fctx` into it and computes `((w_mi * MI) >> ss_x(fctx)).max(4)`. | ||
| 370 | + The earlier "format-blind" claim is retracted upstream; there is nothing here | ||
| 371 | + to change. | ||
| 372 | +* `decode_intrabc_rect` (the non-`owned` sibling, decode.rs:13646) reads its | ||
| 373 | + chroma with the same single-unit `rect_inter_chroma_set(cw, ch)`. It is | ||
| 374 | + ss-correct (lane-ibc444c) and its pinned 4:4:4 witness is 8x16, one unit, so | ||
| 375 | + the multi-unit case is latent there too. I did not widen the fix: this lane's | ||
| 376 | + witness and its gate do not reach it, and a change there would be unmeasured. | ||
| 377 | + Flagged for whoever takes the next 4:4:4 rect cell. | ||
| 378 | + | ||
| 379 | +## 9. What I could not do | ||
| 380 | + | ||
| 381 | +1. The f0/f1 chroma residue of §3 is not identified to a site. 79969 wrong | ||
| 382 | + samples remain out of 2359296 (3.4 %); luma is exact everywhere. | ||
| 383 | +2. The 128-root multi-unit *record* difference in §2 is derived from libaom's | ||
| 384 | + per-unit above/left context update and validated by the gate going from | ||
| 385 | + 640727 wrong samples to 79969 with luma exact; I did not diff our per-unit | ||
| 386 | + above/left contexts against the oracle's rung-by-rung. | ||
| 387 | +3. No heavy encodes were run: the witness was taken from the pin, and the gate | ||
| 388 | + families are fixture-driven. No server fleet run was requested or consumed. | ||