forge
Explore
Log in

Don't you dare go Hollow

U6: ec-h264 delete rd-ablation and enc-profile features, timing.rs, mb_timed!, EncodeTimings and Encoder::timings; RD twin helpers become cfg.transform_8x8, roweven is false and margin 0 so their terms are gone (output unchanged)

Browse files at this commit

83f55a3a3c419685f48e416be8635a3aae150b88Ahmet Kaan GümüşParent: 7e20a36
crates/ec-h264/Cargo.tomlmodified+0 -6
@@ -6,12 +6,6 @@ edition.workspace = true
6 license.workspace = true6 license.workspace = true
7 authors.workspace = true7 authors.workspace = true
8 8
9-[features]
10-# Internal-only RD experiment switches, compiled only by the measurement harness.
11-rd-ablation = []
12-# Per-stage timing counters in the macroblock coder (measurement builds only).
13-enc-profile = []
14-
15 [dependencies]9 [dependencies]
16 ec-core = { workspace = true }10 ec-core = { workspace = true }
17 ec-h264-syntax = { workspace = true }11 ec-h264-syntax = { workspace = true }
crates/ec-h264/src/enc/mb.rsmodified+68 -119
@@ -41,7 +41,7 @@ use super::quant::{
41 forward_4x4, forward_8x8, forward_hadamard_2x2, forward_hadamard_4x4, quant_4x4,41 forward_4x4, forward_8x8, forward_hadamard_2x2, forward_hadamard_4x4, quant_4x4,
42 quant_4x4_offset, quant_8x8, quant_8x8_offset, quant_chroma_dc, quant_luma_dc,42 quant_4x4_offset, quant_8x8, quant_8x8_offset, quant_chroma_dc, quant_luma_dc,
43 };43 };
44-use super::timing::mb_timed;44+
45 use super::{45 use super::{
46 entropy::{EncEntropy, sub_block_4x4},46 entropy::{EncEntropy, sub_block_4x4},
47 lambda_ssd,47 lambda_ssd,
@@ -128,24 +128,12 @@ pub(crate) struct MbEnc<'a> {
128 /// Lagrangian multiplier; it is in the squared-error domain when 8x8128 /// Lagrangian multiplier; it is in the squared-error domain when 8x8
129 /// transform decisions are enabled.129 /// transform decisions are enabled.
130 pub lambda: f64,130 pub lambda: f64,
131- /// Whether `lambda` is the standard squared-error multiplier.
132- pub lambda_standard: bool,
133- /// Extra rate saving an 8x8 trial must buy before it may replace 4x4.
134- pub t8x8_margin_bits: f64,
135 pub preset: Preset,131 pub preset: Preset,
136 /// Fast-preset speed knobs (see [`FastKnobs`]).132 /// Fast-preset speed knobs (see [`FastKnobs`]).
137 pub fast: FastKnobs,133 pub fast: FastKnobs,
138 /// The PPS carries transform_8x8_mode_flag: transform_size_8x8_flag must134 /// The PPS carries transform_8x8_mode_flag: transform_size_8x8_flag must
139 /// be written for every eligible macroblock (7.3.5).135 /// be written for every eligible macroblock (7.3.5).
140 pub transform_8x8: bool,136 pub transform_8x8: bool,
141- /// Whether intra macroblocks may select 8x8. The PPS can remain enabled
142- /// while an ablation measures the classes independently.
143- pub transform_8x8_intra: bool,
144- /// Whether inter macroblocks may select 8x8.
145- pub transform_8x8_inter: bool,
146- /// Whether the ablation restricts 8x8 eligibility to even macroblock
147- /// rows; odd rows then code exactly as they would with 8x8 disabled.
148- pub transform_8x8_roweven: bool,
149 pub ls: LevelScale4x4,137 pub ls: LevelScale4x4,
150 pub ls8: LevelScale8x8,138 pub ls8: LevelScale8x8,
151 /// Neighbourhood of the macroblock being written (CABAC).139 /// Neighbourhood of the macroblock being written (CABAC).
@@ -160,18 +148,6 @@ pub(crate) struct MbEnc<'a> {
160 pub qp_delta_inc: u8,148 pub qp_delta_inc: u8,
161 }149 }
162 150
163-impl MbEnc<'_> {
164- /// Intra 8x8 eligibility of macroblock row `mb_y`.
165- fn t8x8_intra(&self, mb_y: usize) -> bool {
166- self.transform_8x8_intra && (mb_y.is_multiple_of(2) || !self.transform_8x8_roweven)
167- }
168-
169- /// Inter 8x8 eligibility of macroblock row `mb_y`.
170- fn t8x8_inter(&self, mb_y: usize) -> bool {
171- self.transform_8x8_inter && (mb_y.is_multiple_of(2) || !self.transform_8x8_roweven)
172- }
173-}
174-
175 /// Quantised levels of one macroblock, scan order per block.151 /// Quantised levels of one macroblock, scan order per block.
176 #[derive(Clone)]152 #[derive(Clone)]
177 struct Levels {153 struct Levels {
@@ -399,7 +375,7 @@ fn motion_rate(e: &MbEnc<'_>, bits: f64) -> i32 {
399 /// The multiplier `motion_rate` applies, for loops that price many vectors.375 /// The multiplier `motion_rate` applies, for loops that price many vectors.
400 #[inline]376 #[inline]
401 fn motion_lambda(e: &MbEnc<'_>) -> f64 {377 fn motion_lambda(e: &MbEnc<'_>) -> f64 {
402- if e.lambda_standard {378+ if e.transform_8x8 {
403 e.lambda.sqrt()379 e.lambda.sqrt()
404 } else {380 } else {
405 e.lambda381 e.lambda
@@ -565,7 +541,7 @@ pub(crate) fn encode_mb(pic: &mut Picture, e: &mut MbEnc<'_>, w: &mut EncEntropy
565 541
566 let mut inter: Option<Vec<InterChoice>> = None;542 let mut inter: Option<Vec<InterChoice>> = None;
567 if e.slice_type == SliceType::P {543 if e.slice_type == SliceType::P {
568- inter = Some(mb_timed!(0, choose_inter(pic, e, mb_x, mb_y)));544+ inter = Some(choose_inter(pic, e, mb_x, mb_y));
569 }545 }
570 546
571 // Intra against inter is decided on real coded cost: both branches are547 // Intra against inter is decided on real coded cost: both branches are
@@ -597,21 +573,21 @@ pub(crate) fn encode_mb(pic: &mut Picture, e: &mut MbEnc<'_>, w: &mut EncEntropy
597 let gate = e.preset == Preset::Fast && e.fast.intra_gate > 0.0;573 let gate = e.preset == Preset::Fast && e.fast.intra_gate > 0.0;
598 let intra_cost = match inter.as_ref() {574 let intra_cost = match inter.as_ref() {
599 Some(c) if gate && e.fast.lazy_i16 => {575 Some(c) if gate && e.fast.lazy_i16 => {
600- let dc = mb_timed!(1, intra_pre_cost(pic, e, &nbr, mb_x, mb_y, &[2]));576+ let dc = intra_pre_cost(pic, e, &nbr, mb_x, mb_y, &[2]);
601 if f64::from(c[0].satd) <= e.fast.intra_gate * f64::from(dc.satd) {577 if f64::from(c[0].satd) <= e.fast.intra_gate * f64::from(dc.satd) {
602 dc578 dc
603 } else {579 } else {
604- mb_timed!(1, intra_pre_cost(pic, e, &nbr, mb_x, mb_y, &[2, 0, 1, 3]))580+ intra_pre_cost(pic, e, &nbr, mb_x, mb_y, &[2, 0, 1, 3])
605 }581 }
606 }582 }
607- _ => mb_timed!(1, intra_pre_cost(pic, e, &nbr, mb_x, mb_y, &[2, 0, 1, 3])),583+ _ => intra_pre_cost(pic, e, &nbr, mb_x, mb_y, &[2, 0, 1, 3]),
608 };584 };
609 let Some(choices) = inter else {585 let Some(choices) = inter else {
610- mb_timed!(3, encode_intra_mb(pic, e, w, mb_addr, nbr, intra_cost));586+ encode_intra_mb(pic, e, w, mb_addr, nbr, intra_cost);
611 return;587 return;
612 };588 };
613 589
614- let lambda = if e.lambda_standard {590+ let lambda = if e.transform_8x8 {
615 e.lambda591 e.lambda
616 } else {592 } else {
617 lambda_ssd(e.qp)593 lambda_ssd(e.qp)
@@ -622,10 +598,10 @@ pub(crate) fn encode_mb(pic: &mut Picture, e: &mut MbEnc<'_>, w: &mut EncEntropy
622 if gated {598 if gated {
623 // Inter only and one candidate at Fast: nothing is compared, so the599 // Inter only and one candidate at Fast: nothing is compared, so the
624 // macroblock is coded straight into the picture and the writer.600 // macroblock is coded straight into the picture and the writer.
625- mb_timed!(2, encode_inter_mb(pic, e, w, mb_addr, nbr, choices[0]));601+ encode_inter_mb(pic, e, w, mb_addr, nbr, choices[0]);
626 return;602 return;
627 }603 }
628- let before = mb_timed!(4, save_mb_state(pic, e, mb_addr));604+ let before = save_mb_state(pic, e, mb_addr);
629 // The shape and the skip flag are ranked the same way intra and inter are:605 // The shape and the skip flag are ranked the same way intra and inter are:
630 // by coding each candidate and measuring it. The SATD total that ordered606 // by coding each candidate and measuring it. The SATD total that ordered
631 // them inside the search is a prediction-domain estimate that never sees607 // them inside the search is a prediction-domain estimate that never sees
@@ -638,26 +614,23 @@ pub(crate) fn encode_mb(pic: &mut Picture, e: &mut MbEnc<'_>, w: &mut EncEntropy
638 };614 };
639 let mut best_inter: Option<(f64, MbState, EncEntropy)> = None;615 let mut best_inter: Option<(f64, MbState, EncEntropy)> = None;
640 for &choice in &choices[..rd_cands.max(1)] {616 for &choice in &choices[..rd_cands.max(1)] {
641- mb_timed!(4, load_mb_state(pic, e, mb_addr, &before));617+ load_mb_state(pic, e, mb_addr, &before);
642- let mut w_c = mb_timed!(5, w.probe_copy());618+ let mut w_c = w.probe_copy();
643 let start = w_c.bit_len();619 let start = w_c.bit_len();
644- mb_timed!(2, encode_inter_mb(pic, e, &mut w_c, mb_addr, nbr, choice));620+ encode_inter_mb(pic, e, &mut w_c, mb_addr, nbr, choice);
645 let bits = (w_c.bit_len() - start) as f64;621 let bits = (w_c.bit_len() - start) as f64;
646 let rd = ssd_mb(pic, e, mb_x, mb_y) as f64 + lambda * bits;622 let rd = ssd_mb(pic, e, mb_x, mb_y) as f64 + lambda * bits;
647 if best_inter.as_ref().is_none_or(|b| rd < b.0) {623 if best_inter.as_ref().is_none_or(|b| rd < b.0) {
648- best_inter = Some((rd, mb_timed!(4, save_mb_state(pic, e, mb_addr)), w_c));624+ best_inter = Some((rd, save_mb_state(pic, e, mb_addr), w_c));
649 }625 }
650 }626 }
651 let (inter_rd, after_inter, w_inter) = best_inter.expect("at least one inter candidate");627 let (inter_rd, after_inter, w_inter) = best_inter.expect("at least one inter candidate");
652- mb_timed!(4, load_mb_state(pic, e, mb_addr, &before));628+ load_mb_state(pic, e, mb_addr, &before);
653 629
654- let mut w_intra = mb_timed!(5, w.probe_copy());630+ let mut w_intra = w.probe_copy();
655 let intra_bits = {631 let intra_bits = {
656 let start = w_intra.bit_len();632 let start = w_intra.bit_len();
657- mb_timed!(633+ encode_intra_mb(pic, e, &mut w_intra, mb_addr, nbr, intra_cost);
658- 3,
659- encode_intra_mb(pic, e, &mut w_intra, mb_addr, nbr, intra_cost)
660- );
661 (w_intra.bit_len() - start) as f64634 (w_intra.bit_len() - start) as f64
662 };635 };
663 let intra_rd = ssd_mb(pic, e, mb_x, mb_y) as f64 + lambda * intra_bits;636 let intra_rd = ssd_mb(pic, e, mb_x, mb_y) as f64 + lambda * intra_bits;
@@ -665,7 +638,7 @@ pub(crate) fn encode_mb(pic: &mut Picture, e: &mut MbEnc<'_>, w: &mut EncEntropy
665 if intra_rd < inter_rd {638 if intra_rd < inter_rd {
666 w.adopt(w_intra);639 w.adopt(w_intra);
667 } else {640 } else {
668- mb_timed!(4, load_mb_state(pic, e, mb_addr, &after_inter));641+ load_mb_state(pic, e, mb_addr, &after_inter);
669 w.adopt(w_inter);642 w.adopt(w_inter);
670 }643 }
671 }644 }
@@ -1097,18 +1070,15 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Vec<I
1097 1070
1098 let fast = e.preset == Preset::Fast;1071 let fast = e.preset == Preset::Fast;
1099 let mut best = ([0i16; 2], i32::MAX);1072 let mut best = ([0i16; 2], i32::MAX);
1100- mb_timed!(1073+ for (i, &cand) in seeds.iter().enumerate() {
1101- 12,1074+ if seeds[..i].contains(&cand) {
1102- for (i, &cand) in seeds.iter().enumerate() {1075+ continue;
1103- if seeds[..i].contains(&cand) {
1104- continue;
1105- }
1106- let c = cost_of(cand, false);
1107- if c < best.1 {
1108- best = (cand, c);
1109- }
1110 }1076 }
1111- );1077+ let c = cost_of(cand, false);
1078+ if c < best.1 {
1079+ best = (cand, c);
1080+ }
1081+ }
1112 // Every partition is searched. This used to stop at a seed whose cost1082 // Every partition is searched. This used to stop at a seed whose cost
1113 // was already under half a level a sample, on the reasoning that the1083 // was already under half a level a sample, on the reasoning that the
1114 // prediction fit and the search is the encoder's hot loop. Swept on1084 // prediction fit and the search is the encoder's hot loop. Swept on
@@ -1122,34 +1092,31 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Vec<I
1122 // neighbours' motion, so the walk only has to settle around them.1092 // neighbours' motion, so the walk only has to settle around them.
1123 let mut step = if fast { 2i16 * 4 } else { 4i16 * 4 };1093 let mut step = if fast { 2i16 * 4 } else { 4i16 * 4 };
1124 let mut passes = 0;1094 let mut passes = 0;
1125- mb_timed!(1095+ while step >= 4 {
1126- 13,1096+ let mut improved = true;
1127- while step >= 4 {1097+ while improved {
1128- let mut improved = true;1098+ improved = false;
1129- while improved {1099+ passes += 1;
1130- improved = false;1100+ if fast && passes > FAST_ME_PASSES {
1131- passes += 1;1101+ break;
1132- if fast && passes > FAST_ME_PASSES {1102+ }
1133- break;1103+ for (dx, dy) in ME_PATTERN {
1104+ let (dx, dy) = (dx * step, dy * step);
1105+ let cand = [best.0[0] + dx, best.0[1] + dy];
1106+ if (cand[0] - mvp[0]).abs() > range * 4
1107+ || (cand[1] - mvp[1]).abs() > range * 4
1108+ {
1109+ continue;
1134 }1110 }
1135- for (dx, dy) in ME_PATTERN {1111+ let c = cost_of(cand, false);
1136- let (dx, dy) = (dx * step, dy * step);1112+ if c < best.1 {
1137- let cand = [best.0[0] + dx, best.0[1] + dy];1113+ best = (cand, c);
1138- if (cand[0] - mvp[0]).abs() > range * 41114+ improved = true;
1139- || (cand[1] - mvp[1]).abs() > range * 4
1140- {
1141- continue;
1142- }
1143- let c = cost_of(cand, false);
1144- if c < best.1 {
1145- best = (cand, c);
1146- improved = true;
1147- }
1148 }1115 }
1149 }1116 }
1150- step /= 2;
1151 }1117 }
1152- );1118+ step /= 2;
1119+ }
1153 // Sub-sample refinement runs on SATD, not SAD: interpolation1120 // Sub-sample refinement runs on SATD, not SAD: interpolation
1154 // smooths, and a sum of absolute differences reads the smoothing1121 // smooths, and a sum of absolute differences reads the smoothing
1155 // as a better match where a transform-domain cost does not. Worth1122 // as a better match where a transform-domain cost does not. Worth
@@ -1157,7 +1124,7 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Vec<I
1157 // capture. The whole-sample winner is re-costed in the same domain1124 // capture. The whole-sample winner is re-costed in the same domain
1158 // first so the two halves of the search compare.1125 // first so the two halves of the search compare.
1159 let sub_satd = !fast || e.fast.me_satd;1126 let sub_satd = !fast || e.fast.me_satd;
1160- mb_timed!(14, {1127+ {
1161 best.1 = cost_of(best.0, sub_satd);1128 best.1 = cost_of(best.0, sub_satd);
1162 // Balanced iterates both sub-sample steps to convergence. Fast1129 // Balanced iterates both sub-sample steps to convergence. Fast
1163 // looks at each ring of eight once.1130 // looks at each ring of eight once.
@@ -1229,7 +1196,7 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Vec<I
1229 }1196 }
1230 }1197 }
1231 }1198 }
1232- });1199+ }
1233 }1200 }
1234 (1201 (
1235 best.0,1202 best.0,
@@ -1487,7 +1454,7 @@ fn code_luma_4x4(
1487 &source,1454 &source,
1488 &resid,1455 &resid,
1489 &lv.luma[blk],1456 &lv.luma[blk],
1490- zero_block_lambda(e, qp, e.t8x8_inter(mb_y)),1457+ zero_block_lambda(e, qp, e.transform_8x8),
1491 )1458 )
1492 {1459 {
1493 lv.luma[blk] = [0; 16];1460 lv.luma[blk] = [0; 16];
@@ -1535,7 +1502,7 @@ fn code_luma_4x4(
1535 let lambda = if w.is_cabac() {1502 let lambda = if w.is_cabac() {
1536 GROUP_LAMBDA * lambda_ssd(qp)1503 GROUP_LAMBDA * lambda_ssd(qp)
1537 } else {1504 } else {
1538- zero_block_lambda(e, qp, e.t8x8_inter(mb_y))1505+ zero_block_lambda(e, qp, e.transform_8x8)
1539 };1506 };
1540 for g in 0..4 {1507 for g in 0..4 {
1541 if rate[g] == 0.0 {1508 if rate[g] == 0.0 {
@@ -1961,9 +1928,9 @@ fn code_chroma(
1961 e,1928 e,
1962 qp_c,1929 qp_c,
1963 if intra {1930 if intra {
1964- e.t8x8_intra(mb_y)1931+ e.transform_8x8
1965 } else {1932 } else {
1966- e.t8x8_inter(mb_y)1933+ e.transform_8x8
1967 },1934 },
1968 ),1935 ),
1969 ) {1936 ) {
@@ -2189,7 +2156,7 @@ fn code_intra_4x4(
2189 // full rate term this search loses 0.065 dB instead of gaining,2156 // full rate term this search loses 0.065 dB instead of gaining,
2190 // and it loses more the more candidates it sees.2157 // and it loses more the more candidates it sees.
2191 let lambda = ZERO_BLOCK_LAMBDA2158 let lambda = ZERO_BLOCK_LAMBDA
2192- * if e.lambda_standard {2159+ * if e.transform_8x8 {
2193 e.lambda2160 e.lambda
2194 } else {2161 } else {
2195 lambda_ssd(qp)2162 lambda_ssd(qp)
@@ -2322,14 +2289,7 @@ fn code_block_8x8(
2322 dequant_8x8(&mut raster, &e.ls8, qp);2289 dequant_8x8(&mut raster, &e.ls8, qp);
2323 let mut resid = [0i32; 64];2290 let mut resid = [0i32; 64];
2324 inverse_transform_8x8(&raster, &mut resid);2291 inverse_transform_8x8(&raster, &mut resid);
2325- if !rdoq2292+ if !rdoq && !intra && !worth_coding(&d, &resid, out, zero_block_lambda(e, qp, e.transform_8x8))
2326- && !intra
2327- && !worth_coding(
2328- &d,
2329- &resid,
2330- out,
2331- zero_block_lambda(e, qp, e.transform_8x8_inter),
2332- )
2333 {2293 {
2334 *out = [0; 64];2294 *out = [0; 64];
2335 return 0;2295 return 0;
@@ -2807,16 +2767,13 @@ fn encode_intra_mb(
2807 let mut pred_modes8 = [2u8; 4];2767 let mut pred_modes8 = [2u8; 4];
2808 let mut use_i4 = false;2768 let mut use_i4 = false;
2809 let mut chroma_lv = Levels::default();2769 let mut chroma_lv = Levels::default();
2810- let chroma_mode = mb_timed!(2770+ let chroma_mode = choose_chroma_mode_rd(pic, e, w, &nbr, mb_x, mb_y, qp, &mut chroma_lv);
2811- 10,
2812- choose_chroma_mode_rd(pic, e, w, &nbr, mb_x, mb_y, qp, &mut chroma_lv)
2813- );
2814 let mut use_i8 = false;2771 let mut use_i8 = false;
2815 2772
2816 if cost.allow_i4 {2773 if cost.allow_i4 {
2817 let mut lv4 = chroma_lv.clone();2774 let mut lv4 = chroma_lv.clone();
2818- let (m4, p4) = mb_timed!(6, code_intra_4x4(pic, e, mb_x, mb_y, qp, &nbr, &mut lv4));2775+ let (m4, p4) = code_intra_4x4(pic, e, mb_x, mb_y, qp, &nbr, &mut lv4);
2819- let cost4 = if e.t8x8_intra(mb_y) {2776+ let cost4 = if e.transform_8x8 {
2820 let bits = intra_mb_bits(2777 let bits = intra_mb_bits(
2821 pic,2778 pic,
2822 e,2779 e,
@@ -2847,8 +2804,8 @@ fn encode_intra_mb(
2847 let mut recon8 = [0u8; 256];2804 let mut recon8 = [0u8; 256];
2848 let skip8 = e.preset == Preset::Fast2805 let skip8 = e.preset == Preset::Fast
2849 && (e.fast.skip_i8 || (e.fast.p_skip_i8 && e.slice_type == SliceType::P));2806 && (e.fast.skip_i8 || (e.fast.p_skip_i8 && e.slice_type == SliceType::P));
2850- let cost8 = if e.t8x8_intra(mb_y) && !skip8 {2807+ let cost8 = if e.transform_8x8 && !skip8 {
2851- let (m8, p8) = mb_timed!(7, code_intra_8x8(pic, e, w, mb_x, mb_y, qp, &nbr, &mut lv8));2808+ let (m8, p8) = code_intra_8x8(pic, e, w, mb_x, mb_y, qp, &nbr, &mut lv8);
2852 modes8 = m8;2809 modes8 = m8;
2853 pred_modes8 = p8;2810 pred_modes8 = p8;
2854 save_luma(pic, mb_x, mb_y, &mut recon8);2811 save_luma(pic, mb_x, mb_y, &mut recon8);
@@ -2870,11 +2827,8 @@ fn encode_intra_mb(
2870 };2827 };
2871 2828
2872 let mut lv16 = chroma_lv;2829 let mut lv16 = chroma_lv;
2873- mb_timed!(2830+ code_i16_luma(pic, e, mb_x, mb_y, qp, cost.i16_mode, &nbr, &mut lv16);
2874- 11,2831+ let cost16 = if e.transform_8x8 {
2875- code_i16_luma(pic, e, mb_x, mb_y, qp, cost.i16_mode, &nbr, &mut lv16)
2876- );
2877- let cost16 = if e.t8x8_intra(mb_y) {
2878 let bits = intra_mb_bits(2832 let bits = intra_mb_bits(
2879 pic,2833 pic,
2880 e,2834 e,
@@ -2893,9 +2847,7 @@ fn encode_intra_mb(
2893 + lambda_ssd(qp) * rough_intra_bits(&lv16, None) as f642847 + lambda_ssd(qp) * rough_intra_bits(&lv16, None) as f64
2894 };2848 };
2895 2849
2896- if cost8 + e.lambda * e.t8x8_margin_bits <= cost42850+ if cost8 <= cost4 && cost8 <= cost16 {
2897- && cost8 + e.lambda * e.t8x8_margin_bits <= cost16
2898- {
2899 use_i4 = true;2851 use_i4 = true;
2900 use_i8 = true;2852 use_i8 = true;
2901 restore_luma(pic, mb_x, mb_y, &recon8);2853 restore_luma(pic, mb_x, mb_y, &recon8);
@@ -2921,10 +2873,7 @@ fn encode_intra_mb(
2921 }2873 }
2922 } else {2874 } else {
2923 lv = chroma_lv;2875 lv = chroma_lv;
2924- mb_timed!(2876+ code_i16_luma(pic, e, mb_x, mb_y, qp, cost.i16_mode, &nbr, &mut lv);
2925- 11,
2926- code_i16_luma(pic, e, mb_x, mb_y, qp, cost.i16_mode, &nbr, &mut lv)
2927- );
2928 }2877 }
2929 2878
2930 // ---- syntax ----2879 // ---- syntax ----
@@ -3372,9 +3321,9 @@ fn encode_inter_mb(
3372 } else {3321 } else {
3373 03322 0
3374 };3323 };
3375- if e.t8x8_inter(mb_y) && tx_mode == 1 {3324+ if e.transform_8x8 && tx_mode == 1 {
3376 code_luma_8x8(pic, e, w, mb_x, mb_y, qp, &mut lv);3325 code_luma_8x8(pic, e, w, mb_x, mb_y, qp, &mut lv);
3377- } else if e.t8x8_inter(mb_y) && tx_mode != 2 {3326+ } else if e.transform_8x8 && tx_mode != 2 {
3378 // Both transform sizes on the same prediction; the cheaper3327 // Both transform sizes on the same prediction; the cheaper
3379 // rate-distortion cost is coded.3328 // rate-distortion cost is coded.
3380 let mut pred = [0u8; 256];3329 let mut pred = [0u8; 256];
@@ -3397,7 +3346,7 @@ fn encode_inter_mb(
3397 code_luma_8x8(pic, e, w, mb_x, mb_y, qp, &mut lv8);3346 code_luma_8x8(pic, e, w, mb_x, mb_y, qp, &mut lv8);
3398 let bits8 = inter_mb_bits(pic, e, w, mb_addr, &nbr, shape, &mvd, &inc, &lv8);3347 let bits8 = inter_mb_bits(pic, e, w, mb_addr, &nbr, shape, &mvd, &inc, &lv8);
3399 let cost8 = ssd_mb(pic, e, mb_x, mb_y) as f64 + e.lambda * bits8 as f64;3348 let cost8 = ssd_mb(pic, e, mb_x, mb_y) as f64 + e.lambda * bits8 as f64;
3400- if cost8 + e.lambda * e.t8x8_margin_bits < cost4 {3349+ if cost8 < cost4 {
3401 lv = lv8;3350 lv = lv8;
3402 } else {3351 } else {
3403 lv = lv4;3352 lv = lv4;
@@ -3412,7 +3361,7 @@ fn encode_inter_mb(
3412 None => false,3361 None => false,
3413 Some(_) if empty => true,3362 Some(_) if empty => true,
3414 Some(ssd_skip) => {3363 Some(ssd_skip) => {
3415- let coded = if e.t8x8_inter(mb_y) {3364+ let coded = if e.transform_8x8 {
3416 let bits = inter_mb_bits(pic, e, w, mb_addr, &nbr, shape, &mvd, &inc, &lv);3365 let bits = inter_mb_bits(pic, e, w, mb_addr, &nbr, shape, &mvd, &inc, &lv);
3417 ssd_mb(pic, e, mb_x, mb_y) as f64 + e.lambda * bits as f643366 ssd_mb(pic, e, mb_x, mb_y) as f64 + e.lambda * bits as f64
3418 } else {3367 } else {
crates/ec-h264/src/enc/mod.rsmodified+5 -242
@@ -27,7 +27,6 @@ mod mb;
27 mod pool;27 mod pool;
28 mod quant;28 mod quant;
29 mod rc;29 mod rc;
30-pub(crate) mod timing;
31 mod vlc;30 mod vlc;
32 31
33 use ec_core::BitWriter;32 use ec_core::BitWriter;
@@ -37,8 +36,6 @@ use ec_h264_syntax::{SliceType, Sps};
37 36
38 use crate::decoder::deblock_picture;37 use crate::decoder::deblock_picture;
39 use crate::dpb::{Picture, SliceParams as DeblockParams};38 use crate::dpb::{Picture, SliceParams as DeblockParams};
40-#[cfg(feature = "rd-ablation")]
41-use crate::entropy::FLAG_SKIP;
42 use crate::entropy::{FLAG_INTER, FLAG_TRANS8X8};39 use crate::entropy::{FLAG_INTER, FLAG_TRANS8X8};
43 use crate::transform::{LevelScale4x4, LevelScale8x8};40 use crate::transform::{LevelScale4x4, LevelScale8x8};
44 41
@@ -48,8 +45,6 @@ use mb::{MbEnc, Source, encode_mb};
48 use pool::BandPool;45 use pool::BandPool;
49 use rc::RateControl;46 use rc::RateControl;
50 use std::sync::Arc;47 use std::sync::Arc;
51-use std::time::Instant;
52-pub use timing::EncodeTimings;
53 48
54 pub use mb::Preset;49 pub use mb::Preset;
55 50
@@ -87,16 +82,6 @@ pub struct EncoderConfig {
87 /// Turning it off restricts the stream to the Baseline/Main-profile 4x482 /// Turning it off restricts the stream to the Baseline/Main-profile 4x4
88 /// path, which costs 0.7 dB BD-PSNR on film and 0.2 dB on screen capture.83 /// path, which costs 0.7 dB BD-PSNR on film and 0.2 dB on screen capture.
89 pub transform_8x8: bool,84 pub transform_8x8: bool,
90- #[cfg(feature = "rd-ablation")]
91- rd_lambda_standard: bool,
92- #[cfg(feature = "rd-ablation")]
93- rd_transform_8x8_intra: bool,
94- #[cfg(feature = "rd-ablation")]
95- rd_transform_8x8_inter: bool,
96- #[cfg(feature = "rd-ablation")]
97- rd_transform_8x8_roweven: bool,
98- #[cfg(feature = "rd-ablation")]
99- rd_transform_8x8_margin_bits: f64,
100 }85 }
101 86
102 impl EncoderConfig {87 impl EncoderConfig {
@@ -114,16 +99,6 @@ impl EncoderConfig {
114 threads: 0,99 threads: 0,
115 qp: 26,100 qp: 26,
116 transform_8x8: true,101 transform_8x8: true,
117- #[cfg(feature = "rd-ablation")]
118- rd_lambda_standard: false,
119- #[cfg(feature = "rd-ablation")]
120- rd_transform_8x8_intra: false,
121- #[cfg(feature = "rd-ablation")]
122- rd_transform_8x8_inter: false,
123- #[cfg(feature = "rd-ablation")]
124- rd_transform_8x8_roweven: false,
125- #[cfg(feature = "rd-ablation")]
126- rd_transform_8x8_margin_bits: 0.0,
127 }102 }
128 }103 }
129 }104 }
@@ -169,7 +144,6 @@ pub struct Encoder {
169 have_reference: bool,144 have_reference: bool,
170 /// Macroblocks coded with transform_size_8x8_flag set: (intra, inter).145 /// Macroblocks coded with transform_size_8x8_flag set: (intra, inter).
171 t8x8_mbs: (u64, u64),146 t8x8_mbs: (u64, u64),
172- timings: timing::EncodeTimings,
173 }147 }
174 148
175 /// A picture handed to the encoder: three planes, no padding assumptions.149 /// A picture handed to the encoder: three planes, no padding assumptions.
@@ -204,10 +178,6 @@ impl<'a> PictureView<'a> {
204 impl Encoder {178 impl Encoder {
205 /// Build an encoder for `cfg`, refusing what it cannot code.179 /// Build an encoder for `cfg`, refusing what it cannot code.
206 pub fn new(cfg: EncoderConfig) -> Result<Encoder> {180 pub fn new(cfg: EncoderConfig) -> Result<Encoder> {
207- #[cfg(feature = "rd-ablation")]
208- let mut cfg = cfg;
209- #[cfg(feature = "rd-ablation")]
210- apply_rd_ablation(&mut cfg);
211 if cfg.width < 16 || cfg.height < 16 {181 if cfg.width < 16 || cfg.height < 16 {
212 return Err(Error::unsupported(182 return Err(Error::unsupported(
213 "picture smaller than one macroblock",183 "picture smaller than one macroblock",
@@ -288,7 +258,6 @@ impl Encoder {
288 next_id: 0,258 next_id: 0,
289 have_reference: false,259 have_reference: false,
290 t8x8_mbs: (0, 0),260 t8x8_mbs: (0, 0),
291- timings: timing::EncodeTimings::default(),
292 cfg,261 cfg,
293 })262 })
294 }263 }
@@ -304,11 +273,6 @@ impl Encoder {
304 &self.cfg273 &self.cfg
305 }274 }
306 275
307- /// Where the encode time went so far; see [`EncodeTimings`].
308- pub fn timings(&self) -> EncodeTimings {
309- self.timings
310- }
311-
312 /// The reconstruction of the last coded picture, cropped, as I420 planes.276 /// The reconstruction of the last coded picture, cropped, as I420 planes.
313 /// This is what a conformant decoder produces for that picture — the tests277 /// This is what a conformant decoder produces for that picture — the tests
314 /// compare it against this crate's decoder and against the oracle.278 /// compare it against this crate's decoder and against the oracle.
@@ -351,9 +315,7 @@ impl Encoder {
351 if frame.width != self.cfg.width || frame.height != self.cfg.height {315 if frame.width != self.cfg.width || frame.height != self.cfg.height {
352 return Err(Error::corrupt("frame size differs from the encoder's"));316 return Err(Error::corrupt("frame size differs from the encoder's"));
353 }317 }
354- let t_pad = Instant::now();
355 self.pad_source(frame)?;318 self.pad_source(frame)?;
356- self.timings.pad += t_pad.elapsed().as_secs_f64();
357 if self.frames == 0 {319 if self.frames == 0 {
358 self.cqo = chroma_qp_offset_for_source(&self.src, self.cfg.width, self.cfg.height);320 self.cqo = chroma_qp_offset_for_source(&self.src, self.cfg.width, self.cfg.height);
359 let pps_rbsp = write_pps(self.cfg.cabac, self.cfg.transform_8x8, self.cqo);321 let pps_rbsp = write_pps(self.cfg.cabac, self.cfg.transform_8x8, self.cqo);
@@ -399,9 +361,6 @@ impl Encoder {
399 mb_w,361 mb_w,
400 });362 });
401 363
402- let mut busiest = 0.0f64;
403- let mut busy = 0.0f64;
404- let t_bands = Instant::now();
405 let mut answers = Vec::with_capacity(bands.len());364 let mut answers = Vec::with_capacity(bands.len());
406 if self.threads == 1 {365 if self.threads == 1 {
407 // One band: coded on this thread, with no workers.366 // One band: coded on this thread, with no workers.
@@ -434,8 +393,6 @@ impl Encoder {
434 }393 }
435 let mut outputs: Vec<Vec<u8>> = Vec::with_capacity(bands.len());394 let mut outputs: Vec<Vec<u8>> = Vec::with_capacity(bands.len());
436 for (band, answer) in answers.into_iter().enumerate() {395 for (band, answer) in answers.into_iter().enumerate() {
437- busiest = busiest.max(answer.secs);
438- busy += answer.secs;
439 outputs.push(answer.rbsp);396 outputs.push(answer.rbsp);
440 self.workers[band] = answer.pic;397 self.workers[band] = answer.pic;
441 }398 }
@@ -447,10 +404,6 @@ impl Encoder {
447 if let Some(reference) = shared.reference {404 if let Some(reference) = shared.reference {
448 self.reference = reference;405 self.reference = reference;
449 }406 }
450- self.timings.bands_wall += t_bands.elapsed().as_secs_f64();
451- self.timings.bands_busy += busy;
452- self.timings.bands_slowest += busiest;
453- let t_stitch = Instant::now();
454 407
455 // Stitch the bands into worker 0's picture, then filter the whole408 // Stitch the bands into worker 0's picture, then filter the whole
456 // picture the way a decoder does.409 // picture the way a decoder does.
@@ -469,7 +422,6 @@ impl Encoder {
469 for (band, worker) in bands.iter().skip(1).zip(rest.iter()) {422 for (band, worker) in bands.iter().skip(1).zip(rest.iter()) {
470 merge_band(master, worker, *band);423 merge_band(master, worker, *band);
471 }424 }
472- self.timings.stitch += t_stitch.elapsed().as_secs_f64();
473 for &f in &master.mb_flags {425 for &f in &master.mb_flags {
474 if f & FLAG_TRANS8X8 != 0 {426 if f & FLAG_TRANS8X8 != 0 {
475 if f & FLAG_INTER != 0 {427 if f & FLAG_INTER != 0 {
@@ -479,19 +431,7 @@ impl Encoder {
479 }431 }
480 }432 }
481 }433 }
482- // H5 measurement hook: the chosen candidate's trial SSD is the
483- // pre-deblock SSD of the macroblock in this picture (round 4 verified
484- // trial bits and SSD against the final picture), so capturing the
485- // per-macroblock SSD right before and right after the filter is the
486- // exact pre/post comparison with no hooks inside the RD trials.
487- #[cfg(feature = "rd-ablation")]
488- let rd_pre = rd_trace_capture(master, &self.src);
489- let t_deblock = Instant::now();
490 deblock_picture(master);434 deblock_picture(master);
491- self.timings.deblock += t_deblock.elapsed().as_secs_f64();
492- #[cfg(feature = "rd-ablation")]
493- rd_trace_write(master, &self.src, self.frames, rd_pre);
494- let t_output = Instant::now();
495 master.extend_borders();435 master.extend_borders();
496 master.complete = true;436 master.complete = true;
497 std::mem::swap(master, &mut self.reference);437 std::mem::swap(master, &mut self.reference);
@@ -513,8 +453,6 @@ impl Encoder {
513 }453 }
514 454
515 let bits = au.len() as u64 * 8;455 let bits = au.len() as u64 * 8;
516- self.timings.output += t_output.elapsed().as_secs_f64();
517- self.timings.pictures += 1;
518 self.rc.update(idr, qp, bits);456 self.rc.update(idr, qp, bits);
519 self.frames += 1;457 self.frames += 1;
520 self.frame_num = (self.frame_num + 1) % (1 << headers::LOG2_MAX_FRAME_NUM);458 self.frame_num = (self.frame_num + 1) % (1 << headers::LOG2_MAX_FRAME_NUM);
@@ -682,7 +620,6 @@ struct BandMsg {
682 struct BandOut {620 struct BandOut {
683 pic: Picture,621 pic: Picture,
684 rbsp: Vec<u8>,622 rbsp: Vec<u8>,
685- secs: f64,
686 }623 }
687 624
688 /// Code one band on a worker picture.625 /// Code one band on a worker picture.
@@ -693,7 +630,6 @@ fn run_band(msg: BandMsg) -> BandOut {
693 band,630 band,
694 picture_id,631 picture_id,
695 } = msg;632 } = msg;
696- let t_band = Instant::now();
697 let (row0, row1) = shared.bands[band];633 let (row0, row1) = shared.bands[band];
698 let mb_w = shared.mb_w;634 let mb_w = shared.mb_w;
699 pic.start(&shared.sps);635 pic.start(&shared.sps);
@@ -719,11 +655,7 @@ fn run_band(msg: BandMsg) -> BandOut {
719 cqo: shared.cqo,655 cqo: shared.cqo,
720 },656 },
721 );657 );
722- BandOut {658+ BandOut { pic, rbsp }
723- pic,
724- rbsp,
725- secs: t_band.elapsed().as_secs_f64(),
726- }
727 }659 }
728 660
729 struct BandJob<'a> {661 struct BandJob<'a> {
@@ -776,15 +708,10 @@ fn code_band(pic: &mut Picture, job: BandJob<'_>) -> Vec<u8> {
776 slice_id: job.slice_id,708 slice_id: job.slice_id,
777 qp: job.qp,709 qp: job.qp,
778 target_qp: job.qp,710 target_qp: job.qp,
779- lambda: lambda_for(job.qp, rd_lambda_standard(job.cfg)),711+ lambda: lambda_for(job.qp, job.cfg.transform_8x8),
780- t8x8_margin_bits: rd_transform_8x8_margin_bits(job.cfg),
781 preset: job.cfg.preset,712 preset: job.cfg.preset,
782 fast: fast_knobs(),713 fast: fast_knobs(),
783- lambda_standard: rd_lambda_standard(job.cfg),
784 transform_8x8: job.cfg.transform_8x8,714 transform_8x8: job.cfg.transform_8x8,
785- transform_8x8_intra: rd_transform_8x8_intra(job.cfg),
786- transform_8x8_inter: rd_transform_8x8_inter(job.cfg),
787- transform_8x8_roweven: rd_transform_8x8_roweven(job.cfg),
788 ls: LevelScale4x4::new(&[16; 16]),715 ls: LevelScale4x4::new(&[16; 16]),
789 ls8: LevelScale8x8::new(&[16; 64]),716 ls8: LevelScale8x8::new(&[16; 64]),
790 mb_ctx: crate::entropy::MbCtx::default(),717 mb_ctx: crate::entropy::MbCtx::default(),
@@ -801,7 +728,7 @@ fn code_band(pic: &mut Picture, job: BandJob<'_>) -> Vec<u8> {
801 let expected = job.band_target * n as f64 / rows as f64;728 let expected = job.band_target * n as f64 / rows as f64;
802 let delta = job.rc.row_delta(spent, expected);729 let delta = job.rc.row_delta(spent, expected);
803 e.target_qp = (job.qp + delta).clamp(10, 51);730 e.target_qp = (job.qp + delta).clamp(10, 51);
804- e.lambda = lambda_for(e.target_qp, rd_lambda_standard(job.cfg));731+ e.lambda = lambda_for(e.target_qp, job.cfg.transform_8x8);
805 }732 }
806 for mb_x in 0..mb_w {733 for mb_x in 0..mb_w {
807 let addr = mb_y * mb_w + mb_x;734 let addr = mb_y * mb_w + mb_x;
@@ -878,167 +805,6 @@ fn lambda_for(qp: i32, standard: bool) -> f64 {
878 }805 }
879 }806 }
880 807
881-#[cfg(feature = "rd-ablation")]
882-fn apply_rd_ablation(cfg: &mut EncoderConfig) {
883- if let Ok(lambda) = std::env::var("EC_H264_RD_LAMBDA") {
884- cfg.rd_lambda_standard = match lambda.as_str() {
885- "ladder" => false,
886- "standard" => true,
887- _ => panic!("EC_H264_RD_LAMBDA must be ladder or standard"),
888- };
889- }
890- if let Ok(transform) = std::env::var("EC_H264_RD_T8X8") {
891- let (intra, inter, roweven) = match transform.as_str() {
892- "off" => (false, false, false),
893- "on" => (true, true, false),
894- "roweven" => (true, true, true),
895- "intra" => (true, false, false),
896- "inter" => (false, true, false),
897- _ => panic!("EC_H264_RD_T8X8 must be off, on, roweven, intra, or inter"),
898- };
899- cfg.rd_transform_8x8_intra = intra;
900- cfg.rd_transform_8x8_inter = inter;
901- cfg.rd_transform_8x8_roweven = roweven;
902- cfg.transform_8x8 = intra || inter;
903- } else if cfg.transform_8x8 {
904- cfg.rd_transform_8x8_intra = true;
905- cfg.rd_transform_8x8_inter = true;
906- }
907- if let Ok(margin) = std::env::var("EC_H264_RD_T8X8_MARGIN_BITS") {
908- cfg.rd_transform_8x8_margin_bits = margin
909- .parse()
910- .expect("EC_H264_RD_T8X8_MARGIN_BITS must be a number");
911- }
912-}
913-
914-/// Luma and chroma SSD of every macroblock against the source, before the
915-/// deblocking filter — the distortion the RD decision actually paid.
916-#[cfg(feature = "rd-ablation")]
917-fn rd_trace_capture(pic: &Picture, src: &Source) -> Option<Vec<(i64, i64)>> {
918- if std::env::var_os("EC_H264_RD_TRACE").is_none() {
919- return None;
920- }
921- let mut out = Vec::with_capacity(pic.mb_w * pic.mb_h);
922- for mb_y in 0..pic.mb_h {
923- for mb_x in 0..pic.mb_w {
924- out.push(rd_trace_ssd(pic, src, mb_x, mb_y));
925- }
926- }
927- Some(out)
928-}
929-
930-/// One line per macroblock: `frame addr intra trans8 skip qp pre_luma
931-/// pre_chroma post_luma post_chroma`, appended to `$EC_H264_RD_TRACE`.
932-#[cfg(feature = "rd-ablation")]
933-fn rd_trace_write(pic: &Picture, src: &Source, frame: u64, pre: Option<Vec<(i64, i64)>>) {
934- use std::io::Write;
935- let Some(pre) = pre else { return };
936- let mut out = std::fs::OpenOptions::new()
937- .create(true)
938- .append(true)
939- .open(std::env::var_os("EC_H264_RD_TRACE").expect("checked in capture"))
940- .expect("open EC_H264_RD_TRACE");
941- for (addr, &(pre_luma, pre_chroma)) in pre.iter().enumerate() {
942- let (post_luma, post_chroma) = rd_trace_ssd(pic, src, addr % pic.mb_w, addr / pic.mb_w);
943- let f = pic.mb_flags[addr];
944- // A discarded write result here is a SILENTLY SHORT trace: the reader
945- // of `$EC_H264_RD_TRACE` attributes decisions from it and cannot tell a
946- // short line count from a real one. No length check is possible (append
947- // mode has no knowable total), so this is the ec-av1 `append_unknown`
948- // shape: the write error is fatal instead.
949- writeln!(
950- out,
951- "{frame} {addr} {} {} {} {} {pre_luma} {pre_chroma} {post_luma} {post_chroma}",
952- u8::from(f & FLAG_INTER == 0),
953- u8::from(f & FLAG_TRANS8X8 != 0),
954- u8::from(f & FLAG_SKIP != 0),
955- pic.mb_qp[addr]
956- )
957- .expect("write EC_H264_RD_TRACE");
958- }
959-}
960-
961-/// Luma and chroma SSD of one macroblock against the source planes.
962-#[cfg(feature = "rd-ablation")]
963-fn rd_trace_ssd(pic: &Picture, src: &Source, mb_x: usize, mb_y: usize) -> (i64, i64) {
964- let mut luma = 0i64;
965- let stride = pic.y.stride;
966- let origin = pic.y.at(mb_x * 16, mb_y * 16);
967- for row in 0..16 {
968- let s = (mb_y * 16 + row) * src.stride + mb_x * 16;
969- for x in 0..16 {
970- let d = i64::from(src.y[s + x]) - i64::from(pic.y.data[origin + row * stride + x]);
971- luma += d * d;
972- }
973- }
974- let mut chroma = 0i64;
975- for (plane, source) in [(&pic.cb, &src.u), (&pic.cr, &src.v)] {
976- let stride = plane.stride;
977- let origin = plane.at(mb_x * 8, mb_y * 8);
978- for row in 0..8 {
979- let s = (mb_y * 8 + row) * src.c_stride + mb_x * 8;
980- for x in 0..8 {
981- let d = i64::from(source[s + x]) - i64::from(plane.data[origin + row * stride + x]);
982- chroma += d * d;
983- }
984- }
985- }
986- (luma, chroma)
987-}
988-
989-#[cfg(feature = "rd-ablation")]
990-fn rd_lambda_standard(cfg: &EncoderConfig) -> bool {
991- cfg.rd_lambda_standard
992-}
993-
994-#[cfg(not(feature = "rd-ablation"))]
995-fn rd_lambda_standard(cfg: &EncoderConfig) -> bool {
996- cfg.transform_8x8
997-}
998-
999-#[cfg(feature = "rd-ablation")]
1000-fn rd_transform_8x8_intra(cfg: &EncoderConfig) -> bool {
1001- cfg.rd_transform_8x8_intra
1002-}
1003-
1004-#[cfg(not(feature = "rd-ablation"))]
1005-fn rd_transform_8x8_intra(cfg: &EncoderConfig) -> bool {
1006- cfg.transform_8x8
1007-}
1008-
1009-#[cfg(feature = "rd-ablation")]
1010-fn rd_transform_8x8_inter(cfg: &EncoderConfig) -> bool {
1011- cfg.rd_transform_8x8_inter
1012-}
1013-
1014-#[cfg(not(feature = "rd-ablation"))]
1015-fn rd_transform_8x8_inter(cfg: &EncoderConfig) -> bool {
1016- cfg.transform_8x8
1017-}
1018-
1019-#[cfg(feature = "rd-ablation")]
1020-fn rd_transform_8x8_roweven(cfg: &EncoderConfig) -> bool {
1021- cfg.rd_transform_8x8_roweven
1022-}
1023-
1024-#[cfg(not(feature = "rd-ablation"))]
1025-fn rd_transform_8x8_roweven(_: &EncoderConfig) -> bool {
1026- false
1027-}
1028-
1029-#[cfg(not(feature = "rd-ablation"))]
1030-const TRANSFORM_8X8_MARGIN_BITS: f64 = 0.0;
1031-
1032-#[cfg(feature = "rd-ablation")]
1033-fn rd_transform_8x8_margin_bits(cfg: &EncoderConfig) -> f64 {
1034- cfg.rd_transform_8x8_margin_bits
1035-}
1036-
1037-#[cfg(not(feature = "rd-ablation"))]
1038-fn rd_transform_8x8_margin_bits(_: &EncoderConfig) -> f64 {
1039- TRANSFORM_8X8_MARGIN_BITS
1040-}
1041-
1042 /// Split `mb_h` macroblock rows into at most `n` contiguous bands.808 /// Split `mb_h` macroblock rows into at most `n` contiguous bands.
1043 fn split_bands(mb_h: usize, n: usize) -> Vec<(usize, usize)> {809 fn split_bands(mb_h: usize, n: usize) -> Vec<(usize, usize)> {
1044 let n = n.clamp(1, mb_h);810 let n = n.clamp(1, mb_h);
@@ -1198,12 +964,9 @@ mod tests {
1198 fn production_lambda_tracks_transform_mode() {964 fn production_lambda_tracks_transform_mode() {
1199 let mut cfg = EncoderConfig::new(640, 480);965 let mut cfg = EncoderConfig::new(640, 480);
1200 cfg.transform_8x8 = false;966 cfg.transform_8x8 = false;
1201- assert_eq!(967+ assert_eq!(lambda_for(26, cfg.transform_8x8), lambda_for(26, false));
1202- lambda_for(26, rd_lambda_standard(&cfg)),
1203- lambda_for(26, false)
1204- );
1205 cfg.transform_8x8 = true;968 cfg.transform_8x8 = true;
1206- assert_eq!(lambda_for(26, rd_lambda_standard(&cfg)), lambda_ssd(26));969+ assert_eq!(lambda_for(26, cfg.transform_8x8), lambda_ssd(26));
1207 }970 }
1208 971
1209 /// Flat chroma over textured luma picks the negative chroma QP offset, and972 /// Flat chroma over textured luma picks the negative chroma QP offset, and
crates/ec-h264/src/enc/timing.rsdeleted+0 -81
@@ -1,81 +0,0 @@
1-//! Stage timers for one encoder, read through [`Encoder::timings`]. They cost a
2-//! clock read per stage per picture, which is noise next to a picture's coding.
3-//!
4-//! [`Encoder::timings`]: super::Encoder::timings
5-
6-/// Wall-clock seconds spent in each stage of `encode`, summed over every
7-/// picture the encoder has coded.
8-#[derive(Debug, Clone, Copy, Default, PartialEq)]
9-pub struct EncodeTimings {
10- /// Pictures counted.
11- pub pictures: u64,
12- /// Copying and padding the source planes.
13- pub pad: f64,
14- /// The parallel band coding, wall clock.
15- pub bands_wall: f64,
16- /// Sum of every band's own coding time (the work the threads share).
17- pub bands_busy: f64,
18- /// Sum over pictures of the slowest band (the critical path).
19- pub bands_slowest: f64,
20- /// Stitching the bands into one picture.
21- pub stitch: f64,
22- /// The in-loop deblocking filter, which runs on one thread.
23- pub deblock: f64,
24- /// Border extension, the reference swap and assembling the access unit.
25- pub output: f64,
26-}
27-
28-/// Per-stage nanosecond counters for the macroblock coder, behind the
29-/// `enc-profile` feature so a normal build pays nothing. Shared atomics: the
30-/// bands add to them concurrently, which is fine for a profile.
31-#[cfg(feature = "enc-profile")]
32-pub mod mb_stages {
33- use std::sync::atomic::{AtomicU64, Ordering};
34-
35- /// Stage names, in index order.
36- pub const NAMES: [&str; 16] = [
37- "choose_inter",
38- "intra_pre_cost",
39- "inter_rd_candidates",
40- "intra_rd_total",
41- "state_save_load",
42- "entropy_clone",
43- "intra4x4_rd",
44- "intra8x8_rd",
45- "intra_bits_and_ssd",
46- "(unused)",
47- "chroma_mode_rd",
48- "intra16_rd",
49- "me_seeds",
50- "me_int",
51- "me_sub",
52- "me_chroma_skip",
53- ];
54- pub(crate) static NANOS: [AtomicU64; 16] = [const { AtomicU64::new(0) }; 16];
55-
56- /// Nanoseconds spent in each stage so far, in [`NAMES`] order.
57- pub fn snapshot() -> [u64; 16] {
58- std::array::from_fn(|i| NANOS[i].load(Ordering::Relaxed))
59- }
60-}
61-
62-/// Time `$body` into stage `$idx` of [`mb_stages`] when profiling, else just run it.
63-#[cfg(feature = "enc-profile")]
64-macro_rules! mb_timed {
65- ($idx:expr, $body:expr) => {{
66- let t = std::time::Instant::now();
67- let r = $body;
68- $crate::enc::timing::mb_stages::NANOS[$idx].fetch_add(
69- t.elapsed().as_nanos() as u64,
70- std::sync::atomic::Ordering::Relaxed,
71- );
72- r
73- }};
74-}
75-#[cfg(not(feature = "enc-profile"))]
76-macro_rules! mb_timed {
77- ($idx:expr, $body:expr) => {
78- $body
79- };
80-}
81-pub(crate) use mb_timed;
crates/ec-h264/src/lib.rsmodified+2 -4
@@ -46,8 +46,8 @@ mod deblock_mbaff;
46 mod decoder;46 mod decoder;
47 mod dpb;47 mod dpb;
48 mod enc;48 mod enc;
49-mod fmo;
50 mod entropy;49 mod entropy;
50+mod fmo;
51 mod inter;51 mod inter;
52 mod inter16;52 mod inter16;
53 mod mbaff;53 mod mbaff;
@@ -61,6 +61,4 @@ pub use cabac::BitAccount;
61 pub use codec::H264Decoder;61 pub use codec::H264Decoder;
62 pub use decoder::{Decoder, MbShapes, NalOutcome, OutputOrder};62 pub use decoder::{Decoder, MbShapes, NalOutcome, OutputOrder};
63 pub use ec_core::error::{Error, Result};63 pub use ec_core::error::{Error, Result};
64-#[cfg(feature = "enc-profile")]64+pub use enc::{EncodedPicture, Encoder, EncoderConfig, PictureView, Preset};
65-pub use enc::timing::mb_stages;
66-pub use enc::{EncodeTimings, EncodedPicture, Encoder, EncoderConfig, PictureView, Preset};