forge
Explore
Log in

Don't you dare go Hollow

A 128-root block re-stamped its chroma entropy context from the whole-block grid and recorded a 64x128 var-tx block as 128x128 -- the mu-chunk DC sign of every unit but the top-left was lost (dc_sign_ctx 1 vs libaom 2 at the first chroma unit of the 64x128 edge block) and the next superblock's 128-root partition ctx read 16 vs 19

Browse files at this commit

52c91bc63a2e0793876d439518cb9fc82c3fea6dAhmet Kaan GümüşParent: 56e5abe
  • fix
    • a 128-root block re-stamped its chroma entropy context from the whole-block grid and recorded a 64x128 var-tx block as 128x128 -- the mu-chunk DC sign of every unit but the top-left was lost (dc_sign_ctx 1 vs libaom 2 at the first chroma unit of the 64x128 edge block) and the next superblock's 128-root partition ctx read 16 vs 19
    • 192x256 sb128 8-bit inter stream goes 4-of-6 frames differing (36073 bytes) -> 6/6 bit-exact, new gate arm 46
Show full message
fix(av1): a 128-root block re-stamped its chroma entropy context from the whole-block grid and recorded a 64x128 var-tx block as 128x128 -- the mu-chunk DC sign of every unit but the top-left was lost (dc_sign_ctx 1 vs libaom 2 at the first chroma unit of the 64x128 edge block) and the next superblock's 128-root partition ctx read 16 vs 19; 192x256 sb128 8-bit inter stream goes 4-of-6 frames differing (36073 bytes) -> 6/6 bit-exact, new gate arm 46
crates/ec-av1/src/decode.rsmodified+45 -3
@@ -17385,6 +17385,11 @@ fn decode_inter_block(
1738517385 // coefficient-context write-back and the loop-filter grid fill below.
1738617386 let mut vartx_leaves: Option<Vec<(usize, usize, usize, usize)>> = None;
1738717387 let at_mi = at;
17388+ // lane-vert46 r1: set when this block's chroma was coded as one 32x32 unit
17389+ // per 64x64 "mu" chunk (any side above 64), so the end-of-block record
17390+ // below must NOT re-stamp the chroma neighbour context from the assembled
17391+ // whole-block grid.
17392+ let mut mu_chroma = false;
1738817393 if is_inter {
1738917394 let above_nbr = has_above.then(|| NeighbourRef {
1739017395 is_inter: above_inter,
@@ -18364,6 +18369,7 @@ fn decode_inter_block(
1836418369 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,
1836518370 );
1836618371 CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
18372+ mu_chroma = true;
1836718373 let dst = if plane_idx == 1 {
1836818374 &mut u_units
1836918375 } else {
@@ -19465,6 +19471,7 @@ fn decode_inter_block(
1946519471 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,
1946619472 );
1946719473 CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
19474+ mu_chroma = true;
1946819475 let dst = if plane_idx == 1 {
1946919476 &mut u_units
1947019477 } else {
@@ -20134,12 +20141,44 @@ fn decode_inter_block(
2013420141 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
2013520142 );
2013620143 }
20144+ // lane-vert46 r1: libaom stamps the chroma entropy context PER TRANSFORM
20145+ // UNIT (`av1_set_entropy_contexts` inside `decode_reconstruct_tx`'s mu-chunk
20146+ // loop). Above 64 a block's chroma is two or four 32x32 units, so the
20147+ // whole-block re-stamp in the record below overwrote every unit's own DC
20148+ // sign and level with the TOP-LEFT unit's -- the next block then read a
20149+ // stale `dc_sign_ctx` (192x256 --sb-size=128 stream: the 64x128 block at
20150+ // the partial right superblock read row 1 where libaom reads row 2). The
20151+ // units are collected here and re-stamped after that record, in mu-chunk
20152+ // order so a later unit still wins over an earlier one.
20153+ let mu_chroma_units: Vec<((usize, usize), usize, Vec<i32>)> = if mu_chroma {
20154+ let cu = 32usize;
20155+ let mut units = Vec::new();
20156+ for cr in 0..(write_h / 64).max(1) {
20157+ for cc in 0..(write_w / 64).max(1) {
20158+ let cu_mi = (at.0 + cr * 16, at.1 + cc * 16);
20159+ for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
20160+ let mut unit = Vec::with_capacity(cu * cu);
20161+ for rr in 0..cu {
20162+ let start = (cr * cu + rr) * chroma_side + cc * cu;
20163+ unit.extend_from_slice(&grid[start..start + cu]);
20164+ }
20165+ units.push((cu_mi, plane, unit));
20166+ }
20167+ }
20168+ }
20169+ units
20170+ } else {
20171+ Vec::new()
20172+ };
2013720173 if vartx_leaves.is_some() {
2013820174 // Plane 0 is already correct per transform unit
2013920175 // ([`Neighbours::record_mi_luma`] above); this writes everything else
20140- // [`Neighbours::record_rect`] would (a var-tx block is always square,
20141- // so `write_w == write_h == side`).
20142- neighbours.record_split_luma_rect_mi(at, side, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]);
20176+ // [`Neighbours::record_rect`] would. lane-vert46 r1: the block's OWN
20177+ // width/height, not `side` -- var-tx is no longer square-only (the 128
20178+ // root's HORZ/VERT arm decodes 128x64 / 64x128 var-tx blocks), and
20179+ // `side` there stamped `above_side`/`left_side` = 128, so the NEXT
20180+ // superblock's 128-root partition context read 16 where libaom reads 19.
20181+ neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]);
2014320182 } else {
2014420183 neighbours.record_rect_mi(
2014520184 at,
@@ -20150,6 +20189,9 @@ fn decode_inter_block(
2015020189 &[luma_grid, u_grid, v_grid],
2015120190 );
2015220191 }
20192+ for (cu_mi, plane, unit) in &mu_chroma_units {
20193+ neighbours.record_mi_chroma(*cu_mi, 64, 64, *plane, unit);
20194+ }
2015320195 neighbours.record_inter_rect_mi(
2015420196 at,
2015520197 write_w / MI,
crates/ec-av1/src/stream.rsmodified+23 -9
@@ -19002,22 +19002,36 @@ mod tests {
1900219002 // take the arm too, which is still refused by name (square-block
1900319003 // intra), so this gate's source is `mandelbrot`: its key frames split
1900419004 // and its inter frames keep the 128x64/64x128 edge block.
19005- let arms: Vec<(u32, &str, usize, usize, bool, bool)> = vec![
19006- (42, "--cq-level=55", 384, 320, false, false),
19007- (43, "--cq-level=55", 384, 320, true, false),
19008- (44, "--cq-level=32", 192, 256, false, true),
19009- (45, "--cq-level=45", 192, 256, true, true),
19005+ // lane-vert46 r1: the last field picks a SMOOTH deterministic source
19006+ // (`geq` sinusoids, the sb128c r8 intra arm's own fixture) instead of
19007+ // `mandelbrot`. Arm 46 is the stream that exposed this round's two
19008+ // defects: mandelbrot's inter frames never put a 64x128 edge block
19009+ // next to a neighbour whose partition context or per-mu-chunk chroma
19010+ // DC sign decides a symbol, so both were invisible to arms 42-45.
19011+ let arms: Vec<(u32, &str, usize, usize, bool, bool, bool)> = vec![
19012+ (42, "--cq-level=55", 384, 320, false, false, false),
19013+ (43, "--cq-level=55", 384, 320, true, false, false),
19014+ (44, "--cq-level=32", 192, 256, false, true, false),
19015+ (45, "--cq-level=45", 192, 256, true, true, false),
19016+ (46, "--cq-level=55", 192, 256, false, true, true),
1901019017 ];
1901119018 let (mut matched, mut named_refusals) = (0u32, 0u32);
1901219019 let (mut edge_arms, mut inter_arms) = (0u32, 0u32);
19013- for (seed, cq, width, height, ten_bit, vert) in arms {
19020+ for (seed, cq, width, height, ten_bit, vert, smooth) in arms {
1901419021 let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
19022+ let source = if smooth {
19023+ format!(
19024+ "nullsrc=size={width}x{height}:rate=25,format=yuv420p,\
19025+ geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)':\
19026+ cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'"
19027+ )
19028+ } else {
19029+ format!("mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4")
19030+ };
1901519031 let y4m = Command::new("ffmpeg")
1901619032 .args([
1901719033 "-v", "error", "-f", "lavfi", "-i",
19018- &format!(
19019- "mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4"
19020- ),
19034+ &source,
1902119035 "-pix_fmt", pix, "-strict", "-1", "-t", "0.2",
1902219036 "-f", "yuv4mpegpipe", "-",
1902319037 ])
lanes/vert46-r1.report.mdadded+92 -0
@@ -0,0 +1,92 @@
1+# lane-vert46 r1 -- the INTER 64x128 block at a partial 128 superblock
2+
3+Branch `lane-vert46`, worktree `edith_codecs-vert46`, base 103b66f
4+(= lane-sb128c r8). `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vert46`.
5+
6+## Premise (re-measured, not inherited)
7+
8+The sb128c r8 residue stream is reproducible: the arm-46 recipe (192x256
9+8-bit `geq` sinusoids, `--sb-size=128 --min-partition-size=64
10+--enable-rect-partitions=1 --cq-level=55 --cpu-used=0 --limit=5`, WITHOUT
11+`--kf-max-dist=1`) hashed twice to `ccc3bafd6d1c42b1336a69e68482e54b`, the
12+same md5 as `$HOME/.cache/sb128c-r8/vert46.obu`. Frame layout: mi 64x48, two
13+128 superblocks per row, the RIGHT column partial (`mi_col + hbs == mi_cols`),
14+so its 128 root reads the gathered bit. Frame 1 resolved it to
15+PARTITION_VERT = one BLOCK_64X128 inter block; frames 0 and 3 were exact,
16+1/2/4/5 differed (first differing byte 12033 = luma (x=129, y=62)).
17+
18+## Two root causes (both entropy, found on the msac range ladder)
19+
20+1. `crates/ec-av1/src/decode.rs:20146` (new) + `:17400`, `:18379`, `:19483`
21+ -- CHROMA ENTROPY CONTEXT RE-STAMPED PER BLOCK. A block wider or taller
22+ than 64 codes its chroma as one 32x32 unit per 64x64 mu chunk, and each
23+ unit stamps its own DC sign / level into the neighbour bands
24+ (`record_mi_chroma`, libaom `av1_set_entropy_contexts` inside
25+ `decode_reconstruct_tx`). The end-of-block record then OVERWROTE all of
26+ them with `neighbour_state` of the ASSEMBLED whole-block grid, i.e. with
27+ the top-left unit's DC. First diverging element: frame 1, block mi(0,32),
28+ plane 1, chunk 0, the DC sign symbol -- pre-symbol range 39712 on both
29+ sides, aomdec `dcctx=2`, ours `ctx=1`, post-symbol range 41596 vs 64592.
30+ Ours read the left neighbour as the 128x128 block's mu-chunk (0,0) DC
31+ (negative) where libaom reads its mu-chunk (0,16) DC (positive). Fix:
32+ collect the per-unit chroma grids and re-stamp them after the block record.
33+2. `crates/ec-av1/src/decode.rs:20179` -- VAR-TX BLOCK RECORDED AS SQUARE.
34+ `record_split_luma_rect_mi(at, side, side, ..)` wrote
35+ `above_side`/`left_side` = `side` (128) for a 64x128 var-tx block; the
36+ comment "a var-tx block is always square" stopped being true when the 128
37+ root's HORZ/VERT arm landed (sb128c r7). The NEXT superblock's 128-root
38+ partition symbol then read ctx 16 where aomdec reads ctx 19 (aomdec
39+ `EC_PART mi_row=32 mi_col=32 bsize=15 ctx=19 rng=43152`, ours entered the
40+ 64 level at rng=35032). Fix: pass the block's own `write_w`/`write_h`.
41+
42+Both are the same shape as memory classes `context-read-from-one-cell` and
43+`tx-grid-published-block-side` -- a neighbour band published with the BLOCK's
44+geometry instead of the transform unit's / the block's true footprint.
45+
46+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)
47+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
48+
49+## Gate
50+
51+New arm 46 of the existing sb128 inter gate
52+(`a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact`,
53+`crates/ec-av1/src/stream.rs:19005`): the same 192x256 VERT geometry as arm
54+44/45 but with the SMOOTH `geq` source instead of `mandelbrot` -- that is what
55+makes the encoder put a 64x128 edge block next to neighbours whose partition
56+context and chroma DC sign actually decide symbols. Arms 42-45 are unchanged
57+and still hard-assert the edge/inter counters; every decode-order frame
58+(hidden alt-refs included) is compared against the instrumented aomdec.
59+
60+ cargo test -p ec-av1 --lib sb128 -- --nocapture
61+ ... seed 42 384x320 8bit HORZ: 6 frames pixel-exact (1 hidden), edge +2 inter +2
62+ ... seed 43 384x320 10bit HORZ: 6 frames pixel-exact (1 hidden), edge +24 inter +24
63+ ... seed 44 192x256 8bit VERT: 6 frames pixel-exact (1 hidden), edge +2 inter +2
64+ ... seed 45 192x256 10bit VERT: 6 frames pixel-exact (1 hidden), edge +2 inter +2
65+ ... seed 46 192x256 8bit VERT: 6 frames pixel-exact (1 hidden), edge +20 inter +18
66+ test result: ok. 3 passed; 0 failed; 1 ignored (sibling sb128 gates included)
67+
68+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
69+
70+Siblings re-run in the same command (COMMON's SIBLING GATES rule):
71+`a_real_aomenc_sb128_intra_rect_block_decodes_pixel_exact` 5/5 arms exact
72+(128x64 +28/+30/+14, 64x128 +10/+10) and the sb128 CfL/1to4 gate.
73+
74+## Refusals
75+
76+None lifted or added -- both defects were silent wrong answers, not refusals.
77+
78+## Suite
79+
80+`cargo test -p ec-av1 --lib` under a systemd unit (MemoryMax=10G):
81+see `$HOME/.cache/vert46-suite-r1.log` (totals appended below when it lands).
82+
83+## Residue
84+
85+- accepted: the fix collects the per-unit chroma grids into a small `Vec` per
86+ 128-root block (2 or 4 units x 2 planes of 32x32 i32). Only blocks above 64
87+ pay it; below 64 `mu_chroma` is false and the vector is never allocated.
88+- deferred: the intra (key-frame) 128 path has the same end-of-block chroma
89+ record shape but its own reader; sb128c r8's intra gate is green on 5 arms,
90+ so no instance is measured there. Unblocked by a key-frame stream whose 128
91+ block sits LEFT of another coded block -- the arm-46 source with
92+ `--kf-max-dist=1` is exactly that and passes today.