forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-publish' (495bee05): the four skip/pu-edge mode-info maps packed into one cell (one row fill instead of four), neighbour gathering in one pass for all three planes; byte-exact, -0.6% instructions

Browse files at this commit

545e09f1fc135498f31b9afce94660e0a2dfa8eaAhmet Kaan GümüşParent: 8393c45dcb88a2
crates/ec-av1/src/decode.rsmodified+75 -55
@@ -6314,6 +6314,19 @@ const SKIP_CONTEXTS: [[usize; 5]; 5] = [
63146314 [3, 5, 5, 5, 6],
63156315 ];
63166316
6317+/// The `skip` flag, its written-instrument bit, and the covering coded
6318+/// block's origin and dims, packed into ONE 8-byte cell (lane-publish): the
6319+/// four maps are written together by `Neighbours::fill_skip_grid_rect` and by
6320+/// nothing else, so a block's row is one fill instead of four, and the
6321+/// deblocker's `pu_edge` reads origin and dims off one cache line.
6322+#[derive(Clone, Copy)]
6323+struct BlkCell {
6324+ skip: bool,
6325+ written: bool,
6326+ org: [u16; 2],
6327+ dim: [u8; 2],
6328+}
6329+
63176330 /// The neighbour state a block's contexts are read from — a duplicate of
63186331 /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's
63196332 /// territory this round), kept at the same two granularities the real writer
@@ -6449,27 +6462,25 @@ struct Neighbours {
64496462 /// grain [`Self::record_mi`] already writes at), read back at 8x8
64506463 /// granularity by [`apply_cdef`] since `skip` is constant across every
64516464 /// mi cell one coded block covers.
6452- skip_grid: Vec<bool>,
6465+ /// The four per-mi maps [`Neighbours::blk_grid`] packs, in one cell.
64536466 /// lane-cdefstrip r1 instrument: whether any coded block actually WROTE
6454- /// [`Self::skip_grid`] at this mi cell during this frame. A fresh
6467+ /// the `skip` bit at this mi cell during this frame. A fresh
64556468 /// `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so a decode
64566469 /// arm that forgets [`Self::fill_skip_grid_rect`] silently makes
64576470 /// [`apply_cdef`] filter an 8x8 unit libaom's `is_8x8_block_skip`
64586471 /// (`cdef.c:29-38`) excludes -- exactly the lane-cdef defect, and
64596472 /// unobservable from the pixels alone. Counted by
64606473 /// [`cdef_unwritten_skip_units`].
6461- skip_written: Vec<bool>,
64626474 /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block
64636475 /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`,
64646476 /// which re-enables the loop filter at a prediction boundary between two
64656477 /// skipped inter blocks (lane-mergefix r4). Written by
64666478 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.
6467- blk_org_grid: Vec<[u16; 2]>,
64686479 /// Per-4x4-mi `(width, height)` in mi units of the coded block covering
64696480 /// that cell -- the other half of `pu_edge`: libaom tests the edge
64706481 /// coordinate against the block's size in the FILTERED plane's own
64716482 /// pixels, which for chroma is `max(luma_dim / 2, 4)` (lane-t900 r30b).
6472- blk_dim_grid: Vec<[u8; 2]>,
6483+ blk_grid: Vec<BlkCell>,
64736484 skip_grid_cols_mi: usize,
64746485 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder
64756486 /// never splits a coded block's transform below its own size (round 2:
@@ -6591,10 +6602,10 @@ impl Neighbours {
65916602 left_filter: vec![[3u8; 2]; rows * (SUB / MI)],
65926603 mi_cols,
65936604 mi_rows,
6594- skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
6595- skip_written: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
6596- blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)],
6597- blk_dim_grid: vec![[1u8; 2]; cols * (SUB / MI) * rows * (SUB / MI)],
6605+ blk_grid: vec![
6606+ BlkCell { skip: false, written: false, org: [0; 2], dim: [1; 2] };
6607+ cols * (SUB / MI) * rows * (SUB / MI)
6608+ ],
65986609 skip_grid_cols_mi: cols * (SUB / MI),
65996610 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
66006611 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -7002,10 +7013,17 @@ impl Neighbours {
70027013 }
70037014 for rr in 0..h_mi {
70047015 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
7005- fill_span(&mut self.skip_grid, start, w_mi, skip);
7006- fill_span(&mut self.skip_written, start, w_mi, true);
7007- fill_span(&mut self.blk_org_grid, start, w_mi, [mi_r as u16, mi_c as u16]);
7008- fill_span(&mut self.blk_dim_grid, start, w_mi, [w_mi as u8, h_mi as u8]);
7016+ fill_span(
7017+ &mut self.blk_grid,
7018+ start,
7019+ w_mi,
7020+ BlkCell {
7021+ skip,
7022+ written: true,
7023+ org: [mi_r as u16, mi_c as u16],
7024+ dim: [w_mi as u8, h_mi as u8],
7025+ },
7026+ );
70097027 }
70107028 }
70117029
@@ -7019,10 +7037,9 @@ impl Neighbours {
70197037 /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a
70207038 /// filtered edge's two sides are each exactly one coded block wide.
70217039 fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool {
7022- self.skip_grid
7040+ self.blk_grid
70237041 .get(mi_r * self.skip_grid_cols_mi + mi_c)
7024- .copied()
7025- .unwrap_or(false)
7042+ .is_some_and(|c| c.skip)
70267043 }
70277044
70287045 /// The `skip_txfm` context of a block whose top-left mi cell is
@@ -7038,10 +7055,9 @@ impl Neighbours {
70387055 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {
70397056 (0..2).all(|rr| {
70407057 (0..2).all(|cc| {
7041- self.skip_grid
7058+ self.blk_grid
70427059 .get((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))
7043- .copied()
7044- .unwrap_or(false)
7060+ .is_some_and(|c| c.skip)
70457061 })
70467062 })
70477063 }
@@ -7293,19 +7309,21 @@ impl Neighbours {
72937309 /// units, for the same reason [`Self::record_mi`] does.
72947310 fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] {
72957311 let side_mi = side / MI;
7296- std::array::from_fn(|plane| {
7297- let mut above_coded = false;
7298- let mut left_coded = false;
7299- let mut vote = 0;
7300- for cell in 0..side_mi {
7301- let above = &self.above[mi_c + cell][plane];
7302- let left = &self.left[mi_r + cell][plane];
7303- above_coded |= above.level != 0;
7304- left_coded |= left.level != 0;
7305- vote += dc_vote(above.dc) + dc_vote(left.dc);
7306- }
7307- (above_coded, left_coded, vote)
7308- })
7312+ // One pass over the cells accumulating all three planes, not one pass
7313+ // per plane: the three planes of a cell live in the same
7314+ // `[Neighbour; 3]` (6 bytes), so the per-plane form loaded the same
7315+ // cache lines three times (lane-publish).
7316+ let mut out = [(false, false, 0i32); 3];
7317+ for cell in 0..side_mi {
7318+ let above = &self.above[mi_c + cell];
7319+ let left = &self.left[mi_r + cell];
7320+ for (plane, o) in out.iter_mut().enumerate() {
7321+ o.0 |= above[plane].level != 0;
7322+ o.1 |= left[plane].level != 0;
7323+ o.2 += dc_vote(above[plane].dc) + dc_vote(left[plane].dc);
7324+ }
7325+ }
7326+ out
73097327 }
73107328
73117329 /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in
@@ -7319,21 +7337,25 @@ impl Neighbours {
73197337 /// mode-info units, mirroring [`Self::around_mi`].
73207338 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {
73217339 let (w_mi, h_mi) = (w / MI, h / MI);
7322- std::array::from_fn(|plane| {
7323- let mut above_coded = false;
7324- let mut left_coded = false;
7325- let mut vote = 0;
7326- for cell in 0..w_mi {
7327- let above = &self.above[mi_c + cell][plane];
7328- above_coded |= above.level != 0;
7329- vote += dc_vote(above.dc);
7340+ // [`Self::around_mi`]'s single pass, with the two extents split.
7341+ let mut out = [(false, false, 0i32); 3];
7342+ for cell in 0..w_mi {
7343+ let above = &self.above[mi_c + cell];
7344+ for (plane, o) in out.iter_mut().enumerate() {
7345+ o.0 |= above[plane].level != 0;
7346+ o.2 += dc_vote(above[plane].dc);
73307347 }
7331- for cell in 0..h_mi {
7332- let left = &self.left[mi_r + cell][plane];
7333- left_coded |= left.level != 0;
7334- vote += dc_vote(left.dc);
7348+ }
7349+ for cell in 0..h_mi {
7350+ let left = &self.left[mi_r + cell];
7351+ for (plane, o) in out.iter_mut().enumerate() {
7352+ o.1 |= left[plane].level != 0;
7353+ o.2 += dc_vote(left[plane].dc);
73357354 }
7336- if crate::envflags::env_flag!("EC_DCDUMP") {
7355+ }
7356+ if crate::envflags::env_flag!("EC_DCDUMP") {
7357+ for (plane, o) in out.iter().enumerate() {
7358+ let vote = o.2;
73377359 let ab: Vec<String> = (0..w_mi)
73387360 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
73397361 .collect();
@@ -7342,8 +7364,8 @@ impl Neighbours {
73427364 .collect();
73437365 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));
73447366 }
7345- (above_coded, left_coded, vote)
7346- })
7367+ }
7368+ out
73477369 }
73487370
73497371 /// The luma `txb_skip_ctx` of a transform unit smaller than its own block
@@ -18056,8 +18078,8 @@ fn edge_params_body(
1805618078 // bottom/right mi does not start there. Comparing mi origins instead is
1805718079 // the same test only while the block's own origin is aligned to its
1805818080 // size, which a 4x4 luma block read at the `| 1` mi is not.
18059- let cur_org = n.blk_org_grid[mi_r * n.skip_grid_cols_mi + mi_c];
18060- let cur_dim = n.blk_dim_grid[mi_r * n.skip_grid_cols_mi + mi_c];
18081+ let cur_cell = n.blk_grid[mi_r * n.skip_grid_cols_mi + mi_c];
18082+ let (cur_org, cur_dim) = (cur_cell.org, cur_cell.dim);
1806118083 let (org_px, dim_mi) = if c.dir == 0 {
1806218084 (usize::from(cur_org[1]), usize::from(cur_dim[0]))
1806318085 } else {
@@ -19376,10 +19398,9 @@ fn apply_cdef(
1937619398 if (0..2).any(|rr| {
1937719399 (0..2).any(|cc| {
1937819400 !skip_grid
19379- .skip_written
19401+ .blk_grid
1938019402 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
19381- .copied()
19382- .unwrap_or(true)
19403+ .map_or(true, |x| x.written)
1938319404 })
1938419405 }) {
1938519406 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));
@@ -19389,10 +19410,9 @@ fn apply_cdef(
1938919410 }
1939019411 let cell = |rr: usize, cc: usize| {
1939119412 skip_grid
19392- .skip_grid
19413+ .blk_grid
1939319414 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
19394- .copied()
19395- .unwrap_or(false)
19415+ .is_some_and(|x| x.skip)
1939619416 };
1939719417 let first = cell(0, 0);
1939819418 if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) {