forge
Explore
Log in

Don't you dare go Hollow

Sbpart r7 report -- coeff-loop divergence localized to base symbol at (row=1,col=0)

Browse files at this commit

c1e2103021eb67eccc3ff0226c75746d706cc6a9Ahmet Kaan GümüşParent: 36c2f06
  • docs
    • sbpart r7 report -- coeff-loop divergence localized to base symbol at (row=1,col=0)
Show full message
docs(av1): sbpart r7 report -- coeff-loop divergence localized to base symbol at (row=1,col=0)
lanes/sbpart-r7.report.mdadded+192 -0
@@ -0,0 +1,192 @@
1+VERDICT: PARTIAL -- checked r6's tree compiles clean (charter's order 0), built
2+oracle rung 11 (per-symbol range ladder inside `read_coeffs_txb`), and used it
3+to localize block2's real divergence to a specific coefficient `base` symbol
4+inside the luma corner scan -- a materially sharper answer than r5/r6's
5+`around_rect`/context-gather suspects, but did not reach or land a fix.
6+
7+## 0. Compile check (charter's first step)
8+
9+`cargo check -p ec-av1 --tests` on r6's committed-verbatim tree (137f09c):
10+clean, only pre-existing missing-doc warnings. No merge-conflict debris, no
11+signature mismatches. r6's tree was in fact fine; only its report write was
12+interrupted at the cap.
13+
14+## 1. r6's own framing, re-checked
15+
16+r6 proved block2's mode-info prefix (skip/cdef/dq/mode/angle_y/uv_mode/
17+angle_uv) is byte-exact, range-for-range, against the oracle -- and named
18+`around_rect` as the next suspect, since it feeds the coefficient reads'
19+`skip_ctx`/`dc_sign_ctx`. This round re-read `around_rect`/`around_mi_rect`
20+(decode.rs:2094-2118) and `decode_block_rect64`'s call site
21+(decode.rs:3214) against `decode_block_rect`'s own (already-working, per r5's
22+"sibling working" framing) `around_rect` usage: identical shape, identical
23+w/h-split gather pattern (above over the block's own width, left over its own
24+height), and the u/v skip_ctx formula (`above_coded as usize +
25+left_coded as usize`) is textually identical between the two functions. No
26+defect found there by inspection -- consistent with what the range ladder
27+below actually shows (skip_ctx and dc_sign_ctx both read correctly).
28+
29+## 2. Regenerated the pinned mismatch (seed 42, same recipe as r2-r6)
30+
31+`EC_SBPART_GATE_ATTEMPTS=1 EC_AV1_GATE_DUMP=<sp>/sbpart-r7-pin.obu
32+EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib
33+a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact
34+-- --nocapture`: reproduced the frame-0 luma mismatch on the first attempt,
35+pinned OBU captured fresh (scratchpad only, not committed -- per
36+[[oracle-in-reaped-dir]] these do not survive between sessions, re-capture
37+with the same command if needed).
38+
39+## 3. Oracle rung 11: per-symbol coefficient range ladder
40+
41+Rung 3 (`EC_TRACE_COEFF`, built by a sibling lane) only bracketed a whole
42+`av1_read_coeffs_txb` call -- entry/exit `rng`, nothing inside. That is
43+coarse enough to prove a block diverges but not where. Added rung 11 (same
44+env var, no new flag) in `scripts/instrument-aom-oracle.sh`, patching
45+`read_coeffs_txb` in `decodetxb.c` to print `EC_COEFF_STEP tag=<eob|
46+base_eob|after_bases|sign|post_golomb> ... rng=..` at four checkpoints:
47+right after `*eob` is computed, right after the special eob-1 base/br read,
48+right after the reverse-scan base/br loop for every other position, and
49+right after each sign/golomb read in the final forward loop. Applied to the
50+shared `~/.cache/aom-oracle` tree, `ninja -C ~/.cache/aom-oracle/build
51+aomdec`: clean.
52+
53+Mirrored the entry/exit half on our own side: `EC_COEFF`/`EC_COEFF_VAL`
54+prints (same format) at all three coefficient-read call sites in
55+`decode_block_rect64` (luma `read_coeffs`, chroma U/V `read_coeffs_rect`,
56+decode.rs:3214-3320), plus `rng` added to the existing `EC_AV1_TRACE`
57+`eob_pt`/`eob_extra` lines in `read_eob` (decode.rs:1183,1190) for
58+comparability. `read_coeffs`'s own existing per-symbol traces
59+(`all_zero`/`tx_type`/`eob`/`base_eob`/`base`/`br`/`dc_sign`/`golomb`,
60+decode.rs:1261-1394) already carried enough to read off VALUES; this round
61+only needed the oracle side widened to carry `rng`.
62+
63+Ran both traces on the identical pinned OBU
64+(`EC_TRACE_COEFF=1 aomdec --i420 -o /dev/null <pin>.obu`, and
65+`EC_AV1_GATE_DUMP_PIN=<pin>.obu EC_TRACE_COEFF=1 EC_AV1_TRACE=1 cargo test
66+--lib pinned_sbpart_stream_decodes_pixel_exact -- --ignored --nocapture`).
67+
68+## 4. Result: block1 exact, block2's luma coefficient read is where it starts
69+
70+Block1 (mi_col=16), all 3 planes, entry-to-exit rng: **byte-for-byte
71+identical** between ours and the oracle (luma 36949->41600, U 41600->42128,
72+V 42128->45272, all four numbers matching on both sides). Confirms r5's
73+pixel-exact finding down to the entropy level, not just pixels.
74+
75+Block2 (mi_col=24) luma entry rng: **63764 on both sides** -- exact match,
76+confirming r6's mode-info-prefix finding held all the way through the
77+`skip`/`tx_depth` reads too (both zero symbols consumed identically, since
78+`tx_select=false` under `--enable-tx-size-search=0`). But the luma read's
79+**exit** range diverges: ours **46984**, oracle **46344**. This overturns
80+r6's framing that `around_rect` (feeding only `skip_ctx`/`dc_sign_ctx`) was
81+the leading suspect -- `all_zero` reads `value=0` (not skip) on both sides
82+and `dc_sign` reads the same value on both sides, so those two ctx values
83+were consumed correctly; the actual divergence is **inside the coefficient
84+magnitude loop**, after `eob` and before `dc_sign`.
85+
86+Step-by-step inside block2's luma block (rung 11's checkpoints, both sides
87+agree on `eob=6` and the eob-1 symbol `base_eob level=1`):
88+
89+```
90+scan position (row,col) ours base value oracle final level
91+pos=2 (row0,col2) scan5 1 (base_eob) 1
92+pos=33 (row1,col1) scan4 1 1
93+pos=64 (row2,col0) scan3 1 1
94+pos=32 (row1,col0) scan2 3 -> br(ctx8)=0 -> 3 1 <-- FIRST DIVERGENCE
95+pos=1 (row0,col1) scan1 0 ? (not individually logged
96+ oracle-side; our value 0
97+ means no sign is read for
98+ it either way, consistent)
99+pos=0 (row0,col0) scan0 3 -> br,br=3,0 -> 6 1 (downstream, corrupted
100+ by the pos=32 read
101+ already having
102+ consumed the wrong
103+ number/kind of bits)
104+```
105+
106+The oracle decodes **every** non-eob coefficient in this block at level 1
107+(no `br` read ever fires) except the skipped zero at `c=3`. Ours decodes
108+`pos=32` (scan_idx=2, `row=1,col=0`) as base value **3** -- which is
109+`> NUM_BASE_LEVELS`, so it additionally reads a `br` symbol the oracle never
110+consumed at all, and `pos=0` (the DC, scan_idx=0) also comes out base value
111+3 with a further `br,br=3,0` (final level 6) where the oracle's DC is level
112+1. The DC divergence is very likely *downstream* corruption from the
113+scan_idx=2 desync (once one extra symbol is read, everything after it in
114+the reverse scan reads shifted bits); scan_idx=2 (`pos=32`, `row=1,col=0`)
115+is the first place values differ and is the actual desync point.
116+
117+## Named suspect for next round
118+
119+The symbol at `pos=32` is read via `read_coeffs`'s reverse-scan branch
120+(decode.rs:1338-1339): `let ctx = base_ctx(&levels, side, row, col, class);
121+let v = dec.symbol(&mut coding.base[ctx]) as i32;` -- our trace shows
122+`ctx=2` for this position. Since the entry range into the whole coefficient
123+loop and every earlier symbol (`eob`, `base_eob` at scan_idx 5/4/3`) all
124+matched the oracle exactly, the *decoder state* (msac range/value, CDF
125+adaptation counts) going into this read was identical on both sides -- so a
126+different decoded symbol value here can only come from a different **CDF
127+row** being read (wrong `ctx` from `base_ctx`, or `coding.base` indexed
128+under the wrong `TxbSet`/mode row) rather than a desync that already
129+happened earlier. `base_ctx` (decode.rs, search `fn base_ctx`) computes the
130+2D neighbour-magnitude context per spec `get_lower_levels_ctx`
131+(`Mag_Ref_Offset_With_Tx_Class`-style neighbour sum) -- next round should
132+hand-check `base_ctx`'s neighbour offsets and clamping for exactly
133+`(row=1, col=0)` in a 32-wide 2D-class scan against libaom's
134+`get_lower_levels_ctx` (`av1/common/txb_common.h`), and cross-check that
135+`coding.base` (the `cdfs.txb(TxbSet::Luma64, mode).base` table) is the same
136+CDF the oracle's `ec_ctx->coeff_base_cdf[txs_ctx][plane_type]` resolves to
137+for `txs_ctx = get_txsize_entropy_ctx(TX_32X64)` -- **this round did not
138+check** whether `TxbSet::Luma64`'s `txs_ctx` mapping matches libaom's for a
139+true `TX_32X64` (as opposed to a square `TX_64X64`); a mismatched `txs_ctx`
140+would select a differently-adapted CDF row even at the same numeric `ctx`
141+index and is a strong alternate explanation for a value divergence with no
142+range mismatch beforehand.
143+
144+## What was committed (58a0d59)
145+
146+Diagnostics only, no behavior change to the live gate (byte-identical
147+before/after this round's diffs to the gate's own logic; only tracing
148+statements added). `cargo check -p ec-av1 --tests`: clean. Oracle rung 11
149+applied to the shared `~/.cache/aom-oracle` tree and captured in
150+`scripts/instrument-aom-oracle.sh` (env-gated, idempotent, reproduces from a
151+fresh clone) per the charter's "never a throwaway patch left in the tree"
152+rule.
153+
154+## Not attempted this round
155+
156+- No fix landed; `sb_rect_hits() > 0` remains unproven (gate still red,
157+ unchanged from r6).
158+- Did not check `get_txsize_entropy_ctx`'s treatment of `TX_32X64` vs
159+ `TX_64X64` for CDF-set selection purposes (named above as the sharper
160+ alternate suspect to `base_ctx`'s neighbour math) -- ran out of budget
161+ before opening `cdf_state.rs`'s `txb`/`TxbSet::Luma64` resolution path.
162+- Did not extend rung 11 to chroma (`read_coeffs_rect`, untraced per-symbol
163+ on our side -- only entry/exit) since luma is where entry/exit already
164+ proved the divergence lives; chroma U/V exit ranges were not compared this
165+ round (moot until luma is fixed, since bits already shifted downstream).
166+
167+## Hard rules followed
168+
169+Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`
170+every build; foreground `nice -n 19 cargo ... -j4`; `EC_AV1_REQUIRE_AOMENC=1`
171+on the aomenc-driven capture; aomenc recipe unchanged (`--threads=1
172+--row-mt=0 --sb-size=64 --enable-tx-size-search=0`, inherited); oracle rung
173+is env-gated (`EC_TRACE_COEFF`, no new flag), captured in
174+`scripts/instrument-aom-oracle.sh` not left as a standalone patch; no other
175+worktree touched; no push, no merge into main; killed a background
176+`cargo test` full-suite run started by mistake (unscoped `stream::tests::`)
177+before it could pile up, per turn-cap discipline.
178+
179+## Next round, in order
180+
181+1. Check `get_txsize_entropy_ctx(TX_32X64)` vs our `TxbSet::Luma64`'s own
182+ `txs_ctx`/CDF-set resolution (`cdf_state.rs`, search `Luma64`) against
183+ libaom's `av1/common/txb_common.h` `get_txsize_entropy_ctx` -- rule in or
184+ out before touching `base_ctx`'s neighbour math, since a wrong CDF-set
185+ selection produces exactly this symptom (same range in, different value
186+ out, no earlier range mismatch).
187+2. If that's clean, hand-check `base_ctx` (decode.rs) at `(row=1, col=0)`
188+ for a 32-wide `TxClass::TwoD` scan against libaom's
189+ `get_lower_levels_ctx` -- the neighbour offset table/clamping is the
190+ remaining suspect.
191+3. Fix, then re-run the full `n_attempts=40` gate and confirm
192+ `sb_rect_hits() > 0` stays a hard pass.