From cb1dc1fc856b96ef2fec85009ac37372b82a3887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 22:49:27 +0300 Subject: [PATCH] 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.rs | 45 ++++++++++++++++++++++++++++++++++++- crates/ec-av1/src/stream.rs | 7 +++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 4e703249..55329df2 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2515,6 +2515,22 @@ pub(crate) fn uv_mode_mi_override_hits() -> usize { UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get()) } +// lane-t900 r8: how many intra edge-filter-type reads (luma + chroma) the +// INTER neighbour stamp saved: the coarse SUB band still held a SMOOTH mode +// from an earlier block in that pixel row/column while the mi-exact map -- +// which an inter block only started writing this round -- correctly says the +// neighbour is not smooth (libaom `is_smooth`: an inter neighbour's `mode` is +// an INTER mode, and its `uv_mode` "is not set for inter blocks"). +thread_local! { + static INTER_NEIGHBOUR_NOT_SMOOTH_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTER_NEIGHBOUR_NOT_SMOOTH_HITS`]. +pub(crate) fn inter_neighbour_not_smooth_hits() -> usize { + INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|c| c.get()) +} + // lane-mtfix r1: how many times a chroma intra-edge filter-type read was // suppressed at a TILE edge that is not a frame edge -- the above/left // `uv_mode` neighbour of a block on a tile's first mi row/column lives in @@ -5322,6 +5338,23 @@ impl Neighbours { skip_mode: bool, ) { let (r, c) = at_mi; + // lane-t900 r8 (class new-map-ignores-tile-edge's twin: a map NOBODY + // writes for a whole block class): an INTER block left the luma mode + // map untouched, so a later intra block's `get_intra_edge_filter_type` + // (spec 7.11.2, libaom `reconintra.h`'s `is_smooth`) 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 instead of 2. libaom reads `mbmi->mode` of the neighbour, + // which for an inter block is an INTER mode (>= NEARESTMV) and is + // never smooth; DC_PRED is this map's equivalent (the sub-8x8 groups + // already stamped it). + // The chroma twin: `is_smooth(mbmi, plane > 0)` returns 0 outright for + // an inter neighbour ("uv_mode is not set for inter blocks"), so the + // uv map must read DC_PRED over an inter block's cells too. + if is_inter { + self.record_mode_mi(r, c, w_mi, h_mi, DC_PRED); + self.record_uv_mode_mi(r, c, w_mi, h_mi, DC_PRED); + } let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; for cell in 0..w_mi { self.above_skip[c + cell] = skip; @@ -5702,6 +5735,11 @@ impl Neighbours { if above != self.above_uv_mode[c] || left != self.left_uv_mode[r] { UV_MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); } + if (is_smooth_mode(self.above_uv_mode[c]) && !is_smooth_mode(above)) + || (is_smooth_mode(self.left_uv_mode[r]) && !is_smooth_mode(left)) + { + INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|h| h.set(h.get() + 1)); + } is_smooth_mode(above) || is_smooth_mode(left) } @@ -5757,6 +5795,11 @@ impl Neighbours { if above != self.above_mode[c] || left != self.left_mode[r] { MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); } + if (is_smooth_mode(self.above_mode[c]) && !is_smooth_mode(above)) + || (is_smooth_mode(self.left_mode[r]) && !is_smooth_mode(left)) + { + INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|h| h.set(h.get() + 1)); + } // A neighbour the coarse band offered where the tile edge makes it // unavailable -- must never happen (see `MODE_TILE_EDGE_COARSE_LEAKS`). if (mi_r <= self.tile_row0_mi && self.above_mode[c] != DC_PRED) @@ -11052,7 +11095,7 @@ impl PlaneBuf { let row0: Vec = prediction[..side.min(8)].to_vec(); let col0: Vec = (0..side.min(8)).map(|r| prediction[r * side]).collect(); eprintln!( - "@{} 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() + "@{} 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) ); } for row in 0..side { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b1459936..6df83ee1 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -30358,6 +30358,9 @@ mod tests { crate::decode::edge_filter_mi_fix_hits(), ); let sub8tx_before = crate::decode::sub8_chroma_tx_from_ref_hits(); + // lane-t900 r8: the intra edge-filter type an INTER neighbour keeps + // non-smooth (the coarse SUB band still holds an older SMOOTH mode). + let notsmooth_before = crate::decode::inter_neighbour_not_smooth_hits(); let i16_before = crate::decode::intra16x4_in_inter_hits(); let frames = match decode_stream(&stream) { Ok(frames) => frames, @@ -30373,6 +30376,7 @@ mod tests { crate::decode::edge_filter_mi_fix_hits() - before.6, ); let sub8tx = crate::decode::sub8_chroma_tx_from_ref_hits() - sub8tx_before; + let notsmooth = crate::decode::inter_neighbour_not_smooth_hits() - notsmooth_before; let i16_now = crate::decode::intra16x4_in_inter_hits(); let i16 = ( i16_now.0 - i16_before.0, @@ -30391,6 +30395,7 @@ mod tests { ("intra16x4_in_inter 4x16", i16.1), ("intra16x4_in_inter chroma_ref", i16.2), ("sub8_chroma_tx_from_ref", sub8tx), + ("inter_neighbour_not_smooth", notsmooth), ] { assert!( n > 0, @@ -30416,7 +30421,7 @@ mod tests { "{NAME}: 15 shown frames pixel-exact on every plane; warp_plane_suppress={} \ cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \ intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?} \ - sub8_chroma_tx_from_ref={sub8tx}", + sub8_chroma_tx_from_ref={sub8tx} inter_neighbour_not_smooth={notsmooth}", fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i16 ); }