Compound references at the 64x64 root
Browse files at this commit52db304f71532fb67f4cdb76e0f15020bb1c25f4Parent: eabe538- feat
- compound references at the 64x64 root
5 changed files +327 -12
- crates/ec-av1/src/encode.rs +230 -3
- crates/ec-av1/src/encoder.rs +65 -0
- crates/ec-av1/src/tile.rs +26 -9
- lanes/b64b/bin-control +0 -0
- lanes/b64b/ctl.log +6 -0
crates/ec-av1/src/encode.rsmodified+230 -3
| @@ -467,6 +467,32 @@ pub fn take_b64_residual_hits() -> usize { | |||
| 467 | B64_RESIDUAL_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | 467 | B64_RESIDUAL_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) |
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | +/// Whether the 64x64 root also prices COMPOUND candidates (lane-b64b): the | ||
| 471 | +/// `LAST` + extra-reference pairs the 32x32 level already offers, at the | ||
| 472 | +/// three modes a root can form without a second 64x64 motion search -- | ||
| 473 | +/// `NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV` and `NEW_NEARESTMV` (whose NEW half | ||
| 474 | +/// is the vector `search_skip_64`'s own single-reference search already | ||
| 475 | +/// found). `NEAREST_NEWMV`/`NEW_NEWMV` need the SECOND reference's own | ||
| 476 | +/// `NEWMV` vector, which only a second search per superblock produces -- the | ||
| 477 | +/// wall this root exists to save -- so they are not offered here. | ||
| 478 | +/// | ||
| 479 | +/// Off by `EC_AV1_B64COMP=0`, so both arms measure on one build. | ||
| 480 | +fn b64_compound() -> bool { | ||
| 481 | + static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | ||
| 482 | + crate::envflags::var("EC_AV1_B64COMP").ok().map(|v| v != "0") | ||
| 483 | + }); | ||
| 484 | + ENV.unwrap_or(true) && b64_root() | ||
| 485 | +} | ||
| 486 | + | ||
| 487 | +/// How many 64x64 roots took a COMPOUND candidate since the last | ||
| 488 | +/// [`take_b64_compound_hits`] (class `gate-blind-to-feature`). | ||
| 489 | +static B64_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 490 | + | ||
| 491 | +/// The compound 64x64-root count since the last call, and zero it. | ||
| 492 | +pub fn take_b64_compound_hits() -> usize { | ||
| 493 | + B64_COMPOUND_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | ||
| 494 | +} | ||
| 495 | + | ||
| 470 | /// Whether the encoder searches loop restoration at all (spec 7.17): one | 496 | /// Whether the encoder searches loop restoration at all (spec 7.17): one |
| 471 | /// Wiener filter per 64x64 luma restoration unit, picked from | 497 | /// Wiener filter per 64x64 luma restoration unit, picked from |
| 472 | /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a | 498 | /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a |
| @@ -7308,6 +7334,42 @@ fn predict_u8( | |||
| 7308 | prediction.iter().map(|&v| v as u8).collect() | 7334 | prediction.iter().map(|&v| v as u8).collect() |
| 7309 | } | 7335 | } |
| 7310 | 7336 | ||
| 7337 | +/// [`predict_u8`]'s compound counterpart, on the heap because a 64x64 root's | ||
| 7338 | +/// side is twice what [`mc_trial_compound`]'s fixed trial buffers hold: both | ||
| 7339 | +/// references predict into the `CONV_BUF` intermediate domain and are blended | ||
| 7340 | +/// at the simple-average split `(8, 8)`, the same path (and so the same | ||
| 7341 | +/// samples) a `comp_group_idx == 0`, `compound_idx == 1` decoder computes. | ||
| 7342 | +fn predict_compound_u8( | ||
| 7343 | + ref0: (&[u16], usize, usize, usize), | ||
| 7344 | + ref1: (&[u16], usize, usize, usize), | ||
| 7345 | + (x, y): (usize, usize), | ||
| 7346 | + side: usize, | ||
| 7347 | + (mv0, mv1): ((i32, i32), (i32, i32)), | ||
| 7348 | + luma: bool, | ||
| 7349 | + fctx: &crate::decode::FrameCtx, | ||
| 7350 | +) -> Vec<u8> { | ||
| 7351 | + let mut inter = [vec![0i32; side * side], vec![0i32; side * side]]; | ||
| 7352 | + for ((mv, r), dst) in [(mv0, ref0), (mv1, ref1)].into_iter().zip(inter.iter_mut()) { | ||
| 7353 | + mc::predict_compound_intermediate( | ||
| 7354 | + r.0, | ||
| 7355 | + r.1, | ||
| 7356 | + r.2, | ||
| 7357 | + r.3, | ||
| 7358 | + mv_to_q4(x, mv.1, luma), | ||
| 7359 | + mv_to_q4(y, mv.0, luma), | ||
| 7360 | + mc::REF_NO_SCALE, | ||
| 7361 | + side, | ||
| 7362 | + side, | ||
| 7363 | + mc::InterpFilterKind::Regular, | ||
| 7364 | + mc::InterpFilterKind::Regular, | ||
| 7365 | + dst, | ||
| 7366 | + ); | ||
| 7367 | + } | ||
| 7368 | + let mut blended = vec![0u16; side * side]; | ||
| 7369 | + mc::combine_compound(&inter[0], &inter[1], 8, 8, &mut blended, fctx); | ||
| 7370 | + blended.iter().map(|&v| v as u8).collect() | ||
| 7371 | +} | ||
| 7372 | + | ||
| 7311 | /// The 64x64 `PARTITION_NONE` candidate for a whole superblock ([`B64_ROOT`]): | 7373 | /// The 64x64 `PARTITION_NONE` candidate for a whole superblock ([`B64_ROOT`]): |
| 7312 | /// single-reference LAST at `NEARESTMV`/`GLOBALMV`/`NEARMV`/`NEWMV`, coded | 7374 | /// single-reference LAST at `NEARESTMV`/`GLOBALMV`/`NEARMV`/`NEWMV`, coded |
| 7313 | /// SKIP, priced through the same `symbol_bits` path every other candidate | 7375 | /// SKIP, priced through the same `symbol_bits` path every other candidate |
| @@ -7328,6 +7390,10 @@ fn search_skip_64( | |||
| 7328 | residual: bool, | 7390 | residual: bool, |
| 7329 | reference: &Picture, | 7391 | reference: &Picture, |
| 7330 | stack: &MvStack, | 7392 | stack: &MvStack, |
| 7393 | + // The COMPOUND stack of each `LAST` + extra-reference pair at THIS | ||
| 7394 | + // superblock's 16x16-mi window, built off the same grid the tile writer | ||
| 7395 | + // rebuilds it from (empty unless the frame carries `reference_select`). | ||
| 7396 | + compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)], | ||
| 7331 | fctx: &crate::decode::FrameCtx, | 7397 | fctx: &crate::decode::FrameCtx, |
| 7332 | ) -> Option<(f64, BlockCoeffs)> { | 7398 | ) -> Option<(f64, BlockCoeffs)> { |
| 7333 | let side = SUPERBLOCK; | 7399 | let side = SUPERBLOCK; |
| @@ -7366,6 +7432,9 @@ fn search_skip_64( | |||
| 7366 | )); | 7432 | )); |
| 7367 | } | 7433 | } |
| 7368 | } | 7434 | } |
| 7435 | + // `LAST`'s own `NEWMV` vector, kept for the compound `NEW_NEARESTMV` | ||
| 7436 | + // candidate below to pair with the second reference's NEAREST half. | ||
| 7437 | + let mut last_new_mv: Option<(i32, i32)> = None; | ||
| 7369 | if leaf_new_mv() { | 7438 | if leaf_new_mv() { |
| 7370 | let source_block = luma.source_block(x, y, side); | 7439 | let source_block = luma.source_block(x, y, side); |
| 7371 | let (seeds, seed_n) = mv_seeds(stack); | 7440 | let (seeds, seed_n) = mv_seeds(stack); |
| @@ -7387,6 +7456,7 @@ fn search_skip_64( | |||
| 7387 | ); | 7456 | ); |
| 7388 | let mv = round_to_valid_mv(found.mv, stack.pred_mv); | 7457 | let mv = round_to_valid_mv(found.mv, stack.pred_mv); |
| 7389 | if let Some((bits, ref_mv_idx)) = best_new_mv_syntax(stack, mv) { | 7458 | if let Some((bits, ref_mv_idx)) = best_new_mv_syntax(stack, mv) { |
| 7459 | + last_new_mv = Some(mv); | ||
| 7390 | cands.push(( | 7460 | cands.push(( |
| 7391 | symbol_bits(&cdf::NEW_MV[stack.new_mv_ctx], 0) + bits, | 7461 | symbol_bits(&cdf::NEW_MV[stack.new_mv_ctx], 0) + bits, |
| 7392 | info_of(InterMode::NewMv, mv, ref_mv_idx), | 7462 | info_of(InterMode::NewMv, mv, ref_mv_idx), |
| @@ -7438,10 +7508,127 @@ fn search_skip_64( | |||
| 7438 | + trials[2].sse | 7508 | + trials[2].sse |
| 7439 | + search.lambda * (fixed + bits); | 7509 | + search.lambda * (fixed + bits); |
| 7440 | if best.as_ref().is_none_or(|b| cost < b.0) { | 7510 | if best.as_ref().is_none_or(|b| cost < b.0) { |
| 7441 | - best = Some((cost, bits, info, trials)); | 7511 | + best = Some((cost, fixed + bits, info, trials)); |
| 7512 | + } | ||
| 7513 | + } | ||
| 7514 | + | ||
| 7515 | + // lane-b64b: the COMPOUND candidates at the 64 root, the same three a | ||
| 7516 | + // superblock can form without a second motion search ([`b64_compound`]), | ||
| 7517 | + // priced through the same `symbol_bits` path -- `fixed` minus the single | ||
| 7518 | + // reference's tree, plus the pair tree and the compound mode. | ||
| 7519 | + for (ref1, g, cstack) in compound.iter().filter(|_| b64_compound()) { | ||
| 7520 | + let (ref1, g) = (*ref1, *g); | ||
| 7521 | + let uni = (crate::mvstack::BWDREF_FRAME..=crate::mvstack::ALTREF_FRAME).contains(&ref1); | ||
| 7522 | + let pair_bits = symbol_bits(&cdf::COMP_MODE[0], 1) | ||
| 7523 | + + if uni { | ||
| 7524 | + symbol_bits(&cdf::COMP_REF_TYPE[0], 1) | ||
| 7525 | + + symbol_bits(&cdf::COMP_REF[0][0], 0) | ||
| 7526 | + + symbol_bits(&cdf::COMP_REF[0][1], 0) | ||
| 7527 | + + symbol_bits(&cdf::COMP_BWDREF[0][0], 1) | ||
| 7528 | + } else { | ||
| 7529 | + symbol_bits(&cdf::COMP_REF_TYPE[0], 0) | ||
| 7530 | + + symbol_bits(&cdf::UNI_COMP_REF[0][0], 0) | ||
| 7531 | + + symbol_bits(&cdf::UNI_COMP_REF[0][1], 1) | ||
| 7532 | + + symbol_bits(&cdf::UNI_COMP_REF[0][2], 1) | ||
| 7533 | + }; | ||
| 7534 | + let mode_ctx = | ||
| 7535 | + cdf::COMPOUND_MODE_CTX_MAP[cstack.ref_mv_ctx >> 1][cstack.new_mv_ctx.min(4)]; | ||
| 7536 | + let mode_bits_of = | ||
| 7537 | + |mode: usize| pair_bits + symbol_bits(&cdf::INTER_COMPOUND_MODE[mode_ctx], mode); | ||
| 7538 | + let compound_info = |mode: InterMode, mvs: ((i32, i32), (i32, i32))| InterInfo { | ||
| 7539 | + ref1: Some(ref1), | ||
| 7540 | + mv1: mvs.1, | ||
| 7541 | + ref_frame: crate::mvstack::LAST_FRAME, | ||
| 7542 | + mode, | ||
| 7543 | + mv: mvs.0, | ||
| 7544 | + ref_mv_idx: 0, | ||
| 7545 | + }; | ||
| 7546 | + let mut ccands: Vec<(((i32, i32), (i32, i32)), f64, InterInfo)> = vec![ | ||
| 7547 | + ( | ||
| 7548 | + cstack.nearest_mv, | ||
| 7549 | + mode_bits_of(0), | ||
| 7550 | + compound_info(InterMode::NearestNearestMv, cstack.nearest_mv), | ||
| 7551 | + ), | ||
| 7552 | + ( | ||
| 7553 | + ((0, 0), (0, 0)), | ||
| 7554 | + mode_bits_of(6), | ||
| 7555 | + compound_info(InterMode::GlobalGlobalMv, ((0, 0), (0, 0))), | ||
| 7556 | + ), | ||
| 7557 | + ]; | ||
| 7558 | + // `NEW_NEARESTMV`: the NEW half is `LAST`'s vector from the search | ||
| 7559 | + // above, its residual priced against compound stack entry 0 -- what | ||
| 7560 | + // `assign_compound_mv` predicts from at `ref_mv_idx = 0`. | ||
| 7561 | + let cbase = cstack | ||
| 7562 | + .entries | ||
| 7563 | + .first() | ||
| 7564 | + .map_or(cstack.nearest_mv, |e| (e.mv0, e.mv1)); | ||
| 7565 | + if let Some(new_mv) = last_new_mv | ||
| 7566 | + && let Some(b0) = mv_residual_bits(new_mv, cbase.0) | ||
| 7567 | + { | ||
| 7568 | + let mvs = (new_mv, cstack.nearest_mv.1); | ||
| 7569 | + ccands.push(( | ||
| 7570 | + mvs, | ||
| 7571 | + mode_bits_of(3) + b0, | ||
| 7572 | + compound_info(InterMode::NewNearestMv, mvs), | ||
| 7573 | + )); | ||
| 7574 | + } | ||
| 7575 | + ccands.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.total_cmp(&b.1))); | ||
| 7576 | + ccands.dedup_by_key(|c| c.0); | ||
| 7577 | + for (mvs, bits, info) in ccands { | ||
| 7578 | + let trials = [ | ||
| 7579 | + (0usize, x, y, side, true), | ||
| 7580 | + (1, x / 2, y / 2, side / 2, false), | ||
| 7581 | + (2, x / 2, y / 2, side / 2, false), | ||
| 7582 | + ] | ||
| 7583 | + .map(|(plane, px, py, s, is_luma)| { | ||
| 7584 | + let (r0, r1) = match plane { | ||
| 7585 | + 0 => ( | ||
| 7586 | + (reference.y.as_slice(), reference.width, luma.true_width, luma.true_height), | ||
| 7587 | + (g.y.as_slice(), g.width, luma.true_width, luma.true_height), | ||
| 7588 | + ), | ||
| 7589 | + 1 => ( | ||
| 7590 | + ( | ||
| 7591 | + reference.u.as_slice(), | ||
| 7592 | + reference.width / 2, | ||
| 7593 | + chroma[0].true_width, | ||
| 7594 | + chroma[0].true_height, | ||
| 7595 | + ), | ||
| 7596 | + (g.u.as_slice(), g.width / 2, chroma[0].true_width, chroma[0].true_height), | ||
| 7597 | + ), | ||
| 7598 | + _ => ( | ||
| 7599 | + ( | ||
| 7600 | + reference.v.as_slice(), | ||
| 7601 | + reference.width / 2, | ||
| 7602 | + chroma[1].true_width, | ||
| 7603 | + chroma[1].true_height, | ||
| 7604 | + ), | ||
| 7605 | + (g.v.as_slice(), g.width / 2, chroma[1].true_width, chroma[1].true_height), | ||
| 7606 | + ), | ||
| 7607 | + }; | ||
| 7608 | + let prediction = | ||
| 7609 | + predict_compound_u8(r0, r1, (px, py), s, mvs, is_luma, fctx); | ||
| 7610 | + let target: &Plane = if plane == 0 { luma } else { &chroma[plane - 1] }; | ||
| 7611 | + target.code_from_prediction( | ||
| 7612 | + px, | ||
| 7613 | + py, | ||
| 7614 | + s, | ||
| 7615 | + &prediction, | ||
| 7616 | + true, | ||
| 7617 | + search.base_q_idx, | ||
| 7618 | + search.deadzone, | ||
| 7619 | + TxbSet::Luma32Inter, | ||
| 7620 | + ) | ||
| 7621 | + }); | ||
| 7622 | + let syntax = fixed - ref_bits + bits; | ||
| 7623 | + let cost = | ||
| 7624 | + trials[0].sse + trials[1].sse + trials[2].sse + search.lambda * syntax; | ||
| 7625 | + if best.as_ref().is_none_or(|b| cost < b.0) { | ||
| 7626 | + best = Some((cost, syntax, info, trials)); | ||
| 7627 | + } | ||
| 7442 | } | 7628 | } |
| 7443 | } | 7629 | } |
| 7444 | - let (skip_cost, bits, info, skip_trials) = best?; | 7630 | + |
| 7631 | + let (skip_cost, syntax, info, skip_trials) = best?; | ||
| 7445 | 7632 | ||
| 7446 | // The winner's prediction coded with a REAL residual (lane-tx64): one | 7633 | // The winner's prediction coded with a REAL residual (lane-tx64): one |
| 7447 | // TX_64X64 luma transform -- `TxbSet::Luma64`, whose coded quarter is the | 7634 | // TX_64X64 luma transform -- `TxbSet::Luma64`, whose coded quarter is the |
| @@ -7477,7 +7664,7 @@ fn search_skip_64( | |||
| 7477 | let unskip = symbol_bits(&cdf::SKIP[0], 0) - symbol_bits(&cdf::SKIP[0], 1); | 7664 | let unskip = symbol_bits(&cdf::SKIP[0], 0) - symbol_bits(&cdf::SKIP[0], 1); |
| 7478 | let coeff_bits: f64 = residual_trials.iter().map(|t| t.bits).sum(); | 7665 | let coeff_bits: f64 = residual_trials.iter().map(|t| t.bits).sum(); |
| 7479 | let cost = residual_trials.iter().map(|t| t.sse).sum::<f64>() | 7666 | let cost = residual_trials.iter().map(|t| t.sse).sum::<f64>() |
| 7480 | - + search.lambda * (fixed + bits + unskip + coeff_bits); | 7667 | + + search.lambda * (syntax + unskip + coeff_bits); |
| 7481 | if cost < skip_cost { | 7668 | if cost < skip_cost { |
| 7482 | B64_RESIDUAL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 7669 | B64_RESIDUAL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 7483 | chosen = (cost, false, residual_trials); | 7670 | chosen = (cost, false, residual_trials); |
| @@ -9182,6 +9369,42 @@ pub(crate) fn encode_inter_frame( | |||
| 9182 | let (mi_row, mi_col) = (sb_r * 16, sb_c * 16); | 9369 | let (mi_row, mi_col) = (sb_r * 16, sb_c * 16); |
| 9183 | let stack = | 9370 | let stack = |
| 9184 | find_mv_stack(&grid, mi_row, mi_col, 16, 16, LAST_FRAME, mi_cols, mi_rows); | 9371 | find_mv_stack(&grid, mi_row, mi_col, 16, 16, LAST_FRAME, mi_cols, mi_rows); |
| 9372 | + // lane-b64b: the `LAST` + extra-reference pairs at this | ||
| 9373 | + // superblock's own 16x16-mi window, the same stacks the tile | ||
| 9374 | + // writer's `Whole64` arm rebuilds. Empty unless the frame | ||
| 9375 | + // codes `reference_select`, which is what gates the syntax. | ||
| 9376 | + let sb_compound: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> = | ||
| 9377 | + if header.reference_select && b64_compound() { | ||
| 9378 | + [ | ||
| 9379 | + (crate::mvstack::GOLDEN_FRAME, golden), | ||
| 9380 | + (crate::mvstack::ALTREF_FRAME, altref), | ||
| 9381 | + ] | ||
| 9382 | + .into_iter() | ||
| 9383 | + .filter_map(|(r, pic)| { | ||
| 9384 | + pic.map(|p| { | ||
| 9385 | + ( | ||
| 9386 | + r, | ||
| 9387 | + p, | ||
| 9388 | + crate::mvstack::find_mv_stack_compound( | ||
| 9389 | + &grid, | ||
| 9390 | + mi_row, | ||
| 9391 | + mi_col, | ||
| 9392 | + 16, | ||
| 9393 | + 16, | ||
| 9394 | + (crate::mvstack::LAST_FRAME, r), | ||
| 9395 | + mi_cols, | ||
| 9396 | + mi_rows, | ||
| 9397 | + grid.sign_bias_table(), | ||
| 9398 | + &[(0, 0); 7], | ||
| 9399 | + None, | ||
| 9400 | + ), | ||
| 9401 | + ) | ||
| 9402 | + }) | ||
| 9403 | + }) | ||
| 9404 | + .collect() | ||
| 9405 | + } else { | ||
| 9406 | + Vec::new() | ||
| 9407 | + }; | ||
| 9185 | if let Some((cost, block)) = search_skip_64( | 9408 | if let Some((cost, block)) = search_skip_64( |
| 9186 | &mut luma, | 9409 | &mut luma, |
| 9187 | &mut chroma, | 9410 | &mut chroma, |
| @@ -9190,6 +9413,7 @@ pub(crate) fn encode_inter_frame( | |||
| 9190 | b64_residual() && !screen, | 9413 | b64_residual() && !screen, |
| 9191 | reference, | 9414 | reference, |
| 9192 | &stack, | 9415 | &stack, |
| 9416 | + &sb_compound, | ||
| 9193 | fctx, | 9417 | fctx, |
| 9194 | ) { | 9418 | ) { |
| 9195 | let after = snapshot(&luma, &chroma, (x64, y64), SUPERBLOCK); | 9419 | let after = snapshot(&luma, &chroma, (x64, y64), SUPERBLOCK); |
| @@ -9630,6 +9854,9 @@ pub(crate) fn encode_inter_frame( | |||
| 9630 | + sb_search.lambda * crate::tile::partition_bits(SUPERBLOCK, true)) | 9854 | + sb_search.lambda * crate::tile::partition_bits(SUPERBLOCK, true)) |
| 9631 | { | 9855 | { |
| 9632 | B64_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 9856 | B64_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 9857 | + if block.inter.is_some_and(|i| i.ref1.is_some()) { | ||
| 9858 | + B64_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 9859 | + } | ||
| 9633 | blocks.truncate(mark); | 9860 | blocks.truncate(mark); |
| 9634 | restore(&mut luma, &mut chroma, (x64, y64), SUPERBLOCK, &after); | 9861 | restore(&mut luma, &mut chroma, (x64, y64), SUPERBLOCK, &after); |
| 9635 | // Overwrites every 16x16 mi cell the quadrant searches | 9862 | // Overwrites every 16x16 mi cell the quadrant searches |
crates/ec-av1/src/encoder.rsmodified+65 -0
| @@ -2846,6 +2846,71 @@ mod tests { | |||
| 2846 | } | 2846 | } |
| 2847 | } | 2847 | } |
| 2848 | 2848 | ||
| 2849 | + /// A CROSSFADE clip (lane-b64b): each picture is a linear blend of two | ||
| 2850 | + /// stills, so on a leaf frame the average of its past (`LAST`) and future | ||
| 2851 | + /// (`ALTREF`) references IS the source and neither reference alone is -- | ||
| 2852 | + /// exactly the content a COMPOUND 64x64 root pays on. The counter is the | ||
| 2853 | + /// gate (class `gate-blind-to-feature`): without it a green three-way | ||
| 2854 | + /// compare says nothing about whether one compound root was written, and | ||
| 2855 | + /// the writer's compound arm (`write_compound_block` at `SB_MI` 16, no | ||
| 2856 | + /// `motion_mode` symbol) desyncs the whole tile if it is wrong. | ||
| 2857 | + #[test] | ||
| 2858 | + fn a_crossfade_clip_codes_a_compound_64x64_root_and_decodes_sample_exact() { | ||
| 2859 | + let _knobs = crate::speed::knob_write(); | ||
| 2860 | + let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 2861 | + let (width, height) = (256usize, 128usize); | ||
| 2862 | + let (a, b) = (test_card(width, height, 0), test_card(width, height, 24)); | ||
| 2863 | + let sources: Vec<Picture> = (0..9) | ||
| 2864 | + .map(|t| { | ||
| 2865 | + let mut p = a.clone(); | ||
| 2866 | + let w = t as u32; | ||
| 2867 | + for (v, &other) in p.y.iter_mut().zip(&b.y) { | ||
| 2868 | + *v = ((u32::from(*v) * (8 - w) + u32::from(other) * w) / 8) as u16; | ||
| 2869 | + } | ||
| 2870 | + p | ||
| 2871 | + }) | ||
| 2872 | + .collect(); | ||
| 2873 | + let config = EncoderConfig { | ||
| 2874 | + width, | ||
| 2875 | + height, | ||
| 2876 | + base_q_idx: 120, | ||
| 2877 | + gop: 9, | ||
| 2878 | + colour: Colour::Bt709Limited, | ||
| 2879 | + tile_cols_log2: 0, | ||
| 2880 | + tile_rows_log2: 0, | ||
| 2881 | + }; | ||
| 2882 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 2883 | + let mut stream = Vec::new(); | ||
| 2884 | + let _ = crate::encode::take_b64_compound_hits(); | ||
| 2885 | + for packet in encode_all(&mut enc, &sources) { | ||
| 2886 | + stream.extend_from_slice(&packet.data); | ||
| 2887 | + } | ||
| 2888 | + let compound = crate::encode::take_b64_compound_hits(); | ||
| 2889 | + assert!(compound > 0, "a crossfade clip coded no COMPOUND 64x64 root at all"); | ||
| 2890 | + eprintln!("compound 64x64 roots on a crossfade clip: {compound}"); | ||
| 2891 | + | ||
| 2892 | + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | ||
| 2893 | + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | ||
| 2894 | + if !have_ffmpeg() { | ||
| 2895 | + eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2896 | + return; | ||
| 2897 | + } | ||
| 2898 | + let theirs = ffmpeg_decode_luma(&stream, width, height); | ||
| 2899 | + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | ||
| 2900 | + for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { | ||
| 2901 | + let got: Vec<u8> = ours_i.y.iter().map(|&v| v as u8).collect(); | ||
| 2902 | + if let Some(at) = got.iter().zip(theirs_i).position(|(x, y)| x != y) { | ||
| 2903 | + panic!( | ||
| 2904 | + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", | ||
| 2905 | + at % width, | ||
| 2906 | + at / width, | ||
| 2907 | + got[at], | ||
| 2908 | + theirs_i[at], | ||
| 2909 | + ); | ||
| 2910 | + } | ||
| 2911 | + } | ||
| 2912 | + } | ||
| 2913 | + | ||
| 2849 | #[test] | 2914 | #[test] |
| 2850 | fn every_tile_layout_decodes_sample_exact_through_both_decoders() { | 2915 | fn every_tile_layout_decodes_sample_exact_through_both_decoders() { |
| 2851 | let _knobs = crate::speed::knob_read(); | 2916 | let _knobs = crate::speed::knob_read(); |
crates/ec-av1/src/tile.rsmodified+26 -9
| @@ -5634,12 +5634,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5634 | let info = block.inter.ok_or_else(|| { | 5634 | let info = block.inter.ok_or_else(|| { |
| 5635 | Error::unsupported("AV1 tile", "a 64x64 root block is coded inter") | 5635 | Error::unsupported("AV1 tile", "a 64x64 root block is coded inter") |
| 5636 | })?; | 5636 | })?; |
| 5637 | - if info.ref1.is_some() { | ||
| 5638 | - return Err(Error::unsupported( | ||
| 5639 | - "AV1 tile", | ||
| 5640 | - "a 64x64 root block is coded single-reference", | ||
| 5641 | - )); | ||
| 5642 | - } | ||
| 5643 | enc.symbol(PARTITION_NONE, &mut cdfs.partition_w64[sb_ctx]); | 5637 | enc.symbol(PARTITION_NONE, &mut cdfs.partition_w64[sb_ctx]); |
| 5644 | let (mi_r, mi_c) = (sb_at.0 * (SUB / MI), sb_at.1 * (SUB / MI)); | 5638 | let (mi_r, mi_c) = (sb_at.0 * (SUB / MI), sb_at.1 * (SUB / MI)); |
| 5645 | let has_above = neighbours.has_above(mi_r); | 5639 | let has_above = neighbours.has_above(mi_r); |
| @@ -5661,8 +5655,24 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5661 | &neighbours, | 5655 | &neighbours, |
| 5662 | (mi_r, mi_c), | 5656 | (mi_r, mi_c), |
| 5663 | (has_above, has_left), | 5657 | (has_above, has_left), |
| 5664 | - false, | 5658 | + info.ref1.is_some(), |
| 5665 | ); | 5659 | ); |
| 5660 | + // lane-b64b: a COMPOUND 64x64 root takes the same mode chain | ||
| 5661 | + // every other compound block does, at this superblock's own | ||
| 5662 | + // 16x16-mi window. | ||
| 5663 | + let (mv, mv1, is_new_mv) = if info.ref1.is_some() { | ||
| 5664 | + write_compound_block( | ||
| 5665 | + &mut enc, | ||
| 5666 | + &mut cdfs, | ||
| 5667 | + &neighbours, | ||
| 5668 | + &grid, | ||
| 5669 | + (mi_r, mi_c), | ||
| 5670 | + (SB_MI as usize, SB_MI as usize), | ||
| 5671 | + (has_above, has_left), | ||
| 5672 | + info, | ||
| 5673 | + (mi_cols as usize, mi_rows as usize), | ||
| 5674 | + )? | ||
| 5675 | + } else { | ||
| 5666 | write_single_ref( | 5676 | write_single_ref( |
| 5667 | &mut enc, | 5677 | &mut enc, |
| 5668 | &mut cdfs, | 5678 | &mut cdfs, |
| @@ -5683,6 +5693,8 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5683 | mi_rows as usize, | 5693 | mi_rows as usize, |
| 5684 | ); | 5694 | ); |
| 5685 | let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; | 5695 | let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; |
| 5696 | + (mv, (0, 0), is_new_mv) | ||
| 5697 | + }; | ||
| 5686 | for dr in 0..SB_MI as usize { | 5698 | for dr in 0..SB_MI as usize { |
| 5687 | for dc in 0..SB_MI as usize { | 5699 | for dc in 0..SB_MI as usize { |
| 5688 | grid.set( | 5700 | grid.set( |
| @@ -5691,8 +5703,8 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5691 | MiInfo { | 5703 | MiInfo { |
| 5692 | is_inter: true, | 5704 | is_inter: true, |
| 5693 | ref_frame: info.ref_frame, | 5705 | ref_frame: info.ref_frame, |
| 5694 | - ref_frame1: NO_REF1, | 5706 | + ref_frame1: info.ref1.unwrap_or(NO_REF1), |
| 5695 | - mv1: (0, 0), | 5707 | + mv1: mv16(mv1), |
| 5696 | mv: mv16(mv), | 5708 | mv: mv16(mv), |
| 5697 | is_new_mv, | 5709 | is_new_mv, |
| 5698 | size: SB_MI as u8, | 5710 | size: SB_MI as u8, |
| @@ -5703,6 +5715,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5703 | ); | 5715 | ); |
| 5704 | } | 5716 | } |
| 5705 | } | 5717 | } |
| 5718 | + if info.ref1.is_none() { | ||
| 5719 | + // libaom's `motion_mode_allowed` fails on a compound | ||
| 5720 | + // block, so the decoder reads no symbol for one. | ||
| 5706 | write_motion_mode( | 5721 | write_motion_mode( |
| 5707 | &mut enc, | 5722 | &mut enc, |
| 5708 | &mut cdfs, | 5723 | &mut cdfs, |
| @@ -5714,6 +5729,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5714 | info.ref_frame, | 5729 | info.ref_frame, |
| 5715 | block.motion_mode, | 5730 | block.motion_mode, |
| 5716 | )?; | 5731 | )?; |
| 5732 | + } | ||
| 5717 | if tx_select { | 5733 | if tx_select { |
| 5718 | // A skipped inter block writes no `txfm_split` at all -- | 5734 | // A skipped inter block writes no `txfm_split` at all -- |
| 5719 | // that call only publishes the max transform size the | 5735 | // that call only publishes the max transform size the |
| @@ -5759,6 +5775,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5759 | neighbours.record_planes(sb_at, SB, 0, &grids, true); | 5775 | neighbours.record_planes(sb_at, SB, 0, &grids, true); |
| 5760 | } | 5776 | } |
| 5761 | neighbours.record_inter(sb_at, SB, block.skip, true, block_ref(block)); | 5777 | neighbours.record_inter(sb_at, SB, block.skip, true, block_ref(block)); |
| 5778 | + record_block_compound(&mut neighbours, (mi_r, mi_c), SB, block); | ||
| 5762 | continue; | 5779 | continue; |
| 5763 | } | 5780 | } |
| 5764 | match (has_cols, has_rows) { | 5781 | match (has_cols, has_rows) { |
lanes/b64b/bin-controladded+0 -0
Binary file changed
lanes/b64b/ctl.logadded+6 -0
| @@ -0,0 +1,6 @@ | |||
| 1 | + | ||
| 2 | +running 0 tests | ||
| 3 | + | ||
| 4 | +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 602 filtered out; finished in 0.00s | ||
| 5 | + | ||
| 6 | +RC=0 | ||