A 64x64 root may split its luma into four TX_32X32 units
Browse files at this commit3f6896d4a6d1907c57a86140c5d3c654eedd1621Parent: 0070986- feat
- a 64x64 root may split its luma into four TX_32X32 units
4 changed files +255 -22
- crates/ec-av1/src/encode.rs +111 -9
- crates/ec-av1/src/encoder.rs +66 -0
- crates/ec-av1/src/tile.rs +51 -13
- lanes/b64b/r2-ship.log +27 -0
crates/ec-av1/src/encode.rsmodified+111 -9
| @@ -493,6 +493,30 @@ pub fn take_b64_compound_hits() -> usize { | |||
| 493 | B64_COMPOUND_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | 493 | B64_COMPOUND_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | +/// Whether a 64x64 root that codes a residual may SPLIT its luma transform | ||
| 497 | +/// (lane-b64b): four TX_32X32 units instead of the one TX_64X64, decided by | ||
| 498 | +/// [`commit_inter_luma`] like every other inter block's var-tx, and coded by | ||
| 499 | +/// the writer's `Whole64` arm as `txfm_split = 1`. It exists because | ||
| 500 | +/// TX_64X64 zeroes everything outside its 32x32 corner, so a root whose | ||
| 501 | +/// residual has detail in the other three quadrants cannot code it at all. | ||
| 502 | +/// | ||
| 503 | +/// Off by `EC_AV1_B64VARTX=0`. | ||
| 504 | +fn b64_var_tx() -> bool { | ||
| 505 | + static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| { | ||
| 506 | + crate::envflags::var("EC_AV1_B64VARTX").ok().map(|v| v != "0") | ||
| 507 | + }); | ||
| 508 | + ENV.unwrap_or(true) && b64_root() | ||
| 509 | +} | ||
| 510 | + | ||
| 511 | +/// How many 64x64 roots split their luma transform since the last | ||
| 512 | +/// [`take_b64_var_tx_hits`]. | ||
| 513 | +static B64_VAR_TX_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 514 | + | ||
| 515 | +/// The split-luma 64x64-root count since the last call, and zero it. | ||
| 516 | +pub fn take_b64_var_tx_hits() -> usize { | ||
| 517 | + B64_VAR_TX_HITS.swap(0, std::sync::atomic::Ordering::Relaxed) | ||
| 518 | +} | ||
| 519 | + | ||
| 496 | /// Whether the encoder searches loop restoration at all (spec 7.17): one | 520 | /// Whether the encoder searches loop restoration at all (spec 7.17): one |
| 497 | /// Wiener filter per 64x64 luma restoration unit, picked from | 521 | /// Wiener filter per 64x64 luma restoration unit, picked from |
| 498 | /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a | 522 | /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a |
| @@ -3412,7 +3436,7 @@ fn commit_inter_luma( | |||
| 3412 | && !skip | 3436 | && !skip |
| 3413 | && side >= 16 | 3437 | && side >= 16 |
| 3414 | && (second.is_none() || compound_var_tx()) | 3438 | && (second.is_none() || compound_var_tx()) |
| 3415 | - && (side < BLOCK || tx32_depth_search()) | 3439 | + && (side != BLOCK || tx32_depth_search()) |
| 3416 | && x + side <= luma.true_width | 3440 | && x + side <= luma.true_width |
| 3417 | && y + side <= luma.true_height; | 3441 | && y + side <= luma.true_height; |
| 3418 | if !eligible { | 3442 | if !eligible { |
| @@ -3420,7 +3444,14 @@ fn commit_inter_luma( | |||
| 3420 | return (flat.levels.clone(), 0, 0.0); | 3444 | return (flat.levels.clone(), 0, 0.0); |
| 3421 | } | 3445 | } |
| 3422 | let tx = side / 2; | 3446 | let tx = side / 2; |
| 3423 | - let set = if tx >= 16 { TxbSet::Luma16Inter } else { TxbSet::Luma8Inter }; | 3447 | + let set = if tx >= 32 { |
| 3448 | + // lane-b64b: the 64x64 root's halved transform is TX_32X32. | ||
| 3449 | + TxbSet::Luma32Inter | ||
| 3450 | + } else if tx >= 16 { | ||
| 3451 | + TxbSet::Luma16Inter | ||
| 3452 | + } else { | ||
| 3453 | + TxbSet::Luma8Inter | ||
| 3454 | + }; | ||
| 3424 | let mut levels = vec![0i32; side * side]; | 3455 | let mut levels = vec![0i32; side * side]; |
| 3425 | let (mut sse, mut bits) = (0.0, 0.0); | 3456 | let (mut sse, mut bits) = (0.0, 0.0); |
| 3426 | let mut units = Vec::with_capacity(4); | 3457 | let mut units = Vec::with_capacity(4); |
| @@ -3454,14 +3485,22 @@ fn commit_inter_luma( | |||
| 3454 | let split_cost = sse + search.lambda * (bits + txfm_split_bits(side, 1)); | 3485 | let split_cost = sse + search.lambda * (bits + txfm_split_bits(side, 1)); |
| 3455 | let flat_cost = flat.sse + search.lambda * (flat.bits + txfm_split_bits(side, 0)); | 3486 | let flat_cost = flat.sse + search.lambda * (flat.bits + txfm_split_bits(side, 0)); |
| 3456 | let class = usize::from(side == BLOCK) * 4 + usize::from(second.is_some()) * 2; | 3487 | let class = usize::from(side == BLOCK) * 4 + usize::from(second.is_some()) * 2; |
| 3488 | + // The depth census has a leaf row and a 32x32 row and no 64 one, so the | ||
| 3489 | + // 64x64 root counts itself ([`take_b64_var_tx_hits`]) instead of landing | ||
| 3490 | + // in the leaf row (class `gate-blind-to-feature`). | ||
| 3491 | + let counted = side <= BLOCK; | ||
| 3457 | if split_cost < flat_cost { | 3492 | if split_cost < flat_cost { |
| 3458 | for (tu_x, tu_y, trial) in &units { | 3493 | for (tu_x, tu_y, trial) in &units { |
| 3459 | luma.commit(*tu_x, *tu_y, tx, trial); | 3494 | luma.commit(*tu_x, *tu_y, tx, trial); |
| 3460 | } | 3495 | } |
| 3461 | - INTER_TX_SPLIT_HITS[class + 1].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 3496 | + if counted { |
| 3497 | + INTER_TX_SPLIT_HITS[class + 1].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 3498 | + } | ||
| 3462 | return (levels, 1, split_cost - flat_cost); | 3499 | return (levels, 1, split_cost - flat_cost); |
| 3463 | } | 3500 | } |
| 3464 | - INTER_TX_SPLIT_HITS[class].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 3501 | + if counted { |
| 3502 | + INTER_TX_SPLIT_HITS[class].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 3503 | + } | ||
| 3465 | luma.commit(x, y, side, flat); | 3504 | luma.commit(x, y, side, flat); |
| 3466 | (flat.levels.clone(), 0, 0.0) | 3505 | (flat.levels.clone(), 0, 0.0) |
| 3467 | } | 3506 | } |
| @@ -7642,6 +7681,13 @@ fn search_skip_64( | |||
| 7642 | // two numbers are comparable: `fixed` charged `skip` coded 1, and this | 7681 | // two numbers are comparable: `fixed` charged `skip` coded 1, and this |
| 7643 | // arm charges 0 instead and adds its three planes' coefficient bits. | 7682 | // arm charges 0 instead and adds its three planes' coefficient bits. |
| 7644 | let mut chosen = (skip_cost, true, skip_trials); | 7683 | let mut chosen = (skip_cost, true, skip_trials); |
| 7684 | + // Set when [`commit_inter_luma`] already wrote the residual arm's luma | ||
| 7685 | + // into the plane, so the tail below does not commit over its units. | ||
| 7686 | + let mut luma_committed = false; | ||
| 7687 | + // The residual arm's luma levels and the `txfm_split` depth the writer | ||
| 7688 | + // codes: depth 0 is the TX_64X64 corner in 32x32 coordinates, depth 1 is | ||
| 7689 | + // four TX_32X32 units in 64x64 ones. | ||
| 7690 | + let mut luma_levels: Option<(Vec<i32>, u8)> = None; | ||
| 7645 | if residual { | 7691 | if residual { |
| 7646 | let sets = [TxbSet::Luma64, TxbSet::Chroma32, TxbSet::Chroma32]; | 7692 | let sets = [TxbSet::Luma64, TxbSet::Chroma32, TxbSet::Chroma32]; |
| 7647 | let residual_trials = [0usize, 1, 2].map(|plane| { | 7693 | let residual_trials = [0usize, 1, 2].map(|plane| { |
| @@ -7663,16 +7709,54 @@ fn search_skip_64( | |||
| 7663 | }); | 7709 | }); |
| 7664 | let unskip = symbol_bits(&cdf::SKIP[0], 0) - symbol_bits(&cdf::SKIP[0], 1); | 7710 | let unskip = symbol_bits(&cdf::SKIP[0], 0) - symbol_bits(&cdf::SKIP[0], 1); |
| 7665 | let coeff_bits: f64 = residual_trials.iter().map(|t| t.bits).sum(); | 7711 | let coeff_bits: f64 = residual_trials.iter().map(|t| t.bits).sum(); |
| 7712 | + // lane-b64b: the root's own var-tx decision -- one TX_64X64 or the | ||
| 7713 | + // four TX_32X32 units of `txfm_split = 1`, taken by the same | ||
| 7714 | + // `commit_inter_luma` every other inter block's is (it commits the | ||
| 7715 | + // winner and hands back the cost it took off the flat arm). | ||
| 7716 | + let (levels, depth, gain) = if b64_var_tx() { | ||
| 7717 | + let second = info.ref1.and_then(|r1| { | ||
| 7718 | + compound.iter().find(|(r, _, _)| *r == r1).map(|&(_, g, _)| { | ||
| 7719 | + ( | ||
| 7720 | + info.mv1, | ||
| 7721 | + (g.y.as_slice(), g.width, luma.true_width, luma.true_height), | ||
| 7722 | + ) | ||
| 7723 | + }) | ||
| 7724 | + }); | ||
| 7725 | + luma_committed = true; | ||
| 7726 | + commit_inter_luma( | ||
| 7727 | + luma, | ||
| 7728 | + (x, y), | ||
| 7729 | + side, | ||
| 7730 | + info.mv, | ||
| 7731 | + (&reference.y, reference.width, luma.true_width, luma.true_height), | ||
| 7732 | + search, | ||
| 7733 | + &residual_trials[0], | ||
| 7734 | + false, | ||
| 7735 | + second, | ||
| 7736 | + fctx, | ||
| 7737 | + ) | ||
| 7738 | + } else { | ||
| 7739 | + (residual_trials[0].levels.clone(), 0, 0.0) | ||
| 7740 | + }; | ||
| 7666 | let cost = residual_trials.iter().map(|t| t.sse).sum::<f64>() | 7741 | let cost = residual_trials.iter().map(|t| t.sse).sum::<f64>() |
| 7667 | - + search.lambda * (syntax + unskip + coeff_bits); | 7742 | + + search.lambda * (syntax + unskip + coeff_bits) |
| 7743 | + + gain; | ||
| 7668 | if cost < skip_cost { | 7744 | if cost < skip_cost { |
| 7669 | B64_RESIDUAL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 7745 | B64_RESIDUAL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 7746 | + if depth == 1 { | ||
| 7747 | + B64_VAR_TX_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 7748 | + } | ||
| 7749 | + luma_levels = Some((levels, depth)); | ||
| 7670 | chosen = (cost, false, residual_trials); | 7750 | chosen = (cost, false, residual_trials); |
| 7671 | } | 7751 | } |
| 7672 | } | 7752 | } |
| 7673 | 7753 | ||
| 7674 | let (cost, skip, trials) = chosen; | 7754 | let (cost, skip, trials) = chosen; |
| 7675 | - luma.commit(x, y, side, &trials[0]); | 7755 | + // `commit_inter_luma` already wrote the residual arm's luma (its four |
| 7756 | + // split units are not one 64-sided trial); a skip winner overwrites it. | ||
| 7757 | + if skip || !luma_committed { | ||
| 7758 | + luma.commit(x, y, side, &trials[0]); | ||
| 7759 | + } | ||
| 7676 | chroma[0].commit(x / 2, y / 2, side / 2, &trials[1]); | 7760 | chroma[0].commit(x / 2, y / 2, side / 2, &trials[1]); |
| 7677 | chroma[1].commit(x / 2, y / 2, side / 2, &trials[2]); | 7761 | chroma[1].commit(x / 2, y / 2, side / 2, &trials[2]); |
| 7678 | Some(( | 7762 | Some(( |
| @@ -7680,9 +7764,16 @@ fn search_skip_64( | |||
| 7680 | BlockCoeffs { | 7764 | BlockCoeffs { |
| 7681 | skip, | 7765 | skip, |
| 7682 | inter: Some(info), | 7766 | inter: Some(info), |
| 7683 | - // Both grids are 32-sided: the luma one is the 64-point | 7767 | + // The chroma grids are whole TX_32X32; the luma one is the |
| 7684 | - // transform's coded corner, the chroma ones are whole TX_32X32. | 7768 | + // 64-point transform's coded 32x32 corner at depth 0 and the |
| 7685 | - luma: if skip { Vec::new() } else { coeffs(&trials[0].levels, BLOCK) }, | 7769 | + // whole 64-sided block at depth 1 (lane-b64b). |
| 7770 | + tx_depth: luma_levels.as_ref().map_or(0, |&(_, d)| d), | ||
| 7771 | + luma: match (skip, &luma_levels) { | ||
| 7772 | + (true, _) => Vec::new(), | ||
| 7773 | + (false, Some((levels, 1))) => coeffs(levels, SUPERBLOCK), | ||
| 7774 | + (false, Some((levels, _))) => coeffs(levels, BLOCK), | ||
| 7775 | + (false, None) => coeffs(&trials[0].levels, BLOCK), | ||
| 7776 | + }, | ||
| 7686 | u: if skip { Vec::new() } else { coeffs(&trials[1].levels, side / 2) }, | 7777 | u: if skip { Vec::new() } else { coeffs(&trials[1].levels, side / 2) }, |
| 7687 | v: if skip { Vec::new() } else { coeffs(&trials[2].levels, side / 2) }, | 7778 | v: if skip { Vec::new() } else { coeffs(&trials[2].levels, side / 2) }, |
| 7688 | ..BlockCoeffs::default() | 7779 | ..BlockCoeffs::default() |
| @@ -15024,6 +15115,17 @@ mod tests { | |||
| 15024 | // the real side, a screen clip none of them. | 15115 | // the real side, a screen clip none of them. |
| 15025 | let (price_default, price_real) = crate::tile::take_pricing_hits(); | 15116 | let (price_default, price_real) = crate::tile::take_pricing_hits(); |
| 15026 | eprintln!("{name}: pricer armings default={price_default} real={price_real}"); | 15117 | eprintln!("{name}: pricer armings default={price_default} real={price_real}"); |
| 15118 | + // The 64x64 root's own fire shares (lane-b64/tx64/b64b): how many | ||
| 15119 | + // superblocks stayed whole, and how many of those coded a | ||
| 15120 | + // residual, split that residual's luma, or took a compound | ||
| 15121 | + // reference (class `gate-blind-to-feature`). | ||
| 15122 | + eprintln!( | ||
| 15123 | + "{name}: 64x64 roots {} (with a residual {}, split luma {}, compound {})", | ||
| 15124 | + take_b64_root_hits(), | ||
| 15125 | + take_b64_residual_hits(), | ||
| 15126 | + take_b64_var_tx_hits(), | ||
| 15127 | + take_b64_compound_hits(), | ||
| 15128 | + ); | ||
| 15027 | // lane-av1obmc2: the same motion_mode census the 640x384 gate | 15129 | // lane-av1obmc2: the same motion_mode census the 640x384 gate |
| 15028 | // prints (class `gate-blind-to-feature`) -- how many blocks coded | 15130 | // prints (class `gate-blind-to-feature`) -- how many blocks coded |
| 15029 | // the symbol at each footprint and how many took OBMC. Without it | 15131 | // the symbol at each footprint and how many took OBMC. Without it |
crates/ec-av1/src/encoder.rsmodified+66 -0
| @@ -2846,6 +2846,72 @@ mod tests { | |||
| 2846 | } | 2846 | } |
| 2847 | } | 2847 | } |
| 2848 | 2848 | ||
| 2849 | + /// A clip whose inter residual is HIGH-FREQUENCY (lane-b64b): every | ||
| 2850 | + /// frame adds a 4-pixel checkerboard, so the 64x64 root's prediction is | ||
| 2851 | + /// off by exactly the detail a TX_64X64 throws away (it codes only the | ||
| 2852 | + /// top-left 32x32 corner of its coefficient space) and the root's var-tx | ||
| 2853 | + /// arm splits its luma into four TX_32X32 units instead. The counter is | ||
| 2854 | + /// the gate (class `gate-blind-to-feature`), and a `txfm_split` the | ||
| 2855 | + /// reader does not expect desyncs the whole tile, so both decoders have | ||
| 2856 | + /// to reconstruct it sample-exact. | ||
| 2857 | + #[test] | ||
| 2858 | + fn a_high_frequency_clip_splits_the_64x64_roots_luma_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 still = test_card(width, height, 0); | ||
| 2863 | + let sources: Vec<Picture> = (0..4) | ||
| 2864 | + .map(|t| { | ||
| 2865 | + let mut p = still.clone(); | ||
| 2866 | + for (i, v) in p.y.iter_mut().enumerate() { | ||
| 2867 | + let checker = ((i % width) / 4 + (i / width) / 4) % 2; | ||
| 2868 | + let bump = (t * 5 * (checker + 1)) as u16; | ||
| 2869 | + *v = (*v + bump).min(255); | ||
| 2870 | + } | ||
| 2871 | + p | ||
| 2872 | + }) | ||
| 2873 | + .collect(); | ||
| 2874 | + let config = EncoderConfig { | ||
| 2875 | + width, | ||
| 2876 | + height, | ||
| 2877 | + base_q_idx: 90, | ||
| 2878 | + gop: 8, | ||
| 2879 | + colour: Colour::Bt709Limited, | ||
| 2880 | + tile_cols_log2: 0, | ||
| 2881 | + tile_rows_log2: 0, | ||
| 2882 | + }; | ||
| 2883 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 2884 | + let mut stream = Vec::new(); | ||
| 2885 | + let _ = crate::encode::take_b64_var_tx_hits(); | ||
| 2886 | + for packet in encode_all(&mut enc, &sources) { | ||
| 2887 | + stream.extend_from_slice(&packet.data); | ||
| 2888 | + } | ||
| 2889 | + let split = crate::encode::take_b64_var_tx_hits(); | ||
| 2890 | + assert!(split > 0, "no 64x64 root split its luma transform at all"); | ||
| 2891 | + eprintln!("64x64 roots with a SPLIT luma transform: {split}"); | ||
| 2892 | + | ||
| 2893 | + let ours = crate::stream::decode_stream(&stream).expect("our decoder"); | ||
| 2894 | + assert_eq!(ours.len(), sources.len(), "our decoder's frames"); | ||
| 2895 | + if !have_ffmpeg() { | ||
| 2896 | + eprintln!("SKIP the ffmpeg half: no ffmpeg"); | ||
| 2897 | + return; | ||
| 2898 | + } | ||
| 2899 | + let theirs = ffmpeg_decode_luma(&stream, width, height); | ||
| 2900 | + assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames"); | ||
| 2901 | + for (i, (ours_i, theirs_i)) in ours.iter().zip(&theirs).enumerate() { | ||
| 2902 | + let got: Vec<u8> = ours_i.y.iter().map(|&v| v as u8).collect(); | ||
| 2903 | + if let Some(at) = got.iter().zip(theirs_i).position(|(x, y)| x != y) { | ||
| 2904 | + panic!( | ||
| 2905 | + "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}", | ||
| 2906 | + at % width, | ||
| 2907 | + at / width, | ||
| 2908 | + got[at], | ||
| 2909 | + theirs_i[at], | ||
| 2910 | + ); | ||
| 2911 | + } | ||
| 2912 | + } | ||
| 2913 | + } | ||
| 2914 | + | ||
| 2849 | /// A CROSSFADE clip (lane-b64b): each picture is a linear blend of two | 2915 | /// 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 | 2916 | /// 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 -- | 2917 | /// (`ALTREF`) references IS the source and neither reference alone is -- |
crates/ec-av1/src/tile.rsmodified+51 -13
| @@ -3962,13 +3962,13 @@ fn write_luma_tus( | |||
| 3962 | // tables, not the intra ones (`TxbSet::Luma*Inter`). | 3962 | // tables, not the intra ones (`TxbSet::Luma*Inter`). |
| 3963 | inter: bool, | 3963 | inter: bool, |
| 3964 | ) -> Result<()> { | 3964 | ) -> Result<()> { |
| 3965 | - if tx < side && side > 32 { | 3965 | + if tx < side && side > 32 && tx < 32 { |
| 3966 | // A 64x64 block's own levels reach the writer as the 32x32 corner a | 3966 | // A 64x64 block's own levels reach the writer as the 32x32 corner a |
| 3967 | - // 64-point transform codes, not as a 64x64 block grid, so there is | 3967 | + // 64-point transform codes unless the whole block was SPLIT into |
| 3968 | - // nothing to slice per unit here. | 3968 | + // TX_32X32 units (lane-b64b), so any finer split has nothing to slice. |
| 3969 | return Err(Error::unsupported( | 3969 | return Err(Error::unsupported( |
| 3970 | "AV1 tile", | 3970 | "AV1 tile", |
| 3971 | - "a 64x64 block's split luma transform is not written yet", | 3971 | + "a 64x64 block's luma transform splits no finer than TX_32X32", |
| 3972 | )); | 3972 | )); |
| 3973 | } | 3973 | } |
| 3974 | let coeff_side = tx.min(32); | 3974 | let coeff_side = tx.min(32); |
| @@ -4377,8 +4377,25 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { | |||
| 4377 | return match block.skip { | 4377 | return match block.skip { |
| 4378 | true => 0.0, | 4378 | true => 0.0, |
| 4379 | false => { | 4379 | false => { |
| 4380 | - coeff_bits(&dense(&block.luma, 32), TxbSet::Luma64, q_ctx, 0, 0) | 4380 | + // lane-b64b: at `tx_depth = 1` the luma levels are |
| 4381 | - + coeff_bits(&dense(&block.u, 32), TxbSet::Chroma32, q_ctx, 0, 0) | 4381 | + // the whole 64-sided block, written as four |
| 4382 | + // TX_32X32 units, so the pricer slices them the | ||
| 4383 | + // same way the writer does. | ||
| 4384 | + let luma = if block.tx_depth == 1 { | ||
| 4385 | + let g = dense(&block.luma, 64); | ||
| 4386 | + (0..4) | ||
| 4387 | + .map(|tu| { | ||
| 4388 | + let (r0, c0) = ((tu / 2) * 32, (tu % 2) * 32); | ||
| 4389 | + let unit: Vec<i32> = (0..32) | ||
| 4390 | + .flat_map(|row| g[(r0 + row) * 64 + c0..][..32].to_vec()) | ||
| 4391 | + .collect(); | ||
| 4392 | + coeff_bits(&unit, TxbSet::Luma32Inter, q_ctx, 0, 0) | ||
| 4393 | + }) | ||
| 4394 | + .sum::<f64>() | ||
| 4395 | + } else { | ||
| 4396 | + coeff_bits(&dense(&block.luma, 32), TxbSet::Luma64, q_ctx, 0, 0) | ||
| 4397 | + }; | ||
| 4398 | + luma + coeff_bits(&dense(&block.u, 32), TxbSet::Chroma32, q_ctx, 0, 0) | ||
| 4382 | + coeff_bits(&dense(&block.v, 32), TxbSet::Chroma32, q_ctx, 0, 0) | 4399 | + coeff_bits(&dense(&block.v, 32), TxbSet::Chroma32, q_ctx, 0, 0) |
| 4383 | } | 4400 | } |
| 4384 | }; | 4401 | }; |
| @@ -5734,9 +5751,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5734 | // A skipped inter block writes no `txfm_split` at all -- | 5751 | // A skipped inter block writes no `txfm_split` at all -- |
| 5735 | // that call only publishes the max transform size the | 5752 | // that call only publishes the max transform size the |
| 5736 | // reader infers for it; an unskipped one writes the | 5753 | // reader infers for it; an unskipped one writes the |
| 5737 | - // `txfm_split` flag, 0 here because a 64x64 root's luma | 5754 | + // `txfm_split` flag: 0 when the root's luma is one whole |
| 5738 | - // is one whole TX_64X64 (depth 1 is lane-tx64's deferred | 5755 | + // TX_64X64, 1 when it is the four TX_32X32 units |
| 5739 | - // var-tx arm). | 5756 | + // lane-b64b's var-tx arm chose. |
| 5740 | write_tx_syntax_inter( | 5757 | write_tx_syntax_inter( |
| 5741 | &mut enc, | 5758 | &mut enc, |
| 5742 | &mut cdfs, | 5759 | &mut cdfs, |
| @@ -5745,7 +5762,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5745 | SB, | 5762 | SB, |
| 5746 | true, | 5763 | true, |
| 5747 | block.skip, | 5764 | block.skip, |
| 5748 | - 0, | 5765 | + usize::from(block.tx_depth), |
| 5749 | ); | 5766 | ); |
| 5750 | } | 5767 | } |
| 5751 | if block.skip { | 5768 | if block.skip { |
| @@ -5757,11 +5774,32 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5757 | // `sb_coeff_key_frame_tile`'s `Superblock::Whole` writes), | 5774 | // `sb_coeff_key_frame_tile`'s `Superblock::Whole` writes), |
| 5758 | // chroma one whole TX_32X32 per plane, and `split` is | 5775 | // chroma one whole TX_32X32 per plane, and `split` is |
| 5759 | // false because the luma transform covers the block. | 5776 | // false because the luma transform covers the block. |
| 5777 | + // lane-b64b: at `txfm_split = 1` the luma levels arrive in | ||
| 5778 | + // 64x64 block coordinates and are written as the four | ||
| 5779 | + // TX_32X32 units `write_luma_tus` slices out, each | ||
| 5780 | + // publishing its own coefficient context before the next | ||
| 5781 | + // one reads it; chroma is one TX_32X32 per plane either | ||
| 5782 | + // way. | ||
| 5783 | + let split = block.tx_depth == 1; | ||
| 5760 | let grids = [ | 5784 | let grids = [ |
| 5761 | - level_grid(&block.luma, TX32)?, | 5785 | + level_grid(&block.luma, if split { SB } else { TX32 })?, |
| 5762 | level_grid(&block.u, TX32)?, | 5786 | level_grid(&block.u, TX32)?, |
| 5763 | level_grid(&block.v, TX32)?, | 5787 | level_grid(&block.v, TX32)?, |
| 5764 | ]; | 5788 | ]; |
| 5789 | + if split { | ||
| 5790 | + write_luma_tus( | ||
| 5791 | + &mut enc, | ||
| 5792 | + &mut cdfs, | ||
| 5793 | + &mut neighbours, | ||
| 5794 | + (mi_r, mi_c), | ||
| 5795 | + SB, | ||
| 5796 | + TX32, | ||
| 5797 | + &grids[0], | ||
| 5798 | + 0, | ||
| 5799 | + &all_scans, | ||
| 5800 | + true, | ||
| 5801 | + )?; | ||
| 5802 | + } | ||
| 5765 | write_block_planes( | 5803 | write_block_planes( |
| 5766 | &mut enc, | 5804 | &mut enc, |
| 5767 | &mut cdfs, | 5805 | &mut cdfs, |
| @@ -5770,9 +5808,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 5770 | &[&scan32, &scan32, &scan32], | 5808 | &[&scan32, &scan32, &scan32], |
| 5771 | &neighbours.around(sb_at, SB), | 5809 | &neighbours.around(sb_at, SB), |
| 5772 | 0, | 5810 | 0, |
| 5773 | - false, | 5811 | + split, |
| 5774 | ); | 5812 | ); |
| 5775 | - neighbours.record_planes(sb_at, SB, 0, &grids, true); | 5813 | + neighbours.record_planes(sb_at, SB, 0, &grids, !split); |
| 5776 | } | 5814 | } |
| 5777 | neighbours.record_inter(sb_at, SB, block.skip, true, block_ref(block)); | 5815 | neighbours.record_inter(sb_at, SB, block.skip, true, block_ref(block)); |
| 5778 | record_block_compound(&mut neighbours, (mi_r, mi_c), SB, block); | 5816 | record_block_compound(&mut neighbours, (mi_r, mi_c), SB, block); |
lanes/b64b/r2-ship.logmodified+27 -0
| @@ -18,3 +18,30 @@ bars 2160p: motion_mode 32x32 SIMPLE=31585 OBMC=0 WARP=290 | 16x16 SIMPLE=2756 O | |||
| 18 | bars 2160p: inter var-tx depths of 9192 blocks -- leaf single 0=1220 1=600 (33.0% split) | leaf compound 0=1083 1=221 (16.9% split) | 32x32 single 0=371 1=1234 (76.9% split) | 32x32 compound 0=141 1=4322 (96.8% split) | 18 | bars 2160p: inter var-tx depths of 9192 blocks -- leaf single 0=1220 1=600 (33.0% split) | leaf compound 0=1083 1=221 (16.9% split) | 32x32 single 0=371 1=1234 (76.9% split) | 32x32 compound 0=141 1=4322 (96.8% split) |
| 19 | 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: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0) |
| 20 | bars 2160p: filter intra on=true blocks 12387 (modes DC=3329 V=811 H=2621 D157=3956 PAETH=1670) | 20 | bars 2160p: filter intra on=true blocks 12387 (modes DC=3329 V=811 H=2621 D157=3956 PAETH=1670) |
| 21 | +| bars 2160p 1920x1024 | 43.68 dB/229668 B, 47.60 dB/340632 B, 51.18 dB/453178 B, 54.52 dB/582676 B | +12.3% | -10.2% | 45.8s:8.8s:20.6s | | ||
| 22 | +film A (1080p source): 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 }) | ||
| 23 | +film A (1080p source): pricer armings default=20 real=214 | ||
| 24 | +film A (1080p source): motion_mode 32x32 SIMPLE=33077 OBMC=0 WARP=1298 | 16x16 SIMPLE=19240 OBMC=0 WARP=1887 | 8x8 SIMPLE=4708 OBMC=0 WARP=931 (0.0% OBMC / 6.7% WARP of 61141 eligible) | ||
| 25 | +film A (1080p source): inter var-tx depths of 85244 blocks -- leaf single 0=15366 1=2875 (15.8% split) | leaf compound 0=31528 1=6450 (17.0% split) | 32x32 single 0=7510 1=5922 (44.1% split) | 32x32 compound 0=9593 1=6000 (38.5% split) | ||
| 26 | +film A (1080p source): screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0) | ||
| 27 | +film A (1080p source): filter intra on=true blocks 24000 (modes DC=6012 V=3472 H=4526 D157=6964 PAETH=3026) | ||
| 28 | +| film A (1080p source) 1920x768 | 44.29 dB/73949 B, 45.82 dB/123906 B, 47.03 dB/213467 B, 48.28 dB/508664 B | +35.5% | +5.6% | 93.8s:14.5s:17.7s | | ||
| 29 | +film B (2160p HDR source): 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 }) | ||
| 30 | +film B (2160p HDR source): pricer armings default=20 real=189 | ||
| 31 | +film B (2160p HDR source): motion_mode 32x32 SIMPLE=35371 OBMC=0 WARP=1194 | 16x16 SIMPLE=12510 OBMC=0 WARP=1144 | 8x8 SIMPLE=2069 OBMC=0 WARP=483 (0.0% OBMC / 5.3% WARP of 52771 eligible) | ||
| 32 | +film B (2160p HDR source): inter var-tx depths of 75130 blocks -- leaf single 0=14148 1=2497 (15.0% split) | leaf compound 0=27160 1=4854 (15.2% split) | 32x32 single 0=8028 1=5889 (42.3% split) | 32x32 compound 0=7821 1=4733 (37.7% split) | ||
| 33 | +film B (2160p HDR source): screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0) | ||
| 34 | +film B (2160p HDR source): filter intra on=true blocks 17165 (modes DC=4796 V=2302 H=2518 D157=5821 PAETH=1728) | ||
| 35 | +| film B (2160p HDR source) 1920x1024 | 46.91 dB/33324 B, 48.04 dB/67896 B, 49.10 dB/143229 B, 50.25 dB/388721 B | +47.8% | +17.1% | 88.0s:24.0s:17.7s | | ||
| 36 | +screen capture (2026-07-25 02-09-04.mkv): 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 None | ||
| 37 | +screen capture (2026-07-25 02-09-04.mkv): pricer armings default=155 real=0 | ||
| 38 | +screen capture (2026-07-25 02-09-04.mkv): motion_mode 32x32 SIMPLE=23654 OBMC=0 WARP=160 | 16x16 SIMPLE=1322 OBMC=0 WARP=318 | 8x8 SIMPLE=562 OBMC=0 WARP=576 (0.0% OBMC / 4.0% WARP of 26592 eligible) | ||
| 39 | +screen capture (2026-07-25 02-09-04.mkv): inter var-tx depths of 34092 blocks -- leaf single 0=5772 1=7043 (55.0% split) | leaf compound 0=2826 1=2851 (50.2% split) | 32x32 single 0=6059 1=8017 (57.0% split) | 32x32 compound 0=860 1=664 (43.6% split) | ||
| 40 | +screen capture (2026-07-25 02-09-04.mkv): screen frames on=48 off=0 (100.0% on); palette blocks luma 9907 chroma 1109; intrabc blocks 0 (searched 0 / valid 0 / won 0) | ||
| 41 | +screen capture (2026-07-25 02-09-04.mkv): filter intra on=true blocks 8198 (modes DC=98 V=2410 H=5376 D157=223 PAETH=91) | ||
| 42 | +| screen capture (2026-07-25 02-09-04.mkv) 1920x1024 | 45.87 dB/40155 B, 48.55 dB/51325 B, 50.86 dB/63998 B, 53.07 dB/80203 B | +33.4% | -23.8% | 47.9s:15.4s:15.4s | | ||
| 43 | +test encode::tests::bd_rate_screen_native ... ok | ||
| 44 | + | ||
| 45 | +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 602 filtered out; finished in 521.63s | ||
| 46 | + | ||
| 47 | +RC=0 | ||