forge
Explore
Log in

Don't you dare go Hollow

Cherry-pick lane-tiny 9b1297a (chroma tx size in the deblocker) + lane-sub8 r4 report

Browse files at this commit

a3613e4e77c0a7437ee361e003192a4f24b3c494Ahmet Kaan GümüşParent: c24ba5d
  • fix
    • cherry-pick lane-tiny 9b1297a (chroma tx size in the deblocker) + lane-sub8 r4 report
Show full message
fix(av1): cherry-pick lane-tiny 9b1297a (chroma tx size in the deblocker) + lane-sub8 r4 report

Round 4 disproved the lane's own premise: instrumented aomdec shows the gate's
streams contain only PARTITION_NONE/SPLIT, so every rect/AB refusal rounds 2-3
attributed to the encoder was our own desync. With the mi-exact mode
neighbours and has_tr_4x4/has_bl_4x4 in place the symbol ladder is exact
(324/324, 318/318) and luma is bit-exact; 4 chroma pixels remain.
crates/ec-av1/examples/decode_probe.rsmodified+16 -1
@@ -32,7 +32,22 @@ fn main() {
3232 Ok(frames) if frames.is_empty() => {
3333 println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
3434 }
35- Ok(frames) => println!("OK: {} frames decoded", frames.len()),
35+ Ok(frames) => {
36+ println!("OK: {} frames decoded", frames.len());
37+ // Optional second arg: dump the decoded planes as raw yuv420p so a
38+ // pixel diff against `ffmpeg -i s.obu -f rawvideo` needs no test harness.
39+ if let Some(out) = std::env::args().nth(2) {
40+ // 8-bit only: planes are u16, take the low byte.
41+ let mut buf: Vec<u8> = Vec::new();
42+ for f in &frames {
43+ for p in [&f.y, &f.u, &f.v] {
44+ buf.extend(p.iter().map(|&s| s as u8));
45+ }
46+ }
47+ std::fs::write(&out, &buf).expect("writing raw planes");
48+ println!("wrote {} bytes of yuv420p to {out}", buf.len());
49+ }
50+ }
3651 Err(e) => println!("REFUSED: {e}"),
3752 }
3853 }
crates/ec-av1/src/decode.rsmodified+51 -12
@@ -1851,6 +1851,16 @@ struct Neighbours {
18511851 /// lane-rect r2: TX_32X16/TX_16X32 strips deblock their horizontal
18521852 /// edges by tx height (spec 7.14.2 `set_lpf_parameters` dir==VERT).
18531853 tx_h_grid: Vec<u8>,
1854+ /// Per-4x4-mi CHROMA transform width/height in pixels -- lane-tiny r4.
1855+ /// A block's chroma transform is `av1_get_max_uv_txsize(bsize)`: the
1856+ /// largest transform covering the subsampled BLOCK, capped at 32x32. It
1857+ /// does NOT follow luma's `tx_depth` split, so deriving it as
1858+ /// `tx_grid / 2` invented chroma transform edges the deblocker then
1859+ /// filtered (32x16 frames, U plane, seeds 42/47). Written from the
1860+ /// block's own mi span in [`Self::fill_lf_grid_rect`], the one place
1861+ /// every caller routes through.
1862+ uv_tx_grid: Vec<u8>,
1863+ uv_tx_h_grid: Vec<u8>,
18541864 /// Per-4x4-mi reference frame (`0` = intra, magnitude `1..=7` =
18551865 /// `MV_REFERENCE_FRAME`, negative = that reference coded as `GLOBALMV` --
18561866 /// `lf_level`'s `mode_lf_lut` row 0, lane-av1golden2)
@@ -1932,6 +1942,8 @@ impl Neighbours {
19321942 skip_grid_cols_mi: cols * (SUB / MI),
19331943 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
19341944 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
1945+ uv_tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
1946+ uv_tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
19351947 ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)],
19361948 delta_lf_grid: vec![[0i8; 4]; cols * (SUB / MI) * rows * (SUB / MI)],
19371949 above_palette_size: vec![0; cols],
@@ -2135,6 +2147,11 @@ impl Neighbours {
21352147 ref_frame: i8,
21362148 ) {
21372149 let (mi_r, mi_c) = at_mi;
2150+ // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is
2151+ // half its luma one (min 4 px, the smallest transform), capped at
2152+ // TX_32X32 -- independent of this block's luma `tx_depth`.
2153+ let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;
2154+ let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;
21382155 let cur = CURRENT_DELTA_LF.with(|c| c.get());
21392156 let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) {
21402157 std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8)
@@ -2150,6 +2167,12 @@ impl Neighbours {
21502167 if let Some(cell) = self.tx_h_grid.get_mut(idx) {
21512168 *cell = tx_h_px;
21522169 }
2170+ if let Some(cell) = self.uv_tx_grid.get_mut(idx) {
2171+ *cell = uv_tx_w;
2172+ }
2173+ if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) {
2174+ *cell = uv_tx_h;
2175+ }
21532176 if let Some(cell) = self.ref_grid.get_mut(idx) {
21542177 *cell = ref_frame;
21552178 }
@@ -4397,6 +4420,20 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
43974420 /// [`crate::encode`]'s private `Plane`, whose `edges` this mirrors exactly
43984421 /// (own-edge and reach clamps both), passing what it gathers straight to
43994422 /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
4423+/// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written
4424+/// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`.
4425+fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
4426+ use std::io::Write;
4427+ if let Ok(path) = std::env::var(var)
4428+ && let Ok(mut f) = std::fs::File::create(format!("{path}.f0"))
4429+ {
4430+ for p in [y, u, v] {
4431+ let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect();
4432+ let _ = f.write_all(&narrow);
4433+ }
4434+ }
4435+}
4436+
44004437 #[derive(Clone)]
44014438 struct PlaneBuf {
44024439 data: Vec<u16>,
@@ -6026,24 +6063,16 @@ fn plane_to_mi(chroma: bool, coord: usize) -> usize {
60266063 /// half its coded block's luma transform, spec's `av1_get_max_uv_txsize`
60276064 /// under 4:2:0 and a block that never splits its own transform).
60286065 fn tx_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 {
6029- let luma_tx = n
6030- .tx_grid
6031- .get(mi_r * n.skip_grid_cols_mi + mi_c)
6032- .copied()
6033- .unwrap_or(0) as u32;
6034- if chroma { luma_tx / 2 } else { luma_tx }
6066+ let grid = if chroma { &n.uv_tx_grid } else { &n.tx_grid };
6067+ grid.get(mi_r * n.skip_grid_cols_mi + mi_c).copied().unwrap_or(0) as u32
60356068 }
60366069
60376070 /// [`tx_px_at`]'s HEIGHT twin (lane-rect r2): the deblocker's horizontal
60386071 /// edges step and gate by transform height, which differs from width only
60396072 /// on rect partition strips.
60406073 fn tx_h_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 {
6041- let luma_tx = n
6042- .tx_h_grid
6043- .get(mi_r * n.skip_grid_cols_mi + mi_c)
6044- .copied()
6045- .unwrap_or(0) as u32;
6046- if chroma { luma_tx / 2 } else { luma_tx }
6074+ let grid = if chroma { &n.uv_tx_h_grid } else { &n.tx_h_grid };
6075+ grid.get(mi_r * n.skip_grid_cols_mi + mi_c).copied().unwrap_or(0) as u32
60476076 }
60486077
60496078 /// `get_tx_size_context` (spec 9.3's `TxDepthCtx`, libaom
@@ -7850,7 +7879,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
78507879 frame_height as usize,
78517880 );
78527881 let (deblocked_y, deblocked_u, deblocked_v) = (y.clone(), u.clone(), v.clone());
7882+ // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own
7883+ // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
7884+ // dump above these bisect WHICH filter stage introduced a mismatch.
7885+ dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
78537886 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
7887+ dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
78547888 apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);
78557889
78567890 let (fw, fh) = (frame_width as usize, frame_height as usize);
@@ -13745,7 +13779,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1374513779 frame_height as usize,
1374613780 );
1374713781 let (deblocked_y, deblocked_u, deblocked_v) = (y.clone(), u.clone(), v.clone());
13782+ // lane-tiny r4: post-deblock / post-CDEF dumps mirroring aomdec's own
13783+ // EC_AV1_POSTDEBLOCK_DUMP (decodeframe.c ~5404) -- with the pre-filter
13784+ // dump above these bisect WHICH filter stage introduced a mismatch.
13785+ dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v);
1374813786 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
13787+ dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v);
1374913788 apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid);
1375013789
1375113790 let motion_field = build_motion_field(
crates/ec-av1/src/stream.rsmodified+50 -11
@@ -6361,20 +6361,23 @@ mod tests {
63616361 crate::decode::cdef_idx_hits()
63626362 );
63636363 }
6364- /// lane-tiny r1 diagnostic (not a gate): sweeps tiny key-frame sizes
6365- /// against real aomenc + ffmpeg to find the exact size boundary of the
6366- /// silent-wrong-pixels defect the sub8 lane's r2 dead-end flagged (a
6367- /// plain 16x16 stream, no exotic tools). `#[ignore]`d -- prints a
6368- /// pass/fail table, asserts nothing; run manually with `--nocapture`.
6364+ /// lane-tiny r4 GATE (was r1's `#[ignore]`d probe): every tiny key-frame
6365+ /// size real aomenc will encode, decoded pixel-exact against ffmpeg.
6366+ /// Tiny frames are where every edge/partial-superblock corner case is
6367+ /// forced, and this sweep is what found both r3's filter-intra tx_type
6368+ /// CDF row and r4's chroma-transform-size deblock defect -- so it
6369+ /// hard-asserts now: a decode error, a refusal, or one differing sample
6370+ /// at any size/seed fails. Only a genuinely absent oracle skips, and
6371+ /// `EC_AV1_REQUIRE_AOMENC=1` turns that into a failure too.
63696372 #[test]
6370- #[ignore = "diagnostic sweep, run manually with --nocapture"]
6371- fn probe_tiny_frame_size_boundary() {
6373+ fn a_real_aomenc_tiny_frame_size_sweep_decodes_pixel_exact() {
63726374 if !have_ffmpeg() || !have_aomenc() {
63736375 eprintln!("SKIP: no ffmpeg/aomenc");
63746376 return;
63756377 }
63766378 let sizes: &[(usize, usize)] =
63776379 &[(8, 8), (16, 16), (32, 32), (16, 32), (32, 16), (64, 64), (48, 48), (24, 24)];
6380+ let mut total_exact = 0u32;
63786381 for &(width, height) in sizes {
63796382 let mut ok = 0u32;
63806383 let mut bad = 0u32;
@@ -6423,7 +6426,18 @@ mod tests {
64236426 let stream = out.stdout;
64246427 let frames = match decode_stream(&stream) {
64256428 Err(e) => {
6426- eprintln!(" {width}x{height} seed {seed}: REFUSED {e}");
6429+ // A NAMED refusal is the only non-exact outcome this
6430+ // gate tolerates (8x8 still needs a rectangular
6431+ // transform); anything else is a hard failure, and
6432+ // the floor assert below keeps that from going
6433+ // vacuous.
6434+ let msg = e.to_string();
6435+ assert!(
6436+ msg.contains("unsupported"),
6437+ "{width}x{height} seed {seed}: failed outright, not a named \
6438+ refusal: {msg}"
6439+ );
6440+ eprintln!(" {width}x{height} seed {seed}: REFUSED {msg}");
64276441 refused += 1;
64286442 continue;
64296443 }
@@ -6438,6 +6452,12 @@ mod tests {
64386452 ok += 1;
64396453 } else {
64406454 bad += 1;
6455+ let nd = |a: &[u16], b: &[u16]| a.iter().zip(b).filter(|(x, y)| x != y).count();
6456+ let (ndy, ndu, ndv) = (
6457+ nd(&frames[0].y, &ffmpeg_frames[0].y),
6458+ nd(&frames[0].u, &ffmpeg_frames[0].u),
6459+ nd(&frames[0].v, &ffmpeg_frames[0].v),
6460+ );
64416461 let mut first = None;
64426462 for row in 0..height {
64436463 for col in 0..width {
@@ -6458,13 +6478,32 @@ mod tests {
64586478 .filter(|(a, b)| a != b)
64596479 .count();
64606480 eprintln!(
6461- " {width}x{height} seed {seed}: MISMATCH luma first_diff={first:?} ndiff_luma={ndiff}/{}",
6481+ " {width}x{height} seed {seed}: MISMATCH first_diff={first:?} \
6482+ ndiff_luma={ndiff}/{} ndiff y/u/v={ndy}/{ndu}/{ndv}",
64626483 width * height
64636484 );
64646485 }
64656486 }
6466- eprintln!("{width}x{height}: {ok} ok / {bad} mismatch / {refused} refused (of {n})");
6467- }
6487+ assert_eq!(
6488+ bad, 0,
6489+ "{width}x{height}: {bad} of {n} seeds decoded to WRONG PIXELS ({ok} exact, \
6490+ {refused} named refusals)"
6491+ );
6492+ eprintln!("{width}x{height}: {ok}/{n} pixel-exact, {refused} named refusals");
6493+ total_exact += ok;
6494+ }
6495+ // Hit counter: the sweep proved nothing unless every size x seed
6496+ // attempt really ran end to end (aomenc -> us -> ffmpeg compare).
6497+ // Floor (hit counter): 7 of the 8 sizes must decode all 10 seeds
6498+ // pixel-exact -- only 8x8 is allowed to refuse outright today. If a
6499+ // future change makes sizes refuse instead of decode, this fails
6500+ // rather than passing on refusals alone.
6501+ assert!(
6502+ total_exact >= 70,
6503+ "tiny sweep only reached {total_exact} pixel-exact attempts (floor 70) -- \
6504+ refusals cannot substitute for decodes"
6505+ );
6506+ eprintln!("tiny frame sweep: {total_exact} pixel-exact attempts");
64686507 }
64696508
64706509 /// lane-tiny r1: re-decodes the known-failing 32x32 seed 45 fixture with
lanes/sub8-r4.report.mdadded+74 -0
@@ -0,0 +1,74 @@
1+# lane-sub8 report (round 4)
2+
3+## Premise correction (this is the round's main result)
4+Round 2/3 assumed aomenc was really choosing `PARTITION_HORZ`/`VERT` below 8x8
5+and AB partitions in this gate's recipe. **It is not.** Instrumented aomdec on
6+the gate's own stream (seed=117 cq=8, `--enable-rect-partitions=0`) reads only
7+`value=0` (NONE) and `value=3` (SPLIT) at every level:
8+
9+```
10+EC_TRACE=1 ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null s117.obu \
11+ | grep EC_PART_VAL | awk '{print $4,$5}' | sort | uniq -c
12+ 42 bsize=3 value=0 22 bsize=3 value=3 16 bsize=6 value=3
13+ 4 bsize=9 value=3 1 bsize=12 value=3
14+```
15+
16+So all 40 of the gate's "refusals" (`HORZ/VERT below 8x8`, `HORZ_A/B/VERT_A
17+below 16x16`, `a 32x32 partition type value=4/8/9`) were **hallucinated symbols
18+from our own desync**, not encoder choices. `--enable-rect-partitions=0` IS
19+honoured. Every refusal-shaped conclusion in rounds 2-3 was measuring the
20+desync.
21+
22+## Root causes found and fixed (commit "mi-exact intra mode neighbours ...")
23+1. **Coarse mode neighbours (`context-read-from-one-cell` class).**
24+ `above_mode`/`left_mode` are one slot per 16x16; a split cell leaves two
25+ (8x8) or four (4x4) different modes behind, and a leaf whose above/left
26+ neighbour sits in such a cell read the wrong `kf_y_mode` CDF row -> desync.
27+ `Neighbours` now keeps a mi-granular map (`sub8_mode_col`/`sub8_mode_row`,
28+ `record_mode_mi`), written by `record_rect`, `record_split_luma`,
29+ `decode_leaf8` and every 4x4 leaf, read back with an exact-position guard
30+ (`mode_above_mi`/`mode_left_mi`) that falls back to the coarse slot.
31+2. **`has_tr_4x4`/`has_bl_4x4` never transcribed** (`encode.rs`, the
32+ `corner-cut` comment that named this exact ceiling). Side-4 blocks clamped
33+ into the 8x8 table, so a directional 4x4 leaf predicted from above-right
34+ samples the decoder has not written yet -- all-zero pixels in the leaf's
35+ bottom-right triangle. Both tables transcribed verbatim from
36+ `~/.cache/aom-oracle/src/av1/common/reconintra.c:65,254`; `Reach::table`
37+ maps side 4 to the new row.
38+3. Cherry-picked lane-tiny `9b1297a` (deblocker chroma tx size from the block
39+ span) per the charter -- it does not change this lane's residue but keeps
40+ the branch aligned with main's fix.
41+
42+## Gate result
43+`a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact` -- **still RED**,
44+but for a 4-pixel chroma residue instead of a desync:
45+- symbol ladder vs instrumented aomdec is now **exact** on both sampled
46+ streams (324/324 elements seed=117, 318/318 seed=100), no refusal, decode
47+ completes;
48+- luma is **bit-exact** on seed=100;
49+- chroma differs on 4 pixels: U/V (row 20, cols 18-19), deltas 1..3.
50+
51+EVIDENCE: /tmp/.../scratchpad/{ref100.yuv,ours100.yuv} | aomenc seed=100 cq=6 recipe from the gate, decoded by ec-av1 and by ffmpeg | 4096/4096 luma bytes equal, 4/2048 chroma bytes differ (max |delta| 3); before this round the same stream refused at a hallucinated partition symbol
52+EVIDENCE: /tmp/.../scratchpad/{ref.txt,ours.txt} + ladder.py | EC_TRACE/EC_TRACE_MODE_STEP ladder, ours vs instrumented aomdec, seed=117 | 324 elements, no divergence (was: first divergence at element 62)
53+
54+## Suite
55+`cargo test -p ec-av1 --lib` (EC_AV1_REQUIRE_AOMENC=1): **267 passed, 2 failed,
56+22 ignored**, 1124 s.
57+- `stream::a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact` -- the
58+ 4-pixel chroma residue above.
59+- `refusal_inventory::the_decode_path_refuses_exactly_the_listed_cases` --
60+ NOT investigated this round (budget). Expected shape: a refusal the
61+ inventory expects to fire no longer fires now that the desync is gone
62+ (that is what the fix was for), but it is a RED test and no refusal string
63+ was lifted this round.
64+
65+## Open
66+- fix-now: the 4-pixel chroma residue (U/V row 20, cols 18-19 of the 64x64
67+ seed=100 frame; block = chroma 4x4 at (20,16), luma 8x8 group mi(10,8)).
68+ Tried and REVERTED (no effect on these pixels): OR-ing the subsampling scale
69+ into the chroma edge's mi (`set_lpf_parameters`' `scale_vert | ...`) in
70+ `edge_params`. Next step: dump post-reconstruction vs `EC_AV1_PREFILT_DUMP`
71+ to separate recon from deblock before touching either.
72+- fix-now: `refusal_inventory` red (see above).
73+- deferred(gate green): lifting any refusal string -- nothing lifted, none
74+ proven.