From a0c409b88f80fb677020f3e22d84a049b5e89e54 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 20:36:31 +0300 Subject: [PATCH] fix(av1): rect intra leaves inside an inter frame read the deblock-grid tx-depth context (sibling sweep) Class sweep of the measured `decode_block_rect4` defect: `decode_leaf_rect` and `decode_leaf_rect8` still built their tx-depth CDF row from [`tx_size_context_rect`] (the key frame's deblock-grid approximation) where libaom's `get_tx_size_context` reads the `TXFM_CONTEXT` bands for every block of an inter frame. No-op unless `INTRA_IN_INTER_MODE` is set, i.e. key frames are byte-identical. Unmeasured on their own (the measured instance is the 32x8 strip at mi(48,176) of the 10-bit 1920x792 128-superblock stream) -- kept in a separate commit so it can be reverted without losing that fix. lanes/t900-r2.handoff.md carries the ladder state, the next divergence (a chroma txb_skip context row) and the gate that was red mid-suite when the round ended. --- crates/ec-av1/src/decode.rs | 16 ++++- lanes/t900-r2.handoff.md | 136 ++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 lanes/t900-r2.handoff.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index fed8c573..3dceade4 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -8344,7 +8344,13 @@ fn decode_leaf_rect( // a constant `false`. let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh); + // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band read + // every other rect reader now does -- a no-op on a key frame. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, leaf_mi, bw, bh) + } else { + tx_size_context_rect(neighbours, leaf_mi, bw, bh) + }; // lane-rectsplitx r1: `bsize_to_tx_size_cat` (libaom `blockd.h`, // `bsize_to_tx_size_depth_table`) is 2 for BLOCK_16X8/BLOCK_8X16, so // the category is 1 -- NOT the 2 the 32x16 strips read. Same symbol @@ -13084,7 +13090,13 @@ fn decode_leaf_rect8( // and desynced the tile at the very first rect leaf (class // `symbol-consumption-gap`). let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, lmi, bw, bh); + // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band + // read every other rect reader now does -- a no-op on a key frame. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, lmi, bw, bh) + } else { + tx_size_context_rect(neighbours, lmi, bw, bh) + }; dec.symbol(&mut cdfs.tx_size_cat0[ctx]) } else { 0 diff --git a/lanes/t900-r2.handoff.md b/lanes/t900-r2.handoff.md new file mode 100644 index 00000000..1b4b3d79 --- /dev/null +++ b/lanes/t900-r2.handoff.md @@ -0,0 +1,136 @@ +# lane-t900 r2 handoff -- in-inter rect tx-depth context; next wall is the chroma txb_skip ctx + +Branch `lane-t900`, worktree `edith_codecs-t900`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900` (a second `-t900-b` dir was +used for `cargo check` while the suite unit held the first). + +## STEP 1 -- merge of main `5d81a67` (commit `85ce8ff`) + +One conflict, `crates/ec-av1/src/decode.rs`, in the 2:1 intra-in-inter +`tx_depth` rung: HEAD's cached `step_trace` bool vs main's inline +`std::env::var_os("EC_TRACE_MODE_STEP")`. Resolved to HEAD's `step_trace` +(same condition, one env read per block instead of per symbol). + +Publication per exit: NOT one write per exit, but every write is IDENTICAL. +`publish_txfm_bands_if_in_inter` sits right after the depth symbol in +`decode_block_rect4` / `decode_block_rect64` and covers every later exit; +frame36's `txfm_partition_update_rect` tails sit before the split arms' +`return Ok(...)`. Both write `depth_to_tx_wh(bw, bh, depth)` over the same +(bw,bh) footprint, so the split arms write the same bytes twice -- idempotent, +no double-update hazard. Left as-is deliberately (removing either one loses a +different exit). `publish_txfm_bands_if_in_inter` itself also duplicates +`txfm_partition_update_rect`'s two loops with the same values; harmless. + +`cargo check -p ec-av1`: clean. Re-ladder of `t900_2.obu` after the merge: +`mi(0,320) tx_depth val=1 ctx=0 cat=1 rng=54736` still == aomdec, r1's fix +survived the merge. + +## STEP 2 -- ROOT CAUSE FOUND AND FIXED (commit after this file) + +The in-inter `tx_depth` CDF row of a 1:4 strip came from the KEY FRAME's +deblock-grid approximation (`tx_size_context_rect`) instead of the real +`TXFM_CONTEXT` bands (`tx_size_context_txfm_rect`). The 2:1 arm +(decode.rs:7660) and the 16x4 strip (`decode_rect4_16_strip`) already switched +on `INTRA_IN_INTER_MODE`; `decode_block_rect4`, `decode_block_rect64`, +`decode_block_rect` and (sweep) `decode_leaf_rect`, `decode_leaf_rect8` did +not. + +Measured on the 2-frame cut (10-bit 1920x792, 128-superblock), decode-order +frame 1: the 32x8 `PARTITION_HORZ_4` strip at mi(48,176) read `tx_size_cat2` +row 1 where libaom reads row 2 (`EC_TXCTX ... above_px=16 left_px=32 ctx=1` +vs aomdec `ctx=2`). Ladder before: sustained divergence from mi(48,176). +Ladder after: exact through mi(40,221) (`tx_depth val=0 ctx=2 cat=1 +rng=40539` == aomdec), ~230 more oracle symbols. + +New rungs added so a ladder can see the symbol at all (this is what made r1's +bisection stop one block short): `EC_ISTEP ... name=tx_depth val= ctx= cat=` +in `decode_block_rect4` (cat 2), `decode_block_rect` (cat 2), +`decode_block_rect64` (cat 3), `decode_rect4_16_strip` (cat 1). + +## NEXT DIVERGENCE (exact, do not re-bisect) + +Block mi(40,222): strip 2 of a `PARTITION_VERT_4` of the 16x16 at mi(40,220) +(four 4x16 strips, cols 220..223; strip 0 inter, 1..3 intra-in-inter). +Everything through strip 1's luma TU matches. The first differing symbol is +strip 1's CHROMA `all_zero` (txb_skip): + +| | ours | aomdec | +|---|---|---| +| plane 1 `all_zero` (entry rng=37582) | ctx base **1** -> rng **37384** | ctx **9** (= base 2 + chroma offset 7) -> rng **51992** | +| plane 2 `all_zero` | ctx base 1 -> rng 36800 | ctx 9 -> rng 33312 | + +Same VALUES (1 then 0), different CDF ROW. Our chroma skip ctx is built at +`decode_rect4_16_strip`'s chroma call (`let skip_ctx = usize::from(around[plane].0) ++ usize::from(around[plane].1)`, decode.rs ~9480, feeding `read_coeffs_rect` +with `TxbSet::ChromaRect8x4`): the base is 1 where libaom's `get_txb_ctx` +gathers 2. The suspect is the chroma entropy-context map an INTER neighbour +writes (the strip's left/above chroma neighbour here is an inter block), i.e. +class `new-map-ignores-tile-edge` / `context-read-from-one-cell` on the chroma +side -- verify with `EC_DCDUMP`/`around_mi_rect` on the pair mi, and check +whether the inter chroma TU path records that map at all. Reproduce: + + systemd-run --user --scope -q -p MemoryMax=6G env EC_INTRA128_IN_INTER=1 \ + EC_TRACE_COEFF=1 /release/examples/decode_probe \ + ~/.cache/inter128intra-tmp/t900_2.obu 2>&1 | grep -n 'entry=37582' + + (oracle: `EC_TRACE_COEFF=1 ~/.cache/aom-oracle/build/aomdec --codec=av1 \ + -o /dev/null ~/.cache/inter128intra-tmp/t900_2.obu`, line ~475902.) + +## Film state (decode-order frame compare vs instrumented aomdec, EC_AV1_FINAL_DUMP) + +| cut | aomdec frames | ours | f0 | first differing frame | +|---|---|---|---|---| +| 2-frame cut of the 900 s cut | 2 | OK 1 shown | EXACT | 1 (1924240 B, was 2134171 B before the fix) | +| 2 s at 900 s | 267 | REFUSED Golomb tail after 2 | EXACT | 1 | +| 2 s at 5400 s | 275 | REFUSED Golomb tail after 10 | EXACT | 1 | +| 2 s at 6300 s | 125 | (run cut short) | EXACT | 1 | + +So the intra128 witness route is still blocked: no cut is exact through a +frame that fires `intra128_in_inter`, therefore NO fixture was pinned, NO +refusal was lifted, and `refusal_inventory.rs` / `gate_coverage.rs` are +untouched. `EC_INTRA128_IN_INTER` remains opt-in. + +## Suite + +Unit `t900-suite-r2-1788370358` (MemoryMax=10G), log `$HOME/.cache/t900-suite.log`, +was still running at the turn cap and is INCOMPLETE. What it had produced: +`a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact` +**FAILED** (no panic text captured yet -- the log was mid-run). That gate is +the prime suspect for the `decode_block_rect64` / `decode_leaf_rect*` arms of +the ctx switch: re-run it FIRST + + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900 EC_NOMEMGUARD=1 \ + EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ + a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus -- --nocapture + +and, if it is this lane's change, bisect the switch per reader (rect4 alone is +the measured one; rect64 / rect / leaf_rect / leaf_rect8 were a class sweep +with no measurement of their own -- reverting those four is the cheap +fallback). Note the sweep commit is SEPARATE from the measured rect4/rect64 +commit for exactly that reason. + +## Next step list + +1. Re-run the failing 16x4/rect64 gate; if red from this lane, bisect the five + ctx switches (rect4 is measured; the other four are unmeasured sweep). +2. Full suite as a systemd unit (COMMON recipe) and compare totals with + 424 passed / 1 pre-existing failure / 37 ignored. +3. Fix the chroma txb_skip ctx above; re-run the decode-order compare + (`~/.cache/t900-tmp/cmp.sh `, aomdec+ours EC_AV1_FINAL_DUMP, + per-frame byte diff) on `t900_2.obu` until frame 1 is exact. +4. Only then: pin the smallest exact firing prefix (census4/trunc.py) as + `crates/ec-av1/fixtures/reelc_intra128_witness.obu` (`git add -f`, hash + twice), gate every plane of every decode-order frame with a hard + `intra128_in_inter` counter assert, lift the refusal, drop + `EC_INTRA128_IN_INTER`, update `refusal_inventory.rs` + `gate_coverage.rs`. +5. Re-probe `~/.cache/reelc-0-10s.obu` (not run this round). + +## Artifacts + +- `~/.cache/t900-tmp/cmp.sh` -- decode-order frame compare (aomdec vs ours). +- `~/.cache/t900-tmp/{aom_full.trace,ours_full.trace}` -- mode/part ladders, + same round; `{aom_coeff.trace,ours_coeff.trace}` -- `EC_TRACE_COEFF` ladders. +- `~/.cache/t900-tmp/cuts.log` -- the film table above. +- Ladder matcher: greedy in-order match on `(mi_row, mi_col, name, rng)` of + `EC_ISTEP` lines with a 200-entry window -- `difflib` on the deduped rng + sequence is USELESS here (our extra rungs make every hunk an insert).