forge
Explore
Log in

Don't you dare go Hollow

wip(hbd): --lib compiles clean (0 lib errors); encode.rs/motion.rs boxed to u16 locally (encoder stays 8-bit); 17 test-only errors remain

Browse files at this commit

f83f39fafbb186a0771a8bca2021af8beded134fAhmet Kaan GümüşParent: 04357c7
crates/ec-av1/src/encode.rsmodified+51 -7
@@ -196,6 +196,45 @@ impl Picture {
196196 }
197197 }
198198
199+/// lane-hbd r2: the encoder's own reconstruction/source buffers stay `u8`
200+/// (8-bit only, unchanged this round -- widening the encoder is out of this
201+/// round's scope, see `lanes/hbd-r2.report.md`); this is the local box that
202+/// lets it keep calling [`crate::intra::predict`] now that shape is `u16`
203+/// in and out. A block-sized round-trip through `u16` is exact for 8-bit
204+/// content (every value fits both ways), so this changes no encoder output.
205+#[allow(clippy::too_many_arguments)]
206+fn intra_predict_u8(
207+ mode: u8,
208+ angle_delta: i32,
209+ above: Option<&[u8]>,
210+ left: Option<&[u8]>,
211+ corner: Option<u8>,
212+ bw: usize,
213+ bh: usize,
214+ enable_edge_filter: bool,
215+ smooth_neighbor: bool,
216+ dst: &mut [u8],
217+) {
218+ let above16: Option<Vec<u16>> = above.map(|s| s.iter().map(|&v| u16::from(v)).collect());
219+ let left16: Option<Vec<u16>> = left.map(|s| s.iter().map(|&v| u16::from(v)).collect());
220+ let mut dst16 = vec![0u16; dst.len()];
221+ crate::intra::predict(
222+ mode,
223+ angle_delta,
224+ above16.as_deref(),
225+ left16.as_deref(),
226+ corner.map(u16::from),
227+ bw,
228+ bh,
229+ enable_edge_filter,
230+ smooth_neighbor,
231+ &mut dst16,
232+ );
233+ for (d, &s) in dst.iter_mut().zip(dst16.iter()) {
234+ *d = s as u8;
235+ }
236+}
237+
199238 /// Pads one plane to `(padded_width, padded_height)` by repeating its last
200239 /// row and column, so the block coder always sees a whole number of blocks.
201240 /// [`crop_plane`] undoes this on the way back out.
@@ -597,7 +636,7 @@ impl Plane<'_> {
597636 } = at;
598637 let (above, left, corner) = self.edges(x, y, side, reach);
599638 let mut prediction = vec![0u8; side * side];
600- crate::intra::predict(
639+ intra_predict_u8(
601640 mode,
602641 0,
603642 above.as_deref(),
@@ -817,7 +856,7 @@ impl Plane<'_> {
817856 .iter()
818857 .map(|&mode| {
819858 let mut prediction = vec![0u8; side * side];
820- crate::intra::predict(
859+ intra_predict_u8(
821860 mode,
822861 0,
823862 above.as_deref(),
@@ -869,7 +908,7 @@ impl Plane<'_> {
869908 .iter()
870909 .map(|&mode| {
871910 let mut prediction = vec![0u8; side * side];
872- crate::intra::predict(
911+ intra_predict_u8(
873912 mode,
874913 0,
875914 above.as_deref(),
@@ -2136,9 +2175,13 @@ fn mc_trial(
21362175 ) -> Trial {
21372176 let x_q4 = mv_to_q4(x, mv.1, luma);
21382177 let y_q4 = mv_to_q4(y, mv.0, luma);
2139- let mut prediction = vec![0u8; side * side];
2178+ // lane-hbd r2: `reference`/`prediction` stay `u8` here (encoder is
2179+ // 8-bit only this round, see `intra_predict_u8`'s doc comment) --
2180+ // round-trip through `u16` locally to call the now-widened `mc::predict`.
2181+ let reference16: Vec<u16> = reference.iter().map(|&v| u16::from(v)).collect();
2182+ let mut prediction16 = vec![0u16; side * side];
21402183 mc::predict(
2141- reference,
2184+ &reference16,
21422185 stride,
21432186 ref_width,
21442187 ref_height,
@@ -2146,8 +2189,9 @@ fn mc_trial(
21462189 y_q4,
21472190 side,
21482191 side,
2149- &mut prediction,
2192+ &mut prediction16,
21502193 );
2194+ let prediction: Vec<u8> = prediction16.iter().map(|&v| v as u8).collect();
21512195 plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set)
21522196 }
21532197
@@ -4518,7 +4562,7 @@ mod tests {
45184562 let mut prediction = vec![0u8; side * side];
45194563 let t = Instant::now();
45204564 for _ in 0..N {
4521- crate::intra::predict(
4565+ intra_predict_u8(
45224566 D45_PRED,
45234567 0,
45244568 Some(&above),
crates/ec-av1/src/motion.rsmodified+9 -3
@@ -263,16 +263,22 @@ fn search_traced_from_step(
263263 assert_eq!(source.len(), block_w * block_h, "source is one block");
264264 assert!(!reference.is_empty(), "a reference plane has samples");
265265
266- let mut dst = vec![0u8; block_w * block_h];
266+ // lane-hbd r2: this encoder-side search stays `u8` (see
267+ // `encode::intra_predict_u8`'s doc comment) -- `reference` is converted
268+ // once here, outside the per-candidate closure, since `mc::predict` now
269+ // takes `u16`.
270+ let reference16: Vec<u16> = reference.iter().map(|&v| u16::from(v)).collect();
271+ let mut dst16 = vec![0u16; block_w * block_h];
267272 let mut cost_of = |mv: (i32, i32)| -> f64 {
268273 let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3;
269274 let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3;
270275 predict(
271- reference, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h, &mut dst,
276+ &reference16, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h,
277+ &mut dst16,
272278 );
273279 let sad: f64 = source
274280 .iter()
275- .zip(dst.iter())
281+ .zip(dst16.iter())
276282 .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs()))
277283 .sum();
278284 let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1);