forge
Explore
Log in

Don't you dare go Hollow

lane-whtshape: report -- the RELEASE premise refuted, the call site fixed, the residual fork named

Browse files at this commit

fd0fee728963c18d9eb453e676b9780cb049d4c1Ahmet Kaan GümüşParent: c465d06
lanes/whtshape.report.mdadded+278 -0
@@ -0,0 +1,278 @@
1+# lane-whtshape — a non-4x4 unit on the LOSSLESS WHT path
2+
3+Branch `lane-whtshape`, base `a21f3680`, one commit
4+`lossless WHT: a non-4x4 unit is reconstructed as a 4x4 raster, not asserted away`.
5+
6+Files touched: `crates/ec-av1/src/decode.rs`, `crates/ec-av1/src/transform.rs`,
7+`crates/ec-av1/src/stream.rs` (the new gate, appended at the end of the
8+`mod tests` block), and the new pin
9+`crates/ec-av1/fixtures/ll444_sb64_1to4_lossless.obu`.
10+Untouched as instructed: the `read_plane` coefficient-reader region (~19600) and
11+`decode_rect_split`.
12+
13+---
14+
15+## r1 — The charter's premise, measured and partly REFUTED
16+
17+The ticket says a RELEASE build "silently runs a wrong-shape transform — silent
18+wrongness, not a panic". **That is wrong, and the measurement matters: RELEASE
19+panics.**
20+
21+`TxParams::run`'s lossless arm was
22+
23+```rust
24+LOSSLESS_WHT_UNITS.fetch_add(1, …);
25+debug_assert_eq!((self.w, self.h), (4, 4));
26+debug_assert_eq!(self.tx_type, TxType::DctDct);
27+crate::transform::dequant_and_inverse_wht4x4(grid, …) // always 16 values
28+```
29+
30+`dequant_and_inverse_wht4x4` dequantizes with `w = h = 4` and returns 16
31+samples. `TxParams::run` then re-lays them at `stride * h`, copying
32+`w` per row for `h` rows — so a `w * h > 16` unit indexes past the 16-long
33+buffer.
34+
35+| profile | behaviour on the witness | where |
36+| --- | --- | --- |
37+| DEBUG | `assertion left == right failed / left: (8, 4) / right: (4, 4)` | `decode.rs:2787` |
38+| RELEASE | `panicked … range end index 8 out of range for slice of length 0` | `decode.rs:4034` (the strided copy in `push_mc_rect_tx`) |
39+
40+So: no silent wrong pixels, but a *worse* bug than silence — the only thing
41+naming the invariant was compiled out of the profile that ships, and release's
42+failure message named neither lossless nor the transform. **No reachable
43+non-4x4 lossless shape is silent**: every such shape has `w * h > 16`, so the
44+strided copy always overruns. (An `8 x 2`-shaped unit would have been silent,
45+but AV1's minimum transform side is 4, so it is not constructible.)
46+
47+### Reproduction
48+
49+Neither witness named in the ticket exists as a pin; both had to be encoded.
50+Probe over all 48 pinned fixtures in a DEBUG build: **zero** trip the assert.
51+Two independent encodes, both 4:4:4 10-bit `--lossless=1 --profile=1 --i444`:
52+
53+```text
54+ffmpeg -f lavfi -i testsrc2=size=<N>x<N>:rate=25:duration=1 -pix_fmt yuv444p10le -f rawvideo src.yuv
55+aomenc --codec=av1 -w N -h N --i444 --bit-depth=10 --input-bit-depth=10 --passes=1
56+ --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 --limit=2
57+ --threads=1 --enable-rect-partitions=1 --enable-1to4-partitions=1
58+ --min-partition-size=4 --max-partition-size=64 --sb-size=64
59+ --tune-content=screen --enable-intrabc=1 --enable-palette=1
60+ --cq-level=60 --enable-tx-size-search=0 --lossless=1 --profile=1 --obu -o out.obu src.yuv
61+```
62+
63+| witness | size | sha256 (16) | DEBUG | RELEASE (pre-fix) |
64+| --- | --- | --- | --- | --- |
65+| 256x256 | 51107 B | `fdb6467987095b99` | assert `(8, 4)` | `range end index 8 … length 0` |
66+| 640x480 | 186912 B | `5e647e3afe60b5f6` | assert `(8, 4)` | `range end index 8 … length 0` |
67+
68+The ticket's `left: (4, 8)` did not reproduce; `left: (8, 4)` did, on both
69+witnesses. Same defect, transposed unit. 4:2:0 cannot produce the shape at all
70+(its smallest lossless chroma plane block is already 4x4) — which is why the
71+gate asserts a 4:4:4 10-bit header.
72+
73+### Localisation
74+
75+A temporary `#[track_caller]` rung on `TxParams::run` and on
76+`read_inter_plane_rect` (both removed before the commit) put every non-4x4
77+lossless unit on one pair of call sites, in `decode_intrabc_rect`'s var-tx arm:
78+
79+```text
80+EC_RECTSITE plane=1 x=104 y=64 w=8 h=4 stride=8 at decode.rs:13392 (U)
81+EC_RECTSITE plane=2 x=104 y=64 w=8 h=4 stride=8 at decode.rs:13410 (V)
82+```
83+
84+A census of `decode_intrabc_rect` over every pinned fixture shows its chroma
85+plane block is `bw / 2` by `bh / 2` — a hardcoded 4:2:0 halving — so a 16x8
86+luma block at 4:4:4 got an 8x4 chroma plane block, and the walk read it as ONE
87+rect transform unit.
88+
89+---
90+
91+## r2 — What libaom actually does, and the decision
92+
93+Four independent places in the reference say a non-4x4 lossless transform unit
94+cannot exist:
95+
96+1. `av1/decoder/decodeframe.c:140` — `read_tx_mode(rb, coded_lossless)`:
97+ `if (coded_lossless) return ONLY_4X4;` before the `tx_mode` symbol is even
98+ considered.
99+2. `av1/decoder/decodeframe.c:1117` — `read_tx_size`:
100+ `if (xd->lossless[…]) return TX_4X4;` before any tree.
101+3. `av1/common/blockd.h:1447` — `get_vartx_max_txsize`:
102+ `if (xd->lossless[…]) return TX_4X4;` for EVERY plane, which is what sizes
103+ the units `decode_token_recon_block` actually reads.
104+4. `av1/common/idct.c:50` — the WHT dispatch. Of
105+ `highbd_inv_txfm_add_{4x4,4x8,8x4,16x4,…}_c`, **only** the 4x4 one carries a
106+ `lossless` branch (`if (lossless) { av1_highbd_iwht4x4_add(…); return; }`).
107+ Every other size falls straight through to the IDCT network.
108+
109+Point 4 is the decisive one for the "refuse or split?" question: libaom has no
110+non-4x4 lossless inverse transform to dispatch *to*, because points 1–3 make
111+the unit unreachable. So a non-4x4 lossless unit here is not a bitstream shape
112+to be decoded — it is this decoder's own unit geometry being wrong.
113+
114+**Decision: split into 4x4 WHT calls, counted.** Not a refusal: refusing would
115+turn a geometry bug into a decode failure with no way to see the pixels, and
116+`TxParams::run` has no `Result` channel to the point where a refusal could be
117+surfaced (it is called from the recorded-replay worker as well as inline).
118+Splitting makes the function *total*: no shape panics, no shape returns a
119+buffer its caller cannot index, release and debug agree, and the numbers are
120+the ones a correct per-4x4 caller would have written for the same footprint.
121+`LOSSLESS_WHT_SPLIT_UNITS` counts every 4x4 tile reconstructed this way, so a
122+caller that regresses is *named* rather than absorbed.
123+
124+The 4x4 fast path is the same single `dequant_and_inverse_wht4x4` call it
125+always was — `the_4x4_lossless_fast_path_is_unchanged` asserts byte-identity
126+with and without the shape dispatch.
127+
128+The `debug_assert_eq!(self.tx_type, TxType::DctDct)` went with it: the WHT
129+takes no `tx_type` (libaom's `av1_iwht4x4_add` does not either) and
130+`av1_get_tx_type` already answers `DCT_DCT` on every plane of a lossless block,
131+so it asserted an argument nothing reads — a debug-only panic on a value
132+release ignores, i.e. the same divergence class.
133+
134+---
135+
136+## r3 — The call site, and the defect this lane does NOT own
137+
138+`decode_intrabc_rect`, lossless arm:
139+
140+* chroma plane block = `bw >> ss_x` by `bh >> ss_y` at `(px >> ss_x,
141+ py >> ss_y)` — `av1_get_max_uv_txsize` is `ss_size_lookup[bsize]`, no halving
142+ of its own, so at 4:4:4 it is the block's own footprint;
143+* walked as a `(cw/4) * (ch/4)` PLANE-MAJOR raster of TX_4X4 units through the
144+ existing `read_inter_chroma_lossless` (the same helper the inter 8x8 and 128
145+ paths use), matching `decode_token_recon_block`'s
146+ `for plane { for blk_row { for blk_col } }`;
147+* each unit's own coefficient context replayed **over** the whole-block
148+ `record_split_luma_rect_mi` from the composed grid — class
149+ `override-slot-on-one-arm`, the same one `decode_rect_split`'s
150+ `ll_chroma_units` replay exists for. (Getting this order wrong first cost
151+ the exact prefix below: with the replay *before* the record, frame 0's first
152+ divergence sat at x=226 and 18376 luma samples were wrong; after it, x=224
153+ and 16022.)
154+
155+**Scoped to `lossless` on purpose.** The 4:2:0 halving is correct at 4:2:0.
156+Every pinned 4:4:4 stream that reaches `decode_intrabc_rect` does so LOSSY
157+(measured: the `lossless`-gated census over all 48 pins returns nothing), and
158+that 4:4:4 lossy footprint is a separate, already-named open cell —
159+`lanes/av1444rect.report.md`'s 4:4:4 intra-BC chroma. This lane does not move
160+it. A lossless-only split changes no green pin either way.
161+
162+### OPEN after this lane (measured, not guessed)
163+
164+Pinned witness, 256x256 4:4:4 10-bit, 2 frames, 196608 samples per frame:
165+
166+| frame | plane | differing | first differing sample |
167+| --- | --- | --- | --- |
168+| 0 (key) | Y | 16022 / 65536 | 32992 → (x=224, y=128) |
169+| 0 (key) | U | 16985 / 65536 | 32992 → (x=224, y=128) |
170+| 0 (key) | V | 17047 / 65536 | 32992 → (x=224, y=128) |
171+| 1 (inter) | Y | 1681 / 65536 | 55008 → (x=224, y=214) |
172+| 1 (inter) | U | 4071 / 65536 | 9378 → (x=162, y=36) |
173+| 1 (inter) | V | 4078 / 65536 | 9378 → (x=162, y=36) |
174+
175+On the key frame the fork is at the first column PAST the 16x8 lossless
176+intra-BC block at mi (32, 52) = px (208, 128) — that block's own 16x8 luma and
177+chroma are byte-exact, so the fork is at the block boundary, in the block that
178+follows it. That is an entropy desync in a *different* block's residual walk,
179+not the WHT shape: `LOSSLESS_WHT_SPLIT_UNITS` is 0 and no non-4x4 lossless unit
180+exists anywhere in the decode. Not chased here — it is a distinct defect in a
181+distinct path.
182+
183+The gate therefore asserts a measured per-frame, per-plane exact **prefix**, and
184+says so in its own doc comment. Asserting "our output is wrong by exactly N"
185+would encode the defect as expected behaviour; the prefix is the honest form
186+and it only ever grows.
187+
188+---
189+
190+## r4 — Gate and mutation proof
191+
192+`stream::tests::a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units`
193+(pinned fixture, length + FNV asserted first, 4:4:4 10-bit header asserted):
194+
195+1. `intrabc_rect_lossless_chroma4_hits() > 0` — `INTRABC_RECT_LOSSLESS_CHROMA4_HITS`
196+ is EXCLUSIVE to the per-4x4 chroma walk (no other caller walks a rect
197+ intra-BC block's chroma), so `>= 1` cannot be satisfied by the old
198+ single-unit read.
199+2. `lossless_wht_split_units()` delta `== 0` — the shape-total entry is not
200+ quietly papering over a caller that is still wrong.
201+3. `lossless_wht_units()` delta `> 0` — not vacuous.
202+4. Both frames decode, and every decode-order frame's per-plane exact prefix
203+ matches the oracle's own `EC_AV1_FINAL_DUMP`.
204+
205+Plus four unit tests in `transform::lossless_tx_tests` covering the total entry
206+directly (raster equality against independently-composed per-unit 4x4 calls for
207+8x4 / 4x8 / 8x8 / 16x4 / 4x16 / 16x16, the 4x4 fast-path identity, the
208+empty-grid marker, and the partially-zero grid whose other tiles hit the empty
209+marker — that last one caught a real index panic in my first draft).
210+
211+### Mutation results (RELEASE profile, where the debug-only assert never ran)
212+
213+```
214+MUT1 decode_intrabc_rect reverted to the single rect unit + the 4:2:0 halving
215+ -> RED panicked at stream.rs:43682
216+ "the pinned witness was refused: unsupported: AV1 tile
217+ (a Golomb tail longer than this decoder reads)"
218+ test result: FAILED. 0 passed; 1 failed
219+
220+MUT2 dequant_and_inverse_wht forced back to the 4x4-only path
221+ -> stream gate: GREEN (survives -- see finding below)
222+ -> lossless_tx_tests: RED
223+ a_non_4x4_lossless_unit_is_the_raster_of_4x4_wht_units FAILED
224+ assertion left == right failed: 8x4: residual length left: 16 right: 32
225+ a_lossless_split_whose_other_tiles_are_all_zero_still_reconstructs FAILED
226+ assertion left == right failed: 8x4 residual length left: 16 right: 32
227+ test result: FAILED. 3 passed; 2 failed
228+
229+MUT3 hit!(INTRABC_RECT_LOSSLESS_CHROMA4_HITS) removed
230+ -> RED panicked at stream.rs:43687
231+ "no LOSSLESS rect intra-BC block walked its chroma as 4x4 units --
232+ the corrected route never ran, so this gate is measuring the old
233+ single rect unit (class gate-blind-to-feature)"
234+ test result: FAILED. 0 passed; 1 failed
235+
236+LIVE restored tree: stream gate ok, lossless_tx_tests 5 passed
237+```
238+
239+**MUT2 survives the stream gate, and that is reported rather than papered over.**
240+Assertion (2) is a *negative* assertion: after the call-site fix no non-4x4
241+lossless unit exists on this stream, so `split == 0` holds whether or not the
242+total entry works. The stream gate therefore cannot be the positive coverage of
243+`dequant_and_inverse_wht` for a non-4x4 shape — the four unit tests are, and
244+they do bite. Do not read the green stream gate as "the split is exercised
245+here".
246+
247+### Regression scope (release, named tests only — no full suite on this box)
248+
249+```
250+lossless 21 passed; 0 failed
251+444 16 passed; 0 failed
252+intrabc_rect 5 passed; 0 failed
253+rect16x4_chroma_reach 1 passed; 0 failed
254+a_444_lossless_sb64 1 passed; 0 failed (the new gate)
255+a_444_intrabc_rect4 1 passed; 0 failed
256+a_444_sb128_witness 1 passed; 0 failed
257+real_aomenc_mixed_lossless 1 passed; 0 failed
258+transform lossless_tx_tests 5 passed; 0 failed
259+```
260+
261+43 named gates across the lossless / 4:4:4 / intrabc-rect surface, green in
262+release. `cargo check -p ec-av1` is warning-free.
263+
264+## r5 — Follow-ups this lane deliberately did not take
265+
266+1. **`read_block_tx_size_rect`'s lossless arm returns before writing the TXFM
267+ bands.** libaom's `parse_decode_block` (`decodeframe.c:1163`) calls
268+ `set_txfm_ctxs(mbmi->tx_size, xd->width, xd->height, …)` on the lossless
269+ path too; our early return skips it. Unreachable on a fully lossless frame
270+ (no `txfm_partition` symbol is read when `tx_mode == ONLY_4X4`), so it is
271+ latent, not measured-wrong. Not fixed here — it is a neighbour-band concern,
272+ not the WHT shape.
273+2. **The 4:4:4 lossy chroma footprint of `decode_intrabc_rect`** (`bw / 2`,
274+ `px / 2`): wrong at 4:4:4, out of this lane's scope, already named in
275+ `lanes/av1444rect.report.md`.
276+3. **The r3 entropy fork**, localised to the block following the first lossless
277+ 16x8 intra-BC rect block on the key frame and to (162, 36) on the inter
278+ frame's chroma.