A var-tx leaf overwrote the block's chroma deblock transform size
Browse files at this commitd5f333b1d617185e54b2a9456a12b3564e4cc1ffParent: 523f6b7- fix
- a var-tx leaf overwrote the block's chroma deblock transform size
2 changed files +167 -9
- crates/ec-av1/src/decode.rs +49 -9
- lanes/golomb-r6.handoff.md +118 -0
crates/ec-av1/src/decode.rsmodified+49 -9
| @@ -4209,6 +4209,36 @@ impl Neighbours { | |||
| 4209 | } | 4209 | } |
| 4210 | } | 4210 | } |
| 4211 | 4211 | ||
| 4212 | + /// One var-tx / split-tx LEAF's own LUMA transform dims over its mi span. | ||
| 4213 | + /// libaom `get_transform_size` (av1_loopfilter.c:207) applies the split | ||
| 4214 | + /// override only `if ((plane == AOM_PLANE_Y) && ...)` -- chroma keeps | ||
| 4215 | + /// `av1_get_max_uv_txsize(mbmi->bsize)`, the whole BLOCK's uv transform. | ||
| 4216 | + /// Routing a leaf through [`Self::fill_lf_grid_rect`] recomputed the uv | ||
| 4217 | + /// dims from the LEAF span and so invented chroma transform edges the | ||
| 4218 | + /// deblocker then filtered (lane-golomb r6). `ref_grid`/`delta_lf_grid` | ||
| 4219 | + /// are already correct from the block's own fill over the same span. | ||
| 4220 | + fn fill_lf_grid_leaf_luma( | ||
| 4221 | + &mut self, | ||
| 4222 | + at_mi: (usize, usize), | ||
| 4223 | + w_mi: usize, | ||
| 4224 | + h_mi: usize, | ||
| 4225 | + tx_px: u8, | ||
| 4226 | + tx_h_px: u8, | ||
| 4227 | + ) { | ||
| 4228 | + let (mi_r, mi_c) = at_mi; | ||
| 4229 | + for rr in 0..h_mi { | ||
| 4230 | + for cc in 0..w_mi { | ||
| 4231 | + let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); | ||
| 4232 | + if let Some(cell) = self.tx_grid.get_mut(idx) { | ||
| 4233 | + *cell = tx_px; | ||
| 4234 | + } | ||
| 4235 | + if let Some(cell) = self.tx_h_grid.get_mut(idx) { | ||
| 4236 | + *cell = tx_h_px; | ||
| 4237 | + } | ||
| 4238 | + } | ||
| 4239 | + } | ||
| 4240 | + } | ||
| 4241 | + | ||
| 4212 | /// Marks every 4x4 mi cell a just-decoded coded block covers with its | 4242 | /// Marks every 4x4 mi cell a just-decoded coded block covers with its |
| 4213 | /// `skip` flag -- `at_mi`/`side_mi` are the block's own position and | 4243 | /// `skip` flag -- `at_mi`/`side_mi` are the block's own position and |
| 4214 | /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s | 4244 | /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s |
| @@ -8775,8 +8805,22 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, | |||
| 8775 | 8805 | ||
| 8776 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { | 8806 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { |
| 8777 | use std::io::Write; | 8807 | use std::io::Write; |
| 8808 | + // lane-golomb r6: one file per DECODE-order picture, like aomdec's own | ||
| 8809 | + // `ec_dump16` static index -- a single `.f0` overwritten every frame made | ||
| 8810 | + // the post-deblock stage uncomparable across a sequence. | ||
| 8811 | + thread_local! { | ||
| 8812 | + static STAGE_IDX: std::cell::RefCell<std::collections::HashMap<String, usize>> = | ||
| 8813 | + std::cell::RefCell::new(std::collections::HashMap::new()); | ||
| 8814 | + } | ||
| 8815 | + let idx = STAGE_IDX.with(|m| { | ||
| 8816 | + let mut m = m.borrow_mut(); | ||
| 8817 | + let e = m.entry(var.to_string()).or_insert(0); | ||
| 8818 | + let i = *e; | ||
| 8819 | + *e += 1; | ||
| 8820 | + i | ||
| 8821 | + }); | ||
| 8778 | if let Ok(path) = std::env::var(var) | 8822 | if let Ok(path) = std::env::var(var) |
| 8779 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) | 8823 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) |
| 8780 | { | 8824 | { |
| 8781 | for p in [y, u, v] { | 8825 | for p in [y, u, v] { |
| 8782 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); | 8826 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); |
| @@ -18688,21 +18732,17 @@ fn decode_inter_block( | |||
| 18688 | }, | 18732 | }, |
| 18689 | ); | 18733 | ); |
| 18690 | // lane-txselect: a var-tx block's deblock edges follow its own transform | 18734 | // lane-txselect: a var-tx block's deblock edges follow its own transform |
| 18691 | - // units, not the block. Chroma still reads `tx_h_grid / 2` (the block's | 18735 | + // units, not the block -- for LUMA only (lane-golomb r6): the chroma |
| 18692 | - // uv transform is not split) -- a known corner-cut of this round. | 18736 | + // grids keep the block's own `av1_get_max_uv_txsize`, which is what |
| 18737 | + // libaom's `get_transform_size` reads for `plane != AOM_PLANE_Y`. | ||
| 18693 | if let Some(leaves) = &vartx_leaves { | 18738 | if let Some(leaves) = &vartx_leaves { |
| 18694 | for &(row, col, tx_px) in leaves { | 18739 | for &(row, col, tx_px) in leaves { |
| 18695 | - neighbours.fill_lf_grid_rect( | 18740 | + neighbours.fill_lf_grid_leaf_luma( |
| 18696 | (at_mi.0 + row, at_mi.1 + col), | 18741 | (at_mi.0 + row, at_mi.1 + col), |
| 18697 | tx_px / MI, | 18742 | tx_px / MI, |
| 18698 | tx_px / MI, | 18743 | tx_px / MI, |
| 18699 | tx_px as u8, | 18744 | tx_px as u8, |
| 18700 | tx_px as u8, | 18745 | tx_px as u8, |
| 18701 | - if globalmv_for_lf { | ||
| 18702 | - -ref_frame_for_lf | ||
| 18703 | - } else { | ||
| 18704 | - ref_frame_for_lf | ||
| 18705 | - }, | ||
| 18706 | ); | 18746 | ); |
| 18707 | } | 18747 | } |
| 18708 | } | 18748 | } |
lanes/golomb-r6.handoff.mdadded+118 -0
| @@ -0,0 +1,118 @@ | |||
| 1 | +# lane-golomb r6 HANDOFF | ||
| 2 | + | ||
| 3 | +## Merge state (STEP 1: DONE) | ||
| 4 | +* `899d7cf` = `git merge main` (main `18bf7dc`). Real merge commit, not a squash. | ||
| 5 | +* `crates/ec-av1/src/mvstack.rs`: `git diff main -- mvstack.rs` is EMPTY -> ONE copy of the | ||
| 6 | + compound tpl-extension hunk (lane-sb128 `d6cca7d` == our `13aebbe`), byte-identical to main. | ||
| 7 | +* `crates/ec-av1/src/cdf.rs` and `cdf_state.rs`: `git diff main` EMPTY (NZ_MAP/FILTER_INTRA | ||
| 8 | + byte-identical to main). | ||
| 9 | +* 7 `decode.rs` conflicts resolved: 4 were comment-only (took main's text); 3 were the counter | ||
| 10 | + pair -- main's `bump_edge_part` and this lane's `bump_edge32` are INDEPENDENT counters, BOTH | ||
| 11 | + kept at every site (`decode.rs:13094-13101`, `13169-13179`, and the two `!has_rows32/!has_cols32` | ||
| 12 | + guards). | ||
| 13 | +* `#[ignore = "open r2 defect: ..."]` on | ||
| 14 | + `a_32x32_frame_edge_rect_partition_with_a_flat_band_decodes_pixel_exact` | ||
| 15 | + (`stream.rs:18414`) SURVIVED the merge -- verified by grep after the merge commit. | ||
| 16 | + | ||
| 17 | +## Suite r5 | ||
| 18 | +`$HOME/.cache/golomb-suite-r5.log` had NO `test result:` line: the unit was still `active` and | ||
| 19 | +I stopped it (`systemctl --user stop golomb-suite-r5`) to free `CARGO_TARGET_DIR` for r6 -- it | ||
| 20 | +was building the PRE-merge tree, so its result would have been superseded anyway. Every `test` | ||
| 21 | +line present in it up to that point was `ok`. r6 suite armed as unit `golomb-suite-r6` | ||
| 22 | +-> `$HOME/.cache/golomb-suite-r6.log`; READ THAT, not r5. | ||
| 23 | + | ||
| 24 | +## STEP 2: chroma residue -- ROOT CAUSE #1 FOUND AND FIXED | ||
| 25 | + | ||
| 26 | +Stream: `g35.obu`, md5 `9037f5b21db95d35e71f91f040fc33e1` (regenerated, hash confirmed; | ||
| 27 | +recipe `scratchpad/gl-gen.sh 35 <out>`), 192x80 cq35 5 frames 8-bit, 6 decode-order pictures. | ||
| 28 | + | ||
| 29 | +### Localization method (reusable) | ||
| 30 | +Three-stage compare, decode order, ours vs the oracle: | ||
| 31 | +`EC_AV1_PREFILT_DUMP` (pre-loopfilter) / `EC_AV1_POSTDEBLOCK_DUMP` (post-deblock, pre-CDEF) / | ||
| 32 | +`EC_AV1_FINAL_DUMP` (post everything). Ours dumps a PADDED plane (192x96 luma), aomdec dumps | ||
| 33 | +CROPPED (192x80) -- the comparator must use different strides per side. | ||
| 34 | +NOTE: `EC_AV1_PREFILT_DUMP16`/`..._DUMP16` SEGFAULT the oracle aomdec on an 8-bit stream | ||
| 35 | +(`ec_dump16` does `CONVERT_TO_SHORTPTR` unconditionally, decodeframe.c:3968). Use the 8-bit | ||
| 36 | +`*_DUMP` vars for 8-bit streams. | ||
| 37 | +Ours' `dump_stage` used to write `.f0` for EVERY frame (overwrite); r6 gave it a per-var | ||
| 38 | +thread-local index (`decode.rs`, `dump_stage`) so POSTDEBLOCK is now `.f0..fN` like the oracle. | ||
| 39 | + | ||
| 40 | +### The measurement that localized it | ||
| 41 | +Before the fix: prefilt decode-f1 EXACT, post-deblock decode-f1 U342/V380 wrong, luma exact at | ||
| 42 | +every stage -> the defect was the DEBLOCK filter on chroma, not prediction, not CDEF | ||
| 43 | +(`--enable-cdef=0` did NOT fix it), not LR (disabled in the recipe). | ||
| 44 | + | ||
| 45 | +### Root cause (fixed) | ||
| 46 | +`decode.rs`, inter block tail: the var-tx / split-tx LEAF loop called | ||
| 47 | +`Neighbours::fill_lf_grid_rect(leaf_mi, tx_px/MI, tx_px/MI, ...)`, and that function DERIVES | ||
| 48 | +the chroma grids from the span it is given (`uv_tx_w = (w_mi*MI/2).clamp(4,32)`). So every | ||
| 49 | +var-tx leaf OVERWROTE the block's correct `uv_tx_grid`/`uv_tx_h_grid` (the block's | ||
| 50 | +`av1_get_max_uv_txsize`) with `leaf_tx/2`, inventing chroma transform edges the deblocker then | ||
| 51 | +filtered. libaom `get_transform_size` (`av1/common/av1_loopfilter.c:207`) applies the var-tx | ||
| 52 | +override ONLY `if ((plane == AOM_PLANE_Y) && is_inter_block(mbmi) && !mbmi->skip_txfm)`; | ||
| 53 | +chroma always keeps `av1_get_max_uv_txsize(mbmi->bsize, ss_x, ss_y)`. | ||
| 54 | +FIX: new `Neighbours::fill_lf_grid_leaf_luma` writes ONLY `tx_grid`/`tx_h_grid` over the leaf | ||
| 55 | +span (`ref_grid`/`delta_lf_grid` are already correct from the block's own fill over the same | ||
| 56 | +span), and the leaf loop calls it. Sweep: this was the ONLY `fill_lf_grid_rect` caller passing | ||
| 57 | +a TU span; all 12 others pass block dims (checked each). | ||
| 58 | + | ||
| 59 | +### Result | ||
| 60 | +g35 ours vs aomdec, all three stages, decode order: | ||
| 61 | +before f0 exact, f1 U398/V457, f2 U325/V412, f3 U336/V408, f4 U~1000/V~1000, f5 U691/V746 | ||
| 62 | +after f0-f3 EXACT at prefilt+postdeblock+final, f4 U974/V973 (prefilt), f5 inherits it. | ||
| 63 | + | ||
| 64 | +## RESIDUE (still RED) -- exactly one defect left | ||
| 65 | +Gate: `cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition` | ||
| 66 | +=> `192x80 cq35 frames=5 10bit=false frame 3 plane U: 978 pixels differ, first at row 0 col 32 | ||
| 67 | +(ours 33 vs ffmpeg 8) [edge32=[0,36,0,0,0,18,0,0]]`. | ||
| 68 | + | ||
| 69 | +* Stage: **PREFILTER** (prediction+residual), decode-order picture 4 only (f5 inherits). | ||
| 70 | + Deblock/CDEF/LR are exonerated for this one. | ||
| 71 | +* Extent: EXACTLY chroma x 32..63, y 0..31 = luma x 64..127, y 0..63, i.e. one whole 64x64 | ||
| 72 | + superblock. Luma bit-exact inside it. | ||
| 73 | +* Shape of the error: HIGH-FREQUENCY, |delta| up to 52. aomdec's row 0 is smooth | ||
| 74 | + (13,14,14,14,...) where ours is (36,12,0,0,20,22,...). That is a RESIDUAL/inverse-transform | ||
| 75 | + shape, not a prediction-offset shape. | ||
| 76 | +* Blocks in that SB (decode f4, from `EC_TRACE_MODE`): mi(0,16) mode=23 ref0=1 ref1=7 (compound), | ||
| 77 | + mi(0,24) mode=17 ref0=1 ref1=7, mi(8,16) mode=17 ref0=1 ref1=7, mi(8,24) mode=13 ref0=7 | ||
| 78 | + single-ref. All 32x32. | ||
| 79 | + | ||
| 80 | +### Ruled out (each with the command that ruled it out) | ||
| 81 | +* deblock / CDEF / LR: prefilt already differs on f4. | ||
| 82 | +* per-plane `delta_q_u/v_dc/ac`: consumed (`stream.rs:599-603` etc.) AND f0-f3 chroma is now | ||
| 83 | + bit-exact under the same quantizer. | ||
| 84 | +* narrow-block (<=4-wide) chroma MC kernel and sub8x8 chroma MV derivation: impossible in this | ||
| 85 | + stream, `--min-partition-size=32` means the smallest chroma block is 16x16. | ||
| 86 | +* chroma MC rounding: derived by hand that our always-2-pass convolve is bit-identical to | ||
| 87 | + libaom's `av1_convolve_x_sr_c`/`_y_sr_c` single-pass rounding when one fraction is 0 | ||
| 88 | + (identity tap 128, round2(x*16,11) == ROUND_POWER_OF_TWO(x,7)); and f1-f3 are now exact. | ||
| 89 | +* **DIFFWTD compound (the tempting one -- DO NOT re-chase it blind):** `--enable-diff-wtd-comp=0` | ||
| 90 | + made the whole sequence exact, BUT that is a DIFFERENT bitstream (class gate-recipe-confound). | ||
| 91 | + An `EC_DWTD` trace of the ORIGINAL g35 shows only 4 diffwtd blocks in the whole stream, in | ||
| 92 | + decode f1 (px=64,py=0) and decode f2 (px=0,py=0 / px=64,py=0 / px=128,py=32) -- **NONE in | ||
| 93 | + decode f4**, where the residue is. DIFFWTD is therefore EXONERATED for this residue. | ||
| 94 | +* warp / global motion / OBMC / dual filter / masked-comp / interintra / dist-wtd: ablated on | ||
| 95 | + the post-fix build, all still show the f3(display) failure (`scratchpad/abl.sh`). | ||
| 96 | + | ||
| 97 | +### Exact next step | ||
| 98 | +The error is a chroma RESIDUAL in a 64x64 SB of decode-order picture 4 whose luma is exact and | ||
| 99 | +whose entropy is (r5-proven) in sync. Bisect chroma coefficients, not prediction: | ||
| 100 | +1. Run the oracle with `EC_TRACE_COEFF=1` and ours with `EC_TRACE_COEFF=1` on `g35.obu`, isolate | ||
| 101 | + decode picture 4, block mi(0,16), plane 1. Compare the DEQUANTIZED values element by element | ||
| 102 | + (and the msac RANGE per element, never `tell()`). | ||
| 103 | +2. Prime suspect given "luma exact, chroma noisy, whole SB": the chroma `tx_type` inherited from | ||
| 104 | + the colocated luma unit (`decode.rs` `inherited_luma_tx_type`, `av1_get_tx_type` | ||
| 105 | + `blockd.h:1291`). For a var-tx-split luma block the chroma TU spans several luma TUs and | ||
| 106 | + libaom reads the luma tx_type at `blk_row<<ssy, blk_col<<ssx`; ours takes "the top-left unit". | ||
| 107 | + Verify that mapping against `av1_get_tx_type` for a 32x32 block whose luma split to 16x16. | ||
| 108 | + A wrong tx_type gives exactly this signature: right coefficients, wrong basis, chroma only. | ||
| 109 | +3. Second suspect: `txsize_sqr_up_map[tx_size] > TX_32X32 -> DCT_DCT` clamp | ||
| 110 | + (ours clamps at `side >= 32`, on the CHROMA side length -- check that against | ||
| 111 | + `av1_get_ext_tx_set_type`'s use of the chroma tx size). | ||
| 112 | + | ||
| 113 | +## Deferred | ||
| 114 | +* the 192x68 / 68x192 gate arm from r3's verifier ask: **deferred -- the gate it would join is | ||
| 115 | + still RED, a new arm would only add noise -- unblocked by the residue above.** The r3 code ask | ||
| 116 | + itself stays accepted-as-already-satisfied (`decode.rs` `read_var_tx_size`'s | ||
| 117 | + `blk_row >= max_h_mi || blk_col >= max_w_mi` early return, both inter callers pass | ||
| 118 | + `mi_cols/rows - at_mi`). | ||