forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-vert46' (3b4b9b6): per-transform-unit chroma entropy context above 64, var-tx bands stamped at the block's true dims

Browse files at this commit

d4020b927a8196cf14d83dec7eee7009678f4326Ahmet Kaan GümüşParent: de4295bb72a951
crates/ec-av1/src/decode.rsmodified+46 -0
@@ -18946,6 +18946,11 @@ fn decode_inter_block(
18946 // coefficient-context write-back and the loop-filter grid fill below.18946 // coefficient-context write-back and the loop-filter grid fill below.
18947 let mut vartx_leaves: Option<Vec<(usize, usize, usize, usize)>> = None;18947 let mut vartx_leaves: Option<Vec<(usize, usize, usize, usize)>> = None;
18948 let at_mi = at;18948 let at_mi = at;
18949+ // lane-vert46 r1: set when this block's chroma was coded as one 32x32 unit
18950+ // per 64x64 "mu" chunk (any side above 64), so the end-of-block record
18951+ // below must NOT re-stamp the chroma neighbour context from the assembled
18952+ // whole-block grid.
18953+ let mut mu_chroma = false;
18949 if is_inter {18954 if is_inter {
18950 let above_nbr = has_above.then(|| NeighbourRef {18955 let above_nbr = has_above.then(|| NeighbourRef {
18951 is_inter: above_inter,18956 is_inter: above_inter,
@@ -19970,6 +19975,7 @@ fn decode_inter_block(
19970 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,19975 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,
19971 );19976 );
19972 CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));19977 CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
19978+ mu_chroma = true;
19973 let dst = if plane_idx == 1 {19979 let dst = if plane_idx == 1 {
19974 &mut u_units19980 &mut u_units
19975 } else {19981 } else {
@@ -21161,6 +21167,7 @@ fn decode_inter_block(
21161 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,21167 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,
21162 );21168 );
21163 CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));21169 CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
21170+ mu_chroma = true;
21164 let dst = if plane_idx == 1 {21171 let dst = if plane_idx == 1 {
21165 &mut u_units21172 &mut u_units
21166 } else {21173 } else {
@@ -21871,6 +21878,35 @@ fn decode_inter_block(
21871 let pair_chroma = strip_chroma21878 let pair_chroma = strip_chroma
21872 .filter(|s| s.has_chroma)21879 .filter(|s| s.has_chroma)
21873 .map(|s| (s, neighbour_state(&u_grid), neighbour_state(&v_grid)));21880 .map(|s| (s, neighbour_state(&u_grid), neighbour_state(&v_grid)));
21881+ // lane-vert46 r1: libaom stamps the chroma entropy context PER TRANSFORM
21882+ // UNIT (`av1_set_entropy_contexts` inside `decode_reconstruct_tx`'s mu-chunk
21883+ // loop). Above 64 a block's chroma is two or four 32x32 units, so the
21884+ // whole-block re-stamp in the record below overwrote every unit's own DC
21885+ // sign and level with the TOP-LEFT unit's -- the next block then read a
21886+ // stale `dc_sign_ctx` (192x256 --sb-size=128 stream: the 64x128 block at
21887+ // the partial right superblock read row 1 where libaom reads row 2). The
21888+ // units are collected here and re-stamped after that record, in mu-chunk
21889+ // order so a later unit still wins over an earlier one.
21890+ let mu_chroma_units: Vec<((usize, usize), usize, Vec<i32>)> = if mu_chroma {
21891+ let cu = 32usize;
21892+ let mut units = Vec::new();
21893+ for cr in 0..(write_h / 64).max(1) {
21894+ for cc in 0..(write_w / 64).max(1) {
21895+ let cu_mi = (at.0 + cr * 16, at.1 + cc * 16);
21896+ for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
21897+ let mut unit = Vec::with_capacity(cu * cu);
21898+ for rr in 0..cu {
21899+ let start = (cr * cu + rr) * chroma_side + cc * cu;
21900+ unit.extend_from_slice(&grid[start..start + cu]);
21901+ }
21902+ units.push((cu_mi, plane, unit));
21903+ }
21904+ }
21905+ }
21906+ units
21907+ } else {
21908+ Vec::new()
21909+ };
21874 if vartx_leaves.is_some() {21910 if vartx_leaves.is_some() {
21875 // Plane 0 is already correct per transform unit21911 // Plane 0 is already correct per transform unit
21876 // ([`Neighbours::record_mi_luma`] above); this writes everything else21912 // ([`Neighbours::record_mi_luma`] above); this writes everything else
@@ -21886,6 +21922,13 @@ fn decode_inter_block(
21886 // context one value low (ctx 2 where aomdec says 3) and desynced.21922 // context one value low (ctx 2 where aomdec says 3) and desynced.
21887 // The true footprint is `write_w`/`write_h`, exactly as the21923 // The true footprint is `write_w`/`write_h`, exactly as the
21888 // non-var-tx arm below uses.21924 // non-var-tx arm below uses.
21925+ // Plane 0 is already correct per transform unit
21926+ // ([`Neighbours::record_mi_luma`] above); this writes everything else
21927+ // [`Neighbours::record_rect`] would. lane-vert46 r1: the block's OWN
21928+ // width/height, not `side` -- var-tx is no longer square-only (the 128
21929+ // root's HORZ/VERT arm decodes 128x64 / 64x128 var-tx blocks), and
21930+ // `side` there stamped `above_side`/`left_side` = 128, so the NEXT
21931+ // superblock's 128-root partition context read 16 where libaom reads 19.
21889 neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]);21932 neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]);
21890 } else {21933 } else {
21891 neighbours.record_rect_mi(21934 neighbours.record_rect_mi(
@@ -21923,6 +21966,9 @@ fn decode_inter_block(
21923 neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode);21966 neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode);
21924 INTER16_CHROMA_PAIR_HITS.with(|c| c.set(c.get() + 1));21967 INTER16_CHROMA_PAIR_HITS.with(|c| c.set(c.get() + 1));
21925 }21968 }
21969+ for (cu_mi, plane, unit) in &mu_chroma_units {
21970+ neighbours.record_mi_chroma(*cu_mi, 64, 64, *plane, unit);
21971+ }
21926 neighbours.record_inter_rect_mi(21972 neighbours.record_inter_rect_mi(
21927 at,21973 at,
21928 write_w / MI,21974 write_w / MI,
crates/ec-av1/src/stream.rsmodified+23 -9
@@ -22942,22 +22942,36 @@ mod tests {
22942 // take the arm too, which is still refused by name (square-block22942 // take the arm too, which is still refused by name (square-block
22943 // intra), so this gate's source is `mandelbrot`: its key frames split22943 // intra), so this gate's source is `mandelbrot`: its key frames split
22944 // and its inter frames keep the 128x64/64x128 edge block.22944 // and its inter frames keep the 128x64/64x128 edge block.
22945- let arms: Vec<(u32, &str, usize, usize, bool, bool)> = vec![22945+ // lane-vert46 r1: the last field picks a SMOOTH deterministic source
22946- (42, "--cq-level=55", 384, 320, false, false),22946+ // (`geq` sinusoids, the sb128c r8 intra arm's own fixture) instead of
22947- (43, "--cq-level=55", 384, 320, true, false),22947+ // `mandelbrot`. Arm 46 is the stream that exposed this round's two
22948- (44, "--cq-level=32", 192, 256, false, true),22948+ // defects: mandelbrot's inter frames never put a 64x128 edge block
22949- (45, "--cq-level=45", 192, 256, true, true),22949+ // next to a neighbour whose partition context or per-mu-chunk chroma
22950+ // DC sign decides a symbol, so both were invisible to arms 42-45.
22951+ let arms: Vec<(u32, &str, usize, usize, bool, bool, bool)> = vec![
22952+ (42, "--cq-level=55", 384, 320, false, false, false),
22953+ (43, "--cq-level=55", 384, 320, true, false, false),
22954+ (44, "--cq-level=32", 192, 256, false, true, false),
22955+ (45, "--cq-level=45", 192, 256, true, true, false),
22956+ (46, "--cq-level=55", 192, 256, false, true, true),
22950 ];22957 ];
22951 let (mut matched, mut named_refusals) = (0u32, 0u32);22958 let (mut matched, mut named_refusals) = (0u32, 0u32);
22952 let (mut edge_arms, mut inter_arms) = (0u32, 0u32);22959 let (mut edge_arms, mut inter_arms) = (0u32, 0u32);
22953- for (seed, cq, width, height, ten_bit, vert) in arms {22960+ for (seed, cq, width, height, ten_bit, vert, smooth) in arms {
22954 let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };22961 let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
22962+ let source = if smooth {
22963+ format!(
22964+ "nullsrc=size={width}x{height}:rate=25,format=yuv420p,\
22965+ geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)':\
22966+ cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'"
22967+ )
22968+ } else {
22969+ format!("mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4")
22970+ };
22955 let y4m = Command::new("ffmpeg")22971 let y4m = Command::new("ffmpeg")
22956 .args([22972 .args([
22957 "-v", "error", "-f", "lavfi", "-i",22973 "-v", "error", "-f", "lavfi", "-i",
22958- &format!(22974+ &source,
22959- "mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4"
22960- ),
22961 "-pix_fmt", pix, "-strict", "-1", "-t", "0.2",22975 "-pix_fmt", pix, "-strict", "-1", "-t", "0.2",
22962 "-f", "yuv4mpegpipe", "-",22976 "-f", "yuv4mpegpipe", "-",
22963 ])22977 ])
lanes/vert46-r1.handoff.mdadded+72 -0
@@ -0,0 +1,72 @@
1+# lane-vert46 r1 HANDOFF (tool-call cap)
2+
3+Tip: `ae16fec` on `lane-vert46` (base 103b66f = lane-sb128c r8). Two files
4+touched: `crates/ec-av1/src/decode.rs`, `crates/ec-av1/src/stream.rs`.
5+
6+## Stream
7+
8+192x256 8-bit `geq`-sinusoid source, `--sb-size=128 --min-partition-size=64
9+--enable-rect-partitions=1 --enable-tx-size-search=0 --cq-level=55
10+--cpu-used=0 --limit=5`, NO `--kf-max-dist=1`. Reproduced twice, md5
11+`ccc3bafd6d1c42b1336a69e68482e54b`, identical to the r8 residue stream.
12+Recipe script: `$HOME/.cache/vert46-tmp/mk.sh`. mi 64x48 -> the RIGHT 128
13+superblock column is partial (`mi_col + hbs == mi_cols`), so its 128 root
14+reads the gathered bit; frame 1 resolves it to PARTITION_VERT = one
15+BLOCK_64X128 inter block.
16+
17+## First diverging element (before the fix)
18+
19+Frame 1 (decode order), block mi(0,32) BLOCK_64X128, plane 1 (U), mu chunk 0,
20+32x32 chroma unit, the DC SIGN symbol:
21+
22+ pre-symbol range 39712 (identical both sides)
23+ aomdec dcctx=2, post-symbol range 41596
24+ ours ctx=1, post-symbol range 64592
25+
26+Ours read the left neighbour band as the 128x128 block's mu-chunk (0,0) DC
27+(negative) where libaom reads its mu-chunk (0,16) DC (positive).
28+
29+After fixing that, the ladder's next divergence was the 128-root partition
30+symbol of the NEXT superblock: aomdec `EC_PART mi_row=32 mi_col=32 bsize=15
31+ctx=19 rng=43152`, ours entered the 64 level at rng=35032 (ctx 16).
32+
33+## Root cause (two, same shape)
34+
35+1. `decode.rs` `decode_inter_block`, new `mu_chroma` flag + the per-unit
36+ re-stamp loop before `record_inter_rect_mi` (~:20146): a block above 64
37+ codes its chroma as one 32x32 unit per 64x64 mu chunk and each unit stamps
38+ its own DC sign/level (`record_mi_chroma`, libaom `av1_set_entropy_contexts`
39+ inside `decode_reconstruct_tx`). The end-of-block record overwrote ALL of
40+ them with `neighbour_state` of the assembled whole-block grid, i.e. with
41+ the top-left unit's DC. Fix: collect the per-unit grids, re-stamp after the
42+ block record, in mu-chunk order.
43+2. `decode.rs` `decode_inter_block` (~:20179):
44+ `record_split_luma_rect_mi(at, side, side, ..)` stamped
45+ `above_side`/`left_side` = 128 for a 64x128 var-tx block ("a var-tx block
46+ is always square" stopped being true when the 128 root's HORZ/VERT arm
47+ landed in sb128c r7). Fix: pass the block's own `write_w`/`write_h`.
48+
49+## cmp result (the only verification run)
50+
51+`EC_AV1_FINAL_DUMP` decode of the stream under
52+`systemd-run --user --scope -q -p MemoryMax=6G`, `cmp` per decode-order frame
53+against the instrumented aomdec's own `EC_AV1_FINAL_DUMP`:
54+
55+ f0 same f1 same f2 same f3 same f4 same f5 same
56+
57+(before: f1/f2/f4/f5 differed, f1 at byte 12033, 36073 bytes.)
58+Counters on that decode: `sb128_rect: edge_vert=10 inter_64x128=9`.
59+
60+## What is left for the next agent
61+
62+- The full `cargo test -p ec-av1 --lib` suite was STARTED and then STOPPED by
63+ the cap order; it has NOT been run to completion on this tip. Run it first.
64+- Gate arm 46 (smooth `geq` source) was added to
65+ `a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact`
66+ (`stream.rs:~19005`) BEFORE the cap message and IS committed; it and the
67+ sibling sb128 gates were run once, green:
68+ arms 42..46 six decode-order frames pixel-exact each, arm 46 edge +20 /
69+ inter 128-rect +18; `intra_rect_block` 5/5 arms exact.
70+- Oracle: `~/.cache/aom-oracle/src/av1/decoder/decodetxb.c` now prints
71+ `dcctx=%d` on the `EC_COEFF_STEP tag=sign` line (env `EC_TRACE_COEFF`);
72+ aomdec rebuilt with `ninja aomdec` (NOT `make`). Uncommitted, keep it.
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.