Counter for rect intra-in-inter blocks whose tx_depth CDF row moved under the inter-neighbour override
Browse files at this commita0c69515a9d2621b5ffe147e03585891eeeee04fParent: 1ca3e1b- feat
- counter for rect intra-in-inter blocks whose tx_depth CDF row moved under the inter-neighbour override
2 changed files +98 -1
- crates/ec-av1/src/decode.rs +27 -1
- lanes/midcut-r2.handoff.md +71 -0
crates/ec-av1/src/decode.rsmodified+27 -1
| @@ -2389,6 +2389,19 @@ pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] { | |||
| 2389 | INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) | 2389 | INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) |
| 2390 | } | 2390 | } |
| 2391 | 2391 | ||
| 2392 | +// lane-midcut r2: rect intra blocks inside an inter frame whose `tx_depth` CDF | ||
| 2393 | +// ROW moved when libaom's inter-neighbour override was applied -- i.e. exactly | ||
| 2394 | +// the blocks the key frame's deblock-grid approximation used to mis-read. | ||
| 2395 | +thread_local! { | ||
| 2396 | + static INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS: std::cell::Cell<usize> = | ||
| 2397 | + const { std::cell::Cell::new(0) }; | ||
| 2398 | +} | ||
| 2399 | + | ||
| 2400 | +/// Current value of [`INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS`]. | ||
| 2401 | +pub(crate) fn intra_rect_in_inter_txctx_override_hits() -> usize { | ||
| 2402 | + INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS.with(std::cell::Cell::get) | ||
| 2403 | +} | ||
| 2404 | + | ||
| 2392 | // lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER | 2405 | // lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER |
| 2393 | // block path, per shape -- [0] 64x16, [1] 16x64, [2] 32x8, [3] 8x32. Every | 2406 | // block path, per shape -- [0] 64x16, [1] 16x64, [2] 32x8, [3] 8x32. Every |
| 2394 | // one of them was the named refusal "an intra-coded 1:4 (or other non-2:1) | 2407 | // one of them was the named refusal "an intra-coded 1:4 (or other non-2:1) |
| @@ -6747,7 +6760,20 @@ fn tx_size_context_rect( | |||
| 6747 | // var-tx tree had split (measured: a 32x8 intra strip at mi(118,280) of | 6760 | // var-tx tree had split (measured: a 32x8 intra strip at mi(118,280) of |
| 6748 | // the 10-bit 3840x1608 stream read ctx 1 where aomdec reads ctx 2). | 6761 | // the 10-bit 3840x1608 stream read ctx 1 where aomdec reads ctx 2). |
| 6749 | if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { | 6762 | if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { |
| 6750 | - return tx_size_context_txfm_rect(n, (mi_r, mi_c), own_w, own_h); | 6763 | + let ctx = tx_size_context_txfm_rect(n, (mi_r, mi_c), own_w, own_h); |
| 6764 | + // Count only the blocks the deblock-grid approximation got WRONG, so a | ||
| 6765 | + // gate asserting this counter proves the override changed a CDF row | ||
| 6766 | + // (class gate-blind-to-feature: a plain "rect intra in inter" tally is | ||
| 6767 | + // green on the buggy code too). | ||
| 6768 | + let stale = usize::from( | ||
| 6769 | + mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w, | ||
| 6770 | + ) + usize::from( | ||
| 6771 | + mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h, | ||
| 6772 | + ); | ||
| 6773 | + if ctx != stale { | ||
| 6774 | + INTRA_RECT_IN_INTER_TXCTX_OVERRIDE_HITS.with(|c| c.set(c.get() + 1)); | ||
| 6775 | + } | ||
| 6776 | + return ctx; | ||
| 6751 | } | 6777 | } |
| 6752 | let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; | 6778 | let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; |
| 6753 | let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; | 6779 | let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; |
lanes/midcut-r2.handoff.mdadded+71 -0
| @@ -0,0 +1,71 @@ | |||
| 1 | +# lane-midcut r2 handoff (coordinator turn cap) | ||
| 2 | + | ||
| 3 | +Tip: lane-midcut, merged main (243f125) cleanly at STEP 0 (decode.rs/stream.rs auto-merged, `cargo check -p ec-av1` clean). | ||
| 4 | + | ||
| 5 | +## r1's named defect was STALE on both counts | ||
| 6 | +1. `find_mv_stack` call sites decode.rs:20959 and :23046 ALREADY pass | ||
| 7 | + `bw4 = write_w/4`, `bh4 = write_h/4` (lane-rect r2 did that). No `side, side` | ||
| 8 | + remains at any single-ref/compound mv-stack site; the sub-8 leaf sites pass | ||
| 9 | + the literal `1,1` / `2,2` libaom uses. Nothing to fix there. | ||
| 10 | +2. The mv stack at mi(112,288) is IDENTICAL to aomdec's, entry for entry: | ||
| 11 | + i0 (-24,-352) w=700 | i1 (-32,-350) w=664 | i2 (-40,-340) w=644 | i3 (-20,-360) w=4 | ||
| 12 | + (both decoders, both stack=4). Only the DRL index differed, because the | ||
| 13 | + entropy state at that block already differed (aomdec EC_MODE rng=56215 vs | ||
| 14 | + ours 41892) -- r1's "entropy in sync" premise was wrong. It was a downstream | ||
| 15 | + symptom, never a defect. | ||
| 16 | + | ||
| 17 | +## Root cause found and FIXED (commit cde8893) | ||
| 18 | +Reproducing this cut now needs `EC_INTRA16X4_DECODE=1` (main re-added the | ||
| 19 | +16x4-in-inter refusal); without it the probe refuses and every trace truncates. | ||
| 20 | + | ||
| 21 | +First real divergence in frame 1 (2-frame cut, decode order): the 32x8 INTRA | ||
| 22 | +strip at mi(118,280), inside an inter frame, reading its `tx_depth` symbol. | ||
| 23 | + aomdec: `EC_ISTEP mi_row=118 mi_col=280 name=tx_depth val=0 ctx=2 cat=2 rng=63652` | ||
| 24 | + ours : `EC_TXCTX mi_row=118 mi_col=280 w=32 h=8 above_px=16 left_px=16 ctx=1` | ||
| 25 | +Both entered at rng 42394 (the `use_filter_intra` rung matches exactly), so the | ||
| 26 | +ROW of `tx_size_cat2` is the whole defect (class wrong-alphabet-same-value: the | ||
| 27 | +value is 0 in both, only the range moves). | ||
| 28 | + | ||
| 29 | +`tx_size_context_rect` is the KEY FRAME approximation of libaom | ||
| 30 | +`get_tx_size_context` (`pred_common.h:342`): it reads the deblock tx grid and | ||
| 31 | +never applies "an INTER neighbour contributes its BLOCK size, not its transform | ||
| 32 | +size". The above neighbour here is the inter 32x8 at mi(116,280) whose var-tx | ||
| 33 | +tree had split to 16-wide TUs, so libaom sees 32 >= 32 (above=1) while we saw | ||
| 34 | +16 >= 32 (above=0). The 1:4 16x4 strip already branched to | ||
| 35 | +`tx_size_context_txfm_rect` at its own call site (decode.rs:9116); the other six | ||
| 36 | +rect intra readers did not. Fix = one branch inside `tx_size_context_rect` | ||
| 37 | +itself (decode.rs:6737) keyed on `INTRA_IN_INTER_MODE`, so every call site | ||
| 38 | +inherits it. | ||
| 39 | + | ||
| 40 | +### Measured effect (EVIDENCE lines) | ||
| 41 | +EVIDENCE: ~/.cache/midcut-tmp/{m_am.txt,m_o2.txt} | greedy in-order match of every | ||
| 42 | +`EC_MODE mi_row= mi_col= rng=` line, aomdec vs ours, 2-frame cut | first mismatch | ||
| 43 | +moved from aom idx 1998 (mi 120,272) to ALL MATCH 6871/6871 inter blocks. | ||
| 44 | +EVIDENCE: ~/.cache/midcut-tmp/d/{our,aom}.f{0,1} (EC_AV1_PREFILT_DUMP16, both | ||
| 45 | +decoders, regenerated this round) | numpy plane compare | f0 EXACT; f1 luma | ||
| 46 | +4386319 -> 115 wrong samples, U 342, V 860, every delta |1|, luma bbox rows | ||
| 47 | +552..1552 cols 488..969. | ||
| 48 | + | ||
| 49 | +## Also added (compiles, NOT yet gated -- next agent's first job) | ||
| 50 | +`decode::intra_rect_in_inter_txctx_override_hits()` (decode.rs, next to | ||
| 51 | +`intra_rect_in_inter_split_tx_hits`): counts ONLY the rect-intra-in-inter blocks | ||
| 52 | +whose ctx actually MOVED under the override, i.e. the blocks the bug mis-read -- | ||
| 53 | +a plain "rect intra in inter" tally is green on the buggy code too | ||
| 54 | +(class gate-blind-to-feature). | ||
| 55 | + | ||
| 56 | +## Exact next steps | ||
| 57 | +1. Print the new counter in `crates/ec-av1/examples/decode_probe.rs` (model: | ||
| 58 | + the `interintra_rect:` line at :46) and hard-assert a positive delta in | ||
| 59 | + `intra_rect_in_inter_split_tx_gate` / `intra_rect_in_inter_gate` | ||
| 60 | + (stream.rs:5639 / :29785, both bit depths). If neither arm fires the counter, | ||
| 61 | + add an aomenc arm with rect partitions + tx-size search on (the override only | ||
| 62 | + moves the row once a neighbour's var-tx tree splits). | ||
| 63 | +2. Chase the 115/342/860 |1| residue in frame 1 (entropy is now provably exact, | ||
| 64 | + so it is pure reconstruction: MC rounding or an intra edge, luma bbox above). | ||
| 65 | +3. Re-run the 24-offset decode-order table (`~/.cache/midcut-tmp/cen/`, r1's | ||
| 66 | + scripts; the r1 table `cen/after.tsv` is now stale) and report how many | ||
| 67 | + offsets have frame 1 exact. | ||
| 68 | +4. Then the named gates (mv_stack, interintra, rect, hidden_arf, | ||
| 69 | + refusal_inventory, gate_coverage) and the suite unit. None was run this round. | ||
| 70 | +5. No fixture pinned: frame 1 is not exact yet (residue above). | ||
| 71 | +6. No refusal lifted or moved; refusal_inventory/gate_coverage untouched. | ||