OBMC read a 1:4-strip neighbour's interp filter from the wrong mi
Browse files at this commit7285f0396ebc05562f4f686e04c404615e71b755Parent: c249957- fix
- OBMC read a 1:4-strip neighbour's interp filter from the wrong mi
2 changed files +168 -16
- crates/ec-av1/src/decode.rs +89 -16
- crates/ec-av1/src/stream.rs +79 -0
crates/ec-av1/src/decode.rsmodified+89 -16
| @@ -2185,6 +2185,20 @@ pub(crate) fn obmc_rect_leaf_hits() -> usize { | ||
| 2185 | 2185 | OBMC_RECT_LEAF_HITS.with(|c| c.get()) |
| 2186 | 2186 | } |
| 2187 | 2187 | |
| 2188 | +// lane-obmcrec r1: how many OBMC neighbours were taken from the SECOND half of | |
| 2189 | +// a 4-wide/4-tall (1:4 strip) chroma pair -- the case whose interp filter used | |
| 2190 | +// to be read from the pair's FIRST mi, which is a different block and, when | |
| 2191 | +// that half is intra, carries the `[3, 3]` "no filter" sentinel (the three | |
| 2192 | +// 1080p 10-bit film cuts refused there). The gate's proof the shape fired. | |
| 2193 | +thread_local! { | |
| 2194 | + static OBMC_PAIR_FILTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 2195 | +} | |
| 2196 | + | |
| 2197 | +/// Current value of [`OBMC_PAIR_FILTER_HITS`]. | |
| 2198 | +pub(crate) fn obmc_pair_filter_hits() -> usize { | |
| 2199 | + OBMC_PAIR_FILTER_HITS.with(|c| c.get()) | |
| 2200 | +} | |
| 2201 | + | |
| 2188 | 2202 | /// Current value of [`OBMC_HITS_8`]. |
| 2189 | 2203 | pub(crate) fn obmc_hits_8() -> usize { |
| 2190 | 2204 | OBMC_HITS_8.with(|c| c.get()) |
| @@ -18143,7 +18157,7 @@ fn overlappable_above( | ||
| 18143 | 18157 | bw4: usize, |
| 18144 | 18158 | mi_cols: usize, |
| 18145 | 18159 | max_neighbors: usize, |
| 18146 | -) -> Vec<(usize, usize, MiInfo)> { | |
| 18160 | +) -> Vec<(usize, usize, MiInfo, usize)> { | |
| 18147 | 18161 | let mut out = Vec::new(); |
| 18148 | 18162 | if mi_row == 0 { |
| 18149 | 18163 | return out; |
| @@ -18154,17 +18168,25 @@ fn overlappable_above( | ||
| 18154 | 18168 | let cell = grid.get(mi_row - 1, col); |
| 18155 | 18169 | let mut step = cell.map_or(1, |c| c.size).max(1).min(SB_MI as usize); |
| 18156 | 18170 | let mut nb = cell; |
| 18171 | + // lane-obmcrec r1: the mi the neighbour's `MiInfo` is actually taken | |
| 18172 | + // from -- the pair merge below moves it, and libaom reads that same | |
| 18173 | + // `mbmi`'s `interp_filters` (`av1_setup_build_prediction_by_above_pred`). | |
| 18174 | + let mut src = col; | |
| 18157 | 18175 | if step == 1 { |
| 18158 | 18176 | // The pair merge: the walk snaps back to the pair's even column |
| 18159 | 18177 | // and the ODD half (the chroma-carrying one) is the neighbour for |
| 18160 | 18178 | // both -- a 4-wide 1:4 strip is never an OBMC source on its own. |
| 18161 | 18179 | col &= !1; |
| 18162 | - nb = grid.get(mi_row - 1, col + 1); | |
| 18180 | + src = col + 1; | |
| 18181 | + nb = grid.get(mi_row - 1, src); | |
| 18163 | 18182 | step = 2; |
| 18164 | 18183 | } |
| 18165 | 18184 | if let Some(info) = nb { |
| 18166 | 18185 | if info.is_inter { |
| 18167 | - out.push((col - mi_col, step.min(end_col - col), *info)); | |
| 18186 | + if src != col { | |
| 18187 | + OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1)); | |
| 18188 | + } | |
| 18189 | + out.push((col - mi_col, step.min(end_col - col), *info, src - mi_col)); | |
| 18168 | 18190 | } |
| 18169 | 18191 | } |
| 18170 | 18192 | col += step; |
| @@ -18181,7 +18203,7 @@ fn overlappable_left( | ||
| 18181 | 18203 | bh4: usize, |
| 18182 | 18204 | mi_rows: usize, |
| 18183 | 18205 | max_neighbors: usize, |
| 18184 | -) -> Vec<(usize, usize, MiInfo)> { | |
| 18206 | +) -> Vec<(usize, usize, MiInfo, usize)> { | |
| 18185 | 18207 | let mut out = Vec::new(); |
| 18186 | 18208 | if mi_col == 0 { |
| 18187 | 18209 | return out; |
| @@ -18194,17 +18216,23 @@ fn overlappable_left( | ||
| 18194 | 18216 | // width (8) would swallow the strip below it. |
| 18195 | 18217 | let mut step = cell.map_or(1, |c| c.size_h).max(1).min(SB_MI as usize); |
| 18196 | 18218 | let mut nb = cell; |
| 18219 | + // lane-obmcrec r1: see `overlappable_above`'s `src`. | |
| 18220 | + let mut src = row; | |
| 18197 | 18221 | if step == 1 { |
| 18198 | 18222 | // The pair merge, left-column mirror: a 4-TALL neighbour (a 16x4 |
| 18199 | 18223 | // strip) is half of a chroma pair and the pair's SECOND row is the |
| 18200 | 18224 | // neighbour for both. |
| 18201 | 18225 | row &= !1; |
| 18202 | - nb = grid.get(row + 1, mi_col - 1); | |
| 18226 | + src = row + 1; | |
| 18227 | + nb = grid.get(src, mi_col - 1); | |
| 18203 | 18228 | step = 2; |
| 18204 | 18229 | } |
| 18205 | 18230 | if let Some(info) = nb { |
| 18206 | 18231 | if info.is_inter { |
| 18207 | - out.push((row - mi_row, step.min(end_row - row), *info)); | |
| 18232 | + if src != row { | |
| 18233 | + OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1)); | |
| 18234 | + } | |
| 18235 | + out.push((row - mi_row, step.min(end_row - row), *info, src - mi_row)); | |
| 18208 | 18236 | } |
| 18209 | 18237 | } |
| 18210 | 18238 | row += step; |
| @@ -18447,6 +18475,46 @@ fn neighbour_filter( | ||
| 18447 | 18475 | )) |
| 18448 | 18476 | } |
| 18449 | 18477 | |
| 18478 | +/// lane-obmcrec r1 MEASUREMENT rung (`EC_OBMCREC=1`): every OBMC neighbour whose | |
| 18479 | +/// recorded switchable-filter symbols are the `[3, 3]` "never recorded" sentinel | |
| 18480 | +/// -- names the neighbour's own position/shape/reference so the decode path that | |
| 18481 | +/// failed to record its filter can be identified. Read-only, off by default. | |
| 18482 | +#[allow(clippy::too_many_arguments)] | |
| 18483 | +fn obmcrec_probe( | |
| 18484 | + dir: &str, | |
| 18485 | + mi_row: usize, | |
| 18486 | + mi_col: usize, | |
| 18487 | + write_w: usize, | |
| 18488 | + write_h: usize, | |
| 18489 | + off4: usize, | |
| 18490 | + span4: usize, | |
| 18491 | + nb: &MiInfo, | |
| 18492 | + syms: [u8; 2], | |
| 18493 | + cell: Option<MiInfo>, | |
| 18494 | + fixed: bool, | |
| 18495 | +) { | |
| 18496 | + if (syms[0] <= 2 && syms[1] <= 2) || std::env::var_os("EC_OBMCREC").is_none() { | |
| 18497 | + return; | |
| 18498 | + } | |
| 18499 | + eprintln!( | |
| 18500 | + "OBMCREC {dir} cur_mi=({mi_row},{mi_col}) cur_wh=({write_w}x{write_h}) off4={off4} \ | |
| 18501 | +span4={span4} syms={syms:?} fixed={fixed} nb_size=({}x{}) nb_ref={} nb_ref1={:?} nb_mv=({},{}) \ | |
| 18502 | +nb_newmv={} cell_size={:?} cell_inter={:?} cell_ref={:?} sb_row_off={} sb_col_off={}", | |
| 18503 | + nb.size * 4, | |
| 18504 | + nb.size_h * 4, | |
| 18505 | + nb.ref_frame, | |
| 18506 | + nb.ref_frame1, | |
| 18507 | + nb.mv.0, | |
| 18508 | + nb.mv.1, | |
| 18509 | + nb.is_new_mv, | |
| 18510 | + cell.map(|c| (c.size * 4, c.size_h * 4)), | |
| 18511 | + cell.map(|c| c.is_inter), | |
| 18512 | + cell.map(|c| c.ref_frame), | |
| 18513 | + mi_row % 32, | |
| 18514 | + mi_col % 32, | |
| 18515 | + ); | |
| 18516 | +} | |
| 18517 | + | |
| 18450 | 18518 | /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh |
| 18451 | 18519 | /// against its own `mv`/reference/filter (libaom `av1_build_inter_predictor` |
| 18452 | 18520 | /// under `av1_setup_build_prediction_by_{above,left}_pred`). |
| @@ -18778,7 +18846,7 @@ fn obmc_blend( | ||
| 18778 | 18846 | // ABOVE pass skips chroma entirely, the LEFT pass still blends it. |
| 18779 | 18847 | let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16)); |
| 18780 | 18848 | |
| 18781 | - for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) | |
| 18849 | + for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) | |
| 18782 | 18850 | { |
| 18783 | 18851 | // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns |
| 18784 | 18852 | // (this decoder's own outer block-loop granularity), one step |
| @@ -18789,10 +18857,12 @@ fn obmc_blend( | ||
| 18789 | 18857 | // `above_mbmi->interp_filters`); the 16px-granular `Neighbours` slot |
| 18790 | 18858 | // stays as the fallback for paths that do not record one yet |
| 18791 | 18859 | // (compound), which is what every earlier round used. |
| 18792 | - let (h_kind, v_kind) = neighbour_filter( | |
| 18793 | - interp_fixed, | |
| 18794 | - neighbours.above_filter[mi_col + off4], | |
| 18795 | - )?; | |
| 18860 | + let above_syms = neighbours.above_filter[mi_col + src4]; | |
| 18861 | + obmcrec_probe( | |
| 18862 | + "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, above_syms, | |
| 18863 | + grid.get(mi_row - 1, mi_col + src4).copied(), interp_fixed.is_some(), | |
| 18864 | + ); | |
| 18865 | + let (h_kind, v_kind) = neighbour_filter(interp_fixed, above_syms)?; | |
| 18796 | 18866 | ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); |
| 18797 | 18867 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 18798 | 18868 | let nb_scale = mc::scale_factor(ny.width, frame_width); |
| @@ -18808,11 +18878,14 @@ fn obmc_blend( | ||
| 18808 | 18878 | } |
| 18809 | 18879 | } |
| 18810 | 18880 | |
| 18811 | - for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) { | |
| 18812 | - let (h_kind, v_kind) = neighbour_filter( | |
| 18813 | - interp_fixed, | |
| 18814 | - neighbours.left_filter[mi_row + off4], | |
| 18815 | - )?; | |
| 18881 | + for (off4, span4, nb, src4) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) | |
| 18882 | + { | |
| 18883 | + let left_syms = neighbours.left_filter[mi_row + src4]; | |
| 18884 | + obmcrec_probe( | |
| 18885 | + "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, left_syms, | |
| 18886 | + grid.get(mi_row + src4, mi_col - 1).copied(), interp_fixed.is_some(), | |
| 18887 | + ); | |
| 18888 | + let (h_kind, v_kind) = neighbour_filter(interp_fixed, left_syms)?; | |
| 18816 | 18889 | ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); |
| 18817 | 18890 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 18818 | 18891 | let nb_scale = mc::scale_factor(ny.width, frame_width); |
crates/ec-av1/src/stream.rsmodified+79 -0
| @@ -160,6 +160,12 @@ pub fn sb128_ab_counters() -> [usize; 4] { | ||
| 160 | 160 | crate::decode::part128_ab_hits() |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | +/// lane-obmcrec r1: OBMC neighbours taken from the second half of a 1:4-strip | |
| 164 | +/// chroma pair -- the shape whose filter record the r1 fix re-sourced. | |
| 165 | +pub fn obmc_pair_filter_hits() -> usize { | |
| 166 | + crate::decode::obmc_pair_filter_hits() | |
| 167 | +} | |
| 168 | + | |
| 163 | 169 | pub fn rect4_32_counters() -> (usize, usize, usize) { |
| 164 | 170 | ( |
| 165 | 171 | crate::decode::rect4_32_horz_hits(), |
| @@ -4476,6 +4482,15 @@ mod tests { | ||
| 4476 | 4482 | /// Seeds swept by the 10-bit LR gate (the 8-bit gate needs ~40 attempts |
| 4477 | 4483 | /// to land a non-RESTORE_NONE frame; every attempt here still has to |
| 4478 | 4484 | /// decode pixel-exact). |
| 4485 | + /// lane-obmcrec r1: the `LR_SEEDS` members whose 1:4-partition stream both | |
| 4486 | + /// fires `obmc_pair_filter_hits` and decodes every frame pixel-exact. | |
| 4487 | + /// Measured over seeds 42..=73 (32 encodes): 43/46/47/65/66 fire and are | |
| 4488 | + /// exact; 70 and 73 fire and mismatch, but mismatch IDENTICALLY with | |
| 4489 | + /// `--enable-obmc=0` (seed 73 frame 1 luma, seed 70 frame 16), so their | |
| 4490 | + /// defect is in the `--min-partition-size=4` recipe, not in OBMC -- kept | |
| 4491 | + /// out of this gate rather than papered over, and reported as open. | |
| 4492 | + const OBMC_PAIR_SEEDS: [u32; 5] = [43, 46, 47, 65, 66]; | |
| 4493 | + | |
| 4479 | 4494 | const LR_SEEDS: [u32; 16] = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]; |
| 4480 | 4495 | |
| 4481 | 4496 | /// Wiener + SGR + switchable loop-restoration firings, summed. |
| @@ -4616,6 +4631,70 @@ mod tests { | ||
| 4616 | 4631 | ); |
| 4617 | 4632 | } |
| 4618 | 4633 | |
| 4634 | + /// lane-obmcrec r1: OBMC whose above/left neighbour is a 4-wide/4-tall | |
| 4635 | + /// 1:4-partition strip -- the shape the three 1080p 10-bit film cuts | |
| 4636 | + /// refused on ("an OBMC neighbour whose switchable interp filter was never | |
| 4637 | + /// recorded"). `overlappable_above`/`_left` snap such a neighbour to the | |
| 4638 | + /// chroma pair's SECOND mi but used to read its interp filter from the | |
| 4639 | + /// FIRST one, a different block whose filter record is the intra | |
| 4640 | + /// `[3, 3]` sentinel whenever that half is intra. `obmc_pair_filter_hits` | |
| 4641 | + /// counts exactly that neighbour shape, so a stream without 1:4 strips | |
| 4642 | + /// next to an OBMC block cannot stand in for it. | |
| 4643 | + #[test] | |
| 4644 | + fn a_real_aomenc_10bit_obmc_over_1to4_strip_neighbours_decodes_pixel_exact() { | |
| 4645 | + const NAME: &str = "a_real_aomenc_10bit_obmc_over_1to4_strip_neighbours_decodes_pixel_exact"; | |
| 4646 | + if !have_ffmpeg() { | |
| 4647 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 4648 | + return; | |
| 4649 | + } | |
| 4650 | + if !have_aomenc() { | |
| 4651 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 4652 | + return; | |
| 4653 | + } | |
| 4654 | + ten_bit_tool_gate( | |
| 4655 | + NAME, | |
| 4656 | + 128, | |
| 4657 | + 128, | |
| 4658 | + 24, | |
| 4659 | + &[ | |
| 4660 | + "--ec-fixture-noise", | |
| 4661 | + "--cq-level=45", | |
| 4662 | + "--kf-max-dist=1000", | |
| 4663 | + "--auto-alt-ref=1", | |
| 4664 | + "--lag-in-frames=16", | |
| 4665 | + "--enable-fwd-kf=0", | |
| 4666 | + "--enable-order-hint=1", | |
| 4667 | + "--enable-warped-motion=0", | |
| 4668 | + "--enable-obmc=1", | |
| 4669 | + "--tune-content=default", | |
| 4670 | + "--enable-masked-comp=0", | |
| 4671 | + "--enable-interintra-comp=0", | |
| 4672 | + "--enable-onesided-comp=0", | |
| 4673 | + "--enable-interintra-wedge=0", | |
| 4674 | + "--enable-smooth-interintra=0", | |
| 4675 | + "--enable-rect-partitions=1", | |
| 4676 | + "--enable-ab-partitions=0", | |
| 4677 | + "--enable-1to4-partitions=1", | |
| 4678 | + "--enable-filter-intra=0", | |
| 4679 | + "--enable-smooth-intra=0", | |
| 4680 | + "--enable-paeth-intra=0", | |
| 4681 | + "--enable-directional-intra=0", | |
| 4682 | + "--enable-angle-delta=0", | |
| 4683 | + "--enable-tx-size-search=0", | |
| 4684 | + "--enable-cdef=0", | |
| 4685 | + "--enable-restoration=0", | |
| 4686 | + "--max-partition-size=32", | |
| 4687 | + "--min-partition-size=4", | |
| 4688 | + "--enable-palette=0", | |
| 4689 | + "--enable-intrabc=0", | |
| 4690 | + "--enable-cfl-intra=0", | |
| 4691 | + "--enable-ref-frame-mvs=0", | |
| 4692 | + ], | |
| 4693 | + &OBMC_PAIR_SEEDS, | |
| 4694 | + &[("obmc_pair_filter_hits", decode::obmc_pair_filter_hits)], | |
| 4695 | + ); | |
| 4696 | + } | |
| 4697 | + | |
| 4619 | 4698 | /// `bit_depth` of the first sequence header in `stream`. |
| 4620 | 4699 | fn parsed_bit_depth(stream: &[u8]) -> u8 { |
| 4621 | 4700 | let mut probe = Av1Parser::new(); |