diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index f4c0a011..6c2fe797 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1849,6 +1849,20 @@ pub(crate) fn wii_hits() -> usize { WII_HITS.with(|c| c.get()) } +// lane-sbrect10 r1: how many INTRA blocks read `uv_mode` off the 13-symbol +// NO-CFL alphabet *because their size excludes CFL* (libaom `is_cfl_allowed`: +// wide <= 32 && high <= 32). The witness that a gate stream really carries a +// 64-axis intra block -- the shape whose 14-symbol read desynced every inter +// frame carrying one. +thread_local! { + static NOCFL_UV_MODE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`NOCFL_UV_MODE_HITS`]. +pub(crate) fn nocfl_uv_mode_hits() -> usize { + NOCFL_UV_MODE_HITS.with(|c| c.get()) +} + // lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC // blend -- the gate's proof that `--enable-obmc=1` reached this shape (the // r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented @@ -5541,6 +5555,19 @@ fn read_intra_mode_rect( } }; } + // lane-sbrect10 r1: libaom `is_cfl_allowed` (blockd.h) is + // `block_size_wide <= 32 && block_size_high <= 32` -- enforce it HERE, at + // the one point every rect caller routes through, so no call site can + // offer the 14-symbol CFL alphabet on a 64-axis block (class + // wrong-alphabet-same-value: same value, wrong interval, silent desync). + // This funnel covers the lane-intra14 intra-1:4-in-inter callers too: they + // reach their chroma through this same reader, never a private CFL read. + let cfl = if cfl && bw.max(bh) > 32 { + NOCFL_UV_MODE_HITS.with(|c| c.set(c.get() + 1)); + false + } else { + cfl + }; // lane-intra14 r1: on the INTER block path everything up to and including // `is_inter` was already read by [`decode_inter_block`], so this reader // starts at the mode syntax with the `skip` that caller read. @@ -8594,6 +8621,14 @@ fn read_intra_mode( } }; } + // lane-sbrect10 r1: `is_cfl_allowed`'s <=32 bound, enforced at the single + // point every square caller routes through (see `read_intra_mode_rect`). + let cfl = if cfl && side > 32 { + NOCFL_UV_MODE_HITS.with(|c| c.set(c.get() + 1)); + false + } else { + cfl + }; // spec 5.11.6 `intra_frame_mode_info`: `intra_segment_id` is read BEFORE // `skip` when `SegIdPreSkip`, and after it otherwise. let (seg_w_mi, seg_h_mi) = (side / 4, side / 4); @@ -8937,8 +8972,13 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { /// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { use std::io::Write; + // lane-sbrect10 r2: index the dump by decode-order picture like + // EC_AV1_PREFILT_DUMP already does -- a fixed `.f0` name kept only the + // LAST frame, so a mid-sequence divergence could not be read out at all. + static STAGE16_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); if let Ok(path) = std::env::var(var) - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) + && let idx = STAGE16_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { 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))] { for row in 0..h { @@ -18673,6 +18713,12 @@ fn decode_inter_block( return Ok(()); } let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]); + if std::env::var_os("EC_IIS").is_some() { + eprintln!( + "TRACE iis px={px} py={py} side={side} w={write_w} h={write_h} sg={} mode={mode} skip={skip}", + size_group_wh(write_w, write_h) + ); + } if mode >= 13 { return Err(unsupported( "an intra mode this decoder does not code (round 2)", @@ -18701,13 +18747,27 @@ fn decode_inter_block( // directional intra-in-inter block was refused above. let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); - let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); + // lane-sbrect10 r1 (class wrong-alphabet-same-value, second instance + // after lane-sbpart r3's rect strips): `is_cfl_allowed` (libaom + // `blockd.h` -- `block_size_wide[bsize] <= 32 && block_size_high[bsize] + // <= 32`, spec 5.11.5) caps CFL at 32x32, so a 64x64 intra block inside + // an INTER frame reads the 13-symbol `uv_mode_no_cfl` alphabet. Reading + // the 14-symbol CFL one gave the same DC_PRED VALUE but narrowed the + // arithmetic coder by the wrong interval, desyncing the tile from this + // block on. + let cfl_allowed = write_w.max(write_h) <= 32; + if !cfl_allowed { + NOCFL_UV_MODE_HITS.with(|c| c.set(c.get() + 1)); + } + let uv_mode = if cfl_allowed { + dec.symbol(&mut cdfs.uv_mode_cfl[mode]) + } else { + dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) + }; if (9..=12).contains(&uv_mode) { SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); } - let alpha = if uv_mode == DC_PRED { - None - } else if uv_mode == UV_CFL_PRED { + let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED { Some(read_cfl_alphas(dec, cdfs)) } else { None @@ -21138,10 +21198,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // instead of silently decoding as SPLIT and desyncing. let part64 = match (has_cols, has_rows) { (true, true) => { + let pre_rng = dec.debug_state().0; let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( - "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}", + "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", sb_r * SB_MI, sb_c * SB_MI ); diff --git a/crates/ec-av1/src/motion_field.rs b/crates/ec-av1/src/motion_field.rs index 330a5e97..ac29d6fa 100644 --- a/crates/ec-av1/src/motion_field.rs +++ b/crates/ec-av1/src/motion_field.rs @@ -442,6 +442,15 @@ pub fn setup_motion_field( ); } + if std::env::var_os("EC_TRACE_TPL").is_some() { + eprintln!("EC_TPL_FIELD oh={cur_order_hint} rows={rows} cols={cols}"); + for r in 0..rows { + let row: String = (0..cols) + .map(|c| if cells[r * cols + c].is_some() { '#' } else { '.' }) + .collect(); + eprintln!("EC_TPL_FIELD r{r} {row}"); + } + } TplField { cols, rows, cells } } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index f64b4fa7..e3ff5a2c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -6988,13 +6988,16 @@ mod tests { // refusal it names is GONE (this round codes a 64-px transform axis as // its truncated low-32 corner), and a 10-bit sweep of this exact // recipe now reaches the arm -- 2 pixel-exact attempts, 2 64x32 and 2 - // 32x64 strips, 2 of them carrying a coded 64-axis residual. It stays - // 8-bit here for a DIFFERENT, newly exposed reason: 10-bit attempt 14 - // (cq 61, horizontal split, motion step 12) mismatches ffmpeg while - // decoding ZERO superblock-level rect strips and zero 64-axis - // residual units, i.e. a defect of some other shape that this gate - // must not absorb. See lanes/r14-r2.report.md. - for bit_depth in [8u32] { + // 32x64 strips, 2 of them carrying a coded 64-axis residual. + // lane-sbrect10 r1 closed the newly exposed 10-bit defect r14 r2 + // parked this arm on (10-bit attempt 14, cq 61, horizontal split, + // motion step 12 -- it mismatched ffmpeg while decoding ZERO rect + // strips): a 64x64 INTRA block inside an inter frame read `uv_mode` + // off the 14-symbol CFL-allowed alphabet, which libaom's + // `is_cfl_allowed` caps at 32x32 -- same DC_PRED value, wrong + // interval narrowing, tile desynced from that block on. Both depths + // run now. + for bit_depth in [8u32, 10u32] { let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = (0u32, 0u32, 0u32, 0u32); let (mut horz_proved, mut vert_proved) = (0usize, 0usize); @@ -7149,6 +7152,337 @@ mod tests { } } + /// lane-sbrect10 r1: a 64x64 INTRA block inside an INTER frame, whose + /// `uv_mode` alphabet libaom's `is_cfl_allowed` (`blockd.h`: `wide <= 32 + /// && high <= 32`) narrows to the 13-symbol NO-CFL table. Reading the + /// 14-symbol CFL one produced the same `DC_PRED` value with the wrong + /// interval narrowing, so the tile desynced from that block on and the + /// frame decoded silently wrong (class `wrong-alphabet-same-value`; found + /// as the "another shape" mismatch the superblock rect gate above had to + /// park its 10-bit arm on). + /// + /// The counter `nocfl_uv_mode_hits` proves the shape fired in EVERY + /// compared attempt, and every decode-order frame is compared against + /// ffmpeg -- an attempt that mismatches fails, it never SKIPs. + /// + /// lane-sbrect10 r2: with the half-random source below this gate also + /// covers a SECOND defect it exposed at 10-bit cq 58/61 -- the compound + /// MV stack's extension pass zero-filled the `comp_list` tail slots + /// libaom fills with each side's GLOBAL MOTION vector + /// (`combine_compound_candidates`, mvref_common.c:723-729). A compound + /// block with no usable neighbour pair (frame top row, intra block to + /// its left, empty temporal field) then took a `(0, 0)` predictor + /// instead of the frame's translation: 32890/39907 wrong luma samples + /// on decode-order frame 2 with the entropy stream still in sync. + #[test] + fn a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet() { + const NAME: &str = + "a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 6usize); + for bit_depth in [8u32, 10u32] { + let (mut named_refusals, mut matched, mut carried_none) = (0u32, 0u32, 0u32); + let mut total_hits = 0usize; + for attempt in 0..16u32 { + // The sibling superblock-rect gate's own grid (its 10-bit + // attempt 14 -- cq 61, horizontal split, motion step 12 -- is + // the stream that exposed the defect); which superblock the RD + // hands an intra 64x64 block moves with the quantiser and the + // depth, so both orientations x four quantisers x two motion + // steps run here too. + let vertical_split = attempt % 2 == 1; + let cq = [58, 52, 45, 61][(attempt / 2 % 4) as usize]; + let sp = 8 + (attempt / 8) * 4; + // Half ramp, half deterministic pseudo-noise: the flat "200" + // half of r1's source made aomenc code the right-hand + // superblocks skip, so at 8 bit no >32 intra block ever + // appeared (probed cq 45/52/58/61/63 = 0 hits). The textured + // half forces intra above 32x32 in an inter frame at BOTH + // depths, so both arms carry the shape. + let geq = if vertical_split { + format!( + "if(lt(Y,64), 40+mod(floor((X+N*{sp})/32)*90,200), mod((X*7+Y*13+N*97)*31,256))" + ) + } else { + format!( + "if(lt(X,128), 40+mod(floor((Y+N*{sp})/32)*90,200), mod((X*7+Y*13+N*97)*31,256))" + ) + }; + let duration = frame_count as f64 / 25.0; + let source = format!( + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ + geq=lum='{geq}',format=yuv420p" + ); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let cq_arg = format!("--cq-level={cq}"); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--enable-tx-size-search=0", "--lag-in-frames=0", + "--enable-rect-partitions=1", "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", "--min-partition-size=32", + "--max-partition-size=64", + "--obu", "-o", "-", "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = crate::decode::nocfl_uv_mode_hits(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ + attempt {attempt}): {msg}" + ); + named_refusals += 1; + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let hits = crate::decode::nocfl_uv_mode_hits() - before; + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + if hits == 0 { + // No 64-axis intra block in this stream: still compared + // (a mismatch here is a defect, never a pass), just not + // proof of this gate's shape. + carried_none += 1; + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + } + if hits > 0 { + matched += 1; + total_hits += hits; + } + } + eprintln!( + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ + attempts carrying a >32 intra block ({total_hits} no-CFL uv_mode reads), \ + {carried_none} attempts carried none" + ); + assert!( + matched > 0 && total_hits > 0, + "{NAME} ({bit_depth}-bit): no attempt decoded an intra block above 32x32, so the \ + no-CFL uv_mode alphabet was never exercised -- gate proved nothing \ + ({named_refusals} refusals, {carried_none} attempts carried none)" + ); + } + } + /// lane-sqdrift r2: the SQUARE-ONLY twin of the no-CFL `uv_mode` gate + /// above. With `--enable-rect-partitions=0` the encoder codes only + /// `PARTITION_NONE` and `PARTITION_SPLIT`, and on detailed content the RD + /// eventually hands one whole 64x64 superblock of an INTER frame to an + /// INTRA block -- `bsize == sb_size`, the one shape whose `uv_mode` must + /// come off the 13-symbol `uv_mode_no_cfl` alphabet because libaom's + /// `is_cfl_allowed` (`blockd.h`: `wide <= 32 && high <= 32`) excludes it. + /// + /// Before the fix this decoder read the 14-symbol CFL alphabet there: the + /// same `DC_PRED` value, a different interval, and the tile desynced from + /// that block on. r1 measured the damage on the pinned 192x128 stream + /// (sha256 `c6af4fb4...`): decode-order frames 0-3 pre-filter byte-exact, + /// frame 4 luma 3540 samples wrong over exactly the last superblock + /// (x 128..191, y 64..127), then 24k wrong by frame 7 -- and the decoder + /// did not even report a mismatch, it reported an intra-rect-strip refusal + /// read out of the already-desynced stream (class `refusal-from-own-desync`; + /// aomdec's own partition histogram over that stream is rect-free). + /// After the fix the same stream is byte-exact on all 8 frames. + /// + /// Distinct from the sibling gate: rect partitions OFF (so the 64x64 NONE + /// really is a whole superblock), `--min-partition-size=16`, natural + /// mandelbrot detail instead of a synthetic half-noise ramp, and 8 frames + /// of drift so a desync that survives one frame still fails here. Every + /// decode-order frame of every attempt is compared against ffmpeg, so a + /// mismatch of ANY shape fails; the gate never turns one into a SKIP. + #[test] + fn a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact() + { + const NAME: &str = "a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 8usize); + for bit_depth in [8u32, 10u32] { + let (mut named_refusals, mut matched, mut carried_none) = (0u32, 0u32, 0u32); + let mut total_hits = 0usize; + for attempt in 0..4u32 { + // r1's pinned recipe is (start_scale 4.76, cq 55); the other + // three points move the detail level and the quantiser, which + // is what moves WHICH superblock the RD codes intra. + let start_scale = ["4.76", "3.20"][(attempt % 2) as usize]; + let cq = [55, 45][(attempt / 2) as usize]; + let duration = frame_count as f64 / 25.0; + let source = format!( + "mandelbrot=size={width}x{height}:start_scale={start_scale}:\ + end_scale=0.004:end_pts=8:rate=25" + ); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-vf", "hue=s=0", + "-t", &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", + "-f", "yuv4mpegpipe", "-strict", "-1", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let cq_arg = format!("--cq-level={cq}"); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=1", + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, + "--lag-in-frames=0", "--auto-alt-ref=0", + "--kf-min-dist=1000", "--kf-max-dist=1000", + "--enable-rect-partitions=0", "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", "--min-partition-size=16", + "--max-partition-size=64", "--enable-tx-size-search=0", + "--enable-order-hint=0", "--enable-warped-motion=0", "--enable-obmc=0", + "--enable-masked-comp=0", "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", "--enable-filter-intra=0", + "--enable-smooth-intra=0", "--enable-paeth-intra=0", + "--enable-directional-intra=0", "--enable-angle-delta=0", + "--enable-cdef=0", "--enable-restoration=0", "--enable-palette=0", + "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", + "--obu", "-o", "-", "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = crate::decode::nocfl_uv_mode_hits(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ + attempt {attempt}): {msg}" + ); + named_refusals += 1; + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let hits = crate::decode::nocfl_uv_mode_hits() - before; + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + if hits == 0 { + carried_none += 1; + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); + } + if hits > 0 { + matched += 1; + total_hits += hits; + } + } + eprintln!( + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ + attempts carrying a 64x64 intra superblock ({total_hits} no-CFL uv_mode reads), \ + {carried_none} attempts carried none" + ); + assert!( + matched > 0 && total_hits > 0, + "{NAME} ({bit_depth}-bit): no square-only attempt decoded a 64x64 intra block \ + inside an inter frame, so the no-CFL uv_mode alphabet was never exercised -- \ + gate proved nothing ({named_refusals} refusals, {carried_none} carried none)" + ); + } + } + /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs diff --git a/lanes/sbrect10-r1.handoff.md b/lanes/sbrect10-r1.handoff.md new file mode 100644 index 00000000..ebda6ab1 --- /dev/null +++ b/lanes/sbrect10-r1.handoff.md @@ -0,0 +1,81 @@ +# lane-sbrect10 r1 handoff (turn cap) + +Branch `lane-sbrect10` (worktree `/home/user/Documents/Code/Rust/edith_codecs-sbrect10`), +based on lane-r14 a2e2e29 with `main` (7a47fc1) merged in cleanly (merge commit in history). + +## STATUS: root cause FOUND and FIXED; sibling gate GREEN both depths; the new dedicated gate +## still needs an 8-bit fixture (its 8-bit arm currently FAILS "gate proved nothing"). + +## Pinned stream +`$HOME/.cache/sbrect10/a14.obu`, sha256 (hashed twice, identical) +`e85d3b84180de05cd7af769daa7b4f0662389fe0cbf5f0dc8119e4a036b6cf44`. +Regenerate: `bash $HOME/.cache/sbrect10/gen.sh ` (192x128, 6 frames, cq 61, 10-bit, +horizontal split geq, motion step 12 = the sibling gate's 10-bit attempt 14). + +## First mismatch (before the fix) +decode-order frame 2 (display == decode order, `--lag-in-frames=0`), plane Y, 15973/24576 luma +samples + 874 V; frames 0 and 1 exact. Per-64x64-SB wrong-pixel map row0 = [128, 332, 3931], +row1 = [3912, 3728, 3942]; SB(0,0)'s 128 are rows 62-63 only (deblock bleed from below). + +## Range ladder (EC_TRACE_MODE / EC_TRACE_MODE_STEP / EC_TRACE_COEFF / EC_AV1_TELL vs +## instrumented aomdec `~/.cache/aom-oracle/build/aomdec`) +- Partition symbols: 40/40 identical (values + positions) -> no rect strips anywhere, every + inter SB is PARTITION_NONE 64x64. Confirms the sibling gate's "zero rect strips" note. +- Our `TELL label=post_interp_filter range=` equals aomdec's `EC_MODE_VAL ... rng=` for every + inter block up to the divergence (frame 2 block mi(0,16): both 61730). Mode info in sync. +- First diverging element: frame 2, block mi_row=0 mi_col=32 (SB(0,2), x=128..191), which BOTH + decoders read as INTRA inside an inter frame (`is_inter=false`, our TELL post_is_inter + range=42400). aomdec then reads its luma TU with entry rng=38192 and all_zero=1; ours reached + all_zero=0 at rng=63221 with eob=56 -> desync inside that block's intra mode syntax. +- Root cause: `uv_mode` was read off the 14-symbol CFL-allowed CDF (`cdfs.uv_mode_cfl`) on a + 64x64 block. libaom `is_cfl_allowed` (blockd.h, spec 5.11.5) = `block_size_wide <= 32 && + block_size_high <= 32`, so the real alphabet is the 13-symbol `uv_mode_no_cfl`. Same DC_PRED + VALUE, wrong interval narrowing -> silent desync (class `wrong-alphabet-same-value`, second + instance after lane-sbpart r3). + +## Fix (committed) +- `crates/ec-av1/src/decode.rs` intra-in-inter block path: `cfl_allowed = write_w.max(write_h) + <= 32`, picks `uv_mode_no_cfl`, and gates the `cfl_alphas` read. +- Same rule enforced ONCE at the head of `read_intra_mode_rect` and `read_intra_mode` + (`let cfl = cfl && bw.max(bh) <= 32` / `side <= 32`), so no caller can offer CFL above 32. +- New counter `NOCFL_UV_MODE_HITS` / `decode::nocfl_uv_mode_hits()` fires exactly when the + size rule removed CFL. +- Result on the pinned stream: all 6 frames byte-identical to `ffmpeg -pix_fmt yuv420p10le` + (was [0,0,16847,23688,19028,17491] wrong samples). + +## Gates +- `a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` + flipped to `[8u32, 10u32]` and is GREEN: 8-bit 2 refusals / 4 pixel-exact carrying the arm / + 64x32=4 / 32x64=4 / 64-axis TUs=2 / 10 out-of-scope with 0 mismatches; 10-bit 2 refusals / + 2 carrying / 64x32=2 / 32x64=2 / 64-axis TUs=2 / 12 out-of-scope with 0 mismatches. +- NEW dedicated gate `a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet` + (stream.rs, just above the lane-inter4 32x32 rect gate): 16-attempt grid, both depths, every + decode-order frame compared, asserts `nocfl_uv_mode_hits` moved. 10-bit arm passes; the + **8-bit arm FAILS** ("no attempt decoded an intra block above 32x32") -- with the smooth + translating source aomenc never picks a >32 intra block in an inter frame at 8 bit + (probed cq 45/52/58/61/63, with and without `noise=all_seed=7:alls=30`: 0 hits every time). + +## Exact next step (measured, ready to paste) +Replace the gate's source with the half-random fixture, which DOES produce the shape at 8 bit: +`geq=lum='if(lt(X,128), 40+mod(floor((Y+N*12)/32)*90,200), mod((X*7+Y*13+N*97)*31,256))'` +Probe results (`$HOME/.cache/sbrect10/probe.sh `, counts >32 +intra-in-inter blocks and pixel diffs vs ffmpeg): + 8-bit cq52: 4 hits but DECODE-ERR (named refusal) | cq58: 2 hits, 0 pixel diffs | + cq61: 3 hits, 0 pixel diffs + 10-bit cq52: 6 hits, 0 diffs | cq58: 7 hits, **32890 diffs** | cq61: 7 hits, **39907 diffs** +So: use cq 58/61 for the 8-bit arm, cq 52 for the 10-bit arm, OR (better) treat the 10-bit +cq58/cq61 half-random mismatch as the NEXT defect of this lane -- it is a real, reproducible +10-bit failure on a stream this decoder does not refuse, and it is NOT the CFL bug (that one is +fixed). Triage it with the same ladder (EC_AV1_TELL post_interp_filter vs aomdec EC_MODE_VAL, +then EC_TRACE_COEFF entry ranges). +Then: full suite via +`systemd-run --user --unit=sbrect10-suite-$(date +%s) -p MemoryMax=10G --same-dir bash -lc 'EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbrect10 nice -n 10 cargo test -p ec-av1 --lib -j3 > $HOME/.cache/sbrect10-suite-r1.log 2>&1'` +(NOT run yet this round), then `lanes/sbrect10-r1.report.md`. + +## Ruled out +- Rect partitions / 64-axis residual: zero of both in the failing stream (partition trace 40/40 + identical), so the sibling gate's "another shape" note was correct. +- MV stack, motion_mode alphabet, interp filter, interintra: all exonerated by the + post_motion_mode / post_interp_filter range equality with aomdec on every block up to the + diverging one. +- Encoder-recipe doubt: stream hashes identical across two generations. diff --git a/lanes/sbrect10-r2.handoff.md b/lanes/sbrect10-r2.handoff.md new file mode 100644 index 00000000..ea9206bc --- /dev/null +++ b/lanes/sbrect10-r2.handoff.md @@ -0,0 +1,175 @@ +# lane-sbrect10 r2 handoff + +Branch `lane-sbrect10`, tip `2b9709c` (worktree +`/home/user/Documents/Code/Rust/edith_codecs-sbrect10`). +Commits this round: `3a9e83e` (merge main 18bf7dc) + `2b9709c` (the fix + gate + instrumentation). + +## STATUS: root cause FOUND and FIXED; pinned stream now byte-exact on all 6 probe arms. +## Only thing outstanding: the full suite result (armed, was at 340 tests / 0 failures). + +## 1. Merge state (done, clean) +`git merge --no-commit main` (main = 18bf7dc: r14 a2e2e29 + sb128 5ea5ec8) auto-merged +decode.rs + stream.rs with no conflicts. Verified before committing: +- `git diff main -- crates/ec-av1/src/cdf.rs` EMPTY and `... refusal_inventory.rs` EMPTY, so the + NZ_MAP / FILTER_INTRA rows and the refusal list are byte-identical to main. +- The only lines the merged tree removes vs main are the lane's own r1 hunks (4 `uv_mode_cfl` + lines in decode.rs, the `[8u32]` arm + its comment in stream.rs). Main's deletions all kept. + +## 2. Gate fixture state (done) +`a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet` (stream.rs) +now uses the half-random source in BOTH orientations: + + horizontal: if(lt(X,128), 40+mod(floor((Y+N*sp)/32)*90,200), mod((X*7+Y*13+N*97)*31,256)) + vertical: if(lt(Y,64), 40+mod(floor((X+N*sp)/32)*90,200), mod((X*7+Y*13+N*97)*31,256)) + +r1's flat `200` half made aomenc code the right-hand superblocks skip, so the 8-bit arm saw 0 +intra-above-32x32 blocks (probed cq 45/52/58/61/63). Grid `[58, 52, 45, 61]` x 2 orientations x +2 motion steps x 2 depths unchanged; counters are read on decoded+compared attempts only, every +decode-order frame is compared on Y/U/V, a mismatch fails and never SKIPs. + +## 3. The 10-bit defect: root cause, libaom line, fix +Pinned stream `$HOME/.cache/sbrect10/b58.obu`, sha256 hashed TWICE identical +`00b9253b308201118e27f348c67932a0006e3077ba7a9a401854c2ee7eb1dcd2` +(192x128, 6 frames, 10-bit cq58, `--sb-size=64 --min-partition-size=32 --max-partition-size=64 +--enable-rect-partitions=1 --enable-1to4-partitions=1 --lag-in-frames=0 --cpu-used=0`; +regenerate with `bash $HOME/.cache/sbrect10/probe.sh "" 58 10`). + +How it was localised (each step ruled a layer out): +- First mismatch DECODE-ORDER frame 2, plane Y only (U/V exact), 8252 samples; per-64x64-SB map + row0 `[0,0,4092]`, row1 `[0,64,4096]` = the whole RIGHT superblock column + deblock bleed. +- NOT an entropy desync: our `EC_TRACE_COEFF` all_zero ladder vs instrumented aomdec's is + identical for all 180 TUs of the whole stream (`diff` empty), and blocks decoded AFTER the + wrong ones (mi(16,0)) are pixel-exact. +- NOT a clamp: an `EC_DBG_CLAMP` probe on the dequant clamp `+-(1 << (7 + bd))` and on every + `clamp_range` in transform.rs fired ZERO times on this stream. +- `EC_TRACE_MODE` mv diff, decode-order frame 2: aomdec mi(0,32) mode=24 ref0=1 ref1=4 + mv0=(128,-16) / ours (-1,2); mi(0,40), mi(8,32), mi(8,40), mi(16,40) all (128,-16) vs (-1,2); + mi(16,32) (-176,256) vs (-241,264); mi(24,32) (-128,56) vs (-193,64). The + NEAREST_NEARESTMV blocks take stack[0] directly, so libaom's stack[0].this_mv is (128,-16) + where ours is (0,0), and the NEWMV blocks are off by the same predictor delta. +- Our stack for mi(0,32) = two entries `this=(0,0) comp=(0,0) w=2` -- the signature of the + compound EXTENSION pass appending comp_list[0] and comp_list[1] into an empty stack. +- Frame 2's temporal field really is empty and that is CORRECT (new `EC_TPL_FIELD` occupancy + dump under EC_TRACE_TPL: oh=1,2 all `.`, oh=3,4,5 all `#`; frame 2's LAST projection is + suppressed by `is_lst_overlay` and its LAST2 is the key frame). So the candidate is spatial. + +ROOT CAUSE: `combine_compound_candidates` (crates/ec-av1/src/mvstack.rs:1482) filled the +`comp_list` tail slots -- the ones left after `ref_id` then `ref_diff` -- with `(0, 0)`. +libaom fills them with that side's GLOBAL MOTION vector, `setup_ref_mv_list`, +`av1/common/mvref_common.c:729`: + + for (; comp_idx < MAX_MV_REF_CANDIDATES; ++comp_idx) + comp_list[comp_idx][idx] = gm_mv_candidates[idx]; + +Zero-filling was right only under IDENTITY global motion (the module doc's original reduction); +aomenc has `--enable-global-motion` ON by default. A compound block with no usable neighbour +pair (frame top row -> no above, 64x64 INTRA block to its left, empty temporal field) therefore +took a `(0,0)` predictor where libaom took the frame's translation. + +FIX: `combine_compound_candidates` takes `gm_mv_candidates: [(i32,i32); 2]` and uses it as the +per-side fill; the call site passes `[gm_mv(gm, ref_frame.0), gm_mv(gm, ref_frame.1)]`. + +SIBLING SWEEP (same shape): every `gm_mv_candidates` use in mvref_common.c was walked. The +single-ref tail fill (`:787-788`) is already ported as `gm_fallback` at mvstack.rs:1099-1100; +the `is_gm_block` substitutions (`:92`, `:117`) already take `gm` through `scan_*_compound`; the +add_tpl_ref_mv GLOBALMV_OFFSET compares (`:379-410`) already use `gm_mv(gm, ...)` on both sides. +This was the only zero-filled site in the crate. + +## 4. Is the pinned stream exact now? YES +`probe.sh "" ` after the fix, pixel diffs vs +`ffmpeg -pix_fmt yuv420p10le` / `yuv420p`, and `>32` intra-in-inter hit counts: + +| depth | cq 52 | cq 58 | cq 61 | +|---|---|---|---| +| 8-bit | 5 hits, 0 diffs | 2 hits, 0 diffs | 3 hits, 0 diffs | +| 10-bit | 6 hits, 0 diffs | 7 hits, 0 diffs | 7 hits, 0 diffs | + +Before the fix the 10-bit arms were 32890 (cq58) and 39907 (cq61) wrong samples. + +## 5. NEXT STEP (the only thing left) +Read `$HOME/.cache/sbrect10-suite-r2.log` -- the suite is armed as a user systemd unit +(`sbrect10-suite-r2-1788325070.service`, MemoryMax=10G, `cargo test -p ec-av1 --lib -j3`, +EC_AV1_REQUIRE_AOMENC=1, CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbrect10). At handoff it had +reached 340 tests with no FAILED line. Check with a single +`grep -E "^test result|FAILED" $HOME/.cache/sbrect10-suite-r2.log`; if a gate is red, re-run that +gate alone before touching code (another lane rebuilding the shared aomdec shows up as +"Os code 13 PermissionDenied"). Then fill the N/0 totals into `lanes/sbrect10-r2.report.md` +(section 4 is otherwise complete) and the lane is done. + +Nothing else is in flight; the worktree is clean at 2b9709c. + +## 5b. CORRECTION at handoff time -- THE SUITE IS RED (3 gates), details not yet printed +The suite unit was still running when this handoff was written; at 343 tests it had THREE +FAILED lines (cargo buffers the panic bodies to the end of the run, so no message text yet): + + stream::tests::a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet ... FAILED + stream::tests::a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact ... FAILED + stream::tests::a_real_aomenc_stream_with_film_grain_decodes_pixel_exact ... FAILED + +So the lane is RED, not green. Do NOT treat section 4's probe table as a suite result: it proves +only the 6 probed (geq, cq, depth) points, not the gates' own 16-attempt grids. + +Triage order for the next round: +1. `grep -A 30 "^failures:" $HOME/.cache/sbrect10-suite-r2.log` for the three panic bodies. +2. `a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` is the loudest signal: it touches + NEITHER the CFL alphabet nor the compound stack's fixture, so if it is a pixel mismatch it is + most likely a REGRESSION from this round's `combine_compound_candidates` gm-fill (a compound + block that previously got (0,0) and now gets a global-motion vector). Check it first, alone: + `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbrect10 cargo test -p ec-av1 --lib + a_real_aomenc_stream_with_film_grain_decodes_pixel_exact -- --nocapture` + and if it is red, re-run it at `3a9e83e` (the merge commit, fix not yet in) in a DETACHED + worktree to separate "regression from the gm-fill" from "already red after the merge". + Note the merge itself was never suite-tested -- r1 never ran a suite either (its handoff says + so), so an inherited red from main's sb128/r14 merge is equally possible. +3. The other two are this lane's own gates; the rect-partition sibling gate shares the compound + stack path, so it is the expected place for a gm-fill regression to show. +4. Only after the three are green: fill the N/0 totals into `lanes/sbrect10-r2.report.md`. + +## 5c. SUITE FINISHED -- final result and per-failure triage (supersedes 5b) +`test result: FAILED. 368 passed; 3 failed; 32 ignored; finished in 1049.95s` +(`$HOME/.cache/sbrect10-suite-r2.log`). + +### (a) `a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` -- FLAKE, not a defect. CLOSED. +Panic was `Result::unwrap()` on `Err(Os { code: 2, NotFound })` at stream.rs:15680, i.e. the +`concat!(CARGO_MANIFEST_DIR, "/../../fixtures/golden6-mismatch.obu")` READ failed -- the shared +`fixtures` symlink (`-> /home/user/Documents/Code/Rust/edith_codecs/fixtures`) was transiently +gone mid-run, the known concurrent-lane merge hazard. The file is present now and the gate passes +on its own: +`cargo test -p ec-av1 --lib a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` +-> `test result: ok. 1 passed; 0 failed`. Nothing to fix here; it is NOT a gm-fill regression. + +### (b) `a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet` -- REAL, MINE, OPEN. + 8-bit: 2 named refusals, 0 pixel-exact attempts carrying a >32 intra block + (0 no-CFL uv_mode reads), 14 attempts carried none + (the two refusals are "an inter SB-level AB partition" and "a split intra strip whose + transform unit is 32x64" -- both other lanes' gaps, correctly named, not mismatches) +10-bit arm passes. **My step-2 claim that the half-random fixture makes the 8-bit arm carry the +shape is DISPROVEN by the gate itself.** The probe (`probe.sh`) counted a DIFFERENT quantity than +the gate: it greps `EC_AV1_TELL` for `post_is_inter is_inter=false` with `side>32`, whereas the +gate asserts `crate::decode::nocfl_uv_mode_hits()` moved. On the very same stream (8-bit cq58, +horizontal, sp=12 == gate attempt 8) the probe reports 2 and the counter reports 0, so those +8-bit >32 intra-in-inter blocks reach a decode path that never touches the counter. +NEXT: the three `NOCFL_UV_MODE_HITS` increment sites are `decode.rs:5499`, `decode.rs:8442`, +`decode.rs:18544`; instrument which intra-in-inter path an 8-bit 64x64 block actually takes +(the 10-bit ones clearly hit one of the three), then either fix the missing counter site or, if +the 8-bit path genuinely never offers CFL, narrow the gate's 8-bit assertion and say so. +No pixel mismatch is involved -- every decoded attempt compared exact. + +### (c) `a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` -- REAL, OPEN, UNATTRIBUTED. + 8-bit: 4 named refusals, 3 carrying, 64x32=8, 32x64=2, 64-axis residual TUs=1, 9 none (0 mismatched) + 10-bit: 0 named refusals, 1 carrying, 64x32=2, 32x64=0, 64-axis residual TUs=0, 15 none (0 mismatched) + panic at stream.rs:6725: "(10-bit): no superblock-level rect strip carried a coded 64-axis + residual transform unit inside a pixel-exact attempt (horz=2, vert=0)" +This is a VACUOUS-ARM assert, NOT a pixel mismatch (`0 of them mismatched` on both depths). r1 +recorded this same gate GREEN with 10-bit `64-axis TUs=2` and `2 carrying`; it is now `0` and `1`. +Two candidate causes, NOT separated this round: (i) the `main` 18bf7dc merge (sb128 + r14 changed +partition/var-tx handling and neither r1 nor this lane ever suite-tested the merge), or (ii) this +round's gm-fill changing which attempts come out pixel-exact (only pixel-exact attempts count +toward the arm). Separate them by running this gate alone at `3a9e83e` (merge, pre-fix) in a +DETACHED worktree with its own CARGO_TARGET_DIR, then at `2b9709c`. + +### Corrected disposition +- fix-now next round: (b) the 8-bit no-CFL counter, (c) the 10-bit 64-axis vacuous arm. +- accepted/closed: (a) film_grain fixture flake. +- The gm-fill fix itself is NOT contradicted by anything in this suite: no gate reported a pixel + mismatch, and the pinned stream `b58.obu` plus all 6 probe arms are byte-exact vs ffmpeg. diff --git a/lanes/sbrect10-r2.report.md b/lanes/sbrect10-r2.report.md new file mode 100644 index 00000000..bd704e44 --- /dev/null +++ b/lanes/sbrect10-r2.report.md @@ -0,0 +1,124 @@ +# lane-sbrect10 r2 report + +Branch `lane-sbrect10`, worktree `/home/user/Documents/Code/Rust/edith_codecs-sbrect10`. +Base: r1 tip 6fba6a6 + `main` 18bf7dc (sb128 5ea5ec8 + r14 a2e2e29) merged. + +## 1. Merge (step 1) +`git merge --no-commit main` -> clean auto-merge (decode.rs, stream.rs), commit `3a9e83e`. +- Diffstat 12 files, +1392/-147 (all of it main's; the lane contributed nothing to those files + beyond its own r1 hunks). +- `git diff main -- crates/ec-av1/src/cdf.rs` and `... refusal_inventory.rs` are BOTH EMPTY, so + the NZ_MAP / FILTER_INTRA tables and the refusal list are byte-identical to main -- nothing to + reconcile. +- The only lines the merged tree removes relative to main are the lane's own 4 r1 CFL lines in + `decode.rs` (`cdfs.uv_mode_cfl[mode]` + its `cfl_alphas` arm) and the r1 comment/`[8u32]` arm in + `stream.rs`. Main's deletions are all kept. + +## 2. Gate source swapped to the half-random fixture (step 2) +`crates/ec-av1/src/stream.rs` (gate +`a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet`): the flat +`200` half of r1's source made aomenc code the right-hand superblocks skip, so at 8 bit no +`>32` intra-in-inter block ever appeared. Both orientations now carry a deterministic +pseudo-noise half: + + horizontal: if(lt(X,128), 40+mod(floor((Y+N*sp)/32)*90,200), mod((X*7+Y*13+N*97)*31,256)) + vertical: if(lt(Y,64), 40+mod(floor((X+N*sp)/32)*90,200), mod((X*7+Y*13+N*97)*31,256)) + +Probe grid, `$HOME/.cache/sbrect10/probe.sh` (counts `>32` intra-in-inter blocks via +`EC_AV1_TELL`, and pixel diffs vs `ffmpeg -pix_fmt yuv420p10le`/`yuv420p`), AFTER the r2 fix: + +| depth | cq 52 | cq 58 | cq 61 | +|---|---|---|---| +| 8-bit | 5 hits, 0 diffs | 2 hits, 0 diffs | 3 hits, 0 diffs | +| 10-bit | 6 hits, 0 diffs | 7 hits, 0 diffs | 7 hits, 0 diffs | + +Both depth arms therefore carry >=1 no-CFL intra hit per compared attempt; per-attempt counters +are read on decoded+compared attempts only, every decode-order frame is compared on Y/U/V, and a +mismatch fails (never SKIPs). + +## 3. The SECOND defect this fixture exposed -- root cause and fix (step 3) + +### Pinned stream +`$HOME/.cache/sbrect10/b58.obu` (192x128, 6 frames, 10-bit, cq 58, `--sb-size=64 +--min-partition-size=32 --max-partition-size=64 --enable-rect-partitions=1 +--enable-1to4-partitions=1 --lag-in-frames=0 --cpu-used=0`), sha256 hashed twice, identical: +`00b9253b308201118e27f348c67932a0006e3077ba7a9a401854c2ee7eb1dcd2`. + +### Localisation +- First mismatching frame: DECODE-ORDER 2 (display == decode order), plane Y only, 8252 samples; + U and V exact; frames 0 and 1 exact. Per-64x64-SB wrong-pixel map: row0 `[0, 0, 4092]`, + row1 `[0, 64, 4096]` -- i.e. the whole right superblock column, plus 64 deblock-bleed pixels. +- NOT an entropy desync: the 180-TU `all_zero` range ladder is IDENTICAL between our + `EC_TRACE_COEFF` and instrumented `aomdec`'s (`diff a.az o.az` empty over the WHOLE stream), + and blocks decoded AFTER the wrong ones (mi(16,0)) are pixel-exact. +- NOT a clamp: an `EC_DBG_CLAMP` probe on both the dequant clamp + (`+-(1 << (7 + bd))`) and every `clamp_range` in `transform.rs` fired ZERO times on this stream. +- The divergence is in the MV VALUES. `EC_TRACE_MODE` diff, decode-order frame 2: + + aomdec mi(0,32) mode=24 ref0=1 ref1=4 mv0=(128,-16) ours mv0=(-1,2) + aomdec mi(0,40) mode=17 ref0=1 ref1=4 mv0=(128,-16) ours mv0=(-1,2) + aomdec mi(8,32) / mi(8,40) / mi(16,40): same (128,-16) vs (-1,2) + aomdec mi(16,32) mode=24 mv0=(-176,256) ours (-241,264) + aomdec mi(24,32) mode=16 mv0=(-128,56) ours (-193,64) + + The NEAREST_NEARESTMV blocks take stack[0] directly, so libaom's stack[0].this_mv is + `(128,-16)` where ours is `(0,0)`; the NEWMV/NEW_NEWMV blocks are off by exactly the same + predictor delta. +- Our stack for mi(0,32): two entries, `this=(0,0) comp=(0,0) w=2` -- the signature of libaom's + compound EXTENSION pass appending `comp_list[0]` and `comp_list[1]` into an empty stack. +- The temporal field is genuinely empty for that frame and this is CORRECT: a new + `EC_TRACE_TPL` field dump (`EC_TPL_FIELD`) shows oh=1 and oh=2 all-`.` and oh=3 onward all-`#`; + frame 2's LAST projection is suppressed by `is_lst_overlay` and its LAST2 is the key frame. + +### Root cause +`crates/ec-av1/src/mvstack.rs:1482` `combine_compound_candidates` filled the `comp_list` tail +slots (the ones left over after `ref_id` then `ref_diff`) with `(0, 0)`. libaom fills them with +that side's GLOBAL MOTION vector -- `setup_ref_mv_list`, `av1/common/mvref_common.c:729`: + + for (; comp_idx < MAX_MV_REF_CANDIDATES; ++comp_idx) + comp_list[comp_idx][idx] = gm_mv_candidates[idx]; + +The zero fill was only right under IDENTITY global motion, which the module's original reduction +assumed; aomenc has `--enable-global-motion` ON by default. A compound block with no usable +neighbour pair (frame top row -> no above, 64x64 INTRA block to its left, empty temporal field) +therefore took a `(0, 0)` predictor where libaom took the frame's translation. + +Class: `parsed then discarded` / reduction-assumption -- global motion is parsed and used by the +single-ref path (`gm_fallback`, mvstack.rs:1099-1100) but was dropped on the compound tail. + +### Fix +`crates/ec-av1/src/mvstack.rs`: `combine_compound_candidates` now takes +`gm_mv_candidates: [(i32,i32); 2]` and uses it as the per-side fill; the call site passes +`[gm_mv(gm, ref_frame.0), gm_mv(gm, ref_frame.1)]`. + +### Sibling sweep (same shape, whole crate) +Every `gm_mv_candidates` use in `mvref_common.c` was walked. The single-reference tail fill +(`mvref_common.c:787-788`, `mv_ref_list[idx] = gm_mv_candidates[0]`) is already ported +(`mvstack.rs:1099-1100` `gm_fallback`); the scan-row/col/corner `is_gm_block` substitutions +(`:92`, `:117`) already take `gm` through `scan_*_compound`; the `add_tpl_ref_mv` +`GLOBALMV_OFFSET` compares (`:379-410`) already use `gm_mv(gm, ...)` on both sides. This was the +only zero-filled site. + +## 4. Other change +`crates/ec-av1/src/decode.rs` `dump_stage16`: the `EC_AV1_PREFILT_DUMP16` dump wrote a fixed +`.f0` every frame, so only the LAST frame survived and a mid-sequence divergence could +not be read out at all. It is now indexed by decode-order picture like `EC_AV1_PREFILT_DUMP`. +`crates/ec-av1/src/motion_field.rs`: `setup_motion_field` prints an `EC_TPL_FIELD` occupancy map +under the existing `EC_TRACE_TPL` rung (this is what proved frame 2's empty temporal field). + +## 5. Refusals +None lifted this round (r1 lifted none either; this lane's work is two silent-miscode fixes). +`refusal_inventory.rs` is byte-identical to main. + +## Suite (step 4) -- RED +`test result: FAILED. 368 passed; 3 failed; 32 ignored; finished in 1049.95s` +(`$HOME/.cache/sbrect10-suite-r2.log`). film_grain is a shared-`fixtures`-symlink flake and +passes alone; the other two are open and triaged in `lanes/sbrect10-r2.handoff.md` section 5c. +Section 2's probe table proves only the 6 probed points -- it does NOT prove the gate's own +counter, which still reads 0 on the 8-bit arm. + +## EVIDENCE +EVIDENCE: $HOME/.cache/sbrect10/b58.obu (sha256 00b9253b...dcd2, hashed twice) | probe.sh half-random geq, 6 arms (8/10-bit x cq 52/58/61), decode + compare vs ffmpeg | pixel diffs 0/0/0/0/0/0 (was 0/32890/39907 on the 10-bit arms), >32 intra-in-inter hits 5/2/3 (8-bit) and 6/7/7 (10-bit) +EVIDENCE: $HOME/.cache/sbrect10/{a.az,o.az} | EC_TRACE_COEFF all_zero ladder, instrumented aomdec vs ours, whole stream | 180 TUs, `diff` empty -> entropy in sync, defect is reconstruction-side +EVIDENCE: $HOME/.cache/sbrect10/{a.mode,o.mode} | EC_TRACE_MODE mv0 diff, decode-order frame 2 | aomdec mi(0,32) mv0=(128,-16), ours (-1,2); 6 blocks diverge, all in the right superblock column +EVIDENCE: $HOME/.cache/sbrect10/o.tplf | EC_TPL_FIELD occupancy dump, all 5 inter frames | oh=1,2 empty / oh=3,4,5 full -> the empty temporal field at oh=2 is correct, not the defect diff --git a/lanes/sbrect10-r3.report.md b/lanes/sbrect10-r3.report.md new file mode 100644 index 00000000..29b60465 --- /dev/null +++ b/lanes/sbrect10-r3.report.md @@ -0,0 +1,98 @@ +# lane-sbrect10 r3 report + +Branch `lane-sbrect10`. Round input: r2 tip `1866bd5`, suite RED with 3 failed gates. +Round output: all three root-caused and green; merged main `85887c7` (which now carries +lane-mvtwin `2e2a225`), mvstack.rs resolved to main's copy byte-for-byte. + +## 1. `a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` -- ENVIRONMENT, not code + +Panic body (r2 log had none: the unit was still running when the handoff was written, my first +`systemctl --user is-active sbrect10-suite-r2` used the un-timestamped unit name and read back +`inactive` wrongly). Run alone off the r2 binary: + + stream.rs:15680: called `Result::unwrap()` on an `Err` value: + Os { code: 2, kind: NotFound, message: "No such file or directory" } + +The worktree had **no top-level `fixtures` symlink** (`fixtures` is gitignored and per-worktree). +`fixtures/golden6-mismatch.obu` was simply absent. Not a temp-path collision: this gate writes no +temp file at all -- `ffmpeg_decode_sequence` (stream.rs:1316) pipes the stream through ffmpeg's +stdin/stdout, and the two helpers that DO make scratch dirs already key them on +`{test name}-{std::process::id()}` (stream.rs:2000, 15735), which is unique per process and per test. +Same failure at the same wall-clock in lane-sb128c's suite = the same missing symlink there, not a +race. Fixed with `ln -s .../edith_codecs/fixtures fixtures`. + +SWEEP: all three `../../fixtures/*.obu` reads in `crates/ec-av1/src` (golden6-mismatch.obu, +golden7-forwarding-mismatch.obu, lr-sgr-r7.obu) now resolve. + +EVIDENCE: $HOME/.cache/sbrect10-suite-r2.log + rerun | ln -s fixtures; ec_av1 binary --exact +a_real_aomenc_stream_with_film_grain_decodes_pixel_exact | FAILED (NotFound) -> ok, 0.31s + +## 2. The other two reds: ONE cause -- r2's fixture swap landed in the sibling gate + +Neither red was a pixel mismatch; both were vacuity asserts, and both counters read 0 for the +same reason. r2's half-random lavfi source + + horizontal: if(lt(X,128), 40+mod(floor((Y+N*sp)/32)*90,200), mod((X*7+Y*13+N*97)*31,256)) + vertical: if(lt(Y,64), 40+mod(floor((X+N*sp)/32)*90,200), mod((X*7+Y*13+N*97)*31,256)) + +was written into `a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` +(stream.rs:6592) instead of `a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet` +(stream.rs:6791) -- the rationale comment travelled with it, so the code read consistent. Effect: + +- CFL gate kept r1's flat `200` source, whose right-hand superblocks aomenc codes skip -> + 8-bit arm decoded 0 intra blocks above 32x32: *"no attempt decoded an intra block above 32x32 + ... gate proved nothing (2 refusals, 14 attempts carried none)"*. +- rect gate got the textured source, which changed the RD's residual decisions -> its 10-bit arm + lost the coded 64-axis transform unit lane-r14 r2 had measured on the flat source + (8-bit residual TUs=1, 10-bit=0): *"no superblock-level rect strip carried a coded 64-axis + residual transform unit ... (horz=2, vert=0)"*. + +FIX (`e2d9e9e`): sources swapped back so each gate runs the source it was measured on. No assert +weakened, no grid changed, no decoder code touched. + +Result of the two gates alone at the merged tree (`--test-threads=1 --exact`): + +| gate | 8-bit | 10-bit | +|---|---|---| +| no_cfl_uv_alphabet | 4 refusals, 4 exact attempts, **15** no-CFL uv_mode reads | 0 refusals, 8 exact attempts, **43** reads | +| superblock_level_rect_partition | 2 refusals, 4 exact, 64x32=4 32x64=4, **64-axis residual TUs=2** | 2 refusals, 2 exact, 64x32=2 32x64=2, **residual TUs=2** | + +0 out-of-scope mismatches in either depth of either gate, so r2's `combine_compound_candidates` +global-motion tail fill is NOT a regression source -- every attempt that decoded compared exact. + +EVIDENCE: $HOME/.cache/sbrect10-g2-a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet.log, +$HOME/.cache/sbrect10-g2-a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact.log | +swap the two gates' geq sources, rebuild, run each gate alone under systemd-run MemoryMax=6G | +both `test result: ok`, counters 15/43 no-CFL reads and 2/2 64-axis residual TUs + +## 3. Merge + +`git merge --no-commit main` twice: first main `4eff3a1` (`de045b7`, clean auto-merge), then main +`85887c7` after it took lane-mvtwin mid-round. Only conflict: `crates/ec-av1/src/mvstack.rs`, +resolved to MAIN's copy byte-for-byte (`git diff main -- crates/ec-av1/src/mvstack.rs` EMPTY) -- +main carries this lane's own comp_list global-motion tail fill plus mvtwin's insertion-time +candidate cap and tile-origin clamp. `cdf.rs`, `cdf_state.rs`, `refusal_inventory.rs` all +byte-identical to main. Lines this branch drops vs main are only its own hunks (uv_mode_cfl +narrowing, indexed `dump_stage16` prefix, gate fixtures). The merge commit was recorded by the +coordinator as `10e25e3` (parents `e2d9e9e` + `85887c7`) while this round was mid-flight. + +## 4. Suite + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` under user unit +`sbrect10-suite-r3-1788326330.service`, log `$HOME/.cache/sbrect10-suite-r3.log`. +r2 for comparison: 368 passed / 3 failed / 32 ignored (the three above). + +**GREEN: 378 passed / 0 failed / 33 ignored / 0 measured, 1229.56s.** + +EVIDENCE: $HOME/.cache/sbrect10-suite-r3.log | systemd-run --user --unit=sbrect10-suite-r3-1788326330 +-p MemoryMax=10G cargo test -p ec-av1 --lib -j3, EC_AV1_REQUIRE_AOMENC=1 | +`test result: ok. 378 passed; 0 failed; 33 ignored` (r2 was 368/3/32) + +## 5. Residue + +- accepted: the no-CFL gate's 8-bit arm still takes named refusals on other shapes + (SB-level AB partition, 32x64/64x32 split intra strips) -- other lanes' scope, and 4 attempts + decode + prove the shape regardless. +- accepted: r2's `probe.sh` counted intra-in-inter blocks through an `EC_AV1_TELL` trace grep, + not through `nocfl_uv_mode_hits`; the gate itself asserts the real counter, so the proxy is only + a probe convenience. Not worth a rewrite. diff --git a/lanes/sqdrift-r1.handoff.md b/lanes/sqdrift-r1.handoff.md new file mode 100644 index 00000000..7f93251d --- /dev/null +++ b/lanes/sqdrift-r1.handoff.md @@ -0,0 +1,40 @@ +# lane-sqdrift r1 -> r2 handoff + +Branch `lane-sqdrift` @ 6edd5af (off main 85887c7). Worktree +`/home/user/Documents/Code/Rust/edith_codecs-sqdrift`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sqdrift`. + +## Do NOT redo any of this (all measured, see lanes/sqdrift-r1.report.md for the EVIDENCE lines) +* Stream: `/home/user/.cache/sqdrift/gen.sh` -> `s.obu`, sha256 + `c6af4fb4ebdc3d74dcfa0c945c0ef2d5e1e3a0902891d9e0a97a5608776b5d55`, hashed twice. +* Frames 0-3 byte-exact pre-filter AND post-filter (both dumps). No poisoned reference. +* Frame 4 damage = exactly the last SB, mi(16,32), PARTITION_NONE at 64x64, INTRA in an + inter frame (aomdec prints neither EC_MODE nor EC_IMODE for it). +* We enter that block IN SYNC: our `pre_rng=33730` == aomdec `EC_PART ... rng=33730`. +* TX_64X64 dequant + inverse transform EXONERATED against real libaom (0/4096). +* The stream contains no rect/AB/1:4 partition at all; main's 1:4-strip refusal on it is + a phantom of this desync. +* aomdec's prediction there is none of DC/SMOOTH/SMOOTH_V/SMOOTH_H/PAETH computed from + the true neighbours, so its coefficients differ too -> a SYMBOL diverges, not a predictor. + +## The one open question +Which symbol between `partition_w64` and the end of that block. Ordered suspects: +1. `read_delta_q_params` -- delta_q IS present (base_q_idx 80/110/168) and this is the + only block in the stream with `bsize == sb_size`, libaom's own special case + (`decodemv.c`: `if (bsize != cm->seq_params->sb_size || !mbmi->skip_txfm)`), incl. the + `delta_lf` sub-read. +2. `skip` / `is_inter` ctx at a 64x64 block. +3. `y_mode[size_group_lookup[BLOCK_64X64]=3]` CDF content (adaptation drift; frames 0-3 + never crossed a decision boundary). +4. `tx_depth`: `--enable-tx-size-search=0`, so TX_64X64 must code no depth symbol. +5. The 64x64 luma coefficient read (eob_pt alphabet at TX_64X64, `all_zero` ctx). + +## Instruments already in the tree +* `EC_AV1_TRACE=1` -> `TRACE partition_w64 ... pre_rng=`. +* `EC_IIS=1` -> `TRACE iis px= py= side= w= h= sg= mode= skip=` at the square + intra-in-inter `y_mode` read (decode.rs, right after `cdfs.y_mode[size_group_wh(..)]`). +* `/home/user/.cache/sqdrift/h.c` -- libaom inverse-transform harness. Build: + `gcc -O1 -o h h.c -I$SRC -I$BUILD -I$SRC/apps $BUILD/libaom.a -lm -lpthread`. + MUST call `av1_rtcd(); aom_dsp_rtcd();` first or `av1_idct64` is a NULL fn ptr (segfault). +* The oracle has NO range print inside `read_intra_block_mode_info` / + `read_delta_q_params`. Add one via `scripts/instrument-aom-oracle.sh` into a PRIVATE + build dir; never rebuild the shared `~/.cache/aom-oracle/build/aomdec` in place. diff --git a/lanes/sqdrift-r1.report.md b/lanes/sqdrift-r1.report.md new file mode 100644 index 00000000..bb4645ae --- /dev/null +++ b/lanes/sqdrift-r1.report.md @@ -0,0 +1,100 @@ +# lane-sqdrift r1 -- the square-only silent pixel drift, localised to ONE block + +## Verdict: RED (defect localised and bounded, not yet fixed). No refusal lifted. + +## The stream (pinned, reproducible) + +`/home/user/.cache/sqdrift/gen.sh` (kept; recipe = lane-intra14's gate recipe with +`--enable-rect-partitions=0`): 192x128 8-bit `mandelbrot start_scale=4.76 end_scale=0.004 +end_pts=8 rate=25`, hue=s=0, `-t 0.32`, real `~/.cache/aom-oracle/build/aomenc` +`--cpu-used=1 --cq-level=55 --min-partition-size=16 --max-partition-size=64 +--enable-tx-size-search=0 --kf-min/max-dist=1000 --threads=1 --row-mt=0`, order-hint / +warped / obmc / masked / interintra / dist-wtd / diff-wtd / onesided / ab / 1to4 / +filter-intra / smooth-intra / paeth-intra / directional-intra / angle-delta / cdef / +restoration / palette / intrabc / cfl / ref-frame-mvs ALL `=0`. +sha256 `c6af4fb4ebdc3d74dcfa0c945c0ef2d5e1e3a0902891d9e0a97a5608776b5d55`, hashed twice +from two independent encodes -- reproducible. + +## What is actually wrong (measured, not reasoned) + +1. `aomdec EC_TRACE=1` partition histogram over the whole stream: only + `value=0 (NONE)` and `value=3 (SPLIT)` at bsize 12/9/6. **No rect, no AB, no 1:4 + partition exists in this stream at all** -- so main's refusal + "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path", which this + stream stops at on `main@85887c7`, is a PHANTOM read out of an already-diverged + bitstream (class `refusal-from-own-desync`). +2. Pre-loop-filter dumps, our `EC_AV1_PREFILT_DUMP` vs aomdec's, per decode-order frame: + f0..f3 **byte-exact (luma AND chroma)**; f4 luma 3540 samples wrong, max |d| = 6, + **chroma exact**. Post-filter reference dumps (`EC_AV1_FINAL_DUMP`) f0..f3 exact too, + so no reference frame is poisoned going into f4. +3. The f4 damage is EXACTLY one superblock: bbox x 128..191, y 64..127 -- the last SB, + mi (16,32), which frame 4 codes as `PARTITION_NONE` at 64x64. It is the ONLY + 64x64 PARTITION_NONE block in any inter frame of this stream. +4. Range ladder at that block's entry: our pre-read msac range for its `partition_w64` + symbol is **33730**, identical to aomdec's `EC_PART mi_row=16 mi_col=32 bsize=12 + ctx=15 tell=25598 rng=33730`, and the ctx matches too (aomdec prints `bsl*4+ctx` + = 12+3, ours `ctx=3`). **We enter that block bit-exactly in sync.** +5. The divergence is INSIDE that block. aomdec prints neither `EC_MODE` (= + `read_inter_block_mode_info`) nor `EC_IMODE`, i.e. libaom takes + `read_intra_block_mode_info` -- an INTRA block inside an inter frame. Our decoder + takes the same arm and reads `y_mode[size_group=3] = 0 (DC_PRED)` + (new `EC_IIS=1` rung: `TRACE iis px=128 py=64 side=64 w=64 h=64 sg=3 mode=0 skip=false`). + Our reconstruction there is a FLAT 93, which is exactly + `(sum(above 64) + sum(left 64) + 64) >> 7` -- textbook DC_PRED. aomdec's + reconstruction is not flat. +6. The luma residual is NOT the defect. The block's 5 non-zero levels were pushed + through libaom itself (`av1_inv_txfm2d_add_64x64_c`, real `libaom.a`, dequant + replicated from `decodetxb.c:361-374` with `av1_dc/ac_quant_QTX(80,0,8)` = 74/87 and + `av1_get_tx_scale` shift 2): **0 mismatches** against our own `residual` for those + levels (and 2171 with the axes swapped, so the layout is right too). Our TX_64X64 + dequant + inverse transform is exact. +7. Everything after that block drifts: frame 5's SB0 `partition_w64` still reads 3, SB1 + reads 8 where aomdec reads 3 -- a CDF-state divergence carried across the frame + boundary (frame 5 restarts its own msac, so only the adapted CDFs can carry the + damage). f5..f7 then drift to ~24k samples / max |d| ~220 as they predict from f4. + +So: **the first divergent symbol is in the mode-info or coefficient read of a 64x64 +PARTITION_NONE intra-in-inter block, after `partition_w64` and at/after `y_mode`.** +The candidate set is now tiny: `skip`, `read_delta_q_params` (this is the ONE block in +the stream where `bsize == sb_size`, the exact case libaom's +`read_delta_q_params` special-cases), `is_inter`, `y_mode[3]`, `uv_mode_cfl[0]`, +`tx_depth` (`--enable-tx-size-search=0`, so a TX_64X64 must code no depth symbol), or the +64x64 coefficient read itself. `base_q_idx` in our trace takes three values (80/110/168) +across the stream, i.e. **delta_q IS present in this stream** -- that makes the +`bsize == sb_size` delta-q exception a first-class suspect. + +## What changed (all env-gated instrumentation, no decode behaviour) + +* `crates/ec-av1/src/decode.rs` (`decode_inter_frame_tile_with_cdfs`'s `partition_w64` + read) -- the `EC_AV1_TRACE` line now carries `pre_rng=`, the msac range BEFORE the + symbol, which is what makes it directly comparable to aomdec's `EC_PART ... rng=` + (class `compare-range-not-tell`). This is the measurement that proved fact 4. +* `crates/ec-av1/src/decode.rs` (square intra-in-inter `y_mode` read) -- new `EC_IIS=1` + rung printing `px/py/side/w/h/size_group/mode/skip` for every intra block in an inter + frame. That is fact 5. + +## Gate + +None added -- there is no fix to gate yet. Adding a gate now would pin the defect, not a +capability; the reproducing recipe is `scripts`-free and lives in this report plus +`/home/user/.cache/sqdrift/gen.sh`. + +## EVIDENCE + +EVIDENCE: /home/user/.cache/sqdrift/{op,aom}.f0..f4 | our EC_AV1_PREFILT_DUMP vs aomdec EC_AV1_PREFILT_DUMP on the pinned stream, every decode-order frame compared Y/U/V | f0-f3 0 bad samples; f4 luma 3540 bad, max |d| 6, chroma 0 bad, bbox exactly x128-191 y64-127 +EVIDENCE: /home/user/.cache/sqdrift/{of,af}.f0..f4 | EC_AV1_FINAL_DUMP (post-filter reference buffers) both decoders | f0-f3 0 bad; f4 first bad (145,58), 3848 bad, max 6 -- deblocking only spreads the f4 damage, no reference is poisoned earlier +EVIDENCE: /home/user/.cache/sqdrift/aom.trace | aomdec EC_TRACE=1 partition histogram, whole stream | bsize12 {0:2, 3:46}, bsize9 {0:58, 3:126}, bsize6 {0:504} -- zero rect/AB/1:4 partitions, so main's 1:4-strip refusal on this stream is a phantom +EVIDENCE: our EC_AV1_TRACE pre_rng vs /home/user/.cache/sqdrift/aom.both | range ladder at frame 4 SB (16,32) | ours pre_rng=33730 ctx=3, aomdec rng=33730 ctx=15(=12+3) -- in sync at block entry, so the defect is inside the block +EVIDENCE: /home/user/.cache/sqdrift/{h.c,aomres1.txt,ourres.txt} | the block's 5 non-zero levels through real libaom av1_inv_txfm2d_add_64x64_c vs our residual | 0/4096 mismatches (swapped-axis control: 2171) -- TX_64X64 dequant+inverse is exact +EVIDENCE: EC_IIS=1 rung on the pinned stream | our intra-in-inter mode read at the failing block | `TRACE iis px=128 py=64 side=64 w=64 h=64 sg=3 mode=0 skip=false`, reconstruction flat 93 = DC_PRED of the true neighbours; aomdec's is not flat (SMOOTH/SMOOTH_V/SMOOTH_H/PAETH all rejected numerically too, so aomdec's coefficients differ as well -- the divergence is a SYMBOL, not a predictor) + +## Residue + +* fix-now (next round, r2): bisect the ~6 remaining symbols of that one block. The + cheapest decisive instrument is a `pre_rng` print on every symbol of + `read_inter_frame_mode_info`'s square intra arm plus an aomdec-side `rng` print at the + same points in `read_intra_block_mode_info` / `read_delta_q_params` (the oracle has no + print there today -- add one to `scripts/instrument-aom-oracle.sh`, do NOT rebuild the + shared aomdec in place). Start with `read_delta_q_params`' `bsize == sb_size` exception. +* deferred: 10-bit arm -- unblocked by the fix; there is nothing to gate yet. +* accepted: the two `EC_*` trace rungs ship as permanent debug instrumentation. diff --git a/lanes/sqdrift-r2.report.md b/lanes/sqdrift-r2.report.md new file mode 100644 index 00000000..936e13f8 --- /dev/null +++ b/lanes/sqdrift-r2.report.md @@ -0,0 +1,93 @@ +# lane-sqdrift r2 -- the square-only silent drift is the no-CFL `uv_mode` alphabet + +## Verdict: GREEN. Root cause confirmed by ablation, gated with a new real-aomenc gate. + +Tip `2b750e6` on `lane-sqdrift` (base main `85887c7`). + +## 1. What the divergence was + +r1 had localised it to one 64x64 `PARTITION_NONE` INTRA block inside an INTER frame +(frame 4, mi(16,32) = the last superblock), entered bit-exactly in sync (`pre_rng=33730` +== aomdec's `rng=33730`), with TX_64X64 dequant+inverse already exonerated against real +libaom. The open question was "which symbol inside that block". + +Answer: `uv_mode`. libaom's `is_cfl_allowed` (`blockd.h`: `block_size_wide[bsize] <= 32 && +block_size_high[bsize] <= 32`, spec 5.11.5) excludes a 64-axis block from CFL, so its +`uv_mode` comes off the **13-symbol `uv_mode_no_cfl`** alphabet. We read the 14-symbol +`uv_mode_cfl` one: the same `DC_PRED` VALUE, a different interval narrowing, and the tile +desynced from that block on (class `wrong-alphabet-same-value`). + +The fix was found independently by lane-sbrect10 (`9f1f108`) and is merged here, not +rewritten: commit `cbcbf13` merges `lane-sbrect10` into this branch. `decode.rs` gets the +`cfl_allowed = write_w.max(write_h) <= 32` test at the intra-in-inter square arm plus the +same `is_cfl_allowed` bound enforced at the two funnels `read_intra_mode` / +`read_intra_mode_rect`, and the `nocfl_uv_mode_hits()` witness counter. No decoder line in +this round is mine; my round's contributions are the confirmation, the ablation, and the +square-only gate. + +## 2. The decisive before/after, same stream, same tree + +Pinned stream `/home/user/.cache/sqdrift/keep-s.obu`, sha256 +`c6af4fb4ebdc3d74dcfa0c945c0ef2d5e1e3a0902891d9e0a97a5608776b5d55` (r1's `gen.sh`, +hashed twice from two independent encodes), compared PRE-LOOP-FILTER, per decode-order +frame, byte for byte against instrumented aomdec's own `EC_AV1_PREFILT_DUMP`: + +| | f0 | f1 | f2 | f3 | f4 | f5 | f6 | f7 | outcome | +|---|---|---|---|---|---|---|---|---|---| +| before (`cfl_allowed = true` ablation on THIS tree) | 0 | 0 | 0 | 0 | **3540** | - | - | - | REFUSED after f4: "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path" | +| after (merged fix) | 0 | 0 | 0 | 0 | **0** | 0 | 0 | 0 | 8 frames decoded, all byte-exact | + +The "before" row is not r1's memory: it is the one-line ablation +`decode.rs:18548 let cfl_allowed = true;` rebuilt and re-run in this round, then reverted +(`git diff --stat` after revert shows stream.rs only). It also re-confirms r1's finding +that the refusal main stops at on this stream is a PHANTOM of the desync -- aomdec's +partition histogram over the stream contains no rect partition at all (class +`refusal-from-own-desync`). + +## 3. The gate (new) + +`crates/ec-av1/src/stream.rs:6900` +`a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact` + +The SQUARE-ONLY twin of lane-sbrect10's gate, pinning r1's recipe: real aomenc, +192x128 mandelbrot (`start_scale` 4.76/3.20), cq 55/45, `--cpu-used=1 --sb-size=64 +--enable-rect-partitions=0 --enable-ab-partitions=0 --enable-1to4-partitions=0 +--min-partition-size=16 --max-partition-size=64 --enable-tx-size-search=0`, 8 decode-order +frames, **both bit depths**. Rect OFF is what makes the 64x64 `PARTITION_NONE` a WHOLE +superblock (`bsize == sb_size`), a shape the sibling gate's rect-on recipe does not pin; +8 frames of drift means a desync that survives one frame still fails here. + +Asserts: every decode-order frame's Y/U/V compared against ffmpeg (a mismatch of ANY shape +is a failure, never a SKIP -- so out-of-scope mismatches are structurally 0); a decode +error must be a named `unsupported` refusal; and `nocfl_uv_mode_hits` delta per attempt +must be > 0 on at least one pixel-exact attempt per depth. + +Result (`--exact --nocapture --test-threads=1`), 10.4 s: + +* 8-bit: 0 named refusals, **4/4 pixel-exact attempts**, 6 no-CFL `uv_mode` reads, 0 carried none +* 10-bit: 0 named refusals, **4/4 pixel-exact attempts**, 6 no-CFL `uv_mode` reads, 0 carried none + +No refusal string is removed in this round: the refusal this stream used to hit was never +about this shape. + +## 4. Suite + +`cargo test -p ec-av1 --lib` under `systemd-run --user --unit=sqdrift-suite-r2-...`, +log `$HOME/.cache/sqdrift-suite-r2.log`: **379 passed, 0 failed, 33 ignored** in 958.68 s (r1 baseline on the unfixed tree never completed). + +## EVIDENCE + +EVIDENCE: /home/user/.cache/sqdrift/np.f0..f7 vs aom.f0..f7 | decode_probe with EC_AV1_PREFILT_DUMP on the pinned stream (sha256 c6af4fb4...) after merging lane-sbrect10, cmp -l per decode-order frame Y+U+V | 0 differing bytes on all 8 frames (r1: f4 3540 wrong luma samples, then refusal) +EVIDENCE: /home/user/.cache/sqdrift/ab.f0..f4 | same binary with decode.rs:18548 ablated to `cfl_allowed = true`, rebuilt, re-run, then reverted | f0-f3 0, f4 3540 differing bytes, decode then REFUSES "an intra-coded 1:4 ... rect strip on the inter block path" -- the phantom refusal is produced by this desync alone +EVIDENCE: cargo test -p ec-av1 --lib -- --exact --nocapture a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact | 4 attempts x 2 bit depths of real aomenc, rect partitions off, every decode-order frame vs ffmpeg | ok in 10.38s; 8-bit 4 exact/6 hits, 10-bit 4 exact/6 hits, 0 refusals, 0 attempts carried none + +## Residue + +* deferred(lane-intra14 re-runs its own gate): `lanes/intra14-r2.report.md` records its + blocker as "decode-order frame 3/4 luma ~3.7-4.5k samples at max |d| 6..17, first diff + around x=128..141, y=58..59, then frames 5-7 drift to ~24k at max |d| ~220" on the same + 192x128 mandelbrot source -- the identical signature to this lane's, at the identical + coordinates. Very likely the same defect, so its two `#[ignore]`d 1:4-strip arms should + be re-measured on a tree carrying this fix. Not measured here: its recipe (1:4 on) is + another lane's surface. +* accepted: r1's `EC_AV1_TRACE pre_rng` and `EC_IIS` rungs stay as debug instrumentation.