From 7250c10a09c4352e99c3af8cc7dcb7b0b9104da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 23:08:19 +0300 Subject: [PATCH] fix(av1): 8x8 leaf read its single_ref and interp-filter neighbour contexts at SUB(16px) indices after the bands went mi-granular lane-gmaffine r3, on top of the lane-inter8 merge. `decode_inter_block8` still indexed `neighbours.above_ref/above_ref1/above_filter` with `c` and `left_*` with `r` -- `outer_at`, the enclosing 16x16's SUB(16px) coordinates -- while every other read in the same function had moved to `cmi`/`rmi` (mi, 4px) with lane-inter8 r2's mi-granular bands. Wrong units, so a leaf's `read_single_ref` p1..p6 contexts and its `switchable_interp` neighbour rows came from an unrelated 16px column/row. Measured on the gate's own recipe (--min/--max-partition-size=8, gm and warp both off, 8-bit cq32): aomdec's EC_MODE_VAL ladder and ours agree on mode, mv, ref and range for the 16 leaves of the first 32x32 up to (6,4); leaf (6,6) had identical mode/mv/stack but post-mode-info range 41953 vs aomdec's 38345 -- the divergence sat after the mv, in the filter/ref tail. With mi indices that leaf and the next 15 now match to the range. Instrument kept: `EC_MODE_VAL8` under EC_TRACE_MODE, one line per 8x8 leaf (newmv/globalmv/ref0/mv/stack/rng), diffable against aomdec's EC_MODE_VAL. Both 8x8 motion gates are still RED: the next divergence is leaf mi=(0,14) of the same frame, where aomdec reads NEWMV (mv 0,-12) and we read not-new from a 3-entry stack. --- crates/ec-av1/src/decode.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a02d365e..62685504 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -11480,10 +11480,10 @@ fn decode_inter_block8( let ref_frame = read_single_ref( dec, cdfs, - neighbours.above_ref[c], - neighbours.above_ref1[c], - neighbours.left_ref[r], - neighbours.left_ref1[r], + neighbours.above_ref[cmi], + neighbours.above_ref1[cmi], + neighbours.left_ref[rmi], + neighbours.left_ref1[rmi], ); leaf_refs = (ref_frame, None); let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; @@ -11701,17 +11701,17 @@ fn decode_inter_block8( // wrong CDF row. Upgrade: give `Neighbours` a real 8x8-granular // filter array, same shape as the `[3, 3]` approximation the caller // records after the leaf loop. - let above_filter_ctx = if neighbours.above_ref[c] == ref_frame - || neighbours.above_ref1[c] == Some(ref_frame) + let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame + || neighbours.above_ref1[cmi] == Some(ref_frame) { - neighbours.above_filter[c] + neighbours.above_filter[cmi] } else { [3, 3] }; - let left_filter_ctx = if neighbours.left_ref[r] == ref_frame - || neighbours.left_ref1[r] == Some(ref_frame) + let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame + || neighbours.left_ref1[rmi] == Some(ref_frame) { - neighbours.left_filter[r] + neighbours.left_filter[rmi] } else { [3, 3] }; @@ -11728,6 +11728,17 @@ fn decode_inter_block8( false, ); leaf_filter_syms = resolved_filter; + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}", + leaf_mi.0, + leaf_mi.1, + mv.0, + mv.1, + stack.entries.len(), + dec.debug_state().0 + ); + } // lane-gmaffine r1: `allow_warp`'s `global_warp_allowed` branch // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` -- // see [`decode_inter_block`]'s own copy. A local WARPED_CAUSAL model