forge
Explore
Log in

Don't you dare go Hollow

ec-av1: rect intrabc r3 -- key-frame txfm-band publication for rect strips, frame reduced_tx_set

Browse files at this commit

3b06ab729986118215a8e00f98b341f77a719f2dAhmet Kaan GümüşParent: d5adb7a
Two frame-level root causes behind the two remaining red arms of lane-av1-intrabc.

1. The key-frame 2:1 rect readers (decode_block_rect, decode_leaf_rect,
   decode_block_128rect) never published the TXFM_CONTEXT bands, so the
   var-tx context an intrabc block reads was stale. publish_txfm_bands_if_in_inter
   now also fires on an allow_intrabc key frame and the three readers call it.
   The 256x192 testsrc2 cq45 var-tx arm is byte-exact again.

2. decode_key_frame_tile_with_cdfs never published the header's
   reduced_tx_set into fctx.reduced_tx_set_inter, so a rect intrabc block
   (is_inter_block) read the reduced 2-symbol tx_type CDF instead of the
   16-symbol ALL16 row. The 512x384 cq45 arm went 7900 -> 528 luma samples.

Remaining (reported in lanes/av1intrabc.report.md 4c): that arm's only
residual difference is the DV VALUE at mi(84,104) (-504 vs -512, same
post-read range), i.e. our intrabc INTRA_FRAME mv-stack candidate ordering
differs from libaom's. Lane is NOT merge-ready; suite run deferred.
crates/ec-av1/src/decode.rsmodified+47 -4
@@ -11327,6 +11327,14 @@ fn decode_block_rect(
1132711327 } else {
1132811328 0
1132911329 };
11330+ // lane-av1-intrabc r3: this strip's own `set_txfm_ctxs` when the frame
11331+ // reads the `TXFM_CONTEXT` bands -- see [`publish_txfm_bands_if_in_inter`].
11332+ publish_txfm_bands_if_in_inter(
11333+ neighbours,
11334+ (mi_r, mi_c),
11335+ depth_to_tx_wh(bw, bh, depth, fctx),
11336+ (bw, bh), fctx,
11337+ );
1133011338 if depth != 0 || lossless(fctx) {
1133111339 hit!(TX_DEPTH_HITS);
1133211340 // lane-rectsplit r1: a split transform is predicted and reconstructed
@@ -11847,6 +11855,14 @@ fn decode_leaf_rect(
1184711855 } else {
1184811856 0
1184911857 };
11858+ // lane-av1-intrabc r3: this leaf's own `set_txfm_ctxs` when the frame reads
11859+ // the `TXFM_CONTEXT` bands -- see [`publish_txfm_bands_if_in_inter`].
11860+ publish_txfm_bands_if_in_inter(
11861+ neighbours,
11862+ leaf_mi,
11863+ depth_to_tx_wh(bw, bh, depth, fctx),
11864+ (bw, bh), fctx,
11865+ );
1185011866 if depth != 0 || lossless(fctx) {
1185111867 // The same per-transform-unit walk the bigger strips take
1185211868 // (`depth_to_tx_wh`: TX_16X8 -> TX_8X8 at depth 1, -> TX_4X4 at
@@ -15783,19 +15799,22 @@ fn decode_block_128rect(
1578315799 logical_tx as u8,
1578415800 0, fctx,
1578515801 );
15786- if in_inter {
15802+ if in_inter || allow_intrabc_frame(fctx) {
1578715803 // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)`
1578815804 // (libaom `decodeframe.c` `decode_block`) runs for EVERY block of an
1578915805 // inter frame, intra ones included: an intra block stamps its
1579015806 // TRANSFORM size over its own footprint in both TXFM_CONTEXT bands.
15791- // A key frame has no var-tx tree and its readers use the deblock grid,
15792- // so this is the inter path's alone.
15807+ // A key frame reads those bands only when it allows intrabc
15808+ // ([`read_block_tx_size_rect`]'s var-tx context), and then libaom
15809+ // stamps here too -- lane-av1-intrabc r3.
1579315810 txfm_partition_update_rect(
1579415811 neighbours,
1579515812 (mi_r, mi_c),
1579615813 (logical_tx, logical_tx),
1579715814 (bw, bh),
1579815815 );
15816+ }
15817+ if in_inter {
1579915818 hit_do! {
1580015819 INTRA128_IN_INTER_HITS.with(|c| {
1580115820 let mut h = c.get();
@@ -18511,13 +18530,26 @@ fn txfm_partition_update(
1851118530 /// `tx_size_cat1` row 1 instead of row 0 -- same depth VALUE, different CDF,
1851218531 /// range 39156 where the reference has 54736 (class tx-grid-published-block-side
1851318532 /// / early-return-skips-tail).
18533+///
18534+/// lane-av1-intrabc r3: an `allow_intrabc` KEY frame reads the same bands --
18535+/// `read_intra_frame_mode_info` returns early for an intrabc block, so
18536+/// [`read_block_tx_size_rect`]'s var-tx tree is the intra path's one
18537+/// `txfm_partition_context` reader, and it reads whatever the block ABOVE and
18538+/// the block LEFT published. [`decode_block`] has published on such a frame
18539+/// since lane-t900 r32; the RECT strips did not, so the band still held the
18540+/// value of an older, smaller neighbour -- measured on the 256x192 testsrc2
18541+/// cq45 var-tx arm: the coded 16x8 intrabc strip at mi(38,48) read ctx 14
18542+/// where libaom reads 13 (`left_ctx` 4 vs the 8 the 16x8 intra strip at
18543+/// mi(38,44) should have published), desyncing the tile there.
1851418544 fn publish_txfm_bands_if_in_inter(
1851518545 n: &mut Neighbours,
1851618546 at_mi: (usize, usize),
1851718547 (tx_w, tx_h): (usize, usize),
1851818548 (bw, bh): (usize, usize), fctx: &crate::decode::FrameCtx,
1851918549 ) {
18520- if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_none() {
18550+ if fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_none()
18551+ && !allow_intrabc_frame(fctx)
18552+ {
1852118553 return;
1852218554 }
1852318555 let (mi_r, mi_c) = at_mi;
@@ -23126,6 +23158,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2312623158 // lane-av1-intrabc r2: the FRAME's own tx_mode -- an intrabc block's
2312723159 // tx-size read keys on it even inside an intra tile.
2312823160 fctx.tx_select_frame.with(|c| c.set(tx_select));
23161+ // lane-av1-intrabc r3: the FRAME's own `reduced_tx_set_used`, for the same
23162+ // reason and by the same shape as `tx_select_frame` above. `read_tx_type`
23163+ // keys the `tx_type` CDF on it (`av1_get_ext_tx_set_type`), and an INTRABC
23164+ // block is `is_inter_block`, so it reads the INTER sets off
23165+ // [`FrameCtx::reduced_tx_set_inter`] -- which the inter tile decoder sets
23166+ // and a key frame left at its `true` DEFAULT. The first rect intrabc block
23167+ // of a `--enable-tx-size-search=0` screen frame then read the 2-symbol
23168+ // `DCT_IDTX` `tx_type` row where libaom reads the 16-symbol `ALL16` one,
23169+ // desyncing the tile at that block's luma coefficients (measured: the
23170+ // 512x384 testsrc2 cq45 arm, mi(80,106)).
23171+ fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set));
2312923172 if mi_cols == 0 || mi_rows == 0 {
2313023173 return Err(unsupported("a frame with no mode-info grid"));
2313123174 }
lanes/av1intrabc.report.mdmodified+102 -0
@@ -138,3 +138,105 @@ exactly the 256x192 repro above and it is still 4520 bytes off.
138138 witness recipes. `deferred(1:4 pair-chroma model)`
139139 2. **Full-suite gate** -- `deferred(batch-level run after lane-av1-txbands
140140 merges; same file, mid-flight run would measure a half-built tree)`
141+
142+## 4c. Round 3 (2026-09-20) -- two frame-level root causes found, one stream now exact
143+
144+Both repros were localized with a per-symbol range ladder
145+(`EC_TRACE_MODE_STEP` on our decoder vs the instrumented aomdec), then the
146+first untraced region with `EC_TRACE_COEFF`/`EC_ISTEP`.
147+
148+### Root cause 1 (stream A, and latent for every rect strip): the key-frame RECT path never published the `TXFM_CONTEXT` bands
149+
150+`read_intra_frame_mode_info` (libaom `decodemv.c:909`) returns EARLY for an
151+intrabc block, so the block's transform size comes from
152+`parse_decode_block`'s INTER var-tx branch -- `read_tx_size_vartx`, whose
153+depth-0 context is `txfm_partition_context(above_txfm[mi_col],
154+left_txfm[mi_row], bsize, tx_size)`. Those bands are written by libaom's
155+`set_txfm_ctxs` at the end of EVERY `decode_block`/`decode_token_recon_block`,
156+key frames included.
157+
158+Only `decode_block` (lane-t900 r32, gated on the frame's `allow_intrabc`) and
159+`decode_block_rect4`/`decode_block_rect64`/`decode_rect4_16_strip`/
160+`decode_leaf_rect8` (gated on `INTRA_IN_INTER_MODE`) published. The 2:1 strip
161+readers reached on a key frame -- `decode_block_rect` (16x32/32x16),
162+`decode_leaf_rect` (8x16/16x8 leaves of a 16x16 HORZ/VERT split) and
163+`decode_block_128rect` -- published nothing.
164+
165+Measured (256x192 testsrc2 cq45 var-tx arm): the coded intrabc 16x8 strip at
166+mi(38,48) read `txfm_split_rect ctx=14` where aomdec reads `ctx=13`; the left
167+band held 4 (from the 8x8 at mi(38,42)) where libaom had 8 (published by the
168+non-intrabc 16x8 intra strip at mi(38,44), `tx_depth=0` -> `TX_16X8`,
169+`tx_size_high=8`), i.e. `left = 4 < 8` (true) instead of `8 < 8` (false). From
170+that wrong CDF row the tile desynced at the very next symbol.
171+
172+Fix: `publish_txfm_bands_if_in_inter`'s guard now also fires when
173+`allow_intrabc_frame(fctx)`, and the three missing readers above call it with
174+`depth_to_tx_wh(bw, bh, depth, fctx)` (one call each, placed before their
175+`depth != 0` split branch so both arms publish once).
176+
177+### Root cause 2 (stream B): a key frame never published the frame's `reduced_tx_set`
178+
179+`decode_key_frame_tile_with_cdfs` set `tx_select_inter=false` and the (r2)
180+`tx_select_frame`, but not `reduced_tx_set_inter`, which therefore kept its
181+`true` DEFAULT (or an inter frame's stale value). An intrabc block is
182+`is_inter_block`, so `read_tx_type` resolves its `tx_type` through the INTER
183+sets -- `av1_get_ext_tx_set_type` off `cm->features.reduced_tx_set_used`.
184+
185+Measured (512x384 testsrc2 cq45 `--enable-tx-size-search=0`): the first rect
186+(8x16) intrabc block at mi(80,106) read `tx_type` from a 2-symbol CDF
187+(`inter_tx_type_8`, `head=[4167,32768,0]`) where aomdec read the 16-symbol
188+`EXT_TX_SET_ALL16` row (`inter_ext_tx_cdf[1][TX_8X8]`,
189+`eset=1 set=5 sqr=1 nsym=16`, `head=[31123,30195,27990,27057]`); post-read
190+range 37912 vs 62176. Every earlier intrabc block in that frame was 16x16
191+(square), which never consults this cell, so the defect surfaced exactly at the
192+first rect strip.
193+
194+Fix: `decode_key_frame_tile_with_cdfs` now publishes the header's
195+`reduced_tx_set` into `fctx.reduced_tx_set_inter`, mirroring `tx_select_frame`.
196+
197+### State after the two fixes (no push; committed on the lane)
198+
199+| stream | bytes differ before | now |
200+|---|---|---|
201+| A 256x192 var-tx 16x8 | 4520/73728 | **BYTE-EXACT** (Y/U/V, `cmp` vs ffmpeg) |
202+| B 512x384 coded 8x16 | 7900/294912 | 528 luma samples |
203+
204+### What is STILL open on B (precise)
205+
206+The mode-info ladder is now fully IN SYNC (identical symbol sequence AND
207+identical post-read ranges through the end of the frame), and the residual
208+reads agree. The single remaining difference is a **DV VALUE**:
209+
210+```
211+O EC_DV mi_row=84 mi_col=104 dv_col=0 dv_row=-512 rng=33207
212+U EC_DV mi_row=84 mi_col=104 dv_col=0 dv_row=-504 rng=33207
213+```
214+
215+Same pre-range (33207 after the read on both sides) means the coded
216+`diff` is identical; the reconstructed DV differs because the **DV predictor**
217+differs. aomdec's own `EC_IBC` line for that block reads
218+`bsize=6 skip=1 nstack=2 nearest=(-520,0) near=(-512,0) dv_ref=(-520,0)
219+dv=(-512,0)`, i.e. `ref = nearest = -520`; our result `-504` is consistent with
220+`ref = -512` (the `nearmv`), so our intrabc `INTRA_FRAME` MV-stack ORDERING at
221+that block differs from libaom's (`av1_find_mv_refs` -> `setup_ref_mv_list` ->
222+`av1_find_best_ref_mvs`, then `dv_ref = nearestmv != 0 ? nearestmv : nearmv`).
223+
224+The 528 mismatched luma samples (`rows 351..383`, `cols 416..431`) are all
225+inside this one wrong copy: the block is `skip=1`, so the wrong DV is a wrong
226+pixel copy, and the region below it inherits the shift.
227+
228+Next step for whoever takes it: instrument `read_intrabc_dv`'s candidate
229+gathering (`record_intrabc_mi_rect` / the mv-stack build) with the candidate
230+list for mi(84,104) and diff it against aomdec's `EC_IBC`
231+`nstack/nearest/near/dv_ref` (already printed) -- the defect is candidate
232+ORDER/WEIGHT, not the DV syntax.
233+
234+### Gates run this round
235+
236+- `cargo check -p ec-av1 --all-targets` -> 0 warnings.
237+- Standalone: A byte-exact; B 528 luma samples (from 7900).
238+- **Not run**: the in-gate `--lib` arms, the refusal suite, and the full suite.
239+ The lane is NOT merge-ready (B is not byte-exact and the reviewer's
240+ TX_MODE_SELECT gate is still red); the batch-level suite run stays deferred.
241+
242+`deferred(DV-predictor candidate ordering at mi(84,104))`