forge
Explore
Log in

Don't you dare go Hollow

Chroma intra edge-filter type reads the chroma neighbour's uv_mode, not `false`

Browse files at this commit

f0348397e2afbc093a085a29ad603cb8b5bbf094Ahmet Kaan GümüşParent: a3613e4
  • fix
    • chroma intra edge-filter type reads the chroma neighbour's uv_mode, not `false`
Show full message
fix(av1): chroma intra edge-filter type reads the chroma neighbour's uv_mode, not `false`

`get_intra_edge_filter_type` (reconintra.c:974) picks the directional
edge-filter strength/upsample table from the CHROMA neighbours' `uv_mode`
for planes 1/2; `decode_leaf8` and `decode_leaf_split4` passed a hardcoded
`false` for every chroma reconstruct/read_plane, so a directional chroma
block next to a smooth-uv_mode one filtered its above edge with kernel
{0,4,8,4,0} (strength 1) where libaom uses {0,5,6,5,0} (strength 2).

The coarse SUB-grid `above_uv_mode`/`left_uv_mode` slots cannot name that
neighbour once a 16x16 is split into 8x8 leaves (the leaf above writes the
same row slot the block to the left owns), so this adds the `uv_mode` twin
of `sub8_mode_col`/`sub8_mode_row` -- `uv_mode_col`/`uv_mode_row`, written
by `record_rect`, `record_split_luma`, `decode_leaf8` and
`decode_leaf_split4`, read mi-exact by `smooth_uv_neighbour` with the
coarse slot as fallback.

lane-sub8's gate `a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact`
goes RED (4 chroma pixels, U/V row 20 cols 18-19, |delta| <= 3) -> GREEN
(4 firing + pixel-exact runs). Also drops the stale
"a partition below 16x16 other than a clean split" capability claim, which
r4's fixes removed from the decode path (refusal_inventory RED -> green).
crates/ec-av1/src/decode.rsmodified+79 -12
@@ -1781,6 +1781,13 @@ struct Neighbours {
1781 /// of 8x8 or larger (whose one mode is correct for every row it spans).1781 /// of 8x8 or larger (whose one mode is correct for every row it spans).
1782 sub8_mode_col: Vec<(usize, usize)>,1782 sub8_mode_col: Vec<(usize, usize)>,
1783 sub8_mode_row: Vec<(usize, usize)>,1783 sub8_mode_row: Vec<(usize, usize)>,
1784+ /// The `uv_mode` twin of `sub8_mode_col`/`sub8_mode_row` (lane-sub8 r5):
1785+ /// chroma's edge-filter type reads the CHROMA neighbour's `uv_mode`
1786+ /// (`get_intra_edge_filter_type`, reconintra.c:974), and the coarse
1787+ /// [`SUB`] slots cannot name it once a 16x16 is split into 8x8 leaves --
1788+ /// the leaf above writes the same row slot the block to the left owns.
1789+ uv_mode_col: Vec<(usize, usize)>,
1790+ uv_mode_row: Vec<(usize, usize)>,
1784 /// Whether the block above/left of this column/row was coded `skip` --1791 /// Whether the block above/left of this column/row was coded `skip` --
1785 /// an inter frame's own `skip` context (spec `SkipContext`), which the1792 /// an inter frame's own `skip` context (spec `SkipContext`), which the
1786 /// key-frame writer never tracks (its skip context is always zero); a1793 /// key-frame writer never tracks (its skip context is always zero); a
@@ -1920,6 +1927,8 @@ impl Neighbours {
1920 left_side_mi: vec![SB; rows * (SUB / MI)],1927 left_side_mi: vec![SB; rows * (SUB / MI)],
1921 sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],1928 sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
1922 sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],1929 sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
1930+ uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
1931+ uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
1923 above_skip: vec![false; cols],1932 above_skip: vec![false; cols],
1924 left_skip: vec![false; rows],1933 left_skip: vec![false; rows],
1925 above_skip_mode: vec![false; cols],1934 above_skip_mode: vec![false; cols],
@@ -2534,6 +2543,45 @@ impl Neighbours {
2534 }2543 }
2535 }2544 }
2536 2545
2546+ /// [`Self::record_mode_mi`] for the block's `uv_mode`, into
2547+ /// [`Self::uv_mode_col`]/[`Self::uv_mode_row`].
2548+ fn record_uv_mode_mi(
2549+ &mut self,
2550+ mi_r: usize,
2551+ mi_c: usize,
2552+ mi_w: usize,
2553+ mi_h: usize,
2554+ uv_mode: usize,
2555+ ) {
2556+ let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
2557+ for cell in 0..mi_w {
2558+ if let Some(slot) = self.uv_mode_col.get_mut(mi_c + cell) {
2559+ *slot = (last_r, uv_mode);
2560+ }
2561+ }
2562+ for cell in 0..mi_h {
2563+ if let Some(slot) = self.uv_mode_row.get_mut(mi_r + cell) {
2564+ *slot = (last_c, uv_mode);
2565+ }
2566+ }
2567+ }
2568+
2569+ /// Whether either mi-exact chroma neighbour of the block at `(mi_r, mi_c)`
2570+ /// coded a smooth `uv_mode` -- libaom's `intra_edge_filter_type` for
2571+ /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no
2572+ /// block has recorded the exact neighbouring mi.
2573+ fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
2574+ let above = match self.uv_mode_col.get(mi_c) {
2575+ Some(&(row, m)) if mi_r > 0 && row == mi_r - 1 => m,
2576+ _ => self.above_uv_mode[c],
2577+ };
2578+ let left = match self.uv_mode_row.get(mi_r) {
2579+ Some(&(col, m)) if mi_c > 0 && col == mi_c - 1 => m,
2580+ _ => self.left_uv_mode[r],
2581+ };
2582+ is_smooth_mode(above) || is_smooth_mode(left)
2583+ }
2584+
2537 fn record_rect(2585 fn record_rect(
2538 &mut self,2586 &mut self,
2539 at: (usize, usize),2587 at: (usize, usize),
@@ -2555,6 +2603,7 @@ impl Neighbours {
2555 self.left_side[r + cell] = h;2603 self.left_side[r + cell] = h;
2556 }2604 }
2557 self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode);2605 self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode);
2606+ self.record_uv_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, uv_mode);
2558 self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);2607 self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);
2559 }2608 }
2560 2609
@@ -2666,6 +2715,7 @@ impl Neighbours {
2666 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));2715 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2667 let side_mi = side / MI;2716 let side_mi = side / MI;
2668 self.record_mode_mi(mi_r, mi_c, side_mi, side_mi, mode);2717 self.record_mode_mi(mi_r, mi_c, side_mi, side_mi, mode);
2718+ self.record_uv_mode_mi(mi_r, mi_c, side_mi, side_mi, uv_mode);
2669 for cell in 0..side_mi {2719 for cell in 0..side_mi {
2670 self.left_side_mi[mi_r + cell] = side;2720 self.left_side_mi[mi_r + cell] = side;
2671 self.above_side_mi[mi_c + cell] = side;2721 self.above_side_mi[mi_c + cell] = side;
@@ -5268,9 +5318,17 @@ fn decode_leaf8(
5268 if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) {5318 if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) {
5269 left_mode = m;5319 left_mode = m;
5270 }5320 }
5271- // See [`PlaneBuf::reconstruct`]'s doc: chroma stays `false` (exact) until
5272- // a smooth/paeth `uv_mode` can reach decode at all.
5273 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);5321 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
5322+ // Chroma's edge-filter type reads the CHROMA neighbour's `uv_mode`
5323+ // (`get_intra_edge_filter_type`, reconintra.c:974), never the luma mode
5324+ // this leaf's `smooth_neighbor` is built from -- passing `false` here
5325+ // filtered a directional chroma block's edge at the wrong strength
5326+ // (lane-sub8 r5: 4 pixels of one 8x8 leaf's chroma, deltas 1..3).
5327+ // corner-cut: the `uv_mode` neighbours are the coarse [`SUB`] slots, so
5328+ // two 8x8 leaves of one 16x16 see the slot the previous leaf wrote
5329+ // (updated below) rather than a real mi-exact neighbour; upgrade path is
5330+ // an mi-granular map like `sub8_mode_col`.
5331+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
5274 if smooth_neighbor {5332 if smooth_neighbor {
5275 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));5333 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
5276 }5334 }
@@ -5299,6 +5357,9 @@ fn decode_leaf8(
5299 } else {5357 } else {
5300 uv_mode5358 uv_mode
5301 };5359 };
5360+ neighbours.above_uv_mode[c] = uv_predict_mode;
5361+ neighbours.left_uv_mode[r] = uv_predict_mode;
5362+ neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
5302 // `TxMode::Select`'s `tx_depth` at an 8x8 leaf (spec 5.11.16): the only5363 // `TxMode::Select`'s `tx_depth` at an 8x8 leaf (spec 5.11.16): the only
5303 // depths an 8x8 block offers are `TX8` (depth 0) and `TX4` (depth 1,5364 // depths an 8x8 block offers are `TX8` (depth 0) and `TX4` (depth 1,
5304 // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x45365 // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4
@@ -5337,7 +5398,7 @@ fn decode_leaf8(
5337 &vec![0i32; 16],5398 &vec![0i32; 16],
5338 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),5399 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
5339 None,5400 None,
5340- false,5401+ smooth_neighbor_uv,
5341 );5402 );
5342 v.reconstruct(5403 v.reconstruct(
5343 cpx,5404 cpx,
@@ -5349,7 +5410,7 @@ fn decode_leaf8(
5349 &vec![0i32; 16],5410 &vec![0i32; 16],
5350 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),5411 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
5351 None,5412 None,
5352- false,5413+ smooth_neighbor_uv,
5353 );5414 );
5354 luma_grid = vec![0i32; 64];5415 luma_grid = vec![0i32; 64];
5355 u_grid = vec![0i32; 16];5416 u_grid = vec![0i32; 16];
@@ -5403,7 +5464,7 @@ fn decode_leaf8(
5403 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),5464 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
5404 None,5465 None,
5405 None,5466 None,
5406- false,5467+ smooth_neighbor_uv,
5407 )?;5468 )?;
5408 v_grid = read_plane(5469 v_grid = read_plane(
5409 dec,5470 dec,
@@ -5425,7 +5486,7 @@ fn decode_leaf8(
5425 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),5486 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
5426 None,5487 None,
5427 None,5488 None,
5428- false,5489+ smooth_neighbor_uv,
5429 )?;5490 )?;
5430 } else {5491 } else {
5431 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order5492 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order
@@ -5501,7 +5562,7 @@ fn decode_leaf8(
5501 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),5562 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
5502 None,5563 None,
5503 None,5564 None,
5504- false,5565+ smooth_neighbor_uv,
5505 )?;5566 )?;
5506 v_grid = read_plane(5567 v_grid = read_plane(
5507 dec,5568 dec,
@@ -5523,7 +5584,7 @@ fn decode_leaf8(
5523 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),5584 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
5524 None,5585 None,
5525 None,5586 None,
5526- false,5587+ smooth_neighbor_uv,
5527 )?;5588 )?;
5528 // `record_split_luma` expects a `record`-style `(r, c)` position in5589 // `record_split_luma` expects a `record`-style `(r, c)` position in
5529 // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is5590 // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is
@@ -5694,6 +5755,9 @@ fn decode_leaf_split4(
5694 left_mode = pmode;5755 left_mode = pmode;
5695 }5756 }
5696 }5757 }
5758+ // See `decode_leaf8`'s own `smooth_neighbor_uv`: the chroma edge-filter
5759+ // type is the chroma neighbours' `uv_mode`, mi-exact where recorded.
5760+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
5697 let mut leaf_modes = [0usize; 4];5761 let mut leaf_modes = [0usize; 4];
5698 let mut leaf_skips = [false; 4];5762 let mut leaf_skips = [false; 4];
5699 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;5763 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;
@@ -5775,9 +5839,12 @@ fn decode_leaf_split4(
5775 let (uv_mode, angle_delta_uv, alpha) =5839 let (uv_mode, angle_delta_uv, alpha) =
5776 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");5840 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");
5777 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };5841 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
5842+ neighbours.above_uv_mode[c] = uv_predict_mode;
5843+ neighbours.left_uv_mode[r] = uv_predict_mode;
5844+ neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
5778 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {5845 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {
5779- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, false);5846+ u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);
5780- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, false);5847+ v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);
5781 (vec![0i32; 16], vec![0i32; 16])5848 (vec![0i32; 16], vec![0i32; 16])
5782 } else {5849 } else {
5783 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));5850 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
@@ -5785,12 +5852,12 @@ fn decode_leaf_split4(
5785 let ug = read_plane(5852 let ug = read_plane(
5786 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,5853 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
5787 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,5854 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
5788- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, false,5855+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv,
5789 )?;5856 )?;
5790 let vg = read_plane(5857 let vg = read_plane(
5791 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,5858 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
5792 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,5859 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
5793- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, false,5860+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv,
5794 )?;5861 )?;
5795 (ug, vg)5862 (ug, vg)
5796 };5863 };
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
@@ -28,7 +28,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[
28 "a non-2D tx class on a rectangular transform (never expected at this size)",28 "a non-2D tx class on a rectangular transform (never expected at this size)",
29 "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)",29 "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)",
30 "a nonzero angle delta (this encoder never writes one)",30 "a nonzero angle delta (this encoder never writes one)",
31- "a partition below 16x16 other than a clean split (this decoder codes only the square arms below 16x16)",
32 "a tx_type symbol on a rectangular transform (never expected at this size)",31 "a tx_type symbol on a rectangular transform (never expected at this size)",
33 ];32 ];
34 33