Merge branch 'lane-t900' (4d424ef3): chroma deblock edges index the mode-info grid at the bottom/right mi of the 8x8 luma group with a 2-mi step and plane-pixel pu_edge (libaom set_lpf_parameters); superres all-tools 128-SB stream byte-exact
Browse files at this commit2 changed files +70 -22
- crates/ec-av1/src/decode.rs +45 -6
- crates/ec-av1/src/stream.rs +25 -16
crates/ec-av1/src/decode.rsmodified+45 -6
| @@ -4888,6 +4888,11 @@ struct Neighbours { | ||
| 4888 | 4888 | /// skipped inter blocks (lane-mergefix r4). Written by |
| 4889 | 4889 | /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin. |
| 4890 | 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 | 4896 | skip_grid_cols_mi: usize, |
| 4892 | 4897 | /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder |
| 4893 | 4898 | /// never splits a coded block's transform below its own size (round 2: |
| @@ -5011,6 +5016,7 @@ impl Neighbours { | ||
| 5011 | 5016 | skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], |
| 5012 | 5017 | skip_written: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], |
| 5013 | 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 | 5020 | skip_grid_cols_mi: cols * (SUB / MI), |
| 5015 | 5021 | tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 5016 | 5022 | tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| @@ -5454,6 +5460,9 @@ impl Neighbours { | ||
| 5454 | 5460 | if let Some(org) = self.blk_org_grid.get_mut(idx) { |
| 5455 | 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 | 14649 | /// in -- `Neighbours::tx_grid`/`ref_grid` are always indexed at the luma |
| 14641 | 14650 | /// 4x4-mi grain, even when `coord` is a chroma coordinate (2 chroma px per |
| 14642 | 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 | 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 | 14667 | /// This plane's own transform width in pixels at the covering block, spec |
| @@ -16192,10 +16212,15 @@ fn edge_params( | ||
| 16192 | 16212 | return None; |
| 16193 | 16213 | } |
| 16194 | 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 | 16220 | let (pv_mi_r, pv_mi_c) = if dir == 0 { |
| 16196 | - (mi_r, mi_c - 1) | |
| 16221 | + (mi_r, mi_c - step) | |
| 16197 | 16222 | } else { |
| 16198 | - (mi_r - 1, mi_c) | |
| 16223 | + (mi_r - step, mi_c) | |
| 16199 | 16224 | }; |
| 16200 | 16225 | let pv_tx = if dir == 0 { |
| 16201 | 16226 | tx_px_at(n, chroma, pv_mi_r, pv_mi_c) |
| @@ -16214,11 +16239,25 @@ fn edge_params( | ||
| 16214 | 16239 | // is always its own full size", which var-tx broke) had us filtering an |
| 16215 | 16240 | // interior 8-px lattice the reference never touches: on the pinned 192x68 |
| 16216 | 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 | 16249 | let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c]; |
| 16218 | - let pu_edge = if dir == 0 { | |
| 16219 | - mi_c == usize::from(cur_org[1]) | |
| 16250 | + let cur_dim = n.blk_dim_grid[mi_r * n.skip_grid_cols_mi + mi_c]; | |
| 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 | 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 | 16262 | if !pu_edge |
| 16224 | 16263 | && cur_ref != 0 |
crates/ec-av1/src/stream.rsmodified+25 -16
| @@ -4850,25 +4850,34 @@ mod tests { | ||
| 4850 | 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` | |
| 4854 | - /// is 10 frames of `--cpu-used=4 --sb-size=128 --superres-mode=1 | |
| 4853 | + /// lane-t900 r30b: `fixtures/superres_alltools_sb128_320x180.obu` is 10 | |
| 4854 | + /// frames of `--cpu-used=4 --sb-size=128 --superres-mode=1 | |
| 4855 | 4855 | /// --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): | |
| 4859 | - /// display frame 2, plane U, (x=88, y=21), delta 1; the mismatch is | |
| 4860 | - /// CHROMA ONLY and grows with the reference chain (frame 9: 280 U + 331 | |
| 4861 | - /// V samples, max 9). LUMA IS EXACT IN ALL 10 FRAMES. It is NOT the | |
| 4862 | - /// filter chain: re-encoding the same recipe with `--enable-cdef=0 | |
| 4863 | - /// --enable-restoration=0` still mismatches (359 samples, max 5, first | |
| 4864 | - /// bad display frame 4 plane V (115, 31)), and the r29 fix took the | |
| 4865 | - /// filters-on numbers from 37315 samples/max 171 down to 1620/max 11. | |
| 4866 | - /// So the residual is a scaled-reference CHROMA prediction defect at | |
| 4867 | - /// sb128/cpu-used=4 block shapes, not superres filtering -- next round's | |
| 4868 | - /// ladder starts at `EC_AV1_PREFILT_DUMP16` on decode-order frame 4 of | |
| 4869 | - /// the filters-off arm. | |
| 4860 | + /// The defect it pins (fixed at this commit, `decode.rs`'s | |
| 4861 | + /// `plane_to_mi`/`edge_params`): `set_lpf_parameters` | |
| 4862 | + /// (`av1_loopfilter.c:245`) indexes the mi grid for a CHROMA edge at | |
| 4863 | + /// `scale | ((coord << scale) >> MI_SIZE_LOG2)` -- the BOTTOM/RIGHT mi of | |
| 4864 | + /// the co-located 8x8 luma group, the same cell that donates the group's | |
| 4865 | + /// chroma prediction. This decoder dropped that `| 1` and read the | |
| 4866 | + /// group's top-left mi, stepped to the previous cell by one mi instead of | |
| 4867 | + /// `1 << ss`, and priced `pu_edge` by comparing mi origins rather than | |
| 4868 | + /// the edge coordinate against the block size in the FILTERED plane's own | |
| 4869 | + /// pixels (chroma bottoms out at 4). All three are invisible while every | |
| 4870 | + /// block is 8x8 or larger (all four mi of a group carry the same tx size, | |
| 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 | 4880 | #[test] |
| 4871 | - #[ignore = "lane-t900 r29 residual: scaled-reference chroma prediction, frame 2 U (88,21)"] | |
| 4872 | 4881 | fn a_superres_all_tools_sb128_stream_decodes_pixel_exact() { |
| 4873 | 4882 | const NAME: &str = "a_superres_all_tools_sb128_stream_decodes_pixel_exact"; |
| 4874 | 4883 | let _gate_lock = lock_gate_counters(); |