forge
Explore
Log in

Don't you dare go Hollow

S6: filter_frame takes &mut Planes and the frame extent (5 args, was 13); loop_filter passes the scratch it already holds; the planes carry ss_x/ss_y/bd equal to the header values

Browse files at this commit

f5f883a7b1e47aee7c1407347939facab47ade79Ahmet Kaan GümüşParent: 58d72d3
crates/ec-vp9/src/decode.rsmodified+11 -26
@@ -71,22 +71,22 @@ pub struct Picture {
71 pub subsampling_y: u8,71 pub subsampling_y: u8,
72 }72 }
73 73
74-struct Planes {74+pub(crate) struct Planes {
75- y: Vec<Sample>,75+ pub(crate) y: Vec<Sample>,
76- u: Vec<Sample>,76+ pub(crate) u: Vec<Sample>,
77- v: Vec<Sample>,77+ pub(crate) v: Vec<Sample>,
78- ys: usize,78+ pub(crate) ys: usize,
79- uvs: usize,79+ pub(crate) uvs: usize,
80 aw: usize,80 aw: usize,
81 ah: usize,81 ah: usize,
82 /// Bits per sample this frame was decoded at.82 /// Bits per sample this frame was decoded at.
83- bd: u8,83+ pub(crate) bd: u8,
84 /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for84 /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for
85 /// 4:2:0/4:2:2.85 /// 4:2:0/4:2:2.
86- ss_x: usize,86+ pub(crate) ss_x: usize,
87 /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 187 /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 1
88 /// for 4:2:0/4:4:0.88 /// for 4:2:0/4:4:0.
89- ss_y: usize,89+ pub(crate) ss_y: usize,
90 }90 }
91 91
92 /// VP9 level 6.2 caps a picture at 8192x4352 luma samples. Larger frame headers are refused92 /// VP9 level 6.2 caps a picture at 8192x4352 luma samples. Larger frame headers are refused
@@ -116,7 +116,7 @@ impl Planes {
116 /// edge decode at FULL size), so the fill only backs the never-written116 /// edge decode at FULL size), so the fill only backs the never-written
117 /// padding past the MI extent. Chroma planes are `aw >> ss_x` by117 /// padding past the MI extent. Chroma planes are `aw >> ss_x` by
118 /// `ah >> ss_y`; since `aw`/`ah` are 64-multiples the shift is exact.118 /// `ah >> ss_y`; since `aw`/`ah` are 64-multiples the shift is exact.
119- fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes {119+ pub(crate) fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes {
120 let fill = 1u16 << (bd - 1);120 let fill = 1u16 << (bd - 1);
121 let (cw, ch) = (aw >> ss_x, ah >> ss_y);121 let (cw, ch) = (aw >> ss_x, ah >> ss_y);
122 Planes {122 Planes {
@@ -600,23 +600,8 @@ impl Decoder {
600 return;600 return;
601 }601 }
602 let p = self.planes.as_mut().expect("frame scratch");602 let p = self.planes.as_mut().expect("frame scratch");
603- let (ss_x, ss_y) = (hdr.subsampling_x as usize, hdr.subsampling_y as usize);
604 let (vw, vh) = (hdr.mi_cols() as usize * 8, hdr.mi_rows() as usize * 8);603 let (vw, vh) = (hdr.mi_cols() as usize * 8, hdr.mi_rows() as usize * 8);
605- grids.filter_frame(604+ grids.filter_frame(p, vw, vh, hdr.loop_filter.sharpness);
606- &mut p.y,
607- p.ys,
608- &mut p.u,
609- &mut p.v,
610- p.uvs,
611- vw,
612- vh,
613- vw >> ss_x,
614- vh >> ss_y,
615- ss_x,
616- ss_y,
617- hdr.loop_filter.sharpness,
618- hdr.bit_depth,
619- );
620 }605 }
621 606
622 /// Crop the frame scratch to a [`Picture`].607 /// Crop the frame scratch to a [`Picture`].
crates/ec-vp9/src/loopfilter.rsmodified+11 -22
@@ -75,6 +75,7 @@ const LUMA_ABOVE_TXF: [u64; 4] = [u64::MAX, u64::MAX, 0x00ff00ff00ff00ff, 0x0000
75 const LUMA_LEFT_BORDER: u64 = 0x1111111111111111;75 const LUMA_LEFT_BORDER: u64 = 0x1111111111111111;
76 const LUMA_ABOVE_BORDER: u64 = 0x000000ff000000ff;76 const LUMA_ABOVE_BORDER: u64 = 0x000000ff000000ff;
77 77
78+use crate::decode::Planes;
78 use crate::Sample;79 use crate::Sample;
79 80
80 /// `signed_char_clamp_high` (`vpx_dsp/loopfilter.c:23`): clamp to81 /// `signed_char_clamp_high` (`vpx_dsp/loopfilter.c:23`): clamp to
@@ -1192,23 +1193,10 @@ impl LfGrids {
1192 /// `vp9_loop_filter_frame` (vp9_loopfilter.c:1430): luma always takes the1193 /// `vp9_loop_filter_frame` (vp9_loopfilter.c:1430): luma always takes the
1193 /// ss00 path; chroma takes ss00 for 4:4:4, ss11 for 4:2:0, and the1194 /// ss00 path; chroma takes ss00 for 4:4:4, ss11 for 4:2:0, and the
1194 /// non420 slow path otherwise (4:2:2 / 4:4:0).1195 /// non420 slow path otherwise (4:2:2 / 4:4:0).
1195- #[allow(clippy::too_many_arguments)]1196+ pub(crate) fn filter_frame(&self, p: &mut Planes, vw: usize, vh: usize, sharpness: u8) {
1196- pub(crate) fn filter_frame(1197+ let (ss_x, ss_y, bd) = (p.ss_x, p.ss_y, p.bd);
1197- &self,1198+ let (uv_w, uv_h) = (vw >> ss_x, vh >> ss_y);
1198- y: &mut [Sample],1199+ let (stride, uv_stride) = (p.ys, p.uvs);
1199- stride: usize,
1200- u: &mut [Sample],
1201- v: &mut [Sample],
1202- uv_stride: usize,
1203- y_w: usize,
1204- y_h: usize,
1205- uv_w: usize,
1206- uv_h: usize,
1207- ss_x: usize,
1208- ss_y: usize,
1209- sharpness: u8,
1210- bd: u8,
1211- ) {
1212 // The three planes are filtered from the same read-only grids and touch1200 // The three planes are filtered from the same read-only grids and touch
1213 // disjoint buffers, so they run concurrently: luma on one thread, both1201 // disjoint buffers, so they run concurrently: luma on one thread, both
1214 // chroma planes on another. Each plane's edge order is unchanged, so the1202 // chroma planes on another. Each plane's edge order is unchanged, so the
@@ -1226,8 +1214,8 @@ impl LfGrids {
1226 }1214 }
1227 };1215 };
1228 std::thread::scope(|scope| {1216 std::thread::scope(|scope| {
1229- scope.spawn(|| chroma(u, v));1217+ scope.spawn(|| chroma(&mut p.u, &mut p.v));
1230- self.filter_ss00_plane(y, stride, y_w, y_h, sharpness, bd);1218+ self.filter_ss00_plane(&mut p.y, stride, vw, vh, sharpness, bd);
1231 });1219 });
1232 }1220 }
1233 }1221 }
@@ -1253,9 +1241,10 @@ mod tests {
1253 }1241 }
1254 1242
1255 fn run(g: &LfGrids, y: &mut [Sample]) {1243 fn run(g: &LfGrids, y: &mut [Sample]) {
1256- let mut u = vec![128u16; 32 * 32];1244+ let mut p = Planes::new(64, 64, 8, 1, 1);
1257- let mut v = vec![128u16; 32 * 32];1245+ p.y.copy_from_slice(y);
1258- g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 32, 1, 1, 0, 8);1246+ g.filter_frame(&mut p, 64, 64, 0);
1247+ y.copy_from_slice(&p.y);
1259 }1248 }
1260 1249
1261 /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row.1250 /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row.