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] = [
6314 [3, 5, 5, 5, 6],6314 [3, 5, 5, 5, 6],
6315 ];6315 ];
6316 6316
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+
6317 /// The neighbour state a block's contexts are read from — a duplicate of6330 /// The neighbour state a block's contexts are read from — a duplicate of
6318 /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's6331 /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's
6319 /// territory this round), kept at the same two granularities the real writer6332 /// territory this round), kept at the same two granularities the real writer
@@ -6449,27 +6462,25 @@ struct Neighbours {
6449 /// grain [`Self::record_mi`] already writes at), read back at 8x86462 /// grain [`Self::record_mi`] already writes at), read back at 8x8
6450 /// granularity by [`apply_cdef`] since `skip` is constant across every6463 /// granularity by [`apply_cdef`] since `skip` is constant across every
6451 /// mi cell one coded block covers.6464 /// mi cell one coded block covers.
6452- skip_grid: Vec<bool>,6465+ /// The four per-mi maps [`Neighbours::blk_grid`] packs, in one cell.
6453 /// lane-cdefstrip r1 instrument: whether any coded block actually WROTE6466 /// lane-cdefstrip r1 instrument: whether any coded block actually WROTE
6454- /// [`Self::skip_grid`] at this mi cell during this frame. A fresh6467+ /// the `skip` bit at this mi cell during this frame. A fresh
6455 /// `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so a decode6468 /// `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so a decode
6456 /// arm that forgets [`Self::fill_skip_grid_rect`] silently makes6469 /// arm that forgets [`Self::fill_skip_grid_rect`] silently makes
6457 /// [`apply_cdef`] filter an 8x8 unit libaom's `is_8x8_block_skip`6470 /// [`apply_cdef`] filter an 8x8 unit libaom's `is_8x8_block_skip`
6458 /// (`cdef.c:29-38`) excludes -- exactly the lane-cdef defect, and6471 /// (`cdef.c:29-38`) excludes -- exactly the lane-cdef defect, and
6459 /// unobservable from the pixels alone. Counted by6472 /// unobservable from the pixels alone. Counted by
6460 /// [`cdef_unwritten_skip_units`].6473 /// [`cdef_unwritten_skip_units`].
6461- skip_written: Vec<bool>,
6462 /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block6474 /// Per-4x4-mi origin `(mi_row, mi_col)` of the coded (prediction) block
6463 /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`,6475 /// covering that cell -- spec 7.14.2's `isBlockEdge`/libaom `pu_edge`,
6464 /// which re-enables the loop filter at a prediction boundary between two6476 /// which re-enables the loop filter at a prediction boundary between two
6465 /// skipped inter blocks (lane-mergefix r4). Written by6477 /// skipped inter blocks (lane-mergefix r4). Written by
6466 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.6478 /// [`Self::fill_skip_grid_rect`], whose `at_mi` IS that origin.
6467- blk_org_grid: Vec<[u16; 2]>,
6468 /// Per-4x4-mi `(width, height)` in mi units of the coded block covering6479 /// Per-4x4-mi `(width, height)` in mi units of the coded block covering
6469 /// that cell -- the other half of `pu_edge`: libaom tests the edge6480 /// that cell -- the other half of `pu_edge`: libaom tests the edge
6470 /// coordinate against the block's size in the FILTERED plane's own6481 /// coordinate against the block's size in the FILTERED plane's own
6471 /// pixels, which for chroma is `max(luma_dim / 2, 4)` (lane-t900 r30b).6482 /// 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>,
6473 skip_grid_cols_mi: usize,6484 skip_grid_cols_mi: usize,
6474 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder6485 /// Per-4x4-mi luma transform width in pixels (8/16/32/64) -- this decoder
6475 /// never splits a coded block's transform below its own size (round 2:6486 /// never splits a coded block's transform below its own size (round 2:
@@ -6591,10 +6602,10 @@ impl Neighbours {
6591 left_filter: vec![[3u8; 2]; rows * (SUB / MI)],6602 left_filter: vec![[3u8; 2]; rows * (SUB / MI)],
6592 mi_cols,6603 mi_cols,
6593 mi_rows,6604 mi_rows,
6594- skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],6605+ blk_grid: vec![
6595- skip_written: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],6606+ BlkCell { skip: false, written: false, org: [0; 2], dim: [1; 2] };
6596- blk_org_grid: vec![[0u16; 2]; cols * (SUB / MI) * rows * (SUB / MI)],6607+ cols * (SUB / MI) * rows * (SUB / MI)
6597- blk_dim_grid: vec![[1u8; 2]; cols * (SUB / MI) * rows * (SUB / MI)],6608+ ],
6598 skip_grid_cols_mi: cols * (SUB / MI),6609 skip_grid_cols_mi: cols * (SUB / MI),
6599 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],6610 tx_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
6600 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],6611 tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -7002,10 +7013,17 @@ impl Neighbours {
7002 }7013 }
7003 for rr in 0..h_mi {7014 for rr in 0..h_mi {
7004 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;7015 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
7005- fill_span(&mut self.skip_grid, start, w_mi, skip);7016+ fill_span(
7006- fill_span(&mut self.skip_written, start, w_mi, true);7017+ &mut self.blk_grid,
7007- fill_span(&mut self.blk_org_grid, start, w_mi, [mi_r as u16, mi_c as u16]);7018+ start,
7008- fill_span(&mut self.blk_dim_grid, start, w_mi, [w_mi as u8, h_mi as u8]);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+ );
7009 }7027 }
7010 }7028 }
7011 7029
@@ -7019,10 +7037,9 @@ impl Neighbours {
7019 /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a7037 /// filter's `curr_skipped`/`pv_skip_txfm` (spec 7.14.2) want, since a
7020 /// filtered edge's two sides are each exactly one coded block wide.7038 /// filtered edge's two sides are each exactly one coded block wide.
7021 fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool {7039 fn skip_at(&self, mi_r: usize, mi_c: usize) -> bool {
7022- self.skip_grid7040+ self.blk_grid
7023 .get(mi_r * self.skip_grid_cols_mi + mi_c)7041 .get(mi_r * self.skip_grid_cols_mi + mi_c)
7024- .copied()7042+ .is_some_and(|c| c.skip)
7025- .unwrap_or(false)
7026 }7043 }
7027 7044
7028 /// The `skip_txfm` context of a block whose top-left mi cell is7045 /// The `skip_txfm` context of a block whose top-left mi cell is
@@ -7038,10 +7055,9 @@ impl Neighbours {
7038 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {7055 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {
7039 (0..2).all(|rr| {7056 (0..2).all(|rr| {
7040 (0..2).all(|cc| {7057 (0..2).all(|cc| {
7041- self.skip_grid7058+ self.blk_grid
7042 .get((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))7059 .get((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))
7043- .copied()7060+ .is_some_and(|c| c.skip)
7044- .unwrap_or(false)
7045 })7061 })
7046 })7062 })
7047 }7063 }
@@ -7293,19 +7309,21 @@ impl Neighbours {
7293 /// units, for the same reason [`Self::record_mi`] does.7309 /// units, for the same reason [`Self::record_mi`] does.
7294 fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] {7310 fn around_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> [(bool, bool, i32); 3] {
7295 let side_mi = side / MI;7311 let side_mi = side / MI;
7296- std::array::from_fn(|plane| {7312+ // One pass over the cells accumulating all three planes, not one pass
7297- let mut above_coded = false;7313+ // per plane: the three planes of a cell live in the same
7298- let mut left_coded = false;7314+ // `[Neighbour; 3]` (6 bytes), so the per-plane form loaded the same
7299- let mut vote = 0;7315+ // cache lines three times (lane-publish).
7300- for cell in 0..side_mi {7316+ let mut out = [(false, false, 0i32); 3];
7301- let above = &self.above[mi_c + cell][plane];7317+ for cell in 0..side_mi {
7302- let left = &self.left[mi_r + cell][plane];7318+ let above = &self.above[mi_c + cell];
7303- above_coded |= above.level != 0;7319+ let left = &self.left[mi_r + cell];
7304- left_coded |= left.level != 0;7320+ for (plane, o) in out.iter_mut().enumerate() {
7305- vote += dc_vote(above.dc) + dc_vote(left.dc);7321+ o.0 |= above[plane].level != 0;
7306- }7322+ o.1 |= left[plane].level != 0;
7307- (above_coded, left_coded, vote)7323+ o.2 += dc_vote(above[plane].dc) + dc_vote(left[plane].dc);
7308- })7324+ }
7325+ }
7326+ out
7309 }7327 }
7310 7328
7311 /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in7329 /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in
@@ -7319,21 +7337,25 @@ impl Neighbours {
7319 /// mode-info units, mirroring [`Self::around_mi`].7337 /// mode-info units, mirroring [`Self::around_mi`].
7320 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {7338 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {
7321 let (w_mi, h_mi) = (w / MI, h / MI);7339 let (w_mi, h_mi) = (w / MI, h / MI);
7322- std::array::from_fn(|plane| {7340+ // [`Self::around_mi`]'s single pass, with the two extents split.
7323- let mut above_coded = false;7341+ let mut out = [(false, false, 0i32); 3];
7324- let mut left_coded = false;7342+ for cell in 0..w_mi {
7325- let mut vote = 0;7343+ let above = &self.above[mi_c + cell];
7326- for cell in 0..w_mi {7344+ for (plane, o) in out.iter_mut().enumerate() {
7327- let above = &self.above[mi_c + cell][plane];7345+ o.0 |= above[plane].level != 0;
7328- above_coded |= above.level != 0;7346+ o.2 += dc_vote(above[plane].dc);
7329- vote += dc_vote(above.dc);
7330 }7347 }
7331- for cell in 0..h_mi {7348+ }
7332- let left = &self.left[mi_r + cell][plane];7349+ for cell in 0..h_mi {
7333- left_coded |= left.level != 0;7350+ let left = &self.left[mi_r + cell];
7334- vote += dc_vote(left.dc);7351+ for (plane, o) in out.iter_mut().enumerate() {
7352+ o.1 |= left[plane].level != 0;
7353+ o.2 += dc_vote(left[plane].dc);
7335 }7354 }
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;
7337 let ab: Vec<String> = (0..w_mi)7359 let ab: Vec<String> = (0..w_mi)
7338 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))7360 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
7339 .collect();7361 .collect();
@@ -7342,8 +7364,8 @@ impl Neighbours {
7342 .collect();7364 .collect();
7343 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));7365 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));
7344 }7366 }
7345- (above_coded, left_coded, vote)7367+ }
7346- })7368+ out
7347 }7369 }
7348 7370
7349 /// The luma `txb_skip_ctx` of a transform unit smaller than its own block7371 /// The luma `txb_skip_ctx` of a transform unit smaller than its own block
@@ -18056,8 +18078,8 @@ fn edge_params_body(
18056 // bottom/right mi does not start there. Comparing mi origins instead is18078 // bottom/right mi does not start there. Comparing mi origins instead is
18057 // the same test only while the block's own origin is aligned to its18079 // the same test only while the block's own origin is aligned to its
18058 // size, which a 4x4 luma block read at the `| 1` mi is not.18080 // 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];18081+ let cur_cell = n.blk_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];18082+ let (cur_org, cur_dim) = (cur_cell.org, cur_cell.dim);
18061 let (org_px, dim_mi) = if c.dir == 0 {18083 let (org_px, dim_mi) = if c.dir == 0 {
18062 (usize::from(cur_org[1]), usize::from(cur_dim[0]))18084 (usize::from(cur_org[1]), usize::from(cur_dim[0]))
18063 } else {18085 } else {
@@ -19376,10 +19398,9 @@ fn apply_cdef(
19376 if (0..2).any(|rr| {19398 if (0..2).any(|rr| {
19377 (0..2).any(|cc| {19399 (0..2).any(|cc| {
19378 !skip_grid19400 !skip_grid
19379- .skip_written19401+ .blk_grid
19380 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))19402 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
19381- .copied()19403+ .map_or(true, |x| x.written)
19382- .unwrap_or(true)
19383 })19404 })
19384 }) {19405 }) {
19385 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));19406 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));
@@ -19389,10 +19410,9 @@ fn apply_cdef(
19389 }19410 }
19390 let cell = |rr: usize, cc: usize| {19411 let cell = |rr: usize, cc: usize| {
19391 skip_grid19412 skip_grid
19392- .skip_grid19413+ .blk_grid
19393 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))19414 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
19394- .copied()19415+ .is_some_and(|x| x.skip)
19395- .unwrap_or(false)
19396 };19416 };
19397 let first = cell(0, 0);19417 let first = cell(0, 0);
19398 if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) {19418 if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) {