forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1loss444kf'

Browse files at this commit

3bc9845c650ffe4270d12481353fbbacb53a7dddAhmet Kaan GümüşParent: 90e4e6ececc096
crates/ec-av1/src/decode.rsmodified+55 -8
@@ -6301,6 +6301,14 @@ thread_local! {
63016301 /// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose chroma a
63026302 /// lossless 4:4:4 frame walked as per-4x4 [`TxbSet::Chroma4`] units.
63036303 static INTRABC_RECT8_LOSSLESS_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
6304+ /// lane-av1loss444kf: 4:4:4 lossless sub-8x8 RECT (8x4 / 4x8) leaf chroma
6305+ /// units whose libaom-faithful block-relative reach
6306+ /// ([`Reach::of_tu`] over the leaf's own bsize) differs from the
6307+ /// standalone-BLOCK_4X4 lookup that used to answer for them. Zero means
6308+ /// no stream reached a rect leaf where the two disagree -- a gate
6309+ /// asserting the reach fix must see this nonzero, or the fixture never
6310+ /// exercised the fixed path.
6311+ static SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
63046312 }
63056313
63066314 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape
@@ -6343,6 +6351,19 @@ pub fn intrabc_rect8_lossless_chroma_hits() -> usize {
63436351 INTRABC_RECT8_LOSSLESS_CHROMA_HITS.with(|c| c.get())
63446352 }
63456353
6354+/// How many 4:4:4 lossless sub-8x8 RECT leaf chroma units took the
6355+/// block-relative reach libaom's `has_bottom_left` gives, where the
6356+/// standalone-BLOCK_4X4 lookup that used to answer disagreed
6357+/// (lane-av1loss444kf). Zero on a stream with no such leaf.
6358+pub fn sub8_chroma444_lossless_tu_reach_hits() -> usize {
6359+ SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS.with(|c| c.get())
6360+}
6361+
6362+/// Gate-side reset for [`SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS`].
6363+pub fn reset_sub8_chroma444_tu_reach_hits() {
6364+ SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS.with(|c| c.set(0));
6365+}
6366+
63466367 /// Gate-side reset for the two lane-av1-ibc444rect counters above.
63476368 pub fn reset_ibc444rect_hits() {
63486369 INTRABC_RECT8_LOSSLESS_LUMA_HITS.with(|c| c.set(0));
@@ -9903,9 +9924,7 @@ impl Neighbours {
99039924 fill_span(&mut self.uv_owner, row * stride + mi_c, n, owner);
99049925 }
99059926 if crate::envflags::env_flag!("EC_LEFTSSY") {
9906- eprintln!(
9907- "EC_LEAF mi=({mi_r},{mi_c}) wh=({mi_w},{mi_h}) uv_mode={uv_mode}"
9908- );
9927+ eprintln!("EC_LEAF mi=({mi_r},{mi_c}) wh=({mi_w},{mi_h}) uv_mode={uv_mode}");
99099928 }
99109929 }
99119930
@@ -24256,7 +24275,28 @@ fn sub8_leaf_chroma444(
2425624275 );
2425724276 set_palette_pred(pb, fctx);
2425824277 let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4);
24259- let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx);
24278+ // lane-av1loss444kf: libaom asks
24279+ // `has_top_right`/`has_bottom_left` with the
24280+ // LEAF's bsize, this unit's `(col_off, row_off)`
24281+ // and `tx_size` -- not as a standalone BLOCK_4X4
24282+ // at the unit's own position. A 4x8 leaf's FIRST
24283+ // unit has its bottom-left pixels inside the
24284+ // block's own second row (already reconstructed),
24285+ // which `has_bottom_left`'s
24286+ // `row_off + count < plane_bh_unit` early-out
24287+ // answers TRUE; the 4x4 table answered false, so
24288+ // `PlaneBuf::edges` replicated the last left
24289+ // sample and the unit predicted from a fabricated
24290+ // edge (the 4:4:4 lossless key frame's 49-sample
24291+ // chroma damage at (196,200)-(204,200)). The
24292+ // 4:2:2 twin of this arm was fixed the same way
24293+ // (lane-av1-422kf2); this is its 4:4:4 twin.
24294+ let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach);
24295+ if !square
24296+ && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx)
24297+ {
24298+ hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS);
24299+ }
2426024300 let grid = read_plane(
2426124301 dec,
2426224302 cdfs,
@@ -24437,7 +24477,15 @@ fn sub8_leaf_chroma444(
2443724477 let (umi_r, umi_c) = (lmi.0 + ur, lmi.1 + uc);
2443824478 let (upx, upy) = (px + uc * 4, py + ur * 4);
2443924479 let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4);
24440- let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx);
24480+ // lane-av1loss444kf: the block-relative answer, not
24481+ // a standalone BLOCK_4X4 lookup at the unit's own
24482+ // position -- see the intrabc twin above for the
24483+ // libaom citation and the measured damage.
24484+ let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach);
24485+ if !square && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx)
24486+ {
24487+ hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS);
24488+ }
2444124489 let grid = read_plane(
2444224490 dec,
2444324491 cdfs,
@@ -28637,9 +28685,8 @@ fn read_block_tx_size_rect(
2863728685 let full_h_mi = bh / MI;
2863828686 if max_w_mi != full_w_mi || max_h_mi != full_h_mi {
2863928687 LOSSLESS_EDGE_CLIPPED.with(|c| c.set(c.get() + 1));
28640- LOSSLESS_EDGE_CLIP_UNITS.with(|c| {
28641- c.set(c.get() + (full_w_mi * full_h_mi - max_w_mi * max_h_mi))
28642- });
28688+ LOSSLESS_EDGE_CLIP_UNITS
28689+ .with(|c| c.set(c.get() + (full_w_mi * full_h_mi - max_w_mi * max_h_mi)));
2864328690 }
2864428691 let mut leaves = Vec::with_capacity(max_w_mi * max_h_mi);
2864528692 for row in 0..max_h_mi {
crates/ec-av1/src/stream.rsmodified+153 -0
@@ -46423,6 +46423,159 @@ pub(crate) mod tests {
4642346423 }
4642446424 }
4642546425
46426+ /// Decode-order frame 0 only, against the oracle's own
46427+ /// `EC_AV1_FINAL_DUMP` for that frame: how many SAMPLES differ, and the
46428+ /// first one as `(plane, x, y, ours, oracle)`.
46429+ ///
46430+ /// lane-av1loss444kf: the 4:4:4 lossless 256x256 cell's inter frames carry a
46431+ /// SEPARATE, already-diagnosed walk defect (the per-mu-chunk lossless
46432+ /// chroma span, `lanes/av1loss444mm.report.md` r1), so a whole-stream
46433+ /// byte-exactness assert cannot name this one. `aomdec --limit=1` stops
46434+ /// after the key frame, which is exactly the frame the reach fix moves.
46435+ #[allow(clippy::type_complexity)]
46436+ fn key_frame_diffs(
46437+ stream: &[u8],
46438+ name: &str,
46439+ ) -> (usize, Option<(usize, usize, usize, u8, u8)>) {
46440+ let dir = std::env::temp_dir().join(format!("ec-av1-{name}-kf-{}", std::process::id()));
46441+ let _ = std::fs::remove_dir_all(&dir);
46442+ std::fs::create_dir_all(&dir).expect("scratch dir");
46443+ let obu = dir.join("in.obu");
46444+ std::fs::write(&obu, stream).expect("writing the stream");
46445+ let aom_prefix = dir.join("aomkf");
46446+ let out = Command::new(aomdec_path())
46447+ .args(["--codec=av1", "--limit=1", "-o"])
46448+ .arg(dir.join("out.y4m"))
46449+ .arg(&obu)
46450+ .env("EC_AV1_FINAL_DUMP", &aom_prefix)
46451+ .stdin(Stdio::null())
46452+ .stdout(Stdio::piped())
46453+ .stderr(Stdio::piped())
46454+ .output()
46455+ .expect("aomdec failed to run");
46456+ assert!(
46457+ out.status.success(),
46458+ "{name}: the oracle aomdec refused the stream: {}",
46459+ String::from_utf8_lossy(&out.stderr)
46460+ );
46461+ let ours_prefix = dir.join("ourskf");
46462+ set_final_dump_prefix(Some(ours_prefix.display().to_string()));
46463+ let decoded = decode_stream(stream);
46464+ set_final_dump_prefix(None);
46465+ decoded.unwrap_or_else(|e| panic!("{name}: this decoder refused the stream: {e}"));
46466+ let want = std::fs::read(format!("{}.f0", aom_prefix.display())).expect(
46467+ "the oracle wrote no decode-order frame 0 -- rung 12 of \
46468+ scripts/instrument-aom-oracle.sh is missing",
46469+ );
46470+ let got = std::fs::read(format!("{}.f0", ours_prefix.display()))
46471+ .expect("this decoder wrote no decode-order frame 0");
46472+ assert_eq!(
46473+ got.len(),
46474+ want.len(),
46475+ "{name}: our key frame is {} bytes, the oracle's is {}",
46476+ got.len(),
46477+ want.len()
46478+ );
46479+ let side = (want.len() / 3).isqrt();
46480+ let differing = got.iter().zip(&want).filter(|(a, b)| a != b).count();
46481+ let first = got.iter().zip(&want).position(|(a, b)| a != b).map(|at| {
46482+ // the dump is plane after plane (Y, U, V), so the in-plane
46483+ // offset is what carries the x/y split
46484+ let plane = at / (side * side);
46485+ let in_plane = at % (side * side);
46486+ (plane, in_plane % side, in_plane / side, got[at], want[at])
46487+ });
46488+ let _ = std::fs::remove_dir_all(&dir);
46489+ (differing, first)
46490+ }
46491+
46492+ /// lane-av1loss444kf: the 4:4:4 lossless 256x256 key frame's 49-sample
46493+ /// chroma damage, and the `Reach` a transform unit inside a sub-8x8 RECT
46494+ /// leaf must be given.
46495+ ///
46496+ /// The cell: `testsrc2 256x256 rate=25` yuv444p, 6 frames,
46497+ /// `aomenc --lossless=1 --enable-palette=0 --enable-intrabc=0` -- **109215
46498+ /// bytes, sha256 `4563a01f1778600020ffa9f15bc05f5559321cf5712b99a29ed7192675dee6a4`,
46499+ /// fnv1a64 `0xbbb56442f393a9b2`**. Its key frame decodes with **21 U + 28 V
46500+ /// samples wrong** (U over x 196..207 / y 200..203, V over x 196..206),
46501+ /// luma exact, entropy bit-locked over all 81933 of its symbol reads and
46502+ /// its 12288 transform units at identical absolute `(plane, x, y)`.
46503+ ///
46504+ /// The defect: libaom's `has_bottom_left` (`reconintra.c:381`) is asked
46505+ /// with the **leaf's** `bsize`, the unit's `(row_off, col_off)` and
46506+ /// `tx_size` -- and its first branch inside the left column is
46507+ /// `if (row_off + bottom_left_count_unit < plane_bh_unit) return 1;`, the
46508+ /// block's OWN next row, already reconstructed. A 4x8 leaf's first TX_4X4
46509+ /// unit therefore HAS four bottom-left samples. `sub8_leaf_chroma444`
46510+ /// instead looked a standalone `BLOCK_4X4` up at the unit's own position
46511+ /// (`Reach::of(4, upx, upy, ..)`), which answers false there, so
46512+ /// [`PlaneBuf::edges`] replicated the last left sample out to the edge's
46513+ /// full `bw + bh` reach and the unit predicted D203/CFL from a fabricated
46514+ /// edge. The 4:2:2 twin of the same function was fixed this way already
46515+ /// (lane-av1-422kf2, whose comment names the old lookup); this is its
46516+ /// 4:4:4 twin, still carrying the stale copy.
46517+ ///
46518+ /// Non-vacuity, in order:
46519+ /// 1. the live re-encode's length AND fnv1a64 -- a recipe or encoder drift
46520+ /// fails here instead of passing as this cell;
46521+ /// 2. [`assert_444_header`] -- at 4:2:0 the arm is unreachable (every
46522+ /// caller of `sub8_leaf_chroma444` sits behind `chroma_444`) and every
46523+ /// assert below would pass for free;
46524+ /// 3. [`key_frame_diffs`] == 0 samples, with the first differing sample
46525+ /// NAMED in the failure so a regression is a location, not a count;
46526+ /// 4. [`crate::decode::sub8_chroma444_lossless_tu_reach_hits`] rose over
46527+ /// the decode -- the units where the block-relative answer and the
46528+ /// standalone one disagree, which is what makes this a witness of the
46529+ /// FIXED path and not of a stream that merely has rect leaves.
46530+ #[test]
46531+ fn a_lossless_444_sub8_rect_leaf_chroma_reach_decodes_the_key_frame_pixel_exact() {
46532+ const NAME: &str = "lossless-444-sub8-rect-leaf-chroma-reach";
46533+ let _gate_lock = lock_gate_counters();
46534+ if !have_ffmpeg() || !have_aomenc() {
46535+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
46536+ return;
46537+ }
46538+ let stream = chroma_format_stream(
46539+ 256,
46540+ 256,
46541+ "yuv444p",
46542+ 8,
46543+ 6,
46544+ &["--lossless=1", "--enable-palette=0", "--enable-intrabc=0"],
46545+ 0,
46546+ );
46547+ assert_eq!(
46548+ (stream.len(), fnv1a64(&stream)),
46549+ (109215, 0xbbb5_6442_f393_a9b2),
46550+ "{NAME}: the pinned 4:4:4 lossless 256x256 cell is {} bytes / fnv1a64 {:#x}, \
46551+ not 109215 / 0xbbb56442f393a9b2 -- the recipe or the encoder drifted, so a \
46552+ result here is not a result about this cell",
46553+ stream.len(),
46554+ fnv1a64(&stream)
46555+ );
46556+ assert_444_header(&stream, NAME, 8);
46557+ crate::decode::reset_sub8_chroma444_tu_reach_hits();
46558+ let (differing, first) = key_frame_diffs(&stream, NAME);
46559+ assert_eq!(
46560+ differing, 0,
46561+ "{NAME}: the 4:4:4 lossless key frame differs from aomdec in {differing} samples \
46562+ (first {first:?} as (plane, x, y, ours, oracle)) -- a sub-8x8 RECT leaf's chroma \
46563+ unit must be given the reach libaom's has_bottom_left computes for the LEAF, not a \
46564+ standalone BLOCK_4X4 lookup at the unit's own position"
46565+ );
46566+ let reach_hits = crate::decode::sub8_chroma444_lossless_tu_reach_hits();
46567+ assert!(
46568+ reach_hits > 0,
46569+ "{NAME}: went blind -- not one 4:4:4 lossless rect-leaf chroma unit had the \
46570+ block-relative reach disagree with the standalone BLOCK_4X4 lookup, so the cell \
46571+ never reached the fixed path and the byte-exactness above proves nothing about it"
46572+ );
46573+ eprintln!(
46574+ "{NAME}: key frame byte-exact vs aomdec (0 of 196608 samples differ), {reach_hits} \
46575+ rect-leaf chroma unit(s) took the block-relative reach"
46576+ );
46577+ }
46578+
4642646579 /// lane-av1distwtd: the gate that pays the `enable-dist-wtd-comp` entry in
4642746580 /// `gate_coverage.rs`'s [`NEVER_EXERCISED_8BIT`], and corrects its stated
4642846581 /// reason. The entry said "distance-weighted compound is unimplemented" --
lanes/av1loss444kf.report.mdadded+346 -0
@@ -0,0 +1,346 @@
1+# lane-av1loss444kf — the 4:4:4-lossless key frame's 49 chroma samples: found, fixed, witnessed
2+
3+**Tree.** branch `lane-av1loss444kf` off `c6112723`, worktree
4+`~/.cache/wt/av1loss444kf`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss444kf`
5+(lane-private), `TMPDIR=$HOME/.cache/tmp`. Nothing pushed. Files touched:
6+`crates/ec-av1/src/decode.rs` (the fix + the counter + its accessor),
7+`crates/ec-av1/src/stream.rs` (one comparison helper + one gate). No temporary
8+instrumentation survived — see §7.
9+
10+## 0. Verdict in one table
11+
12+| question | measured answer |
13+|---|---|
14+| does the carrier reproduce? | **yes**, byte-for-byte: 109215 B, sha256 `4563a01f17786000…` |
15+| does the 49-sample fingerprint reproduce? | **yes**, exactly: 21 U + 28 V, same extents, same per-cell counts 6/16 · 9/16 · 6/16, first sample U(201,200) 160 vs 159 |
16+| which stages are inert? | the oracle's pre-deblock, post-deblock, post-CDEF and final key-frame dumps are **byte-identical to each other**; ours too. The whole filter chain is inert on BOTH sides |
17+| prediction or residual? | **prediction**, and arithmetically so: the pixel delta IS the prediction delta (identical coefficients ⇒ identical residual), and it is fully reproduced by libaom's z3 with a different left edge |
18+| fixed? | **yes** — 49 → **0**, on the 109215 B carrier *and* on the 109909 B one |
19+| witness | `a_lossless_444_sub8_rect_leaf_chroma_reach_decodes_the_key_frame_pixel_exact`, red-before at the exact 49/first-sample fingerprint, non-vacuous on a counter that reads **86** on this cell |
20+| 4:2:0 / 4:2:2 identity | structural: every caller of the changed function sits behind `chroma_444` (ss 0/0). `-- lossless 444` 48/0, `-- 420` 2/0, `-- intrabc` 21/0, `-- 422` 6/0 |
21+
22+## 1. The carrier, pinned and reproduced
23+
24+`testsrc2 256x256:rate=25` → `yuv444p`, 6 frames, piped to the durable oracle as
25+y4m, encoded with
26+
27+```
28+aomenc --lossless=1 --enable-palette=0 --enable-intrabc=0 \
29+ --codec=av1 --passes=1 --end-usage=q --threads=1 --row-mt=0 \
30+ --lag-in-frames=0 --kf-max-dist=100 --limit=6 --obu -o - -
31+```
32+
33+* **109215 bytes, sha256 `4563a01f1778600020ffa9f15bc05f5559321cf5712b99a29ed7192675dee6a4`,
34+ fnv1a64 `0xbbb56442f393a9b2`** — the cell `lanes/av1tilemeasure` published. The
35+ gate re-encodes it live and asserts BOTH the length and the fnv1a64, so a
36+ recipe or encoder drift fails as drift instead of passing as this cell.
37+* The key frame alone, split to `SEQ + TD + FRAME` in the original OBU order
38+ (`split.py`, 18140 B, sha256 `f390434237f1a94f…`), is what every measurement
39+ below runs on: `aomdec --limit=1` and this decoder each see one frame, so no
40+ inter-frame walk defect can be mistaken for this one.
41+* The second, independent encode of the same cell — `+ --sb-size=128` with
42+ intrabc on, **109909 B, sha256 `d4427a7372e443e1…`** (key frame 18131 B) — is
43+ the second arm in §5.
44+
45+**Fingerprint, measured on the key frame (ours vs `aomdec`'s `EC_AV1_FINAL_DUMP`):**
46+
47+| | before | after |
48+|---|---|---|
49+| key frame samples differing from the oracle | **49** | **0** |
50+| per plane | U 21, V 28, **luma 0** | 0 / 0 / 0 |
51+| extent | U x 196..207 y 200..203, V x 196..206 y 200..203 | — |
52+| per 4x4 cell (U) | 6/16, 9/16, 6/16 | — |
53+| first sample | plane 1, x 201, y 200: ours 160, oracle 159 | — |
54+| deltas (ours − oracle) | U **−3 … +1**, V **−6 … +1** | — |
55+
56+**One correction to the handed-down fingerprint, measured.** The report I was
57+given says the deltas run `+1 … +63` (U) and `−54 … +47` (V), 17 and 23 distinct
58+values. On the pinned 109215 B carrier the deltas are **−3 … +1** (U, 4 distinct)
59+and **−6 … +1** (V, 6 distinct). The COUNT, the planes, the extents, the per-cell
60+partiality and the first sample all reproduce exactly; only the magnitude claim
61+does not, and it was read off a stream that is not this one. The "not a rounding
62+constant" conclusion survives (it is not a constant), but nothing in this
63+defect needs ±63.
64+
65+## 2. Stage ladder: the whole filter chain is inert, on BOTH sides
66+
67+One `aomdec` run of the key-frame stream with four dump rungs at once
68+(`EC_AV1_PREFILT_DUMP`, `EC_AV1_POSTDEBLOCK_DUMP`, `EC_AV1_POSTCDEF_DUMP`,
69+`EC_AV1_FINAL_DUMP`), and this decoder with its own `EC_AV1_PREFILT_DUMP`:
70+
71+```
72+oracle pre == deblock == cdef == final (all four files byte-identical, 196608 B)
73+ours pre == final (byte-identical)
74+ours pre vs oracle pre 49 samples — the SAME 49
75+```
76+
77+So deblocking, CDEF and loop restoration changed nothing on either side of this
78+frame, and the divergence is already present in the **reconstruction**. The
79+filter chain is exonerated as the ORIGIN, not merely as a contributor, and that
80+is measured here rather than inherited from the other lanes' stage claims.
81+
82+## 3. Prediction vs residual: decided by arithmetic, then by transcription
83+
84+**The cheap discriminator.** On a lossless frame `recon = prediction + residual`
85+exactly, and the coefficients are the same on both sides (entropy is bit-locked,
86+the transform-unit walk is position-identical), so the residual is the same on
87+both sides. Therefore
88+
89+> the 49-sample pixel delta **is** the 49-sample prediction delta.
90+
91+That alone moves the search space from "prediction, dequant/WHT, placement" to
92+"prediction" — but it is only valid if the coefficients really are identical, so
93+it was checked rather than assumed: with the prediction delta fully explained
94+(§3b) the coefficients cannot differ anywhere, because a coefficient difference
95+would show up as a pixel delta that the prediction cannot produce.
96+
97+**The paired prediction rungs.** `EC_PRED=1` on both decoders over the key frame:
98+
99+* the oracle prints 3130 `EC_PRED` lines (directional + filter-intra only; a
100+ non-directional block prints just `EC_PREDOUT8`) and **12288** `EC_PREDOUT8`
101+ lines; this decoder prints **12288** `OUR_PRED` lines. Same count, same
102+ decode order.
103+* Index-pairing is a trap here: at the first order disagreement our (200,196)
104+ is read against the oracle's (196,200) and every value looks wrong. Pairing
105+ by `(x, y, plane)` instead — both traces carry the coordinates, the oracle's
106+ from `mb_to_top_edge` — gives **exactly 4 sum mismatches out of 3130
107+ directional predictions**, all four inside the two 4x8 rect leaves at
108+ (196,200) and (200,200), chroma planes, mode 7 (D203, p_angle 203). Every
109+ other directional prediction in the frame, luma and chroma, is identical.
110+* The third damaged block (204,200) is a `UV_CFL_PRED` leaf, whose base
111+ prediction is DC and therefore prints no `EC_PRED` line at all. It is damaged
112+ for a different reason — see §3c.
113+
114+**3b. The 16 samples, from a transcription of libaom's own code.** With the
115+prediction deltas known, `pred_oracle = pred_ours − (recon_ours − recon_oracle)`
116+gives the oracle's full 4x4 prediction for each damaged unit. A from-scratch
117+transcription of `av1_dr_prediction_z3_c` + `av1_filter_intra_edge_c` +
118+`av1_upsample_intra_edge_c` + `intra_edge_filter_strength` +
119+`av1_use_intra_edge_upsample` (`reconintra.c:573-638, 989-1082`), fed the edge
120+pixels read out of the ORACLE's own reconstruction, then run over the two
121+candidate left columns:
122+
123+| unit | n_bl = 0 (replicated edge) | n_bl = 4 (real bottom-left) |
124+|---|---|---|
125+| (196,200) U | **= our prediction, all 16** | = the oracle's prediction, all 16 |
126+| (196,200) V | = our prediction, all 16 | = the oracle's prediction, all 16 |
127+| (200,200) U | neither | **= the oracle's prediction, all 16** |
128+| (200,200) V | neither | **= the oracle's prediction, all 16** |
129+
130+16/16 samples on all four units, with the intra edge filter type at both values
131+(ft=0 and ft=1 make no difference at p_angle 203, 4x4: strength 0 either way and
132+upsample 1 either way — so the filter type is NOT the variable here, and the
133+`ft` column in the oracle's trace is a red herring for this cell). **The
134+difference is exactly `n_bottomleft_px`, and nothing else.** The dequant scale,
135+the 4x4 WHT and the unit placement are exonerated by construction: they produce
136+the residual, and the residual is not what differs.
137+
138+**3c. Why two different predictors looked guilty.** Blocks #735 (D203) and #736
139+(CFL) do not fail independently. On a lossless frame a wrong prediction is
140+written to the frame and the NEXT block reads it as its left edge, so the
141+damage cascades one block to the right: our wrong pixels at (199, 201) and
142+(199, 202) are the left column of the block at (200,200) (measured: oracle
143+`[158,164,169,166,…]`, ours `[158,165,167,166,…]`), and the pixels at
144+(203, 201/202) are the left column of the CFL block. **One wrong block explains
145+all three** — the D203+CFL mix was a consequence, not a second cause. This is
146+what killed the "two predictors, one cause" reading the defect invited.
147+
148+## 4. The deciding site, and the fix
149+
150+`crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma444` — the 4:4:4 lossless chroma
151+walk of a sub-8x8 leaf. Each TX_4X4 chroma unit asked for its reach with
152+
153+```rust
154+let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx);
155+```
156+
157+which is a **standalone `BLOCK_4X4` lookup at the unit's own position**. libaom
158+(`reconintra.c:1852`) asks `has_bottom_left(sb_size, bsize, mi_row, mi_col, …,
159+txsz, row_off, col_off, ss_x, ss_y)` — with the **leaf's** `bsize`, the unit's
160+`(row_off, col_off)` and `tx_size` — and that function's first branch inside the
161+left column is
162+
163+```c
164+const int bh_unit = mi_size_high[bsize];
165+const int plane_bh_unit = AOMMAX(bh_unit >> ss_y, 1);
166+const int bottom_left_count_unit = tx_size_high_unit[txsz];
167+if (row_off + bottom_left_count_unit < plane_bh_unit) return 1; // the block's OWN next row
168+```
169+
170+For a 4x8 leaf's FIRST unit (`row_off = 0`, `tx = TX_4X4`) that is `0 + 1 < 2` →
171+**true**: the four bottom-left samples are the block's own second-row left
172+neighbours, already reconstructed. The oracle's own `EC_PRED` rung prints
173+`n_bl=4` there and `n_bl=0` for the leaf's second unit, exactly as that ladder
174+predicts. Our 4x4 table said false, so `PlaneBuf::edges` handed the predictor a
175+left column replicated out to the edge's full `bw + bh` reach, and the unit
176+predicted from a fabricated edge.
177+
178+`Reach::of_tu` is the crate's existing transcription of that pair of functions
179+(`has_tr_*`/`has_bl_*` for a unit at `(col_off, row_off)` inside a `bw x bh`
180+block whose own answer is `block`), and it is what the function's OWN block-level
181+`reach` is built for — the value was computed at the top of `sub8_leaf_chroma444`
182+and then not used by the per-unit walk. The 4:2:2 twin of this function was
183+fixed exactly this way already (lane-av1-422kf2, whose comment at `decode.rs`
184+names "the standalone square-4x4 table the old `Reach::of(4, ..)` lookup used");
185+this was its 4:4:4 twin, still carrying the stale copy.
186+
187+```rust
188+let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach);
189+if !square && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx) {
190+ hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS);
191+}
192+```
193+
194+applied at **both** lossless 4:4:4 arms (the intra one and the intrabc one), plus
195+the counter declaration and its two accessors.
196+
197+**The class, swept repo-wide.** Every `Reach::of(4, …)` in `decode.rs` is now
198+accounted for, and this was the last stale copy:
199+
200+| site | verdict |
201+|---|---|
202+| `sub8_leaf_chroma444` block-level reach (~23942) | correct — the leaf's own answer, the value the fix now threads down |
203+| `sub8_leaf_chroma444` per-unit, intra arm | **fixed** |
204+| `sub8_leaf_chroma444` per-unit, intrabc arm | **fixed** (same lines, the same defect) |
205+| `sub8_leaf_chroma422` block-level reach | already correct (lane-av1-422kf2) |
206+| `decode_leaf_split4` (~25016) | correct — a standalone `BLOCK_4X4` leaf really is a 4x4 block |
207+| `read_intra_chroma_lossless`'s `tu_reach(side, side, …)` | correct — all four of its callers pass a SQUARE plane block, so the unit dims are the block dims |
208+
209+`Reach::of_tu` itself is **unchanged**; the fix only starts calling it. Nothing in
210+`encode.rs`, `intra.rs` or `transform.rs` is touched.
211+
212+## 5. The witness, and the red-before
213+
214+`stream::tests::a_lossless_444_sub8_rect_leaf_chroma_reach_decodes_the_key_frame_pixel_exact`
215+with a new non-panicking helper `key_frame_diffs` (`aomdec --limit=1` +
216+`EC_AV1_FINAL_DUMP` on frame 0 only, versus this decoder's own decode-order
217+frame 0), because a whole-stream byte-exactness assert cannot name this defect:
218+the carrier's inter frames still carry the SEPARATE mu-chunk chroma-walk defect
219+(§6).
220+
221+Non-vacuity, in order, every step load-bearing:
222+
223+1. the live re-encode is 109215 bytes and fnv1a64 `0xbbb56442f393a9b2` — a
224+ drifted recipe/encoder fails HERE, not silently;
225+2. `assert_444_header` — at 4:2:0 the changed function is unreachable and every
226+ assert below would pass for free;
227+3. the key frame is byte-exact, 0 of 196608 samples, and the failure message
228+ NAMES the first differing sample as `(plane, x, y, ours, oracle)`;
229+4. `sub8_chroma444_lossless_tu_reach_hits()` rose over the decode — measured
230+ **86** units on this cell, i.e. 86 units where the block-relative answer and
231+ the standalone lookup disagree. This is what makes the gate a witness of the
232+ FIXED path rather than of a stream that merely contains rect leaves.
233+
234+**Red-before, with only the two reach expressions reverted** (counter, accessor
235+and gate untouched):
236+
237+```
238+assertion `left == right` failed: the 4:4:4 lossless key frame differs from
239+aomdec in 49 samples (first Some((1, 201, 200, 160, 159)) as
240+(plane, x, y, ours, oracle))
241+ left: 49
242+ right: 0
243+test result: FAILED. 0 passed; 1 failed
244+```
245+
246+Restored → green:
247+
248+```
249+lossless-444-sub8-rect-leaf-chroma-reach: key frame byte-exact vs aomdec
250+(0 of 196608 samples differ), 86 rect-leaf chroma unit(s) took the
251+block-relative reach
252+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 748 filtered out
253+```
254+
255+**Second, independent encode.** The 109909 B stream (`--sb-size=128`, intrabc
256+ON, a different key frame with 82697 symbol reads) decodes its key frame
257+**byte-exactly** with the fix and with 49-ish samples wrong without it. Same
258+defect, same class, two byte streams.
259+
260+**The 49-sample tripwire.** No bound anywhere was re-pinned: the tripwire is the
261+gate's own `differing == 0`, and it came DOWN to 0 as a consequence of the fix.
262+Nothing was weakened to make a gate pass.
263+
264+## 6. Identity at other shapes
265+
266+| set | result |
267+|---|---|
268+| `cargo test -p ec-av1 --lib -- lossless 444` | **48 passed, 0 failed** (17.4 s) |
269+| `cargo test -p ec-av1 --lib -- 420` | **2 passed, 0 failed** |
270+| `cargo test -p ec-av1 --lib -- intrabc` | **21 passed, 0 failed, 1 ignored** |
271+| `cargo test -p ec-av1 --lib -- 422` | **6 passed, 0 failed** (all refusal-inventory: 4:2:2 is refused by name) |
272+
273+Arithmetically first, then measured:
274+
275+* **4:2:0 and 4:2:2 are structurally unreachable.** All five call sites of
276+ `sub8_leaf_chroma444` sit behind `if chroma_444`, which is
277+ `ss_x(fctx) == 0 && ss_y(fctx) == 0`. The changed lines cannot execute at
278+ either subsampling, so the 4:2:0 and 4:2:2 decodes are unchanged by
279+ construction, not by measurement alone.
280+* **A 4x4 (square) leaf is unchanged even at 4:4:4.** `of_tu(4, 4, 0, 0, 4, 4, r)`
281+ has `col_off == 0` (so not the `col_off > 0 → false` branch) and
282+ `row_off + tx_h < bh` is `0 + 4 < 4` — false — so BOTH flags fall through to
283+ `r`, the leaf's own reach, which for a square leaf is
284+ `Reach::of(4, px, py, ..)`: the old value exactly. The counter's `!square`
285+ guard is that same fact, so a square leaf cannot even bump it.
286+* The rect leaves the fix does move are the `(8, 4)` / `(4, 8)` shapes the three
287+ non-square call sites pass; a `4x4` leaf is the only square one.
288+
289+## 7. What is still open, precisely
290+
291+* **The carrier's inter frames still diverge, and that is NOT this defect.**
292+ Frames 1..5 still differ, and they differ by almost exactly as much as they did
293+ BEFORE this fix (same 6-frame stream, same tree, only the two reach
294+ expressions flipped):
295+
296+ | decode-order frame | before | after |
297+ |---|---|---|
298+ | 0 (KEY) | 49 | **0** |
299+ | 1 | 70151 | 70149 |
300+ | 2 | 138579 | 138579 |
301+ | 3 | 114966 | 114962 |
302+ | 4 | 139220 | 139220 |
303+ | 5 | 139919 | 139918 |
304+
305+ That residual is the per-mu-chunk lossless chroma walk
306+ (`lanes/av1loss444mm.report.md` r1: the intra tail of `decode_inter_block`'s
307+ `side > 64` arm passed the chunk's chroma region as `(cu_tx, cu_tx)`,
308+ `cu_tx = 32`, instead of `64 >> ss`), fixed on that lane's UNMERGED branch.
309+ The 2- and 4-sample movements are the key frame's 49 chroma samples no longer
310+ poisoning the inter frames' prediction source — this fix's whole downstream
311+ contribution. Whoever merges that r1 gets the 6-frame stream.
312+* **The prior report's delta magnitudes are refuted** (§1). Its count, extents,
313+ per-cell partiality and first sample all reproduce; its `+1 … +63` /
314+ `−54 … +47` does not. Anyone matching on magnitude will not match this cell.
315+* **Not merge-ready in the conflict sense:** the fix edits `sub8_leaf_chroma444`
316+ and `decode_inter_block`'s neighbourhood is a different function, but a
317+ materialised merge has not been compiled.
318+* **Housekeeping observed, not touched:** the primary checkout carries an
319+ untracked `lanes/av1probes.report.md` that is not mine (it appeared during
320+ this lane). I did not add, move or delete anything there; the primary's
321+ tracked files are unmodified.
322+
323+## 8. Reproduce it
324+
325+```bash
326+D=$HOME/.cache/loss444kf; mkdir -p $D
327+ffmpeg -v error -f lavfi -i "testsrc2=size=256x256:rate=25" -frames:v 6 \
328+ -pix_fmt yuv444p -strict -1 -f yuv4mpegpipe -y $D/6.y4m
329+~/.cache/aom-oracle/build/aomenc --lossless=1 --enable-palette=0 --enable-intrabc=0 \
330+ --codec=av1 --passes=1 --end-usage=q --threads=1 --row-mt=0 \
331+ --lag-in-frames=0 --kf-max-dist=100 --limit=6 --obu -o - - \
332+ < $D/6.y4m > $D/vc.obu # 109215 B, sha256 4563a01f17786000…
333+python3 $D/split.py $D/vc.obu $D/kf.obu # SEQ+TD+FRAME, 18140 B
334+EC_AV1_FINAL_DUMP=$D/orc_final ~/.cache/aom-oracle/build/aomdec --codec=av1 \
335+ --limit=1 --noblit -o /dev/null $D/kf.obu
336+EC_PRED=1 EC_AV1_PREFILT_DUMP=$D/our_pre EC_AV1_POSTDEBLOCK_DUMP=$D/orc_deblock \
337+ EC_AV1_POSTCDEF_DUMP=$D/orc_cdef \
338+ cargo run -p ec-av1 --example dump_yuv -- $D/kf.obu $D/ours # or the gate:
339+EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss444kf \
340+ cargo test -p ec-av1 --lib a_lossless_444_sub8_rect_leaf_chroma_reach -- --nocapture
341+```
342+
343+Analysis scripts (read-only, outside the repo): `split.py` (the key-frame OBU
344+split), `an.py` (the per-plane fingerprint), `pair.py` (the EC_PRED /
345+OUR_PRED ladder paired by coordinates), `sim2.py` (the libaom z3 + edge filter +
346+upsample transcription that closes prediction-vs-residual).