forge
Explore
Log in

Don't you dare go Hollow

S6: TileWalk context struct for decode_partition and decode_block (12 and 14 args, now 4 and 6); same calls in the same order

Browse files at this commit

96bcfed14237ea1b512776b793ee9c2422619d16Ahmet Kaan GümüşParent: f5f883a
crates/ec-vp9/src/decode.rsmodified+43 -166
@@ -981,157 +981,52 @@ impl Decoder {
981 }981 }
982 982
983 /// `decode_partition` (decodeframe.c:1173).983 /// `decode_partition` (decodeframe.c:1173).
984- #[allow(clippy::too_many_arguments)]984+ fn decode_partition(&mut self, w: &mut TileWalk<'_, '_>, row: usize, col: usize, n4: usize) -> Result<()> {
985- fn decode_partition(985+ if row >= w.mi.mi_rows || col >= w.mi.mi_cols {
986- &mut self,
987- r: &mut crate::bool::BoolDecoder,
988- mi: &mut MiState,
989- ectx: &mut [PlaneContexts; 3],
990- grids: &mut LfGrids,
991- level_of_seg: &[[u8; 2]; 8],
992- hdr: &FrameHeader,
993- row: usize,
994- col: usize,
995- n4: usize,
996- tile_col_start: usize,
997- tx_mode: u8,
998- counts: &mut crate::adapt::Counts,
999- ) -> Result<()> {
1000- if row >= mi.mi_rows || col >= mi.mi_cols {
1001 return Ok(());986 return Ok(());
1002 }987 }
1003 let n8 = n4 - 1;988 let n8 = n4 - 1;
1004 let hbs = (1usize << n8) >> 1;989 let hbs = (1usize << n8) >> 1;
1005- let has_rows = row + hbs < mi.mi_rows;990+ let has_rows = row + hbs < w.mi.mi_rows;
1006- let has_cols = col + hbs < mi.mi_cols;991+ let has_cols = col + hbs < w.mi.mi_cols;
1007 // libvpx reads the partition symbol at EVERY level INCLUDING 8x8992 // libvpx reads the partition symbol at EVERY level INCLUDING 8x8
1008 // (decodeframe.c:1188 runs before the `!hbs` branch): the 8x8993 // (decodeframe.c:1188 runs before the `!hbs` branch): the 8x8
1009 // symbol picks 8x8 / 8x4 / 4x8 / 4x4-split — the sub-8x8 shapes.994 // symbol picks 8x8 / 8x4 / 4x8 / 4x4-split — the sub-8x8 shapes.
1010 // Only the 4x4 level has no symbol, and SPLIT recursion never995 // Only the 4x4 level has no symbol, and SPLIT recursion never
1011 // reaches it (it stops at n4 == 1).996 // reaches it (it stops at n4 == 1).
1012 let partition = {997 let partition = {
1013- let ctx = mi.partition_ctx(row, col, n8 as u32);998+ let ctx = w.mi.partition_ctx(row, col, n8 as u32);
1014 let probs = &self.ctx.partition[ctx];999 let probs = &self.ctx.partition[ctx];
1015 let p = if has_rows && has_cols {1000 let p = if has_rows && has_cols {
1016- r.read_tree(&PARTITION_TREE, probs)1001+ w.r.read_tree(&PARTITION_TREE, probs)
1017 } else if !has_rows && has_cols {1002 } else if !has_rows && has_cols {
1018- if r.read_bool(probs[1]) { 3 } else { 1 }1003+ if w.r.read_bool(probs[1]) { 3 } else { 1 }
1019 } else if has_rows && !has_cols {1004 } else if has_rows && !has_cols {
1020- if r.read_bool(probs[2]) { 3 } else { 2 }1005+ if w.r.read_bool(probs[2]) { 3 } else { 2 }
1021 } else {1006 } else {
1022 31007 3
1023 };1008 };
1024 // libvpx counts the implied SPLIT too (`++counts->partition[ctx][p]`).1009 // libvpx counts the implied SPLIT too (`++counts->partition[ctx][p]`).
1025- counts.partition[ctx][p as usize] += 1;1010+ w.counts.partition[ctx][p as usize] += 1;
1026 p1011 p
1027 };1012 };
1028 let bsize = bsize_of_n4(n4);1013 let bsize = bsize_of_n4(n4);
1029 let subsize = SUBSIZE_LOOKUP[partition as usize * 13 + bsize] as usize;1014 let subsize = SUBSIZE_LOOKUP[partition as usize * 13 + bsize] as usize;
1030 if hbs == 0 {1015 if hbs == 0 {
1031- self.decode_block(1016+ self.decode_block(w, row, col, subsize, 1, 1)?;
1032- r,
1033- mi,
1034- ectx,
1035- grids,
1036- level_of_seg,
1037- hdr,
1038- row,
1039- col,
1040- subsize,
1041- 1,
1042- 1,
1043- tile_col_start,
1044- tx_mode,
1045- counts,
1046- )?;
1047 } else {1017 } else {
1048 match partition {1018 match partition {
1049- 0 => self.decode_block(1019+ 0 => self.decode_block(w, row, col, subsize, n4, n4)?,
1050- r,
1051- mi,
1052- ectx,
1053- grids,
1054- level_of_seg,
1055- hdr,
1056- row,
1057- col,
1058- subsize,
1059- n4,
1060- n4,
1061- tile_col_start,
1062- tx_mode,
1063- counts,
1064- )?,
1065 1 => {1020 1 => {
1066- self.decode_block(1021+ self.decode_block(w, row, col, subsize, n4, n8)?;
1067- r,
1068- mi,
1069- ectx,
1070- grids,
1071- level_of_seg,
1072- hdr,
1073- row,
1074- col,
1075- subsize,
1076- n4,
1077- n8,
1078- tile_col_start,
1079- tx_mode,
1080- counts,
1081- )?;
1082 if has_rows {1022 if has_rows {
1083- self.decode_block(1023+ self.decode_block(w, row + hbs, col, subsize, n4, n8)?;
1084- r,
1085- mi,
1086- ectx,
1087- grids,
1088- level_of_seg,
1089- hdr,
1090- row + hbs,
1091- col,
1092- subsize,
1093- n4,
1094- n8,
1095- tile_col_start,
1096- tx_mode,
1097- counts,
1098- )?;
1099 }1024 }
1100 }1025 }
1101 2 => {1026 2 => {
1102- self.decode_block(1027+ self.decode_block(w, row, col, subsize, n8, n4)?;
1103- r,
1104- mi,
1105- ectx,
1106- grids,
1107- level_of_seg,
1108- hdr,
1109- row,
1110- col,
1111- subsize,
1112- n8,
1113- n4,
1114- tile_col_start,
1115- tx_mode,
1116- counts,
1117- )?;
1118 if has_cols {1028 if has_cols {
1119- self.decode_block(1029+ self.decode_block(w, row, col + hbs, subsize, n8, n4)?;
1120- r,
1121- mi,
1122- ectx,
1123- grids,
1124- level_of_seg,
1125- hdr,
1126- row,
1127- col + hbs,
1128- subsize,
1129- n8,
1130- n4,
1131- tile_col_start,
1132- tx_mode,
1133- counts,
1134- )?;
1135 }1030 }
1136 }1031 }
1137 _ => {1032 _ => {
@@ -1141,49 +1036,21 @@ impl Decoder {
1141 (row + hbs, col),1036 (row + hbs, col),
1142 (row + hbs, col + hbs),1037 (row + hbs, col + hbs),
1143 ] {1038 ] {
1144- self.decode_partition(1039+ self.decode_partition(w, rr, cc, n8)?;
1145- r,
1146- mi,
1147- ectx,
1148- grids,
1149- level_of_seg,
1150- hdr,
1151- rr,
1152- cc,
1153- n8,
1154- tile_col_start,
1155- tx_mode,
1156- counts,
1157- )?;
1158 }1040 }
1159 }1041 }
1160 }1042 }
1161 }1043 }
1162 if bsize >= 3 && (bsize == 3 || partition != 3) {1044 if bsize >= 3 && (bsize == 3 || partition != 3) {
1163- mi.update_partition_ctx(row, col, subsize, 1 << n8);1045+ w.mi.update_partition_ctx(row, col, subsize, 1 << n8);
1164 }1046 }
1165 Ok(())1047 Ok(())
1166 }1048 }
1167 1049
1168 /// `decode_block` intra path (decodeframe.c:913).1050 /// `decode_block` intra path (decodeframe.c:913).
1169- #[allow(clippy::too_many_arguments)]1051+ fn decode_block(&mut self, w: &mut TileWalk<'_, '_>, row: usize, col: usize, sb_type: usize, bwl: usize, bhl: usize) -> Result<()> {
1170- fn decode_block(1052+ let TileWalk { r, mi, ectx, grids, level_of_seg, hdr, tile_col_start, tx_mode, counts } = w;
1171- &mut self,1053+ let (level_of_seg, hdr, tile_col_start, tx_mode) = (&*level_of_seg, *hdr, *tile_col_start, *tx_mode);
1172- r: &mut crate::bool::BoolDecoder,
1173- mi: &mut MiState,
1174- ectx: &mut [PlaneContexts; 3],
1175- grids: &mut LfGrids,
1176- level_of_seg: &[[u8; 2]; 8],
1177- hdr: &FrameHeader,
1178- row: usize,
1179- col: usize,
1180- sb_type: usize,
1181- bwl: usize,
1182- bhl: usize,
1183- tile_col_start: usize,
1184- tx_mode: u8,
1185- counts: &mut crate::adapt::Counts,
1186- ) -> Result<()> {
1187 let bw = 1 << (bwl - 1);1054 let bw = 1 << (bwl - 1);
1188 let bh = 1 << (bhl - 1);1055 let bh = 1 << (bhl - 1);
1189 let x_mis = bw.min(mi.mi_cols - col);1056 let x_mis = bw.min(mi.mi_cols - col);
@@ -1918,6 +1785,18 @@ fn interp_filter_of(hdr: &FrameHeader) -> u8 {
1918 // the frame; the columns are then copied into the frame in column order. The1785 // the frame; the columns are then copied into the frame in column order. The
1919 // counts are sums, so the result does not depend on the worker count.1786 // counts are sums, so the result does not depend on the worker count.
1920 1787
1788+struct TileWalk<'a, 'd> {
1789+ r: &'a mut crate::bool::BoolDecoder<'d>,
1790+ mi: &'a mut MiState,
1791+ ectx: &'a mut [PlaneContexts; 3],
1792+ grids: &'a mut LfGrids,
1793+ level_of_seg: &'a [[u8; 2]; 8],
1794+ hdr: &'a FrameHeader,
1795+ tile_col_start: usize,
1796+ tx_mode: u8,
1797+ counts: &'a mut crate::adapt::Counts,
1798+}
1799+
1921 /// Everything a tile walk reads that is fixed for the whole frame.1800 /// Everything a tile walk reads that is fixed for the whole frame.
1922 struct TileJob<'a> {1801 struct TileJob<'a> {
1923 hdr: &'a FrameHeader,1802 hdr: &'a FrameHeader,
@@ -2072,20 +1951,18 @@ impl Decoder {
2072 ectx.iter_mut().for_each(|p| p.left = [0; 32]);1951 ectx.iter_mut().for_each(|p| p.left = [0; 32]);
2073 mi.left_seg = [0; 32];1952 mi.left_seg = [0; 32];
2074 for sb_col in (col_lo..col_hi).step_by(SB_MI) {1953 for sb_col in (col_lo..col_hi).step_by(SB_MI) {
2075- self.decode_partition(1954+ let mut w = TileWalk {
2076- &mut r,1955+ r: &mut r,
2077- &mut mi,1956+ mi: &mut mi,
2078- &mut ectx,1957+ ectx: &mut ectx,
2079- grids,1958+ grids: &mut *grids,
2080- &job.level_of_seg,1959+ level_of_seg: &job.level_of_seg,
2081 hdr,1960 hdr,
2082- sb_row,1961+ tile_col_start: col_lo,
2083- sb_col,1962+ tx_mode: job.tx_mode,
2084- 4,1963+ counts: &mut *counts,
2085- col_lo,1964+ };
2086- job.tx_mode,1965+ self.decode_partition(&mut w, sb_row, sb_col, 4)?;
2087- counts,
2088- )?;
2089 }1966 }
2090 }1967 }
2091 ensure(1968 ensure(