From 30a94a1d323d5d236f428725f8e76430f8daaaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 18:51:01 +0300 Subject: [PATCH] test(av1): the RDOQ pass only lowers D + lambda*R and reports its own grid --- crates/ec-av1/src/tile.rs | 76 +++++++++++++++++++++++++++++++++++++++ lanes/rdoq-ctl.log | 14 ++++++++ 2 files changed, 90 insertions(+) diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index a6d99d05..3b502dd1 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -8488,6 +8488,82 @@ mod tests { /// be: every position exactly once, the origin first, and never a position /// before one it sits diagonally behind — which is what lets a decoder read /// a coefficient's context off the coefficients it has already decoded. + /// lane-rdoq's two contracts, on a block shaped like the ones the pass + /// exists for (a strong DC, two mid levels and a tail of barely-rounded + /// +-1s): it may only move a block to a LOWER `D + lambda * R`, and the + /// bits it hands back must be the price of the grid it leaves behind -- + /// the search takes that number as the block's rate, so a stale one + /// would price a tile nobody writes. + #[test] + fn rdoq_only_lowers_the_cost_and_reports_its_own_grid() { + let (side, set, q, lambda) = (16usize, TxbSet::Luma16, 150u8, 0.0275); + let mut scaled = vec![0f32; side * side]; + for (i, v) in [ + (0usize, 7.4f32), + (1, 2.6), + (side, -1.55), + // The tail the pass exists for: coefficients the deadzone only + // just rounded up to +-1, which give a whole level back for a + // fraction of one step of squared error. + (2, 0.55), + (2 * side + 1, -0.52), + (3 * side + 3, 0.51), + ] { + scaled[i] = v; + } + // The deadzone quantiser this pass runs after, at the shipped 0.5. + let mut levels: Vec = scaled + .iter() + .map(|&v| { + let m = f64::from(v).abs() + 0.5; + let l = if m < 1.0 { 0 } else { m.floor() as i32 }; + if v < 0.0 { -l } else { l } + }) + .collect(); + let before = levels.clone(); + let dc = f64::from(crate::quant::dc_q(8, i32::from(q))); + let ac = f64::from(crate::quant::ac_q(8, i32::from(q))); + let dc_weight = (dc / ac) * (dc / ac); + let cost = |grid: &[i32]| -> f64 { + let d: f64 = grid + .iter() + .zip(&scaled) + .enumerate() + .map(|(i, (&l, &s))| { + (if i == 0 { dc_weight } else { 1.0 }) + * (f64::from(s) - f64::from(l)).powi(2) + }) + .sum(); + d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) + }; + let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda); + assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); + assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); + // The tail is what it is for: the last coded position moves earlier. + let last = |g: &[i32]| scan_of(side).iter().rposition(|&p| g[usize::from(p)] != 0); + assert!(last(&levels) < last(&before), "eob {:?} -> {:?}", last(&before), last(&levels)); + // A 64-point transform is priced on its top-left 32x32 corner, and + // the pass has to hand back THAT price (the dense path). + let (side, set) = (64usize, TxbSet::Luma64); + let mut scaled = vec![0f32; side * side]; + for (i, v) in [(0usize, 6.1f32), (1, 0.55), (side + 1, -0.53)] { + scaled[i] = v; + } + let mut levels: Vec = scaled + .iter() + .map(|&v| { + let m = f64::from(v).abs() + 0.5; + let l = if m < 1.0 { 0 } else { m.floor() as i32 }; + if v < 0.0 { -l } else { l } + }) + .collect(); + let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda); + let corner: Vec = (0..32) + .flat_map(|row| levels[row * side..][..32].to_vec()) + .collect(); + assert_eq!(bits, coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0)); + } + #[test] fn the_default_scan_walks_every_position_outwards() { for side in [TX16, TX32] { diff --git a/lanes/rdoq-ctl.log b/lanes/rdoq-ctl.log index 5d647e9f..f10b6a11 100644 --- a/lanes/rdoq-ctl.log +++ b/lanes/rdoq-ctl.log @@ -4,3 +4,17 @@ test encode::tests::bd_rate_screen_native ... native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128 | clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) | |---|---|---|---|---| +bars 1080p: sequence, pyramid requested Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) effective Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) +bars 1080p: pricer armings default=17 real=182 +bars 1080p: motion_mode 32x32 SIMPLE=48527 OBMC=0 WARP=211 | 16x16 SIMPLE=4508 OBMC=0 WARP=438 | 8x8 SIMPLE=16138 OBMC=0 WARP=1529 (0.0% OBMC / 3.1% WARP of 71351 eligible) +bars 1080p: inter var-tx depths of 11187 blocks -- leaf single 0=1531 1=1124 (42.3% split) | leaf compound 0=869 1=639 (42.4% split) | 32x32 single 0=769 1=1874 (70.9% split) | 32x32 compound 0=2146 1=2235 (51.0% split) +bars 1080p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0) +bars 1080p: filter intra on=true blocks 28842 (modes DC=6848 V=3145 H=5568 D157=8774 PAETH=4507) +| bars 1080p 1920x1024 | 44.16 dB/219474 B, 47.71 dB/322777 B, 51.09 dB/442730 B, 54.30 dB/593065 B | +2.2% | -14.0% | 43.9s:8.0s:18.9s | +bars 2160p: sequence, pyramid requested Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) effective Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) +bars 2160p: pricer armings default=14 real=175 +bars 2160p: motion_mode 32x32 SIMPLE=42061 OBMC=0 WARP=284 | 16x16 SIMPLE=3119 OBMC=0 WARP=671 | 8x8 SIMPLE=7819 OBMC=0 WARP=252 (0.0% OBMC / 2.2% WARP of 54206 eligible) +bars 2160p: inter var-tx depths of 9166 blocks -- leaf single 0=1267 1=519 (29.1% split) | leaf compound 0=1061 1=257 (19.5% split) | 32x32 single 0=400 1=1261 (75.9% split) | 32x32 compound 0=161 1=4240 (96.3% split) +bars 2160p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0) +bars 2160p: filter intra on=true blocks 13065 (modes DC=3422 V=776 H=2756 D157=4292 PAETH=1819) +| bars 2160p 1920x1024 | 43.68 dB/232087 B, 47.61 dB/341622 B, 51.20 dB/455971 B, 54.53 dB/583936 B | +12.7% | -9.8% | 43.1s:6.3s:20.9s |