From f9547e32fc67bae11fec4536edad2b97bd844ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 20:42:05 +0300 Subject: [PATCH] wip(part32): pin decode_block_rect64's block2 defect to a scan-table mismatch Debug harness (debug_part32_r2_sbpart_pin_mismatch_geometry, #[ignore]d) plus two env-gated filter bypasses (EC_AV1_DEBUG_SKIP_DEBLOCK/CDEF, off by default) added to bisect a_real_aomenc_stream_with_a_superblock_level_ horz_vert_partition_decodes_pixel_exact's seed-42 failure. Findings, all measured on THIS tree (not inherited from round 1 or lane-rect64q): - Reproduces: 266 passed, 1 failed, same as the trial merge. - Pre-filter reconstruction (deblock+CDEF both disabled on our side) matches the aom-oracle's own EC_AV1_PREFILT_DUMP pixel-for-pixel through the end of SB(1,0)'s first VERT-64 sub-block (px=64..95, all-zero DC, correct). First divergence is (96,0): oracle=81, ours=76 -- exactly the first pixel of the SECOND VERT-64 sub-block (px=96, mi_c=24), which has real coefficients (eob_nonzero=true). Deblock/CDEF are proven NOT the cause (mismatch persists identically with both disabled). - msac RANGE ladder (EC_TRACE_COEFF/EC_AV1_TRACE vs oracle's rung 2/4): ranges agree exactly up to and including the `rng=63764` entering this block's luma coefficient read. Both sides read eob=6. But the oracle's per-step trace assigns nonzero level=1 to scan positions (indices) 0, 1, 2, 4, 5; ours reads real (row,col) pairs (0,0) (0,1) (1,0) (2,0) (1,1) (0,2) via `scan32 = default_scan(TX32)` -- the plain square 32x32 scan. The two do not correspond to the same physical layout, and the range diverges within this same coefficient read (37896 after, vs the oracle's 46344) -- an in-block entropy desync, not a post-processing or dequant bug. - Root-cause hypothesis (not yet landed): AV1's real scan-table selection for a truncated-corner VERT-64 (TX_32X64/TX_64X32) block is NOT the same physical scan as a genuine square TX_32X32 -- spec names a distinct Default_Scan_32x64/64x32 table, same shape as this file's own `NZ_MAP_CTX_OFFSET_32X64`/`_64X32` split fixed at lane-sbpart r8 for the *context* table; the *scan order* itself needs the same treatment and hasn't had it. `decode_block_rect64`'s `scan32 = default_scan(TX32)` at crates/ec-av1/src/decode.rs:3559 is the call site; needs a real SCAN_32X64/SCAN_64X32 table (1024-entry, truncated-corner) ported from libaom's `av1_scan_orders[TX_32X64]`/`[TX_64X32]`, selected the same way `chroma_scan` already is a few lines below (bw==64 ? ... : ...). NOT fixed this round -- turn budget spent on entropy-layer localization (charter's own step 2), out of runway to safely port and verify a new 1024-entry table. HEAD still red on the target gate; committing per this repo's "landing red on the lane is fine" rule. --- crates/ec-av1/src/decode.rs | 9 +++++++ crates/ec-av1/src/stream.rs | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index f8d7e0cc..c8d0bf28 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5681,6 +5681,11 @@ fn apply_deblock( frame_width: usize, frame_height: usize, ) { + // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel + // mismatch between the raw reconstruction and post-filter output. + if std::env::var_os("EC_AV1_DEBUG_SKIP_DEBLOCK").is_some() { + return; + } if lf.level[0] != 0 || lf.level[1] != 0 { deblock_plane(y, 0, lf, n, frame_width, frame_height); } @@ -6298,6 +6303,10 @@ fn apply_cdef( cdef: &CdefParams, skip_grid: &Neighbours, ) { + // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling. + if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() { + return; + } // `cdef.bits == 0` still means "no filtering at all" whenever the single // (index 0) strength pair is all-zero -- the fast path every existing // gate stream takes. A `bits > 0` frame can still be all-zero-strength diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 9f05fa43..94e56e1c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -9512,6 +9512,59 @@ mod tests { ); } + /// lane-part32 r2: prints the exact mismatch geometry (block coords, + /// got/want pixels) of the pinned seed-42 stream captured off + /// `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` + /// via `EC_AV1_GATE_DUMP`. Debug-only, `#[ignore]`d. + #[test] + #[ignore = "debug harness, run manually with EC_AV1_GATE_DUMP_PIN"] + fn debug_part32_r2_sbpart_pin_mismatch_geometry() { + let path = std::env::var("EC_AV1_GATE_DUMP_PIN").expect("set EC_AV1_GATE_DUMP_PIN"); + let stream = std::fs::read(&path).expect("read pinned stream"); + let frames = decode_stream(&stream).expect("pinned stream must decode"); + if let Ok(dump) = std::env::var("EC_DEBUG_DUMP_Y") { + let bytes: Vec = frames[0].y.iter().map(|&v| v as u8).collect(); + std::fs::write(&dump, bytes).expect("write y dump"); + } + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 192, 128, 1); + let got = &frames[0]; + let want = &ffmpeg_frames[0]; + let width = 192usize; + let mut n = 0; + let (mut min_x, mut max_x, mut min_y, mut max_y) = (width, 0, 128, 0); + for y in 0..128usize { + for x in 0..width { + let idx = y * width + x; + if got.y[idx] != want.y[idx] { + n += 1; + min_x = min_x.min(x); + max_x = max_x.max(x); + min_y = min_y.min(y); + max_y = max_y.max(y); + } + } + } + eprintln!( + "total luma mismatches: {n} bbox x=[{min_x},{max_x}] y=[{min_y},{max_y}] frame=192x128" + ); + for y in 0..128usize { + let mut row_first = None; + let mut row_count = 0; + for x in 0..width { + let idx = y * width + x; + if got.y[idx] != want.y[idx] { + if row_first.is_none() { + row_first = Some(x); + } + row_count += 1; + } + } + if let Some(fx) = row_first { + eprintln!("row {y}: first mismatch x={fx} count={row_count}"); + } + } + } + /// lane-rect64q r1: same recipe as /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`] /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is