diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2f810b6a..13e456d1 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -7540,6 +7540,16 @@ fn decode_intra_rect_in_inter( return Ok(()); } let mode = dec.symbol(&mut cdfs.y_mode[size_group]); + // lane-t900 r1: this arm read six mode symbols with no ladder rung of its + // own, so a cross-decoder bisection could only see the block's first + // coefficient. Same names/format as [`read_tx_size`]'s rung. + let step_trace = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); + if step_trace { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=y_mode val={mode} grp={size_group} rng={}", + dec.debug_state().0 + ); + } if mode >= 13 { return Err(unsupported( "an intra mode this decoder does not code (round 2)", @@ -7565,6 +7575,13 @@ fn decode_intra_rect_in_inter( } else { dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) }; + if step_trace { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=uv_mode val={uv_mode} cfl={} rng={}", + u8::from(cfl_allowed), + dec.debug_state().0 + ); + } if (9..=12).contains(&uv_mode) { SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1)); } @@ -7617,11 +7634,18 @@ fn decode_intra_rect_in_inter( // The INTER frame's own `TXFM_CONTEXT` bands, not the key frame's // deblock-grid approximation -- [`tx_size_context_txfm_rect`]. let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64)); - match tx_cat { + let d = match tx_cat { 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), + }; + if step_trace { + eprintln!( + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat={tx_cat} rng={}", + dec.debug_state().0 + ); } + d } else { 0 }; @@ -8615,6 +8639,14 @@ fn decode_block_rect4( } else { 0 }; + // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra + // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`]. + publish_txfm_bands_if_in_inter( + neighbours, + (mi_r, mi_c), + depth_to_tx_wh(bw, bh, depth), + (bw, bh), + ); if depth != 0 { // lane-rectsplitx r1: the per-transform-unit walk, at this strip's // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a @@ -9577,6 +9609,14 @@ fn decode_block_rect64( } else { 0 }; + // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra + // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`]. + publish_txfm_bands_if_in_inter( + neighbours, + (mi_r, mi_c), + depth_to_tx_wh(bw, bh, depth), + (bw, bh), + ); if depth != 0 { TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); // lane-rectsplit r1/r4: the superblock-level strip splits its @@ -13606,6 +13646,46 @@ fn txfm_partition_update( /// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): /// the left column records `tx_size_high` over the parent's own height and /// the above row records `tx_size_wide` over its width. +/// libaom `set_txfm_ctxs` + `txfm_partition_update` (`decodeframe.c`, end of +/// `decode_token_recon_block`): EVERY block of an inter frame publishes its +/// TRANSFORM size into both `TXFM_CONTEXT` bands, intra blocks included. The +/// key frame writes neither (its readers use the deblock grid), so the +/// key-frame bodies reused by [`decode_intra_rect_in_inter`] have to do it +/// themselves when they run inside an inter frame. The 2:1 and 16x4 arms do it +/// at the call site (the transform size comes back to them); the 1:4 arms +/// ([`decode_block_rect4`] / [`decode_block_rect64`]) keep their size inside, +/// so they call this where their own depth resolves. A no-op on a key frame +/// ([`INTRA_IN_INTER_MODE`] unset), where those bands are not read at all. +/// +/// lane-t900 r1 root cause: the HORZ_4 32x8 intra strip at mi(0,312) of an +/// inter frame left `left_txfm[0]` at a stale 32 where libaom's own +/// `set_txfm_ctxs` writes 8, so the intra 8x16 block at mi(0,320) read +/// `tx_size_cat1` row 1 instead of row 0 -- same depth VALUE, different CDF, +/// range 39156 where the reference has 54736 (class tx-grid-published-block-side +/// / early-return-skips-tail). +fn publish_txfm_bands_if_in_inter( + n: &mut Neighbours, + at_mi: (usize, usize), + (tx_w, tx_h): (usize, usize), + (bw, bh): (usize, usize), +) { + if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_none() { + return; + } + let (mi_r, mi_c) = at_mi; + txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh)); + for i in 0..bw / MI { + if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { + *cell = tx_w as u8; + } + } + for i in 0..bh / MI { + if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { + *cell = tx_h as u8; + } + } +} + fn txfm_partition_update_rect( n: &mut Neighbours, (mi_r, mi_c): (usize, usize), diff --git a/lanes/t900-r1.handoff.md b/lanes/t900-r1.handoff.md new file mode 100644 index 00000000..f4979cb7 --- /dev/null +++ b/lanes/t900-r1.handoff.md @@ -0,0 +1,100 @@ +# lane-t900 r1 handoff -- 1:4 intra strips in an inter frame never published their TXFM_CONTEXT bands + +Branch `lane-t900` (base main `5dd3dcb`), worktree `edith_codecs-t900`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900`. +Witness: `~/.cache/inter128intra-tmp/t900_2.obu` (2-frame cut of the 10-bit +1920x792 128-superblock stream at 900 s). Ladders regenerated in one round in +`~/.cache/t900-tmp/` (`o3.trace` ours `EC_TRACE_PART=1 EC_TRACE_MODE_STEP=1 +EC_TRACE_MODE=1`, `aom.trace` aomdec `EC_TRACE=1 EC_TRACE_MODE=1 +EC_TRACE_MODE_STEP=1`). + +## First diverging element -- before + +Last common symbol: `mi(24,312) tx_depth rng=38975` (filter-intra 32x32). +First differing element, one superblock later: + +| | ours | aomdec | +|---|---|---| +| `mi(0,320)` `tx_depth` (BLOCK_8X16, cat 1) | val=1 **ctx=1** rng=**39156** | val=1 **ctx=0** rng=**54736** | + +Same VALUE, different CDF ROW -> different range. `EC_TXCTX mi=0,320 +own=8x16 ... left_txfm=32 left=true` -- our left TXFM band held 32 where +libaom's `set_txfm_ctxs` had written 8. + +## Root cause + +The block left of `mi(0,320)` is the first 32x8 strip of a `PARTITION_HORZ_4` +at `mi(0,312)` -- an INTRA strip inside an INTER frame, decoded through the +key frame's own body (`decode_block_rect4`). libaom runs `set_txfm_ctxs` + +`txfm_partition_update` for EVERY block of an inter frame, intra ones +included; the 2:1 arm and the 16x4 arm of `decode_intra_rect_in_inter` do that +at their call sites (the transform size comes back to them), but the **1:4 +arms** (`decode_block_rect4` for 32x8/8x32, `decode_block_rect64` for +64x16/16x64) keep the size inside and published nothing, so both bands stayed +stale across the strip's footprint for the rest of the frame. +Classes: `tx-grid-published-block-side`, `early-return-skips-tail`. + +## Fix (path:line, this branch) + +- `crates/ec-av1/src/decode.rs` `publish_txfm_bands_if_in_inter()` (new, next + to `txfm_partition_update_rect`): `txfm_partition_update_rect` + both + `above_txfm`/`left_txfm` band writes, a no-op unless `INTRA_IN_INTER_MODE` + is set (key frames unchanged, bands unread there). +- called right after the depth symbol resolves in `decode_block_rect4` + (32x8/8x32) and in `decode_block_rect64` (64x16/16x64) -- depth 0 included, + which is the measured case. +- three new `EC_TRACE_MODE_STEP` rungs in `decode_intra_rect_in_inter` + (`y_mode`, `uv_mode`, `tx_depth` with ctx/cat): that arm read six mode + symbols with no rung of its own, so a bisection could previously only see + the block's first coefficient. + +## Ladder -- after + +`mi(0,320)` `tx_depth val=1 ctx=0 cat=1 rng=54736` == aomdec; +`mi(0,322)` `rng=53468` == aomdec; next partition `mi(0,324) bsize=6 rng=36404` +== aomdec. The superblock at mi(0,320) now matches element for element. + +Next difference in the deduped range ladder is at `mi(0,152)` (ours@15464 / +aom@19643): aomdec prints `motion_mode val=2` (WARPED_CAUSAL) + `interp` for +the 32x16 HORZ half, ours prints `txfm_split_rect` -- but BOTH decoders are +back at `rng=37626` on the next block `mi(4,152)` and at `rng=37736` for its +mv, so this is a RUNG-SET artifact (ours reads motion_mode without a rung), +not a proven divergence. Confirm with a rung before treating it as a defect. + +## State of the cut + +- default path: `decode_probe` now walks frame 2 to the known 128x64 wall -- + `REFUSED: an intra-coded 128x64 block on the inter block path` (that arrival + is no longer downstream of a desync; the r1 report's "premise is a + downstream artifact" verdict is now STALE). +- `EC_INTRA128_IN_INTER=1`: **`OK: 1 frames decoded, 1920x792`, + `intra128_in_inter: 128x64=15`** -- the whole 2-frame cut decodes, where r1 + measured a Golomb-tail wall with 128x64=0. + +## Next step (in order) + +1. Pixel-compare the 2-frame cut vs ffmpeg (`EC_PROBE_OUT16`, census6/run6.sh + recipe) with and without `EC_INTRA128_IN_INTER=1`. +2. Re-run the full 2 s cuts `~/.cache/rectres-tmp/{t900,t5400,t6300,t8100}.obu` + (frames, stop string, per-frame exact). +3. If the firing frame is exact, pin the smallest exact prefix + (census4/trunc.py) as `crates/ec-av1/fixtures/reelc_intra128_witness.obu` + (`git add -f` + sha256), gate every plane / every decode-order frame with a + hard counter assert, lift the refusal, drop `EC_INTRA128_IN_INTER`, update + `refusal_inventory.rs` + `gate_coverage.rs`. +4. Full suite as a systemd unit (COMMON recipe). NOT RUN this round. +5. Sibling sweep owed: every other caller of `decode_block_rect4` / + `decode_block_rect64` under `INTRA_IN_INTER_MODE`, and the same + publication question for `decode_block_rect` (2:1 key-frame body) if it is + ever reached in-inter. + +## Deviations + +- Charter forbids rebase/merge, COMMON requires rebasing onto main first: the + charter wins, so this branch is still on `5dd3dcb` and does NOT carry main's + `5d81a67` (vartxsplit) commits. The coordinator's note that main fixed + `decode_block_rect4`'s three exits refers to the frame36 r2 work already in + this base (`6202717`); that fix covers the SPLIT/return tails, not the + inter-frame band publication fixed here -- verified by the measured stale + `left_txfm=32`. +- Suite not run (coordinator instruction). `cargo check -p ec-av1` clean.