forge
Explore
Log in

Don't you dare go Hollow

av1lm444loss: lane report -- H1 fixed (TX grid frame-edge clip), lead (b) blocked

Browse files at this commit

65ae1e49faa48073591d29b17b7ac785e21156f0Ahmet Kaan GümüşParent: 589db23
Evidence for the frame-edge clip fix and its mutation proof, plus the
one-line diagnosis of the separate hardcoded-4:2:0 chroma halving in
decode_intrabc_rect that stops lead (b) before it reaches its entropy
fork.
lanes/av1lm444loss.report.mdadded+258 -0
@@ -0,0 +1,258 @@
1+# lane-av1lm444loss — H1: 4:4:4 LOSSLESS byte-exactness
2+
3+**Verdict.** Lead (a) **FIXED**: the pinned `ll444_128root_lossless.obu` is now
4+byte-exact on all six frames and its `EC_SYMR` ladder is bit-identical to the
5+oracle (235,940 reads, zero fork; it forked at read 71,322 before). The defect
6+was **not** in the coefficient reader — it was the transform-unit **walk**: a
7+lossless block's TX grid was never clipped at the frame edge, so the decoder
8+read 256 units per inter frame that libaom never codes, and the fork lands on a
9+PLANE change (`plane=0` luma where the oracle had moved to `plane=1` chroma).
10+
11+Lead (b) is **blocked by a separate, pre-existing defect**, diagnosed to a
12+one-line cause in §5. Not this lane's class; not fixed here.
13+
14+**Tree.** `lane-av1lm444loss` off `a21f3680`, worktree `~/.cache/wt/av1lm444loss`.
15+One commit, `7b9f46fa`. Not pushed (Main merges).
16+
17+## 1. Lead (a): reproduction and the first fork
18+
19+`fixtures/ll444_128root_lossless.obu` (63429 bytes, 128x96 yuv444p, 6 frames).
20+Decoded-order dump vs the oracle's `EC_AV1_FINAL_DUMP`, at the base tree:
21+
22+| frame | wrong samples | first differing byte |
23+|---|---|---|
24+| 0 | 0 | — |
25+| 1 | 5596 | 16544 |
26+| 2 | 25693 | 0 |
27+| 3 | 28492 | 0 |
28+| 4 | 32289 | 0 |
29+| 5 | 33561 | 0 |
30+
31+`EC_SYMR` on both sides, one line per `symbol()` call, aligned on
32+`(value, range, symbol, post_rng)`:
33+
34+```
35+index 71321 both mi=(0,0) decodetxb.c:158 (txb_skip) s=1 pre=(35131,51766) post=51766
36+index 71322 ORACLE mi=(0,0) decodetxb.c:158 s=1 pre=(35131,51110) post=49256 cdf0=31697
37+index 71322 OURS mi=(0,0) (luma walk) s=1 pre=(35131,51110) post=50351 icdf0=377
38+```
39+
40+Both sides read the same site and the same 2-class `txb_skip` CDF. The CDF row
41+content diverges (`32768 - 377 = 32391` vs the oracle's pre-adapt `32391` at
42+71321, `31697` at 71322), so this is the two sides being on **different units**,
43+not the same unit read two ways.
44+
45+`EC_COEFF_STEP tag=all_zero` names them:
46+
47+```
48+[3967] ORACLE plane=0 bc=15 br=23 ctx=1 (luma, block row 23 = y 92..95)
49+[3968] ORACLE plane=1 bc=0 br=16 ctx=10 (chroma — the walk moved planes)
50+[3968] OURS side=4 ctx=1 (still luma)
51+```
52+
53+That is the whole story in one line: the oracle finished the luma plane at
54+transform row 24 and moved to chroma; we were still reading luma.
55+
56+## 2. Mechanism: the missing frame-edge clip
57+
58+libaom bounds a block's transform grid by the part of it **inside the frame**:
59+
60+- `max_block_high` / `max_block_wide` (`av1_common_int.h:1579`, `:1565`) start
61+ from `block_size_high/wide[bsize]` and, when `mb_to_bottom_edge` /
62+ `mb_to_right_edge` is negative, add `>> (3 + ss)`, then `>> MI_SIZE_LOG2`.
63+- `mb_to_bottom_edge` is `GET_MV_SUBPEL((mi_rows - bh - mi_row) * MI_SIZE)`
64+ (`set_mi_row_col`, `av1_common_int.h:1360`), so the clip reduces exactly to
65+ the block's extent within the frame, in transform units.
66+- `decode_token_recon_block` then caps every mu chunk with
67+ `unit_height = ROUND_POWER_OF_TWO(AOMMIN(mu_blocks_high + row,
68+ max_blocks_high), ss_y)` — the out-of-frame units are never read.
69+
70+Our decoder already had this exact arithmetic. `read_block_tx_size`'s **var-tx**
71+branch computes it, twenty lines below the lossless branch:
72+
73+```rust
74+let max_w_mi = side_mi.min(mi_cols.saturating_sub(at_mi.1));
75+let max_h_mi = side_mi.min(mi_rows.saturating_sub(at_mi.0));
76+```
77+
78+and `read_var_tx_size` bails on it (`if blk_row >= max_h_mi || blk_col >=
79+max_w_mi { return; }`). The **lossless** branch returned a plain
80+`0..side/MI` square, and so did `read_block_tx_size_rect`'s lossless branch.
81+
82+**The arithmetic, exactly.** Frame 128x96. `side = 128`, so `side / MI = 32`;
83+`mi_rows = 2 * ceil(96/8) = 24`. `max_blocks_high = 128 + (-32 >> 3) = 96`,
84+`>> 2 = 24`. Clipped rows 24, columns 32.
85+
86+| | luma units / frame | chroma units / frame | total |
87+|---|---|---|---|
88+| oracle | 24 x 32 = **768** | 2 x 24 x 32 = **1536** | **2304** |
89+| ours, before | 32 x 32 = **1024** | 1536 | **2560** |
90+
91+The 256-unit excess is exactly the 8 unclipped transform rows x 32 columns past
92+the frame bottom, per inter frame. Chroma was already clipped — the
93+`read_inter_chroma_lossless` loop carries its own
94+`if cpx + ox >= u.true_width || cpy + oy >= u.true_height { continue; }` — which
95+is why only the LUMA side of the walk diverged.
96+
97+## 3. The fix
98+
99+Both lossless leaf builders now clip. `decode.rs`, `read_block_tx_size`:
100+
101+```rust
102+let side_mi = side / MI;
103+let max_w_mi = side_mi.min(mi_cols.saturating_sub(at_mi.1));
104+let max_h_mi = side_mi.min(mi_rows.saturating_sub(at_mi.0));
105+```
106+
107+and `read_block_tx_size_rect` the same over `(bw, bh)`. Two hit counters ride
108+along: `lossless_edge_clipped()` (blocks whose grid the clip shortened) and
109+`lossless_edge_clip_units()` (units removed).
110+
111+**The clip is inert when the block fits** — for any block whose `at_mi + side/MI`
112+is inside the frame, `min` returns `side_mi` and the leaf vector is
113+byte-identical. That is the structural reason 4:2:0 cannot move, and the gate's
114+control arm pins it.
115+
116+### After
117+
118+| measurement | before | after |
119+|---|---|---|
120+| frames byte-exact vs oracle aomdec (decode order) | 1 of 6 | **6 of 6** |
121+| worst frame wrong samples | 33561 | **0** |
122+| `EC_SYMR` reads, ours | 258035 | **235940** |
123+| `EC_SYMR` reads, oracle | 235945 | 235945 |
124+| first `EC_SYMR` fork | read 71322 | **none, all 235940 paired** |
125+
126+## 4. Gate
127+
128+`stream::tests::a_lossless_block_clips_its_transform_grid_at_the_frame_edge`,
129+same fixture as its sibling
130+`a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major` (96 is not a
131+multiple of the 128 superblock — that is the entire reason this stream is the
132+witness).
133+
134+| # | assertion | value |
135+|---|---|---|
136+| 1 | `lossless_edge_clipped()` delta | **5** = one 128 root per inter frame. Reads 0 on a frame that fits, so a stream that merely decodes cannot satisfy it |
137+| 2 | `lossless_edge_clip_units()` delta | **1280** = 5 x 256 (8 rows x 32 cols removed per root) |
138+| 3 | every sample of all 6 frames vs oracle `aomdec --rawvideo`, decode order | exact |
139+| 4 | control arm (`ll444_minp64_128root_control`): both clip counters | **0 / 0** — the clip is a no-op where blocks fit |
140+
141+### Mutation proof (run, not asserted)
142+
143+Reverting only the two clip expressions to the unclipped grid, keeping the gate
144+and the counters:
145+
146+```
147+=== MUT clip ===
148+test stream::tests::a_lossless_block_clips_its_transform_grid_at_the_frame_edge ... FAILED
149+panicked at crates/ec-av1/src/stream.rs:6924:
150+ the frame-edge clip fired on 0/5 of the 128 roots -- it must be 0 on a frame
151+ that fits, so this is what makes the gate non-vacuous
152+ left: 0 right: 5
153+test result: FAILED. 0 passed; 1 failed
154+SUITE EXIT: 101
155+```
156+
157+Same reverted build, decoded-order dumps vs the oracle — assertion 3's failure
158+mode, captured:
159+
160+```
161+f0: 0 wrong f3: 28492 wrong, first at byte 0
162+f1: 5596 wrong, first at byte 16544 f4: 32289 wrong
163+f2: 25693 wrong, first at byte 0 f5: 33561 wrong
164+```
165+
166+File restored from a saved copy (not `git checkout --`, per
167+`skill://stash-red-before-proof`), re-verified with `diff -q`, then:
168+
169+```
170+=== LIVE ===
171+test ... a_lossless_block_clips_its_transform_grid_at_the_frame_edge ... ok
172+test result: ok. 1 passed; 0 failed
173+EXIT: 0
174+```
175+
176+## 5. Lead (b): blocked by a different defect (not fixed here)
177+
178+`testsrc2 512x128 yuv444p --lossless=1 --cpu-used=2 --lag-in-frames=0
179+--kf-max-dist=100 --limit=6` does **not** reach the entropy fork the ticket
180+describes. It dies first, on the base tree, before and after this fix:
181+
182+```
183+thread 'main' panicked at crates/ec-av1/src/decode.rs:2787:
184+assertion `left == right` failed left: (4, 8) right: (4, 4)
185+ 4: <ec_av1::decode::TxParams>::run
186+ 5: ec_av1::decode::push_mc_rect_tx
187+ 6: ec_av1::decode::read_inter_plane_rect
188+ 7: ec_av1::decode::decode_intrabc_rect
189+ 8: ec_av1::decode::decode_leaf_rect
190+ 9: ec_av1::decode::decode_key_frame_tile_with_cdfs
191+```
192+
193+(release builds wrap the assert and panic one frame later at
194+`decode.rs:2823`, `range end index 4 out of range for slice of length 0`).
195+
196+**Cause, measured.** A temporary env-gated probe at `decode_intrabc_rect`'s
197+residual split:
198+
199+```
200+EC_PROBE_IBC mi=(28,106) bw=8 bh=16 lossless=true leaves=Some(8)
201+```
202+
203+The luma leaves are all TX_4X4 (8 of them, 2 x 4) — the lossless branch is
204+correct. The `(4, 8)` comes from the **chroma** call in the same arm:
205+`decode_intrabc_rect` derives the chroma footprint as
206+`let (cw, ch) = (bw / 2, bh / 2); let (cpx, cpy) = (px / 2, py / 2);` — a
207+hardcoded 4:2:0 halving. At 4:4:4 that block's chroma plane block is 8x16, not
208+4x8, so a **lossless** 4x8 chroma rect transform reaches `TxParams::run`, whose
209+lossless arm requires 4x4 (the Walsh-Hadamard path). Same class the
210+`av1tilerows` lane landed in the lossless 16x4/4x16 chroma-pair walk: a
211+hardcoded 4:2:0-shaped chroma reach at 4:4:4.
212+
213+Confirming it is the whole blocker: the same stream re-encoded with
214+`--enable-intrabc=0` (118365 bytes) decodes on this tree **byte-exact on all six
215+frames** against the oracle aomdec.
216+
217+**Not fixed in this lane.** It is a different defect class from H1, in
218+`decode_intrabc_rect`'s chroma geometry rather than the coefficient reader or
219+the TX-4X4 path this lane owns, and that function carries other lanes' gates
220+(`a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units`,
221+`a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands`). The shape
222+correction is `bw >> ss_x(fctx)` / `bh >> ss_y(fctx)` on `cw`/`ch`/`cpx`/`cpy`;
223+dispatching it to the intrabc-rect owner is cheaper than widening this lane.
224+
225+Also measured, so nobody re-derives it: the cached `g_512x128_notile.obu`
226+under `~/.cache/h4/` is byte-exact on all 7 decode-order frames on this tree —
227+its recipe carries `--enable-rect-partitions=0`, so it never reaches the
228+intrabc rect route.
229+
230+## 6. Invariants — all green on this tree
231+
232+| group | result |
233+|---|---|
234+| new gate `a_lossless_block_clips_its_transform_grid_at_the_frame_edge` | 1 passed, 0 failed (mutation red, §4) |
235+| all `lossless` + `444` gates (`cargo test -- lossless 444`) | **24 passed / 0 failed** |
236+| 4:2:0 lossless + frame-edge gates (17 scoped: `frame_edge`, `partial`, `edge`, `odd`, `lossless`, non-444) | **17 passed / 0 failed** |
237+| sibling `a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major` | ok — its parity assertions 2/3 (4 walks, 1536 chroma units per inter frame) are unchanged and still exact |
238+| `cargo check -p ec-av1` | 0 warnings, 0 errors |
239+| source-scan guards | untouched — no `include_str!` anchor was edited; the only test hunks are in `stream.rs`, the only non-test hunks in the two leaf builders plus the two counters |
240+
241+Full-suite validation is Main's; the runs above are the scoped groups this
242+lane's invariant names.
243+
244+## 7. Refutation notes for the reviewer
245+
246+- The reserved 4:2:0 group-tail chroma SKIP arm and `last_intrabc` tails are
247+ outside every hunk — the diff is the two lossless leaf builders, two counters,
248+ two accessors, one gate.
249+- 4:2:0 unreachability is not the argument here and is not claimed: the clip
250+ changes behaviour for **any** subsampling when a lossless block overhangs the
251+ frame. The 4:2:0 argument is the `min` no-op above, pinned by the gate's
252+ control arm and by the 17 scoped 4:2:0 gates.
253+- The clip reuses the var-tx branch's own variables and its own
254+ `mi_cols`/`mi_rows` definition, so it introduces no new notion of the frame
255+ grid. Its only approximation is that `mi_rows` is `2 * ceil(h / 8)` rather
256+ than libaom's floor `h >> 3`; the two agree on every multiple-of-8 height,
257+ which is the fixture's 96, and differ by at most one 4-px transform row
258+ otherwise — the same approximation the shipped var-tx branch already carries.