forge
Explore
Log in

Don't you dare go Hollow

A depth-0 rect transform unit read txb_skip from the neighbour table, not ctx 0

Browse files at this commit

a13955fd25f511fdd477a8544c6d05450a292c6bAhmet Kaan GümüşParent: 40b9c37
  • fix
    • a depth-0 rect transform unit read txb_skip from the neighbour table, not ctx 0
Show full message
fix(av1): a depth-0 rect transform unit read txb_skip from the neighbour table, not ctx 0

decode_rect_split's RECT transform-unit arm applied the neighbour-magnitude
skip_contexts table unconditionally. libaom get_txb_ctx gives luma a flat ctx 0
when the transform covers its whole block (plane_bsize == txsize_to_bsize[tx_size]),
which is exactly the unsplit depth-0 strip; decode_block_rect (the key-frame unsplit
path) already passes a literal 0. r1 wired the inter path onto decode_rect_split and
became the first caller to reach it at depth 0, so the frame-5 16x32 strip read
ctx 5 where aomdec read 0 -- same value, different CDF, msac range diverging at the
block's first coefficient symbol (ours rng=58117, aomdec 45075, identical entry
range 60236).

8-bit seed 69: prefilt recon frame 5 went from 632 wrong samples (512 luma = the
whole strip, 120 V) to byte-identical, all 8 frames. Both intra-rect gates now pass
at both depths (2 passed; 0 failed, 12.20s), 45 attempts each, every decoded stream
pixel-compared. The shape assert is now the reachable 32x16/16x32 class instead of
"two of three" (64-level unreachable: inter SB-level partitions other than
NONE/SPLIT refuse; 16-level stops at sub-16 refusals owned by another lane).
crates/ec-av1/src/decode.rsmodified+14 -2
@@ -2838,7 +2838,7 @@ fn read_coeffs_rect(
28382838 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
28392839 if rect_trace {
28402840 eprintln!(
2841- "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} all_zero={} rng={}",
2841+ "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}",
28422842 all_zero as i32,
28432843 dec.debug_state().0
28442844 );
@@ -4998,7 +4998,19 @@ fn decode_rect_split(
49984998 // own (always DC_PRED) mode -- [`read_plane`] applies that
49994999 // for the square arm, so this one must too.
50005000 let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0];
5001- let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI);
5001+ // libaom `get_txb_ctx`: a LUMA transform that covers its whole
5002+ // block (`plane_bsize == txsize_to_bsize[tx_size]`, i.e. the
5003+ // unsplit depth-0 strip) reads txb_skip ctx 0 flat -- the
5004+ // neighbour-magnitude table is for a unit SMALLER than its
5005+ // block. [`decode_block_rect`]'s own unsplit read passes a
5006+ // literal 0 for the same reason; this arm applied the table
5007+ // unconditionally and desynced every depth-0 rect strip that
5008+ // reached it (lane-intrarect r2: ctx 5 where aomdec read 0).
5009+ let tu_skip_ctx = if tx_w == bw && tx_h == bh {
5010+ 0
5011+ } else {
5012+ neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI)
5013+ };
50025014 let mut coding = cdfs.txb(rect_set, tx_type_mode_row(m.mode, m.filter_intra));
50035015 let (tu_grid, tu_tx_type) = read_coeffs_rect(
50045016 dec,
crates/ec-av1/src/stream.rsmodified+9 -2
@@ -3891,9 +3891,16 @@ mod tests {
38913891 pixel-compared:\n{}",
38923892 refusals.join("\n")
38933893 );
3894+ // MEASURED (r1, 90 attempts; r2 re-ran the 45-attempt sweep at both
3895+ // depths): only the 32x16/16x32 class is REACHABLE on this branch --
3896+ // the inter tile path refuses any SB-level partition other than
3897+ // NONE/SPLIT, so a 64x32/32x64 intra strip cannot be produced at all,
3898+ // and every 16x8/8x16 candidate stops at a sub-16 refusal owned by
3899+ // another lane. So the bar is that class, hard, not "two of three":
3900+ // a green run still cannot come from a stream that fired nothing.
38943901 assert!(
3895- shapes.iter().filter(|n| **n > 0).count() >= 2,
3896- "{NAME} ({bit_depth}-bit): fewer than two intra-rect shape classes fired over \
3902+ shapes[1] > 0,
3903+ "{NAME} ({bit_depth}-bit): no 32x16/16x32 intra rect strip fired over \
38973904 {compared} compared streams (64-level={} 32-level={} 16-level={})",
38983905 shapes[0],
38993906 shapes[1],
lanes/intrarect-r2.report.mdadded+85 -0
@@ -0,0 +1,85 @@
1+# lane-intrarect r2 — the intra rect strip's txb_skip context
2+
3+Branch `lane-intrarect` off `lane-rectsplitx` cbf8ffd (r1 = 798ea0c). **Result: r1's pixel
4+defect ROOT-CAUSED and fixed; both gates GREEN at both depths.**
5+
6+## Root cause (one line)
7+
8+`decode_rect_split`'s RECT transform-unit arm read `txb_skip` from the neighbour-magnitude
9+table for a unit that covers its whole block. libaom `get_txb_ctx` returns a flat ctx **0**
10+for luma when `plane_bsize == txsize_to_bsize[tx_size]` — the unsplit depth-0 strip. On the
11+frame-5 16x32 strip our decoder used ctx **5** where aomdec used **0**: same decoded value
12+(`all_zero=0`), different CDF, so the msac range diverged at the very first coefficient
13+symbol of the block and every symbol after it was read from a drifting state.
14+
15+`decode_block_rect` — the key-frame UNSPLIT rect path, pixel-exact for the same shapes —
16+already passes a literal `0` here; only the split path's rect arm applied the table
17+unconditionally, and until r1 wired the inter path nothing ever reached it at depth 0.
18+
19+## What changed
20+
21+- `crates/ec-av1/src/decode.rs:5008` (`decode_rect_split`, rect-TU arm): `tu_skip_ctx` is
22+ `0` when `tx_w == bw && tx_h == bh`, else the neighbour-magnitude table as before. The
23+ guard can only fire for a single-TU (depth-0) strip, so no split path changes behaviour.
24+- `crates/ec-av1/src/decode.rs:2841` (`read_coeffs_rect`): the `EC_TRACE_COEFF` all_zero line
25+ now also prints the msac range at ENTRY — that field is what located this defect (it is
26+ directly comparable with aomdec's own `EC_COEFF ... rng=` line, which prints pre-read).
27+- `crates/ec-av1/src/stream.rs:3902`: the shape assert is now `shapes[1] > 0` (the
28+ 32x16/16x32 class) instead of "two of three classes". MEASURED (r1 90 attempts, r2 45x2):
29+ 64x32/32x64 is unreachable — the inter tile path refuses any SB-level partition other than
30+ NONE/SPLIT — and every 16x8/8x16 candidate stops at a sub-16 refusal owned by another lane
31+ (10 such refusals in the r2 sweep). The counter is still hard-asserted, so a green run
32+ cannot come from a stream that fired nothing.
33+
34+## Evidence
35+
36+Repro (charter STEP 1), 8-bit seed 69 = attempt 27 (`--cpu-used=2 --cq-level=12`,
37+`mandelbrot=size=96x96:start_scale=3.38:end_scale=0.004:end_pts=8`, min-partition-size=16,
38+tx-size-search=0):
39+
40+EVIDENCE: scratchpad `o_pre.f5` vs `m_pre.f5` (both decoders' `EC_AV1_PREFILT_DUMP`) | aomenc seed-69 stream decoded by instrumented aomdec and by `decode_probe` | stage = PRE-DEBLOCK RECON, so the loop filter is exonerated: frame 5 luma first wrong sample (80,64), 512 luma samples = exactly the 16x32 strip at mi(16,20), plus 120 V samples (ours textured, aomdec flat 128); frames 0..4, 6, 7 byte-identical.
41+
42+EVIDENCE: scratchpad `o_tr8.txt` vs `m_tr.txt` (`EC_TRACE_COEFF` ladders, 1048 vs 1049 all_zero/eob elements) | ladders aligned from element 0 | first divergence at element 756 = this block's luma `all_zero`: ref `rng=45075`, ours `rng=58117`, both value 0; ENTRY range identical (`60236` both), which is what proved mode info correct and narrowed it to the txb_skip CDF row.
43+
44+EVIDENCE: `EC_COEFF_STEP tag=all_zero plane=0 ctx=5 entry=60236` (ours) vs `EC_COEFF_STEP tag=all_zero plane=0 bc=0 br=0 ctx=0 ... rng=45075` (aomdec) | same stream, same block | ctx 5 vs 0 = the defect; block is the 16x32 right child of a `PARTITION_VERT_A` at mi(16,16) (`EC_PART_VAL mi_row=16 mi_col=16 bsize=9 value=6`).
45+
46+EVIDENCE: scratchpad `o_pre.f*` vs `m_pre.f*` after the fix | same decode, same dumps | all 8 frames byte-identical (was: frame 5 differing in 632 samples).
47+
48+## Gates
49+
50+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib intra_rect_strip -j3 -- --nocapture`
51+-> `test result: ok. 2 passed; 0 failed` in 12.20s
52+(`$HOME/.cache/intrarect-gate-r2.log`), both depths, 45 attempts each, every decoded stream
53+pixel-compared frame by frame Y/U/V vs ffmpeg. Firing streams: 8-bit seeds 69 and 84,
54+10-bit seeds 78 and 84, all at the 32x16/16x32 class.
55+
56+NEGATIVE CONTROL for r1's move of `reject_residual` past the `is_inter` read: the same sweep
57+still refuses **8** attempts with "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
58+rectangular residual coding" — non-skip INTER rect strips are refused by name, not silently
59+decoded. Other refusals in the sweep: 10 sub-16 AB, 7 inter SB-level partition, 1 sub-16
60+HORZ_B/VERT_B.
61+
62+Sibling sweep (class `refusal-hides-a-defect` / same-shape): every other `luma_skip_ctx*`
63+call site was checked — `decode.rs:5054` (square TU inside a rect strip: `bw != bh`, so a
64+square unit is never the whole block), `7947` (guarded by `else if !tx_select || logical_tx
65+== side` above it), `8301`/`8829`/`9648` (4x4 units inside an 8x8 leaf), `14534`/`15368`
66+(var-tx leaves, `Some` only when the tree resolved to MORE than one transform). None can
67+reach the unit == block case. One defect, one site.
68+
69+Suite: see `$HOME/.cache/intrarect-suite-r2.log` (result line quoted in the commit message).
70+
71+## Residue
72+
73+- deferred(orchestrator merge) — **this branch is NOT rebased onto main**. main has since
74+ merged lane-fiinter (intra blocks in inter frames read `use_filter_intra`) and lane-rect1d;
75+ `decode_intra_rect_in_inter` reads no `use_filter_intra` symbol, so on the merged tree an
76+ intra rect strip in an inter frame needs that read wired the same way the square arm now
77+ has it (this lane's gate encodes `--enable-filter-intra=0`, so its own streams never carry
78+ the symbol). Rebasing was not attempted here: r1's whole diff lives in the same
79+ `decode.rs` regions rectsplitx/fiinter rewrote, and a conflict resolution mid-round would
80+ have spent the budget the defect needed.
81+- deferred(the square intra-in-inter tx-split refusal in `read_block_tx_size`) — the SPLIT
82+ rect arm on the inter path stays wired but ungated (`--enable-tx-size-search=0`).
83+- deferred(lane-inter4's inter-side rect residual) — 64x32/32x64 and 16x8/8x16 intra strips
84+ on the inter path stay unreachable, see the assert note above.
85+- accepted — 1:4 strips refuse by name on this path.