diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 6702cce1..62afe159 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -39140,6 +39140,49 @@ thread_local! { /// the number that says the route changed an answer. pub(crate) static CHROMA_QUAD_LEAF_TX_DIFF_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } +thread_local! { + /// lane-av1f9singleland: the SINGLE-REFERENCE copy of + /// [`CHROMA_QUAD_LEAF_TX_HITS`], and the half of its + /// [`CHROMA_QUAD_LEAF_TX_DIFF_HITS`] that belongs to that arm. + /// + /// Why a separate pair rather than trusting the shared counters: the + /// shared ones are bumped from BOTH arms of the four-unit 4:4:4 chroma + /// arm, so a green witness on them says nothing about which arm produced + /// the hits. `decode_inter_block` has two textually parallel copies of + /// that arm -- the compound prediction arm (the `build` closure) and the + /// single-reference arm -- and a refactor can delete or revert either one + /// while the other keeps the shared total non-zero. Measured on the pinned + /// witness `fixtures/444_quad_leaf_tx_type.obu`: 96 units resolve through + /// the covering leaf, and 88 of them are the single-reference arm's, so + /// the shared counter is 92% single-reference and the compound arm alone + /// would be a 4-unit sample of the route it appears to witness. + pub(crate) static CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +thread_local! { + /// Of [`CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS`], how many resolved a type + /// that DIFFERS from the block-level one. This is the arm's own non-vacuity + /// bar: a route count alone stays green through a no-op resolve, because + /// on a block whose four luma leaves all agree the per-quadrant value and + /// the block-level one are the same answer. Mutating only the + /// single-reference arm's `Some(cu_tx_type)` back to `Some(luma_tx_type)` + /// turns the witness red with 777 bytes differing in decode-order frame 1. + pub(crate) static CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// [`CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS`]: single-reference-arm chroma units +/// that took their type from the covering luma leaf. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn chroma_quad_leaf_tx_singleref_hits() -> usize { + CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS.with(std::cell::Cell::get) +} + +/// [`CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS`]: of those, the units whose +/// covering leaf's type differs from the block-level one. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn chroma_quad_leaf_tx_singleref_diff_hits() -> usize { + CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS.with(std::cell::Cell::get) +} /// [`CHROMA_QUAD_LEAF_TX_HITS`]: chroma units that took their type from the /// covering luma leaf. @@ -42963,8 +43006,14 @@ fn decode_inter_block( .unwrap_or(luma_tx_type); if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi).is_some() { hit!(CHROMA_QUAD_LEAF_TX_HITS); + hit!(CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS); + // lane-av1f9singleland: this arm's own + // non-vacuity number -- the shared + // DIFFERS counter below cannot say which + // arm changed an answer. if cu_tx_type != luma_tx_type { hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS); + hit!(CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS); } } let cu_grid = read_inter_plane( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b8aa2361..46528c9c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -21326,6 +21326,106 @@ pub(crate) mod tests { ); } + /// lane-av1f9singleland: `decode_inter_block` has TWO textually parallel + /// copies of the 4:4:4 four-unit chroma arm -- the compound prediction + /// arm (the `build` closure) and the single-reference arm. Both resolve + /// each unit's `tx_type` through `covering_leaf_tx_type` over a + /// `leaf_tx_types` list collected at EVERY size, both bumped the same + /// `CHROMA_QUAD_LEAF_TX_HITS` / `..._DIFF_HITS` pair, and the gate above + /// asserts only that pair. So that gate cannot say which arm its witness + /// came from, and the two arms can be reverted independently. + /// + /// Measured on the gate's own witness `fixtures/444_quad_leaf_tx_type.obu` + /// (the census is the point of this test, so it is quoted rather than + /// assumed): 96 chroma units resolve through their covering luma leaf, of + /// which 88 are the single-reference arm's and 8 the compound arm's; of + /// the 8 units whose resolved type DIFFERS from the block-level one -- + /// the non-vacuity bar, since a block whose four leaves agree makes the + /// per-quadrant resolve a no-op -- ALL 8 are the single-reference arm's. + /// The shared counters' non-vacuity number is therefore 100% + /// single-reference, and the compound arm contributes 8 of 96 route hits + /// and none of the 8 that change an answer. + /// + /// The other 26 pinned 4:4:4 fixtures in this tree reach the arm zero + /// times (`444_intrabc_rect4_witness`, `444_leaf8_oob`, + /// `444_lossy_rect4_*`, `444_lossy_superres_*`, `444_sb128rect_lr_witness`, + /// and every `ll444_*`), so this one witness is the only thing pinning + /// the single-reference copy of the arm at all. + /// + /// Non-vacuity, per the mutation recorded in + /// `lanes/av1f9singleland.report.md`: reverting ONLY this arm's + /// `Some(cu_tx_type)` to `Some(luma_tx_type)` turns this gate red on + /// decode-order frame 1 with 777 bytes differing; gating ONLY this arm's + /// leaf push back behind `if side > 64` (the pre-`6c33f204` state) turns + /// it red with the same 777 bytes. + #[test] + fn the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms() { + const NAME: &str = + "the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms"; + const FIXTURE_LEN: usize = 27933; + const FIXTURE_FNV: u64 = 0x85fa_830b_8800_90df; + let _gate_lock = lock_gate_counters(); + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/444_quad_leaf_tx_type.obu"); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); + + let q0 = crate::decode::chroma_quad_leaf_tx_hits(); + let s0 = crate::decode::chroma_quad_leaf_tx_singleref_hits(); + let sd0 = crate::decode::chroma_quad_leaf_tx_singleref_diff_hits(); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: the witness no longer decodes: {e}")) + .len(); + assert_eq!(frames, 4, "{NAME}: expected 4 shown frames"); + let quad = crate::decode::chroma_quad_leaf_tx_hits() - q0; + let singleref = crate::decode::chroma_quad_leaf_tx_singleref_hits() - s0; + let sr_diff = crate::decode::chroma_quad_leaf_tx_singleref_diff_hits() - sd0; + + assert!( + singleref > quad / 2, + "{NAME}: the single-reference arm resolved {singleref} of {quad} covering-leaf chroma \ + units -- the shared counter is no longer dominated by the arm this gate witnesses, so \ + a revert of the single-reference copy would leave the shared total comfortably non-zero" + ); + assert!( + sr_diff >= 2, + "{NAME}: the single-reference arm's per-quadrant resolve never CHANGED an answer \ + (differing {sr_diff}). A route count alone is not a witness: it fires on every \ + four-unit chroma read, including the blocks whose four luma leaves all agree -- the \ + exact shape a no-op resolve looks green on." + ); + eprintln!( + "{NAME}: {singleref} of {quad} covering-leaf units are the single-reference arm's, \ + {sr_diff} of which changed an answer" + ); + + // 4:2:0 control, as in the gate above: the four-unit arm is the 4:4:4 + // (`ss 0/0`) route only, so the single-reference arm's own counters + // must stay at exactly 0 there too. + let control = std::fs::read( + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/av1_192x128_8bit_intra64_in_inter.obu"), + ) + .unwrap_or_else(|e| panic!("{NAME}: reading the 4:2:0 control: {e}")); + let c_s0 = crate::decode::chroma_quad_leaf_tx_singleref_hits(); + let c_sd0 = crate::decode::chroma_quad_leaf_tx_singleref_diff_hits(); + let c_frames = decode_stream(&control) + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 control no longer decodes: {e}")) + .len(); + assert!(c_frames > 0, "{NAME}: the 4:2:0 control decoded no frames"); + assert_eq!( + ( + crate::decode::chroma_quad_leaf_tx_singleref_hits() - c_s0, + crate::decode::chroma_quad_leaf_tx_singleref_diff_hits() - c_sd0, + ), + (0, 0), + "{NAME}: the 4:2:0 control fired the single-reference arm's four-unit route -- the \ + counter is not specific to the route it claims to witness" + ); + } + /// lane-av1chrtx: the SIBLING of lane-av1444chr's four-unit arm -- a RECT /// inter block's chroma plane, read by `read_inter_rect_chroma`. That /// helper was left handing every unit the block-level `luma_tx_type` diff --git a/lanes/av1f9singleland.report.md b/lanes/av1f9singleland.report.md new file mode 100644 index 00000000..de96bc96 --- /dev/null +++ b/lanes/av1f9singleland.report.md @@ -0,0 +1,237 @@ +# lane-av1f9singleland — the "unlanded" fix was ALREADY ON MAIN (census false positive); landed instead the arm-attribution gap: the four-unit 4:4:4 witness is 88/96 single-reference and 8/8 of the non-vacuity bar, and no gate said so + +## 1. The premise is false: `c7fd5afa` is a duplicate, not an unlanded fix + +The ticket said the fix on `lane-av1-f9single` tip `c7fd5afa` "never reached +main" and that "main still reads `if side > 64` around `decode.rs:42271`". +Both statements are wrong. The cherry-pick and the blame: + +``` +$ git -C ~/.cache/wt/av1f9singleland cherry-pick --no-commit c7fd5afa +Auto-merging crates/ec-av1/src/decode.rs +CONFLICT (content): Merge conflict in crates/ec-av1/src/decode.rs +error: could not apply c7fd5afa... +``` + +``` +$ git merge-base --is-ancestor 6c33f204 HEAD && echo YES # the "compound twin" +YES +$ git merge-base --is-ancestor c7fd5afa HEAD && echo YES # the "unlanded" fix +NO +``` + +`git blame` on the single-reference arm's two sites attributes BOTH to +`6c33f204` — the commit the ticket describes as the *already-landed compound +twin*: + +``` +$ git blame -L 42250,42262 -s crates/ec-av1/src/decode.rs +6c33f2047 42261) leaf_tx_types.push((row, col, tw, th, tu_tx_type)); +$ git blame -L 42636,42644 -s crates/ec-av1/src/decode.rs +6c33f2047 42636) let cu_rel_mi = (cr * (cu_tx / MI), cc * (cu_tx / MI)); +6c33f2047 42637) let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi) +6c33f2047 42639) if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi).is_some() { +6c33f2047 42640) hit!(CHROMA_QUAD_LEAF_TX_HITS); +6c33f2047 42641) if cu_tx_type != luma_tx_type { +6c33f2047 42642) hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS); +``` + +`6c33f204` ("4:4:4 inter chroma units inherit their own quadrant's luma +tx_type") collected `leaf_tx_types` at EVERY size and pointed BOTH copies of +the four-unit arm at the covering lookup. Its own message calls the +single-reference side "the single-reference twin" — the commit was a +twin-flow sweep, not a compound-only change, and the branch census read the +*commit subject* rather than the diff. + +**Main's form is also the better one.** The branch's version inlines a +four-clause `.iter().copied().find(...)` closure; main extracts the shared +`covering_leaf_tx_type` (decode.rs:38785) that the intra 128 path, the rect +sibling and both four-unit arms all call. Cherry-picking the branch would have +reintroduced a fourth inline copy of a convention main had already +deduplicated. So the conflict is a genuine "do not take this" signal, not +something to resolve by hand. + +The `if side > 64` the ticket pointed at (decode.rs:42304 on this tree) is a +DIFFERENT guard — the 128x128 mu-chunk walk from lane-sb128c r1, which is +correctly `side > 64`. The leaf-push guard the fix was about no longer exists; +the push is unconditional. + +## 2. What was actually missing: the witness cannot say which arm it witnessed + +`CHROMA_QUAD_LEAF_TX_HITS` and `..._DIFF_HITS` are bumped from **both** arms +of the four-unit 4:4:4 chroma arm, and +`a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type` +asserts only that pair. `decode_inter_block` carries two textually parallel +copies of that arm — the compound prediction arm (the `build` closure at +decode.rs:39879) and the single-reference arm — so either can be reverted +while the other keeps the shared total comfortably non-zero. + +Measured by arm, on the existing witness `fixtures/444_quad_leaf_tx_type.obu` +(27933 B, sha256 `a06c9f7a0862252f6ab7ebdcec340d0602e730e38089365f14747db37f8e78d5`), +with a temporary arm-separating counter: + +``` +TEMP-PROBE 444_quad_leaf_tx_type.obu: frames 4, quad 96 (diff 8), of which SINGLE-REF 88 (sr diff 8) +TEMP-PROBE 444_rect_strip_leaf_tx_type.obu: frames 3, quad 8 (diff 2), of which SINGLE-REF 8 (sr diff 2) +``` + +**88 of 96** covering-leaf units are the single-reference arm's, and **all 8** +of the DIFFERS units — the number the existing gate uses as its non-vacuity +bar — are the single-reference arm's. The compound arm contributes 8 of 96 +route hits and none of the 8 that change an answer. The gate's non-vacuity +number is 100% single-reference, and nothing in the tree said so. + +The other 26 pinned 4:4:4 fixtures reach the arm **zero** times +(`444_intrabc_rect4_witness`, `444_leaf8_oob`, `444_lossy_rect4_*`, +`444_lossy_superres_*`, `444_sb128rect_lr_witness`, and every `ll444_*`), so +that one witness is the only thing pinning the single-reference copy at all. + +## 3. Change (additive: +149/-0, no decode-semantics edit) + +- `decode.rs`: `CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS` + + `CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS` and their accessors, bumped only + in the single-reference arm. +- `stream.rs`: `the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms` + — asserts the single-ref arm holds the majority of the shared total, that + its own DIFFERS count clears the non-vacuity bar, and that the 4:2:0 control + fires neither new counter. + +The compound arm is untouched; the two arms stay textually comparable, which is +the point of a twin: + +```rust +// COMPOUND arm, decode.rs:40876-40885 // SINGLE-REF arm, decode.rs:42679-42693 +let cu_rel_mi = (cr * (cu_tx / MI), cc * (cu_tx / MI)); let cu_rel_mi = (cr * (cu_tx / MI), cc * (cu_tx / MI)); +let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, + cu_rel_mi) cu_rel_mi) + .unwrap_or(luma_tx_type); .unwrap_or(luma_tx_type); +if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi) if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi) + .is_some() { .is_some() { + hit!(CHROMA_QUAD_LEAF_TX_HITS); hit!(CHROMA_QUAD_LEAF_TX_HITS); + if cu_tx_type != luma_tx_type { hit!(CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS); + hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS); if cu_tx_type != luma_tx_type { + } hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS); +} hit!(CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS); + } + } +``` + +## 4. Mutation / red-before: three independent reds, all on the single-ref arm + +The two hunks `c7fd5afa` proposed were each re-applied as a mutation to prove +the single-reference arm is load-bearing on its own, and the new gate was +proven non-vacuous a third way. + +**Red 1 — covering lookup reverted to the block-level type** (hunk 2 of the +proposed fix, `Some(cu_tx_type)` -> `Some(luma_tx_type)`, single-ref arm only): + +``` +a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type: + decode-order frame 1 of 4 (4 shown, 0 hidden) differs from the oracle at byte + 36635 (ours 127 vs 126), 777 bytes differ +test result: FAILED. 0 passed; 1 failed +``` + +**Red 2 — leaf push gated back behind `if side > 64`** (hunk 1, the pre-`6c33f204` +state, single-ref arm only): + +``` +a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type: + decode-order frame 1 of 4 (4 shown, 0 hidden) differs from the oracle at byte + 36635 (ours 127 vs 126), 777 bytes differ +test result: FAILED. 0 passed; 1 failed +``` + +777 bytes, the same number `6c33f204` reports for its own pre-fix state — +confirming the single-reference arm was the arm that needed the fix all along, +and that the pre-`6c33f204` defect really was 777/640/554 wrong V samples. + +**Red 3 — the new gate's own non-vacuity.** The single-reference arm's covering +route disabled, leaving the compound arm intact: + +``` +the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms: + the single-reference arm resolved 0 of 8 covering-leaf chroma units -- the shared + counter is no longer dominated by the arm this gate witnesses, so a revert of the + single-reference copy would leave the shared total comfortably non-zero +test result: FAILED. 0 passed; 1 failed +``` + +Note the shape of Red 3: the shared total is still **8** (all compound). A +gate reading only the shared counters sees a healthy non-zero number while the +arm it exists to witness is dead. That is the gap, demonstrated. + +**Green after restore** (both mutations reverted): + +``` +a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type: + quad-resolved chroma units 96, of which 8 differed ... ok +the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms: + 88 of 96 covering-leaf units are the single-reference arm's, 8 of which changed an answer ... ok +``` + +## 5. Neighbouring gates re-run (all green, all with the oracle required) + +`EC_AV1_REQUIRE_AOMENC=1` against the instrumented +`~/.cache/aom-oracle/build/{aomenc,aomdec}`, so no arm silently skipped: + +| Set | Filter | Result | +| --- | --- | --- | +| 444 four-unit arm (existing) | `quadrants_tx_type` | 1 passed, 0 failed — 96 units, 8 differed | +| 444 four-unit arm (NEW) | `single_reference_arms` | 1 passed, 0 failed — 88 of 96, 8 changed an answer | +| 4:4:4 family | `444` | **39 passed**, 0 failed (18.66s) | +| intrabc_rect family | `intrabc_rect` | **7 passed**, 0 failed | +| rect-strip sibling | `rect_strip` | **10 passed**, 0 failed (15.94s) | +| `covering_leaf_tx_type` unit test | `leaf_tx_type` | 1 passed, 0 failed | +| 4:2:0 control | `inter_block` | 3 passed, 0 failed | +| 4:2:0 chroma tx | `chroma_tx` | 2 passed, 0 failed | +| 4:2:0 streams | `420` | 2 passed, 0 failed | + +`cargo check -p ec-av1 --all-targets`: clean, **0 warnings** (private +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1f9singleland`). + +The 4:2:0 sets are unchanged because the covering consumer is gated on +`ss_x == 0 && ss_y == 0`; at 4:2:0 the arm is unreachable and the new +counters are asserted at exactly `(0, 0)` there by the new gate's own control. + +## 6. Merge verification onto the advanced main tip + +Main advanced 35 commits past this lane's base (`3aa16dd1` -> `57834ee2`) +while the lane ran, so the merge was proved rather than assumed: + +``` +$ git merge-tree --write-tree main 0b5b46d8 +45857ebeda17d40d140238accb80344f40331ade # exit 0, no conflict +``` + +Built as a real two-parent commit and re-ran against it: + +``` +cargo check -p ec-av1 --all-targets -> Finished, 0 warnings +single_reference_arms -> 88 of 96 covering-leaf units, 8 changed an answer ok +quadrants_tx_type -> quad-resolved chroma units 96, of which 8 differed ok +``` + +Same numbers as on the lane base, so nothing in those 35 commits moved the +witness. + +## 7. Not done / out of scope + +- The compound arm is still only 8-of-96 witnessed. A witness that exercises + the compound four-unit arm's DIFFERS condition would need a stream whose + *compound* blocks carry skipped luma leaves; the one pinned 444 witness does + not. Not attempted — out of this lane's scope (it is a compound-arm coverage + question, not a single-reference one), and flagged here rather than left + implied. +- No new fixture was encoded. The census named `a6tools444_26frame_444_inter.obu`; + no such fixture exists in this tree and no `aomenc` is on PATH, so its + 26-frame claim could not be re-measured. It is not needed: the census's own + measurement, and this lane's, agree the fix is already in. +- The full `--lib` suite was not run: the box is under three concurrent sibling + suites (`av1pinspec`, an `a_444_intrabc_owned_rect` lane, and a + `--test-threads=4` run). Per-lane scoping only; project-wide validation is + the integrator's call. +- `lanes/av1f9single.report.md` from the branch was NOT brought over. It + documents measurements of an arm state that never existed on main, and its + "counter left compound-only" claim is false against main (the counters are in + both arms). Keeping it would re-seed the same false-positive census entry.