forge
Explore
Log in

Don't you dare go Hollow

4:4:4 2x2 chroma walk: window the intra-BC/palette override per unit

Browse files at this commit

69d5cc5306c7161afdc925c817094211d699e46cAhmet Kaan GümüşParent: bd8cc17
A skipped 64x64 square block at 4:4:4 has a 64x64 chroma plane block, which
libaom walks as a 2x2 grid of TX_32X32 units (get_vartx_max_txsize ->
av1_get_adjusted_tx_size(TX_64X64) = TX_32X32). Its chroma prediction is not
edge-derived: it is the intra-BC / UV-palette override, a whole
`chroma_side x chroma_height` buffer on the PALETTE_PRED slot, and
`PlaneBuf::reconstruct` uses the buffer it takes as the UNIT's own
`chroma_tx x chroma_tx_h` prediction (`let prediction = if let Some(buf) = pred
{ buf } else { ... }`). A multi-unit plane block must therefore hand each unit
its own WINDOW of it.

The pre-fix call was `set_palette_pred(ub.clone(), fctx)`: the whole buffer, for
every unit. At 4:2:0 the chroma plane block of a 64x64 block is a single 32x32
unit, so the whole buffer IS that unit's window and the bug is INVISIBLE --
which is why every 4:2:0 gate stayed green -- and at 4:4:4 every unit took the
buffer's first 32x32. The site already said so for LUMA ("its per-TU windowing
is the non-skip loop's own `palette_y_buf` slice, untested for skip and
unreachable in these streams"); the chroma half never got the same treatment and
r512.obu is the stream that makes it reachable.

MEASURED PROOF, before the fix (EC_PRED, per-unit prediction trace; identical
sums and identical row0/col0 are the signature of a copied window):

  OUR_PRED x=320 y=448 plane=1 side=32 sum=882176 row0=[241 x8] col0=[241,202,...]
  OUR_PRED x=352 y=448 plane=1 side=32 sum=882176 row0=[241 x8] col0=[241,202,...]
  OUR_PRED x=320 y=448 plane=2 side=32 sum=751936 row0=[110 x8] col0=[110,222,...]
  OUR_PRED x=352 y=448 plane=2 side=32 sum=751936 row0=[110 x8] col0=[110,222,...]

and EC_DEBUG_EDGES printed nothing for x=320/352 at y=448, i.e. edges() was
never called -- the prediction came from the override. The coded sibling at
x=448 DOES print its edges, and its units were already right.

RED-BEFORE, on the UNPATCHED tree, new gate
`a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`:

  decode-order frame 0 plane U is byte-exact nowhere -- first divergence at
  sample 229728 of 262144 (x=352, y=448), 7488 samples wrong. The seed is frame
  0, mi=(112,80) px=(320,448) side=64 skip=1, whose chroma unit cu=(1,0) at
  px=(352,448) must be the SECOND 32x32 window of the block's chroma override
  and not a copy of cu=(0,0)'s.

AFTER, same oracle (aomdec EC_AV1_FINAL_DUMP vs set_final_dump_prefix, 512x512
8-bit 4:4:4, decode order), wrong samples per plane:

  f0  Y 0 | U 7488 -> 0 | V 8128 -> 0
  f1  Y 0 | U 22571 -> 0 | V 41782 -> 0
  f2  Y 0 | U 0 | V 0

79969 -> 0: every plane of every frame byte-exact, 2359296/2359296 samples. The
floors in `a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes`
were RAISED from [[262144, 229728, 229728], [262144, 65704, 65704], [262144,
262144, 262144]] to [[262144; 3]; 3]; both floors' history is in that test's doc.
No floor was lowered. decode_intrabc_owned_rect is NOT touched.

CLASS SWEEP, all four unit positions of every multi-unit chroma-override walk on
the witness (temporary EC_ZZSRC probe, removed before this commit; win_head is
the unit window's first eight samples):

  f0 px=(320,448) skip=1 intrabc  (0,0)=241 (1,0)=202 (0,1)=241 (1,1)=202
  f0 px=(384,448) skip=1 intrabc  (0,0)=202 (1,0)=203 (0,1)=202 (1,1)=203
  f1 px=(128,128) skip=1 intrabc  (0,0)=54  (1,0)=54  (0,1)=54  (1,1)=54
  f1 px=(320,448) skip=1 intrabc  (0,0)=240 (1,0)=202 (0,1)=240 (1,1)=202
  f1 px=(448,384) skip=1 intrabc  (0,0)=166 (1,0)=166 (0,1)=166 (1,1)=166

The rule: invisible when the buffer is constant across the plane block, wrong at
exactly (1,0) and (1,1) when it varies, and (0,0)/(0,1) never wrong -- they
read offset 0, which is their own window. That is why the r2 dirty map starts at
x=352 = 320+32 and not at x=320. Every multi-unit walk on this witness is
src=intrabc; the UV-palette source shares the fixed line but has no multi-unit
witness here, and that cell of the class is argued, not measured.

f1 HYPOTHESIS CONFIRMED: r2 predicted f1's dirty column x=128..192 (first dirty
cell (168,128), 56/64 wrong) was the skipped 64x64 at px=(128,128). It is -- the
only multi-unit override walk in that column -- and frame 1 goes 22571 U + 41782
V wrong to 0 with this fix and no other change.

New counter SKIP_CHROMA_OVERRIDE_WINDOW_HITS counts chroma units whose override
had to be windowed (cn_cols * cn_rows > 1), exclusive to this walk; the gate
asserts >= 8 before it compares a single sample, so the exactness cannot be
vacuous.

Gates: 34/34 on the 4:4:4-lossless + intrabc_rect + 4:2:0-twin set (33 of r5
plus this lane's new gate). The wider `rect intrabc ibc chroma 444 420
subsampl` family is 141 passed / 0 failed / 5 ignored on this tip against
140 / 0 / 5 on the base 57834ee2, the set difference being exactly this lane's
new gate. Mutations, each reverted: M1 the pre-fix whole-buffer shape -> RED at
229728 (x=352,y=448); M2 window row stride chroma_side -> chroma_tx -> RED at
229824 (x=448,y=448); M3 cu_row/cu_col transposed -> RED at 229728.
crates/ec-av1/src/decode.rsmodified+57 -2
@@ -2710,6 +2710,15 @@ pub fn skip_split_tx_hits() -> usize {
2710 // witness this path, so a gate that wants it needs the counter.2710 // witness this path, so a gate that wants it needs the counter.
2711 thread_local! {2711 thread_local! {
2712 static SKIP_SPLIT_TX_OVERRIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2712 static SKIP_SPLIT_TX_OVERRIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2713+ /// lane-av1chromadc: chroma units of a skipped block whose intra-BC /
2714+ /// UV-palette override had to be WINDOWED to the unit's own extent --
2715+ /// i.e. `cn_cols * cn_rows > 1`, which at 4:2:0 never happens (the chroma
2716+ /// plane block is one 32x32 unit) and at 4:4:4 is every block of 64 and
2717+ /// above. Counts UNITS, not blocks. EXCLUSIVE to this walk: the other two
2718+ /// override sites (the luma slot and `decode_intrabc_owned_rect`) have
2719+ /// their own windows.
2720+ static SKIP_CHROMA_OVERRIDE_WINDOW_HITS: std::cell::Cell<usize> =
2721+ const { std::cell::Cell::new(0) };
2713 }2722 }
2714 2723
2715 /// Current value of [`SKIP_SPLIT_TX_OVERRIDE_HITS`] (blocks).2724 /// Current value of [`SKIP_SPLIT_TX_OVERRIDE_HITS`] (blocks).
@@ -2717,6 +2726,18 @@ pub fn skip_split_tx_override_hits() -> usize {
2717 SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.get())2726 SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.get())
2718 }2727 }
2719 2728
2729+/// lane-av1chromadc: [`SKIP_CHROMA_OVERRIDE_WINDOW_HITS`].
2730+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2731+pub fn skip_chroma_override_window_hits() -> usize {
2732+ SKIP_CHROMA_OVERRIDE_WINDOW_HITS.with(|c| c.get())
2733+}
2734+
2735+/// Zeroes [`SKIP_CHROMA_OVERRIDE_WINDOW_HITS`] before a gate's own decode.
2736+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2737+pub fn reset_skip_chroma_override_window_hits() {
2738+ SKIP_CHROMA_OVERRIDE_WINDOW_HITS.with(|c| c.set(0));
2739+}
2740+
2720 /// Zeroes [`SKIP_SPLIT_TX_OVERRIDE_HITS`] before a gate's own decode attempt.2741 /// Zeroes [`SKIP_SPLIT_TX_OVERRIDE_HITS`] before a gate's own decode attempt.
2721 pub fn reset_skip_split_tx_override_hits() {2742 pub fn reset_skip_split_tx_override_hits() {
2722 SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.set(0));2743 SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.set(0));
@@ -21671,8 +21692,42 @@ fn decode_block(
21671 )21692 )
21672 };21693 };
21673 let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h);21694 let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h);
21695+ // lane-av1chromadc: the chroma override is a whole
21696+ // `chroma_side x chroma_height` buffer and
21697+ // `PlaneBuf::reconstruct` uses the buffer it takes as the
21698+ // UNIT's own `chroma_tx x chroma_tx_h` prediction, so a
21699+ // multi-unit plane block must hand each unit its own window of
21700+ // it. Handing the whole buffer (the pre-fix shape) made every
21701+ // unit predict from the top-left one: at 4:2:0 the chroma plane
21702+ // block is a single 32x32 unit, so the whole buffer IS that
21703+ // unit's window and the bug is invisible -- which is why every
21704+ // 4:2:0 gate stayed green -- and at 4:4:4 a 64x64 block's 64x64
21705+ // plane block is a 2x2 grid whose right and bottom columns were
21706+ // a copy of its top-left unit.
21707+ // MEASURED on `fixtures/r512.obu` (4:4:4 8-bit 512x512, three
21708+ // frames): frame 0's skipped 64x64 intra-BC block at
21709+ // `mi=(112,80)` `px=(320,448)` reconstructed its `cu=(1,0)`
21710+ // unit at `px=(352,448)` as a flat 241 where the oracle has
21711+ // 202 -- byte-identical to its `cu=(0,0)` prediction, sum
21712+ // 882176 and all -- and the coded 64x64 to its right then read
21713+ // 202/175 against the oracle's 165/166. Gate:
21714+ // `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`.
21715+ let chroma_window = |buf: &[u16]| -> Vec<u16> {
21716+ if cn_cols == 1 && cn_rows == 1 {
21717+ return buf.to_vec();
21718+ }
21719+ let mut window = Vec::with_capacity(chroma_tx * chroma_tx_h);
21720+ for row in 0..chroma_tx_h {
21721+ let at = (cu_row * chroma_tx_h + row) * chroma_side + cu_col * chroma_tx;
21722+ window.extend_from_slice(&buf[at..at + chroma_tx]);
21723+ }
21724+ window
21725+ };
21674 if let Some((ub, _)) = &palette_uv_bufs {21726 if let Some((ub, _)) = &palette_uv_bufs {
21675- set_palette_pred(ub.clone(), fctx);21727+ if cn_cols * cn_rows > 1 {
21728+ hit!(SKIP_CHROMA_OVERRIDE_WINDOW_HITS);
21729+ }
21730+ set_palette_pred(chroma_window(ub), fctx);
21676 }21731 }
21677 push_intra_unit(21732 push_intra_unit(
21678 1,21733 1,
@@ -21690,7 +21745,7 @@ fn decode_block(
21690 fctx,21745 fctx,
21691 );21746 );
21692 if let Some((_, vb)) = &palette_uv_bufs {21747 if let Some((_, vb)) = &palette_uv_bufs {
21693- set_palette_pred(vb.clone(), fctx);21748+ set_palette_pred(chroma_window(vb), fctx);
21694 }21749 }
21695 push_intra_unit(21750 push_intra_unit(
21696 2,21751 2,
crates/ec-av1/src/stream.rsmodified+142 -19
@@ -157,6 +157,20 @@ pub fn reset_ibc_owned_rect_chroma_footprint_444_hits() {
157 crate::decode::reset_ibc_owned_rect_chroma_footprint_444_hits()157 crate::decode::reset_ibc_owned_rect_chroma_footprint_444_hits()
158 }158 }
159 159
160+/// lane-av1chromadc: chroma units of a skipped block whose intra-BC / UV
161+/// palette override had to be windowed to the unit's own extent -- `cn_cols *
162+/// cn_rows > 1`, which at 4:2:0 never happens and at 4:4:4 is every block of
163+/// 64 and above. Counts UNITS. EXCLUSIVE to `decode_block`'s skipped square
164+/// block chroma walk.
165+pub fn skip_chroma_override_window_hits() -> usize {
166+ crate::decode::skip_chroma_override_window_hits()
167+}
168+
169+/// Gate-side reset for the lane-av1chromadc counter above.
170+pub fn reset_skip_chroma_override_window_hits() {
171+ crate::decode::reset_skip_chroma_override_window_hits()
172+}
173+
160 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900174 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900
161 /// r22) -- the counter a screen-content witness gate reads to prove it175 /// r22) -- the counter a screen-content witness gate reads to prove it
162 /// exercises the inter-frame palette path, not the key frame's.176 /// exercises the inter-frame palette path, not the key frame's.
@@ -49182,19 +49196,21 @@ pub(crate) mod tests {
49182 /// was deleted: `rect_inter_chroma_set` still refuses (32, 64) and the49196 /// was deleted: `rect_inter_chroma_set` still refuses (32, 64) and the
49183 /// string is still in the source, it is just not on this path any more.49197 /// string is still in the source, it is just not on this path any more.
49184 ///49198 ///
49185- /// The assertion is a per-(frame, plane) EXACT PREFIX against the49199+ /// The floors were RAISED to full byte-exactness on all three planes of
49186- /// instrumented aomdec, the same shape as the sibling49200+ /// all three frames by lane-av1chromadc, which closed the "open chroma
49187- /// `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`. The49201+ /// fork" this gate used to carry: a skipped 64x64 square block at 4:4:4
49188- /// floors are MEASURED, and each one only grows:49202+ /// has a 64x64 chroma plane block, libaom walks it as a 2x2 grid of
49189- ///49203+ /// `TX_32X32` units, and the intra-BC chroma override was handed to every
49190- /// * luma is byte-exact on ALL THREE frames (786432/786432 samples).49204+ /// unit whole instead of windowed per unit (see
49191- /// Before the fix frame 0 luma was 166229 samples wrong from 65728 --49205+ /// `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`
49192- /// the halving's chroma misread desynced the tile.49206+ /// and lanes/av1chromadc.report.md). The history of these floors:
49193- /// * frame 2 is byte-exact on all three planes. Before the fix it was49207+ ///
49194- /// 9216 U + 8192 V wrong.49208+ /// * lane-av1chromarect, after the ss-derived extent and the multi-unit
49195- /// * frames 0 and 1 carry an OPEN chroma fork at a DIFFERENT site (see49209+ /// walk: `[[262144, 229728, 229728], [262144, 65704, 65704],
49196- /// lanes/av1chromarect.report.md); the floors below are the exact49210+ /// [262144, 262144, 262144]]` -- luma exact on all three frames, frame 2
49197- /// prefixes, not a claim that the tail is right.49211+ /// exact on all three planes, 79969 chroma samples still wrong.
49212+ /// * lane-av1chromadc: `[[262144; 3]; 3]` -- every plane of every frame
49213+ /// byte-exact against aomdec. Floors only ever grow.
49198 #[test]49214 #[test]
49199 fn a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes() {49215 fn a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes() {
49200 const NAME: &str =49216 const NAME: &str =
@@ -49203,12 +49219,9 @@ pub(crate) mod tests {
49203 const LEN: usize = 6948;49219 const LEN: usize = 6948;
49204 /// 512x512 8-bit 4:4:4, one plane.49220 /// 512x512 8-bit 4:4:4, one plane.
49205 const PLANE: usize = 512 * 512;49221 const PLANE: usize = 512 * 512;
49206- /// First differing sample per (frame, plane), decode order.49222+ /// Exact prefix per (frame, plane), decode order. FULL: every plane of
49207- const EXACT_PREFIX: [[usize; 3]; 3] = [49223+ /// every frame is byte-exact against the oracle.
49208- [PLANE, 229728, 229728],49224+ const EXACT_PREFIX: [[usize; 3]; 3] = [[PLANE; 3]; 3];
49209- [PLANE, 65704, 65704],
49210- [PLANE, PLANE, PLANE],
49211- ];
49212 let path =49225 let path =
49213 std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}"));49226 std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}"));
49214 let stream = std::fs::read(&path)49227 let stream = std::fs::read(&path)
@@ -49298,4 +49311,114 @@ pub(crate) mod tests {
49298 }49311 }
49299 let _ = std::fs::remove_dir_all(&dir);49312 let _ = std::fs::remove_dir_all(&dir);
49300 }49313 }
49314+
49315+ /// lane-av1chromadc: a SKIPPED 64x64 square block at 4:4:4 has a 64x64
49316+ /// chroma plane block, which libaom walks as a 2x2 grid of `TX_32X32` units
49317+ /// (`get_vartx_max_txsize`: `av1_get_adjusted_tx_size(TX_64X64) =
49318+ /// TX_32X32`). The intra-BC / UV-palette chroma override
49319+ /// ([`decode_block`]'s `intrabc_bufs` / `palette_uv_bufs`, the
49320+ /// `PALETTE_PRED` slot) is a whole-`chroma_side x chroma_height` buffer and
49321+ /// must be WINDOWED per unit: `PlaneBuf::reconstruct` uses the buffer it
49322+ /// takes as the unit's own `side x side` prediction. At 4:2:0 the chroma
49323+ /// plane block is one 32x32 unit, so the whole buffer IS that unit's
49324+ /// window and the bug is invisible -- which is why it survived every 4:2:0
49325+ /// gate. At 4:4:4 every unit was handed the buffer's FIRST 32x32, so the
49326+ /// block's right and bottom chroma columns were a copy of its top-left
49327+ /// unit.
49328+ ///
49329+ /// The witness: `fixtures/r512.obu`, 4:4:4 8-bit 512x512, three frames. The
49330+ /// seed is frame 0, `mi=(112,80)`, `px=(320,448)`, `side=64`, `skip=1`,
49331+ /// `mode=0`, `uv_mode=0` -- a skipped intra-BC block at the frame's bottom
49332+ /// edge. Its chroma unit `cu=(1,0)` at `px=(352,448)` reconstructs a flat
49333+ /// 241 (U) / 110 (V) where the oracle has 202 / 222, because it read the
49334+ /// same override window as `cu=(0,0)`.
49335+ ///
49336+ /// This gate asserts FULL frame exactness on all three planes of all three
49337+ /// frames. It is the red-before: on the unpatched tree it fails at
49338+ /// `(352,448)` of frame 0, which is the seed's second chroma unit.
49339+ #[test]
49340+ fn a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit() {
49341+ const NAME: &str = "a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit";
49342+ const FILE: &str = "r512.obu";
49343+ const LEN: usize = 6948;
49344+ const PLANE: usize = 512 * 512;
49345+ let path =
49346+ std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}"));
49347+ let stream = std::fs::read(&path)
49348+ .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}"));
49349+ assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved");
49350+ assert_444_header(&stream, NAME, 8);
49351+
49352+ let _guard = lock_gate_counters();
49353+ reset_skip_chroma_override_window_hits();
49354+ let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id()));
49355+ let _ = std::fs::remove_dir_all(&dir);
49356+ std::fs::create_dir_all(&dir).expect("scratch dir");
49357+ let obu = dir.join("in.obu");
49358+ std::fs::write(&obu, &stream).expect("writing the stream");
49359+ let aom_prefix = dir.join("aom");
49360+ let out = Command::new(aomdec_path())
49361+ .args(["--codec=av1", "-o"])
49362+ .arg(dir.join("out.y4m"))
49363+ .arg(&obu)
49364+ .env("EC_AV1_FINAL_DUMP", &aom_prefix)
49365+ .stdin(Stdio::null())
49366+ .stdout(Stdio::piped())
49367+ .stderr(Stdio::piped())
49368+ .output()
49369+ .expect("aomdec failed to run");
49370+ assert!(
49371+ out.status.success(),
49372+ "{NAME}: the oracle aomdec refused the stream: {}",
49373+ String::from_utf8_lossy(&out.stderr)
49374+ );
49375+ let ours_prefix = dir.join("ours");
49376+ set_final_dump_prefix(Some(ours_prefix.display().to_string()));
49377+ if let Err(e) = decode_stream(&stream) {
49378+ panic!("{NAME}: this decoder refused the witness: {e}");
49379+ }
49380+ set_final_dump_prefix(None);
49381+ // Non-vacuity: the windowed arm must have run, or the exactness below
49382+ // is measuring a witness that never reached the 2x2 chroma walk.
49383+ let windows = skip_chroma_override_window_hits();
49384+ assert!(
49385+ windows >= 8,
49386+ "{NAME}: {windows} windowed chroma override unit(s) on this witness, expected at \
49387+ least 8 (two skipped 64x64 intra-BC blocks x 2x2 units x 2 planes) -- the witness \
49388+ stopped exercising the arm, so the exactness below is vacuous"
49389+ );
49390+ for f in 0..3 {
49391+ let aom_dump = std::fs::read(format!("{}.f{f}", aom_prefix.display()))
49392+ .unwrap_or_else(|e| panic!("{NAME}: oracle dump f{f} missing: {e}"));
49393+ let our_dump = std::fs::read(format!("{}.f{f}", ours_prefix.display()))
49394+ .unwrap_or_else(|e| panic!("{NAME}: our dump f{f} missing: {e}"));
49395+ assert_eq!(
49396+ our_dump.len(),
49397+ 3 * PLANE,
49398+ "{NAME}: frame {f} is not 8-bit 4:4:4 512x512"
49399+ );
49400+ for (plane, name) in [(0usize, "Y"), (1, "U"), (2, "V")] {
49401+ let at = plane * PLANE;
49402+ if our_dump[at..at + PLANE] == aom_dump[at..at + PLANE] {
49403+ continue;
49404+ }
49405+ let first = (0..PLANE)
49406+ .find(|&s| our_dump[at + s] != aom_dump[at + s])
49407+ .unwrap_or(PLANE);
49408+ let wrong = (0..PLANE)
49409+ .filter(|&s| our_dump[at + s] != aom_dump[at + s])
49410+ .count();
49411+ panic!(
49412+ "{NAME}: decode-order frame {f} plane {name} is byte-exact nowhere -- first \
49413+ divergence at sample {first} of {PLANE} (x={}, y={}), {wrong} samples \
49414+ wrong. The seed is frame 0, mi=(112,80) px=(320,448) side=64 skip=1, whose \
49415+ chroma unit cu=(1,0) at px=(352,448) must be the SECOND 32x32 window of \
49416+ the block's chroma override and not a copy of cu=(0,0)'s.",
49417+ first % 512,
49418+ first / 512
49419+ );
49420+ }
49421+ }
49422+ let _ = std::fs::remove_dir_all(&dir);
49423+ }
49301 }49424 }
lanes/av1chromadc.report.mdadded+205 -0
@@ -0,0 +1,205 @@
1+# lane-av1chromadc — the 4:4:4 2x2 chroma override window (79969 → 0)
2+
3+Worktree `~/.cache/wt/av1chromadc`, branch `lane-av1chromadc`, base `57834ee2`
4+("Merge lane-av1chromarect-r2"). All edits absolute-pathed inside this worktree;
5+`git -C ~/Documents/Code/Rust/edith_codecs status --porcelain` printed nothing
6+after every edit batch.
7+
8+Fixes the residual `lanes/av1chromarect-r2.report.md` narrowed, in
9+`decode_block`'s SQUARE path, and closes the witness to **full byte-exactness on
10+every plane of every frame**. `decode_intrabc_owned_rect` (the strip arm) is not
11+touched.
12+
13+## 1. Red-before, on the UNPATCHED tree
14+
15+Gate `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`
16+(`crates/ec-av1/src/stream.rs`), added first, asserting full frame exactness on
17+`fixtures/r512.obu` against the instrumented aomdec:
18+
19+ $ EC_AV1_REQUIRE_AOMDEC=1 cargo test -p ec-av1 --lib a_444_skipped_64x64 -- --nocapture
20+ thread 'stream::tests::a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit' panicked:
21+ a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit: decode-order frame 0
22+ plane U is byte-exact nowhere -- first divergence at sample 229728 of 262144 (x=352, y=448),
23+ 7488 samples wrong. The seed is frame 0, mi=(112,80) px=(320,448) side=64 skip=1, whose
24+ chroma unit cu=(1,0) at px=(352,448) must be the SECOND 32x32 window of the block's chroma
25+ override and not a copy of cu=(0,0)'s.
26+ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 768 filtered out
27+
28+That is the unpatched decode diverging at the seed's exact sample, not a mutation
29+red. The 79969 total from r2 is the same measurement: 7488 + 8128 on frame 0,
30+22571 + 41782 on frame 1, 0 on frame 2.
31+
32+## 2. The defect
33+
34+A skipped 64x64 square block at 4:4:4 has a **64x64 chroma plane block**, which
35+libaom walks as a 2x2 grid of `TX_32X32` units (`get_vartx_max_txsize` →
36+`av1_get_adjusted_tx_size(TX_64X64) = TX_32X32`, decodeframe.c:994-1004).
37+
38+Its chroma prediction is not edge-derived: it is the intra-BC / UV-palette
39+**override**, a whole-`chroma_side x chroma_height` buffer carried on the
40+`PALETTE_PRED` slot (`decode_block`'s `intrabc_bufs` / `palette_uv_bufs` →
41+`set_palette_pred` → `PlaneBuf::reconstruct`'s `pred`). `reconstruct` uses the
42+buffer it takes as the **unit's own** `chroma_tx x chroma_tx_h` prediction --
43+`let prediction = if let Some(buf) = pred { buf } else { … }` -- so a multi-unit
44+plane block must hand each unit its own WINDOW of that buffer.
45+
46+The pre-fix call was `set_palette_pred(ub.clone(), fctx)`: the whole buffer, for
47+every unit. At 4:2:0 the chroma plane block of a 64x64 block is a single 32x32
48+unit, so the whole buffer IS that unit's window and the bug is **invisible** --
49+which is why every 4:2:0 gate stayed green. At 4:4:4 every unit took the buffer's
50+first 32x32.
51+
52+The code already said so, at the site, for LUMA: *"its per-TU windowing is the
53+non-skip loop's own `palette_y_buf` slice, untested for skip and unreachable in
54+these streams"*, and `lane-svt1` had armed the whole-block luma buffer on the
55+skip arm for a related reason. The chroma half never got the same treatment, and
56+`r512.obu` is the stream that makes it reachable.
57+
58+**Measured proof, before the fix** (`EC_PRED`, the per-unit prediction trace;
59+identical sums and identical `row0`/`col0` are the signature of a copied window):
60+
61+ OUR_PRED x=320 y=448 plane=1 side=32 mode=0 sum=882176 row0=[241,241,241,241,241,241,241,241] col0=[241,202,241,202,241,202,241,202]
62+ OUR_PRED x=352 y=448 plane=1 side=32 mode=0 sum=882176 row0=[241,241,241,241,241,241,241,241] col0=[241,202,241,202,241,202,241,202]
63+ OUR_PRED x=320 y=448 plane=2 side=32 mode=0 sum=751936 row0=[110,110,110,110,110,110,110,110] col0=[110,222,110,222,110,222,110,222]
64+ OUR_PRED x=352 y=448 plane=2 side=32 mode=0 sum=751936 row0=[110,110,110,110,110,110,110,110] col0=[110,222,110,222,110,222,110,222]
65+
66+and `EC_DEBUG_EDGES` printed **nothing** for x=320/352 at y=448, i.e. `edges()`
67+was never called -- the prediction came from the override, not from the edges.
68+(`EDGES_SQ` DOES print for the coded sibling at x=448, whose units therefore went
69+through the per-unit DC path and were already right.)
70+
71+## 3. The fix
72+
73+`decode_block`'s skip-arm chroma unit loop, both planes: one `chroma_window`
74+closure that returns the buffer whole when the plane block is a single unit and
75+otherwise slices rows `cu_row*chroma_tx_h .. +chroma_tx_h` × cols
76+`cu_col*chroma_tx .. +chroma_tx` at the buffer's own `chroma_side` stride.
77+
78+Nothing else changes: the single-unit case (every 4:2:0 shape, every 4:4:4 shape
79+below 64) takes the identical path it took before, and the strip arm is
80+untouched.
81+
82+## 4. Result
83+
84+ $ EC_AV1_REQUIRE_AOMDEC=1 cargo test -p ec-av1 --lib -- a_444_intrabc_owned_rect a_444_skipped_64x64
85+ test stream::tests::a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit ... ok
86+ test stream::tests::a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes ... ok
87+ test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 767 filtered out
88+
89+Per (frame, plane), wrong samples, before → after:
90+
91+| frame | Y | U | V |
92+| --- | --- | --- | --- |
93+| 0 | 0 → 0 | 7488 → **0** | 8128 → **0** |
94+| 1 | 0 → 0 | 22571 → **0** | 41782 → **0** |
95+| 2 | 0 → 0 | 0 → 0 | 0 → 0 |
96+
97+**79969 → 0.** Every plane of every frame is byte-exact against the aomdec
98+oracle, 2359296/2359296 samples. The floors in
99+`a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes` were
100+RAISED from `[[262144, 229728, 229728], [262144, 65704, 65704], [262144, 262144,
101+262144]]` to `[[262144; 3]; 3]`; both floors' history is recorded in the test's
102+doc comment. No floor was lowered.
103+
104+## 5. Class sweep — all four unit positions, and which were already right
105+
106+Every multi-unit chroma-override walk on the witness, with the window head the fix
107+now hands each unit (temporary `EC_ZZSRC` probe, removed before the commit;
108+`win_head` = the unit window's first eight samples):
109+
110+| frame | block | skip | source | cu(0,0) | cu(1,0) | cu(0,1) | cu(1,1) | pre-fix state |
111+| --- | --- | --- | --- | --- | --- | --- | --- | --- |
112+| 0 | px=(320,448) side=64 | true | intrabc | 241 | 202 | 241 | 202 | **(1,0) and (1,1) WRONG** (both got 241) |
113+| 0 | px=(384,448) side=64 | true | intrabc | 202 | 203 | 202 | 203 | all four right -- the buffer is flat, so the copy was indistinguishable |
114+| 1 | px=(128,128) side=64 | true | intrabc | 54 | 54 | 54 | 54 | (1,0)/(1,1) wrong further into the window -- see §6 |
115+| 1 | px=(320,448) side=64 | true | intrabc | 240 | 202 | 240 | 202 | **(1,0) and (1,1) WRONG** |
116+| 1 | px=(448,384) side=64 | true | intrabc | 166 | 166 | 166 | 166 | all four right -- flat buffer |
117+
118+The rule the sweep establishes: the bug is invisible when the override buffer is
119+constant across the plane block (rows 2 and 5 above, and both `cu_col == 0`
120+positions always), and wrong at exactly the `(1,0)` and `(1,1)` positions
121+whenever the buffer varies. `(0,0)` and `(0,1)` were never wrong -- they read
122+offset 0, which is their own window. That is why the dirty map in r2 §1 starts at
123+x=352 = 320 + 32 and not at x=320.
124+
125+**Both edge families:** the intra-BC and UV-palette sources share one line
126+(`palette_uv_bufs` is `intrabc_bufs`' chroma half when intrabc is present, else
127+the palette map), so the fix is structurally shared. MEASURED, though: every
128+multi-unit walk on this witness is `src=intrabc`; the UV-palette source never
129+reaches a multi-unit chroma walk here, so its arm of the sweep is argued from
130+the shared code path, not witnessed. That is the one cell of the class this lane
131+does not have a measurement for.
132+
133+Non-vacuity: new counter `SKIP_CHROMA_OVERRIDE_WINDOW_HITS` counts chroma units
134+whose override had to be windowed (`cn_cols * cn_rows > 1`), exclusive to this
135+walk. The gate asserts `>= 8` (two skipped 64x64 intra-BC blocks × 2×2 units × 2
136+planes) before it compares a single sample, so the exactness cannot be vacuous.
137+
138+## 6. The f1 hypothesis: CONFIRMED
139+
140+r2 §5 predicted f1's dirty column `x=128..192` (first dirty cell `(168,128)`,
141+56 of 64 samples wrong) was the skipped 64x64 at `px=(128,128)`. It is. That is
142+the only multi-unit override walk in that column, it is `skip=1 side=64 src=intrabc`,
143+and frame 1 goes from 22571 U + 41782 V wrong to **0** with this fix and no other
144+change. Its four windows' first eight samples are all `54`, so the difference is
145+further into the unit window than the head I printed — the block is flat near its
146+top-left and not flat at `(168,128)`, which is exactly the invisible-until-it-isn't
147+shape the sweep above describes.
148+
149+## 7. Gates
150+
151+`cargo check -p ec-av1 --all-targets` clean (0 errors, 0 warnings) before every
152+run, on a private `CARGO_TARGET_DIR`; a green gate next to a build error would
153+have been a stale binary.
154+
155+ $ EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 \
156+ cargo test -p ec-av1 --lib -- a_444 lossless_444 intrabc_rect 444_lossless -- --nocapture
157+ test result: ok. 34 passed; 0 failed; 0 ignored; 0 measured; 735 filtered out
158+
159+34 = the 33 of lane-av1chromarect's r5 quote plus this lane's new gate. The set
160+carries the 4:4:4-lossless family (`a_lossless_444_*`,
161+`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units`,
162+`a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`), the intrabc_rect
163+family, and the 4:2:0 identity arm
164+(`a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, whose
165+`420_intrabc_rect4_witness.obu` twin goes through `decode_all_frames_vs_oracle`).
166+
167+One filtered run per tree, same filter string, same env, private
168+`CARGO_TARGET_DIR` each:
169+
170+ $ EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \
171+ -- rect intrabc ibc chroma 444 420 subsampl -- --nocapture
172+
173+| tree | result |
174+| --- | --- |
175+| base `57834ee2` (`~/.cache/wt/av1chromadc-base`, detached) | `ok. 140 passed; 0 failed; 5 ignored; 0 measured; 623 filtered out; finished in 284.66s` |
176+| tip `lane-av1chromadc` | `ok. 141 passed; 0 failed; 5 ignored; 0 measured; 623 filtered out; finished in 288.94s` |
177+
178+The set difference of the two passing-test lists is exactly this lane's new
179+gate and nothing else:
180+
181+```
182+> test stream::tests::a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit
183+```
184+
185+The same 5 tests are `#[ignore]`d in both trees.
186+
187+### Mutation proofs, each reverted
188+
189+| # | mutation | result |
190+| --- | --- | --- |
191+| M1 | `chroma_window` returns the whole buffer unconditionally (the pre-fix shape) | **RED** — `frame 0 plane U … first divergence at sample 229728 (x=352, y=448), 7488 samples wrong` |
192+| M2 | the window's row stride `chroma_side` → `chroma_tx` | **RED** — `frame 0 plane U … first divergence at sample 229824 (x=448, y=448), 7488 samples wrong` |
193+| M3 | `cu_row`/`cu_col` transposed in the window offset | **RED** — `frame 0 plane U … first divergence at sample 229728 (x=352, y=448), 7488 samples wrong` |
194+
195+## 8. Not done
196+
197+1. The UV-palette arm of the class sweep has no witness here (§5). It shares the
198+ fixed line, but a 4:4:4 `--enable-palette=1` stream with a skipped block of 64
199+ and above would be the measurement, and I did not encode one.
200+2. `decode_intrabc_rect` (decode.rs:13646) and the other rect paths read their
201+ chroma through `read_inter_rect_chroma` / the intrabc split walk, which
202+ already window per unit; I did not re-verify each of them against a
203+ multi-unit override, only that the wide family is unchanged.
204+3. No heavy encodes: the witness came from the pin and the gate families are
205+ fixture-driven. No server fleet run was requested or consumed.