From 1122732fdecded977848611ac3adbbcd38fe6003 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 21:22:44 +0300 Subject: [PATCH] wip(rectx): round 2's in-flight work, committed at the turn cap by the orchestrator State unverified: the agent stopped mid-run with no report. --- crates/ec-av1/src/decode.rs | 10 +++++ crates/ec-av1/src/stream.rs | 75 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 63b2ba78..93d32391 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3536,6 +3536,9 @@ fn decode_leaf_rect( tx_select: bool, ) -> Result { let _ = base_q_idx; + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { + eprintln!("decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?}"); + } let (r, c) = outer_at; let mut above_mode = neighbours.above_mode[c]; let mut left_mode = neighbours.left_mode[r]; @@ -3567,6 +3570,9 @@ fn decode_leaf_rect( leaf_mi.0, leaf_mi.1, )?; + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { + eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); + } if filter_intra.is_some() { return Err(unsupported( "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", @@ -3624,6 +3630,10 @@ fn decode_leaf_rect( let (l_levels, luma_tx_type) = read_coeffs_rect( dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct, )?; + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { + let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect(); + eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}"); + } luma_levels = l_levels; let luma_residual = dequant_and_inverse_typed_wh( &luma_levels, bw, bh, crate::decode::bit_depth(), diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8a2b0df0..6e4d5ef1 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5328,6 +5328,81 @@ mod tests { result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) ); } + #[test] + fn scratch_probe_rectx_mandelbrot() { + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP: no tools"); + return; + } + let cases = vec![(64usize, 64usize, 24u32, 0.4f64)]; + let mut found = false; + for (width, height, cq, seed_off) in cases { + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", + &format!("mandelbrot=size={width}x{height}:start_x={seed_off}"), + "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()) + .output().expect("ffmpeg failed to run"); + assert!(y4m.status.success()); + let mut child = Command::new(aomenc_path()) + .args([ + "--threads=1", "--row-mt=0", "--sb-size=64", "--cpu-used=4", "--end-usage=q", + &format!("--cq-level={cq}"), "--passes=1", + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", + "--enable-tx-size-search=0", "--min-partition-size=8", + "--max-partition-size=32", "--kf-max-dist=0", + "--obu", "-o", "-", "-", + ]) + .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()) + .spawn().expect("aomenc failed to start"); + child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); + let out = child.wait_with_output().unwrap(); + assert!(out.status.success()); + let stream = out.stdout; + let before = crate::decode::rect_leaf_coeff_hits(); + let result = decode_stream(&stream); + let delta = crate::decode::rect_leaf_coeff_hits() - before; + if delta > 0 { + if let Ok(frames) = &result { + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + let mismatched = frames.iter().zip(&ffmpeg_frames).filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count(); + eprintln!( + "HIT {width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} mismatched={mismatched}/{}", + frames.len() + ); + // debug: locate first y mismatch + if let (Some(got), Some(want)) = (frames.first(), ffmpeg_frames.first()) { + 'outer: for row in 0..height { + for col in 0..width { + let gi = row * width + col; + if got.y[gi] != want.y[gi] { + eprintln!( + "first Y mismatch at ({col},{row}): got={} want={}", + got.y[gi], want.y[gi] + ); + break 'outer; + } + } + } + } + if mismatched == 0 { + found = true; + break; + } + } else { + eprintln!( + "{width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} result={:?}", + result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) + ); + } + } + } + eprintln!("found pixel-exact firing case: {found}"); + } + /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never /// gets to choose a real rect/ab split. This charter's premise ("rect