From cecc096ea6836759e2cf82074c853930ef92cf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 29 Sep 2026 06:16:25 +0300 Subject: [PATCH] lane-av1loss444kf: a sub-8x8 RECT leaf's chroma unit gets the LEAF's reach The 4:4:4 lossless 256x256 key frame (109215 B, sha256 4563a01f17786000...) decoded with 21 U + 28 V samples wrong over x 196..207 / y 200..203, luma exact, entropy bit-locked over all 81933 symbol reads and its 12288 transform units at identical absolute (plane, x, y). The whole filter chain is inert on both sides of that frame (the oracle's pre-deblock, post-deblock, post-CDEF and final dumps are byte-identical to each other, and so are ours), and on a lossless frame the pixel delta IS the prediction delta -- so the residual, the dequant scale and the 4x4 WHT placement are exonerated by arithmetic, not by search. libaom asks has_bottom_left with the LEAF's bsize, the unit's (row_off, col_off) and tx_size, and answers TRUE inside the left column whenever `row_off + count < plane_bh_unit` -- the block's own next row, already reconstructed. A 4x8 leaf's first TX_4X4 unit therefore has four real bottom-left samples. sub8_leaf_chroma444 looked a standalone BLOCK_4X4 up at the unit's own position instead, got false, and PlaneBuf::edges replicated the last left sample across the edge's full reach: the unit predicted D203/CFL from a fabricated edge. A from-scratch transcription of libaom's z3 + edge filter + upsample reproduces all 16 oracle samples of each damaged unit with the real column and all 16 of ours with the replicated one, and the damage in the 2nd and 3rd blocks is that first wrong block's pixels read back as their left edge. Fix: Reach::of_tu over the leaf's own (bw, bh, col_off, row_off, tx) with the block reach the function already computes -- at both lossless 4:4:4 arms, the intra one and the intrabc one, which is what the 4:2:2 twin of this function was already fixed to do (lane-av1-422kf2). 49 -> 0 on the 109215 B carrier and on the independent 109909 B one. Witness: a_lossless_444_sub8_rect_leaf_chroma_reach_decodes_the_key_frame_pixel_exact -- live re-encode pinned by length and fnv1a64, 4:4:4 header asserted, key frame byte-exact against aomdec --limit=1, and the new sub8_chroma444_lossless_tu_reach_hits() counter (86 on this cell) proving the fixed path fired. Red-before with only the two reach expressions reverted: "differs from aomdec in 49 samples (first Some((1, 201, 200, 160, 159)))". 4:2:0 and 4:2:2 are structurally untouched (every call site sits behind `chroma_444`), and a square 4x4 leaf is provably unchanged (of_tu falls through to the block's own answer, which for a square leaf IS the old lookup). -- lossless 444: 48/0. -- 420: 2/0. -- intrabc: 21/0. -- 422: 6/0. --- crates/ec-av1/src/decode.rs | 63 ++++++- crates/ec-av1/src/stream.rs | 153 ++++++++++++++++ lanes/av1loss444kf.report.md | 346 +++++++++++++++++++++++++++++++++++ 3 files changed, 554 insertions(+), 8 deletions(-) create mode 100644 lanes/av1loss444kf.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 3d646978..dee93929 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6301,6 +6301,14 @@ thread_local! { /// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose chroma a /// lossless 4:4:4 frame walked as per-4x4 [`TxbSet::Chroma4`] units. static INTRABC_RECT8_LOSSLESS_CHROMA_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-av1loss444kf: 4:4:4 lossless sub-8x8 RECT (8x4 / 4x8) leaf chroma + /// units whose libaom-faithful block-relative reach + /// ([`Reach::of_tu`] over the leaf's own bsize) differs from the + /// standalone-BLOCK_4X4 lookup that used to answer for them. Zero means + /// no stream reached a rect leaf where the two disagree -- a gate + /// asserting the reach fix must see this nonzero, or the fixture never + /// exercised the fixed path. + static SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// 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 { INTRABC_RECT8_LOSSLESS_CHROMA_HITS.with(|c| c.get()) } +/// How many 4:4:4 lossless sub-8x8 RECT leaf chroma units took the +/// block-relative reach libaom's `has_bottom_left` gives, where the +/// standalone-BLOCK_4X4 lookup that used to answer disagreed +/// (lane-av1loss444kf). Zero on a stream with no such leaf. +pub fn sub8_chroma444_lossless_tu_reach_hits() -> usize { + SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS.with(|c| c.get()) +} + +/// Gate-side reset for [`SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS`]. +pub fn reset_sub8_chroma444_tu_reach_hits() { + SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS.with(|c| c.set(0)); +} + /// Gate-side reset for the two lane-av1-ibc444rect counters above. pub fn reset_ibc444rect_hits() { INTRABC_RECT8_LOSSLESS_LUMA_HITS.with(|c| c.set(0)); @@ -9903,9 +9924,7 @@ impl Neighbours { fill_span(&mut self.uv_owner, row * stride + mi_c, n, owner); } if crate::envflags::env_flag!("EC_LEFTSSY") { - eprintln!( - "EC_LEAF mi=({mi_r},{mi_c}) wh=({mi_w},{mi_h}) uv_mode={uv_mode}" - ); + eprintln!("EC_LEAF mi=({mi_r},{mi_c}) wh=({mi_w},{mi_h}) uv_mode={uv_mode}"); } } @@ -24237,7 +24256,28 @@ fn sub8_leaf_chroma444( ); set_palette_pred(pb, fctx); let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4); - let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx); + // lane-av1loss444kf: libaom asks + // `has_top_right`/`has_bottom_left` with the + // LEAF's bsize, this unit's `(col_off, row_off)` + // and `tx_size` -- not as a standalone BLOCK_4X4 + // at the unit's own position. A 4x8 leaf's FIRST + // unit has its bottom-left pixels inside the + // block's own second row (already reconstructed), + // which `has_bottom_left`'s + // `row_off + count < plane_bh_unit` early-out + // answers TRUE; the 4x4 table answered false, so + // `PlaneBuf::edges` replicated the last left + // sample and the unit predicted from a fabricated + // edge (the 4:4:4 lossless key frame's 49-sample + // chroma damage at (196,200)-(204,200)). The + // 4:2:2 twin of this arm was fixed the same way + // (lane-av1-422kf2); this is its 4:4:4 twin. + let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach); + if !square + && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx) + { + hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS); + } let grid = read_plane( dec, cdfs, @@ -24418,7 +24458,15 @@ fn sub8_leaf_chroma444( let (umi_r, umi_c) = (lmi.0 + ur, lmi.1 + uc); let (upx, upy) = (px + uc * 4, py + ur * 4); let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4); - let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx); + // lane-av1loss444kf: the block-relative answer, not + // a standalone BLOCK_4X4 lookup at the unit's own + // position -- see the intrabc twin above for the + // libaom citation and the measured damage. + let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach); + if !square && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx) + { + hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS); + } let grid = read_plane( dec, cdfs, @@ -28618,9 +28666,8 @@ fn read_block_tx_size_rect( let full_h_mi = bh / MI; if max_w_mi != full_w_mi || max_h_mi != full_h_mi { LOSSLESS_EDGE_CLIPPED.with(|c| c.set(c.get() + 1)); - LOSSLESS_EDGE_CLIP_UNITS.with(|c| { - c.set(c.get() + (full_w_mi * full_h_mi - max_w_mi * max_h_mi)) - }); + LOSSLESS_EDGE_CLIP_UNITS + .with(|c| c.set(c.get() + (full_w_mi * full_h_mi - max_w_mi * max_h_mi))); } let mut leaves = Vec::with_capacity(max_w_mi * max_h_mi); for row in 0..max_h_mi { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index db0428f0..d63bc4bf 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -46268,6 +46268,159 @@ pub(crate) mod tests { } } + /// Decode-order frame 0 only, against the oracle's own + /// `EC_AV1_FINAL_DUMP` for that frame: how many SAMPLES differ, and the + /// first one as `(plane, x, y, ours, oracle)`. + /// + /// lane-av1loss444kf: the 4:4:4 lossless 256x256 cell's inter frames carry a + /// SEPARATE, already-diagnosed walk defect (the per-mu-chunk lossless + /// chroma span, `lanes/av1loss444mm.report.md` r1), so a whole-stream + /// byte-exactness assert cannot name this one. `aomdec --limit=1` stops + /// after the key frame, which is exactly the frame the reach fix moves. + #[allow(clippy::type_complexity)] + fn key_frame_diffs( + stream: &[u8], + name: &str, + ) -> (usize, Option<(usize, usize, usize, u8, u8)>) { + let dir = std::env::temp_dir().join(format!("ec-av1-{name}-kf-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let obu = dir.join("in.obu"); + std::fs::write(&obu, stream).expect("writing the stream"); + let aom_prefix = dir.join("aomkf"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "--limit=1", "-o"]) + .arg(dir.join("out.y4m")) + .arg(&obu) + .env("EC_AV1_FINAL_DUMP", &aom_prefix) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{name}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ours_prefix = dir.join("ourskf"); + set_final_dump_prefix(Some(ours_prefix.display().to_string())); + let decoded = decode_stream(stream); + set_final_dump_prefix(None); + decoded.unwrap_or_else(|e| panic!("{name}: this decoder refused the stream: {e}")); + let want = std::fs::read(format!("{}.f0", aom_prefix.display())).expect( + "the oracle wrote no decode-order frame 0 -- rung 12 of \ + scripts/instrument-aom-oracle.sh is missing", + ); + let got = std::fs::read(format!("{}.f0", ours_prefix.display())) + .expect("this decoder wrote no decode-order frame 0"); + assert_eq!( + got.len(), + want.len(), + "{name}: our key frame is {} bytes, the oracle's is {}", + got.len(), + want.len() + ); + let side = (want.len() / 3).isqrt(); + let differing = got.iter().zip(&want).filter(|(a, b)| a != b).count(); + let first = got.iter().zip(&want).position(|(a, b)| a != b).map(|at| { + // the dump is plane after plane (Y, U, V), so the in-plane + // offset is what carries the x/y split + let plane = at / (side * side); + let in_plane = at % (side * side); + (plane, in_plane % side, in_plane / side, got[at], want[at]) + }); + let _ = std::fs::remove_dir_all(&dir); + (differing, first) + } + + /// lane-av1loss444kf: the 4:4:4 lossless 256x256 key frame's 49-sample + /// chroma damage, and the `Reach` a transform unit inside a sub-8x8 RECT + /// leaf must be given. + /// + /// The cell: `testsrc2 256x256 rate=25` yuv444p, 6 frames, + /// `aomenc --lossless=1 --enable-palette=0 --enable-intrabc=0` -- **109215 + /// bytes, sha256 `4563a01f1778600020ffa9f15bc05f5559321cf5712b99a29ed7192675dee6a4`, + /// fnv1a64 `0xbbb56442f393a9b2`**. Its key frame decodes with **21 U + 28 V + /// samples wrong** (U over x 196..207 / y 200..203, V over x 196..206), + /// luma exact, entropy bit-locked over all 81933 of its symbol reads and + /// its 12288 transform units at identical absolute `(plane, x, y)`. + /// + /// The defect: libaom's `has_bottom_left` (`reconintra.c:381`) is asked + /// with the **leaf's** `bsize`, the unit's `(row_off, col_off)` and + /// `tx_size` -- and its first branch inside the left column is + /// `if (row_off + bottom_left_count_unit < plane_bh_unit) return 1;`, the + /// block's OWN next row, already reconstructed. A 4x8 leaf's first TX_4X4 + /// unit therefore HAS four bottom-left samples. `sub8_leaf_chroma444` + /// instead looked a standalone `BLOCK_4X4` up at the unit's own position + /// (`Reach::of(4, upx, upy, ..)`), which answers false there, so + /// [`PlaneBuf::edges`] replicated the last left sample out to the edge's + /// full `bw + bh` reach and the unit predicted D203/CFL from a fabricated + /// edge. The 4:2:2 twin of the same function was fixed this way already + /// (lane-av1-422kf2, whose comment names the old lookup); this is its + /// 4:4:4 twin, still carrying the stale copy. + /// + /// Non-vacuity, in order: + /// 1. the live re-encode's length AND fnv1a64 -- a recipe or encoder drift + /// fails here instead of passing as this cell; + /// 2. [`assert_444_header`] -- at 4:2:0 the arm is unreachable (every + /// caller of `sub8_leaf_chroma444` sits behind `chroma_444`) and every + /// assert below would pass for free; + /// 3. [`key_frame_diffs`] == 0 samples, with the first differing sample + /// NAMED in the failure so a regression is a location, not a count; + /// 4. [`crate::decode::sub8_chroma444_lossless_tu_reach_hits`] rose over + /// the decode -- the units where the block-relative answer and the + /// standalone one disagree, which is what makes this a witness of the + /// FIXED path and not of a stream that merely has rect leaves. + #[test] + fn a_lossless_444_sub8_rect_leaf_chroma_reach_decodes_the_key_frame_pixel_exact() { + const NAME: &str = "lossless-444-sub8-rect-leaf-chroma-reach"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let stream = chroma_format_stream( + 256, + 256, + "yuv444p", + 8, + 6, + &["--lossless=1", "--enable-palette=0", "--enable-intrabc=0"], + 0, + ); + assert_eq!( + (stream.len(), fnv1a64(&stream)), + (109215, 0xbbb5_6442_f393_a9b2), + "{NAME}: the pinned 4:4:4 lossless 256x256 cell is {} bytes / fnv1a64 {:#x}, \ + not 109215 / 0xbbb56442f393a9b2 -- the recipe or the encoder drifted, so a \ + result here is not a result about this cell", + stream.len(), + fnv1a64(&stream) + ); + assert_444_header(&stream, NAME, 8); + crate::decode::reset_sub8_chroma444_tu_reach_hits(); + let (differing, first) = key_frame_diffs(&stream, NAME); + assert_eq!( + differing, 0, + "{NAME}: the 4:4:4 lossless key frame differs from aomdec in {differing} samples \ + (first {first:?} as (plane, x, y, ours, oracle)) -- a sub-8x8 RECT leaf's chroma \ + unit must be given the reach libaom's has_bottom_left computes for the LEAF, not a \ + standalone BLOCK_4X4 lookup at the unit's own position" + ); + let reach_hits = crate::decode::sub8_chroma444_lossless_tu_reach_hits(); + assert!( + reach_hits > 0, + "{NAME}: went blind -- not one 4:4:4 lossless rect-leaf chroma unit had the \ + block-relative reach disagree with the standalone BLOCK_4X4 lookup, so the cell \ + never reached the fixed path and the byte-exactness above proves nothing about it" + ); + eprintln!( + "{NAME}: key frame byte-exact vs aomdec (0 of 196608 samples differ), {reach_hits} \ + rect-leaf chroma unit(s) took the block-relative reach" + ); + } + /// lane-av1distwtd: the gate that pays the `enable-dist-wtd-comp` entry in /// `gate_coverage.rs`'s [`NEVER_EXERCISED_8BIT`], and corrects its stated /// reason. The entry said "distance-weighted compound is unimplemented" -- diff --git a/lanes/av1loss444kf.report.md b/lanes/av1loss444kf.report.md new file mode 100644 index 00000000..dcf669b9 --- /dev/null +++ b/lanes/av1loss444kf.report.md @@ -0,0 +1,346 @@ +# lane-av1loss444kf — the 4:4:4-lossless key frame's 49 chroma samples: found, fixed, witnessed + +**Tree.** branch `lane-av1loss444kf` off `c6112723`, worktree +`~/.cache/wt/av1loss444kf`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss444kf` +(lane-private), `TMPDIR=$HOME/.cache/tmp`. Nothing pushed. Files touched: +`crates/ec-av1/src/decode.rs` (the fix + the counter + its accessor), +`crates/ec-av1/src/stream.rs` (one comparison helper + one gate). No temporary +instrumentation survived — see §7. + +## 0. Verdict in one table + +| question | measured answer | +|---|---| +| does the carrier reproduce? | **yes**, byte-for-byte: 109215 B, sha256 `4563a01f17786000…` | +| 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 | +| 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 | +| 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 | +| fixed? | **yes** — 49 → **0**, on the 109215 B carrier *and* on the 109909 B one | +| 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 | +| 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 | + +## 1. The carrier, pinned and reproduced + +`testsrc2 256x256:rate=25` → `yuv444p`, 6 frames, piped to the durable oracle as +y4m, encoded with + +``` +aomenc --lossless=1 --enable-palette=0 --enable-intrabc=0 \ + --codec=av1 --passes=1 --end-usage=q --threads=1 --row-mt=0 \ + --lag-in-frames=0 --kf-max-dist=100 --limit=6 --obu -o - - +``` + +* **109215 bytes, sha256 `4563a01f1778600020ffa9f15bc05f5559321cf5712b99a29ed7192675dee6a4`, + fnv1a64 `0xbbb56442f393a9b2`** — the cell `lanes/av1tilemeasure` published. The + gate re-encodes it live and asserts BOTH the length and the fnv1a64, so a + recipe or encoder drift fails as drift instead of passing as this cell. +* The key frame alone, split to `SEQ + TD + FRAME` in the original OBU order + (`split.py`, 18140 B, sha256 `f390434237f1a94f…`), is what every measurement + below runs on: `aomdec --limit=1` and this decoder each see one frame, so no + inter-frame walk defect can be mistaken for this one. +* The second, independent encode of the same cell — `+ --sb-size=128` with + intrabc on, **109909 B, sha256 `d4427a7372e443e1…`** (key frame 18131 B) — is + the second arm in §5. + +**Fingerprint, measured on the key frame (ours vs `aomdec`'s `EC_AV1_FINAL_DUMP`):** + +| | before | after | +|---|---|---| +| key frame samples differing from the oracle | **49** | **0** | +| per plane | U 21, V 28, **luma 0** | 0 / 0 / 0 | +| extent | U x 196..207 y 200..203, V x 196..206 y 200..203 | — | +| per 4x4 cell (U) | 6/16, 9/16, 6/16 | — | +| first sample | plane 1, x 201, y 200: ours 160, oracle 159 | — | +| deltas (ours − oracle) | U **−3 … +1**, V **−6 … +1** | — | + +**One correction to the handed-down fingerprint, measured.** The report I was +given says the deltas run `+1 … +63` (U) and `−54 … +47` (V), 17 and 23 distinct +values. On the pinned 109215 B carrier the deltas are **−3 … +1** (U, 4 distinct) +and **−6 … +1** (V, 6 distinct). The COUNT, the planes, the extents, the per-cell +partiality and the first sample all reproduce exactly; only the magnitude claim +does not, and it was read off a stream that is not this one. The "not a rounding +constant" conclusion survives (it is not a constant), but nothing in this +defect needs ±63. + +## 2. Stage ladder: the whole filter chain is inert, on BOTH sides + +One `aomdec` run of the key-frame stream with four dump rungs at once +(`EC_AV1_PREFILT_DUMP`, `EC_AV1_POSTDEBLOCK_DUMP`, `EC_AV1_POSTCDEF_DUMP`, +`EC_AV1_FINAL_DUMP`), and this decoder with its own `EC_AV1_PREFILT_DUMP`: + +``` +oracle pre == deblock == cdef == final (all four files byte-identical, 196608 B) +ours pre == final (byte-identical) +ours pre vs oracle pre 49 samples — the SAME 49 +``` + +So deblocking, CDEF and loop restoration changed nothing on either side of this +frame, and the divergence is already present in the **reconstruction**. The +filter chain is exonerated as the ORIGIN, not merely as a contributor, and that +is measured here rather than inherited from the other lanes' stage claims. + +## 3. Prediction vs residual: decided by arithmetic, then by transcription + +**The cheap discriminator.** On a lossless frame `recon = prediction + residual` +exactly, and the coefficients are the same on both sides (entropy is bit-locked, +the transform-unit walk is position-identical), so the residual is the same on +both sides. Therefore + +> the 49-sample pixel delta **is** the 49-sample prediction delta. + +That alone moves the search space from "prediction, dequant/WHT, placement" to +"prediction" — but it is only valid if the coefficients really are identical, so +it was checked rather than assumed: with the prediction delta fully explained +(§3b) the coefficients cannot differ anywhere, because a coefficient difference +would show up as a pixel delta that the prediction cannot produce. + +**The paired prediction rungs.** `EC_PRED=1` on both decoders over the key frame: + +* the oracle prints 3130 `EC_PRED` lines (directional + filter-intra only; a + non-directional block prints just `EC_PREDOUT8`) and **12288** `EC_PREDOUT8` + lines; this decoder prints **12288** `OUR_PRED` lines. Same count, same + decode order. +* Index-pairing is a trap here: at the first order disagreement our (200,196) + is read against the oracle's (196,200) and every value looks wrong. Pairing + by `(x, y, plane)` instead — both traces carry the coordinates, the oracle's + from `mb_to_top_edge` — gives **exactly 4 sum mismatches out of 3130 + directional predictions**, all four inside the two 4x8 rect leaves at + (196,200) and (200,200), chroma planes, mode 7 (D203, p_angle 203). Every + other directional prediction in the frame, luma and chroma, is identical. +* The third damaged block (204,200) is a `UV_CFL_PRED` leaf, whose base + prediction is DC and therefore prints no `EC_PRED` line at all. It is damaged + for a different reason — see §3c. + +**3b. The 16 samples, from a transcription of libaom's own code.** With the +prediction deltas known, `pred_oracle = pred_ours − (recon_ours − recon_oracle)` +gives the oracle's full 4x4 prediction for each damaged unit. A from-scratch +transcription of `av1_dr_prediction_z3_c` + `av1_filter_intra_edge_c` + +`av1_upsample_intra_edge_c` + `intra_edge_filter_strength` + +`av1_use_intra_edge_upsample` (`reconintra.c:573-638, 989-1082`), fed the edge +pixels read out of the ORACLE's own reconstruction, then run over the two +candidate left columns: + +| unit | n_bl = 0 (replicated edge) | n_bl = 4 (real bottom-left) | +|---|---|---| +| (196,200) U | **= our prediction, all 16** | = the oracle's prediction, all 16 | +| (196,200) V | = our prediction, all 16 | = the oracle's prediction, all 16 | +| (200,200) U | neither | **= the oracle's prediction, all 16** | +| (200,200) V | neither | **= the oracle's prediction, all 16** | + +16/16 samples on all four units, with the intra edge filter type at both values +(ft=0 and ft=1 make no difference at p_angle 203, 4x4: strength 0 either way and +upsample 1 either way — so the filter type is NOT the variable here, and the +`ft` column in the oracle's trace is a red herring for this cell). **The +difference is exactly `n_bottomleft_px`, and nothing else.** The dequant scale, +the 4x4 WHT and the unit placement are exonerated by construction: they produce +the residual, and the residual is not what differs. + +**3c. Why two different predictors looked guilty.** Blocks #735 (D203) and #736 +(CFL) do not fail independently. On a lossless frame a wrong prediction is +written to the frame and the NEXT block reads it as its left edge, so the +damage cascades one block to the right: our wrong pixels at (199, 201) and +(199, 202) are the left column of the block at (200,200) (measured: oracle +`[158,164,169,166,…]`, ours `[158,165,167,166,…]`), and the pixels at +(203, 201/202) are the left column of the CFL block. **One wrong block explains +all three** — the D203+CFL mix was a consequence, not a second cause. This is +what killed the "two predictors, one cause" reading the defect invited. + +## 4. The deciding site, and the fix + +`crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma444` — the 4:4:4 lossless chroma +walk of a sub-8x8 leaf. Each TX_4X4 chroma unit asked for its reach with + +```rust +let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx); +``` + +which is a **standalone `BLOCK_4X4` lookup at the unit's own position**. libaom +(`reconintra.c:1852`) asks `has_bottom_left(sb_size, bsize, mi_row, mi_col, …, +txsz, row_off, col_off, ss_x, ss_y)` — with the **leaf's** `bsize`, the unit's +`(row_off, col_off)` and `tx_size` — and that function's first branch inside the +left column is + +```c +const int bh_unit = mi_size_high[bsize]; +const int plane_bh_unit = AOMMAX(bh_unit >> ss_y, 1); +const int bottom_left_count_unit = tx_size_high_unit[txsz]; +if (row_off + bottom_left_count_unit < plane_bh_unit) return 1; // the block's OWN next row +``` + +For a 4x8 leaf's FIRST unit (`row_off = 0`, `tx = TX_4X4`) that is `0 + 1 < 2` → +**true**: the four bottom-left samples are the block's own second-row left +neighbours, already reconstructed. The oracle's own `EC_PRED` rung prints +`n_bl=4` there and `n_bl=0` for the leaf's second unit, exactly as that ladder +predicts. Our 4x4 table said false, so `PlaneBuf::edges` handed the predictor a +left column replicated out to the edge's full `bw + bh` reach, and the unit +predicted from a fabricated edge. + +`Reach::of_tu` is the crate's existing transcription of that pair of functions +(`has_tr_*`/`has_bl_*` for a unit at `(col_off, row_off)` inside a `bw x bh` +block whose own answer is `block`), and it is what the function's OWN block-level +`reach` is built for — the value was computed at the top of `sub8_leaf_chroma444` +and then not used by the per-unit walk. The 4:2:2 twin of this function was +fixed exactly this way already (lane-av1-422kf2, whose comment at `decode.rs` +names "the standalone square-4x4 table the old `Reach::of(4, ..)` lookup used"); +this was its 4:4:4 twin, still carrying the stale copy. + +```rust +let unit_reach = Reach::of_tu(bw, bh, uc * 4, ur * 4, 4, 4, reach); +if !square && unit_reach != Reach::of(4, upx, upy, y.width, y.height, fctx) { + hit!(SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS); +} +``` + +applied at **both** lossless 4:4:4 arms (the intra one and the intrabc one), plus +the counter declaration and its two accessors. + +**The class, swept repo-wide.** Every `Reach::of(4, …)` in `decode.rs` is now +accounted for, and this was the last stale copy: + +| site | verdict | +|---|---| +| `sub8_leaf_chroma444` block-level reach (~23942) | correct — the leaf's own answer, the value the fix now threads down | +| `sub8_leaf_chroma444` per-unit, intra arm | **fixed** | +| `sub8_leaf_chroma444` per-unit, intrabc arm | **fixed** (same lines, the same defect) | +| `sub8_leaf_chroma422` block-level reach | already correct (lane-av1-422kf2) | +| `decode_leaf_split4` (~25016) | correct — a standalone `BLOCK_4X4` leaf really is a 4x4 block | +| `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 | + +`Reach::of_tu` itself is **unchanged**; the fix only starts calling it. Nothing in +`encode.rs`, `intra.rs` or `transform.rs` is touched. + +## 5. The witness, and the red-before + +`stream::tests::a_lossless_444_sub8_rect_leaf_chroma_reach_decodes_the_key_frame_pixel_exact` +with a new non-panicking helper `key_frame_diffs` (`aomdec --limit=1` + +`EC_AV1_FINAL_DUMP` on frame 0 only, versus this decoder's own decode-order +frame 0), because a whole-stream byte-exactness assert cannot name this defect: +the carrier's inter frames still carry the SEPARATE mu-chunk chroma-walk defect +(§6). + +Non-vacuity, in order, every step load-bearing: + +1. the live re-encode is 109215 bytes and fnv1a64 `0xbbb56442f393a9b2` — a + drifted recipe/encoder fails HERE, not silently; +2. `assert_444_header` — at 4:2:0 the changed function is unreachable and every + assert below would pass for free; +3. the key frame is byte-exact, 0 of 196608 samples, and the failure message + NAMES the first differing sample as `(plane, x, y, ours, oracle)`; +4. `sub8_chroma444_lossless_tu_reach_hits()` rose over the decode — measured + **86** units on this cell, i.e. 86 units where the block-relative answer and + the standalone lookup disagree. This is what makes the gate a witness of the + FIXED path rather than of a stream that merely contains rect leaves. + +**Red-before, with only the two reach expressions reverted** (counter, accessor +and gate untouched): + +``` +assertion `left == right` failed: the 4:4:4 lossless key frame differs from +aomdec in 49 samples (first Some((1, 201, 200, 160, 159)) as +(plane, x, y, ours, oracle)) + left: 49 + right: 0 +test result: FAILED. 0 passed; 1 failed +``` + +Restored → green: + +``` +lossless-444-sub8-rect-leaf-chroma-reach: key frame byte-exact vs aomdec +(0 of 196608 samples differ), 86 rect-leaf chroma unit(s) took the +block-relative reach +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 748 filtered out +``` + +**Second, independent encode.** The 109909 B stream (`--sb-size=128`, intrabc +ON, a different key frame with 82697 symbol reads) decodes its key frame +**byte-exactly** with the fix and with 49-ish samples wrong without it. Same +defect, same class, two byte streams. + +**The 49-sample tripwire.** No bound anywhere was re-pinned: the tripwire is the +gate's own `differing == 0`, and it came DOWN to 0 as a consequence of the fix. +Nothing was weakened to make a gate pass. + +## 6. Identity at other shapes + +| set | result | +|---|---| +| `cargo test -p ec-av1 --lib -- lossless 444` | **48 passed, 0 failed** (17.4 s) | +| `cargo test -p ec-av1 --lib -- 420` | **2 passed, 0 failed** | +| `cargo test -p ec-av1 --lib -- intrabc` | **21 passed, 0 failed, 1 ignored** | +| `cargo test -p ec-av1 --lib -- 422` | **6 passed, 0 failed** (all refusal-inventory: 4:2:2 is refused by name) | + +Arithmetically first, then measured: + +* **4:2:0 and 4:2:2 are structurally unreachable.** All five call sites of + `sub8_leaf_chroma444` sit behind `if chroma_444`, which is + `ss_x(fctx) == 0 && ss_y(fctx) == 0`. The changed lines cannot execute at + either subsampling, so the 4:2:0 and 4:2:2 decodes are unchanged by + construction, not by measurement alone. +* **A 4x4 (square) leaf is unchanged even at 4:4:4.** `of_tu(4, 4, 0, 0, 4, 4, r)` + has `col_off == 0` (so not the `col_off > 0 → false` branch) and + `row_off + tx_h < bh` is `0 + 4 < 4` — false — so BOTH flags fall through to + `r`, the leaf's own reach, which for a square leaf is + `Reach::of(4, px, py, ..)`: the old value exactly. The counter's `!square` + guard is that same fact, so a square leaf cannot even bump it. +* The rect leaves the fix does move are the `(8, 4)` / `(4, 8)` shapes the three + non-square call sites pass; a `4x4` leaf is the only square one. + +## 7. What is still open, precisely + +* **The carrier's inter frames still diverge, and that is NOT this defect.** + Frames 1..5 still differ, and they differ by almost exactly as much as they did + BEFORE this fix (same 6-frame stream, same tree, only the two reach + expressions flipped): + + | decode-order frame | before | after | + |---|---|---| + | 0 (KEY) | 49 | **0** | + | 1 | 70151 | 70149 | + | 2 | 138579 | 138579 | + | 3 | 114966 | 114962 | + | 4 | 139220 | 139220 | + | 5 | 139919 | 139918 | + + That residual is the per-mu-chunk lossless chroma walk + (`lanes/av1loss444mm.report.md` r1: the intra tail of `decode_inter_block`'s + `side > 64` arm passed the chunk's chroma region as `(cu_tx, cu_tx)`, + `cu_tx = 32`, instead of `64 >> ss`), fixed on that lane's UNMERGED branch. + The 2- and 4-sample movements are the key frame's 49 chroma samples no longer + poisoning the inter frames' prediction source — this fix's whole downstream + contribution. Whoever merges that r1 gets the 6-frame stream. +* **The prior report's delta magnitudes are refuted** (§1). Its count, extents, + per-cell partiality and first sample all reproduce; its `+1 … +63` / + `−54 … +47` does not. Anyone matching on magnitude will not match this cell. +* **Not merge-ready in the conflict sense:** the fix edits `sub8_leaf_chroma444` + and `decode_inter_block`'s neighbourhood is a different function, but a + materialised merge has not been compiled. +* **Housekeeping observed, not touched:** the primary checkout carries an + untracked `lanes/av1probes.report.md` that is not mine (it appeared during + this lane). I did not add, move or delete anything there; the primary's + tracked files are unmodified. + +## 8. Reproduce it + +```bash +D=$HOME/.cache/loss444kf; mkdir -p $D +ffmpeg -v error -f lavfi -i "testsrc2=size=256x256:rate=25" -frames:v 6 \ + -pix_fmt yuv444p -strict -1 -f yuv4mpegpipe -y $D/6.y4m +~/.cache/aom-oracle/build/aomenc --lossless=1 --enable-palette=0 --enable-intrabc=0 \ + --codec=av1 --passes=1 --end-usage=q --threads=1 --row-mt=0 \ + --lag-in-frames=0 --kf-max-dist=100 --limit=6 --obu -o - - \ + < $D/6.y4m > $D/vc.obu # 109215 B, sha256 4563a01f17786000… +python3 $D/split.py $D/vc.obu $D/kf.obu # SEQ+TD+FRAME, 18140 B +EC_AV1_FINAL_DUMP=$D/orc_final ~/.cache/aom-oracle/build/aomdec --codec=av1 \ + --limit=1 --noblit -o /dev/null $D/kf.obu +EC_PRED=1 EC_AV1_PREFILT_DUMP=$D/our_pre EC_AV1_POSTDEBLOCK_DUMP=$D/orc_deblock \ + EC_AV1_POSTCDEF_DUMP=$D/orc_cdef \ + cargo run -p ec-av1 --example dump_yuv -- $D/kf.obu $D/ours # or the gate: +EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss444kf \ + cargo test -p ec-av1 --lib a_lossless_444_sub8_rect_leaf_chroma_reach -- --nocapture +``` + +Analysis scripts (read-only, outside the repo): `split.py` (the key-frame OBU +split), `an.py` (the per-plane fingerprint), `pair.py` (the EC_PRED / +OUR_PRED ladder paired by coordinates), `sim2.py` (the libaom z3 + edge filter + +upsample transcription that closes prediction-vs-residual).