From 7fb533fa99c91c8580b3ed4cde69c3b2da050f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 24 Sep 2026 23:14:43 +0300 Subject: [PATCH] av1intrapred: arm INTRABC_CHROMA_TX for leaf8 TX4-split intrabc leaves decode_leaf8's resolved==4 (TX4 var-tx split) arm read each luma 4x4 TU off the 16-symbol inter tx_type set (correct) but never armed INTRABC_CHROMA_TX, so the group's chroma reads fell back to default_intra_tx_type(DC_PRED) = DCT_DCT and took the 2D eob row, 2D scan and 2D nz contexts where libaom (which classifies intrabc as is_inter_block) inherits the co-located luma TU's coded type. R5's first fork, mi (36,66): luma TU (0,0) coded H_ADST, chroma U decoded eob=11 off the 2D row where aomdec decoded eob=13 off the class-1 row. Also disarm the slot after the arm's two chroma reads: left set, the next leaf's chroma inherited the intrabc leaf's luma type instead of its own derivation (seen live at mi (54,24)). Gates: R5 entropy now aligns 3321/3321 all_zero reads rng-for-rng vs instrumented aomdec (was 2162); luma byte-exact; first pixel diff moved 82216 -> 231864, total chroma diffs 127862 -> 3305. W2 (cq8 re-encode) 352 -> 231848, 305032 -> 3254. R9 stays byte-exact vs ffmpeg. Suite: 607 passed / 0 failed (exit 0). Remaining chroma diffs are a new class - intrabc chroma frame-copy prediction (origin U(184,4), block mi (2,92), entropy identical) - documented with a trace line in the lane report. --- crates/ec-av1/src/decode.rs | 32 +++++++++++++++++ lanes/av1intrapred.report.md | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d101dc8a..9cc66916 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -17255,6 +17255,7 @@ fn decode_leaf8( // 8x8 `mode` and reading its own fresh context off the earlier // units in this same leaf (the same per-TU pattern `decode_block`'s // multi-TU branch runs at bigger blocks). + let mut first_leaf_tx: Option = None; for tu_row in 0..2 { for tu_col in 0..2 { let tu_mi = (leaf_mi.0 + tu_row, leaf_mi.1 + tu_col); @@ -17327,6 +17328,28 @@ fn decode_leaf8( ); } neighbours.record_mi_luma(tu_mi, 4, &tu_grid); + // The FIRST (top-left, co-located with this group's chroma) + // TU's coded tx_type is what the group's chroma inherits -- + // the same capture [`decode_block`]'s multi-TU branch makes + // for `first_leaf_tx` (libaom `av1_get_tx_type`, blockd.h: + // an inter-classified block's `PLANE_TYPE_UV` reads + // `tx_type_map`, and intrabc is inter-classified). + if first_leaf_tx.is_none() { + first_leaf_tx = Some(fctx.luma_tx_type.with(std::cell::Cell::get)); + } + } + } + // lane-av1intrapred: an intrabc leaf whose var-tx tree split to + // TX_4X4 never armed [`INTRABC_CHROMA_TX`], so its chroma reads fell + // back to `default_intra_tx_type(DC_PRED)` = `DCT_DCT` and took the + // 2D scan, the 2D eob row and the 2D nz contexts where libaom takes + // the inherited luma type's (R5's first fork: mi (36,66), luma + // (0,0) coded `H_ADST` off the 16-symbol inter set, chroma U then + // decoded its `eob` from the wrong CDF row). Same arm the + // `resolved != 4` branch above runs for its whole-leaf unit. + if intrabc_dv.is_some() { + if let Some(t) = first_leaf_tx { + fctx.intrabc_chroma_tx.with(|c| c.set(Some(t))); } } let ac = alpha.map(|_| cfl_src(px, py, 8)); @@ -17381,6 +17404,15 @@ fn decode_leaf8( None, smooth_neighbor_uv, fctx, )?; + // The two chroma reads above are the only consulters of this leaf's + // armed [`INTRABC_CHROMA_TX`]; leaving it set would make the NEXT + // leaf's chroma inherit this leaf's luma type instead of its own + // derivation (class armed-slot-leak-into-next-leaf, seen live: the + // regular-intra leaf after an intrabc TX4 leaf took the intrabc + // luma's `V_ADST` for its chroma eob row). + if intrabc_dv.is_some() { + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } // `record_split_luma` expects a `record`-style `(r, c)` position in // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is // already in mi units, so calling it here double-scaled the diff --git a/lanes/av1intrapred.report.md b/lanes/av1intrapred.report.md index 73ad4cab..cdf199ce 100644 --- a/lanes/av1intrapred.report.md +++ b/lanes/av1intrapred.report.md @@ -68,3 +68,73 @@ which I could not complete within this run's budget. * The oracle build `~/.cache/aom-oracle` gained extra env-gated probes during this hunt (EC_R5CELL, EC_ROWS8, `cdf0=` in the all_zero line, EC_DBGCTX retargeted to mi 36,66). They are env-gated and outside the repo; retarget/keep as needed. + +--- + +# lane-av1-intrapred r2 — the reported CDF fork is FIXED; next fork is intrabc chroma prediction + +Base 3f6748d5, same worktree/branch. The reported "chroma txb_skip CDF-content" fork was +neither the Chroma4 defaults (all four q tables match aom `token_cdfs.h` exactly) nor the +adaptation — it was the missing `INTRABC_CHROMA_TX` arming in `decode_leaf8`'s TX4 arm. + +## Root cause (machine-checked against `~/.cache/aom-oracle` R5 traces) + +* mi (36,66) is an **intrabc** 8x8 leaf whose var-tx tree split luma to 4x TX_4X4. + libaom classifies intrabc as `is_inter_block` (`blockd.h:373`), so: + * each luma TU codes `tx_type` off the **16-symbol inter set** + (`av1_get_ext_tx_set_type(TX_4X4, inter=1)` = `EXT_TX_SET_ALL16`) — TU (0,0) coded + `H_ADST(13)` in R5; + * each chroma TU **inherits** the co-located luma type (`av1_get_tx_type`'s + `is_inter_block` branch reads `tx_type_map`) → class `TX_CLASS_HORIZ` → the class-1 + `eob_flag_cdf16[1][1]` row, the HORIZ scan and the HORIZ nz-context offsets. +* `decode_leaf8`'s `resolved != 4` arm already armed `INTRABC_CHROMA_TX`; the + `resolved == 4` (TX4) arm did not. Its chroma reads fell back to + `default_intra_tx_type(DC_PRED)` = `DCT_DCT` → 2D eob row → at the U txb of (36,66) + ours decoded `eob=11` where aomdec decoded `eob=13` (same entry rng 44076), and the + tile desynced one read later than the all_zero ladder could see. +* The r5-era `tx_type` handling of the luma side was already correct (ours read the same + 16-symbol symbol and got `H_ADST`); only the chroma arming was missing. + +## Fix (two hunks in `decode_leaf8`, decode.rs) + +1. TX4 arm: capture the first TU's `tx_type` (`first_leaf_tx`, mirroring `decode_block`'s + multi-TU capture) and arm `INTRABC_CHROMA_TX` with it before the group's chroma reads. +2. TX4 arm: disarm the slot after the two chroma reads — without this the slot leaked + into the NEXT leaf (seen live: a regular-intra leaf at mi (54,24) took the previous + intrabc leaf's `V_ADST` for its chroma eob row). + +## Gates (all machine-captured, same fixtures as the stop report) + +* R5 (`~/.cache/av1ibcvtx-tmp/R5.obu`): pre-fix first diff byte 82216 / 127862 differing + bytes → post-fix first diff byte **231864** / 3305 differing bytes (luma byte-exact; + aomdec and ffmpeg agree with each other, sha256 `c91229ee…` both). +* W2 (re-encoded at `--cq-level=8`, `/tmp/w2.obu` — the report's W2 was not in the cache): + pre-fix first diff byte 352 (report said 353 ✓ reproduces) / 305032 diffs → post-fix + 231848 / 3254. 23x further into the stream, 94x fewer diffs. +* R9 (smptebars): still byte-exact vs ffmpeg post-fix (regression clean). +* Entropy: ALL 3321 `all_zero` reads now align 1:1 rng-for-rng against the instrumented + aomdec (was 2162/4248). +* Pre-fix non-vacuity: scratch worktree at 3f6748d5 rebuild reproduces the byte-352 fork + on W2 and byte-82216 on R5. + +## Next fork (new class — NOT entropy, NOT the ticket's CDF fork) + +`R5` first differing byte 231864 = chroma U pixel **(184,4)**; 3305 differing bytes, all +chroma (U 1730 / V 1575), origin unit = the chroma 4x4 at cpx (184,4), i.e. the 8x8 +**intrabc** leaf at luma (368,8), mi **(2,92)**, var-tx TX4 split, luma TU (1,0) coded +`H_ADST`, TU (0,0) `DCT_DCT`, chroma inherits `DCT_DCT` on BOTH sides (ours: probe slot +`Some(DctDct)`; aom: `EC_TXTYPE mi=2,92 plane=1 tx_type=0`). The full symbol stream is +aligned (3321/3321 `all_zero` reads, rng-identical), luma is byte-exact, so this is a +**prediction-stage** divergence: the intrabc chroma frame-copy (bilinear at the chroma +half-pel phase of the block DV) produces different samples than aomdec for this unit and +everything predicted off it. Trace line: + +``` +R5: ours U(184,4)=[103,97,107,101] aom=[86,116,55,110]; entropy identical + (read 2428 U / 2429 V of block mi (2,92) match through their coefficients); + suspect the chroma DV rounding/clamp in the leaf8 intrabc_bufs path + (mv_to_q4(cpx, dv_col, false) — odd-DV chroma phase) vs libaom's + av1_predict_intra_block intrabc clamp. +``` + +W2 shows the same signature (first diff U(168,4), byte 231848).