forge
Explore
Log in

Don't you dare go Hollow

lane-av1llintercdf: the lossless sub-8 intra leaf reads its uv_mode off the canonical cfl_allowed_px alphabet

Browse files at this commit

10366d7d40e1ef13c23601aab0e3f1aacfd7af05Ahmet Kaan GümüşParent: 97a9038
The t6 frame-1 all_zero divergence the llkf lane deferred was never a CDF
adaptation desync: the all_zero rows were identical at the divergent read (the
llkf report compared our PRE-update row snapshot against the oracle's
POST-update cdf0 print). The states part one block earlier, inside the intra
8x4 leaf's uv_mode read -- decode_intra_sub8_leaf picked the 14-symbol
uv_mode_cfl row unconditionally where av1_is_cfl_allowed forces the 13-symbol
uv_mode_no_cfl row for a lossless block whose chroma plane block is not a
single TX_4X4 (an 8x4 leaf at 4:4:4). The read now goes through the canonical
cfl_allowed_px like every other uv site; 4:2:0 is arithmetically unchanged
(every sub-8 chroma block is 4x4-or-smaller, predicate stays true).

t6 frame 0 stays byte-exact; pairs 2316/2317 now match the oracle's (value,
rng) and the ECIN bits delta returns to the constant +15. Frames 1..5 still
differ through a second, independent site named in the report: the same leaf's
chroma_444 && bw != bh arm reads one TX_8X4/TX_4X8 rect unit per plane where
lossless forces per-unit TX_4X4 (oracle: four units, ctx 11) -- stopped with
the site per the ticket. Gates: a_lossless 7 passed; cargo check
--all-targets 0 warnings.
crates/ec-av1/src/decode.rsmodified+14 -3
@@ -35697,9 +35697,20 @@ fn decode_intra_sub8_leaf(
3569735697 // No angle delta below 8x8 (`av1_use_angle_delta`), for luma or chroma.
3569835698 let angle_delta_y = 0;
3569935699 let (uv_mode, alpha) = if has_chroma {
35700- // `is_cfl_allowed` is `wide <= 32 && high <= 32` -- true for this
35701- // shape, so the 14-symbol CFL alphabet is the right one.
35702- let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
35700+ // `is_cfl_allowed` (blockd.h): away from lossless it is
35701+ // `wide <= 32 && high <= 32` -- true for this shape; at lossless the
35702+ // CHROMA plane block must be a single TX_4X4, so at 4:4:4 only the
35703+ // 4x4 leaf keeps the 14-symbol CFL alphabet while an 8x4/4x8 leaf
35704+ // reads the 13-symbol `uv_mode_no_cfl` one (the t6 frame-1 8x4 leaf
35705+ // desynced at its uv_mode symbol reading the CFL alphabet,
35706+ // lane-av1llintercdf). At 4:2:0 a sub-8 shape's chroma block is
35707+ // always 4x4-or-smaller, so the predicate stays true and this read
35708+ // is unchanged.
35709+ let uv_mode = if cfl_allowed_px(bw, bh, fctx) {
35710+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
35711+ } else {
35712+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
35713+ };
3570335714 if step {
3570435715 eprintln!(
3570535716 "EC_ISTEP mi_row={} mi_col={} name=uv_mode val={uv_mode} rng={}",
lanes/av1llintercdf.report.mdadded+100 -0
@@ -0,0 +1,100 @@
1+# lane-av1llintercdf: the t6 frame-1 INTER all_zero divergence named (and the one-site fix)
2+
3+## Ticket
4+
5+Deferred item 1 of `lanes/av1llkf.report.md`: the 6-frame default-partition
6+lossless 4:4:4 testsrc2 stream (t6) reads frame 0 fully exact, then diverges at
7+frame 1 (INTER), luma `all_zero` read #2317 — "same ctx row (1) and same decoded
8+value as the oracle but different CDF contents (ours `cdf0=5892` vs aom
9+`27244`)", suspected adaptation-history/row-selection desync. Name the divergent
10+symbol and its reader, decide missed-update vs applied-twice, fix only if one
11+site.
12+
13+## The llkf reading is refuted — the CDF rows were EQUAL
14+
15+Both trace printers were misread as the same quantity:
16+
17+- ours (`decode.rs:6811-6823`): `cdf=[a, 32768, n]` is the row snapshot taken
18+ BEFORE `dec.symbol` — the PRE-update row, in OUR storage, where
19+ `ours_v = 32768 - aom_v` (complement).
20+- oracle (`decodetxb.c:161`): `cdf0=` is printed AFTER `aom_read_symbol` — the
21+ POST-update value in aom storage.
22+
23+Replaying frame 0 read-by-read (rate-4 adaptation, val=0 up / val=1 down in our
24+convention) matches every printed pair: at the divergent read aom's pre-state
25+was `26876` (aom storage) = `5892` (ours) — the rows were IDENTICAL, and both
26+sides adapted that read symmetrically. So the answer to "missed update or
27+applied twice" is **neither**: there was no adaptation desync at all; the rng
28+mismatch at read #2316 (0-indexed; the report's #2317) came from symbols read
29+EARLIER in the same block's mode info, which the all_zero-only ladder cannot
30+see.
31+
32+## The divergent symbol and reader (measured, t6, EC_ECDUMP_IN + EC_TRACE_COEFF
33++ EC_TRACE_MODE_STEP on both sides)
34+
35+Between the last coefficient read of frame 1's first superblock row and read
36+#2316, both sides decode the INTRA 8x4 leaf at mi=(0,2) — an intra leaf inside
37+an INTER frame, through `read_intra_block_mode_info` (decodemv.c:1065). The
38+states part inside its `uv_mode` read:
39+
40+- ours pre-`use_filter_intra` rng 60904, oracle 58668; ours consumed 100 bits
41+ across the block's mode info, the oracle 98 (+2).
42+- ours read `uv_mode` off the **14-symbol `uv_mode_cfl`** row
43+ (`decode.rs:35703`, then unconditional); the oracle reads it off the
44+ **13-symbol `uv_mode_no_cfl`** row, because `av1_is_cfl_allowed` (blockd.h)
45+ returns 0 for a lossless block whose chroma plane block is not a single
46+ TX_4X4 — an 8x4 leaf at 4:4:4 has an 8x4 chroma plane block.
47+
48+Reader: `decode_intra_sub8_leaf`'s uv read (`decode.rs:35703`), the one
49+`uv_mode` site that bypassed the canonical `cfl_allowed_px` predicate every
50+other uv read site uses (`decode.rs:9791, 11206, 15610, 18853, 34062, 38675`).
51+The block comment there stated only the non-lossless term.
52+
53+The neighbouring 4x4 leaf (mi=(0,1)) kept matching by construction: at 4:4:4
54+lossless a 4x4 leaf's chroma block IS a single TX_4X4, so CFL stays allowed and
55+the 14-symbol row is correct there — which is why frame 1 synced for 2316 reads
56+and 5 blocks before diverging on the first 8x4.
57+
58+## Change (decode.rs, one site)
59+
60+`decode_intra_sub8_leaf`'s uv read now goes through
61+`cfl_allowed_px(bw, bh, fctx)` — the canonical predicate, which already
62+implements the lossless term (chroma plane block must be a single TX_4X4).
63+4:2:0 is arithmetically identical: every sub-8 shape's chroma block is
64+4x4-or-smaller under 4:2:0, so the predicate stays true and the row choice is
65+unchanged; the 4:2:0 lossless gates (below) are green.
66+
67+## Verification (measured, this tree @ HEAD + this change)
68+
69+- Entropy: pairs #2316 and #2317 (the whole 8x4 leaf's luma) now match the
70+ oracle's (value, rng) exactly, and the ECIN bits delta returns to the
71+ constant +15 header offset through the block.
72+- Byte witness: t6 frame 0 is byte-exact vs fresh `aomdec --rawvideo` (36864
73+ bytes; sha256 of the full 6-frame decode differs — see the deferred item).
74+- Gates: `cargo test -p ec-av1 --lib a_lossless` → 7 passed, 0 failed (both
75+ 4:2:0 lossless libaom gates, the 444 min-partition-64 inter gate, the sb128
76+ pair, the 16x4 pair).
77+- `cargo check -p ec-av1 --all-targets` (target dir
78+ `$HOME/.cache/cargo-target-av1llintercdf`): 0 warnings, 0 errors.
79+
80+## Named, not chased (spoken)
81+
82+1. t6 frames 1..5 still differ (first diff frame-1 byte 65): a SECOND site in
83+ the same leaf, independent of the alphabet fix. At the still-shared state
84+ rng=51429 after the 8x4 leaf's luma, the oracle reads the leaf's chroma as
85+ FOUR TX_4X4 units (plane 1 bc=0,1 ctx=11 then plane 2 bc=0,1 — lossless
86+ forces per-unit TX_4X4), while `decode_intra_sub8_leaf`'s
87+ `chroma_444 && bw != bh` arm (`decode.rs:36104-36139`) reads the chroma
88+ plane as ONE `TX_8X4`/`TX_4X8` rect unit per plane (`read_coeffs_rect`,
89+ skip ctx fixed at above+left=1 where the oracle derives 11≡4). The fix is
90+ the b3f815c8-style per-unit lossless 444 chroma walk (unit decomposition +
91+ per-unit `get_txb_ctx` + dropped tx_type), i.e. a shape port of its own —
92+ not a one-site fix, so per the ticket it is stopped-with-site, deferred(
93+ the sub-8 4:4:4 lossless chroma walk; unblock: port the
94+ `decode_leaf_rect8`/8x8-leaf per-unit walk into the `chroma_444 && bw != bh`
95+ arm).
96+2. Instrument gap, no decode impact: the rect coefficient reader
97+ (`read_coeffs_rect`, `decode.rs:7056`) prints `EC_COEFF_STEP` with a
98+ hardcoded `plane=0` and no `EC_ECDUMP_IN` line, so rect-path reads are
99+ invisible to the (value, rng, bitpos) pairing used here. Worth one rung of
100+ parity next time that path is debugged.