forge
Explore
Log in

Don't you dare go Hollow

A chroma deblock edge must read the group's BOTTOM/RIGHT mi

Browse files at this commit

58b009bb899650af1bbdab9d581dc768acc474fbAhmet Kaan GümüşParent: eb63f3e
  • fix
    • a chroma deblock edge must read the group's BOTTOM/RIGHT mi
Show full message
fix(av1): a chroma deblock edge must read the group's BOTTOM/RIGHT mi

`set_lpf_parameters` (libaom av1_loopfilter.c:245) indexes the mi grid for a
CHROMA edge at `scale | ((coord << scale) >> MI_SIZE_LOG2)` -- the bottom/right
mi of the co-located 8x8 luma group, the same cell that donates the group's
chroma prediction -- steps to the previous cell by `1 << ss` mi, and prices
`pu_edge` by testing the edge coordinate against the block size in the FILTERED
plane's own pixels (chroma bottoms out at 4 px).

This decoder dropped the `| 1`, stepped by one mi, and compared mi origins.
All three are invisible while every block is 8x8 or larger -- all four mi of a
group carry the same tx size, ref frame, skip flag and delta_lf -- and wrong
the moment cpu-used=4 splits a group into 4x4 luma blocks: the top-left mi's
filter level 12 fired filter4 on a U edge where the bottom/right block's level
8 leaves it alone. Class `context-read-from-one-cell`.

Measured on fixtures/superres_alltools_sb128_320x180.obu against the
instrumented libaom: post-deblock (EC_AV1_POSTDEBLOCK_DUMP) 1 wrong U sample in
frame 2 growing to 137 U + 131 V by frame 9 -> 0 in all 10 frames, and the
final output goes from 280 U + 331 V (max 9) to byte-exact vs ffmpeg. The
prediction path was never at fault: every prefilt frame was already exact, and
the frame-4 prefilt drift was the deblocked reference chain.

`a_superres_all_tools_sb128_stream_decodes_pixel_exact` is un-ignored.
crates/ec-av1/src/decode.rsmodified+45 -6
@@ -4888,6 +4888,11 @@ struct Neighbours {
4888 /// skipped inter blocks (lane-mergefix r4). Written by4888 /// skipped inter blocks (lane-mergefix r4). Written by
4889 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.4889 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.
4890 blk_org_grid: Vec<[u16; 2]>,4890 blk_org_grid: Vec<[u16; 2]>,
4891+ /// Per-4x4-mi `(width, height)` in mi units of the coded block covering
4892+ /// that cell -- the other half of `pu_edge`: libaom tests the edge
4893+ /// coordinate against the block's size in the FILTERED plane's own
4894+ /// pixels, which for chroma is `max(luma_dim / 2, 4)` (lane-t900 r30b).
4895+ blk_dim_grid: Vec<[u8; 2]>,
4891 skip_grid_cols_mi: usize,4896 skip_grid_cols_mi: usize,
4892 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder4897 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder
4893 /// never splits a coded block's transform below its own size (round 2:4898 /// never splits a coded block's transform below its own size (round 2:
@@ -5011,6 +5016,7 @@ impl Neighbours {
5011 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],5016 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
5012 skip_written: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],5017 skip_written: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
5013 blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)],5018 blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)],
5019+ blk_dim_grid: vec![[1u8; 2]; cols * (SUB / MI) * rows * (SUB / MI)],
5014 skip_grid_cols_mi: cols * (SUB / MI),5020 skip_grid_cols_mi: cols * (SUB / MI),
5015 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],5021 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
5016 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],5022 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -5454,6 +5460,9 @@ impl Neighbours {
5454 if let Some(org) = self.blk_org_grid.get_mut(idx) {5460 if let Some(org) = self.blk_org_grid.get_mut(idx) {
5455 *org = [mi_r as u16, mi_c as u16];5461 *org = [mi_r as u16, mi_c as u16];
5456 }5462 }
5463+ if let Some(dim) = self.blk_dim_grid.get_mut(idx) {
5464+ *dim = [w_mi as u8, h_mi as u8];
5465+ }
5457 }5466 }
5458 }5467 }
5459 }5468 }
@@ -14640,8 +14649,19 @@ fn apply_deblock(
14640 /// in -- `Neighbours::tx_grid`/`ref_grid` are always indexed at the luma14649 /// in -- `Neighbours::tx_grid`/`ref_grid` are always indexed at the luma
14641 /// 4x4-mi grain, even when `coord` is a chroma coordinate (2 chroma px per14650 /// 4x4-mi grain, even when `coord` is a chroma coordinate (2 chroma px per
14642 /// mi unit under this decoder's assumed 4:2:0 subsampling).14651 /// mi unit under this decoder's assumed 4:2:0 subsampling).
14652+///
14653+/// lane-t900 r30b: the chroma arm ORs in the subsampling, exactly as
14654+/// `set_lpf_parameters` does (`av1_loopfilter.c:245`, `mi_col = scale_horz |
14655+/// ((x << scale_horz) >> MI_SIZE_LOG2)`) -- "for sub8x8 block, chroma
14656+/// prediction mode is obtained from the bottom/right mi structure of the
14657+/// co-located 8x8 luma block, so for chroma plane both mi_row and mi_col
14658+/// should be odd". Dropping that `| 1` read the group's TOP-LEFT mi, which
14659+/// is the same cell for every block 8x8 and larger and a DIFFERENT coded
14660+/// block (different tx size, ref frame, skip flag and delta_lf) as soon as
14661+/// the group is split into 4x4 luma blocks (class
14662+/// `context-read-from-one-cell`).
14643 fn plane_to_mi(chroma: bool, coord: usize) -> usize {14663 fn plane_to_mi(chroma: bool, coord: usize) -> usize {
14644- if chroma { coord / 2 } else { coord / 4 }14664+ if chroma { (coord / 2) | 1 } else { coord / 4 }
14645 }14665 }
14646 14666
14647 /// This plane's own transform width in pixels at the covering block, spec14667 /// This plane's own transform width in pixels at the covering block, spec
@@ -16192,10 +16212,15 @@ fn edge_params(
16192 return None;16212 return None;
16193 }16213 }
16194 let cur_ref = n.ref_grid[mi_r * n.skip_grid_cols_mi + mi_c];16214 let cur_ref = n.ref_grid[mi_r * n.skip_grid_cols_mi + mi_c];
16215+ // `mode_step` (`set_lpf_parameters`): one mi for luma, `1 << ss` for
16216+ // chroma -- the previous cell must keep the odd parity `plane_to_mi`
16217+ // just established, i.e. the bottom/right mi of the PREVIOUS 8x8 luma
16218+ // group, not the other half of this one.
16219+ let step = if chroma { 2 } else { 1 };
16195 let (pv_mi_r, pv_mi_c) = if dir == 0 {16220 let (pv_mi_r, pv_mi_c) = if dir == 0 {
16196- (mi_r, mi_c - 1)16221+ (mi_r, mi_c - step)
16197 } else {16222 } else {
16198- (mi_r - 1, mi_c)16223+ (mi_r - step, mi_c)
16199 };16224 };
16200 let pv_tx = if dir == 0 {16225 let pv_tx = if dir == 0 {
16201 tx_px_at(n, chroma, pv_mi_r, pv_mi_c)16226 tx_px_at(n, chroma, pv_mi_r, pv_mi_c)
@@ -16214,11 +16239,25 @@ fn edge_params(
16214 // is always its own full size", which var-tx broke) had us filtering an16239 // is always its own full size", which var-tx broke) had us filtering an
16215 // interior 8-px lattice the reference never touches: on the pinned 192x6816240 // interior 8-px lattice the reference never touches: on the pinned 192x68
16216 // inter stream frame 1 went from 7244 wrong post-deblock luma px to 0.16241 // inter stream frame 1 went from 7244 wrong post-deblock luma px to 0.
16242+ // libaom prices `pu_edge` in the PLANE's own pixels against the plane's
16243+ // block size (`!(coord & (block_size_wide[get_plane_block_size(bsize)] -
16244+ // 1))`), which for chroma bottoms out at 4 px: every 4-aligned chroma
16245+ // edge of a sub-8x8 group is a prediction edge, even though the group's
16246+ // bottom/right mi does not start there. Comparing mi origins instead is
16247+ // the same test only while the block's own origin is aligned to its
16248+ // size, which a 4x4 luma block read at the `| 1` mi is not.
16217 let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c];16249 let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c];
16218- let pu_edge = if dir == 0 {16250+ let cur_dim = n.blk_dim_grid[mi_r * n.skip_grid_cols_mi + mi_c];
16219- mi_c == usize::from(cur_org[1])16251+ let (org_px, dim_mi) = if dir == 0 {
16252+ (usize::from(cur_org[1]), usize::from(cur_dim[0]))
16253+ } else {
16254+ (usize::from(cur_org[0]), usize::from(cur_dim[1]))
16255+ };
16256+ let pu_edge = if chroma {
16257+ let plane_dim = (dim_mi * MI / 2).max(4);
16258+ (if dir == 0 { x0 } else { y0 }) % plane_dim == 0
16220 } else {16259 } else {
16221- mi_r == usize::from(cur_org[0])16260+ plane_to_mi(false, if dir == 0 { x0 } else { y0 }) == org_px
16222 };16261 };
16223 if !pu_edge16262 if !pu_edge
16224 && cur_ref != 016263 && cur_ref != 0
crates/ec-av1/src/stream.rsmodified+25 -16
@@ -4850,25 +4850,34 @@ mod tests {
4850 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");4850 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");
4851 }4851 }
4852 4852
4853- /// lane-t900 r29 RESIDUAL, ignored: `fixtures/superres_alltools_sb128_320x180.obu`4853+ /// lane-t900 r30b: `fixtures/superres_alltools_sb128_320x180.obu` is 10
4854- /// is 10 frames of `--cpu-used=4 --sb-size=128 --superres-mode=14854+ /// frames of `--cpu-used=4 --sb-size=128 --superres-mode=1
4855 /// --superres-denominator=12 --cq-level=32` with every tool aomenc turns4855 /// --superres-denominator=12 --cq-level=32` with every tool aomenc turns
4856- /// on by default (CDEF, loop restoration, OBMC, compound, warp).4856+ /// on by default (CDEF, loop restoration, OBMC, compound, warp) -- the
4857+ /// first stream here that deblocks CHROMA across a group of 4x4 luma
4858+ /// blocks.
4857 ///4859 ///
4858- /// FIRST BAD (measured 2026-09-04, after the r29 upscale-before-LR fix):4860+ /// The defect it pins (fixed at this commit, `decode.rs`'s
4859- /// display frame 2, plane U, (x=88, y=21), delta 1; the mismatch is4861+ /// `plane_to_mi`/`edge_params`): `set_lpf_parameters`
4860- /// CHROMA ONLY and grows with the reference chain (frame 9: 280 U + 3314862+ /// (`av1_loopfilter.c:245`) indexes the mi grid for a CHROMA edge at
4861- /// V samples, max 9). LUMA IS EXACT IN ALL 10 FRAMES. It is NOT the4863+ /// `scale | ((coord << scale) >> MI_SIZE_LOG2)` -- the BOTTOM/RIGHT mi of
4862- /// filter chain: re-encoding the same recipe with `--enable-cdef=04864+ /// the co-located 8x8 luma group, the same cell that donates the group's
4863- /// --enable-restoration=0` still mismatches (359 samples, max 5, first4865+ /// chroma prediction. This decoder dropped that `| 1` and read the
4864- /// bad display frame 4 plane V (115, 31)), and the r29 fix took the4866+ /// group's top-left mi, stepped to the previous cell by one mi instead of
4865- /// filters-on numbers from 37315 samples/max 171 down to 1620/max 11.4867+ /// `1 << ss`, and priced `pu_edge` by comparing mi origins rather than
4866- /// So the residual is a scaled-reference CHROMA prediction defect at4868+ /// the edge coordinate against the block size in the FILTERED plane's own
4867- /// sb128/cpu-used=4 block shapes, not superres filtering -- next round's4869+ /// pixels (chroma bottoms out at 4). All three are invisible while every
4868- /// ladder starts at `EC_AV1_PREFILT_DUMP16` on decode-order frame 4 of4870+ /// block is 8x8 or larger (all four mi of a group carry the same tx size,
4869- /// the filters-off arm.4871+ /// ref frame, skip flag and delta_lf) and wrong the moment cpu-used=4
4872+ /// splits a group into 4x4 blocks: on this stream one U sample of frame 2
4873+ /// took a filter level of 12 where libaom's neighbouring 4x4 block gives
4874+ /// 8, and the error compounded through the reference chain to 280 U + 331
4875+ /// V samples (max 9) by frame 9. Class `context-read-from-one-cell`.
4876+ ///
4877+ /// Post-deblock, this stream is now byte-exact against the instrumented
4878+ /// libaom (`EC_AV1_POSTDEBLOCK_DUMP`) in all 10 frames, and the final
4879+ /// output matches ffmpeg's.
4870 #[test]4880 #[test]
4871- #[ignore = "lane-t900 r29 residual: scaled-reference chroma prediction, frame 2 U (88,21)"]
4872 fn a_superres_all_tools_sb128_stream_decodes_pixel_exact() {4881 fn a_superres_all_tools_sb128_stream_decodes_pixel_exact() {
4873 const NAME: &str = "a_superres_all_tools_sb128_stream_decodes_pixel_exact";4882 const NAME: &str = "a_superres_all_tools_sb128_stream_decodes_pixel_exact";
4874 let _gate_lock = lock_gate_counters();4883 let _gate_lock = lock_gate_counters();