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 {
196 }196 }
197 }197 }
198 198
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+
199 /// Pads one plane to `(padded_width, padded_height)` by repeating its last238 /// Pads one plane to `(padded_width, padded_height)` by repeating its last
200 /// row and column, so the block coder always sees a whole number of blocks.239 /// row and column, so the block coder always sees a whole number of blocks.
201 /// [`crop_plane`] undoes this on the way back out.240 /// [`crop_plane`] undoes this on the way back out.
@@ -597,7 +636,7 @@ impl Plane<'_> {
597 } = at;636 } = at;
598 let (above, left, corner) = self.edges(x, y, side, reach);637 let (above, left, corner) = self.edges(x, y, side, reach);
599 let mut prediction = vec![0u8; side * side];638 let mut prediction = vec![0u8; side * side];
600- crate::intra::predict(639+ intra_predict_u8(
601 mode,640 mode,
602 0,641 0,
603 above.as_deref(),642 above.as_deref(),
@@ -817,7 +856,7 @@ impl Plane<'_> {
817 .iter()856 .iter()
818 .map(|&mode| {857 .map(|&mode| {
819 let mut prediction = vec![0u8; side * side];858 let mut prediction = vec![0u8; side * side];
820- crate::intra::predict(859+ intra_predict_u8(
821 mode,860 mode,
822 0,861 0,
823 above.as_deref(),862 above.as_deref(),
@@ -869,7 +908,7 @@ impl Plane<'_> {
869 .iter()908 .iter()
870 .map(|&mode| {909 .map(|&mode| {
871 let mut prediction = vec![0u8; side * side];910 let mut prediction = vec![0u8; side * side];
872- crate::intra::predict(911+ intra_predict_u8(
873 mode,912 mode,
874 0,913 0,
875 above.as_deref(),914 above.as_deref(),
@@ -2136,9 +2175,13 @@ fn mc_trial(
2136 ) -> Trial {2175 ) -> Trial {
2137 let x_q4 = mv_to_q4(x, mv.1, luma);2176 let x_q4 = mv_to_q4(x, mv.1, luma);
2138 let y_q4 = mv_to_q4(y, mv.0, luma);2177 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];
2140 mc::predict(2183 mc::predict(
2141- reference,2184+ &reference16,
2142 stride,2185 stride,
2143 ref_width,2186 ref_width,
2144 ref_height,2187 ref_height,
@@ -2146,8 +2189,9 @@ fn mc_trial(
2146 y_q4,2189 y_q4,
2147 side,2190 side,
2148 side,2191 side,
2149- &mut prediction,2192+ &mut prediction16,
2150 );2193 );
2194+ let prediction: Vec<u8> = prediction16.iter().map(|&v| v as u8).collect();
2151 plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set)2195 plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set)
2152 }2196 }
2153 2197
@@ -4518,7 +4562,7 @@ mod tests {
4518 let mut prediction = vec![0u8; side * side];4562 let mut prediction = vec![0u8; side * side];
4519 let t = Instant::now();4563 let t = Instant::now();
4520 for _ in 0..N {4564 for _ in 0..N {
4521- crate::intra::predict(4565+ intra_predict_u8(
4522 D45_PRED,4566 D45_PRED,
4523 0,4567 0,
4524 Some(&above),4568 Some(&above),
crates/ec-av1/src/motion.rsmodified+9 -3
@@ -263,16 +263,22 @@ fn search_traced_from_step(
263 assert_eq!(source.len(), block_w * block_h, "source is one block");263 assert_eq!(source.len(), block_w * block_h, "source is one block");
264 assert!(!reference.is_empty(), "a reference plane has samples");264 assert!(!reference.is_empty(), "a reference plane has samples");
265 265
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];
267 let mut cost_of = |mv: (i32, i32)| -> f64 {272 let mut cost_of = |mv: (i32, i32)| -> f64 {
268 let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3;273 let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3;
269 let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3;274 let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3;
270 predict(275 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,
272 );278 );
273 let sad: f64 = source279 let sad: f64 = source
274 .iter()280 .iter()
275- .zip(dst.iter())281+ .zip(dst16.iter())
276 .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs()))282 .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs()))
277 .sum();283 .sum();
278 let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1);284 let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1);