Per-frame stage dumps + MC trace, and re-localise the 192x128 frame-2 mismatch to a 64x64 INTRA block
Browse files at this commitf8667591d0b96d704cc72d5801de77a54cef294dParent: fcf808d- fix
- per-frame stage dumps + MC trace, and re-localise the 192x128 frame-2 mismatch to a 64x64 INTRA block
6 changed files +147 -3
- crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu +0 -0
- crates/ec-av1/src/decode.rs +16 -3
- crates/ec-av1/src/mc.rs +8 -0
- crates/ec-av1/src/warp.rs +3 -0
- lanes/mc64-r1.handoff.md +29 -0
- lanes/mc64-r1.report.md +91 -0
crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+16 -3
| @@ -8836,10 +8836,19 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { | |||
| 8836 | /// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of | 8836 | /// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of |
| 8837 | /// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) -- | 8837 | /// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) -- |
| 8838 | /// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). | 8838 | /// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). |
| 8839 | +/// lane-mc64 r1: the decode-order index the stage dumps below key their file | ||
| 8840 | +/// name on. `PREFILT_PICTURE_IDX` is bumped once per frame just BEFORE the | ||
| 8841 | +/// deblock/CDEF stages run, so the frame being dumped here is `idx - 1` -- | ||
| 8842 | +/// without this every frame overwrote `.f0` and a per-frame bisection silently | ||
| 8843 | +/// compared the LAST decoded frame (ledger, class stale-output-faked-measurement). | ||
| 8844 | +fn stage_dump_idx() -> usize { | ||
| 8845 | + PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst).saturating_sub(1) | ||
| 8846 | +} | ||
| 8847 | + | ||
| 8839 | fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { | 8848 | fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { |
| 8840 | use std::io::Write; | 8849 | use std::io::Write; |
| 8841 | if let Ok(path) = std::env::var(var) | 8850 | if let Ok(path) = std::env::var(var) |
| 8842 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) | 8851 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", stage_dump_idx())) |
| 8843 | { | 8852 | { |
| 8844 | for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] { | 8853 | for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] { |
| 8845 | for row in 0..h { | 8854 | for row in 0..h { |
| @@ -8856,7 +8865,7 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, | |||
| 8856 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { | 8865 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { |
| 8857 | use std::io::Write; | 8866 | use std::io::Write; |
| 8858 | if let Ok(path) = std::env::var(var) | 8867 | if let Ok(path) = std::env::var(var) |
| 8859 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) | 8868 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", stage_dump_idx())) |
| 8860 | { | 8869 | { |
| 8861 | for p in [y, u, v] { | 8870 | for p in [y, u, v] { |
| 8862 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); | 8871 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); |
| @@ -16449,6 +16458,9 @@ fn decode_inter_block( | |||
| 16449 | let (cpx, cpy) = (px / 2, py / 2); | 16458 | let (cpx, cpy) = (px / 2, py / 2); |
| 16450 | let chroma_side = side / 2; | 16459 | let chroma_side = side / 2; |
| 16451 | let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); | 16460 | let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); |
| 16461 | + if std::env::var_os("EC_MC_TRACE").is_some() { | ||
| 16462 | + eprintln!("EC_IB px={px} py={py} side={side} w={write_w} h={write_h}"); | ||
| 16463 | + } | ||
| 16452 | 16464 | ||
| 16453 | if std::env::var_os("EC_AV1_TELL").is_some() { | 16465 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 16454 | eprintln!( | 16466 | eprintln!( |
| @@ -16501,9 +16513,10 @@ fn decode_inter_block( | |||
| 16501 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; | 16513 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 16502 | if std::env::var_os("EC_TRACE_MODE").is_some() { | 16514 | if std::env::var_os("EC_TRACE_MODE").is_some() { |
| 16503 | eprintln!( | 16515 | eprintln!( |
| 16504 | - "EC_MODE mi_row={} mi_col={} rng={}", | 16516 | + "EC_MODE mi_row={} mi_col={} is_inter={} skip={skip} rng={}", |
| 16505 | rmi, | 16517 | rmi, |
| 16506 | cmi, | 16518 | cmi, |
| 16519 | + is_inter as u8, | ||
| 16507 | dec.debug_state().0 | 16520 | dec.debug_state().0 |
| 16508 | ); | 16521 | ); |
| 16509 | } | 16522 | } |
crates/ec-av1/src/mc.rsmodified+8 -0
| @@ -345,6 +345,11 @@ pub fn predict_with_filters( | |||
| 345 | let xfrac = x_q4.rem_euclid(16) as usize; | 345 | let xfrac = x_q4.rem_euclid(16) as usize; |
| 346 | let y0 = y_q4.div_euclid(16); | 346 | let y0 = y_q4.div_euclid(16); |
| 347 | let yfrac = y_q4.rem_euclid(16) as usize; | 347 | let yfrac = y_q4.rem_euclid(16) as usize; |
| 348 | + if std::env::var_os("EC_MC_TRACE").is_some() && block_w >= 4 { | ||
| 349 | + eprintln!( | ||
| 350 | + "EC_MC_CALL x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} xfrac={xfrac} yfrac={yfrac} hk={h_kind:?} vk={v_kind:?} tw={true_width} th={true_height} stride={stride}" | ||
| 351 | + ); | ||
| 352 | + } | ||
| 348 | 353 | ||
| 349 | // Whole-pel fast path: `SUBPEL_FILTERS[0]` is the identity tap (`128` at | 354 | // Whole-pel fast path: `SUBPEL_FILTERS[0]` is the identity tap (`128` at |
| 350 | // its centre, everything else `0`), and both rounding shifts are exactly | 355 | // its centre, everything else `0`), and both rounding shifts are exactly |
| @@ -659,6 +664,9 @@ pub fn predict_compound_intermediate( | |||
| 659 | 664 | ||
| 660 | let y0 = y_q4.div_euclid(16); | 665 | let y0 = y_q4.div_euclid(16); |
| 661 | let yfrac = y_q4.rem_euclid(16) as usize; | 666 | let yfrac = y_q4.rem_euclid(16) as usize; |
| 667 | + if std::env::var_os("EC_MC_TRACE").is_some() { | ||
| 668 | + eprintln!("EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}"); | ||
| 669 | + } | ||
| 662 | 670 | ||
| 663 | let (v_wide, v_narrow) = v_kind.tables(); | 671 | let (v_wide, v_narrow) = v_kind.tables(); |
| 664 | let v_filter = if block_h <= 4 { | 672 | let v_filter = if block_h <= 4 { |
crates/ec-av1/src/warp.rsmodified+3 -0
| @@ -444,6 +444,9 @@ pub fn warp_affine( | |||
| 444 | subsampling_x: i32, | 444 | subsampling_x: i32, |
| 445 | subsampling_y: i32, | 445 | subsampling_y: i32, |
| 446 | ) { | 446 | ) { |
| 447 | + if std::env::var_os("EC_MC_TRACE").is_some() { | ||
| 448 | + eprintln!("EC_MC_WARP x={p_col} y={p_row} w={p_width} h={p_height}"); | ||
| 449 | + } | ||
| 447 | let bd = i32::from(crate::decode::bit_depth()); | 450 | let bd = i32::from(crate::decode::bit_depth()); |
| 448 | // `reduce_bits_vert`, non-compound: `2 * FILTER_BITS - round_0`. | 451 | // `reduce_bits_vert`, non-compound: `2 * FILTER_BITS - round_0`. |
| 449 | let reduce_bits_vert = 2 * FILTER_BITS - REDUCE_BITS_HORIZ; | 452 | let reduce_bits_vert = 2 * FILTER_BITS - REDUCE_BITS_HORIZ; |
lanes/mc64-r1.handoff.mdadded+29 -0
| @@ -0,0 +1,29 @@ | |||
| 1 | +# lane-mc64 r1 handoff | ||
| 2 | + | ||
| 3 | +STREAM: `crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu` | ||
| 4 | +(md5 add55f625b6302c523455bb8662b19f5, sha256 e4cff46cb1700527c68efc866db27a2835705e949d646f73f0c9df577d594bd6). | ||
| 5 | +The r2 aomenc recipe does NOT regenerate it (measured: 19003 bytes md5 278be003743daed5ea116cd41056537a). Use the fixture. | ||
| 6 | + | ||
| 7 | +DEFECT, restated correctly: | ||
| 8 | +decode-order frame 2, superblock at px(128,64) = mi(16,32), `EC_PART_VAL bsize=12 value=0` | ||
| 9 | +(PARTITION_NONE 64x64), **INTRA block in an inter frame** (aomdec prints no EC_MODE/EC_IMODE | ||
| 10 | +for it because `read_intra_block_mode_info` is uninstrumented; ours prints | ||
| 11 | +`EC_MODE ... is_inter=0 skip=false`). Pre-deblock luma differs in exactly that 64x64 | ||
| 12 | +(3720/4096 samples, delta -12..+9), chroma bit-exact. Frames 0 and 1 exact. | ||
| 13 | +The charter's `mode=16 ref0=4 mv0=(-340,-116)` belongs to FRAME 1's mi(16,32), which is | ||
| 14 | +PARTITION_SPLIT there and decodes exactly. Do not chase MC: `EC_MC_TRACE=1` shows zero | ||
| 15 | +MC/warp/compound calls for this block. | ||
| 16 | + | ||
| 17 | +REPRO (both under systemd-run --user --scope -q -p MemoryMax=6G): | ||
| 18 | + EC_AV1_PREFILT_DUMP=<dir>/ref ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null <obu> | ||
| 19 | + EC_NOMEMGUARD=1 EC_AV1_PREFILT_DUMP=<dir>/our <target>/debug/examples/decode_probe <obu> | ||
| 20 | + cmp -l <dir>/ref.f2 <dir>/our.f2 | wc -l # 3720 | ||
| 21 | +Scratch scripts: ~/.cache/mc64-tmp/{cmp.sh,gen.sh,gen2.sh}. Decode stops at frame 3 with | ||
| 22 | +lane-intra64split's "a split intra strip whose transform unit is 64x32" refusal — unrelated. | ||
| 23 | + | ||
| 24 | +NEXT: luma-only + chroma-exact on a 64x64 intra block points at the 64-length luma transform. | ||
| 25 | +Bisect in this order: (1) TX_64X64 coefficient region (`av1_get_adjusted_tx_size` -> only the | ||
| 26 | +top-left 32x32 is coded) and its eob domain; (2) the 64-point inverse (`transform.rs:276` | ||
| 27 | +`hadamard` tail, `row_shift_wh(64,64) == 2`); (3) the 64x64 intra prediction itself. | ||
| 28 | +`transform.rs:1412 a_64x64_transform_keeps_what_fits_in_its_coded_quarter` is the existing | ||
| 29 | +64x64 self-check — it passes, so whatever is wrong is outside its span. | ||
lanes/mc64-r1.report.mdadded+91 -0
| @@ -0,0 +1,91 @@ | |||
| 1 | +# lane-mc64 r1 — RED (charter premise disproved; real defect re-localised) | ||
| 2 | + | ||
| 3 | +## Verdict | ||
| 4 | +RED. The charter's defect description is wrong in its central fact: the | ||
| 5 | +mismatching block is **not** an inter NEWMV block off GOLDEN with a half-pel | ||
| 6 | +mv. It is a **64x64 INTRA block inside an inter frame** (no motion | ||
| 7 | +compensation happens for it in either decoder), so every one of the charter's | ||
| 8 | +six candidate causes (a)..(f) is about a code path this block never enters. | ||
| 9 | +No fix shipped; the lane is re-pointed, with the measurement chain below. | ||
| 10 | + | ||
| 11 | +## Premise re-measurement (all commands run this round) | ||
| 12 | +Stream pinned as `crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu` | ||
| 13 | +(byte-identical to the r2 scratch `s48.obu`, md5 `add55f625b6302c523455bb8662b19f5`, | ||
| 14 | +sha256 `e4cff46cb1700527c68efc866db27a2835705e949d646f73f0c9df577d594bd6`). | ||
| 15 | + | ||
| 16 | +The r2 recipe **does not regenerate it**: re-running the gate's exact aomenc | ||
| 17 | +argv (attempt 6 => seed 48, 192x128, `--cpu-used=2 --cq-level=40`, mandelbrot | ||
| 18 | +`start_scale=4.64`) on the identical y4m (md5 `6de0c8c6c3ff90715b476d966c622932`, | ||
| 19 | +hashed twice) yields a 19003-byte stream md5 `278be003743daed5ea116cd41056537a`, | ||
| 20 | +not the 26321-byte `s48.obu`. Both file-output and the gate's stdin/stdout form | ||
| 21 | +give the same 19003-byte result. So `s48.obu` came from some *other* r2 scratch | ||
| 22 | +invocation; the .obu is therefore pinned as a fixture instead of as a recipe. | ||
| 23 | + | ||
| 24 | +EVIDENCE: ~/.cache/mc64-tmp/{gen.sh,gen2.sh,g48.obu,g48b.obu,s48.obu} | ffmpeg lavfi -> aomenc twice, file and pipe forms | md5 278be00... twice vs pinned add55f6..., sizes 19003 vs 26321 | ||
| 25 | + | ||
| 26 | +Mismatch itself reproduces exactly as reported: | ||
| 27 | +EVIDENCE: ~/.cache/mc64-tmp/{A.ref.f0..f2,A.our.f0..f2} | aomdec EC_AV1_PREFILT_DUMP vs our EC_AV1_PREFILT_DUMP on the pinned obu | frame 0 diff 0, frame 1 diff 0, frame 2 luma diff 3720 confined to x 128..191 y 64..127, chroma diff 0 | ||
| 28 | + | ||
| 29 | +## ROOT LOCALISATION — the block is intra, not inter | ||
| 30 | +1. `aomdec EC_TRACE=1 EC_TRACE_MODE=1` interleaved: the frame-2 superblock at | ||
| 31 | + mi(16,32) reads `EC_PART_VAL mi_row=16 mi_col=32 bsize=12 value=0` | ||
| 32 | + (PARTITION_NONE, 64x64) and then **no `EC_MODE` and no `EC_IMODE` line at | ||
| 33 | + all** — the next trace line is the following frame's first `EC_PART` | ||
| 34 | + (`tell=1`). | ||
| 35 | +2. Oracle source, `av1/decoder/decodemv.c:1698-1710`: `read_inter_frame_mode_info` | ||
| 36 | + prints `EC_MODE` only from `read_inter_block_mode_info`; the | ||
| 37 | + `read_intra_block_mode_info` arm (intra block in an inter frame) is | ||
| 38 | + **uninstrumented**. Silence there means `inter_block == 0`, not "no block". | ||
| 39 | +3. Our decoder agrees: `EC_MODE mi_row=16 mi_col=32 is_inter=0 skip=false` | ||
| 40 | + with `EC_IB px=128 py=64 side=64 w=64 h=64`, and **zero** MC / warp / | ||
| 41 | + compound calls for it (`EC_MC_TRACE` instruments `mc::predict_with_filters`, | ||
| 42 | + `mc::predict_compound_intermediate` and `warp::warp_affine`; 33 MC calls in | ||
| 43 | + the whole decode, none at this block). | ||
| 44 | +4. The charter's `mode=16 ref0=4 mv0=(-340,-116)` line is real but belongs to | ||
| 45 | + **decode-order frame 1**, where mi(16,32) is `EC_PART_VAL bsize=12 value=3` | ||
| 46 | + (SPLIT) into four 32x32 blocks. Frame 1 is pixel-exact for us. This is the | ||
| 47 | + class `[[dump-not-call-unique]]` / `[[stale-output-faked-measurement]]` | ||
| 48 | + again: a coordinate-keyed grep with no frame key picked the wrong call. | ||
| 49 | + | ||
| 50 | +EVIDENCE: ~/.cache/mc64-tmp/{aom_both.log,aom_part.log,mct4.log} | aomdec EC_TRACE+EC_TRACE_MODE and our EC_MC_TRACE on the pinned obu | frame-2 mi(16,32) = PARTITION_NONE 64x64 with no mode trace line; ours is_inter=0, 0 MC calls; frame-1 mi(16,32) = PARTITION_SPLIT, that is where mv=(-340,-116) lives | ||
| 51 | + | ||
| 52 | +## What the defect actually is (direction, not yet a fix) | ||
| 53 | +A 64x64 **intra** block in an inter frame: luma wrong by -12..+9 over 3720 of | ||
| 54 | +4096 samples, chroma (32x32, TX_32X32) bit-exact. Luma is the only plane with a | ||
| 55 | +64-length transform, and `av1_get_adjusted_tx_size` codes only the top-left | ||
| 56 | +32x32 of a TX_64X64. So the suspects are, in order: the TX_64X64 coefficient | ||
| 57 | +region / eob domain, the 64-point inverse transform's row/col zeroing, and the | ||
| 58 | +intra prediction of a 64x64 block. The error is structured, not a constant | ||
| 59 | +offset, which argues residual over prediction — 376 of 4096 samples are equal, | ||
| 60 | +so it is not a wholesale desync either. | ||
| 61 | + | ||
| 62 | +## What changed | ||
| 63 | +* `crates/ec-av1/src/decode.rs` — `stage_dump_idx()`; `dump_stage`/`dump_stage16` | ||
| 64 | + now key their file on the decode-order picture index instead of always | ||
| 65 | + writing `.f0`. Before this, `EC_AV1_POSTDEBLOCK_DUMP`/`POSTCDEF_DUMP` compared | ||
| 66 | + the LAST decoded frame no matter which frame you meant (the ledger records | ||
| 67 | + this for the pre-8c6065e prefilt dump; the postdeblock/postcdef twins were | ||
| 68 | + never fixed). This is a real instrument defect, fixed, not a workaround. | ||
| 69 | +* `crates/ec-av1/src/decode.rs` — `EC_MC_TRACE` prints `EC_IB px py side w h` | ||
| 70 | + at `decode_inter_block` entry; `EC_MODE` now carries `is_inter=` and `skip=`. | ||
| 71 | +* `crates/ec-av1/src/mc.rs`, `crates/ec-av1/src/warp.rs` — `EC_MC_TRACE` prints | ||
| 72 | + `EC_MC_CALL` / `EC_MC_COMP` / `EC_MC_WARP` with the q4 position, block size, | ||
| 73 | + subpel fractions and resolved kernels. Placed BEFORE the whole-pel fast path | ||
| 74 | + so a block that takes no MC call at all is visible as an absence. | ||
| 75 | +* `crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu` — the stream, | ||
| 76 | + pinned (`git add -f`), because its recipe does not reproduce it. | ||
| 77 | + | ||
| 78 | +## Refusals | ||
| 79 | +None lifted, none added. No gate added: a gate asserting a counter for a shape | ||
| 80 | +whose cause is unidentified would be theatre, and the charter's counter | ||
| 81 | +("64x64 NEWMV single-ref blocks with half-pel mvs") counts a population this | ||
| 82 | +defect is not in. | ||
| 83 | +deferred(root cause): the gate — needs the TX_64X64-vs-prediction split below. | ||
| 84 | + | ||
| 85 | +## Residue | ||
| 86 | +* fix-now (r2): split prediction from residual for frame-2 mi(16,32) by | ||
| 87 | + reconstructing the block with the residual forced to zero and comparing the | ||
| 88 | + *shape* of the error; then bisect TX_64X64 (adjusted 32x32 coefficient | ||
| 89 | + region, eob domain, `row_shift_wh(64,64)==2`, the 64-point `hadamard` tail at | ||
| 90 | + `transform.rs:276`) against `EC_TRACE_COEFF` from the oracle. | ||
| 91 | +* accepted: the r2 recipe is not reproducible; the .obu is a fixture now. | ||