forge
Explore
Log in

Don't you dare go Hollow

lane-av1-llband2: port 01a34bc8, 444 lossless rect-strip chroma unit span

Browse files at this commit

f3e2fd4c52c8b016fb0557a655aedeb91d4cf9f4Ahmet Kaan GümüşParent: f0141f9
decode_rect_split's lossless chroma arm here is the same writer the
reviewed sibling commit 01a34bc8 (edith_codecs-av1llband) fixed for the
av1llsub8 stop at aligned step 19228 (16x8 leaf, U bc=2 br=0, txb_skip
base 1 vs oracle base 0 off a polluted above-band cell). Same base tree
6cf92769, same defect site (hardcoded luma_span=8 at decode.rs:10458).
Ported that fix instead of authoring a second one: unit luma span now
derived from the plane subsampling (span_x=4<<ss_x, span_y=4<<ss_y) for
the cu_mi step, around_mi_rect, tu_reach and the immediate + replayed
record_mi_chroma stamps, plus the rect_split_lossless_chroma444_hits
non-vacuity counter, the a_real_aomenc_lossless_444_key_frame gate over
the pinned fixtures/ll444-lossless-key.obu, and the decode_probe llband
line. Post-images cmp-identical to 01a34bc8; 4:2:0 arithmetic unchanged.

Measured here: 444 lossless key frame 178 -> 0 differing bytes
(sample-exact all planes, counter 160 units on the fixture); 4:2:0
lossless key + inter gates green; cargo check -p ec-av1 --all-targets
0 warnings. decode_rect4_16_strip, read_inter_rect_chroma,
restoration.rs and the intra write-back untouched. Details in
lanes/av1llband2.report.md.
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
@@ -216,6 +216,10 @@ fn main() {
216 ec_av1::decode::chroma_edge_tu_clip_hits(),216 ec_av1::decode::chroma_edge_tu_clip_hits(),
217 ec_av1::decode::skip_lossless_band_reset_hits(),217 ec_av1::decode::skip_lossless_band_reset_hits(),
218 );218 );
219+ println!(
220+ "llband: rect_split_lossless_chroma444={}",
221+ ec_av1::decode::rect_split_lossless_chroma444_hits()
222+ );
219 // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular223 // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular
220 // uv_mode grid instead of the coarse one-slot-per-column map.224 // uv_mode grid instead of the coarse one-slot-per-column map.
221 println!(225 println!(
crates/ec-av1/src/decode.rsmodified+35 -10
@@ -5321,6 +5321,10 @@ thread_local! {
5321 /// entropy bands were zeroed per unit (libaom `av1_reset_entropy_context`,5321 /// entropy bands were zeroed per unit (libaom `av1_reset_entropy_context`,
5322 /// decodeframe.c:1262) instead of leaking the previous occupant's.5322 /// decodeframe.c:1262) instead of leaking the previous occupant's.
5323 static SKIP_LOSSLESS_BAND_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };5323 static SKIP_LOSSLESS_BAND_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5324+ /// lane-av1-llband: 4x4 chroma transform units a lossless HORZ/VERT strip
5325+ /// walked at subsampling 0/0 (one unit per mi cell -- the geometry the
5326+ /// hardcoded 4:2:0 span mis-stepped).
5327+ static RECT_SPLIT_LOSSLESS_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5324 }5328 }
5325 5329
5326 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape5330 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape
@@ -5343,6 +5347,14 @@ pub fn skip_lossless_band_reset_hits() -> usize {
5343 SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.get())5347 SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.get())
5344 }5348 }
5345 5349
5350+/// How many 4x4 chroma transform units a lossless HORZ/VERT strip walked at
5351+/// subsampling 0/0 (lane-av1-llband). Zero means a stream never decoded the
5352+/// 4:4:4 lossless unit walk this counter proves -- a gate asserting the fix
5353+/// must see this nonzero.
5354+pub fn rect_split_lossless_chroma444_hits() -> usize {
5355+ RECT_SPLIT_LOSSLESS_CHROMA444_HITS.with(|c| c.get())
5356+}
5357+
5346 /// Gate-side reset for the two lane-av1-loss64 counters above.5358 /// Gate-side reset for the two lane-av1-loss64 counters above.
5347 pub fn reset_loss64_hits() {5359 pub fn reset_loss64_hits() {
5348 CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0));5360 CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0));
@@ -10403,7 +10415,7 @@ fn decode_rect_split(
10403 // them with the LAST unit's state (class `override-slot-on-one-arm`: the10415 // them with the LAST unit's state (class `override-slot-on-one-arm`: the
10404 // next block then read `dc_sign_ctx` 1 where libaom reads 0). They are10416 // next block then read `dc_sign_ctx` 1 where libaom reads 0). They are
10405 // collected here and replayed after that record.10417 // collected here and replayed after that record.
10406- let mut ll_chroma_units: Vec<((usize, usize), usize, Grid)> = Vec::new();10418+ let mut ll_chroma_units: Vec<((usize, usize), usize, Grid, usize, usize)> = Vec::new();
10407 // The chroma_tiled arm below stamps each unit's coefficient context10419 // The chroma_tiled arm below stamps each unit's coefficient context
10408 // immediately (so the NEXT unit reads it), then the whole-strip10420 // immediately (so the NEXT unit reads it), then the whole-strip
10409 // `record_split_luma_rect_mi` rewrites every chroma cell with ONE10421 // `record_split_luma_rect_mi` rewrites every chroma cell with ONE
@@ -10451,19 +10463,29 @@ fn decode_rect_split(
10451 let scan4 = default_scan(4);10463 let scan4 = default_scan(4);
10452 let offset = (chroma_w > 4 || chroma_h > 4).then_some(3);10464 let offset = (chroma_w > 4 || chroma_h > 4).then_some(3);
10453 let (cw_n, ch_n) = (chroma_w / 4, chroma_h / 4);10465 let (cw_n, ch_n) = (chroma_w / 4, chroma_h / 4);
10466+ // lane-av1-llband: one 4x4 chroma unit's extent in LUMA pixels -- 4
10467+ // chroma px scaled by the plane's own subsampling. The hardcoded 8
10468+ // was the 4:2:0 unit's span; at 4:4:4 a unit is 4x4 LUMA px (one mi
10469+ // cell), and the 8-px step made every unit past the first column/row
10470+ // read its `txb_skip` context at the WRONG mi (two cells over) and
10471+ // stamp a 2-cell span with one unit's state -- the polluted above-band
10472+ // cell behind a 16x8 leaf's U bc=2 unit of the 444 lossless key frame
10473+ // (measured: oracle `EC_DBGCTX` reads 1-cell spans at 1-mi steps;
10474+ // ours read `above[28..29]` where the oracle read `above[26]`).
10475+ let span_x = 4 << ss_x(fctx);
10476+ let span_y = 4 << ss_y(fctx);
10454 let mut last = [Grid::Zero(16), Grid::Zero(16)];10477 let mut last = [Grid::Zero(16), Grid::Zero(16)];
10455 for plane_idx in 1..=2 {10478 for plane_idx in 1..=2 {
10456 for cu_row in 0..ch_n {10479 for cu_row in 0..ch_n {
10457 for cu_col in 0..cw_n {10480 for cu_col in 0..cw_n {
10458- let luma_span = 8;
10459 let cu_mi = (10481 let cu_mi = (
10460- mi_r + cu_row * (luma_span / MI),10482+ mi_r + cu_row * (span_y / MI),
10461- mi_c + cu_col * (luma_span / MI),10483+ mi_c + cu_col * (span_x / MI),
10462 );10484 );
10463- let cu_around = neighbours.around_mi(cu_mi, luma_span);10485+ let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y);
10464 let cu_reach = tu_reach(10486 let cu_reach = tu_reach(
10465 bw, bh,10487 bw, bh,
10466- cu_col * luma_span, cu_row * luma_span, luma_span,10488+ cu_col * span_x, cu_row * span_y, span_x,
10467 block_reach, px, py, y.width, y.height, fctx,10489 block_reach, px, py, y.width, y.height, fctx,
10468 );10490 );
10469 let (cu_x, cu_y) = (cpx + cu_col * 4, cpy + cu_row * 4);10491 let (cu_x, cu_y) = (cpx + cu_col * 4, cpy + cu_row * 4);
@@ -10485,8 +10507,11 @@ fn decode_rect_split(
10485 }),10507 }),
10486 None, offset, m.smooth_neighbor_uv, fctx,10508 None, offset, m.smooth_neighbor_uv, fctx,
10487 )?;10509 )?;
10488- neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_idx, &grid);10510+ if span_x == 4 && span_y == 4 {
10489- ll_chroma_units.push((cu_mi, plane_idx, grid.clone()));10511+ hit!(RECT_SPLIT_LOSSLESS_CHROMA444_HITS);
10512+ }
10513+ neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &grid);
10514+ ll_chroma_units.push((cu_mi, plane_idx, grid.clone(), span_x, span_y));
10490 last[plane_idx - 1] = grid;10515 last[plane_idx - 1] = grid;
10491 }10516 }
10492 }10517 }
@@ -10658,8 +10683,8 @@ fn decode_rect_split(
10658 m.uv_predict_mode,10683 m.uv_predict_mode,
10659 [&u_grid, &v_grid],10684 [&u_grid, &v_grid],
10660 );10685 );
10661- for (cu_mi, plane, unit) in &ll_chroma_units {10686+ for (cu_mi, plane, unit, span_w, span_h) in &ll_chroma_units {
10662- neighbours.record_mi_chroma(*cu_mi, 8, 8, *plane, unit);10687+ neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);
10663 }10688 }
10664 for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units {10689 for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units {
10665 neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);10690 neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);
crates/ec-av1/src/stream.rsmodified+77 -0
@@ -5399,6 +5399,83 @@ pub(crate) mod tests {
5399 }5399 }
5400 }5400 }
5401 5401
5402+ /// lane-av1-llband: the pinned 4:4:4 LOSSLESS key frame
5403+ /// (`fixtures/ll444-lossless-key.obu`, the `ll444` recipe's frame 0 --
5404+ /// `testsrc2 128x96` yuv444p cut to its key frame) decodes sample-exact,
5405+ /// and its HORZ/VERT strips really walked their chroma as 4x4 units at
5406+ /// subsampling 0/0 (one unit per mi cell). That unit walk used the 4:2:0
5407+ /// span (8 luma px per 4x4 chroma unit) unconditionally, so every unit
5408+ /// past the first column/row read its `txb_skip` context two mi cells
5409+ /// over and stamped a 2-cell smear -- the 178-byte key-frame miss, first
5410+ /// divergence at the 16x8 leaf mi (16,24)'s U bc=2 unit (oracle
5411+ /// `txb_skip` base 0 off `above[26]`, ours base 1 off the polluted
5412+ /// `above[29]`). The counter assertion is the non-vacuity half (class
5413+ /// `gate-blind-to-feature`): a stream that never reaches the 4:4:4 unit
5414+ /// walk must not pass.
5415+ #[test]
5416+ fn a_real_aomenc_lossless_444_key_frame_decodes_sample_exact() {
5417+ const NAME: &str = "a_real_aomenc_lossless_444_key_frame_decodes_sample_exact";
5418+ if !have_ffmpeg() {
5419+ eprintln!("SKIP {NAME}: no ffmpeg");
5420+ return;
5421+ }
5422+ let Ok(stream) = std::fs::read(pin_dir().join("ll444-lossless-key.obu")) else {
5423+ eprintln!(
5424+ "SKIP {NAME}: no pinned bytes at {} -- regenerate with \
5425+ `testsrc2 128x96` yuv444p 6 frames, aomenc --profile=1 --lossless=1 \
5426+ --enable-palette=0 --enable-intrabc=0, cut to the key frame's OBUs",
5427+ pin_dir().join("ll444-lossless-key.obu").display()
5428+ );
5429+ return;
5430+ };
5431+ // Blindness guard: the pinned fixture must really be a lossless frame.
5432+ let mut parser = Av1Parser::new();
5433+ let mut pos = 0usize;
5434+ let mut lossless = false;
5435+ while pos < stream.len() {
5436+ let obu = parser.parse_obu(&stream[pos..]).expect("aomenc OBU parses");
5437+ pos += obu.total_size.max(1);
5438+ if let ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) = obu.kind {
5439+ lossless = h.lossless.iter().all(|&l| l);
5440+ }
5441+ }
5442+ assert!(lossless, "{NAME} went blind: the pinned frame is not lossless");
5443+ let before = crate::decode::rect_split_lossless_chroma444_hits();
5444+ let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes");
5445+ assert_eq!(ours.len(), 1, "{NAME}: frame count");
5446+ assert!(
5447+ crate::decode::rect_split_lossless_chroma444_hits() > before,
5448+ "{NAME} went blind: no lossless HORZ/VERT strip walked its chroma \
5449+ as 4x4 units at subsampling 0/0"
5450+ );
5451+ let refs = Command::new("ffmpeg")
5452+ .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-"])
5453+ .stdin(Stdio::piped())
5454+ .stdout(Stdio::piped())
5455+ .stderr(Stdio::piped())
5456+ .spawn()
5457+ .and_then(|mut child| {
5458+ use std::io::Write as _;
5459+ child.stdin.as_mut().expect("stdin").write_all(&stream)?;
5460+ child.wait_with_output()
5461+ })
5462+ .expect("ffmpeg 444 decode failed");
5463+ assert!(refs.status.success(), "{}", String::from_utf8_lossy(&refs.stderr));
5464+ let frame = &ours[0];
5465+ let planes = [
5466+ (&frame.y, frame.width * frame.height),
5467+ (&frame.u, frame.width * frame.height),
5468+ (&frame.v, frame.width * frame.height),
5469+ ];
5470+ let mut off = 0usize;
5471+ for (plane, (g, len)) in planes.iter().enumerate() {
5472+ let raw = &refs.stdout[off..off + len];
5473+ let bad = g.iter().zip(raw.iter()).filter(|&(&a, &b)| a != u16::from(b)).count();
5474+ assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ");
5475+ off += len;
5476+ }
5477+ }
5478+
5402 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis5479 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis
5403 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces5480 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces
5404 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane5481 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane
lanes/av1llband2.report.mdadded+90 -0
@@ -0,0 +1,90 @@
1+# lane-av1-llband2: 4:4:4 lossless above-band cell — sibling fix ported (r1)
2+
3+## Charter
4+
5+Resolve the `av1llsub8` stop (aligned step 19228: 16x8 leaf, U unit bc=2
6+br=0, `txb_skip` base 1 vs oracle base 0 — an above-band cell). Port the
7+already-reviewed sibling fix if it is the same writer; never author a
8+second fix for the same defect. 4:2:0 lossless stays exact. Work in
9+`edith_codecs-av1llband2` @ 6cf92769.
10+
11+## Writer identification (done before any edit)
12+
13+Read `edith_codecs-av1llband` r1 (`lanes/av1llband.report.md`) and commit
14+`01a34bc8` before writing anything. That sibling took the exact same stop
15+(178-byte key-frame miss, first divergence at the 16x8 leaf mi (16,24)'s
16+U bc=2 unit) to **0 differing bytes**, and was reviewed.
17+
18+Same-writer proof:
19+
20+- This branch HEAD is the sibling's parent commit `6cf92769` byte-for-byte
21+ (both continue `av1llsub8`).
22+- The defect site in THIS tree is the identical code the sibling named:
23+ `decode_rect_split`'s lossless chroma arm hardcoding the 4:2:0 unit span
24+ — `let luma_span = 8;` at `decode.rs:10458` here, feeding the `cu_mi`
25+ step, `around_mi`, `tu_reach` and both `record_mi_chroma` stamps.
26+- The stop signature matches the sibling's reproduced defect exactly
27+ (step 19228, 16x8 leaf, U bc=2 br=0, base 1 / row `[0][11]` vs oracle
28+ base 0 / row `[0][10]`).
29+
30+⇒ `01a34bc8` IS that writer's fix. Ported it; no second fix invented.
31+
32+## Port (faithful, byte-identical)
33+
34+`git cherry-pick -n 01a34bc8`, dropping the sibling's lane report file
35+(`lanes/av1llband.report.md` — this lane writes its own). Post-images of
36+all three source files `cmp`-verified IDENTICAL against the sibling
37+worktree at `01a34bc8`:
38+
39+- `crates/ec-av1/src/decode.rs` (+45/−10): `span_x = 4 << ss_x(fctx)`,
40+ `span_y = 4 << ss_y(fctx)` replaces the hardcoded 8 for the `cu_mi`
41+ step, `around_mi_rect`, `tu_reach`, the immediate and replayed
42+ `record_mi_chroma` stamps (`ll_chroma_units` carries per-unit spans);
43+ non-vacuity counter `RECT_SPLIT_LOSSLESS_CHROMA444_HITS` +
44+ `rect_split_lossless_chroma444_hits()`.
45+- `crates/ec-av1/src/stream.rs` (+77): gate
46+ `a_real_aomenc_lossless_444_key_frame_decodes_sample_exact` over the
47+ pinned fixture, with the lossless-frame blindness guard and the
48+ counter-moved non-vacuity assert.
49+- `crates/ec-av1/examples/decode_probe.rs` (+4): `llband:` counter line.
50+
51+Off-limits files untouched: `decode_rect4_16_strip`,
52+`read_inter_rect_chroma`, `restoration.rs`, intra write-back. No 422
53+model, no luma path, no `sub8_leaf_chroma444` (innocent: the 16x8 leaf
54+never reaches it). 4:2:0 arithmetic is unchanged (`4 << 1 = 8`).
55+
56+Fixture provenance: `fixtures/ll444-lossless-key.obu` (untracked, as in
57+the sibling), copied from the sibling worktree, sha256
58+`9fc9ce1f5f6475a1d483f404b44acb90f72a80be2e5c51dedf0aeb1da9a3f5dc`
59+(4927 B; cut of the `ll444` recipe's key-frame OBUs: `testsrc2 128x96`
60+yuv444p, `aomenc --profile=1 --lossless=1 --enable-palette=0
61+--enable-intrabc=0`, oracle build `~/.cache/aom-oracle`).
62+
63+## Verification (measured, this tree)
64+
65+- New gate `a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`:
66+ **green** — key frame decodes **0 differing bytes** (sample-exact,
67+ all 3 planes vs ffmpeg `yuv444p` rawvideo, 36864 samples compared) and
68+ the counter moved (non-vacuity).
69+- `decode_probe` on the pinned fixture: `llband:
70+ rect_split_lossless_chroma444=160` (matches the sibling's 160 units),
71+ no panic.
72+- 4:2:0 lossless stays green:
73+ `a_lossless_libaom_key_frame_decodes_sample_exact`,
74+ `a_lossless_libaom_inter_frame_decodes_sample_exact` — both ok
75+ (3 passed, 0 failed in the gate run).
76+- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors.
77+
78+## Deferred (spoken, not hidden)
79+
80+- **1:4 strips at lossless 4:4:4** (`decode_rect4_16_strip`): same span
81+ defect class (per the sibling's r1), but the file is owned by a live
82+ lane and off-limits to this branch — the fix is the same span
83+ derivation measured here. deferred(fix-now in the owning lane).
84+- Lossless INTER frames panic at `reconstruct_mc_rect` (decode.rs:2589):
85+ `read_inter_rect_chroma`'s branch, untouched, as chartered.
86+ deferred(fix-now in the owning lane).
87+- Intrabc rect leaves at lossless 444 still route the rect arm's
88+ `read_coeffs_rect` path: unreachable with `--enable-intrabc=0`
89+ fixtures. deferred(fix-now after the inter side is green, with an
90+ intrabc 4:4:4 fixture), matching `av1llsub8`/`av1llband`.