diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 70738bdf..713c137a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6642,6 +6642,19 @@ fn read_coeffs_rect( }; grid[pos] = if negative { -level } else { level }; } + // lane-d792: the rect unit's LEVEL grid in row-major (w) order, the + // twin of the oracle's `EC_DQCOEFF` rung -- a residual mismatch whose + // grids differ is a reader defect, one whose grids agree is a transform + // defect. + if crate::envflags::env_flag!("EC_DQCOEFF") { + let nz: Vec = grid + .iter() + .enumerate() + .filter(|&(_, &v)| v != 0) + .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w)) + .collect(); + eprintln!("OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", nz.join(",")); + } Ok((Grid::Own(grid), tx_type)) } @@ -13648,6 +13661,17 @@ impl PlaneBuf<'_> { self.data.to_mut()[(y + row) * self.width + x + col] = sample; } } + // lane-d792: the RECONSTRUCTION rung beside `EC_PRED`'s prediction one + // -- a block whose prediction matches the oracle's but whose written + // samples do not is either a residual defect or a later overwrite, and + // only this print separates the two. + if crate::envflags::env_flag!("EC_PRED") { + let row0: Vec = + (0..bw.min(8)).map(|c| self.data[y * self.width + x + c]).collect(); + let col0: Vec = + (0..bh.min(8)).map(|r| self.data[(y + r) * self.width + x]).collect(); + eprintln!("OUR_RECON x={x} y={y} bw={bw} bh={bh} row0={row0:?} col0={col0:?}"); + } } /// Predicts under `mode` then adds `residual` (side*side, raster), diff --git a/crates/ec-av1/src/transform.rs b/crates/ec-av1/src/transform.rs index 36bfdef9..5b985e3b 100644 --- a/crates/ec-av1/src/transform.rs +++ b/crates/ec-av1/src/transform.rs @@ -3105,3 +3105,38 @@ mod lossless_tx_tests { } } } + +#[cfg(test)] +mod d792_tests { + /// lane-d792: ONE 16x8 DCT_DCT inverse against libaom's own numbers. + /// + /// The dequantized grid below is `EC_DQCOEFF`'s dump of the first + /// TX_16X8 unit of `$HOME/.cache/d792/small/f100.obu` (a rav1e + /// `speed=6 quantizer=100` encode of a 384x152 crop, whose bottom + /// straddle is where the reference-ladder decode failures live), in + /// libaom's own column-major `input[c * h + r]` order; the expected + /// residual is `aomdec`'s reconstruction of that block minus its + /// prediction (the two decoders' predictions are byte-identical there, + /// checked with the oracle's `EC_PREDOUT8` rung). + #[test] + fn a_16x8_inverse_matches_libaoms_own_dqcoeff_and_residual() { + const H: usize = 8; + const W: usize = 16; + // (libaom index, dequantized value). + const NZ: [(usize, i32); 17] = [ + (0, 1554), (1, -1768), (2, 624), (3, -104), (9, 104), (10, -520), (11, 312), + (16, -104), (17, 104), (18, -104), (24, -104), (25, 104), (27, -104), (32, 208), + (33, -104), (35, -104), (40, 104), + ]; + let mut grid = vec![0i32; W * H]; + for (i, v) in NZ { + let (r, c) = (i % H, i / H); + grid[r * W + c] = v; + } + let out = super::inverse_transform_2d_typed_wh(&grid, W, H, 8, super::TxType::DctDct); + let col0: Vec = (0..H).map(|r| out[r * W]).collect(); + let row0: Vec = out[..8].to_vec(); + assert_eq!(col0, vec![-7, -2, 6, 17, 27, 34, 36, 37], "column 0"); + assert_eq!(row0, vec![-7, -7, -6, -5, -2, 0, 1, -1], "row 0"); + } +} diff --git a/lanes/d792.report.md b/lanes/d792.report.md index 7bdff1c1..b50fc460 100644 --- a/lanes/d792.report.md +++ b/lanes/d792.report.md @@ -69,3 +69,61 @@ fewer `sign`/`base` ones (aom 23085 base / 7966 sign / 3338 br; ours 23634 / 7715 / 3351). First divergence is an extra `br` at trace line ~22951 of 44647. Next: resolve that line to its transform unit and read the rule that differs there. + +## Elimination chain (all measured on the 384x152 small repro, frame 0) + +The first differing sample is inside the luma block at `x=0 y=144`, a 16x8 +intra block in the bottom straddle (PARTITION_HORZ is forced there by the +frame edge). For that block: + +1. **Prediction: identical.** `OUR_PRED sum=6959 row0=[82,74,65,56,50,47,46,45] + col0=[82,85,85,85,85,85,85,85]` == the oracle's new `EC_PREDOUT8` line for + `mi_row=36 mi_col=4`(sic: `mi_col=0`), to the sample. +2. **Coefficient bitstream: in sync.** `EC_TRACE_COEFF`'s `all_zero` range + value agrees at ALL 750 transform units; `eob` agrees at all 514. +3. **Transform type: identical.** The oracle now prints the resolved + `txtype`/`txsize`; the 514-long sequence matches ours entry for entry. + All 19 TX_16X8 units are DCT_DCT. +4. **Transform unit shapes: identical.** Both decoders code 19 16x8, 27 8x4 + and 1 32x16 rectangular units (the oracle's new `EC_DQCOEFF` rung vs our + new `OUR_LEVELS` rung). +5. **Level grids: identical.** The first three 16x8 units' non-zero + (row/col, level) sets match the oracle's `EC_DQCOEFF` dump converted out + of libaom's column-major `input[c * h + r]` layout -- which also + re-verifies `SCAN_16X8` against `av1_default_scan_16x8`. +6. **The 16x8 inverse transform is correct.** New pin + `transform::d792_tests::a_16x8_inverse_matches_libaoms_own_dqcoeff_and_residual` + feeds our `inverse_transform_2d_typed_wh` libaom's own dequantized grid + and asserts libaom's own residual (`aomdec` reconstruction minus the + identical prediction): PASSES. +7. **The q index is frame-constant.** `aomdec`'s `current_base_qindex` is 127 + for all 1518 blocks of the 1920x792 key frame; no delta-q is in play. + +So the residual our decoder ADDS differs (ours `col0 = [-6,-3,4,13,21,26,28, +28]`, libaom's `[-7,-2,6,17,27,34,36,37]`, roughly a 0.77 factor) while the +levels, the shape, the type and the transform kernel all agree. The +remaining link is the DEQUANT step between them -- `dequant_and_inverse_typed_wh` +at the intra rect call sites (`decode.rs:9487/9543/9713/10826...`), where the +suspects are the `(w, h)` argument order (class `adjacent same-typed args`; +a transposed grid would weaken exactly the vertical response we see) and the +q index / DC-AC delta that site passes. + +## Instruments added this round + +* Oracle (`~/.cache/aom-oracle/src`, build2): `EC_PREDOUT8` on both 8-bit + prediction paths, `txtype=`/`txsize=` on the `tag=tx_type` rung, and + `EC_DQCOEFF` (the dequantized grid the inverse transform runs on). +* Ours: `OUR_RECON` (reconstructed row0/col0 beside `EC_PRED`'s prediction) + and `OUR_LEVELS` (a rect unit's level grid, `EC_DQCOEFF=1`). + +## NOT done this round (budget) + +* `deferred: the root cause and its fix -- the dequant link above is the one + unchecked step -- unblocked by dumping the dequantized grid at the rect + intra call site and diffing it against the oracle's EC_DQCOEFF line` +* `deferred: the libaom crf-5 "Golomb tail" refusal -- it does NOT reproduce + standalone at 046dbe0e (all four libaom points decode exact), so it needs + the gate arm itself re-run to confirm it is stale` +* `deferred: the synthetic straddling fixtures (384x152 / 384x184 gates), the + 1920x792 green arm, the suite and the workspace check -- they gate a fix + that does not exist yet`