From 5350f30a8d1b14982b9224844d40122bc518c934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 23 Sep 2026 20:01:29 +0300 Subject: [PATCH] lane-av1-444: assemble real per-unit chroma grids in the 64x64 inter arm; unit-complete mu re-stamp at ss 0/0; fixture byte-exact end-to-end (60/60 shown, three-way sha256 c3f95bca); report continuation 8 --- crates/ec-av1/src/decode.rs | 145 ++++++++++++++++++++++++++++-------- lanes/av1444.report.md | 60 +++++++++++++++ 2 files changed, 174 insertions(+), 31 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b4e23478..a0ec1b41 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -29537,11 +29537,17 @@ fn decode_inter_block( // +3, so `luma_skip_ctx: Some(3)` (lane-sb128b r3's // convention, as the 128 mu path above). let cu_tx = chroma_tx; - let mu_chroma_units = chroma_side / cu_tx; + let mu_units_n = chroma_side / cu_tx; + let mut u_acc: Vec = Vec::new(); + let mut v_acc: Vec = Vec::new(); for plane_idx in 1..3 { - let (src, buf) = if plane_idx == 1 { (su, &mut *u) } else { (sv, &mut *v) }; - for cr in 0..mu_chroma_units { - for cc in 0..mu_chroma_units { + let (src, buf, acc) = if plane_idx == 1 { + (su, &mut *u, &mut u_acc) + } else { + (sv, &mut *v, &mut v_acc) + }; + for cr in 0..mu_units_n { + for cc in 0..mu_units_n { let cu_mi = (rmi + cr * (cu_tx / MI), cmi + cc * (cu_tx / MI)); let cu_around = neighbours.around_mi(cu_mi, cu_tx); let cu_grid = read_inter_plane( @@ -29568,12 +29574,28 @@ fn decode_inter_block( cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid, ); hit!(CHROMA_SPLIT_TX_HITS); + // lane-av1-444 c8: the unit's levels must ALSO + // land in the block grid -- the block-tail mu + // re-stamp slices the per-unit states back out + // of it. This arm used to hand it a ZERO grid, + // so the re-stamp (and `record_rect_mi`'s + // whole-block write under it) painted the whole + // block's chroma context cells 0 AFTER the + // correct per-unit stamps above: the next block + // read `txb_skip_ctx` base 0 where aom gathers + // 1 (f52 mi(52,16) U all_zero, ctx 0 vs 8). + let dst = mu_units(acc, chroma_side * chroma_side); + for rr in 0..cu_tx { + let start = (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + } } } } mu_chroma = true; - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Own(u_acc); + v_grid = Grid::Own(v_acc); } else { u_grid = read_inter_plane( dec, @@ -30898,11 +30920,17 @@ fn decode_inter_block( // +3, so `luma_skip_ctx: Some(3)` (lane-sb128b r3's // convention, as the 128 mu path above). let cu_tx = chroma_tx; - let mu_chroma_units = chroma_side / cu_tx; + let mu_units_n = chroma_side / cu_tx; + let mut u_acc: Vec = Vec::new(); + let mut v_acc: Vec = Vec::new(); for plane_idx in 1..3 { - let (src, buf) = if plane_idx == 1 { (su, &mut *u) } else { (sv, &mut *v) }; - for cr in 0..mu_chroma_units { - for cc in 0..mu_chroma_units { + let (src, buf, acc) = if plane_idx == 1 { + (su, &mut *u, &mut u_acc) + } else { + (sv, &mut *v, &mut v_acc) + }; + for cr in 0..mu_units_n { + for cc in 0..mu_units_n { let cu_mi = (rmi + cr * (cu_tx / MI), cmi + cc * (cu_tx / MI)); let cu_around = neighbours.around_mi(cu_mi, cu_tx); let cu_grid = read_inter_plane( @@ -30929,12 +30957,28 @@ fn decode_inter_block( cu_mi, cu_tx, cu_tx, plane_idx, &cu_grid, ); hit!(CHROMA_SPLIT_TX_HITS); + // lane-av1-444 c8: the unit's levels must ALSO + // land in the block grid -- the block-tail mu + // re-stamp slices the per-unit states back out + // of it. This arm used to hand it a ZERO grid, + // so the re-stamp (and `record_rect_mi`'s + // whole-block write under it) painted the whole + // block's chroma context cells 0 AFTER the + // correct per-unit stamps above: the next block + // read `txb_skip_ctx` base 0 where aom gathers + // 1 (f52 mi(52,16) U all_zero, ctx 0 vs 8). + let dst = mu_units(acc, chroma_side * chroma_side); + for rr in 0..cu_tx { + let start = (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + } } } } mu_chroma = true; - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Own(u_acc); + v_grid = Grid::Own(v_acc); } else { u_grid = read_inter_plane( dec, @@ -31750,28 +31794,64 @@ fn decode_inter_block( // the partial right superblock read row 1 where libaom reads row 2). The // units are collected here and re-stamped after that record, in mu-chunk // order so a later unit still wins over an earlier one. - let mu_chroma_units: Vec<((usize, usize), usize, Grid)> = if mu_chroma { + let mu_chroma_units: Vec<((usize, usize), usize, Grid, usize, usize)> = if mu_chroma { // lane-lossless2: the unit is TX_32X32 (one per 64x64 mu chunk) // normally and TX_4X4 on a lossless frame, where the whole chroma // plane block is a raster of them. let cu = if lossless(fctx) { 4usize } else { 32usize }; - let span = cu * 2; - let (rows, cols) = if lossless(fctx) { - ((write_h / 2).div_ceil(cu), (write_w / 2).div_ceil(cu)) - } else { - ((write_h / 64).max(1), (write_w / 64).max(1)) - }; let mut units = Vec::new(); - for cr in 0..rows { - for cc in 0..cols { - let cu_mi = (at.0 + cr * (span / MI), at.1 + cc * (span / MI)); - for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { - let mut unit = Vec::with_capacity(cu * cu); - for rr in 0..cu { - let start = (cr * cu + rr) * chroma_side + cc * cu; - unit.extend_from_slice(&grid[start..start + cu]); + if lossless(fctx) { + let (rows, cols) = ((write_h / 2).div_ceil(cu), (write_w / 2).div_ceil(cu)); + for cr in 0..rows { + for cc in 0..cols { + let cu_mi = (at.0 + cr * (cu * 2 / MI), at.1 + cc * (cu * 2 / MI)); + for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { + let mut unit = Vec::with_capacity(cu * cu); + for rr in 0..cu { + let start = (cr * cu + rr) * chroma_side + cc * cu; + unit.extend_from_slice(&grid[start..start + cu]); + } + units.push((cu_mi, plane, Grid::Own(unit), cu * 2, cu * 2)); + } + } + } + } else { + // lane-av1-444 c8: a 64x64 mu chunk's chroma plane block is + // (64 >> ss) square -- ONE TX_32X32 unit per chunk at 4:2:0 but + // FOUR at ss 0/0 (`av1_get_max_uv_txsize` caps the unit at 32 + // either way). Enumerate every unit at its own mi origin, its + // own (32 << ss)-px entropy-cell span, and its own 32x32 + // quadrant of the assembled plane grid; stamping one quadrant's + // state over the whole chunk desynced the next block's + // `txb_skip_ctx` (f52 mi(52,16) U read base 0, aom 1). + let (ur, uc) = (((64usize) >> ss_y(fctx)) / cu, ((64usize) >> ss_x(fctx)) / cu); + let (rows, cols) = ((write_h / 64).max(1), (write_w / 64).max(1)); + for cr in 0..rows { + for cc in 0..cols { + for kr in 0..ur { + for kc in 0..uc { + let cu_mi = ( + at.0 + (cr * 64 + kr * (cu << ss_y(fctx))) / MI, + at.1 + (cc * 64 + kc * (cu << ss_x(fctx))) / MI, + ); + let cy = cr * ((64usize) >> ss_y(fctx)) + kr * cu; + let cx = cc * ((64usize) >> ss_x(fctx)) + kc * cu; + for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { + let mut unit = Vec::with_capacity(cu * cu); + for rr in 0..cu { + let start = (cy + rr) * chroma_side + cx; + unit.extend_from_slice(&grid[start..start + cu]); + } + units.push(( + cu_mi, + plane, + Grid::Own(unit), + cu << ss_x(fctx), + cu << ss_y(fctx), + )); + } + } } - units.push((cu_mi, plane, Grid::Own(unit))); } } } @@ -31908,9 +31988,12 @@ fn decode_inter_block( neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode); hit!(INTER16_CHROMA_PAIR_HITS); } - let mu_span = if lossless(fctx) { 8 } else { 64 }; - for (cu_mi, plane, unit) in &mu_chroma_units { - neighbours.record_mi_chroma(*cu_mi, mu_span, mu_span, *plane, unit); + // lane-av1-444 c8: each unit stamps its OWN span (32 << ss px at + // TX_32X32, 8 px lossless) -- a 64x64 mu chunk at ss 0/0 holds four + // TX_32X32 units, so the old whole-chunk 64-px span smeared one unit's + // state over its three neighbours' cells too. + for (cu_mi, plane, unit, span_w, span_h) in &mu_chroma_units { + neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit); } neighbours.record_inter_rect_mi( at, diff --git a/lanes/av1444.report.md b/lanes/av1444.report.md index 66f559d3..1246dbbd 100644 --- a/lanes/av1444.report.md +++ b/lanes/av1444.report.md @@ -176,6 +176,66 @@ Full suite NOT run this round (budget wall). 4. Full suite `--test-threads=1` (NOT run this round), 0-warning parity (build IS warning-clean), update this report. +## Continuation 8 (2026-09-23, Av1X444Cont8 — lane closed: fixture byte-exact end-to-end) + +Round-7's ONE-symbol wall is RESOLVED; `av1-profile1-444.ivf` decodes ALL 60 +shown frames byte-exact vs ffmpeg AND aomdec (three-way sha256 +`c3f95bca00f0ba5ea9f7071f5645edd910b590efebea2d73398017d10dc272d7`). + +1. **Root cause (class `override-slot-on-one-arm` via a zero grid):** the + 64x64-inter four-TX_32X32 chroma arm read each unit correctly and stamped + each unit's context IMMEDIATELY (`record_mi_chroma(cu_mi, 32, 32, ..)`), + then set `mu_chroma = true` and handed `Grid::Zero` to `u_grid`/`v_grid`. + The block tail then painted 0 over those correct stamps TWICE: + `record_rect_mi`'s whole-block chroma write (state of the zero grid) and + the `mu_chroma_units` re-stamp, which sliced its "units" out of the SAME + zero grids. Every block after a 64x64 inter block thus read chroma + coefficient contexts 0 across the block's whole span. Oracle trace at the + wall (`EC_DBGCTX`, rebuilt `build-c/aomdec`): `mi=52,16 plane=1 tx=2 + above0=0 left0=21 base=1 off=7 ctx=8 cellsA=0,0,0,0 cellsL=21,21,21,21` + — aom's left cells for the mi(52,16) U TX_16X16 hold the mi(48,0) block's + U TX_32X32 (48,8) unit's running cul (raw cell 21; only zero-vs-nonzero + matters for `get_entropy_context`), ours held 0 → ctx 0 vs 8. +2. **Fix (both copies of the arm — single-ref and compound):** + - The arm now assembles the four per-unit coefficient grids per plane + into `u_grid`/`v_grid` (`mu_units` + `Grid::Own`, same pattern as the + 128-root path), so the block-tail re-stamp slices REAL states. + - `mu_chroma_units` collection enumerates FOUR TX_32X32 units per 64x64 + mu chunk at ss 0/0 (one at 4:2:0 — byte-identical to the old loop), + each at its own mi origin, own `(32 << ss)`-px entropy-cell span, own + 32x32 quadrant of the assembled grid; the stamp loop uses each unit's + own span (was a blanket 64 px). Lossless branch unchanged. +3. **Witness gate (all fresh runs, ffmpeg `-y` added to the scripts — the + old scripts could silently compare a STALE ffmpeg reference when the + output file existed):** + + | stream | result | + | --- | --- | + | `av1-profile1-444.ivf`, all 60 shown frames | IDENTICAL (ffmpeg == aomdec == ours, sha256 above) | + | 444 square 8-bit, filters off | IDENTICAL | + | 444 square 8-bit, filters ON (LF+CDEF+LR) | IDENTICAL | + | 444 square 10-bit, filters off | IDENTICAL (new `witness_444_10b.sh`) | + | 444 square 10-bit, filters on | IDENTICAL | + | 444 forced-64x64 blocks (`gradients --min-partition-size=64`) | IDENTICAL | + | 420 square, filters off (regression) | IDENTICAL | + | 4:2:2 | refused by name (suite gate, unchanged) | + + **Inter square 64x64 at 4:4:4 is witnessed by the fixture itself**: the + 64x64 PARTITION_NONE inter block at mi(48,0) of decode idx 52 codes the + four-unit U/V TX_32X32 loop, and every later block in rows 48..59 + (including f52's own mi(52,16) read) consumes its per-unit contexts — + byte-exactness of frames 52..59 is that consumption proof. The + forced-64x64 generated arm stays intra-only and passes. +4. Regression arms quoted above; `reelb_*` 10-bit, mono 60f, qmatrix-refused + and cdf-exact gates ride the full suite (final line appended below). +5. Named gap, unchanged: an inter 128x128 block at 4:4:4 still codes ONE + chroma unit per mu chunk where libaom codes four (`side > 64` arm) — + unported symbol stream, same disposition class as the rect2 sub8 row. + The collection fix makes the CONTEXT machinery unit-complete for it, but + the stream port is not attempted. +6. Full suite `--test-threads=1` (hub-supervised): see the suite line at + the bottom of this file. + ## Continuation 7 (2026-09-23, Vefa — budget-wall WIP) Round-6's wall is RESOLVED; the fixture moved from "shown 18 seed" to a new,