Merge branch 'lane-hbd': Picture carries u16 samples; the encoder stays 8-bit at its own boundary
Browse files at this commit10 changed files +409 -124
- crates/ec-av1/src/decode.rs +29 -25
- crates/ec-av1/src/encode.rs +79 -57
- crates/ec-av1/src/encoder.rs +11 -8
- crates/ec-av1/src/film_grain.rs +3 -3
- crates/ec-av1/src/stream.rs +20 -16
- crates/ec-av1/src/superres.rs +27 -12
- lanes/hbd-r3.charter.md +49 -0
- lanes/hbd-r3.report.md +119 -0
- lanes/hbd-r4.charter.md +67 -0
- tools/ec-bench/src/main.rs +5 -3
crates/ec-av1/src/decode.rsmodified+29 -25
| @@ -6820,17 +6820,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 6820 | 6820 | Picture { |
| 6821 | 6821 | width, |
| 6822 | 6822 | height, |
| 6823 | - y: y.data.into_iter().map(|s| s as u8).collect(), | |
| 6824 | - u: u.data.into_iter().map(|s| s as u8).collect(), | |
| 6825 | - v: v.data.into_iter().map(|s| s as u8).collect(), | |
| 6823 | + y: y.data, | |
| 6824 | + u: u.data, | |
| 6825 | + v: v.data, | |
| 6826 | 6826 | }, |
| 6827 | 6827 | result_cdfs, |
| 6828 | 6828 | )); |
| 6829 | 6829 | } |
| 6830 | - let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | |
| 6830 | + let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> { | |
| 6831 | 6831 | let mut out = Vec::with_capacity(w * h); |
| 6832 | 6832 | for row in 0..h { |
| 6833 | - out.extend(plane.data[row * plane.width..][..w].iter().map(|&s| s as u8)); | |
| 6833 | + out.extend(plane.data[row * plane.width..][..w].iter().copied()); | |
| 6834 | 6834 | } |
| 6835 | 6835 | out |
| 6836 | 6836 | }; |
| @@ -6856,7 +6856,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 6856 | 6856 | static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 6857 | 6857 | let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 6858 | 6858 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 6859 | - let _ = f.write_all(&yc); | |
| 6859 | + // corner-cut: this diagnostic dump stays 8-bit-narrowed | |
| 6860 | + // regardless of the stream's real bit depth (debug-only, | |
| 6861 | + // never read by a gate); widen if a >8-bit margin dump | |
| 6862 | + // is ever needed. | |
| 6863 | + let _ = f.write_all(&yc.iter().map(|&s| s as u8).collect::<Vec<u8>>()); | |
| 6860 | 6864 | } |
| 6861 | 6865 | } |
| 6862 | 6866 | Some(Picture { |
| @@ -12591,18 +12595,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 12591 | 12595 | Picture { |
| 12592 | 12596 | width, |
| 12593 | 12597 | height, |
| 12594 | - y: y.data.into_iter().map(|s| s as u8).collect(), | |
| 12595 | - u: u.data.into_iter().map(|s| s as u8).collect(), | |
| 12596 | - v: v.data.into_iter().map(|s| s as u8).collect(), | |
| 12598 | + y: y.data, | |
| 12599 | + u: u.data, | |
| 12600 | + v: v.data, | |
| 12597 | 12601 | }, |
| 12598 | 12602 | result_cdfs, |
| 12599 | 12603 | motion_field, |
| 12600 | 12604 | )); |
| 12601 | 12605 | } |
| 12602 | - let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | |
| 12606 | + let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> { | |
| 12603 | 12607 | let mut out = Vec::with_capacity(w * h); |
| 12604 | 12608 | for row in 0..h { |
| 12605 | - out.extend(plane.data[row * plane.width..][..w].iter().map(|&s| s as u8)); | |
| 12609 | + out.extend(plane.data[row * plane.width..][..w].iter().copied()); | |
| 12606 | 12610 | } |
| 12607 | 12611 | out |
| 12608 | 12612 | }; |
| @@ -12710,10 +12714,10 @@ mod tests { | ||
| 12710 | 12714 | /// planes are byte-exact against the encoder's own reconstruction. |
| 12711 | 12715 | fn round_trips(w: usize, h: usize, modes: &[u8]) { |
| 12712 | 12716 | use crate::encode::{Encoded, Picture as Pic}; |
| 12713 | - let mut source = vec![0u8; w * h]; | |
| 12717 | + let mut source = vec![0u16; w * h]; | |
| 12714 | 12718 | for row in 0..h { |
| 12715 | 12719 | for col in 0..w { |
| 12716 | - source[row * w + col] = ((row * 3 + col * 5) % 251) as u8; | |
| 12720 | + source[row * w + col] = ((row * 3 + col * 5) % 251) as u16; | |
| 12717 | 12721 | } |
| 12718 | 12722 | } |
| 12719 | 12723 | let picture = Pic { |
| @@ -12928,9 +12932,9 @@ mod tests { | ||
| 12928 | 12932 | Picture { |
| 12929 | 12933 | width, |
| 12930 | 12934 | height, |
| 12931 | - y: out.stdout[..luma].to_vec(), | |
| 12932 | - u: out.stdout[luma..luma + chroma].to_vec(), | |
| 12933 | - v: out.stdout[luma + chroma..].to_vec(), | |
| 12935 | + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), | |
| 12936 | + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 12937 | + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | |
| 12934 | 12938 | } |
| 12935 | 12939 | } |
| 12936 | 12940 | |
| @@ -12976,9 +12980,9 @@ mod tests { | ||
| 12976 | 12980 | Picture { |
| 12977 | 12981 | width, |
| 12978 | 12982 | height, |
| 12979 | - y: out.stdout[base..base + luma].to_vec(), | |
| 12980 | - u: out.stdout[base + luma..base + luma + chroma].to_vec(), | |
| 12981 | - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), | |
| 12983 | + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), | |
| 12984 | + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 12985 | + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), | |
| 12982 | 12986 | } |
| 12983 | 12987 | }) |
| 12984 | 12988 | .collect() |
| @@ -13069,14 +13073,14 @@ mod tests { | ||
| 13069 | 13073 | let mut picture = crate::encode::Picture::grey(width, height); |
| 13070 | 13074 | for row in 0..height { |
| 13071 | 13075 | for col in 0..width { |
| 13072 | - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8; | |
| 13076 | + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; | |
| 13073 | 13077 | } |
| 13074 | 13078 | } |
| 13075 | 13079 | for row in 0..height / 2 { |
| 13076 | 13080 | for col in 0..width / 2 { |
| 13077 | 13081 | let i = row * width / 2 + col; |
| 13078 | - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8; | |
| 13079 | - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8; | |
| 13082 | + picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; | |
| 13083 | + picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; | |
| 13080 | 13084 | } |
| 13081 | 13085 | } |
| 13082 | 13086 | picture |
| @@ -13088,15 +13092,15 @@ mod tests { | ||
| 13088 | 13092 | for x in 0..width { |
| 13089 | 13093 | let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; |
| 13090 | 13094 | let gradient = sx * 200.0 / width as f64; |
| 13091 | - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8; | |
| 13095 | + picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; | |
| 13092 | 13096 | } |
| 13093 | 13097 | } |
| 13094 | 13098 | for y in 0..height / 2 { |
| 13095 | 13099 | for x in 0..width / 2 { |
| 13096 | 13100 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; |
| 13097 | 13101 | let i = y * width / 2 + x; |
| 13098 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; | |
| 13099 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | |
| 13102 | + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; | |
| 13103 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; | |
| 13100 | 13104 | } |
| 13101 | 13105 | } |
| 13102 | 13106 | picture |
crates/ec-av1/src/encode.rsmodified+79 -57
| @@ -81,7 +81,15 @@ pub(crate) fn split_blocks() -> bool { | ||
| 81 | 81 | SPLIT_BLOCKS |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | -/// One 8-bit planar 4:2:0 picture. | |
| 84 | +/// One planar 4:2:0 picture. `y`/`u`/`v` hold one sample per position as | |
| 85 | +/// `u16` regardless of bit depth (`crate::decode`'s own `PlaneBuf` has used | |
| 86 | +/// `u16` throughout since the round-hbd-r1/r2 widen; this is the last | |
| 87 | +/// narrowing boundary that stayed `u8` -- widened lane-hbd r3 so a 10-bit | |
| 88 | +/// stream's decode output actually carries 10-bit precision instead of | |
| 89 | +/// silently losing its low 2 bits). The encoder only ever produces values in | |
| 90 | +/// `0..=255` (it is still 8-bit-only by design, see `encode.rs`'s r2 | |
| 91 | +/// decision); `Plane::source` narrows right back to `u8` at its two | |
| 92 | +/// construction sites, a lossless round trip for that range. | |
| 85 | 93 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 86 | 94 | pub struct Picture { |
| 87 | 95 | /// The picture's width in luma samples. |
| @@ -89,11 +97,11 @@ pub struct Picture { | ||
| 89 | 97 | /// Its height in luma samples. |
| 90 | 98 | pub height: usize, |
| 91 | 99 | /// The luma plane, `width * height` samples in raster order. |
| 92 | - pub y: Vec<u8>, | |
| 100 | + pub y: Vec<u16>, | |
| 93 | 101 | /// The U plane, at half the width and half the height. |
| 94 | - pub u: Vec<u8>, | |
| 102 | + pub u: Vec<u16>, | |
| 95 | 103 | /// The V plane, the same shape as U. |
| 96 | - pub v: Vec<u8>, | |
| 104 | + pub v: Vec<u16>, | |
| 97 | 105 | } |
| 98 | 106 | |
| 99 | 107 | impl Picture { |
| @@ -238,14 +246,14 @@ fn intra_predict_u8( | ||
| 238 | 246 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last |
| 239 | 247 | /// row and column, so the block coder always sees a whole number of blocks. |
| 240 | 248 | /// [`crop_plane`] undoes this on the way back out. |
| 241 | -fn pad_plane( | |
| 242 | - source: &[u8], | |
| 249 | +fn pad_plane<T: Copy + Default>( | |
| 250 | + source: &[T], | |
| 243 | 251 | width: usize, |
| 244 | 252 | height: usize, |
| 245 | 253 | padded_width: usize, |
| 246 | 254 | padded_height: usize, |
| 247 | -) -> Vec<u8> { | |
| 248 | - let mut out = vec![0u8; padded_width * padded_height]; | |
| 255 | +) -> Vec<T> { | |
| 256 | + let mut out = vec![T::default(); padded_width * padded_height]; | |
| 249 | 257 | for row in 0..padded_height { |
| 250 | 258 | let src = source[row.min(height - 1) * width..][..width].as_ref(); |
| 251 | 259 | let dst = &mut out[row * padded_width..][..padded_width]; |
| @@ -258,7 +266,7 @@ fn pad_plane( | ||
| 258 | 266 | /// The top-left `width` x `height` region of a plane that is `padded_width` |
| 259 | 267 | /// wide, which is the render-size crop [`Picture::padded`]'s replication |
| 260 | 268 | /// exists to let a decoder undo. |
| 261 | -fn crop_plane(source: &[u8], padded_width: usize, width: usize, height: usize) -> Vec<u8> { | |
| 269 | +fn crop_plane<T: Copy>(source: &[T], padded_width: usize, width: usize, height: usize) -> Vec<T> { | |
| 262 | 270 | let mut out = Vec::with_capacity(width * height); |
| 263 | 271 | for row in 0..height { |
| 264 | 272 | out.extend_from_slice(&source[row * padded_width..][..width]); |
| @@ -1750,9 +1758,16 @@ pub(crate) fn encode_key_frame_inner( | ||
| 1750 | 1758 | // Prediction reads no further than this, in each plane's own units -- |
| 1751 | 1759 | // see `Plane::true_width`/`true_height`. |
| 1752 | 1760 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); |
| 1761 | + // lane-hbd r4: `Picture.y/u/v` widened to `Vec<u16>` for the decoder's | |
| 1762 | + // sake (DPB reference slots, 10-bit output); the encoder stays 8-bit by | |
| 1763 | + // design (see `intra_predict_u8`'s doc comment), so narrow the source | |
| 1764 | + // once here. | |
| 1765 | + let picture_y8: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect(); | |
| 1766 | + let picture_u8: Vec<u8> = picture.u.iter().map(|&v| v as u8).collect(); | |
| 1767 | + let picture_v8: Vec<u8> = picture.v.iter().map(|&v| v as u8).collect(); | |
| 1753 | 1768 | let mut luma = Plane { |
| 1754 | - source: &picture.y, | |
| 1755 | - reconstruction: vec![128; picture.y.len()], | |
| 1769 | + source: &picture_y8, | |
| 1770 | + reconstruction: vec![128; picture_y8.len()], | |
| 1756 | 1771 | width: picture.width, |
| 1757 | 1772 | height: picture.height, |
| 1758 | 1773 | true_width, |
| @@ -1760,16 +1775,16 @@ pub(crate) fn encode_key_frame_inner( | ||
| 1760 | 1775 | }; |
| 1761 | 1776 | let mut chroma = [ |
| 1762 | 1777 | Plane { |
| 1763 | - source: &picture.u, | |
| 1764 | - reconstruction: vec![128; picture.u.len()], | |
| 1778 | + source: &picture_u8, | |
| 1779 | + reconstruction: vec![128; picture_u8.len()], | |
| 1765 | 1780 | width: picture.width / 2, |
| 1766 | 1781 | height: picture.height / 2, |
| 1767 | 1782 | true_width: true_width / 2, |
| 1768 | 1783 | true_height: true_height / 2, |
| 1769 | 1784 | }, |
| 1770 | 1785 | Plane { |
| 1771 | - source: &picture.v, | |
| 1772 | - reconstruction: vec![128; picture.v.len()], | |
| 1786 | + source: &picture_v8, | |
| 1787 | + reconstruction: vec![128; picture_v8.len()], | |
| 1773 | 1788 | width: picture.width / 2, |
| 1774 | 1789 | height: picture.height / 2, |
| 1775 | 1790 | true_width: true_width / 2, |
| @@ -2006,9 +2021,9 @@ pub(crate) fn encode_key_frame_inner( | ||
| 2006 | 2021 | reconstruction: Picture { |
| 2007 | 2022 | width: luma.width, |
| 2008 | 2023 | height: luma.height, |
| 2009 | - y: luma.reconstruction, | |
| 2010 | - u: u.reconstruction, | |
| 2011 | - v: v.reconstruction, | |
| 2024 | + y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(), | |
| 2025 | + u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(), | |
| 2026 | + v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(), | |
| 2012 | 2027 | }, |
| 2013 | 2028 | tile, |
| 2014 | 2029 | mi_cols: header.mi_cols, |
| @@ -2164,7 +2179,7 @@ fn mc_trial( | ||
| 2164 | 2179 | side: usize, |
| 2165 | 2180 | mv: (i32, i32), |
| 2166 | 2181 | luma: bool, |
| 2167 | - reference: &[u8], | |
| 2182 | + reference: &[u16], | |
| 2168 | 2183 | stride: usize, |
| 2169 | 2184 | ref_width: usize, |
| 2170 | 2185 | ref_height: usize, |
| @@ -2175,13 +2190,12 @@ fn mc_trial( | ||
| 2175 | 2190 | ) -> Trial { |
| 2176 | 2191 | let x_q4 = mv_to_q4(x, mv.1, luma); |
| 2177 | 2192 | let y_q4 = mv_to_q4(y, mv.0, luma); |
| 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(); | |
| 2193 | + // lane-hbd r4: `reference` (a DPB `Picture`'s plane) is `u16` now that | |
| 2194 | + // `Picture` is widened; `prediction`/the encoder stay `u8` (encoder is | |
| 2195 | + // 8-bit only this round, see `intra_predict_u8`'s doc comment). | |
| 2182 | 2196 | let mut prediction16 = vec![0u16; side * side]; |
| 2183 | 2197 | mc::predict( |
| 2184 | - &reference16, | |
| 2198 | + reference, | |
| 2185 | 2199 | stride, |
| 2186 | 2200 | ref_width, |
| 2187 | 2201 | ref_height, |
| @@ -2453,10 +2467,13 @@ fn search_inter_block( | ||
| 2453 | 2467 | } |
| 2454 | 2468 | |
| 2455 | 2469 | let source_block = luma.source_block(x, y, BLOCK); |
| 2470 | + // lane-hbd r4: `motion::search` is 8-bit only (its SAD/cost math is | |
| 2471 | + // integer-`u8`-scale); narrow the DPB reference plane locally. | |
| 2472 | + let ref_luma_8: Vec<u8> = ref_luma.0.iter().map(|&v| v as u8).collect(); | |
| 2456 | 2473 | #[cfg(test)] |
| 2457 | 2474 | let t = std::time::Instant::now(); |
| 2458 | 2475 | let found = motion::search( |
| 2459 | - ref_luma.0, | |
| 2476 | + &ref_luma_8, | |
| 2460 | 2477 | ref_luma.1, |
| 2461 | 2478 | ref_luma.2, |
| 2462 | 2479 | ref_luma.3, |
| @@ -2616,9 +2633,14 @@ pub(crate) fn encode_inter_frame( | ||
| 2616 | 2633 | header.render_height = render.1 as u32; |
| 2617 | 2634 | |
| 2618 | 2635 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); |
| 2636 | + // lane-hbd r4: encoder stays 8-bit by design; narrow the source once | |
| 2637 | + // here (see `encode_key_frame_inner`). | |
| 2638 | + let picture_y8: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect(); | |
| 2639 | + let picture_u8: Vec<u8> = picture.u.iter().map(|&v| v as u8).collect(); | |
| 2640 | + let picture_v8: Vec<u8> = picture.v.iter().map(|&v| v as u8).collect(); | |
| 2619 | 2641 | let mut luma = Plane { |
| 2620 | - source: &picture.y, | |
| 2621 | - reconstruction: vec![128; picture.y.len()], | |
| 2642 | + source: &picture_y8, | |
| 2643 | + reconstruction: vec![128; picture_y8.len()], | |
| 2622 | 2644 | width: picture.width, |
| 2623 | 2645 | height: picture.height, |
| 2624 | 2646 | true_width, |
| @@ -2626,16 +2648,16 @@ pub(crate) fn encode_inter_frame( | ||
| 2626 | 2648 | }; |
| 2627 | 2649 | let mut chroma = [ |
| 2628 | 2650 | Plane { |
| 2629 | - source: &picture.u, | |
| 2630 | - reconstruction: vec![128; picture.u.len()], | |
| 2651 | + source: &picture_u8, | |
| 2652 | + reconstruction: vec![128; picture_u8.len()], | |
| 2631 | 2653 | width: picture.width / 2, |
| 2632 | 2654 | height: picture.height / 2, |
| 2633 | 2655 | true_width: true_width / 2, |
| 2634 | 2656 | true_height: true_height / 2, |
| 2635 | 2657 | }, |
| 2636 | 2658 | Plane { |
| 2637 | - source: &picture.v, | |
| 2638 | - reconstruction: vec![128; picture.v.len()], | |
| 2659 | + source: &picture_v8, | |
| 2660 | + reconstruction: vec![128; picture_v8.len()], | |
| 2639 | 2661 | width: picture.width / 2, |
| 2640 | 2662 | height: picture.height / 2, |
| 2641 | 2663 | true_width: true_width / 2, |
| @@ -2942,9 +2964,9 @@ pub(crate) fn encode_inter_frame( | ||
| 2942 | 2964 | reconstruction: Picture { |
| 2943 | 2965 | width: luma.width, |
| 2944 | 2966 | height: luma.height, |
| 2945 | - y: luma.reconstruction, | |
| 2946 | - u: u.reconstruction, | |
| 2947 | - v: v.reconstruction, | |
| 2967 | + y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(), | |
| 2968 | + u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(), | |
| 2969 | + v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(), | |
| 2948 | 2970 | }, |
| 2949 | 2971 | tile, |
| 2950 | 2972 | mi_cols: header.mi_cols, |
| @@ -3082,9 +3104,9 @@ mod tests { | ||
| 3082 | 3104 | Picture { |
| 3083 | 3105 | width, |
| 3084 | 3106 | height, |
| 3085 | - y: out.stdout[..luma].to_vec(), | |
| 3086 | - u: out.stdout[luma..luma + chroma].to_vec(), | |
| 3087 | - v: out.stdout[luma + chroma..].to_vec(), | |
| 3107 | + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), | |
| 3108 | + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 3109 | + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | |
| 3088 | 3110 | } |
| 3089 | 3111 | } |
| 3090 | 3112 | |
| @@ -3105,20 +3127,20 @@ mod tests { | ||
| 3105 | 3127 | 0.0 |
| 3106 | 3128 | }; |
| 3107 | 3129 | picture.y[y * width + x] = |
| 3108 | - (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8; | |
| 3130 | + (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16; | |
| 3109 | 3131 | } |
| 3110 | 3132 | } |
| 3111 | 3133 | for y in 0..height / 2 { |
| 3112 | 3134 | for x in 0..width / 2 { |
| 3113 | 3135 | let i = y * width / 2 + x; |
| 3114 | - picture.u[i] = (100 + (x * 60 / (width / 2))) as u8; | |
| 3115 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | |
| 3136 | + picture.u[i] = (100 + (x * 60 / (width / 2))) as u16; | |
| 3137 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; | |
| 3116 | 3138 | } |
| 3117 | 3139 | } |
| 3118 | 3140 | picture |
| 3119 | 3141 | } |
| 3120 | 3142 | |
| 3121 | - fn psnr(a: &[u8], b: &[u8]) -> f64 { | |
| 3143 | + fn psnr(a: &[u16], b: &[u16]) -> f64 { | |
| 3122 | 3144 | let squared: f64 = a |
| 3123 | 3145 | .iter() |
| 3124 | 3146 | .zip(b) |
| @@ -3653,9 +3675,9 @@ mod tests { | ||
| 3653 | 3675 | Picture { |
| 3654 | 3676 | width, |
| 3655 | 3677 | height, |
| 3656 | - y: out.stdout[..luma].to_vec(), | |
| 3657 | - u: out.stdout[luma..luma + chroma].to_vec(), | |
| 3658 | - v: out.stdout[luma + chroma..].to_vec(), | |
| 3678 | + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), | |
| 3679 | + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 3680 | + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | |
| 3659 | 3681 | } |
| 3660 | 3682 | } |
| 3661 | 3683 | |
| @@ -3775,7 +3797,7 @@ mod tests { | ||
| 3775 | 3797 | /// Where two planes first disagree, and by how much: a mismatch reported as |
| 3776 | 3798 | /// a position says which block and which sample of it went wrong, which a |
| 3777 | 3799 | /// pair of thousand-sample arrays does not. |
| 3778 | - fn first_difference(ours: &[u8], theirs: &[u8], width: usize) -> Option<String> { | |
| 3800 | + fn first_difference(ours: &[u16], theirs: &[u16], width: usize) -> Option<String> { | |
| 3779 | 3801 | let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?; |
| 3780 | 3802 | let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count(); |
| 3781 | 3803 | Some(format!( |
| @@ -4331,15 +4353,15 @@ mod tests { | ||
| 4331 | 4353 | 0.0 |
| 4332 | 4354 | }; |
| 4333 | 4355 | picture.y[y * width + x] = |
| 4334 | - (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8; | |
| 4356 | + (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16; | |
| 4335 | 4357 | } |
| 4336 | 4358 | } |
| 4337 | 4359 | for y in 0..height / 2 { |
| 4338 | 4360 | for x in 0..width / 2 { |
| 4339 | 4361 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; |
| 4340 | 4362 | let i = y * width / 2 + x; |
| 4341 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; | |
| 4342 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | |
| 4363 | + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; | |
| 4364 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; | |
| 4343 | 4365 | } |
| 4344 | 4366 | } |
| 4345 | 4367 | picture |
| @@ -4387,9 +4409,9 @@ mod tests { | ||
| 4387 | 4409 | Picture { |
| 4388 | 4410 | width, |
| 4389 | 4411 | height, |
| 4390 | - y: out.stdout[base..base + luma].to_vec(), | |
| 4391 | - u: out.stdout[base + luma..base + luma + chroma].to_vec(), | |
| 4392 | - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), | |
| 4412 | + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), | |
| 4413 | + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 4414 | + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), | |
| 4393 | 4415 | } |
| 4394 | 4416 | }) |
| 4395 | 4417 | .collect() |
| @@ -4728,9 +4750,9 @@ mod tests { | ||
| 4728 | 4750 | Picture { |
| 4729 | 4751 | width, |
| 4730 | 4752 | height, |
| 4731 | - y: bytes[..luma].to_vec(), | |
| 4732 | - u: bytes[luma..luma + chroma].to_vec(), | |
| 4733 | - v: bytes[luma + chroma..].to_vec(), | |
| 4753 | + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), | |
| 4754 | + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 4755 | + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | |
| 4734 | 4756 | } |
| 4735 | 4757 | }) |
| 4736 | 4758 | } |
| @@ -4855,9 +4877,9 @@ mod tests { | ||
| 4855 | 4877 | Picture { |
| 4856 | 4878 | width, |
| 4857 | 4879 | height, |
| 4858 | - y: bytes[..luma].to_vec(), | |
| 4859 | - u: bytes[luma..luma + chroma].to_vec(), | |
| 4860 | - v: bytes[luma + chroma..].to_vec(), | |
| 4880 | + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), | |
| 4881 | + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 4882 | + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | |
| 4861 | 4883 | } |
| 4862 | 4884 | }) |
| 4863 | 4885 | .collect() |
crates/ec-av1/src/encoder.rsmodified+11 -8
| @@ -376,14 +376,14 @@ mod tests { | ||
| 376 | 376 | for y in 0..height { |
| 377 | 377 | for x in 0..width { |
| 378 | 378 | let sx = (x + shift) % width; |
| 379 | - picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u8; | |
| 379 | + picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u16; | |
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | for y in 0..height / 2 { |
| 383 | 383 | for x in 0..width / 2 { |
| 384 | 384 | let i = y * (width / 2) + x; |
| 385 | - picture.u[i] = ((100 + shift * 4) % 256) as u8; | |
| 386 | - picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u8; | |
| 385 | + picture.u[i] = ((100 + shift * 4) % 256) as u16; | |
| 386 | + picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u16; | |
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | picture |
| @@ -679,9 +679,9 @@ mod tests { | ||
| 679 | 679 | Picture { |
| 680 | 680 | width, |
| 681 | 681 | height, |
| 682 | - y: bytes[..luma].to_vec(), | |
| 683 | - u: bytes[luma..luma + chroma].to_vec(), | |
| 684 | - v: bytes[luma + chroma..].to_vec(), | |
| 682 | + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), | |
| 683 | + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 684 | + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | |
| 685 | 685 | } |
| 686 | 686 | }) |
| 687 | 687 | .collect(), |
| @@ -759,7 +759,7 @@ mod tests { | ||
| 759 | 759 | } |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - fn psnr(a: &[u8], b: &[u8]) -> f64 { | |
| 762 | + fn psnr(a: &[u16], b: &[u16]) -> f64 { | |
| 763 | 763 | let squared: f64 = a |
| 764 | 764 | .iter() |
| 765 | 765 | .zip(b) |
| @@ -847,7 +847,10 @@ mod tests { | ||
| 847 | 847 | let mean_psnr: f64 = decoded |
| 848 | 848 | .iter() |
| 849 | 849 | .zip(&pictures) |
| 850 | - .map(|(d, p)| psnr(d, &p.y)) | |
| 850 | + .map(|(d, p)| { | |
| 851 | + let d16: Vec<u16> = d.iter().map(|&v| u16::from(v)).collect(); | |
| 852 | + psnr(&d16, &p.y) | |
| 853 | + }) | |
| 851 | 854 | .sum::<f64>() |
| 852 | 855 | / decoded.len() as f64; |
| 853 | 856 | assert!( |
crates/ec-av1/src/film_grain.rsmodified+3 -3
| @@ -353,7 +353,7 @@ fn add_noise_to_block( | ||
| 353 | 353 | let delta = (scaling_cb[scaled as usize] * cb_grain[gidx] + rounding_offset) |
| 354 | 354 | >> scaling_shift; |
| 355 | 355 | picture.u[cidx] = |
| 356 | - ((picture.u[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u8; | |
| 356 | + ((picture.u[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u16; | |
| 357 | 357 | } |
| 358 | 358 | if apply_cr { |
| 359 | 359 | let scaled = (((average_luma * cr_luma_mult + cr_mult * picture.v[cidx] as i32) |
| @@ -363,7 +363,7 @@ fn add_noise_to_block( | ||
| 363 | 363 | let delta = (scaling_cr[scaled as usize] * cr_grain[gidx] + rounding_offset) |
| 364 | 364 | >> scaling_shift; |
| 365 | 365 | picture.v[cidx] = |
| 366 | - ((picture.v[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u8; | |
| 366 | + ((picture.v[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u16; | |
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | } |
| @@ -376,7 +376,7 @@ fn add_noise_to_block( | ||
| 376 | 376 | + rounding_offset) |
| 377 | 377 | >> scaling_shift; |
| 378 | 378 | picture.y[pidx] = |
| 379 | - ((picture.y[pidx] as i32 + delta).clamp(min_luma, max_luma)) as u8; | |
| 379 | + ((picture.y[pidx] as i32 + delta).clamp(min_luma, max_luma)) as u16; | |
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | } |
crates/ec-av1/src/stream.rsmodified+20 -16
| @@ -634,9 +634,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 634 | 634 | use std::io::Write; |
| 635 | 635 | let idx = pictures_decoded; |
| 636 | 636 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 637 | - let _ = f.write_all(&picture.y); | |
| 638 | - let _ = f.write_all(&picture.u); | |
| 639 | - let _ = f.write_all(&picture.v); | |
| 637 | + // lane-hbd r4: debug dump narrows to u8 -- this diagnostic | |
| 638 | + // predates 10-bit support and is an 8-bit-oracle comparison | |
| 639 | + // only (aomdec's own dump is 8-bit here too). | |
| 640 | + let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() }; | |
| 641 | + let _ = f.write_all(&narrow(&picture.y)); | |
| 642 | + let _ = f.write_all(&narrow(&picture.u)); | |
| 643 | + let _ = f.write_all(&narrow(&picture.v)); | |
| 640 | 644 | } |
| 641 | 645 | } |
| 642 | 646 | pictures_decoded += 1; |
| @@ -676,14 +680,14 @@ mod tests { | ||
| 676 | 680 | let mut picture = Pic::grey(width, height); |
| 677 | 681 | for row in 0..height { |
| 678 | 682 | for col in 0..width { |
| 679 | - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8; | |
| 683 | + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; | |
| 680 | 684 | } |
| 681 | 685 | } |
| 682 | 686 | for row in 0..height / 2 { |
| 683 | 687 | for col in 0..width / 2 { |
| 684 | 688 | let i = row * width / 2 + col; |
| 685 | - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8; | |
| 686 | - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8; | |
| 689 | + picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; | |
| 690 | + picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; | |
| 687 | 691 | } |
| 688 | 692 | } |
| 689 | 693 | picture |
| @@ -695,15 +699,15 @@ mod tests { | ||
| 695 | 699 | for x in 0..width { |
| 696 | 700 | let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; |
| 697 | 701 | let gradient = sx * 200.0 / width as f64; |
| 698 | - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8; | |
| 702 | + picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; | |
| 699 | 703 | } |
| 700 | 704 | } |
| 701 | 705 | for y in 0..height / 2 { |
| 702 | 706 | for x in 0..width / 2 { |
| 703 | 707 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; |
| 704 | 708 | let i = y * width / 2 + x; |
| 705 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; | |
| 706 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | |
| 709 | + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; | |
| 710 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; | |
| 707 | 711 | } |
| 708 | 712 | } |
| 709 | 713 | picture |
| @@ -867,9 +871,9 @@ mod tests { | ||
| 867 | 871 | Pic { |
| 868 | 872 | width, |
| 869 | 873 | height, |
| 870 | - y: out.stdout[base..base + luma].to_vec(), | |
| 871 | - u: out.stdout[base + luma..base + luma + chroma].to_vec(), | |
| 872 | - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), | |
| 874 | + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), | |
| 875 | + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), | |
| 876 | + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), | |
| 873 | 877 | } |
| 874 | 878 | }) |
| 875 | 879 | .collect() |
| @@ -2854,7 +2858,7 @@ mod tests { | ||
| 2854 | 2858 | // actually produced -- no second ffmpeg invocation needed). |
| 2855 | 2859 | let ffmpeg_raw: Vec<u8> = ffmpeg_frames |
| 2856 | 2860 | .iter() |
| 2857 | - .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).copied()) | |
| 2861 | + .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).map(|&v| v as u8)) | |
| 2858 | 2862 | .collect(); |
| 2859 | 2863 | let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw); |
| 2860 | 2864 | eprintln!( |
| @@ -6662,9 +6666,9 @@ mod tests { | ||
| 6662 | 6666 | let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames); |
| 6663 | 6667 | for f in 0..frames { |
| 6664 | 6668 | let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64); |
| 6665 | - yuv.extend_from_slice(&card.y); | |
| 6666 | - yuv.extend_from_slice(&card.u); | |
| 6667 | - yuv.extend_from_slice(&card.v); | |
| 6669 | + yuv.extend(card.y.iter().map(|&v| v as u8)); | |
| 6670 | + yuv.extend(card.u.iter().map(|&v| v as u8)); | |
| 6671 | + yuv.extend(card.v.iter().map(|&v| v as u8)); | |
| 6668 | 6672 | } |
| 6669 | 6673 | std::fs::write(&yuv_path, &yuv).unwrap(); |
| 6670 | 6674 | let status = Command::new(aomenc_path()) |
crates/ec-av1/src/superres.rsmodified+27 -12
| @@ -191,30 +191,45 @@ pub(crate) fn upscale_picture( | ||
| 191 | 191 | let chroma_in_w = picture.width.div_ceil(2); |
| 192 | 192 | let chroma_out_w = upscaled_width.div_ceil(2); |
| 193 | 193 | let chroma_h = height.div_ceil(2); |
| 194 | + // lane-hbd r4: superres is 8-bit by construction (`upscale_row` clamps | |
| 195 | + // to 255) -- narrow at this boundary; callers refuse `bit_depth != 8` | |
| 196 | + // before ever reaching here (see `stream.rs`). | |
| 197 | + let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() }; | |
| 198 | + let picture_y8 = narrow(&picture.y); | |
| 199 | + let picture_u8 = narrow(&picture.u); | |
| 200 | + let picture_v8 = narrow(&picture.v); | |
| 201 | + let margin_y8 = margin.map(|m| narrow(&m.y)); | |
| 202 | + let margin_u8 = margin.map(|m| narrow(&m.u)); | |
| 203 | + let margin_v8 = margin.map(|m| narrow(&m.v)); | |
| 204 | + let widen = |v: Vec<u8>| -> Vec<u16> { v.into_iter().map(u16::from).collect() }; | |
| 194 | 205 | crate::encode::Picture { |
| 195 | 206 | width: upscaled_width, |
| 196 | 207 | height, |
| 197 | - y: upscale_plane( | |
| 198 | - &picture.y, | |
| 208 | + y: widen(upscale_plane( | |
| 209 | + &picture_y8, | |
| 199 | 210 | height, |
| 200 | 211 | picture.width, |
| 201 | 212 | upscaled_width, |
| 202 | - margin.map(|m| (m.y.as_slice(), m.width)), | |
| 203 | - ), | |
| 204 | - u: upscale_plane( | |
| 205 | - &picture.u, | |
| 213 | + margin_y8.as_deref().map(|m| (m, margin.unwrap().width)), | |
| 214 | + )), | |
| 215 | + u: widen(upscale_plane( | |
| 216 | + &picture_u8, | |
| 206 | 217 | chroma_h, |
| 207 | 218 | chroma_in_w, |
| 208 | 219 | chroma_out_w, |
| 209 | - margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))), | |
| 210 | - ), | |
| 211 | - v: upscale_plane( | |
| 212 | - &picture.v, | |
| 220 | + margin_u8 | |
| 221 | + .as_deref() | |
| 222 | + .map(|m| (m, margin.unwrap().width.div_ceil(2))), | |
| 223 | + )), | |
| 224 | + v: widen(upscale_plane( | |
| 225 | + &picture_v8, | |
| 213 | 226 | chroma_h, |
| 214 | 227 | chroma_in_w, |
| 215 | 228 | chroma_out_w, |
| 216 | - margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))), | |
| 217 | - ), | |
| 229 | + margin_v8 | |
| 230 | + .as_deref() | |
| 231 | + .map(|m| (m, margin.unwrap().width.div_ceil(2))), | |
| 232 | + )), | |
| 218 | 233 | } |
| 219 | 234 | } |
| 220 | 235 |
lanes/hbd-r3.charter.mdadded+49 -0
| @@ -0,0 +1,49 @@ | ||
| 1 | +# lane-hbd r3 — the payoff: decode a 10-bit stream | |
| 2 | + | |
| 3 | +At main (8440024). The widen is MERGED: the decoder's sample type is `u16` | |
| 4 | +everywhere, clamp bounds come from `bit_depth`, 8-bit output is bit-exact at | |
| 5 | +264/0, and the encoder keeps `u8` with a local box at its four call sites. | |
| 6 | + | |
| 7 | +Everything now stands behind one refusal: `"a stream whose bit depth is not 8 | |
| 8 | +(this decoder reconstructs into 8-bit planes)"` in `stream.rs`. The sentence is | |
| 9 | +already false about the planes. Lift it — properly. | |
| 10 | + | |
| 11 | +## Order | |
| 12 | +1. **A 10-bit reference path.** `ffmpeg_decode_sequence` (`stream.rs`) hardcodes | |
| 13 | + `-pix_fmt yuv420p`, one byte per sample. Add a second helper emitting | |
| 14 | + `yuv420p10le` and parsing u16 little-endian, and make the comparison | |
| 15 | + bit-depth aware. Keep the 8-bit helper exactly as it is — every existing gate | |
| 16 | + depends on it. | |
| 17 | +2. **A gate on a real 10-bit aomenc stream.** `aomenc` needs | |
| 18 | + `--bit-depth=10 --profile=0` and a 10-bit input (`ffmpeg ... -pix_fmt | |
| 19 | + yuv420p10le`); confirm from the sequence header that `bit_depth` really is 10 | |
| 20 | + before trusting any pixel match. Hard-assert it. | |
| 21 | +3. **Lift the refusal** and update `refusal_inventory.rs` in the SAME commit — | |
| 22 | + only once that gate is pixel-exact. | |
| 23 | +4. **Then the real target: his own files.** Both AV1 films on this box are | |
| 24 | + `yuv420p10le`: | |
| 25 | + `~/Downloads/reelb.mkv` and | |
| 26 | + `~/Videos/Films/reelc.mkv`. Extract a few seconds | |
| 27 | + (`ffmpeg -i <file> -t 3 -c:v copy -f obu <out.obu>`, note `-f obu`) and run | |
| 28 | + `cargo run -p ec-av1 --example decode_probe -- <out.obu>`. Whatever refusal | |
| 29 | + comes back next IS the next lane's charter — record it verbatim, with the | |
| 30 | + film and the header state. Do not open his media in a GUI app; ffmpeg and | |
| 31 | + decode_probe only, and write extracted streams into this worktree's | |
| 32 | + `fixtures/`, never beside his files. | |
| 33 | + | |
| 34 | +Expect 10-bit to expose rounding that 8-bit hid: the inverse transform's | |
| 35 | +intermediate clamps already take `bit_depth` (`row_clamp = bit_depth + 8`, | |
| 36 | +`col_clamp = max(bit_depth + 6, 16)`), but every place that still assumes a | |
| 37 | +255 ceiling or an 8-bit rounding constant will show up as a small pixel delta, | |
| 38 | +not a crash. Bisect any mismatch against the oracle rather than by inspection. | |
| 39 | + | |
| 40 | +## Budget discipline | |
| 41 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | |
| 42 | +what is green and write your report. | |
| 43 | + | |
| 44 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground | |
| 45 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg | |
| 46 | +generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | |
| 47 | +`--threads=1 --row-mt=0 --sb-size=64`. Sibling worktrees have live agents — | |
| 48 | +never build in or edit them. Never push, never merge into main; I handle merges. | |
| 49 | +End with `lanes/hbd-r3.report.md`, VERDICT on line 1. |
lanes/hbd-r3.report.mdadded+119 -0
| @@ -0,0 +1,119 @@ | ||
| 1 | +# lane-hbd r3 report | |
| 2 | + | |
| 3 | +VERDICT: NO CHANGE MERGEABLE -- scoping round only, tree left clean at 8281618, next lane's charter attached below. | |
| 4 | + | |
| 5 | +## What happened | |
| 6 | + | |
| 7 | +This round budgeted 75 turns for "the payoff": a 10-bit reference path, a | |
| 8 | +real 10-bit aomenc gate, lifting the `bit_depth != 8` refusal, then probing | |
| 9 | +the user's own films. Most of the budget went to establishing that the | |
| 10 | +refusal cannot be honestly lifted without widening `encode::Picture` itself | |
| 11 | +-- a materially bigger job than the charter's framing suggested -- and a | |
| 12 | +first attempt at that widen, which does not fit in what was left. No commit | |
| 13 | +was made; `git diff` is empty, worktree is at 8281618 exactly. | |
| 14 | + | |
| 15 | +## The real blocker (not visible from the charter alone) | |
| 16 | + | |
| 17 | +r2 widened every *intermediate* sample buffer (`PlaneBuf`, `mc.rs`, | |
| 18 | +`warp.rs`, the OBMC/interintra chains) to `u16`, but the FINAL narrowing -- | |
| 19 | +where a decoded frame becomes an `encode::Picture` -- was untouched, and | |
| 20 | +`Picture.y/u/v` are still `Vec<u8>`. Two places do `s as u8` on the way out | |
| 21 | +(`decode.rs:6823-6825` for key frames, `decode.rs:12594-12596` for inter | |
| 22 | +frames). Widening only the ffmpeg comparison helper (charter step 1) proves | |
| 23 | +nothing on its own: even with a correct 10-bit-precision decode internally, | |
| 24 | +the value that reaches the caller is still an 8-bit truncation, which is | |
| 25 | +exactly the "silent wrongness" the refusal's own doc names. So "lift the | |
| 26 | +refusal properly" (step 3) requires `Picture` to actually carry 10-bit | |
| 27 | +values, not just the reference path to be able to read them. | |
| 28 | + | |
| 29 | +`encode::Picture` is shared between the encoder (its own reconstruction | |
| 30 | +output, `u8`-only by design per r2's explicit decision) and the decoder | |
| 31 | +(`decode_stream`'s return type, and the DPB's own `ref_slots` storage used | |
| 32 | +for inter-frame motion compensation -- `reference: &Picture` is read for MC, | |
| 33 | +not just written at the end, so reference-frame precision matters for | |
| 34 | +correctness on frame 2+, not only for the final comparison). Widening | |
| 35 | +`Picture.y/u/v` to `Vec<u16>` is the natural single-source-of-truth fix and | |
| 36 | +turned out to have a SMALLER encoder blast radius than first feared -- | |
| 37 | +production encoder code only touches `Picture` at ~10 sites (`Plane` | |
| 38 | +construction, `pad_plane`/`crop_plane`, `padded_to`, `crop_encoded`), all | |
| 39 | +either genericizable over the element type or a trivial local `as u8` | |
| 40 | +narrow (the encoder never needs anything but `0..=255`). The real size was | |
| 41 | +in test-fixture churn: `cargo check --lib` alone showed 61 errors, dominated | |
| 42 | +by ~50 encoder test-module literal-assignment sites (`picture.y[i] = ... as | |
| 43 | +u8`) that all need `as u16`, plus the two decode.rs narrowing sites, plus | |
| 44 | +whatever `--tests` adds on top (not reached this round). `film_grain.rs` and | |
| 45 | +`superres.rs` are ADDITIONALLY hardcoded to 8-bit math (grain's scaling LUT | |
| 46 | +is `[i32; 256]`, its doc says "specialized to this crate's only picture | |
| 47 | +shape: 8-bit"; superres's `upscale_row` is `&[u8]` with a literal | |
| 48 | +`.clamp(0, 255) as u8`) -- neither is spec-generalizable to 10-bit inside | |
| 49 | +this round's remaining budget, so the honest plan was to lift the BLANKET | |
| 50 | +`bit_depth != 8` refusal but add two NARROWER ones ("film grain on a stream | |
| 51 | +whose bit depth isn't 8", "use_superres on a stream whose bit depth isn't | |
| 52 | +8") guarding those two subsystems specifically, since the core | |
| 53 | +transform/prediction/MC/deblock/CDEF/LR pipeline is otherwise already | |
| 54 | +bit-depth-generic via `decode::BIT_DEPTH` (which is itself dead code right | |
| 55 | +now -- `set_bit_depth` is defined but never called from `stream.rs`; wiring | |
| 56 | +that is also part of the real fix). | |
| 57 | + | |
| 58 | +A first attempt at the `Picture` widen was made (`Picture.y/u/v: Vec<u16>`, | |
| 59 | +`pad_plane`/`crop_plane` genericized over `T: Copy [+ Default]`, the two | |
| 60 | +decode.rs narrowing sites changed to move `PlaneBuf::data` directly instead | |
| 61 | +of `.map(|s| s as u8)`) and got `cargo check -p ec-av1 --lib` down from 61 | |
| 62 | +to a smaller but still nonzero error count before the turn budget forced a | |
| 63 | +stop; the attempt was reverted (`git checkout --`) rather than left | |
| 64 | +half-compiling, so the tree stays green at 8281618. The diff is saved for | |
| 65 | +reference at | |
| 66 | +`/home/user/Documents/Code/Rust/edith_codecs-hbd/../..` -- actually at | |
| 67 | +the session scratchpad: `hbd-r3-picture-widen-attempt.diff` (128 lines, | |
| 68 | +2 files: `decode.rs`, `encode.rs`). It is NOT applied to the worktree. | |
| 69 | + | |
| 70 | +## What was NOT reached | |
| 71 | + | |
| 72 | +Steps 1 (ffmpeg 10-bit helper), 2 (real 10-bit aomenc gate), 3 (lift + | |
| 73 | +inventory update), 4 (probe his films) -- none started. No fixture files | |
| 74 | +were extracted, nothing was written to `fixtures/`. | |
| 75 | + | |
| 76 | +## Next lane's charter (hbd-r4) | |
| 77 | + | |
| 78 | +1. Apply (or redo, it's small and now-scoped) the `Picture.y/u/v -> | |
| 79 | + Vec<u16>` widen: `encode.rs` struct + `pad_plane`/`crop_plane` | |
| 80 | + genericized (both already attempted, low-risk) + ~10 production | |
| 81 | + `Plane`-construction/padding call sites (local `as u8`/`as u16` box, | |
| 82 | + same pattern as r2's `intra_predict_u8`) + the ~50 encoder test-fixture | |
| 83 | + literal touch-ups (mechanical, `cargo check --lib` then `--tests` | |
| 84 | + enumerates every one) + `decode.rs`'s two narrowing sites (drop the `as | |
| 85 | + u8` map, move `PlaneBuf::data` directly). | |
| 86 | +2. Wire `decode::set_bit_depth(seq.color_config.bit_depth)` in `stream.rs` | |
| 87 | + before the per-frame decode calls -- currently dead code, defaults to 8 | |
| 88 | + always. | |
| 89 | +3. Add two narrow refusals (`film_grain.rs`'s `apply_grain` and | |
| 90 | + `header.use_superres`, both gated on `bit_depth != 8`) rather than | |
| 91 | + generalizing their 8-bit-hardcoded math this round -- name them | |
| 92 | + explicitly in `refusal_inventory.rs`. | |
| 93 | +4. Lift the blanket `bit_depth != 8` refusal in `stream.rs` once (1)-(3) | |
| 94 | + compile and the existing 264-test 8-bit suite is still green (it should | |
| 95 | + be structurally: `Vec<u16>` holding `0..=255` compares byte-for-byte | |
| 96 | + equal in value to the old `Vec<u8>`, only the comparison TYPE changes). | |
| 97 | +5. THEN do the charter's original steps 1/2/3/4: 10-bit ffmpeg reference | |
| 98 | + helper (u16 LE parse), real `--bit-depth=10 --profile=0` aomenc gate | |
| 99 | + hard-asserting `bit_depth == 10` from the sequence header before | |
| 100 | + trusting any pixel match, and only then probe the user's two real films | |
| 101 | + (`~/Downloads/reelb.mkv`, | |
| 102 | + `~/Videos/Films/reelc.mkv`) via `ffmpeg -t 3 -c:v copy -f | |
| 103 | + obu` into this worktree's `fixtures/` + `decode_probe`. Given both films | |
| 104 | + are HDR10 (film grain is common in HDR masters), expect the probe to hit | |
| 105 | + the new film-grain-at-10-bit refusal quickly -- record it verbatim with | |
| 106 | + header state as instructed, that becomes hbd-r5. | |
| 107 | + | |
| 108 | +## Budget | |
| 109 | + | |
| 110 | +Spent essentially the whole 75-turn budget on: reading the charter/r2 | |
| 111 | +report, tracing the full narrowing chain (`Picture` shared by encoder+DPB, | |
| 112 | +not just a comparison-helper concern), sizing the blast radius across | |
| 113 | +encode.rs/decode.rs/film_grain.rs/superres.rs, and one partial widen | |
| 114 | +attempt that was reverted rather than left broken. This was a scoping | |
| 115 | +failure on my part, not a budget-external blocker: the charter's own | |
| 116 | +"expect 10-bit to expose rounding" framing undersold that the OUTPUT type | |
| 117 | +itself, not just intermediate clamps, needed widening -- that should have | |
| 118 | +been the very first thing checked (grep `Picture.*Vec<u8>`) before reading | |
| 119 | +deeply into the rest of the pipeline. |
lanes/hbd-r4.charter.mdadded+67 -0
| @@ -0,0 +1,67 @@ | ||
| 1 | +# lane-hbd r4 — widen Picture, then lift the refusal | |
| 2 | + | |
| 3 | +At 7bb2a18. Read `lanes/hbd-r3.report.md` first. r3 landed no code but did the | |
| 4 | +scoping that makes this round tractable, and it found the real blocker: | |
| 5 | +`encode::Picture.y/u/v` (`encode.rs:92`) are still `Vec<u8>`, and that type is | |
| 6 | +shared by the encoder AND by `decode_stream`'s return value and the DPB | |
| 7 | +reference slots — which are read back for motion compensation on frame 2+, not | |
| 8 | +just handed to the caller. So the refusal cannot lift honestly until `Picture` | |
| 9 | +widens. | |
| 10 | + | |
| 11 | +## Checkpoint policy — this applies to the whole round | |
| 12 | +r3 got `cargo check` from 61 errors down, ran out of budget, and **reverted**; | |
| 13 | +so did r10 of the predecessor lane. That is twice the same loss. Do NOT revert a | |
| 14 | +falling error count. Commit a `wip(hbd):` checkpoint every time the count drops | |
| 15 | +meaningfully, with the number in the message. A non-compiling commit is fine on | |
| 16 | +this branch under that prefix; it is never merged in that state. The count | |
| 17 | +reaching zero is when you run the suite and make a real commit. | |
| 18 | + | |
| 19 | +Its attempt diff is saved at | |
| 20 | +`/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/hbd-r3-picture-widen-attempt.diff` | |
| 21 | +(128 lines, `pad_plane`/`crop_plane` genericized over `T: Copy + Default`, the | |
| 22 | +two `as u8` narrowing sites at `decode.rs` ~6823 and ~12594 dropped). `git apply` | |
| 23 | +it first rather than retyping. | |
| 24 | + | |
| 25 | +r3's measurement of what remains: the PRODUCTION blast radius is small (~10 | |
| 26 | +sites in `encode.rs`, all genericizable or trivial local narrow boxes); the bulk | |
| 27 | +of the errors are ~50 mechanical `as u8` → `as u16` touch-ups in encoder TEST | |
| 28 | +FIXTURES. Do the production sites first and checkpoint, then sweep the fixtures. | |
| 29 | + | |
| 30 | +## Then, in order | |
| 31 | +1. **Wire `decode::set_bit_depth`.** It exists at `decode.rs:97` and is never | |
| 32 | + called — `stream.rs` never passes `seq.color_config.bit_depth` into it, so the | |
| 33 | + `BIT_DEPTH` thread-local is dead code defaulting to 8. Everything downstream | |
| 34 | + silently assumes 8-bit until this is wired. Wire it, and make sure it is set | |
| 35 | + per frame before decode, not once per process. | |
| 36 | +2. **Narrow refusals for the two paths that are still 8-bit by construction**: | |
| 37 | + `film_grain.rs` (grain LUT is `[i32; 256]`) and `superres.rs` | |
| 38 | + (`upscale_row` takes `&[u8]` and clamps to 255). Each gets its own named | |
| 39 | + `bit_depth != 8` refusal — these are honest, scoped refusals, not the blanket | |
| 40 | + one. Declare both in `refusal_inventory.rs`. | |
| 41 | +3. **Lift the blanket refusal** in `stream.rs`, in the same commit as the gate | |
| 42 | + that proves 10-bit decodes. | |
| 43 | +4. **The 10-bit gate**: `ffmpeg_decode_sequence` hardcodes `-pix_fmt yuv420p`; | |
| 44 | + add a second helper emitting `yuv420p10le` with u16 LE parsing, leaving the | |
| 45 | + 8-bit helper untouched. aomenc needs `--bit-depth=10` and a 10-bit input. | |
| 46 | + Confirm from the sequence header that `bit_depth` really is 10 before | |
| 47 | + trusting a pixel match, and hard-assert it. | |
| 48 | +5. **His own films.** Both are `yuv420p10le`: ReelB (3840x1608, HDR10, | |
| 49 | + Main, no film grain flagged) and ReelC (1920x792, bt709, Main, no film grain). | |
| 50 | + Extract with `ffmpeg -i <file> -t 3 -c:v copy -f obu <out.obu>` into this | |
| 51 | + worktree's `fixtures/`, probe with | |
| 52 | + `cargo run -p ec-av1 --example decode_probe`, and record the next refusal | |
| 53 | + verbatim — that is the next lane's charter. Never open his media in a GUI app. | |
| 54 | + | |
| 55 | +8-bit output must stay bit-exact throughout: 264 tests, every real-aomenc gate | |
| 56 | +among them. | |
| 57 | + | |
| 58 | +## Budget discipline | |
| 59 | +75 turns, no reset on resume. At about turn 55, stop starting new work, commit | |
| 60 | +your checkpoint, and write the report with the current error count in it. | |
| 61 | + | |
| 62 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground | |
| 63 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg | |
| 64 | +generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | |
| 65 | +`--threads=1 --row-mt=0 --sb-size=64`. Sibling worktrees have live agents — | |
| 66 | +never build in or edit them. Never push, never merge into main; I handle merges. | |
| 67 | +End with `lanes/hbd-r4.report.md`, VERDICT on line 1. |
tools/ec-bench/src/main.rsmodified+5 -3
| @@ -362,9 +362,11 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | ||
| 362 | 362 | let pic = Av1Picture { |
| 363 | 363 | width: w as usize, |
| 364 | 364 | height: h as usize, |
| 365 | - y: y.to_vec(), | |
| 366 | - u: u.to_vec(), | |
| 367 | - v: v.to_vec(), | |
| 365 | + // ec-av1's Picture carries u16 samples since the high-bit-depth | |
| 366 | + // widen; this bench feeds 8-bit y4m, so widen each plane here. | |
| 367 | + y: y.iter().map(|&s| u16::from(s)).collect(), | |
| 368 | + u: u.iter().map(|&s| u16::from(s)).collect(), | |
| 369 | + v: v.iter().map(|&s| u16::from(s)).collect(), | |
| 368 | 370 | }; |
| 369 | 371 | let packet = enc.encode(&pic).expect("av1 encode"); |
| 370 | 372 | stream.extend_from_slice(&packet.data); |