A 1:4 intra strip in an inter frame publishes its TXFM_CONTEXT bands
Browse files at this commitd52f632baa11054329c6e5d9defa07a34908ee76Parent: e15b305- fix
- a 1:4 intra strip in an inter frame publishes its TXFM_CONTEXT bands
2 changed files +181 -1
- crates/ec-av1/src/decode.rs +81 -1
- lanes/t900-r1.handoff.md +100 -0
crates/ec-av1/src/decode.rsmodified+81 -1
| @@ -7540,6 +7540,16 @@ fn decode_intra_rect_in_inter( | |||
| 7540 | return Ok(()); | 7540 | return Ok(()); |
| 7541 | } | 7541 | } |
| 7542 | let mode = dec.symbol(&mut cdfs.y_mode[size_group]); | 7542 | let mode = dec.symbol(&mut cdfs.y_mode[size_group]); |
| 7543 | + // lane-t900 r1: this arm read six mode symbols with no ladder rung of its | ||
| 7544 | + // own, so a cross-decoder bisection could only see the block's first | ||
| 7545 | + // coefficient. Same names/format as [`read_tx_size`]'s rung. | ||
| 7546 | + let step_trace = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); | ||
| 7547 | + if step_trace { | ||
| 7548 | + eprintln!( | ||
| 7549 | + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=y_mode val={mode} grp={size_group} rng={}", | ||
| 7550 | + dec.debug_state().0 | ||
| 7551 | + ); | ||
| 7552 | + } | ||
| 7543 | if mode >= 13 { | 7553 | if mode >= 13 { |
| 7544 | return Err(unsupported( | 7554 | return Err(unsupported( |
| 7545 | "an intra mode this decoder does not code (round 2)", | 7555 | "an intra mode this decoder does not code (round 2)", |
| @@ -7565,6 +7575,13 @@ fn decode_intra_rect_in_inter( | |||
| 7565 | } else { | 7575 | } else { |
| 7566 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | 7576 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 7567 | }; | 7577 | }; |
| 7578 | + if step_trace { | ||
| 7579 | + eprintln!( | ||
| 7580 | + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=uv_mode val={uv_mode} cfl={} rng={}", | ||
| 7581 | + u8::from(cfl_allowed), | ||
| 7582 | + dec.debug_state().0 | ||
| 7583 | + ); | ||
| 7584 | + } | ||
| 7568 | if (9..=12).contains(&uv_mode) { | 7585 | if (9..=12).contains(&uv_mode) { |
| 7569 | SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1)); | 7586 | SMOOTH_UV_HITS.with(|h| h.set(h.get() + 1)); |
| 7570 | } | 7587 | } |
| @@ -7617,11 +7634,18 @@ fn decode_intra_rect_in_inter( | |||
| 7617 | // The INTER frame's own `TXFM_CONTEXT` bands, not the key frame's | 7634 | // The INTER frame's own `TXFM_CONTEXT` bands, not the key frame's |
| 7618 | // deblock-grid approximation -- [`tx_size_context_txfm_rect`]. | 7635 | // deblock-grid approximation -- [`tx_size_context_txfm_rect`]. |
| 7619 | let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64)); | 7636 | let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64)); |
| 7620 | - match tx_cat { | 7637 | + let d = match tx_cat { |
| 7621 | 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), | 7638 | 1 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), |
| 7622 | 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), | 7639 | 2 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), |
| 7623 | _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), | 7640 | _ => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), |
| 7641 | + }; | ||
| 7642 | + if step_trace { | ||
| 7643 | + eprintln!( | ||
| 7644 | + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat={tx_cat} rng={}", | ||
| 7645 | + dec.debug_state().0 | ||
| 7646 | + ); | ||
| 7624 | } | 7647 | } |
| 7648 | + d | ||
| 7625 | } else { | 7649 | } else { |
| 7626 | 0 | 7650 | 0 |
| 7627 | }; | 7651 | }; |
| @@ -8615,6 +8639,14 @@ fn decode_block_rect4( | |||
| 8615 | } else { | 8639 | } else { |
| 8616 | 0 | 8640 | 0 |
| 8617 | }; | 8641 | }; |
| 8642 | + // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra | ||
| 8643 | + // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`]. | ||
| 8644 | + publish_txfm_bands_if_in_inter( | ||
| 8645 | + neighbours, | ||
| 8646 | + (mi_r, mi_c), | ||
| 8647 | + depth_to_tx_wh(bw, bh, depth), | ||
| 8648 | + (bw, bh), | ||
| 8649 | + ); | ||
| 8618 | if depth != 0 { | 8650 | if depth != 0 { |
| 8619 | // lane-rectsplitx r1: the per-transform-unit walk, at this strip's | 8651 | // lane-rectsplitx r1: the per-transform-unit walk, at this strip's |
| 8620 | // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a | 8652 | // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a |
| @@ -9577,6 +9609,14 @@ fn decode_block_rect64( | |||
| 9577 | } else { | 9609 | } else { |
| 9578 | 0 | 9610 | 0 |
| 9579 | }; | 9611 | }; |
| 9612 | + // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra | ||
| 9613 | + // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`]. | ||
| 9614 | + publish_txfm_bands_if_in_inter( | ||
| 9615 | + neighbours, | ||
| 9616 | + (mi_r, mi_c), | ||
| 9617 | + depth_to_tx_wh(bw, bh, depth), | ||
| 9618 | + (bw, bh), | ||
| 9619 | + ); | ||
| 9580 | if depth != 0 { | 9620 | if depth != 0 { |
| 9581 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 9621 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 9582 | // lane-rectsplit r1/r4: the superblock-level strip splits its | 9622 | // lane-rectsplit r1/r4: the superblock-level strip splits its |
| @@ -13606,6 +13646,46 @@ fn txfm_partition_update( | |||
| 13606 | /// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): | 13646 | /// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): |
| 13607 | /// the left column records `tx_size_high` over the parent's own height and | 13647 | /// the left column records `tx_size_high` over the parent's own height and |
| 13608 | /// the above row records `tx_size_wide` over its width. | 13648 | /// the above row records `tx_size_wide` over its width. |
| 13649 | +/// libaom `set_txfm_ctxs` + `txfm_partition_update` (`decodeframe.c`, end of | ||
| 13650 | +/// `decode_token_recon_block`): EVERY block of an inter frame publishes its | ||
| 13651 | +/// TRANSFORM size into both `TXFM_CONTEXT` bands, intra blocks included. The | ||
| 13652 | +/// key frame writes neither (its readers use the deblock grid), so the | ||
| 13653 | +/// key-frame bodies reused by [`decode_intra_rect_in_inter`] have to do it | ||
| 13654 | +/// themselves when they run inside an inter frame. The 2:1 and 16x4 arms do it | ||
| 13655 | +/// at the call site (the transform size comes back to them); the 1:4 arms | ||
| 13656 | +/// ([`decode_block_rect4`] / [`decode_block_rect64`]) keep their size inside, | ||
| 13657 | +/// so they call this where their own depth resolves. A no-op on a key frame | ||
| 13658 | +/// ([`INTRA_IN_INTER_MODE`] unset), where those bands are not read at all. | ||
| 13659 | +/// | ||
| 13660 | +/// lane-t900 r1 root cause: the HORZ_4 32x8 intra strip at mi(0,312) of an | ||
| 13661 | +/// inter frame left `left_txfm[0]` at a stale 32 where libaom's own | ||
| 13662 | +/// `set_txfm_ctxs` writes 8, so the intra 8x16 block at mi(0,320) read | ||
| 13663 | +/// `tx_size_cat1` row 1 instead of row 0 -- same depth VALUE, different CDF, | ||
| 13664 | +/// range 39156 where the reference has 54736 (class tx-grid-published-block-side | ||
| 13665 | +/// / early-return-skips-tail). | ||
| 13666 | +fn publish_txfm_bands_if_in_inter( | ||
| 13667 | + n: &mut Neighbours, | ||
| 13668 | + at_mi: (usize, usize), | ||
| 13669 | + (tx_w, tx_h): (usize, usize), | ||
| 13670 | + (bw, bh): (usize, usize), | ||
| 13671 | +) { | ||
| 13672 | + if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_none() { | ||
| 13673 | + return; | ||
| 13674 | + } | ||
| 13675 | + let (mi_r, mi_c) = at_mi; | ||
| 13676 | + txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh)); | ||
| 13677 | + for i in 0..bw / MI { | ||
| 13678 | + if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { | ||
| 13679 | + *cell = tx_w as u8; | ||
| 13680 | + } | ||
| 13681 | + } | ||
| 13682 | + for i in 0..bh / MI { | ||
| 13683 | + if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { | ||
| 13684 | + *cell = tx_h as u8; | ||
| 13685 | + } | ||
| 13686 | + } | ||
| 13687 | +} | ||
| 13688 | + | ||
| 13609 | fn txfm_partition_update_rect( | 13689 | fn txfm_partition_update_rect( |
| 13610 | n: &mut Neighbours, | 13690 | n: &mut Neighbours, |
| 13611 | (mi_r, mi_c): (usize, usize), | 13691 | (mi_r, mi_c): (usize, usize), |
lanes/t900-r1.handoff.mdadded+100 -0
| @@ -0,0 +1,100 @@ | |||
| 1 | +# lane-t900 r1 handoff -- 1:4 intra strips in an inter frame never published their TXFM_CONTEXT bands | ||
| 2 | + | ||
| 3 | +Branch `lane-t900` (base main `5dd3dcb`), worktree `edith_codecs-t900`, | ||
| 4 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-t900`. | ||
| 5 | +Witness: `~/.cache/inter128intra-tmp/t900_2.obu` (2-frame cut of the 10-bit | ||
| 6 | +1920x792 128-superblock stream at 900 s). Ladders regenerated in one round in | ||
| 7 | +`~/.cache/t900-tmp/` (`o3.trace` ours `EC_TRACE_PART=1 EC_TRACE_MODE_STEP=1 | ||
| 8 | +EC_TRACE_MODE=1`, `aom.trace` aomdec `EC_TRACE=1 EC_TRACE_MODE=1 | ||
| 9 | +EC_TRACE_MODE_STEP=1`). | ||
| 10 | + | ||
| 11 | +## First diverging element -- before | ||
| 12 | + | ||
| 13 | +Last common symbol: `mi(24,312) tx_depth rng=38975` (filter-intra 32x32). | ||
| 14 | +First differing element, one superblock later: | ||
| 15 | + | ||
| 16 | +| | ours | aomdec | | ||
| 17 | +|---|---|---| | ||
| 18 | +| `mi(0,320)` `tx_depth` (BLOCK_8X16, cat 1) | val=1 **ctx=1** rng=**39156** | val=1 **ctx=0** rng=**54736** | | ||
| 19 | + | ||
| 20 | +Same VALUE, different CDF ROW -> different range. `EC_TXCTX mi=0,320 | ||
| 21 | +own=8x16 ... left_txfm=32 left=true` -- our left TXFM band held 32 where | ||
| 22 | +libaom's `set_txfm_ctxs` had written 8. | ||
| 23 | + | ||
| 24 | +## Root cause | ||
| 25 | + | ||
| 26 | +The block left of `mi(0,320)` is the first 32x8 strip of a `PARTITION_HORZ_4` | ||
| 27 | +at `mi(0,312)` -- an INTRA strip inside an INTER frame, decoded through the | ||
| 28 | +key frame's own body (`decode_block_rect4`). libaom runs `set_txfm_ctxs` + | ||
| 29 | +`txfm_partition_update` for EVERY block of an inter frame, intra ones | ||
| 30 | +included; the 2:1 arm and the 16x4 arm of `decode_intra_rect_in_inter` do that | ||
| 31 | +at their call sites (the transform size comes back to them), but the **1:4 | ||
| 32 | +arms** (`decode_block_rect4` for 32x8/8x32, `decode_block_rect64` for | ||
| 33 | +64x16/16x64) keep the size inside and published nothing, so both bands stayed | ||
| 34 | +stale across the strip's footprint for the rest of the frame. | ||
| 35 | +Classes: `tx-grid-published-block-side`, `early-return-skips-tail`. | ||
| 36 | + | ||
| 37 | +## Fix (path:line, this branch) | ||
| 38 | + | ||
| 39 | +- `crates/ec-av1/src/decode.rs` `publish_txfm_bands_if_in_inter()` (new, next | ||
| 40 | + to `txfm_partition_update_rect`): `txfm_partition_update_rect` + both | ||
| 41 | + `above_txfm`/`left_txfm` band writes, a no-op unless `INTRA_IN_INTER_MODE` | ||
| 42 | + is set (key frames unchanged, bands unread there). | ||
| 43 | +- called right after the depth symbol resolves in `decode_block_rect4` | ||
| 44 | + (32x8/8x32) and in `decode_block_rect64` (64x16/16x64) -- depth 0 included, | ||
| 45 | + which is the measured case. | ||
| 46 | +- three new `EC_TRACE_MODE_STEP` rungs in `decode_intra_rect_in_inter` | ||
| 47 | + (`y_mode`, `uv_mode`, `tx_depth` with ctx/cat): that arm read six mode | ||
| 48 | + symbols with no rung of its own, so a bisection could previously only see | ||
| 49 | + the block's first coefficient. | ||
| 50 | + | ||
| 51 | +## Ladder -- after | ||
| 52 | + | ||
| 53 | +`mi(0,320)` `tx_depth val=1 ctx=0 cat=1 rng=54736` == aomdec; | ||
| 54 | +`mi(0,322)` `rng=53468` == aomdec; next partition `mi(0,324) bsize=6 rng=36404` | ||
| 55 | +== aomdec. The superblock at mi(0,320) now matches element for element. | ||
| 56 | + | ||
| 57 | +Next difference in the deduped range ladder is at `mi(0,152)` (ours@15464 / | ||
| 58 | +aom@19643): aomdec prints `motion_mode val=2` (WARPED_CAUSAL) + `interp` for | ||
| 59 | +the 32x16 HORZ half, ours prints `txfm_split_rect` -- but BOTH decoders are | ||
| 60 | +back at `rng=37626` on the next block `mi(4,152)` and at `rng=37736` for its | ||
| 61 | +mv, so this is a RUNG-SET artifact (ours reads motion_mode without a rung), | ||
| 62 | +not a proven divergence. Confirm with a rung before treating it as a defect. | ||
| 63 | + | ||
| 64 | +## State of the cut | ||
| 65 | + | ||
| 66 | +- default path: `decode_probe` now walks frame 2 to the known 128x64 wall -- | ||
| 67 | + `REFUSED: an intra-coded 128x64 block on the inter block path` (that arrival | ||
| 68 | + is no longer downstream of a desync; the r1 report's "premise is a | ||
| 69 | + downstream artifact" verdict is now STALE). | ||
| 70 | +- `EC_INTRA128_IN_INTER=1`: **`OK: 1 frames decoded, 1920x792`, | ||
| 71 | + `intra128_in_inter: 128x64=15`** -- the whole 2-frame cut decodes, where r1 | ||
| 72 | + measured a Golomb-tail wall with 128x64=0. | ||
| 73 | + | ||
| 74 | +## Next step (in order) | ||
| 75 | + | ||
| 76 | +1. Pixel-compare the 2-frame cut vs ffmpeg (`EC_PROBE_OUT16`, census6/run6.sh | ||
| 77 | + recipe) with and without `EC_INTRA128_IN_INTER=1`. | ||
| 78 | +2. Re-run the full 2 s cuts `~/.cache/rectres-tmp/{t900,t5400,t6300,t8100}.obu` | ||
| 79 | + (frames, stop string, per-frame exact). | ||
| 80 | +3. If the firing frame is exact, pin the smallest exact prefix | ||
| 81 | + (census4/trunc.py) as `crates/ec-av1/fixtures/reelc_intra128_witness.obu` | ||
| 82 | + (`git add -f` + sha256), gate every plane / every decode-order frame with a | ||
| 83 | + hard counter assert, lift the refusal, drop `EC_INTRA128_IN_INTER`, update | ||
| 84 | + `refusal_inventory.rs` + `gate_coverage.rs`. | ||
| 85 | +4. Full suite as a systemd unit (COMMON recipe). NOT RUN this round. | ||
| 86 | +5. Sibling sweep owed: every other caller of `decode_block_rect4` / | ||
| 87 | + `decode_block_rect64` under `INTRA_IN_INTER_MODE`, and the same | ||
| 88 | + publication question for `decode_block_rect` (2:1 key-frame body) if it is | ||
| 89 | + ever reached in-inter. | ||
| 90 | + | ||
| 91 | +## Deviations | ||
| 92 | + | ||
| 93 | +- Charter forbids rebase/merge, COMMON requires rebasing onto main first: the | ||
| 94 | + charter wins, so this branch is still on `5dd3dcb` and does NOT carry main's | ||
| 95 | + `5d81a67` (vartxsplit) commits. The coordinator's note that main fixed | ||
| 96 | + `decode_block_rect4`'s three exits refers to the frame36 r2 work already in | ||
| 97 | + this base (`6202717`); that fix covers the SPLIT/return tails, not the | ||
| 98 | + inter-frame band publication fixed here -- verified by the measured stale | ||
| 99 | + `left_txfm=32`. | ||
| 100 | +- Suite not run (coordinator instruction). `cargo check -p ec-av1` clean. | ||