4:4:4 chroma plane block at the 128-root intra-BC strip: walk it in
Browse files at this commitb88c866186a80170492725d24751d8972d51a7ffParent: 287d79c3 changed files +821 -128
- crates/ec-av1/src/decode.rs +321 -98
- crates/ec-av1/src/stream.rs +113 -30
- lanes/av1chromarect.report.md +387 -0
crates/ec-av1/src/decode.rsmodified+321 -98
| @@ -10429,6 +10429,20 @@ impl Neighbours { | |||
| 10429 | mode: usize, | 10429 | mode: usize, |
| 10430 | uv_mode: usize, | 10430 | uv_mode: usize, |
| 10431 | 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, | ||
| 10432 | ) { | 10446 | ) { |
| 10433 | 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)); |
| 10434 | // 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 |
| @@ -10452,7 +10466,28 @@ impl Neighbours { | |||
| 10452 | } | 10466 | } |
| 10453 | 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); |
| 10454 | 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); |
| 10455 | - 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); | ||
| 10456 | } | 10491 | } |
| 10457 | 10492 | ||
| 10458 | /// The coefficient-context half of [`Self::record`], taking the block's | 10493 | /// The coefficient-context half of [`Self::record`], taking the block's |
| @@ -10652,6 +10687,39 @@ impl Neighbours { | |||
| 10652 | mode: usize, | 10687 | mode: usize, |
| 10653 | uv_mode: usize, | 10688 | uv_mode: usize, |
| 10654 | 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, | ||
| 10655 | ) { | 10723 | ) { |
| 10656 | let (mi_r, mi_c) = at_mi; | 10724 | let (mi_r, mi_c) = at_mi; |
| 10657 | let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | 10725 | let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); |
| @@ -10677,22 +10745,6 @@ impl Neighbours { | |||
| 10677 | 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); |
| 10678 | 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); |
| 10679 | 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); |
| 10680 | - let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 10681 | - let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | ||
| 10682 | - for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { | ||
| 10683 | - let plane = plane_idx + 1; | ||
| 10684 | - let state = neighbour_state(grid); | ||
| 10685 | - for cell in 0..h_mi { | ||
| 10686 | - if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { | ||
| 10687 | - self.left[mi_r + cell][plane] = state; | ||
| 10688 | - } | ||
| 10689 | - } | ||
| 10690 | - for cell in 0..w_mi { | ||
| 10691 | - if cell < w_mi.min(bound_w.saturating_sub(mi_c)) { | ||
| 10692 | - self.above[mi_c + cell][plane] = state; | ||
| 10693 | - } | ||
| 10694 | - } | ||
| 10695 | - } | ||
| 10696 | } | 10748 | } |
| 10697 | } | 10749 | } |
| 10698 | 10750 | ||
| @@ -16982,6 +17034,8 @@ fn decode_intrabc_owned_rect( | |||
| 16982 | u_grid = Grid::Zero(cside * cside); | 17034 | u_grid = Grid::Zero(cside * cside); |
| 16983 | v_grid = Grid::Zero(cside * cside); | 17035 | v_grid = Grid::Zero(cside * cside); |
| 16984 | } 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()); | ||
| 16985 | for (idx, &(row, col, tw, th)) in ls.iter().enumerate() { | 17039 | for (idx, &(row, col, tw, th)) in ls.iter().enumerate() { |
| 16986 | let tu_mi = (mi_r + row, mi_c + col); | 17040 | let tu_mi = (mi_r + row, mi_c + col); |
| 16987 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); | 17041 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| @@ -17024,6 +17078,7 @@ fn decode_intrabc_owned_rect( | |||
| 17024 | fctx, | 17078 | fctx, |
| 17025 | )? | 17079 | )? |
| 17026 | }; | 17080 | }; |
| 17081 | + leaf_types.push((row, col, tw, th, tt)); | ||
| 17027 | if idx == 0 { | 17082 | if idx == 0 { |
| 17028 | luma_tx_type = tt; | 17083 | luma_tx_type = tt; |
| 17029 | } | 17084 | } |
| @@ -17039,43 +17094,66 @@ fn decode_intrabc_owned_rect( | |||
| 17039 | } | 17094 | } |
| 17040 | } | 17095 | } |
| 17041 | luma_grid = Grid::Zero(side * side); | 17096 | luma_grid = Grid::Zero(side * side); |
| 17042 | - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); | 17097 | + if cw.min(32) != cw || ch.min(32) != ch { |
| 17043 | - let (ug, _) = read_inter_plane_rect( | 17098 | + // lane-av1chromarect: more than one chroma transform unit (the |
| 17044 | - dec, | 17099 | + // 4:4:4 32x64/64x32 plane block). See the helper. |
| 17045 | - cdfs, | 17100 | + let (ug, vg) = read_intrabc_rect_chroma_split( |
| 17046 | - rect_inter_chroma_set(cw, ch)?, | 17101 | + dec, |
| 17047 | - (cw, ch), | 17102 | + cdfs, |
| 17048 | - cside, | 17103 | + neighbours, |
| 17049 | - 1, | 17104 | + (mi_r, mi_c), |
| 17050 | - around[1], | 17105 | + (cpx, cpy), |
| 17051 | - 0, | 17106 | + (cw, ch), |
| 17052 | - u, | 17107 | + cside, |
| 17053 | - cpx, | 17108 | + &pred_u, |
| 17054 | - cpy, | 17109 | + &pred_v, |
| 17055 | - Pred::Inline(&pred_u, cside), | 17110 | + &leaf_types, |
| 17056 | - Some(luma_tx_type), | 17111 | + luma_tx_type, |
| 17057 | - None, | 17112 | + u, |
| 17058 | - fctx, | 17113 | + v, |
| 17059 | - )?; | 17114 | + fctx, |
| 17060 | - let (vg, _) = read_inter_plane_rect( | 17115 | + )?; |
| 17061 | - dec, | 17116 | + u_grid = ug; |
| 17062 | - cdfs, | 17117 | + v_grid = vg; |
| 17063 | - rect_inter_chroma_set(cw, ch)?, | 17118 | + } else { |
| 17064 | - (cw, ch), | 17119 | + let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); |
| 17065 | - cside, | 17120 | + let (ug, _) = read_inter_plane_rect( |
| 17066 | - 2, | 17121 | + dec, |
| 17067 | - around[2], | 17122 | + cdfs, |
| 17068 | - 0, | 17123 | + rect_inter_chroma_set(cw, ch)?, |
| 17069 | - v, | 17124 | + (cw, ch), |
| 17070 | - cpx, | 17125 | + cside, |
| 17071 | - cpy, | 17126 | + 1, |
| 17072 | - Pred::Inline(&pred_v, cside), | 17127 | + around[1], |
| 17073 | - Some(luma_tx_type), | 17128 | + 0, |
| 17074 | - None, | 17129 | + u, |
| 17075 | - fctx, | 17130 | + cpx, |
| 17076 | - )?; | 17131 | + cpy, |
| 17077 | - u_grid = ug; | 17132 | + Pred::Inline(&pred_u, cside), |
| 17078 | - 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 | + } | ||
| 17079 | } else { | 17157 | } else { |
| 17080 | 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); |
| 17081 | let (g, tt) = read_inter_plane_rect( | 17159 | let (g, tt) = read_inter_plane_rect( |
| @@ -17097,53 +17175,93 @@ fn decode_intrabc_owned_rect( | |||
| 17097 | )?; | 17175 | )?; |
| 17098 | luma_tx_type = tt; | 17176 | luma_tx_type = tt; |
| 17099 | luma_grid = g; | 17177 | luma_grid = g; |
| 17100 | - let (ug, _) = read_inter_plane_rect( | 17178 | + if cw.min(32) != cw || ch.min(32) != ch { |
| 17101 | - dec, | 17179 | + // lane-av1chromarect: more than one chroma transform unit (the |
| 17102 | - cdfs, | 17180 | + // 4:4:4 32x64/64x32 plane block). See the helper. |
| 17103 | - rect_inter_chroma_set(cw, ch)?, | 17181 | + let (ug, vg) = read_intrabc_rect_chroma_split( |
| 17104 | - (cw, ch), | 17182 | + dec, |
| 17105 | - cside, | 17183 | + cdfs, |
| 17106 | - 1, | 17184 | + neighbours, |
| 17107 | - around[1], | 17185 | + (mi_r, mi_c), |
| 17108 | - 0, | 17186 | + (cpx, cpy), |
| 17109 | - u, | 17187 | + (cw, ch), |
| 17110 | - cpx, | 17188 | + cside, |
| 17111 | - cpy, | 17189 | + &pred_u, |
| 17112 | - Pred::Inline(&pred_u, cside), | 17190 | + &pred_v, |
| 17113 | - Some(luma_tx_type), | 17191 | + &[], |
| 17114 | - None, | 17192 | + luma_tx_type, |
| 17115 | - fctx, | 17193 | + u, |
| 17116 | - )?; | 17194 | + v, |
| 17117 | - let (vg, _) = read_inter_plane_rect( | 17195 | + fctx, |
| 17118 | - dec, | 17196 | + )?; |
| 17119 | - cdfs, | 17197 | + u_grid = ug; |
| 17120 | - rect_inter_chroma_set(cw, ch)?, | 17198 | + v_grid = vg; |
| 17121 | - (cw, ch), | 17199 | + } else { |
| 17122 | - cside, | 17200 | + let (ug, _) = read_inter_plane_rect( |
| 17123 | - 2, | 17201 | + dec, |
| 17124 | - around[2], | 17202 | + cdfs, |
| 17125 | - 0, | 17203 | + rect_inter_chroma_set(cw, ch)?, |
| 17126 | - v, | 17204 | + (cw, ch), |
| 17127 | - cpx, | 17205 | + cside, |
| 17128 | - cpy, | 17206 | + 1, |
| 17129 | - Pred::Inline(&pred_v, cside), | 17207 | + around[1], |
| 17130 | - Some(luma_tx_type), | 17208 | + 0, |
| 17131 | - None, | 17209 | + u, |
| 17132 | - fctx, | 17210 | + cpx, |
| 17133 | - )?; | 17211 | + cpy, |
| 17134 | - u_grid = ug; | 17212 | + Pred::Inline(&pred_u, cside), |
| 17135 | - 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 | + } | ||
| 17136 | } | 17237 | } |
| 17137 | 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); | ||
| 17138 | if leaves.is_some() { | 17250 | if leaves.is_some() { |
| 17139 | - neighbours.record_split_luma_rect_mi( | 17251 | + if chroma_split_units { |
| 17140 | - (mi_r, mi_c), | 17252 | + neighbours.record_split_luma_rect_mi_modes((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED); |
| 17141 | - bw, | 17253 | + } else { |
| 17142 | - bh, | 17254 | + neighbours.record_split_luma_rect_mi( |
| 17143 | - DC_PRED, | 17255 | + (mi_r, mi_c), |
| 17144 | - DC_PRED, | 17256 | + bw, |
| 17145 | - [&u_grid, &v_grid], | 17257 | + bh, |
| 17146 | - ); | 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); | ||
| 17147 | } else { | 17265 | } else { |
| 17148 | neighbours.record_rect_mi( | 17266 | neighbours.record_rect_mi( |
| 17149 | (mi_r, mi_c), | 17267 | (mi_r, mi_c), |
| @@ -17179,6 +17297,111 @@ fn decode_intrabc_owned_rect( | |||
| 17179 | Ok(()) | 17297 | Ok(()) |
| 17180 | } | 17298 | } |
| 17181 | 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 | + | ||
| 17182 | fn predict_intrabc_window( | 17405 | fn predict_intrabc_window( |
| 17183 | plane: &PlaneBuf<'_>, | 17406 | plane: &PlaneBuf<'_>, |
| 17184 | px: usize, | 17407 | px: usize, |
crates/ec-av1/src/stream.rsmodified+113 -30
| @@ -48468,23 +48468,50 @@ pub(crate) mod tests { | |||
| 48468 | } | 48468 | } |
| 48469 | 48469 | ||
| 48470 | /// lane-av1chromarect: the 128-root intra-BC HORZ/VERT strip's chroma | 48470 | /// lane-av1chromarect: the 128-root intra-BC HORZ/VERT strip's chroma |
| 48471 | - /// plane block, on the 4:4:4 LOSSY witness that reaches | 48471 | + /// plane block, on the 4:4:4 LOSSY witness `fixtures/r512.obu` that |
| 48472 | - /// `decode_intrabc_owned_rect`. | 48472 | + /// reaches `decode_intrabc_owned_rect` five times. |
| 48473 | /// | 48473 | /// |
| 48474 | - /// The extent is the ss-derived one (`bw >> ss_x` by `bh >> ss_y`, | 48474 | + /// The extent is the ss-derived one (`bw >> ss_x` by `bh >> ss_y`; |
| 48475 | /// `av1_get_max_uv_txsize` = `ss_size_lookup[bsize]`, blockd.h:1372), and | 48475 | /// `av1_get_max_uv_txsize` = `ss_size_lookup[bsize]`, blockd.h:1372), and |
| 48476 | - /// the witness is pinned at the size that shape forces -- a 4:4:4 32x64 | 48476 | + /// the plane block is walked by `get_vartx_max_txsize` steps -- a 4:4:4 |
| 48477 | - /// luma block's chroma plane block is 32x64. **This gate asserts the | 48477 | + /// 32x64 luma block's chroma plane block is 32x64, which libaom codes as |
| 48478 | - /// refusal, on purpose.** It exists so the day the missing arm lands the | 48478 | + /// TWO `TX_32X32` units, not as one 32x64 transform. |
| 48479 | - /// gate goes RED and the assertion has to be rewritten as the | 48479 | + /// |
| 48480 | - /// pixel-exactness check -- a witness with no gate is a pin, and a pin | 48480 | + /// This gate WAS the refusal assertion "a rectangular inter chroma |
| 48481 | - /// with no governing refusal is a defect nobody is looking at. | 48481 | + /// transform unit whose shape has no coefficient table set here", put |
| 48482 | - #[test] | 48482 | + /// there one commit earlier so that the day the arm landed it would go |
| 48483 | - fn a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_coefficient_set() { | 48483 | + /// RED and force this rewrite. The refusal string is GONE from the |
| 48484 | + /// witness's decode because nothing reaches it any more, not because it | ||
| 48485 | + /// was deleted: `rect_inter_chroma_set` still refuses (32, 64) and the | ||
| 48486 | + /// string is still in the source, it is just not on this path any more. | ||
| 48487 | + /// | ||
| 48488 | + /// The assertion is a per-(frame, plane) EXACT PREFIX against the | ||
| 48489 | + /// instrumented aomdec, the same shape as the sibling | ||
| 48490 | + /// `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`. The | ||
| 48491 | + /// floors are MEASURED, and each one only grows: | ||
| 48492 | + /// | ||
| 48493 | + /// * luma is byte-exact on ALL THREE frames (786432/786432 samples). | ||
| 48494 | + /// Before the fix frame 0 luma was 166229 samples wrong from 65728 -- | ||
| 48495 | + /// the halving's chroma misread desynced the tile. | ||
| 48496 | + /// * frame 2 is byte-exact on all three planes. Before the fix it was | ||
| 48497 | + /// 9216 U + 8192 V wrong. | ||
| 48498 | + /// * frames 0 and 1 carry an OPEN chroma fork at a DIFFERENT site (see | ||
| 48499 | + /// lanes/av1chromarect.report.md); the floors below are the exact | ||
| 48500 | + /// prefixes, not a claim that the tail is right. | ||
| 48501 | + #[test] | ||
| 48502 | + fn a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes() { | ||
| 48484 | const NAME: &str = | 48503 | const NAME: &str = |
| 48485 | - "a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_coefficient_set"; | 48504 | + "a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes"; |
| 48486 | const FILE: &str = "r512.obu"; | 48505 | const FILE: &str = "r512.obu"; |
| 48487 | const LEN: usize = 6948; | 48506 | const LEN: usize = 6948; |
| 48507 | + /// 512x512 8-bit 4:4:4, one plane. | ||
| 48508 | + const PLANE: usize = 512 * 512; | ||
| 48509 | + /// First differing sample per (frame, plane), decode order. | ||
| 48510 | + const EXACT_PREFIX: [[usize; 3]; 3] = [ | ||
| 48511 | + [PLANE, 229728, 229728], | ||
| 48512 | + [PLANE, 65704, 65704], | ||
| 48513 | + [PLANE, PLANE, PLANE], | ||
| 48514 | + ]; | ||
| 48488 | let path = | 48515 | let path = |
| 48489 | std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}")); | 48516 | std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}")); |
| 48490 | let stream = std::fs::read(&path) | 48517 | let stream = std::fs::read(&path) |
| @@ -48494,28 +48521,84 @@ pub(crate) mod tests { | |||
| 48494 | 48521 | ||
| 48495 | let _guard = lock_gate_counters(); | 48522 | let _guard = lock_gate_counters(); |
| 48496 | reset_ibc_owned_rect_chroma_footprint_444_hits(); | 48523 | reset_ibc_owned_rect_chroma_footprint_444_hits(); |
| 48497 | - let err = decode_stream(&stream).err().unwrap_or_else(|| { | 48524 | + // The refusal this gate used to assert must NOT be what happens now. |
| 48498 | - panic!( | 48525 | + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); |
| 48499 | - "{NAME}: the witness DECODED -- the extent is not the ss-derived one any \ | 48526 | + let _ = std::fs::remove_dir_all(&dir); |
| 48500 | - more, so this gate is no longer measuring what it names" | 48527 | + std::fs::create_dir_all(&dir).expect("scratch dir"); |
| 48501 | - ) | 48528 | + let obu = dir.join("in.obu"); |
| 48502 | - }); | 48529 | + std::fs::write(&obu, &stream).expect("writing the stream"); |
| 48503 | - let msg = err.to_string(); | 48530 | + let aom_prefix = dir.join("aom"); |
| 48531 | + let out = Command::new(aomdec_path()) | ||
| 48532 | + .args(["--codec=av1", "-o"]) | ||
| 48533 | + .arg(dir.join("out.y4m")) | ||
| 48534 | + .arg(&obu) | ||
| 48535 | + .env("EC_AV1_FINAL_DUMP", &aom_prefix) | ||
| 48536 | + .stdin(Stdio::null()) | ||
| 48537 | + .stdout(Stdio::piped()) | ||
| 48538 | + .stderr(Stdio::piped()) | ||
| 48539 | + .output() | ||
| 48540 | + .expect("aomdec failed to run"); | ||
| 48504 | assert!( | 48541 | assert!( |
| 48505 | - msg.contains( | 48542 | + out.status.success(), |
| 48506 | - "a rectangular inter chroma transform unit whose shape has no coefficient table \ | 48543 | + "{NAME}: the oracle aomdec refused the stream: {}", |
| 48507 | - set here" | 48544 | + String::from_utf8_lossy(&out.stderr) |
| 48508 | - ), | ||
| 48509 | - "{NAME}: expected the missing-rect-chroma-set refusal, got: {msg}" | ||
| 48510 | ); | 48545 | ); |
| 48546 | + let ours_prefix = dir.join("ours"); | ||
| 48547 | + set_final_dump_prefix(Some(ours_prefix.display().to_string())); | ||
| 48548 | + let decoded = decode_stream(&stream); | ||
| 48549 | + set_final_dump_prefix(None); | ||
| 48550 | + if let Err(e) = decoded { | ||
| 48551 | + panic!( | ||
| 48552 | + "{NAME}: this decoder refused the witness: {e} -- the chroma plane block is \ | ||
| 48553 | + sized ss-wide and walked in `get_vartx_max_txsize` units, so the 4:4:4 32x64 \ | ||
| 48554 | + plane block is two TX_32X32 units, NOT the rect unit the refusal named" | ||
| 48555 | + ); | ||
| 48556 | + } | ||
| 48511 | let hits = ibc_owned_rect_chroma_footprint_444_hits(); | 48557 | let hits = ibc_owned_rect_chroma_footprint_444_hits(); |
| 48512 | - // Exactly 1, not 5: the decode stops AT the first 4:4:4 strip, so this | ||
| 48513 | - // counts the strips that reached the corrected extent before the | ||
| 48514 | - // refusal ended the stream. The pixel-exactness gate that replaces | ||
| 48515 | - // this one sees all five. | ||
| 48516 | assert_eq!( | 48558 | assert_eq!( |
| 48517 | - hits, 1, | 48559 | + hits, 5, |
| 48518 | - "{NAME}: {hits} 128-root intra-BC strip(s) sized at 4:4:4 before the refusal, not 1" | 48560 | + "{NAME}: {hits} 128-root intra-BC strip(s) sized at 4:4:4, not 5 -- the witness \ |
| 48561 | + stopped exercising the arm" | ||
| 48519 | ); | 48562 | ); |
| 48563 | + assert!( | ||
| 48564 | + !std::fs::read(format!("{}.f0", ours_prefix.display())) | ||
| 48565 | + .unwrap_or_default() | ||
| 48566 | + .is_empty(), | ||
| 48567 | + "{NAME}: our decoder wrote no frame" | ||
| 48568 | + ); | ||
| 48569 | + for f in 0..3 { | ||
| 48570 | + let aom_dump = std::fs::read(format!("{}.f{f}", aom_prefix.display())) | ||
| 48571 | + .unwrap_or_else(|e| panic!("{NAME}: oracle dump f{f} missing: {e}")); | ||
| 48572 | + let our_dump = std::fs::read(format!("{}.f{f}", ours_prefix.display())) | ||
| 48573 | + .unwrap_or_else(|e| panic!("{NAME}: our dump f{f} missing: {e}")); | ||
| 48574 | + assert_eq!( | ||
| 48575 | + our_dump.len(), | ||
| 48576 | + 3 * PLANE, | ||
| 48577 | + "{NAME}: frame {f} is not 8-bit 4:4:4 512x512" | ||
| 48578 | + ); | ||
| 48579 | + assert_eq!( | ||
| 48580 | + our_dump.len(), | ||
| 48581 | + aom_dump.len(), | ||
| 48582 | + "{NAME}: frame {f} length differs" | ||
| 48583 | + ); | ||
| 48584 | + for (plane, name) in [(0usize, "Y"), (1, "U"), (2, "V")] { | ||
| 48585 | + let at = plane * PLANE; | ||
| 48586 | + let floor = EXACT_PREFIX[f][plane]; | ||
| 48587 | + if our_dump[at..at + floor] == aom_dump[at..at + floor] { | ||
| 48588 | + continue; | ||
| 48589 | + } | ||
| 48590 | + let first = (0..floor) | ||
| 48591 | + .find(|&s| our_dump[at + s] != aom_dump[at + s]) | ||
| 48592 | + .unwrap_or(floor); | ||
| 48593 | + panic!( | ||
| 48594 | + "{NAME}: frame {f} plane {name} diverges from the oracle at sample {first} \ | ||
| 48595 | + of {PLANE} (x={}, y={}) -- the exact prefix this gate pins is {floor} and \ | ||
| 48596 | + it only grows", | ||
| 48597 | + first % 512, | ||
| 48598 | + first / 512 | ||
| 48599 | + ); | ||
| 48600 | + } | ||
| 48601 | + } | ||
| 48602 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 48520 | } | 48603 | } |
| 48521 | } | 48604 | } |
lanes/av1chromarect.report.mdadded+387 -0
| @@ -0,0 +1,387 @@ | |||
| 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:45606`, body ends at `46434`. It carries a | ||
| 316 | +`chroma_444` branch set and **zero** `chroma_422` mentions inside the body | ||
| 317 | +(`awk 'NR>=45606 && NR<=46400' | grep -c chroma_422` → `0`; the two | ||
| 318 | +`chroma_422` mentions at 45406/45418 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 | +| 46095 | `let chroma_444 = ss_x == 0 && ss_y == 0` | `false` at (1,0) | | ||
| 326 | +| 46098 | `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 | +| 46100-46105 | `reach_c` = the piece's own rect reach at 4:4:4 | `group_reach` (a 8x8 group reach) | | ||
| 328 | +| 46107 | `band_r, band_c` from `lmi` | from `r, c` (the group) | | ||
| 329 | +| 46113-46114 | `smooth_uv_neighbour` sampled at `lmi` | sampled at `gr, gc` | | ||
| 330 | +| 46127 | `record_uv_mode_mi(lmi, w_mi, h_mi)` | `record_uv_mode_mi(gr, gc, 2, 2)` — a 2x2 group stamp | | ||
| 331 | +| 46134 | `cfl_src_rect(px, py, bw, bh)` | not taken | | ||
| 332 | +| 46146, 46210 | the non-square 4:4:4 unit shape arms | not taken | | ||
| 333 | +| 46352 | chroma per-unit gather at `lmi` with a 4-px step | at `group_mi` with an 8-px step | | ||
| 334 | + | ||
| 335 | +The shape the missing arm would have to be: at 4:2:2 `ss_size_lookup` maps an | ||
| 336 | +8x4 block to `BLOCK_INVALID` (common_data.c:38) and no `TX_4X8` chroma unit | ||
| 337 | +exists, so a 4:2:2 sub-8 leaf's chroma is coded CHUNKED, exactly the | ||
| 338 | +`invalid_ss_plane` case `read_inter_rect_chroma` already special-cases | ||
| 339 | +(decode.rs:29328, `(4, 32)` at ss (1,0) → `(4, 8)` units). | ||
| 340 | + | ||
| 341 | +**Caller set — exactly two sites, and BOTH are already 4:2:2-aware:** | ||
| 342 | + | ||
| 343 | +1. `decode.rs:44736` — the `BLOCK_4X4` leaf of the sub-8x8 intra-in-inter split | ||
| 344 | + arm. It passes | ||
| 345 | + `has_chroma = chroma_444 || (cmi & 1 == 1 && chroma_422) || i == 3` | ||
| 346 | + (libaom's `is_chroma_reference`, `av1_common_int.h:1459`: BOTH odd-column | ||
| 347 | + pieces at 4:2:2). | ||
| 348 | +2. `decode.rs:46622` — the `(bw, bh)` 8x8/4x8/8x4 piece. It passes | ||
| 349 | + `has_chroma = piece_is_chroma_ref(i)`, and `piece_is_chroma_ref` | ||
| 350 | + (decode.rs:46546) has an explicit `else if chroma_422 { !vert || ((gc + i) & 1) == 1 }` | ||
| 351 | + branch. | ||
| 352 | + | ||
| 353 | +So the callers compute the 4:2:2 chroma-reference rule correctly and the leaf | ||
| 354 | +body has no geometry arm to honour it. This is a latent gap, not a live bug: the | ||
| 355 | +crate refuses 4:2:2 by name at the sequence header | ||
| 356 | +(`"a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder | ||
| 357 | +decodes 4:2:0 and 4:4:4; 4:2:2 is not ported"`, `refusal_inventory.rs:119`, gate | ||
| 358 | +`a_non_420_subsampled_sequence_header_is_refused_by_name`, stream.rs:2258), so | ||
| 359 | +`chroma_422` is always `false` when this function runs. Not implemented here, by | ||
| 360 | +charter. | ||
| 361 | + | ||
| 362 | +## 8. Scope boundaries, stated | ||
| 363 | + | ||
| 364 | +* `cfl_ac_q3_at` (decode.rs:20179, `let (cw, ch) = (bw / 2, bh / 2);`, no | ||
| 365 | + `fctx`) — **untouched, another lane owns it.** §3 measures that the witness | ||
| 366 | + codes no CfL, so it is not this witness's residual either. | ||
| 367 | +* `suppress_internal_lf_edges` — **not re-fixed.** C1 (wave 3d, on this base) | ||
| 368 | + already threads `fctx` into it and computes `((w_mi * MI) >> ss_x(fctx)).max(4)`. | ||
| 369 | + The earlier "format-blind" claim is retracted upstream; there is nothing here | ||
| 370 | + to change. | ||
| 371 | +* `decode_intrabc_rect` (the non-`owned` sibling, decode.rs:13646) reads its | ||
| 372 | + chroma with the same single-unit `rect_inter_chroma_set(cw, ch)`. It is | ||
| 373 | + ss-correct (lane-ibc444c) and its pinned 4:4:4 witness is 8x16, one unit, so | ||
| 374 | + the multi-unit case is latent there too. I did not widen the fix: this lane's | ||
| 375 | + witness and its gate do not reach it, and a change there would be unmeasured. | ||
| 376 | + Flagged for whoever takes the next 4:4:4 rect cell. | ||
| 377 | + | ||
| 378 | +## 9. What I could not do | ||
| 379 | + | ||
| 380 | +1. The f0/f1 chroma residue of §3 is not identified to a site. 79969 wrong | ||
| 381 | + samples remain out of 2359296 (3.4 %); luma is exact everywhere. | ||
| 382 | +2. The 128-root multi-unit *record* difference in §2 is derived from libaom's | ||
| 383 | + per-unit above/left context update and validated by the gate going from | ||
| 384 | + 640727 wrong samples to 79969 with luma exact; I did not diff our per-unit | ||
| 385 | + above/left contexts against the oracle's rung-by-rung. | ||
| 386 | +3. No heavy encodes were run: the witness was taken from the pin, and the gate | ||
| 387 | + families are fixture-driven. No server fleet run was requested or consumed. | ||