The RDOQ pass only lowers D + lambda*R and reports its own grid
Browse files at this commit30a94a1d323d5d236f428725f8e76430f8daaaf2Parent: 4cc1d86- test
- the RDOQ pass only lowers D + lambda*R and reports its own grid
2 changed files +90 -0
- crates/ec-av1/src/tile.rs +76 -0
- lanes/rdoq-ctl.log +14 -0
crates/ec-av1/src/tile.rsmodified+76 -0
| @@ -8488,6 +8488,82 @@ mod tests { | ||
| 8488 | 8488 | /// be: every position exactly once, the origin first, and never a position |
| 8489 | 8489 | /// before one it sits diagonally behind — which is what lets a decoder read |
| 8490 | 8490 | /// a coefficient's context off the coefficients it has already decoded. |
| 8491 | + /// lane-rdoq's two contracts, on a block shaped like the ones the pass | |
| 8492 | + /// exists for (a strong DC, two mid levels and a tail of barely-rounded | |
| 8493 | + /// +-1s): it may only move a block to a LOWER `D + lambda * R`, and the | |
| 8494 | + /// bits it hands back must be the price of the grid it leaves behind -- | |
| 8495 | + /// the search takes that number as the block's rate, so a stale one | |
| 8496 | + /// would price a tile nobody writes. | |
| 8497 | + #[test] | |
| 8498 | + fn rdoq_only_lowers_the_cost_and_reports_its_own_grid() { | |
| 8499 | + let (side, set, q, lambda) = (16usize, TxbSet::Luma16, 150u8, 0.0275); | |
| 8500 | + let mut scaled = vec![0f32; side * side]; | |
| 8501 | + for (i, v) in [ | |
| 8502 | + (0usize, 7.4f32), | |
| 8503 | + (1, 2.6), | |
| 8504 | + (side, -1.55), | |
| 8505 | + // The tail the pass exists for: coefficients the deadzone only | |
| 8506 | + // just rounded up to +-1, which give a whole level back for a | |
| 8507 | + // fraction of one step of squared error. | |
| 8508 | + (2, 0.55), | |
| 8509 | + (2 * side + 1, -0.52), | |
| 8510 | + (3 * side + 3, 0.51), | |
| 8511 | + ] { | |
| 8512 | + scaled[i] = v; | |
| 8513 | + } | |
| 8514 | + // The deadzone quantiser this pass runs after, at the shipped 0.5. | |
| 8515 | + let mut levels: Vec<i32> = scaled | |
| 8516 | + .iter() | |
| 8517 | + .map(|&v| { | |
| 8518 | + let m = f64::from(v).abs() + 0.5; | |
| 8519 | + let l = if m < 1.0 { 0 } else { m.floor() as i32 }; | |
| 8520 | + if v < 0.0 { -l } else { l } | |
| 8521 | + }) | |
| 8522 | + .collect(); | |
| 8523 | + let before = levels.clone(); | |
| 8524 | + let dc = f64::from(crate::quant::dc_q(8, i32::from(q))); | |
| 8525 | + let ac = f64::from(crate::quant::ac_q(8, i32::from(q))); | |
| 8526 | + let dc_weight = (dc / ac) * (dc / ac); | |
| 8527 | + let cost = |grid: &[i32]| -> f64 { | |
| 8528 | + let d: f64 = grid | |
| 8529 | + .iter() | |
| 8530 | + .zip(&scaled) | |
| 8531 | + .enumerate() | |
| 8532 | + .map(|(i, (&l, &s))| { | |
| 8533 | + (if i == 0 { dc_weight } else { 1.0 }) | |
| 8534 | + * (f64::from(s) - f64::from(l)).powi(2) | |
| 8535 | + }) | |
| 8536 | + .sum(); | |
| 8537 | + d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) | |
| 8538 | + }; | |
| 8539 | + let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda); | |
| 8540 | + assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); | |
| 8541 | + assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); | |
| 8542 | + // The tail is what it is for: the last coded position moves earlier. | |
| 8543 | + let last = |g: &[i32]| scan_of(side).iter().rposition(|&p| g[usize::from(p)] != 0); | |
| 8544 | + assert!(last(&levels) < last(&before), "eob {:?} -> {:?}", last(&before), last(&levels)); | |
| 8545 | + // A 64-point transform is priced on its top-left 32x32 corner, and | |
| 8546 | + // the pass has to hand back THAT price (the dense path). | |
| 8547 | + let (side, set) = (64usize, TxbSet::Luma64); | |
| 8548 | + let mut scaled = vec![0f32; side * side]; | |
| 8549 | + for (i, v) in [(0usize, 6.1f32), (1, 0.55), (side + 1, -0.53)] { | |
| 8550 | + scaled[i] = v; | |
| 8551 | + } | |
| 8552 | + let mut levels: Vec<i32> = scaled | |
| 8553 | + .iter() | |
| 8554 | + .map(|&v| { | |
| 8555 | + let m = f64::from(v).abs() + 0.5; | |
| 8556 | + let l = if m < 1.0 { 0 } else { m.floor() as i32 }; | |
| 8557 | + if v < 0.0 { -l } else { l } | |
| 8558 | + }) | |
| 8559 | + .collect(); | |
| 8560 | + let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda); | |
| 8561 | + let corner: Vec<i32> = (0..32) | |
| 8562 | + .flat_map(|row| levels[row * side..][..32].to_vec()) | |
| 8563 | + .collect(); | |
| 8564 | + assert_eq!(bits, coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0)); | |
| 8565 | + } | |
| 8566 | + | |
| 8491 | 8567 | #[test] |
| 8492 | 8568 | fn the_default_scan_walks_every_position_outwards() { |
| 8493 | 8569 | for side in [TX16, TX32] { |
lanes/rdoq-ctl.logmodified+14 -0
| @@ -4,3 +4,17 @@ test encode::tests::bd_rate_screen_native ... | ||
| 4 | 4 | native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128 |
| 5 | 5 | | clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) | |
| 6 | 6 | |---|---|---|---|---| |
| 7 | +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 }) | |
| 8 | +bars 1080p: pricer armings default=17 real=182 | |
| 9 | +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) | |
| 10 | +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) | |
| 11 | +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) | |
| 12 | +bars 1080p: filter intra on=true blocks 28842 (modes DC=6848 V=3145 H=5568 D157=8774 PAETH=4507) | |
| 13 | +| 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 | | |
| 14 | +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 }) | |
| 15 | +bars 2160p: pricer armings default=14 real=175 | |
| 16 | +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) | |
| 17 | +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) | |
| 18 | +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) | |
| 19 | +bars 2160p: filter intra on=true blocks 13065 (modes DC=3422 V=776 H=2756 D157=4292 PAETH=1819) | |
| 20 | +| 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 | |