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 {
2515 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())2515 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())
2516 }2516 }
2517 2517
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+
2518 // lane-mtfix r1: how many times a chroma intra-edge filter-type read was2534 // lane-mtfix r1: how many times a chroma intra-edge filter-type read was
2519 // suppressed at a TILE edge that is not a frame edge -- the above/left2535 // suppressed at a TILE edge that is not a frame edge -- the above/left
2520 // `uv_mode` neighbour of a block on a tile's first mi row/column lives in2536 // `uv_mode` neighbour of a block on a tile's first mi row/column lives in
@@ -5322,6 +5338,23 @@ impl Neighbours {
5322 skip_mode: bool,5338 skip_mode: bool,
5323 ) {5339 ) {
5324 let (r, c) = at_mi;5340 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+ }
5325 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;5358 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
5326 for cell in 0..w_mi {5359 for cell in 0..w_mi {
5327 self.above_skip[c + cell] = skip;5360 self.above_skip[c + cell] = skip;
@@ -5702,6 +5735,11 @@ impl Neighbours {
5702 if above != self.above_uv_mode[c] || left != self.left_uv_mode[r] {5735 if above != self.above_uv_mode[c] || left != self.left_uv_mode[r] {
5703 UV_MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));5736 UV_MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
5704 }5737 }
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+ }
5705 is_smooth_mode(above) || is_smooth_mode(left)5743 is_smooth_mode(above) || is_smooth_mode(left)
5706 }5744 }
5707 5745
@@ -5757,6 +5795,11 @@ impl Neighbours {
5757 if above != self.above_mode[c] || left != self.left_mode[r] {5795 if above != self.above_mode[c] || left != self.left_mode[r] {
5758 MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));5796 MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
5759 }5797 }
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+ }
5760 // A neighbour the coarse band offered where the tile edge makes it5803 // A neighbour the coarse band offered where the tile edge makes it
5761 // unavailable -- must never happen (see `MODE_TILE_EDGE_COARSE_LEAKS`).5804 // unavailable -- must never happen (see `MODE_TILE_EDGE_COARSE_LEAKS`).
5762 if (mi_r <= self.tile_row0_mi && self.above_mode[c] != DC_PRED)5805 if (mi_r <= self.tile_row0_mi && self.above_mode[c] != DC_PRED)
@@ -11052,7 +11095,7 @@ impl PlaneBuf {
11052 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();11095 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
11053 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();11096 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
11054 eprintln!(11097 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)
11056 );11099 );
11057 }11100 }
11058 for row in 0..side {11101 for row in 0..side {
crates/ec-av1/src/stream.rsmodified+6 -1
@@ -30358,6 +30358,9 @@ mod tests {
30358 crate::decode::edge_filter_mi_fix_hits(),30358 crate::decode::edge_filter_mi_fix_hits(),
30359 );30359 );
30360 let sub8tx_before = crate::decode::sub8_chroma_tx_from_ref_hits();30360 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();
30361 let i16_before = crate::decode::intra16x4_in_inter_hits();30364 let i16_before = crate::decode::intra16x4_in_inter_hits();
30362 let frames = match decode_stream(&stream) {30365 let frames = match decode_stream(&stream) {
30363 Ok(frames) => frames,30366 Ok(frames) => frames,
@@ -30373,6 +30376,7 @@ mod tests {
30373 crate::decode::edge_filter_mi_fix_hits() - before.6,30376 crate::decode::edge_filter_mi_fix_hits() - before.6,
30374 );30377 );
30375 let sub8tx = crate::decode::sub8_chroma_tx_from_ref_hits() - sub8tx_before;30378 let sub8tx = crate::decode::sub8_chroma_tx_from_ref_hits() - sub8tx_before;
30379+ let notsmooth = crate::decode::inter_neighbour_not_smooth_hits() - notsmooth_before;
30376 let i16_now = crate::decode::intra16x4_in_inter_hits();30380 let i16_now = crate::decode::intra16x4_in_inter_hits();
30377 let i16 = (30381 let i16 = (
30378 i16_now.0 - i16_before.0,30382 i16_now.0 - i16_before.0,
@@ -30391,6 +30395,7 @@ mod tests {
30391 ("intra16x4_in_inter 4x16", i16.1),30395 ("intra16x4_in_inter 4x16", i16.1),
30392 ("intra16x4_in_inter chroma_ref", i16.2),30396 ("intra16x4_in_inter chroma_ref", i16.2),
30393 ("sub8_chroma_tx_from_ref", sub8tx),30397 ("sub8_chroma_tx_from_ref", sub8tx),
30398+ ("inter_neighbour_not_smooth", notsmooth),
30394 ] {30399 ] {
30395 assert!(30400 assert!(
30396 n > 0,30401 n > 0,
@@ -30416,7 +30421,7 @@ mod tests {
30416 "{NAME}: 15 shown frames pixel-exact on every plane; warp_plane_suppress={} \30421 "{NAME}: 15 shown frames pixel-exact on every plane; warp_plane_suppress={} \
30417 cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \30422 cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \
30418 intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?} \30423 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}",
30420 fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i1630425 fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i16
30421 );30426 );
30422 }30427 }