wip(rectx): round 2's in-flight work, committed at the turn cap by the orchestrator
Browse files at this commit1122732fdecded977848611ac3adbbcd38fe6003Parent: 6c0af342 changed files +85 -0
- crates/ec-av1/src/decode.rs +10 -0
- crates/ec-av1/src/stream.rs +75 -0
crates/ec-av1/src/decode.rsmodified+10 -0
| @@ -3536,6 +3536,9 @@ fn decode_leaf_rect( | |||
| 3536 | tx_select: bool, | 3536 | tx_select: bool, |
| 3537 | ) -> Result<usize> { | 3537 | ) -> Result<usize> { |
| 3538 | let _ = base_q_idx; | 3538 | let _ = base_q_idx; |
| 3539 | + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { | ||
| 3540 | + eprintln!("decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?}"); | ||
| 3541 | + } | ||
| 3539 | let (r, c) = outer_at; | 3542 | let (r, c) = outer_at; |
| 3540 | let mut above_mode = neighbours.above_mode[c]; | 3543 | let mut above_mode = neighbours.above_mode[c]; |
| 3541 | let mut left_mode = neighbours.left_mode[r]; | 3544 | let mut left_mode = neighbours.left_mode[r]; |
| @@ -3567,6 +3570,9 @@ fn decode_leaf_rect( | |||
| 3567 | leaf_mi.0, | 3570 | leaf_mi.0, |
| 3568 | leaf_mi.1, | 3571 | leaf_mi.1, |
| 3569 | )?; | 3572 | )?; |
| 3573 | + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { | ||
| 3574 | + eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); | ||
| 3575 | + } | ||
| 3570 | if filter_intra.is_some() { | 3576 | if filter_intra.is_some() { |
| 3571 | return Err(unsupported( | 3577 | return Err(unsupported( |
| 3572 | "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", | 3578 | "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", |
| @@ -3624,6 +3630,10 @@ fn decode_leaf_rect( | |||
| 3624 | let (l_levels, luma_tx_type) = read_coeffs_rect( | 3630 | let (l_levels, luma_tx_type) = read_coeffs_rect( |
| 3625 | dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct, | 3631 | dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct, |
| 3626 | )?; | 3632 | )?; |
| 3633 | + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { | ||
| 3634 | + let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect(); | ||
| 3635 | + eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}"); | ||
| 3636 | + } | ||
| 3627 | luma_levels = l_levels; | 3637 | luma_levels = l_levels; |
| 3628 | let luma_residual = dequant_and_inverse_typed_wh( | 3638 | let luma_residual = dequant_and_inverse_typed_wh( |
| 3629 | &luma_levels, bw, bh, crate::decode::bit_depth(), | 3639 | &luma_levels, bw, bh, crate::decode::bit_depth(), |
crates/ec-av1/src/stream.rsmodified+75 -0
| @@ -5328,6 +5328,81 @@ mod tests { | |||
| 5328 | result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) | 5328 | result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) |
| 5329 | ); | 5329 | ); |
| 5330 | } | 5330 | } |
| 5331 | + #[test] | ||
| 5332 | + fn scratch_probe_rectx_mandelbrot() { | ||
| 5333 | + let _gate_lock = lock_gate_counters(); | ||
| 5334 | + if !have_ffmpeg() || !have_aomenc() { | ||
| 5335 | + eprintln!("SKIP: no tools"); | ||
| 5336 | + return; | ||
| 5337 | + } | ||
| 5338 | + let cases = vec![(64usize, 64usize, 24u32, 0.4f64)]; | ||
| 5339 | + let mut found = false; | ||
| 5340 | + for (width, height, cq, seed_off) in cases { | ||
| 5341 | + let y4m = Command::new("ffmpeg") | ||
| 5342 | + .args([ | ||
| 5343 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 5344 | + &format!("mandelbrot=size={width}x{height}:start_x={seed_off}"), | ||
| 5345 | + "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", | ||
| 5346 | + ]) | ||
| 5347 | + .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()) | ||
| 5348 | + .output().expect("ffmpeg failed to run"); | ||
| 5349 | + assert!(y4m.status.success()); | ||
| 5350 | + let mut child = Command::new(aomenc_path()) | ||
| 5351 | + .args([ | ||
| 5352 | + "--threads=1", "--row-mt=0", "--sb-size=64", "--cpu-used=4", "--end-usage=q", | ||
| 5353 | + &format!("--cq-level={cq}"), "--passes=1", | ||
| 5354 | + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", | ||
| 5355 | + "--enable-tx-size-search=0", "--min-partition-size=8", | ||
| 5356 | + "--max-partition-size=32", "--kf-max-dist=0", | ||
| 5357 | + "--obu", "-o", "-", "-", | ||
| 5358 | + ]) | ||
| 5359 | + .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()) | ||
| 5360 | + .spawn().expect("aomenc failed to start"); | ||
| 5361 | + child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); | ||
| 5362 | + let out = child.wait_with_output().unwrap(); | ||
| 5363 | + assert!(out.status.success()); | ||
| 5364 | + let stream = out.stdout; | ||
| 5365 | + let before = crate::decode::rect_leaf_coeff_hits(); | ||
| 5366 | + let result = decode_stream(&stream); | ||
| 5367 | + let delta = crate::decode::rect_leaf_coeff_hits() - before; | ||
| 5368 | + if delta > 0 { | ||
| 5369 | + if let Ok(frames) = &result { | ||
| 5370 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); | ||
| 5371 | + let mismatched = frames.iter().zip(&ffmpeg_frames).filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count(); | ||
| 5372 | + eprintln!( | ||
| 5373 | + "HIT {width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} mismatched={mismatched}/{}", | ||
| 5374 | + frames.len() | ||
| 5375 | + ); | ||
| 5376 | + // debug: locate first y mismatch | ||
| 5377 | + if let (Some(got), Some(want)) = (frames.first(), ffmpeg_frames.first()) { | ||
| 5378 | + 'outer: for row in 0..height { | ||
| 5379 | + for col in 0..width { | ||
| 5380 | + let gi = row * width + col; | ||
| 5381 | + if got.y[gi] != want.y[gi] { | ||
| 5382 | + eprintln!( | ||
| 5383 | + "first Y mismatch at ({col},{row}): got={} want={}", | ||
| 5384 | + got.y[gi], want.y[gi] | ||
| 5385 | + ); | ||
| 5386 | + break 'outer; | ||
| 5387 | + } | ||
| 5388 | + } | ||
| 5389 | + } | ||
| 5390 | + } | ||
| 5391 | + if mismatched == 0 { | ||
| 5392 | + found = true; | ||
| 5393 | + break; | ||
| 5394 | + } | ||
| 5395 | + } else { | ||
| 5396 | + eprintln!( | ||
| 5397 | + "{width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} result={:?}", | ||
| 5398 | + result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) | ||
| 5399 | + ); | ||
| 5400 | + } | ||
| 5401 | + } | ||
| 5402 | + } | ||
| 5403 | + eprintln!("found pixel-exact firing case: {found}"); | ||
| 5404 | + } | ||
| 5405 | + | ||
| 5331 | /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 | 5406 | /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 |
| 5332 | /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never | 5407 | /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never |
| 5333 | /// gets to choose a real rect/ab split. This charter's premise ("rect | 5408 | /// gets to choose a real rect/ab split. This charter's premise ("rect |