From 1ca3e1be04093081251ec38093527bb18fb7f81c 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:01:54 +0300 Subject: [PATCH] fix(av1): rect intra blocks inside an inter frame read tx_depth off the key frame's deblock-grid ctx `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 the "an INTER neighbour contributes its BLOCK size, not its transform size" override, which only matters once a neighbour's var-tx tree splits. The 1:4 16x4 strip already branched to `tx_size_context_txfm_rect` at its own call site; every other rect intra reader reached from an inter frame (the 2:1 strips, the 32-level and 64-level 1:4 bodies) did not. Fixed once in `tx_size_context_rect` itself, so all six call sites inherit it. Measured on a 2-frame cut of the 10-bit 3840x1608 stream: the 32x8 intra strip at mi(118,280) of frame 1 read tx_size_cat2 row 1 where aomdec reads row 2 (both val=0, ranges 55568 vs 63652) and desynced the tile from there. After the fix every one of the 6871 inter blocks aomdec reports in that frame matches ours on entry range, and the decode-order PREFILT16 compare goes from 4386319 wrong luma samples to 115 (chroma 342/860, all |delta|=1). --- crates/ec-av1/src/decode.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 05705180..39ebd84b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6736,6 +6736,19 @@ fn tx_size_context_rect( // this way, lane-sb128b r1). Without the cap the 64x128 half of a 128-root // VERT reads the tx-depth symbol off row 0 where libaom uses row 1. let (own_w, own_h) = (own_w.min(64), own_h.min(64)); + // lane-midcut r2: on an INTER frame `get_tx_size_context` reads the real + // `TXFM_CONTEXT` bands and lets an INTER neighbour contribute its BLOCK + // size ([`tx_size_context_txfm_rect`]); the deblock-grid approximation + // below is the KEY FRAME's, and it is right only where those bands were + // never written. The 1:4 intra strip already branched this way at its own + // call site -- every other rect intra reader reached from an inter frame + // (2:1 strips, the 32-level and 64-level 1:4 bodies) read `tx_size_cat*` + // off the wrong row whenever the neighbour above was an inter block whose + // 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 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; if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {