diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2a22fee8..f638557e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -17385,6 +17385,11 @@ fn decode_inter_block( // coefficient-context write-back and the loop-filter grid fill below. let mut vartx_leaves: Option> = None; let at_mi = at; + // lane-vert46 r1: set when this block's chroma was coded as one 32x32 unit + // per 64x64 "mu" chunk (any side above 64), so the end-of-block record + // below must NOT re-stamp the chroma neighbour context from the assembled + // whole-block grid. + let mut mu_chroma = false; if is_inter { let above_nbr = has_above.then(|| NeighbourRef { is_inter: above_inter, @@ -18364,6 +18369,7 @@ fn decode_inter_block( cu_mi, luma_span, luma_span, plane_idx, &cu_grid, ); CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + mu_chroma = true; let dst = if plane_idx == 1 { &mut u_units } else { @@ -19465,6 +19471,7 @@ fn decode_inter_block( cu_mi, luma_span, luma_span, plane_idx, &cu_grid, ); CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + mu_chroma = true; let dst = if plane_idx == 1 { &mut u_units } else { @@ -20134,12 +20141,44 @@ fn decode_inter_block( rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 ); } + // lane-vert46 r1: libaom stamps the chroma entropy context PER TRANSFORM + // UNIT (`av1_set_entropy_contexts` inside `decode_reconstruct_tx`'s mu-chunk + // loop). Above 64 a block's chroma is two or four 32x32 units, so the + // whole-block re-stamp in the record below overwrote every unit's own DC + // sign and level with the TOP-LEFT unit's -- the next block then read a + // stale `dc_sign_ctx` (192x256 --sb-size=128 stream: the 64x128 block at + // 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, Vec)> = if mu_chroma { + let cu = 32usize; + let mut units = Vec::new(); + for cr in 0..(write_h / 64).max(1) { + for cc in 0..(write_w / 64).max(1) { + let cu_mi = (at.0 + cr * 16, at.1 + cc * 16); + 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, unit)); + } + } + } + units + } else { + Vec::new() + }; if vartx_leaves.is_some() { // Plane 0 is already correct per transform unit // ([`Neighbours::record_mi_luma`] above); this writes everything else - // [`Neighbours::record_rect`] would (a var-tx block is always square, - // so `write_w == write_h == side`). - neighbours.record_split_luma_rect_mi(at, side, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); + // [`Neighbours::record_rect`] would. lane-vert46 r1: the block's OWN + // width/height, not `side` -- var-tx is no longer square-only (the 128 + // root's HORZ/VERT arm decodes 128x64 / 64x128 var-tx blocks), and + // `side` there stamped `above_side`/`left_side` = 128, so the NEXT + // superblock's 128-root partition context read 16 where libaom reads 19. + neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); } else { neighbours.record_rect_mi( at, @@ -20150,6 +20189,9 @@ fn decode_inter_block( &[luma_grid, u_grid, v_grid], ); } + for (cu_mi, plane, unit) in &mu_chroma_units { + neighbours.record_mi_chroma(*cu_mi, 64, 64, *plane, unit); + } neighbours.record_inter_rect_mi( at, write_w / MI, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 901357a3..3e1d3a27 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -19002,22 +19002,36 @@ mod tests { // take the arm too, which is still refused by name (square-block // intra), so this gate's source is `mandelbrot`: its key frames split // and its inter frames keep the 128x64/64x128 edge block. - let arms: Vec<(u32, &str, usize, usize, bool, bool)> = vec![ - (42, "--cq-level=55", 384, 320, false, false), - (43, "--cq-level=55", 384, 320, true, false), - (44, "--cq-level=32", 192, 256, false, true), - (45, "--cq-level=45", 192, 256, true, true), + // lane-vert46 r1: the last field picks a SMOOTH deterministic source + // (`geq` sinusoids, the sb128c r8 intra arm's own fixture) instead of + // `mandelbrot`. Arm 46 is the stream that exposed this round's two + // defects: mandelbrot's inter frames never put a 64x128 edge block + // next to a neighbour whose partition context or per-mu-chunk chroma + // DC sign decides a symbol, so both were invisible to arms 42-45. + let arms: Vec<(u32, &str, usize, usize, bool, bool, bool)> = vec![ + (42, "--cq-level=55", 384, 320, false, false, false), + (43, "--cq-level=55", 384, 320, true, false, false), + (44, "--cq-level=32", 192, 256, false, true, false), + (45, "--cq-level=45", 192, 256, true, true, false), + (46, "--cq-level=55", 192, 256, false, true, true), ]; let (mut matched, mut named_refusals) = (0u32, 0u32); let (mut edge_arms, mut inter_arms) = (0u32, 0u32); - for (seed, cq, width, height, ten_bit, vert) in arms { + for (seed, cq, width, height, ten_bit, vert, smooth) in arms { let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let source = if smooth { + format!( + "nullsrc=size={width}x{height}:rate=25,format=yuv420p,\ + geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)':\ + cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" + ) + } else { + format!("mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4") + }; let y4m = Command::new("ffmpeg") .args([ "-v", "error", "-f", "lavfi", "-i", - &format!( - "mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4" - ), + &source, "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", "-f", "yuv4mpegpipe", "-", ]) diff --git a/lanes/vert46-r1.report.md b/lanes/vert46-r1.report.md new file mode 100644 index 00000000..e5aba87e --- /dev/null +++ b/lanes/vert46-r1.report.md @@ -0,0 +1,92 @@ +# lane-vert46 r1 -- the INTER 64x128 block at a partial 128 superblock + +Branch `lane-vert46`, worktree `edith_codecs-vert46`, base 103b66f +(= lane-sb128c r8). `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vert46`. + +## Premise (re-measured, not inherited) + +The sb128c r8 residue stream is reproducible: the arm-46 recipe (192x256 +8-bit `geq` sinusoids, `--sb-size=128 --min-partition-size=64 +--enable-rect-partitions=1 --cq-level=55 --cpu-used=0 --limit=5`, WITHOUT +`--kf-max-dist=1`) hashed twice to `ccc3bafd6d1c42b1336a69e68482e54b`, the +same md5 as `$HOME/.cache/sb128c-r8/vert46.obu`. Frame layout: mi 64x48, two +128 superblocks per row, the RIGHT column partial (`mi_col + hbs == mi_cols`), +so its 128 root reads the gathered bit. Frame 1 resolved it to +PARTITION_VERT = one BLOCK_64X128 inter block; frames 0 and 3 were exact, +1/2/4/5 differed (first differing byte 12033 = luma (x=129, y=62)). + +## Two root causes (both entropy, found on the msac range ladder) + +1. `crates/ec-av1/src/decode.rs:20146` (new) + `:17400`, `:18379`, `:19483` + -- CHROMA ENTROPY CONTEXT RE-STAMPED PER BLOCK. A block wider or taller + than 64 codes its chroma as one 32x32 unit per 64x64 mu chunk, and each + unit stamps its own DC sign / level into the neighbour bands + (`record_mi_chroma`, libaom `av1_set_entropy_contexts` inside + `decode_reconstruct_tx`). The end-of-block record then OVERWROTE all of + them with `neighbour_state` of the ASSEMBLED whole-block grid, i.e. with + the top-left unit's DC. First diverging element: frame 1, block mi(0,32), + plane 1, chunk 0, the DC sign symbol -- pre-symbol range 39712 on both + sides, aomdec `dcctx=2`, ours `ctx=1`, post-symbol range 41596 vs 64592. + Ours read the left neighbour as the 128x128 block's mu-chunk (0,0) DC + (negative) where libaom reads its mu-chunk (0,16) DC (positive). Fix: + collect the per-unit chroma grids and re-stamp them after the block record. +2. `crates/ec-av1/src/decode.rs:20179` -- VAR-TX BLOCK RECORDED AS SQUARE. + `record_split_luma_rect_mi(at, side, side, ..)` wrote + `above_side`/`left_side` = `side` (128) for a 64x128 var-tx block; the + comment "a var-tx block is always square" stopped being true when the 128 + root's HORZ/VERT arm landed (sb128c r7). The NEXT superblock's 128-root + partition symbol then read ctx 16 where aomdec reads ctx 19 (aomdec + `EC_PART mi_row=32 mi_col=32 bsize=15 ctx=19 rng=43152`, ours entered the + 64 level at rng=35032). Fix: pass the block's own `write_w`/`write_h`. + +Both are the same shape as memory classes `context-read-from-one-cell` and +`tx-grid-published-block-side` -- a neighbour band published with the BLOCK's +geometry instead of the transform unit's / the block's true footprint. + +EVIDENCE: $HOME/.cache/vert46-tmp/{our,aom}.f0..f5 | EC_AV1_FINAL_DUMP decode_probe v.obu vs instrumented aomdec, cmp per frame | 6/6 decode-order frames byte-identical (was 4 of 6 differing, 36073 bytes on frame 1) +EVIDENCE: $HOME/.cache/vert46-tmp/{a.lad,o.lad2} | EC_TRACE_COEFF range ladders, aomdec vs ours | first divergence moved 81 -> 109 -> none of 120 elements + +## Gate + +New arm 46 of the existing sb128 inter gate +(`a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact`, +`crates/ec-av1/src/stream.rs:19005`): the same 192x256 VERT geometry as arm +44/45 but with the SMOOTH `geq` source instead of `mandelbrot` -- that is what +makes the encoder put a 64x128 edge block next to neighbours whose partition +context and chroma DC sign actually decide symbols. Arms 42-45 are unchanged +and still hard-assert the edge/inter counters; every decode-order frame +(hidden alt-refs included) is compared against the instrumented aomdec. + + cargo test -p ec-av1 --lib sb128 -- --nocapture + ... seed 42 384x320 8bit HORZ: 6 frames pixel-exact (1 hidden), edge +2 inter +2 + ... seed 43 384x320 10bit HORZ: 6 frames pixel-exact (1 hidden), edge +24 inter +24 + ... seed 44 192x256 8bit VERT: 6 frames pixel-exact (1 hidden), edge +2 inter +2 + ... seed 45 192x256 10bit VERT: 6 frames pixel-exact (1 hidden), edge +2 inter +2 + ... seed 46 192x256 8bit VERT: 6 frames pixel-exact (1 hidden), edge +20 inter +18 + test result: ok. 3 passed; 0 failed; 1 ignored (sibling sb128 gates included) + +EVIDENCE: $HOME/.cache/vert46-gate-r1.log | cargo test -p ec-av1 --lib sb128 --nocapture | 5/5 edge arms + 5/5 intra-rect arms + the CfL/1to4 gate pixel-exact, arm 46 fires 20 edge / 18 inter 128-rect blocks + +Siblings re-run in the same command (COMMON's SIBLING GATES rule): +`a_real_aomenc_sb128_intra_rect_block_decodes_pixel_exact` 5/5 arms exact +(128x64 +28/+30/+14, 64x128 +10/+10) and the sb128 CfL/1to4 gate. + +## Refusals + +None lifted or added -- both defects were silent wrong answers, not refusals. + +## Suite + +`cargo test -p ec-av1 --lib` under a systemd unit (MemoryMax=10G): +see `$HOME/.cache/vert46-suite-r1.log` (totals appended below when it lands). + +## Residue + +- accepted: the fix collects the per-unit chroma grids into a small `Vec` per + 128-root block (2 or 4 units x 2 planes of 32x32 i32). Only blocks above 64 + pay it; below 64 `mu_chroma` is false and the vector is never allocated. +- deferred: the intra (key-frame) 128 path has the same end-of-block chroma + record shape but its own reader; sb128c r8's intra gate is green on 5 arms, + so no instance is measured there. Unblocked by a key-frame stream whose 128 + block sits LEFT of another coded block -- the arm-46 source with + `--kf-max-dist=1` is exactly that and passes today.