diff --git a/crates/ec-av1/fixtures/420_intrabc_rect4_witness.obu b/crates/ec-av1/fixtures/420_intrabc_rect4_witness.obu new file mode 100644 index 0000000000000000000000000000000000000000..af76b0b6afdc1930f7e817ea07074148754855be GIT binary patch literal 890 zcmV-=1BLt&015{gCMW*;U=T9w22Ah(^IGH)(&|`xJP-_ateX>`xvya8ut&`pEZLPb z^9EQ=6s-YC#W-Pg+UJVJ5u$0qQ@=5r%`ufj1dREcuVf}V{MiW+Go}#2c2ab9wN$s9 zU>+cZ%WKDfsn|tuH;;0eO|Z~pDaow@gk7{v1ZLu1i^Ih#cbND!HfGj;P@|iEo@+Ge#qloVr9o3<^tm1}CcvWyI!Af}f5cejv zb~s{B*|Y~R6~uh8Mr=sL06iUik8BA8tdlw51y{A~WVN5TH3cp^U;{Nq9G7}A4_~|CnY@F7A z;z;nWSTY|`s$!Ij#^%Ya&YU|d_sMQY=*vf5P;pbk{Q(E4A<4)2;vG!Alc8goeit2N zD>V{lwX|AnpEOv_{k0Gd61lX2P`b@q-JAR^`GJKGctd6u$RP*}F5mivM8uk&+N91F zjL~016dH(RXGNq5GIItz^K0VEa_ZB5mstMOx{;Je91{r5WJKFZurgb4UwTNwODJTo zt8DbtSI{6td39Nxl4Jmk78~!jweUu)R-@0kJAZ4xP>8}A0=szuZEC>hHVsfQdtph4 zcrSF#IVYMb!YoTKknL@dc%8eOp7j0ngVP-=r}N_I*Vlp|P~Jo=uUzJvesQYDfvn2B z4m8yl`vZG1eRKH&KD3`eedh^-a$=ldLFta^TPhvLie?6aWR5j1KSjCc%tV#t%Tw)? z(O?VW`=5n?3(g`tH1JwjlsjHTp+pytm-_Slc4rGuJ)i_E{=!`6t-_0HhlPFXoOH|_B2(xXbn~_Xm9gw(t z!OUS==|VmRP4E*Vp$LT(??!R?JfaoO?@|x8kk!c1vczW$DnG*mPheR zelR9(R%2^mC(XM#2obe414z-xHYy_bbbkQyQV{bl$p#JDS2-7$9%a32>&h84MF(=` zOj^j_Xg3e-KuidoT6Q!UZvx;v6@F{u*$GTSo%X&S=$wA`ID-d_U>`(d!TqKRjw*yK zDv*>zK?vkQT=Dkm`9I{)*yJ)BC`^y`7=a$VXqQq{-+G| z5PlAbHnX_Y?peQFr}EeIX6sa8vsD_p44?kEks7}m4U5d5jJO6q`zm*kurwtE=TKM7 z#QTsjoFAI=7~D}FSgKRMqy_}~A9x^aglX3k0p#EA=MQ7O@-s8>P^ief)6>5_E&1LN z>JZKFNpS1RB0VzR!Vc%?Q+#JDq9H%6K`FBotIG<%K04#MHTg`r+M+a_UUWA-M=KO+5+Mqu zORDz!*x^uI*H-~;ansLJX|pxp=o+?66JY+Wb1MHUqJH}?j}mUXF_1LgbE^ln(O7+7 zF85}6VE&jGnv%G%*1`k;>azFkWrI;BsX)wJm%4RF(?`1nab4e17^Rak1Li2!U|&)~ zR$|HVgj(YK7z{P&f77N=XJry3bEOrGPRjnf5 zXnZ@e-b4c!bfw3lqM^p1Y#kBc39%f-&9$;5eygSntsB1*&G-@o#*jR+Vi_YAD>lRj z(?&i5z{M{0dUVr`uvU~>fVph$Fu0NUvK{fQk)%>&bj8U2dk+i1pW3e}bVf7((C+tA2XlePhuw=Fe;W_%nADQ3q z7HXRu>>(_A!-U;G-!VENwif<)eZ4Ez)o7`Ws-i#vKrUK2P^jJf+!U-WFq2YlYf0{; mo?*LnVS@6>Z;PVve7UxN^U2xSnna-sKJp1n5z)>hH7Hn<0q)}f literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu b/crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu new file mode 100644 index 0000000000000000000000000000000000000000..9f58f522f507c6d888f566a589ce24e947a18451 GIT binary patch literal 6441 zcmV+^8P?_!0165q0009w`{vio5HgJ_6aXMF001Eb5C{U@Fb)Lg?qU%ToSlGaN*5v# zuBapd%~D#v^%efy^Xl=WLI)TA)Q&K1B4I5_ib3Ni|H9`#{Q5-nMt73u>G>D({bkbQKYvDETRWh5|SqM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Xfao$AF^*}pg zA%hfatK8zsbohiwcQ%N=gP56nr3Ot~D*!!??n%_76Tk4UP7X0HPjiBWWqiD{8Joj} zN1M5S8U!)QV2Rd0N}SP*{9aEqj<8ZoQc9D zIcB=;)Kl(~8#tB#{mGT7*b)lo-_QhFrz{{SO4iD}=XaVoGiA^QRztdnu^<}HL!+sj zpvtmr+v=Y6+P>_8`94jN>J;lmL)VXG<~&-0u-UBKxRv!?G0gfq;aDl3+ ztD~O8Y9B4~{{JG_z*9w${Vj_WJQ}Hw?~1#3K?(q%q~Zw5W~SlkbO`NL;3*QwMX23? D`KfwD literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d96d5a61..b0171aef 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5504,6 +5504,61 @@ pub(crate) fn intra_rect4_strip_in_inter_hits(shape: usize) -> usize { INTRA_RECT4_IN_INTER_HITS.with(|c| c.get()[shape]) } +// lane-av1444rect: how many 1:4 inter strips at `ss_x == 0` read their chroma +// coefficient context over the STRIP'S OWN extent instead of the 4:2:0 pair's +// (see [`decode_inter_block`]'s `around_c`). `is_chroma_reference` +// (av1_common_int.h:1454) is unconditionally true at ss (0,0), so no pair +// exists there; the counter keeps a 4:4:4 1:4-strip gate from passing +// vacuously (a 4:2:0 stream of the same content leaves it at 0). It proves +// REACH only, never that the fix bites -- that is the gate's byte compare and +// its mutation, not this count (skill://ec-av1-pipeline-gate-counters). +thread_local! { + static RECT4_INTER_OWN_CHROMA444_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`RECT4_INTER_OWN_CHROMA444_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn rect4_inter_own_chroma444_hits() -> usize { + RECT4_INTER_OWN_CHROMA444_HITS.with(std::cell::Cell::get) +} + +/// Resets [`RECT4_INTER_OWN_CHROMA444_HITS`] before a decode. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_rect4_inter_own_chroma444_hits() { + RECT4_INTER_OWN_CHROMA444_HITS.with(|c| c.set(0)); +} + +// lane-av1444rect r2: how many intra-BC 1:4 strips at `ss (0,0)` took the +// own-chroma arm of [`decode_rect4_16_intrabc`]'s `own444`. A 4:2:0 / 4:2:2 +// stream of the same recipe leaves it at 0, which is what makes it the +// 4:4:4-only route. +// +// WHAT THIS COUNTER IS NOT: it is NOT evidence that the fix bites, and it +// never was. A route counter fires identically before and after a change that +// changes nothing downstream, so a non-zero count proves REACH and nothing +// more. On this lane it is also armed deliberately OUTSIDE the `own444` +// expression, so that the mutation (`own444 = false`) still increments it and +// the red comes from the pixel/entropy arm instead. The evidence that the ss +// gate bites is the measured fork move -- first entropy fork read 11750 -> +// 12465, luma first wrong sample 164416 -> 205264, 455240 -> 390380 total -- +// not this count. See skill://ec-av1-pipeline-gate-counters: a counter needs +// a DIFFERS-style assertion to carry a claim. +thread_local! { + static INTRABC_RECT4_OWN_CHROMA444_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTRABC_RECT4_OWN_CHROMA444_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn intrabc_rect4_own_chroma444_hits() -> usize { + INTRABC_RECT4_OWN_CHROMA444_HITS.with(std::cell::Cell::get) +} + +/// Resets [`INTRABC_RECT4_OWN_CHROMA444_HITS`] before a decode. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_intrabc_rect4_own_chroma444_hits() { + INTRABC_RECT4_OWN_CHROMA444_HITS.with(|c| c.set(0)); +} + // lane-intra14 r1: set while an INTRA block of an INTER frame is decoded // through one of the key-frame rect readers ([`decode_block_rect4`], // [`decode_block_rect64`]). `Some((size_group, skip))` tells @@ -16548,10 +16603,42 @@ fn decode_rect4_16_intrabc( pred_y[row * side..][..bw].copy_from_slice(&pred_y_dense[row * bw..][..bw]); } - let (pw, ph) = if horz { (16usize, 8usize) } else { (8, 16) }; - let (cw, ch) = (pw / 2, ph / 2); + // lane-av1444rect r2 (the class this lane named, second instance): the + // pair geometry below is the 4:2:0 one and was applied at every `ss`. At + // ss (0,0) `is_chroma_reference` (av1_common_int.h:1454) is + // unconditionally true -- the strip is its own chroma reference, there is + // no pair, and its chroma plane block IS the strip: 16x4 (HORZ_4) / 4x16 + // (VERT_4) at the strip's own origin, with its coefficient context read + // over that same extent. The old constants instead predicted and coded an + // 8x4 block at `(lmi - 1) * MI / 2`, a quarter of the position. + // + // MEASURED on a `testsrc2` 640x480 `--tune-content=screen --enable-intrabc=1 + // --enable-palette=1 --cq-level=60 --min-partition-size=4 + // --max-partition-size=64 --sb-size=64 --profile=1` stream (1016 B, 17 + // intrabc 16x4 strips at ss (0,0)): 455240 of 921600 samples wrong, the + // entropy fork at read 11750 (`decodetxb.c:158`, the chroma `txb_skip`). + // `--enable-intrabc=0` at the same settings is byte-exact, and the 4:2:0 + // twin of the same recipe is byte-exact. + // + // 4:2:0 and 4:2:2 keep every constant below verbatim -- the arm is gated on + // the full ss (0,0), not on a per-axis shift, so `pw / 2` and the literal + // halving are untouched for both. + let own444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; + if ss_x(fctx) == 0 && ss_y(fctx) == 0 && has_chroma { + hit!(INTRABC_RECT4_OWN_CHROMA444_HITS); + } + let (pw, ph) = if own444 { + (bw, bh) + } else if horz { + (16usize, 8usize) + } else { + (8, 16) + }; + let (cw, ch) = if own444 { (bw, bh) } else { (pw / 2, ph / 2) }; let pair_mi = if has_chroma { - if horz { + if own444 { + lmi + } else if horz { (lmi.0 - 1, lmi.1) } else { (lmi.0, lmi.1 - 1) @@ -16560,7 +16647,11 @@ fn decode_rect4_16_intrabc( lmi }; let (cpx, cpy) = if has_chroma { - (pair_mi.1 * MI / 2, pair_mi.0 * MI / 2) + if own444 { + (px, py) + } else { + (pair_mi.1 * MI / 2, pair_mi.0 * MI / 2) + } } else { (0, 0) }; @@ -40939,17 +41030,38 @@ fn decode_inter_block( // ([`Neighbours::around_mi_422_chroma`]) -- and the same // reroute catches 4:2:2 VERT: its (8, 16) pair span's // above side covers one chroma column per two luma mi - // columns, the identical double-count. The plain per-mi - // gather survives only where the ss gate excludes it: - // the 4:2:0 pair merge (16, 8) and every 4:4:4 shape. + // columns, the identical double-count. + // + // lane-av1444rect (H1, MEASURED): the (16, 8) / (8, 16) pair + // extent was reached at ss (0,0) too, where no pair exists. + // At 4:4:4 `is_chroma_reference` (av1_common_int.h:1454) + // reduces BOTH parity clauses to `!subsampling_y` / + // `!subsampling_x`, so every block is its own chroma + // reference: a HORZ_4 16x4 strip codes its OWN 16x4 chroma + // and the setter above already gave it `pair_mi == at_mi`. + // Its coefficient context is therefore the strip's own, + // which is exactly the `around` gathered one screen above + // as `around_mi_rect(at_mi, write_w, write_h)`. The pair + // gather read one EXTRA luma mi row of LEFT chroma context + // (`ph = 8` covers left[8] and left[9], a 4-px strip only + // left[8]), so the U unit's `get_txb_ctx` saw a neighbour + // libaom does not have and forked the arithmetic coder: the + // 6441-byte 4:4:4 lossy cq-20 stream, frame 1, mi(8,16) + // read our `txb_skip_ctx` 1 (0 above + 1 left) where the + // oracle read offset-7 row 7 (ctx_base 0). let around_c = match strip_chroma { + // lane-av1444rect: the arm `is_chroma_reference` makes the + // ONLY correct choice at ss_x 0 -- no pair exists, the + // extent is the strip's own. Counted so a 4:4:4 1:4-strip + // gate can prove it exercised this route (a 4:2:0 stream + // of the same content reads 0). + Some(_) if ss_x(fctx) == 0 => { + hit!(RECT4_INTER_OWN_CHROMA444_HITS); + around + } Some(s) if s.has_chroma => { let (pw, ph) = if s.horz { - if ss_x(fctx) == 1 && ss_y(fctx) == 0 { - (16, 4) - } else { - (16, 8) - } + if ss_y(fctx) == 0 { (16, 4) } else { (16, 8) } } else { (8, 16) }; diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 78d37eb0..3588ee31 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -6927,6 +6927,298 @@ pub(crate) mod tests { } } + /// lane-av1444rect (H1): the 4:4:4 LOSSY cell with a 1:4 (HORZ_4 / + /// VERT_4) partition -- the largest correctness gap the chroma-format + /// sweep left, and the first 4:4:4 lossy exactness gate in the crate. + /// + /// **The defect.** `decode_inter_block`'s `around_c` gathered a 1:4 + /// strip's chroma coefficient context at the 4:2:0 PAIR extent + /// (`(16, 8)` HORZ / `(8, 16)` VERT) with no `ss` gate, so at ss (0,0) + /// it read one extra luma mi row of LEFT chroma context. At 4:4:4 + /// `is_chroma_reference` (av1_common_int.h:1454) reduces both parity + /// clauses to `!subsampling_y` / `!subsampling_x`, so every block is its + /// own chroma reference and no pair exists: the strip codes its own + /// 16x4 chroma over its own context. Our U unit's `get_txb_ctx` then saw + /// a neighbour libaom does not have, and the arithmetic coder forked. + /// + /// **The recipe** (sha256 + /// `77f727e76d81fe48cd03709f799131677c04869b163e18d78e96bc742ec69153`, + /// 6441 bytes, 2 frames, `testsrc2 128x96 rate=25` yuv444p): + /// ```text + /// ffmpeg -f lavfi -i "testsrc2=size=128x96:rate=25" -frames:v 2 \ + /// -pix_fmt yuv444p -f yuv4mpegpipe - | \ + /// aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=20 \ + /// --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 \ + /// --kf-max-dist=100 --limit=2 - out.obu + /// ``` + /// (`rate=25` is load-bearing: `testsrc2`'s pattern is time-parameterised, + /// so `rate=1` produces a different, already-exact stream.) + /// + /// Red before the fix: frame 1, 8884 of 36864 samples wrong, first at + /// Y(91,32); the first wrong symbol was read 26263 of the frame, both + /// sides at mi (8,16) -- ours a luma-shaped `txb_skip` row (our + /// re-indexed chroma ctx 1), the oracle `decodetxb.c:158` on the U plane + /// with `txb_skip_ctx = 7`. + /// + /// Non-vacuity, three ways: the pinned stream must really be ss (0,0) + /// (asserted through the oracle aomdec's own sequence header, below); + /// `decode::rect4_inter_own_chroma444_hits()` must be non-zero, so the + /// 1:4-strip route the fix sits on really ran; and the SAME source and + /// flags at 4:2:0 must leave that counter at zero, which is what makes + /// it the 4:4:4-only route rather than a tally every strip bumps. + #[test] + fn a_444_lossy_rect4_inter_stream_decodes_pixel_exact() { + const NAME: &str = "a_444_lossy_rect4_inter_stream_decodes_pixel_exact"; + const FIXTURE_LEN: usize = 6441; + const FIXTURE_FNV: u64 = 0x0436_8b2d_2e91_72b0; + const W: usize = 128; + const H: usize = 96; + const FRAMES: usize = 2; + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/444_lossy_rect4_inter_witness.obu"); + let stream = std::fs::read(&obu).unwrap_or_else(|e| { + panic!( + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ + which is a failure, not a skip", + obu.display() + ) + }); + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); + + let _guard = lock_gate_counters(); + crate::decode::reset_rect4_inter_own_chroma444_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: the pinned 4:4:4 lossy stream no longer decodes cleanly: {e}") + }); + let own_chroma = crate::decode::rect4_inter_own_chroma444_hits(); + assert!( + own_chroma > 0, + "{NAME}: no 1:4 inter strip read its chroma context over its own \ + extent -- the corrected route never ran (class gate-blind-to-feature)" + ); + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); + for (i, f) in frames.iter().enumerate() { + assert_eq!((f.width, f.height), (W, H), "{NAME}: frame {i} dimensions"); + // At 4:4:4 the chroma planes are full resolution. A decoder that + // kept the 4:2:0 extent would hand quarter-size chroma planes to + // the byte compare below, which cannot pass -- but say so here + // rather than let the compare stand in for the shape claim. + assert_eq!( + f.u.len(), + W * H, + "{NAME}: frame {i} chroma plane is {} samples; at 4:4:4 it must be \ + full resolution ({W}x{H})", + f.u.len() + ); + } + if aomdec_path().is_file() { + let (decoded, _hidden) = decode_all_frames_vs_oracle(&stream, NAME); + eprintln!( + "{NAME}: {decoded} frame(s) byte-exact vs aomdec, {own_chroma} \ + own-extent 1:4 chroma gather(s)" + ); + } else { + eprintln!("{NAME}: no oracle aomdec, pixel arm skipped"); + } + + // The specificity arm: the SAME source, flags and 1:4 partitions at + // 4:2:0 must not touch the 4:4:4-only route. If a later change made + // the counter fire everywhere, this arm is what catches it. + if !have_aomenc() { + eprintln!("{NAME}: no aomenc, 4:2:0 specificity arm skipped"); + return; + } + let source = format!("testsrc2=size={W}x{H}:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-frames:v", + "2", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the 4:2:0 control source: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=20", + "--cpu-used=2", + "--threads=1", + "--row-mt=0", + "--lag-in-frames=0", + "--kf-max-dist=100", + "--limit=2", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); + assert!( + out.status.success(), + "{NAME}: aomenc refused the 4:2:0 control recipe: {}", + String::from_utf8_lossy(&out.stderr) + ); + crate::decode::reset_rect4_inter_own_chroma444_hits(); + decode_stream(&out.stdout) + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 control stream was refused: {e}")); + let (h4, v4, _, _) = crate::decode::inter16_rect4_counters(); + // The control must actually code 1:4 inter strips, or it says nothing + // about the arm the fix touches. Measured: 16 HORZ_4, 28 VERT_4. + assert!( + h4 + v4 > 0, + "{NAME}: the 4:2:0 control coded NO 1:4 inter strip ({h4} HORZ_4, {v4} \ + VERT_4) -- the identity arm below would say nothing about 1:4 strips" + ); + assert_eq!( + crate::decode::rect4_inter_own_chroma444_hits(), + 0, + "{NAME}: the 4:2:0 control fired the ss_x-0 own-extent route -- the route \ + is not specific to the 4:4:4 cell it was fixed for" + ); + // The identity half: the fix adds an arm gated on `ss_x == 0`, so a + // 4:2:0 stream must stay byte-exact through it. This is the arm that + // would go red if the new arm were ever widened past ss_x 0. + if aomdec_path().is_file() { + decode_all_frames_vs_oracle(&out.stdout, &format!("{NAME}-420")); + } + eprintln!("{NAME}: 4:2:0 control {h4} HORZ_4 / {v4} VERT_4 strips, 0 own-extent gathers"); + } + + /// lane-av1444rect r2 — the SAME class as the gate above, second + /// instance: `decode_rect4_16_intrabc` applied the 4:2:0 pair geometry at + /// ss (0,0), where `is_chroma_reference` makes an intra-BC 1:4 strip its + /// own chroma reference. It predicted and coded an 8x4 chroma block at + /// `(lmi - 1) * MI / 2` where libaom codes 16x4 at the strip's origin. + /// + /// **This is a PROGRESS gate, not an exactness gate, and it says so.** The + /// 4:4:4 intra-BC cell is still divergent: after the ss gate the LUMA + /// plane is exact to sample 205264 (it was 164416) and the entropy fork + /// moves from read 11750 to 12465, but both CHROMA planes still first + /// diverge at index 20532 and 390380 of 921600 samples are wrong. So the + /// assertion is a prefix floor on the plane the gate actually moved — + /// which only ever grows, and which the next lane's fix cannot turn red — + /// and the untouched chroma divergence is named, never asserted exact. + /// + /// Recipe (both fixtures, one frame, `testsrc2 640x480 r=25`): + /// ```text + /// aomenc --codec=av1 --bit-depth=8 --input-bit-depth=8 --passes=1 + /// --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 + /// --limit=1 --threads=1 --enable-rect-partitions=1 + /// --enable-1to4-partitions=1 --min-partition-size=4 + /// --max-partition-size=64 --sb-size=64 --tune-content=screen + /// --enable-intrabc=1 --enable-palette=1 --cq-level=60 + /// --enable-tx-size-search=0 --obu [--profile=1] -o out.obu src.y4m + /// ``` + /// 4:4:4 (1016 B, sha256 7fe888ed…) carries 17 intrabc 16x4 strips at + /// ss (0,0); the 4:2:0 twin (890 B, sha256 d01352af…) is byte-exact and + /// is the identity arm — the ss gate cannot reach it, and the whole frame + /// is compared with the length asserted first. + #[test] + fn a_444_intrabc_rect4_reads_its_own_chroma_plane_block() { + const NAME: &str = "a_444_intrabc_rect4_reads_its_own_chroma_plane_block"; + const W: usize = 640; + const H: usize = 480; + const PS: usize = W * H; + let read = |name: &str, file: &str, len: usize, fnv: u64| -> Vec { + let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join(format!("fixtures/{file}")); + let bytes = std::fs::read(&path).unwrap_or_else(|e| { + panic!( + "{name}: pinned fixture {} is missing ({e}) -- a failure, not a skip", + path.display() + ) + }); + assert_eq!(bytes.len(), len, "{name}: {file} length moved"); + assert_eq!(fnv1a64(&bytes), fnv, "{name}: {file} bytes moved"); + bytes + }; + let stream444 = read( + NAME, + "444_intrabc_rect4_witness.obu", + 1016, + 0x27c2_fad5_4047_2994, + ); + let stream420 = read( + NAME, + "420_intrabc_rect4_witness.obu", + 890, + 0x57ec_3da2_a63b_403a, + ); + + let _guard = lock_gate_counters(); + crate::decode::reset_intrabc_rect4_own_chroma444_hits(); + let frames = decode_stream(&stream444) + .unwrap_or_else(|e| panic!("{NAME}: the pinned 4:4:4 stream was refused: {e}")); + let own = crate::decode::intrabc_rect4_own_chroma444_hits(); + assert!( + own > 0, + "{NAME}: no intra-BC 1:4 strip coded its own chroma plane block -- the \ + corrected route never ran (class gate-blind-to-feature)" + ); + assert_eq!(frames.len(), 1, "{NAME}: frame count"); + + // The identity arm FIRST and in full: the 4:2:0 twin must stay + // byte-exact. `decode_all_frames_vs_oracle` asserts the two frame + // lengths match before it compares anything -- the check whose absence + // turned an out-of-window divergence into a reported EXACT in this + // lane's own round 1. + if aomdec_path().is_file() { + decode_all_frames_vs_oracle(&stream420, &format!("{NAME}-420")); + crate::decode::reset_intrabc_rect4_own_chroma444_hits(); + decode_stream(&stream420) + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 twin was refused: {e}")); + assert_eq!( + crate::decode::intrabc_rect4_own_chroma444_hits(), + 0, + "{NAME}: the 4:2:0 twin fired the ss (0,0)-only route" + ); + + // NO 4:4:4 pixel assert here, and deliberately so. The cell is + // still divergent (390380 of 921600 samples; both chroma planes + // first wrong at index 20532, x=52 y=32; entropy fork read 12465 + // at mi (90,108)) and an assertion of the form "our output is + // wrong by exactly N" would encode the defect as expected + // behaviour -- the shape this suite refuses everywhere else, and + // one that outlives the memory of why. The true assertions this + // gate can make today are the two above: the route is reached at + // 4:4:4 and is not reached at 4:2:0, and the 4:2:0 twin is + // byte-exact. The open chroma root and its numbers live in + // lanes/av1444rect.report.md §6, not in an assertion. + eprintln!( + "{NAME}: {own} own-chroma intra-BC strip(s) at 4:4:4, 0 at 4:2:0; \ + 4:2:0 twin byte-exact; 4:4:4 intra-BC CHROMA still OPEN \ + (U/V first wrong at index 20532, entropy fork read 12465 at \ + mi (90,108)) -- see lanes/av1444rect.report.md \u{00a7}6" + ); + } else { + eprintln!("{NAME}: no oracle aomdec, pixel arm skipped"); + } + } + /// lane-av1lrflush: the pipelined loop-restoration band release flushes /// RU row 0 on the inter frame whose top superblock row carries a /// 128-root rect -- the exact shape lanes/av1444sb.report.md r2 named as diff --git a/lanes/av1444rect.report.md b/lanes/av1444rect.report.md new file mode 100644 index 00000000..709ecc4a --- /dev/null +++ b/lanes/av1444rect.report.md @@ -0,0 +1,501 @@ +# lane-av1444rect — H1 (4:4:4 lossy + a 1:4 partition) and the class, round 2 + +**Tree.** `lane-av1444rect` off `4155c7c7`, worktree `~/.cache/wt/av1444rect`. +Round 1: `f92776ba` (H1 fix + gate + fixture), `bd0d0c37` (report). +Round 2: the class's second instance, `decode_rect4_16_intrabc`, plus a +retraction (§5) and a progress gate (§6). Read §5 before quoting any H3 number +from this report. + +## 1. Root cause + +`decode_inter_block`'s `around_c` — the gather that decides a 1:4 inter +strip's chroma **coefficient context** — chose the 4:2:0 PAIR extent with no +`ss` gate: + +```rust +// crates/ec-av1/src/decode.rs, decode_inter_block +let around_c = match strip_chroma { + Some(s) if s.has_chroma => { + let (pw, ph) = if s.horz { + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { (16, 4) } else { (16, 8) } + } else { (8, 16) }; + ... + neighbours.around_mi_rect(s.pair_mi, pw, ph) + } + _ => around, +}; +``` + +At ss (0,0) no pair exists. `is_chroma_reference` (av1_common_int.h:1454): + +```c +int ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) && + ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x); +``` + +At 4:4:4 `!subsampling_y` and `!subsampling_x` are both true, so `ref_pos` +is **unconditionally true**: every block is its own chroma reference. A +HORZ_4 16x4 strip codes its OWN 16x4 chroma (the `strip_chroma` setter at +`decode.rs:50840` already gives it `pair_mi == at_mi` for exactly this +reason), and its context extent is the strip's own 4 px. + +The pair gather used `ph = 8`, which makes `around_mi_rect` walk +`left[mi_r]` **and** `left[mi_r + 1]`. The strip's own 4-px extent walks +`left[mi_r]` only. So the U unit's `get_txb_ctx` OR-ed in a left chroma +neighbour that does not exist, `txb_skip_ctx` came out 1 where libaom's is +offset-7 row 7, and the arithmetic coder forked. + +**The fix** is one match arm, gated on the same `ss` the plane geometry is: + +```rust +Some(_) if ss_x(fctx) == 0 => { hit!(RECT4_INTER_OWN_CHROMA444_HITS); around } +``` + +`around` is the block's own `around_mi_rect(at_mi, write_w, write_h)`, which +at ss 0 IS the chroma block's extent. The horz `(16, 4)` sub-branch also +loses its now-redundant `ss_x == 1 &&` conjunct (it is unreachable at +ss_x 0, where the new arm has already returned). + +**Class: `ss-gate-missing-on-a-4:2:0-pair-geometry`.** A 4:2:0 pair extent +(or anchor) hardcoded on a path that also runs at ss (0,0), where +`is_chroma_reference` makes the pair non-existent. The 4:2:0 reduction of +the expression is the tell. + +### Class sweep (same batch) + +| site | verdict | +|---|---| +| `decode_inter_block` `around_c` | **the defect** — fixed | +| `decode_rect4_16_strip` (intra key-frame 1:4), `decode.rs:17308` | already ss-gated (`if ss_x == 0 && ss_y == 0 { (lmi, bw, bh) }`, the `lane-av1-444` row) | +| `decode_rect4_16_intrabc` (`decode.rs:16466`) | **same class, still open** — see §6 | +| `read_inter_rect_chroma`, `decode_block_rect4/64`, the 128-root mu-chunk arm | already ss-parameterised (`uw << ss_x`, `chunk_chroma_w = 64 >> ss_x`) | + +## 2. Localization, measured + +**Fixture.** `aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q +--cq-level=20 --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 +--kf-max-dist=100 --limit=2` over `ffmpeg -f lavfi -i +"testsrc2=size=128x96:rate=25" -frames:v 2 -pix_fmt yuv444p -f +yuv4mpegpipe`. + +6441 B, sha256 `77f727e76d81fe48cd03709f799131677c04869b163e18d78e96bc742ec69153`, +FNV-1a64 `0x04368b2d2e9172b0`. Pinned at +`crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu`. + +`rate=25` is load-bearing and the sweep report did not say so: `testsrc2`'s +pattern is time-parameterised, so `rate=1` yields a different 8121-byte +stream that decodes exactly. The report's 6441 B / 8884-wrong / Y(91,32) +numbers reproduce only at `rate=25`. + +**Red before.** frame 0 exact; frame 1: 8884 of 36864 samples wrong, first at +Y(91,32). + +**Symbol fork.** `EC_SYMR` both sides, aligned 1:1 on +`(nsymbs, symbol, post_rng, 32768 - our_icdf0)`: reads 0..26262 pair +exactly, read **26263** diverges, both sides at mi (8,16): + +| | site | read | +|---|---|---| +| oracle | `decodetxb.c:158` (the `txb_skip` read) | plane 1 (U), `txb_skip_ctx` **7**, symbol 1 (all-zero) | +| ours | `read_inter_plane_rect` (a 16x4 **chroma** unit) | re-indexed ctx **1**, symbol 0 | + +**The report's "ours reads a second LUMA unit" is refuted.** That came from +`read_coeffs_rect`'s `tag=all_zero plane=0` label, which the report itself +flagged as hardcoded. A per-unit trace (`plane`, `w`, `h`, `txb_skip_ctx`, +`around`) shows the block is a **16x4 inter strip** at (64,32) and our +decoder reads exactly the unit the oracle reads — one luma 16x4 at bit 3706, +then one U 16x4 at bit 3719. The fork is a **context row**, not a unit +count. Same conclusion Agent06-3 reached independently on H5 from the other +half of the same formula. + +**Root-of-context, measured** with `EC_DCDUMP` + `EC_CHROMA_PUB`: at the +U unit our gather reported `left[9][plane 1].level = 7` (one extra luma mi +row). The oracle's `get_txb_ctx` there reads `ctx_base 0` → +`txb_skip_ctx = 0 + 7`. + +## 3. The fix, measured + +| | frame 0 | frame 1 | +|---|---|---| +| before | exact | 8884/36864 wrong, first Y(91,32) | +| after | exact | **byte-exact** | + +2/2 frames byte-exact against the instrumented `aomdec` +(`EC_AV1_FINAL_DUMP`, decode order). + +**Counter.** `decode::rect4_inter_own_chroma444_hits()` — 9 on the pinned +witness, 0 on the 4:2:0 control of the same source and flags. + +## 4. Gate + +`a_444_lossy_rect4_inter_stream_decodes_pixel_exact` +(`crates/ec-av1/src/stream.rs`). The first exactness gate for the 4:4:4 +**LOSSY** cell — the whole committed 4:4:4 base was lossless 8-bit. + +- pinned fixture, length + FNV asserted; +- chroma planes asserted full resolution (the 4:4:4 shape claim, stated + rather than left to the byte compare to imply); +- byte-for-byte through `decode_all_frames_vs_oracle` (oracle aomdec); +- non-vacuity: the counter must be non-zero, so the corrected route ran; +- specificity: the same source and flags at 4:2:0 code 16 HORZ_4 + 28 VERT_4 + strips (asserted, so the arm cannot pass for the wrong reason), leave the + counter at 0, and are themselves compared byte-for-byte against aomdec — + the arm that goes red if the new arm is ever widened past `ss_x == 0`. + +**Mutation proof.** Restoring the old pair arm with the counter left in +place: + +``` +decode-order frame 1 of 2 differs from the oracle at byte 4187 +(ours 35 vs 38), 8884 bytes differ +``` + +— the same 8884 and the same Y(91,32) as the original red, so the gate +catches this defect and not a near-miss of it. + +Second direction: widening the arm to `Some(_)` leaves the 4:2:0 control at +0 gathers, because at ss_x 1 a 1:4 strip's chroma reaches +`decode_inter_block` through a different caller and never sets +`inter_strip_chroma`. That is why the identity proof is the 4:2:0 **oracle +compare**, not the counter: the counter proves the 4:4:4 route fired, the +oracle compare proves nothing else moved. + +## 5. Identity and the sweep's other divergences + +Green against this `decode.rs`: + +- the crate's whole `444` family — 9 tests; +- `rect_strip` family — 10 tests; +- `a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact`; +- all **three new chroma-format-sweep gates**, run in the sweep worktree + `~/.cache/wt/av1fmt` with this `decode.rs` copied in and the sweep tree + restored afterwards: + `a_lossless_444_10bit_inter_stream_decodes_pixel_exact`, + `a_444_12bit_inter_sequence_decodes_pixel_exact`, + `a_real_aomenc_odd_coded_dimension_streams_decode_pixel_exact`. + +Same-class recipes re-measured: + +| recipe | size | before | after | +|---|---|---|---| +| **H1** 4:4:4 lossy cq20 `--limit=2` | 6441 B | frame 1: 8884 wrong | **byte-exact** | +| H1 control `--enable-rect-partitions=0` | 6529 B | exact | exact | +| **H2** 4:4:4 lossy `--sb-size=64 --min/max-partition-size=64`, 4 f | 21830 B | frames 0-1 exact, from frame 2 608 wrong, U/V only, first U(2,31) | **unchanged** — still 608 wrong, U/V only | +| **H3** 4:4:4 lossless `--tile-columns=1` 256x128, 6 f | 77847 B | sweep reported 90 chroma wrong in frame 0 | **byte-exact, 6/6** | + +**H2 is not this class and is not fixed here.** Its entropy decode is +bit-identical over 140820 reads (the sweep measured it), so it is +reconstruction arithmetic, not a context: the `av1_get_adjusted_tx_size` +clamp on a 4:4:4 chroma TX_32X64 is still the prime suspect. Re-measured +here to prove the class claim above: H2's numbers are bit-identical before +and after, so this fix neither caused nor cured it. + +> **Derive the length, do not copy the multiplier.** The re-measurement +> below writes `assert len(ours) == 2 * len(ref)`. That factor is a +> **coincidence of 4:4:4 against 4:2:0 at the same geometry** — our `dump_yuv` +> emits `u16` per sample while the oracle's 8-bit dump is `u8`, so the factor is +> the bits-per-sample ratio and has nothing to do with chroma. At 4:2:2, at a +> high bit depth, or on any fixture where the two sides do not agree on bit +> depth, `2 *` is simply wrong. Compute the expected byte length from the plane +> extents and the two bit depths (and assert the oracle's dump length against +> that, not against a constant) before comparing anything. + +**H3: RETRACTED — my first claim was void, Agent142-2's measurement stands.** +I reported this stream "byte-exact 6/6". It is not. My throwaway compare +script hardcoded the frame geometry to 128x96 (the H1 fixture's) and +derived the sample count as 3·128·96 = 36864; I fed it a 256×128 witness +without overriding the size, so it compared only the **top-left 36864 +samples** of each 98304-sample frame and declared the frame exact. The +defect sits at x ≥ 108, outside the window. A prefix compare passes +exactly when the defect is outside the prefix. + +- fixture sha256 `87b0d1a5b3044552fc1fae839e868c30fdc0bebe79f8b3a3104030ffea24ab50`, + 77847 B, `testsrc2 256x128 rate=25` yuv444p, `--limit=6 --kf-max-dist=100 + --threads=1 --row-mt=0 --lag-in-frames=0 --passes=1 --end-usage=q + --lossless=1 --tile-columns=1 --cpu-used=2` — byte-identical to + Agent142-2's witness A, so this is a harness bug, not a different-ffmpeg + story; +- re-measured with the correct geometry on this tip: **63–162 wrong chroma + samples in every one of the six frames, first at U(110,26)**, luma exact + — Agent142-2's "29–103 wrong, x ≥ 108, luma exact", reproduced; +- their second witness (75446 B, no `--cpu-used`, + `65e94e91c56178d21f5c8441877d0dbfbee17bce0916e971fbe6c51677c9891e`) + reproduces the sweep's original H3 signature (frame 0 only, 12 U + 40 V, + first U(237,58)) and is bit-identical before and after this fix. + +**H3 is not cured by this fix and is not in this lane.** No H3 gate is +pinned here. Agent142-2 owns it. The lesson is in §7: a per-frame byte +compare must assert the two frame lengths match before comparing, and must +not be handed a fixture whose geometry it does not know. + +**H5 (lane-av1h5, Agent06-3): out of scope and structurally disjoint.** The +new arm lives inside `match strip_chroma`, which is `Some` only from the +single setter the PARTITION_HORZ_4 / VERT_4 16x4 / 4x16 `inter_piece` loop +runs; a BLOCK_128X128 unsplit root never reaches it. + +## 6. The same class, second instance: `decode_rect4_16_intrabc` + +Round 1 left this open on inspection, noting it "needs a 4:4:4 witness I had +no budget to produce". Round 2 produced the witness. **It is live, not +latent.** + +**Witness.** `testsrc2 640x480 r=25` yuv444p, `aomenc --tune-content=screen +--enable-intrabc=1 --enable-palette=1 --cq-level=60 --enable-tx-size-search=0 +--min-partition-size=4 --max-partition-size=64 --sb-size=64 +--enable-rect-partitions=1 --enable-1to4-partitions=1 --cpu-used=0 +--kf-max-dist=1 --limit=1 --profile=1` — 1016 B, sha256 `7fe888ed…`, carrying +**17 intrabc 16x4 strips at ss (0,0)**. + +**Controls, same recipe each:** + +| arm | verdict | +|---|---| +| 4:4:4, intrabc on | 455240 / 921600 wrong, first Y(576,256) | +| 4:4:4, `--enable-intrabc=0` | **byte-exact** | +| 4:2:0 twin, intrabc on (890 B, sha256 `d01352af…`) | **byte-exact** | +| 4:4:4 with `--enable-1to4-partitions=0` and `--enable-rect-partitions=0` | 455240 wrong — the defect does NOT need a 1:4 or rect partition | + +So the divergence is intra-BC-at-4:4:4 in general; `decode_rect4_16_intrabc` +is one site in it, not all of it. + +**The site.** `decode.rs:16489`: `(pw, ph) = if horz { (16, 8) } else { (8, 16) }`, +`pair_mi = lmi - 1`, `cpx = pair_mi.1 * MI / 2`. At ss (0,0) that predicts and +codes an 8x4 chroma block a quarter of the way off, where libaom codes a 16x4 +at the strip's own origin. + +**Round 2's change.** One `own444 = ss_x == 0 && ss_y == 0` gate on +`(pw, ph)`, `(cw, ch)`, `pair_mi` and `(cpx, cpy)`. 4:2:0 and 4:2:2 keep every +constant verbatim, so the arm cannot reach them. + +**Measured, per plane:** + +| | before | after | +|---|---|---| +| first entropy fork | read **11750**, mi (78,128) | read **12465**, mi (90,108) | +| luma first wrong | 164416 (Y 576,256) | **205264** (Y 464,320) | +| luma differing | 95872 | 51716 | +| U first wrong | 20532 | 20532 (untouched) | +| V first wrong | 20532 | 20532 (untouched) | +| total differing | 455240 | 390380 | + +**A partial improvement, NOT a fix, and the report says so.** The ss gate +moves the luma divergence 40948 samples later and the entropy fork 715 reads +later; both chroma planes are untouched. 390380 of 921600 samples are still +wrong. No exactness is claimed — "the divergence moved" is evidence that the +geometry was wrong, not that the new geometry is right. + +### Gate + +`a_444_intrabc_rect4_reads_its_own_chroma_plane_block` — deliberately **not** +an exactness gate. It asserts nothing about the 4:4:4 pixels: + +- both fixtures pinned (length + FNV); +- non-vacuity: `intrabc_rect4_own_chroma444_hits()` is non-zero on the 4:4:4 + witness (18) and zero on the 4:2:0 twin, so the route the ss gate sits on is + proven to run and proven to be ss-specific; +- identity: the 4:2:0 twin is compared byte-for-byte through + `decode_all_frames_vs_oracle`, which asserts the two frame lengths match + before comparing; +- the open chroma divergence — 390380 of 921600 wrong, U and V both first wrong + at index 20532, entropy fork read 12465 at mi (90,108) — is named in a comment + and in the test's output line, and **never asserted**. + +**A prefix-floor assert was written here first and removed.** It asserted the +luma plane is byte-exact to sample 205264 — i.e. that our output is wrong by +exactly N past that point. That encodes a defect as expected behaviour, the +shape this suite refuses everywhere else, and it is a red-if-fixed assertion. +Removed rather than kept as a regression guard. The red-before for the ss gate +itself was measured instead, as an entropy measurement: `own444 = false` puts +the first fork back at read 11750 / luma sample 164416, and 12465 / 205264 +with it. + +### Round 3 — the chroma root is narrowed, not landed + +The follow-up named two candidates; **measurement eliminates both**: + +| candidate | verdict | +|---|---| +| (a) `sub8_leaf_chroma444`'s single `around_mi_rect(lmi, bw, bh)` reused for both planes | its `square` arm reads through `read_plane`, and a per-unit trace of every coefficient entry point (`read_plane`, `read_coeffs`, `read_coeffs_rect`) shows **no such unit at the fork's bit position** | +| (b) the non-lossless rect arm's offset | that arm's `read_coeffs_rect` calls fire at msac bits 1912–2097, nowhere near the fork | + +**The fork, localized to a call shape.** Instrumenting all three coefficient +entry points pins read 12465 to a `read_coeffs_rect` call with **w=4, h=8, +`skip_ctx`=0** at bit 6893, at mi (90,108) — a 4x8 rect unit where the oracle is +on a chroma `txb_skip` (`decodetxb.c:158`, symbol 1). Which caller and which +plane is not yet established. + +### Round 4 — the unit census: it is NOT an ordering defect + +Main's neighbour lanes both warned that a chroma-only, ordering-suspect defect +should be checked by COUNTING units first (Agent10-2's H5 was a token-order +blowup, 16x too many chroma walks). Counted on the 1016 B witness, one frame: + +| | ours | oracle | +|---|---|---| +| total coefficient unit reads | 2688 | 2395 | +| luma (square reader) | 1213 | 1309 | +| chroma (square reader) | 636 | 543 per plane, 1086 total | +| rect-unit reads (`read_coeffs_rect`) | 839 | (subsumed above) | + +The oracle's 2395 `EC_COEFF_STEP tag=all_zero` lines are per +`av1_read_coeffs_txb` call and are NOT skipped on eob=0, so the two sides are +counting the same thing. The counts are in the same range — no 16x blowup, no +missing order. **The intra-BC 4:4:4 chroma defect is not a token-order +defect**, which is what Main asked to rule out before chasing a value-level +root, and it is the second independent lane to reach that conclusion about a +4:4:4 chroma fork (Agent10-2's own 128-root turn, Agent142-2's H2/H3 census). + +There IS an asymmetry worth recording for whoever continues: we read 636 +square chroma units against the oracle's 1086, and 2052 luma reads against its +1309. The luma side is pixel-exact to sample 205264, so the luma surplus is +most likely a counting-shape difference (our var-tx leaves versus libaom's +unit walk) rather than a walk defect; it is NOT established either way, and I +am not claiming it. + +**Handed back, not landed.** The remaining 4:4:4 intra-BC defect is a **4x8 +rect coefficient unit**, present with 1:4 and rect partitions both disabled, +and it is neither of the two candidates the follow-up named. Landing a partial +is out of scope for this round, so the merge candidate is the H1 fix (exact, +gated, mutation-proven) plus the measured `own444` gate on the intra-BC 1:4 +geometry, and the chroma root goes on as a fresh task with the numbers above. + +**The fastest next measurement** (Agent142-2, from the H2 round): the per-unit +`txtype` census from the oracle's `idct.c` rung. On H2 it found the fault in +one pass — two chroma units whose `txtype` differed from what the block-level +type implied, on a frame where every luma unit was IDTX, so "luma is exact" +carried no information. This cell has exactly that asymmetry (entropy fork on +a chroma unit, luma clean), so the census decides in about a minute whether +the fork is a coefficient-read problem or a type/extent problem — the only +fork left in this cell. + +## 7. Residue handed on, not fixed here + +- **4:4:4 intra-BC chroma** — a 4x8 rect coefficient unit: read 12465, + mi (90,108), `read_coeffs_rect(w=4, h=8, skip_ctx=0)` at bit 6893; U and V + first wrong at index 20532. Per §6; both originally-named candidates + eliminated by measurement, so this needs a fresh start, not a continuation. +- **H2** and **H3** are with Agent24-2 as of this writing (Agent142-2's round + closed with the census committed); §5's retraction is the record they need. +- **H4** — 4:4:4 lossless + tile rows, hard divergence. Own lane; untouched. +- **H5** — 4:4:4 10-bit lossless 128 root, chroma band/offset term. Agent06-3. +- **H6** — 12-bit 4:4:4 needs a smoothed source. Coverage caveat, not a defect. + +**The prior, adopted from Agent142-2's round 4.** 4:4:4 chroma defects in this +decoder cluster in the **sub-8 and strip/partition unit walks, not in the +64x64 whole-block paths**. The 64x64 whole-block 4:4:4 paths are exact in every +cell closed so far; the odd-dimension 66x66 control is exact; 4:2:0 12-bit +tiles and superres are exact. Everything divergent is a 4:4:4 cell whose +chroma is split into units smaller than the block, or where a partial-frame +geometry applies. It matches what is left here — a 4x8 rect unit, not a strip +— and it reframes the earlier "it is the 1:4 reader" guess as wrong. + +The sharper frame is Agent142-2's: **a value whose scope is wrong at the point +it is consumed.** Both candidates this lane chased were that mistake, just not +at the site — one had a per-plane extent that was not at the fork at all, the +other fired 4800 msac bits away. + +## 8. Scope confirmation (Agent00-2's ablation — FIRST VERSION RETRACTED) + +**This section was published wrong and is corrected here.** The first version +of it recorded a four-arm ablation in which `4e151813` alone was EXACT 4/4 on +both of Agent00-2's cells, concluding the two fixes were independent and that +this lane's fix did not reach them. That arm never ran: the tree was reset with +`git checkout -- `, which restores from the INDEX, and the index still +held both cherry-picks — so that arm silently re-measured the both-commits +tree, and cargo saw byte-identical sources so it did not even relink. The +conclusion was a phantom. **The claim "this lane's fix does not reach those two +cells" is retracted; the opposite is true.** + +The corrected 2x2, re-run by Agent00-2 with `git reset --hard 4155c7c7` and a +verified rebuild (binary mtime printed) at every arm, on their pinned fixtures, +4/4 decode-order frames vs aomdec: + +| arm | odd444_130x122 | sr444 (256x128) | +|---|---|---| +| base | DIVERGENT f3 11521 | DIVERGENT f2 25296 + f3 51108 | +| base + rung + `4e151813` | DIVERGENT f3 11521 | DIVERGENT f2 25296 + f3 51108 — byte-identical to base | +| base + rung + `f92776ba` (this lane) | **EXACT 4/4** | **EXACT 4/4** | +| base + rung + `4e151813` + `f92776ba` | EXACT 4/4 | EXACT 4/4 | + +Three consequences, all of which enlarge this lane's scope rather than narrow +it: + +1. **Both cells are this class, and `f92776ba` alone fixes them.** `4e151813` + contributes nothing to either: the divergence counts are identical to base + with and without it, because its two `tu_reach` call sites both sit inside + `decode_rect4_16_strip`'s `if lossless_pair {` arm while both cells are + 4:4:4 LOSSY cq-20 on the `} else if skip {` path at `decode.rs:17579`. +2. **`f92776ba` does not depend on `4e151813`.** It applies and goes green on + `4155c7c7` on its own, so merge order is free and nothing else is a + prerequisite. +3. **Red-before on both cells**, with the counter left in place: mutating the + `Some(_) if ss_x(fctx) == 0 => around` arm back to the 4:2:0 pair extent + `(16, 8)` gives sr444 76404 samples with first wrong Y(192,0) — the sweep's + exact number — and odd444_130x122 9203 samples, first wrong Y(100,32) on + frame 3. + +So the 4:4:4 lossy class now has two more independent witnesses at geometries +and depths this lane's 128x96 gate does not cover (130x122, a partial-frame +right edge; 256x128, with CDEF and LR live on the last two frames). One +correction to the sweep's own matrix, from Agent00-2's report: its "4:4:4 +superres" cell turns out not to be a superres cell at all, and that one is +EXACT. + +**Method notes carried over** (still valid; the retraction was in the ablation, +not in the instrumentation): + +- The first wrong SYMBOL is invisible in the `EC_MODE` ladder because that + print carries no `bsize`. What localizes these cells is the per-superblock + decode-order pixel map of the pre-filter dump — the first wrong superblock in + decode order is the one whose above-neighbour context then forks the NEXT + block's `ref0`. On sr444 f2 that is SBcol2/SBrow0, first wrong pixel (128,48) + = mi(12,32) with the mode identical on both sides, and the `ref0` fork (LAST + vs our GOLDEN) lands on the very next block, mi(13,32). A pixel error cannot + cause a mode fork, so the same bsize/footprint error has to feed both. +- **`git checkout -- ` does not reset a tree to a commit.** It restores + from the INDEX, so any staged cherry-pick survives it and the "arm" measures + the tree you thought you had removed. A per-arm ablation needs + `git reset --hard ` and a rebuild whose binary mtime is printed, or it + measures nothing. This bit me twice in one session: here, and earlier when a + temporary trace landed in the main checkout instead of the lane worktree + because the edit tool resolved a relative path against the workspace root. + +## 9. Method notes for the next lane + +- **A route counter is not proof a fix bites.** This lane learned it the hard + way: a counter can fire identically before and after a change that changes + nothing downstream, so a non-zero count proves REACH and nothing more. Both + counters this lane added carry that warning in their own doc comment, and + the intra-BC one is deliberately armed OUTSIDE the `own444` expression so the + mutation still increments it and the red lands on the pixel/entropy arm + instead. What carries the claim is the measured fork move and the mutation + red. Rule now in skill://ec-av1-pipeline-gate-counters: a counter needs a + DIFFERS-style assertion before it can carry a claim. +- `testsrc2` is time-parameterised: any sweep recipe quoting it must pin + `rate`, or the fixture is not reproducible. `rate=1` vs `rate=25` on + 128x96 yuv444p is the difference between an 8121-byte exact stream and + the 6441-byte divergent one. +- `read_coeffs_rect`'s `EC_COEFF_STEP tag=all_zero` prints a hardcoded + `plane=0`. It has now mis-attributed a chroma read as a luma one in two + independent reports. The oracle's `EC_COEFF_STEP` prints the real plane. + Pair the two traces by the msac `post_rng` (both sides print it after the + read) rather than by line index. +- `EC_AV1_TELL ... label=block_entry` prints the msac bit position at each + `decode_inter_block` entry, and the oracle's `EC_SYMR` `pre` third field + is our bit position minus a constant 15. That pair joins the two symbol + streams to a block without any new instrumentation. +- `EC_DCDUMP` already dumps the above/left entropy contexts per plane; + `#[track_caller]` on `Neighbours::around_mi_rect` names the gather site + in one line if you ever need to attribute one again. +- **A byte compare that truncates to `min(len(ours), len(ref))` is a PREFIX + compare, and a prefix compare passes exactly when the defect is outside the + prefix.** This lane reported an H3 stream "byte-exact 6/6" that way: the + throwaway script carried the H1 fixture's 128x96 geometry, so it compared + 36864 of 98304 samples and the divergence at x >= 108 was invisible. Agent142-2 + caught it. **Every ours-vs-oracle compare must assert the two lengths are + equal before it compares anything**, must not be handed a fixture whose + geometry it does not know, and must clear BOTH sides' scratch files between + runs (mine cleared `aom.*` and not `ours.*`, a stale-file hazard sitting right + next to the truncation bug). The crate's own + `decode_all_frames_vs_oracle` does assert `got.len() != want.len()`, which is + why the committed gates in this lane were never exposed to it.