av1lm444loss-corr: report -- the ss-aware replay step, and why the old branch is do-not-merge
Browse files at this commit9dcbf14aef9badee9ee8337091c2c20bc7479952Parent: 30d94ca1 changed file +202 -0
lanes/av1lm444loss-corr.report.mdadded+202 -0
| @@ -0,0 +1,202 @@ | |||
| 1 | +# lane-av1lm444loss-corr — the ss-aware replay step in `decode_intrabc_rect` | ||
| 2 | + | ||
| 3 | +**Verdict.** One line, one real bug, already on main in everything but that | ||
| 4 | +line. `lane-whtshape` (`f541d062`, merged `afa13bcf`) gave `decode_intrabc_rect` | ||
| 5 | +the lossless per-TX_4X4 chroma walk and its tail replay. The replay stepped the | ||
| 6 | +mi origin by `4 >> ss_y(fctx)` — 4:2:0-only arithmetic — so on a 4:4:4 lossless | ||
| 7 | +frame it stamped every replayed unit at **4x its own mi row/column**, writing | ||
| 8 | +over cells that belong to other blocks. Corrected to `(4 << ss) / MI`, the form | ||
| 9 | +the codebase's own reference construction already uses. | ||
| 10 | + | ||
| 11 | +**Tree.** `lane-av1lm444loss-corr` off current main `4532caa6`, worktree | ||
| 12 | +`~/.cache/wt/av1lm444corr`. One commit, `c9b48f5d`. Not pushed (Main merges). | ||
| 13 | + | ||
| 14 | +## 0. What happened to the previous branch, stated plainly | ||
| 15 | + | ||
| 16 | +`lane-av1lm444loss`'s r2/r3 (`5519aaf8`, `6490933c`, `927dbf09`) is | ||
| 17 | +**DO-NOT-MERGE**, and the review is right: | ||
| 18 | + | ||
| 19 | +* `decode_intrabc_rect` on main already carries the lossless arm from | ||
| 20 | + `lane-whtshape` — ss-aware geometry at `decode.rs:13343`/`:13352`, the | ||
| 21 | + `read_inter_chroma_lossless` walk with `hit!(INTRABC_RECT_LOSSLESS_CHROMA4_HITS)` | ||
| 22 | + at `:13687`, and the tail replay. My `5519aaf8` re-implemented all of that on | ||
| 23 | + a stale base (`a21f3680`), unaware of it. | ||
| 24 | +* Resolved "theirs", it would have **deleted** main's | ||
| 25 | + `INTRABC_RECT_LOSSLESS_CHROMA4_HITS` and replaced main's | ||
| 26 | + `ll_chroma: Option<(Vec, Vec)>` tail with my `mu_chroma: bool` + | ||
| 27 | + `Grid::Own(mu_units(...))`. | ||
| 28 | +* My headline — "two defects, both only at 4:4:4 lossless" — was ~80% already | ||
| 29 | + merged under another lane's name, and my report never mentioned `whtshape`. | ||
| 30 | + | ||
| 31 | +So: I worked blind to main. The old branch's own report also carried stale | ||
| 32 | +provenance (it said "off `a21f3680` with one commit `7b9f46fa`" when by r3 it | ||
| 33 | +was off `9249442f` with five) — a report that misstates its own base is a | ||
| 34 | +defect in itself, and that is recorded here rather than patched there. | ||
| 35 | + | ||
| 36 | +What survives from the old branch and is carried here: the **fixture** and the | ||
| 37 | +**finding** that the step is wrong. What is dropped: the re-implementation. | ||
| 38 | + | ||
| 39 | +This is a new report. The old one's history is left exactly as it was. | ||
| 40 | + | ||
| 41 | +## 1. The line | ||
| 42 | + | ||
| 43 | +`crates/ec-av1/src/decode.rs`, in `decode_intrabc_rect`'s tail replay, on main | ||
| 44 | +at line 13895: | ||
| 45 | + | ||
| 46 | +```rust | ||
| 47 | +// main (WRONG at ss (0,0)): | ||
| 48 | +(mi_r + ur * (4 >> ss_y(fctx)), mi_c + uc * (4 >> ss_x(fctx))), | ||
| 49 | + | ||
| 50 | +// this branch: | ||
| 51 | +(mi_r + ur * ((4 << ss_y(fctx)) / MI), mi_c + uc * ((4 << ss_x(fctx)) / MI)), | ||
| 52 | +``` | ||
| 53 | + | ||
| 54 | +## 2. Mechanism, and the libaom reference for the step | ||
| 55 | + | ||
| 56 | +The replay re-stamps each TX_4X4 chroma unit's own coefficient context, because | ||
| 57 | +the block's whole-block `record_split_luma_rect_mi` / `record_rect_mi` above it | ||
| 58 | +re-stamps the plane from ONE composed grid — level = the sum over units, dc = | ||
| 59 | +the top-left unit's sign. libaom does not compose: `decode_token_recon_block` | ||
| 60 | +(`av1/decoder/decodeframe.c:972`) walks 64x64 "mu" chunks and, inside each, | ||
| 61 | +`for (plane..) for (blk_row..) for (blk_col..)` calls `decode_reconstruct_tx` | ||
| 62 | +per unit, and `av1_set_entropy_context` stamps **that unit's** span. So the | ||
| 63 | +replay's job is to place unit `(ur, uc)` at the mi cell that unit really | ||
| 64 | +occupies. | ||
| 65 | + | ||
| 66 | +A TX_4X4 chroma unit covers `4 << ss` **luma** pixels. The chroma entropy bands | ||
| 67 | +are luma-mi indexed (`Neighbours::record_mi_chroma`'s convention), so the origin | ||
| 68 | +advances by that footprint expressed in mi: | ||
| 69 | + | ||
| 70 | +``` | ||
| 71 | +step = (4 << ss_y) / MI MI = 4 | ||
| 72 | +ss (1,1) 4:2:0: (4 << 1) / 4 = 8/4 = 2 mi | ||
| 73 | +ss (0,0) 4:4:4: (4 << 0) / 4 = 4/4 = 1 mi | ||
| 74 | +``` | ||
| 75 | + | ||
| 76 | +which is exactly what `decode_inter_block`'s reference `mu_chroma_units` | ||
| 77 | +construction writes at `decode.rs:43688`: | ||
| 78 | + | ||
| 79 | +```rust | ||
| 80 | +let cu_mi = ( | ||
| 81 | + at.0 + cr * ((cu << ss_y(fctx)) / MI), | ||
| 82 | + at.1 + cc * ((cu << ss_x(fctx)) / MI), | ||
| 83 | +); | ||
| 84 | +``` | ||
| 85 | + | ||
| 86 | +with `cu = 4` on a lossless frame (the same function's `let cu = if lossless(fctx) | ||
| 87 | +{ 4usize } else { 32usize };`). Its own comment states the rule: "a TX_4X4 | ||
| 88 | +chroma unit covers `4 << ss` LUMA pixels ... each unit's own origin sits | ||
| 89 | +`(cu << ss) / MI` mi cells out". The intrabc-rect replay was the outlier that | ||
| 90 | +had `4 >> ss` instead. | ||
| 91 | + | ||
| 92 | +The SPAN argument on the same call, `4 << ss_x(fctx)`, was already the | ||
| 93 | +ss-aware form on main. Only the STEP was not — which is why the two sit | ||
| 94 | +adjacently and disagree, and why the bug is invisible at 4:2:0. | ||
| 95 | + | ||
| 96 | +## 3. Why 4:2:0 is unchanged — by construction, then measured | ||
| 97 | + | ||
| 98 | +At ss (1,1) the old expression is `4 >> 1` = **2** and the new one is | ||
| 99 | +`(4 << 1) / 4` = **2**. The same integer. So the corrected line cannot alter a | ||
| 100 | +4:2:0 decode at all; this is arithmetic, not an empirical hope, and the 4:2:0 | ||
| 101 | +battery below is confirmation rather than the argument. | ||
| 102 | + | ||
| 103 | +At ss (0,0) the old is `4 >> 0` = **4 mi** = 16 luma px per 4x4 chroma unit, | ||
| 104 | +where the unit covers 4 luma px = 1 mi — a 4x overshoot on both axes. The | ||
| 105 | +replayed states land four mi rows and four mi columns beyond where they belong, | ||
| 106 | +which is sixteen luma pixels out, over cells that belong to other blocks (or to | ||
| 107 | +nothing, past the block's own span). | ||
| 108 | + | ||
| 109 | +4:2:2 is refused upstream by name, so there is no third case to reason about. | ||
| 110 | + | ||
| 111 | +## 4. Reachability and measurement | ||
| 112 | + | ||
| 113 | +Fixture `crates/ec-av1/fixtures/ll444_intrabc_rect_l2.obu` — 121844 bytes, | ||
| 114 | +sha256 `f0de080edce35d34cdd628b71f63dc452f946e8328352b69d3c1da090a54ec67`, | ||
| 115 | +recipe `testsrc2 512x128 yuv444p`, aomenc `--lossless=1 --cpu-used=2 | ||
| 116 | +--lag-in-frames=0 --kf-max-dist=100 --limit=6`, 6 frames. | ||
| 117 | + | ||
| 118 | +**The fixture does reach the corrected step** — no unit-level stand-in needed. | ||
| 119 | +Measured on main's own build, decode order against the oracle aomdec: | ||
| 120 | + | ||
| 121 | +| frame | wrong samples (main) | wrong samples (corrected) | first byte (main) | | ||
| 122 | +|---|---|---|---| | ||
| 123 | +| 0 (key) | **10604** | **0** | **33216** = Y(64,448) | | ||
| 124 | +| 1 | 123987 | 0 | 0 | | ||
| 125 | +| 2 | 171773 | 0 | 0 | | ||
| 126 | +| 3 | 171988 | 0 | 0 | | ||
| 127 | +| 4 | 171783 | 0 | 0 | | ||
| 128 | +| 5 | 151736 | 0 | 0 | | ||
| 129 | + | ||
| 130 | +and the entropy ladder goes from forked to **540833 reads on both sides, zero | ||
| 131 | +fork** (ours 540833 / oracle 540833, every read paired on | ||
| 132 | +`(value, range, symbol, post_rng)`). | ||
| 133 | + | ||
| 134 | +Note the first divergence is **luma**, on a chroma-context defect. That is the | ||
| 135 | +signature of this bug and worth reading as such: the wrongly-placed chroma | ||
| 136 | +stamps corrupt the `txb_skip_ctx` the NEXT unit reads, the tile desyncs, and | ||
| 137 | +the pixels that move first are whichever block comes next in luma. Anyone | ||
| 138 | +chasing a "luma divergence on a chroma fix" should check the step before | ||
| 139 | +suspecting the reconstruction. | ||
| 140 | + | ||
| 141 | +## 5. Gate | ||
| 142 | + | ||
| 143 | +`stream::tests::a_lossless_444_intrabc_rect_replay_steps_by_the_units_own_mi_footprint` | ||
| 144 | + | ||
| 145 | +| # | assertion | what it rules out | | ||
| 146 | +|---|---|---| | ||
| 147 | +| 1 | `(subsampling_x, subsampling_y, bit_depth) == (0, 0, 8)` from the **parsed sequence header** | at (1,1) the two steps are the same integer, so a 4:2:0 stream cannot fail this gate and every other row would pass vacuously | | ||
| 148 | +| 2 | lane-whtshape's own `intrabc_rect_lossless_chroma4_hits()` is nonzero | the walk really ran, so the corrected expression was evaluated — a gate that never reached its own subject | | ||
| 149 | +| 3 | U and V plane extents are luma-sized | the grid the replay steps mi cells through | | ||
| 150 | +| 4 | `decode_all_frames_vs_oracle`: decode-order frame-COUNT parity, then byte-exactness on every frame | and it covers hidden alt-refs | | ||
| 151 | +| 5 | control: the 128x96 4:4:4 lossless pin must read that counter **0** | whole square blocks have no multi-unit chroma plane block, so the step is not exercised there at all | | ||
| 152 | + | ||
| 153 | +The gate uses **main's** counters (`INTRABC_RECT_LOSSLESS_CHROMA4_HITS` and its | ||
| 154 | +`reset_…` helper). Nothing of whtshape's was renamed, removed, or shadowed. | ||
| 155 | + | ||
| 156 | +### Mutation proof (run) | ||
| 157 | + | ||
| 158 | +Reverting only the step expression, counters and gate untouched: | ||
| 159 | + | ||
| 160 | +``` | ||
| 161 | +=== MUT corr === | ||
| 162 | +panicked at crates/ec-av1/src/stream.rs:9396: | ||
| 163 | + decode-order frame 0 of 6 (6 shown, 0 hidden) differs from the oracle at | ||
| 164 | + byte 33216 (ours 101 vs 100), 10604 bytes differ | ||
| 165 | +test result: FAILED. 0 passed; 1 failed | ||
| 166 | +MUT EXIT: 101 | ||
| 167 | + | ||
| 168 | +=== LIVE === | ||
| 169 | +test ... a_lossless_444_intrabc_rect_replay_steps_by_the_units_own_mi_footprint ... ok | ||
| 170 | +LIVE EXIT: 0 | ||
| 171 | +``` | ||
| 172 | + | ||
| 173 | +File restored from a saved copy with `cp`, verified with `diff -q`, `grep -c "MUT | ||
| 174 | +corr"` = 0. | ||
| 175 | + | ||
| 176 | +## 6. Invariants | ||
| 177 | + | ||
| 178 | +| group | result | | ||
| 179 | +|---|---| | ||
| 180 | +| new gate | 1 passed (mutation red, §5) | | ||
| 181 | +| `cargo test -- lossless 444` | **47 passed / 0 failed** | | ||
| 182 | +| `cargo test -- intrabc` | **22 passed / 0 failed / 1 ignored** | | ||
| 183 | +| `cargo test -- <17 scoped 4:2:0 lossless + frame-edge>` | **17 passed / 0 failed** | | ||
| 184 | +| `cargo check -p ec-av1` | 0 warnings, 0 errors | | ||
| 185 | +| source-scan guards | untouched — no `include_str!` anchor edited | | ||
| 186 | +| blast radius | one expression in `decode.rs`; the rest of the diff is the gate plus one test-only helper. `decode_intrabc_rect`'s chroma walk, its `ll_chroma` tail and whtshape's counter are **byte-identical to main** | | ||
| 187 | + | ||
| 188 | +## 7. For the reviewer | ||
| 189 | + | ||
| 190 | +- **Provenance.** This branch is off main `4532caa6` and contains exactly one | ||
| 191 | + commit. The old `lane-av1lm444loss` branch is not to be merged; this one | ||
| 192 | + supersedes it and duplicates none of it. | ||
| 193 | +- **4:2:0.** Stated as arithmetic first (`4 >> 1` == `(4 << 1)/4` == 2) and then | ||
| 194 | + measured (§6). The gate deliberately does **not** claim a 4:2:0 arm: a 4:2:0 | ||
| 195 | + stream cannot fail it, and a floor-on-wrong-output assertion there would be | ||
| 196 | + theatre. | ||
| 197 | +- **Not speculative.** The step is reachable and was measured wrong on main | ||
| 198 | + before the edit (§4): 10604 samples in the key frame, 123987..171988 in the | ||
| 199 | + inter frames. | ||
| 200 | +- **Citation.** The step rule is taken from this codebase's own reference | ||
| 201 | + construction (`decode.rs:43688`) rather than re-derived only from libaom, so | ||
| 202 | + the change matches the shape every other replay in the tree already uses. | ||