From 00aa4498c0f89da2f4321bea1562572089789fc5 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 23:40:45 +0300 Subject: [PATCH] fix(av1): the warp-sample top-right probe needs libaom's rect shape refinements, not just the longer side r9 changed `av1_findSamples`' top-right probe to libaom's `AOMMAX(xd->width, xd->height)` (mvref_common.c:1235) but left our `has_top_right` port without the two shape refinements libaom applies right after the mask loop (`av1_common_int.h:1419-1428`): is_last_vertical_rect = !((mi_col + width) & (height - 1)) [width < height] is_first_horizontal_rect = !(mi_row & (width - 1)) [width > height] Both are derivable from mi_row/mi_col/bw4/bh4 alone -- no partition context -- and they only bite when bw4 != bh4, i.e. exactly the blocks whose probe size r9 changed. Probing at the longer side WITHOUT them is half a port: it fixed the 64x128 block (bs=32 > 16, early-out, no top-right sample, 2-symbol obmc alphabet) and broke a 32-wide tall leaf in an earlier superblock, moving the first divergence of the 10-bit 1920x792 264-frame cut EARLIER (decode frame 49, mi(24,376) -> its successor mi(24,380) read a different rng). With the refinements ported, on that cut: * mode ladder vs the instrumented reference decoder over ALL 264 frames: 915 equal runs, 914 inserts (our per-sub-block prints the reference does not emit), ZERO replace/delete -- every EC_MODE (mi_row, mi_col, rng) triple the reference emits matches ours, previously the first mismatch was frame 49. * pixel compare vs the reference decoder: 231/267 frames bit-exact, 36 frames differ by 1-3 bytes each (the known chroma-MC bottom-row clamp residue, lane-t900 r8); was 218/267 frames differing, frame 49 alone by 2.26 MB. `tr_reach_longer_side_hits()` now counts blocks where the full probe disagrees with the old square-at-width probe (9936 on that cut). corner-cut: libaom's third refinement (PARTITION_VERT_A bottom-left square) still not ported -- it needs the parent partition type; ceiling and upgrade path recorded on `mvstack::has_top_right`. --- crates/ec-av1/src/decode.rs | 2 +- crates/ec-av1/src/mvstack.rs | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 7278fcfc..e0e8140c 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -18991,7 +18991,7 @@ fn find_samples( // `num_proj_ref >= 1` picked the 3-symbol `motion_mode_cdf` where // libaom reads the 2-symbol `obmc_cdf` (class // wrong-alphabet-same-value). - let tr_reach = has_top_right(mi_row, mi_col, bw4.max(bh4)); + let tr_reach = crate::mvstack::has_top_right(mi_row, mi_col, bw4, bh4); if do_tr && bw4 != bh4 && tr_reach != has_top_right(mi_row, mi_col, bw4) { TR_REACH_LONGER_SIDE_HITS.with(|c| c.set(c.get() + 1)); } diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index c13b0e3d..c309d4f7 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -688,11 +688,13 @@ fn top_right_scan_allowed(bw4: usize, bh4: usize) -> bool { /// (what this module did before lane-sb128 r2) cannot see. It cost frame 6 of /// the 128 inter gate 380 wrong luma bytes with the entropy stream in sync. /// -/// corner-cut: libaom's three shape refinements (`is_last_vertical_rect`, -/// `is_first_horizontal_rect`, the `PARTITION_VERT_A` bottom-left square) are -/// not ported -- the ceiling is rectangular and AB-partitioned INTER leaves, -/// which this decoder refuses by name today; port them with the rect inter -/// leaf. +/// lane-t900 r10 ports `is_last_vertical_rect` and `is_first_horizontal_rect` +/// (both derivable from `mi_row`/`mi_col`/`bw4`/`bh4` alone). +/// corner-cut: libaom's third refinement (the `PARTITION_VERT_A` bottom-left +/// SQUARE, which needs the parent partition type this port does not thread +/// here) is still missing -- ceiling is a square INTER leaf inside a VERT_A +/// partition whose warp-sample top-right probe may answer 1 where libaom says +/// 0; upgrade path = thread `partition` into this call. pub(crate) fn has_top_right(mi_row: usize, mi_col: usize, bw4: usize, bh4: usize) -> bool { let sb_mi_size = crate::decode::sb_mi_cur() as usize; let bs0 = bw4.max(bh4); @@ -713,6 +715,24 @@ pub(crate) fn has_top_right(mi_row: usize, mi_col: usize, bw4: usize, bh4: usize } bs <<= 1; } + // lane-t900 r10: two of libaom's three shape refinements, computed from + // the block's own position and side (`av1_common_int.h:1419-1428` sets + // `is_last_vertical_rect` / `is_first_horizontal_rect` from exactly these + // terms, no partition context). They only bite when `bw4 != bh4`, which is + // also the only case where `bs0` differs from the block's width -- probing + // at the longer side WITHOUT them is half a port and moved the first + // divergence of the 10-bit 1080p cut EARLIER (r9). + if bw4 < bh4 { + let is_last_vertical_rect = (mi_col + bw4) & (bh4 - 1) == 0; + if !is_last_vertical_rect { + has_tr = true; + } + } else if bw4 > bh4 { + let is_first_horizontal_rect = mi_row & (bw4 - 1) == 0; + if !is_first_horizontal_rect { + has_tr = false; + } + } has_tr }