forge
Explore
Log in

Don't you dare go Hollow

av1h5: report -- band refuted, chunk-major order found and fixed, residual named

Browse files at this commit

339d121d643d4e6933976a3df36bfee7f3d70629Ahmet Kaan GümüşParent: f93609f
lanes/av1h5.report.mdmodified+136 -99
@@ -71,118 +71,155 @@ for a chroma unit; the symbols happen to survive three reads and then diverge.
7171 Nothing here is reconstruction arithmetic — the two decoders are reading
7272 different probability distributions from the same bit position.
7373
74-## 5. Where the row selection goes wrong (the handoff)
7574
76-libaom, `get_txb_ctx_general` (`av1/common/txb_common.h:353-359`), chroma arm:
75+---
7776
78-```c
79-const int ctx_base = get_entropy_context(tx_size, a, l);
80-const int ctx_offset = (num_pels_log2_lookup[plane_bsize] >
81- num_pels_log2_lookup[txsize_to_bsize[tx_size]]) ? 10 : 7;
82-txb_ctx->txb_skip_ctx = ctx_base + ctx_offset;
83-```
77+## 9. RESOLUTION (lane-av1h5 r2, commit `8a91ee14`)
8478
85-Two rows of the port's chroma table matter and the oracle census says both
86-fire. `EC_DBGCTX` on the oracle, whole stream, 9216 chroma units:
79+### 9a. The handoff's suspect site is REFUTED, not fixed
8780
88-```
89-off=7 520 units off=10 8696 units
90-```
81+§5 named `read_plane`'s chroma band (`decode.rs:19627-19636`) and pointed at
82+`luma_skip_ctx`. I instrumented the band selection on our side (a
83+`EC_DBGCTX`-shaped rung printing `plane`, `tx`, `above0`, `left0`, `base`,
84+`off`, `ctx`) and diffed it against the oracle's own `EC_DBGCTX` for all
85+**9216** chroma units of the stream.
9186
92-and at the fork site itself (`mi=0,0`, the first inter block) every chroma unit
93-is `tx=0` (TX_4X4 — lossless forces it) with **`off=7`**:
87+**The band is correct at 100% of them.** After the port's `+7` reindex
88+(our rows 0..2 are libaom's 7..9, our 3..5 are libaom's 10..12):
9489
9590 ```
96-EC_DBGCTX mi=0,0 plane=1 tx=0 above0=0 left0=0 base=0 off=7 ctx=7 cellsA=0, cellsL=0,
97-EC_DBGCTX mi=0,0 plane=2 tx=0 above0=0 left0=0 base=0 off=7 ctx=7 cellsA=0, cellsL=0,
91+compared=9216 off/ctx diffs=0
9892 ```
9993
100-`read_plane` (`decode.rs:19627-19636`) picks the band like this:
94+Frame 0 (1536 units) matches the oracle unit-for-unit. Frames 1–5 are
95+**100% `off=10`** on both sides — the 520 `off=7` units in the oracle census
96+are all frame 0 (measured with `--limit=1/2/3`: 1536 / 3072 / 4608). §5's
97+"at the fork site every chroma unit is tx=0 with off=7" was a grep that
98+matched frame 0's `mi=0,0` lines, which recur in every frame.
99+
100+So the offset term was never wrong, and no `+3` was missing. **Do not touch
101+`read_plane`'s band.** (Its doc comment, which scoped the `+3` to "a 128x128
102+block's TX_32X32 chroma units", is now corrected: the 4:4:4 lossless 128
103+root's TX_4X4 chroma units read the offset-10 rows too.)
104+
105+### 9b. The real defect: the token order at a 128 root is chunk-major
106+
107+Our chroma stream diverged from the oracle's at unit **1539** with the band
108+right and `ctx_base` wrong — a left-context that had not been published yet.
109+Instrumenting the walk that produces it (`read_inter_chroma_lossless`) with
110+its caller, region and unit geometry:
101111
102-```rust
103-let skip_ctx = if plane_idx == 0 {
104- luma_skip_ctx.unwrap_or(0)
105-} else {
106- usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0)
107-};
112+```
113+EC_DBGCTX walk n=1536 at_mi=(0,0) org=(0,0) reg=(64,64) blk=(128,128) true=(128,96)
114+EC_DBGCTX walk n=2049 at_mi=(0,0) org=(64,0) reg=(64,64) blk=(128,128) true=(128,96)
115+EC_DBGCTX walk n=2562 at_mi=(0,0) org=(0,0) reg=(64,64) blk=(128,128) true=(128,96) <-- again
108116 ```
109117
110-and `luma_skip_ctx` / `luma_skip_ctx_rect` (`decode.rs:9361-9411`) return the
111-**luma** formula `SKIP_CONTEXTS[top][left]` — a value that is being used here
112-as the chroma **offset band**. Its own doc comment says the `+3` that reaches
113-the offset-10 rows applies "only [to] a 128x128 block's TX_32X32 chroma units,
114-lane-sb128b r3". **H5 is a 128x128 root with TX_4X4 units**, i.e. exactly the
115-combination that comment does not cover, and it is the only committed-free cell
116-where a 128-root meets lossless. That is where to look first: whether the
117-offset-10 band is being selected (or the offset-7 band) for a 128-root's
118-lossless chroma units, and whether `ctx_base` should be
119-`get_entropy_context` rather than the luma `SKIP_CONTEXTS` table.
120-
121-Note the port's table is **reindexed**: our chroma rows 0..2 stand for libaom's
122-7..9 and our 3..5 for libaom's 10..12, so a raw `ctx` comparison between the
123-two traces is meaningless without that `+7`. Verified on the first two
124-coefficient units of the stream (ours `ctx=0` ↔ oracle `ctx=7`).
125-
126-## 6. Is this Agent04's H1 class?
127-
128-**No — different site, different trigger.** H1 is 4:4:4 **lossy** + a **rect**
129-partition, and its fork is a unit-ordering bug: the rect walk emits a second
130-luma unit where the oracle moves to the chroma plane (the `EC_COEFF_STEP`
131-`plane=0` label on our side is a label bug there). H5 is 4:4:4 **lossless** +
132-a **square 128 root**, and its fork is a single wrong `txb_skip` CDF row inside
133-one unit — the unit walk itself is aligned (the `all_zero` reads pair up with
134-identical `rng` on both sides for the whole prefix). Same broad neighbourhood
135-(4:4:4 chroma coefficient context), different defect. Notified
136-`agent://Agent04-2` so it is not fixed twice.
137-
138-### 6b. The H1/H5 split is formula-halves, and the arms are disjoint
139-
140-`Agent04-2`'s H1 root cause (confirmed to me directly): the 1:4-pair chroma
141-gather runs at the 4:2:0 PAIR extent (16x8 / 8x16), where
142-`is_chroma_reference` reduces both parity clauses to `!ss_y` / `!ss_x`, so the
143-strip is its own chroma reference and the gather reads one extra luma mi row of
144-LEFT context. Their `ctx_base` came out 1 (0 above + 1 left) where the oracle
145-read offset-7 row 7 (= `ctx_base` 0). Pinned fixture 6441 B,
146-sha256 `77f727e7...`, now byte-exact on their branch.
147-
148-The two lanes split ONE formula along its two terms:
118+320 walk calls for 5 inter frames — **64 per frame, where libaom codes 4** —
119+and each `chunkdone` showed `leaves=1024` (the full 32x32 mi block, not the
120+frame's 32x24) firing every 16 leaves:
149121
150122 ```
151-txb_skip_ctx = get_entropy_context(tx_size, a, l) <-- H1: the ctx_base term
152- + (plane_bsize > tx block ? 10 : 7) <-- H5: the BAND/OFFSET term
123+chunkdone idx=15 chunk=(0,0) at=(0,15,4,4) next=Some((0,16,4,4))
124+chunkdone idx=31 chunk=(0,1) at=(0,31,4,4) next=Some((1,0,4,4))
125+chunkdone idx=47 chunk=(0,0) at=(1,15,4,4) next=Some((1,16,4,4)) <-- back to (0,0)
153126 ```
154127
155-**The arms are structurally disjoint, not merely different.** Agent04's fix is
156-the match arm `Some(_) if ss_x(fctx) == 0 => around` inside `match
157-strip_chroma`, and `strip_chroma` is `Some` only from the single setter
158-(`decode.rs:50852`) that the `PARTITION_HORZ_4` / `VERT_4` 16x4 / 4x16
159-`inter_piece` loop runs. A `BLOCK_128X128` unsplit root never reaches that
160-loop, so `mi(0,0)` on this 128-root stream cannot move through Agent04's gate.
161-They are re-running this exact recipe (63429 B, sha256 `bbffb979...`) against
162-base and their tip to turn that argument into a measured "unchanged".
163-
164-**Caveat for whoever measures:** H5 was characterized on a tree that does NOT
165-contain Agent04's fix. The `--max-partition-size=64` control being byte-exact
166-proves the 128 root is necessary, but on its own it says nothing about the
167-`ctx_base` half at that root. Take the re-measurement above as the authority.
168-
169-## 7. What a follow-up lane should do, in order
170-
171-1. Instrument the band selection in `read_plane` (a one-line
172- `EC_DBGCTX`-shaped rung on our side: plane, tx_size, plane_bsize, the chosen
173- offset) and diff it against the oracle's `EC_DBGCTX` for the first inter
174- block. That single run should name the wrong term.
175-2. Fix one class: the 128-root lossless chroma band. Do **not** touch the rect
176- unit walk (H1's territory).
177-3. Re-run the two arms of §2. Both must be byte-exact.
178-4. Then arm a gate: the recipe above at `--cpu-used=0`, `ss (0,0)` + 10-bit
179- header assert, plus a counter on the corrected route so the gate is not
180- blind, and a mutation proof (flip the band back → the gate must go red on
181- the first inter frame, byte 74769).
182-5. Re-measure the committed 4:4:4 / 4:2:0 pins afterwards.
183-
184-## 8. State
185-
186-No commit. `~/.cache/wt/av1h5` carries no source edits — the work was
187-measurement only (EC_SYMR / EC_TRACE_COEFF / EC_DBGCTX traces, all env-gated
188-and pre-existing). No `EC_AV1_ALLOW_422_PROBE` bypass was applied or needed.
128+Ground truth, `decodeframe.c:972-1006`: `decode_token_recon_block` walks
129+`for (row…) for (col…) { for (plane…) { for (blk_row…) for (blk_col…) } }` —
130+the **plane loop is inside the chunk loop**, and `blk_row`/`blk_col` restart
131+at the chunk origin. The chunk grid is `mu_blocks_wide = mi_size_wide[BLOCK_64X64] = 16` mi
132+per axis, i.e. **16 mi across, not 32**.
133+
134+Our var-tx leaf list is a BLOCK-wide raster (32 leaves across at 128), so a
135+chunk's members are **not contiguous**: leaves 0..15 are chunk (0,0) row 0,
136+but chunk (0,0) rows 1..15 are leaves 32..47, 64..79, … A chunk test
137+`(leaves[idx+1].0/16, leaves[idx+1].1/16) != (row/16, col/16)` therefore
138+closed the chunk every **sixteen** leaves, and each of the four chunks' chroma
139+was coded sixteen times — 24576 chroma units per inter frame against the
140+oracle's 1536.
141+
142+Below 64 a block IS one chunk, so the two orders coincide and every committed
143+pin passed. **This is the only committed cell where an unsplit BLOCK_128X128
144+root meets lossless.**
145+
146+### 9c. The fix and the class sweep
147+
148+`grep "row / 16, col / 16"` finds **four** sites carrying the test. All four
149+now sort the leaf walk chunk-major at `side > 64` and take the successor from
150+that order:
151+
152+| site | arm |
153+|---|---|
154+| `decode.rs:13543` | inter 128x64 / 64x128 (compound/intrabc rect) |
155+| `decode.rs:39268` | intra 128 |
156+| `decode.rs:40932` | inter 128x128 (**the H5 cell**) |
157+| `decode.rs:41952` | inter vartx 128 |
158+
159+The order key is `(row/16)*nchunk + (col/16)`, ties broken by the original
160+index, so within a chunk the leaves keep the tree's own raster — which is what
161+libaom's per-chunk `blk_row`/`blk_col` walk is.
162+
163+### 9d. Measured, on the pinned fixture vs `aomdec`
164+
165+| | before | after | oracle |
166+|---|---|---|---|
167+| chroma walks / inter frame | 64 | **4** | 4 |
168+| chroma units / inter frame | 24576 | **1536** | 1536 |
169+| chroma units, whole stream | 124416 | **9216** | 9216 |
170+| first `skip_ctx` divergence | unit 1539 | unit 2573 | — |
171+| first differing pixel byte | 74769 | **90272** | — |
172+| oracle plane sequence / frame | — | 256,256,256,256,128,128,128,128 ×2 | same |
173+
174+Frame 0 is unaffected (it splits, no 128 root) and still matches the oracle
175+exactly on all 1536 chroma units.
176+
177+### 9e. Verification
178+
179+* **Identity**: `lossless_444` 6/6, `sb128` 12/12 (1 pre-existing `#[ignore]`),
180+ `420` 2/2, `vartx` 3/3, `a_real_aomenc_tiny_frame_size_sweep`,
181+ `a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg` all pass.
182+* **Control arm**: the same recipe at `--max-partition-size=64` (61494 B,
183+ sha256 `4cadce41e1f89675…`) decodes **byte-exact** — the 128 root is still
184+ necessary, and the fix does not touch it.
185+* **Gate**: `a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major`,
186+ pin `fixtures/ll444_128root_lossless.obu` (63429 B, sha256 `bbffb979…`,
187+ fnv1a64 `0xf07d47fcfd512658`). Non-vacuous: it asserts `mu_chunk_order_hits`
188+ rose, and pins the first-difference position at `>= 90272`.
189+* **Mutation (red-before)**: rewriting the chunk key back to a block raster
190+ (`(col/16)*1000 + c`) turns the gate **RED**; reverting turns it green.
191+
192+### 9f. NOT fixed — the residual, and what it is not
193+
194+**The fixture is still not byte-exact.** One defect remains, and it is a
195+*different* one, below the chunk-order bug this lane fixed:
196+
197+* first difference: **byte 90272** = decode-order frame 1, sample 4136 →
198+ **Y(32, 40)** (was Y(4, 8)).
199+* first chroma `skip_ctx` divergence: global unit **2573** — frame 1, plane 1,
200+ the clipped lower chunk row.
201+* It is **not** a band/offset error (off matches at every unit) and **not**
202+ the `ctx_base`/left-context gather: at unit 2572 both sides read the SAME
203+ `skip_ctx` (11) and the oracle's unit 2572 publishes level 0 while ours
204+ publishes non-zero. So the two decoders decode *different coefficients*
205+ from an identical CDF row at 2572 — the fork is at the coefficient decode,
206+ not at context selection.
207+
208+That is the next thing to chase, and it needs its own EC_SYMR pass anchored
209+at unit 2572. §7's plan is superseded: **the band is fine, the order was not.**
210+
211+### 9g. Interaction with H1
212+
213+Untouched and unaffected: `strip_chroma` is still `Some` only from the
214+PARTITION_HORZ_4 / VERT_4 setter, which an unsplit BLOCK_128X128 root never
215+enters. This lane's change is the leaf-walk ORDER at `side > 64`; it touches
216+no `strip_chroma` site and no chroma-context predicate, so it cannot double-fix
217+Agent04-2's arm. Their stream should be unaffected — `agent://Agent04-2` was
218+notified.
219+
220+### 9h. State
221+
222+Branch `lane-av1h5`, two commits on top of `4155c7c7`:
223+`11954074` (report as handed over, incl. §6b) and `8a91ee14` (the fix, the
224+gate, the pin). Nothing pushed. All instrumentation was env-gated and has been
225+removed from the commit; no `EC_AV1_ALLOW_422_PROBE` bypass was used or needed.