A compound 8x8 leaf whose transform split erased its four 4x4 TUs' coefficient context
Browse files at this commit8fd60198b4454fb52314fb8735824feada139625Parent: 64c4983- fix
- a compound 8x8 leaf whose transform split erased its four 4x4 TUs' coefficient context
2 changed files +89 -1
crates/ec-av1/src/decode.rsmodified+32 -1
| @@ -4279,7 +4279,7 @@ fn read_coeffs_rect( | ||
| 4279 | 4279 | }; |
| 4280 | 4280 | if rect_trace { |
| 4281 | 4281 | let (rng, _) = dec.debug_state(); |
| 4282 | - eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} rng={rng}", u8::from(negative)); | |
| 4282 | + eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", u8::from(negative)); | |
| 4283 | 4283 | } |
| 4284 | 4284 | let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { |
| 4285 | 4285 | let g = read_golomb(dec)?; |
| @@ -5336,6 +5336,15 @@ impl Neighbours { | ||
| 5336 | 5336 | left_coded |= left.level != 0; |
| 5337 | 5337 | vote += dc_vote(left.dc); |
| 5338 | 5338 | } |
| 5339 | + if plane == 0 && std::env::var_os("EC_DCDUMP").is_some() { | |
| 5340 | + let ab: Vec<String> = (0..w_mi) | |
| 5341 | + .map(|k| format!("{:?}/{}", self.above[mi_c + k][0].dc, self.above[mi_c + k][0].level)) | |
| 5342 | + .collect(); | |
| 5343 | + let lf: Vec<String> = (0..h_mi) | |
| 5344 | + .map(|k| format!("{:?}/{}", self.left[mi_r + k][0].dc, self.left[mi_r + k][0].level)) | |
| 5345 | + .collect(); | |
| 5346 | + eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); | |
| 5347 | + } | |
| 5339 | 5348 | (above_coded, left_coded, vote) |
| 5340 | 5349 | }) |
| 5341 | 5350 | } |
| @@ -24114,7 +24123,29 @@ fn decode_inter_block8( | ||
| 24114 | 24123 | // there before. Every leaf of the gate's stream is compound, |
| 24115 | 24124 | // so the 16x16 below a split block read partition ctx 0 |
| 24116 | 24125 | // instead of 1 and mis-read PARTITION_SPLIT as NONE. |
| 24126 | + // lane-vartxsplit r1: the COMPOUND twin of `decode_leaf8`'s | |
| 24127 | + // `saved_luma_ctx` (class: twin functions drift). When the | |
| 24128 | + // leaf's transform split, `read_inter_luma8` returns an | |
| 24129 | + // all-zero placeholder grid and each 4x4 TU has already | |
| 24130 | + // written its own plane-0 coefficient state through | |
| 24131 | + // `record_mi_luma`; recording the placeholder over all three | |
| 24132 | + // planes erased those four cul_level/DC-sign cells, so the | |
| 24133 | + // NEXT block read `dc_sign_ctx` 1 where libaom reads 0. | |
| 24134 | + let saved_luma_ctx = split8.then(|| { | |
| 24135 | + ( | |
| 24136 | + [neighbours.left[leaf_mi.0][0], neighbours.left[leaf_mi.0 + 1][0]], | |
| 24137 | + [neighbours.above[leaf_mi.1][0], neighbours.above[leaf_mi.1 + 1][0]], | |
| 24138 | + ) | |
| 24139 | + }); | |
| 24117 | 24140 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 24141 | + if let Some((left, above)) = saved_luma_ctx { | |
| 24142 | + for (cell, state) in left.into_iter().enumerate() { | |
| 24143 | + neighbours.left[leaf_mi.0 + cell][0] = state; | |
| 24144 | + } | |
| 24145 | + for (cell, state) in above.into_iter().enumerate() { | |
| 24146 | + neighbours.above[leaf_mi.1 + cell][0] = state; | |
| 24147 | + } | |
| 24148 | + } | |
| 24118 | 24149 | // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s |
| 24119 | 24150 | // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi |
| 24120 | 24151 | // cells of the 8x8; this leaf wrote none of them, so a 64x64 |
lanes/vartxsplit-r1.handoff.mdadded+57 -0
| @@ -0,0 +1,57 @@ | ||
| 1 | +# lane-vartxsplit r1 — handoff (root cause FOUND and FIXED; gate work not done) | |
| 2 | + | |
| 3 | +## Pinned stream (reproducible: two runs, identical md5) | |
| 4 | +`~/.cache/vartxsplit-tmp/s8.obu`, md5 `842355ef494455ead0352f62f84f2c56` | |
| 5 | +(generator `~/.cache/vartxsplit-tmp/gen.sh`), 8-bit 384x256 6 frames @25, | |
| 6 | +source `128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)`, oracle aomenc: | |
| 7 | +`--codec=av1 --passes=1 --end-usage=q --cq-level=10 --cpu-used=0 --threads=1 --row-mt=0 | |
| 8 | + --sb-size=64 --bit-depth=8 --input-bit-depth=8 --enable-restoration=0 --enable-palette=0 | |
| 9 | + --deltaq-mode=0 --enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0 | |
| 10 | + --lag-in-frames=0 --kf-max-dist=9999 --tile-columns=0 --enable-tx-size-search=1 | |
| 11 | + --enable-rect-partitions=1 --enable-ab-partitions=1 --enable-1to4-partitions=1 | |
| 12 | + --min-partition-size=8 --max-partition-size=64 --obu` | |
| 13 | +(gaterecipe r1's recipe 1; the 10-bit 16x32 twin was NOT re-measured this round.) | |
| 14 | + | |
| 15 | +## First diverging element (before the fix) | |
| 16 | +Decode-order frame 2, luma, block mi(8,16) (8x16, TX_8X16), the FIRST DC-sign symbol | |
| 17 | +of its plane-0 transform unit: | |
| 18 | +- entry range 43680 in both decoders; | |
| 19 | +- aomdec `EC_COEFF_STEP tag=sign c=0 sign=1 dcctx=0 rng=41828` | |
| 20 | +- ours `EC_COEFF_STEP tag=sign_rect pos=0 sign=1 dcctx=1 rng=41148` | |
| 21 | +i.e. same value, wrong CDF row: our DC-sign context was 1 (negative vote) where libaom's | |
| 22 | +is 0. Everything before it — partitions, var-tx `txfm_split` ladder (1362 lines of frame 1 | |
| 23 | +byte-identical; 92 lines of frame 2), coefficients — matched. | |
| 24 | + | |
| 25 | +## Root cause (fixed, decode.rs) | |
| 26 | +`EC_DCDUMP mi=(8,16) wh=(8,16) vote=-2 above=[Some(true)/7,Some(false)/7] | |
| 27 | +left=[None/0,None/0,Some(true)/7,Some(true)/7]`: the two left cells at mi rows 8-9 were | |
| 28 | +EMPTY. They belong to the compound 8x8 leaf at mi(8,14) whose transform SPLIT into four | |
| 29 | +4x4 TUs. `read_inter_luma8` returns an all-zero placeholder `luma_grid` in the split case | |
| 30 | +because each 4x4 TU already wrote its own plane-0 state via `record_mi_luma`; the compound | |
| 31 | +leaf arm then called `neighbours.record_mi(leaf_mi, 8, ...)`, which rewrites all three | |
| 32 | +planes of those cells and erased the four per-TU cul_level/DC-sign records. The | |
| 33 | +single-ref twin (`decode_leaf8`, decode.rs:25091) already had the `saved_luma_ctx` | |
| 34 | +save/restore around exactly this call; the compound arm never got it (class: | |
| 35 | +twin-functions-drift / mvstack-compound-tpl-extension). | |
| 36 | + | |
| 37 | +Fix: same save/restore around `record_mi` in the compound arm (decode.rs, the | |
| 38 | +`neighbours.record_mi(leaf_mi, 8, ...)` at the end of the compound 8x8 leaf). | |
| 39 | + | |
| 40 | +## Result | |
| 41 | +`dump_yuv s8.obu` vs `ffmpeg -pix_fmt yuv420p`: all 6 frames byte-identical | |
| 42 | +(was: frames 2-5 differ, 91201 luma samples on frame 2). | |
| 43 | + | |
| 44 | +## NOT done (next steps, in order) | |
| 45 | +1. Full suite (`systemd-run --user --unit=vartxsplit-suite-... cargo test -p ec-av1 --lib`). | |
| 46 | +2. Re-measure the 10-bit 16x32 arm (gaterecipe recipe 2: gate A's flag set, | |
| 47 | + `--enable-ab-partitions=0 --enable-dual-filter=0 --enable-obmc=0 --enable-tx64=1`, | |
| 48 | + attempt 16/17) — it may be the same defect or a second one; recipe 1's compound leaf | |
| 49 | + only exists because THIS recipe leaves `--enable-obmc`/dual-filter on. | |
| 50 | +3. Turn the gate B `split-tx-8x4` arm (stream.rs ~11036, marked unproven by gaterecipe r1) | |
| 51 | + back into a hard assert, and add the 10-bit 16x32 arm to | |
| 52 | + `real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal`. | |
| 53 | +4. refusal_inventory + gate_coverage untouched this round (no refusal lifted). | |
| 54 | + | |
| 55 | +## Instrumentation left in the tree (env-gated, cheap) | |
| 56 | +- `EC_DCDUMP=1`: `around_mi_rect` prints per-cell above/left DC state + vote (plane 0). | |
| 57 | +- `EC_TRACE_COEFF` rect sign line now carries `dcctx=`. |