forge
Explore
Log in

Don't you dare go Hollow

Inter frame per-tile decode loop, MV stack bounded per tile

Browse files at this commit

aaa4b1b330a3a7627d523a5829003df9a656ee5bAhmet Kaan GümüşParent: 1a6617f
  • feat
    • inter frame per-tile decode loop, MV stack bounded per tile
Show full message
feat(av1): inter frame per-tile decode loop, MV stack bounded per tile

decode_inter_frame_tile_with_cdfs now takes tiles: &[&[u8]] + &TileInfo and
grows the same per-tile loop decode_key_frame_tile_with_cdfs already has:
fresh SymbolDecoder + CDF copy per tile, PlaneBuf::set_tile_origin threaded
with real x1/y1 (right/bottom reach bound), only context_update_tile_id's
own adapted table kept as the frame's own output.

mvstack.rs: MiGrid gets tile_row0/col0/row1/col1 bounds (set_tile_bounds,
called once per tile) so scan_row/scan_col/scan_top_right's grid.get()
cannot see a cell outside the current tile -- bounds all four
find_mv_stack*/find_mv_stack_compound call sites through the one grid they
all read, without touching their own signatures.

Lifts the "an inter frame with more than one tile" refusal (verbatim,
removed from stream.rs and refusal_inventory.rs's pinned list). The
>2-columns and multi-tile-with-loop-filter refusals stay -- not
gate-proven safe to lift this round (deferred, see report).

cargo check clean; scoped tests green: tile/frame/mvstack/stream tile
tests (44), refusal_inventory (2), gate_coverage (2), including the
existing mi_units_outside_the_tile_contribute_nothing tile-bound test and
both real-aomenc two-tile-column gates.
crates/ec-av1/src/decode.rsmodified+78 -13
@@ -9486,8 +9486,14 @@ pub fn decode_inter_frame_tile(
9486 enable_dual_filter: bool,9486 enable_dual_filter: bool,
9487 reference_select: bool,9487 reference_select: bool,
9488 ) -> Result<Picture> {9488 ) -> Result<Picture> {
9489+ let single_tile = TileInfo {
9490+ mi_col_starts: vec![0, mi_cols],
9491+ mi_row_starts: vec![0, mi_rows],
9492+ ..TileInfo::default()
9493+ };
9489 decode_inter_frame_tile_with_cdfs(9494 decode_inter_frame_tile_with_cdfs(
9490- data,9495+ &[data],
9496+ &single_tile,
9491 mi_cols,9497 mi_cols,
9492 mi_rows,9498 mi_rows,
9493 base_q_idx,9499 base_q_idx,
@@ -9528,7 +9534,8 @@ pub fn decode_inter_frame_tile(
9528 /// `primary_ref_frame == PRIMARY_REF_NONE` too (an error-resilient stream),9534 /// `primary_ref_frame == PRIMARY_REF_NONE` too (an error-resilient stream),
9529 /// so `None` is a real case here, not only a convenience default.9535 /// so `None` is a real case here, not only a convenience default.
9530 pub(crate) fn decode_inter_frame_tile_with_cdfs(9536 pub(crate) fn decode_inter_frame_tile_with_cdfs(
9531- data: &[u8],9537+ tiles: &[&[u8]],
9538+ tile_info: &TileInfo,
9532 mi_cols: u32,9539 mi_cols: u32,
9533 mi_rows: u32,9540 mi_rows: u32,
9534 base_q_idx: u8,9541 base_q_idx: u8,
@@ -9733,7 +9740,37 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9733 let scan8 = default_scan(TX8);9740 let scan8 = default_scan(TX8);
9734 let scan4 = default_scan(TX4);9741 let scan4 = default_scan(TX4);
9735 9742
9736- let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx)));9743+ let base_cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx)));
9744+ let mut result_cdfs = base_cdfs.clone();
9745+ let mut neighbours = Neighbours::new(
9746+ cols as usize * 2,
9747+ rows as usize * 2,
9748+ mi_cols as usize,
9749+ mi_rows as usize,
9750+ );
9751+ let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize);
9752+
9753+ // lane-tiles r6: mirrors decode_key_frame_tile_with_cdfs's own per-tile
9754+ // loop (spec 5.11.2 decode_tile / 7.20 exit_symbol) -- each tile gets
9755+ // its own fresh SymbolDecoder over its own byte range and its own fresh
9756+ // copy of the frame's initial CDFs; only context_update_tile_id's own
9757+ // end-of-tile adapted table becomes the frame's own output.
9758+ for (tile_idx, &data) in tiles.iter().enumerate() {
9759+ let tile_num = tile_idx as u32;
9760+ let (trow, tcol) = (tile_num / tile_info.cols, tile_num % tile_info.cols);
9761+ let mi_row0 = tile_info.mi_row_starts[trow as usize];
9762+ let mi_row1 = tile_info.mi_row_starts[trow as usize + 1];
9763+ let mi_col0 = tile_info.mi_col_starts[tcol as usize];
9764+ let mi_col1 = tile_info.mi_col_starts[tcol as usize + 1];
9765+ let (sb_r0, sb_r1) = (
9766+ (mi_row0 / SB_MI).min(sb_rows),
9767+ mi_row1.div_ceil(SB_MI).min(sb_rows),
9768+ );
9769+ let (sb_c0, sb_c1) = (
9770+ (mi_col0 / SB_MI).min(sb_cols),
9771+ mi_col1.div_ceil(SB_MI).min(sb_cols),
9772+ );
9773+ let mut cdfs = base_cdfs.clone();
9737 let mut dec = SymbolDecoder::new(data);9774 let mut dec = SymbolDecoder::new(data);
9738 // lane-comppin r9: tile-entry range, the earliest point comparable9775 // lane-comppin r9: tile-entry range, the earliest point comparable
9739 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the9776 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the
@@ -9745,17 +9782,40 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9745 dec.debug_state().09782 dec.debug_state().0
9746 );9783 );
9747 }9784 }
9748- let mut neighbours = Neighbours::new(9785+ neighbours.start_tile(mi_row0 as usize, mi_col0 as usize, mi_col1 as usize);
9749- cols as usize * 2,9786+ y.set_tile_origin(
9750- rows as usize * 2,9787+ mi_col0 as usize * 4,
9751- mi_cols as usize,9788+ mi_row0 as usize * 4,
9752- mi_rows as usize,9789+ (mi_col1 as usize * 4).min(y.width),
9790+ (mi_row1 as usize * 4).min(y.height),
9791+ );
9792+ u.set_tile_origin(
9793+ mi_col0 as usize * 2,
9794+ mi_row0 as usize * 2,
9795+ (mi_col1 as usize * 2).min(u.width),
9796+ (mi_row1 as usize * 2).min(u.height),
9797+ );
9798+ v.set_tile_origin(
9799+ mi_col0 as usize * 2,
9800+ mi_row0 as usize * 2,
9801+ (mi_col1 as usize * 2).min(v.width),
9802+ (mi_row1 as usize * 2).min(v.height),
9803+ );
9804+ // lane-tiles r6: an MV candidate scan (mvstack.rs's grid.get) must
9805+ // not reach across a tile boundary any more than intra prediction's
9806+ // PlaneBuf reach does -- bounding the shared grid's own read window
9807+ // per tile is equivalent to threading tile bounds through every
9808+ // find_mv_stack* call site (all four read through this one grid).
9809+ grid.set_tile_bounds(
9810+ mi_row0 as usize,
9811+ mi_col0 as usize,
9812+ mi_row1 as usize,
9813+ mi_col1 as usize,
9753 );9814 );
9754- let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize);
9755 9815
9756- for sb_r in 0..sb_rows {9816+ for sb_r in sb_r0..sb_r1 {
9757 neighbours.start_row();9817 neighbours.start_row();
9758- for sb_c in 0..sb_cols {9818+ for sb_c in sb_c0..sb_c1 {
9759 CDEF_TRANSMITTED.with(|c| c.set(false));9819 CDEF_TRANSMITTED.with(|c| c.set(false));
9760 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);9820 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);
9761 let sb_ctx = neighbours.partition_ctx(sb_at, SB);9821 let sb_ctx = neighbours.partition_ctx(sb_at, SB);
@@ -10945,6 +11005,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10945 }11005 }
10946 }11006 }
10947 11007
11008+ if tile_num == tile_info.context_update_tile_id {
11009+ result_cdfs = cdfs;
11010+ }
11011+ }
11012+
10948 // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's11013 // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's
10949 // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against11014 // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against
10950 // that isolate whether a decode-order frame's mismatch already exists11015 // that isolate whether a decode-order frame's mismatch already exists
@@ -10982,7 +11047,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10982 u: u.data,11047 u: u.data,
10983 v: v.data,11048 v: v.data,
10984 },11049 },
10985- cdfs,11050+ result_cdfs,
10986 motion_field,11051 motion_field,
10987 ));11052 ));
10988 }11053 }
@@ -11001,7 +11066,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11001 u: crop(&u, fw / 2, fh / 2),11066 u: crop(&u, fw / 2, fh / 2),
11002 v: crop(&v, fw / 2, fh / 2),11067 v: crop(&v, fw / 2, fh / 2),
11003 },11068 },
11004- cdfs,11069+ result_cdfs,
11005 motion_field,11070 motion_field,
11006 ))11071 ))
11007 }11072 }
crates/ec-av1/src/mvstack.rsmodified+33 -3
@@ -177,6 +177,15 @@ pub struct MiGrid {
177 cols: usize,177 cols: usize,
178 rows: usize,178 rows: usize,
179 cells: Vec<Option<MiInfo>>,179 cells: Vec<Option<MiInfo>>,
180+ /// lane-tiles r6: the current tile's own mi-unit bounds (spec: an MV
181+ /// candidate scan never reaches across a tile boundary, mirroring
182+ /// `PlaneBuf`'s `tile_x0`/`tile_x1` reach clamp for intra prediction).
183+ /// Defaults to the whole grid (the single-tile case, unchanged old
184+ /// behaviour) and is narrowed per tile via [`Self::set_tile_bounds`].
185+ tile_row0: usize,
186+ tile_col0: usize,
187+ tile_row1: usize,
188+ tile_col1: usize,
180 }189 }
181 190
182 impl MiGrid {191 impl MiGrid {
@@ -186,9 +195,24 @@ impl MiGrid {
186 cols,195 cols,
187 rows,196 rows,
188 cells: vec![None; cols * rows],197 cells: vec![None; cols * rows],
198+ tile_row0: 0,
199+ tile_col0: 0,
200+ tile_row1: rows,
201+ tile_col1: cols,
189 }202 }
190 }203 }
191 204
205+ /// Narrows [`Self::get`]'s own read window to one tile's mi-unit span
206+ /// (`row1`/`col1` exclusive) -- called once per tile, before that
207+ /// tile's own superblock walk, the same way `Neighbours::start_tile`
208+ /// and `PlaneBuf::set_tile_origin` are.
209+ pub fn set_tile_bounds(&mut self, row0: usize, col0: usize, row1: usize, col1: usize) {
210+ self.tile_row0 = row0;
211+ self.tile_col0 = col0;
212+ self.tile_row1 = row1;
213+ self.tile_col1 = col1;
214+ }
215+
192 /// Records the unit at `(row, col)`. Out-of-range coordinates are a216 /// Records the unit at `(row, col)`. Out-of-range coordinates are a
193 /// no-op — the caller only ever addresses units inside the grid it built.217 /// no-op — the caller only ever addresses units inside the grid it built.
194 pub fn set(&mut self, row: usize, col: usize, info: MiInfo) {218 pub fn set(&mut self, row: usize, col: usize, info: MiInfo) {
@@ -197,10 +221,16 @@ impl MiGrid {
197 }221 }
198 }222 }
199 223
200- /// The unit at `(row, col)`, or `None` when it is outside the grid (the224+ /// The unit at `(row, col)`, or `None` when it is outside the grid, hasn't
201- /// tile) or hasn't been coded.225+ /// been coded, or sits outside the current tile's own bounds ([`Self::set_tile_bounds`]).
202 pub fn get(&self, row: usize, col: usize) -> Option<&MiInfo> {226 pub fn get(&self, row: usize, col: usize) -> Option<&MiInfo> {
203- if row < self.rows && col < self.cols {227+ if row < self.rows
228+ && col < self.cols
229+ && row >= self.tile_row0
230+ && row < self.tile_row1
231+ && col >= self.tile_col0
232+ && col < self.tile_col1
233+ {
204 self.cells[row * self.cols + col].as_ref()234 self.cells[row * self.cols + col].as_ref()
205 } else {235 } else {
206 None236 None
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
@@ -51,7 +51,6 @@ const REFUSALS: &[&str] = &[
51 "a frame with more than one tile row (only tile columns are proven pixel-exact so far)",51 "a frame with more than one tile row (only tile columns are proven pixel-exact so far)",
52 "a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented)",52 "a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented)",
53 "a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach)",53 "a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach)",
54- "an inter frame with more than one tile (the inter tile-decode path has no per-tile loop, only key frames do)",
55 "a frame with no mode-info grid",54 "a frame with no mode-info grid",
56 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",55 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",
57 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",56 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
crates/ec-av1/src/stream.rsmodified+8 -7
@@ -308,12 +308,12 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
308 // is capped at 2. Tile rows are untested this round, so `rows`308 // is capped at 2. Tile rows are untested this round, so `rows`
309 // stays capped at 1.309 // stays capped at 1.
310 let loop_filter_on = header.loop_filter.level.iter().any(|&l| l != 0);310 let loop_filter_on = header.loop_filter.level.iter().any(|&l| l != 0);
311- if header.frame_type != FrameType::Key && header.tile_info.cols > 1 {311+ // lane-tiles r6: decode_inter_frame_tile_with_cdfs now takes
312- return Err(Error::unsupported(312+ // `tiles: &[&[u8]]` and grows the same per-tile loop
313- "AV1 decode_stream",313+ // decode_key_frame_tile_with_cdfs has (mvstack.rs's MiGrid bounded
314- "an inter frame with more than one tile (the inter tile-decode path has no per-tile loop, only key frames do)",314+ // per tile too, see MiGrid::set_tile_bounds), so an inter frame with
315- ));315+ // >1 tile column is no longer refused by name -- the >2-columns and
316- }316+ // loop-filter refusals below stay (unproven this round).
317 if header.tile_info.rows > 1 {317 if header.tile_info.rows > 1 {
318 return Err(Error::unsupported(318 return Err(Error::unsupported(
319 "AV1 decode_stream",319 "AV1 decode_stream",
@@ -472,7 +472,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
472 )472 )
473 });473 });
474 decode_inter_frame_tile_with_cdfs(474 decode_inter_frame_tile_with_cdfs(
475- tile_bytes,475+ &tile_bufs,
476+ &header.tile_info,
476 header.mi_cols,477 header.mi_cols,
477 header.mi_rows,478 header.mi_rows,
478 header.quantization.base_q_idx,479 header.quantization.base_q_idx,