From a0c69515a9d2621b5ffe147e03585891eeeee04f 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 21:03:28 +0300 Subject: [PATCH] feat(av1): counter for rect intra-in-inter blocks whose tx_depth CDF row moved under the inter-neighbour override `intra_rect_in_inter_txctx_override_hits()` counts only the blocks where libaom's "an INTER neighbour contributes its BLOCK size" override changes the `tx_size_cat*` row versus the key frame's deblock-grid approximation -- i.e. exactly the blocks the previous commit fixes. A plain "rect intra in an inter frame" tally is green on the buggy code too, so a gate has to assert this one. Not yet wired into a gate (turn cap); lanes/midcut-r2.handoff.md names the two gate call sites and the fallback aomenc arm. --- crates/ec-av1/src/decode.rs | 28 ++++++++++++++- lanes/midcut-r2.handoff.md | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 lanes/midcut-r2.handoff.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 39ebd84b..7eeed91c 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2389,6 +2389,19 @@ pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] { INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) } +// lane-midcut r2: rect intra blocks inside an inter frame whose `tx_depth` CDF +// ROW moved when libaom's inter-neighbour override was applied -- i.e. exactly +// the blocks the key frame's deblock-grid approximation used to mis-read. +thread_local! { + static INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS`]. +pub(crate) fn intra_rect_in_inter_txctx_override_hits() -> usize { + INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS.with(std::cell::Cell::get) +} + // lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER // block path, per shape -- [0] 64x16, [1] 16x64, [2] 32x8, [3] 8x32. Every // one of them was the named refusal "an intra-coded 1:4 (or other non-2:1) @@ -6747,7 +6760,20 @@ fn tx_size_context_rect( // var-tx tree had split (measured: a 32x8 intra strip at mi(118,280) of // the 10-bit 3840x1608 stream read ctx 1 where aomdec reads ctx 2). if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { - return tx_size_context_txfm_rect(n, (mi_r, mi_c), own_w, own_h); + let ctx = tx_size_context_txfm_rect(n, (mi_r, mi_c), own_w, own_h); + // Count only the blocks the deblock-grid approximation got WRONG, so a + // gate asserting this counter proves the override changed a CDF row + // (class gate-blind-to-feature: a plain "rect intra in inter" tally is + // green on the buggy code too). + let stale = usize::from( + mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w, + ) + usize::from( + mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h, + ); + if ctx != stale { + INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS.with(|c| c.set(c.get() + 1)); + } + return ctx; } let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; diff --git a/lanes/midcut-r2.handoff.md b/lanes/midcut-r2.handoff.md new file mode 100644 index 00000000..df8f7526 --- /dev/null +++ b/lanes/midcut-r2.handoff.md @@ -0,0 +1,71 @@ +# lane-midcut r2 handoff (coordinator turn cap) + +Tip: lane-midcut, merged main (243f125) cleanly at STEP 0 (decode.rs/stream.rs auto-merged, `cargo check -p ec-av1` clean). + +## r1's named defect was STALE on both counts +1. `find_mv_stack` call sites decode.rs:20959 and :23046 ALREADY pass + `bw4 = write_w/4`, `bh4 = write_h/4` (lane-rect r2 did that). No `side, side` + remains at any single-ref/compound mv-stack site; the sub-8 leaf sites pass + the literal `1,1` / `2,2` libaom uses. Nothing to fix there. +2. The mv stack at mi(112,288) is IDENTICAL to aomdec's, entry for entry: + i0 (-24,-352) w=700 | i1 (-32,-350) w=664 | i2 (-40,-340) w=644 | i3 (-20,-360) w=4 + (both decoders, both stack=4). Only the DRL index differed, because the + entropy state at that block already differed (aomdec EC_MODE rng=56215 vs + ours 41892) -- r1's "entropy in sync" premise was wrong. It was a downstream + symptom, never a defect. + +## Root cause found and FIXED (commit cde8893) +Reproducing this cut now needs `EC_INTRA16X4_DECODE=1` (main re-added the +16x4-in-inter refusal); without it the probe refuses and every trace truncates. + +First real divergence in frame 1 (2-frame cut, decode order): the 32x8 INTRA +strip at mi(118,280), inside an inter frame, reading its `tx_depth` symbol. + aomdec: `EC_ISTEP mi_row=118 mi_col=280 name=tx_depth val=0 ctx=2 cat=2 rng=63652` + ours : `EC_TXCTX mi_row=118 mi_col=280 w=32 h=8 above_px=16 left_px=16 ctx=1` +Both entered at rng 42394 (the `use_filter_intra` rung matches exactly), so the +ROW of `tx_size_cat2` is the whole defect (class wrong-alphabet-same-value: the +value is 0 in both, only the range moves). + +`tx_size_context_rect` is the KEY FRAME approximation of libaom +`get_tx_size_context` (`pred_common.h:342`): it reads the deblock tx grid and +never applies "an INTER neighbour contributes its BLOCK size, not its transform +size". The above neighbour here is the inter 32x8 at mi(116,280) whose var-tx +tree had split to 16-wide TUs, so libaom sees 32 >= 32 (above=1) while we saw +16 >= 32 (above=0). The 1:4 16x4 strip already branched to +`tx_size_context_txfm_rect` at its own call site (decode.rs:9116); the other six +rect intra readers did not. Fix = one branch inside `tx_size_context_rect` +itself (decode.rs:6737) keyed on `INTRA_IN_INTER_MODE`, so every call site +inherits it. + +### Measured effect (EVIDENCE lines) +EVIDENCE: ~/.cache/midcut-tmp/{m_am.txt,m_o2.txt} | greedy in-order match of every +`EC_MODE mi_row= mi_col= rng=` line, aomdec vs ours, 2-frame cut | first mismatch +moved from aom idx 1998 (mi 120,272) to ALL MATCH 6871/6871 inter blocks. +EVIDENCE: ~/.cache/midcut-tmp/d/{our,aom}.f{0,1} (EC_AV1_PREFILT_DUMP16, both +decoders, regenerated this round) | numpy plane compare | f0 EXACT; f1 luma +4386319 -> 115 wrong samples, U 342, V 860, every delta |1|, luma bbox rows +552..1552 cols 488..969. + +## Also added (compiles, NOT yet gated -- next agent's first job) +`decode::intra_rect_in_inter_txctx_override_hits()` (decode.rs, next to +`intra_rect_in_inter_split_tx_hits`): counts ONLY the rect-intra-in-inter blocks +whose ctx actually MOVED under the override, i.e. the blocks the bug mis-read -- +a plain "rect intra in inter" tally is green on the buggy code too +(class gate-blind-to-feature). + +## Exact next steps +1. Print the new counter in `crates/ec-av1/examples/decode_probe.rs` (model: + the `interintra_rect:` line at :46) and hard-assert a positive delta in + `intra_rect_in_inter_split_tx_gate` / `intra_rect_in_inter_gate` + (stream.rs:5639 / :29785, both bit depths). If neither arm fires the counter, + add an aomenc arm with rect partitions + tx-size search on (the override only + moves the row once a neighbour's var-tx tree splits). +2. Chase the 115/342/860 |1| residue in frame 1 (entropy is now provably exact, + so it is pure reconstruction: MC rounding or an intra edge, luma bbox above). +3. Re-run the 24-offset decode-order table (`~/.cache/midcut-tmp/cen/`, r1's + scripts; the r1 table `cen/after.tsv` is now stale) and report how many + offsets have frame 1 exact. +4. Then the named gates (mv_stack, interintra, rect, hidden_arf, + refusal_inventory, gate_coverage) and the suite unit. None was run this round. +5. No fixture pinned: frame 1 is not exact yet (residue above). +6. No refusal lifted or moved; refusal_inventory/gate_coverage untouched.