forge
Explore
Log in

Don't you dare go Hollow

An inter block never stamped the luma/chroma mode maps, so a later intra block's edge-filter type fell back to a stale SMOOTH mode

Browse files at this commit

cb1dc1fc856b96ef2fec85009ac37372b82a3887Ahmet Kaan GümüşParent: f6360d3
  • fix
    • an inter block never stamped the luma/chroma mode maps, so a later intra block's edge-filter type fell back to a stale SMOOTH mode
Show full message
fix(av1): an inter block never stamped the luma/chroma mode maps, so a later intra block's edge-filter type fell back to a stale SMOOTH mode

`get_intra_edge_filter_type` (spec 7.11.2, libaom `reconintra.h`'s
`is_smooth`) reads the above/left neighbour's `mode` (luma) and `uv_mode`
(chroma). For an INTER neighbour libaom answers "not smooth" by
construction: `mbmi->mode` holds an inter mode (>= NEARESTMV) and
`is_smooth(mbmi, plane > 0)` returns 0 outright ("uv_mode is not set for
inter blocks"). Our mi-exact mode maps were written only by intra paths,
so an intra block whose neighbour was an 8x8 inter leaf found no mi entry
and fell back to the coarse SUB-row band -- which still held a SMOOTH
mode from an earlier block in that pixel row. The directional edge filter
then ran at strength 3 where libaom uses 2, and `use_intra_edge_upsample`
can flip with it.

`record_inter_rect_mi` now stamps DC_PRED into both maps for every inter
block. New counter `inter_neighbour_not_smooth_hits` counts the reads
where the coarse band would have said SMOOTH and the mi-exact map does
not; the 128-SB inter witness gate asserts it (375 hits, still pixel-exact
on all 15 shown frames). The square-block `OUR_PRED` trace now prints
`ft=` like the rect one, which is what localised this.

Decode-order compare against aomdec on a 10-bit 1920x792 125-frame cut:
frame 11 luma+U now exact (was 28 luma / 3 U samples off), whole-cut
differing bytes 18108 -> 12780.
crates/ec-av1/src/decode.rsmodified+44 -1
@@ -2515,6 +2515,22 @@ pub(crate) fn uv_mode_mi_override_hits() -> usize {
25152515 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())
25162516 }
25172517
2518+// lane-t900 r8: how many intra edge-filter-type reads (luma + chroma) the
2519+// INTER neighbour stamp saved: the coarse SUB band still held a SMOOTH mode
2520+// from an earlier block in that pixel row/column while the mi-exact map --
2521+// which an inter block only started writing this round -- correctly says the
2522+// neighbour is not smooth (libaom `is_smooth`: an inter neighbour's `mode` is
2523+// an INTER mode, and its `uv_mode` "is not set for inter blocks").
2524+thread_local! {
2525+ static INTER_NEIGHBOUR_NOT_SMOOTH_HITS: std::cell::Cell<usize> =
2526+ const { std::cell::Cell::new(0) };
2527+}
2528+
2529+/// Current value of [`INTER_NEIGHBOUR_NOT_SMOOTH_HITS`].
2530+pub(crate) fn inter_neighbour_not_smooth_hits() -> usize {
2531+ INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|c| c.get())
2532+}
2533+
25182534 // lane-mtfix r1: how many times a chroma intra-edge filter-type read was
25192535 // suppressed at a TILE edge that is not a frame edge -- the above/left
25202536 // `uv_mode` neighbour of a block on a tile's first mi row/column lives in
@@ -5322,6 +5338,23 @@ impl Neighbours {
53225338 skip_mode: bool,
53235339 ) {
53245340 let (r, c) = at_mi;
5341+ // lane-t900 r8 (class new-map-ignores-tile-edge's twin: a map NOBODY
5342+ // writes for a whole block class): an INTER block left the luma mode
5343+ // map untouched, so a later intra block's `get_intra_edge_filter_type`
5344+ // (spec 7.11.2, libaom `reconintra.h`'s `is_smooth`) fell back to the
5345+ // coarse SUB-row band, which still held a SMOOTH mode from an earlier
5346+ // block in that pixel row -- the directional edge filter then ran at
5347+ // strength 3 instead of 2. libaom reads `mbmi->mode` of the neighbour,
5348+ // which for an inter block is an INTER mode (>= NEARESTMV) and is
5349+ // never smooth; DC_PRED is this map's equivalent (the sub-8x8 groups
5350+ // already stamped it).
5351+ // The chroma twin: `is_smooth(mbmi, plane > 0)` returns 0 outright for
5352+ // an inter neighbour ("uv_mode is not set for inter blocks"), so the
5353+ // uv map must read DC_PRED over an inter block's cells too.
5354+ if is_inter {
5355+ self.record_mode_mi(r, c, w_mi, h_mi, DC_PRED);
5356+ self.record_uv_mode_mi(r, c, w_mi, h_mi, DC_PRED);
5357+ }
53255358 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
53265359 for cell in 0..w_mi {
53275360 self.above_skip[c + cell] = skip;
@@ -5702,6 +5735,11 @@ impl Neighbours {
57025735 if above != self.above_uv_mode[c] || left != self.left_uv_mode[r] {
57035736 UV_MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
57045737 }
5738+ if (is_smooth_mode(self.above_uv_mode[c]) && !is_smooth_mode(above))
5739+ || (is_smooth_mode(self.left_uv_mode[r]) && !is_smooth_mode(left))
5740+ {
5741+ INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|h| h.set(h.get() + 1));
5742+ }
57055743 is_smooth_mode(above) || is_smooth_mode(left)
57065744 }
57075745
@@ -5757,6 +5795,11 @@ impl Neighbours {
57575795 if above != self.above_mode[c] || left != self.left_mode[r] {
57585796 MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
57595797 }
5798+ if (is_smooth_mode(self.above_mode[c]) && !is_smooth_mode(above))
5799+ || (is_smooth_mode(self.left_mode[r]) && !is_smooth_mode(left))
5800+ {
5801+ INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|h| h.set(h.get() + 1));
5802+ }
57605803 // A neighbour the coarse band offered where the tile edge makes it
57615804 // unavailable -- must never happen (see `MODE_TILE_EDGE_COARSE_LEAKS`).
57625805 if (mi_r <= self.tile_row0_mi && self.above_mode[c] != DC_PRED)
@@ -11052,7 +11095,7 @@ impl PlaneBuf {
1105211095 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
1105311096 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
1105411097 eprintln!(
11055- "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller()
11098+ "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), i32::from(smooth_neighbor)
1105611099 );
1105711100 }
1105811101 for row in 0..side {
crates/ec-av1/src/stream.rsmodified+6 -1
@@ -30358,6 +30358,9 @@ mod tests {
3035830358 crate::decode::edge_filter_mi_fix_hits(),
3035930359 );
3036030360 let sub8tx_before = crate::decode::sub8_chroma_tx_from_ref_hits();
30361+ // lane-t900 r8: the intra edge-filter type an INTER neighbour keeps
30362+ // non-smooth (the coarse SUB band still holds an older SMOOTH mode).
30363+ let notsmooth_before = crate::decode::inter_neighbour_not_smooth_hits();
3036130364 let i16_before = crate::decode::intra16x4_in_inter_hits();
3036230365 let frames = match decode_stream(&stream) {
3036330366 Ok(frames) => frames,
@@ -30373,6 +30376,7 @@ mod tests {
3037330376 crate::decode::edge_filter_mi_fix_hits() - before.6,
3037430377 );
3037530378 let sub8tx = crate::decode::sub8_chroma_tx_from_ref_hits() - sub8tx_before;
30379+ let notsmooth = crate::decode::inter_neighbour_not_smooth_hits() - notsmooth_before;
3037630380 let i16_now = crate::decode::intra16x4_in_inter_hits();
3037730381 let i16 = (
3037830382 i16_now.0 - i16_before.0,
@@ -30391,6 +30395,7 @@ mod tests {
3039130395 ("intra16x4_in_inter 4x16", i16.1),
3039230396 ("intra16x4_in_inter chroma_ref", i16.2),
3039330397 ("sub8_chroma_tx_from_ref", sub8tx),
30398+ ("inter_neighbour_not_smooth", notsmooth),
3039430399 ] {
3039530400 assert!(
3039630401 n > 0,
@@ -30416,7 +30421,7 @@ mod tests {
3041630421 "{NAME}: 15 shown frames pixel-exact on every plane; warp_plane_suppress={} \
3041730422 cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \
3041830423 intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?} \
30419- sub8_chroma_tx_from_ref={sub8tx}",
30424+ sub8_chroma_tx_from_ref={sub8tx} inter_neighbour_not_smooth={notsmooth}",
3042030425 fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i16
3042130426 );
3042230427 }