forge
Explore
Log in

Don't you dare go Hollow

wip(part32): pin decode_block_rect64's block2 defect to a scan-table mismatch

Browse files at this commit

f9547e32fc67bae11fec4536edad2b97bd844ad5Ahmet Kaan GümüşParent: c3dde3f
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.rsmodified+9 -0
@@ -5681,6 +5681,11 @@ fn apply_deblock(
5681 frame_width: usize,5681 frame_width: usize,
5682 frame_height: usize,5682 frame_height: usize,
5683 ) {5683 ) {
5684+ // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel
5685+ // mismatch between the raw reconstruction and post-filter output.
5686+ if std::env::var_os("EC_AV1_DEBUG_SKIP_DEBLOCK").is_some() {
5687+ return;
5688+ }
5684 if lf.level[0] != 0 || lf.level[1] != 0 {5689 if lf.level[0] != 0 || lf.level[1] != 0 {
5685 deblock_plane(y, 0, lf, n, frame_width, frame_height);5690 deblock_plane(y, 0, lf, n, frame_width, frame_height);
5686 }5691 }
@@ -6298,6 +6303,10 @@ fn apply_cdef(
6298 cdef: &CdefParams,6303 cdef: &CdefParams,
6299 skip_grid: &Neighbours,6304 skip_grid: &Neighbours,
6300 ) {6305 ) {
6306+ // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.
6307+ if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() {
6308+ return;
6309+ }
6301 // `cdef.bits == 0` still means "no filtering at all" whenever the single6310 // `cdef.bits == 0` still means "no filtering at all" whenever the single
6302 // (index 0) strength pair is all-zero -- the fast path every existing6311 // (index 0) strength pair is all-zero -- the fast path every existing
6303 // gate stream takes. A `bits > 0` frame can still be all-zero-strength6312 // gate stream takes. A `bits > 0` frame can still be all-zero-strength
crates/ec-av1/src/stream.rsmodified+53 -0
@@ -9512,6 +9512,59 @@ mod tests {
9512 );9512 );
9513 }9513 }
9514 9514
9515+ /// lane-part32 r2: prints the exact mismatch geometry (block coords,
9516+ /// got/want pixels) of the pinned seed-42 stream captured off
9517+ /// `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`
9518+ /// via `EC_AV1_GATE_DUMP`. Debug-only, `#[ignore]`d.
9519+ #[test]
9520+ #[ignore = "debug harness, run manually with EC_AV1_GATE_DUMP_PIN"]
9521+ fn debug_part32_r2_sbpart_pin_mismatch_geometry() {
9522+ let path = std::env::var("EC_AV1_GATE_DUMP_PIN").expect("set EC_AV1_GATE_DUMP_PIN");
9523+ let stream = std::fs::read(&path).expect("read pinned stream");
9524+ let frames = decode_stream(&stream).expect("pinned stream must decode");
9525+ if let Ok(dump) = std::env::var("EC_DEBUG_DUMP_Y") {
9526+ let bytes: Vec<u8> = frames[0].y.iter().map(|&v| v as u8).collect();
9527+ std::fs::write(&dump, bytes).expect("write y dump");
9528+ }
9529+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 192, 128, 1);
9530+ let got = &frames[0];
9531+ let want = &ffmpeg_frames[0];
9532+ let width = 192usize;
9533+ let mut n = 0;
9534+ let (mut min_x, mut max_x, mut min_y, mut max_y) = (width, 0, 128, 0);
9535+ for y in 0..128usize {
9536+ for x in 0..width {
9537+ let idx = y * width + x;
9538+ if got.y[idx] != want.y[idx] {
9539+ n += 1;
9540+ min_x = min_x.min(x);
9541+ max_x = max_x.max(x);
9542+ min_y = min_y.min(y);
9543+ max_y = max_y.max(y);
9544+ }
9545+ }
9546+ }
9547+ eprintln!(
9548+ "total luma mismatches: {n} bbox x=[{min_x},{max_x}] y=[{min_y},{max_y}] frame=192x128"
9549+ );
9550+ for y in 0..128usize {
9551+ let mut row_first = None;
9552+ let mut row_count = 0;
9553+ for x in 0..width {
9554+ let idx = y * width + x;
9555+ if got.y[idx] != want.y[idx] {
9556+ if row_first.is_none() {
9557+ row_first = Some(x);
9558+ }
9559+ row_count += 1;
9560+ }
9561+ }
9562+ if let Some(fx) = row_first {
9563+ eprintln!("row {y}: first mismatch x={fx} count={row_count}");
9564+ }
9565+ }
9566+ }
9567+
9515 /// lane-rect64q r1: same recipe as9568 /// lane-rect64q r1: same recipe as
9516 /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]9569 /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]
9517 /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is9570 /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is