forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1ichromatx: close the last block-level chroma tx_type handoff in decode_inter_block

Browse files at this commit

909de54b5dedc5afc958386895e62513b6e38e1fAhmet Kaan GümüşParent: 59edf7d4ebd218
The recorded defect (777/640/554 wrong V samples on the pinned 444_quad_leaf_tx_type witness) does
NOT reproduce on main: 0 wrong on all four frames, byte-identical to the instrumented aomdec. The
recorded numbers are the MUTATION red from lanes/av1444chr.report.md, not a live measurement, and
both fix commits are ancestors (6c33f204 four-unit 4:4:4 arms; 2142d2cf read_inter_rect_chroma
sibling). The three sites were relocated: A and B already resolve per unit; C (the whole-plane square
chroma arm's Some(luma_tx_type)) is an IDENTITY, not a defect -- its single chroma unit reads the
block's own MI (0,0) cell and luma_tx_type is leaves[0]'s coded type (41 reads, 0 differ). What
lands: read_inter_rect_chroma's block-level FALLBACK -- the one live block-level handoff -- is closed
with debug_assert!(leaf_tx_types.is_empty()) naming the defect shape, two counters, and a gate
asserting multi_fallback >= 2 so the assertion cannot go vacuous. Mutation (forcing the covering-leaf
resolve to miss) reds both the assertion and the gate; 0 occurrences of the bad shape across 90
streams (87 committed pins + 3 fresh server encodes).
crates/ec-av1/src/decode.rsmodified+66 -0
@@ -29955,6 +29955,37 @@ fn read_inter_rect_chroma(
29955 }29955 }
29956 Some(t)29956 Some(t)
29957 } else {29957 } else {
29958+ // lane-av1ichromatx: the ONE remaining site in
29959+ // `decode_inter_block` that can hand a chroma unit a
29960+ // BLOCK-level type on a split plane. `covering_leaf_tx_
29961+ // type` found nothing, i.e. no luma leaf covers this
29962+ // unit's own MI cell -- which is exactly the shape a
29963+ // block that coded a SINGLE luma transform has (its
29964+ // leaf list is empty, so every lookup misses). For
29965+ // that block `luma_tx_type` IS the type of the one
29966+ // luma unit whose stamp covers the whole plane, so the
29967+ // fallback is correct there.
29968+ //
29969+ // What is NOT correct is a fallback on a plane with
29970+ // `leaves` NON-empty: then some luma leaf does exist,
29971+ // it simply does not cover this unit's cell, and the
29972+ // block-level value is a DIFFERENT leaf's type. The
29973+ // assertion below is what closes that shape, so the
29974+ // fallback can never again be a silent mistype: the
29975+ // class is "block-level where the unit's own cell
29976+ // says otherwise", and this is its last site.
29977+ hit!(CHROMA_RECT_BLOCK_TX_FALLBACK);
29978+ if multi {
29979+ hit!(CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI);
29980+ }
29981+ debug_assert!(
29982+ leaf_tx_types.is_empty(),
29983+ "lane-av1ichromatx: a multi-unit rect chroma plane fell back to the \
29984+ block-level tx_type while {} luma leaves were coded -- the unit's own \
29985+ av1_get_tx_type cell is then some other leaf's stamp, not \
29986+ luma_tx_type",
29987+ leaf_tx_types.len()
29988+ );
29958 Some(luma_tx_type)29989 Some(luma_tx_type)
29959 };29990 };
29960 let cu_grid = read_inter_plane_rect(29991 let cu_grid = read_inter_plane_rect(
@@ -39718,6 +39749,41 @@ pub(crate) fn chroma_rect_leaf_tx_diff_hits() -> usize {
39718 CHROMA_RECT_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get)39749 CHROMA_RECT_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get)
39719 }39750 }
39720 39751
39752+thread_local! {
39753+ /// lane-av1ichromatx: [`read_inter_rect_chroma`] units that fell through
39754+ /// `covering_leaf_tx_type` to the BLOCK-level `luma_tx_type`, and of those
39755+ /// the ones whose chroma plane is MULTI-unit (`nx*ny > 1`) -- the only
39756+ /// shape where two units of one plane can disagree, i.e. where a
39757+ /// block-level value could actually mistype a unit.
39758+ ///
39759+ /// Why this needs its own number: `CHROMA_RECT_LEAF_TX_HITS` counts the
39760+ /// units that took the covering leaf, so it says nothing about the units
39761+ /// that did NOT -- and the fallback is the only remaining place in
39762+ /// `decode_inter_block` where a chroma unit is handed a block-level type
39763+ /// on a split plane.
39764+ pub(crate) static CHROMA_RECT_BLOCK_TX_FALLBACK: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
39765+}
39766+
39767+thread_local! {
39768+ /// Of [`CHROMA_RECT_BLOCK_TX_FALLBACK`], how many were on a multi-unit
39769+ /// chroma plane -- the non-vacuity bar for the assertion at that site.
39770+ pub(crate) static CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
39771+}
39772+
39773+/// [`CHROMA_RECT_BLOCK_TX_FALLBACK`]: rect chroma units handed the block-level
39774+/// type because no luma leaf covered their own MI cell.
39775+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
39776+pub(crate) fn chroma_rect_block_tx_fallback() -> usize {
39777+ CHROMA_RECT_BLOCK_TX_FALLBACK.with(std::cell::Cell::get)
39778+}
39779+
39780+/// [`CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI`]: of those, the ones whose chroma
39781+/// plane had more than one unit.
39782+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
39783+pub(crate) fn chroma_rect_block_tx_fallback_multi() -> usize {
39784+ CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI.with(std::cell::Cell::get)
39785+}
39786+
39721 fn decode_inter_block(39787 fn decode_inter_block(
39722 dec: &mut SymbolDecoder,39788 dec: &mut SymbolDecoder,
39723 cdfs: &mut Cdfs,39789 cdfs: &mut Cdfs,
crates/ec-av1/src/stream.rsmodified+56 -0
@@ -22040,6 +22040,62 @@ pub(crate) mod tests {
22040 );22040 );
22041 }22041 }
22042 22042
22043+ /// lane-av1ichromatx: the LAST site in `decode_inter_block` that can hand a
22044+ /// chroma unit the BLOCK-level `luma_tx_type` instead of the unit's own
22045+ /// `tx_type_map` cell is [`read_inter_rect_chroma`]'s fallback: the branch
22046+ /// taken when `covering_leaf_tx_type` finds no luma leaf covering the
22047+ /// unit's own MI cell. The decode closes it with an assertion (a
22048+ /// multi-unit chroma plane may only reach the fallback when the block
22049+ /// coded a SINGLE luma transform, whose stamp covers the whole plane and
22050+ /// makes `luma_tx_type` that unit's own cell).
22051+ ///
22052+ /// This gate is the measurement behind that assertion, on the witness that
22053+ /// reaches it: `fixtures/444_rect_strip_leaf_tx_type.obu` (26839 bytes,
22054+ /// sha256 `06174a66e92aaeb751a8e86db59711fcb1f18d74bde2d77e1ef1be7983eb7c80`).
22055+ /// Measured there: the rect arm is called twice, BOTH on a multi-unit
22056+ /// chroma plane (`nx*ny > 1`), and 4 of its 8 units take the block-level
22057+ /// fallback -- every one of them with an EMPTY leaf list, i.e. the
22058+ /// single-luma-unit shape the assertion allows. So `multi_fallback >= 2`
22059+ /// here is the number that says the guarded shape is REACHED (a fallback
22060+ /// count of 0 would leave the assertion vacuous), and the decoded frames
22061+ /// stay byte-exact against instrumented aomdec, which is what says the
22062+ /// fallback still hands the right value on that shape.
22063+ ///
22064+ /// Non-vacuity, by mutation: forcing the covering-leaf resolve to miss on a
22065+ /// multi-unit plane (`…unit_rel_mi).filter(|_| !multi)`) turns the
22066+ /// assertion RED on this same witness --
22067+ /// `a multi-unit rect chroma plane fell back to the block-level tx_type
22068+ /// while 5 luma leaves were coded` -- so the closure is not a comment.
22069+ #[test]
22070+ fn a_multi_unit_rect_chroma_plane_only_falls_back_to_the_block_type_on_a_single_luma_unit() {
22071+ const NAME: &str = "a_multi_unit_rect_chroma_plane_only_falls_back_to_the_block_type_on_a_single_luma_unit";
22072+ const FIXTURE_LEN: usize = 26839;
22073+ const FIXTURE_FNV: u64 = 0xc77f_310c_036d_ff73;
22074+ let _gate_lock = lock_gate_counters();
22075+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
22076+ .join("fixtures/444_rect_strip_leaf_tx_type.obu");
22077+ let stream = std::fs::read(&path)
22078+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
22079+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved");
22080+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
22081+
22082+ let fb0 = crate::decode::chroma_rect_block_tx_fallback();
22083+ let fbm0 = crate::decode::chroma_rect_block_tx_fallback_multi();
22084+ let frames = decode_stream(&stream)
22085+ .unwrap_or_else(|e| panic!("{NAME}: the witness no longer decodes: {e}"))
22086+ .len();
22087+ let fb = crate::decode::chroma_rect_block_tx_fallback() - fb0;
22088+ let fbm = crate::decode::chroma_rect_block_tx_fallback_multi() - fbm0;
22089+ assert_eq!(frames, 3, "{NAME}: expected 3 shown frames");
22090+ assert!(
22091+ fbm >= 2,
22092+ "{NAME}: only {fbm} block-level fallbacks landed on a MULTI-unit chroma plane \
22093+ ({fb} in total) -- the shape the decode's assertion guards is no longer reached, so \
22094+ that assertion is vacuous on this witness"
22095+ );
22096+ eprintln!("{NAME}: {fb} block-level chroma fallbacks, {fbm} of them on a multi-unit plane");
22097+ }
22098+
22043 /// lane-av1readcensus: the 4:4:4 coefficient-UNIT census, pinned.22099 /// lane-av1readcensus: the 4:4:4 coefficient-UNIT census, pinned.
22044 ///22100 ///
22045 /// The lane report `av1444rect` round 4 left an unexplained signal: 63622101 /// The lane report `av1444rect` round 4 left an unexplained signal: 636
lanes/av1ichromatx.report.mdadded+209 -0
@@ -0,0 +1,209 @@
1+# lane-av1ichromatx — the recorded 4:4:4 lossy divergence is ALREADY FIXED on main; the last block-level `tx_type` site is now closed with an assertion
2+
3+Branch `lane-av1ichromatx` (worktree `~/.cache/wt/av1ichromatx`), base `8680e31d` (main).
4+Oracle `~/.cache/aom-oracle/build/{aomdec,aomenc}` (instrumented).
5+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1ichromatx`.
6+
7+## 0. Headline: the ticket's premise does not reproduce
8+
9+The ticket's recorded divergence (**777 / 640 / 554 wrong V samples on decode-order
10+frames 1/2/3** of `444_quad_leaf_tx_type.obu`) is **not present on current main**.
11+Measured on the unpatched tree, every frame is byte-identical to instrumented
12+`aomdec`'s `EC_AV1_FINAL_DUMP`:
13+
14+```
15+$ EC_AV1_FINAL_DUMP=/tmp/cmpx/ours decode_probe crates/ec-av1/fixtures/444_quad_leaf_tx_type.obu
16+frame 0: len 49152 vs 49152 IDENTICAL
17+frame 1: len 49152 vs 49152 IDENTICAL
18+frame 2: len 49152 vs 49152 IDENTICAL
19+frame 3: len 49152 vs 49152 IDENTICAL
20+```
21+
22+Per-frame wrong-sample counts, decode order: **f0 0, f1 0, f2 0, f3 0** (before AND
23+after this lane's change). Fixture confirmed first:
24+
25+```
26+$ sha256sum crates/ec-av1/fixtures/444_quad_leaf_tx_type.obu
27+a06c9f7a0862252f6ab7ebdcec340d0602e730e38089365f14747db37f8e78d5 (27933 bytes)
28+```
29+
30+It is a committed pin (`crates/ec-av1/src/stream.rs:21241`, fnv `0x85fa830b880090df`,
31+also `scripts/fixture-library.tsv:53`), so the ticket's "may already be a committed
32+pin — reuse it" is the case.
33+
34+**Where 777/640/554 comes from:** it is the PRE-fix / mutation number recorded in
35+`lanes/av1444chr.report.md:77-80` ("reverting only the live arm's resolve … 777
36+bytes differ") and re-measured in `lanes/av1f9singleland.report.md`. The fix is
37+already an ancestor of main:
38+
39+```
40+$ git merge-base --is-ancestor 6c33f204 HEAD && echo ANCESTOR # four-unit arms, BOTH copies
41+ANCESTOR
42+$ git merge-base --is-ancestor 2142d2cf HEAD && echo ANCESTOR # read_inter_rect_chroma sibling
43+ANCESTOR
44+```
45+
46+## 1. Re-locating the three sites (by grep, not by line number)
47+
48+`decode_inter_block` is `decode.rs:39235-44746` and carries TWO textually parallel
49+copies of the chroma arm chain (compound `40673-41297`, single-ref `42442-43105`).
50+Grep for every place a chroma read is handed the BLOCK-level `luma_tx_type`:
51+
52+| # | site | line (single-ref / compound) | state on main |
53+|---|---|---|---|
54+| A | four-unit 4:4:4 arm, per-quadrant resolve | `41258` / `43006` | **already per-unit** (`covering_leaf_tx_type`, 6c33f204) |
55+| B | `read_inter_rect_chroma`, per-unit resolve | `29476` | **already per-unit** (2142d2cf) |
56+| B' | `read_inter_rect_chroma`, block-level FALLBACK | `29482` | **the one live block-level handoff** |
57+| C | whole-plane square chroma arm (`Some(luma_tx_type)`) | `41273`/`41292` / `43081`/`43100` | identity — see §3 |
58+
59+So the ticket's "three sites" are the three site-KINDS (A, B/B', C); A and B were
60+fixed before this lane, B' and C are what remained.
61+
62+## 2. Measuring each site against libaom's real cell
63+
64+`av1_get_tx_type` (`blockd.h:1291-1296`) reads `xd->tx_type_map[blk_row << ss_y][blk_col << ss_x]`,
65+i.e. the unit's OWN cell. A luma leaf stamps its own top-left cell with its coded
66+type; a 64-class leaf additionally stamps every 16-px sub-cell
67+(`decodetxb.c:504-507`); an `all_zero` leaf stamps `DCT_DCT` at its own cell
68+(`decodetxb.c:199-203`). I modelled those three stamp rules in a temporary probe
69+and compared, per site, the block-level value against the cell the unit's own
70+position reads.
71+
72+```
73+444_rect_strip_leaf_tx_type.obu site1=8/2 site2=13/0 site3=20/0 leaf0=13/13 agree=24/0
74+w_sb64_1to4_cq24.obu (new) site1=150/0 site2=1/0 site3=2/0 leaf0=1/1 agree=150/0
75+w_sb128_1to4_cq20.obu (new) site1=150/0 site2=1/0 site3=4/0 leaf0=1/1 agree=150/0
76+w_sb64_1to4_cq30.obu (new) site1=146/0 site2=1/0 site3=4/0 leaf0=1/1 agree=146/0
77+```
78+
79+(read as `reads/differs-from-own-cell`)
80+
81+* **A (four-unit arms)** — resolved per quadrant; `agree=0` disagreements between
82+ `covering_leaf_tx_type` and the true stamped cell across 470 resolves.
83+* **C (whole-plane square arm)** — 41 reads, **0 differ**. Its argument: that arm
84+ reads ONE chroma unit covering the whole plane, so its own cell is the block's
85+ MI (0,0), and `luma_tx_type` is `first_tx_type` = `leaves[0]`'s coded type.
86+ Measured `leaves[0]` at MI (0,0) in **15/15** vartx blocks, so C is an identity,
87+ not a defect. It is also vacuous to "fix": resolving `(0,0)` returns the same
88+ value.
89+* **B' (rect fallback)** — the only site that can still hand a block-level type to
90+ a chroma unit. It fires **4x** on the pinned rect witness, all on a MULTI-unit
91+ chroma plane. That is the shape where a block-level value could mistype a unit,
92+ so it needed closing rather than measuring.
93+
94+## 3. Why B' is safe, and what closes it
95+
96+Every observed B' firing has `leaves == 0`:
97+
98+```
99+$ EC_TEMP_SITES=1 decode_probe crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obu
100+TEMPFB multi=true leaves=0 rel_mi=(0, 0) luma=DctDct first=None x2
101+TEMPFB multi=true leaves=0 rel_mi=(8, 0) luma=DctDct first=None x2
102+TEMPNZ nz=0 / nz=1 / nz=13 (units that took the fallback DO carry coefficients)
103+```
104+
105+`leaves == 0` means the block coded a SINGLE luma transform, whose own stamp
106+covers the whole plane, so `luma_tx_type` **is** that unit's cell — the fallback is
107+correct. The shape that would be wrong is a fallback on a plane while
108+`leaves` is NON-empty (some leaf exists, it just does not cover this unit's cell,
109+so the block-level value is a *different* leaf's type). Measured over the 87
110+committed fixtures plus 3 fresh streams (90 streams, decode_probe, debug build):
111+**0 occurrences**.
112+
113+Closed with an assertion, not a comment (`decode.rs:29482`):
114+
115+```rust
116+hit!(CHROMA_RECT_BLOCK_TX_FALLBACK);
117+if multi { hit!(CHROMA_RECT_BLOCK_TX_FALLBACK_MULTI); }
118+debug_assert!(
119+ leaf_tx_types.is_empty(),
120+ "lane-av1ichromatx: a multi-unit rect chroma plane fell back to the block-level \
121+ tx_type while {} luma leaves were coded -- the unit's own av1_get_tx_type cell \
122+ is then some other leaf's stamp, not luma_tx_type",
123+ leaf_tx_types.len()
124+);
125+```
126+
127+## 4. Red-before (mutation) — the closure bites
128+
129+Forcing the covering-leaf resolve to miss on a multi-unit plane
130+(`covering_leaf_tx_type(leaf_tx_types, unit_rel_mi).filter(|_| !multi)`):
131+
132+```
133+$ cargo test -p ec-av1 --lib -- --exact stream::tests::a_multi_unit_rect_chroma_plane_...
134+lane-av1ichromatx: a multi-unit rect chroma plane fell back to the block-level tx_type
135+while 5 luma leaves were coded -- the unit's own av1_get_tx_type cell is then some
136+other leaf's stamp, not luma_tx_type
137+test result: FAILED. 0 passed; 1 failed
138+```
139+
140+Reverted; green again: `4 block-level chroma fallbacks, 4 of them on a multi-unit plane`.
141+
142+## 5. New gate (non-vacuous)
143+
144+`stream::tests::a_multi_unit_rect_chroma_plane_only_falls_back_to_the_block_type_on_a_single_luma_unit`
145+
146+Pins `fixtures/444_rect_strip_leaf_tx_type.obu` (26839 B, fnv `0xc77f310c036dff73`),
147+asserts `multi_fallback >= 2` — the number that says the guarded shape is REACHED,
148+so the assertion cannot go vacuous — and the same mutation above turns it red.
149+Measured: 4 fallbacks, 4 of them multi-unit.
150+
151+## 6. Neighbours re-quoted (no SKIP, all compared against instrumented aomdec)
152+
153+```
154+a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type ok (96 quad-resolved units, 8 differed)
155+the_pinned_444_quadrant_witness_is_the_single_reference_arms_... ok (88/96 single-ref, 8 changed an answer)
156+a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf ok (4 resolved, 2 differed)
157+a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact ok
158+a_lossless_444_defaultp_inter_strip_stream_decodes_byte_exact ok
159+a_multi_unit_rect_chroma_plane_only_falls_back_... (new) ok (4/4)
160+test result: ok. 6 passed; 0 failed; 0 ignored
161+```
162+
163+Per-frame byte comparison against `EC_AV1_FINAL_DUMP`, before and after the change —
164+identical, all EXACT:
165+
166+| stream | frames | result |
167+|---|---|---|
168+| `444_quad_leaf_tx_type.obu` | 4 | f0-f3 EXACT |
169+| `444_rect_strip_leaf_tx_type.obu` | 3 | f0-f2 EXACT |
170+| `ll444_defaultp_inter_strip.obu` | 7 | f0-f6 EXACT |
171+| `ll444_minp64_inter.obu` | 6 | f0-f5 EXACT |
172+| `av1_192x128_8bit_intra64_in_inter.obu` (4:2:0 control) | 6 | f0-f5 EXACT |
173+| `w_sb64_1to4_cq24.obu` (new, server) | 6 | f0-f5 EXACT |
174+| `w_sb128_1to4_cq20.obu` (new, server) | 6 | f0-f5 EXACT |
175+| `w_sb64_1to4_cq30.obu` (new, server) | 6 | f0-f5 EXACT |
176+
177+## 7. tx_type evidence — the 2 `DCT_DCT` chroma units on V, frame 1
178+
179+`EC_TRACE_TXTYPE=1`, per decode-order frame, chroma units only:
180+
181+```
182+frame 1: 32 chroma units, tx_type=DctDct at U(0,32) V(0,32) U(64,96) V(64,96)
183+ inherited DctDct -> Some(DctDct) on all four
184+frame 2: 32 chroma units, tx_type=DctDct at U(64,96) V(64,96)
185+frame 3: 32 chroma units, tx_type=DctDct at U(64,96) V(64,96)
186+```
187+
188+So frame 1 has **exactly 2 `DCT_DCT` chroma units on V** — `V(0,32)` and `V(64,96)` —
189+and they are exactly the quadrants that sit over a luma leaf which coded NOTHING:
190+the value comes from `covering_leaf_tx_type`, i.e. from that leaf's `all_zero`
191+`DCT_DCT` stamp (`decodetxb.c:199-203`), while the block-level type on those blocks
192+is `Idtx`. That is the ticket's H2 mechanism, already landed; 4 + 2 + 2 = 8 units,
193+which is precisely the `diff = 8` the existing gate asserts.
194+
195+## 8. What remains
196+
197+* Nothing in this class is open in `decode_inter_block`: A and B resolve per unit,
198+ C is an identity by construction (measured 15/15), B' is closed by assertion.
199+* **4:2:2 is out of scope and provably so**: `stream.rs:1766` refuses
200+ `subsampling_x != subsampling_y` by name at the sequence header, so the
201+ `invalid_ss_plane` (8x32 luma → 4x8 chroma) path inside
202+ `read_inter_rect_chroma`, whose units sit at luma MI cells a single 8x32 leaf
203+ stamps only at (0,0), can never be reached.
204+* `covering_leaf_tx_type` models the leaf's own stamp, not libaom's
205+ never-cleared map. For every shape reachable today (leaf tops align with the
206+ chroma-unit grid, or a 64-class leaf stamps the whole area) the two coincide —
207+ measured 0 disagreements in 470 resolves. A stream where a chroma unit's cell
208+ lands strictly INSIDE a sub-64 luma leaf would expose the difference; no such
209+ shape is reachable with the current arm conditions.