forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1422a2a4: intrabc var-tx tail no longer clobbers the per-leaf band

Browse files at this commit

05d59ea237122024f4cc57b50c8eb20a446d53b3Ahmet Kaan GümüşParent: 13a1ba36c3a872
A4 (sha256 e680b638..., 30937 B) refused mid-tile on efd1adf0 with the
subsize string. Both oracles decode those bytes. The refusal was a desync:
decode_block's tail published a block-level TXFM context after an intrabc
var-tx tree, resetting left_txfm 16 to 8. The next tree read ctx 10 where
libaom reads 9. Both publishes are now gated on the tree having run.
The subsize guard is unchanged. decode_intrabc_owned_rect is not in the diff.

Reviewer PASS 0.92. Re-decoded A2, A3, and A4 byte-exact vs ffmpeg and
aomdec. Both tail mutations red at the gate's own assert (stream.rs:9755).

Correction, not in the lane text: the gate pins size and FNV-1a64, not
sha256. The sha equality to the hunt stream was proven by the reviewer
with sha256sum and cmp, and is not what the gate enforces.
crates/ec-av1/fixtures/422_intrabc_vartx_mixedtree_a4.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+42 -8
@@ -24525,13 +24525,32 @@ fn decode_block(
24525 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));24525 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
24526 neighbours.record_palette_uv(at, side, puv_size, puv_colors);24526 neighbours.record_palette_uv(at, side, puv_size, puv_colors);
24527 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);24527 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
24528- neighbours.fill_lf_grid(24528+ if intrabc_leaves.is_some() {
24529- (r * (SUB / MI), c * (SUB / MI)),24529+ // lane-av1422a2a4: the var-tx tree already published the
24530- side / MI,24530+ // TXFM_CONTEXT bands per leaf ([`read_var_tx_size`] →
24531- logical_tx as u8,24531+ // [`txfm_partition_update_rect`]); [`Self::fill_lf_grid_rect`]'s
24532- 0,24532+ // whole-footprint publish would overwrite them with the block's own
24533- fctx,24533+ // `logical_tx` -- the same class [`Self::fill_lf_grid_rect_after_vartx`]
24534- );24534+ // exists for (lane-av1oddheightfork3). Only the deblock grid is
24535+ // still wanted here, so publish nothing.
24536+ neighbours.fill_lf_grid_rect_after_vartx(
24537+ (r * (SUB / MI), c * (SUB / MI)),
24538+ side / MI,
24539+ side / MI,
24540+ logical_tx as u8,
24541+ logical_tx as u8,
24542+ 0,
24543+ fctx,
24544+ );
24545+ } else {
24546+ neighbours.fill_lf_grid(
24547+ (r * (SUB / MI), c * (SUB / MI)),
24548+ side / MI,
24549+ logical_tx as u8,
24550+ 0,
24551+ fctx,
24552+ );
24553+ }
24535 // lane-t900 r32 / lane-av1txbands: libaom runs `set_txfm_ctxs(mbmi->tx_size,24554 // lane-t900 r32 / lane-av1txbands: libaom runs `set_txfm_ctxs(mbmi->tx_size,
24536 // n4_w, n4_h, skip_txfm && is_inter_block(mbmi), xd)` at the end of EVERY24555 // n4_w, n4_h, skip_txfm && is_inter_block(mbmi), xd)` at the end of EVERY
24537 // `decode_block`. An intra-only frame's blocks also publish their TRANSFORM24556 // `decode_block`. An intra-only frame's blocks also publish their TRANSFORM
@@ -24541,7 +24560,22 @@ fn decode_block(
24541 // "inter" block an intra-only frame codes (`blockd.h:373`). So this call24560 // "inter" block an intra-only frame codes (`blockd.h:373`). So this call
24542 // stays the authority wherever one can appear; with `allow_intrabc` unset24561 // stays the authority wherever one can appear; with `allow_intrabc` unset
24543 // it writes exactly what the grid already did.24562 // it writes exactly what the grid already did.
24544- if allow_intrabc {24563+ //
24564+ // lane-av1422a2a4: `parse_decode_block`'s tx branch (decodeframe.c:1227-1236)
24565+ // is an EITHER/OR. When the var-tx branch ran, `read_tx_size_vartx` already
24566+ // published per-leaf band sizes and libaom NEVER calls `set_txfm_ctxs` --
24567+ // the blanket write below is the `else` branch's publish only. Writing it
24568+ // after a var-tx tree clobbers the per-leaf band values with
24569+ // `leaves[0]`'s transform: measured on the pinned A4 witness (256x224 4:2:2,
24570+ // cq 30), the 32x32 intrabc block at mi(32,8) resolved a mixed tree
24571+ // (8x8 leaves at (0,0)+(0,4), 16x16 leaves at (4,0)+(4,4)), leaving
24572+ // `left_txfm[32..35] == 16`; the blanket write reset those cells to 8, so
24573+ // the NEXT tree's sub-read at (32,16) took `txfm_partition_ctx` 10 where
24574+ // libaom takes 9 (oracle operands: above=16, left=16) -- that frame's first
24575+ // divergent read, surfacing ~30 partition symbols later as the
24576+ // "block size 4x8 ... invalid" refusal (an E6/E7-class desync symptom, not
24577+ // an invalid shape). Gate the blanket write on the tree NOT having run.
24578+ if allow_intrabc && !(intrabc_leaves.is_some() && intrabc_leaves.as_ref().unwrap().len() > 1) {
24545 set_txfm_ctxs(24579 set_txfm_ctxs(
24546 neighbours,24580 neighbours,
24547 (mi_r, mi_c),24581 (mi_r, mi_c),
crates/ec-av1/src/stream.rsmodified+43 -0
@@ -3533,6 +3533,49 @@ pub(crate) mod tests {
3533 }3533 }
3534 }3534 }
3535 3535
3536+ /// lane-av1422a2a4: the firing gate for `decode_block`'s var-tx EITHER/OR
3537+ /// tail at 4:2:2 -- an INTRABC block whose var-tx tree resolved MIXED
3538+ /// leaves, where the old blanket `set_txfm_ctxs` + `fill_lf_grid` publishes
3539+ /// clobbered the per-leaf TXFM_CONTEXT bands libaom keeps.
3540+ ///
3541+ /// Provenance: aomenc profile 2, `testsrc2=size=128x112:rate=25` tiled 2x2
3542+ /// to 256x224, cq 30, 3 frames (`lanes/av1422ibcrect.report.md` §2, stream
3543+ /// A4). The oracle decodes it to completion; the pre-fix tree refused it
3544+ /// mid-tile with the documented `decodeframe.c:1456` subsize string -- the
3545+ /// E6/E7 desync-symptom class, NOT an invalid shape.
3546+ ///
3547+ /// Measured on the pinned bytes: the 32x32 intrabc block at mi(32,8)
3548+ /// resolves leaves (0,0)+((0,4) 8x8, (4,0)+(4,4) 16x16, so
3549+ /// `left_txfm[32..35]` must read 16 when the NEXT tree's sub-unit at
3550+ /// (32,16) row0col0 reads its `txfm_partition` context (oracle operands
3551+ /// `above=16 left=16`, ctx 9). The blanket publishes reset those cells to
3552+ /// 8 -> ctx 10 -> a wrong `is_split` -> the first divergent read, and the
3553+ /// refusal surfaced ~30 partition symbols later.
3554+ #[test]
3555+ fn the_pinned_422_intrabc_vartx_mixedtree_witnesses_decode_pixel_exact() {
3556+ const NAME: &str = "the_pinned_422_intrabc_vartx_mixedtree_witnesses_decode_pixel_exact";
3557+ if !have_ffmpeg() {
3558+ eprintln!("SKIP {NAME}: no ffmpeg");
3559+ return;
3560+ }
3561+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
3562+ .join("fixtures")
3563+ .join("422_intrabc_vartx_mixedtree_a4.obu");
3564+ let data = std::fs::read(&path).unwrap_or_else(|e| {
3565+ panic!(
3566+ "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run",
3567+ path.display()
3568+ )
3569+ });
3570+ assert_eq!(data.len(), 30937, "{NAME}: pinned witness size drifted");
3571+ assert_eq!(
3572+ fnv1a64(&data),
3573+ 0x6f0fc77c2217910a_u64,
3574+ "{NAME}: pinned witness bytes drifted"
3575+ );
3576+ assert_422_stream_pixel_exact(NAME, &data, 256, 224, 3, 8, true);
3577+ }
3578+
3536 /// lane-av1422ibctxsel: the firing gate for `decode_intrabc_owned_rect`'s3579 /// lane-av1422ibctxsel: the firing gate for `decode_intrabc_owned_rect`'s
3537 /// NON-SPLIT chroma coefficient context at 4:2:2.3580 /// NON-SPLIT chroma coefficient context at 4:2:2.
3538 ///3581 ///
lanes/av1422a2a4.report.mdadded+170 -0
@@ -0,0 +1,170 @@
1+# lane/av1422a2a4 — Re-measure the refused 4:2:2 hunt streams A2 and A4 on current main
2+
3+Base: `efd1adf0` (the `lane/av1422ibctxsel` merge). Worktree:
4+`/home/user/.cache/wt/av1422a2a4`, private target
5+`$HOME/.cache/tgt-av1422a2a4`. No re-encode: both pinned shas verified before
6+any work.
7+
8+## 1. Re-measurement (disposition of the two named streams)
9+
10+Fixture bytes verified this turn, both sha256-match the charter:
11+
12+| stream | sha256 | size | our verdict (pre-fix) | ffmpeg | aomdec |
13+|---|---|---|---|---|---|
14+| A2 `1a165ef9d3d040a5ed29bd2cf41a16178f6cdd44dfff1b5f5596cb993118953b` | 4567 B | **OK, 4/4 frames, byte-exact both oracles** | OK 4 frames | OK 4 frames |
15+| A4 `e680b6386a8a3a961f45424dfe7a8b7faa0e43789cce38eb92f4264af20e036e` | 30937 B | **REFUSED** mid-tile, same subsize string | OK 2 frames | OK 2 frames |
16+
17+The pair-rule fix that closed E6/E7 also un-refused A2 on this main: A2 now
18+decodes all 4 frames byte-exact against ffmpeg rawvideo yuv422p AND against
19+`aomdec --rawvideo`. Geometry from the sequence header (384x288 8-bit 4:2:2),
20+not the filename. Report-only per the charter: A2 reaches no arm beyond the
21+ones already gated (`chroma422_square`/`chroma422_rect` counters already
22+covered by committed pins) — not pinned.
23+
24+**A4 is the E6/E7 class**: both oracles decode the same bytes to completion
25+(2 shown frames, 344064 B raw); we refused mid-tile with
26+
27+```
28+a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at
29+this frame's subsampling mode (libaom: "Block size %dx%d invalid with this
30+subsampling mode", av1/decoder/decodeframe.c:1456, refusing by the same rule)
31+```
32+
33+i.e. a desync symptom, not an invalid shape (oracle rule re-read from
34+`~/.cache/aom-oracle/src/av1/common/common_data.c` `av1_ss_size_lookup[1][0]`:
35+4x8 IS invalid at 4:2:2 — our predicate table is faithful; libaom simply never
36+selects that subsize on a synced decode).
37+
38+Liveness control for the zero/count claims: the compare oracle is ffmpeg; the
39+A4 verdict moved REFUSED→byte-exact after the fix, and the pinned gate's
40+pixel compare reads `ours.len() == 3` frames (2 shown + 1 hidden alt-ref) and
41+asserts every plane against ffmpeg — a flipped oracle sample moves that assert
42+by construction (the assert names frame/plane/sample on mismatch; exercised by
43+the two mutation proofs below, each red with a Y-plane sample mismatch).
44+
45+## 2. A3 (charter's compare-only extra)
46+
47+`/home/user/.cache/av1422ibcrect/A3.obu` exists. It decoded on the old
48+tree; on this main it decodes 4/4 frames and is **byte-exact against both
49+oracles** (ffmpeg and aomdec). No divergence, so compare-only stands; no edit,
50+no pin (its arms are the square-chroma ones the A1/A2 class already covers).
51+
52+## 3. Class sweep (bounded to the two named directories)
53+
54+Every `*.obu` in `/home/user/.cache/av1422ibcrect/` and
55+`/home/user/.cache/ibcrect-hunt/` was decoded with the pre-fix probe and
56+grepped for refusals: **A4 is the only file in either directory refused with
57+that string** (and the only refusal of any kind). 183 files executed, 0 other
58+refusals. Nothing else to disposition.
59+
60+## 4. Localization (first wrong symbol)
61+
62+Both decoders' partition walks agree for the first 36 symbols (byte-identical
63+`(mi, bsize, value)` prefix, sha256-equal). The divergence at symbol 37
64+(32x32 partition at mi(40,16): ours HORZ vs oracle NONE) is downstream — the
65+decoder `tell` had already drifted +963 bits. Rung-by-rung (skill
66+`ec-av1-first-symbol-divergence`):
67+
68+- The (32,0) and (32,8) intrabc var-tx trees match the oracle value-for-value
69+ (`EC_VARTX`/`EC_VARTXCTX` pairing; the earlier apparent ladder fork was
70+ instrument asymmetry — the oracle's `EC_VARTX` rung prints `bitpos`, not
71+ `rng`, so those reads were invisible to the rng ladder. Every printed
72+ symbol still matched → the desync lives in the coefficient phase.)
73+- `EC_TRACE_COEFF` ladders (deduped rng, `SequenceMatcher`): the last long
74+ equal block ends at ours[40646]/aom[40596] — inside the mi(32,16) intrabc
75+ block's own var-tx tree. Read 1 (root, `txfm_split=1 ctx=8`) matches; **read
76+ 2 (sub-unit 16x16 at (32,16) row0col0) is the first wrong symbol**: ours
77+ `ctx=10`, oracle `ctx=9`, both reading `is_split=0` from different CDF rows.
78+
79+`EC_VARTXCTX` operand pairing at that read: oracle `above=16 left=16`; ours
80+`above=16 left=8`. The left operand is `left_txfm[32]` — the TXFM_CONTEXT
81+band cell for mi row 32, col band of the tree's sub-unit — written by the
82+PREVIOUS block (the 32x32 intrabc at mi(32,8)).
83+
84+That block's tree (both sides): split root, 8x8 leaves at (0,0)+(0,4),
85+16x16 leaves at (4,0)+(4,4). Per-leaf publication leaves
86+`left_txfm[32..35] == 16` (the 16x16 leaves' height). Our decode wrote 8:
87+two blanket writes ran AFTER the tree:
88+
89+1. `decode_block`'s tail `set_txfm_ctxs` (decode.rs:24545, the
90+ `lane-t900 r32` arm): wrote `logical_tx = leaves[0].2 = 8` over the whole
91+ footprint, resetting `left_txfm[32..35]` 16→8. libaom's
92+ `parse_decode_block` tx branch (decodeframe.c:1227-1236) is an EITHER/OR:
93+ the var-tx branch publishes per leaf via `txfm_partition_update` and
94+ NEVER calls `set_txfm_ctxs`.
95+2. `decode_block`'s tail `fill_lf_grid` (publishing variant): same overwrite
96+ via the deblock-grid publish.
97+
98+Result: the next tree's sub-read at (32,16) took `txfm_partition_ctx` 10
99+where libaom takes 9 — the frame's first divergent read — and the desync
100+surfaced ~30 partition symbols later as the 4x8 subsize refusal at the leaf-8
101+walk (guard site `decode.rs:37719`, 8x8 VERT at 4:2:2). The subsize guard
102+itself is honest and was NOT weakened.
103+
104+**Function ownership**: the fix site is `decode_block`'s tail publication,
105+NOT `decode_intrabc_owned_rect` (which this lane never touched).
106+
107+## 5. Fix
108+
109+`crates/ec-av1/src/decode.rs`, `decode_block` tail — both blanket publishes
110+gated on the intrabc var-tx tree NOT having run:
111+
112+1. `set_txfm_ctxs` arm: `if allow_intrabc && !(intrabc_leaves.is_some() && …len() > 1)`.
113+2. `fill_lf_grid` arm: when `intrabc_leaves.is_some()`, call
114+ `fill_lf_grid_rect_after_vartx` (deblock grid only, no TXFM band publish)
115+ — the helper `lane-av1oddheightfork3` introduced for exactly this class.
116+
117+`allow_intrabc &&` keeps the intra-only-frame behavior byte-identical (no
118+`allow_intrabc` ⇒ the `set_txfm_ctxs` write was already a no-op restatement of
119+what the grid did; now it simply does not run, and `record_intrabc_mi`
120+follows unchanged). A single-leaf tree (len 1) still publishes — libaom's
121+"unsplit" tree is one leaf covering the block, and the per-leaf publication
122+wrote exactly the block's own size there, so both spellings agree; measured,
123+A4's three trees stay correct with this predicate.
124+
125+## 6. Gate + non-vacuity (mutation proofs)
126+
127+Fixture pinned: `crates/ec-av1/fixtures/422_intrabc_vartx_mixedtree_a4.obu`
128+(30937 B, sha256 `e680b6…036e`, FNV-1a64 `0x6f0fc77c2217910a` — asserted in
129+the gate). Provenance: aomenc profile 2, testsrc2 128x112 tiled 2x2 = 256x224,
130+cq 30, 3 frames (prior report §2 recipe, stream A4).
131+
132+Gate: `the_pinned_422_intrabc_vartx_mixedtree_witnesses_decode_pixel_exact`
133+(stream.rs) — asserts size + FNV fingerprint, decodes via the crate's own
134+4:2:2 pipeline, and asserts every plane byte-equal to ffmpeg (yuv422p).
135+
136+Red-before, one hunk at a time (each mutation rebuilt, gate re-run, reverted):
137+
138+- Mutation 1 (`set_txfm_ctxs` re-armed):
139+ `test result: FAILED. 0 passed; 1 failed` — panicked at stream.rs:9755
140+ (Y-plane sample mismatch vs ffmpeg).
141+- Mutation 2 (`fill_lf_grid` publish re-armed):
142+ `test result: FAILED. 0 passed; 1 failed` — same site.
143+
144+Green after restore. Scoped runs (post-fix tree):
145+
146+- `cargo test -p ec-av1 --lib -- the_pinned_422` → **8 passed, 0 failed**.
147+- `cargo test -p ec-av1 --lib -- intrabc` → **29 passed, 0 failed, 1 ignored**
148+ (pre-existing ignore, untouched).
149+- `cargo test -p ec-av1 --lib -- vartx` → **5 passed, 0 failed**.
150+
151+## 7. Final byte-exact sweep (fixed binary, all four hunt streams)
152+
153+| stream | decode | vs ffmpeg yuv422p |
154+|---|---|---|
155+| A1 | 4 frames | EXACT |
156+| A2 | 4 frames | EXACT |
157+| A3 | 4 frames | EXACT |
158+| A4 | 3 frames (2 shown + hidden alt-ref) | **EXACT** |
159+
160+A4 also byte-exact against `aomdec --rawvideo` (verified after the fix: the
161+344064-byte raw dumps compare equal).
162+
163+## 8. Commit
164+
165+One commit on `lane/av1422a2a4`: the two decode.rs hunks, the pinned fixture
166+(force-added; `fixtures` is gitignored, crate pins negated in .gitignore), and
167+this report. No env-gated probe committed (the temporary `above/left` operand
168+print in `read_var_tx_size`'s EC_ISTEP line was reverted before commit; all
169+tracing used pre-existing `EC_*` flags). No `EC_AV1_ALLOW_422_PROBE` anywhere.
170+`decode_intrabc_owned_rect` untouched.