forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1trial' (782b5748): trial-set census, exact SAD pre-pass skip, split RD breakout (0.125 lambda)

Browse files at this commit

826851c8cfadef517a5725f067ae280a9f1b6a1eAhmet Kaan GümüşParent: 7c2597d4e368e4
Wall -11.0/-11.1/-6.9% (instructions -10.0% 1080p) for BD +0.1/+0.3/-0.2
vs libaom (+121.2/+146.4/+79.1). Chroma top-K ships off (measured: SAD
ranks the chroma winner first only 67-77% of the time). Census via
EC_AV1_CENSUS=1 on examples/enc_probe.
crates/ec-av1/examples/enc_probe.rsmodified+15 -0
@@ -51,6 +51,21 @@ fn main() {
51 h = (h ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3);51 h = (h ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3);
52 }52 }
53 println!("q={q} bytes={} fnv1a={h:016x}", e.stream.len());53 println!("q={q} bytes={} fnv1a={h:016x}", e.stream.len());
54+ if ec_av1::encode::census_on() {
55+ let (kinds, luma_rank, chroma_rank) = ec_av1::encode::take_census();
56+ for (name, n) in ec_av1::encode::CENSUS_KINDS.iter().zip(kinds) {
57+ println!(" census {name}: {n}");
58+ }
59+ let pct = |h: &[usize]| {
60+ let total: usize = h.iter().sum::<usize>().max(1);
61+ h.iter()
62+ .map(|n| format!("{:.1}%", 100.0 * *n as f64 / total as f64))
63+ .collect::<Vec<_>>()
64+ .join(" ")
65+ };
66+ println!(" census luma SAD rank of RD winner: {}", pct(&luma_rank));
67+ println!(" census chroma SAD rank of RD winner: {}", pct(&chroma_rank));
68+ }
54 }69 }
55 println!("wall {:.3}s", start.elapsed().as_secs_f64());70 println!("wall {:.3}s", start.elapsed().as_secs_f64());
56 }71 }
crates/ec-av1/src/encode.rsmodified+221 -17
@@ -244,6 +244,45 @@ fn restoration_enabled() -> bool {
244 /// future explicit speed preset.244 /// future explicit speed preset.
245 const SPLIT_BREAKOUT_COEFFS: usize = 0;245 const SPLIT_BREAKOUT_COEFFS: usize = 0;
246 246
247+/// libaom's `partition_search_breakout_rate_thr` shape, in this encoder's own
248+/// currency: a 32x32 inter block whose whole-block RD cost per pixel comes
249+/// out under `threshold * lambda` is not offered the split at all, and a
250+/// 16x16 leaf under it is not offered the 8x8 split. `0.0` offers both
251+/// always, as before this lever.
252+///
253+/// The census is what points here: the split trial runs on nearly every
254+/// non-skip block (15132 leaf searches per ladder point on the 1080p clip)
255+/// and wins 7.6% of the time on film, 3.0% on screen -- yet the coefficient
256+/// -count breakout ([`SPLIT_BREAKOUT_COEFFS`]) that prunes it costs 18-31 BD
257+/// points, so the gate has to read the block's own RD cost, not its levels.
258+///
259+/// Swept on the BD gate over 0.125/0.25/0.5/1.0 (vs libaom, against a base of
260+/// +121.1/+146.1/+79.3): 0.125 is +121.2/+146.4/+79.1 (+0.1/+0.3/-0.2) for
261+/// -10.0%/-5.7% instructions (1080p/screen, `perf stat` ABAB x2) and
262+/// -7.7/-8.6/-4.5% wall; 0.25 already costs +0.7/+0.6/+0.6, 0.5 costs
263+/// +3.5/+4.7/+1.8 for -15% wall, and 1.0 costs +19/+27/+6. So 0.125 ships --
264+/// the largest threshold whose BD stays inside the +0.3 keep rule on every
265+/// clip.
266+const SPLIT_RD_THRESHOLD: f64 = 0.125;
267+
268+/// [`SPLIT_RD_THRESHOLD`], swept by `EC_AV1_SPLIT_RD` in any build.
269+fn split_rd_threshold() -> f64 {
270+ static T: std::sync::OnceLock<f64> = std::sync::OnceLock::new();
271+ *T.get_or_init(|| {
272+ std::env::var("EC_AV1_SPLIT_RD")
273+ .ok()
274+ .and_then(|v| v.parse().ok())
275+ .unwrap_or(SPLIT_RD_THRESHOLD)
276+ })
277+}
278+
279+/// Whether `cost` over a `side` x `side` block is cheap enough per pixel that
280+/// [`split_rd_threshold`] withholds the split trial.
281+fn split_rd_breakout(cost: f64, side: usize, lambda: f64) -> bool {
282+ let t = split_rd_threshold();
283+ t > 0.0 && cost < t * lambda * (side * side) as f64
284+}
285+
247 /// [`SPLIT_BREAKOUT_COEFFS`], swept by `EC_AV1_SPLIT_BREAKOUT` in a test286 /// [`SPLIT_BREAKOUT_COEFFS`], swept by `EC_AV1_SPLIT_BREAKOUT` in a test
248 /// build.287 /// build.
249 fn split_breakout_coeffs() -> usize {288 fn split_breakout_coeffs() -> usize {
@@ -276,6 +315,76 @@ pub(crate) fn take_partition_hits() -> [usize; 4] {
276 [0, 1, 2, 3].map(|i| PARTITION_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))315 [0, 1, 2, 3].map(|i| PARTITION_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
277 }316 }
278 317
318+/// Whether the trial-set census (`EC_AV1_CENSUS=1`) is on: how many full
319+/// rate-distortion trials the block search actually runs, by kind, and where
320+/// the winner sat in the cheap SAD ranking the pruning levers rank by. Off by
321+/// default, and a measurement build rather than a speed one -- the census
322+/// runs the SAD pre-pass the unpruned search otherwise skips.
323+pub fn census_on() -> bool {
324+ static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
325+ *ON.get_or_init(|| matches!(std::env::var("EC_AV1_CENSUS").as_deref(), Ok("1")))
326+}
327+
328+/// What each [`CENSUS`] counter counts.
329+pub const CENSUS_KINDS: [&str; 11] = [
330+ "intra blocks searched (key frame + inter leaves)",
331+ "intra luma mode trials",
332+ "chroma searches",
333+ "chroma mode trials (each = 2 plane trials)",
334+ "tx-depth trials (transform units, depth >= 1)",
335+ "inter 32x32 blocks searched",
336+ "inter block intra-mode trials",
337+ "inter mv candidates (each = 3 mc trials)",
338+ "inter leaves searched (intra vs NEARESTMV/NEWMV)",
339+ " of those, intra won",
340+ " of those, the NEARESTMV trial coded no residual",
341+];
342+
343+/// The census counters themselves, indexed by [`CENSUS_KINDS`].
344+static CENSUS: [std::sync::atomic::AtomicUsize; 11] =
345+ [const { std::sync::atomic::AtomicUsize::new(0) }; 11];
346+
347+/// Where the RD winner sat in the SAD ranking, for the luma intra search and
348+/// the chroma mode search -- what says whether a top-N prune would have kept
349+/// the block the search actually chose.
350+static LUMA_RANK: [std::sync::atomic::AtomicUsize; 13] =
351+ [const { std::sync::atomic::AtomicUsize::new(0) }; 13];
352+static CHROMA_RANK: [std::sync::atomic::AtomicUsize; 7] =
353+ [const { std::sync::atomic::AtomicUsize::new(0) }; 7];
354+
355+fn census_add(kind: usize, n: usize) {
356+ if census_on() {
357+ CENSUS[kind].fetch_add(n, std::sync::atomic::Ordering::Relaxed);
358+ }
359+}
360+
361+/// Reads (and clears) the census, so a driver can attribute it to its own encode.
362+pub fn take_census() -> ([usize; 11], [usize; 13], [usize; 7]) {
363+ let take = |c: &std::sync::atomic::AtomicUsize| c.swap(0, std::sync::atomic::Ordering::Relaxed);
364+ (
365+ std::array::from_fn(|i| take(&CENSUS[i])),
366+ std::array::from_fn(|i| take(&LUMA_RANK[i])),
367+ std::array::from_fn(|i| take(&CHROMA_RANK[i])),
368+ )
369+}
370+
371+/// The rank of `winner` in `scored` ordered by its cheap score, cheapest
372+/// first -- the census's one shared rule, so the luma and chroma histograms
373+/// mean the same thing.
374+fn sad_rank(scored: &[(f64, u8)], winner: u8) -> usize {
375+ scored
376+ .iter()
377+ .filter(|&&(score, mode)| {
378+ mode != winner
379+ && score
380+ < scored
381+ .iter()
382+ .find(|&&(_, m)| m == winner)
383+ .map_or(f64::INFINITY, |&(s, _)| s)
384+ })
385+ .count()
386+}
387+
279 /// Whether a 32x32 block may be split into four 16x16 ones when the trial says388 /// Whether a 32x32 block may be split into four 16x16 ones when the trial says
280 /// four cost less. Set from the measurement in the lane report.389 /// four cost less. Set from the measurement in the lane report.
281 const SPLIT_BLOCKS: bool = true;390 const SPLIT_BLOCKS: bool = true;
@@ -961,7 +1070,11 @@ impl Plane<'_> {
961 x, y, side, reach, ..1070 x, y, side, reach, ..
962 } = at;1071 } = at;
963 let (above, left, corner) = self.edges(x, y, side, reach);1072 let (above, left, corner) = self.edges(x, y, side, reach);
964- let mut prediction = vec![0u8; side * side];1073+ // Per-candidate scratch on the search's hottest path, so both buffers
1074+ // live on the stack -- `side` is at most `BLOCK` -- rather than
1075+ // costing a malloc/free pair per trial (`mc_trial` already does this).
1076+ let mut prediction = [0u8; BLOCK * BLOCK];
1077+ let prediction = &mut prediction[..side * side];
965 intra_predict_u8(1078 intra_predict_u8(
966 mode,1079 mode,
967 0,1080 0,
@@ -972,10 +1085,11 @@ impl Plane<'_> {
972 side,1085 side,
973 false,1086 false,
974 false,1087 false,
975- &mut prediction, fctx,1088+ prediction, fctx,
976 );1089 );
977 1090
978- let mut residual = vec![0i32; side * side];1091+ let mut residual = [0i32; BLOCK * BLOCK];
1092+ let residual = &mut residual[..side * side];
979 for row in 0..side {1093 for row in 0..side {
980 for col in 0..side {1094 for col in 0..side {
981 residual[row * side + col] =1095 residual[row * side + col] =
@@ -986,7 +1100,7 @@ impl Plane<'_> {
986 #[cfg(test)]1100 #[cfg(test)]
987 let t = std::time::Instant::now();1101 let t = std::time::Instant::now();
988 let levels =1102 let levels =
989- forward_and_quantize_typed(&residual, side, 8, i32::from(base_q_idx), deadzone, tx_type);1103+ forward_and_quantize_typed(residual, side, 8, i32::from(base_q_idx), deadzone, tx_type);
990 let coded =1104 let coded =
991 dequant_and_inverse_typed(&levels, side, 8, i32::from(base_q_idx), 0, 0, tx_type);1105 dequant_and_inverse_typed(&levels, side, 8, i32::from(base_q_idx), 0, 0, tx_type);
992 #[cfg(test)]1106 #[cfg(test)]
@@ -1069,7 +1183,8 @@ impl Plane<'_> {
1069 bits: 0.0,1183 bits: 0.0,
1070 };1184 };
1071 }1185 }
1072- let mut residual = vec![0i32; side * side];1186+ let mut residual = [0i32; BLOCK * BLOCK];
1187+ let residual = &mut residual[..side * side];
1073 for row in 0..side {1188 for row in 0..side {
1074 for col in 0..side {1189 for col in 0..side {
1075 residual[row * side + col] =1190 residual[row * side + col] =
@@ -1079,7 +1194,7 @@ impl Plane<'_> {
1079 }1194 }
1080 #[cfg(test)]1195 #[cfg(test)]
1081 let t = std::time::Instant::now();1196 let t = std::time::Instant::now();
1082- let levels = forward_and_quantize(&residual, side, 8, i32::from(base_q_idx), deadzone);1197+ let levels = forward_and_quantize(residual, side, 8, i32::from(base_q_idx), deadzone);
1083 let coded = dequant_and_inverse(&levels, side, 8, i32::from(base_q_idx));1198 let coded = dequant_and_inverse(&levels, side, 8, i32::from(base_q_idx));
1084 #[cfg(test)]1199 #[cfg(test)]
1085 stage_add(2, t.elapsed());1200 stage_add(2, t.elapsed());
@@ -1142,6 +1257,7 @@ impl Plane<'_> {
1142 _ => TxbSet::Luma4,1257 _ => TxbSet::Luma4,
1143 };1258 };
1144 let mut levels = vec![0i32; side * side];1259 let mut levels = vec![0i32; side * side];
1260+ census_add(4, n * n);
1145 let (mut sse, mut bits) = (0.0, 0.0);1261 let (mut sse, mut bits) = (0.0, 0.0);
1146 for tu_row in 0..n {1262 for tu_row in 0..n {
1147 for tu_col in 0..n {1263 for tu_col in 0..n {
@@ -1266,6 +1382,11 @@ impl Plane<'_> {
1266 x, y, side, reach, ..1382 x, y, side, reach, ..
1267 } = at;1383 } = at;
1268 let (above, left, corner) = self.edges(x, y, side, reach);1384 let (above, left, corner) = self.edges(x, y, side, reach);
1385+ // Nothing ranks by the SAD pre-pass unless `top_k` prunes by it (or
1386+ // the census reports it), so summing it under the default unpruned
1387+ // search is `side * side` absolute differences per mode spent on a
1388+ // number no one reads.
1389+ let want_sad = search.top_k.is_some() || census_on();
1269 let mut scored: Vec<(f64, u8, Vec<u8>)> = search1390 let mut scored: Vec<(f64, u8, Vec<u8>)> = search
1270 .modes1391 .modes
1271 .iter()1392 .iter()
@@ -1283,16 +1404,20 @@ impl Plane<'_> {
1283 false,1404 false,
1284 &mut prediction, fctx,1405 &mut prediction, fctx,
1285 );1406 );
1286- let sad: f64 = (0..side * side)1407+ let sad: f64 = if want_sad {
1287- .map(|i| {1408+ (0..side * side)
1288- let (row, col) = (i / side, i % side);1409+ .map(|i| {
1289- f64::from(1410+ let (row, col) = (i / side, i % side);
1290- (i32::from(self.source[(y + row) * self.width + x + col])1411+ f64::from(
1291- - i32::from(prediction[i]))1412+ (i32::from(self.source[(y + row) * self.width + x + col])
1292- .abs(),1413+ - i32::from(prediction[i]))
1293- )1414+ .abs(),
1294- })1415+ )
1295- .sum();1416+ })
1417+ .sum()
1418+ } else {
1419+ 0.0
1420+ };
1296 (1421 (
1297 sad + search.lambda * mode_bits[usize::from(mode)],1422 sad + search.lambda * mode_bits[usize::from(mode)],
1298 mode,1423 mode,
@@ -1315,6 +1440,13 @@ impl Plane<'_> {
1315 }1440 }
1316 }1441 }
1317 }1442 }
1443+ let ranking: Vec<(f64, u8)> = if census_on() {
1444+ scored.iter().map(|&(score, mode, _)| (score, mode)).collect()
1445+ } else {
1446+ Vec::new()
1447+ };
1448+ census_add(0, 1);
1449+ census_add(1, scored.len());
1318 let mut best: Option<(f64, u8, Trial)> = None;1450 let mut best: Option<(f64, u8, Trial)> = None;
1319 for (_, mode, prediction) in scored {1451 for (_, mode, prediction) in scored {
1320 let trial = self.code_from_prediction(1452 let trial = self.code_from_prediction(
@@ -1336,6 +1468,10 @@ impl Plane<'_> {
1336 }1468 }
1337 }1469 }
1338 let (cost, mode, trial) = best.expect("the search offers at least one mode");1470 let (cost, mode, trial) = best.expect("the search offers at least one mode");
1471+ if census_on() {
1472+ LUMA_RANK[sad_rank(&ranking, mode).min(12)]
1473+ .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1474+ }
1339 self.commit(x, y, side, &trial);1475 self.commit(x, y, side, &trial);
1340 (coeffs(&trial.levels, side), mode, cost)1476 (coeffs(&trial.levels, side), mode, cost)
1341 }1477 }
@@ -2173,6 +2309,34 @@ pub(crate) fn take_uv_mode_hits() -> [usize; 13] {
2173 /// (directional, spec `read_intra_angle_info`), the zero `angle_delta_uv` the2309 /// (directional, spec `read_intra_angle_info`), the zero `angle_delta_uv` the
2174 /// writer then has to code.2310 /// writer then has to code.
2175 #[allow(clippy::too_many_arguments)]2311 #[allow(clippy::too_many_arguments)]
2312+/// How many of [`CHROMA_MODES`] the chroma search runs a full trial pair on,
2313+/// ranked by the SAD of their predictions summed over both planes (`DC_PRED`
2314+/// always kept, the same rule [`prune_by_sad`] applies to luma). `None`
2315+/// trials all seven, as before this lever.
2316+///
2317+/// The census (`EC_AV1_CENSUS=1`) is what justifies the lever: chroma was
2318+/// the search's largest trial population by far -- seven modes times two
2319+/// planes for every intra block, against 3.7 luma trials -- and the RD
2320+/// winner sat at SAD rank 0 for 67-77% of blocks and inside the top three
2321+/// for 88%. `EC_AV1_CHROMA_K` sweeps it in any build.
2322+fn chroma_top_k() -> Option<usize> {
2323+ static K: std::sync::OnceLock<Option<usize>> = std::sync::OnceLock::new();
2324+ *K.get_or_init(|| match std::env::var("EC_AV1_CHROMA_K").ok() {
2325+ Some(v) => v.parse::<usize>().ok().filter(|&k| k > 0),
2326+ None => CHROMA_TOP_K,
2327+ })
2328+}
2329+
2330+/// [`chroma_top_k`]'s default. `None`: no `K` cleared the keep rule on the BD
2331+/// gate. Swept over 2/3/4/5 (vs libaom, base +121.1/+146.1/+79.3):
2332+/// K=2 is +122.3/+147.5/+79.8 for -7.0/-8.3/-7.9% wall, K=3 +121.4/+146.8/
2333+/// +80.6 for -5.4/-5.2/-4.6%, K=4 +120.5/+145.2/+79.3 (BD-neutral or better)
2334+/// for only -3.4% wall and -2.8% instructions, K=5 +122.0/+145.1/+80.0. The
2335+/// BD swings by about a point in either direction as near-tie chroma modes
2336+/// flip, which is the measurement's own sensitivity, not a trend: nothing
2337+/// here buys >=5% wall at <=+0.3 BD, so the default stays unpruned.
2338+const CHROMA_TOP_K: Option<usize> = None;
2339+
2176 fn search_chroma(2340 fn search_chroma(
2177 chroma: &mut [Plane; 2],2341 chroma: &mut [Plane; 2],
2178 (x, y): (usize, usize),2342 (x, y): (usize, usize),
@@ -2189,10 +2353,34 @@ fn search_chroma(
2189 reach: Reach::none(),2353 reach: Reach::none(),
2190 set,2354 set,
2191 };2355 };
2356+ // The census's cheap proxy for a chroma mode: the SAD of its prediction
2357+ // summed over both planes, ranked by the same rule the luma histogram
2358+ // uses. Only built under `EC_AV1_CENSUS`.
2359+ // The SAD of each mode's prediction, summed over both planes -- the
2360+ // census's ranking rule, and what [`chroma_top_k`] prunes by.
2361+ let sad_scores = |chroma: &[Plane; 2]| -> Vec<(f64, u8)> {
2362+ let u = chroma[0].intra_scores(at, &CHROMA_MODES, &[0.0; 13], 0.0, fctx);
2363+ let v = chroma[1].intra_scores(at, &CHROMA_MODES, &[0.0; 13], 0.0, fctx);
2364+ u.iter()
2365+ .zip(v.iter())
2366+ .map(|(&(us, mode), &(vs, _))| (us + vs, mode))
2367+ .collect()
2368+ };
2369+ let modes: Vec<u8> = match chroma_top_k() {
2370+ Some(k) if k < CHROMA_MODES.len() => prune_by_sad(&CHROMA_MODES, sad_scores(chroma), k),
2371+ _ => CHROMA_MODES.to_vec(),
2372+ };
2192 let uv_cdf = &cdf::UV_MODE_CFL[usize::from(luma_mode)];2373 let uv_cdf = &cdf::UV_MODE_CFL[usize::from(luma_mode)];
2193 let dc_bits = symbol_bits(uv_cdf, usize::from(DC_PRED));2374 let dc_bits = symbol_bits(uv_cdf, usize::from(DC_PRED));
2375+ let ranking: Vec<(f64, u8)> = if census_on() {
2376+ sad_scores(chroma)
2377+ } else {
2378+ Vec::new()
2379+ };
2380+ census_add(2, 1);
2381+ census_add(3, modes.len());
2194 let mut best: Option<(f64, u8, Trial, Trial)> = None;2382 let mut best: Option<(f64, u8, Trial, Trial)> = None;
2195- for mode in CHROMA_MODES {2383+ for mode in modes {
2196 let mut bits = symbol_bits(uv_cdf, usize::from(mode)) - dc_bits;2384 let mut bits = symbol_bits(uv_cdf, usize::from(mode)) - dc_bits;
2197 if (V_PRED..=D67_PRED).contains(&mode) {2385 if (V_PRED..=D67_PRED).contains(&mode) {
2198 bits += symbol_bits(&cdf::ANGLE_DELTA[usize::from(mode - V_PRED)], 3);2386 bits += symbol_bits(&cdf::ANGLE_DELTA[usize::from(mode - V_PRED)], 3);
@@ -2206,6 +2394,10 @@ fn search_chroma(
2206 }2394 }
2207 }2395 }
2208 let (cost, mode, u, v) = best.expect("CHROMA_MODES is not empty");2396 let (cost, mode, u, v) = best.expect("CHROMA_MODES is not empty");
2397+ if census_on() {
2398+ CHROMA_RANK[sad_rank(&ranking, mode).min(6)]
2399+ .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
2400+ }
2209 UV_MODE_HITS[usize::from(mode)].fetch_add(1, std::sync::atomic::Ordering::Relaxed);2401 UV_MODE_HITS[usize::from(mode)].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
2210 chroma[0].commit(at.x, at.y, at.side, &u);2402 chroma[0].commit(at.x, at.y, at.side, &u);
2211 chroma[1].commit(at.x, at.y, at.side, &v);2403 chroma[1].commit(at.x, at.y, at.side, &v);
@@ -2472,6 +2664,13 @@ fn code_square_inter(
2472 }2664 }
2473 }2665 }
2474 2666
2667+ census_add(8, 1);
2668+ if skip {
2669+ census_add(10, 1);
2670+ }
2671+ if inter_cost >= intra_cost {
2672+ census_add(9, 1);
2673+ }
2475 if inter_cost < intra_cost {2674 if inter_cost < intra_cost {
2476 let (levels, tx_depth, dcost) = commit_inter_luma(2675 let (levels, tx_depth, dcost) = commit_inter_luma(
2477 luma, (x, y), side, mv, (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), search, &luma_trial, skip, fctx,2676 luma, (x, y), side, mv, (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), search, &luma_trial, skip, fctx,
@@ -3767,6 +3966,8 @@ fn search_inter_block(
3767 }3966 }
3768 _ => search.modes.to_vec(),3967 _ => search.modes.to_vec(),
3769 };3968 };
3969+ census_add(5, 1);
3970+ census_add(6, intra_modes.len());
3770 for &mode in &intra_modes {3971 for &mode in &intra_modes {
3771 let luma_trial = luma.trial(3972 let luma_trial = luma.trial(
3772 At {3973 At {
@@ -4021,6 +4222,7 @@ fn search_inter_block(
4021 .then(a.1.total_cmp(&b.1))4222 .then(a.1.total_cmp(&b.1))
4022 });4223 });
4023 cands.dedup_by_key(|c| (c.2.ref_frame, c.0));4224 cands.dedup_by_key(|c| (c.2.ref_frame, c.0));
4225+ census_add(7, cands.len());
4024 {4226 {
4025 for (mv, mode_bits_inter, info) in cands {4227 for (mv, mode_bits_inter, info) in cands {
4026 let (ref_luma, ref_u, ref_v) = match extra4228 let (ref_luma, ref_u, ref_v) = match extra
@@ -4413,6 +4615,7 @@ pub(crate) fn encode_inter_frame(
4413 // nothing is not offered the split at all.4615 // nothing is not offered the split at all.
4414 let breakout = split_breakout_coeffs();4616 let breakout = split_breakout_coeffs();
4415 let split = (!block.skip4617 let split = (!block.skip
4618+ && !split_rd_breakout(cost_whole, BLOCK, search.lambda)
4416 && (breakout == 0 || block.luma.len() > 4 * breakout)4619 && (breakout == 0 || block.luma.len() > 4 * breakout)
4417 && leaves_legal4620 && leaves_legal
4418 && split_inter_blocks())4621 && split_inter_blocks())
@@ -4447,6 +4650,7 @@ pub(crate) fn encode_inter_frame(
4447 // at BLOCK_16X16 (lane-av1rd2). Same4650 // at BLOCK_16X16 (lane-av1rd2). Same
4448 // skipped-block prune as the level above.4651 // skipped-block prune as the level above.
4449 let eight = (!leaf.skip4652 let eight = (!leaf.skip
4653+ && !split_rd_breakout(leaf_cost, SUB, search.lambda)
4450 && (breakout == 0 || leaf.luma.len() > breakout)4654 && (breakout == 0 || leaf.luma.len() > breakout)
4451 && split_inter_8())4655 && split_inter_8())
4452 .then(|| {4656 .then(|| {